Move Form and Species to traits, implement a bunch of mocks
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-11-28 21:34:28 +01:00
parent c1e09c654b
commit bce636b97e
25 changed files with 447 additions and 155 deletions

View File

@@ -76,16 +76,16 @@ pub enum Event<'own> {
/// The pokemon that changed species.
pokemon: &'own Pokemon,
/// The new species of the Pokemon.
species: Arc<Species>,
species: Arc<dyn Species>,
/// The form of the species the Pokemon will have.
form: Arc<Form>,
form: Arc<dyn Form>,
},
/// This event happens when a Pokemon changes form during battle. This is rather common.
FormChange {
/// The pokemon that changed forms.
pokemon: &'own Pokemon,
/// The new form of the Pokemon.
form: &'own Form,
form: Arc<dyn Form>,
},
/// This event happens when a Pokemon takes damage.
Damage {

View File

@@ -100,7 +100,7 @@ impl ValueIdentifiable for LearnedMove {
#[cfg(test)]
mod tests {
use super::*;
use crate::static_data::MockMoveData;
use crate::static_data::tests::MockMoveData;
#[test]
fn create_learned_move_restore_uses() {

View File

@@ -32,16 +32,16 @@ pub struct Pokemon {
/// The library data of the Pokemon.
library: Arc<DynamicLibrary>,
/// The species of the Pokemon.
species: RwLock<Arc<Species>>,
species: RwLock<Arc<dyn Species>>,
/// The form of the Pokemon.
form: RwLock<Arc<Form>>,
form: RwLock<Arc<dyn Form>>,
/// An optional display species of the Pokemon. If this is set, the client should display this
/// species. An example of usage for this is the Illusion ability.
display_species: Option<Arc<Species>>,
display_species: Option<Arc<dyn Species>>,
/// An optional display form of the Pokemon. If this is set, the client should display this
// species. An example of usage for this is the Illusion ability.
display_form: Option<Arc<Form>>,
display_form: Option<Arc<dyn Form>>,
/// The current level of the Pokemon.
level: Atomic<LevelInt>,
@@ -121,8 +121,8 @@ impl Pokemon {
/// Instantiates a new Pokemon.
pub fn new(
library: Arc<DynamicLibrary>,
species: Arc<Species>,
form: &Arc<Form>,
species: Arc<dyn Species>,
form: &Arc<dyn Form>,
ability: AbilityIndex,
level: LevelInt,
unique_identifier: u32,
@@ -192,15 +192,15 @@ impl Pokemon {
&self.library
}
/// The species of the Pokemon.
pub fn species(&self) -> Arc<Species> {
pub fn species(&self) -> Arc<dyn Species> {
self.species.read().clone()
}
/// The form of the Pokemon.
pub fn form(&self) -> Arc<Form> {
pub fn form(&self) -> Arc<dyn Form> {
self.form.read().clone()
}
/// The species that should be displayed to the user. This handles stuff like the Illusion ability.
pub fn display_species(&self) -> Arc<Species> {
pub fn display_species(&self) -> Arc<dyn Species> {
if let Some(v) = &self.display_species {
v.clone()
} else {
@@ -208,7 +208,7 @@ impl Pokemon {
}
}
/// The form that should be displayed to the user. This handles stuff like the Illusion ability.
pub fn display_form(&self) -> Arc<Form> {
pub fn display_form(&self) -> Arc<dyn Form> {
if let Some(v) = &self.display_form {
v.clone()
} else {
@@ -465,7 +465,7 @@ impl Pokemon {
}
/// Change the species of the Pokemon.
pub fn change_species(&self, species: Arc<Species>, form: Arc<Form>) {
pub fn change_species(&self, species: Arc<dyn Species>, form: Arc<dyn Form>) {
*self.species.write() = species.clone();
*self.form.write() = form.clone();
@@ -498,7 +498,7 @@ impl Pokemon {
}
/// Change the form of the Pokemon.
pub fn change_form(&self, form: &Arc<Form>) {
pub fn change_form(&self, form: &Arc<dyn Form>) {
if self.form().value_identifier() == form.value_identifier() {
return;
}
@@ -542,7 +542,10 @@ impl Pokemon {
let r = self.battle_data.read();
if let Some(battle_data) = r.deref() {
if let Some(battle) = battle_data.battle() {
battle.event_hook().trigger(Event::FormChange { pokemon: self, form })
battle.event_hook().trigger(Event::FormChange {
pokemon: self,
form: form.clone(),
})
}
}
}