Skip to main content

wowlab_engine_application/game_data/spells/
resources.rs

1use wowlab_engine_domain::dbc::{
2    PassiveQuery, cost_entry_index, primary_cost, primary_cost_pct, primary_max_cost_pct,
3    primary_optional_cost, primary_optional_cost_pct, primary_power_burn_cost,
4    primary_resource_gain, secondary_cost, secondary_optional_cost, secondary_resource_gain,
5};
6use wowlab_types::data::{SpellDataFlat, SpellResources};
7
8use super::context::SpellResolutionContext;
9
10pub(super) fn resolve_spell_resources(
11    context: &SpellResolutionContext<'_, '_>,
12    spell: &SpellDataFlat,
13) -> SpellResources {
14    let (primary, actives) = (context.primary_resource_type, context.active_aura_spell_ids);
15    let base_primary_cost = primary_cost(spell, primary, context.power_modifiers, actives).0;
16    let primary_cost = modified_resource_cost(context, spell, primary, base_primary_cost);
17    let base_secondary_cost = secondary_cost(
18        spell,
19        context.secondary_resource_type,
20        context.power_modifiers,
21        context.active_aura_spell_ids,
22    );
23    let secondary_cost = context
24        .secondary_resource_type
25        .map_or(base_secondary_cost, |kind| {
26            modified_resource_cost(context, spell, kind, base_secondary_cost)
27        });
28    let secondary_optional_cost = secondary_optional_cost(
29        spell,
30        context.secondary_resource_type,
31        context.power_modifiers,
32        context.active_aura_spell_ids,
33    );
34    let health = wowlab_engine_domain::dbc::health_cost(spell, actives);
35
36    SpellResources {
37        primary_cost,
38        primary_optional_cost: primary_optional_cost(
39            spell,
40            context.primary_resource_type,
41            context.power_modifiers,
42            context.active_aura_spell_ids,
43        ) + primary_power_burn_cost(
44            spell,
45            context.primary_resource_type,
46            context.power_modifiers,
47        ),
48        primary_cost_pct: primary_cost_pct(spell, primary, actives),
49        primary_max_cost_pct: primary_max_cost_pct(spell, primary, actives),
50        primary_optional_cost_pct: primary_optional_cost_pct(spell, primary, actives),
51        primary_gain: primary_resource_gain(
52            spell,
53            context.primary_resource_type,
54            context.power_modifiers,
55        ),
56        secondary_cost,
57        secondary_optional_cost,
58        secondary_gain: secondary_resource_gain(
59            spell,
60            context.secondary_resource_type,
61            context.power_modifiers,
62        ),
63        health_cost: health.cost,
64        health_cost_pct: health.cost_pct,
65        health_max_cost_pct: health.max_cost_pct,
66        health_optional_cost: health.optional_cost,
67        health_optional_cost_pct: health.optional_cost_pct,
68        primary_cost_entry: cost_entry_index(spell, Some(primary), actives),
69        secondary_cost_entry: cost_entry_index(spell, context.secondary_resource_type, actives),
70    }
71}
72
73fn modified_resource_cost(
74    context: &SpellResolutionContext<'_, '_>,
75    spell: &SpellDataFlat,
76    resource_type: i32,
77    base_cost: f64,
78) -> f64 {
79    if base_cost <= 0.0 {
80        return base_cost;
81    }
82
83    wowlab_engine_domain::dbc::passive_resource_cost(
84        PassiveQuery {
85            passives: context.passives,
86            spell,
87        },
88        resource_type,
89        base_cost,
90        context.active_aura_spell_ids,
91        context.power_modifiers,
92    )
93}