hurtlog keeps a LAN guest's hurts across a respawn

A guest's body is rebuilt when it respawns, and its hurt and attack logs
went with the old one: the control socket's hurtlog lost the hurts that
killed it whenever the death and the respawn fell between two reads.
The logs now pass to the new body, and a dead guest's are read too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit df9fa5f0185766f7a7338df5046200d1a2e67d22)
This commit is contained in:
Ludovic Marie
2026-10-21 12:09:18 +02:00
parent 33183952d5
commit 169be6374c
3 changed files with 29 additions and 8 deletions
+12 -7
View File
@@ -715,9 +715,12 @@ impl Game<'_> {
/// The hurts and melee attacks each player logged since the last call
/// (`PlayerMotion::hurt_log`, `attack_log`), taken out.
fn control_hurt_log(&mut self) -> Value {
fn drain(name: &str, p: &mut horizon_client::motion::PlayerMotion) -> Value {
let hurts: Vec<Value> = p
.hurt_log
fn drain(
name: &str,
hurt_log: &mut Vec<horizon_client::health::HurtRecord>,
attack_log: &mut Vec<horizon_client::health::AttackRecord>,
) -> Value {
let hurts: Vec<Value> = hurt_log
.drain(..)
.map(|r| {
json!({
@@ -728,8 +731,7 @@ impl Game<'_> {
})
})
.collect();
let attacks: Vec<Value> = p
.attack_log
let attacks: Vec<Value> = attack_log
.drain(..)
.map(|r| {
json!({
@@ -742,13 +744,16 @@ impl Game<'_> {
}
let mut players = Vec::new();
if let Some(p) = self.player.as_mut() {
players.push(drain("host", p));
players.push(drain("host", &mut p.hurt_log, &mut p.attack_log));
}
if let Some(host) = self.lan.as_mut() {
for g in &mut host.hub.guests {
let name = g.name.clone();
if let Some(m) = g.motion.as_mut() {
players.push(drain(&name, m));
players.push(drain(&name, &mut m.hurt_log, &mut m.attack_log));
} else if let Some((mut hurts, mut attacks)) = g.logs_kept.take() {
// Dead, not yet respawned: what its last body logged.
players.push(drain(&name, &mut hurts, &mut attacks));
}
}
}
@@ -200,6 +200,11 @@ impl Game<'_> {
host.hub.guests[i].position[2],
);
host.hub.guests[i].motion = PlayerMotion::new(self.motion, p).ok().map(Box::new);
let kept = host.hub.guests[i].logs_kept.take();
if let (Some(m), Some((hurts, attacks))) = (host.hub.guests[i].motion.as_mut(), kept) {
m.hurt_log = hurts;
m.attack_log = attacks;
}
}
let mut play = host.play.remove(&conn).unwrap_or_default();
let g = &mut host.hub.guests[i];
@@ -1336,7 +1341,10 @@ impl Game<'_> {
g.food = 20;
g.saturation = 5.0;
g.sent_health = None;
g.motion = None;
if let Some(m) = g.motion.take() {
let m = *m;
g.logs_kept = Some((m.hurt_log, m.attack_log));
}
let mut xp = Experience {
level: g.xp_level,
progress: g.xp_progress,
+8
View File
@@ -122,6 +122,13 @@ pub struct Guest {
pub tracker: Tracker,
// Player state the gameplay code reads and writes.
pub motion: Option<Box<PlayerMotion>>,
/// The hurt and attack logs of the body it had before it respawned,
/// until the new body takes them over (the control socket's `hurtlog`
/// reads across a death).
pub logs_kept: Option<(
Vec<crate::health::HurtRecord>,
Vec<crate::health::AttackRecord>,
)>,
/// The 36 inventory slots (hotbar first), armor (head..feet) and off hand.
pub inventory: Vec<Option<ItemStack>>,
pub armor: [Option<ItemStack>; 4],
@@ -251,6 +258,7 @@ impl Guest {
batch_quota: 0.0,
tracker: Tracker::default(),
motion: None,
logs_kept: None,
inventory: vec![None; 36],
armor: [None, None, None, None],
offhand: None,