A lot more documentation, some initial work on the script resolver.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -7,32 +7,43 @@ use crate::dynamic_data::script_handling::ScriptSource;
|
||||
use crate::script_hook;
|
||||
use crate::utils::Random;
|
||||
|
||||
/// The RNG for a battle.
|
||||
#[derive(Default)]
|
||||
pub struct BattleRandom {
|
||||
/// The actual underlying RNG. This is in a mutex, so it is thread safe, and can be ran
|
||||
/// predictably, with guaranteed the same outputs.
|
||||
random: Mutex<Random>,
|
||||
}
|
||||
|
||||
impl BattleRandom {
|
||||
/// Initializes a new RNG with a given seed.
|
||||
pub fn new_with_seed(seed: u128) -> Self {
|
||||
BattleRandom {
|
||||
random: Mutex::new(Random::new(seed)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the underlying random number generator.
|
||||
pub fn get_rng(&self) -> &Mutex<Random> {
|
||||
&self.random
|
||||
}
|
||||
|
||||
/// Get a random 32 bit integer. Can be any value between min int and max int.
|
||||
pub fn get(&self) -> i32 {
|
||||
return self.get_rng().lock().unwrap().get();
|
||||
}
|
||||
/// Get a random 32 bit integer between 0 and max.
|
||||
pub fn get_max(&self, max: i32) -> i32 {
|
||||
return self.get_rng().lock().unwrap().get_max(max);
|
||||
}
|
||||
/// Get a random 32 bit integer between min and max.
|
||||
pub fn get_between(&self, min: i32, max: i32) -> i32 {
|
||||
return self.get_rng().lock().unwrap().get_between(min, max);
|
||||
}
|
||||
|
||||
/// Gets whether or not a move triggers its secondary effect. This takes its chance, and
|
||||
/// rolls whether it triggers. As a side effect this run scripts to allow modifying this random
|
||||
/// chance.
|
||||
pub fn effect_chance(
|
||||
&self,
|
||||
mut chance: f32,
|
||||
|
||||
Reference in New Issue
Block a user