From 962e2b9f8e17a50c7d7d37a424591b0df62f265c Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Thu, 23 Jul 2020 02:47:52 +0200 Subject: 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. --- src/analyzers/helpers.rs | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'src/analyzers/helpers.rs') 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 { 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() { -- cgit v1.2.3