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

use openlogs_parser::unit_flags::{
AFFILIATION_GROUP, CONTROL_NPC, REACTION_FRIENDLY, REACTION_HOSTILE, TYPE_GUARDIAN, TYPE_PET,
};
use openlogs_parser::{NULL_GUID, Unit};

/// Index into [`Actors`]. [`NOBODY`] stands for an empty unit slot.
pub type ActorId = u32;
pub const NOBODY: ActorId = 0;

const TYPE_PET: u32 = 0x1000;
const TYPE_GUARDIAN: u32 = 0x2000;
/// Affiliation mine | party | raid.
const AFFILIATION_GROUP: u32 = 0x7;
const REACTION_FRIENDLY: u32 = 0x10;
const REACTION_HOSTILE: u32 = 0x40;
const CONTROL_NPC: u32 = 0x200;
/// Owner chains longer than this are treated as broken (cycles, bad data).
const MAX_OWNER_DEPTH: usize = 8;

Expand All @@ -36,10 +32,15 @@ pub struct Actor {
/// Lines that logged this actor hostile, and lines that did not.
hostile_lines: u32,
other_lines: u32,
/// Logged as an NPC-controlled friendly unit on a line outside the logging player's turns.
logged_friendly: bool,
fought_group: bool,
/// Direct owner (summoner) of a pet or guardian.
pub owner: Option<ActorId>,
/// From `COMBATANT_INFO`, players only.
pub spec_id: Option<u32>,
/// From the player's own casts, for players without a known spec; see [`Actor::class`].
pub class_id: Option<u32>,
/// Largest item level the advanced block reported; players only.
pub item_level: Option<u32>,
/// Largest max HP the advanced block reported; players only.
Expand All @@ -57,12 +58,29 @@ impl Actor {
self.hostile_lines > self.other_lines
}

/// The spec's class, else the class the player's casts belong to.
pub fn class(&self) -> Option<u32> {
self.spec_class().or(self.class_id)
}

pub fn spec_class(&self) -> Option<u32> {
spec_class(self.spec_id)
}

/// 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()
}
}

/// The class of a spec the game data knows; a spec of 0 (none chosen) or an unknown one has
/// none, so the class then comes from casts.
pub fn spec_class(spec_id: Option<u32>) -> Option<u32> {
spec_id
.and_then(openlogs_gamedata::spec)
.map(|spec| spec.class_id)
}

/// An NPC-controlled unit logged friendly: how enemies look while the logging player is turned
/// against the raid.
pub(crate) fn npc_logged_friendly(unit: &Unit<'_>) -> bool {
Expand Down Expand Up @@ -93,8 +111,11 @@ impl Actors {
flags: 0,
hostile_lines: 0,
other_lines: 0,
logged_friendly: false,
fought_group: false,
owner: None,
spec_id: None,
class_id: None,
item_level: None,
max_hp: None,
}],
Expand All @@ -109,8 +130,11 @@ impl Actors {
actor.flags = 0;
actor.hostile_lines = 0;
actor.other_lines = 0;
actor.logged_friendly = false;
actor.fought_group = false;
actor.owner = None;
actor.spec_id = None;
actor.class_id = None;
actor.item_level = None;
actor.max_hp = None;
}
Expand Down Expand Up @@ -157,8 +181,11 @@ impl Actors {
flags: 0,
hostile_lines: 0,
other_lines: 0,
logged_friendly: false,
fought_group: false,
owner: None,
spec_id: None,
class_id: None,
item_level: None,
max_hp: None,
});
Expand Down Expand Up @@ -213,6 +240,10 @@ impl Actors {
}
}

pub(crate) fn set_class(&mut self, unit: ActorId, class_id: Option<u32>) {
self.list[unit as usize].class_id = class_id;
}

/// 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 Expand Up @@ -256,6 +287,27 @@ impl Actors {
pub fn is_enemy(&self, id: ActorId) -> bool {
self.is_unowned_npc(id) && self.get(id).mostly_hostile()
}

