Merge branch 'coffee-compiler/fix_trade_with_everyone' into 'master'

Fix ability to send trade requests to every entity

See merge request veloren/veloren!4549
This commit is contained in:
crabman 2024-08-14 09:53:58 +00:00
commit b8feae67de
2 changed files with 25 additions and 4 deletions

View File

@ -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

View File

@ -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::<Alignment>(*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)
};
},