From f659bebc9a23883674acc19be8eeafa57c4288b7 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Thu, 23 Jul 2026 06:17:59 +0200 Subject: [PATCH] Adds a basis for analysis --- Cargo.toml | 2 +- badges/testmonster.tex | 113 ----------------------- crates/config/src/monsters.rs | 4 +- crates/monsters/Cargo.toml | 2 + crates/monsters/src/lib.rs | 6 +- crates/monsters/src/monster_analysis.rs | 43 +++++++++ crates/monsters/src/monster_database.rs | 116 +++++++++++++++--------- crates/monsters/src/monster_export.rs | 4 +- crates/monsters/src/monster_render.rs | 52 +++++++++++ crates/monsters/src/monster_structs.rs | 81 ++++++++++++++++- 10 files changed, 260 insertions(+), 163 deletions(-) delete mode 100644 badges/testmonster.tex create mode 100644 crates/monsters/src/monster_analysis.rs create mode 100644 crates/monsters/src/monster_render.rs diff --git a/Cargo.toml b/Cargo.toml index 6769bcc..efd0cd8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ resolver = "3" # edition = "2024" # license = "MIT OR Apache-2.0" [workspace.package] -version = "0.3.12" +version = "0.3.13" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/badges/testmonster.tex b/badges/testmonster.tex deleted file mode 100644 index 002f688..0000000 --- a/badges/testmonster.tex +++ /dev/null @@ -1,113 +0,0 @@ -\begin{tblr}{ - vspan=even, hspan=minimal, - colspec={X[-1] X[-1]}, - cell{1}{1}={c=2}{c}, - } - -\includegraphics[height=5cm] ./bob.png & \\ -& \\ -Nom & Bobifron 3000 \\ -Dénomination & \\ -Calamité & Yanouïlle \\ -Niveau de danger (HSE) & 9001 \\ -& \\ -Habitat & \SetCell{font=\footnotesize} House \\ -Dysmorphisme & \SetCell{font=\footnotesize} \\ -Couleurs & \SetCell{font=\footnotesize} 7 \\ -Réaction à l'homme & \SetCell{font=\footnotesize} 8 \\ -Variantes & \SetCell{font=\footnotesize} 8\\ -Mœurs & \SetCell{font=\footnotesize} 9 \\ -\end{tblr} -\vfill -\begin{tblr}{ - colspec={X[-1]}, - hline{2,4,6}, - row{2,4,6}={font=\footnotesize} - } -\textbf{Description} \\ -9 \\ -\textbf{Annotations} \\ -8 \\ -\textbf{Récompenses} \\ -\end{tblr} -\begin{tblr}{ - colspec={X[-1] X[-1,c] X[-1,j]}, - vspan=even, hspan=minimal, - row{1-Z}={font=\footnotesize}, - rows={m}, -} - \SetCell[c=2]{j} Sang (base, combat, dépeçage) & & 10, 5, 5 \\ - Larewoard & Reward & 4\blood{}, 4\Tox. Gives much love. \\ -\end{tblr} -\vfill -\begin{tblr}{ - colspec={X[l,-1] X[-1] X[-1] X[] X[] X[-1] X[-1] X[] X[]}, - rowspec={X[t] X[t,c] X[c,2em] X[c,2em] X[c,2em] X[c,2em] X[c,2em] X[c,2em] X[c,2em] X[c,2em] X[c,2em] X[j,5em]}, - hspan=minimal, - cell{1}{2}={c=4}{c}, - cell{1}{6}={c=4}{c}, - row{2,12}={font=\footnotesize}, - vline{6} = {2-11}{solid}, -} - & P1 & & & & P2 & \\ - & Seuil & Prot & Intégrité & PV & Seuil & Prot & Intégrité & PV\\ -\hline -\SetCell{font=\footnotesize} VV & $1$ & $2$ & \SetCell{r,f}\tiny$3$ & \SetCell{r,f}\tiny$4$ & $5$ & $6$ & \SetCell{r,f}\tiny$7$ & \SetCell{r,f}\tiny$8$\\ \hline -\SetCell[c=9]{j,h} {\textbf{Notes} \\ \\ -\hline -\end{tblr} \center{ -\begin{tblr}{ - colspec={Q[3.5em] Q[1.6em] Q[1.6em] Q[1.6em] Q[1.6em] Q[1.6em] Q[1.6em] Q[1.6em] Q[1.6em] Q[1.6em] Q[1.6em] Q[1.6em] Q[1.6em]}, - rowspec={Q[c,f] Q[c,m] Q[c] Q[c] Q[c] Q[c] Q[c] Q[c] Q[c] Q[c] Q[c]}, - row{3-11}={font=\tiny}, -} - & & & & & & & \small{*} & & & & \small{*} & \small{*} & \\ -\SetCell{c} Res & \slash & \pierce & \blunt & \symceleste & \symfire & \symearth & \symwood & \symmagma & \symabyss & \symwater & \symwind & \symice & \symthunder \\ -\hline - \SetCell{font=\footnotesize} & $9$ & $$ & $10$ & $12$ & $13$ & $15$ & $16$ & $14$ & $$ & $19$ & $18$ & $20$ & $21$ \\ - \end{tblr}\begin{tblr}{ - colspec={c c c c c c c c c c c c c c c c c c c}, - row{2}={font=\footnotesize}, - row{3-6}={font=\tiny}, -} - & \SetCell[c=2]{c} P1 & & \SetCell[c=2]{c} P2 & & & \SetCell[c=7]{c} Stats & & & & & & & & \SetCell[c=4]{c} Mouvement & & & & \\ - \cline{2-3} \cline{4-5} \cline{7-13} \cline{15-18} -\rb{Initiative} & \rb{Valeur} & \rb{Actions} & \rb{Valeur} & \rb{Actions} & & \rb{Force} & \rb{Perception} & \rb{Volonté} & \rb{Res Alt} & \rb{Torque} & \rb{Vigilance} & \rb{Fatigue} & & \rb{Marche} & \rb{Trot} & \rb{Course} & \rb{Vol} \\ -\SetCell{font=\footnotesize}$t_1$ & ${{p1_init}}$ & $4$A & ${{p2_init}}$ & $4$A & & ${{strength}}$ & ${{perception}}$ & ${{willpower}}$ & ${{alteration_resistance}}$ & ${{torque}}$ & ${{awareness}}$ & ${{fatigue}}$ & & ${{mvt_walk}}$ & ${{mvt_trot}}$ & ${{mvt_run}}$ & ${{mvt_flight}}$ \\ -\begin{tblr}{ - colspec={c c c c c c c c c c c c c c c c c c c}, - row{2}={font=\footnotesize}, - row{3-6}={font=\tiny}, -} - & \SetCell[c=2]{c} P1 & & \SetCell[c=2]{c} P2 & & & \SetCell[c=7]{c} Stats & & & & & & & & \SetCell[c=4]{c} Mouvement & & & & \\ - \cline{2-3} \cline{4-5} \cline{7-13} \cline{15-18} -\rb{Initiative} & \rb{Valeur} & \rb{Actions} & \rb{Valeur} & \rb{Actions} & & \rb{Force} & \rb{Perception} & \rb{Volonté} & \rb{Res Alt} & \rb{Torque} & \rb{Vigilance} & \rb{Fatigue} & & \rb{Marche} & \rb{Trot} & \rb{Course} & \rb{Vol} \\ -\SetCell{font=\footnotesize}$t_1$ & $500$ & $4$A & $22$ & $4$A & & $8$ & $6$ & $5$ & $4$ & $40$ & $6$ & $20$ & & $10$ & $20$ & $50$ & $0$ \\ -\SetCell{font=\footnotesize}$t_2$ & $10$ & & $12$ & 52A \\ -\SetCell{font=\footnotesize}$t_3$ & $5$ & & $2$ & 21A \\ -\scriptsize{ -\begin{tblr}{ - colspec={X[0.05] X[4,l] X[1,c] X[1,c] X[0.3,c] X[0.3,c] X[0.3,c] X[0.3,c] X[0.3,c] X[2,r] X[2,c] X[0.3,c] X[0.3,c]}, - hspan=minimal, - colsep=2pt, - row{2}={font=\tiny}, -} - & & & & & \SetCell[c=2]{c} Coûts & & & \SetCell[c=2]{c} Dégâts & & & \SetCell[c=2]{c} Seuils & \\ -\cline{6-7} \cline{9-10} \cline{12-13} -& \SetCell{c} & {ID} & {Type} & \rb{Ciblage} & \rb{Fatigue} & \rb{Action} & \rb{Élément} & \rb{Fatigue} & \SetCell{c} \rb{Normaux} & {Effets} & \rb{Parade} & \rb{Esquive} \\ -\SetHline{1-13}{solid} - \end{tblr} -} -\vfill -\renewcommand{\rb}{\undefined} - \begin{tblr}{ - colspec={X[7] X[3]}, - rowspec={X[c] X[j,h,8cm]}, - vline{2}, - hline{2}, - row{2}={font=\footnotesize}, -} -Plan de combat & Graphique d'intentions \\ -9 & 7 \\ -\end{tblr} -\vfill diff --git a/crates/config/src/monsters.rs b/crates/config/src/monsters.rs index 7de93cf..cb3fd6c 100644 --- a/crates/config/src/monsters.rs +++ b/crates/config/src/monsters.rs @@ -46,8 +46,8 @@ pub enum MonsterTarget { // Clean, /// Generate the monster list Export, - // /// Show useful data - // Show, + /// Balancing data + Balance, } /// Configuration data for generating a monster sheet. diff --git a/crates/monsters/Cargo.toml b/crates/monsters/Cargo.toml index 0eaa6d7..5af9f24 100644 --- a/crates/monsters/Cargo.toml +++ b/crates/monsters/Cargo.toml @@ -15,6 +15,8 @@ serde_rusqlite = {workspace = true} serde_json = {workspace = true} handlebars = {workspace = true} strum = { version = "0.28.0", features = ["derive"] } +comfy-table = "7.2.2" +colored = "3.1.1" [dev-dependencies] regex = {workspace = true} diff --git a/crates/monsters/src/lib.rs b/crates/monsters/src/lib.rs index e1af0f6..148f1cc 100644 --- a/crates/monsters/src/lib.rs +++ b/crates/monsters/src/lib.rs @@ -13,12 +13,15 @@ //! (`MonsterConfig`) and delegates to the appropriate sub‑routine (clean, export or show). //! -use crate::monster_export::generate_monsters_tex; +use crate::{monster_analysis::show_balancing_data, monster_export::generate_monsters_tex}; + use config::monsters::MonsterTarget; use anyhow::Context; +mod monster_analysis; mod monster_database; mod monster_export; +mod monster_render; pub mod monster_structs; use anyhow::Result; @@ -37,6 +40,7 @@ pub fn monsters_dispatch(args: &MonsterConfig, config: &Config) -> Result<()> { // MonsterTarget::Clean => unimplemented!("implement cleaning logic"), MonsterTarget::Export => generate_monsters_tex(args, config, connection)?, // MonsterTarget::Show => unimplemented!("implement show logic"), + MonsterTarget::Balance => show_balancing_data(args, config, connection)?, } Ok(()) } diff --git a/crates/monsters/src/monster_analysis.rs b/crates/monsters/src/monster_analysis.rs new file mode 100644 index 0000000..83656ed --- /dev/null +++ b/crates/monsters/src/monster_analysis.rs @@ -0,0 +1,43 @@ +//! Monster export module + +use crate::{ + Config, Connection, MonsterConfig, + monster_database::{fetch_all_creature_data, fetch_all_player_data}, + monster_render::ToRow, + monster_structs::PlayerBalancing, +}; +use comfy_table::presets::UTF8_FULL; +use comfy_table::*; +use more_fields::FieldsAsSlice; + +/// Shows balancing information for monsters and players. +pub fn show_balancing_data( + args: &MonsterConfig, + config: &Config, + connection: Connection, +) -> Result<(), anyhow::Error> { + let _ = args; + let _data = fetch_all_creature_data(&connection, config)?; + let player_data = fetch_all_player_data(&connection, config)?; + + let mut table = Table::new(); + table + .load_preset(UTF8_FULL) + .set_content_arrangement(ContentArrangement::Dynamic) + .set_width(120) + .set_header( + PlayerBalancing::attributes_slice() + .iter() + .map(|(a, _b)| Cell::new(a)), + ); + // table.add_row(player_data.as_slice()); + + for entry in player_data { + table.add_row(entry.to_row()); + } + // for creature in data { + // println!("{} {:#?}", creature.name, creature.balancing); + // } + println!("{table}"); + Ok(()) +} diff --git a/crates/monsters/src/monster_database.rs b/crates/monsters/src/monster_database.rs index e97901e..35bdfa8 100644 --- a/crates/monsters/src/monster_database.rs +++ b/crates/monsters/src/monster_database.rs @@ -1,12 +1,15 @@ #![allow(dead_code)] -use crate::monster_structs::{self, CreatureReward, MonsterAllAttacks, MonsterRepetableInitRow}; +use crate::monster_structs::{ + self, CreatureReward, MonsterAllAttacks, MonsterRepetableInitRow, PlayerBalancing, +}; use crate::monster_structs::{ CreatureBodyPart, CreatureData, CreatureListAttacks, CreatureStats, FullMonster, MonsterSingleAttack, }; use anyhow::{Context, anyhow}; use cli_parser::Config; +use more_fields::FieldsAsSlice; use rusqlite::Connection; use serde::de::DeserializeOwned; @@ -26,12 +29,12 @@ macro_rules! fetch_from { /// Fetch all data from the database // TODO: WARN the master filter is hardcoded here -pub(crate) fn fetch_all_data( - connection: Connection, +pub(crate) fn fetch_all_creature_data( + connection: &Connection, config: &Config, ) -> Result, anyhow::Error> { let list_creatures = generic_deserialize::( - &connection, + connection, "creature", Some("show_to_master=1"), Some("id"), @@ -39,39 +42,8 @@ pub(crate) fn fetch_all_data( let mut finished_creatures = Vec::new(); for creature in list_creatures.iter() { // println!("Working on {}@{}", creature.id, creature.name); - let creature_attacks = fetch_from!( - MonsterSingleAttack, - connection, - creature, - "creature_abilities", - Some("phase, attack_group, ordering") - ); - let creature_resistances = fetch_from!( - CreatureBodyPart, - connection, - creature, - "creature_body_parts", - None - ); - - let creature_stats = - fetch_from!(CreatureStats, connection, creature, "creature_stats", None); - if creature_stats.len() != 1 { - return Err(anyhow!( - "The stat line for the creature {} should be exactly one found {}", - creature.name, - creature_stats.len() - )); - }; - let creature_stats = creature_stats.first().unwrap().clone(); - - let creature_rewards = fetch_from!( - CreatureReward, - connection, - creature, - "creature_rewards", - None - ); + let creature_stats: CreatureStats = + fetch_one_field(connection, creature, "creature_stats")?; finished_creatures.push(FullMonster { id: creature.id, name: creature.name.clone(), @@ -81,23 +53,81 @@ pub(crate) fn fetch_all_data( &creature_stats.p1_actions, &creature_stats.p2_actions, ), - stats: creature_stats, - all_attacks: MonsterAllAttacks::from_retrieved_data(&creature_attacks, config), + stats: creature_stats, // fetch_one_field(connection, creature, "creature_stats")?, + all_attacks: MonsterAllAttacks::from_retrieved_data( + &fetch_from!( + MonsterSingleAttack, + connection, + creature, + "creature_abilities", + Some("phase, attack_group, ordering") + ), + config, + ), attacks: CreatureListAttacks { - attacks: creature_attacks, + attacks: fetch_from!( + MonsterSingleAttack, + connection, + creature, + "creature_abilities", + Some("phase, attack_group, ordering") + ), }, body_parts: monster_structs::CreatureListBodyParts { - body_parts: creature_resistances, + body_parts: fetch_from!( + CreatureBodyPart, + connection, + creature, + "creature_body_parts", + None + ), }, - data: creature.clone(), rewards: monster_structs::CreatureListRewards { - rewards: creature_rewards, + rewards: fetch_from!( + CreatureReward, + connection, + creature, + "creature_rewards", + None + ), }, + balancing: fetch_one_field(connection, creature, "creature_balancing")?, + data: creature.clone(), }); } Ok(finished_creatures) } +pub(crate) fn fetch_all_player_data( + connection: &Connection, + config: &Config, +) -> Result, anyhow::Error> { + let _ = config; + generic_deserialize::(connection, "player_balancing", None, None) +} + +/// Fetches **the single** row that matches `creature` from the given `table_name`. +/// +/// The query is performed through the `fetch_from!` macro, which returns a vector of +/// values deserialised into `T`. If the resulting vector does not contain exactly +/// one element an error is returned; otherwise the sole value is extracted. +fn fetch_one_field( + connection: &Connection, + creature: &CreatureData, + table_name: &str, +) -> Result { + let mut creature_stats = fetch_from!(T, connection, creature, table_name, None); + if creature_stats.len() != 1 { + return Err(anyhow!( + "The number of {} entries for the creature {} should be exactly one found {}", + table_name, + creature.name, + creature_stats.len() + )); + }; + Ok(creature_stats.pop().unwrap()) +} + /// A generic Deserialisation from a database fn generic_deserialize( connection: &Connection, diff --git a/crates/monsters/src/monster_export.rs b/crates/monsters/src/monster_export.rs index 2846ead..34010f0 100644 --- a/crates/monsters/src/monster_export.rs +++ b/crates/monsters/src/monster_export.rs @@ -8,7 +8,7 @@ use indexmap::IndexMap; use rusqlite::Connection; use std::{fmt::Write, fs::File, io::Write as OtherWrite}; -use crate::monster_database::fetch_all_data; +use crate::monster_database::fetch_all_creature_data; use crate::monster_structs::{MonsterAllAttacks, MonsterFullAttack, MonsterSingleAttack}; /// Load a template from a struct field into a `templates` collection. @@ -44,7 +44,7 @@ pub fn generate_monsters_tex( config: &Config, connection: Connection, ) -> std::result::Result<(), anyhow::Error> { - let all_monsters = fetch_all_data(connection, config)?; + let all_monsters = fetch_all_creature_data(&connection, config)?; let templates = load_templates(config)?; println!("Processing"); let mut m_out = String::new(); diff --git a/crates/monsters/src/monster_render.rs b/crates/monsters/src/monster_render.rs new file mode 100644 index 0000000..44c82c4 --- /dev/null +++ b/crates/monsters/src/monster_render.rs @@ -0,0 +1,52 @@ +use comfy_table::Color; +use comfy_table::{Cell, Row}; + +use crate::monster_structs::{PlayerBalancing, ProfileHSE, ProfileStance}; + +/// Handy trait: “give me the table row that represents this record” +pub trait ToCell { + fn to_cell(&self) -> Cell; +} + +pub trait ToRow { + fn to_row(&self) -> Row; +} + +impl ToRow for PlayerBalancing { + fn to_row(&self) -> Row { + vec![ + self.profile_hse.to_cell(), + self.profile_stance.to_cell(), + Cell::new(format!("{:?}", self.damage_per_s)), + Cell::new(format!("{:?}", self.successes)), + Cell::new(format!("{:?}", self.protection)), + Cell::new(format!("{:?}", self.strength)), + Cell::new(format!("{:?}", self.integrity)), + Cell::new(format!("{:?}", self.health)), + ] + .into() + } +} + +impl ToCell for ProfileHSE { + fn to_cell(&self) -> Cell { + match self { + ProfileHSE::Lowest => Into::::into(format!("{self:?}")).fg(Color::DarkRed), + ProfileHSE::Low => Into::::into(format!("{self:?}")).fg(Color::Red), + ProfileHSE::Mid => Into::::into(format!("{self:?}")).fg(Color::Yellow), + ProfileHSE::High => Into::::into(format!("{self:?}")).fg(Color::Green), + ProfileHSE::Highest => Into::::into(format!("{self:?}")).fg(Color::Blue), + ProfileHSE::HighestPlus => Into::::into(format!("{self:?}")).fg(Color::DarkBlue), + } + } +} + +impl ToCell for ProfileStance { + fn to_cell(&self) -> Cell { + match self { + ProfileStance::Defensive => Into::::into(format!("{self:?}")).fg(Color::Blue), + ProfileStance::Offensive => Into::::into(format!("{self:?}")).fg(Color::Red), + ProfileStance::Neutral => Into::::into(format!("{self:?}")).fg(Color::Yellow), + } + } +} diff --git a/crates/monsters/src/monster_structs.rs b/crates/monsters/src/monster_structs.rs index 160ed62..f008401 100644 --- a/crates/monsters/src/monster_structs.rs +++ b/crates/monsters/src/monster_structs.rs @@ -16,6 +16,9 @@ use indexmap::IndexMap; use more_fields::FieldsAsSlice; use serde::{Deserialize, Serialize}; +/// Full data, including monster_data & balancing data +pub struct FullData {} + /// A monster ready for consumption by other modules. /// /// This struct is extremely export centric @@ -47,6 +50,9 @@ pub struct FullMonster { /// Serialized stats directly copied from the database table. pub stats: CreatureStats, + + /// Serialized balancing data + pub balancing: CreatureBalancing, } /// One row from the `creature` table. @@ -350,7 +356,7 @@ pub struct GroupedResists { // } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, FieldsAsSlice)] -/// All creature stats +/// All creature stats used in combat calculations. pub struct CreatureStats { #[INTEGER] pub creature_id: i64, @@ -395,6 +401,79 @@ pub struct CreatureStats { #[INTEGER] pub blood_carve: i64, } +/// Balancing metadata for a creature. +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, FieldsAsSlice)] +pub struct CreatureBalancing { + #[INTEGER] + creature_id: i64, + #[TEXT] + /// (Fixed) HSE profile of the monster (see `ProfileHSE`). + profile_hse: ProfileHSE, + #[INTEGER] + /// (Goal) Turns needed to reach phase 2. + time_to_p2: i64, + #[INTEGER] + /// (Goal) Turns until the monster’s armor breaks. + time_to_armorbreak: i64, + #[INTEGER] + /// (GOAL) Avg. turns to kill a single target. + time_to_kill_avg: i64, + #[INTEGER] + /// (FIXED) Size of a single monster group (usually one). + monster_groupsize: i64, + #[INTEGER] + /// (FIXED) The number of players this fight was designed for + player_groupsize: i64, +} + +/// Balancing info on all the player depending on their level +/// +/// All this info is FIXED and calculated based on average game data +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, FieldsAsSlice)] +pub struct PlayerBalancing { + #[INTEGER] + /// HSE profile of the player (see `ProfileHSE`). + pub profile_hse: ProfileHSE, + #[INTEGER] + /// Stance used in this datapoint. + pub profile_stance: ProfileStance, + #[INTEGER] + /// Damage dealt per success. + pub damage_per_s: f64, + #[INTEGER] + /// Number of successes per round. + pub successes: i64, + #[INTEGER] + /// Amount of protection (e.g., armor) the player has. + pub protection: i64, + #[INTEGER] + /// Strength stat of the player. + pub strength: i64, + #[INTEGER] + /// Integrity / hit‑point reserve of the player. + pub integrity: i64, + #[INTEGER] + /// Current health points. + pub health: i64, +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +/// Player stance preference used for balance tables. +pub enum ProfileStance { + Defensive, + Offensive, + Neutral, +} +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +/// Hunter Star Equivalent (roughly level+skill) profile used throughout the system. +pub enum ProfileHSE { + Lowest, + Low, + Mid, + High, + Highest, + HighestPlus, +} // ----------- HERE BE WARCRIMES -------------