Browse Source

Fix player.add

main
ThePerkinrex 4 years ago
parent
commit
66f2cf6349
No known key found for this signature in database GPG Key ID: FD81DE6D75E20917
  1. 13
      server/src/games/run.rs
  2. 2
      server/src/games/run/types.rs

13
server/src/games/run.rs

@ -1,6 +1,6 @@
use rhai::{ use rhai::{
serde::{from_dynamic, to_dynamic}, serde::{from_dynamic, to_dynamic},
Dynamic, Func, AST, Dynamic, EvalAltResult, Func, AST,
}; };
use uuid::Uuid; use uuid::Uuid;
@ -138,9 +138,17 @@ impl RunningGame {
fn turn_end(&mut self) -> RhaiResult<()> { fn turn_end(&mut self) -> RhaiResult<()> {
let data = self.data_as_dynamic()?; 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])?; self.save_data(&arr[0])?;
log::debug!("Turn ended for: {}", self.current_player);
self.current_player = arr.remove(1).cast(); self.current_player = arr.remove(1).cast();
log::debug!("New current: {}", self.current_player);
self.has_finished = arr.remove(1).cast(); self.has_finished = arr.remove(1).cast();
self.turn_start() self.turn_start()
} }
@ -151,6 +159,7 @@ impl RunningGame {
.functions .functions
.turn_start(data, self.current_player) .turn_start(data, self.current_player)
.transpose()?; .transpose()?;
log::debug!("Turn started for: {}", self.current_player);
if let Some(data) = data { if let Some(data) = data {
self.save_data(&data)?; self.save_data(&data)?;
} }

2
server/src/games/run/types.rs

@ -26,7 +26,7 @@ impl Player {
rhai_error("Can't add negative players")?; rhai_error("Can't add negative players")?;
} }
if self.num + n as u32 >= self.max { 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 { } else {
self.num += n as u32; self.num += n as u32;
} }

Loading…
Cancel
Save