Rename unique_identifier --> personality_value, minor fixes
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-07-09 11:17:43 +02:00
parent bc9b3ed964
commit f6df95a824
8 changed files with 70 additions and 46 deletions

View File

@@ -50,8 +50,8 @@ struct PokemonData {
level: Atomic<LevelInt>,
/// The amount of experience of the Pokemon.
experience: AtomicU32,
/// A unique random number for this Pokemon.
unique_identifier: u32,
/// The personality value of the Pokemon.
personality_value: u32,
/// The gender of the Pokemon.
gender: RwLock<Gender>,
@@ -171,7 +171,7 @@ impl Pokemon {
display_form: None,
level: Atomic::new(level),
experience: AtomicU32::new(experience),
unique_identifier,
personality_value: unique_identifier,
gender: RwLock::new(gender),
coloring,
held_item: RwLock::new(None),
@@ -239,16 +239,19 @@ impl Pokemon {
}
}
/// The current level of the Pokemon.
/// [See also](https://bulbapedia.bulbagarden.net/wiki/Level)
pub fn level(&self) -> LevelInt {
self.data.level.load(Ordering::Relaxed)
}
/// The amount of experience of the Pokemon.
/// [See also](https://bulbapedia.bulbagarden.net/wiki/Experience)
pub fn experience(&self) -> u32 {
self.data.experience.load(Ordering::Relaxed)
}
/// A unique random number for this Pokemon.
pub fn unique_identifier(&self) -> u32 {
self.data.unique_identifier
/// The personality value of the Pokemon.
/// [See also](https://bulbapedia.bulbagarden.net/wiki/Personality_value)
pub fn personality_value(&self) -> u32 {
self.data.personality_value
}
/// The gender of the Pokemon.
pub fn gender(&self) -> Gender {

View File

@@ -3,7 +3,7 @@ use parking_lot::lock_api::RwLockReadGuard;
use parking_lot::{RawRwLock, RwLock};
use crate::dynamic_data::models::pokemon::Pokemon;
use crate::VecExt;
use crate::{PkmnError, VecExt};
/// A list of Pokemon belonging to a trainer.
#[derive(Debug)]
@@ -43,8 +43,18 @@ impl PokemonParty {
}
/// Swaps two Pokemon in the party around.
pub fn switch(&self, a: usize, b: usize) {
pub fn switch(&self, a: usize, b: usize) -> Result<()> {
let write_lock = self.pokemon.write();
if a >= write_lock.len() || b >= write_lock.len() {
return Err(PkmnError::IndexOutOfBounds {
index: if a >= write_lock.len() { a } else { b },
len: write_lock.len(),
}
.into());
}
self.pokemon.write().swap(a, b);
Ok(())
}
/// Sets the Pokemon at an index to a Pokemon, returning the old Pokemon.