1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use serde::Deserialize;
use std::ops::RangeInclusive;

//  _____ _                           _
// | ____| | ___ _ __ ___   ___ _ __ | |_
// |  _| | |/ _ \ '_ ` _ \ / _ \ '_ \| __|
// | |___| |  __/ | | | | |  __/ | | | |_
// |_____|_|\___|_| |_| |_|\___|_| |_|\__|
//

#[derive(Copy, Clone, Debug, Deserialize, Eq, PartialEq, Hash)]
pub enum Element {
    Earth,
    Water,
    Air,
    Fire,
    Neutral,
}

impl Element {
    /// Return the element that boosts the damages applied in this element.
    pub fn effective_stat(&self) -> Element {
        match self {
            Self::Neutral => Self::Earth,
            _ => *self,
        }
    }
}

//  ____                                   _     _
// |  _ \  __ _ _ __ ___   __ _  __ _  ___| |   (_)_ __   ___
// | | | |/ _` | '_ ` _ \ / _` |/ _` |/ _ \ |   | | '_ \ / _ \
// | |_| | (_| | | | | | | (_| | (_| |  __/ |___| | | | |  __/
// |____/ \__,_|_| |_| |_|\__,_|\__, |\___|_____|_|_| |_|\___|
//                              |___/

#[derive(Debug, Deserialize)]
pub enum Effect {
    Hit {
        element: Element,
        bounds:  RangeInclusive<u8>,

        #[serde(default)]
        lifesteal: bool,
    },
}

#[derive(Debug, Deserialize)]
pub struct SpellEffects {
    pub effect: Vec<Effect>,
    pub ranged: bool,

    #[serde(default = "default_false")]
    pub weapon: bool,

    #[serde(default = "default_spell_critical")]
    pub critical: u8,

    #[serde(default)]
    pub critical_effect: Vec<Effect>,
}

/// Default spell critical chances.
fn default_spell_critical() -> u8 {
    5
}

fn default_false() -> bool {
    false
}