Removes derive-getters, as it was incredibly annoying in IDEs, and couldn't figure out borrow lifetimes.

This commit is contained in:
2022-06-06 14:43:41 +02:00
parent ce33ec0649
commit c27ea0ae1e
16 changed files with 395 additions and 57 deletions

View File

@@ -16,7 +16,6 @@ use crate::static_data::statistic_set::{ClampedStatisticSet, StatisticSet};
use crate::static_data::statistics::Statistic;
use crate::utils::random::Random;
use crate::{PkmnResult, ScriptCategory};
use derive_getters::Getters;
use std::collections::HashSet;
use std::sync::{Arc, RwLock, Weak};
@@ -44,11 +43,10 @@ impl<'a> PokemonBattleData<'a> {
}
}
#[derive(Getters, Debug)]
#[derive(Debug)]
pub struct Pokemon<'a> {
library: &'a DynamicLibrary<'a>,
species: &'a Species<'a>,
#[getter(skip)]
form: &'a Form<'a>,
display_species: Option<&'a Species<'a>>,
@@ -70,14 +68,12 @@ pub struct Pokemon<'a> {
boosted_stats: StatisticSet<u32>,
individual_values: ClampedStatisticSet<u8, 0, 31>,
effort_values: ClampedStatisticSet<u8, 0, 252>,
#[getter(skip)]
nature: &'a Nature,
nickname: Option<String>,
ability_index: AbilityIndex,
is_ability_overridden: bool,
overridden_ability_name: String,
battle_data: Option<PokemonBattleData<'a>>,
@@ -109,8 +105,8 @@ impl<'a> Pokemon<'a> {
.growth_rates()
.calculate_experience(species.growth_rate(), level);
let health = form.get_base_stat(Statistic::HP) as u32;
let weight = *form.weight();
let height = *form.height();
let weight = form.weight();
let height = form.height();
let nature = library
.static_data()
.natures()
@@ -140,7 +136,6 @@ impl<'a> Pokemon<'a> {
nickname: None,
ability_index: ability,
is_ability_overridden: false,
overridden_ability_name: "".to_string(),
battle_data: None,
moves: [None, None, None, None],
allowed_experience: false,
@@ -154,9 +149,121 @@ impl<'a> Pokemon<'a> {
pokemon
}
pub fn library(&self) -> &'a DynamicLibrary<'a> {
self.library
}
pub fn species(&self) -> &'a Species<'a> {
self.species
}
pub fn form(&self) -> &'a Form<'a> {
self.form
}
pub fn display_species(&self) -> &'a Species<'a> {
if let Some(v) = self.display_species {
v
} else {
self.species
}
}
pub fn display_form(&self) -> &'a Form<'a> {
if let Some(v) = self.display_form {
v
} else {
self.form
}
}
pub fn level(&self) -> LevelInt {
self.level
}
pub fn experience(&self) -> u32 {
self.experience
}
pub fn unique_identifier(&self) -> u32 {
self.unique_identifier
}
pub fn gender(&self) -> Gender {
self.gender
}
pub fn coloring(&self) -> u8 {
self.coloring
}
pub fn held_item(&self) -> Option<&'a Item> {
self.held_item
}
pub fn current_health(&self) -> u32 {
self.current_health
}
pub fn max_health(&self) -> u32 {
self.boosted_stats.hp()
}
pub fn weight(&self) -> f32 {
self.weight
}
pub fn height(&self) -> f32 {
self.height
}
pub fn nickname(&self) -> &Option<String> {
&self.nickname
}
pub fn real_ability(&self) -> &AbilityIndex {
&self.ability_index
}
pub fn types(&self) -> &Vec<u8> {
&self.types
}
pub fn learned_moves(&self) -> &[Option<LearnedMove>; MAX_MOVES] {
&self.moves
}
pub fn status(&self) -> &Option<Box<dyn Script>> {
&self.status_script
}
pub fn flat_stats(&self) -> &StatisticSet<u32> {
&self.flat_stats
}
pub fn boosted_stats(&self) -> &StatisticSet<u32> {
&self.boosted_stats
}
pub fn stat_boost(&self) -> &ClampedStatisticSet<i8, -6, 6> {
&self.stat_boost
}
pub fn individual_values(&self) -> &ClampedStatisticSet<u8, 0, 31> {
&self.individual_values
}
pub fn effort_values(&self) -> &ClampedStatisticSet<u8, 0, 252> {
&self.effort_values
}
pub fn get_battle(&self) -> Option<&Weak<RwLock<Battle<'a>>>> {
if let Some(data) = &self.battle_data {
Some(&data.battle)
} else {
None
}
}
pub fn get_battle_side_index(&self) -> Option<u8> {
self.battle_data.as_ref().map(|data| data.battle_side_index)
}
pub fn get_battle_index(&self) -> Option<u8> {
self.battle_data.as_ref().map(|data| data.index)
}
pub fn is_ability_overriden(&self) -> bool {
self.is_ability_overridden
}
pub fn active_ability(&self) -> &Option<Box<dyn Script>> {
&self.ability_script
}
pub fn seen_opponents(&self) -> Option<&HashSet<u32>> {
if let Some(data) = &self.battle_data {
Some(&data.seen_opponents)
} else {
None
}
}
pub fn allowed_experience_gain(&self) -> bool {
self.allowed_experience
}
pub fn nature(&self) -> &'a Nature {
self.nature
}
@@ -174,7 +281,7 @@ impl<'a> Pokemon<'a> {
self.form = form;
// If the pokemon is genderless, but it's new species is not, we want to set its gender
if self.gender != Gender::Genderless && *species.gender_rate() < 0.0 {
if self.gender != Gender::Genderless && species.gender_rate() < 0.0 {
if self.battle_data.is_some() {
let battle_data = self.battle_data.as_mut().unwrap();
self.gender = species.get_random_gender(
@@ -194,7 +301,7 @@ impl<'a> Pokemon<'a> {
}
}
// Else if the new species is genderless, but the pokemon has a gender, make the creature genderless.
else if *species.gender_rate() < 0.0 && self.gender != Gender::Genderless {
else if species.gender_rate() < 0.0 && self.gender != Gender::Genderless {
self.gender = Gender::Genderless;
}
// TODO: Battle Event trigger
@@ -224,8 +331,8 @@ impl<'a> Pokemon<'a> {
data.on_battle_field = value;
if !value {
self.volatile.write().unwrap().clear();
self.weight = *self.form.weight();
self.height = *self.form.height();
self.weight = self.form.weight();
self.height = self.form.height();
}
}
}