PkmnLib_rs/src/dynamic_data/models/battle_party.rs

57 lines
1.8 KiB
Rust
Executable File

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)]
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
pub struct BattleParty {
/// The party the BattleParty is holding.
party: Arc<PokemonParty>,
/// The indices for which the party is responsible, in the format (side, index)
responsible_indices: Vec<(u8, u8)>,
}
impl BattleParty {
/// Initializes a battle party with the underlying party, and the indices the party is responsible
/// for.
pub fn new(party: Arc<PokemonParty>, 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<Arc<Pokemon>> {
self.party.at(index)
}
/// Gets the underlying Pokemon Party
pub fn party(&self) -> &Arc<PokemonParty> {
&self.party
}
}