50 lines
1.2 KiB
Rust
50 lines
1.2 KiB
Rust
use crate::common_usings::*;
|
|
|
|
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<Vec<Rc<EffectParameter>>>,
|
|
) -> PkmnResult<()> {
|
|
self.heal_modifier.store(
|
|
parameters.unwrap().get(0).unwrap().as_float(),
|
|
Ordering::SeqCst,
|
|
);
|
|
Ok(())
|
|
}
|
|
|
|
fn on_secondary_effect(&self, mv: ExecutingMove, target: Pokemon, hit: u8) -> PkmnResult<()> {
|
|
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)?;
|
|
Ok(())
|
|
}
|
|
|
|
fn as_any(&self) -> &dyn Any {
|
|
self
|
|
}
|
|
}
|