Skip to main content

wowlab_engine_domain/rotation/buffer/
player.rs

1wowlab_engine_macros::define_slot! {
2    #[slot(domain = "player", kind = singleton)]
3    pub struct PlayerSlot {
4        #[expr("gcd_is_active", Float, TimestampActive)]
5        #[expr("gcd_remaining", Float, TimestampRemaining)]
6        pub gcd_end: f64,
7
8        pub cast_end: f64,
9        pub channel_end: f64,
10
11        #[expr("haste", Float, Direct)]
12        pub haste: f64,
13
14        #[expr("crit", Float, Direct)]
15        pub crit: f64,
16
17        #[expr("mastery", Float, Direct)]
18        pub mastery: f64,
19
20        #[expr("versatility", Float, Direct)]
21        pub versatility: f64,
22
23        #[expr("attack_power", Float, Direct)]
24        pub attack_power: f64,
25
26        #[expr("spell_power", Float, Direct)]
27        pub spell_power: f64,
28
29        #[expr("level", Int, Direct)]
30        pub level: i32,
31
32        #[expr("is_moving", Bool, Direct)]
33        pub is_moving: i32,
34
35        #[expr("is_alive", Bool, Direct)]
36        pub is_alive: i32,
37
38        #[expr("is_in_combat", Bool, Direct)]
39        pub in_combat: i32,
40
41        #[expr("is_stealthed", Bool, Direct)]
42        pub stealthed: i32,
43
44        pub shapeshift_form: i32,
45
46        #[expr("is_mounted", Bool, Direct)]
47        pub mounted: i32,
48
49        _padding: i32,
50
51        #[expr("movement_remaining", Float, TimestampRemaining)]
52        pub movement_end: f64,
53
54        #[expr("stamina", Float, Direct)]
55        pub stamina: f64,
56
57        #[expr("armor", Float, Direct)]
58        pub armor: f64,
59
60        #[expr("primary_stat", Float, Direct)]
61        pub primary_stat: f64,
62
63        #[expr("gcd_duration", Float, Direct)]
64        pub gcd_duration: f64,
65
66        #[expr("gcd_max", Float, Direct)]
67        pub gcd_max: f64,
68    }
69
70    impl {
71        #[inline]
72        pub fn set_haste(&mut self, val: f64) {
73            self.haste = val;
74        }
75
76        #[inline]
77        #[must_use]
78        pub fn haste_factor(&self) -> f64 {
79            1.0 + self.haste / wowlab_types::constants::HUNDRED
80        }
81    }
82}
83
84#[cfg(test)]
85mod tests {
86    use googletest::prelude::*;
87    use rstest::rstest;
88
89    use super::*;
90
91    #[gtest]
92    #[rstest]
93    #[case(0.0, 1.0)]
94    #[case(100.0, 2.0)]
95    #[case(25.0, 1.25)]
96    #[case(-50.0, 0.5)]
97    fn haste_factor_scales_from_percent(#[case] haste: f64, #[case] expected: f64) -> Result<()> {
98        let slot = PlayerSlot {
99            haste,
100            ..Default::default()
101        };
102
103        verify_that!(slot.haste_factor(), near(expected, 1e-9))
104    }
105}