Skip to main content

wowlab_engine_combat/builder/aura_builder/
health_threshold.rs

1use wowlab_engine_domain::dbc::{AuraSubtypeKind, EffectLookup, aura_subtype_is};
2
3use super::{AuraDefinitionDraft, BuilderError};
4use crate::state::{BuffEffect, HealthThresholdDirection};
5
6pub(super) fn apply_from_data(
7    aura: AuraDefinitionDraft,
8    lookup: EffectLookup<'_>,
9) -> Result<AuraDefinitionDraft, BuilderError> {
10    let spell_id = lookup.effect.spell.as_u32();
11
12    if !aura_subtype_is(
13        lookup.effect_aura(),
14        AuraSubtypeKind::TriggerSpellBasedOnHealthPercent,
15    ) {
16        return Ok(aura);
17    }
18
19    let property = lookup.effect_misc_value_0();
20    let direction = match property {
21        0 => HealthThresholdDirection::Above,
22        1 => HealthThresholdDirection::Below,
23        _ => {
24            return Err(crate::builder::BuilderErrorKind::InvalidScalar {
25                spell_id,
26                field: "health_threshold.direction",
27                value: f64::from(property),
28            }
29            .into());
30        }
31    };
32    let triggered =
33        lookup
34            .trigger_spell()
35            .ok_or(crate::builder::BuilderErrorKind::MissingSpellData {
36                spell_id,
37                field: "health_threshold.trigger_spell",
38            })?;
39
40    aura.push_effect(BuffEffect::HealthThresholdTrigger {
41        threshold_pct: lookup.base_points(),
42        direction,
43        spell_id: triggered.as_u32(),
44    })
45}