From 1311c7c7c020c9f2ab484f749f93580ee344db5b Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Mon, 10 Feb 2025 20:11:34 +0100 Subject: [PATCH] Workflow and mock --- weaponry/Cargo.toml | 1 + weaponry/src/strategy.rs | 87 +++++++++++++++++++++++ weaponry/src/weaponry_structs.rs | 116 ++++++++++++++++++++++++++++--- weaponry/workflow.md | 18 +++++ 4 files changed, 211 insertions(+), 11 deletions(-) create mode 100644 weaponry/workflow.md diff --git a/weaponry/Cargo.toml b/weaponry/Cargo.toml index b1036d5..84ccf64 100644 --- a/weaponry/Cargo.toml +++ b/weaponry/Cargo.toml @@ -4,3 +4,4 @@ version = "0.1.0" edition = "2024" [dependencies] +rayon = "1.10.0" diff --git a/weaponry/src/strategy.rs b/weaponry/src/strategy.rs index 617b4ef..15c8c97 100644 --- a/weaponry/src/strategy.rs +++ b/weaponry/src/strategy.rs @@ -4,3 +4,90 @@ //! //! These strategies can lock a parameter to allow a more fine tuned balancing //! or balancing specifically one parameter (balancing materials, balencing finishes etc..) +//! These strategies must take into account the level of the fighter (hence his precision) and of the craftsman (hence a difficulty diminution) +//! +#![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 + GenerateAll, + /// Generate all the named equipements + GenerateNamed, + /// Do not add finishing touches + NoFinishes, +} + +/// Which material to select +pub enum MaterialsStrategy { + /// Add all materials to the mix + AllMaterials, + /// Add only tier one material + OnlyTier1, + /// Add only easy materials + OnlyEasy, + /// Add only cheap materials + OnlyCheap, + /// Add only one material + OnlyOne, +} + +/// Filter to apply after the generation +pub enum EquipementFilter { + /// Don't filter anything + All, + /// Filter all outliers + Outiliers, + /// Filter in all the named + Named, +} + +// /// D +// struct Gen +// where +// T: Send, +// { +// /// E +// elem: Vec, +// } + +// impl ParallelIterator for Gen { +// type Item = T; + +// fn drive_unindexed(self, consumer: C) -> C::Result +// where +// C: rayon::iter::plumbing::UnindexedConsumer, +// { +// let _ = consumer; +// todo!() +// } +// } +// /// Default full generation strategy +// pub fn default_generation() -> impl ParallelIterator { +// Gen:: { elem: Vec::new() } +// } +/// Default full generation strategy +pub fn default_generation(a: Vec, b: Vec) -> Vec<(T, T)> { + a.iter() + .flat_map(|e| { + b.iter() + .map(|f| ((e.clone()), (f.clone()))) + .collect::>() + }) + // .collect::>>() + // .flatten() + .collect() +} + +#[cfg(test)] +mod test { + use super::*; + #[test] + fn test_creator() { + let t = default_generation(vec![1, 2, 3], vec![5, 6, 7]); + println!("{:?}", t); + panic!() + } +} diff --git a/weaponry/src/weaponry_structs.rs b/weaponry/src/weaponry_structs.rs index e10f106..6589178 100644 --- a/weaponry/src/weaponry_structs.rs +++ b/weaponry/src/weaponry_structs.rs @@ -5,8 +5,36 @@ #![allow(dead_code)] /// The inner statistics of the equipement, used across all parts and final weapon -#[derive(Default)] -pub struct InnerStats {} +// #[derive(Default)] +#[allow(clippy::missing_docs_in_private_items)] +pub struct InnerStats { + 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, + two_handed: u8, + one_handed: u8, + dodge: u8, + parry: u8, + speed: u8, + stealth: u8, + category: WeaponCategory, + special: Vec, + action_cost: u8, + reload_cost: u8, + range: u8, + agility_bonus: u8, +} /// The final equipement, obtained by combining all parts pub struct Equipement { @@ -52,21 +80,87 @@ pub enum NatureTarget { Armor, } -/// Weapon damage types +/// Enum of all different physical weapon damage types #[allow(clippy::missing_docs_in_private_items)] -pub enum SingleDamageType { +pub enum PhysicalDamageType { Blunt, Slash, Pierce, } -/// Weapon damage, signifying wether the damage is pure or [secondary] or [[tertiary]] -#[allow(clippy::missing_docs_in_private_items)] -pub enum DamageMod { - Primary(SingleDamageType), - Secondary(SingleDamageType), - Tertiary(SingleDamageType), +impl From<&str> for PhysicalDamageType { + fn from(value: &str) -> Self { + let _ = value; + // Matchcase for all damage types + todo!() + } } -/// Damage values, meant to be serialised to tex and deserialized directly from the table +/// 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); + +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() {} +} diff --git a/weaponry/workflow.md b/weaponry/workflow.md new file mode 100644 index 0000000..1fc616a --- /dev/null +++ b/weaponry/workflow.md @@ -0,0 +1,18 @@ +# Workflow + A B C +Database -> -> -> Balancing data + -> Exported data + +# Description + - A : Use structs defines in weaponry_structs + : impl From for all weapon parts + - B : Every part can be converted to a weapon(ish) + : Use the correct solver to add all parts + - C1 : Use the traits to generate the tex data + + +# Strategy +Since the structs will become more than just weapons but will become craft afterwards, polymorphism is the key + +The creation algorithm will pick a Strategy depending on the user's choice and build a final weapon depending on it +The creation will implement an iterator to go with itertools / rayon ? -- 2.45.1