aboutsummaryrefslogtreecommitdiffstats
path: root/src/shared/champion.rs
blob: 05f13ef82b56e0cf037c4ef9bae7bb66b06f2a7e (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
use crate::shared::ability::*;
use crate::shared::stats::*;
use crate::shared::*;
use bevy::utils::*;
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)),
        }
    }
}

impl Champion {
    pub fn base_stats(self) -> BaseStats {
        match self {
            Champion::Meele => BaseStats(Stats {
                attack_range: 25.,
                movement_speed: 75.,
                max_health: 150.,
            }),
            Champion::Ranged => BaseStats(Stats {
                attack_range: 60.,
                movement_speed: 85.,
                max_health: 100.,
            }),
        }
    }

    pub fn ability(self, ability_slot: AbilitySlot) -> Ability {
        match self {
            Champion::Meele => match ability_slot {
                AbilitySlot::Q => {
                    Ability::Directional(DirectionalAbility::Dash(Dash { max_distance: 60. }))
                }
                AbilitySlot::W => {
                    Ability::Directional(DirectionalAbility::Pull(Pull { max_distance: 60. }))
                }
                AbilitySlot::R => {
                    Ability::Targeted(TargetedAbility::MeeleAttack(MeeleAttack { damage: 45. }))
                }
                AbilitySlot::G => {
                    Ability::Activated(ActivatedAbility::Speed(Speed { duration: 2.5 }))
                }
                _ => Ability::Targeted(TargetedAbility::MeeleAttack(MeeleAttack { damage: 5. })),
            },
            Champion::Ranged => match ability_slot {
                AbilitySlot::Q => Ability::Directional(DirectionalAbility::Spear(Spear {
                    max_distance: 250.,
                    damage: 15.,
                })),
                AbilitySlot::G => {
                    Ability::Activated(ActivatedAbility::Speed(Speed { duration: 2.5 }))
                }
                _ => Ability::Targeted(TargetedAbility::RangedAttack(RangedAttack { damage: 6. })),
            },
        }
    }

    pub fn base_cooldown(self) -> BaseCooldown {
        match self {
            Champion::Meele => {
                BaseCooldown([0.75, 5., 5., 10., 25., 50., 50.].map(Duration::from_secs_f32))
            }
            Champion::Ranged => {
                BaseCooldown([1.25, 5., 5., 10., 25., 50., 50.].map(Duration::from_secs_f32))
            }
        }
    }
}