aboutsummaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-19 06:52:42 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-19 06:52:42 +0100
commit9d8bf0fde7b12fa77569333d17f310e55df58db9 (patch)
tree958de22a18bc5d8a837db55233d282af3e7f4af4 /src/shared
parente9dce64b009455163f2a262ed481c37300917c4a (diff)
feat: focus ability
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/ability.rs81
-rw-r--r--src/shared/buffs.rs1
-rw-r--r--src/shared/champion.rs19
-rw-r--r--src/shared/cooldown.rs3
-rw-r--r--src/shared/stats.rs3
5 files changed, 99 insertions, 8 deletions
diff --git a/src/shared/ability.rs b/src/shared/ability.rs
index 4d45a4d..b841661 100644
--- a/src/shared/ability.rs
+++ b/src/shared/ability.rs
@@ -1,3 +1,5 @@
+use crate::server::entity_map::*;
+use crate::shared::buffs::*;
use crate::shared::player::*;
use crate::shared::projectile::*;
use crate::shared::*;
@@ -55,14 +57,93 @@ impl TargetedAbility {
#[derive(Copy, Clone, PartialEq, Debug, Deserialize, Serialize)]
pub enum ActivatedAbility {
+ Focus(Focus),
+ Haste(Haste),
Speed(Speed),
}
#[derive(Copy, Clone, PartialEq, Debug, Deserialize, Serialize)]
+pub struct Focus {
+ pub duration: f32,
+}
+
+#[derive(Copy, Clone, PartialEq, Debug, Deserialize, Serialize)]
+pub struct Haste {
+ pub duration: f32,
+}
+
+#[derive(Copy, Clone, PartialEq, Debug, Deserialize, Serialize)]
pub struct Speed {
pub duration: f32,
}
+pub type ActivatedAbilityActivation = Box<dyn FnOnce(&mut Commands, PlayerId) -> ()>;
+
+impl ActivatedAbility {
+ pub fn activate(self) -> ActivatedAbilityActivation {
+ match self {
+ ActivatedAbility::Focus(focus) => focus_activation(focus),
+ ActivatedAbility::Haste(haste) => haste_activation(haste),
+ ActivatedAbility::Speed(speed) => speed_activation(speed),
+ }
+ }
+}
+
+fn speed_activation(speed: Speed) -> ActivatedAbilityActivation {
+ Box::new(move |commands: &mut Commands, source_id: PlayerId| {
+ commands.add(move |world: &mut World| {
+ world.run_system_once(
+ move |entity_map: Res<EntityMap>, mut buffses: Query<&mut Buffs>| {
+ let Some(entity_id) = entity_map.0.get(&source_id.0) else {
+ return;
+ };
+ let Ok(mut buffs) = buffses.get_mut(*entity_id) else {
+ return;
+ };
+ buffs.speed = Some(Timer::from_seconds(speed.duration, TimerMode::Once));
+ },
+ )
+ });
+ })
+}
+
+fn haste_activation(haste: Haste) -> ActivatedAbilityActivation {
+ Box::new(move |commands: &mut Commands, source_id: PlayerId| {
+ commands.add(move |world: &mut World| {
+ world.run_system_once(
+ move |entity_map: Res<EntityMap>, mut buffses: Query<&mut Buffs>| {
+ let Some(entity_id) = entity_map.0.get(&source_id.0) else {
+ return;
+ };
+ let Ok(mut buffs) = buffses.get_mut(*entity_id) else {
+ return;
+ };
+ buffs.haste = Some(Timer::from_seconds(haste.duration, TimerMode::Once));
+ },
+ )
+ });
+ })
+}
+
+fn focus_activation(focus: Focus) -> ActivatedAbilityActivation {
+ Box::new(move |commands: &mut Commands, source_id: PlayerId| {
+ commands.add(move |world: &mut World| {
+ world.run_system_once(
+ move |entity_map: Res<EntityMap>, mut buffses: Query<&mut Buffs>| {
+ let Some(entity_id) = entity_map.0.get(&source_id.0) else {
+ return;
+ };
+ let Ok(mut buffs) = buffses.get_mut(*entity_id) else {
+ return;
+ };
+ buffs.haste = Some(Timer::from_seconds(focus.duration, TimerMode::Once));
+ buffs.speed = Some(Timer::from_seconds(focus.duration, TimerMode::Once));
+ },
+ )
+ });
+ })
+}
+
#[derive(Copy, Clone, PartialEq, Debug, Deserialize, Serialize)]
pub enum DirectionalAbility {
Dash(Dash),
diff --git a/src/shared/buffs.rs b/src/shared/buffs.rs
index 4fe033d..e8992d5 100644
--- a/src/shared/buffs.rs
+++ b/src/shared/buffs.rs
@@ -2,6 +2,7 @@ use crate::shared::*;
#[derive(Clone, Component, Default, Debug)]
pub struct Buffs {
+ pub haste: Option<Timer>,
pub slow: Option<Timer>,
pub speed: Option<Timer>,
}
diff --git a/src/shared/champion.rs b/src/shared/champion.rs
index 05f13ef..da63664 100644
--- a/src/shared/champion.rs
+++ b/src/shared/champion.rs
@@ -33,13 +33,15 @@ impl Champion {
match self {
Champion::Meele => BaseStats(Stats {
attack_range: 25.,
- movement_speed: 75.,
+ attack_speed: 0.75,
max_health: 150.,
+ movement_speed: 75.,
}),
Champion::Ranged => BaseStats(Stats {
attack_range: 60.,
- movement_speed: 85.,
+ attack_speed: 1.5,
max_health: 100.,
+ movement_speed: 85.,
}),
}
}
@@ -62,14 +64,17 @@ impl Champion {
_ => Ability::Targeted(TargetedAbility::MeeleAttack(MeeleAttack { damage: 5. })),
},
Champion::Ranged => match ability_slot {
- AbilitySlot::Q => Ability::Directional(DirectionalAbility::Spear(Spear {
+ AbilitySlot::E => Ability::Directional(DirectionalAbility::Spear(Spear {
max_distance: 250.,
- damage: 15.,
+ damage: 25.,
})),
+ AbilitySlot::R => {
+ Ability::Activated(ActivatedAbility::Focus(Focus { duration: 5. }))
+ }
AbilitySlot::G => {
Ability::Activated(ActivatedAbility::Speed(Speed { duration: 2.5 }))
}
- _ => Ability::Targeted(TargetedAbility::RangedAttack(RangedAttack { damage: 6. })),
+ _ => Ability::Targeted(TargetedAbility::RangedAttack(RangedAttack { damage: 8. })),
},
}
}
@@ -77,10 +82,10 @@ impl Champion {
pub fn base_cooldown(self) -> BaseCooldown {
match self {
Champion::Meele => {
- BaseCooldown([0.75, 5., 5., 10., 25., 50., 50.].map(Duration::from_secs_f32))
+ BaseCooldown([0., 5., 5., 10., 25., 50., 50.].map(Duration::from_secs_f32))
}
Champion::Ranged => {
- BaseCooldown([1.25, 5., 5., 10., 25., 50., 50.].map(Duration::from_secs_f32))
+ BaseCooldown([0., 10., 10., 15., 35., 50., 50.].map(Duration::from_secs_f32))
}
}
}
diff --git a/src/shared/cooldown.rs b/src/shared/cooldown.rs
index 8f72520..6995941 100644
--- a/src/shared/cooldown.rs
+++ b/src/shared/cooldown.rs
@@ -4,6 +4,9 @@ use serde::Deserialize;
use serde::Serialize;
use std::default::Default;
+// TODO `AbilitySlot::A`'s cooldown is unused
+//
+// cf. `Stats`' `attack_speed`
#[derive(Component, Message, Serialize, Deserialize, Clone, Copy, PartialEq, Debug, Default)]
pub struct Cooldown(pub [Duration; 7]);
diff --git a/src/shared/stats.rs b/src/shared/stats.rs
index bc9a509..239405e 100644
--- a/src/shared/stats.rs
+++ b/src/shared/stats.rs
@@ -3,8 +3,9 @@ use crate::shared::*;
#[derive(Clone, Copy, Serialize, Deserialize, PartialEq, Debug)]
pub struct Stats {
pub attack_range: f32,
- pub movement_speed: f32,
+ pub attack_speed: f32,
pub max_health: f32,
+ pub movement_speed: f32,
}
#[derive(Component, Message, Clone, Copy, Serialize, Deserialize, PartialEq, Debug)]