summaryrefslogtreecommitdiff
path: root/src/components/interactable.rs
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-09-21 02:32:22 +0200
committertroido <troido@protonmail.com>2020-09-21 02:32:22 +0200
commite2281d8c6293b311ccc187e3503093a1120e6215 (patch)
treed74043230ec580584e46ead5a123d2922deabfc0 /src/components/interactable.rs
parent92e437e50498f7705e33a556535ba39a2b918f9d (diff)
exchange is now an interaction again
Diffstat (limited to 'src/components/interactable.rs')
-rw-r--r--src/components/interactable.rs28
1 files changed, 18 insertions, 10 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>
-}
-