Gen7ScriptsRs/gen_7_scripts/src/moves/after_you.rs

74 lines
1.8 KiB
Rust
Executable File

use core::any::Any;
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(&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) {
if !target
.battle()
.unwrap()
.choice_queue()
.move_pokemon_choice_next(&target)
{
mv.get_hit_data(&target, hit).fail()
}
}
fn as_any(&self) -> &dyn Any {
self
}
}
#[cfg(test)]
mod tests {
use super::*;
use alloc::rc::Rc;
use pkmn_lib_interface::app_interface::{
MockBattle, MockChoiceQueue, MockExecutingMove, MockPokemon,
};
#[test]
fn move_pokemon_choice_next_gets_called_once() {
let mut battle = MockBattle::new();
battle.expect_choice_queue().once().return_once_st(move || {
let mut choice_queue = MockChoiceQueue::new();
choice_queue
.expect_move_pokemon_choice_next()
.once()
.return_const(true);
Rc::new(choice_queue)
});
let battle = Rc::new(battle);
let mut target = MockPokemon::new();
target
.expect_battle()
.once()
.return_once_st(move || Some(battle));
let target = Rc::new(target);
let script = AfterYou::new();
script.on_secondary_effect(Rc::new(MockExecutingMove::new()), target, 0);
}
}