aboutsummaryrefslogtreecommitdiffstats
path: root/src/shared/champion.rs
blob: 8de12a52e01ffe14031f7fe81e98f70aa507acd0 (plain)
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
use crate::shared::ability::*;
use crate::shared::*;
use std::str::FromStr;

#[derive(Component, Message, Clone, Copy, Serialize, Deserialize, PartialEq, Debug)]
pub enum Champion {
    Meele,
    Ranged,
}

impl Default for Champion {
    fn default() -> Champion {
        Champion::Meele
    }
}

impl FromStr for Champion {
    type Err = String;

    fn from_str(s: &str) -> Result<Champion, String> {
        match s {
            "ranged" => Ok(Champion::Ranged),
            "meele" => Ok(Champion::Meele),
            _ => Err(format!("unknown champion: {}", s)),
        }
    }
}

pub struct Stats {
    pub attack_range: f32,
}

impl Stats {
    pub fn from_champion(champion: Champion) -> Self {
        match champion {
            Champion::Meele => Stats { attack_range: 25. },
            Champion::Ranged => Stats { attack_range: 60. },
        }
    }
}

impl Champion {
    pub fn to_ability(self, attack_key: AttackKey) -> Ability {
        match self {
            Champion::Meele => match attack_key {
                AttackKey::Q => Ability::Directional(DirectionalAbility::Spear),
                _ => Ability::Targeted(TargetedAbility::MeeleAttack),
            },
            Champion::Ranged => match attack_key {
                AttackKey::Q => Ability::Directional(DirectionalAbility::Spear),
                _ => Ability::Targeted(TargetedAbility::RangedAttack),
            },
        }
    }
}