use std::sync::Arc; use crate::dynamic_data::models::pokemon::Pokemon; use crate::dynamic_data::models::pokemon_party::PokemonParty; /// A battle party is a wrapper around a party, with the indices for which the party is responsible /// on the field attached. #[derive(Debug)] pub struct BattleParty<'own, 'library> { /// The party the BattleParty is holding. party: Arc>, /// The indices for which the party is responsible, in the format (side, index) responsible_indices: Vec<(u8, u8)>, } impl<'own, 'library> BattleParty<'own, 'library> { /// Initializes a battle party with the underlying party, and the indices the party is responsible /// for. pub fn new(party: Arc>, responsible_indices: Vec<(u8, u8)>) -> Self { Self { party, responsible_indices, } } /// Checks whether the party is responsible for the given index. pub fn is_responsible_for_index(&self, side: u8, index: u8) -> bool { for responsible_index in &self.responsible_indices { if responsible_index.0 == side && responsible_index.1 == index { return true; } } false } /// Whether or not the party has non fainted Pokemon that could be thrown out into the field. pub fn has_pokemon_not_in_field(&self) -> bool { for pokemon in self.party.pokemon().iter().flatten() { if pokemon.is_usable() && !pokemon.is_on_battlefield() { return true; } } false } /// Gets a Pokemon at an index. pub fn get_pokemon(&self, index: usize) -> &Option>> { self.party.at(index) } }