aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2020-06-28 17:22:43 +0200
committerDaniel Schadt <kingdread@gmx.de>2020-06-28 17:22:43 +0200
commit0978345648cf9cdad6222f583dd21497b409d07e (patch)
tree9470f87a879e36c68104ef067c6657eb94cd98e5 /src/lib.rs
parentacdc4d977e573d54c73530f77ba210efd2184cf0 (diff)
downloadevtclib-0978345648cf9cdad6222f583dd21497b409d07e.tar.gz
evtclib-0978345648cf9cdad6222f583dd21497b409d07e.tar.bz2
evtclib-0978345648cf9cdad6222f583dd21497b409d07e.zip
start implementing analyzers
It turns out that the different encounters do require quite some encounter-specific logic, not only to determine whether the CM was activated, but also to determine whether the fight was successful, the duration of the fight, later the phases, ... Wrapping all of this in pre-defined "triggers" (like CmTrigger) feels like it will be a bit unfitting, so with this patch we have introduced the evtclib::Analyzer, which can be used to analyze the fights. Currently, the whole CM detection logic has been moved to this new interface, and soon we also want the success-detection logic in there. The tests pass and the interface of Log::is_cm is unchanged.
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs83
1 files changed, 9 insertions, 74 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 519d1c4..a0bb741 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -88,7 +88,6 @@
//! While there are legitimate use cases for writing/modification support, they are currently not
//! implemented (but might be in a future version).
-use std::collections::HashMap;
use std::convert::TryFrom;
use std::marker::PhantomData;
@@ -105,9 +104,11 @@ mod processing;
pub use processing::{process, process_file, process_stream, Compression};
pub mod gamedata;
-use gamedata::CmTrigger;
pub use gamedata::{Boss, EliteSpec, Profession};
+pub mod analyzers;
+pub use analyzers::Analyzer;
+
/// Any error that can occur during the processing of evtc files.
#[derive(Error, Debug)]
pub enum EvtcError {
@@ -789,6 +790,11 @@ impl Log {
Boss::from_u16(self.boss_id)
}
+ /// Return an analyzer suitable to analyze the given log.
+ pub fn analyzer<'s>(&'s self) -> Option<Box<dyn Analyzer + 's>> {
+ analyzers::for_log(&self)
+ }
+
/// Return all events present in this log.
#[inline]
pub fn events(&self) -> &[Event] {
@@ -832,46 +838,7 @@ impl Log {
/// * We cannot determine whether the CM was active
/// * The boss is not known
pub fn is_cm(&self) -> bool {
- let trigger = self
- .encounter()
- .map(Boss::cm_trigger)
- .unwrap_or(CmTrigger::Unknown);
- match trigger {
- CmTrigger::HpThreshold(hp_threshold) => {
- for event in self.events() {
- if let EventKind::MaxHealthUpdate {
- agent_addr,
- max_health,
- } = *event.kind()
- {
- if self.is_boss(agent_addr) && max_health >= hp_threshold as u64 {
- return true;
- }
- }
- }
- false
- }
-
- CmTrigger::BuffPresent(wanted_buff_id) => {
- for event in self.events() {
- if let EventKind::BuffApplication { buff_id, .. } = *event.kind() {
- if buff_id == wanted_buff_id {
- return true;
- }
- }
- }
- false
- }
-
- CmTrigger::TimeBetweenBuffs(buff_id, threshold) => {
- let tbb = time_between_buffs(&self.events, buff_id);
- tbb != 0 && tbb <= threshold
- }
-
- CmTrigger::Always => true,
-
- CmTrigger::None | CmTrigger::Unknown => false,
- }
+ self.analyzer().map(|a| a.is_cm()).unwrap_or(false)
}
/// Get the timestamp of when the log was started.
@@ -925,35 +892,3 @@ impl Log {
})
}
}
-
-fn time_between_buffs(events: &[Event], wanted_buff_id: u32) -> u64 {
- let mut time_maps: HashMap<u64, Vec<u64>> = HashMap::new();
- for event in events {
- if let EventKind::BuffApplication {
- destination_agent_addr,
- buff_id,
- ..
- } = event.kind()
- {
- if *buff_id == wanted_buff_id {
- time_maps
- .entry(*destination_agent_addr)
- .or_default()
- .push(event.time());
- }
- }
- }
- let timestamps = if let Some(ts) = time_maps.values().max_by_key(|v| v.len()) {
- ts
- } else {
- return 0;
- };
- timestamps
- .iter()
- .zip(timestamps.iter().skip(1))
- .map(|(a, b)| b - a)
- // Arbitrary limit to filter out duplicated buff application events
- .filter(|x| *x > 50)
- .min()
- .unwrap_or(0)
-}