use prost::bytes::Buf;
use prost::Message;
use crate::error::Error;
use crate::result::Result;
impl BattleResults {
pub fn parse(buffer: impl Buf) -> Result<Self> {
Self::decode(buffer).map_err(Error::DecodeFailed)
}
}
#[derive(Message)]
pub struct BattleResults {
#[prost(int64, tag = "2")]
pub timestamp: i64,
#[prost(message, repeated, tag = "201")]
pub players: Vec<Player>,
#[prost(message, repeated, tag = "301")]
pub player_results: Vec<PlayerResults>,
}
#[derive(Message)]
pub struct Player {
#[prost(uint32, tag = "1")]
pub account_id: u32,
#[prost(message, required, tag = "2")]
pub info: PlayerInfo,
}
#[derive(Message)]
pub struct PlayerInfo {
#[prost(string, tag = "1")]
pub nickname: String,
#[prost(uint32, optional, tag = "2")]
pub platoon_id: Option<u32>,
#[prost(enumeration = "TeamNumber", tag = "3")]
pub team_number: i32,
#[prost(string, optional, tag = "5")]
pub clan_tag: Option<String>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, prost::Enumeration)]
#[repr(i32)]
pub enum TeamNumber {
One = 1,
Two = 2,
}
#[derive(Message)]
pub struct PlayerResults {
#[prost(uint32, tag = "1")]
pub result_id: u32,
#[prost(message, required, tag = "2")]
pub info: PlayerResultsInfo,
}
#[derive(Message)]
pub struct PlayerResultsInfo {
#[prost(uint32, tag = "2")]
pub credits: u32,
#[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,
#[prost(uint32, tag = "17")]
pub n_enemies_damaged: u32,
#[prost(uint32, tag = "18")]
pub n_enemies_destroyed: u32,
#[prost(uint32, tag = "32")]
pub victory_points_1: u32,
#[prost(uint32, tag = "33")]
pub victory_points_2: u32,
#[prost(uint32, tag = "101")]
pub account_id: u32,
#[prost(uint32, tag = "103")]
pub tank_id: u32,
#[prost(float, optional, tag = "107")]
pub mm_rating: Option<f32>,
#[prost(uint32, tag = "117")]
pub damage_blocked: u32,
}
impl PlayerResultsInfo {
pub fn display_rating(&self) -> Option<u32> {
self.mm_rating
.map(|mm_rating| (mm_rating * 10.0 + 3000.0) as u32)
}
}