diff --git a/src/models/battle_results.rs b/src/models/battle_results.rs index de533dd..34c7850 100644 --- a/src/models/battle_results.rs +++ b/src/models/battle_results.rs @@ -23,6 +23,10 @@ pub struct BattleResults { /// Players in the battle. #[prost(message, repeated, tag = "201")] pub players: Vec, + + /// Player's results. + #[prost(message, repeated, tag = "301")] + pub player_results: Vec, } /// Battle player. @@ -61,3 +65,81 @@ pub enum TeamNumber { One = 1, Two = 2, } + +/// Player's battle results. +#[derive(Message)] +pub struct PlayerResults { + /// Looks like some sort of sequential result ID. They reference each other, + /// but I haven't figured this out yet. + #[prost(uint32, tag = "1")] + pub result_id: u32, + + /// Extended player's results information. + #[prost(message, required, tag = "2")] + pub info: PlayerResultsInfo, +} + +/// Extended player's results information. +#[derive(Message)] +pub struct PlayerResultsInfo { + /// Base XP (the total without multipliers). + #[prost(uint32, tag = "3")] + pub base_xp: u32, + + #[prost(uint32, tag = "4")] + pub n_shots: u32, + + #[prost(uint32, tag = "5")] + pub n_hits_dealt: u32, + + #[prost(uint32, tag = "7")] + pub n_penetrations_dealt: u32, + + #[prost(uint32, tag = "8")] + pub damage_dealt: u32, + + #[prost(uint32, tag = "9")] + pub damage_assisted_1: u32, + + #[prost(uint32, tag = "10")] + pub damage_assisted_2: u32, + + #[prost(uint32, tag = "12")] + pub n_hits_received: u32, + + #[prost(uint32, tag = "13")] + pub n_non_penetrating_hits_received: u32, + + #[prost(uint32, tag = "15")] + pub n_penetrations_received: u32, + + /// TODO: distinguish earned vs seized. + #[prost(uint32, tag = "32")] + pub victory_points_1: u32, + + /// TODO: distinguish earned vs seized. + #[prost(uint32, tag = "33")] + pub victory_points_2: u32, + + /// Player's account ID. + #[prost(uint32, tag = "101")] + pub account_id: u32, + + /// Rating for the Rating Battles. + /// + /// Note, that this is **not** the game client's displayed rating. + /// This field matches the `mm_rating` as returned by the Wargaming.net API. + #[prost(float, optional, tag = "107")] + pub mm_rating: Option, + + #[prost(uint32, tag = "117")] + pub damage_blocked: u32, +} + +impl PlayerResultsInfo { + /// Returns displayed rating as per the game client. + pub fn display_rating(&self) -> Option { + self.mm_rating + .map(|mm_rating| (mm_rating * 10.0 + 3000.0) as u32) + } +} diff --git a/tests/battle_results.rs b/tests/battle_results.rs index c45d85d..0723f51 100644 --- a/tests/battle_results.rs +++ b/tests/battle_results.rs @@ -6,8 +6,8 @@ use wotbreplay_parser::Replay; #[test] fn battle_results_ok() -> Result<()> { - let mut replay = Replay::open(File::open("tests/replays/battle_results_ok.wotbreplay")?)?; - let battle_results = replay.read_battle_results()?; + let battle_results = Replay::open(File::open("tests/replays/battle_results_ok.wotbreplay")?)? + .read_battle_results()?; assert_eq!(battle_results.timestamp, 1670018359); assert_eq!(battle_results.players.len(), 14); @@ -23,3 +23,54 @@ fn battle_results_ok() -> Result<()> { Ok(()) } + +#[test] +fn player_results_ok() -> Result<()> { + let battle_results = Replay::open(File::open("tests/replays/player_results_ok.wotbreplay")?)? + .read_battle_results()?; + + let snak_the_ripper_info = &battle_results.player_results[3].info; + assert_eq!(snak_the_ripper_info.base_xp, 929); + assert_eq!(snak_the_ripper_info.damage_dealt, 2584); + assert_eq!(snak_the_ripper_info.damage_assisted_1, 37); + assert_eq!(snak_the_ripper_info.account_id, 566225799); + assert_eq!(snak_the_ripper_info.display_rating(), Some(4070)); + assert_eq!(snak_the_ripper_info.n_shots, 6); + assert_eq!(snak_the_ripper_info.n_hits_dealt, 5); + assert_eq!(snak_the_ripper_info.n_penetrations_dealt, 5); + + let zeekrab_info = &battle_results.player_results[10].info; + assert_eq!(zeekrab_info.base_xp, 701); + assert_eq!(zeekrab_info.damage_dealt, 1438); + assert_eq!(zeekrab_info.damage_assisted_2, 31); + assert_eq!(zeekrab_info.damage_blocked, 190); + assert_eq!(zeekrab_info.account_id, 594778041); + assert_eq!(zeekrab_info.display_rating(), Some(4277)); + assert_eq!(zeekrab_info.n_shots, 5); + assert_eq!(zeekrab_info.n_hits_dealt, 5); + assert_eq!(zeekrab_info.n_penetrations_dealt, 5); + assert_eq!(zeekrab_info.n_hits_received, 3); + assert_eq!(zeekrab_info.n_penetrations_received, 3); + assert_eq!(zeekrab_info.n_non_penetrating_hits_received, 0); + assert_eq!(zeekrab_info.victory_points_1, 40); + assert_eq!(zeekrab_info.victory_points_2, 40); + + let balls_soup_info = &battle_results.player_results[8].info; + assert_eq!(balls_soup_info.damage_dealt, 2064); + assert_eq!(balls_soup_info.display_rating(), None); + assert_eq!(balls_soup_info.n_shots, 9); + assert_eq!(balls_soup_info.n_hits_dealt, 8); + assert_eq!(balls_soup_info.n_penetrations_dealt, 8); + assert_eq!(balls_soup_info.n_hits_received, 6); + assert_eq!(balls_soup_info.n_penetrations_received, 4); + assert_eq!(balls_soup_info.n_non_penetrating_hits_received, 2); + + let ceaser_info = &battle_results.player_results[0].info; + assert_eq!(ceaser_info.damage_dealt, 919); + assert_eq!(ceaser_info.display_rating(), Some(4439)); + assert_eq!(ceaser_info.n_shots, 9); + assert_eq!(ceaser_info.n_hits_dealt, 6); + assert_eq!(ceaser_info.n_penetrations_dealt, 5); + + Ok(()) +} diff --git a/tests/replays/player_results_ok.wotbreplay b/tests/replays/player_results_ok.wotbreplay new file mode 100644 index 0000000..9dd1367 Binary files /dev/null and b/tests/replays/player_results_ok.wotbreplay differ