diff options
author | Daniel Schadt <kingdread@gmx.de> | 2021-11-16 23:44:14 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2021-11-16 23:44:14 +0100 |
commit | b962896e0d31667162b0a844e3f2186707b641ad (patch) | |
tree | 80a51a0b6fcbfddfaef97b0b958769c457f4c8e9 | |
parent | 8e1e84cac23894f40fab49c03c782ad96d535111 (diff) | |
download | evtclib-b962896e0d31667162b0a844e3f2186707b641ad.tar.gz evtclib-b962896e0d31667162b0a844e3f2186707b641ad.tar.bz2 evtclib-b962896e0d31667162b0a844e3f2186707b641ad.zip |
Add GameMode and Log::game_mode
For a lot of applications, it can be useful to distinguish between logs
made in raids, fractals, ...
Note that we probably don't want further categorization (as for example
done in ezau).
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | src/lib.rs | 48 | ||||
-rw-r--r-- | tests/parsing.rs | 45 | ||||
-rw-r--r-- | tests/wvw.rs | 1 |
4 files changed, 93 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 926a979..60d78c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file. - `Encounter::EaterOfSouls` (`Boss::EaterOfSouls`) - `Encounter::StatueOfDarkness` (`Boss::EyeOfJudgment` and `Boss::EyeOfFate`) - `Log::is_generic` to check whether a log is generic (WvW) +- `GameMode` and the `Log::game_mode` method - `FromRawEventError::UnknownLanguage` has been added to deal with an invalid language byte. @@ -134,6 +134,27 @@ pub enum EvtcError { Utf8Error(#[from] std::str::Utf8Error), } +/// The game mode in which a log was produced. +/// +/// Note that the distinction made here is relatively arbitrary, but hopefully still useful. In +/// Guild Wars 2 terms, there is no clear definition of what a "game mode" is. +/// +/// The game mode of a [`Log`] is obtained through [`Log::game_mode()`]. +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] +pub enum GameMode { + /// The log is from a raid encounter. + Raid, + /// The log is from a fractal fight. + Fractal, + /// The log is from a strike mission. + Strike, + /// The log is from a training golem. + Golem, + /// The log is from a world-versus-world fight. + WvW, +} + /// A fully processed log file. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, Clone)] @@ -274,6 +295,33 @@ impl Log { pub fn is_generic(&self) -> bool { self.boss_id == 1 } + + /// Returns the game mode that the log was made in. + /// + /// Note that if the game mode cannot be determined or is unknown to `evtclib`, `None` is + /// returned. + pub fn game_mode(&self) -> Option<GameMode> { + // Here we assume that any generic log is a WvW log, I'm not aware of other generic logs + // being produced at the moment. + if self.is_generic() { + return Some(GameMode::WvW); + } + use Encounter::*; + match self.encounter()? { + MAMA | Siax | Ensolyss | Skorvald | Artsariiv | Arkk | Ai => Some(GameMode::Fractal), + + ValeGuardian | Gorseval | Sabetha | Slothasor | BanditTrio | Matthias + | KeepConstruct | Xera | Cairn | MursaatOverseer | Samarog | Deimos + | SoullessHorror | RiverOfSouls | BrokenKing | EaterOfSouls | StatueOfDarkness + | VoiceInTheVoid | ConjuredAmalgamate | TwinLargos | Qadim | CardinalAdina + | CardinalSabir | QadimThePeerless => Some(GameMode::Raid), + + IcebroodConstruct | Boneskinner | SuperKodanBrothers | FraenirOfJormag + | WhisperOfJormag => Some(GameMode::Strike), + + StandardKittyGolem | MediumKittyGolem | LargeKittyGolem => Some(GameMode::Golem), + } + } } /// Convenience data accessing funtions for [`Log`][Log]s. diff --git a/tests/parsing.rs b/tests/parsing.rs index 4949805..598bafd 100644 --- a/tests/parsing.rs +++ b/tests/parsing.rs @@ -3,10 +3,10 @@ use std::fs::File; use std::io::BufReader; -use evtclib::{EliteSpec::*, Encounter, Profession::*}; +use evtclib::{EliteSpec::*, Encounter, GameMode::*, Profession::*}; macro_rules! test { - (name: $name:ident, log: $log:literal, boss: $boss:expr, players: $players:expr,) => { + (name: $name:ident, log: $log:literal, boss: $boss:expr, mode: $mode:expr, players: $players:expr,) => { #[test] fn $name() { let mut file = BufReader::new(File::open(format!("tests/{}", $log)).unwrap()); @@ -14,6 +14,7 @@ macro_rules! test { let log = evtclib::process(&log).expect("processing log failed"); assert_eq!(log.encounter(), Some($boss)); assert!(!log.is_generic()); + assert_eq!(log.game_mode(), Some($mode)); let players = $players; @@ -44,6 +45,7 @@ test! { name: parse_vale_guardian, log: "logs/vg-20200421.zevtc", boss: Encounter::ValeGuardian, + mode: Raid, players: &[ (4, ":AliceWindwalker.6238", "Fafnarin Sunseeker", Warrior, Some(Berserker)), (4, ":Gellalli.6580", "Germi N", Revenant, Some(Renegade)), @@ -62,6 +64,7 @@ test! { name: parse_gorseval, log: "logs/gorseval-20200421.zevtc", boss: Encounter::Gorseval, + mode: Raid, players: &[ (4, ":AliceWindwalker.6238", "Fafnarin Sunseeker", Warrior, Some(Berserker)), (4, ":Gellalli.6580", "Germi N", Revenant, Some(Renegade)), @@ -80,6 +83,7 @@ test! { name: parse_sabetha, log: "logs/sabetha-20200421.zevtc", boss: Encounter::Sabetha, + mode: Raid, players: &[ (4, ":AliceWindwalker.6238", "Fafnarin Sunseeker", Warrior, Some(Berserker)), (4, ":Gellalli.6580", "Germi N", Revenant, Some(Renegade)), @@ -100,6 +104,7 @@ test! { name: parse_slothasor, log: "logs/slothasor-20200420.zevtc", boss: Encounter::Slothasor, + mode: Raid, players: &[ (2, ":Basafrass.4138", "Miss Mary J", Guardian, Some(Dragonhunter)), (2, ":Gellalli.6580", "Gellalli V", Guardian, Some(Dragonhunter)), @@ -118,6 +123,7 @@ test! { name: parse_bandit_trio, log: "logs/trio-20210501.zevtc", boss: Encounter::BanditTrio, + mode: Raid, players: &[ (2, ":Dunje.4863", "Pallida Howhite", Warrior, Some(Berserker)), (2, ":Straimer.1093", "Deepfreeze Myself", Elementalist, Some(Weaver)), @@ -136,6 +142,7 @@ test! { name: parse_matthias, log: "logs/matthias-20200421.zevtc", boss: Encounter::Matthias, + mode: Raid, players: &[ (2, ":Basafrass.4138", "Miss Mary J", Guardian, Some(Dragonhunter)), (2, ":Gellalli.6580", "Germi N", Revenant, Some(Renegade)), @@ -156,6 +163,7 @@ test! { name: parse_keep_construct, log: "logs/kc-20200426.zevtc", boss: Encounter::KeepConstruct, + mode: Raid, players: &[ (3, ":Bomaga.2106", "Krupniczek", Guardian, Some(Dragonhunter)), (3, ":Buddy Christ.1758", "Block Buddy", Guardian, Some(Dragonhunter)), @@ -174,6 +182,7 @@ test! { name: parse_xera, log: "logs/xera-20200415.zevtc", boss: Encounter::Xera, + mode: Raid, players: &[ (2, ":Marcoliveira.7526", "Flamed Horns", Guardian, Some(Dragonhunter)), (2, ":Marvin.4612", "Necro Rp", Necromancer, Some(Reaper)), @@ -194,6 +203,7 @@ test! { name: parse_cairn, log: "logs/cairn-20200426.zevtc", boss: Encounter::Cairn, + mode: Raid, players: &[ (3, ":Bomaga.2106", "Krupniczek", Guardian, Some(Dragonhunter)), (3, ":Buddy Christ.1758", "Block Buddy", Guardian, Some(Firebrand)), @@ -212,6 +222,7 @@ test! { name: parse_mursaat_overseer, log: "logs/mo-20200426.zevtc", boss: Encounter::MursaatOverseer, + mode: Raid, players: &[ (3, ":Bomaga.2106", "Krupniczek", Guardian, Some(Dragonhunter)), (3, ":Buddy Christ.1758", "Block Buddy", Guardian, Some(Dragonhunter)), @@ -230,6 +241,7 @@ test! { name: parse_samarog, log: "logs/samarog-20200426.zevtc", boss: Encounter::Samarog, + mode: Raid, players: &[ (3, ":Bomaga.2106", "Krupniczek", Guardian, Some(Dragonhunter)), (3, ":Buddy Christ.1758", "Block Buddy", Guardian, Some(Dragonhunter)), @@ -248,6 +260,7 @@ test! { name: parse_deimos, log: "logs/deimos-20200428.zevtc", boss: Encounter::Deimos, + mode: Raid, players: &[ (2, ":CrusaderCody.6935", "Cody Quickfire", Guardian, Some(Firebrand)), (2, ":Mrperfect.5213", "Hanna Kowalski", Revenant, Some(Renegade)), @@ -268,6 +281,7 @@ test! { name: parse_desmina, log: "logs/desmina-20200425.zevtc", boss: Encounter::SoullessHorror, + mode: Raid, players: &[ (3, ":AliceWindwalker.6238", "Fafnarin Sunseeker", Warrior, Some(Berserker)), (3, ":Dunje.4863", "Godric Gobbledygook", Mesmer, Some(Chronomancer)), @@ -286,6 +300,7 @@ test! { name: parse_river, log: "logs/river-20210412.zevtc", boss: Encounter::RiverOfSouls, + mode: Raid, players: &[ (1, ":Baragos.2384", "Cicadania", Mesmer, Some(Chronomancer)), (1, ":Jupp.4570", "Aldwor", Guardian, Some(Firebrand)), @@ -304,6 +319,7 @@ test! { name: parse_broken_king, log: "logs/broken-king-20211115.zevtc", boss: Encounter::BrokenKing, + mode: Raid, players: &[ (1, ":Dunje.4863", "Pallida Howhite", Warrior, Some(Berserker)), (1, ":Straimer.1093", "I Want Smite Back", Guardian, Some(Dragonhunter)), @@ -322,6 +338,7 @@ test! { name: parse_eater, log: "logs/eater-20211115.zevtc", boss: Encounter::EaterOfSouls, + mode: Raid, players: &[ (1, ":Dunje.4863", "Pallida Howhite", Warrior, Some(Berserker)), (1, ":Straimer.1093", "I Want Smite Back", Guardian, Some(Dragonhunter)), @@ -340,6 +357,7 @@ test! { name: parse_eyes, log: "logs/eyes-20211115.zevtc", boss: Encounter::StatueOfDarkness, + mode: Raid, players: &[ (1, ":Dunje.4863", "Pallida Howhite", Warrior, Some(Berserker)), (1, ":Straimer.1093", "I Want Smite Back", Guardian, Some(Dragonhunter)), @@ -358,6 +376,7 @@ test! { name: parse_dhuum, log: "logs/dhuum-20200428.zevtc", boss: Encounter::VoiceInTheVoid, + mode: Raid, players: &[ (1, ":DaZzius.4753", "Amestye Aëther", Mesmer, Some(Chronomancer)), (1, ":Dunje.4863", "Maho Shiina", Revenant, Some(Renegade)), @@ -378,6 +397,7 @@ test! { name: parse_conjured_amalgamate, log: "logs/ca-20200426.zevtc", boss: Encounter::ConjuredAmalgamate, + mode: Raid, players: &[ (3, ":Admiral Aka Inu.4962", "Großadmiral Aka Inu", Warrior, Some(Berserker)), (3, ":Dunje.4863", "Irodo", Elementalist, Some(Weaver)), @@ -396,6 +416,7 @@ test! { name: parse_largos_twins, log: "logs/largos-20200426.zevtc", boss: Encounter::TwinLargos, + mode: Raid, players: &[ (3, ":Cyen Lazarus.4170", "Cyen Blackarrow", Ranger, Some(Druid)), (3, ":Dunje.4863", "Godric Gobbledygook", Mesmer, Some(Mirage)), @@ -414,6 +435,7 @@ test! { name: parse_qadim, log: "logs/qadim-20200427.zevtc", boss: Encounter::Qadim, + mode: Raid, players: &[ (3, ":Cyen Lazarus.4170", "Cyen Blackarrow", Ranger, Some(Druid)), (3, ":Lopoeo.1594", "Glücklich Und Satt", Mesmer, Some(Chronomancer)), @@ -434,6 +456,7 @@ test! { name: parse_adina, log: "logs/adina-20200427.zevtc", boss: Encounter::CardinalAdina, + mode: Raid, players: &[ (3, ":Arkady.3768", "Just Pakly", Engineer, Some(Holosmith)), (3, ":Dunje.4863", "Peter Party", Ranger, Some(Soulbeast)), @@ -452,6 +475,7 @@ test! { name: parse_sabir, log: "logs/sabir-20200427.zevtc", boss: Encounter::CardinalSabir, + mode: Raid, players: &[ (3, ":Arkady.3768", "Just Pakly", Engineer, Some(Holosmith)), (3, ":Dunje.4863", "Emma Hydes", Elementalist, Some(Weaver)), @@ -470,6 +494,7 @@ test! { name: parse_qadim_the_peerless, log: "logs/qadimp-20200427.zevtc", boss: Encounter::QadimThePeerless, + mode: Raid, players: &[ (3, ":AliceWindwalker.6238", "Fafnarin Sunseeker", Warrior, Some(Berserker)), (3, ":Arkady.3768", "Just Pakly", Engineer, Some(Holosmith)), @@ -490,6 +515,7 @@ test! { name: parse_standard_kitty_golem, log: "logs/standard-golem-20211112.zevtc", boss: Encounter::StandardKittyGolem, + mode: Golem, players: &[ (1, ":Dunje.4863", "Ai Higashi", Guardian, Some(Dragonhunter)), ], @@ -499,6 +525,7 @@ test! { name: parse_medium_kitty_golem, log: "logs/medium-golem-20211112.zevtc", boss: Encounter::MediumKittyGolem, + mode: Golem, players: &[ (1, ":Dunje.4863", "Ai Higashi", Guardian, Some(Dragonhunter)), ], @@ -508,6 +535,7 @@ test! { name: parse_large_kitty_golem, log: "logs/large-golem-20211112.zevtc", boss: Encounter::LargeKittyGolem, + mode: Golem, players: &[ (1, ":Dunje.4863", "Ai Higashi", Guardian, Some(Dragonhunter)), ], @@ -519,6 +547,7 @@ test! { name: parse_ai, log: "logs/ai-20200922.zevtc", boss: Encounter::Ai, + mode: Fractal, players: &[ (0, ":Dunje.4863", "Padme Amidada", Guardian, Some(Firebrand)), (0, ":Speeaaakmaan.8974", "Damage Modifiers", Guardian, Some(Firebrand)), @@ -534,6 +563,7 @@ test! { name: parse_skorvald, log: "logs/skorvald-20200427.zevtc", boss: Encounter::Skorvald, + mode: Fractal, players: &[ (0, ":Dunje.4863", "Jane Whiskerlisp", Revenant, Some(Renegade)), (0, ":Gellalli.6580", "Germi X", Ranger, Some(Soulbeast)), @@ -547,6 +577,7 @@ test! { name: parse_artsariiv, log: "logs/artsariiv-20200427.zevtc", boss: Encounter::Artsariiv, + mode: Fractal, players: &[ (0, ":Dunje.4863", "Jane Whiskerlisp", Revenant, Some(Renegade)), (0, ":Gellalli.6580", "Germi X", Ranger, Some(Soulbeast)), @@ -560,6 +591,7 @@ test! { name: parse_arkk, log: "logs/arkk-20200427.zevtc", boss: Encounter::Arkk, + mode: Fractal, players: &[ (0, ":Dunje.4863", "Jane Whiskerlisp", Revenant, Some(Renegade)), (0, ":Gellalli.6580", "Germi X", Ranger, Some(Soulbeast)), @@ -575,6 +607,7 @@ test! { name: parse_mama, log: "logs/mama-20200427.zevtc", boss: Encounter::MAMA, + mode: Fractal, players: &[ (0, ":Dunje.4863", "Jane Whiskerlisp", Revenant, Some(Renegade)), (0, ":Gellalli.6580", "Germi X", Ranger, Some(Soulbeast)), @@ -588,6 +621,7 @@ test! { name: parse_siax, log: "logs/siax-20200427.zevtc", boss: Encounter::Siax, + mode: Fractal, players: &[ (0, ":Dunje.4863", "Jane Whiskerlisp", Revenant, Some(Renegade)), (0, ":Gellalli.6580", "Germi X", Ranger, Some(Soulbeast)), @@ -601,6 +635,7 @@ test! { name: parse_ensolyss, log: "logs/ensolyss-20200427.zevtc", boss: Encounter::Ensolyss, + mode: Fractal, players: &[ (0, ":Dunje.4863", "Jane Whiskerlisp", Revenant, Some(Renegade)), (0, ":Gellalli.6580", "Germi X", Ranger, Some(Soulbeast)), @@ -616,6 +651,7 @@ test! { name: parse_icebrood, log: "logs/icebrood-20200424.zevtc", boss: Encounter::IcebroodConstruct, + mode: Strike, players: &[ (3, ":Dunje.4863", "Thank You Exorcist", Necromancer, Some(Reaper)), (3, ":Speeaaakmaan.8974", "Damage Modifiers", Guardian, Some(Firebrand)), @@ -634,6 +670,7 @@ test! { name: parse_kodan_brothers, log: "logs/kodans-20200424.zevtc", boss: Encounter::SuperKodanBrothers, + mode: Strike, players: &[ (3, ":Gellalli.6580", "Germi J", Necromancer, Some(Scourge)), (3, ":Speeaaakmaan.8974", "Damage Modifiers", Guardian, Some(Firebrand)), @@ -652,6 +689,7 @@ test! { name: parse_fraenir_of_jormag, log: "logs/fraenir-20200424.zevtc", boss: Encounter::FraenirOfJormag, + mode: Strike, players: &[ (3, ":Dunje.4863", "Thank You Exorcist", Necromancer, Some(Reaper)), (3, ":Speeaaakmaan.8974", "Damage Modifiers", Guardian, Some(Firebrand)), @@ -670,6 +708,7 @@ test! { name: parse_boneskinner, log: "logs/boneskinner-20200424.zevtc", boss: Encounter::Boneskinner, + mode: Strike, players: &[ (3, ":Gellalli.6580", "Germi J", Necromancer, Some(Scourge)), (3, ":Speeaaakmaan.8974", "Damage Modifiers", Guardian, Some(Firebrand)), @@ -688,6 +727,7 @@ test! { name: parse_whisper_of_jormag, log: "logs/whisper-20200424.zevtc", boss: Encounter::WhisperOfJormag, + mode: Strike, players: &[ (3, ":Gellalli.6580", "Germi J", Necromancer, Some(Scourge)), (3, ":Speeaaakmaan.8974", "Damage Modifiers", Guardian, Some(Firebrand)), @@ -708,6 +748,7 @@ test! { name: parse_old_cairn_log, log: "logs/old-cairn-20180321.evtc.zip", boss: Encounter::Cairn, + mode: Raid, players: &[ (1, ":Medejz.1679", "Nuerha", Guardian, Some(Firebrand)), (1, ":ONEVA.5860", "Berserkoala", Revenant, Some(Renegade)), diff --git a/tests/wvw.rs b/tests/wvw.rs index 5af15c7..6ff35cf 100644 --- a/tests/wvw.rs +++ b/tests/wvw.rs @@ -8,4 +8,5 @@ fn test_smoke() { let log = "./tests/logs/wvw-20211112.zevtc"; let log = evtclib::process_file(log, evtclib::Compression::Zip).unwrap(); assert!(log.is_generic()); + assert_eq!(log.game_mode(), Some(evtclib::GameMode::WvW)); } |