Provide buff information on killed entities

This commit is contained in:
Jesus Bracho 2021-01-18 05:46:53 +00:00 committed by Samuel Keiffer
parent 16c865ac27
commit ec79890335
7 changed files with 70 additions and 7 deletions

View File

@ -12,13 +12,15 @@
"hud.chat.fall_kill_msg": "[{name}] died from fall damage", "hud.chat.fall_kill_msg": "[{name}] died from fall damage",
"hud.chat.suicide_msg": "[{name}] died from self-inflicted wounds", "hud.chat.suicide_msg": "[{name}] died from self-inflicted wounds",
"hud.chat.pvp_buff_kill_msg": "[{victim}] died of {buff} caused by [{attacker}]",
"hud.chat.pvp_melee_kill_msg": "[{attacker}] defeated [{victim}]", "hud.chat.pvp_melee_kill_msg": "[{attacker}] defeated [{victim}]",
"hud.chat.pvp_ranged_kill_msg": "[{attacker}] shot [{victim}]", "hud.chat.pvp_ranged_kill_msg": "[{attacker}] shot [{victim}]",
"hud.chat.pvp_explosion_kill_msg": "[{attacker}] blew up [{victim}]", "hud.chat.pvp_explosion_kill_msg": "[{attacker}] blew up [{victim}]",
"hud.chat.pvp_energy_kill_msg": "[{attacker}] killed [{victim}] with magic", "hud.chat.pvp_energy_kill_msg": "[{attacker}] killed [{victim}] with magic",
"hud.chat.pvp_buff_kill_msg": "[{attacker}] killed [{victim}]",
"hud.chat.nonexistent_buff_kill_msg": "[{victim}] died of {buff}",
"hud.chat.npc_buff_kill_msg": "[{victim}] died of {buff} caused by [{attacker}]",
"hud.chat.npc_melee_kill_msg": "{attacker} killed [{victim}]", "hud.chat.npc_melee_kill_msg": "{attacker} killed [{victim}]",
"hud.chat.npc_ranged_kill_msg": "{attacker} shot [{victim}]", "hud.chat.npc_ranged_kill_msg": "{attacker} shot [{victim}]",
"hud.chat.npc_explosion_kill_msg": "{attacker} blew up [{victim}]", "hud.chat.npc_explosion_kill_msg": "{attacker} blew up [{victim}]",

View File

