use crate::utils::random::Random; use std::fmt::{Debug, Formatter}; use std::sync::Mutex; #[derive(Default)] pub struct BattleRandom { random: Mutex, } impl BattleRandom { pub fn new_with_seed(seed: u128) -> Self { BattleRandom { random: Mutex::new(Random::new(seed)), } } pub fn get_rng(&self) -> &Mutex { &self.random } pub fn get(&self) -> i32 { return self.get_rng().lock().unwrap().get(); } pub fn get_max(&self, max: i32) -> i32 { return self.get_rng().lock().unwrap().get_max(max); } pub fn get_between(&self, min: i32, max: i32) -> i32 { return self.get_rng().lock().unwrap().get_between(min, max); } } impl Debug for BattleRandom { fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { f.debug_struct("BattleRandom").finish() } } impl Clone for BattleRandom { fn clone(&self) -> Self { Self { random: Mutex::new(self.random.lock().unwrap().clone()), } } }