diff options
| author | troido <troido@protonmail.com> | 2020-09-21 02:32:22 +0200 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-09-21 02:32:22 +0200 |
| commit | e2281d8c6293b311ccc187e3503093a1120e6215 (patch) | |
| tree | d74043230ec580584e46ead5a123d2922deabfc0 /src/systems/interact.rs | |
| parent | 92e437e50498f7705e33a556535ba39a2b918f9d (diff) | |
exchange is now an interaction again
Diffstat (limited to 'src/systems/interact.rs')
| -rw-r--r-- | src/systems/interact.rs | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/systems/interact.rs b/src/systems/interact.rs index 35c30b6..1eb4589 100644 --- a/src/systems/interact.rs +++ b/src/systems/interact.rs @@ -28,7 +28,7 @@ use crate::{ Minable }, controls::{Control}, - resources::{Ground, Emigration}, + resources::{Ground, Emigration, NewEntities}, hashmap, playerstate::RoomPos, PlayerId, @@ -51,10 +51,11 @@ impl <'a> System<'a> for Interact { ReadStorage<'a, Player>, Write<'a, Emigration>, WriteStorage<'a, Whitelist>, - WriteStorage<'a, Minable> + WriteStorage<'a, Minable>, + Read<'a, NewEntities> ); - fn run(&mut self, (entities, controllers, positions, ground, mut cooldowns, interactables, mut triggerbox, mut ears, inventories, visibles, players, mut emigration, mut whitelists, mut minables): Self::SystemData) { + fn run(&mut self, (entities, controllers, positions, ground, mut cooldowns, interactables, mut triggerbox, mut ears, mut inventories, visibles, players, mut emigration, mut whitelists, mut minables, new): Self::SystemData) { for (actor, controller, position) in (&entities, &controllers, &positions).join(){ let mut target = None; let ear = ears.get_mut(actor); @@ -136,6 +137,27 @@ impl <'a> System<'a> for Interact { } } } + Interactable::Exchange(prefix, exchanges) => { + if let Some(txt) = arg { + if let (Some(inventory), Some(action)) = (inventories.get_mut(actor), strip_prefix(&txt, prefix)) { + if let Some(exchange) = exchanges.get(action) { + if exchange.can_trade(inventory){ + exchange.trade(inventory, &new.encyclopedia); + say(ear, format!("Success! '{}' ({})", txt, exchange.show()), name); + } else { + say(ear, format!("You do not have the required items or inventory space for '{}' ({})", txt, exchange.show()), name); + } + } else { + say(ear, format!("Invalid option: {}", action), name); + } + } + } else if let Some(ear) = ear { + ear.sounds.push(Notification::Options{ + description: "".to_string(), + options: exchanges.iter().map(|(id, exchange)| (format!("{}{}", prefix, id), exchange.show())).collect() + }) + } + } } cooldowns.insert(actor, ControlCooldown{amount: cooldown}).unwrap(); } |
