diff options
author | Alexander Foremny <aforemny@posteo.de> | 2024-03-17 13:37:58 +0100 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2024-03-17 13:40:26 +0100 |
commit | 885d0bf2c02fc69fc890765d65067c01741ce47b (patch) | |
tree | 3aaee8b6fb196aa94f46d393d41a2bdf99d6942a /src/shared/ability.rs | |
parent | 601474aa84cfc071c724051ac121e3c9cc796577 (diff) |
chore: refactor abilities
Diffstat (limited to 'src/shared/ability.rs')
-rw-r--r-- | src/shared/ability.rs | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/shared/ability.rs b/src/shared/ability.rs new file mode 100644 index 0000000..8ef0c29 --- /dev/null +++ b/src/shared/ability.rs @@ -0,0 +1,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., + }, + } + } +} |