First chunk of battling is now fully working, along with integration tests! 🎉
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2022-06-17 19:53:33 +02:00
parent 59cc150643
commit b6ddd1ee13
34 changed files with 1934 additions and 1293 deletions

View File

@@ -1,12 +1,21 @@
use crate::dynamic_data::models::pokemon::Pokemon;
use crate::dynamic_data::models::pokemon_party::PokemonParty;
use parking_lot::RwLock;
use std::sync::Arc;
#[derive(Debug)]
pub struct BattleParty<'own, 'library> {
party: &'own PokemonParty<'own, 'library>,
party: Arc<PokemonParty<'own, 'library>>,
responsible_indices: Vec<(u8, u8)>,
}
impl<'own, 'library> BattleParty<'own, 'library> {
pub fn new(party: Arc<PokemonParty<'own, 'library>>, responsible_indices: Vec<(u8, u8)>) -> Self {
Self {
party,
responsible_indices,
}
}
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 {
@@ -18,11 +27,15 @@ impl<'own, 'library> BattleParty<'own, 'library> {
pub fn has_pokemon_not_in_field(&self) -> bool {
for pokemon in self.party.pokemon().iter().flatten() {
let pokemon = pokemon.read().unwrap();
let pokemon = pokemon.read();
if pokemon.is_usable() && !pokemon.is_on_battlefield() {
return true;
}
}
false
}
pub fn get_pokemon(&self, index: usize) -> &Option<Arc<RwLock<Pokemon<'own, 'library>>>> {
self.party.at(index)
}
}