Loads more work on battling, initial stretch to run a turn done.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-06-16 17:59:33 +02:00
parent a33369afcc
commit ff541b0696
50 changed files with 105871 additions and 497 deletions

View File

@@ -43,11 +43,7 @@ pub mod tests {
let mut lib = AbilityLibrary::new(1);
lib.add(
&StringKey::new("test_ability"),
Box::new(Ability::new(
&"test_ability".into(),
&"test_ability".into(),
Vec::new(),
)),
Box::new(Ability::new(&"test_ability".into(), &"test_ability".into(), Vec::new())),
);
// Drops borrow as mut

View File

@@ -39,7 +39,7 @@ pub mod tests {
use crate::static_data::moves::move_data::{MoveCategory, MoveData, MoveTarget};
use crate::static_data::moves::secondary_effect::SecondaryEffect;
use crate::StringKey;
use std::collections::HashSet;
use hashbrown::HashSet;
fn build_move() -> MoveData {
MoveData::new(

View File

@@ -27,12 +27,7 @@ impl<'a> DataLibrary<'a, Box<Species<'a>>> for SpeciesLibrary<'a> {
&self.list
}
fn get_modify(
&mut self,
) -> (
&mut HashMap<StringKey, Box<Species<'a>>>,
&mut Vec<StringKey>,
) {
fn get_modify(&mut self) -> (&mut HashMap<StringKey, Box<Species<'a>>>, &mut Vec<StringKey>) {
(&mut self.map, &mut self.list)
}
}

View File

@@ -73,8 +73,7 @@ pub mod test {
use crate::static_data::libraries::library_settings::LibrarySettings;
use crate::static_data::libraries::static_data::StaticData;
use crate::static_data::libraries::{
ability_library, growth_rate_library, item_library, move_library, species_library,
type_library,
ability_library, growth_rate_library, item_library, move_library, species_library, type_library,
};
use crate::static_data::natures;

View File

@@ -1,8 +1,13 @@
use crate::static_data::SecondaryEffect;
use crate::StringKey;
use std::collections::HashSet;
use hashbrown::HashSet;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[derive(Copy, Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub enum MoveCategory {
Physical = 0,
Special = 1,
@@ -10,6 +15,7 @@ pub enum MoveCategory {
}
#[derive(Copy, Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum MoveTarget {
Adjacent = 0,
AdjacentAlly,
@@ -25,6 +31,7 @@ pub enum MoveTarget {
Any,
RandomOpponent,
#[cfg_attr(feature = "serde", serde(rename = "Self"))]
SelfUse,
}
@@ -39,7 +46,7 @@ pub struct MoveData {
target: MoveTarget,
priority: i8,
secondary_effect: SecondaryEffect,
flags: HashSet<String>,
flags: HashSet<StringKey>,
}
impl MoveData {
@@ -53,7 +60,7 @@ impl MoveData {
target: MoveTarget,
priority: i8,
secondary_effect: SecondaryEffect,
flags: HashSet<String>,
flags: HashSet<StringKey>,
) -> MoveData {
MoveData {
name: name.clone(),
@@ -99,7 +106,11 @@ impl MoveData {
&self.secondary_effect
}
pub fn has_flag(&self, key: &str) -> bool {
pub fn has_secondary_effect(&self) -> bool {
self.secondary_effect.effect_name() != &StringKey::empty()
}
pub fn has_flag(&self, key: &StringKey) -> bool {
self.flags.contains(key)
}
}

View File

@@ -1,3 +1,5 @@
use crate::StringKey;
#[derive(PartialEq, Debug)]
pub enum EffectParameter {
Bool(bool),
@@ -9,7 +11,7 @@ pub enum EffectParameter {
#[derive(PartialEq, Debug)]
pub struct SecondaryEffect {
chance: f32,
effect_name: String,
effect_name: StringKey,
parameters: Vec<EffectParameter>,
}
@@ -17,15 +19,11 @@ impl SecondaryEffect {
pub fn empty() -> SecondaryEffect {
SecondaryEffect {
chance: 0.0,
effect_name: "".to_string(),
effect_name: StringKey::empty(),
parameters: vec![],
}
}
pub fn new(
chance: f32,
effect_name: String,
parameters: Vec<EffectParameter>,
) -> SecondaryEffect {
pub fn new(chance: f32, effect_name: StringKey, parameters: Vec<EffectParameter>) -> SecondaryEffect {
SecondaryEffect {
chance,
effect_name,
@@ -36,7 +34,7 @@ impl SecondaryEffect {
pub fn chance(&self) -> f32 {
self.chance
}
pub fn effect_name(&self) -> &str {
pub fn effect_name(&self) -> &StringKey {
&self.effect_name
}
pub fn parameters(&self) -> &Vec<EffectParameter> {
@@ -53,11 +51,11 @@ mod tests {
fn create_secondary_effect() {
let empty = SecondaryEffect::empty();
assert_approx_eq!(empty.chance(), 0.0);
assert_eq!(empty.effect_name(), "");
assert_eq!(empty.effect_name(), &"".into());
assert_eq!(empty.parameters().len(), 0);
let set = SecondaryEffect::new(50.0, "foo".to_string(), Vec::new());
let set = SecondaryEffect::new(50.0, "foo".into(), Vec::new());
assert_approx_eq!(set.chance(), 50.0);
assert_eq!(set.effect_name(), "foo");
assert_eq!(set.effect_name(), &"foo".into());
assert_eq!(set.parameters().len(), 0);
}
}

View File

@@ -95,10 +95,7 @@ pub mod tests {
#[test]
fn create_nature_library_insert_and_retrieve() {
let mut lib = NatureLibrary::new(2);
lib.load_nature(
"foo".into(),
Nature::new(Statistic::HP, Statistic::Attack, 1.1, 0.9),
);
lib.load_nature("foo".into(), Nature::new(Statistic::HP, Statistic::Attack, 1.1, 0.9));
lib.load_nature(
"bar".into(),
Nature::new(Statistic::Attack, Statistic::Defense, 1.1, 0.9),
@@ -113,10 +110,7 @@ pub mod tests {
#[test]
fn create_nature_library_insert_and_get_name() {
let mut lib = NatureLibrary::new(2);
lib.load_nature(
"foo".into(),
Nature::new(Statistic::HP, Statistic::Attack, 1.1, 0.9),
);
lib.load_nature("foo".into(), Nature::new(Statistic::HP, Statistic::Attack, 1.1, 0.9));
lib.load_nature(
"bar".into(),
Nature::new(Statistic::Attack, Statistic::Defense, 1.1, 0.9),

View File

@@ -120,8 +120,7 @@ impl<'a> Form<'a> {
self.abilities[rand.get_between_unsigned(0, self.abilities.len() as u32) as usize]
}
pub fn get_random_hidden_ability(&self, rand: &mut Random) -> &Ability {
self.hidden_abilities
[rand.get_between_unsigned(0, self.hidden_abilities.len() as u32) as usize]
self.hidden_abilities[rand.get_between_unsigned(0, self.hidden_abilities.len() as u32) as usize]
}
pub fn has_flag(&self, key: &StringKey) -> bool {

View File

@@ -3,6 +3,7 @@ use crate::static_data::Gender;
use crate::Random;
use crate::StringKey;
use hashbrown::{HashMap, HashSet};
use std::lazy::SyncLazy;
#[derive(Debug)]
pub struct Species<'a> {
@@ -14,9 +15,8 @@ pub struct Species<'a> {
forms: HashMap<StringKey, Form<'a>>,
flags: HashSet<StringKey>,
}
lazy_static::lazy_static! {
static ref DEFAULT_KEY: StringKey = StringKey::new("default");
}
static DEFAULT_KEY: SyncLazy<StringKey> = SyncLazy::new(|| StringKey::new("default"));
impl<'a> Species<'a> {
pub fn new(

View File

@@ -18,14 +18,7 @@ impl<T> StatisticSet<T>
where
T: PrimInt,
{
pub fn new(
hp: T,
attack: T,
defense: T,
special_attack: T,
special_defense: T,
speed: T,
) -> Self {
pub fn new(hp: T, attack: T, defense: T, special_attack: T, special_defense: T, speed: T) -> Self {
Self {
hp,
attack,
@@ -117,21 +110,13 @@ impl<T, const MIN: i64, const MAX: i64> ClampedStatisticSet<T, MIN, MAX>
where
T: PrimInt,
{
pub fn new(
hp: T,
attack: T,
defense: T,
special_attack: T,
special_defense: T,
speed: T,
) -> Self {
pub fn new(hp: T, attack: T, defense: T, special_attack: T, special_defense: T, speed: T) -> Self {
Self {
hp: cast(clamp(cast::<T, i64>(hp).unwrap(), MIN, MAX)).unwrap(),
attack: cast(clamp(cast::<T, i64>(attack).unwrap(), MIN, MAX)).unwrap(),
defense: cast(clamp(cast::<T, i64>(defense).unwrap(), MIN, MAX)).unwrap(),
special_attack: cast(clamp(cast::<T, i64>(special_attack).unwrap(), MIN, MAX)).unwrap(),
special_defense: cast(clamp(cast::<T, i64>(special_defense).unwrap(), MIN, MAX))
.unwrap(),
special_defense: cast(clamp(cast::<T, i64>(special_defense).unwrap(), MIN, MAX)).unwrap(),
speed: cast(clamp(cast::<T, i64>(speed).unwrap(), MIN, MAX)).unwrap(),
}
}
@@ -200,12 +185,8 @@ where
Statistic::HP => Self::change_stat(self.hp + value, &mut self.hp),
Statistic::Attack => Self::change_stat(self.attack + value, &mut self.attack),
Statistic::Defense => Self::change_stat(self.defense + value, &mut self.defense),
Statistic::SpecialAttack => {
Self::change_stat(self.special_attack + value, &mut self.special_attack)
}
Statistic::SpecialDefense => {
Self::change_stat(self.special_defense + value, &mut self.special_defense)
}
Statistic::SpecialAttack => Self::change_stat(self.special_attack + value, &mut self.special_attack),
Statistic::SpecialDefense => Self::change_stat(self.special_defense + value, &mut self.special_defense),
Statistic::Speed => Self::change_stat(self.speed + value, &mut self.speed),
}
}
@@ -215,12 +196,8 @@ where
Statistic::HP => Self::change_stat(self.hp - value, &mut self.hp),
Statistic::Attack => Self::change_stat(self.attack - value, &mut self.attack),
Statistic::Defense => Self::change_stat(self.defense - value, &mut self.defense),
Statistic::SpecialAttack => {
Self::change_stat(self.special_attack - value, &mut self.special_attack)
}
Statistic::SpecialDefense => {
Self::change_stat(self.special_defense - value, &mut self.special_defense)
}
Statistic::SpecialAttack => Self::change_stat(self.special_attack - value, &mut self.special_attack),
Statistic::SpecialDefense => Self::change_stat(self.special_defense - value, &mut self.special_defense),
Statistic::Speed => Self::change_stat(self.speed - value, &mut self.speed),
}
}