Removes derive-getters, as it was incredibly annoying in IDEs, and couldn't figure out borrow lifetimes.
This commit is contained in:
@@ -43,9 +43,9 @@ impl BattleStatCalculator {
|
||||
|
||||
fn calculate_health_stat(&self, pokemon: &Pokemon) -> u32 {
|
||||
let base = pokemon.form().get_base_stat(Statistic::HP) as u32;
|
||||
let iv = *pokemon.individual_values().hp() as u32;
|
||||
let ev = *pokemon.effort_values().hp() as u32;
|
||||
let level = *pokemon.level() as u32;
|
||||
let iv = pokemon.individual_values().hp() as u32;
|
||||
let ev = pokemon.effort_values().hp() as u32;
|
||||
let level = pokemon.level() as u32;
|
||||
(((2 * base + iv + (ev / 4)) * level) / 100) + level + 10
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ impl BattleStatCalculator {
|
||||
let base = pokemon.form().get_base_stat(stat) as u32;
|
||||
let iv = pokemon.individual_values().get_stat(stat) as u32;
|
||||
let ev = pokemon.effort_values().get_stat(stat) as u32;
|
||||
let level = *pokemon.level() as u32;
|
||||
let level = pokemon.level() as u32;
|
||||
let unmodified = (((2 * base + iv + (ev / 4)) * level) / 100) + 5;
|
||||
return (unmodified as f32 * pokemon.nature().get_stat_modifier(stat)) as u32;
|
||||
}
|
||||
|
||||
@@ -6,20 +6,20 @@ use crate::dynamic_data::models::battle_party::BattleParty;
|
||||
use crate::dynamic_data::models::battle_random::BattleRandom;
|
||||
use crate::dynamic_data::models::battle_result::BattleResult;
|
||||
use crate::dynamic_data::models::battle_side::BattleSide;
|
||||
use crate::dynamic_data::script_handling::script::Script;
|
||||
use crate::dynamic_data::script_handling::script_set::ScriptSet;
|
||||
use derive_getters::Getters;
|
||||
use crate::dynamic_data::script_handling::volatile_scripts::VolatileScripts;
|
||||
use crate::{PkmnResult, ScriptCategory};
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
#[derive(Getters, Debug)]
|
||||
#[derive(Debug)]
|
||||
pub struct Battle<'a> {
|
||||
#[getter(skip)]
|
||||
library: &'a DynamicLibrary<'a>,
|
||||
parties: Vec<BattleParty<'a>>,
|
||||
can_flee: bool,
|
||||
number_of_sides: u8,
|
||||
pokemon_per_side: u8,
|
||||
sides: Vec<BattleSide<'a>>,
|
||||
#[getter(skip)]
|
||||
random: BattleRandom,
|
||||
choice_queue: ChoiceQueue,
|
||||
has_ended: bool,
|
||||
@@ -27,7 +27,7 @@ pub struct Battle<'a> {
|
||||
event_hook: EventHook,
|
||||
history_holder: Box<HistoryHolder>,
|
||||
current_turn: u32,
|
||||
volatile: ScriptSet,
|
||||
volatile: Arc<RwLock<ScriptSet>>,
|
||||
last_turn_time: i64,
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ impl<'a> Battle<'a> {
|
||||
event_hook: Default::default(),
|
||||
history_holder: Box::new(HistoryHolder {}),
|
||||
current_turn: 0,
|
||||
volatile: ScriptSet::default(),
|
||||
volatile: Default::default(),
|
||||
last_turn_time: 0,
|
||||
}));
|
||||
|
||||
@@ -71,15 +71,60 @@ impl<'a> Battle<'a> {
|
||||
battle
|
||||
}
|
||||
|
||||
pub fn library(&self) -> &'a DynamicLibrary<'a> {
|
||||
self.library
|
||||
}
|
||||
pub fn parties(&self) -> &Vec<BattleParty<'a>> {
|
||||
&self.parties
|
||||
}
|
||||
pub fn can_flee(&self) -> bool {
|
||||
self.can_flee
|
||||
}
|
||||
pub fn number_of_sides(&self) -> u8 {
|
||||
self.number_of_sides
|
||||
}
|
||||
pub fn pokemon_per_side(&self) -> u8 {
|
||||
self.pokemon_per_side
|
||||
}
|
||||
pub fn sides(&self) -> &Vec<BattleSide<'a>> {
|
||||
&self.sides
|
||||
}
|
||||
pub fn random(&self) -> &BattleRandom {
|
||||
&self.random
|
||||
}
|
||||
pub fn has_ended(&self) -> bool {
|
||||
self.has_ended
|
||||
}
|
||||
pub fn result(&self) -> BattleResult {
|
||||
self.result
|
||||
}
|
||||
pub fn event_hook(&self) -> &EventHook {
|
||||
&self.event_hook
|
||||
}
|
||||
pub fn history_holder(&self) -> &Box<HistoryHolder> {
|
||||
&self.history_holder
|
||||
}
|
||||
pub fn current_turn(&self) -> u32 {
|
||||
self.current_turn
|
||||
}
|
||||
pub fn last_turn_time(&self) -> i64 {
|
||||
self.last_turn_time
|
||||
}
|
||||
pub fn choice_queue(&self) -> &ChoiceQueue {
|
||||
&self.choice_queue
|
||||
}
|
||||
|
||||
pub fn can_slot_be_filled(&self) -> bool {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn library(&self) -> &'a DynamicLibrary<'a> {
|
||||
self.library
|
||||
impl<'a> VolatileScripts<'a> for Battle<'a> {
|
||||
fn volatile_scripts(&self) -> &Arc<RwLock<ScriptSet>> {
|
||||
&self.volatile
|
||||
}
|
||||
|
||||
fn load_volatile_script(&self, key: &str) -> PkmnResult<Box<dyn Script>> {
|
||||
self.library.load_script(ScriptCategory::Battle, key)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum BattleResult {
|
||||
Inconclusive,
|
||||
Conclusive(u8),
|
||||
|
||||
@@ -8,10 +8,9 @@ use crate::dynamic_data::script_handling::script_set::ScriptSet;
|
||||
use crate::dynamic_data::script_handling::volatile_scripts::VolatileScripts;
|
||||
use crate::dynamic_data::script_handling::ScriptSource;
|
||||
use crate::{script_hook, PkmnResult};
|
||||
use derive_getters::Getters;
|
||||
use std::sync::{Arc, RwLock, Weak};
|
||||
|
||||
#[derive(Getters, Debug)]
|
||||
#[derive(Debug)]
|
||||
pub struct BattleSide<'a> {
|
||||
index: u8,
|
||||
pokemon_per_side: u8,
|
||||
@@ -48,6 +47,33 @@ impl<'a> BattleSide<'a> {
|
||||
volatile_scripts: Default::default(),
|
||||
}
|
||||
}
|
||||
pub fn index(&self) -> u8 {
|
||||
self.index
|
||||
}
|
||||
pub fn pokemon_per_side(&self) -> u8 {
|
||||
self.pokemon_per_side
|
||||
}
|
||||
pub fn pokemon(&self) -> &Vec<Option<Arc<RwLock<Pokemon<'a>>>>> {
|
||||
&self.pokemon
|
||||
}
|
||||
pub fn choices(&self) -> &Vec<Option<Arc<TurnChoice<'a>>>> {
|
||||
&self.choices
|
||||
}
|
||||
pub fn fillable_slots(&self) -> &Vec<bool> {
|
||||
&self.fillable_slots
|
||||
}
|
||||
pub fn choices_set(&self) -> u8 {
|
||||
self.choices_set
|
||||
}
|
||||
pub fn battle(&self) -> &Weak<RwLock<Battle<'a>>> {
|
||||
&self.battle
|
||||
}
|
||||
pub fn has_fled_battle(&self) -> bool {
|
||||
self.has_fled_battle
|
||||
}
|
||||
pub fn volatile_scripts(&self) -> &Arc<RwLock<ScriptSet>> {
|
||||
&self.volatile_scripts
|
||||
}
|
||||
|
||||
pub fn all_choices_set(&self) -> bool {
|
||||
self.choices_set == self.pokemon_per_side
|
||||
@@ -108,13 +134,13 @@ impl<'a> BattleSide<'a> {
|
||||
let battle = self.battle.upgrade().unwrap();
|
||||
let battle = battle.read().unwrap();
|
||||
for side in battle.sides() {
|
||||
if *side.index() == self.index {
|
||||
if side.index() == self.index {
|
||||
continue;
|
||||
}
|
||||
for opponent in side.pokemon().iter().flatten() {
|
||||
let mut opponent = opponent.write().unwrap();
|
||||
opponent.mark_opponent_as_seen(*pokemon.unique_identifier());
|
||||
pokemon.mark_opponent_as_seen(*opponent.unique_identifier());
|
||||
opponent.mark_opponent_as_seen(pokemon.unique_identifier());
|
||||
pokemon.mark_opponent_as_seen(opponent.unique_identifier());
|
||||
}
|
||||
}
|
||||
battle.event_hook().trigger(Event::Switch {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user