weapons #27
|
|
@ -4,4 +4,13 @@ version = "0.1.0"
|
|||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
pretty_assertions = "1.4.1"
|
||||
rayon = "1.10.0"
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = { version = "0.5"}
|
||||
|
||||
[[bench]]
|
||||
name = "iter_creation"
|
||||
harness = false
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,119 @@
|
|||
use criterion::{Criterion, criterion_group, criterion_main};
|
||||
use std::{hint::black_box, time::Duration};
|
||||
use weaponry::{
|
||||
interfaces::RecipeCollection,
|
||||
weaponry_structs::{
|
||||
Equipement, FinalEquipementList, equipement_structs::FinalEquipementListPar,
|
||||
},
|
||||
};
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
let steps = [
|
||||
FinalEquipementList::from_vectored(vec![Equipement::default(); 100]),
|
||||
FinalEquipementList::from_vectored(vec![Equipement::default(); 100]),
|
||||
FinalEquipementList::from_vectored(vec![Equipement::default(); 100]),
|
||||
];
|
||||
let par_steps = [
|
||||
FinalEquipementListPar::from_vectored(vec![Equipement::default(); 100]),
|
||||
FinalEquipementListPar::from_vectored(vec![Equipement::default(); 100]),
|
||||
FinalEquipementListPar::from_vectored(vec![Equipement::default(); 100]),
|
||||
];
|
||||
c.bench_function("creating 100 Elements", |b| {
|
||||
b.iter(|| FinalEquipementList::from_vectored(black_box(vec![Equipement::default(); 100])))
|
||||
});
|
||||
c.bench_function("IterGen: 100x100x100", |b| {
|
||||
b.iter(|| {
|
||||
let mut s = steps[0].clone();
|
||||
s.combine_all(steps[1].clone());
|
||||
s.combine_all(steps[2].clone());
|
||||
})
|
||||
});
|
||||
c.bench_function("IterGen: 100x100x100", |b| {
|
||||
b.iter(|| {
|
||||
let mut s = par_steps[0].clone();
|
||||
s.combine_all(par_steps[1].clone());
|
||||
s.combine_all(par_steps[2].clone());
|
||||
})
|
||||
});
|
||||
// c.bench_function("IterGen: 100x100x100x100", |b| {
|
||||
// b.iter(|| {
|
||||
// let mut s = steps[0].clone();
|
||||
// s.combine_all(steps[1].clone());
|
||||
// s.combine_all(steps[2].clone());
|
||||
// s.combine_all(steps[2].clone());
|
||||
// })
|
||||
// });
|
||||
c.bench_function("IterGenPar: 100x100x100x100", |b| {
|
||||
b.iter(|| {
|
||||
let mut s = par_steps[0].clone();
|
||||
s.combine_all(par_steps[1].clone());
|
||||
s.combine_all(par_steps[2].clone());
|
||||
s.combine_all(par_steps[2].clone());
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group! {
|
||||
name = benches;
|
||||
config = Criterion::default().measurement_time(Duration::from_secs(10));
|
||||
targets= criterion_benchmark
|
||||
}
|
||||
criterion_main!(benches);
|
||||
|
||||
// TODO: Add to a How to add new Lists
|
||||
|
||||
// #[derive(Clone)]
|
||||
// struct Equipo {
|
||||
// stats: InnerStats,
|
||||
// }
|
||||
|
||||
// impl Equipo {
|
||||
// fn newish(i: u8) -> Self {
|
||||
// let mut stats = InnerStats::default();
|
||||
// stats.id = i;
|
||||
// Equipo { stats }
|
||||
// }
|
||||
// }
|
||||
|
||||
// struct ListStatic {
|
||||
// inner: Vec<Equipo>,
|
||||
// }
|
||||
// struct ListParIter {
|
||||
// inner: Vec<Equipo>,
|
||||
// }
|
||||
|
||||
// impl RecipeCollection for ListStatic {
|
||||
// type Recipes = Equipo;
|
||||
|
||||
// fn combine_all<G>(&mut self, other: G)
|
||||
// where
|
||||
// G: RecipeCollection<Recipes = Self::Recipes>,
|
||||
// {
|
||||
// todo!()
|
||||
// }
|
||||
|
||||
// fn inner(&self) -> Vec<Self::Recipes> {
|
||||
// self.inner.clone()
|
||||
// }
|
||||
|
||||
// fn from_vectored(list: Vec<Self::Recipes>) -> Self {
|
||||
// Self { inner: list }
|
||||
// }
|
||||
// }
|
||||
|
||||
// impl Combineable for Equipo {
|
||||
// type Inner = InnerStats;
|
||||
|
||||
// fn clone_combinable_part(&self) -> Self::Inner {
|
||||
// self.stats.clone()
|
||||
// }
|
||||
|
||||
// fn add_to_self<T>(&self, rhs: T) -> Self
|
||||
// where
|
||||
// T: Combineable<Inner = Self::Inner>,
|
||||
// {
|
||||
// Equipo {
|
||||
// stats: self.clone_combinable_part() + rhs.clone_combinable_part(),
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
|
@ -10,3 +10,44 @@ pub trait ToTex {}
|
|||
|
||||
/// Specify this element can be made from parts (Unsure, maybe a way to ensure Add is presend ?)
|
||||
pub trait FromParts {}
|
||||
|
||||
/// Trait implemented for the final collection of a recipe, allowing it to be combined with parts
|
||||
///
|
||||
/// A recipe list will be combined with a part list to be updated and generate all combinaisons, so on and so forth
|
||||
pub trait RecipeCollection {
|
||||
/// The type of the inner recipes, this type must be combinable
|
||||
type Recipes: Combineable;
|
||||
|
||||
/// Combine all current recipies with all the parts given
|
||||
fn combine_all<G>(&mut self, other: G)
|
||||
where
|
||||
G: RecipeCollection<Recipes = Self::Recipes> + std::marker::Sync;
|
||||
|
||||
/// Access the inner list
|
||||
// TODO: Use iterators ?
|
||||
fn inner(&self) -> Vec<Self::Recipes>;
|
||||
// Optional filter ?
|
||||
|
||||
/// Create a collection from a vector
|
||||
fn from_vectored(list: Vec<Self::Recipes>) -> Self;
|
||||
}
|
||||
|
||||
/// Trait that ensure that two elements of a recipe are combinable,
|
||||
///
|
||||
/// Being combinable means it can be coerced into elements that implement add
|
||||
pub trait Combineable {
|
||||
/// The inner type of the combined elements, this type must implement Add
|
||||
// TODO : Make this help much more readable
|
||||
type Inner: std::ops::Add;
|
||||
|
||||
/// Give access to an owned underlying type that can be combined
|
||||
// TODO: the ownership part might not be needed
|
||||
fn clone_combinable_part(&self) -> Self::Inner;
|
||||
|
||||
/// Add an element to self and return a new value
|
||||
///
|
||||
/// This method will clone it's own combinable part
|
||||
fn add_to_self<T>(&self, rhs: T) -> Self
|
||||
where
|
||||
T: Combineable<Inner = Self::Inner>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,6 @@
|
|||
|
||||
mod database;
|
||||
mod export;
|
||||
mod interfaces;
|
||||
pub mod interfaces;
|
||||
mod strategy;
|
||||
mod weaponry_structs;
|
||||
pub mod weaponry_structs;
|
||||
|
|
|
|||
|
|
@ -8,8 +8,6 @@
|
|||
//!
|
||||
#![allow(dead_code)]
|
||||
|
||||
use rayon::iter::ParallelIterator;
|
||||
|
||||
/// Generation strategy, how to generate all the data, instead of a full permutation
|
||||
pub enum EquipementStrategy {
|
||||
/// Full permutation, generate all possible outcomes
|
||||
|
|
@ -44,50 +42,39 @@ pub enum EquipementFilter {
|
|||
Named,
|
||||
}
|
||||
|
||||
// /// D
|
||||
// struct Gen<T>
|
||||
// where
|
||||
// T: Send,
|
||||
// {
|
||||
// /// E
|
||||
// elem: Vec<T>,
|
||||
// }
|
||||
|
||||
// impl<T: Send> ParallelIterator for Gen<T> {
|
||||
// type Item = T;
|
||||
|
||||
// fn drive_unindexed<C>(self, consumer: C) -> C::Result
|
||||
// where
|
||||
// C: rayon::iter::plumbing::UnindexedConsumer<Self::Item>,
|
||||
// {
|
||||
// let _ = consumer;
|
||||
// todo!()
|
||||
// }
|
||||
// }
|
||||
// /// Default full generation strategy
|
||||
// pub fn default_generation() -> impl ParallelIterator {
|
||||
// Gen::<u8> { elem: Vec::new() }
|
||||
// }
|
||||
/// Default full generation strategy
|
||||
pub fn default_generation<T: Copy>(a: Vec<T>, b: Vec<T>) -> Vec<(T, T)> {
|
||||
a.iter()
|
||||
.flat_map(|e| {
|
||||
b.iter()
|
||||
.map(|f| ((e.clone()), (f.clone())))
|
||||
.collect::<Vec<(T, T)>>()
|
||||
})
|
||||
// .collect::<Vec<Vec<(T, T)>>>()
|
||||
// .flatten()
|
||||
.collect()
|
||||
}
|
||||
|
||||
// /// Default full generation strategy
|
||||
// pub fn naive_generation<T>(left: Vec<T>, right: Vec<T>) -> Vec<T>
|
||||
// where
|
||||
// T: Clone,
|
||||
// for<'a> &'a T: std::ops::Add<&'a T>,
|
||||
// {
|
||||
// left.iter()
|
||||
// .flat_map(move |e| right.iter().map(move |f| (e + f)).collect::<Vec<T>>())
|
||||
// .collect()
|
||||
// }
|
||||
|
||||
// /// Default full generation strategy
|
||||
// ///
|
||||
// /// Take a list of various parts that are combinable and combines them
|
||||
// pub fn naive_generation<T>(
|
||||
// list_recipes: Vec<Box<impl ReceipeCombinaison<Recipes = u8>>>,
|
||||
// ) -> Vec<T> {
|
||||
// list_recipes.iter().reduce(|acc, e| acc.combine_all(e));
|
||||
// todo!()
|
||||
// }
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
// use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_creator() {
|
||||
let t = default_generation(vec![1, 2, 3], vec![5, 6, 7]);
|
||||
println!("{:?}", t);
|
||||
panic!()
|
||||
fn test_naive_generator() {
|
||||
// let t = naive_generation(vec![1, 2, 3], vec![5, 6, 7]);
|
||||
// assert_eq!(t.len(), 3 * 3);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,168 +0,0 @@
|
|||
// Workspace: weaponry
|
||||
// File: weaponry/src/weaponry_structs.rs
|
||||
//! All weaponry intermod structures
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
/// The inner statistics of the equipement, used across all parts and final weapon
|
||||
// #[derive(Default)]
|
||||
#[allow(clippy::missing_docs_in_private_items)]
|
||||
pub struct InnerStats {
|
||||
id: usize,
|
||||
name: String,
|
||||
rarity: u8,
|
||||
cost: u8,
|
||||
difficulty: u8,
|
||||
tier: u8,
|
||||
damage: u8,
|
||||
p_damage: u8,
|
||||
precision: u8,
|
||||
rmax: u8,
|
||||
armor_break: u8,
|
||||
armor_pierce: u8,
|
||||
antimaterial: u8,
|
||||
damage_type: DamageMod,
|
||||
protection: u8,
|
||||
integrity: u8,
|
||||
torque_two_handed: Option<u8>,
|
||||
torque_one_handed: Option<u8>,
|
||||
dodge: u8,
|
||||
parry: u8,
|
||||
speed: u8,
|
||||
stealth: u8,
|
||||
category: WeaponCategory,
|
||||
special: Vec<String>,
|
||||
action_cost: u8,
|
||||
reload_cost: Option<u8>,
|
||||
range: u8,
|
||||
agility_bonus: u8,
|
||||
}
|
||||
|
||||
/// The final equipement, obtained by combining all parts
|
||||
pub struct Equipement {
|
||||
/// The inner stats used by the equipement
|
||||
stats: InnerStats,
|
||||
}
|
||||
|
||||
/// Shape of the equipement, first mandatory part of an equipement
|
||||
pub struct EqShape {
|
||||
/// The inner stats of the part
|
||||
stats: InnerStats,
|
||||
}
|
||||
|
||||
/// Material used for the equipement, all equipements are crafted with 1-2 materials
|
||||
pub struct EqMaterial {
|
||||
/// The inner stats of the part
|
||||
stats: InnerStats,
|
||||
}
|
||||
|
||||
/// Nature of the equipement, some natures are reserved and some can be chained
|
||||
///
|
||||
/// Deciding on the combinaison can be tricky an will need an extra field
|
||||
pub struct EqNature {
|
||||
/// The inner stats of the part
|
||||
stats: InnerStats,
|
||||
/// Which kind of target this nature applies to
|
||||
target: NatureTarget,
|
||||
}
|
||||
|
||||
/// Finishing touches, since all of them have a cost, they are treated in a special fashion
|
||||
pub struct EqFinishing {
|
||||
/// The inner stats of the part
|
||||
stats: InnerStats,
|
||||
}
|
||||
|
||||
/// The kind of target this nature can apply to
|
||||
pub enum NatureTarget {
|
||||
/// Can apply to a weapon and is unique
|
||||
WeaponUnique,
|
||||
/// Can apply to a weapon and must be combined with another
|
||||
WeaponCombined,
|
||||
/// Can apply to an armor (all armor nature are unique)
|
||||
Armor,
|
||||
}
|
||||
|
||||
/// Enum of all different physical weapon damage types
|
||||
#[allow(clippy::missing_docs_in_private_items)]
|
||||
pub enum PhysicalDamageType {
|
||||
Blunt,
|
||||
Slash,
|
||||
Pierce,
|
||||
}
|
||||
|
||||
impl From<&str> for PhysicalDamageType {
|
||||
fn from(value: &str) -> Self {
|
||||
let _ = value;
|
||||
// Matchcase for all damage types
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Weapon damage, combining the base weapon damage type and it's level
|
||||
///
|
||||
/// Signifying wether the damage is pure or [secondary] or [[tertiary]]
|
||||
#[allow(clippy::missing_docs_in_private_items)]
|
||||
pub enum DamageMod {
|
||||
Primary(PhysicalDamageType),
|
||||
Secondary(PhysicalDamageType),
|
||||
Tertiary(PhysicalDamageType),
|
||||
}
|
||||
|
||||
impl From<&str> for DamageMod {
|
||||
fn from(value: &str) -> Self {
|
||||
let _ = value;
|
||||
// Detect [] and recurse from
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Combined damage type, as a vector of all damage types
|
||||
///
|
||||
/// Meant to be serialised to tex and deserialized directly from the table
|
||||
pub struct DamageType(Vec<DamageMod>);
|
||||
|
||||
impl From<&str> for DamageType {
|
||||
fn from(value: &str) -> Self {
|
||||
let _ = value;
|
||||
// Split by , then recurse from and collect
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
/// List all weapon categories
|
||||
#[allow(clippy::missing_docs_in_private_items)]
|
||||
pub enum WeaponCategory {
|
||||
Exotic,
|
||||
Dagger,
|
||||
Claws,
|
||||
Blade,
|
||||
Haroth,
|
||||
Axe,
|
||||
Kahml,
|
||||
Hammer,
|
||||
Rhodarak,
|
||||
Staff,
|
||||
Lance,
|
||||
Landscapper,
|
||||
Bow,
|
||||
Crossbow,
|
||||
Cannon,
|
||||
}
|
||||
|
||||
impl From<&str> for WeaponCategory {
|
||||
fn from(value: &str) -> Self {
|
||||
let _ = value;
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
// use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_data_serialisation() {}
|
||||
|
||||
#[test]
|
||||
fn test_data_deserialisation() {}
|
||||
}
|
||||
|
|
@ -0,0 +1,121 @@
|
|||
// Workspace: weaponry
|
||||
// File: weaponry/src/weaponry_structs/equipement_fields.rs
|
||||
//! The inner fields used by the super structs
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
#[cfg_attr(test, derive(Debug, PartialEq))]
|
||||
/// The special category, a vec of string, for display purposes only
|
||||
pub struct SpecialCategory(pub(super) Vec<String>);
|
||||
|
||||
/// The kind of target this nature can apply to
|
||||
pub enum NatureTarget {
|
||||
/// Can apply to a weapon and is unique
|
||||
WeaponUnique,
|
||||
/// Can apply to a weapon and must be combined with another
|
||||
WeaponCombined,
|
||||
/// Can apply to an armor (all armor nature are unique)
|
||||
Armor,
|
||||
}
|
||||
|
||||
/// Enum of all different physical weapon damage types
|
||||
#[allow(clippy::missing_docs_in_private_items)]
|
||||
#[derive(Clone)]
|
||||
#[cfg_attr(test, derive(Debug, PartialEq))]
|
||||
pub enum PhysicalDamageType {
|
||||
Blunt,
|
||||
Slash,
|
||||
Pierce,
|
||||
}
|
||||
impl From<&str> for PhysicalDamageType {
|
||||
fn from(value: &str) -> Self {
|
||||
let _ = value;
|
||||
// Matchcase for all damage types
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Weapon damage, combining the base weapon damage type and it's level
|
||||
///
|
||||
/// Signifying wether the damage is pure or [secondary] or [[tertiary]]
|
||||
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
|
||||
#[derive(Clone)]
|
||||
#[cfg_attr(test, derive(Debug, PartialEq))]
|
||||
pub enum DamageMod {
|
||||
Primary(PhysicalDamageType),
|
||||
Secondary(PhysicalDamageType),
|
||||
Tertiary(PhysicalDamageType),
|
||||
}
|
||||
|
||||
impl From<&str> for DamageMod {
|
||||
fn from(value: &str) -> Self {
|
||||
let _ = value;
|
||||
// Detect [] and recurse from
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
/// Combined damage type, as a vector of all damage types
|
||||
///
|
||||
/// Meant to be serialised to tex and deserialized directly from the table
|
||||
#[derive(Clone)]
|
||||
#[cfg_attr(test, derive(Debug, PartialEq))]
|
||||
pub struct DamageType(pub(super) Vec<DamageMod>);
|
||||
|
||||
impl From<&str> for DamageType {
|
||||
fn from(value: &str) -> Self {
|
||||
let _ = value;
|
||||
// Split by , then recurse from and collect
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
/// List all weapon categories
|
||||
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
|
||||
#[derive(Clone)]
|
||||
#[cfg_attr(test, derive(Debug, PartialEq))]
|
||||
pub enum WeaponCategory {
|
||||
Exotic,
|
||||
Dagger,
|
||||
Claws,
|
||||
Blade,
|
||||
Haroth,
|
||||
Axe,
|
||||
Kahml,
|
||||
Hammer,
|
||||
Rhodarak,
|
||||
Staff,
|
||||
Lance,
|
||||
Landscapper,
|
||||
Bow,
|
||||
Crossbow,
|
||||
Cannon,
|
||||
}
|
||||
|
||||
impl From<&str> for WeaponCategory {
|
||||
fn from(value: &str) -> Self {
|
||||
let _ = value;
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Consider this for test
|
||||
// impl Equipement{
|
||||
// fn random_equipement(){}
|
||||
// }
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
// use super::*;
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_fields_serialisation() {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_fields_deserialisation() {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
// Workspace: weaponry
|
||||
// File: weaponry/src/weaponry_structs/equipement_impl_database.rs
|
||||
//! All database specific implementations
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
// Workspace: weaponry
|
||||
// File: weaponry/src/weaponry_structs/equipement_impl_io.rs
|
||||
//! All implementation IO specific (mainly export and serde)
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
// use super::*;
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_structs_serialisation() {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_structs_deserialisation() {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,287 @@
|
|||
// Workspace: weaponry
|
||||
// File: weaponry/src/weaponry_structs/equipement_impl_logic.rs
|
||||
//! Implementation of the logic traits, used for equipement generation
|
||||
|
||||
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
|
||||
|
||||
use crate::interfaces::{Combineable, RecipeCollection};
|
||||
|
||||
use super::{
|
||||
Equipement, FinalEquipementList, SpecialCategory,
|
||||
equipement_structs::{FinalEquipementListPar, InnerStats},
|
||||
};
|
||||
|
||||
impl std::ops::Add for InnerStats {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
Self {
|
||||
// TODO: Decide the behaviour of ids, as uuid are useless but this is even more useless
|
||||
id: self.id,
|
||||
name: [self.name, rhs.name].join("+"),
|
||||
rarity: self.rarity + rhs.rarity,
|
||||
cost: self.cost + rhs.cost,
|
||||
difficulty: self.difficulty + rhs.difficulty,
|
||||
tier: self.tier + rhs.tier,
|
||||
damage: self.damage + rhs.damage,
|
||||
p_damage: self.p_damage + rhs.p_damage,
|
||||
precision: self.precision + rhs.precision,
|
||||
rmax: self.rmax + rhs.rmax,
|
||||
armor_break: self.armor_break + rhs.armor_break,
|
||||
armor_pierce: self.armor_pierce + rhs.armor_pierce,
|
||||
antimaterial: self.antimaterial + rhs.antimaterial,
|
||||
damage_type: {
|
||||
match (self.damage_type, rhs.damage_type) {
|
||||
(None, None) => None,
|
||||
(None, Some(a)) => Some(a),
|
||||
(Some(a), None) => Some(a),
|
||||
(Some(mut a), Some(mut b)) => {
|
||||
a.0.append(&mut b.0);
|
||||
Some(a)
|
||||
}
|
||||
}
|
||||
},
|
||||
protection: self.protection + rhs.protection,
|
||||
integrity: self.integrity + rhs.integrity,
|
||||
torque_two_handed: self.torque_two_handed + rhs.torque_two_handed,
|
||||
torque_one_handed: self.torque_one_handed + rhs.torque_one_handed,
|
||||
dodge: self.dodge + rhs.dodge,
|
||||
parry: self.parry + rhs.parry,
|
||||
speed: self.speed + rhs.speed,
|
||||
stealth: self.stealth + rhs.stealth,
|
||||
category: self.category.or(rhs.category),
|
||||
special: self.special + rhs.special,
|
||||
action_cost: self.action_cost + rhs.action_cost,
|
||||
reload_cost: self.reload_cost.or(rhs.reload_cost),
|
||||
range: self.range + rhs.range,
|
||||
agility_bonus: self.agility_bonus + rhs.agility_bonus,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Add for SpecialCategory {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
let mut c = self.clone();
|
||||
// TODO: Overcopy, kinda meaningless optimisation tho
|
||||
c.0.append(&mut rhs.clone().0);
|
||||
c
|
||||
}
|
||||
}
|
||||
|
||||
impl Combineable for Equipement {
|
||||
type Inner = InnerStats;
|
||||
fn clone_combinable_part(&self) -> InnerStats {
|
||||
self.stats.clone()
|
||||
}
|
||||
|
||||
fn add_to_self<T>(&self, rhs: T) -> Self
|
||||
where
|
||||
T: Combineable<Inner = Self::Inner>,
|
||||
{
|
||||
Self {
|
||||
stats: self.clone_combinable_part() + rhs.clone_combinable_part(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RecipeCollection for FinalEquipementList {
|
||||
type Recipes = Equipement;
|
||||
|
||||
fn combine_all<G>(&mut self, other: G)
|
||||
where
|
||||
G: RecipeCollection<Recipes = Self::Recipes>,
|
||||
{
|
||||
self.inner = self
|
||||
.inner()
|
||||
.iter()
|
||||
.flat_map(|e| {
|
||||
other
|
||||
.inner()
|
||||
.iter()
|
||||
.map(|f: &Self::Recipes| e.add_to_self(f.clone()))
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.collect();
|
||||
}
|
||||
|
||||
fn inner(&self) -> Vec<Self::Recipes> {
|
||||
self.inner.clone()
|
||||
}
|
||||
|
||||
fn from_vectored(list: Vec<Self::Recipes>) -> Self {
|
||||
Self { inner: list }
|
||||
}
|
||||
}
|
||||
|
||||
impl RecipeCollection for FinalEquipementListPar {
|
||||
type Recipes = Equipement;
|
||||
|
||||
fn combine_all<G>(&mut self, other: G)
|
||||
where
|
||||
G: RecipeCollection<Recipes = Self::Recipes> + std::marker::Sync,
|
||||
{
|
||||
self.inner = self
|
||||
.inner()
|
||||
.par_iter()
|
||||
.flat_map(|e| {
|
||||
other
|
||||
.inner()
|
||||
.par_iter()
|
||||
.map(|f: &Self::Recipes| e.add_to_self(f.clone()))
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.collect();
|
||||
}
|
||||
|
||||
fn inner(&self) -> Vec<Self::Recipes> {
|
||||
self.inner.clone()
|
||||
}
|
||||
|
||||
fn from_vectored(list: Vec<Self::Recipes>) -> Self {
|
||||
Self { inner: list }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::{
|
||||
interfaces::RecipeCollection,
|
||||
weaponry_structs::{
|
||||
DamageMod, DamageType, Equipement, FinalEquipementList, SpecialCategory,
|
||||
WeaponCategory, equipement_fields::PhysicalDamageType, equipement_structs::InnerStats,
|
||||
},
|
||||
};
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn test_struct_generation() {
|
||||
let mut f = FinalEquipementList::from_vectored(vec![
|
||||
Equipement::newish("", 1),
|
||||
Equipement::newish("", 2),
|
||||
]);
|
||||
let g = FinalEquipementList::from_vectored(vec![
|
||||
Equipement::newish("", 4),
|
||||
Equipement::newish("", 8),
|
||||
]);
|
||||
|
||||
assert_eq!(
|
||||
f.inner(),
|
||||
vec![Equipement::newish("", 1), Equipement::newish("", 2)]
|
||||
);
|
||||
|
||||
f.combine_all(g);
|
||||
assert_eq!(
|
||||
f,
|
||||
FinalEquipementList::from_vectored(vec![
|
||||
Equipement::newish("+", 5),
|
||||
Equipement::newish("+", 9),
|
||||
Equipement::newish("+", 6),
|
||||
Equipement::newish("+", 10)
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_base_operation() {
|
||||
// let inner = InnerStats::default();
|
||||
// let inner2 = inner.clone() + inner.clone();
|
||||
// assert_eq!(inner, inner2); // True because of the 0 initialisation
|
||||
let i1 = InnerStats {
|
||||
rarity: 1,
|
||||
integrity: 2,
|
||||
range: 3,
|
||||
agility_bonus: 4,
|
||||
category: Some(WeaponCategory::Dagger),
|
||||
special: SpecialCategory(vec!["zero".into()]),
|
||||
damage_type: Some(DamageType(vec![DamageMod::Secondary(
|
||||
PhysicalDamageType::Slash,
|
||||
)])),
|
||||
..Default::default()
|
||||
};
|
||||
let i2 = InnerStats {
|
||||
integrity: 3,
|
||||
agility_bonus: 5,
|
||||
damage: 10,
|
||||
damage_type: Some(DamageType(vec![DamageMod::Primary(
|
||||
PhysicalDamageType::Blunt,
|
||||
)])),
|
||||
special: SpecialCategory(vec!["one".into(), "two".into()]),
|
||||
..Default::default()
|
||||
};
|
||||
assert_eq!(
|
||||
i1 + i2,
|
||||
InnerStats {
|
||||
name: "+".into(),
|
||||
rarity: 1,
|
||||
integrity: 5,
|
||||
agility_bonus: 9,
|
||||
damage: 10,
|
||||
range: 3,
|
||||
category: Some(WeaponCategory::Dagger),
|
||||
special: SpecialCategory(vec!["zero".into(), "one".into(), "two".into()]),
|
||||
damage_type: Some(DamageType(vec![
|
||||
DamageMod::Secondary(PhysicalDamageType::Slash,),
|
||||
DamageMod::Primary(PhysicalDamageType::Blunt,),
|
||||
])),
|
||||
..Default::default()
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
InnerStats {
|
||||
damage_type: Some(DamageType(vec![
|
||||
DamageMod::Secondary(PhysicalDamageType::Slash,),
|
||||
DamageMod::Primary(PhysicalDamageType::Blunt,),
|
||||
])),
|
||||
..Default::default()
|
||||
} + InnerStats::default(),
|
||||
InnerStats {
|
||||
name: "+".into(),
|
||||
damage_type: Some(DamageType(vec![
|
||||
DamageMod::Secondary(PhysicalDamageType::Slash,),
|
||||
DamageMod::Primary(PhysicalDamageType::Blunt,),
|
||||
])),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
assert_eq!(
|
||||
InnerStats::default()
|
||||
+ InnerStats {
|
||||
damage_type: Some(DamageType(vec![
|
||||
DamageMod::Secondary(PhysicalDamageType::Slash,),
|
||||
DamageMod::Primary(PhysicalDamageType::Blunt,),
|
||||
])),
|
||||
..Default::default()
|
||||
},
|
||||
InnerStats {
|
||||
name: "+".into(),
|
||||
damage_type: Some(DamageType(vec![
|
||||
DamageMod::Secondary(PhysicalDamageType::Slash,),
|
||||
DamageMod::Primary(PhysicalDamageType::Blunt,),
|
||||
])),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_generator_function() {}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_basic_logic() {}
|
||||
|
||||
impl Equipement {
|
||||
fn newish(name: &str, i: u8) -> Self {
|
||||
Equipement {
|
||||
stats: InnerStats {
|
||||
name: name.to_owned(),
|
||||
rarity: i,
|
||||
..Default::default()
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,130 @@
|
|||
// Workspace: weaponry
|
||||
// File: weaponry/src/weaponry_structs/equipement_structs.rs
|
||||
//! Base equipement structures
|
||||
|
||||
use super::{DamageType, NatureTarget, SpecialCategory, WeaponCategory};
|
||||
|
||||
/// The final equipement list
|
||||
///
|
||||
/// This list is initialized with the base part and updated by succesive combinaisons
|
||||
#[derive(Clone)]
|
||||
#[cfg_attr(test, derive(PartialEq, Debug))]
|
||||
pub struct FinalEquipementList {
|
||||
/// Inner List of final equipements
|
||||
pub(super) inner: Vec<Equipement>,
|
||||
}
|
||||
|
||||
/// A parallel Implementation of the final equipement list
|
||||
///
|
||||
/// This list only serve for benchmark purposes
|
||||
#[derive(Clone)]
|
||||
#[cfg_attr(test, derive(PartialEq, Debug))]
|
||||
pub struct FinalEquipementListPar {
|
||||
/// Inner List of final equipements
|
||||
pub(super) inner: Vec<Equipement>,
|
||||
}
|
||||
|
||||
/// The final equipement, obtained by combining all parts
|
||||
#[derive(Clone, Default)]
|
||||
#[cfg_attr(test, derive(PartialEq, Debug))]
|
||||
pub struct Equipement {
|
||||
/// The inner stats used by the equipement
|
||||
pub(super) stats: InnerStats,
|
||||
}
|
||||
|
||||
/// The inner statistics of the equipement, used across all parts and final weapon
|
||||
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
|
||||
#[derive(Clone, Default)]
|
||||
#[cfg_attr(test, derive(Debug, PartialEq))]
|
||||
pub struct InnerStats {
|
||||
pub id: u8,
|
||||
pub name: String,
|
||||
pub(super) rarity: u8,
|
||||
pub(super) cost: u8,
|
||||
pub(super) difficulty: u8,
|
||||
pub(super) tier: u8,
|
||||
pub(super) damage: u8,
|
||||
pub(super) p_damage: u8,
|
||||
pub(super) precision: u8,
|
||||
pub(super) rmax: u8,
|
||||
pub(super) armor_break: u8,
|
||||
pub(super) armor_pierce: u8,
|
||||
pub(super) antimaterial: u8,
|
||||
pub(super) damage_type: Option<DamageType>,
|
||||
pub(super) protection: u8,
|
||||
pub(super) integrity: u8,
|
||||
pub(super) torque_two_handed: u8,
|
||||
pub(super) torque_one_handed: u8,
|
||||
pub(super) dodge: u8,
|
||||
pub(super) parry: u8,
|
||||
pub(super) speed: u8,
|
||||
pub(super) stealth: u8,
|
||||
pub(super) category: Option<WeaponCategory>,
|
||||
pub(super) special: SpecialCategory,
|
||||
pub(super) action_cost: u8,
|
||||
pub(super) reload_cost: Option<u8>,
|
||||
pub(super) range: u8,
|
||||
pub(super) agility_bonus: u8,
|
||||
}
|
||||
|
||||
/// Shape of the equipement, first mandatory part of an equipement
|
||||
pub struct EqShape {
|
||||
/// The inner stats of the part
|
||||
pub(super) stats: InnerStats,
|
||||
}
|
||||
|
||||
/// Material used for the equipement, all equipements are crafted with 1-2 materials
|
||||
pub struct EqMaterial {
|
||||
/// The inner stats of the part
|
||||
pub(super) stats: InnerStats,
|
||||
}
|
||||
|
||||
/// Nature of the equipement, some natures are reserved and some can be chained
|
||||
///
|
||||
/// Deciding on the combinaison can be tricky an will need an extra field
|
||||
pub struct EqNature {
|
||||
/// The inner stats of the part
|
||||
pub(super) stats: InnerStats,
|
||||
/// Which kind of target this nature applies to
|
||||
pub(super) target: NatureTarget,
|
||||
}
|
||||
|
||||
/// Finishing touches, since all of them have a cost, they are treated in a special fashion
|
||||
pub struct EqFinishing {
|
||||
/// The inner stats of the part
|
||||
pub(super) stats: InnerStats,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
// use super::*;
|
||||
|
||||
use super::{Equipement, InnerStats};
|
||||
|
||||
fn list_equip() -> Vec<Equipement> {
|
||||
(0..10)
|
||||
.map(|_| Equipement {
|
||||
..Default::default()
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_struct_creation() {
|
||||
let stats = InnerStats::default();
|
||||
let eq1 = Equipement {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let list_eq = list_equip();
|
||||
|
||||
assert_eq!(stats, eq1.stats);
|
||||
assert_eq!(list_eq[0], eq1);
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn test_default_behaviour() {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
// Workspace: weaponry
|
||||
// File: weaponry/src/weaponry_structs/mod.rs
|
||||
//! All weaponry intermod structures
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
mod equipement_fields;
|
||||
mod equipement_impl_database;
|
||||
mod equipement_impl_io;
|
||||
mod equipement_impl_logic;
|
||||
pub mod equipement_structs;
|
||||
|
||||
// Republishes the most used symbols
|
||||
// All generic structs
|
||||
pub use equipement_structs::{Equipement, FinalEquipementList};
|
||||
|
||||
// All generic fields
|
||||
#[allow(unused_imports)]
|
||||
pub use equipement_fields::{DamageMod, DamageType, NatureTarget, SpecialCategory, WeaponCategory};
|
||||
Loading…
Reference in New Issue