From 885d0bf2c02fc69fc890765d65067c01741ce47b Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Sun, 17 Mar 2024 13:37:58 +0100 Subject: chore: refactor abilities --- src/shared/ability.rs | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/shared/ability.rs (limited to 'src/shared/ability.rs') 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., + }, + } + } +} -- cgit v1.2.3