74 lines
2.2 KiB
Rust
74 lines
2.2 KiB
Rust
use core::any::Any;
|
|
use core::sync::atomic::{AtomicI8, Ordering};
|
|
use pkmn_lib_interface::app_interface::list::ImmutableList;
|
|
use pkmn_lib_interface::app_interface::{
|
|
DynamicLibrary, EffectParameter, ExecutingMove, Pokemon, Statistic,
|
|
};
|
|
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
|
|
|
|
macro_rules! change_stat_effect {
|
|
(
|
|
$stat:ident
|
|
) => {
|
|
paste::paste! {
|
|
pub struct [<ChangeTarget $stat>] {
|
|
amount: AtomicI8,
|
|
}
|
|
|
|
impl [<ChangeTarget $stat>] {
|
|
pub const fn get_const_name() -> &'static str {
|
|
stringify!([<"change_target_" $stat:snake>])
|
|
}
|
|
}
|
|
|
|
impl Script for [<ChangeTarget $stat>] {
|
|
fn new() -> Self {
|
|
Self {
|
|
amount: Default::default(),
|
|
}
|
|
}
|
|
|
|
fn get_name(&self) -> &'static str {
|
|
Self::get_const_name()
|
|
}
|
|
|
|
fn get_capabilities(&self) -> &[ScriptCapabilities] {
|
|
&[
|
|
ScriptCapabilities::Initialize,
|
|
ScriptCapabilities::OnSecondaryEffect,
|
|
]
|
|
}
|
|
|
|
fn on_initialize(
|
|
&self,
|
|
_library: &DynamicLibrary,
|
|
parameters: Option<ImmutableList<EffectParameter>>,
|
|
) {
|
|
self.amount.store(
|
|
parameters.unwrap().get(0).unwrap().as_int() as i8,
|
|
Ordering::SeqCst,
|
|
);
|
|
}
|
|
|
|
fn on_secondary_effect(&self, mv: ExecutingMove, target: Pokemon, _hit: u8) {
|
|
target.change_stat_boost(
|
|
Statistic::$stat,
|
|
self.amount.load(Ordering::SeqCst),
|
|
mv.user() == target,
|
|
);
|
|
}
|
|
|
|
fn as_any(&self) -> &dyn Any {
|
|
self
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
change_stat_effect!(Attack);
|
|
change_stat_effect!(Defense);
|
|
change_stat_effect!(SpecialAttack);
|
|
change_stat_effect!(SpecialDefense);
|
|
change_stat_effect!(Speed);
|