mirror of
https://codeberg.org/icewind/tf-log-parser.git
synced 2026-11-30 04:40:47 +01:00
fix medic data
This commit is contained in:
parent
f05433724c
commit
8aa8ae6e3f
2 changed files with 46 additions and 14 deletions
|
|
@ -2,7 +2,7 @@ use main_error::MainError;
|
||||||
use std::env::args;
|
use std::env::args;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use tf_log_parser::module::Kills;
|
use tf_log_parser::module::Kills;
|
||||||
use tf_log_parser::{parse_with_handler, Class};
|
use tf_log_parser::parse_with_handler;
|
||||||
|
|
||||||
fn main() -> Result<(), MainError> {
|
fn main() -> Result<(), MainError> {
|
||||||
let path = args().nth(1).expect("No path provided");
|
let path = args().nth(1).expect("No path provided");
|
||||||
|
|
@ -11,9 +11,6 @@ fn main() -> Result<(), MainError> {
|
||||||
let kills = parse_with_handler::<Kills>(&content)?.0;
|
let kills = parse_with_handler::<Kills>(&content)?.0;
|
||||||
|
|
||||||
for kill in kills {
|
for kill in kills {
|
||||||
if kill.victim.class == Class::Medic && kill.charge.is_none() {
|
|
||||||
panic!("medic death without charge");
|
|
||||||
}
|
|
||||||
println!("{}", serde_json::to_string(&kill)?);
|
println!("{}", serde_json::to_string(&kill)?);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::common::{Class, SubjectId};
|
use crate::common::{Class, SubjectId};
|
||||||
use crate::data::{Position, Weapon};
|
use crate::data::{Position, Weapon};
|
||||||
use crate::event::{GameEvent, KillAssistEvent, KillEvent, MedicDeathExEvent};
|
use crate::event::{GameEvent, KillAssistEvent, KillEvent, MedicDeathEvent, MedicDeathExEvent};
|
||||||
use crate::module::GlobalData;
|
use crate::module::GlobalData;
|
||||||
use crate::raw_event::RawEventType;
|
use crate::raw_event::RawEventType;
|
||||||
use crate::{EventMeta, SubjectMap};
|
use crate::{EventMeta, SubjectMap};
|
||||||
|
|
@ -108,7 +108,13 @@ impl Kill {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_medic_info(&mut self, event: &MedicDeathExEvent) {
|
fn add_medic_info(&mut self, event: &MedicDeathEvent) {
|
||||||
|
if event.charge == Some(1) {
|
||||||
|
self.charge = Some(100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_medic_info_ex(&mut self, event: &MedicDeathExEvent) {
|
||||||
self.charge = event.charge_percentage;
|
self.charge = event.charge_percentage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -116,7 +122,8 @@ impl Kill {
|
||||||
struct EarlyData {
|
struct EarlyData {
|
||||||
time: u32,
|
time: u32,
|
||||||
victim: SteamID,
|
victim: SteamID,
|
||||||
medic: Option<MedicDeathExEvent>,
|
medic: Option<MedicDeathEvent>,
|
||||||
|
medic_ex: Option<MedicDeathExEvent>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
@ -130,22 +137,28 @@ pub struct Kills {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Kills {
|
impl Kills {
|
||||||
fn early_data(&mut self, time: u32, victim: SteamID) -> Option<MedicDeathExEvent> {
|
fn early_data(
|
||||||
|
&mut self,
|
||||||
|
time: u32,
|
||||||
|
victim: SteamID,
|
||||||
|
) -> Option<(Option<MedicDeathEvent>, Option<MedicDeathExEvent>)> {
|
||||||
self.early_data
|
self.early_data
|
||||||
.take_if(|data| data.time == time && data.victim == victim)
|
.take()
|
||||||
.and_then(|data| data.medic)
|
.filter(|data| data.time == time && data.victim == victim)
|
||||||
|
.map(|data| (data.medic, data.medic_ex))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn early_data_mut(&mut self, time: u32, victim: SteamID) -> &mut EarlyData {
|
fn early_data_mut(&mut self, time: u32, victim: SteamID) -> &mut EarlyData {
|
||||||
// remove state early data
|
// remove state early data
|
||||||
let _ = self
|
let _ = self
|
||||||
.early_data
|
.early_data
|
||||||
.take_if(|data| data.time == time && data.victim == victim);
|
.take_if(|data| !(data.time == time && data.victim == victim));
|
||||||
|
|
||||||
self.early_data.get_or_insert(EarlyData {
|
self.early_data.get_or_insert(EarlyData {
|
||||||
time,
|
time,
|
||||||
victim,
|
victim,
|
||||||
medic: None,
|
medic: None,
|
||||||
|
medic_ex: None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -159,6 +172,9 @@ impl GlobalData for Kills {
|
||||||
RawEventType::Killed
|
RawEventType::Killed
|
||||||
| RawEventType::KillAssist
|
| RawEventType::KillAssist
|
||||||
| RawEventType::Spawned
|
| RawEventType::Spawned
|
||||||
|
| RawEventType::ChargeDeployed
|
||||||
|
| RawEventType::ChargeReady
|
||||||
|
| RawEventType::MedicDeath
|
||||||
| RawEventType::MedicDeathEx
|
| RawEventType::MedicDeathEx
|
||||||
| RawEventType::RoundStart
|
| RawEventType::RoundStart
|
||||||
| RawEventType::RoundWin
|
| RawEventType::RoundWin
|
||||||
|
|
@ -210,9 +226,15 @@ impl GlobalData for Kills {
|
||||||
self.classes.insert(subject, class);
|
self.classes.insert(subject, class);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(medic_info) = self.early_data(time, kill.victim.id) {
|
if let Some((medic, medic_ex)) = self.early_data(time, kill.victim.id) {
|
||||||
kill.add_medic_info(&medic_info);
|
if let Some(medic) = medic {
|
||||||
|
kill.add_medic_info(&medic);
|
||||||
|
}
|
||||||
|
if let Some(medic_ex) = medic_ex {
|
||||||
|
kill.add_medic_info_ex(&medic_ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.kills.push(kill);
|
self.kills.push(kill);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -226,7 +248,11 @@ impl GlobalData for Kills {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GameEvent::MedicDeathEx(event) if self.active => {
|
GameEvent::ChargeReady | GameEvent::ChargeDeployed(_) => {
|
||||||
|
self.classes.insert(subject, Class::Medic);
|
||||||
|
}
|
||||||
|
GameEvent::MedicDeath(event) if self.active => {
|
||||||
|
self.classes.insert(subject, Class::Medic);
|
||||||
if let (Some(kill), Some(victim)) = (self.kills.last_mut(), subject.steam_id()) {
|
if let (Some(kill), Some(victim)) = (self.kills.last_mut(), subject.steam_id()) {
|
||||||
if kill.time == time && kill.victim.id == victim {
|
if kill.time == time && kill.victim.id == victim {
|
||||||
kill.add_medic_info(event);
|
kill.add_medic_info(event);
|
||||||
|
|
@ -235,6 +261,15 @@ impl GlobalData for Kills {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
GameEvent::MedicDeathEx(event) if self.active => {
|
||||||
|
if let (Some(kill), Some(victim)) = (self.kills.last_mut(), subject.steam_id()) {
|
||||||
|
if kill.time == time && kill.victim.id == victim {
|
||||||
|
kill.add_medic_info_ex(event);
|
||||||
|
} else {
|
||||||
|
self.early_data_mut(time, victim).medic_ex = Some(event.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue