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
43 changes: 43 additions & 0 deletions crates/openlogs-analysis/src/actors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::HashMap;

use openlogs_gamedata::Role;
use openlogs_parser::unit_flags::{
AFFILIATION_GROUP, CONTROL_NPC, REACTION_FRIENDLY, REACTION_HOSTILE, TYPE_GUARDIAN, TYPE_PET,
};
Expand Down Expand Up @@ -45,6 +46,26 @@ pub struct Actor {
pub item_level: Option<u32>,
/// Largest max HP the advanced block reported; players only.
pub max_hp: Option<u64>,
/// The talent tree a player of a game without specs put most points into; see
/// [`crate::assign_talent_specs`].
pub talent_spec: Option<TalentSpec>,
}

/// A talent tree as a player's spec, with their role in this pull.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TalentSpec {
pub tree_id: u32,
pub name: String,
pub icon: String,
pub role: Role,
}

/// The spec a player is shown with: their spec, else their talent spec.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ShownSpec<'a> {
pub name: &'a str,
pub icon: &'a str,
pub role: Role,
}

impl Actor {
Expand All @@ -67,6 +88,21 @@ impl Actor {
spec_class(self.spec_id)
}

pub fn shown_spec(&self) -> Option<ShownSpec<'_>> {
match self.spec_id.and_then(openlogs_gamedata::spec) {
Some(spec) => Some(ShownSpec {
name: &spec.name,
icon: &spec.icon,
role: spec.role,
}),
None => self.talent_spec.as_ref().map(|spec| ShownSpec {
name: &spec.name,
icon: &spec.icon,
role: spec.role,
}),
}
}

/// Belongs to the logging player's group (mine, party or raid) and is not hostile.
pub fn is_friendly(&self) -> bool {
self.flags & AFFILIATION_GROUP != 0 && !self.is_hostile()
Expand Down Expand Up @@ -118,6 +154,7 @@ impl Actors {
class_id: None,
item_level: None,
max_hp: None,
talent_spec: None,
}],
by_guid: HashMap::new(),
}
Expand All @@ -137,6 +174,7 @@ impl Actors {
actor.class_id = None;
actor.item_level = None;
actor.max_hp = None;
actor.talent_spec = None;
}
carried
}
Expand Down Expand Up @@ -188,6 +226,7 @@ impl Actors {
class_id: None,
item_level: None,
max_hp: None,
talent_spec: None,
});
self.by_guid.insert(guid.to_string(), id);
id
Expand Down Expand Up @@ -244,6 +283,10 @@ impl Actors {
self.list[unit as usize].class_id = class_id;
}

pub(crate) fn set_talent_spec(&mut self, unit: ActorId, spec: Option<TalentSpec>) {
self.list[unit as usize].talent_spec = spec;
}

