weapons #29
|
|
@ -14,22 +14,20 @@ 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 {
|
||||
pub trait RecipeCollection
|
||||
where
|
||||
for<'a> &'a <<Self as RecipeCollection>::Recipes as Combineable>::Inner: std::ops::Add,
|
||||
{
|
||||
/// The type of the inner recipes, this type must be combinable
|
||||
type Recipes: Combineable;
|
||||
|
||||
// /// Combine all current recipies with all the parts given
|
||||
// #[deprecated]
|
||||
// fn combine_all<G>(&mut self, other: G)
|
||||
// where
|
||||
// G: RecipeCollection<Recipes = Self::Recipes> + std::marker::Sync;
|
||||
|
||||
/// Do the parrallel combination all inside
|
||||
/// A blanket implementation giving all combinaisons of recipes with another RecipeCollection
|
||||
///
|
||||
/// This method doesn't make use of parallel iterators as the workload is way faster than would be the memory dispatch
|
||||
fn combine_all_by_blanket<G>(&mut self, other: &G)
|
||||
where
|
||||
G: RecipeCollection<Recipes = Self::Recipes>,
|
||||
{
|
||||
// TODO: Test Add to Self instead
|
||||
self.assign_inner(
|
||||
self.ref_inner()
|
||||
.iter()
|
||||
|
|
@ -46,23 +44,6 @@ pub trait RecipeCollection {
|
|||
);
|
||||
}
|
||||
|
||||
// fn combine_all_by_ref<G>(&mut self, other: G)
|
||||
// where
|
||||
// G: RecipeCollection<Recipes = Self::Recipes> + std::marker::Sync,
|
||||
// {
|
||||
// let mut future_receipes = vec![self.ref_inner().clone(); other.ref_inner().len()];
|
||||
// future_receipes
|
||||
// .par_iter_mut()
|
||||
// .zip(other.ref_inner())
|
||||
// .for_each(move |(a, b)| {
|
||||
// a.par_iter_mut().for_each(move |e| {
|
||||
// e.add_to_self(b);
|
||||
// });
|
||||
// });
|
||||
|
||||
// self.inner = future_receipes.into_par_iter().flatten().collect();
|
||||
// }
|
||||
|
||||
/// Assign the inner value from an owned value, used for blanket implementations
|
||||
fn assign_inner(&mut self, inner: Vec<Self::Recipes>);
|
||||
|
||||
|
|
@ -71,10 +52,6 @@ pub trait RecipeCollection {
|
|||
/// This allows to only clone when needed
|
||||
fn ref_inner(&self) -> &Vec<Self::Recipes>;
|
||||
|
||||
// /// Gives access to a mutable reference of the inner list
|
||||
// #[deprecated]
|
||||
// fn refmut_inner(&mut self) -> &mut Vec<Self::Recipes>;
|
||||
|
||||
// Optional filter ?
|
||||
|
||||
/// Create a collection from a vector
|
||||
|
|
@ -84,30 +61,19 @@ pub trait RecipeCollection {
|
|||
/// 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 {
|
||||
pub trait Combineable
|
||||
where
|
||||
for<'a> &'a <Self as Combineable>::Inner: std::ops::Add,
|
||||
{
|
||||
/// The inner type of the combined elements, this type must implement Add
|
||||
// TODO : Make this help much more readable
|
||||
type Inner: std::ops::Add + std::ops::AddAssign;
|
||||
type Inner;
|
||||
|
||||
/// Give access to a reference of the underlying data to be combined
|
||||
///
|
||||
/// The designed combinaison method is std::ops::Add
|
||||
fn combinable_part(&self) -> &Self::Inner;
|
||||
|
||||
// /// Add an element to self and return a new value
|
||||
// ///
|
||||
// /// This method will clone it's own combinable part
|
||||
// #[deprecated]
|
||||
// fn add_to_other<T>(&self, rhs: T) -> Self
|
||||
// where
|
||||
// T: Combineable<Inner = Self::Inner>;
|
||||
|
||||
/// Add an element to a mutable self
|
||||
// #[deprecated(note = "Mutate in place")]
|
||||
fn add_to_self<T>(&mut self, rhs: &T)
|
||||
where
|
||||
T: Combineable<Inner = Self::Inner>;
|
||||
|
||||
/// Add an element to self and generate a new Self
|
||||
///
|
||||
/// As the signature implies, it will not mutate self not rhs and will generate a new value from the operation
|
||||
|
|
|
|||
|
|
@ -13,13 +13,6 @@ impl Combineable for Equipement {
|
|||
&self.stats
|
||||
}
|
||||
|
||||
fn add_to_self<T>(&mut self, rhs: &T)
|
||||
where
|
||||
T: Combineable<Inner = Self::Inner>,
|
||||
{
|
||||
self.stats += rhs.combinable_part().clone()
|
||||
}
|
||||
|
||||
fn add_ref_to_self<T>(&self, rhs: &T) -> Self
|
||||
where
|
||||
T: Combineable<Inner = Self::Inner>,
|
||||
|
|
@ -110,7 +103,7 @@ mod test {
|
|||
..Default::default()
|
||||
};
|
||||
assert_eq!(
|
||||
i1 + i2,
|
||||
&i1 + &i2,
|
||||
InnerStats {
|
||||
rarity: 1,
|
||||
integrity: 5,
|
||||
|
|
@ -143,8 +136,8 @@ mod test {
|
|||
},
|
||||
);
|
||||
assert_eq!(
|
||||
InnerStats::default()
|
||||
+ InnerStats {
|
||||
&InnerStats::default()
|
||||
+ &InnerStats {
|
||||
damage_type: Some(DamageType(vec![
|
||||
DamageMod::Secondary(PhysicalDamageType::Slash,),
|
||||
DamageMod::Primary(PhysicalDamageType::Blunt,),
|
||||
|
|
|
|||
|
|
@ -6,57 +6,6 @@
|
|||
use super::equipement_structs::InnerStats;
|
||||
use crate::weaponry_structs::SpecialCategory;
|
||||
|
||||
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: {
|
||||
let mut b = self.name.clone();
|
||||
b.append(&mut rhs.name.clone());
|
||||
b
|
||||
},
|
||||
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 &InnerStats {
|
||||
type Output = InnerStats;
|
||||
|
||||
|
|
@ -109,50 +58,6 @@ impl std::ops::Add for &InnerStats {
|
|||
}
|
||||
}
|
||||
|
||||
impl std::ops::AddAssign for InnerStats {
|
||||
fn add_assign(&mut self, rhs: InnerStats) {
|
||||
// self.id;
|
||||
// self.name.push('+');
|
||||
// self.name.push_str(&rhs.name);
|
||||
self.rarity += rhs.rarity;
|
||||
self.cost += rhs.cost;
|
||||
self.difficulty += rhs.difficulty;
|
||||
self.tier += rhs.tier;
|
||||
self.damage += rhs.damage;
|
||||
self.p_damage += rhs.p_damage;
|
||||
self.precision += rhs.precision;
|
||||
self.rmax += rhs.rmax;
|
||||
self.armor_break += rhs.armor_break;
|
||||
self.armor_pierce += rhs.armor_pierce;
|
||||
self.antimaterial += rhs.antimaterial;
|
||||
self.damage_type = {
|
||||
match (self.damage_type.clone(), rhs.damage_type.clone()) {
|
||||
(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)
|
||||
}
|
||||
}
|
||||
};
|
||||
self.protection += rhs.protection;
|
||||
self.integrity += rhs.integrity;
|
||||
self.torque_two_handed += rhs.torque_two_handed;
|
||||
self.torque_one_handed += rhs.torque_one_handed;
|
||||
self.dodge += rhs.dodge;
|
||||
self.parry += rhs.parry;
|
||||
self.speed += rhs.speed;
|
||||
self.stealth += rhs.stealth;
|
||||
self.category.clone().or(rhs.category.clone()); // Can be further optimized
|
||||
// self.special += rhs.special.clone(); // Can be further optimized
|
||||
self.action_cost += rhs.action_cost;
|
||||
self.reload_cost.or(rhs.reload_cost);
|
||||
self.range += rhs.range;
|
||||
self.agility_bonus += rhs.agility_bonus;
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Add for SpecialCategory {
|
||||
type Output = Self;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
// Workspace: weaponry
|
||||
// File: weaponry/src/weaponry_structs/equipement_into_impls.rs
|
||||
// TODO: At some point a trait might want to be used to use these into instead of calling it directly
|
||||
// : Doing so would ensure all prerequists are met
|
||||
// : Another way of doing so might be to instead use Into<Combinable> instead
|
||||
// : Another way would be to add a filter field that would allow or not the combinaison and abstract all
|
||||
// logic that would be into doing multi traits things
|
||||
//! Implementations to transform all Specialized equipement into a generic Equipement
|
||||
//! A specific implementation could be preferable, but this simplicity might allow for easier developpement
|
||||
|
||||
use super::{
|
||||
Equipement,
|
||||
equipement_structs::{EqFinishing, EqMaterial, EqNature, EqShape},
|
||||
};
|
||||
|
||||
impl From<EqShape> for Equipement {
|
||||
fn from(val: EqShape) -> Self {
|
||||
Self { stats: val.stats }
|
||||
}
|
||||
}
|
||||
impl From<EqMaterial> for Equipement {
|
||||
fn from(val: EqMaterial) -> Self {
|
||||
Self { stats: val.stats }
|
||||
}
|
||||
}
|
||||
impl From<EqNature> for Equipement {
|
||||
fn from(val: EqNature) -> Self {
|
||||
Self { stats: val.stats }
|
||||
}
|
||||
}
|
||||
impl From<EqFinishing> for Equipement {
|
||||
fn from(val: EqFinishing) -> Self {
|
||||
Self { stats: val.stats }
|
||||
}
|
||||
}
|
||||
|
|
@ -59,21 +59,6 @@ pub struct InnerStats {
|
|||
pub(super) agility_bonus: u8,
|
||||
}
|
||||
|
||||
// /// A type representing a weapon reload potential
|
||||
// #[derive(Clone, Default)]
|
||||
// #[cfg_attr(test, derive(Debug, PartialEq))]
|
||||
// pub struct OptionnalReloadType(Option<u8>);
|
||||
|
||||
// /// Optionnal Weapon
|
||||
// #[derive(Clone, Default)]
|
||||
// #[cfg_attr(test, derive(Debug, PartialEq))]
|
||||
// pub struct OptionnalWeaponCategory(Option<WeaponCategory>);
|
||||
|
||||
// /// Optionnal damage type
|
||||
// #[derive(Clone, Default)]
|
||||
// #[cfg_attr(test, derive(Debug, PartialEq))]
|
||||
// pub struct OptionnalDamageType(Option<DamageType>);
|
||||
|
||||
/// Shape of the equipement, first mandatory part of an equipement
|
||||
pub struct EqShape {
|
||||
/// The inner stats of the part
|
||||
|
|
@ -92,6 +77,8 @@ pub struct EqMaterial {
|
|||
pub struct EqNature {
|
||||
/// The inner stats of the part
|
||||
pub(super) stats: InnerStats,
|
||||
// TODO: Be sure to take this into account
|
||||
#[allow(dead_code)]
|
||||
/// Which kind of target this nature applies to
|
||||
pub(super) target: NatureTarget,
|
||||
}
|
||||
|
|
@ -106,7 +93,11 @@ pub struct EqFinishing {
|
|||
mod test {
|
||||
// use super::*;
|
||||
|
||||
use super::{Equipement, InnerStats};
|
||||
use crate::{interfaces::RecipeCollection, weaponry_structs::NatureTarget};
|
||||
|
||||
use super::{
|
||||
EqFinishing, EqMaterial, EqNature, EqShape, Equipement, FinalEquipementList, InnerStats,
|
||||
};
|
||||
|
||||
fn list_equip() -> Vec<Equipement> {
|
||||
(0..10)
|
||||
|
|
@ -130,7 +121,38 @@ mod test {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_creating_all_equipements() {}
|
||||
fn test_creating_all_equipements() {
|
||||
let shape = vec![
|
||||
EqShape {
|
||||
stats: InnerStats::default(),
|
||||
}
|
||||
.into(),
|
||||
];
|
||||
let nature = vec![
|
||||
EqNature {
|
||||
stats: InnerStats::default(),
|
||||
target: NatureTarget::Armor,
|
||||
}
|
||||
.into(),
|
||||
];
|
||||
let material = vec![
|
||||
EqMaterial {
|
||||
stats: InnerStats::default(),
|
||||
}
|
||||
.into(),
|
||||
];
|
||||
let finishing = vec![
|
||||
EqFinishing {
|
||||
stats: InnerStats::default(),
|
||||
}
|
||||
.into(),
|
||||
];
|
||||
|
||||
let mut leq = FinalEquipementList::from_vectored(shape);
|
||||
leq.combine_all_by_blanket(&FinalEquipementList::from_vectored(nature));
|
||||
leq.combine_all_by_blanket(&FinalEquipementList::from_vectored(material));
|
||||
leq.combine_all_by_blanket(&FinalEquipementList::from_vectored(finishing));
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ mod equipement_impl_database;
|
|||
mod equipement_impl_io;
|
||||
mod equipement_impl_logic;
|
||||
mod equipement_impl_math;
|
||||
mod equipement_into_impls;
|
||||
pub mod equipement_structs;
|
||||
|
||||
// Republishes the most used symbols
|
||||
|
|
|
|||
Loading…
Reference in New Issue