2022-06-03 14:35:18 +00:00
|
|
|
use crate::utils::random::Random;
|
|
|
|
use std::fmt::{Debug, Formatter};
|
2022-06-04 10:40:32 +00:00
|
|
|
use std::sync::Mutex;
|
2022-06-03 14:35:18 +00:00
|
|
|
|
2022-06-04 10:40:32 +00:00
|
|
|
#[derive(Default)]
|
2022-06-03 14:35:18 +00:00
|
|
|
pub struct BattleRandom {
|
2022-06-04 10:40:32 +00:00
|
|
|
random: Mutex<Random>,
|
2022-06-03 14:35:18 +00:00
|
|
|
}
|
|
|
|
|
2022-06-04 10:40:32 +00:00
|
|
|
impl BattleRandom {
|
|
|
|
pub fn new_with_seed(seed: u128) -> Self {
|
|
|
|
BattleRandom {
|
|
|
|
random: Mutex::new(Random::new(seed)),
|
|
|
|
}
|
2022-06-03 14:35:18 +00:00
|
|
|
}
|
|
|
|
|
2022-06-04 10:40:32 +00:00
|
|
|
pub fn get_rng(&self) -> &Mutex<Random> {
|
|
|
|
&self.random
|
2022-06-03 14:35:18 +00:00
|
|
|
}
|
2022-06-04 10:40:32 +00:00
|
|
|
}
|
2022-06-03 14:35:18 +00:00
|
|
|
|
2022-06-04 10:40:32 +00:00
|
|
|
impl Debug for BattleRandom {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
|
|
|
|
f.debug_struct("BattleRandom").finish()
|
2022-06-03 14:35:18 +00:00
|
|
|
}
|
2022-06-04 10:40:32 +00:00
|
|
|
}
|
2022-06-03 14:35:18 +00:00
|
|
|
|
2022-06-04 10:40:32 +00:00
|
|
|
impl Clone for BattleRandom {
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
Self {
|
|
|
|
random: Mutex::new(self.random.lock().unwrap().clone()),
|
|
|
|
}
|
2022-06-03 14:35:18 +00:00
|
|
|
}
|
|
|
|
}
|