From 3c8bd5f7c50bac16cafdd15ecb9c8ebadca50f2b Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 10 Sep 2022 13:51:28 +0200 Subject: [PATCH] Implements flinch effect --- gen_7_scripts/src/moves/flinch.rs | 54 +++++++++++++++++++++++++ gen_7_scripts/src/moves/mod.rs | 1 + gen_7_scripts/src/registered_scripts.rs | 1 + 3 files changed, 56 insertions(+) create mode 100644 gen_7_scripts/src/moves/flinch.rs diff --git a/gen_7_scripts/src/moves/flinch.rs b/gen_7_scripts/src/moves/flinch.rs new file mode 100644 index 0000000..f4c71f3 --- /dev/null +++ b/gen_7_scripts/src/moves/flinch.rs @@ -0,0 +1,54 @@ +use crate::script; +use alloc::boxed::Box; +use core::any::Any; +use pkmn_lib_interface::app_interface::{ExecutingMove, Pokemon}; +use pkmn_lib_interface::handling::{Script, ScriptCapabilities}; + +script!(Flinch, "flinch"); + +impl Script for Flinch { + fn new() -> Self { + Self {} + } + + fn get_name(&self) -> &'static str { + Self::get_const_name() + } + + fn get_capabilities(&self) -> &[ScriptCapabilities] { + &[ScriptCapabilities::OnSecondaryEffect] + } + + fn on_secondary_effect(&self, _move: ExecutingMove, target: Pokemon, _hit: u8) { + target.add_volatile(Box::new(FlinchEffect::new())); + } + + fn as_any(&self) -> &dyn Any { + self + } +} + +script!(FlinchEffect, "flinch_effect"); + +impl Script for FlinchEffect { + fn new() -> Self { + Self {} + } + + fn get_name(&self) -> &'static str { + Self::get_const_name() + } + + fn get_capabilities(&self) -> &[ScriptCapabilities] { + &[ScriptCapabilities::PreventMove] + } + + fn prevent_move(&self, mv: ExecutingMove, prevent: &mut bool) { + *prevent = true; + mv.user().remove_volatile(self); + } + + fn as_any(&self) -> &dyn Any { + self + } +} diff --git a/gen_7_scripts/src/moves/mod.rs b/gen_7_scripts/src/moves/mod.rs index fc25546..70b6e3a 100755 --- a/gen_7_scripts/src/moves/mod.rs +++ b/gen_7_scripts/src/moves/mod.rs @@ -10,6 +10,7 @@ pub mod change_all_target_stats; pub mod change_target_stats; pub mod cure_party_status; pub mod drain; +pub mod flinch; pub mod light_screen; pub mod multi_hit_move; pub mod reflect; diff --git a/gen_7_scripts/src/registered_scripts.rs b/gen_7_scripts/src/registered_scripts.rs index 23209b4..20245bb 100755 --- a/gen_7_scripts/src/registered_scripts.rs +++ b/gen_7_scripts/src/registered_scripts.rs @@ -44,6 +44,7 @@ pub fn get_script(category: ScriptCategory, name: &StringKey) -> Option