Skip to main content

wowlab_engine_combat/systems/damage_pipeline/
absorbs.rs

1//! Outgoing damage absorption.
2
3use wowlab_types::{
4    combat::{DamageSchool, HitResult},
5    sim::{ActorId, EnemyIdx},
6};
7
8use crate::state::{AbsorbKind, CombatState, ProcHitMask};
9
10#[derive(Clone, Copy, Debug)]
11pub(in crate::systems) struct OutgoingDamageResolution {
12    pub(super) amount: f64,
13    pub(super) hit_mask: ProcHitMask,
14}
15
16pub(in crate::systems) fn resolve_outgoing_absorbs(
17    state: &mut CombatState,
18    target: EnemyIdx,
19    school: DamageSchool,
20    amount: f64,
21    hit_result: HitResult,
22) -> OutgoingDamageResolution {
23    let mut hit_mask = ProcHitMask::from_hit_result(hit_result);
24    let absorbed = crate::systems::absorbs::consume_absorbs(
25        state,
26        ActorId::Enemy(target),
27        AbsorbKind::Damage,
28        wowlab_engine_domain::dbc::SpellSchoolMask::from(school),
29        amount,
30    );
31    let amount = (amount - absorbed).max(0.0);
32
33    if absorbed > f64::EPSILON {
34        hit_mask |= ProcHitMask::ABSORB;
35    }
36
37    if amount <= f64::EPSILON {
38        hit_mask.remove(ProcHitMask::NORMAL | ProcHitMask::CRITICAL | ProcHitMask::GLANCE);
39    }
40
41    OutgoingDamageResolution { amount, hit_mask }
42}