From 16019515dffe4dd790adc72ed8a8ece8fc54c260 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 29 Apr 2020 15:49:24 +0200 Subject: update evtclib to 0.2.0 --- src/main.rs | 139 +++++++++++++++++++++++------------------------------------- 1 file changed, 52 insertions(+), 87 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 231fbdc..8cd1329 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,13 +11,12 @@ use chrono::{NaiveDateTime, Weekday}; use colored::Colorize; use itertools::Itertools; use log::debug; -use num_traits::cast::FromPrimitive; use regex::Regex; use rustyline::Editor; use structopt::StructOpt; use walkdir::{DirEntry, WalkDir}; -use evtclib::{AgentKind, AgentName, EventKind, Log}; +use evtclib::{EliteSpec, EventKind, Log, Profession}; mod fexpr; mod filters; @@ -26,16 +25,6 @@ mod guilds; mod logger; mod output; -macro_rules! unwrap { - ($p:pat = $e:expr => { $r:expr} ) => { - if let $p = $e { - $r - } else { - panic!("Pattern match failed!"); - } - }; -} - /// A program that allows you to search through all your evtc logs for specific people. /// /// raidgrep supports different predicates that determine whether a log is included or not. @@ -405,7 +394,7 @@ fn extract_info(entry: &DirEntry, log: &Log) -> LogResult { debug!( "log file has unknown boss: {:?} (id: {:#x})", entry.path(), - log.boss_id() + log.encounter_id() ); "unknown" }) @@ -415,30 +404,20 @@ fn extract_info(entry: &DirEntry, log: &Log) -> LogResult { let mut players = log .players() - .map(|p| { - unwrap! { AgentKind::Player { profession, elite } = p.kind() => { - unwrap! { AgentName::Player { - account_name, - character_name, - subgroup, - } = p.name() => - { - Player { - account_name: account_name.clone(), - character_name: character_name.clone(), - profession: get_profession_name(*profession, *elite).into(), - subgroup: *subgroup, - guild_id: guild_ids.get(p.addr()).cloned(), - } - }}}} + .map(|p| Player { + account_name: p.account_name().to_owned(), + character_name: p.character_name().to_owned(), + profession: get_profession_name(p.profession(), p.elite()).into(), + subgroup: p.subgroup(), + guild_id: guild_ids.get(&p.addr()).cloned(), }) .collect::>(); players.sort_by_key(|p| p.subgroup); LogResult { log_file: entry.path().to_path_buf(), - time: NaiveDateTime::from_timestamp(i64::from(get_start_timestamp(log)), 0), - boss_id: log.boss_id(), + time: NaiveDateTime::from_timestamp(i64::from(log.local_start_timestamp().unwrap_or(0)), 0), + boss_id: log.encounter_id(), boss_name, players, outcome: get_fight_outcome(log), @@ -466,34 +445,19 @@ fn get_guild_mapping(log: &Log) -> HashMap { .collect() } -/// Get the timestamp of the log start time. -fn get_start_timestamp(log: &Log) -> u32 { - for event in log.events() { - if let EventKind::LogStart { - local_timestamp, .. - } = event.kind - { - return local_timestamp; - } - } - 0 -} - /// Get the outcome of the fight. fn get_fight_outcome(log: &Log) -> FightOutcome { - for event in log.events() { - if let EventKind::Reward { .. } = event.kind { - return FightOutcome::Success; - } + if log.was_rewarded() { + FightOutcome::Success + } else { + FightOutcome::Wipe } - FightOutcome::Wipe } /// Get the (english) name for the given encounter fn get_encounter_name(log: &Log) -> Option<&'static str> { - use evtclib::statistics::gamedata::Boss; - let boss = Boss::from_u16(log.boss_id())?; - Some(match boss { + use evtclib::Boss; + Some(match log.encounter()? { Boss::ValeGuardian => "Vale Guardian", Boss::Gorseval => "Gorseval", Boss::Sabetha => "Sabetha", @@ -537,41 +501,42 @@ fn get_encounter_name(log: &Log) -> Option<&'static str> { } /// Get the (english) name for the given profession/elite specialization. -fn get_profession_name(profession: u32, elite: u32) -> &'static str { - match (profession, elite) { - (1, 0) => "Guardian", - (2, 0) => "Warrior", - (3, 0) => "Engineer", - (4, 0) => "Ranger", - (5, 0) => "Thief", - (6, 0) => "Elementalist", - (7, 0) => "Mesmer", - (8, 0) => "Necromancer", - (9, 0) => "Revenant", - - (1, 27) => "Dragonhunter", - (2, 18) => "Berserker", - (3, 43) => "Scrapper", - (4, 5) => "Druid", - (5, 7) => "Daredevil", - (6, 48) => "Tempest", - (7, 40) => "Chronomancer", - (8, 34) => "Reaper", - (9, 52) => "Herald", - - (1, 62) => "Firebrand", - (2, 61) => "Spellbreaker", - (3, 57) => "Holosmith", - (4, 55) => "Soulbeast", - (5, 58) => "Deadeye", - (6, 56) => "Weaver", - (7, 59) => "Mirage", - (8, 60) => "Scourge", - (9, 63) => "Renegade", - - _ => { - debug!("Unknown spec (prof: {}, elite: {})", profession, elite); - "Unknown" +fn get_profession_name(profession: Profession, elite: Option) -> &'static str { + use EliteSpec::*; + use Profession::*; + + if let Some(elite) = elite { + match elite { + Dragonhunter => "Dragonhunter", + Firebrand => "Firebrand", + Berserker => "Berserker", + Spellbreaker => "Spellbreaker", + Herald => "Herald", + Renegade => "Renegade", + Scrapper => "Scrapper", + Holosmith => "Holosmith", + Druid => "Druid", + Soulbeast => "Soulbeast", + Daredevil => "Daredevil", + Deadeye => "Deadeye", + Tempest => "Tempest", + Weaver => "Weaver", + Chronomancer => "Chronomancer", + Mirage => "Mirage", + Reaper => "Reaper", + Scourge => "Scourge", + } + } else { + match profession { + Guardian => "Guardian", + Warrior => "Warrior", + Revenant => "Revenant", + Engineer => "Engineer", + Ranger => "Ranger", + Thief => "Thief", + Elementalist => "Elementalist", + Mesmer => "Mesmer", + Necromancer => "Necromancer", } } } -- cgit v1.2.3