diff options
Diffstat (limited to 'src/server.rs')
-rw-r--r-- | src/server.rs | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/server.rs b/src/server.rs index 0b15c5f..55e7ebc 100644 --- a/src/server.rs +++ b/src/server.rs @@ -34,7 +34,7 @@ struct ServerPlugin { pub transport: TransportConfig, } -const HEALTH_REGEN_RATE: f32 = 1.; +const HEALTH_REGEN_RATE: f32 = 5.; #[derive(Resource)] struct HealthRegenTimer(pub Timer); @@ -472,6 +472,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.); let _ = connection_manager .send_message_to_target::<Channel1, HealthChanged>( HealthChanged(HealthEvent { @@ -480,7 +481,6 @@ fn projectile_despawn( }), NetworkTarget::All, ); - health.0 = (health.0 - projectile.damage).max(0.); } } } @@ -502,10 +502,22 @@ fn timers_tick(mut health_regen_timer: ResMut<HealthRegenTimer>, time: Res<Time> health_regen_timer.0.tick(time.delta()); } -fn health_regen(health_regen_timer: Res<HealthRegenTimer>, mut healths: Query<&mut Health>) { +const HEALTH_REGEN: f32 = 5.; +fn health_regen( + health_regen_timer: Res<HealthRegenTimer>, + mut connection_manager: ResMut<ServerConnectionManager>, + mut healths: Query<(&PlayerId, &mut Health)>, +) { if health_regen_timer.0.just_finished() { - for mut health in healths.iter_mut() { - health.0 = (health.0 + 1.).min(MAX_HEALTH); + for (target_player, mut health) in healths.iter_mut() { + health.0 = (health.0 + HEALTH_REGEN).min(MAX_HEALTH); + let _ = connection_manager.send_message_to_target::<Channel1, HealthChanged>( + HealthChanged(HealthEvent { + target_player: *target_player, + health_gained: HEALTH_REGEN, + }), + NetworkTarget::All, + ); } } } |