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 { Activated(ActivatedAbility), Directional(DirectionalAbility), Targeted(TargetedAbility), } #[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 ActivatedAbility { Speed, } #[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 { vec![ AbilitySlot::A, AbilitySlot::Q, AbilitySlot::W, AbilitySlot::E, AbilitySlot::R, AbilitySlot::F, AbilitySlot::G, ] } } impl Index for [Duration; 7] { type Output = Duration; fn index(&self, ability_slot: AbilitySlot) -> &Self::Output { &self[ability_slot as usize] } } impl IndexMut for [Duration; 7] { fn index_mut(&mut self, ability_slot: AbilitySlot) -> &mut Self::Output { &mut self[ability_slot as usize] } }