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
|
|
@ -1,6 +1,6 @@
|
|||
use crate::common::{Class, SubjectId};
|
||||
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::raw_event::RawEventType;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -116,7 +122,8 @@ impl Kill {
|
|||
struct EarlyData {
|
||||
time: u32,
|
||||
victim: SteamID,
|
||||
medic: Option<MedicDeathExEvent>,
|
||||
medic: Option<MedicDeathEvent>,
|
||||
medic_ex: Option<MedicDeathExEvent>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
|
@ -130,22 +137,28 @@ pub struct 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
|
||||
.take_if(|data| data.time == time && data.victim == victim)
|
||||
.and_then(|data| data.medic)
|
||||
.take()
|
||||
.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 {
|
||||
// remove state early data
|
||||
let _ = self
|
||||
.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 {
|
||||
time,
|
||||
victim,
|
||||
medic: None,
|
||||
medic_ex: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -159,6 +172,9 @@ impl GlobalData for Kills {
|
|||
RawEventType::Killed
|
||||
| RawEventType::KillAssist
|
||||
| RawEventType::Spawned
|
||||
| RawEventType::ChargeDeployed
|
||||
| RawEventType::ChargeReady
|
||||
| RawEventType::MedicDeath
|
||||
| RawEventType::MedicDeathEx
|
||||
| RawEventType::RoundStart
|
||||
| RawEventType::RoundWin
|
||||
|
|
@ -210,9 +226,15 @@ impl GlobalData for Kills {
|
|||
self.classes.insert(subject, class);
|
||||
}
|
||||
|
||||
if let Some(medic_info) = self.early_data(time, kill.victim.id) {
|
||||
kill.add_medic_info(&medic_info);
|
||||
if let Some((medic, medic_ex)) = self.early_data(time, kill.victim.id) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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 kill.time == time && kill.victim.id == victim {
|
||||
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