First chunk of battling is now fully working, along with integration tests! 🎉
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2022-06-17 19:53:33 +02:00
parent 59cc150643
commit b6ddd1ee13
34 changed files with 1934 additions and 1293 deletions

View File

@@ -40,6 +40,7 @@ pub trait DamageLibrary: std::fmt::Debug {
hit_data: &HitData,
) -> f32;
}
#[derive(Debug)]
pub struct Gen7DamageLibrary {
has_randomness: bool,
@@ -93,8 +94,14 @@ impl DamageLibrary for Gen7DamageLibrary {
}
if self.has_randomness {
let battle = executing_move.user().read().get_battle().unwrap().upgrade().unwrap();
let random_percentage = 85 + battle.read().random().get_between(0, 16);
let random_percentage = 85
+ executing_move
.user()
.read()
.get_battle()
.unwrap()
.random()
.get_between(0, 16);
float_damage = (float_damage * (random_percentage as f32 / 100.0)).floor();
}

View File

@@ -10,14 +10,32 @@ use crate::{PkmnResult, StringKey};
#[derive(Debug)]
pub struct DynamicLibrary {
static_data: StaticData<'static>,
static_data: StaticData,
stat_calculator: BattleStatCalculator,
damage_calculator: Box<dyn DamageLibrary>,
misc_library: Box<dyn MiscLibrary<'static>>,
}
impl<'library> DynamicLibrary {
pub fn static_data(&self) -> &StaticData<'library> {
unsafe impl Sync for DynamicLibrary {}
unsafe impl Send for DynamicLibrary {}
impl DynamicLibrary {
pub fn new(
static_data: StaticData,
stat_calculator: BattleStatCalculator,
damage_calculator: Box<dyn DamageLibrary>,
misc_library: Box<dyn MiscLibrary<'static>>,
) -> Self {
Self {
static_data,
stat_calculator,
damage_calculator,
misc_library,
}
}
pub fn static_data(&self) -> &StaticData {
&self.static_data
}
pub fn stat_calculator(&self) -> &BattleStatCalculator {