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:
@@ -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;
|
||||
|
||||
@@ -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)),
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user