aboutsummaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/ability.rs42
-rw-r--r--src/shared/buffs.rs1
-rw-r--r--src/shared/champion.rs4
-rw-r--r--src/shared/health.rs18
-rw-r--r--src/shared/player.rs5
5 files changed, 63 insertions, 7 deletions
diff --git a/src/shared/ability.rs b/src/shared/ability.rs
index b841661..80c74b2 100644
--- a/src/shared/ability.rs
+++ b/src/shared/ability.rs
@@ -59,6 +59,7 @@ impl TargetedAbility {
pub enum ActivatedAbility {
Focus(Focus),
Haste(Haste),
+ Shield(Shield),
Speed(Speed),
}
@@ -73,6 +74,12 @@ pub struct Haste {
}
#[derive(Copy, Clone, PartialEq, Debug, Deserialize, Serialize)]
+pub struct Shield {
+ pub duration: f32,
+ pub blocked_damage: f32,
+}
+
+#[derive(Copy, Clone, PartialEq, Debug, Deserialize, Serialize)]
pub struct Speed {
pub duration: f32,
}
@@ -84,12 +91,13 @@ impl ActivatedAbility {
match self {
ActivatedAbility::Focus(focus) => focus_activation(focus),
ActivatedAbility::Haste(haste) => haste_activation(haste),
+ ActivatedAbility::Shield(shield) => shield_activation(shield),
ActivatedAbility::Speed(speed) => speed_activation(speed),
}
}
}
-fn speed_activation(speed: Speed) -> ActivatedAbilityActivation {
+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(
@@ -100,7 +108,8 @@ fn speed_activation(speed: Speed) -> ActivatedAbilityActivation {
let Ok(mut buffs) = buffses.get_mut(*entity_id) else {
return;
};
- buffs.speed = Some(Timer::from_seconds(speed.duration, TimerMode::Once));
+ buffs.haste = Some(Timer::from_seconds(focus.duration, TimerMode::Once));
+ buffs.speed = Some(Timer::from_seconds(focus.duration, TimerMode::Once));
},
)
});
@@ -125,7 +134,31 @@ fn haste_activation(haste: Haste) -> ActivatedAbilityActivation {
})
}
-fn focus_activation(focus: Focus) -> ActivatedAbilityActivation {
+fn shield_activation(shield: Shield) -> 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 healths: Query<&mut Health>,
+ mut buffses: Query<&mut Buffs>| {
+ let Some(entity_id) = entity_map.0.get(&source_id.0) else {
+ return;
+ };
+ let Ok(mut health) = healths.get_mut(*entity_id) else {
+ return;
+ };
+ let Ok(mut buffs) = buffses.get_mut(*entity_id) else {
+ return;
+ };
+ health.shield = health.shield + shield.blocked_damage;
+ buffs.shield = Some(Timer::from_seconds(shield.duration, TimerMode::Once));
+ },
+ )
+ });
+ })
+}
+
+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(
@@ -136,8 +169,7 @@ fn focus_activation(focus: Focus) -> ActivatedAbilityActivation {
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));
+ buffs.speed = Some(Timer::from_seconds(speed.duration, TimerMode::Once));
},
)
});
diff --git a/src/shared/buffs.rs b/src/shared/buffs.rs
index e8992d5..6b518a5 100644
--- a/src/shared/buffs.rs
+++ b/src/shared/buffs.rs
@@ -3,6 +3,7 @@ use crate::shared::*;
#[derive(Clone, Component, Default, Debug)]
pub struct Buffs {
pub haste: Option<Timer>,
+ pub shield: Option<Timer>,
pub slow: Option<Timer>,
pub speed: Option<Timer>,
}
diff --git a/src/shared/champion.rs b/src/shared/champion.rs
index da63664..86bd41e 100644
--- a/src/shared/champion.rs
+++ b/src/shared/champion.rs
@@ -55,6 +55,10 @@ impl Champion {
AbilitySlot::W => {
Ability::Directional(DirectionalAbility::Pull(Pull { max_distance: 60. }))
}
+ AbilitySlot::E => Ability::Activated(ActivatedAbility::Shield(Shield {
+ blocked_damage: 35.,
+ duration: 2.,
+ })),
AbilitySlot::R => {
Ability::Targeted(TargetedAbility::MeeleAttack(MeeleAttack { damage: 45. }))
}
diff --git a/src/shared/health.rs b/src/shared/health.rs
index b88f19c..f9cc300 100644
--- a/src/shared/health.rs
+++ b/src/shared/health.rs
@@ -1,4 +1,20 @@
use crate::shared::*;
#[derive(Component, Message, Serialize, Deserialize, Clone, Copy, Debug, PartialEq)]
-pub struct Health(pub f32);
+pub struct Health {
+ pub health: f32,
+ pub shield: f32,
+}
+
+impl Health {
+ pub fn apply_damage(&mut self, damage: f32) {
+ let shield_damage = damage.min(self.shield);
+ let health_damage = damage - shield_damage;
+ self.shield = self.shield - shield_damage;
+ self.health = (self.health - health_damage).max(0.);
+ }
+
+ pub fn heal(&mut self, health: f32, max_health: f32) {
+ self.health = (self.health + health).min(max_health);
+ }
+}
diff --git a/src/shared/player.rs b/src/shared/player.rs
index d1df3af..3805969 100644
--- a/src/shared/player.rs
+++ b/src/shared/player.rs
@@ -37,7 +37,10 @@ impl PlayerBundle {
color: PlayerColor(color),
imperative: Imperative::Idle,
cooldown: Cooldown::default(),
- health: Health(effective_stats.0.max_health),
+ health: Health {
+ health: effective_stats.0.max_health,
+ shield: 0.,
+ },
champion,
effective_stats,
buffs: Buffs::default(),