From f1a1785918236173cf86b3fdb69bacfa42eda2dd Mon Sep 17 00:00:00 2001 From: Shaydera Date: Sat, 21 Nov 2026 03:31:12 +0100 Subject: [PATCH] Count a druid's bear form from before the pull A Forever druid usually takes bear form long before a pull, which then holds no line of it, so a tanking Feral Combat druid counted as damage. The index now remembers each player's last logged bear form and gives every pull the state it began with. --- crates/openlogs-analysis/src/fight.rs | 2 + crates/openlogs-analysis/src/load.rs | 4 ++ crates/openlogs-analysis/src/talent_specs.rs | 6 +- crates/openlogs-analysis/tests/support/mod.rs | 1 + .../openlogs-analysis/tests/talent_specs.rs | 16 +++++ crates/openlogs-gamedata/src/lib.rs | 2 +- crates/openlogs-gamedata/src/talent_trees.rs | 3 - crates/openlogs-index/src/builder.rs | 63 ++++++++++++++++--- crates/openlogs-index/src/combat.rs | 1 + crates/openlogs-index/src/model.rs | 9 ++- crates/openlogs-index/src/scan.rs | 16 ++++- crates/openlogs-index/tests/combat_pulls.rs | 63 ++++++++++++++++--- crates/openlogs-index/tests/index_mini.rs | 2 + crates/openlogs-index/tests/index_runs.rs | 2 + crates/openlogs-service/src/test_fight.rs | 1 + 15 files changed, 165 insertions(+), 26 deletions(-) diff --git a/crates/openlogs-analysis/src/fight.rs b/crates/openlogs-analysis/src/fight.rs index 2b4243d..0300fbf 100644 --- a/crates/openlogs-analysis/src/fight.rs +++ b/crates/openlogs-analysis/src/fight.rs @@ -58,6 +58,8 @@ pub struct Fight { pub roster: BTreeSet, /// `(node, rank)` of each player's talents, from `COMBATANT_INFO` in the pull or the index. pub talents: HashMap>, + /// Players the index saw in a bear form when the pull began. + pub in_bear_form_at_start: BTreeSet, /// The log's game, which decides how player names are shown; `None` until the caller /// that knows the log sets it. pub flavor: Option, diff --git a/crates/openlogs-analysis/src/load.rs b/crates/openlogs-analysis/src/load.rs index 6020b09..612855d 100644 --- a/crates/openlogs-analysis/src/load.rs +++ b/crates/openlogs-analysis/src/load.rs @@ -80,6 +80,9 @@ fn apply_roster(fight: &mut Fight, roster: &[RosterEntry]) { continue; }; fight.roster.insert(id); + if entry.bear_form { + fight.in_bear_form_at_start.insert(id); + } if entry.spec_id != 0 && fight.actors.get(id).spec_id.is_none() { fight.actors.set_spec(id, entry.spec_id); } @@ -273,6 +276,7 @@ impl FightBuilder { heal_grants: Vec::new(), delayed_hits: Vec::new(), talents: HashMap::new(), + in_bear_form_at_start: BTreeSet::new(), roster: BTreeSet::new(), flavor: None, }, diff --git a/crates/openlogs-analysis/src/talent_specs.rs b/crates/openlogs-analysis/src/talent_specs.rs index 29dfcad..301d630 100644 --- a/crates/openlogs-analysis/src/talent_specs.rs +++ b/crates/openlogs-analysis/src/talent_specs.rs @@ -1,4 +1,5 @@ -use openlogs_gamedata::{BEAR_FORMS, Role, TalentTrees, TreeRole, tree_role}; +use openlogs_gamedata::{Role, TalentTrees, TreeRole, tree_role}; +use openlogs_index::BEAR_FORMS; use crate::actors::{ActorId, TalentSpec}; use crate::auras::{AuraInterval, aura_intervals, union_ms}; @@ -64,5 +65,8 @@ fn bear_form_share(fight: &Fight, bear_forms: &[AuraInterval], player: ActorId) .filter(|interval| interval.target == player) .map(|interval| (interval.start_ms, interval.end_ms)) .collect(); + if spans.is_empty() && fight.in_bear_form_at_start.contains(&player) { + return 1.0; + } union_ms(&spans, 0, duration) as f64 / f64::from(duration) } diff --git a/crates/openlogs-analysis/tests/support/mod.rs b/crates/openlogs-analysis/tests/support/mod.rs index e36ddee..03603a0 100644 --- a/crates/openlogs-analysis/tests/support/mod.rs +++ b/crates/openlogs-analysis/tests/support/mod.rs @@ -48,6 +48,7 @@ impl FightBuilder { heal_grants: Vec::new(), delayed_hits: Vec::new(), talents: HashMap::new(), + in_bear_form_at_start: BTreeSet::new(), roster: BTreeSet::new(), flavor: None, }, diff --git a/crates/openlogs-analysis/tests/talent_specs.rs b/crates/openlogs-analysis/tests/talent_specs.rs index 528fa86..466ba6f 100644 --- a/crates/openlogs-analysis/tests/talent_specs.rs +++ b/crates/openlogs-analysis/tests/talent_specs.rs @@ -102,6 +102,22 @@ fn a_feral_druid_tanks_a_pull_spent_in_bear_form() { ); } +#[test] +fn a_feral_druid_who_began_the_pull_in_bear_form_tanks_it() { + let mut b = FightBuilder::new(60_000); + let druid = b.player("Player-1", "Brakk-Thornfield-Normal-EU", 1484); + b.fight.talents.insert(druid, vec![(FERAL_NODE, 31)]); + b.fight.in_bear_form_at_start.insert(druid); + let mut fight = b.build(); + + assign_talent_specs(&mut fight, &trees()); + + assert_eq!( + shown(&fight, druid).map(|(_, _, role)| role), + Some(Role::Tank) + ); +} + #[test] fn shown_spec_prefers_the_retail_spec() { let mut b = FightBuilder::new(60_000); diff --git a/crates/openlogs-gamedata/src/lib.rs b/crates/openlogs-gamedata/src/lib.rs index 9d985c4..a7eb1a2 100644 --- a/crates/openlogs-gamedata/src/lib.rs +++ b/crates/openlogs-gamedata/src/lib.rs @@ -50,5 +50,5 @@ pub use specs::{ClassInfo, Role, SpecInfo, class, classes, spec, specs}; pub use spell_classes::{SpellClasses, SpellClassesError}; pub use spell_icons::{SpellIconError, SpellIconTable}; pub use talent_trees::{ - BEAR_FORMS, TalentTree, TalentTreeCsvs, TalentTrees, TalentTreesError, TreeRole, tree_role, + TalentTree, TalentTreeCsvs, TalentTrees, TalentTreesError, TreeRole, tree_role, }; diff --git a/crates/openlogs-gamedata/src/talent_trees.rs b/crates/openlogs-gamedata/src/talent_trees.rs index f38a39e..c39e1cd 100644 --- a/crates/openlogs-gamedata/src/talent_trees.rs +++ b/crates/openlogs-gamedata/src/talent_trees.rs @@ -8,9 +8,6 @@ use crate::csv_columns::{MissingColumn, column}; use crate::specs::Role; use crate::spell_icons::{SpellIconError, read_icon_files}; -/// Bear Form and Dire Bear Form. -pub const BEAR_FORMS: [u32; 2] = [5487, 9634]; - /// `TraitNode.PosX` where the middle and the right column of a class tree begin. const COLUMN_STARTS: [i64; 2] = [4000, 8000]; diff --git a/crates/openlogs-index/src/builder.rs b/crates/openlogs-index/src/builder.rs index 0dc8b04..770f247 100644 --- a/crates/openlogs-index/src/builder.rs +++ b/crates/openlogs-index/src/builder.rs @@ -1,17 +1,17 @@ use std::collections::{BTreeMap, HashMap, HashSet, VecDeque}; use openlogs_parser::{ - ChallengeModeEnd, ChallengeModeStart, CombatEvent, CombatKind, EncounterEnd, EncounterStart, - Event, LogLine, Timestamp, + AuraAction, ChallengeModeEnd, ChallengeModeStart, CombatEvent, CombatKind, EncounterEnd, + EncounterStart, Event, LogLine, Timestamp, }; use crate::combat::{DeadEnemies, Exchange, KnownSpec, OpenCombat, counted_damage, exchange}; use crate::markers::MarkerState; use crate::model::{ - BOSS_TAIL_MICROS, ChallengeMode, DUNGEON_DIFFICULTIES, END_GRACE_LINES, END_GRACE_MICROS, - FightSummary, GameFlavor, LEAD_MAX_MICROS, LogIndex, MYTHIC_KEYSTONE_DIFFICULTY, MapBounds, - Outcome, PRELUDE_MICROS, RESUME_MAX_GAP_MICROS, RosterEntry, RunKind, SUPPORTED_LOG_VERSION, - WorldMarker, + BEAR_FORMS, BOSS_TAIL_MICROS, ChallengeMode, DUNGEON_DIFFICULTIES, END_GRACE_LINES, + END_GRACE_MICROS, FightSummary, GameFlavor, LEAD_MAX_MICROS, LogIndex, + MYTHIC_KEYSTONE_DIFFICULTY, MapBounds, Outcome, PRELUDE_MICROS, RESUME_MAX_GAP_MICROS, + RosterEntry, RunKind, SUPPORTED_LOG_VERSION, WorldMarker, }; use crate::runs::{OpenRun, run_outcome}; @@ -55,6 +55,8 @@ pub struct IndexBuilder { last_specs: HashMap, /// Position of each talent list in the index's `talent_sets`. talent_set_ids: HashMap, u32>, + /// Players in one of the [`BEAR_FORMS`] as the log last showed; tracked for Forever only. + bears: HashSet, markers: MarkerState, /// Latest bounds per `MAP_CHANGE` map ID; facts about the map, so never reset. map_bounds: BTreeMap, @@ -88,6 +90,7 @@ impl IndexBuilder { zone_difficulty: 0, last_specs: HashMap::new(), talent_set_ids: HashMap::new(), + bears: HashSet::new(), markers: MarkerState::default(), map_bounds: BTreeMap::new(), last_index: 0, @@ -101,6 +104,41 @@ impl IndexBuilder { self.open.is_some() } + /// Whether the index reads the bear form lines outside fights, which only Forever needs. + pub fn tracks_bear_forms(&self) -> bool { + self.index.flavor == Some(GameFlavor::Forever) + } + + /// A bear form line outside boss pulls, which is otherwise skipped like other aura lines. + pub fn note_bear_form_line(&mut self, line: &LogLine<'_>) { + if let Event::Combat(event) = &line.event { + self.note_bear_form(event); + } + } + + fn note_bear_form(&mut self, event: &CombatEvent<'_>) { + let CombatKind::Aura(change) = event.kind else { + return; + }; + if !self.tracks_bear_forms() + || event.source.guid != event.target.guid + || !event + .spell + .is_some_and(|spell| BEAR_FORMS.contains(&spell.id)) + { + return; + } + match change.action { + AuraAction::Applied => { + self.bears.insert(event.target.guid.to_string()); + } + AuraAction::Removed => { + self.bears.remove(event.target.guid); + } + _ => {} + } + } + /// Records a line outside boss pulls that was only parsed up to its event name. pub fn push_skipped(&mut self, span: LineSpan, timestamp: Timestamp) { self.release_end(None); @@ -183,15 +221,17 @@ impl IndexBuilder { talent_set: (self.index.flavor == Some(GameFlavor::Forever)) .then(|| self.talent_set(info.talents().collect())), }; + let bear = self.bears.contains(info.guid); if let Some(fight) = &mut self.open { - add_combatant(&mut fight.summary.roster, info.guid, &known); + add_combatant(&mut fight.summary.roster, info.guid, &known, bear); } if let Some(run) = &mut self.run { - add_combatant(&mut run.summary.roster, info.guid, &known); + add_combatant(&mut run.summary.roster, info.guid, &known, bear); } self.last_specs.insert(info.guid.to_string(), known); } Event::Combat(event) => { + self.note_bear_form(event); if self.run.as_mut().is_some_and(|run| run.learn_copy(event)) { self.settle_copy(); } @@ -847,7 +887,11 @@ impl IndexBuilder { let Some(combat) = &mut self.combat else { return; }; + let known_players = combat.summary.roster.len(); combat.observe(event, span, timestamp, spent); + for entry in &mut combat.summary.roster[known_players..] { + entry.bear_form = self.bears.contains(&entry.guid); + } if let CombatKind::UnitDied { unconscious: false } = event.kind && let Some(outcome) = combat.on_death(event.target.guid) { @@ -950,13 +994,14 @@ fn extend(summary: &mut FightSummary, span: LineSpan, timestamp: Timestamp) { summary.end_offset = span.next_offset; } -fn add_combatant(roster: &mut Vec, guid: &str, known: &KnownSpec) { +fn add_combatant(roster: &mut Vec, guid: &str, known: &KnownSpec, bear: bool) { if roster.iter().all(|entry| entry.guid != guid) { roster.push(RosterEntry { guid: guid.to_string(), name: None, spec_id: known.spec_id, talent_set: known.talent_set, + bear_form: bear, }); } } diff --git a/crates/openlogs-index/src/combat.rs b/crates/openlogs-index/src/combat.rs index a57582c..0869632 100644 --- a/crates/openlogs-index/src/combat.rs +++ b/crates/openlogs-index/src/combat.rs @@ -200,6 +200,7 @@ impl OpenCombat { name: player.name.map(str::to_string), spec_id: 0, talent_set: None, + bear_form: false, }); } } diff --git a/crates/openlogs-index/src/model.rs b/crates/openlogs-index/src/model.rs index 4a20489..ce4e0e0 100644 --- a/crates/openlogs-index/src/model.rs +++ b/crates/openlogs-index/src/model.rs @@ -4,7 +4,7 @@ use openlogs_parser::Timestamp; use serde::{Deserialize, Serialize}; /// Bumped whenever the index layout or its rules change; invalidates cached indexes. -pub const INDEX_FORMAT_VERSION: u32 = 19; +pub const INDEX_FORMAT_VERSION: u32 = 20; /// The combat log format this tool is built and tested against. pub const SUPPORTED_LOG_VERSION: u32 = 22; /// Lookback before `ENCOUNTER_START` that belongs to a fight (pre-pots, pre-casts). @@ -101,6 +101,9 @@ impl DataGame { } } +/// Bear Form and Dire Bear Form: a Feral Combat druid's time in them decides whether they tank. +pub const BEAR_FORMS: [u32; 2] = [5487, 9634]; + /// Difficulty ID of Mythic+ (Mythic Keystone) dungeons; run entries carry it too. pub const MYTHIC_KEYSTONE_DIFFICULTY: u32 = 8; /// Difficulties whose visit is a dungeon run: Normal, Heroic, Mythic, Timewalking, Follower. @@ -316,6 +319,10 @@ pub struct RosterEntry { /// whose spec comes from them. #[serde(default, skip_serializing_if = "Option::is_none")] pub talent_set: Option, + /// In one of the [`BEAR_FORMS`] when the pull began, as the log last showed; kept for + /// Forever only. Forms taken long before a pull leave no line inside it. + #[serde(default, skip_serializing_if = "std::ops::Not::not")] + pub bear_form: bool, } /// Display name of a difficulty ID; `None` for unknown IDs, which are shown raw. diff --git a/crates/openlogs-index/src/scan.rs b/crates/openlogs-index/src/scan.rs index 7b9ffa1..5d2978b 100644 --- a/crates/openlogs-index/src/scan.rs +++ b/crates/openlogs-index/src/scan.rs @@ -4,7 +4,7 @@ use std::path::Path; use openlogs_parser::{Lines, RawLine, parse_header, parse_line}; use crate::builder::{IndexBuilder, LineSpan}; -use crate::model::LogIndex; +use crate::model::{BEAR_FORMS, LogIndex}; /// Events that matter to the index even outside fights. Mythic+ runs start, end and list /// their players between boss pulls. @@ -40,6 +40,14 @@ const COMBAT_PULL_EVENTS: [&str; 15] = [ "UNIT_DIED", ]; +/// Entering or leaving a bear form, which a pull begun later inherits. +fn is_bear_form_line(name: &str, text: &str) -> bool { + matches!(name, "SPELL_AURA_APPLIED" | "SPELL_AURA_REMOVED") + && BEAR_FORMS + .iter() + .any(|spell| text.contains(&format!(",{spell},"))) +} + /// A longer line is no combat log line. It counts as broken instead of being kept, which bounds /// the memory a wrong file (a video, an archive) can take. const MAX_LINE_BYTES: u64 = 1 << 20; @@ -152,6 +160,12 @@ impl Indexer { Ok((timestamp, name)) if !META_EVENTS.contains(&name) && !COMBAT_PULL_EVENTS.contains(&name) => { + if self.builder.tracks_bear_forms() + && is_bear_form_line(name, text) + && let Ok(line) = parse_line(text, fields) + { + self.builder.note_bear_form_line(&line); + } self.builder.push_skipped(span, timestamp); return; } diff --git a/crates/openlogs-index/tests/combat_pulls.rs b/crates/openlogs-index/tests/combat_pulls.rs index c8b99c6..adb6f0b 100644 --- a/crates/openlogs-index/tests/combat_pulls.rs +++ b/crates/openlogs-index/tests/combat_pulls.rs @@ -431,22 +431,63 @@ fn combat_pulls_take_the_last_known_spec() { /// A boss pull with Faelan's combatant info, then a trash pull, logged by `project_id`. fn boss_then_trash(project_id: u32) -> String { + boss_then_trash_with(project_id, "", "") +} + +/// [`boss_then_trash`] with `before` logged before the boss pull and `between` after it. +fn boss_then_trash_with(project_id: u32, before: &str, between: &str) -> String { [ - &format!("10/7/2026 19:03:00.0000 COMBAT_LOG_VERSION,22,ADVANCED_LOG_ENABLED,1,BUILD_VERSION,1.60.1,PROJECT_ID,{project_id} -"), - "10/7/2026 19:03:02.0762 ENCOUNTER_START,3492,\"Ula'tek\",15,23,3004 -", - "10/7/2026 19:03:02.0762 COMBATANT_INFO,Player-4101-8E8C0182,1,100,200,300,400,0,0,0,0,10,10,10,0,92,1025,1025,1025,230,807,110,110,110,2726,1488,[(105722,130451,5),(105724,130453,3)],(0,0,0,0),[(249976,330,(),(7364,0),())],[],57,0,0,0 -", + &format!("10/7/2026 19:03:00.0000 COMBAT_LOG_VERSION,22,ADVANCED_LOG_ENABLED,1,BUILD_VERSION,1.60.1,PROJECT_ID,{project_id}\n"), + before, + "10/7/2026 19:03:02.0762 ENCOUNTER_START,3492,\"Ula'tek\",15,23,3004\n", + "10/7/2026 19:03:02.0762 COMBATANT_INFO,Player-4101-8E8C0182,1,100,200,300,400,0,0,0,0,10,10,10,0,92,1025,1025,1025,230,807,110,110,110,2726,1488,[(105722,130451,5),(105724,130453,3)],(0,0,0,0),[(249976,330,(),(7364,0),())],[],57,0,0,0\n", &hit("10/7/2026 19:03:03.0000", &FAELAN, &KNIGHT, 100), - "10/7/2026 19:04:02.0762 ENCOUNTER_END,3492,\"Ula'tek\",15,23,0,60000 -", + "10/7/2026 19:04:02.0762 ENCOUNTER_END,3492,\"Ula'tek\",15,23,0,60000\n", + between, &hit("10/7/2026 19:05:00.0000", &FAELAN, &KNIGHT, 100), &hit("10/7/2026 19:05:01.0000", &KNIGHT, &PYRRIN, 100), ] .concat() } +/// Faelan entering (`APPLIED`) or leaving (`REMOVED`) Dire Bear Form at `timestamp`. +fn dire_bear(timestamp: &str, action: &str) -> String { + format!( + "{timestamp} SPELL_AURA_{action},{guid},\"{name}\",0x511,0x0,{guid},\"{name}\",0x511,0x0,9634,\"Dire Bear Form\",0x1,BUFF\n", + guid = FAELAN.guid, + name = FAELAN.name, + ) +} + +/// Each pull's players who were in bear form when it began. +fn bears_of_pulls(index: &openlogs_index::LogIndex) -> Vec> { + index + .fights + .iter() + .map(|fight| { + fight + .roster + .iter() + .filter(|entry| entry.bear_form) + .map(|entry| entry.guid.as_str()) + .collect() + }) + .collect() +} + +#[test] +fn a_forever_pull_knows_who_began_it_in_bear_form() { + let log = boss_then_trash_with( + 18, + &dire_bear("10/7/2026 19:02:00.0000", "APPLIED"), + &dire_bear("10/7/2026 19:04:30.0000", "REMOVED"), + ); + assert_eq!( + bears_of_pulls(&index_bytes(log.as_bytes())), + [vec![FAELAN.guid], vec![]] + ); +} + /// Each player's `(node, rank)` talents, by GUID. type RosterTalents<'a> = Vec<(&'a str, Vec<(u32, u32)>)>; @@ -483,9 +524,11 @@ fn a_forever_combat_pull_keeps_the_last_logged_talents() { } #[test] -fn a_retail_index_keeps_no_talents() { - let index = index_bytes(boss_then_trash(1).as_bytes()); +fn a_retail_index_keeps_no_talents_or_bear_forms() { + let log = boss_then_trash_with(1, &dire_bear("10/7/2026 19:02:00.0000", "APPLIED"), ""); + let index = index_bytes(log.as_bytes()); assert!(index.talent_sets.is_empty()); + assert!(bears_of_pulls(&index).iter().all(Vec::is_empty)); } #[test] diff --git a/crates/openlogs-index/tests/index_mini.rs b/crates/openlogs-index/tests/index_mini.rs index 38f8b8f..7a7cf4f 100644 --- a/crates/openlogs-index/tests/index_mini.rs +++ b/crates/openlogs-index/tests/index_mini.rs @@ -68,12 +68,14 @@ fn wipe_with_roster_boss_hp_and_prelude() { name: Some("Faelan-Emberfall-EU".into()), spec_id: 62, talent_set: None, + bear_form: false, }, RosterEntry { guid: "Player-4101-77D4A765".into(), name: Some("Pyrrin-Emberfall-EU".into()), spec_id: 105, talent_set: None, + bear_form: false, }, ] ); diff --git a/crates/openlogs-index/tests/index_runs.rs b/crates/openlogs-index/tests/index_runs.rs index 8383e5e..7d16c49 100644 --- a/crates/openlogs-index/tests/index_runs.rs +++ b/crates/openlogs-index/tests/index_runs.rs @@ -122,12 +122,14 @@ fn a_run_is_indexed_with_its_key_its_roster_and_its_prelude() { name: Some("Faelan-Emberfall-EU".into()), spec_id: 62, talent_set: None, + bear_form: false, }, RosterEntry { guid: "Player-4101-77D4A765".into(), name: Some("Pyrrin-Emberfall-EU".into()), spec_id: 105, talent_set: None, + bear_form: false, }, ] ); diff --git a/crates/openlogs-service/src/test_fight.rs b/crates/openlogs-service/src/test_fight.rs index a95bebc..44c1498 100644 --- a/crates/openlogs-service/src/test_fight.rs +++ b/crates/openlogs-service/src/test_fight.rs @@ -48,6 +48,7 @@ pub fn fight(actors: Actors, mut events: Vec) -> Fight { heal_grants: Vec::new(), delayed_hits: Vec::new(), talents: HashMap::new(), + in_bear_form_at_start: BTreeSet::new(), roster: BTreeSet::new(), flavor: None, }