diff --git a/src/chat.rs b/src/chat.rs index e219fa3..c5afdfc 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -679,7 +679,7 @@ pub fn handle_chat_events( } } ChatEvent::GotoIf(condition, goto) => { - if condition != "" { + if vars.evaluate(condition, &chat.talker.actor_id) { chat.position = goto.clone(); } } diff --git a/src/chats/serenity.yaml b/src/chats/serenity.yaml index f2fed59..ec3b256 100644 --- a/src/chats/serenity.yaml +++ b/src/chats/serenity.yaml @@ -17,14 +17,13 @@ - chat: Icarus -- if: $talked_before +- if: $met then: - Oh hey, you're back! - - Nice to see you again! - - goto: back + - How are you doing? + - goto: howru - Oh hey, you're awake! -- set: $talked_before -- label: back +- set: $met - I found you drifting out cold, and thought, I better watch over you. - Took us here behind that moonlet, to shield you from the micros. - Thank you!: diff --git a/src/var.rs b/src/var.rs index 952e9be..93f727a 100644 --- a/src/var.rs +++ b/src/var.rs @@ -224,17 +224,15 @@ impl GameVars { return None; } - #[allow(dead_code)] pub fn getb(&self, key: &str) -> bool { if let Some(value) = self.db.get(key) { - return value != "0"; + return Self::evaluate_str_as_bool(value); } return false; } - #[allow(dead_code)] - pub fn set(&mut self, key: &str, value: String) { - self.db.insert(key.to_lowercase(), value); + pub fn evaluate_str_as_bool(string: &str) -> bool { + return string != "0"; } // This method ensures that the variable name contains a scope separator, @@ -279,4 +277,21 @@ impl GameVars { let key = Self::normalize_varname(fallback_scope, key); self.db.insert(key, value); } + + pub fn evaluate(&self, condition: &str, scope: &str) -> bool { + let parts: Vec<&str> = condition.split(" ").collect(); + if parts.len() == 1 { + let part = parts[0]; + if part.contains(SCOPE_SEPARATOR) { + let part = Self::normalize_varname(scope, part); + let value_bool = self.getb(part.as_str()); + return value_bool; + } + else { + return Self::evaluate_str_as_bool(part); + } + } else { + return false; + } + } }