@ -1797,6 +1797,12 @@ impl Client {
// Needed for cli clients that don't set localization info // Needed for cli clients that don't set localization info
if message.is_empty() { if message.is_empty() {
match kill_source { match kill_source {
KillSource::Player(attacker_uid, KillType::Buff(buff_kind)) => format!(
"[{}] died of {} caused by [{}]",
alias_of_uid(victim),
format!("{:?}", buff_kind).to_lowercase().as_str(),
alias_of_uid(attacker_uid)
),
KillSource::Player(attacker_uid, KillType::Melee) => format!( KillSource::Player(attacker_uid, KillType::Melee) => format!(
"[{}] killed [{}]", "[{}] killed [{}]",
alias_of_uid(attacker_uid), alias_of_uid(attacker_uid),
@ -1822,6 +1828,17 @@ impl Client {
alias_of_uid(attacker_uid), alias_of_uid(attacker_uid),
alias_of_uid(victim) alias_of_uid(victim)
), ),
KillSource::NonExistent(KillType::Buff(buff_kind)) => format!(
"[{}] died of {}",
alias_of_uid(victim),
format!("{:?}", buff_kind).to_lowercase().as_str()
),
KillSource::NonPlayer(attacker_name, KillType::Buff(buff_kind)) => format!(
"[{}] died of {} caused by [{}]",
alias_of_uid(victim),
format!("{:?}", buff_kind).to_lowercase().as_str(),
attacker_name
),
KillSource::NonPlayer(attacker_name, KillType::Melee) => { KillSource::NonPlayer(attacker_name, KillType::Melee) => {
format!("{} killed [{}]", attacker_name, alias_of_uid(victim)) format!("{} killed [{}]", attacker_name, alias_of_uid(victim))
}, },
@ -1848,10 +1865,15 @@ impl Client {
KillSource::Suicide => { KillSource::Suicide => {
format!("[{}] died from self-inflicted wounds", alias_of_uid(victim)) format!("[{}] died from self-inflicted wounds", alias_of_uid(victim))
}, },
KillSource::NonExistent(_) => format!("[{}] died", alias_of_uid(victim)),
KillSource::Other => format!("[{}] died", alias_of_uid(victim)), KillSource::Other => format!("[{}] died", alias_of_uid(victim)),
} }
} else { } else {
match kill_source { match kill_source {
KillSource::Player(attacker_uid, KillType::Buff(buff_kind)) => message
.replace("{attacker}", &alias_of_uid(attacker_uid))
.replace("{buff}", format!("{:?}", buff_kind).to_lowercase().as_str())
.replace("{victim}", &alias_of_uid(victim)),
KillSource::Player(attacker_uid, KillType::Melee) => message KillSource::Player(attacker_uid, KillType::Melee) => message
.replace("{attacker}", &alias_of_uid(attacker_uid)) .replace("{attacker}", &alias_of_uid(attacker_uid))
.replace("{victim}", &alias_of_uid(victim)), .replace("{victim}", &alias_of_uid(victim)),
@ -1867,6 +1889,13 @@ impl Client {
KillSource::Player(attacker_uid, KillType::Other) => message KillSource::Player(attacker_uid, KillType::Other) => message
.replace("{attacker}", &alias_of_uid(attacker_uid)) .replace("{attacker}", &alias_of_uid(attacker_uid))
.replace("{victim}", &alias_of_uid(victim)), .replace("{victim}", &alias_of_uid(victim)),
KillSource::NonExistent(KillType::Buff(buff_kind)) => message
.replace("{buff}", format!("{:?}", buff_kind).to_lowercase().as_str())
.replace("{victim}", &alias_of_uid(victim)),
KillSource::NonPlayer(attacker_name, KillType::Buff(buff_kind)) => message
.replace("{attacker}", attacker_name)
.replace("{buff}", format!("{:?}", buff_kind).to_lowercase().as_str())
.replace("{victim}", &alias_of_uid(victim)),
KillSource::NonPlayer(attacker_name, KillType::Melee) => message KillSource::NonPlayer(attacker_name, KillType::Melee) => message
.replace("{attacker}", attacker_name) .replace("{attacker}", attacker_name)
.replace("{victim}", &alias_of_uid(victim)), .replace("{victim}", &alias_of_uid(victim)),
@ -1887,6 +1916,9 @@ impl Client {
.replace("{environment}", environment), .replace("{environment}", environment),
KillSource::FallDamage => message.replace("{name}", &alias_of_uid(victim)), KillSource::FallDamage => message.replace("{name}", &alias_of_uid(victim)),
KillSource::Suicide => message.replace("{name}", &alias_of_uid(victim)), KillSource::Suicide => message.replace("{name}", &alias_of_uid(victim)),
KillSource::NonExistent(_) => {
message.replace("{name}", &alias_of_uid(victim))
},
KillSource::Other => message.replace("{name}", &alias_of_uid(victim)), KillSource::Other => message.replace("{name}", &alias_of_uid(victim)),
} }
} }

View File

@ -1,7 +1,7 @@
use crate::{ use crate::{
comp::{ comp::{
inventory::item::{armor::Protection, ItemKind}, inventory::item::{armor::Protection, ItemKind},
HealthChange, HealthSource, Inventory, BuffKind, HealthChange, HealthSource, Inventory,
}, },
uid::Uid, uid::Uid,
util::Dir, util::Dir,
@ -17,6 +17,7 @@ pub enum GroupTarget {
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)] #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub enum DamageSource { pub enum DamageSource {
Buff(BuffKind),
Melee, Melee,
Healing, Healing,
Projectile, Projectile,
@ -149,6 +150,13 @@ impl Damage {
cause: HealthSource::World, cause: HealthSource::World,
} }
}, },
DamageSource::Buff(_) => HealthChange {
amount: -damage as i32,
cause: HealthSource::Damage {
kind: self.source,
by: uid,
},
},
DamageSource::Other => HealthChange { DamageSource::Other => HealthChange {
amount: -damage as i32, amount: -damage as i32,
cause: HealthSource::Damage { cause: HealthSource::Damage {

View File

@ -1,4 +1,7 @@
use crate::{comp::group::Group, uid::Uid}; use crate::{
comp::{group::Group, BuffKind},
uid::Uid,
};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use specs::Component; use specs::Component;
use specs_idvs::IdvStorage; use specs_idvs::IdvStorage;
@ -47,6 +50,7 @@ impl Default for ChatMode {
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub enum KillType { pub enum KillType {
Buff(BuffKind),
Melee, Melee,
Projectile, Projectile,
Explosion, Explosion,
@ -59,6 +63,7 @@ pub enum KillType {
pub enum KillSource { pub enum KillSource {
Player(Uid, KillType), Player(Uid, KillType),
NonPlayer(String, KillType), NonPlayer(String, KillType),
NonExistent(KillType),
Environment(String), Environment(String),
FallDamage, FallDamage,
Suicide, Suicide,

View File

@ -95,7 +95,7 @@ impl<'a> System<'a> for Sys {
HealthSource::Heal { by: buff_owner } HealthSource::Heal { by: buff_owner }
} else { } else {
HealthSource::Damage { HealthSource::Damage {
kind: DamageSource::Other, kind: DamageSource::Buff(buff.kind),
by: buff_owner, by: buff_owner,
} }
}; };

View File

@ -100,10 +100,10 @@ pub fn handle_destroy(server: &mut Server, entity: EcsEntity, cause: HealthSourc
} else if let Some(stats) = state.ecs().read_storage::<Stats>().get(char_entity) { } else if let Some(stats) = state.ecs().read_storage::<Stats>().get(char_entity) {
KillSource::NonPlayer(stats.name.clone(), cause_of_death) KillSource::NonPlayer(stats.name.clone(), cause_of_death)
} else { } else {
KillSource::NonPlayer("<?>".to_string(), cause_of_death) KillSource::NonExistent(cause_of_death)
} }
} else { } else {
KillSource::NonPlayer("<?>".to_string(), cause_of_death) KillSource::NonExistent(cause_of_death)
} }
}; };
@ -131,6 +131,10 @@ pub fn handle_destroy(server: &mut Server, entity: EcsEntity, cause: HealthSourc
kind: DamageSource::Energy, kind: DamageSource::Energy,
by: Some(by), by: Some(by),
} => get_attacker_name(KillType::Energy, by), } => get_attacker_name(KillType::Energy, by),
HealthSource::Damage {
kind: DamageSource::Buff(buff_kind),
by: Some(by),
} => get_attacker_name(KillType::Buff(buff_kind), by),
HealthSource::Damage { HealthSource::Damage {
kind: DamageSource::Other, kind: DamageSource::Other,
by: Some(by), by: Some(by),

View File

@ -355,6 +355,10 @@ impl<'a> Widget for Chat<'a> {
.get("hud.chat.offline_msg") .get("hud.chat.offline_msg")
.to_string(), .to_string(),
ChatType::Kill(kill_source, _) => match kill_source { ChatType::Kill(kill_source, _) => match kill_source {
KillSource::Player(_, KillType::Buff(_)) => self
.localized_strings
.get("hud.chat.pvp_buff_kill_msg")
.to_string(),
KillSource::Player(_, KillType::Melee) => self KillSource::Player(_, KillType::Melee) => self
.localized_strings .localized_strings
.get("hud.chat.pvp_melee_kill_msg") .get("hud.chat.pvp_melee_kill_msg")
@ -375,6 +379,14 @@ impl<'a> Widget for Chat<'a> {
.localized_strings .localized_strings
.get("hud.chat.pvp_other_kill_msg") .get("hud.chat.pvp_other_kill_msg")
.to_string(), .to_string(),
KillSource::NonExistent(KillType::Buff(_)) => self
.localized_strings
.get("hud.chat.nonexistent_buff_kill_msg")
.to_string(),
KillSource::NonPlayer(_, KillType::Buff(_)) => self
.localized_strings
.get("hud.chat.npc_buff_kill_msg")
.to_string(),
KillSource::NonPlayer(_, KillType::Melee) => self KillSource::NonPlayer(_, KillType::Melee) => self
.localized_strings .localized_strings
.get("hud.chat.npc_melee_kill_msg") .get("hud.chat.npc_melee_kill_msg")
@ -407,7 +419,7 @@ impl<'a> Widget for Chat<'a> {
.localized_strings .localized_strings
.get("hud.chat.suicide_msg") .get("hud.chat.suicide_msg")
.to_string(), .to_string(),
KillSource::Other => self KillSource::NonExistent(_) | KillSource::Other => self
.localized_strings .localized_strings
.get("hud.chat.default_death_msg") .get("hud.chat.default_death_msg")
.to_string(), .to_string(),