Gen7ScriptsRs/gen_7_scripts/src/test_script.rs

103 lines
2.9 KiB
Rust

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())),
);
}
}