Adds effects for changing target stats.
This commit is contained in:
parent
a710527975
commit
0f85f4f0a4
|
@ -9,6 +9,7 @@ crate-type = ["cdylib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
pkmn_lib_interface = { path = "../pkmn_lib_interface" }
|
pkmn_lib_interface = { path = "../pkmn_lib_interface" }
|
||||||
|
paste = { version = "1.0.7" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
pkmn_lib_interface = { path = "../pkmn_lib_interface", features = ["mock_data"] }
|
pkmn_lib_interface = { path = "../pkmn_lib_interface", features = ["mock_data"] }
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
use crate::script;
|
||||||
|
use core::any::Any;
|
||||||
|
use pkmn_lib_interface::app_interface::{ExecutingMove, Pokemon, Statistic};
|
||||||
|
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
|
||||||
|
|
||||||
|
script!(Automize, "automize");
|
||||||
|
|
||||||
|
impl Script for Automize {
|
||||||
|
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 = mv.user();
|
||||||
|
let stats = user.boosted_stats();
|
||||||
|
let original_speed = stats.speed();
|
||||||
|
let original_weight = user.weight();
|
||||||
|
user.change_stat_boost(Statistic::Speed, 2, true);
|
||||||
|
if user.boosted_stats().speed() != original_speed {
|
||||||
|
user.set_weight(original_weight - 100.0);
|
||||||
|
if user.weight() != original_weight {
|
||||||
|
// TODO: Became nimble dialog.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_any(&self) -> &dyn Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
use crate::script;
|
||||||
|
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};
|
||||||
|
|
||||||
|
script!(
|
||||||
|
ChangeAllTargetStats,
|
||||||
|
"change_all_target_stats",
|
||||||
|
amount: AtomicI8
|
||||||
|
);
|
||||||
|
|
||||||
|
impl Script for ChangeAllTargetStats {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
amount: 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<EffectParameter>>,
|
||||||
|
) {
|
||||||
|
self.amount.store(
|
||||||
|
parameters.unwrap().get(0).unwrap().as_int() as i8,
|
||||||
|
Ordering::SeqCst,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_secondary_effect(&self, mv: ExecutingMove, target: Pokemon, _hit: u8) {
|
||||||
|
let user = mv.user();
|
||||||
|
let amount = self.amount.load(Ordering::SeqCst);
|
||||||
|
target.change_stat_boost(Statistic::Attack, amount, user == target);
|
||||||
|
target.change_stat_boost(Statistic::Defense, amount, user == target);
|
||||||
|
target.change_stat_boost(Statistic::SpecialAttack, amount, user == target);
|
||||||
|
target.change_stat_boost(Statistic::SpecialDefense, amount, user == target);
|
||||||
|
target.change_stat_boost(Statistic::Speed, amount, user == target);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_any(&self) -> &dyn Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,74 @@
|
||||||
|
use crate::script;
|
||||||
|
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};
|
||||||
|
|
||||||
|
macro_rules! change_stat_effect {
|
||||||
|
(
|
||||||
|
$stat:ident
|
||||||
|
) => {
|
||||||
|
paste::paste! {
|
||||||
|
pub struct [<ChangeTarget $stat>] {
|
||||||
|
amount: AtomicI8,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl [<ChangeTarget $stat>] {
|
||||||
|
pub const fn get_const_name() -> &'static str {
|
||||||
|
stringify!([<"change_target_" $stat:snake>])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Script for [<ChangeTarget $stat>] {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
amount: 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<EffectParameter>>,
|
||||||
|
) {
|
||||||
|
self.amount.store(
|
||||||
|
parameters.unwrap().get(0).unwrap().as_int() as i8,
|
||||||
|
Ordering::SeqCst,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn on_secondary_effect(&self, mv: ExecutingMove, target: Pokemon, _hit: u8) {
|
||||||
|
target.change_stat_boost(
|
||||||
|
Statistic::$stat,
|
||||||
|
self.amount.load(Ordering::SeqCst),
|
||||||
|
mv.user() == target,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn as_any(&self) -> &dyn Any {
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
change_stat_effect!(Attack);
|
||||||
|
change_stat_effect!(Defense);
|
||||||
|
change_stat_effect!(SpecialAttack);
|
||||||
|
change_stat_effect!(SpecialDefense);
|
||||||
|
change_stat_effect!(Speed);
|
|
@ -5,6 +5,9 @@ pub mod assist;
|
||||||
pub mod assurance;
|
pub mod assurance;
|
||||||
pub mod attract;
|
pub mod attract;
|
||||||
pub mod aurora_veil;
|
pub mod aurora_veil;
|
||||||
|
pub mod automize;
|
||||||
|
pub mod change_all_target_stats;
|
||||||
|
pub mod change_target_stats;
|
||||||
pub mod light_screen;
|
pub mod light_screen;
|
||||||
pub mod multi_hit_move;
|
pub mod multi_hit_move;
|
||||||
pub mod reflect;
|
pub mod reflect;
|
||||||
|
|
|
@ -35,6 +35,13 @@ pub fn get_script(category: ScriptCategory, name: &StringKey) -> Option<Box<dyn
|
||||||
multi_hit_move::MultiHitMove,
|
multi_hit_move::MultiHitMove,
|
||||||
attract::Attract,
|
attract::Attract,
|
||||||
aurora_veil::AuroraVeil,
|
aurora_veil::AuroraVeil,
|
||||||
|
automize::Automize,
|
||||||
|
change_all_target_stats::ChangeAllTargetStats,
|
||||||
|
change_target_stats::ChangeTargetAttack,
|
||||||
|
change_target_stats::ChangeTargetDefense,
|
||||||
|
change_target_stats::ChangeTargetSpecialAttack,
|
||||||
|
change_target_stats::ChangeTargetSpecialDefense,
|
||||||
|
change_target_stats::ChangeTargetSpeed,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
ScriptCategory::Ability => {}
|
ScriptCategory::Ability => {}
|
||||||
|
|
|
@ -171,6 +171,13 @@ impl Pokemon {
|
||||||
unsafe { pokemon_heal(self.inner.reference, amount, allow_revive) }
|
unsafe { pokemon_heal(self.inner.reference, amount, allow_revive) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "mock_data"))]
|
||||||
|
pub fn set_weight(&self, weight: f32) {
|
||||||
|
unsafe {
|
||||||
|
pokemon_set_weight(self.reference(), weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
#[cfg(not(feature = "mock_data"))]
|
||||||
pub fn battle_side(&self) -> BattleSide {
|
pub fn battle_side(&self) -> BattleSide {
|
||||||
self.battle()
|
self.battle()
|
||||||
|
@ -319,6 +326,7 @@ extern "wasm" {
|
||||||
fn pokemon_change_form(r: ExternRef<Pokemon>, form: ExternRef<Form>);
|
fn pokemon_change_form(r: ExternRef<Pokemon>, form: ExternRef<Form>);
|
||||||
fn pokemon_damage(r: ExternRef<Pokemon>, damage: u32, source: DamageSource);
|
fn pokemon_damage(r: ExternRef<Pokemon>, damage: u32, source: DamageSource);
|
||||||
fn pokemon_heal(r: ExternRef<Pokemon>, amount: u32, allow_revive: bool) -> bool;
|
fn pokemon_heal(r: ExternRef<Pokemon>, amount: u32, allow_revive: bool) -> bool;
|
||||||
|
fn pokemon_set_weight(r: ExternRef<Pokemon>, weight: f32);
|
||||||
|
|
||||||
fn pokemon_add_volatile_by_name(r: ExternRef<Pokemon>, name: *const c_char) -> ScriptPtr;
|
fn pokemon_add_volatile_by_name(r: ExternRef<Pokemon>, name: *const c_char) -> ScriptPtr;
|
||||||
fn pokemon_add_volatile(r: ExternRef<Pokemon>, script: ScriptPtr) -> ScriptPtr;
|
fn pokemon_add_volatile(r: ExternRef<Pokemon>, script: ScriptPtr) -> ScriptPtr;
|
||||||
|
|
|
@ -35,6 +35,35 @@ impl EffectParameter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn as_bool(&self) -> bool {
|
||||||
|
if let EffectParameter::Bool(b) = self {
|
||||||
|
return *b;
|
||||||
|
}
|
||||||
|
panic!("Unexpected effect parameter type: {}", self);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn as_int(&self) -> i64 {
|
||||||
|
if let EffectParameter::Int(i) = self {
|
||||||
|
return *i;
|
||||||
|
}
|
||||||
|
panic!("Unexpected effect parameter type: {}", self);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn as_float(&self) -> f32 {
|
||||||
|
if let EffectParameter::Float(f) = self {
|
||||||
|
return *f;
|
||||||
|
}
|
||||||
|
panic!("Unexpected effect parameter type: {}", self);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn as_string(&self) -> StringKey {
|
||||||
|
if let EffectParameter::String(s) = self {
|
||||||
|
return s.clone();
|
||||||
|
}
|
||||||
|
panic!("Unexpected effect parameter type: {}", self);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "mock_data"))]
|
#[cfg(not(feature = "mock_data"))]
|
||||||
|
|
Loading…
Reference in New Issue