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

213 lines
6.0 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, Deserialize, Serialize)]
#[cfg_attr(test, derive(PartialEq))]
pub struct InnerEquipementStats {
#[INTEGER]
pub id: Vec<u8>,
pub name: Vec<String>,
#[INTEGER]
pub(super) rarity: u8,
#[INTEGER]
pub(super) cost: u8,
#[INTEGER]
pub(super) difficulty: u8,
#[INTEGER]
pub(super) tier: u8,
#[INTEGER]
pub(super) damage: u8,
#[INTEGER]
pub(super) p_damage: u8,
#[INTEGER]
pub(super) precision: i8,
#[INTEGER]
pub(super) rmax: u8,
#[INTEGER]
pub(super) armor_break: u8,
#[INTEGER]
pub(super) armor_pierce: u8,
#[INTEGER]
pub(super) antimaterial: u8,
pub(super) damage_type: Option<DamageType>,
#[INTEGER]
pub(super) protection: u8,
#[INTEGER]
pub(super) integrity: u8,
#[INTEGER]
pub(super) torque_two_handed: u8,
#[INTEGER]
pub(super) torque_one_handed: u8,
#[INTEGER]
pub(super) dodge: u8,
#[INTEGER]
pub(super) parry: u8,
#[INTEGER]
pub(super) speed: u8,
#[INTEGER]
pub(super) stealth: u8,
pub(super) category: Option<WeaponCategory>,
pub(super) target: Option<WeaponCategory>,
pub(super) special: SpecialCategory,
#[INTEGER]
pub(super) action_cost: u8,
pub(super) reload_cost: Option<u8>,
#[INTEGER]
pub(super) range: u8,
#[INTEGER]
pub(super) agility_bonus: u8,
}
#[allow(dead_code)]
/// A manually implemented hashmap of all values
#[doc(hidden)]
macro_rules! r {
() => {
fastrand::u8(1..10)
};
}
// 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()
}
}
}
/// 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!()
}
}