fix damage

This commit is contained in:
Robin Appelman 2021-08-08 01:32:04 +02:00
commit cdaa164575
6 changed files with 97 additions and 7 deletions

View file

@ -43,11 +43,13 @@ impl<'a, T> GameEventErrTrait<T> for IResult<&str, T> {
}
}
#[derive(Debug)]
pub enum GameEvent<'a> {
ShotFired(ShotFiredEvent<'a>),
ShotHit(ShotHitEvent<'a>),
Damage(DamageEvent<'a>),
Kill(KillEvent<'a>),
KillAssist(KillAssistEvent<'a>),
Say(&'a str),
SayTeam(&'a str),
Healed(HealedEvent<'a>),
@ -65,6 +67,18 @@ impl<'a> GameEvent<'a> {
RawEventType::ShotFired => {
GameEvent::ShotFired(shot_fired_event_parser(raw.params).with_type(raw.ty)?)
}
RawEventType::ShotHit => {
GameEvent::ShotHit(shot_hit_event_parser(raw.params).with_type(raw.ty)?)
}
RawEventType::Damage => {
GameEvent::Damage(damage_event_parser(raw.params).with_type(raw.ty)?)
}
RawEventType::Killed => {
GameEvent::Kill(kill_event_parser(raw.params).with_type(raw.ty)?)
}
RawEventType::KillAssist => {
GameEvent::KillAssist(kill_assist_event_parser(raw.params).with_type(raw.ty)?)
}
RawEventType::SayTeam => GameEvent::SayTeam(raw.params.trim_matches('"')),
RawEventType::Say => GameEvent::Say(raw.params.trim_matches('"')),
RawEventType::Healed => {
@ -122,7 +136,7 @@ fn param_pair_parse(input: &str) -> IResult<&str, (&str, &str)> {
let (input, _) = tag(r#"""#)(input)?;
if open_tag.is_some() {
let (_input, _) = tag("(")(input)?;
let (_input, _) = tag(")")(input)?;
}
Ok((input, (key, value)))
}

View file

@ -1,4 +1,4 @@
use crate::event::{param_parse, param_parse_with, position, quoted, u_int, ParamIter};
use crate::event::{param_parse, param_parse_with, position, u_int, ParamIter};
use crate::raw_event::{subject_parser, RawSubject};
use nom::combinator::opt;
use nom::IResult;
@ -19,9 +19,9 @@ pub struct ShotHitEvent<'a> {
pub weapon: Option<&'a str>,
}
pub fn shot_hit_event_parser(input: &str) -> IResult<&str, ShotFiredEvent> {
pub fn shot_hit_event_parser(input: &str) -> IResult<&str, ShotHitEvent> {
let (input, weapon) = opt(param_parse("weapon"))(input)?;
Ok((input, ShotFiredEvent { weapon }))
Ok((input, ShotHitEvent { weapon }))
}
#[derive(Debug)]
@ -42,8 +42,8 @@ pub fn damage_event_parser(input: &str) -> IResult<&str, DamageEvent> {
};
for (key, value) in ParamIter::new(input) {
match key {
"damage" => event.damage = NonZeroU32::new(quoted(u_int)(value)?.1),
"realdamage" => event.real_damage = NonZeroU32::new(quoted(u_int)(value)?.1),
"damage" => event.damage = NonZeroU32::new(u_int(value)?.1),
"realdamage" => event.real_damage = NonZeroU32::new(u_int(value)?.1),
"weapon" => event.weapon = Some(value.trim_matches('"')),
_ => {}
}