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/components | |
| parent | 92e437e50498f7705e33a556535ba39a2b918f9d (diff) | |
exchange is now an interaction again
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/interactable.rs | 28 | ||||
| -rw-r--r-- | src/components/mod.rs | 2 |
2 files changed, 19 insertions, 11 deletions
diff --git a/src/components/interactable.rs b/src/components/interactable.rs index 2e286cf..2f20966 100644 --- a/src/components/interactable.rs +++ b/src/components/interactable.rs @@ -8,7 +8,9 @@ use crate::{ exchange::Exchange, components::{Trigger, equipment::Stat}, RoomId, - parameter::Parameter + parameter::Parameter, + fromtoparameter::FromToParameter, + ItemId, }; #[derive(Component, Debug, Clone, PartialEq)] @@ -18,7 +20,8 @@ pub enum Interactable { Visit(RoomId), Mine(Stat), Say(String), - Reply(String) + Reply(String), + Exchange(String, HashMap<String, Exchange>), } use Interactable::*; @@ -32,7 +35,12 @@ impl Interactable { ("mine", Parameter::String(s)) => Mine(Stat::from_str(s)?), ("say", Parameter::String(s)) => Say(s.clone()), ("reply", Parameter::String(s)) => Reply(s.clone()), - _ => None? + ("exchange", p) => { + let (prefix, trades) = <(String, Vec<(String, Vec<ItemId>, Vec<ItemId>)>)>::from_parameter(p.clone())?; + let exchanges = trades.into_iter().map(|(k, cost, offer)| (k, Exchange{cost, offer})).collect(); + Exchange(prefix, exchanges) + } + _ => {return None} }) } @@ -49,15 +57,15 @@ impl Interactable { Mine(_) => arg.is_none(), Say(_) => arg.is_none(), Reply(_) => arg.is_some(), + Exchange(prefix, _exchanges) => { + if let Some(txt) = arg { + txt.starts_with(prefix) + } else { + true + } + }, } } } -#[derive(Component, Debug, Clone, PartialEq)] -#[storage(HashMapStorage)] -pub struct Exchanger { - pub prefix: String, - pub exchanges: HashMap<String, Exchange> -} - diff --git a/src/components/mod.rs b/src/components/mod.rs index f315060..38a14bd 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -16,7 +16,7 @@ pub use messages::{ TriggerBox }; pub use faction::Faction; -pub use interactable::{Interactable, Exchanger}; +pub use interactable::{Interactable}; pub use equipment::Equipment; pub use inventory::Inventory; pub use serialise::Serialise; |