/// Records a player's item level and max HP from an advanced block, keeping the largest.
pub fn note_advanced(&mut self, unit: ActorId, level: u32, max_hp: u64) {
let actor = &mut self.list[unit as usize];
Expand Down
2 changes: 1 addition & 1 deletion crates/openlogs-analysis/src/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn infer_classes(fight: &mut Fight, spell_classes: &SpellClasses) {
let mut casts: HashMap<ActorId, HashMap<u32, u32>> = fight
.actors
.players()
.filter(|player| player.spec_class().is_none())
.filter(|player| player.class().is_none())
.map(|player| (player.id, HashMap::new()))
.collect();
for event in &fight.events {
Expand Down
4 changes: 3 additions & 1 deletion crates/openlogs-analysis/src/fight.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{BTreeMap, BTreeSet};
use std::collections::{BTreeMap, BTreeSet, HashMap};

use openlogs_index::{GameFlavor, MapBounds, Outcome};
pub use openlogs_parser::{AuraAction, AuraType, DamageVia};
Expand Down Expand Up @@ -56,6 +56,8 @@ pub struct Fight {
/// The index's roster: players with `COMBATANT_INFO` in a boss pull or run, the players
/// who fought in a combat pull.
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)>>,
/// 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: 3 additions & 1 deletion crates/openlogs-analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ mod reports;
mod resources;
mod run_result;
mod scope;
mod talent_specs;
mod targets;
mod timeline;
mod turned;
mod usage;
mod views;

pub use ability::{AbilityDetail, AbilityHit, TargetHits, ability_detail};
pub use actors::{Actor, ActorId, ActorKind, Actors, NOBODY, spec_class};
pub use actors::{Actor, ActorId, ActorKind, Actors, NOBODY, ShownSpec, TalentSpec, spec_class};
pub use aura_report::{AuraHolder, AuraLane, AuraRow, AurasReport, SourceSpec, auras_report};
pub use auras::{AuraInterval, aura_intervals, coverage, union_ms};
pub use breakdown::{
Expand Down Expand Up @@ -98,6 +99,7 @@ pub use resources::{
};
pub use run_result::{BossProgress, RunResult, run_result};
pub use scope::{AbilityRef, Scope, Side, UnitRef, side_of, unit_of};
pub use talent_specs::assign_talent_specs;
pub use targets::{
EnemyGroup, TargetDetail, UnitLife, WAVE_GAP_MS, Wave, enemy_groups, target_detail,
};
Expand Down
8 changes: 8 additions & 0 deletions crates/openlogs-analysis/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ fn apply_roster(fight: &mut Fight, roster: &[RosterEntry]) {
if entry.spec_id != 0 && fight.actors.get(id).spec_id.is_none() {
fight.actors.set_spec(id, entry.spec_id);
}
if !entry.talents.is_empty() {
fight
.talents
.entry(id)
.or_insert_with(|| entry.talents.clone());
}
}
}

Expand Down Expand Up @@ -259,6 +265,7 @@ impl FightBuilder {
logger_turned: Vec::new(),
heal_grants: Vec::new(),
delayed_hits: Vec::new(),
talents: HashMap::new(),
roster: BTreeSet::new(),
flavor: None,
},
Expand Down Expand Up @@ -288,6 +295,7 @@ impl FightBuilder {
LogEvent::CombatantInfo(info) => {
let id = self.fight.actors.intern_guid(info.guid);
self.fight.actors.set_spec(id, info.spec_id);
self.fight.talents.insert(id, info.talents().collect());
}
LogEvent::Combat(event) => {
let converted = self.convert(t, event);
Expand Down
2 changes: 2 additions & 0 deletions crates/openlogs-analysis/src/replay/units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct ReplayUnit {
pub name: String,
pub kind: UnitKind,
pub spec_id: Option<u32>,
pub spec_icon: Option<String>,
pub class_id: Option<u32>,
pub owner: Option<ActorId>,
/// Adds of one name are numbered from 1 in the order they were first positioned.
Expand Down Expand Up @@ -61,6 +62,7 @@ impl Roster {
name: actor.name.clone().unwrap_or_default(),
kind,
spec_id: actor.spec_id,
spec_icon: actor.shown_spec().map(|spec| spec.icon.to_string()),
class_id: actor.class(),
owner: actor.owner,
add_number: None,
Expand Down
68 changes: 68 additions & 0 deletions crates/openlogs-analysis/src/talent_specs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use openlogs_gamedata::{BEAR_FORMS, Role, TalentTrees, TreeRole, tree_role};

use crate::actors::{ActorId, TalentSpec};
use crate::auras::{AuraInterval, aura_intervals, union_ms};
use crate::fight::Fight;

/// A Feral Combat druid tanks a pull they spent at least this share of in Bear Form.
const BEAR_FORM_TANK_SHARE: f64 = 0.2;

/// Gives each player with talents the tree they put most points into, with their role in this
/// pull, and each player whose spec ID is one of the game's class specs that class.
pub fn assign_talent_specs(fight: &mut Fight, trees: &TalentTrees) {
let players: Vec<(ActorId, Option<u32>)> = fight
.actors
.players()
.map(|player| (player.id, player.spec_id))
.collect();
let mut bear_forms: Option<Vec<AuraInterval>> = None;
for (player, spec_id) in players {
let tree = fight
.talents
.get(&player)
.and_then(|talents| trees.spec_of(talents.iter().copied()));
let class = spec_id
.and_then(|spec_id| trees.class_of_spec(spec_id))
.or(tree.map(|tree| tree.class_id));
if class.is_some() {
fight.actors.set_class(player, class);
}
let spec = tree.map(|tree| TalentSpec {
tree_id: tree.id,
name: tree.name.clone(),
icon: tree.icon.clone(),
role: match tree_role(tree.id) {
TreeRole::Fixed(role) => role,
TreeRole::BearForm => {
let intervals = bear_forms.get_or_insert_with(|| bear_form_intervals(fight));
if bear_form_share(fight, intervals, player) >= BEAR_FORM_TANK_SHARE {
Role::Tank
} else {
Role::Damage
}
}
},
});
fight.actors.set_talent_spec(player, spec);
}
}

fn bear_form_intervals(fight: &Fight) -> Vec<AuraInterval> {
aura_intervals(fight)
.into_iter()
.filter(|interval| BEAR_FORMS.contains(&interval.spell))
.collect()
}

fn bear_form_share(fight: &Fight, bear_forms: &[AuraInterval], player: ActorId) -> f64 {
let duration = i32::try_from(fight.duration_ms).unwrap_or(i32::MAX);
if duration <= 0 {
return 0.0;
}
let spans: Vec<(i32, i32)> = bear_forms
.iter()
.filter(|interval| interval.target == player)
.map(|interval| (interval.start_ms, interval.end_ms))
.collect();
union_ms(&spans, 0, duration) as f64 / f64::from(duration)
}
2 changes: 2 additions & 0 deletions crates/openlogs-analysis/tests/replay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ fn units_are_classified_and_adds_numbered_per_name() {
name: name.into(),
kind,
spec_id: None,
spec_icon: None,
class_id: None,
owner: None,
add_number: None,
Expand All @@ -124,6 +125,7 @@ fn units_are_classified_and_adds_numbered_per_name() {
vec![
ReplayUnit {
spec_id: Some(62),
spec_icon: Some(openlogs_gamedata::spec(62).unwrap().icon.clone()),
class_id: Some(8),
..unit(mage, "Ilvaren", UnitKind::Player)
},
Expand Down
3 changes: 2 additions & 1 deletion crates/openlogs-analysis/tests/support/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Each test binary uses a different subset of these helpers.
#![allow(dead_code)]

use std::collections::{BTreeMap, BTreeSet};
use std::collections::{BTreeMap, BTreeSet, HashMap};

use openlogs_analysis::{
ActorId, Actors, Damage, DamageVia, Event, EventKind, Fight, FightKind, Heal, NO_SPELL, NOBODY,
Expand Down Expand Up @@ -47,6 +47,7 @@ impl FightBuilder {
logger_turned: Vec::new(),
heal_grants: Vec::new(),
delayed_hits: Vec::new(),
talents: HashMap::new(),
roster: BTreeSet::new(),
flavor: None,
},
Expand Down
Loading
Loading