Fix for some of the tracking issues

This commit is contained in:
Lol3rrr
2024-09-26 15:54:05 +02:00
parent ddfac3591f
commit d1e1caee92
2 changed files with 46 additions and 33 deletions

View File

@@ -68,6 +68,9 @@ pub fn parse(buf: &[u8]) -> Result<EndOfGame, ()> {
&mut player_life, &mut player_life,
); );
} }
csdemo::game_event::GameEvent::PlayerHurt(phurt) => {
// println!("Untracked: {:?}", phurt);
}
_ => {} _ => {}
}; };
} }
@@ -111,7 +114,9 @@ fn player_death(
let attacker_id = match death.attacker.filter(|p| p.0 < 10) { let attacker_id = match death.attacker.filter(|p| p.0 < 10) {
Some(a) => a, Some(a) => a,
None => return, None => {
return;
},
}; };
player_died.deaths += 1; player_died.deaths += 1;
@@ -147,38 +152,42 @@ fn player_hurt(
) { ) {
let attacked_player = match player_info.get(hurt.userid.as_ref().unwrap()) { let attacked_player = match player_info.get(hurt.userid.as_ref().unwrap()) {
Some(a) => a, Some(a) => a,
None => return, None => {
return;
},
}; };
let attacker_id = match hurt.attacker { let attacker_id = match hurt.attacker {
Some(aid) => aid, Some(aid) => aid,
None => return, None => {
return;
},
}; };
let attacking_player = match player_info.get(&attacker_id) {
Some(a) => a,
None => return,
};
let attacker = player_stats.entry(attacker_id).or_default();
let n_health = match hurt.health { let n_health = match hurt.health {
Some(csdemo::RawValue::F32(v)) => v as u8, Some(csdemo::RawValue::F32(v)) => v as u8,
Some(csdemo::RawValue::I32(v)) => v as u8, Some(csdemo::RawValue::I32(v)) => v as u8,
Some(csdemo::RawValue::U64(v)) => v as u8, Some(csdemo::RawValue::U64(v)) => v as u8,
_ => 0, _ => 0,
}; };
let dmg_dealt = player_life let previous_health = player_life.get(hurt.userid.as_ref().unwrap()).copied().unwrap();
.get(hurt.userid.as_ref().unwrap()) let dmg_dealt = previous_health - n_health;
.copied()
.unwrap_or(100)
- n_health;
player_life.insert(hurt.userid.unwrap(), n_health); player_life.insert(hurt.userid.unwrap(), n_health);
if attacking_player.team == attacked_player.team { if let Some(attacking_player) = player_info.get(&attacker_id) {
return; if attacking_player.xuid == 76561198119236104 {
} println!("Shot {:?} for {}", attacked_player, dmg_dealt);
}
attacker.damage += dmg_dealt as usize; let attacker = player_stats.entry(attacker_id).or_default();
if attacking_player.xuid == attacked_player.xuid {
attacker.self_damage += dmg_dealt as usize;
} else if attacking_player.team == attacked_player.team {
attacker.team_damage += dmg_dealt as usize;
} else {
attacker.damage += dmg_dealt as usize;
}
}
} }

View File

@@ -2,7 +2,7 @@ use analysis::endofgame;
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
#[test] #[test]
fn ancient() { fn nuke() {
let input_bytes = include_bytes!("../../testfiles/nuke.dem"); let input_bytes = include_bytes!("../../testfiles/nuke.dem");
let result = endofgame::parse(input_bytes).unwrap(); let result = endofgame::parse(input_bytes).unwrap();
@@ -39,7 +39,7 @@ fn ancient() {
kills: 15, kills: 15,
deaths: 12, deaths: 12,
damage: 1827, damage: 1827,
team_damage: 0, team_damage: 4,
self_damage: 0, self_damage: 0,
assists: 6, assists: 6,
}, },
@@ -56,7 +56,7 @@ fn ancient() {
kills: 11, kills: 11,
deaths: 16, deaths: 16,
damage: 1394, damage: 1394,
team_damage: 0, team_damage: 13,
self_damage: 0, self_damage: 0,
assists: 5, assists: 5,
}, },
@@ -91,8 +91,10 @@ fn ancient() {
deaths: 17, deaths: 17,
damage: 1148, damage: 1148,
team_damage: 0, team_damage: 0,
self_damage: 0, self_damage: 34,
assists: 2, // TODO
// Leetify says 2, my calculations say 3
assists: 3,
}, },
), ),
( (
@@ -107,8 +109,8 @@ fn ancient() {
kills: 17, kills: 17,
deaths: 16, deaths: 16,
damage: 2143, damage: 2143,
team_damage: 0, team_damage: 109,
self_damage: 0, self_damage: 5,
assists: 7, assists: 7,
}, },
), ),
@@ -124,7 +126,7 @@ fn ancient() {
kills: 7, kills: 7,
deaths: 15, deaths: 15,
damage: 844, damage: 844,
team_damage: 0, team_damage: 100,
self_damage: 0, self_damage: 0,
assists: 4, assists: 4,
}, },
@@ -141,8 +143,8 @@ fn ancient() {
kills: 13, kills: 13,
deaths: 17, deaths: 17,
damage: 1423, damage: 1423,
team_damage: 0, team_damage: 44,
self_damage: 0, self_damage: 4,
assists: 6, assists: 6,
}, },
), ),
@@ -158,9 +160,11 @@ fn ancient() {
kills: 19, kills: 19,
deaths: 15, deaths: 15,
damage: 1512, damage: 1512,
team_damage: 0, team_damage: 31,
self_damage: 0, self_damage: 0,
assists: 3, // TODO
// Leetify says 3, my calc says 4
assists: 4,
}, },
), ),
( (
@@ -175,7 +179,7 @@ fn ancient() {
kills: 14, kills: 14,
deaths: 16, deaths: 16,
damage: 1431, damage: 1431,
team_damage: 0, team_damage: 68,
self_damage: 0, self_damage: 0,
assists: 4, assists: 4,
}, },