diff options
author | Daniel Schadt <kingdread@gmx.de> | 2018-06-14 17:26:23 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2018-06-14 17:26:23 +0200 |
commit | 9f6f3db682ab927fef4f1399d13c4cfc91313f82 (patch) | |
tree | bef44f963e1822b837049fe87642609948243578 /src/lib.rs | |
parent | aac51cfaf15659e9447a79032dea5c05e0441709 (diff) | |
download | evtclib-9f6f3db682ab927fef4f1399d13c4cfc91313f82.tar.gz evtclib-9f6f3db682ab927fef4f1399d13c4cfc91313f82.tar.bz2 evtclib-9f6f3db682ab927fef4f1399d13c4cfc91313f82.zip |
deal with multiple boss agents
Exemplary done with Xera.
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -35,6 +35,8 @@ pub use event::{Event, EventKind}; pub mod statistics; +use statistics::gamedata::{self, Boss}; + /// A macro that returns `true` when the given expression matches the pattern. /// /// ```rust @@ -165,12 +167,35 @@ impl Log { } /// Return the boss agent. + /// + /// Be careful with encounters that have multiple boss agents, such as Trio + /// and Xera. pub fn boss(&self) -> &Agent { self.npcs() .find(|n| matches!(n.kind, AgentKind::Character(x) if x == self.boss_id)) .expect("Boss has no agent!") } + /// Return all boss agents. + /// + /// This correctly returns multiple agents on encounters where multiple + /// agents are needed. + pub fn boss_agents(&self) -> Vec<&Agent> { + let boss_ids = if self.boss_id == Boss::Xera as u16 { + vec![self.boss_id, gamedata::XERA_PHASE2_ID] + } else { + vec![self.boss_id] + }; + self.npcs() + .filter(|a| matches!(a.kind, AgentKind::Character(x) if boss_ids.contains(&x))) + .collect() + } + + /// Check whether the given address is a boss agent. + pub fn is_boss(&self, addr: u64) -> bool { + self.boss_agents().into_iter().any(|a| *a.addr() == addr) + } + /// Return all events present in this log. pub fn events(&self) -> &[Event] { &self.events |