Skip to main content

wowlab_engine_combat/context/hook/
proc_counters.rs

1use crate::context::HookCtx;
2
3pub(super) fn add(ctx: &mut HookCtx<'_>, driver_spell_id: u32, amount: u32) -> u32 {
4    let count = get(ctx, driver_spell_id).saturating_add(amount);
5
6    ctx.state
7        .runtime
8        .procs
9        .proc_counters
10        .insert(driver_spell_id, count);
11
12    count
13}
14
15pub(super) fn reset(ctx: &mut HookCtx<'_>, driver_spell_id: u32) {
16    ctx.state
17        .runtime
18        .procs
19        .proc_counters
20        .remove(&driver_spell_id);
21}
22
23pub(super) fn get(ctx: &HookCtx<'_>, driver_spell_id: u32) -> u32 {
24    ctx.state
25        .runtime
26        .procs
27        .proc_counters
28        .get(&driver_spell_id)
29        .copied()
30        .unwrap_or(0)
31}
32
33pub(super) fn mark_once(ctx: &mut HookCtx<'_>, driver_spell_id: u32, flags: u32) -> bool {
34    if flags == 0 {
35        return false;
36    }
37
38    let current = get(ctx, driver_spell_id);
39
40    if current & flags != 0 {
41        return false;
42    }
43
44    ctx.state
45        .runtime
46        .procs
47        .proc_counters
48        .insert(driver_spell_id, current | flags);
49
50    true
51}
52
53pub(super) fn consume(ctx: &mut HookCtx<'_>, driver_spell_id: u32, amount: u32) -> u32 {
54    let remaining = get(ctx, driver_spell_id).saturating_sub(amount);
55
56    if remaining == 0 {
57        reset(ctx, driver_spell_id);
58    } else {
59        ctx.state
60            .runtime
61            .procs
62            .proc_counters
63            .insert(driver_spell_id, remaining);
64    }
65
66    remaining
67}
68
69pub(super) fn advance(
70    ctx: &mut HookCtx<'_>,
71    driver_spell_id: u32,
72    amount: u32,
73    threshold: u32,
74) -> bool {
75    if threshold == 0 {
76        return false;
77    }
78
79    let count = add(ctx, driver_spell_id, amount);
80
81    if count >= threshold {
82        reset(ctx, driver_spell_id);
83
84        true
85    } else {
86        false
87    }
88}