diff --git a/server/src/games/run.rs b/server/src/games/run.rs index a17f324..bb8f72b 100644 --- a/server/src/games/run.rs +++ b/server/src/games/run.rs @@ -1,6 +1,6 @@ use rhai::{ serde::{from_dynamic, to_dynamic}, - Dynamic, Func, AST, + Dynamic, EvalAltResult, Func, AST, }; use uuid::Uuid; @@ -138,9 +138,17 @@ impl RunningGame { fn turn_end(&mut self) -> RhaiResult<()> { let data = self.data_as_dynamic()?; - let mut arr = self.functions.turn_end(data, self.current_player)?; + let mut arr = match self.functions.turn_end(data, self.current_player) { + Err(x) => match x.as_ref() { + EvalAltResult::Return(x, _) => Ok(x.clone_cast()), + _ =>{log::debug!("ERR: {}", x);Err(x)}, + }, + x => x, + }?; self.save_data(&arr[0])?; + log::debug!("Turn ended for: {}", self.current_player); self.current_player = arr.remove(1).cast(); + log::debug!("New current: {}", self.current_player); self.has_finished = arr.remove(1).cast(); self.turn_start() } @@ -151,6 +159,7 @@ impl RunningGame { .functions .turn_start(data, self.current_player) .transpose()?; + log::debug!("Turn started for: {}", self.current_player); if let Some(data) = data { self.save_data(&data)?; } diff --git a/server/src/games/run/types.rs b/server/src/games/run/types.rs index 9d36aac..ee08577 100644 --- a/server/src/games/run/types.rs +++ b/server/src/games/run/types.rs @@ -26,7 +26,7 @@ impl Player { rhai_error("Can't add negative players")?; } if self.num + n as u32 >= self.max { - self.add(n - self.max as i64)?; + self.num = (self.num + n as u32) % self.max; } else { self.num += n as u32; }