aboutsummaryrefslogtreecommitdiffstats
path: root/src/shared/ability.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/ability.rs')
-rw-r--r--src/shared/ability.rs81
1 files changed, 81 insertions, 0 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),