From 937e1ed8d240c1a5b42f5b8cf1104321b9d79c4a Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Mon, 18 Mar 2024 04:19:34 +0100 Subject: fix: fix abilities selecting the right cooldown --- src/shared/ability.rs | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ src/shared/champion.rs | 10 ++++----- src/shared/cooldown.rs | 17 ++++++++-------- src/shared/imperative.rs | 15 ++------------ 4 files changed, 68 insertions(+), 27 deletions(-) (limited to 'src/shared') diff --git a/src/shared/ability.rs b/src/shared/ability.rs index 9639afe..cab7ae6 100644 --- a/src/shared/ability.rs +++ b/src/shared/ability.rs @@ -1,6 +1,8 @@ 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 { @@ -64,3 +66,54 @@ impl DirectionalAbility { } } } + +#[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] + } +} diff --git a/src/shared/champion.rs b/src/shared/champion.rs index 8de12a5..28d1ff2 100644 --- a/src/shared/champion.rs +++ b/src/shared/champion.rs @@ -40,14 +40,14 @@ impl Stats { } impl Champion { - pub fn to_ability(self, attack_key: AttackKey) -> Ability { + pub fn to_ability(self, ability_slot: AbilitySlot) -> Ability { match self { - Champion::Meele => match attack_key { - AttackKey::Q => Ability::Directional(DirectionalAbility::Spear), + Champion::Meele => match ability_slot { + AbilitySlot::Q => Ability::Directional(DirectionalAbility::Spear), _ => Ability::Targeted(TargetedAbility::MeeleAttack), }, - Champion::Ranged => match attack_key { - AttackKey::Q => Ability::Directional(DirectionalAbility::Spear), + Champion::Ranged => match ability_slot { + AbilitySlot::Q => Ability::Directional(DirectionalAbility::Spear), _ => Ability::Targeted(TargetedAbility::RangedAttack), }, } diff --git a/src/shared/cooldown.rs b/src/shared/cooldown.rs index f27d7fc..2d6b6ae 100644 --- a/src/shared/cooldown.rs +++ b/src/shared/cooldown.rs @@ -5,13 +5,12 @@ use serde::Serialize; use std::default::Default; #[derive(Component, Message, Serialize, Deserialize, Clone, Copy, PartialEq, Debug, Default)] -pub struct Cooldown { - pub a_cooldown: Duration, - pub q_cooldown: Duration, - pub w_cooldown: Duration, - pub e_cooldown: Duration, - pub r_cooldown: Duration, - pub d_cooldown: Duration, - pub f_cooldown: Duration, - pub g_cooldown: Duration, +pub struct Cooldown(pub [Duration; 7]); + +pub struct BaseCooldown(pub [Duration; 7]); + +impl BaseCooldown { + pub fn from_champion(_champion: Champion) -> Self { + BaseCooldown([1., 5., 5., 10., 25., 50., 50.].map(Duration::from_secs_f32)) + } } diff --git a/src/shared/imperative.rs b/src/shared/imperative.rs index afdf244..44a0e43 100644 --- a/src/shared/imperative.rs +++ b/src/shared/imperative.rs @@ -8,17 +8,6 @@ use serde::Serialize; pub enum Imperative { Idle, WalkTo(Vec2), - AttackTarget(TargetedAbility, PlayerId), - AttackDirection(DirectionalAbility, Vec2), -} - -#[derive(Resource, Copy, Clone, PartialEq, Debug, Deserialize, Serialize)] -pub enum AttackKey { - A, - Q, - W, - E, - R, - F, - G, + AttackTarget(AbilitySlot, PlayerId), + AttackDirection(AbilitySlot, Vec2), } -- cgit v1.2.3