Implements struggle.
This commit is contained in:
parent
349dafcb4b
commit
156b4e146d
|
@ -13,3 +13,4 @@ pub mod drain;
|
||||||
pub mod light_screen;
|
pub mod light_screen;
|
||||||
pub mod multi_hit_move;
|
pub mod multi_hit_move;
|
||||||
pub mod reflect;
|
pub mod reflect;
|
||||||
|
pub mod struggle;
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
|
@ -44,6 +44,7 @@ pub fn get_script(category: ScriptCategory, name: &StringKey) -> Option<Box<dyn
|
||||||
change_target_stats::ChangeTargetSpeed,
|
change_target_stats::ChangeTargetSpeed,
|
||||||
cure_party_status::CurePartyStatus,
|
cure_party_status::CurePartyStatus,
|
||||||
drain::Drain,
|
drain::Drain,
|
||||||
|
struggle::Struggle,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
ScriptCategory::Ability => {}
|
ScriptCategory::Ability => {}
|
||||||
|
|
|
@ -291,6 +291,8 @@ pub enum DamageSource {
|
||||||
MoveDamage = 0,
|
MoveDamage = 0,
|
||||||
/// The damage is done by something else.
|
/// The damage is done by something else.
|
||||||
Misc = 1,
|
Misc = 1,
|
||||||
|
/// The damage is done because of struggling.
|
||||||
|
Struggle = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
crate::handling::cacheable::cacheable!(Pokemon);
|
crate::handling::cacheable::cacheable!(Pokemon);
|
||||||
|
|
Loading…
Reference in New Issue