From 877549baca100d534c1272000b2af7a8b364cd35 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sun, 10 Jun 2018 01:16:30 +0200 Subject: basic structure for mechanic tracker --- src/statistics/gamedata.rs | 52 ++++++++++++++++++++++++++++++++++++++++++++++ src/statistics/trackers.rs | 39 +++++++++++++++++++++++++++++++++- 2 files changed, 90 insertions(+), 1 deletion(-) (limited to 'src/statistics') diff --git a/src/statistics/gamedata.rs b/src/statistics/gamedata.rs index 73f2780..ea1be39 100644 --- a/src/statistics/gamedata.rs +++ b/src/statistics/gamedata.rs @@ -2,6 +2,12 @@ //! some statistics. use super::boon::{BoonQueue, BoonType}; +/// Enum containing all bosses with their IDs. +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub enum Boss { + ValeGuardian = 15483, +} + /// Contains a boon. /// /// Fields: @@ -61,3 +67,49 @@ pub static BOONS: &[Boon] = &[ pub fn get_boon(boon_id: u16) -> Option<&'static Boon> { BOONS.iter().find(|b| b.0 == boon_id) } + +/// Contains pre-defined triggers for boss mechanics. +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub enum Trigger { + /// Triggers when the given boon is applied to the player. + BoonPlayer(u16), + /// Triggers when the given boon is applied to the boss. + BoonBoss(u16), + /// Triggers when the given skill is used by a player. + SkillByPlayer(u16), + /// Triggers when the given skill is used on a player. + SkillOnPlayer(u16), + /// Triggers when the given boon is stripped from an enemy. + BoonStripped(u16), + /// Triggers when the given entity spawned. + Spawn(u16), + /// Triggers when the boss finishes channeling the given skill. + ChannelComplete(u16), +} + +/// Struct describing a boss mechanic. +/// +/// Fields: +/// * Boss id that this mechanic belongs to. +/// * How the mechanic is triggered. +/// * Technical term for the mechanic (for debugging purposes). +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct Mechanic(pub u16, pub Trigger, pub &'static str); + +macro_rules! mechanics { + ($boss_id:expr => [ $($name:expr => $trigger:expr,)* ]) => { + $(Mechanic($boss_id as u16, $trigger, $name)),* + } +} + +/// A slice of all mechanics that we know about. +pub static MECHANICS: &[Mechanic] = &[ + mechanics! { Boss::ValeGuardian => [ + "Unstable Magic Spike" => Trigger::SkillOnPlayer(31860), + ]}, +]; + +/// Get all mechanics that belong to the given boss. +pub fn get_mechanics(boss_id: u16) -> Vec<&'static Mechanic> { + MECHANICS.iter().filter(|m| m.0 == boss_id).collect() +} diff --git a/src/statistics/trackers.rs b/src/statistics/trackers.rs index 6e23480..bcf5e90 100644 --- a/src/statistics/trackers.rs +++ b/src/statistics/trackers.rs @@ -16,7 +16,7 @@ use std::error::Error; use super::super::{Event, EventKind, Log}; use super::boon::BoonQueue; -use super::gamedata; +use super::gamedata::{self, Mechanic, Trigger}; use super::DamageStats; // A support macro to introduce a new block. @@ -377,3 +377,40 @@ impl Tracker for BoonTracker { Ok(self.boon_areas) } } + +/// A tracker that tracks boss mechanics for each player. +pub struct MechanicTracker { + mechanics: HashMap>, + available_mechanics: Vec<&'static Mechanic>, + boss_address: u64, +} + +impl MechanicTracker { + /// Create a new mechanic tracker that watches over the given mechanics. + pub fn new(boss_address: u64, mechanics: Vec<&'static Mechanic>) -> MechanicTracker { + MechanicTracker { + mechanics: HashMap::new(), + available_mechanics: mechanics, + boss_address: boss_address, + } + } +} + +impl Tracker for MechanicTracker { + type Stat = HashMap>; + type Error = !; + + fn feed(&mut self, event: &Event) -> Result<(), Self::Error> { + for mechanic in &self.available_mechanics { + match (&event.kind, &mechanic.1) { + (EventKind::SkillUse { .. }, Trigger::SkillOnPlayer { .. }) => (), + _ => (), + } + } + Ok(()) + } + + fn finalize(self) -> Result { + Ok(self.mechanics) + } +} -- cgit v1.2.3