aboutsummaryrefslogtreecommitdiffstats
path: root/src/shared/ability.rs
blob: 8ef0c29d9ac27a97b21135d9267a7f3c8c87c477 (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
use crate::shared::projectile::*;
use crate::shared::*;

#[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.,
            },
        }
    }
}