use crate::script; 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"); impl Assist { fn get_party_moves(party: &Party, user: &Pokemon) -> Vec { let mut possible_moves = Vec::new(); // Iterate over every mon in the party for mon_index in 0..party.length() { let mon = party.get_pokemon(mon_index); if let Some(mon) = mon { // Ignore moves from the user if mon == *user { continue; } // Iterate over all moves. We make the assumption of 4 moves. for move_index in 0..4 { let mv = mon.get_learned_move(move_index); if let Some(mv) = mv { // Make sure we can copy the move, otherwise add it as possible move. if crate::utils::copyable_moves::can_copy_move(&mv.move_data()) { possible_moves.push(mv.move_data()) } } } } } possible_moves } } impl Script for Assist { fn new() -> Self { Self {} } fn get_name(&self) -> &'static str { Self::get_const_name() } fn get_capabilities(&self) -> &[ScriptCapabilities] { &[ScriptCapabilities::ChangeMove] } fn change_move(&self, choice: TurnChoice, move_name: &mut StringKey) { let user = choice.user(); let battle = user.battle().unwrap(); let party = battle.find_party_for_pokemon(&user).unwrap().party(); let possible_moves = Self::get_party_moves(&party, &user); if possible_moves.len() == 0 { choice.fail(); return; } let random = battle.random().get_max(possible_moves.len() as i32); *move_name = possible_moves[random as usize].name(); } fn as_any(&self) -> &dyn Any { self } }