firecore_battle/moves/
damage.rs

1use pokedex::{moves::Power, pokemon::Health, types::Effective};
2use serde::{Deserialize, Serialize};
3
4use super::Percent;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
7pub enum DamageKind {
8    Power(Power),
9    PercentCurrent(Percent),
10    PercentMax(Percent),
11    Constant(Health),
12}
13
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)]
15pub enum ClientDamage<N> {
16    Result(DamageResult<N>),
17    Number(N),
18}
19
20#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
21pub struct DamageResult<N> {
22    /// Inflicted damage
23    pub damage: N,
24    /// Whether the attack was effective
25    pub effective: Effective,
26    /// If the attack was a critical hit
27    pub crit: bool,
28}
29
30impl<N> ClientDamage<N> {
31    pub fn damage(self) -> N {
32        match self {
33            ClientDamage::Result(result) => result.damage,
34            ClientDamage::Number(n) => n,
35        }
36    }
37}
38
39impl<N: Default> Default for DamageResult<N> {
40    fn default() -> Self {
41        Self {
42            damage: Default::default(),
43            effective: Effective::Ineffective,
44            crit: false,
45        }
46    }
47}
48
49impl<N> From<N> for DamageResult<N> {
50    fn from(damage: N) -> Self {
51        Self {
52            damage,
53            effective: Effective::Effective,
54            crit: false,
55        }
56    }
57}