Implements Drain moves

This commit is contained in:
Deukhoofd 2022-09-10 12:54:34 +02:00
parent 19706c4c3c
commit 349dafcb4b
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
4 changed files with 56 additions and 0 deletions

View File

@ -10,6 +10,7 @@ crate-type = ["cdylib"]
[dependencies]
pkmn_lib_interface = { path = "../pkmn_lib_interface" }
paste = { version = "1.0.7" }
atomic_float = "0.1.0"
[dev-dependencies]
pkmn_lib_interface = { path = "../pkmn_lib_interface", features = ["mock_data"] }

View File

@ -0,0 +1,53 @@
use crate::script;
use atomic_float::AtomicF32;
use core::any::Any;
use core::sync::atomic::Ordering;
use pkmn_lib_interface::app_interface::list::ImmutableList;
use pkmn_lib_interface::app_interface::{DynamicLibrary, EffectParameter, ExecutingMove, Pokemon};
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
script!(Drain, "drain", heal_modifier: AtomicF32);
impl Script for Drain {
fn new() -> Self {
Self {
heal_modifier: 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.heal_modifier.store(
parameters.unwrap().get(0).unwrap().as_float(),
Ordering::SeqCst,
);
}
fn on_secondary_effect(&self, mv: ExecutingMove, target: Pokemon, hit: u8) {
let hit_data = mv.get_hit_data(&target, hit);
let damage = hit_data.damage();
let mut modifier = self.heal_modifier.load(Ordering::SeqCst);
if mv.user().has_held_item("big_root") {
modifier *= 1.3;
}
mv.user().heal((damage as f32 * modifier) as u32, false);
}
fn as_any(&self) -> &dyn Any {
self
}
}

View File

@ -9,6 +9,7 @@ pub mod automize;
pub mod change_all_target_stats;
pub mod change_target_stats;
pub mod cure_party_status;
pub mod drain;
pub mod light_screen;
pub mod multi_hit_move;
pub mod reflect;

View File

@ -43,6 +43,7 @@ pub fn get_script(category: ScriptCategory, name: &StringKey) -> Option<Box<dyn
change_target_stats::ChangeTargetSpecialDefense,
change_target_stats::ChangeTargetSpeed,
cure_party_status::CurePartyStatus,
drain::Drain,
);
}
ScriptCategory::Ability => {}