wowlab_engine_combat/builder/def/
damage.rs1#[derive(Clone, Copy, Debug)]
2#[non_exhaustive]
3pub(crate) enum BuilderDamageDef {
4 None,
5 Flat(f64),
6 ApCoefficient {
7 coef: f64,
8 is_physical: bool,
9 ap_type: crate::state::WeaponApType,
10 },
11 SpCoefficient {
12 coef: f64,
13 is_physical: bool,
14 },
15 Weapon {
16 multiplier: f64,
17 flat_bonus: f64,
18 normalized: bool,
19 is_physical: bool,
20 hand: crate::state::WeaponApType,
21 },
22}
23
24impl BuilderDamageDef {
25 pub(crate) fn from_resolved(
26 def: wowlab_engine_gamedata::ResolvedDamageDef,
27 off_hand_ap_multiplier: f64,
28 ) -> Option<Self> {
29 use wowlab_engine_gamedata::{ResolvedDamageKind, ResolvedDamageWeapon};
30
31 let hand = match def.weapon {
32 ResolvedDamageWeapon::MainHand => crate::state::WeaponApType::MainHand,
33 ResolvedDamageWeapon::OffHand => crate::state::WeaponApType::OffHand,
34 _ => return None,
35 };
36
37 Some(match def.kind {
38 ResolvedDamageKind::Ap => Self::ApCoefficient {
39 coef: def.coefficient
40 * if hand == crate::state::WeaponApType::OffHand {
41 off_hand_ap_multiplier
42 } else {
43 1.0
44 },
45 is_physical: def.is_physical,
46 ap_type: hand,
47 },
48 ResolvedDamageKind::Sp => Self::SpCoefficient {
49 coef: def.coefficient,
50 is_physical: def.is_physical,
51 },
52 ResolvedDamageKind::Flat => Self::Flat(def.base_points),
53 ResolvedDamageKind::Weapon
54 | ResolvedDamageKind::WeaponPercent
55 | ResolvedDamageKind::NormalizedWeapon => Self::Weapon {
56 multiplier: def.coefficient,
57 flat_bonus: def.base_points,
58 normalized: matches!(def.kind, ResolvedDamageKind::NormalizedWeapon),
59 is_physical: def.is_physical,
60 hand,
61 },
62 _ => return None,
63 })
64 }
65
66 pub(crate) fn scaled(self, multiplier: f64) -> Self {
67 match self {
68 Self::None => Self::None,
69 Self::Flat(amount) => Self::Flat(amount * multiplier),
70 Self::ApCoefficient {
71 coef,
72 is_physical,
73 ap_type,
74 } => Self::ApCoefficient {
75 coef: coef * multiplier,
76 is_physical,
77 ap_type,
78 },
79 Self::SpCoefficient { coef, is_physical } => Self::SpCoefficient {
80 coef: coef * multiplier,
81 is_physical,
82 },
83 Self::Weapon {
84 multiplier: weapon_multiplier,
85 flat_bonus,
86 normalized,
87 is_physical,
88 hand,
89 } => Self::Weapon {
90 multiplier: weapon_multiplier * multiplier,
91 flat_bonus: flat_bonus * multiplier,
92 normalized,
93 is_physical,
94 hand,
95 },
96 }
97 }
98}