Replace "Player 1" with an NPC name when trading with an NPC

This commit is contained in:
ubruntu 2021-07-11 18:27:34 +00:00 committed by Samuel Keiffer
parent 7cf5bc4bb7
commit 6bb47b447e
2 changed files with 26 additions and 5 deletions

View File

@ -17,7 +17,7 @@ use client::Client;
use common::{
comp::{
inventory::item::{MaterialStatManifest, Quality},
Inventory,
Inventory, Stats,
},
trade::{PendingTrade, SitePrices, TradeAction, TradePhase},
};
@ -169,7 +169,7 @@ impl<'a> Trade<'a> {
(x, is_ours) if ours == is_ours => x,
_ => check_if_us(1)?.0,
};
// TODO: update in accordence with https://gitlab.com/veloren/veloren/-/issues/960
// TODO: update in accordance with https://gitlab.com/veloren/veloren/-/issues/960
let inventory = inventories.get(entity)?;
// Alignment for Grid
@ -188,6 +188,13 @@ impl<'a> Trade<'a> {
.player_list()
.get(&uid)
.map(|info| info.player_alias.clone())
.or_else(|| {
self.client
.state()
.read_storage::<Stats>()
.get(entity)
.map(|e| e.name.to_owned())
})
.unwrap_or_else(|| format!("Player {}", who));
let offer_header = self

View File

@ -15,7 +15,7 @@ use common::{
inventory::slot::{EquipSlot, Slot},
invite::InviteKind,
item::{tool::ToolKind, ItemDef, ItemDesc},
ChatMsg, ChatType, InputKind, InventoryUpdateEvent, Pos, UtteranceKind, Vel,
ChatMsg, ChatType, InputKind, InventoryUpdateEvent, Pos, Stats, UtteranceKind, Vel,
},
consts::{MAX_MOUNT_RANGE, MAX_PICKUP_RANGE},
outcome::Outcome,
@ -164,7 +164,15 @@ impl SessionState {
};
let target_name = match client.player_list().get(&target) {
Some(info) => info.player_alias.clone(),
None => format!("<entity {}>", target),
None => match client.state().ecs().entity_from_uid(target.0) {
Some(entity) => {
let stats = client.state().read_storage::<Stats>();
stats
.get(entity)
.map_or(format!("<entity {}>", target), |e| e.name.to_owned())
},
None => format!("<uid {}>", target),
},
};
let answer_str = match answer {
InviteAnswer::Accepted => "accepted",
@ -698,7 +706,13 @@ impl PlayState for SessionState {
.get(&uid)
.map(|info| info.player_alias.clone())
.unwrap_or_else(|| {
format!("<entity {:?}>", uid)
let stats = client
.state()
.read_storage::<Stats>();
stats.get(entity).map_or(
format!("<entity {:?}>", uid),
|e| e.name.to_owned(),
)
});
let msg = global_state
.i18n