Combined attack logs that happen on the same tick, involving the player

This commit is contained in:
Llywelwyn 2023-08-01 20:23:08 +01:00
parent 51893def78
commit 60fe39c834
2 changed files with 20 additions and 14 deletions

View file

@ -240,7 +240,9 @@ impl<'a> System<'a> for ItemUseSystem {
equipped.remove(*item); equipped.remove(*item);
backpack.insert(*item, InBackpack { owner: target }).expect("Unable to insert backpack"); backpack.insert(*item, InBackpack { owner: target }).expect("Unable to insert backpack");
if target == *player_entity { if target == *player_entity {
logger = logger.append("You remove your").item_name_n(&item_being_used.name).period(); if let Some(name) = names.get(*item) {
logger = logger.append("You remove your").item_name_n(&name.name).period();
}
} }
} }

View file

@ -63,6 +63,8 @@ impl<'a> System<'a> for MeleeCombatSystem {
// 1d20 must be less than 10, 45% chance of a hit // 1d20 must be less than 10, 45% chance of a hit
const COMBAT_LOGGING: bool = true; const COMBAT_LOGGING: bool = true;
let mut logger = gamelog::Logger::new();
let mut something_to_log = false;
for (entity, wants_melee, name, attacker_attributes, attacker_skills, attacker_pools) in for (entity, wants_melee, name, attacker_attributes, attacker_skills, attacker_pools) in
(&entities, &wants_melee, &names, &attributes, &skills, &pools).join() (&entities, &wants_melee, &names, &attributes, &skills, &pools).join()
@ -223,18 +225,18 @@ impl<'a> System<'a> for MeleeCombatSystem {
} }
SufferDamage::new_damage(&mut inflict_damage, wants_melee.target, damage, entity == *player_entity); SufferDamage::new_damage(&mut inflict_damage, wants_melee.target, damage, entity == *player_entity);
if entity == *player_entity { if entity == *player_entity {
gamelog::Logger::new() // You hit the <name>. something_to_log = true;
logger = logger // You hit the <name>.
.append("You hit the") .append("You hit the")
.npc_name_n(&target_name.name) .npc_name_n(&target_name.name)
.period() .period();
.log();
} else if wants_melee.target == *player_entity { } else if wants_melee.target == *player_entity {
gamelog::Logger::new() // <name> hits you! something_to_log = true;
logger = logger // <name> hits you!
.append("The") .append("The")
.npc_name(&name.name) .npc_name(&name.name)
.append(attack_verb) .append(attack_verb)
.append("you!") .append("you!");
.log();
} else { } else {
gamelog::Logger::new() // <name> misses the <target>. gamelog::Logger::new() // <name> misses the <target>.
.append("The") .append("The")
@ -255,16 +257,16 @@ impl<'a> System<'a> for MeleeCombatSystem {
particle_builder.attack_miss(pos.x, pos.y) particle_builder.attack_miss(pos.x, pos.y)
} }
if entity == *player_entity { if entity == *player_entity {
gamelog::Logger::new() // You miss. something_to_log = true;
.append("You miss.") logger = logger // You miss.
.log(); .append("You miss.");
} else if wants_melee.target == *player_entity { } else if wants_melee.target == *player_entity {
gamelog::Logger::new() // <name> misses! something_to_log = true;
logger = logger // <name> misses!
.append("The") .append("The")
.npc_name(&name.name) .npc_name(&name.name)
.colour(rltk::WHITE) .colour(rltk::WHITE)
.append("misses!") .append("misses!");
.log();
} else { } else {
gamelog::Logger::new() // <name> misses the <target>. gamelog::Logger::new() // <name> misses the <target>.
.append("The") .append("The")
@ -278,8 +280,10 @@ impl<'a> System<'a> for MeleeCombatSystem {
} }
} }
} }
wants_melee.clear(); wants_melee.clear();
if something_to_log {
logger.log();
}
} }
} }