303 lines
8.5 KiB
Rust
303 lines
8.5 KiB
Rust
// Workspace: weaponry
|
|
// File: weaponry/src/weaponry_structs/equipement_structs.rs
|
|
//! Base equipement structures
|
|
|
|
use std::rc::Rc;
|
|
|
|
use crate::interfaces::{FilterFunction, FilterFunctionType};
|
|
use more_fields::FieldsAsSlice;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use super::{DamageType, SpecialCategory, WeaponCategory};
|
|
|
|
/// The final equipement list
|
|
///
|
|
/// This list is initialized with the base part and updated by succesive combinaisons
|
|
#[derive(Clone, Debug)]
|
|
#[cfg_attr(test, derive(PartialEq))]
|
|
pub struct InitialEquipementList {
|
|
/// Inner List of final equipements
|
|
pub(super) inner: Vec<Equipement>,
|
|
}
|
|
|
|
/// The final equipement, obtained by combining all parts
|
|
#[derive(Clone, Debug)]
|
|
#[cfg_attr(test, derive(PartialEq))]
|
|
pub struct Equipement {
|
|
/// The inner stats used by the equipement
|
|
pub(super) stats: InnerEquipementStats,
|
|
/// The filter, used to determine if adding is warranted
|
|
pub(super) filter_function: FilterFunction<InnerEquipementStats>,
|
|
}
|
|
|
|
impl Default for Equipement {
|
|
fn default() -> Self {
|
|
Self {
|
|
filter_function: FilterFunction::new(default_filter()),
|
|
stats: InnerEquipementStats::random_new(),
|
|
}
|
|
}
|
|
}
|
|
|
|
/// The default filter to use, usefull to implement a new filter function that also uses the default filter
|
|
pub(crate) fn default_filter()
|
|
-> &'static impl Fn(&InnerEquipementStats, &InnerEquipementStats) -> bool {
|
|
&|self_, lhs| !self_.id.iter().any(|a| *a == lhs.id[0])
|
|
}
|
|
|
|
impl<T> FilterFunction<T> {
|
|
/// Generate a new filter
|
|
// TODO: This static lifetime is basically telling us that an owned value is needed
|
|
pub fn new(filter: &'static FilterFunctionType<T>) -> Self {
|
|
Self(Box::new(Rc::new(filter)))
|
|
}
|
|
}
|
|
/// 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, FieldsAsSlice, Debug)]
|
|
#[cfg_attr(test, derive(PartialEq))]
|
|
pub struct InnerEquipementStats {
|
|
pub id: Vec<u8>,
|
|
pub name: Vec<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: i8,
|
|
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) target: 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,
|
|
}
|
|
|
|
// TODO: This implementation of default is painfull
|
|
// TODO: Have either an auto-macro implementation or a manual one
|
|
// TODO: This implementation is Quasi-redondant
|
|
// TODO: Have a way to limit code duplication
|
|
#[allow(clippy::missing_docs_in_private_items, missing_docs)]
|
|
#[derive(Clone, FieldsAsSlice, Debug, Deserialize, Serialize)]
|
|
#[cfg_attr(test, derive(PartialEq))]
|
|
pub struct DatabaseEquipementStats {
|
|
#[INTEGER]
|
|
pub id: u8,
|
|
pub meta_category: String,
|
|
pub name: String,
|
|
#[INTEGER]
|
|
pub rarity: u8,
|
|
#[INTEGER]
|
|
pub cost: u8,
|
|
#[INTEGER]
|
|
pub difficulty: u8,
|
|
#[INTEGER]
|
|
pub tier: u8,
|
|
#[INTEGER]
|
|
pub damage: u8,
|
|
#[INTEGER]
|
|
pub p_damage: u8,
|
|
#[INTEGER]
|
|
pub precision: i8,
|
|
#[INTEGER]
|
|
pub rmax: u8,
|
|
#[INTEGER]
|
|
pub armor_break: u8,
|
|
#[INTEGER]
|
|
pub armor_pierce: u8,
|
|
#[INTEGER]
|
|
pub antimaterial: u8,
|
|
pub damage_type: String,
|
|
#[INTEGER]
|
|
pub protection: u8,
|
|
#[INTEGER]
|
|
pub integrity: u8,
|
|
#[INTEGER]
|
|
pub torque_two_handed: u8,
|
|
#[INTEGER]
|
|
pub torque_one_handed: u8,
|
|
#[INTEGER]
|
|
pub dodge: u8,
|
|
#[INTEGER]
|
|
pub parry: u8,
|
|
#[INTEGER]
|
|
pub speed: u8,
|
|
#[INTEGER]
|
|
pub stealth: u8,
|
|
pub category: String,
|
|
pub target: String,
|
|
pub special: String,
|
|
#[INTEGER]
|
|
pub action_cost: u8,
|
|
pub reload_cost: String,
|
|
#[INTEGER]
|
|
pub range: u8,
|
|
#[INTEGER]
|
|
pub agility_bonus: u8,
|
|
}
|
|
|
|
impl Default for DatabaseEquipementStats {
|
|
fn default() -> Self {
|
|
Self {
|
|
id: 0,
|
|
meta_category: "EqShape".to_string(),
|
|
name: String::new(),
|
|
damage_type: serde_json::to_string(&None::<DamageType>).unwrap(),
|
|
category: serde_json::to_string(&None::<WeaponCategory>).unwrap(),
|
|
target: serde_json::to_string(&None::<WeaponCategory>).unwrap(),
|
|
special: serde_json::to_string(&SpecialCategory::default()).unwrap(),
|
|
reload_cost: serde_json::to_string(&None::<u8>).unwrap(),
|
|
rarity: 0,
|
|
cost: 0,
|
|
difficulty: 0,
|
|
tier: 0,
|
|
damage: 0,
|
|
p_damage: 0,
|
|
precision: 0,
|
|
rmax: 0,
|
|
armor_break: 0,
|
|
armor_pierce: 0,
|
|
antimaterial: 0,
|
|
protection: 0,
|
|
integrity: 0,
|
|
torque_two_handed: 0,
|
|
torque_one_handed: 0,
|
|
dodge: 0,
|
|
parry: 0,
|
|
speed: 0,
|
|
stealth: 0,
|
|
range: 0,
|
|
agility_bonus: 0,
|
|
action_cost: 0,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
/// A manually implemented hashmap of all values
|
|
#[doc(hidden)]
|
|
macro_rules! r {
|
|
() => {
|
|
fastrand::u8(1..u8::MAX)
|
|
};
|
|
}
|
|
// TODO: Make this a test requirement or hide it behind a profile
|
|
impl InnerEquipementStats {
|
|
/// Testing function to fuzz data
|
|
pub fn random_new() -> Self {
|
|
Self {
|
|
id: vec![r!()],
|
|
range: r!(),
|
|
damage: r!(),
|
|
p_damage: r!(),
|
|
protection: r!(),
|
|
..Default::default()
|
|
}
|
|
}
|
|
}
|
|
// TODO: Make this a test requirement or hide it behind a profile
|
|
impl DatabaseEquipementStats {
|
|
/// Testing function to fuzz data
|
|
pub fn random_new() -> Self {
|
|
Self {
|
|
id: r!(),
|
|
range: r!(),
|
|
damage: r!(),
|
|
p_damage: r!(),
|
|
protection: r!(),
|
|
..Default::default()
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Shape of the equipement, first mandatory part of an equipement
|
|
#[derive(Default)]
|
|
pub struct EqShape {
|
|
/// The inner stats of the part
|
|
pub(super) stats: InnerEquipementStats,
|
|
}
|
|
|
|
/// Material used for the equipement, all equipements are crafted with 1-2 materials
|
|
#[derive(Default)]
|
|
pub struct EqMaterial {
|
|
/// The inner stats of the part
|
|
pub(super) stats: InnerEquipementStats,
|
|
}
|
|
|
|
/// 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
|
|
#[derive(Default)]
|
|
pub struct EqNature {
|
|
/// The inner stats of the part
|
|
pub(super) stats: InnerEquipementStats,
|
|
}
|
|
|
|
/// Finishing touches, since all of them have a cost, they are treated in a special fashion
|
|
#[derive(Default)]
|
|
pub struct EqFinishing {
|
|
/// The inner stats of the part
|
|
pub(super) stats: InnerEquipementStats,
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod test {
|
|
use super::{
|
|
EqFinishing, EqMaterial, EqNature, EqShape, Equipement, InitialEquipementList,
|
|
InnerEquipementStats,
|
|
};
|
|
use crate::interfaces::RecipeCollection;
|
|
|
|
fn list_equip() -> Vec<Equipement> {
|
|
(0..10)
|
|
.map(|_| Equipement {
|
|
..Default::default()
|
|
})
|
|
.collect::<Vec<_>>()
|
|
}
|
|
|
|
#[test]
|
|
fn test_struct_creation() {
|
|
let _stats = InnerEquipementStats::default();
|
|
let _eq1 = Equipement {
|
|
..Default::default()
|
|
};
|
|
|
|
let _list_eq = list_equip();
|
|
}
|
|
|
|
#[test]
|
|
fn test_creating_all_equipements() {
|
|
let shape = vec![EqShape::default().into(), EqShape::default().into()];
|
|
let nature = vec![EqNature::default().into(), EqNature::default().into()];
|
|
let material = vec![EqMaterial::default().into(), EqMaterial::default().into()];
|
|
let finishing = vec![EqFinishing::default().into(), EqMaterial::default().into()];
|
|
|
|
let mut leq = InitialEquipementList::from_vectored(shape);
|
|
leq.combine_all(&InitialEquipementList::from_vectored(nature));
|
|
leq.combine_all(&InitialEquipementList::from_vectored(material));
|
|
leq.combine_all(&InitialEquipementList::from_vectored(finishing));
|
|
}
|
|
|
|
#[ignore]
|
|
#[test]
|
|
fn test_default_behaviour() {
|
|
unimplemented!()
|
|
}
|
|
}
|