From f47034bdf86e7ddc831ecb8f50689b9b07a0f6ca Mon Sep 17 00:00:00 2001 From: troido Date: Thu, 21 May 2020 12:45:44 +0200 Subject: actually added talk system and removed reply interaction --- src/systems/interact.rs | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/systems/interact.rs') diff --git a/src/systems/interact.rs b/src/systems/interact.rs index b377a7a..2090f6f 100644 --- a/src/systems/interact.rs +++ b/src/systems/interact.rs @@ -82,12 +82,6 @@ impl <'a> System<'a> for Interact { Interactable::Trigger(trigger) => { TriggerBox::add_message(&mut triggerbox, ent, *trigger); } - Interactable::Say(text) => { - say(ear, text.clone(), name); - } - Interactable::Reply(text) => { - say(ear, text.replace("{}", &arg.unwrap()), name); - } Interactable::Exchange(prefix, exchanges) => { if let Some(txt) = arg { if let (Some(inventory), Some(action)) = (inventories.get_mut(actor), strip_prefix(&txt, prefix)) { -- cgit From 1899b27b791734a6b72e28cfb1420536c6035ee4 Mon Sep 17 00:00:00 2001 From: troido Date: Thu, 21 May 2020 15:26:12 +0200 Subject: added exchanger as seperate component/system; refactored other interactions; parameter parsing returns result instead of option --- src/systems/interact.rs | 39 ++++++--------------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) (limited to 'src/systems/interact.rs') diff --git a/src/systems/interact.rs b/src/systems/interact.rs index 2090f6f..bce2afc 100644 --- a/src/systems/interact.rs +++ b/src/systems/interact.rs @@ -28,7 +28,7 @@ use crate::{ Minable }, controls::{Control}, - resources::{Ground, NewEntities, Emigration}, + resources::{Ground, Emigration}, hashmap, playerstate::RoomPos, PlayerId, @@ -45,7 +45,6 @@ impl <'a> System<'a> for Interact { WriteStorage<'a, ControlCooldown>, ReadStorage<'a, Interactable>, WriteStorage<'a, TriggerBox>, - Write<'a, NewEntities>, WriteStorage<'a, Ear>, WriteStorage<'a, Inventory>, ReadStorage<'a, Visible>, @@ -55,21 +54,16 @@ impl <'a> System<'a> for Interact { WriteStorage<'a, Minable> ); - fn run(&mut self, (entities, controllers, positions, ground, mut cooldowns, interactables, mut triggerbox, new, mut ears, mut 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, inventories, visibles, players, mut emigration, mut whitelists, mut minables): Self::SystemData) { for (actor, controller, position) in (&entities, &controllers, &positions).join(){ let mut target = None; let ear = ears.get_mut(actor); match &controller.control { Control::Interact(directions, arg) => { - 'targets: for direction in directions { - let pos = position.pos + direction.to_position(); - for ent in ground.cells.get(&pos).unwrap_or(&HashSet::new()) { - if let Some(interactable) = interactables.get(*ent) { - if interactable.accepts_arg(arg){ - target = Some((*ent, interactable, arg.clone())); - break 'targets; - } - } + for (ent, interactable) in ground.components_near(position.pos, directions, &interactables) { + if interactable.accepts_arg(arg){ + target = Some((ent, interactable, arg.clone())); + break; } } } @@ -82,27 +76,6 @@ impl <'a> System<'a> for Interact { Interactable::Trigger(trigger) => { TriggerBox::add_message(&mut triggerbox, ent, *trigger); } - 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() - }) - } - } Interactable::Visit(dest) => { if let Some(argument) = arg { if let (Some(player), Some(whitelist)) = (players.get(actor), whitelists.get_mut(ent)){ -- cgit From 92e437e50498f7705e33a556535ba39a2b918f9d Mon Sep 17 00:00:00 2001 From: troido Date: Mon, 21 Sep 2020 00:59:38 +0200 Subject: made talk and reply a form of interact again --- src/systems/interact.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/systems/interact.rs') diff --git a/src/systems/interact.rs b/src/systems/interact.rs index bce2afc..35c30b6 100644 --- a/src/systems/interact.rs +++ b/src/systems/interact.rs @@ -73,6 +73,12 @@ impl <'a> System<'a> for Interact { let mut cooldown = 2; let name = visibles.get(ent).map(|v| v.name.as_str()); match interactable { + Interactable::Say(text) => { + say(ear, text.clone(), name); + } + Interactable::Reply(text) => { + say(ear, text.replace("{}", &arg.unwrap()), name); + } Interactable::Trigger(trigger) => { TriggerBox::add_message(&mut triggerbox, ent, *trigger); } -- cgit From e2281d8c6293b311ccc187e3503093a1120e6215 Mon Sep 17 00:00:00 2001 From: troido Date: Mon, 21 Sep 2020 02:32:22 +0200 Subject: exchange is now an interaction again --- src/systems/interact.rs | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'src/systems/interact.rs') 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(); } -- cgit