summaryrefslogtreecommitdiff
path: root/src/systems
diff options
context:
space:
mode:
Diffstat (limited to 'src/systems')
-rw-r--r--src/systems/attacking.rs10
-rw-r--r--src/systems/die.rs40
-rw-r--r--src/systems/mod.rs4
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
};