summaryrefslogtreecommitdiff
path: root/src/systems/droploot.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/systems/droploot.rs')
-rw-r--r--src/systems/droploot.rs24
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();
+ }
+ }
+ }
+ _ => {}
}
}
}