mirror of
https://codeberg.org/icewind/tf-log-parser.git
synced 2026-11-30 04:40:47 +01:00
more kill info
This commit is contained in:
parent
c8664f9e47
commit
5d1729110b
7 changed files with 196 additions and 99 deletions
|
|
@ -2,7 +2,7 @@ use main_error::MainError;
|
|||
use std::env::args;
|
||||
use std::fs;
|
||||
use tf_log_parser::module::Kills;
|
||||
use tf_log_parser::parse_with_handler;
|
||||
use tf_log_parser::{parse_with_handler, Class};
|
||||
|
||||
fn main() -> Result<(), MainError> {
|
||||
let path = args().nth(1).expect("No path provided");
|
||||
|
|
@ -11,6 +11,9 @@ fn main() -> Result<(), MainError> {
|
|||
let kills = parse_with_handler::<Kills>(&content)?.0;
|
||||
|
||||
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)?);
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -4,19 +4,19 @@ use crate::{Error, Event, Result};
|
|||
|
||||
use crate::parsing::{skip, take_until};
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct RoundWinEvent<'a> {
|
||||
#[event(name = "winner")]
|
||||
pub team: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct RoundLengthEvent {
|
||||
#[event(name = "seconds")]
|
||||
pub length: Option<f32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct LogFileStartedEvent<'a> {
|
||||
pub file: Option<&'a str>,
|
||||
pub game: Option<&'a str>,
|
||||
|
|
@ -39,7 +39,7 @@ impl<'a> Event<'a> for TournamentModeStartedEvent<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct CaptureBlockedEvent<'a> {
|
||||
pub cp: Option<u8>,
|
||||
#[event(name = "cpname")]
|
||||
|
|
@ -103,19 +103,19 @@ impl<'a> Event<'a> for PointCapturedEvent<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct CurrentScoreEvent {
|
||||
pub score: u8,
|
||||
#[event(name = "with")]
|
||||
pub players: u8,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct GameOverEvent<'a> {
|
||||
pub reason: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct FinalScoreEvent {
|
||||
pub score: u8,
|
||||
#[event(name = "with")]
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use crate::event::{parse_field, ParamIter};
|
|||
use crate::raw_event::RawSubject;
|
||||
use crate::{Event, Result};
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct HealedEvent<'a> {
|
||||
#[event(name = "against")]
|
||||
pub target: Option<RawSubject<'a>>,
|
||||
|
|
@ -11,33 +11,34 @@ pub struct HealedEvent<'a> {
|
|||
pub amount: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct ChargeDeployedEvent<'a> {
|
||||
pub medigun: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct ChargeEndedEvent {
|
||||
pub duration: Option<f32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct AdvantageLostEvent {
|
||||
pub time: Option<f32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct FirstHealEvent {
|
||||
pub time: Option<f32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct MedicDeathEvent {
|
||||
#[event(name = "ubercharge")]
|
||||
pub charge: Option<u32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct MedicDeathExEvent {
|
||||
#[event(name = "uberpct")]
|
||||
pub charge_percentage: Option<u8>,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,17 +4,17 @@ use crate::raw_event::{subject_parser, RawSubject};
|
|||
use crate::{Error, Event, Result};
|
||||
use std::net::SocketAddr;
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct ShotFiredEvent<'a> {
|
||||
pub weapon: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct ShotHitEvent<'a> {
|
||||
pub weapon: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct DamageEvent<'a> {
|
||||
#[event(name = "against")]
|
||||
#[event(default)]
|
||||
|
|
@ -25,18 +25,20 @@ pub struct DamageEvent<'a> {
|
|||
pub weapon: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct KillEvent<'a> {
|
||||
#[event(unnamed)]
|
||||
#[event(subject)]
|
||||
pub target: RawSubject<'a>,
|
||||
#[event(name = "with")]
|
||||
pub weapon: &'a str,
|
||||
#[event(name = "customkill")]
|
||||
pub custom_kill: Option<&'a str>,
|
||||
pub attacker_position: Option<(i32, i32, i32)>,
|
||||
pub victim_position: Option<(i32, i32, i32)>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct KillAssistEvent<'a> {
|
||||
#[event(name = "against")]
|
||||
pub target: RawSubject<'a>,
|
||||
|
|
@ -44,75 +46,75 @@ pub struct KillAssistEvent<'a> {
|
|||
pub victim_position: Option<(i32, i32, i32)>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct SpawnEvent {
|
||||
#[event(name = "as")]
|
||||
pub class: Option<Class>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct RoleChangeEvent {
|
||||
#[event(name = "to")]
|
||||
pub class: Option<Class>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct ConnectedEvent {
|
||||
#[event(name = "address")]
|
||||
pub address: SocketAddr,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct JoinedTeamEvent {
|
||||
pub team: Team,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct CommittedSuicideEvent<'a> {
|
||||
#[event(name = "with")]
|
||||
pub weapon: &'a str,
|
||||
pub attacker_position: Option<(i32, i32, i32)>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct PickedUpEvent<'a> {
|
||||
pub item: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct DominationEvent<'a> {
|
||||
pub against: RawSubject<'a>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct RevengeEvent<'a> {
|
||||
pub against: RawSubject<'a>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct DisconnectEvent<'a> {
|
||||
pub reason: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct BuiltObjectEvent<'a> {
|
||||
pub object: Option<&'a str>,
|
||||
pub position: Option<(i32, i32, i32)>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct BuiltCarryEvent<'a> {
|
||||
pub object: Option<&'a str>,
|
||||
pub position: Option<(i32, i32, i32)>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct DropObjectEvent<'a> {
|
||||
pub object: Option<&'a str>,
|
||||
pub position: Option<(i32, i32, i32)>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct KilledObjectEvent<'a> {
|
||||
pub object: Option<&'a str>,
|
||||
pub weapon: Option<&'a str>,
|
||||
|
|
@ -121,14 +123,14 @@ pub struct KilledObjectEvent<'a> {
|
|||
pub attacker_position: Option<(i32, i32, i32)>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct ObjectDetonatedEvent<'a> {
|
||||
pub object: Option<&'a str>,
|
||||
#[event(name = "attacker_position")]
|
||||
pub position: Option<(i32, i32, i32)>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct ExtinguishedEvent<'a> {
|
||||
pub against: RawSubject<'a>,
|
||||
pub with: &'a str,
|
||||
|
|
@ -136,13 +138,13 @@ pub struct ExtinguishedEvent<'a> {
|
|||
pub victim_position: Option<(i32, i32, i32)>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct SayEvent<'a> {
|
||||
#[event(unnamed)]
|
||||
pub text: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Debug, Event)]
|
||||
#[derive(Debug, Event, Clone)]
|
||||
pub struct SayTeamEvent<'a> {
|
||||
#[event(unnamed)]
|
||||
pub text: &'a str,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
pub use crate::common::{SteamId3, SubjectData, SubjectError, SubjectId};
|
||||
pub use crate::common::{Class, SteamId3, SubjectData, SubjectError, SubjectId};
|
||||
pub use crate::module::EventHandler;
|
||||
use crate::module::{
|
||||
ChatMessages, ClassStatsHandler, HealSpread, MedicStatsBuilder, PlayerHandler,
|
||||
|
|
|
|||
|
|
@ -1,86 +1,160 @@
|
|||
use crate::common::SubjectId;
|
||||
use crate::common::{Class, SubjectId};
|
||||
use crate::data::Weapon;
|
||||
use crate::event::{GameEvent, KillAssistEvent, KillEvent};
|
||||
use crate::event::{GameEvent, KillAssistEvent, KillEvent, MedicDeathExEvent};
|
||||
use crate::module::GlobalData;
|
||||
use crate::raw_event::RawEventType;
|
||||
use crate::{EventMeta, SubjectMap};
|
||||
use ahash::AHashMap;
|
||||
use serde::Serialize;
|
||||
use steamid_ng::SteamID;
|
||||
|
||||
#[derive(PartialEq)]
|
||||
pub struct RawKill {
|
||||
pub time: u32,
|
||||
pub killer: SubjectId,
|
||||
pub assister: Option<SubjectId>,
|
||||
pub victim: SubjectId,
|
||||
pub weapon: Weapon,
|
||||
pub attacker_position: Option<(i32, i32, i32)>,
|
||||
pub assister_position: Option<(i32, i32, i32)>,
|
||||
pub victim_position: Option<(i32, i32, i32)>,
|
||||
#[derive(Serialize, PartialEq)]
|
||||
pub struct Participant {
|
||||
#[serde(with = "super::serde_steamid")]
|
||||
pub id: SteamID,
|
||||
pub class: Class,
|
||||
}
|
||||
|
||||
impl RawKill {
|
||||
fn from_event(time: u32, subject: SubjectId, event: &KillEvent) -> Option<Self> {
|
||||
Some(RawKill {
|
||||
time,
|
||||
killer: subject,
|
||||
assister: None,
|
||||
victim: event.target.id().ok()?,
|
||||
weapon: Weapon::from(event.weapon),
|
||||
attacker_position: event.attacker_position,
|
||||
assister_position: None,
|
||||
victim_position: event.victim_position,
|
||||
})
|
||||
}
|
||||
#[derive(Serialize, PartialEq)]
|
||||
pub struct Position {
|
||||
pub x: i32,
|
||||
pub y: i32,
|
||||
pub z: i32,
|
||||
}
|
||||
|
||||
fn add_assist(&mut self, subject: SubjectId, event: &KillAssistEvent) {
|
||||
self.assister = Some(subject);
|
||||
self.assister_position = event.assister_position;
|
||||
impl From<(i32, i32, i32)> for Position {
|
||||
fn from((x, y, z): (i32, i32, i32)) -> Self {
|
||||
Position { x, y, z }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, PartialEq)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum KillKind {
|
||||
Normal,
|
||||
Backstab,
|
||||
Headshot,
|
||||
DeathRinger,
|
||||
}
|
||||
|
||||
impl KillKind {
|
||||
pub fn new(event: &KillEvent) -> Self {
|
||||
match event.custom_kill {
|
||||
Some("backstab") => Self::Backstab,
|
||||
Some("headshot") => Self::Headshot,
|
||||
Some("feign_death") => Self::DeathRinger,
|
||||
_ => Self::Normal,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, PartialEq)]
|
||||
pub struct Kill {
|
||||
pub time: u32,
|
||||
#[serde(with = "super::serde_steamid")]
|
||||
pub killer: SteamID,
|
||||
#[serde(with = "super::serde_steamid::opt")]
|
||||
pub assister: Option<SteamID>,
|
||||
#[serde(with = "super::serde_steamid")]
|
||||
pub victim: SteamID,
|
||||
pub killer: Participant,
|
||||
pub assister: Option<Participant>,
|
||||
pub victim: Participant,
|
||||
pub charge: Option<u8>,
|
||||
pub weapon: Weapon,
|
||||
pub attacker_position: Option<(i32, i32, i32)>,
|
||||
pub assister_position: Option<(i32, i32, i32)>,
|
||||
pub victim_position: Option<(i32, i32, i32)>,
|
||||
pub kind: KillKind,
|
||||
pub attacker_position: Option<Position>,
|
||||
pub assister_position: Option<Position>,
|
||||
pub victim_position: Option<Position>,
|
||||
}
|
||||
|
||||
impl Kill {
|
||||
pub fn from_raw(raw: RawKill, subjects: &SubjectMap) -> Option<Kill> {
|
||||
let killer = subjects.steam_id(raw.killer)?;
|
||||
let assister = raw.assister.and_then(|subject| subjects.steam_id(subject));
|
||||
let victim = subjects.steam_id(raw.victim)?;
|
||||
|
||||
fn from_event(
|
||||
time: u32,
|
||||
subject: SubjectId,
|
||||
event: &KillEvent,
|
||||
classes: &AHashMap<SubjectId, Class>,
|
||||
) -> Option<Self> {
|
||||
let victim = event.target.id().ok()?;
|
||||
Some(Kill {
|
||||
time: raw.time,
|
||||
killer,
|
||||
assister,
|
||||
victim,
|
||||
weapon: raw.weapon,
|
||||
attacker_position: raw.attacker_position,
|
||||
assister_position: raw.assister_position,
|
||||
victim_position: raw.victim_position,
|
||||
time,
|
||||
killer: Participant {
|
||||
id: subject.steam_id()?,
|
||||
class: classes.get(&subject).copied().unwrap_or_default(),
|
||||
},
|
||||
assister: None,
|
||||
victim: Participant {
|
||||
id: victim.steam_id()?,
|
||||
class: classes.get(&victim).copied().unwrap_or_default(),
|
||||
},
|
||||
charge: None,
|
||||
weapon: Weapon::from(event.weapon),
|
||||
kind: KillKind::new(event),
|
||||
attacker_position: event.attacker_position.map(Position::from),
|
||||
assister_position: None,
|
||||
victim_position: event.victim_position.map(Position::from),
|
||||
})
|
||||
}
|
||||
|
||||
fn add_assist(
|
||||
&mut self,
|
||||
subject: SubjectId,
|
||||
event: &KillAssistEvent,
|
||||
classes: &AHashMap<SubjectId, Class>,
|
||||
) {
|
||||
if let Some(steam_id) = subject.steam_id() {
|
||||
self.assister = Some(Participant {
|
||||
id: steam_id,
|
||||
class: classes.get(&subject).copied().unwrap_or_default(),
|
||||
});
|
||||
self.assister_position = event.assister_position.map(Position::from);
|
||||
}
|
||||
}
|
||||
|
||||
fn add_medic_info(&mut self, event: &MedicDeathExEvent) {
|
||||
self.charge = dbg!(event.charge_percentage);
|
||||
}
|
||||
}
|
||||
|
||||
struct EarlyData {
|
||||
time: u32,
|
||||
victim: SteamID,
|
||||
medic: Option<MedicDeathExEvent>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Kills(Vec<RawKill>);
|
||||
pub struct Kills {
|
||||
classes: AHashMap<SubjectId, Class>,
|
||||
kills: Vec<Kill>,
|
||||
early_data: Option<EarlyData>,
|
||||
}
|
||||
|
||||
impl Kills {
|
||||
fn early_data(&mut self, time: u32, victim: SteamID) -> Option<MedicDeathExEvent> {
|
||||
self.early_data
|
||||
.take_if(|data| data.time == time && data.victim == victim)
|
||||
.and_then(|data| data.medic)
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
self.early_data.get_or_insert(EarlyData {
|
||||
time,
|
||||
victim,
|
||||
medic: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl GlobalData for Kills {
|
||||
type Output = Vec<Kill>;
|
||||
|
||||
fn does_handle(ty: RawEventType) -> bool {
|
||||
matches!(ty, RawEventType::Killed | RawEventType::KillAssist)
|
||||
matches!(
|
||||
ty,
|
||||
RawEventType::Killed
|
||||
| RawEventType::KillAssist
|
||||
| RawEventType::Spawned
|
||||
| RawEventType::MedicDeathEx
|
||||
)
|
||||
}
|
||||
|
||||
fn handle_event(&mut self, meta: &EventMeta, subject: SubjectId, event: &GameEvent) {
|
||||
|
|
@ -89,27 +163,44 @@ impl GlobalData for Kills {
|
|||
return;
|
||||
}
|
||||
match event {
|
||||
GameEvent::Spawned(event) => {
|
||||
if let Some(class) = event.class {
|
||||
self.classes.insert(subject, class);
|
||||
}
|
||||
}
|
||||
GameEvent::Killed(event) => {
|
||||
if let Some(kill) = RawKill::from_event(time, subject, event) {
|
||||
self.0.push(kill);
|
||||
if let Some(mut kill) = Kill::from_event(time, subject, event, &self.classes) {
|
||||
if let Some(medic_info) = self.early_data(time, kill.victim.id) {
|
||||
kill.add_medic_info(&medic_info);
|
||||
}
|
||||
self.kills.push(kill);
|
||||
}
|
||||
}
|
||||
GameEvent::KillAssist(event) => {
|
||||
if let Some(kill) = self.0.last_mut() {
|
||||
if let Some(kill) = self.kills.last_mut() {
|
||||
debug_assert_eq!(kill.time, time);
|
||||
debug_assert_eq!(kill.victim, event.target.id().unwrap());
|
||||
debug_assert_eq!(
|
||||
kill.victim.id,
|
||||
event.target.id().unwrap().steam_id().unwrap()
|
||||
);
|
||||
|
||||
kill.add_assist(subject, event);
|
||||
kill.add_assist(subject, event, &self.classes);
|
||||
}
|
||||
}
|
||||
GameEvent::MedicDeathEx(event) => {
|
||||
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);
|
||||
} else {
|
||||
self.early_data_mut(time, victim).medic = Some(event.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn finish(self, subjects: &SubjectMap) -> Self::Output {
|
||||
self.0
|
||||
.into_iter()
|
||||
.filter_map(|raw| Kill::from_raw(raw, subjects))
|
||||
.collect()
|
||||
fn finish(self, _subjects: &SubjectMap) -> Self::Output {
|
||||
self.kills
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ fn test_parse_date() {
|
|||
);
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub enum RawSubject<'a> {
|
||||
Player(&'a str),
|
||||
Team(Team),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue