diff options
author | Daniel Schadt <kingdread@gmx.de> | 2020-07-23 02:47:52 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2020-07-23 02:47:52 +0200 |
commit | 962e2b9f8e17a50c7d7d37a424591b0df62f265c (patch) | |
tree | 61efe53eae3768aca9d5ce1eb89c91f5adaceeba /src/analyzers/helpers.rs | |
parent | 0978345648cf9cdad6222f583dd21497b409d07e (diff) | |
download | evtclib-962e2b9f8e17a50c7d7d37a424591b0df62f265c.tar.gz evtclib-962e2b9f8e17a50c7d7d37a424591b0df62f265c.tar.bz2 evtclib-962e2b9f8e17a50c7d7d37a424591b0df62f265c.zip |
implement proper outcome for w1-w4
It turns out that `was_rewarded` is a pretty bad heuristic if you ever
kill a boss a second time per week (basically, was_rewarded=false does
not imply that the boss was unsuccessful). Therefore, we need a proper
detection of when a fight failed and when a fight succeeded.
This is the first batch that implements this as part of the Analyzer
trait for bosses of wings 1 to 4.
Diffstat (limited to 'src/analyzers/helpers.rs')
-rw-r--r-- | src/analyzers/helpers.rs | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/src/analyzers/helpers.rs b/src/analyzers/helpers.rs index ec09355..674d752 100644 --- a/src/analyzers/helpers.rs +++ b/src/analyzers/helpers.rs @@ -1,7 +1,7 @@ //! This module contains helper methods that are used in different analyzers. use std::collections::HashMap; -use crate::{EventKind, Log}; +use crate::{AgentKind, EventKind, Log}; /// Returns the maximum health of the boss agent. /// @@ -24,6 +24,49 @@ pub fn boss_health(log: &Log) -> Option<u64> { health } +/// Checks if any of the boss NPCs have died. +/// +/// Death is determined by checking for the [`EventKind::ChangeDead`][EventKind::ChangeDead] event, +/// and whether a NPC is a boss is determined by the [`Log::is_boss`][Log::is_boss] method. +pub fn boss_is_dead(log: &Log) -> bool { + log.events().iter().any(|ev| match ev.kind() { + EventKind::ChangeDead { agent_addr } if log.is_boss(*agent_addr) => true, + _ => false, + }) +} + +/// Checks whether the players exit combat after the boss. +/// +/// This is useful to determine the success state of some fights. +pub fn players_exit_after_boss(log: &Log) -> bool { + let mut player_exit = 0u64; + let mut boss_exit = 0u64; + + for event in log.events() { + if let EventKind::ExitCombat { agent_addr } = event.kind() { + let agent = if let Some(a) = log.agent_by_addr(*agent_addr) { + a + } else { + continue; + }; + + match agent.kind() { + AgentKind::Player(_) if event.time() >= player_exit => { + player_exit = event.time(); + } + AgentKind::Character(_) + if event.time() >= boss_exit && log.is_boss(*agent_addr) => + { + boss_exit = event.time(); + } + _ => (), + } + } + } + // Safety margin + boss_exit != 0 && player_exit > boss_exit + 1000 +} + /// Checks if the given buff is present in the log. pub fn buff_present(log: &Log, wanted_buff_id: u32) -> bool { for event in log.events() { |