mirror of
https://codeberg.org/icewind/tf-log-parser.git
synced 2026-06-04 02:34:10 +02:00
healspread
This commit is contained in:
parent
747ee7d1a9
commit
d1b3525b2a
10 changed files with 209 additions and 16 deletions
|
|
@ -2,6 +2,7 @@ use crate::common::{SubjectData, SubjectId};
|
|||
use crate::module::EventHandler;
|
||||
use crate::raw_event::{RawEvent, RawEventType};
|
||||
use crate::SubjectMap;
|
||||
use serde::Serialize;
|
||||
use std::convert::Infallible;
|
||||
use steamid_ng::SteamID;
|
||||
|
||||
|
|
@ -12,6 +13,7 @@ struct BareChatMessage {
|
|||
pub chat_type: ChatType,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct ChatMessage {
|
||||
pub time: u32,
|
||||
pub name: String,
|
||||
|
|
@ -38,6 +40,7 @@ impl ChatMessage {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub enum ChatType {
|
||||
All,
|
||||
Team,
|
||||
|
|
|
|||
67
src/module/healspread.rs
Normal file
67
src/module/healspread.rs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
use crate::common::{SteamId3, SubjectId};
|
||||
use crate::event::healed_event_parser;
|
||||
use crate::module::EventHandler;
|
||||
use crate::raw_event::{RawEvent, RawEventType};
|
||||
use crate::SubjectMap;
|
||||
use serde::{Serialize, Serializer};
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryFrom;
|
||||
use thiserror::Error;
|
||||
|
||||
impl Serialize for SteamId3 {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
self.0.steam3().serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct HealSpreadHandler(HashMap<SteamId3, HashMap<SteamId3, u32>>);
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
#[error("Invalid healed event: {0}")]
|
||||
pub struct InvalidHealEvent(String);
|
||||
|
||||
impl EventHandler for HealSpreadHandler {
|
||||
type Output = HashMap<SteamId3, HashMap<SteamId3, u32>>;
|
||||
type Error = InvalidHealEvent;
|
||||
|
||||
fn does_handle(&self, ty: RawEventType) -> bool {
|
||||
matches!(ty, RawEventType::Healed)
|
||||
}
|
||||
|
||||
fn handle(
|
||||
&mut self,
|
||||
_time: u32,
|
||||
subject: SubjectId,
|
||||
event: &RawEvent,
|
||||
) -> Result<(), Self::Error> {
|
||||
let healer_steam_id = if let Some(steam_id) = subject.steam_id() {
|
||||
steam_id
|
||||
} else {
|
||||
return Ok(());
|
||||
};
|
||||
if matches!(event.ty, RawEventType::Healed) {
|
||||
let (_, heal_event) = healed_event_parser(event.params)
|
||||
.map_err(|_| InvalidHealEvent(event.params.into()))?;
|
||||
if let Ok(target_subject) = SubjectId::try_from(&heal_event.subject) {
|
||||
if let Some(target_steam_id) = target_subject.steam_id() {
|
||||
let healed = self
|
||||
.0
|
||||
.entry(SteamId3(healer_steam_id))
|
||||
.or_default()
|
||||
.entry(SteamId3(target_steam_id))
|
||||
.or_default();
|
||||
*healed += heal_event.amount
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn finish(self, _subjects: &SubjectMap) -> Self::Output {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ use crate::common::SubjectId;
|
|||
use crate::raw_event::{RawEvent, RawEventType};
|
||||
use crate::SubjectMap;
|
||||
pub use chat::{ChatHandler, ChatMessage, ChatType};
|
||||
pub use healspread::{HealSpreadHandler, InvalidHealEvent};
|
||||
pub use lobbysettings::{
|
||||
LobbySettingsError, LobbySettingsHandler, Location, Settings as LobbySettings,
|
||||
};
|
||||
|
|
@ -11,6 +12,7 @@ use std::fmt::Debug;
|
|||
use thiserror::Error;
|
||||
|
||||
mod chat;
|
||||
mod healspread;
|
||||
mod lobbysettings;
|
||||
|
||||
pub trait EventHandler: Default {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue