Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/openlogs-analysis/src/fight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ pub struct Fight {
pub roster: BTreeSet<ActorId>,
/// `(node, rank)` of each player's talents, from `COMBATANT_INFO` in the pull or the index.
pub talents: HashMap<ActorId, Vec<(u32, u32)>>,
/// Players the index saw in a bear form when the pull began.
pub in_bear_form_at_start: BTreeSet<ActorId>,
/// The log's game, which decides how player names are shown; `None` until the caller
/// that knows the log sets it.
pub flavor: Option<GameFlavor>,
Expand Down
4 changes: 4 additions & 0 deletions crates/openlogs-analysis/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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,
},
Expand Down
6 changes: 5 additions & 1 deletion crates/openlogs-analysis/src/talent_specs.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions crates/openlogs-analysis/tests/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
16 changes: 16 additions & 0 deletions crates/openlogs-analysis/tests/talent_specs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion crates/openlogs-gamedata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
3 changes: 0 additions & 3 deletions crates/openlogs-gamedata/src/talent_trees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
63 changes: 54 additions & 9 deletions crates/openlogs-index/src/builder.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -55,6 +55,8 @@ pub struct IndexBuilder {
last_specs: HashMap<String, KnownSpec>,
/// Position of each talent list in the index's `talent_sets`.
talent_set_ids: HashMap<Vec<(u32, u32)>, u32>,
/// Players in one of the [`BEAR_FORMS`] as the log last showed; tracked for Forever only.
bears: HashSet<String>,
markers: MarkerState,
/// Latest bounds per `MAP_CHANGE` map ID; facts about the map, so never reset.
map_bounds: BTreeMap<u32, MapBounds>,
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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<RosterEntry>, guid: &str, known: &KnownSpec) {
fn add_combatant(roster: &mut Vec<RosterEntry>, 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,
});
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/openlogs-index/src/combat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ impl OpenCombat {
name: player.name.map(str::to_string),
spec_id: 0,
talent_set: None,
bear_form: false,
});
}
}
Expand Down
9 changes: 8 additions & 1 deletion crates/openlogs-index/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -316,6 +319,10 @@ pub struct RosterEntry {
/// whose spec comes from them.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub talent_set: Option<u32>,
/// 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.
Expand Down
16 changes: 15 additions & 1 deletion crates/openlogs-index/src/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
63 changes: 53 additions & 10 deletions crates/openlogs-index/tests/combat_pulls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<&str>> {
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)>)>;

Expand Down Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions crates/openlogs-index/tests/index_mini.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
]
);
Expand Down
Loading
Loading