/// An unowned NPC that fought the group and was never logged friendly outside the logging
/// player's turns: it stands against the raid even on lines that log it neutral.
pub(crate) fn fights_group_unfriendly(&self, id: ActorId) -> bool {
let actor = self.get(id);
actor.fought_group && !actor.logged_friendly
}

pub(crate) fn note_logged_friendly(&mut self, id: ActorId) {
self.list[id as usize].logged_friendly = true;
}

/// Marks the unowned NPCs on one side of a damage or miss with a player or a player's pet
/// on the other. Needs the pull's final owners.
pub(crate) fn note_fought_group(&mut self, source: ActorId, target: ActorId) {
for (npc, other) in [(source, target), (target, source)] {
if self.is_unowned_npc(npc) && self.credited_player(other).is_some() {
self.list[npc as usize].fought_group = true;
}
}
}
}

fn kind_from_guid(guid: &str) -> ActorKind {
Expand Down
44 changes: 44 additions & 0 deletions crates/openlogs-analysis/src/classes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use std::collections::HashMap;

use openlogs_gamedata::SpellClasses;

use crate::actors::ActorId;
use crate::fight::{EventKind, Fight};

/// Gives each player without a known spec the class most of their own casts belong to. A tie,
/// or no cast of a class spell, leaves the class unset; casts by their pets do not count.
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())
.map(|player| (player.id, HashMap::new()))
.collect();
for event in &fight.events {
if event.kind != EventKind::CastSuccess {
continue;
}
if let (Some(per_class), Some(class)) = (
casts.get_mut(&event.source),
spell_classes.class_of(event.spell),
) {
*per_class.entry(class).or_default() += 1;
}
}
for (player, per_class) in casts {
fight.actors.set_class(player, most_cast(&per_class));
}
}

fn most_cast(casts_per_class: &HashMap<u32, u32>) -> Option<u32> {
let mut ranked: Vec<(u32, u32)> = casts_per_class
.iter()
.map(|(&class, &casts)| (casts, class))
.collect();
ranked.sort_unstable_by(|a, b| b.cmp(a));
match ranked.as_slice() {
[(first, _), (second, _), ..] if first == second => None,
[(_, class), ..] => Some(*class),
[] => None,
}
}
10 changes: 7 additions & 3 deletions crates/openlogs-analysis/src/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use openlogs_gamedata::Curated;
use crate::ability::unit_name;
use crate::actors::ActorId;
use crate::deaths::nth_death_ms;
use crate::fight::Fight;
use crate::fight::{Fight, listed_player};
use crate::filter::{Attribution, Overkill, ReportFilter};
use crate::overview::{QuickOverview, quick_overview_in};
use crate::reports::damage::damage_done;
Expand Down Expand Up @@ -117,15 +117,19 @@ fn sort_key(row: &ComparedPlayer) -> (u8, f64) {
}
}

