From 1219ed9a6c3b7cc978d70e0c62f96e09e8efe04f Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Sat, 23 Mar 2024 14:06:23 +0100 Subject: feat: respawn players --- src/server.rs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/server.rs b/src/server.rs index 413c7fd..d9eccb6 100644 --- a/src/server.rs +++ b/src/server.rs @@ -101,7 +101,8 @@ impl Plugin for ServerPlugin { (tower_ai, (minion_ai_attack, minion_ai_walk).chain()) .before(imperative_attack_approach), ) - .add_systems(FixedUpdate, minion_despawn) + .add_systems(FixedUpdate, despawn) + .add_systems(FixedUpdate, player_respawn) .add_systems(FixedUpdate, (nexus_tick, nexus_spawn_minions)) .add_systems( FixedUpdate, @@ -834,15 +835,27 @@ fn minion_ai_attack( } } -fn minion_despawn( - minions: Query<(Entity, &PlayerId, &Health), With>, +fn despawn( + minions: Query<(Entity, &PlayerId, &Health), Without>, mut commands: Commands, mut entity_map: ResMut, ) { - for (minion_entity, minion_player_id, minion_health) in minions.iter() { - if minion_health.health <= 0. { - commands.entity(minion_entity).despawn(); - entity_map.0.remove(&minion_player_id.0); + for (entity, player_id, health) in minions.iter() { + if health.health <= 0. { + commands.entity(entity).despawn(); + entity_map.0.remove(&player_id.0); + } + } +} + +fn player_respawn( + mut players: Query<(&mut Health, &mut PlayerPosition, &EffectiveStats), With>, +) { + for (mut health, mut player_position, effective_stats) in players.iter_mut() { + if health.health <= 0. { + health.health = effective_stats.0.max_health; + health.shield = 0.; + player_position.0 = Vec2::ZERO; } } } -- cgit v1.2.3