aboutsummaryrefslogtreecommitdiffstats
path: root/src/shared/ability.rs
blob: cab7ae6a31a0a002232f8e6f60daf6c4617ce523 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
use crate::shared::player::*;
use crate::shared::projectile::*;
use crate::shared::*;
use bevy::utils::Duration;
use std::ops::*;

#[derive(Copy, Clone, PartialEq, Debug, Deserialize, Serialize)]
pub enum Ability {
    Targeted(TargetedAbility),
    Directional(DirectionalAbility),
}

#[derive(Copy, Clone, PartialEq, Debug, Deserialize, Serialize)]
pub enum TargetedAbility {
    MeeleAttack,
    RangedAttack,
}

impl TargetedAbility {
    pub fn to_projectile(
        self,
        source_player: PlayerId,
        position: Vec2,
        target_player: PlayerId,
    ) -> Projectile {
        match self {
            TargetedAbility::MeeleAttack => Projectile {
                type_: ProjectileType::Targeted(TargetedProjectile {
                    target_player,
                    position,
                }),
                source_player,
                damage: 5.,
            },
            TargetedAbility::RangedAttack => Projectile {
                type_: ProjectileType::Instant(InstantProjectile { target_player }),
                source_player,
                damage: 6.,
            },
        }
    }
}

#[derive(Copy, Clone, PartialEq, Debug, Deserialize, Serialize)]
pub enum DirectionalAbility {
    Spear,
}

impl DirectionalAbility {
    pub fn to_projectile(
        self,
        source_player: PlayerId,
        position: Vec2,
        direction: Vec2,
    ) -> Projectile {
        match self {
            DirectionalAbility::Spear => Projectile {
                type_: ProjectileType::Free(FreeProjectile {
                    position,
                    direction,
                    starting_position: position,
                }),
                source_player,
                damage: 15.,
            },
        }
    }
}

#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
pub enum AbilitySlot {
    A,
    Q,
    W,
    E,
    R,
    F,
    G,
}

impl AbilitySlot {
    pub fn to_label(self) -> &'static str {
        match self {
            AbilitySlot::A => "A",
            AbilitySlot::Q => "Q",
            AbilitySlot::W => "W",
            AbilitySlot::E => "E",
            AbilitySlot::R => "R",
            AbilitySlot::F => "F",
            AbilitySlot::G => "G",
        }
    }

    pub fn all() -> Vec<Self> {
        vec![
            AbilitySlot::A,
            AbilitySlot::Q,
            AbilitySlot::W,
            AbilitySlot::E,
            AbilitySlot::R,
            AbilitySlot::F,
            AbilitySlot::G,
        ]
    }
}

impl Index<AbilitySlot> for [Duration; 7] {
    type Output = Duration;

    fn index(&self, ability_slot: AbilitySlot) -> &Self::Output {
        &self[ability_slot as usize]
    }
}

impl IndexMut<AbilitySlot> for [Duration; 7] {
    fn index_mut(&mut self, ability_slot: AbilitySlot) -> &mut Self::Output {
        &mut self[ability_slot as usize]
    }
}