diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/mod.rs | 8 | ||||
| -rw-r--r-- | src/componentwrapper.rs | 6 | ||||
| -rw-r--r-- | src/room.rs | 2 | ||||
| -rw-r--r-- | src/systems/droploot.rs | 30 |
4 files changed, 31 insertions, 15 deletions
diff --git a/src/components/mod.rs b/src/components/mod.rs index 8ffe30d..394284a 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -197,10 +197,16 @@ pub struct Clan { #[derive(Component, Debug, Clone)] #[storage(HashMapStorage)] pub struct Loot { - pub spread: bool, pub loot: Vec<(Template, f64)> } +#[derive(Component, Debug, Clone)] +#[storage(HashMapStorage)] +pub struct LootHolder { + pub loot: Vec<(Template, f64)> +} + + #[derive(Component, Debug, Clone)] #[storage(HashMapStorage)] diff --git a/src/componentwrapper.rs b/src/componentwrapper.rs index 0eca576..392c0dc 100644 --- a/src/componentwrapper.rs +++ b/src/componentwrapper.rs @@ -182,8 +182,8 @@ components!(all: Home (home: Pos); Faction (faction: String) {Faction::from_str(faction.as_str()).ok_or(aerr!("invalid faction name"))?}; Interactable (action: Interaction) {action}; - Loot (loot: List, spread: Bool) { - Loot {spread, loot: + Loot (loot: List) { + Loot {loot: loot .iter() .map(|param| {match param { @@ -291,6 +291,8 @@ components!(all: total } }; + Removed; + LootHolder () {panic!("LootHolder from parameters not implemented")}; ); diff --git a/src/room.rs b/src/room.rs index 3020241..9583a93 100644 --- a/src/room.rs +++ b/src/room.rs @@ -120,7 +120,7 @@ impl <'a, 'b>Room<'a, 'b> { world.insert(NewEntities::new(encyclopedia)); register_insert!( world, - (Position, Visible, Controller, Movable, New, Removed, Moved, Player, Inventory, Health, Serialise, RoomExit, Entered, TriggerBox, Trap, Fighter, Healing, ControlCooldown, Autofight, MonsterAI, Home, AttackInbox, Item, Spawner, Clan, Faction, Interactable, Loot, Timer, Equipment, TimeOffset, Flags, Ear, Build, Whitelist, Dedup, Minable), + (Position, Visible, Controller, Movable, New, Removed, Moved, Player, Inventory, Health, Serialise, RoomExit, Entered, TriggerBox, Trap, Fighter, Healing, ControlCooldown, Autofight, MonsterAI, Home, AttackInbox, Item, Spawner, Clan, Faction, Interactable, Loot, Timer, Equipment, TimeOffset, Flags, Ear, Build, Whitelist, Dedup, Minable, LootHolder), (Ground, Input, Output, Size, Spawn, Players, Emigration, Time) ); diff --git a/src/systems/droploot.rs b/src/systems/droploot.rs index 604f29f..d9d79d2 100644 --- a/src/systems/droploot.rs +++ b/src/systems/droploot.rs @@ -13,12 +13,15 @@ use crate::{ components::{ Position, Loot, + LootHolder, Trigger, TriggerBox, Flags, - Flag + Flag, + Removed }, resources::{NewEntities, Ground}, + componentwrapper::ComponentWrapper, Pos }; @@ -31,20 +34,25 @@ impl <'a> System<'a> for DropLoot{ ReadStorage<'a, TriggerBox>, ReadStorage<'a, Loot>, Read<'a, Ground>, - ReadStorage<'a, Flags> + ReadStorage<'a, Flags>, + ReadStorage<'a, LootHolder> ); - fn run(&mut self, (positions, mut new, triggerboxes, loots, ground, flags): Self::SystemData) { + fn run(&mut self, (positions, mut new, triggerboxes, loots, ground, flags, lootholders): Self::SystemData) { for (position, triggerbox, loot) in (&positions, &triggerboxes, &loots).join(){ if triggerbox.has_message(&[Trigger::Die, Trigger::Loot]) { - for (template, chance) in &loot.loot { - if *chance > rand::thread_rng().gen_range(0.0, 1.0) { - let pos = if loot.spread { - pick_position(position.pos, &ground, &flags) - } else {position.pos}; - // todo: better error handling - new.create(pos, &template).unwrap(); - } + new.to_build.push((position.pos, vec![ + ComponentWrapper::LootHolder(LootHolder{loot: loot.loot.clone()}), + ComponentWrapper::Removed(Removed) + ])); + } + } + for (position, loot) in (&positions, &lootholders).join() { + for (template, chance) in &loot.loot { + if *chance > rand::thread_rng().gen_range(0.0, 1.0) { + let pos = pick_position(position.pos, &ground, &flags); + // todo: better error handling + new.create(pos, &template).unwrap(); } } } |
