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
7 changes: 5 additions & 2 deletions crates/openlogs-analysis/src/fight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,9 @@ pub struct Damage {
/// For a `SWING_DAMAGE_LANDED`: the index in [`Fight::events`] of the hit's attacker-side
/// line, set by [`crate::pair_melee_lines`].
pub attacker_line: Option<u32>,
/// A swing whose `SWING_DAMAGE_LANDED` copy is logged after the pull's end.
pub lands_after_end: bool,
/// A swing the pull shows no `SWING_DAMAGE_LANDED` copy of, in a pull whose log writes
/// them; set by [`crate::pair_melee_lines`].
pub unlanded: bool,
}

impl Damage {
Expand Down Expand Up @@ -349,6 +350,8 @@ pub struct Missed {
/// Prevented amount for partial misses, else 0.
pub amount_missed: u64,
pub critical: bool,
/// Like [`Damage::unlanded`], for a swing a shield took whole.
pub unlanded: bool,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
Expand Down
3 changes: 1 addition & 2 deletions crates/openlogs-analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ pub use interrupts::{
};
pub use links::AbilityLink;
pub use load::{
LANDED_TAIL_BYTES, load_fight, load_fight_file, load_fight_slice, load_fight_slice_with,
pair_melee_lines,
load_fight, load_fight_file, load_fight_slice, load_fight_slice_with, pair_melee_lines,
};
pub use meter::{Meter, MeterCategory, MeterEntry, MeterKey, MeterRow, meter};
pub use options::{FilterOption, OptionValue, SpellVariant, filter_options};
Expand Down
115 changes: 30 additions & 85 deletions crates/openlogs-analysis/src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ pub fn load_fight(data: &[u8], summary: &FightSummary) -> Fight {
load_fight_slice(data, 0, summary)
}

/// How far past a fight's end a part of the log should reach, so that the landed copies of
/// its last swings are in it.
pub const LANDED_TAIL_BYTES: u64 = 2 * 1024 * 1024;

/// Loads one fight from a part of the log that starts at byte `base_offset` and covers the
/// fight from its prelude to its end, plus up to [`LANDED_TAIL_BYTES`] after it.
/// fight from its prelude to its end.
pub fn load_fight_slice(data: &[u8], base_offset: u64, summary: &FightSummary) -> Fight {
load_slice(data, base_offset, summary, Actors::new(), true)
}
Expand Down Expand Up @@ -69,13 +65,11 @@ fn load_slice(
Err(_) => builder.fight.broken_lines += 1,
}
}
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);
pair_melee_lines(&mut fight);
note_delayed_hits(&mut fight);
fight
}
Expand All @@ -92,14 +86,6 @@ fn apply_roster(fight: &mut Fight, roster: &[RosterEntry]) {
}
}

/// A `SWING_DAMAGE_LANDED` logged after the fight's end, of units the fight knows.
struct LateLanded {
t: i32,
source: ActorId,
target: ActorId,
melee_total: u64,
}

enum MeleeLine {
/// `SWING_DAMAGE`, or `SWING_MISSED` ABSORB for a hit a shield took whole.
Attacker,
Expand All @@ -120,24 +106,35 @@ fn melee_line(event: &Event) -> Option<(MeleeLine, u64)> {
}
}

/// Pairs each melee hit's landed copy with its attacker-side line, as loading does, for a
/// fight built without loading it. A landed copy left without one is the hit itself.
/// Pairs each melee hit's landed copy with its attacker-side line and marks the swings left
/// without one, as loading does, for a fight built without loading it. A landed copy left
/// without an attacker-side line is the hit itself.
pub fn pair_melee_lines(fight: &mut Fight) {
pair_landed_copies(fight);
let unlanded = pair_landed_copies(fight);
for line in unlanded {
match &mut fight.events[line].kind {
EventKind::Damage(damage) => damage.unlanded = true,
EventKind::Missed(missed) => missed.unlanded = true,
_ => {}
}
}
}

