Add support for team kill tracking in the analysis

This commit is contained in:
Lol3rrr
2024-09-26 16:22:52 +02:00
parent d1e1caee92
commit 803c8e28b9
2 changed files with 27 additions and 12 deletions

View File

@@ -18,9 +18,10 @@ pub struct PlayerStats {
pub kills: usize,
pub deaths: usize,
pub damage: usize,
pub assists: usize,
pub team_kills: usize,
pub team_damage: usize,
pub self_damage: usize,
pub assists: usize,
}
pub fn parse(buf: &[u8]) -> Result<EndOfGame, ()> {
@@ -116,7 +117,7 @@ fn player_death(
Some(a) => a,
None => {
return;
},
}
};
player_died.deaths += 1;
@@ -124,8 +125,13 @@ fn player_death(
let attacker_player = player_info
.get(&attacker_id)
.expect(&format!("Attacker-ID: {:?}", attacker_id));
if attacker_player.team == player_died_player.team {
// return;
if attacker_player.xuid == player_died_player.xuid {
// TODO
// Player committed Suicide
// How to handle?
} else if attacker_player.team == player_died_player.team {
let attacker = player_stats.entry(attacker_id).or_default();
attacker.team_kills += 1;
} else {
let attacker = player_stats.entry(attacker_id).or_default();
attacker.kills += 1;
@@ -154,14 +160,14 @@ fn player_hurt(
Some(a) => a,
None => {
return;
},
}
};
let attacker_id = match hurt.attacker {
Some(aid) => aid,
None => {
return;
},
}
};
let n_health = match hurt.health {
@@ -170,16 +176,15 @@ fn player_hurt(
Some(csdemo::RawValue::U64(v)) => v as u8,
_ => 0,
};
let previous_health = player_life.get(hurt.userid.as_ref().unwrap()).copied().unwrap();
let previous_health = player_life
.get(hurt.userid.as_ref().unwrap())
.copied()
.unwrap();
let dmg_dealt = previous_health - n_health;
player_life.insert(hurt.userid.unwrap(), n_health);
if let Some(attacking_player) = player_info.get(&attacker_id) {
if attacking_player.xuid == 76561198119236104 {
println!("Shot {:?} for {}", attacked_player, dmg_dealt);
}
let attacker = player_stats.entry(attacker_id).or_default();
if attacking_player.xuid == attacked_player.xuid {

View File

@@ -22,6 +22,7 @@ fn nuke() {
kills: 28,
deaths: 11,
damage: 2504,
team_kills: 0,
team_damage: 0,
self_damage: 0,
assists: 4,
@@ -39,6 +40,7 @@ fn nuke() {
kills: 15,
deaths: 12,
damage: 1827,
team_kills: 0,
team_damage: 4,
self_damage: 0,
assists: 6,
@@ -56,6 +58,7 @@ fn nuke() {
kills: 11,
deaths: 16,
damage: 1394,
team_kills: 0,
team_damage: 13,
self_damage: 0,
assists: 5,
@@ -73,6 +76,7 @@ fn nuke() {
kills: 11,
deaths: 15,
damage: 1331,
team_kills: 0,
team_damage: 0,
self_damage: 0,
assists: 3,
@@ -90,6 +94,7 @@ fn nuke() {
kills: 9,
deaths: 17,
damage: 1148,
team_kills: 0,
team_damage: 0,
self_damage: 34,
// TODO
@@ -109,6 +114,7 @@ fn nuke() {
kills: 17,
deaths: 16,
damage: 2143,
team_kills: 1,
team_damage: 109,
self_damage: 5,
assists: 7,
@@ -126,6 +132,7 @@ fn nuke() {
kills: 7,
deaths: 15,
damage: 844,
team_kills: 1,
team_damage: 100,
self_damage: 0,
assists: 4,
@@ -143,6 +150,7 @@ fn nuke() {
kills: 13,
deaths: 17,
damage: 1423,
team_kills: 0,
team_damage: 44,
self_damage: 4,
assists: 6,
@@ -160,6 +168,7 @@ fn nuke() {
kills: 19,
deaths: 15,
damage: 1512,
team_kills: 0,
team_damage: 31,
self_damage: 0,
// TODO
@@ -179,6 +188,7 @@ fn nuke() {
kills: 14,
deaths: 16,
damage: 1431,
team_kills: 1,
team_damage: 68,
self_damage: 0,
assists: 4,