From 41fead32a48ff1952e9fb83c60ad03695bf4c386 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Fri, 24 Jul 2026 20:20:19 +0200 Subject: [PATCH] Progress on the balancer --- crates/config/src/monsters.rs | 10 +++ crates/monsters/src/monster_analysis.rs | 104 ++++++++++++++++++----- crates/monsters/src/monster_database.rs | 2 +- crates/monsters/src/monster_render.rs | 107 ++++++++++++++++-------- crates/monsters/src/monster_structs.rs | 6 +- ravenous_databases | 2 +- 6 files changed, 171 insertions(+), 60 deletions(-) diff --git a/crates/config/src/monsters.rs b/crates/config/src/monsters.rs index cb3fd6c..6f94eaa 100644 --- a/crates/config/src/monsters.rs +++ b/crates/config/src/monsters.rs @@ -37,6 +37,16 @@ pub struct MonsterConfig { // /// Clean all the artefacts (including generated images) // #[arg(short, long)] // pub all: bool, + /// Show extra balancing data + #[arg(long, default_value_t = false)] + pub show_extra: bool, + + /// Show extra balancing data + #[arg(long, default_value_t = false)] + pub show_profiles: bool, + // /// Defense profile + // #[arg(long, default_value_t=DefenseMode::Best)] + // pub defense_mode: DefenseMode, } #[derive(ValueEnum, Debug, Clone)] diff --git a/crates/monsters/src/monster_analysis.rs b/crates/monsters/src/monster_analysis.rs index 0629898..2927870 100644 --- a/crates/monsters/src/monster_analysis.rs +++ b/crates/monsters/src/monster_analysis.rs @@ -6,12 +6,15 @@ use crate::{ monster_analysis::monster_analysis_structs::{ArmorBreakCategory, DamageCategory}, monster_database::{fetch_all_creature_data, fetch_all_player_data}, monster_render::ToTable, - monster_structs::PlayerBalancing, + monster_structs::{PlayerBalancing, ProfileStance}, }; use more_fields::FieldsAsSlice; -use probability::distribution::Discrete; -use probability::prelude::Binomial; -use std::cmp::{max, min}; +use probability::{distribution::Discrete, prelude::Binomial}; +use std::{ + cmp::{max, min}, + collections::HashMap, +}; +use strum::Display; pub mod monster_analysis_structs; /// Shows balancing information for monsters and players. @@ -35,38 +38,82 @@ pub fn show_balancing_data( .filter(|v| &v.profile_hse == player_level) .collect::>(); - // TODO: This doen't dynamically select profiles ! - let profile_a = &available_profiles[0]; - let attacks: Vec = creature.into(); - // let table = attacks.to_table(); - // println!("{table}"); - - let mut res = Vec::new(); - for attack in attacks { - let report = attack_player(&attack, profile_a, DefenseMode::Best).unwrap(); - res.push(report); - } - let res = res + let profiles: HashMap = available_profiles .into_iter() - .filter(|v| { - v.damage_category != v.damage_expected || v.armor_expected != v.armor_category - }) - .collect::>(); - println!("{}", res.to_table()); + .map(|profile| (profile.profile_stance, profile)) + .collect(); + + display_monster_attacks(args, creature, profiles); } - // println!("{table}"); Ok(()) } -#[derive(Debug)] + +fn display_monster_attacks( + args: &MonsterConfig, + creature: crate::monster_structs::FullMonster, + profiles: HashMap, +) { + let attacks: Vec = creature.into(); + if args.show_profiles { + let table = attacks.to_table(); + println!("{table}"); + } + + let mut res = Vec::new(); + for attack in attacks { + let mut report = all_attacks(args, &attack, &profiles, DefenseMode::Best); + res.append(&mut report); + } + println!("{}", res.to_table()); +} + +#[derive(Debug, Copy, Clone, Display)] pub enum DefenseMode { Best, Worst, } +/// Returns the Balancing profile, and eventually the other profiles as well +pub fn all_attacks( + args: &MonsterConfig, + attack: &monster_analysis_structs::MonsterBalancingAttack, + victims: &HashMap, + mode: DefenseMode, +) -> Vec { + let mut balancing = vec![ + attack_player( + attack, + &victims[&attack.target_stance], + mode, + Showcase::Balancing, + ) + .unwrap(), + ]; + // Filter + if balancing[0].damage_category == attack.target_damage + && balancing[0].armor_category == attack.target_ab + { + return Vec::new(); + } + if !args.show_extra { + return balancing; + } + let mut v = victims + .iter() + .filter(|&(stance, _)| *stance != attack.target_stance) // keep only non‑targets + .map(|(_, victim)| attack_player(attack, victim, mode, Showcase::Display)) + .collect::>>() + .unwrap(); + + balancing.append(&mut v); + balancing +} + pub fn attack_player( attack: &monster_analysis_structs::MonsterBalancingAttack, victim: &PlayerBalancing, mode: DefenseMode, + showcase: Showcase, ) -> Option { // How much successes left let threshold = match mode { @@ -120,6 +167,8 @@ pub fn attack_player( threshold, attack_successes: attack.successes, mode, + showcase, + stance: victim.profile_stance, }; Some(report) } @@ -169,9 +218,18 @@ pub struct DamageReport { #[SKIP] pub mode: DefenseMode, #[SKIP] + pub stance: ProfileStance, + #[SKIP] pub attack_successes: i64, + #[SKIP] + pub showcase: Showcase, } +#[derive(Debug, Clone, Copy)] +pub enum Showcase { + Display, + Balancing, +} impl DamageCategory { fn from_percent(percent: f64) -> Self { match percent { diff --git a/crates/monsters/src/monster_database.rs b/crates/monsters/src/monster_database.rs index 35bdfa8..c7de0cd 100644 --- a/crates/monsters/src/monster_database.rs +++ b/crates/monsters/src/monster_database.rs @@ -36,7 +36,7 @@ pub(crate) fn fetch_all_creature_data( let list_creatures = generic_deserialize::( connection, "creature", - Some("show_to_master=1"), + Some("show_to_master=1 AND (id<5)"), Some("id"), )?; let mut finished_creatures = Vec::new(); diff --git a/crates/monsters/src/monster_render.rs b/crates/monsters/src/monster_render.rs index 7bb0d5c..eb55b10 100644 --- a/crates/monsters/src/monster_render.rs +++ b/crates/monsters/src/monster_render.rs @@ -2,7 +2,7 @@ use comfy_table::{Color, Table, *}; use crate::{ monster_analysis::{ - DamageReport, + DamageReport, Showcase, monster_analysis_structs::{ArmorBreakCategory, DamageCategory, MonsterBalancingAttack}, }, monster_structs::{PlayerBalancing, ProfileHSE, ProfileStance}, @@ -70,44 +70,85 @@ impl ToRow for PlayerBalancing { .into() } } + +// macro_rules! show_if { +// ($self:ident, $content:expr) => {{ +// match $self.showcase { +// Showcase::Display => String::new().to_cell(), +// Showcase::Balancing => $content, +// } +// }}; +// } +macro_rules! dim_if_not { + ($self:ident, $content:expr) => {{ + match $self.showcase { + Showcase::Display => $content + // .add_attribute(Attribute::Dim) + .add_attribute(Attribute::NoReverse), + // .fg(Color::DarkGrey) + Showcase::Balancing => $content, + } + }}; +} impl ToRow for DamageReport { fn to_row(&self) -> Row { vec![ - self.name.to_cell().fg(Color::Green), - format!( - "{:.1} [{:.1}r]", - self.damage_incoming, self.attack_successes, - ) - .to_cell(), - format!("{:.1} [>{:.1}]", self.successes_left, self.threshold) + match self.showcase { + Showcase::Balancing => self.name.to_cell().fg(Color::Green), + Showcase::Display => self.stance.to_string().to_cell().fg(Color::DarkGrey), + }, + dim_if_not!( + self, + format!( + "{:.1} [{:.1}r]", + self.damage_incoming, self.attack_successes, + ) .to_cell() - .fg(if self.successes_left > 0.0 { - Color::Blue - } else { - Color::Red - }), - format!("{:.1}/{:.1}", self.damage_tanked, self.player_health) - .to_cell() - .fg(self.damage_category.get_color()), - self.damage_category.to_cell().add_attribute( - if self.damage_expected != self.damage_category { - Attribute::Reverse - } else { - Attribute::Dim - }, ), - self.damage_expected.to_cell(), - format!("{:.1}/{:.1}", self.armor_loss, self.player_integrity) - .to_cell() - .fg(self.armor_category.get_color()), - self.armor_category.to_cell().add_attribute( - if self.armor_expected != self.armor_category { - Attribute::Reverse - } else { - Attribute::Dim - }, + dim_if_not!( + self, + format!("{:.1} [>{:.1}]", self.successes_left, self.threshold) + .to_cell() + .fg(if self.successes_left > 0.0 { + Color::Blue + } else { + Color::Red + }) ), - self.armor_expected.to_cell(), + dim_if_not!( + self, + format!("{:.1}/{:.1}", self.damage_tanked, self.player_health) + .to_cell() + .fg(self.damage_category.get_color()) + ), + dim_if_not!( + self, + self.damage_category.to_cell().add_attribute( + if self.damage_expected != self.damage_category { + Attribute::Reverse + } else { + Attribute::Dim + }, + ) + ), + dim_if_not!(self, self.damage_expected.to_cell()), + dim_if_not!( + self, + format!("{:.1}/{:.1}", self.armor_loss, self.player_integrity) + .to_cell() + .fg(self.armor_category.get_color()) + ), + dim_if_not!( + self, + self.armor_category.to_cell().add_attribute( + if self.armor_expected != self.armor_category { + Attribute::Reverse + } else { + Attribute::Dim + }, + ) + ), + dim_if_not!(self, self.armor_expected.to_cell()), ] .into() } diff --git a/crates/monsters/src/monster_structs.rs b/crates/monsters/src/monster_structs.rs index a20ad99..7c2015c 100644 --- a/crates/monsters/src/monster_structs.rs +++ b/crates/monsters/src/monster_structs.rs @@ -15,7 +15,7 @@ use indexmap::IndexMap; use more_fields::FieldsAsSlice; use serde::{Deserialize, Serialize}; -use strum::EnumString; +use strum::{Display, EnumString}; /// Full data, including monster_data & balancing data pub struct FullData {} @@ -476,7 +476,9 @@ pub struct PlayerBalancing { pub specialty_def: i64, } -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default, EnumString)] +#[derive( + Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default, EnumString, Hash, Display, +)] /// Player stance preference used for balance tables. pub enum ProfileStance { Defensive, diff --git a/ravenous_databases b/ravenous_databases index abacba0..521c7f3 160000 --- a/ravenous_databases +++ b/ravenous_databases @@ -1 +1 @@ -Subproject commit abacba00c4b888241d47bfb2621322d5586f77d4 +Subproject commit 521c7f3cad4417ec340b6a4d0dbaea92944daa4c