wowlab_engine_combat/systems/damage_pipeline/
snapshot.rs1use wowlab_engine_domain::rotation::DenseBuffer;
2use wowlab_types::sim::AuraKey;
3
4use super::{
5 DamageFlags, DamageRequest, WeaponDamageInput,
6 dispatch::run_single_hit,
7 setup::{DamageSetup, DamageSnapshot, SnapshotDamageContext, SnapshotDamageEvent},
8};
9use crate::context::CombatCtx;
10
11#[derive(Clone, Copy, Debug)]
12pub(crate) enum SnapshotPower {
13 Attack,
14 Spell,
15}
16
17pub(crate) fn read_aura_snapshot(buf: &DenseBuffer, key: AuraKey) -> Option<DamageSnapshot> {
18 let a = buf.aura(key)?;
19
20 if a.snapshot_has == 0 {
21 return None;
22 }
23
24 Some(DamageSnapshot {
25 ap: a.snapshot_ap,
26 sp: a.snapshot_sp,
27 crit_pct: a.snapshot_crit,
28 vers_pct: a.snapshot_vers,
29 mastery_mult: a.snapshot_mastery_mult,
30 damage_mult: a.snapshot_damage_mult,
31 })
32}
33
34pub(crate) fn deal_damage_with_snapshot(
35 ctx: &mut CombatCtx<'_>,
36 effect: crate::state::DamageEffectRef,
37 coef: f64,
38 flags: DamageFlags,
39 snap: &DamageSnapshot,
40 power: SnapshotPower,
41) -> (f64, bool) {
42 let spell_id = effect.spell_id;
43 let target = ctx.target;
44 let setup = DamageSetup::from_snapshot_for(
45 SnapshotDamageContext::new(
46 ctx.state,
47 ctx.buf,
48 SnapshotDamageEvent {
49 source: ctx.source,
50 target,
51 now: ctx.now,
52 },
53 ),
54 effect,
55 flags,
56 snap,
57 );
58
59 let power = match power {
60 SnapshotPower::Attack => snap.ap,
61 SnapshotPower::Spell => snap.sp,
62 };
63
64 run_single_hit(
65 ctx,
66 target,
67 &setup,
68 &DamageRequest {
69 effect,
70 geometry_effect: effect,
71 source_position: None,
72 destination: None,
73 profile_spell_id: spell_id,
74 base_points: None,
75 coef,
76 power,
77 weapon: WeaponDamageInput::none(),
78 flags: flags | DamageFlags::PERIODIC,
79 },
80 1.0,
81 )
82}