summaryrefslogtreecommitdiff
path: root/src/systems
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-03-04 16:10:32 +0100
committertroido <troido@protonmail.com>2020-03-04 16:10:32 +0100
commitf8364fb636a8e9276939ae8523966b038388e4ff (patch)
tree8edd2f48cda4f2d605cec6df3ca4ec3a974de009 /src/systems
parent21919636f95a1214b7ed1a3e4aa6527f45b9d073 (diff)
added loot/harvest
Diffstat (limited to 'src/systems')
-rw-r--r--src/systems/droploot.rs41
-rw-r--r--src/systems/mod.rs4
2 files changed, 44 insertions, 1 deletions
diff --git a/src/systems/droploot.rs b/src/systems/droploot.rs
new file mode 100644
index 0000000..616d38d
--- /dev/null
+++ b/src/systems/droploot.rs
@@ -0,0 +1,41 @@
+
+use rand::Rng;
+
+use specs::{
+ ReadStorage,
+ WriteStorage,
+ System,
+ Join,
+ Write
+};
+
+use crate::{
+ components::{
+ Position,
+ Loot,
+ Dead
+ },
+ resources::{NewEntities}
+};
+
+
+pub struct DropLoot;
+impl <'a> System<'a> for DropLoot{
+ type SystemData = (
+ WriteStorage<'a, Position>,
+ Write<'a, NewEntities>,
+ ReadStorage<'a, Dead>,
+ 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.clone()).unwrap();
+ }
+ }
+ }
+ }
+}
diff --git a/src/systems/mod.rs b/src/systems/mod.rs
index 887a1f9..1735df9 100644
--- a/src/systems/mod.rs
+++ b/src/systems/mod.rs
@@ -18,6 +18,7 @@ mod controlai;
mod die;
mod spawn;
mod interact;
+mod droploot;
pub use self::{
controlinput::ControlInput,
@@ -38,5 +39,6 @@ pub use self::{
controlai::ControlAI,
die::Die,
spawn::Spawn,
- interact::Interact
+ interact::Interact,
+ droploot::DropLoot
};