Fixes all clippy warnings
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
717fcdefda
commit
0d95dcf618
|
@ -5,6 +5,9 @@ pub use target_resolver::*;
|
|||
#[doc(inline)]
|
||||
pub use turn_runner::*;
|
||||
|
||||
/// Data for enqueueing and retrieving choices.
|
||||
mod choice_queue;
|
||||
/// Data for the resolving and validation of targets for moves.
|
||||
mod target_resolver;
|
||||
/// Logic required to run turns.
|
||||
mod turn_runner;
|
||||
|
|
|
@ -61,6 +61,7 @@ impl<'own, 'library> Battle<'own, 'library> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Executes a single choice.
|
||||
fn execute_choice(&self, choice: &TurnChoice<'own, 'library>) -> PkmnResult<()> {
|
||||
// A pass turn choice means the user does not intend to do anything. As such, return.
|
||||
if let TurnChoice::Pass(..) = choice {
|
||||
|
@ -89,6 +90,7 @@ impl<'own, 'library> Battle<'own, 'library> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Executes a move choice.
|
||||
fn execute_move_choice<'func>(&'func self, choice: &'func TurnChoice<'own, 'library>) -> PkmnResult<()> {
|
||||
let choice = choice.get_move_turn_data();
|
||||
let used_move = choice.used_move();
|
||||
|
@ -145,6 +147,7 @@ impl<'own, 'library> Battle<'own, 'library> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Executes a move turn choice on a single target.
|
||||
fn handle_move_for_target(
|
||||
&self,
|
||||
executing_move: &mut ExecutingMove<'_, 'own, 'library>,
|
||||
|
|
|
@ -9,8 +9,13 @@ pub use misc_library::*;
|
|||
#[doc(inline)]
|
||||
pub use script_resolver::*;
|
||||
|
||||
/// Data regarding the calculation of battle stats.
|
||||
mod battle_stat_calculator;
|
||||
/// Data regarding the calculation of damage.
|
||||
mod damage_library;
|
||||
/// Collection of all libraries.
|
||||
pub(crate) mod dynamic_library;
|
||||
/// Misc data required for battles.
|
||||
mod misc_library;
|
||||
/// Data for dynamically resolving scripts during battles.
|
||||
mod script_resolver;
|
||||
|
|
|
@ -11,9 +11,15 @@ pub use models::*;
|
|||
#[doc(inline)]
|
||||
pub use script_handling::*;
|
||||
|
||||
/// Holds different choices Pokemon can use during battle.
|
||||
mod choices;
|
||||
/// Holds data to callback events from the battle to clients.
|
||||
mod event_hooks;
|
||||
/// Holds logic on how the battle is executed.
|
||||
mod flow;
|
||||
/// Holds information regarding data that is required for battle execution.
|
||||
pub(crate) mod libraries;
|
||||
/// Holds different struct types that are required for functioning.
|
||||
mod models;
|
||||
/// Holds information for dynamic runtime behaviour during battles.
|
||||
mod script_handling;
|
||||
|
|
|
@ -9,7 +9,6 @@ use crate::dynamic_data::choices::TurnChoice;
|
|||
use crate::dynamic_data::event_hooks::{Event, EventHook};
|
||||
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::models::pokemon::Pokemon;
|
||||
use crate::dynamic_data::ChoiceQueue;
|
||||
|
@ -350,3 +349,13 @@ impl<'own, 'library> ScriptSource<'own> for Battle<'own, 'library> {
|
|||
self.get_own_scripts(scripts);
|
||||
}
|
||||
}
|
||||
|
||||
/// The result of a battle.
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum BattleResult {
|
||||
/// The battle has no winner. Either the battle has not ended, or everyone is dead, or one of
|
||||
/// the parties has ran away.
|
||||
Inconclusive,
|
||||
/// The battle has a winner, with the inner value being the index of the side that has won.
|
||||
Conclusive(u8),
|
||||
}
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
/// The result of a battle.
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum BattleResult {
|
||||
/// The battle has no winner. Either the battle has not ended, or everyone is dead, or one of
|
||||
/// the parties has ran away.
|
||||
Inconclusive,
|
||||
/// The battle has a winner, with the inner value being the index of the side that has won.
|
||||
Conclusive(u8),
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
/// A source of damage. This should be as unique as possible.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum DamageSource {
|
||||
/// The damage is done by a move.
|
||||
MoveDamage = 0,
|
||||
/// The damage is done by something else.
|
||||
Misc = 1,
|
||||
}
|
|
@ -5,12 +5,8 @@ pub use battle_party::*;
|
|||
#[doc(inline)]
|
||||
pub use battle_random::*;
|
||||
#[doc(inline)]
|
||||
pub use battle_result::*;
|
||||
#[doc(inline)]
|
||||
pub use battle_side::*;
|
||||
#[doc(inline)]
|
||||
pub use damage_source::*;
|
||||
#[doc(inline)]
|
||||
pub use executing_move::*;
|
||||
#[doc(inline)]
|
||||
pub use learned_move::*;
|
||||
|
@ -21,14 +17,21 @@ pub use pokemon_builder::*;
|
|||
#[doc(inline)]
|
||||
pub use pokemon_party::*;
|
||||
|
||||
/// Data regarding the battle itself.
|
||||
mod battle;
|
||||
/// Data regarding parties that are part of a battle.
|
||||
mod battle_party;
|
||||
/// Data regarding the RNG for battles.
|
||||
mod battle_random;
|
||||
mod battle_result;
|
||||
/// Data regarding a single side on the battle.
|
||||
mod battle_side;
|
||||
mod damage_source;
|
||||
/// Data regarding a move that is being executed.
|
||||
mod executing_move;
|
||||
/// Data regarding a move that is learned by a Pokemon.
|
||||
mod learned_move;
|
||||
/// Data for an individual Pokemon.
|
||||
mod pokemon;
|
||||
/// A constructor for Pokemon.
|
||||
mod pokemon_builder;
|
||||
/// Data for a group of Pokemon belonging to a trainer.
|
||||
mod pokemon_party;
|
||||
|
|
|
@ -8,18 +8,17 @@ use parking_lot::RwLock;
|
|||
use crate::defines::{LevelInt, MAX_MOVES};
|
||||
use crate::dynamic_data::event_hooks::Event;
|
||||
use crate::dynamic_data::models::battle::Battle;
|
||||
use crate::dynamic_data::models::damage_source::DamageSource;
|
||||
use crate::dynamic_data::models::learned_move::{LearnedMove, MoveLearnMethod};
|
||||
use crate::dynamic_data::script_handling::{ScriptSource, ScriptSourceData, ScriptWrapper};
|
||||
use crate::dynamic_data::{DynamicLibrary, Script, ScriptCategory, ScriptContainer, ScriptSet, VolatileScriptsOwner};
|
||||
use crate::static_data::DataLibrary;
|
||||
use crate::static_data::Form;
|
||||
use crate::static_data::Gender;
|
||||
use crate::static_data::Item;
|
||||
use crate::static_data::Nature;
|
||||
use crate::static_data::Species;
|
||||
use crate::static_data::TypeIdentifier;
|
||||
use crate::static_data::{Ability, Statistic};
|
||||
use crate::static_data::{AbilityIndex, TypeIdentifier};
|
||||
use crate::static_data::{AbilityIndex, DataLibrary};
|
||||
use crate::static_data::{ClampedStatisticSet, StatisticSet};
|
||||
use crate::utils::Random;
|
||||
use crate::{script_hook, PkmnResult, StringKey};
|
||||
|
@ -344,11 +343,15 @@ impl<'own, 'library> Pokemon<'own, 'library> {
|
|||
|
||||
let mut changed = false;
|
||||
let old_value = self.stat_boost.get_stat(stat);
|
||||
if diff_amount > 0 {
|
||||
changed = self.stat_boost.increase_stat(stat, diff_amount);
|
||||
} else if diff_amount < 0 {
|
||||
match diff_amount.cmp(&0_i8) {
|
||||
std::cmp::Ordering::Less => {
|
||||
changed = self.stat_boost.decrease_stat(stat, -diff_amount);
|
||||
}
|
||||
std::cmp::Ordering::Greater => {
|
||||
changed = self.stat_boost.increase_stat(stat, -diff_amount);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
if changed {
|
||||
if let Some(battle) = self.get_battle() {
|
||||
let new_value = self.stat_boost(stat);
|
||||
|
@ -361,7 +364,7 @@ impl<'own, 'library> Pokemon<'own, 'library> {
|
|||
}
|
||||
self.recalculate_boosted_stats();
|
||||
}
|
||||
return changed;
|
||||
changed
|
||||
}
|
||||
|
||||
/// The [individual values](https://bulbapedia.bulbagarden.net/wiki/Individual_values) of the Pokemon.
|
||||
|
@ -740,12 +743,20 @@ impl<'own, 'library> VolatileScriptsOwner<'own> for Pokemon<'own, 'library> {
|
|||
}
|
||||
}
|
||||
|
||||
/// A source of damage. This should be as unique as possible.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum DamageSource {
|
||||
/// The damage is done by a move.
|
||||
MoveDamage = 0,
|
||||
/// The damage is done by something else.
|
||||
Misc = 1,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod test {
|
||||
use crate::dynamic_data::models::pokemon::Pokemon;
|
||||
use crate::static_data::AbilityIndex;
|
||||
use crate::static_data::DataLibrary;
|
||||
use crate::static_data::Gender;
|
||||
use crate::static_data::{AbilityIndex, DataLibrary};
|
||||
|
||||
#[test]
|
||||
fn construct_pokemon() {
|
||||
|
|
|
@ -11,9 +11,13 @@ pub use script_set::*;
|
|||
#[doc(inline)]
|
||||
pub use volatile_scripts_owner::*;
|
||||
|
||||
/// Scripts that are used for item usage
|
||||
mod item_script;
|
||||
/// Scripts that are used to change how a battle functions.
|
||||
mod script;
|
||||
/// Collections of scripts.
|
||||
mod script_set;
|
||||
/// A trait to add volatile scripts to any object.
|
||||
mod volatile_scripts_owner;
|
||||
|
||||
/// This macro runs a script function on a given ScriptSource, and all its parents. It will ensure
|
||||
|
@ -202,7 +206,7 @@ impl ScriptIterator {
|
|||
ScriptWrapper::Set(set) => {
|
||||
let set = set.upgrade().unwrap();
|
||||
let sc = set.at(self.set_index as usize);
|
||||
return Some(sc.clone());
|
||||
return Some(sc);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -43,6 +43,6 @@ pub trait DataLibrary<'a, T: 'a> {
|
|||
/// Gets a random value from the library.
|
||||
fn random_value(&self, rand: &mut Random) -> &T {
|
||||
let i = rand.get_between(0, self.len() as i32);
|
||||
return &self.map().get_index(i as usize).unwrap().1;
|
||||
return self.map().get_index(i as usize).unwrap().1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,12 +17,21 @@ pub use static_data::StaticData;
|
|||
#[doc(inline)]
|
||||
pub use type_library::*;
|
||||
|
||||
/// The library data for abilities.
|
||||
mod ability_library;
|
||||
/// Basic helper trait for libraries.
|
||||
mod data_library;
|
||||
/// The library data for groth rates.
|
||||
mod growth_rate_library;
|
||||
/// The library data for items.
|
||||
mod item_library;
|
||||
/// The library data for misc settings.
|
||||
mod library_settings;
|
||||
/// The library data for moves.
|
||||
mod move_library;
|
||||
/// The library data for species.
|
||||
mod species_library;
|
||||
/// The combination of all libraries.
|
||||
pub(crate) mod static_data;
|
||||
/// The library data for types.
|
||||
mod type_library;
|
||||
|
|
|
@ -15,11 +15,19 @@ pub use statistic_set::*;
|
|||
#[doc(inline)]
|
||||
pub use statistics::*;
|
||||
|
||||
/// Growth rates define how fast a Pokemon can level up.
|
||||
mod growth_rates;
|
||||
/// Items are objects which the player can pick up, keep in their Bag, and use in some manner
|
||||
mod items;
|
||||
/// The libraries module holds all data storage types.
|
||||
pub(crate) mod libraries;
|
||||
/// Moves are actions Pokemon can take in battle.
|
||||
mod moves;
|
||||
/// Natures give stat boosts to specific stats.
|
||||
mod natures;
|
||||
/// Species data holds base data for species.
|
||||
mod species_data;
|
||||
/// Statistic sets are collection of different statistics that can be used by Pokemon in multiple ways.
|
||||
mod statistic_set;
|
||||
/// Statistics are numerical values on Pokemon that are used in battle.
|
||||
mod statistics;
|
||||
|
|
|
@ -3,5 +3,7 @@ pub use move_data::*;
|
|||
#[doc(inline)]
|
||||
pub use secondary_effect::*;
|
||||
|
||||
/// The data belonging to a certain move.
|
||||
mod move_data;
|
||||
/// A secondary effect is an effect on a move that happens after it hits.
|
||||
mod secondary_effect;
|
||||
|
|
|
@ -35,3 +35,13 @@ impl Ability {
|
|||
&self.parameters
|
||||
}
|
||||
}
|
||||
|
||||
/// An ability index allows us to find an ability on a form. It combines a bool for whether the
|
||||
/// ability is hidden or not, and then an index of the ability.
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub struct AbilityIndex {
|
||||
/// Whether or not the ability we're referring to is a hidden ability.
|
||||
pub hidden: bool,
|
||||
/// The index of the ability.
|
||||
pub index: u8,
|
||||
}
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
/// An ability index allows us to find an ability on a form. It combines a bool for whether the
|
||||
/// ability is hidden or not, and then an index of the ability.
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub struct AbilityIndex {
|
||||
/// Whether or not the ability we're referring to is a hidden ability.
|
||||
pub hidden: bool,
|
||||
/// The index of the ability.
|
||||
pub index: u8,
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
use hashbrown::HashSet;
|
||||
|
||||
use crate::static_data::LearnableMoves;
|
||||
use crate::static_data::Statistic;
|
||||
use crate::static_data::TypeIdentifier;
|
||||
use crate::static_data::{Ability, StaticStatisticSet};
|
||||
use crate::static_data::{AbilityIndex, TypeIdentifier};
|
||||
use crate::static_data::{AbilityIndex, LearnableMoves};
|
||||
use crate::Random;
|
||||
use crate::StringKey;
|
||||
|
||||
|
|
|
@ -1,19 +1,22 @@
|
|||
#[doc(inline)]
|
||||
pub use ability::Ability;
|
||||
pub use ability::*;
|
||||
#[doc(inline)]
|
||||
pub use ability_index::AbilityIndex;
|
||||
pub use form::*;
|
||||
#[doc(inline)]
|
||||
pub use form::Form;
|
||||
pub use gender::*;
|
||||
#[doc(inline)]
|
||||
pub use gender::Gender;
|
||||
pub use learnable_moves::*;
|
||||
#[doc(inline)]
|
||||
pub use learnable_moves::LearnableMoves;
|
||||
#[doc(inline)]
|
||||
pub use species::Species;
|
||||
pub use species::*;
|
||||
|
||||
/// An ability is a passive effect in battle that is attached to a Pokemon.
|
||||
mod ability;
|
||||
mod ability_index;
|
||||
/// A form is a variant of a specific species. A species always has at least one form, but can have
|
||||
/// many more.
|
||||
mod form;
|
||||
/// Gender is a Pokemon characteristic.
|
||||
mod gender;
|
||||
/// This allows for storage of the moves a Pokemon can learn.
|
||||
mod learnable_moves;
|
||||
/// The data belonging to a Pokemon with certain characteristics.
|
||||
mod species;
|
||||
|
|
|
@ -3,5 +3,8 @@ pub use random::Random;
|
|||
#[doc(inline)]
|
||||
pub use string_key::StringKey;
|
||||
|
||||
/// The random module defines a RNG implementation used in pkmn_lib
|
||||
mod random;
|
||||
/// The string_key module defines a custom string handling for reduced allocations and fast lookups
|
||||
/// and equality checks.
|
||||
mod string_key;
|
||||
|
|
Loading…
Reference in New Issue