Count the combat statistics

damage_resisted, damage_absorbed and damage_blocked_by_shield now add up when
Resistance, absorption hearts or a shield take damage, and a player who lands
the killing blow on another player gets player_kills.
This commit is contained in:
Kacpherek
2026-10-26 15:16:34 +01:00
parent 8027cb4176
commit 273729aac8
3 changed files with 39 additions and 0 deletions
+10
View File
@@ -73,6 +73,16 @@ impl Game<'_> {
self.recheck_combat();
for e in events {
let (name, amount) = match e {
// LivingEntity.getDamageAfterMagicAbsorb (Resistance) and
// Player.actuallyHurt (absorption hearts), in tenths.
MotionEvent::Health(HealthEvent::Statistic { name, amount }) => {
match *name {
"resisted" => self.stats.custom("damage_resisted", *amount),
"absorbed" => self.stats.custom("damage_absorbed", *amount),
_ => {}
}
continue;
}
MotionEvent::Health(HealthEvent::RecordedDamage { source, amount }) => {
let Some(d) = self.motion.health.damage.definition(*source) else {
continue;
+22
View File
@@ -253,6 +253,28 @@ impl Game<'_> {
Victim::Host => land(self),
Victim::Guest(conn) => self.guest_struck_by(host, conn, land).unwrap_or(false),
};
// ServerPlayer.awardKillScore: the blow that kills a player.
if hurt {
let died = match victim {
Victim::Host => self
.player
.as_ref()
.is_some_and(|p| p.health.dead_or_dying()),
Victim::Guest(conn) => host
.hub
.guest(conn)
.and_then(|g| g.motion.as_deref())
.is_some_and(|p| p.health.dead_or_dying()),
};
if died {
match s.attacker {
Some(conn) => {
self.as_guest(host, conn, |g| g.stats.custom("player_kills", 1));
}
None => self.stats.custom("player_kills", 1),
}
}
}
if hurt && s.crit {
let target = match victim {
Victim::Host => self.player.as_ref().map(|p| (host.host_entity, p)),
+7
View File
@@ -121,6 +121,13 @@ impl Game<'_> {
attacker: Option<u32>,
projectile: bool,
) {
// LivingEntity.hurtServer: the damage the shield took, in tenths.
if outcome.blocked > 0.0 {
self.stats.custom(
"damage_blocked_by_shield",
(outcome.blocked * 10.0).round() as i32,
);
}
let Some((slot, _)) = self.using else { return };
let Some(stack) = self.stack_in(slot).cloned() else {
return;