/// Pairs each landed copy with its attacker-side line, which the log writes up to
/// [`LANDED_MATCH_MS`] before or after it, and records that line in the copy. Returns the
/// attacker-side lines of the last [`LANDED_MATCH_MS`] that are still unpaired.
fn pair_landed_copies(fight: &mut Fight) -> VecDeque<(usize, u64)> {
/// attacker-side lines left without a copy; none when the pull has no landed copy at all, as
/// in logs that do not write them.
fn pair_landed_copies(fight: &mut Fight) -> Vec<usize> {
let mut attackers: VecDeque<(usize, u64)> = VecDeque::new();
let mut landed: VecDeque<(usize, u64)> = VecDeque::new();
let mut unlanded = Vec::new();
let mut pairs = Vec::new();
let mut any_landed = false;
for index in 0..fight.events.len() {
let event = &fight.events[index];
let expired = |&(line, _): &(usize, u64)| event.t - fight.events[line].t > LANDED_MATCH_MS;
while attackers.front().is_some_and(expired) {
attackers.pop_front();
while let Some(attacker) = attackers.pop_front_if(|a| expired(a)) {
unlanded.push(attacker.0);
}
while landed.front().is_some_and(expired) {
landed.pop_front();
Expand All @@ -147,7 +144,10 @@ fn pair_landed_copies(fight: &mut Fight) -> VecDeque<(usize, u64)> {
};
let (unpaired, other_side) = match side {
MeleeLine::Attacker => (&mut attackers, &mut landed),
MeleeLine::Landed => (&mut landed, &mut attackers),
MeleeLine::Landed => {
any_landed = true;
(&mut landed, &mut attackers)
}
};
let pair = |&(line, other_total): &(usize, u64)| {
let other = &fight.events[line];
Expand All @@ -169,30 +169,11 @@ fn pair_landed_copies(fight: &mut Fight) -> VecDeque<(usize, u64)> {
damage.attacker_line = u32::try_from(attacker).ok();
}
}
attackers
}

/// Flags the swings among `unpaired` whose landed copy is one of `late`.
fn mark_swings_landing_after_end(
fight: &mut Fight,
mut unpaired: VecDeque<(usize, u64)>,
late: &[LateLanded],
) {
for copy in late {
let landed_after = |&(line, total): &(usize, u64)| {
let swing = &fight.events[line];
total == copy.melee_total
&& swing.source == copy.source
&& swing.target == copy.target
&& copy.t - swing.t <= LANDED_MATCH_MS
};
if let Some(position) = unpaired.iter().position(landed_after)
&& let Some((swing, _)) = unpaired.remove(position)
&& let EventKind::Damage(damage) = &mut fight.events[swing].kind
{
damage.lands_after_end = true;
}
if !any_landed {
return Vec::new();
}
unlanded.extend(attackers.into_iter().map(|(line, _)| line));
unlanded
}

/// Memory-maps `path` and loads one fight from it.
Expand Down Expand Up @@ -505,43 +486,6 @@ impl FightBuilder {
FailReason::Other(u16::try_from(index).unwrap_or(u16::MAX))
}

/// The landed copies in `tail`, the lines after the fight, until they could no longer
/// belong to one of its swings.
fn landed_after_end<'a>(&self, tail: &'a [u8], fields: &mut Vec<&'a str>) -> Vec<LateLanded> {
let end = i32::try_from(self.fight.duration_ms).unwrap_or(i32::MAX);
let actors = &self.fight.actors;
let mut late = Vec::new();
for raw in Lines::new(tail) {
let Ok(line) = raw.text().and_then(|text| parse_line(text, fields)) else {
continue;
};
let t = self.relative_ms(line.timestamp);
if t > end.saturating_add(LANDED_MATCH_MS) {
break;
}
let LogEvent::Combat(event) = &line.event else {
continue;
};
let CombatKind::Damage(damage) = event.kind else {
continue;
};
if damage.via != DamageVia::SwingLanded || damage.supporter.is_some() {
continue;
}
if let (Some(source), Some(target)) =
(actors.id(event.source.guid), actors.id(event.target.guid))
{
late.push(LateLanded {
t,
source,
target,
melee_total: damage.amount + damage.absorbed,
});
}
}
late
}

fn relative_ms(&self, timestamp: Timestamp) -> i32 {
((timestamp.0 - self.start.0) / 1_000).clamp(i64::from(i32::MIN), i64::from(i32::MAX))
as i32
Expand Down Expand Up @@ -673,13 +617,14 @@ impl FightBuilder {
critical: d.critical,
supporter: self.actor(d.supporter),
attacker_line: None,
lands_after_end: false,
unlanded: false,
}),
CombatKind::Missed(m) => EventKind::Missed(Missed {
via: m.via,
miss_type: MissType::from_log(m.miss_type),
amount_missed: m.amount_missed.unwrap_or(0),
critical: m.critical,
unlanded: false,
}),
CombatKind::Heal(h) => EventKind::Heal(Heal {
periodic: h.via == HealVia::Periodic,
Expand Down
35 changes: 22 additions & 13 deletions crates/openlogs-analysis/src/reports/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,18 +663,19 @@ pub(crate) fn keeps_support(
) -> SupportParts {
if scope.selects_all() {
return SupportParts {
buffed: true,
buffed: support.hit_counts,
credit: true,
};
}
let target = unit_of(fight, support.target);
SupportParts {
buffed: scope.accepts(
fight,
Some(&unit_of(fight, support.doer)),
ability,
Some(&target),
),
buffed: support.hit_counts
&& scope.accepts(
fight,
Some(&unit_of(fight, support.doer)),
ability,
Some(&target),
),
credit: scope.accepts(
fight,
Some(&UnitRef::Player(support.evoker)),
Expand Down Expand Up @@ -860,6 +861,8 @@ pub(crate) struct Support {
pub buff: SpellId,
pub target: ActorId,
pub amount: u64,
/// Whether the buffed hit is in the numbers itself; the Evoker's share counts either way.
pub hit_counts: bool,
}

/// The parts of an amount that went into or came from shields, and that heal absorbs took.
Expand Down Expand Up @@ -914,16 +917,15 @@ impl Absorbs {
}
}

/// Damage done: hits on enemies (see [`hits_enemy`]), credited through pets.
/// Support from an unknown Evoker is not a share.
/// Damage done: hits on enemies (see [`hits_enemy`]), credited through pets. The Evoker's share
/// of a hit a player dealt themselves counts for the Evoker alone. Support from an unknown Evoker
/// is not a share.
pub(crate) fn damage_share(fight: &Fight, event: &Event, overkill: Overkill) -> Option<Share> {
let damage = dealt_damage(event)?;
if !hits_enemy(fight, event) {
return None;
}
let player = fight.actors.credited_player(event.source)?;
let on_enemy = hits_enemy(fight, event);
if damage.supporter == NOBODY {
return credited_as_damage_done(&damage).then_some(Share::Own {
return (on_enemy && credited_as_damage_done(&damage)).then_some(Share::Own {
player,
actor: event.source,
spell: event.spell,
Expand All @@ -935,13 +937,19 @@ pub(crate) fn damage_share(fight: &Fight, event: &Event, overkill: Overkill) ->
});
}
let evoker = fight.actors.credited_player(damage.supporter)?;
let self_hit_buffed_by_another =
evoker != player && fight.actors.credited_player(event.target) == Some(player);
if !(on_enemy || self_hit_buffed_by_another) {
return None;
}
Some(Share::Support(Support {
player,
evoker,
doer: event.source,
buff: event.spell,
target: event.target,
amount: damage_done_amount(&damage, overkill),
hit_counts: on_enemy,
}))
}

Expand Down Expand Up @@ -1057,6 +1065,7 @@ pub(crate) fn healing_share(fight: &Fight, event: &Event) -> Option<Share> {
buff: spell,
target: event.target,
amount,
hit_counts: true,
}))
}

Expand Down
8 changes: 4 additions & 4 deletions crates/openlogs-analysis/src/timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ pub fn is_distinct_hit(damage: &Damage) -> bool {
}
}

/// Whether a hit is in the Damage Done numbers. They leave out a swing whose landed copy is
/// logged after the pull's end, mostly the boss's killing blow.
/// Whether a hit is in the Damage Done numbers. They leave out a swing the log never shows
/// landing in the pull, like the boss's killing blow or a hit on a unit logged neutral.
pub(crate) fn credited_as_damage_done(damage: &Damage) -> bool {
is_distinct_hit(damage) && !damage.lands_after_end
is_distinct_hit(damage) && !damage.unlanded
}

/// The damage an event deals its target. A hit a shield swallowed completely is logged as an
Expand All @@ -43,7 +43,7 @@ pub(crate) fn dealt_damage(event: &Event) -> Option<Damage> {
critical: missed.critical,
supporter: NOBODY,
attacker_line: None,
lands_after_end: false,
unlanded: missed.unlanded,
}),
_ => None,
}
Expand Down
44 changes: 23 additions & 21 deletions crates/openlogs-analysis/src/views/parts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,27 +184,29 @@ fn own_side(
miss: None,
row,
});
let (spell, kind) = match hit {
Some((_, spell)) => (spell, CellKind::Own),
None => (NO_SPELL, CellKind::Unmatched),
};
book(Part {
source: support.doer,
spell,
kind,
target: support.target,
amount: -amount,
absorbed: -(deducted.absorbed as i64),
heal_absorbed: -(deducted.heal_absorbed as i64),
overheal: 0,
healed: 0,
hit: false,
cost: false,
crit: false,
periodic,
miss: None,
row,
});
if support.hit_counts {
let (spell, kind) = match hit {
Some((_, spell)) => (spell, CellKind::Own),
None => (NO_SPELL, CellKind::Unmatched),
};
book(Part {
source: support.doer,
spell,
kind,
target: support.target,
amount: -amount,
absorbed: -(deducted.absorbed as i64),
heal_absorbed: -(deducted.heal_absorbed as i64),
overheal: 0,
healed: 0,
hit: false,
cost: false,
crit: false,
periodic,
miss: None,
row,
});
}
}
_ => {}
}
Expand Down
Loading
Loading