aboutsummaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-18 04:19:34 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-18 04:19:34 +0100
commit937e1ed8d240c1a5b42f5b8cf1104321b9d79c4a (patch)
treec9cc6f8ec35e3e9b1ba97b5fd42091cf0ab2afb6 /src/shared
parentab675360c0005718a3c9b8b5e7962af897269c04 (diff)
fix: fix abilities selecting the right cooldown
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/ability.rs53
-rw-r--r--src/shared/champion.rs10
-rw-r--r--src/shared/cooldown.rs17
-rw-r--r--src/shared/imperative.rs15
4 files changed, 68 insertions, 27 deletions
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<Self> {
+ vec![
+ AbilitySlot::A,
+ AbilitySlot::Q,
+ AbilitySlot::W,
+ AbilitySlot::E,
+ AbilitySlot::R,
+ AbilitySlot::F,
+ AbilitySlot::G,
+ ]
+ }
+}
+
+impl Index<AbilitySlot> for [Duration; 7] {
+ type Output = Duration;
+
+ fn index(&self, ability_slot: AbilitySlot) -> &Self::Output {
+ &self[ability_slot as usize]
+ }
+}
+
+impl IndexMut<AbilitySlot> 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),
}