From ea533afc01bac3699cdfdb57f4a76d2d4fc1a4ac Mon Sep 17 00:00:00 2001 From: coffee-compiler <22056268-coffee-compiler@users.noreply.gitlab.com> Date: Wed, 14 Aug 2024 09:53:58 +0000 Subject: [PATCH] Fix ability to send trade requests to every entity --- CHANGELOG.md | 1 + voxygen/src/session/mod.rs | 28 ++++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f82a2d554..9c357679ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Text overflow and flickering in the crafting menu. - Crash when deleting entries from the server list. - Active buttons in repair equipment interface when missing requirements. +- Ability to send trade requests to every entity. ## [0.16.0] - 2024-03-30 diff --git a/voxygen/src/session/mod.rs b/voxygen/src/session/mod.rs index b4051bc7b3..63f49c36b8 100644 --- a/voxygen/src/session/mod.rs +++ b/voxygen/src/session/mod.rs @@ -19,8 +19,8 @@ use common::{ inventory::slot::{EquipSlot, Slot}, invite::InviteKind, item::{tool::ToolKind, ItemDesc}, - CharacterActivity, ChatType, Content, Fluid, InputKind, InventoryUpdateEvent, Pos, - PresenceKind, Stats, UtteranceKind, Vel, + Alignment, CharacterActivity, ChatType, Content, Fluid, InputKind, InventoryUpdateEvent, + Pos, PresenceKind, Stats, UtteranceKind, Vel, }, consts::MAX_MOUNT_RANGE, event::UpdateCharacterMetadata, @@ -1133,8 +1133,26 @@ impl PlayState for SessionState { match interactable { Interactable::Block(_, _, _) => {}, Interactable::Entity(entity) => { - if let Some(uid) = - client.state().ecs().uid_from_entity(*entity) + let can_trade_to = client + .state() + .read_component_cloned::(*entity) + .is_some_and(|a| match a { + Alignment::Npc => true, + Alignment::Owned(owner) + if client.uid().is_some_and( + |uid| owner == uid, + ) => + { + true + }, + _ => false, + }); + + if can_trade_to + && let Some(uid) = client + .state() + .ecs() + .uid_from_entity(*entity) { let name = client .player_list() @@ -1149,12 +1167,14 @@ impl PlayState for SessionState { |e| e.name.to_owned(), ) }); + self.hud.new_message(ChatType::Meta.into_msg( Content::localized_with_args( "hud-trade-invite_sent", [("playername", name)], ), )); + client.send_invite(uid, InviteKind::Trade) }; },