aboutsummaryrefslogtreecommitdiff
path: root/src/analyzers/helpers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/analyzers/helpers.rs')
-rw-r--r--src/analyzers/helpers.rs45
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() {