Implements struggle.

This commit is contained in:
Deukhoofd 2022-09-10 13:08:44 +02:00
parent 349dafcb4b
commit 156b4e146d
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
4 changed files with 59 additions and 0 deletions

View File

@ -13,3 +13,4 @@ pub mod drain;
pub mod light_screen;
pub mod multi_hit_move;
pub mod reflect;
pub mod struggle;

View File

@ -0,0 +1,55 @@
use crate::script;
use core::any::Any;
use pkmn_lib_interface::app_interface::{DamageSource, ExecutingMove, Pokemon, TurnChoice};
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
script!(Struggle, "struggle");
impl Script for Struggle {
fn new() -> Self {
Self {}
}
fn get_name(&self) -> &'static str {
Self::get_const_name()
}
fn get_capabilities(&self) -> &[ScriptCapabilities] {
&[
ScriptCapabilities::ChangeEffectiveness,
ScriptCapabilities::IsInvulnerable,
ScriptCapabilities::ChangeNumberOfHits,
ScriptCapabilities::OnSecondaryEffect,
]
}
fn change_effectiveness(
&self,
_move: ExecutingMove,
_target: Pokemon,
_hit: u8,
effectiveness: &mut f32,
) {
*effectiveness = 1.0;
}
fn is_invulnerable(&self, _move: ExecutingMove, _target: Pokemon, invulnerable: &mut bool) {
*invulnerable = false;
}
fn change_number_of_hits(&self, _choice: TurnChoice, number_of_hits: &mut u8) {
*number_of_hits = 1
}
fn on_secondary_effect(&self, mv: ExecutingMove, _target: Pokemon, hit: u8) {
let mut damage = mv.user().max_health() / 4;
if damage == 0 {
damage = 1
}
mv.user().damage(damage, DamageSource::Struggle);
}
fn as_any(&self) -> &dyn Any {
self
}
}

View File

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

View File

@ -291,6 +291,8 @@ pub enum DamageSource {
MoveDamage = 0,
/// The damage is done by something else.
Misc = 1,
/// The damage is done because of struggling.
Struggle = 2,
}
crate::handling::cacheable::cacheable!(Pokemon);