A bunch of work on unit testing
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -45,7 +45,7 @@ pub struct Pokemon {
|
||||
display_form: Option<Arc<Form>>,
|
||||
|
||||
/// The current level of the Pokemon.
|
||||
level: LevelInt,
|
||||
level: Atomic<LevelInt>,
|
||||
/// The amount of experience of the Pokemon.
|
||||
experience: AtomicU32,
|
||||
/// A unique random number for this Pokemon.
|
||||
@@ -151,7 +151,7 @@ impl Pokemon {
|
||||
form: RwLock::new(form.clone()),
|
||||
display_species: None,
|
||||
display_form: None,
|
||||
level,
|
||||
level: Atomic::new(level),
|
||||
experience: AtomicU32::new(experience),
|
||||
unique_identifier,
|
||||
gender: RwLock::new(gender),
|
||||
@@ -218,7 +218,7 @@ impl Pokemon {
|
||||
}
|
||||
/// The current level of the Pokemon.
|
||||
pub fn level(&self) -> LevelInt {
|
||||
self.level
|
||||
self.level.load(Ordering::Relaxed)
|
||||
}
|
||||
/// The amount of experience of the Pokemon.
|
||||
pub fn experience(&self) -> u32 {
|
||||
@@ -705,6 +705,21 @@ impl Pokemon {
|
||||
pub fn clear_status(&self) {
|
||||
self.status_script.clear()
|
||||
}
|
||||
|
||||
/// Increases the level by a certain amount
|
||||
pub fn change_level_by(&self, amount: LevelInt) {
|
||||
self.level
|
||||
.fetch_update(Ordering::SeqCst, Ordering::Relaxed, |x| {
|
||||
let max_level = self.library().static_data().settings().maximum_level();
|
||||
if x + amount > max_level {
|
||||
Some(max_level)
|
||||
} else {
|
||||
Some(x + amount)
|
||||
}
|
||||
})
|
||||
.expect("Failed to change level.");
|
||||
self.recalculate_flat_stats();
|
||||
}
|
||||
}
|
||||
|
||||
/// The data of the Pokemon related to being in a battle.
|
||||
|
||||
Reference in New Issue
Block a user