/// The players of one pull by GUID: everyone with a spec, plus anyone who did damage or
/// The players of one pull by GUID: every listed player, plus anyone who did damage or
/// healing or died there (an Evoker outside the raid, a player without `COMBATANT_INFO`).
fn player_sides(
fight: &Fight,
overview: &QuickOverview,
filter: &ReportFilter,
) -> HashMap<String, PlayerSide> {
let mut sides: HashMap<ActorId, PlayerSide> = HashMap::new();
for player in fight.actors.players().filter(|p| p.spec_id.is_some()) {
for player in fight
.actors
.players()
.filter(|p| listed_player(fight, p.id))
{
side(&mut sides, player.id);
}
for player in damage_done(fight, filter).players {
Expand Down
32 changes: 25 additions & 7 deletions crates/openlogs-analysis/src/fight.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::collections::BTreeMap;
use std::collections::{BTreeMap, BTreeSet};

use openlogs_index::{MapBounds, Outcome};
pub use openlogs_parser::{AuraAction, AuraType, DamageVia};

use crate::actors::{ActorId, Actors, NOBODY};
use crate::actors::{ActorId, ActorKind, Actors, NOBODY};

pub type SpellId = u32;
/// Spell of melee swings, environmental damage and deaths.
Expand Down Expand Up @@ -53,6 +53,9 @@ pub struct Fight {
/// What Refractive Images took of hits, as `(event index, amount)` sorted by index, on the
/// line the hit counts on; see [`Fight::delayed_part`].
pub delayed_hits: Vec<(u32, u64)>,
/// 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>,
}

impl Fight {
Expand Down Expand Up @@ -94,15 +97,19 @@ impl Fight {
self.against_raid_at(event.target, event.target_logged_hostile, event.t)
}

/// Whether `actor`, logged `hostile` on a line at `t`, stands against the raid. While the
/// logging player is turned the log swaps the sides: an unowned NPC then counts by how it
/// was logged over the pull, and players and their pets by the swapped flag.
/// Whether `actor`, logged `hostile` on a line at `t`, stands against the raid. A neutral
/// NPC that fought the group does too. While the logging player is turned the log swaps the
/// sides: an unowned NPC then counts by how it was logged over the pull, and players and
/// their pets by the swapped flag.
pub fn against_raid_at(&self, actor: ActorId, hostile: bool, t: i32) -> bool {
if actor == NOBODY || !self.logger_turned_at(t) {
if actor == NOBODY {
return hostile;
}
if !self.logger_turned_at(t) {
return hostile || self.actors.fights_group_unfriendly(actor);
}
if self.actors.is_unowned_npc(actor) {
self.actors.is_enemy(actor)
self.actors.is_enemy(actor) || self.actors.fights_group_unfriendly(actor)
} else {
!hostile
}
Expand All @@ -127,6 +134,17 @@ pub enum FightKind {
Pull,
/// A Mythic+ run, `CHALLENGE_MODE_START` to `CHALLENGE_MODE_END`.
Run,
/// A fight against NPCs outside a boss encounter; it has no bosses.
Combat,
}

/// Whether the player belongs on the fight's player lists: a player with a spec, or one who
/// fought in a combat pull, where most players have no `COMBATANT_INFO`.
pub fn listed_player(fight: &Fight, id: ActorId) -> bool {
let actor = fight.actors.get(id);
actor.kind == ActorKind::Player
&& (actor.spec_id.is_some()
|| (fight.kind == FightKind::Combat && fight.roster.contains(&id)))
}

/// A boss encounter inside a Mythic+ run, in ms since the run started.
Expand Down
6 changes: 4 additions & 2 deletions crates/openlogs-analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod auras;
mod breakdown;
mod casts;
mod cells;
mod classes;
mod compare;
mod deaths;
mod deaths_report;
Expand Down Expand Up @@ -35,7 +36,7 @@ mod usage;
mod views;

pub use ability::{AbilityDetail, AbilityHit, TargetHits, ability_detail};
pub use actors::{Actor, ActorId, ActorKind, Actors, NOBODY};
pub use actors::{Actor, ActorId, ActorKind, Actors, NOBODY, 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 All @@ -44,6 +45,7 @@ pub use breakdown::{
};
pub use casts::{CastExtra, CastsReport, casts_report};
pub use cells::{Cell, CellKind, Misses, ScopeMetric, cells};
pub use classes::infer_classes;
pub use compare::{ComparedPlayer, PlayerSide, PullComparison, compare_pulls};
pub use deaths::{
AbilityAmount, BURST_GAP_MS, DEATH_WINDOW_MS, Death, Hit, LethalBurst, Resurrection, deaths,
Expand All @@ -55,7 +57,7 @@ pub use fight::{
Absorbed, AuraAction, AuraType, Damage, DamageVia, Energize, Event, EventKind, FailReason,
Fight, FightKind, Heal, HealAbsorbed, LANDED_MATCH_MS, MarkerInterval, MissType, Missed,
NO_SPELL, POWER_SAMPLE_MS, PositionSample, PowerSample, RunEncounter, SpellId, SpellInfo,
UnitHp, WorldMarkerInterval,
UnitHp, WorldMarkerInterval, listed_player,
};
pub use filter::{Attribution, Overkill, ReportFilter};
pub use granted::note_heal_grants;
Expand Down
34 changes: 32 additions & 2 deletions crates/openlogs-analysis/src/load.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::collections::{BTreeMap, HashMap, VecDeque};
use std::collections::{BTreeMap, BTreeSet, HashMap, VecDeque};
use std::fs::File;
use std::io;
use std::path::Path;

use openlogs_index::{FightSummary, MapBounds, Outcome};
use openlogs_index::{FightSummary, MapBounds, Outcome, RosterEntry};
use openlogs_parser::{
CombatEvent, CombatKind, EncounterEnd, EncounterStart, Event as LogEvent, HealVia, Lines,
LogLine, Spell, Timestamp, parse_line,
Expand Down Expand Up @@ -71,12 +71,27 @@ fn load_slice(
}
let late = builder.landed_after_end(&data[end..], &mut fields);
let mut fight = builder.finish();
// A combat pull's specs come from `COMBATANT_INFO` before its range, which only the index
// read; a spec logged inside the range wins.
apply_roster(&mut fight, &summary.roster);
let unpaired = pair_landed_copies(&mut fight);
mark_swings_landing_after_end(&mut fight, unpaired, &late);
note_delayed_hits(&mut fight);
fight
}

fn apply_roster(fight: &mut Fight, roster: &[RosterEntry]) {
for entry in roster {
let Some(id) = fight.actors.id(&entry.guid) else {
continue;
};
fight.roster.insert(id);
if entry.spec_id != 0 && fight.actors.get(id).spec_id.is_none() {
fight.actors.set_spec(id, entry.spec_id);
}
}
}

/// A `SWING_DAMAGE_LANDED` logged after the fight's end, of units the fight knows.
struct LateLanded {
t: i32,
Expand Down Expand Up @@ -227,6 +242,8 @@ impl FightBuilder {
fight: Fight {
kind: if summary.is_run() {
FightKind::Run
} else if summary.is_combat() {
FightKind::Combat
} else {
FightKind::Pull
},
Expand Down Expand Up @@ -261,6 +278,7 @@ impl FightBuilder {
logger_turned: Vec::new(),
heal_grants: Vec::new(),
delayed_hits: Vec::new(),
roster: BTreeSet::new(),
},
last_power: HashMap::new(),
last_t: i32::MIN,
Expand Down Expand Up @@ -362,11 +380,23 @@ impl FightBuilder {
.max_by_key(|&(&map, &count)| (count, std::cmp::Reverse(map)))
.map(|(&map, _)| map);
self.fight.events.sort_by_key(|event| event.t);
for event in &self.fight.events {
if matches!(event.kind, EventKind::Damage(_) | EventKind::Missed(_)) {
self.fight
.actors
.note_fought_group(event.source, event.target);
}
}
self.fight.power.sort_by_key(|p| p.t);
self.fight.npc_power.sort_by_key(|p| p.t);
self.fight.positions.sort_by_key(|p| p.t);
self.friendly_npc_lines.sort_by_key(|&(t, _)| t);
self.fight.logger_turned = logger_turned_spans(&self.fight, &self.friendly_npc_lines);
for &(t, id) in &self.friendly_npc_lines {
if !self.fight.logger_turned_at(t) {
self.fight.actors.note_logged_friendly(id);
}
}
note_heal_grants(&mut self.fight);
self.fight
}
Expand Down
Loading
Loading