diff options
| author | troido <troido@protonmail.com> | 2020-04-12 23:10:10 +0200 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-04-12 23:10:10 +0200 |
| commit | cfd462a26b3ed4c5f23760a77ae87ce61dc9bbe2 (patch) | |
| tree | c5118158196ec9924ba1123f6279cfe88dbca6e5 /src/systems/droploot.rs | |
| parent | 883e56e07a48dc0d4916614abc33e40dde1d1d66 (diff) | |
replaced Dead component with trigger messages
Diffstat (limited to 'src/systems/droploot.rs')
| -rw-r--r-- | src/systems/droploot.rs | 24 |
1 files changed, 16 insertions, 8 deletions
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(); + } + } + } + _ => {} } } } |
