diff options
| author | troido <troido@protonmail.com> | 2020-03-02 22:28:03 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-03-02 22:28:03 +0100 |
| commit | 22168c8eedac95fdfde9a536a1d1f6ddf622cfa1 (patch) | |
| tree | 6870bff418367fc635d64b58b3921d85ee0dbbb0 /src/systems | |
| parent | 27c0795fb70739ce5609a0f424d80491d4a8c5a1 (diff) | |
added purgatory
Diffstat (limited to 'src/systems')
| -rw-r--r-- | src/systems/attacking.rs | 10 | ||||
| -rw-r--r-- | src/systems/die.rs | 40 | ||||
| -rw-r--r-- | src/systems/mod.rs | 4 |
3 files changed, 47 insertions, 7 deletions
diff --git a/src/systems/attacking.rs b/src/systems/attacking.rs index d28e301..6075bd5 100644 --- a/src/systems/attacking.rs +++ b/src/systems/attacking.rs @@ -9,7 +9,7 @@ use specs::{ }; use crate::{ - components::{Health, AttackInbox, Dying, Removed, Position}, + components::{Health, AttackInbox, Dead, Position}, resources::NewEntities, Template, util @@ -22,12 +22,11 @@ impl <'a> System<'a> for Attacking { Entities<'a>, WriteStorage<'a, AttackInbox>, WriteStorage<'a, Health>, - WriteStorage<'a, Dying>, - WriteStorage<'a, Removed>, + WriteStorage<'a, Dead>, ReadStorage<'a, Position>, Write<'a, NewEntities> ); - fn run(&mut self, (entities, mut attackeds, mut healths, mut deads, mut removals, positions, mut new): Self::SystemData) { + fn run(&mut self, (entities, mut attackeds, mut healths, mut deads, positions, mut new): Self::SystemData) { for (ent, health, attacked) in (&entities, &mut healths, &mut attackeds).join() { let mut wounded = false; for attack in attacked.messages.drain(..) { @@ -38,8 +37,7 @@ impl <'a> System<'a> for Attacking { } health.health = util::clamp(health.health, 0, health.maxhealth); if health.health == 0 { - deads.insert(ent, Dying).unwrap(); - removals.insert(ent, Removed).unwrap(); + deads.insert(ent, Dead).unwrap(); } if let Some(position) = positions.get(ent){ if wounded { diff --git a/src/systems/die.rs b/src/systems/die.rs new file mode 100644 index 0000000..fd953e0 --- /dev/null +++ b/src/systems/die.rs @@ -0,0 +1,40 @@ + +use specs::{ + Write, + WriteStorage, + ReadStorage, + Entities, + System, + Join +}; + +use crate::{ + components::{Mortal, Dead, Removed, Player}, + resources::Emigration, + purgatory, + playerstate::RoomPos +}; + + +pub struct Die; +impl <'a> System<'a> for Die { + type SystemData = ( + Entities<'a>, + ReadStorage<'a, Mortal>, + ReadStorage<'a, Dead>, + WriteStorage<'a, Removed>, + Write<'a, Emigration>, + ReadStorage<'a, Player> + ); + fn run(&mut self, (entities, mortals, deads, mut removeds, mut emigration, players): Self::SystemData) { + // npcs etc get removed when dead + for (entity, _, _) in (&entities, &mortals, &deads).join() { + removeds.insert(entity, Removed).unwrap(); + } + // players move to purgatory when dead + for (player, _) in (&players, &deads).join() { + emigration.emigrants.push((player.id.clone(), purgatory::purgatory_id(), RoomPos::Unknown)); + } + } +} + diff --git a/src/systems/mod.rs b/src/systems/mod.rs index 221ffc4..f4b3edb 100644 --- a/src/systems/mod.rs +++ b/src/systems/mod.rs @@ -15,6 +15,7 @@ mod heal; mod volate; mod updatecooldowns; mod controlai; +mod die; pub use self::{ controlinput::ControlInput, @@ -32,5 +33,6 @@ pub use self::{ heal::Heal, volate::Volate, updatecooldowns::UpdateCooldowns, - controlai::ControlAI + controlai::ControlAI, + die::Die }; |
