From cfd462a26b3ed4c5f23760a77ae87ce61dc9bbe2 Mon Sep 17 00:00:00 2001 From: troido Date: Sun, 12 Apr 2020 23:10:10 +0200 Subject: replaced Dead component with trigger messages --- src/systems/droploot.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/systems/droploot.rs') diff --git a/src/systems/droploot.rs b/src/systems/droploot.rs index 5eff7f7..33e71c0 100644 --- a/src/systems/droploot.rs +++ b/src/systems/droploot.rs @@ -12,7 +12,8 @@ use crate::{ components::{ Position, Loot, - Dead + Trigger, + TriggerBox }, resources::{NewEntities} }; @@ -23,16 +24,23 @@ impl <'a> System<'a> for DropLoot{ type SystemData = ( ReadStorage<'a, Position>, Write<'a, NewEntities>, - ReadStorage<'a, Dead>, + ReadStorage<'a, TriggerBox>, ReadStorage<'a, Loot> ); - fn run(&mut self, (positions, mut new, deads, loots): Self::SystemData) { - for (position, _, loot) in (&positions, &deads, &loots).join(){ - for (template, chance) in &loot.loot { - if *chance > rand::thread_rng().gen_range(0.0, 1.0) { - // todo: better error handling - new.create(position.pos, &template).unwrap(); + fn run(&mut self, (positions, mut new, triggerboxes, loots): Self::SystemData) { + for (position, triggerbox, loot) in (&positions, &triggerboxes, &loots).join(){ + for message in triggerbox.messages.iter() { + match message { + Trigger::Die | Trigger::Loot => { + for (template, chance) in &loot.loot { + if *chance > rand::thread_rng().gen_range(0.0, 1.0) { + // todo: better error handling + new.create(position.pos, &template).unwrap(); + } + } + } + _ => {} } } } -- cgit