2022-06-30 15:34:57 +00:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2022-06-17 17:53:33 +00:00
|
|
|
use crate::dynamic_data::models::pokemon::Pokemon;
|
2022-06-06 11:54:59 +00:00
|
|
|
use crate::dynamic_data::models::pokemon_party::PokemonParty;
|
|
|
|
|
2022-06-30 15:34:57 +00:00
|
|
|
/// A battle party is a wrapper around a party, with the indices for which the party is responsible
|
|
|
|
/// on the field attached.
|
2022-06-03 14:35:18 +00:00
|
|
|
#[derive(Debug)]
|
2022-09-07 16:01:26 +00:00
|
|
|
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
|
2022-08-20 11:17:20 +00:00
|
|
|
pub struct BattleParty {
|
2022-06-30 15:34:57 +00:00
|
|
|
/// The party the BattleParty is holding.
|
2022-08-20 11:17:20 +00:00
|
|
|
party: Arc<PokemonParty>,
|
2022-06-30 15:34:57 +00:00
|
|
|
/// The indices for which the party is responsible, in the format (side, index)
|
2022-06-06 11:54:59 +00:00
|
|
|
responsible_indices: Vec<(u8, u8)>,
|
|
|
|
}
|
|
|
|
|
2022-08-20 11:17:20 +00:00
|
|
|
impl BattleParty {
|
2022-06-30 15:34:57 +00:00
|
|
|
/// Initializes a battle party with the underlying party, and the indices the party is responsible
|
|
|
|
/// for.
|
2022-08-20 11:17:20 +00:00
|
|
|
pub fn new(party: Arc<PokemonParty>, responsible_indices: Vec<(u8, u8)>) -> Self {
|
2022-06-17 17:53:33 +00:00
|
|
|
Self {
|
|
|
|
party,
|
|
|
|
responsible_indices,
|
|
|
|
}
|
|
|
|
}
|
2022-06-30 15:34:57 +00:00
|
|
|
|
|
|
|
/// Checks whether the party is responsible for the given index.
|
2022-06-06 11:54:59 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-06-30 15:34:57 +00:00
|
|
|
/// Whether or not the party has non fainted Pokemon that could be thrown out into the field.
|
2022-06-06 11:54:59 +00:00
|
|
|
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
|
|
|
|
}
|
2022-06-17 17:53:33 +00:00
|
|
|
|
2022-06-30 15:34:57 +00:00
|
|
|
/// Gets a Pokemon at an index.
|
2022-08-20 11:17:20 +00:00
|
|
|
pub fn get_pokemon(&self, index: usize) -> &Option<Arc<Pokemon>> {
|
2022-06-17 17:53:33 +00:00
|
|
|
self.party.at(index)
|
|
|
|
}
|
2022-09-07 16:01:26 +00:00
|
|
|
|
|
|
|
/// Gets the underlying Pokemon Party
|
|
|
|
pub fn party(&self) -> &Arc<PokemonParty> {
|
|
|
|
&self.party
|
|
|
|
}
|
2022-06-06 11:54:59 +00:00
|
|
|
}
|