Adds HealEachEndOfTurn effect, move common usings for scripts to separate file
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2023-01-28 13:59:54 +01:00
parent 44a169cba7
commit 2df5feab26
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
28 changed files with 153 additions and 105 deletions

View File

@ -0,0 +1,12 @@
pub use crate::script;
pub use alloc::boxed::Box;
pub use alloc::rc::Rc;
pub use atomic_float::AtomicF32;
pub use core::any::Any;
pub use core::sync::atomic::{AtomicBool, AtomicI8, AtomicU32, Ordering};
pub use pkmn_lib_interface::app_interface::list::ImmutableList;
pub use pkmn_lib_interface::app_interface::{
get_volatile_as, BattleSide, DamageSource, DynamicLibrary, EffectParameter, ExecutingMove,
Gender, MoveCategory, MoveData, Party, Pokemon, Statistic, StringKey, TurnChoice,
};
pub use pkmn_lib_interface::handling::{Script, ScriptCapabilities, ScriptOwner};

View File

@ -15,6 +15,7 @@ use pkmn_lib_interface::set_load_script_fn;
#[macro_use]
pub mod registered_scripts;
pub(crate) mod common_usings;
pub mod moves;
pub mod pokemon;
pub mod util_scripts;

View File

@ -1,7 +1,4 @@
use crate::script;
use core::any::Any;
use pkmn_lib_interface::app_interface::{ExecutingMove, Pokemon};
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
use crate::common_usings::*;
script!(Acrobatics, "acrobatics");

View File

@ -1,7 +1,5 @@
use core::any::Any;
use crate::common_usings::*;
use core::mem::transmute;
use pkmn_lib_interface::app_interface::{ExecutingMove, Pokemon, Statistic};
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
pub struct Acupressure {}

View File

@ -1,6 +1,4 @@
use core::any::Any;
use pkmn_lib_interface::app_interface::{ExecutingMove, Pokemon};
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
use crate::common_usings::*;
pub struct AfterYou {}

View File

@ -1,8 +1,5 @@
use crate::script;
use crate::common_usings::*;
use alloc::vec::Vec;
use core::any::Any;
use pkmn_lib_interface::app_interface::{MoveData, Party, Pokemon, StringKey, TurnChoice};
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
script!(Assist, "assist");

View File

@ -1,11 +1,4 @@
use crate::script;
use alloc::boxed::Box;
use core::any::Any;
use core::sync::atomic::{AtomicBool, Ordering};
use pkmn_lib_interface::app_interface::{
get_volatile_as, BattleSide, DamageSource, ExecutingMove, Pokemon, TurnChoice,
};
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
use crate::common_usings::*;
script!(Assurance, "assurance");

View File

@ -1,8 +1,5 @@
use crate::common_usings::*;
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");

View File

