Adds attract

This commit is contained in:
2022-09-10 10:29:00 +02:00
parent 4275816fd9
commit 19d2705221
8 changed files with 131 additions and 3 deletions

View File

@@ -13,6 +13,7 @@ use pkmn_lib_interface::set_load_script_fn;
pub mod registered_scripts;
pub mod moves;
pub mod pokemon;
pub mod util_scripts;
pub(crate) mod utils;

View File

@@ -0,0 +1,40 @@
use crate::pokemon::infatuated::Infatuated;
use crate::script;
use core::any::Any;
use pkmn_lib_interface::app_interface::{ExecutingMove, Gender, Pokemon};
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
script!(Attract, "attract");
impl Script for Attract {
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, mv: ExecutingMove, target: Pokemon, hit: u8) {
let user_gender = mv.user().gender();
let target_gender = target.gender();
// If the move is used on a Pokémon that is the same gender as the user, it will fail
if target_gender == user_gender {
return mv.get_hit_data(&target, hit).fail();
}
// It will also fail if used by or on a gender-unknown Pokémon
if user_gender == Gender::Genderless || target_gender == Gender::Genderless {
return mv.get_hit_data(&target, hit).fail();
}
// If the target is the opposite gender of the Pokémon who launched the move, the target becomes infatuated
target.add_volatile_by_name(Infatuated::get_const_name());
}
fn as_any(&self) -> &dyn Any {
self
}
}

View File

@@ -1,6 +1,7 @@
pub mod acrobatics;
pub mod acupressure;
pub mod after_you;
pub mod multi_hit_move;
pub mod assist;
pub mod assurance;
pub mod attract;
pub mod multi_hit_move;

View File

@@ -0,0 +1,30 @@
use crate::script;
use core::any::Any;
use pkmn_lib_interface::app_interface::ExecutingMove;
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
script!(Infatuated, "infatuated");
impl Script for Infatuated {
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) {
if mv.user().battle().unwrap().random().get_max(2) == 0 {
*prevent = true
}
}
fn as_any(&self) -> &dyn Any {
self
}
}

View File

@@ -0,0 +1 @@
pub mod infatuated;

View File

@@ -1,4 +1,5 @@
use crate::moves::*;
use crate::pokemon::*;
use alloc::boxed::Box;
use pkmn_lib_interface::app_interface::{get_hash, StringKey};
use pkmn_lib_interface::handling::{Script, ScriptCategory};
@@ -32,11 +33,14 @@ pub fn get_script(category: ScriptCategory, name: &StringKey) -> Option<Box<dyn
assist::Assist,
assurance::Assurance,
multi_hit_move::MultiHitMove,
attract::Attract,
);
}
ScriptCategory::Ability => {}
ScriptCategory::Status => {}
ScriptCategory::Pokemon => {}
ScriptCategory::Pokemon => {
resolve_match!(name.hash(), infatuated::Infatuated,)
}
ScriptCategory::Battle => {
resolve_match!(name.hash(), crate::util_scripts::ForceEffectTriggerScript,)
}