ravenous-tools/weaponry/src/weaponry_structs/equipement_impl_math.rs

120 lines
4.0 KiB
Rust

// Workspace: weaponry
// File: weaponry/src/weaponry_structs/equipement_math.rs
//! Implements base math for each field
//!
use super::equipement_structs::InnerStats;
use crate::weaponry_structs::SpecialCategory;
/// Add a new vector to a clone of a inner field
macro_rules! add_to_vec {
($self: expr, $rhs: expr) => {{
let mut new = $self.clone();
new.append(&mut $rhs.clone());
new
}};
}
impl std::ops::Add for &InnerStats {
type Output = InnerStats;
fn add(self, rhs: Self) -> Self::Output {
InnerStats {
// TODO: Decide the behaviour of ids, as uuid are useless but this is even more useless
id: add_to_vec!(self.id, rhs.id),
name: add_to_vec!(self.name, rhs.name),
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.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)
}
}
},
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.clone().or(rhs.category.clone()), // Can be further optimized
target: self.target.clone().or(rhs.target.clone()), // Can be further optimized
special: self.special.clone() + rhs.special.clone(), // Can be further optimized
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 std::ops::AddAssign for SpecialCategory {
// fn add_assign(&mut self, rhs: Self) {
// todo!()
// }
// }
// impl std::ops::Add for OptionnalReloadType {
// type Output = OptionnalReloadType;
// fn add(self, rhs: Self) -> Self::Output {
// todo!()
// }
// }
// impl std::ops::AddAssign for OptionnalReloadType {
// fn add_assign(&mut self, rhs: Self) {
// todo!()
// }
// }
// impl std::ops::Add for OptionnalWeaponCategory {
// type Output = OptionnalWeaponCategory;
// fn add(self, rhs: Self) -> Self::Output {
// todo!()
// }
// }
// impl std::ops::AddAssign for OptionnalWeaponCategory {
// fn add_assign(&mut self, rhs: Self) {
// todo!()
// }
// }
// impl std::ops::Add for OptionnalDamageType {
// type Output = OptionnalDamageType;
// fn add(self, rhs: Self) -> Self::Output {
// todo!()
// }
// }
// impl std::ops::AddAssign for OptionnalDamageType {
// fn add_assign(&mut self, rhs: Self) {
// todo!()
// }
// }