@ -1,13 +1,7 @@
use crate::common_usings::*;
use crate::moves::light_screen::LightScreenEffect;
use crate::moves::reflect::ReflectEffect;
use crate::script;
use crate::weather::hail::Hail;
use alloc::boxed::Box;
use core::any::Any;
use core::sync::atomic::{AtomicU32, Ordering};
use pkmn_lib_interface::app_interface::{ExecutingMove, MoveCategory, Pokemon};
use pkmn_lib_interface::handling::ScriptCapabilities::OnEndTurn;
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
script!(AuroraVeil, "aurora_veil");
@ -60,7 +54,10 @@ impl Script for AuroraVeilEffect {
}
fn get_capabilities(&self) -> &[ScriptCapabilities] {
&[ScriptCapabilities::ChangeIncomingDamage, OnEndTurn]
&[
ScriptCapabilities::ChangeIncomingDamage,
ScriptCapabilities::OnEndTurn,
]
}
fn change_incoming_damage(

View File

@ -1,7 +1,4 @@
use crate::script;
use core::any::Any;
use pkmn_lib_interface::app_interface::{ExecutingMove, Pokemon, Statistic};
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
use crate::common_usings::*;
script!(Automize, "automize");

View File

@ -1,12 +1,4 @@
use crate::script;
use alloc::rc::Rc;
use core::any::Any;
use core::sync::atomic::{AtomicI8, Ordering};
use pkmn_lib_interface::app_interface::list::ImmutableList;
use pkmn_lib_interface::app_interface::{
DynamicLibrary, EffectParameter, ExecutingMove, Pokemon, Statistic,
};
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
use crate::common_usings::*;
script!(
ChangeAllTargetStats,

View File

@ -1,11 +1,4 @@
use alloc::rc::Rc;
use core::any::Any;
use core::sync::atomic::{AtomicI8, Ordering};
use pkmn_lib_interface::app_interface::list::ImmutableList;
use pkmn_lib_interface::app_interface::{
DynamicLibrary, EffectParameter, ExecutingMove, Pokemon, Statistic,
};
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
use crate::common_usings::*;
macro_rules! change_stat_effect {
(

View File

@ -1,7 +1,4 @@
use crate::script;
use core::any::Any;
use pkmn_lib_interface::app_interface::{ExecutingMove, Pokemon};
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
use crate::common_usings::*;
script!(CurePartyStatus, "cure_party_status");

View File

@ -1,11 +1,4 @@
use crate::script;
use alloc::rc::Rc;
use atomic_float::AtomicF32;
use core::any::Any;
use core::sync::atomic::Ordering;
use pkmn_lib_interface::app_interface::list::ImmutableList;
use pkmn_lib_interface::app_interface::{DynamicLibrary, EffectParameter, ExecutingMove, Pokemon};
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
use crate::common_usings::*;
script!(Drain, "drain", heal_modifier: AtomicF32);

View File

@ -1,8 +1,4 @@
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};
use crate::common_usings::*;
script!(Flinch, "flinch");

View File

@ -0,0 +1,53 @@
use crate::common_usings::*;
use crate::pokemon::heal_each_end_of_turn::HealEachEndOfTurnEffect;
script!(
HealEachEndOfTurn,
"heal_each_end_of_turn",
heal_percent: AtomicF32
);
impl Script for HealEachEndOfTurn {
fn new() -> Self {
Self {
heal_percent: 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<ImmutableList<Rc<EffectParameter>>>,
) {
self.heal_percent.store(
parameters.unwrap().get(0).unwrap().as_float() / 100.0,
Ordering::SeqCst,
);
}
fn on_secondary_effect(&self, _mv: ExecutingMove, target: Pokemon, _hit: u8) {
let script = target.add_volatile_by_name("heal_each_end_of_turn_effect");
let amount = self.heal_percent.load(Ordering::SeqCst);
script
.as_any()
.downcast_ref::<HealEachEndOfTurnEffect>()
.unwrap()
.heal_percent
.store(amount, Ordering::SeqCst);
}
fn as_any(&self) -> &dyn Any {
self
}
}

View File

@ -15,3 +15,4 @@ pub mod light_screen;
pub mod multi_hit_move;
pub mod reflect;
pub mod struggle;
pub mod heal_each_end_of_turn;

View File

@ -1,6 +1,4 @@
use core::any::Any;
use pkmn_lib_interface::app_interface::TurnChoice;
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
use crate::common_usings::*;
pub struct MultiHitMove {}

View File

@ -1,7 +1,4 @@
use crate::script;
use core::any::Any;
use pkmn_lib_interface::app_interface::{DamageSource, ExecutingMove, Pokemon, TurnChoice};
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
use crate::common_usings::*;
script!(Struggle, "struggle");
@ -23,6 +20,14 @@ impl Script for Struggle {
]
}
fn change_number_of_hits(&self, _choice: TurnChoice, number_of_hits: &mut u8) {
*number_of_hits = 1
}
fn is_invulnerable(&self, _move: ExecutingMove, _target: Pokemon, invulnerable: &mut bool) {
*invulnerable = false;
}
fn change_effectiveness(
&self,
_move: ExecutingMove,
@ -33,14 +38,6 @@ impl Script for Struggle {
*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 {

View File

@ -0,0 +1,38 @@
use crate::common_usings::*;
script!(
HealEachEndOfTurnEffect,
"heal_each_end_of_turn_effect",
pub heal_percent: AtomicF32
);
impl Script for HealEachEndOfTurnEffect {
fn new() -> Self {
Self {
heal_percent: Default::default(),
}
}
fn get_name(&self) -> &'static str {
Self::get_const_name()
}
fn get_capabilities(&self) -> &[ScriptCapabilities] {
&[ScriptCapabilities::OnEndTurn]
}
fn on_end_turn(&self) {
if let Some(ScriptOwner::Pokemon(pokemon)) = self.get_owner() {
let mut amount =
pokemon.max_health() as f32 * self.heal_percent.load(Ordering::Relaxed);
if pokemon.has_held_item("big_root") {
amount *= 1.3;
}
pokemon.heal(amount as u32, false);
}
}
fn as_any(&self) -> &dyn Any {
self
}
}

View File

@ -1,7 +1,4 @@
use crate::script;
use core::any::Any;
use pkmn_lib_interface::app_interface::ExecutingMove;
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
use crate::common_usings::*;
script!(Infatuated, "infatuated");

View File

@ -1 +1,2 @@
pub mod heal_each_end_of_turn;
pub mod infatuated;

View File

@ -1,4 +1,5 @@
use crate::moves::*;
use crate::pokemon;
use crate::pokemon::*;
use alloc::boxed::Box;
use pkmn_lib_interface::app_interface::{get_hash, StringKey};
@ -25,14 +26,13 @@ macro_rules! resolve_match {
pub fn get_script(category: ScriptCategory, name: &StringKey) -> Option<Box<dyn Script>> {
match category {
ScriptCategory::Move => {
resolve_match!(
resolve_match! {
name.hash(),
acrobatics::Acrobatics,
acupressure::Acupressure,
after_you::AfterYou,
assist::Assist,
assurance::Assurance,
multi_hit_move::MultiHitMove,
attract::Attract,
aurora_veil::AuroraVeil,
automize::Automize,
@ -45,16 +45,22 @@ pub fn get_script(category: ScriptCategory, name: &StringKey) -> Option<Box<dyn
cure_party_status::CurePartyStatus,
drain::Drain,
flinch::Flinch,
crate::moves::heal_each_end_of_turn::HealEachEndOfTurn,
multi_hit_move::MultiHitMove,
struggle::Struggle,
);
};
}
ScriptCategory::Ability => {}
ScriptCategory::Status => {}
ScriptCategory::Pokemon => {
resolve_match!(name.hash(), infatuated::Infatuated,)
resolve_match! {
name.hash(),
infatuated::Infatuated,
pokemon::heal_each_end_of_turn::HealEachEndOfTurnEffect,
}
}
ScriptCategory::Battle => {
resolve_match!(name.hash(), crate::util_scripts::ForceEffectTriggerScript,)
resolve_match! {name.hash(), crate::util_scripts::ForceEffectTriggerScript,}
}
ScriptCategory::Side => {}
ScriptCategory::ItemBattleTrigger => {}

View File

@ -1,6 +1,4 @@
use core::any::Any;
use pkmn_lib_interface::app_interface::{ExecutingMove, Pokemon};
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
use crate::common_usings::*;
pub struct ForceEffectTriggerScript {}

View File

@ -7,12 +7,12 @@ macro_rules! script{
$id: literal
$(
,
$field_name:ident : $field_type:ty
$field_vis:vis $field_name:ident : $field_type:ty
)*
) => {
pub struct $name {
$(
$field_name: $field_type,
$field_vis $field_name: $field_type,
)*
}

View File

@ -1,6 +1,5 @@
use crate::script;
use core::any::Any;
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
use crate::common_usings::*;
script!(Hail, "hail");
impl Script for Hail {

View File

@ -14,6 +14,7 @@ pub use capabilities::*;
#[cfg(not(feature = "mock_data"))]
pub(crate) use cacheable::Cacheable;
pub use script::Script;
pub use script::ScriptOwner;
#[repr(u8)]
pub enum ScriptCategory {

View File

@ -410,6 +410,7 @@ impl ScriptOwner {
Some(ScriptOwner::Battle(Rc::new(r.unwrap())))
}
}
3 => None,
_ => panic!("Unknown script owner kind: {}", kind),
}
}