PkmnLib_rs/src/ffi/dynamic_data/libraries/battle_stat_calculator.rs

62 lines
2.1 KiB
Rust

use crate::dynamic_data::{BattleStatCalculator, Gen7BattleStatCalculator, Pokemon};
use crate::ffi::ffi_handle::{FFIHandle, FromFFIHandle};
use crate::ffi::{ExternPointer, FFIResult};
use crate::static_data::{Statistic, StatisticSet};
use std::ops::Deref;
use std::sync::Arc;
/// Creates a new Gen 7 battle stat calculator
#[no_mangle]
extern "C" fn gen_7_battle_stat_calculator_new() -> FFIHandle<Arc<dyn BattleStatCalculator>> {
let v: Arc<dyn BattleStatCalculator> = Arc::new(Gen7BattleStatCalculator::new());
FFIHandle::get_handle(v.into())
}
/// Calculate all the flat stats of a Pokemon, disregarding stat boosts.
#[no_mangle]
extern "C" fn battle_stat_calculator_calculate_flat_stats(
ptr: FFIHandle<Arc<dyn BattleStatCalculator>>,
pokemon: ExternPointer<Pokemon>,
stats: FFIHandle<Arc<StatisticSet<u32>>>,
) -> FFIResult<()> {
ptr.from_ffi_handle()
.calculate_flat_stats(pokemon.as_ref(), stats.from_ffi_handle().deref())
.into()
}
/// Calculate a single flat stat of a Pokemon, disregarding stat boost
#[no_mangle]
extern "C" fn battle_stat_calculator_calculate_flat_stat(
ptr: FFIHandle<Arc<dyn BattleStatCalculator>>,
pokemon: FFIHandle<Pokemon>,
stat: Statistic,
) -> FFIResult<u32> {
ptr.from_ffi_handle()
.calculate_flat_stat(&pokemon.from_ffi_handle(), stat)
.into()
}
/// Calculate all the boosted stats of a Pokemon, including stat boosts.
#[no_mangle]
extern "C" fn battle_stat_calculator_calculate_boosted_stats(
ptr: FFIHandle<Arc<dyn BattleStatCalculator>>,
pokemon: FFIHandle<Pokemon>,
stats: FFIHandle<Arc<StatisticSet<u32>>>,
) -> FFIResult<()> {
ptr.from_ffi_handle()
.calculate_boosted_stats(&pokemon.from_ffi_handle(), stats.from_ffi_handle().deref())
.into()
}
/// Calculate a single boosted stat of a Pokemon, including stat boosts.
#[no_mangle]
extern "C" fn battle_stat_calculator_calculate_boosted_stat(
ptr: FFIHandle<Arc<dyn BattleStatCalculator>>,
pokemon: FFIHandle<Pokemon>,
stat: Statistic,
) -> FFIResult<u32> {
ptr.from_ffi_handle()
.calculate_boosted_stat(&pokemon.from_ffi_handle(), stat)
.into()
}