aboutsummaryrefslogtreecommitdiffstats
path: root/src/server.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/server.rs')
-rw-r--r--src/server.rs19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/server.rs b/src/server.rs
index 483314d..fc44120 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -55,7 +55,7 @@ impl Plugin for ServerPlugin {
.add_systems(Update, (connects, disconnects))
.add_systems(Update, receive_message)
.add_systems(FixedUpdate, timers_tick)
- .add_systems(FixedUpdate, effective_stats)
+ .add_systems(FixedUpdate, effective_stats.after(buffs_despawn))
.add_systems(FixedUpdate, health_regen.after(timers_tick))
.add_systems(
FixedUpdate,
@@ -466,7 +466,7 @@ fn projectile_despawn(
if let Some(target_player) = maybe_target_player {
if let Some(target_entity) = entity_map.0.get(&target_player.0) {
if let Ok(mut health) = healths.get_mut(*target_entity) {
- health.0 = (health.0 - projectile.damage).max(0.);
+ health.apply_damage(projectile.damage);
let _ = connection_manager
.send_message_to_target::<Channel1, HealthChanged>(
HealthChanged(HealthEvent {
@@ -504,7 +504,7 @@ fn health_regen(
) {
if health_regen_timer.0.just_finished() {
for (target_player, mut health, effective_stats) in healths.iter_mut() {
- health.0 = (health.0 + HEALTH_REGEN).min(effective_stats.0.max_health);
+ health.heal(HEALTH_REGEN, effective_stats.0.max_health);
let _ = connection_manager.send_message_to_target::<Channel1, HealthChanged>(
HealthChanged(HealthEvent {
target_player: *target_player,
@@ -531,7 +531,10 @@ fn effective_stats(
stats.attack_speed *= 0.5;
}
effective_stats.0 = stats;
- health.0 = health.0.min(effective_stats.0.max_health);
+ health.health = health.health.min(effective_stats.0.max_health);
+ if buffs.shield.is_none() {
+ health.shield = 0.;
+ }
}
}
@@ -541,6 +544,9 @@ fn buffs_tick(mut buffses: Query<&mut Buffs>, time: Res<Time>) {
if let Some(ref mut timer) = &mut buffs.haste {
timer.tick(dt);
}
+ if let Some(ref mut timer) = &mut buffs.shield {
+ timer.tick(dt);
+ }
if let Some(ref mut timer) = &mut buffs.slow {
timer.tick(dt);
}
@@ -557,6 +563,11 @@ fn buffs_despawn(mut buffses: Query<&mut Buffs>) {
buffs.haste = None;
}
}
+ if let Some(timer) = &buffs.shield {
+ if timer.finished() {
+ buffs.shield = None;
+ }
+ }
if let Some(timer) = &buffs.slow {
if timer.finished() {
buffs.slow = None;