Implements first few actual move effects.
This commit is contained in:
@@ -12,7 +12,8 @@ use pkmn_lib_interface::set_load_script_fn;
|
||||
#[macro_use]
|
||||
|
||||
pub mod registered_scripts;
|
||||
pub mod test_script;
|
||||
pub mod moves;
|
||||
pub mod util_scripts;
|
||||
|
||||
#[no_mangle]
|
||||
#[cfg(not(test))]
|
||||
|
||||
40
gen_7_scripts/src/moves/acrobatics.rs
Normal file
40
gen_7_scripts/src/moves/acrobatics.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
use pkmn_lib_interface::app_interface::{ExecutingMove, Pokemon};
|
||||
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
|
||||
|
||||
pub struct Acrobatics {}
|
||||
|
||||
impl Acrobatics {
|
||||
pub const fn get_const_name() -> &'static str {
|
||||
"acrobatics"
|
||||
}
|
||||
}
|
||||
|
||||
impl Script for Acrobatics {
|
||||
fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
fn get_name() -> &'static str {
|
||||
Self::get_const_name()
|
||||
}
|
||||
|
||||
fn get_capabilities(&self) -> &[ScriptCapabilities] {
|
||||
&[ScriptCapabilities::ChangeBasePower]
|
||||
}
|
||||
|
||||
fn change_base_power(
|
||||
&self,
|
||||
mv: ExecutingMove,
|
||||
_target: Pokemon,
|
||||
_hit: u8,
|
||||
base_power: &mut u8,
|
||||
) {
|
||||
if mv.user().held_item().is_none() {
|
||||
if *base_power >= 128_u8 {
|
||||
*base_power = 255
|
||||
} else {
|
||||
*base_power *= 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
35
gen_7_scripts/src/moves/acupressure.rs
Normal file
35
gen_7_scripts/src/moves/acupressure.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use core::mem::transmute;
|
||||
use pkmn_lib_interface::app_interface::{ExecutingMove, Pokemon, Statistic};
|
||||
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
|
||||
|
||||
pub struct Acupressure {}
|
||||
|
||||
impl Acupressure {
|
||||
pub const fn get_const_name() -> &'static str {
|
||||
"acupressure"
|
||||
}
|
||||
}
|
||||
|
||||
impl Script for Acupressure {
|
||||
fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
fn get_name() -> &'static str {
|
||||
Self::get_const_name()
|
||||
}
|
||||
|
||||
fn get_capabilities(&self) -> &[ScriptCapabilities] {
|
||||
&[ScriptCapabilities::OnSecondaryEffect]
|
||||
}
|
||||
|
||||
fn on_secondary_effect(&self, mv: ExecutingMove, target: Pokemon, hit: u8) {
|
||||
if target == mv.user() {
|
||||
mv.get_hit_data(&target, hit).fail();
|
||||
return;
|
||||
}
|
||||
let rand_stat: Statistic =
|
||||
unsafe { transmute(target.battle().unwrap().random().get_between(1, 6) as u8) };
|
||||
target.change_stat_boost(rand_stat, 2, false);
|
||||
}
|
||||
}
|
||||
35
gen_7_scripts/src/moves/after_you.rs
Normal file
35
gen_7_scripts/src/moves/after_you.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use pkmn_lib_interface::app_interface::{ExecutingMove, Pokemon};
|
||||
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
|
||||
|
||||
pub struct AfterYou {}
|
||||
|
||||
impl AfterYou {
|
||||
pub const fn get_const_name() -> &'static str {
|
||||
"after_you"
|
||||
}
|
||||
}
|
||||
|
||||
impl Script for AfterYou {
|
||||
fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
fn get_name() -> &'static str {
|
||||
Self::get_const_name()
|
||||
}
|
||||
|
||||
fn get_capabilities(&self) -> &[ScriptCapabilities] {
|
||||
&[ScriptCapabilities::OnSecondaryEffect]
|
||||
}
|
||||
|
||||
fn on_secondary_effect(&self, mv: ExecutingMove, target: Pokemon, hit: u8) {
|
||||
if !target
|
||||
.battle()
|
||||
.unwrap()
|
||||
.choice_queue()
|
||||
.move_pokemon_choice_next(&target)
|
||||
{
|
||||
mv.get_hit_data(&target, hit).fail()
|
||||
}
|
||||
}
|
||||
}
|
||||
4
gen_7_scripts/src/moves/mod.rs
Normal file
4
gen_7_scripts/src/moves/mod.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
pub mod acrobatics;
|
||||
pub mod acupressure;
|
||||
pub mod after_you;
|
||||
pub mod multi_hit_move;
|
||||
37
gen_7_scripts/src/moves/multi_hit_move.rs
Normal file
37
gen_7_scripts/src/moves/multi_hit_move.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
use pkmn_lib_interface::app_interface::TurnChoice;
|
||||
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
|
||||
|
||||
pub struct MultiHitMove {}
|
||||
|
||||
impl MultiHitMove {
|
||||
pub const fn get_const_name() -> &'static str {
|
||||
"2_5_hit_move"
|
||||
}
|
||||
}
|
||||
|
||||
impl Script for MultiHitMove {
|
||||
fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
fn get_name() -> &'static str {
|
||||
Self::get_const_name()
|
||||
}
|
||||
|
||||
fn get_capabilities(&self) -> &[ScriptCapabilities] {
|
||||
&[ScriptCapabilities::ChangeNumberOfHits]
|
||||
}
|
||||
|
||||
fn change_number_of_hits(&self, choice: TurnChoice, number_of_hits: &mut u8) {
|
||||
// 35% chance that it will hit 2 times, a 35% chance it will hit 3 times, a 15% chance it
|
||||
// will hit 4 times, and a 15% chance it will hit 5 times.
|
||||
let rand_value = choice.user().battle().unwrap().random().get_between(0, 100);
|
||||
*number_of_hits = match rand_value {
|
||||
0..=34 => 2,
|
||||
35..=69 => 3,
|
||||
70..=84 => 4,
|
||||
85..=100 => 5,
|
||||
_ => *number_of_hits,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,19 @@
|
||||
use crate::test_script::TestScript;
|
||||
use crate::moves::*;
|
||||
use alloc::boxed::Box;
|
||||
use pkmn_lib_interface::app_interface::{get_hash_const, StringKey};
|
||||
use pkmn_lib_interface::app_interface::{get_hash, StringKey};
|
||||
use pkmn_lib_interface::handling::{Script, ScriptCategory};
|
||||
|
||||
macro_rules! resolve_match {
|
||||
(
|
||||
$mid:expr,
|
||||
$(
|
||||
$key:expr => $script:ident,
|
||||
$script:ty,
|
||||
)*
|
||||
) => (
|
||||
match $mid {
|
||||
$(
|
||||
const { get_hash_const($key) } => {
|
||||
return Some(Box::new($script {}))
|
||||
const { get_hash(<$script>::get_const_name()) } => {
|
||||
return Some(Box::new(<$script>::new()))
|
||||
}
|
||||
)*
|
||||
_ => {}
|
||||
@@ -26,13 +26,18 @@ pub fn get_script(category: ScriptCategory, name: &StringKey) -> Option<Box<dyn
|
||||
ScriptCategory::Move => {
|
||||
resolve_match!(
|
||||
name.hash(),
|
||||
b"test" => TestScript,
|
||||
acrobatics::Acrobatics,
|
||||
acupressure::Acupressure,
|
||||
after_you::AfterYou,
|
||||
multi_hit_move::MultiHitMove,
|
||||
);
|
||||
}
|
||||
ScriptCategory::Ability => {}
|
||||
ScriptCategory::Status => {}
|
||||
ScriptCategory::Pokemon => {}
|
||||
ScriptCategory::Battle => {}
|
||||
ScriptCategory::Battle => {
|
||||
resolve_match!(name.hash(), crate::util_scripts::ForceEffectTriggerScript,)
|
||||
}
|
||||
ScriptCategory::Side => {}
|
||||
ScriptCategory::ItemBattleTrigger => {}
|
||||
}
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
use pkmn_lib_interface::app_interface::list::ImmutableList;
|
||||
use pkmn_lib_interface::app_interface::{
|
||||
get_hash_const, DamageSource, DataLibrary, DynamicLibrary, EffectParameter, TurnChoice,
|
||||
};
|
||||
use pkmn_lib_interface::dbg;
|
||||
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
|
||||
|
||||
pub struct TestScript {}
|
||||
|
||||
impl Script for TestScript {
|
||||
fn new() -> Self {
|
||||
TestScript {}
|
||||
}
|
||||
fn destroy(&self) {}
|
||||
|
||||
fn get_name(&self) -> &str {
|
||||
"TestScript"
|
||||
}
|
||||
|
||||
fn get_capabilities(&self) -> &[ScriptCapabilities] {
|
||||
&[
|
||||
ScriptCapabilities::Initialize,
|
||||
ScriptCapabilities::OnBeforeTurn,
|
||||
]
|
||||
}
|
||||
|
||||
fn on_initialize(
|
||||
&self,
|
||||
library: &DynamicLibrary,
|
||||
parameters: Option<ImmutableList<EffectParameter>>,
|
||||
) {
|
||||
let l = library.data_library();
|
||||
let ml = l.move_library();
|
||||
let m = ml.get_by_hash(const { get_hash_const(b"tackle") }).unwrap();
|
||||
dbg!("found move!");
|
||||
dbg!("{:?} has {} base power", m.name().str(), m.base_power());
|
||||
dbg!(
|
||||
"Found a parameter with value: {}",
|
||||
parameters.unwrap().get(0).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
fn on_before_turn(&self, choice: TurnChoice) {
|
||||
dbg!(
|
||||
"On before turn for user: {}",
|
||||
choice.user().species().name()
|
||||
);
|
||||
// choice.user().damage(50, DamageSource::Misc);
|
||||
if let TurnChoice::Move(d) = choice {
|
||||
dbg!(
|
||||
"On before turn for move choice: {}",
|
||||
d.used_move().move_data().name()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use pkmn_lib_interface::app_interface::move_library::MoveLibrary;
|
||||
use pkmn_lib_interface::app_interface::species_library::SpeciesLibrary;
|
||||
use pkmn_lib_interface::app_interface::type_library::TypeLibrary;
|
||||
use pkmn_lib_interface::app_interface::{
|
||||
Item, ItemLibrary, LibrarySettings, MoveCategory, MoveData, MoveTarget, StaticData,
|
||||
};
|
||||
use pkmn_lib_interface::handling::Script;
|
||||
|
||||
#[test]
|
||||
fn test_foo() {
|
||||
let item = Item::mock();
|
||||
assert_eq!(item.name().str().to_str().unwrap(), "test");
|
||||
|
||||
let script = TestScript::new();
|
||||
assert_eq!(script.get_name(), "TestScript");
|
||||
|
||||
let lib = DynamicLibrary::new(StaticData::mock(
|
||||
MoveLibrary::mock(),
|
||||
ItemLibrary::mock(),
|
||||
SpeciesLibrary::mock(),
|
||||
TypeLibrary::mock(),
|
||||
LibrarySettings::mock(100),
|
||||
));
|
||||
lib.data_library().move_library().insert(
|
||||
const { get_hash_const(b"tackle") },
|
||||
MoveData::mock(
|
||||
"tackle",
|
||||
0,
|
||||
MoveCategory::Physical,
|
||||
60,
|
||||
100,
|
||||
10,
|
||||
MoveTarget::Adjacent,
|
||||
0,
|
||||
),
|
||||
);
|
||||
script.on_initialize(
|
||||
&lib,
|
||||
Some(ImmutableList::mock((&[EffectParameter::Int(100)]).to_vec())),
|
||||
);
|
||||
}
|
||||
}
|
||||
35
gen_7_scripts/src/util_scripts/force_effect_trigger.rs
Normal file
35
gen_7_scripts/src/util_scripts/force_effect_trigger.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use pkmn_lib_interface::app_interface::{ExecutingMove, Pokemon};
|
||||
use pkmn_lib_interface::handling::{Script, ScriptCapabilities};
|
||||
|
||||
pub struct ForceEffectTriggerScript {}
|
||||
|
||||
impl ForceEffectTriggerScript {
|
||||
pub const fn get_const_name() -> &'static str {
|
||||
"force_effect_trigger"
|
||||
}
|
||||
}
|
||||
|
||||
impl Script for ForceEffectTriggerScript {
|
||||
fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
fn get_name() -> &'static str {
|
||||
Self::get_const_name()
|
||||
}
|
||||
|
||||
fn get_capabilities(&self) -> &[ScriptCapabilities] {
|
||||
&[ScriptCapabilities::ChangeEffectChance]
|
||||
}
|
||||
|
||||
fn change_effect_chance(
|
||||
&self,
|
||||
_mv: ExecutingMove,
|
||||
_target: Pokemon,
|
||||
_hit: u8,
|
||||
chance: &mut f32,
|
||||
) {
|
||||
// Set to 50_000% chance.
|
||||
*chance = 50_000.0;
|
||||
}
|
||||
}
|
||||
3
gen_7_scripts/src/util_scripts/mod.rs
Normal file
3
gen_7_scripts/src/util_scripts/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
mod force_effect_trigger;
|
||||
|
||||
pub use force_effect_trigger::*;
|
||||
Reference in New Issue
Block a user