mirror of
https://codeberg.org/icewind/tf-log-parser.git
synced 2026-11-30 04:40:47 +01:00
use weapon to try and correct missing class switch
This commit is contained in:
parent
b38b5773cb
commit
f05433724c
2 changed files with 340 additions and 4 deletions
|
|
@ -1,8 +1,10 @@
|
|||
use serde::Serialize;
|
||||
use strum::{AsRefStr, EnumString};
|
||||
|
||||
use crate::Class;
|
||||
|
||||
#[derive(EnumString, AsRefStr, Debug, PartialEq)]
|
||||
#[strum(serialize_all = "lowercase")]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
pub enum Weapon {
|
||||
Letranger,
|
||||
TfProjectilePipeRemote,
|
||||
|
|
@ -66,11 +68,13 @@ pub enum Weapon {
|
|||
Samrevolver,
|
||||
Degreaser,
|
||||
PrinnyMachete,
|
||||
#[strum(serialize = "scorch_shot", serialize = "scorchshot")]
|
||||
ScorchShot,
|
||||
Fists,
|
||||
FrontierJustice,
|
||||
NecroSmasher,
|
||||
UllapoolCaber,
|
||||
UllapoolCaberExplosion,
|
||||
Axtinguisher,
|
||||
HamShank,
|
||||
WrapAssassin,
|
||||
|
|
@ -84,6 +88,7 @@ pub enum Weapon {
|
|||
Wrench,
|
||||
NonnonviolentProtest,
|
||||
CompoundBow,
|
||||
TfProjectileArrowFire,
|
||||
FreedomStaff,
|
||||
Sword,
|
||||
LooseCannon,
|
||||
|
|
@ -101,6 +106,7 @@ pub enum Weapon {
|
|||
EurekaEffect,
|
||||
SouthernHospitality,
|
||||
SpyCicle,
|
||||
#[strum(serialize = "rescue_ranger", serialize = "the_rescue_ranger")]
|
||||
RescueRanger,
|
||||
Atomizer,
|
||||
SteelFists,
|
||||
|
|
@ -120,6 +126,7 @@ pub enum Weapon {
|
|||
Bat,
|
||||
BazaarBargain,
|
||||
TheClassic,
|
||||
#[strum(serialize = "shortstop", serialize = "short_stop")]
|
||||
Shortstop,
|
||||
Bonesaw,
|
||||
Fireaxe,
|
||||
|
|
@ -182,6 +189,39 @@ pub enum Weapon {
|
|||
Rocketpack,
|
||||
LaserPointer,
|
||||
Quickfix,
|
||||
DeflectArrow,
|
||||
DeflectPromode,
|
||||
DeflectSticky,
|
||||
DeflectRocket,
|
||||
DeflectFlare,
|
||||
DeflectHuntsmanFlyingburn,
|
||||
RescueRangerReflect,
|
||||
LooseCannonReflect,
|
||||
LooseCannonImpact,
|
||||
TauntSoldier,
|
||||
TauntScout,
|
||||
TauntMedic,
|
||||
TauntHeavy,
|
||||
TauntEngineer,
|
||||
TauntDemoman,
|
||||
TauntSpy,
|
||||
TauntSniper,
|
||||
TauntPyro,
|
||||
ObjMinisentry,
|
||||
ObjSentrygun,
|
||||
WranglerKill,
|
||||
GigerCounter,
|
||||
TfProjectileArrow,
|
||||
Ball,
|
||||
Sapper,
|
||||
PdaSpy,
|
||||
Demoshield,
|
||||
Mantreads,
|
||||
HolyMackerel,
|
||||
SplendidScreen,
|
||||
TideTurner,
|
||||
PlayerPenetration,
|
||||
DragonsFuryBonus,
|
||||
#[strum(default)]
|
||||
Other(String),
|
||||
}
|
||||
|
|
@ -193,6 +233,259 @@ impl Weapon {
|
|||
_ => self.as_ref(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get all classes that can equip a weapon.
|
||||
///
|
||||
/// If not known, all classes will be returned
|
||||
pub fn classes(&self) -> &[Class] {
|
||||
match self {
|
||||
Weapon::Letranger
|
||||
| Weapon::Revolver
|
||||
| Weapon::Ambassador
|
||||
| Weapon::Knife
|
||||
| Weapon::Samrevolver
|
||||
| Weapon::Enforcer
|
||||
| Weapon::EternalReward
|
||||
| Weapon::SpyCicle
|
||||
| Weapon::VoodooPin
|
||||
| Weapon::PdaSpy
|
||||
| Weapon::Sapper
|
||||
| Weapon::SharpDresser
|
||||
| Weapon::Kunai
|
||||
| Weapon::BigEarner
|
||||
| Weapon::Diamondback
|
||||
| Weapon::TauntSpy
|
||||
| Weapon::BlackRose => &[Class::Spy],
|
||||
Weapon::TfProjectilePipeRemote
|
||||
| Weapon::IronBomber
|
||||
| Weapon::TfProjectilePipe
|
||||
| Weapon::LochNLoad
|
||||
| Weapon::IronCurtain
|
||||
| Weapon::UllapoolCaber
|
||||
| Weapon::Bottle
|
||||
| Weapon::ScotlandShard
|
||||
| Weapon::Headtaker
|
||||
| Weapon::TauntDemoman
|
||||
| Weapon::StickyResistance
|
||||
| Weapon::Demokatana
|
||||
| Weapon::LooseCannon
|
||||
| Weapon::LooseCannonImpact
|
||||
| Weapon::StickybombDefender
|
||||
| Weapon::Claidheamohmor
|
||||
| Weapon::Sword
|
||||
| Weapon::PersianPersuader
|
||||
| Weapon::Nessieclub
|
||||
| Weapon::Battleaxe
|
||||
| Weapon::UllapoolCaberExplosion
|
||||
| Weapon::Demoshield
|
||||
| Weapon::TideTurner
|
||||
| Weapon::SplendidScreen
|
||||
| Weapon::QuickiebombLauncher => &[Class::DemoMan],
|
||||
Weapon::AwperHand
|
||||
| Weapon::Club
|
||||
| Weapon::Sniperrifle
|
||||
| Weapon::Tribalkukri
|
||||
| Weapon::LongHeatmaker
|
||||
| Weapon::Smg
|
||||
| Weapon::SydneySleeper
|
||||
| Weapon::TauntSniper
|
||||
| Weapon::Shahanshah
|
||||
| Weapon::ProSmg
|
||||
| Weapon::TfProjectileArrow
|
||||
| Weapon::CompoundBow
|
||||
| Weapon::TfProjectileArrowFire
|
||||
| Weapon::PrinnyMachete
|
||||
| Weapon::ProRifle
|
||||
| Weapon::Jar
|
||||
| Weapon::TheClassic
|
||||
| Weapon::PlayerPenetration
|
||||
| Weapon::BazaarBargain
|
||||
| Weapon::ShootingStar
|
||||
| Weapon::Machina
|
||||
| Weapon::Bushwacka => &[Class::Sniper],
|
||||
Weapon::QuakeRl
|
||||
| Weapon::RighteousBison
|
||||
| Weapon::ShotgunSoldier
|
||||
| Weapon::TfProjectileRocket
|
||||
| Weapon::Blackbox
|
||||
| Weapon::TauntSoldier
|
||||
| Weapon::RocketlauncherDirecthit
|
||||
| Weapon::CowMangler
|
||||
| Weapon::UniquePickaxeEscape
|
||||
| Weapon::MarketGardener
|
||||
| Weapon::DisciplinaryAction
|
||||
| Weapon::BuffItem
|
||||
| Weapon::Shovel
|
||||
| Weapon::UniquePickaxe
|
||||
| Weapon::Airstrike
|
||||
| Weapon::Mantreads
|
||||
| Weapon::DumpsterDevice
|
||||
| Weapon::LibertyLauncher => &[Class::Soldier],
|
||||
Weapon::CrusadersCrossbow
|
||||
| Weapon::Blutsauger
|
||||
| Weapon::SyringegunMedic
|
||||
| Weapon::Bonesaw
|
||||
| Weapon::Battleneedle
|
||||
| Weapon::Kritzkrieg
|
||||
| Weapon::TauntMedic
|
||||
| Weapon::Amputator
|
||||
| Weapon::ProtoSyringe
|
||||
| Weapon::Medigun
|
||||
| Weapon::Quickfix
|
||||
| Weapon::SolemnVow
|
||||
| Weapon::Ubersaw => &[Class::Medic],
|
||||
Weapon::Scattergun
|
||||
| Weapon::BackScatter
|
||||
| Weapon::ForceANature
|
||||
| Weapon::PistolScout
|
||||
| Weapon::BostonBasher
|
||||
| Weapon::Bat
|
||||
| Weapon::LavaBat
|
||||
| Weapon::TauntScout
|
||||
| Weapon::HolyMackerel
|
||||
| Weapon::Shortstop
|
||||
| Weapon::SodaPopper
|
||||
| Weapon::PepPistol
|
||||
| Weapon::UnarmedCombat
|
||||
| Weapon::Ball
|
||||
| Weapon::Holymackerel
|
||||
| Weapon::Guillotine
|
||||
| Weapon::TheWinger
|
||||
| Weapon::JarMilk
|
||||
| Weapon::Batsaber
|
||||
| Weapon::Sandman
|
||||
| Weapon::CandyCane
|
||||
| Weapon::Warfan
|
||||
| Weapon::PepBrawlerblaster
|
||||
| Weapon::Atomizer
|
||||
| Weapon::WrapAssassin
|
||||
| Weapon::ScoutSword => &[Class::Scout],
|
||||
Weapon::ShotgunPrimary
|
||||
| Weapon::Pistol
|
||||
| Weapon::Widowmaker
|
||||
| Weapon::RobotArm
|
||||
| Weapon::Pomson
|
||||
| Weapon::TauntEngineer
|
||||
| Weapon::ObjMinisentry
|
||||
| Weapon::ObjSentrygun
|
||||
| Weapon::LaserPointer
|
||||
| Weapon::Wrench
|
||||
| Weapon::WrenchGolden
|
||||
| Weapon::ShortCircuit
|
||||
| Weapon::Builder
|
||||
| Weapon::Mailbox
|
||||
| Weapon::WrenchJag
|
||||
| Weapon::WranglerKill
|
||||
| Weapon::GigerCounter
|
||||
| Weapon::EurekaEffect
|
||||
| Weapon::SouthernHospitality
|
||||
| Weapon::RescueRanger
|
||||
| Weapon::FrontierJustice => &[Class::Engineer],
|
||||
Weapon::ShotgunPyro
|
||||
| Weapon::Rainblower
|
||||
| Weapon::Powerjack
|
||||
| Weapon::Flamethrower
|
||||
| Weapon::Lollichop
|
||||
| Weapon::RescueRangerReflect
|
||||
| Weapon::Phlogistinator
|
||||
| Weapon::HotHand
|
||||
| Weapon::LavaAxe
|
||||
| Weapon::Annihilator
|
||||
| Weapon::JarGas
|
||||
| Weapon::DeflectArrow
|
||||
| Weapon::DeflectPromode
|
||||
| Weapon::DeflectRocket
|
||||
| Weapon::DeflectFlare
|
||||
| Weapon::DeflectHuntsmanFlyingburn
|
||||
| Weapon::DeflectSticky
|
||||
| Weapon::LooseCannonReflect
|
||||
| Weapon::TauntPyro
|
||||
| Weapon::BackScratcher
|
||||
| Weapon::Rocketpack
|
||||
| Weapon::TheMaul
|
||||
| Weapon::DragonsFuryBonus
|
||||
| Weapon::Manmelter
|
||||
| Weapon::Sledgehammer
|
||||
| Weapon::Backburner
|
||||
| Weapon::Detonator
|
||||
| Weapon::Degreaser
|
||||
| Weapon::ScorchShot
|
||||
| Weapon::Flaregun
|
||||
| Weapon::Thirddegree
|
||||
| Weapon::AiFlamethrower
|
||||
| Weapon::DragonsFury
|
||||
| Weapon::Fireaxe
|
||||
| Weapon::Axtinguisher => &[Class::Pyro],
|
||||
Weapon::TheCapper | Weapon::Maxgun => &[Class::Scout, Class::Engineer],
|
||||
Weapon::PanicAttack => &[
|
||||
Class::Soldier,
|
||||
Class::Engineer,
|
||||
Class::Pyro,
|
||||
Class::HeavyWeapons,
|
||||
],
|
||||
Weapon::ShotgunHwg
|
||||
| Weapon::Tomislav
|
||||
| Weapon::FamilyBusiness
|
||||
| Weapon::Minigun
|
||||
| Weapon::Natascha
|
||||
| Weapon::Gloves
|
||||
| Weapon::TauntHeavy
|
||||
| Weapon::Fists
|
||||
| Weapon::Lunchbox
|
||||
| Weapon::BreadBite
|
||||
| Weapon::WarriorSpirit
|
||||
| Weapon::EvictionNotice
|
||||
| Weapon::HolidayPunch
|
||||
| Weapon::Apocofists
|
||||
| Weapon::SteelFists
|
||||
| Weapon::BrassBeast
|
||||
| Weapon::GlovesRunningUrgently => &[Class::HeavyWeapons],
|
||||
Weapon::Fryingpan
|
||||
| Weapon::GoldenFryingpan
|
||||
| Weapon::FreedomStaff
|
||||
| Weapon::Skullbat
|
||||
| Weapon::HamShank
|
||||
| Weapon::CrossingGuard
|
||||
| Weapon::MemoryMaker
|
||||
| Weapon::NonnonviolentProtest => &[
|
||||
Class::Scout,
|
||||
Class::Soldier,
|
||||
Class::DemoMan,
|
||||
Class::Pyro,
|
||||
Class::Medic,
|
||||
Class::Sniper,
|
||||
Class::HeavyWeapons,
|
||||
],
|
||||
Weapon::NecroSmasher => &[
|
||||
Class::Scout,
|
||||
Class::Soldier,
|
||||
Class::DemoMan,
|
||||
Class::Pyro,
|
||||
Class::Medic,
|
||||
Class::Sniper,
|
||||
Class::HeavyWeapons,
|
||||
Class::Spy,
|
||||
],
|
||||
Weapon::Saxxy
|
||||
| Weapon::Spellbook
|
||||
| Weapon::Other(_)
|
||||
| Weapon::GrapplingHook
|
||||
| Weapon::LunchboxDrink => &[
|
||||
Class::Scout,
|
||||
Class::Soldier,
|
||||
Class::DemoMan,
|
||||
Class::Pyro,
|
||||
Class::Medic,
|
||||
Class::Sniper,
|
||||
Class::Engineer,
|
||||
Class::HeavyWeapons,
|
||||
Class::Spy,
|
||||
],
|
||||
Weapon::Paintrain => &[Class::Soldier, Class::DemoMan],
|
||||
Weapon::Shotgun => &[Class::Soldier, Class::Engineer, Class::HeavyWeapons],
|
||||
Weapon::ReserveShooter => &[Class::Pyro, Class::Soldier],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for Weapon {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,12 @@ pub struct Participant {
|
|||
pub class: Class,
|
||||
}
|
||||
|
||||
impl Participant {
|
||||
pub fn subject(&self) -> SubjectId {
|
||||
SubjectId::Player(self.id.account_id())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, PartialEq)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum KillKind {
|
||||
|
|
@ -115,7 +121,10 @@ struct EarlyData {
|
|||
|
||||
#[derive(Default)]
|
||||
pub struct Kills {
|
||||
active: bool,
|
||||
game_started: bool,
|
||||
classes: AHashMap<SubjectId, Class>,
|
||||
alive: AHashMap<SubjectId, bool>,
|
||||
kills: Vec<Kill>,
|
||||
early_data: Option<EarlyData>,
|
||||
}
|
||||
|
|
@ -151,29 +160,63 @@ impl GlobalData for Kills {
|
|||
| RawEventType::KillAssist
|
||||
| RawEventType::Spawned
|
||||
| RawEventType::MedicDeathEx
|
||||
| RawEventType::RoundStart
|
||||
| RawEventType::RoundWin
|
||||
| RawEventType::TournamentModeStarted
|
||||
)
|
||||
}
|
||||
|
||||
fn handle_event(&mut self, meta: &EventMeta, subject: SubjectId, event: &GameEvent) {
|
||||
let time = meta.time;
|
||||
|
||||
match event {
|
||||
GameEvent::RoundStart | GameEvent::TournamentModeStarted(_) => {
|
||||
self.active = true;
|
||||
self.game_started = true;
|
||||
}
|
||||
GameEvent::RoundWin(_) => {
|
||||
// self.active = false;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
if !matches!(subject, SubjectId::Player(_)) {
|
||||
return;
|
||||
}
|
||||
|
||||
match event {
|
||||
GameEvent::Spawned(event) => {
|
||||
// sometimes the round start seems to be missing, so catch the round-start-spawn
|
||||
self.active = self.game_started;
|
||||
|
||||
if let Some(class) = event.class {
|
||||
self.classes.insert(subject, class);
|
||||
}
|
||||
self.alive.insert(subject, true);
|
||||
}
|
||||
GameEvent::Killed(event) => {
|
||||
GameEvent::Killed(event) if self.active => {
|
||||
if let Some(mut kill) = Kill::from_event(time, subject, event, &self.classes) {
|
||||
self.alive.insert(kill.victim.subject(), false);
|
||||
|
||||
// sometimes, spawn events are missing and we miss a class change
|
||||
// we try using the weapon to correct this
|
||||
if !kill.weapon.classes().contains(&kill.killer.class) {
|
||||
let class = match kill.weapon.classes() {
|
||||
&[class] => class,
|
||||
_ => Class::Unknown,
|
||||
};
|
||||
|
||||
kill.killer.class = class;
|
||||
self.classes.insert(subject, class);
|
||||
}
|
||||
|
||||
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) => {
|
||||
GameEvent::KillAssist(event) if self.active => {
|
||||
if let Some(kill) = self.kills.last_mut() {
|
||||
if kill.time == time
|
||||
&& Some(kill.victim.id)
|
||||
|
|
@ -183,7 +226,7 @@ impl GlobalData for Kills {
|
|||
}
|
||||
}
|
||||
}
|
||||
GameEvent::MedicDeathEx(event) => {
|
||||
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(event);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue