Balancing & some display features #170

Merged
Dandaedre merged 1 commits from database_monsters into main 2026-07-30 04:04:26 +02:00
7 changed files with 37 additions and 19 deletions

View File

@ -3,6 +3,7 @@
use comfy_table::modifiers;
use config::monsters::BalanceArgs;
use indexmap::IndexMap;
use crate::{
Config, Connection,
@ -12,9 +13,8 @@ use crate::{
monster_structs::{PlayerBalancing, ProfileStance},
};
pub mod attack_analysis;
pub mod helpers;
use std::collections::HashMap;
pub mod defense_analysis;
pub mod helpers;
pub mod monster_analysis_structs;
/// Shows balancing information for monsters and players.
@ -53,7 +53,7 @@ pub fn show_balancing_data(
.filter(|v| &v.profile_hse == player_level)
.collect::<Vec<PlayerBalancing>>();
let profiles: HashMap<ProfileStance, PlayerBalancing> = available_profiles
let profiles: IndexMap<ProfileStance, PlayerBalancing> = available_profiles
.into_iter()
.map(|profile| (profile.profile_stance, profile))
.collect();

View File

@ -8,15 +8,15 @@ use crate::{
monster_structs::{PlayerBalancing, ProfileStance},
};
use config::monsters::BalanceArgs;
use indexmap::IndexMap;
use more_fields::FieldsAsSlice;
use std::cmp::max;
use std::collections::HashMap;
/// Returns the Balancing profile, and eventually the other profiles as well
pub fn all_attacks(
args: &BalanceArgs,
attack: &monster_analysis_structs::MonsterBalancingAttack,
victims: &HashMap<ProfileStance, PlayerBalancing>,
victims: &IndexMap<ProfileStance, PlayerBalancing>,
mode: DefenseMode,
) -> Vec<DamageReport> {
let mut balancing = vec![

View File

@ -8,13 +8,14 @@ use crate::{
monster_structs::{CreatureBodyPart, FullMonster, PlayerBalancing, ProfileHSE, ProfileStance},
};
use config::monsters::BalanceArgs;
use indexmap::IndexMap;
use more_fields::FieldsAsSlice;
use std::{collections::HashMap, ops::AddAssign};
use std::ops::AddAssign;
pub(crate) fn display_player_attacks(
args: &BalanceArgs,
creature: &FullMonster,
profiles: &HashMap<ProfileStance, PlayerBalancing>,
profiles: &IndexMap<ProfileStance, PlayerBalancing>,
mode: DefenseMode,
) {
let _ = mode;
@ -25,7 +26,7 @@ pub(crate) fn display_player_attacks(
fn report_from_profile(
args: &BalanceArgs,
creature: &FullMonster,
profiles: &HashMap<ProfileStance, PlayerBalancing>,
profiles: &IndexMap<ProfileStance, PlayerBalancing>,
) -> Vec<DefenseReport> {
creature
.body_parts
@ -405,7 +406,7 @@ pub struct DefenseReport {
pub(crate) fn display_monster_attacks(
args: &BalanceArgs,
creature: FullMonster,
profiles: &HashMap<ProfileStance, PlayerBalancing>,
profiles: &IndexMap<ProfileStance, PlayerBalancing>,
mode: DefenseMode,
) {
let attacks: Vec<monster_analysis_structs::MonsterBalancingAttack> = creature.into();

View File

@ -34,7 +34,7 @@ pub(crate) fn fetch_all_creature_data(
filter: Option<&str>,
) -> Result<Vec<FullMonster>, anyhow::Error> {
let list_creatures =
generic_deserialize::<CreatureData>(connection, "creature", filter, Some("id"))?;
generic_deserialize::<CreatureData>(connection, "creature", filter, Some("sort_id"))?;
let mut finished_creatures = Vec::new();
for creature in list_creatures.iter() {
// println!("Working on {}@{}", creature.id, creature.name);

View File

@ -96,6 +96,17 @@ macro_rules! dim_if_not {
}
}};
}
macro_rules! attr_if_not {
($self:ident, $content:expr, $attribute:expr) => {{
match $self.showcase {
Showcase::Display => $content
// .add_attribute(Attribute::Dim)
.add_attribute($attribute),
// .fg(Color::DarkGrey)
Showcase::Balancing => $content,
}
}};
}
impl ToRow for DamageReport {
fn to_row(&self) -> Row {
vec![
@ -111,12 +122,16 @@ impl ToRow for DamageReport {
)
.to_cell()
),
format!("{}", self.fatigue,)
.to_cell()
.add_attribute(match self.fatigue == 0 {
true => Attribute::Hidden,
false => Attribute::NoHidden,
}),
attr_if_not!(
self,
format!("{}", self.fatigue,)
.to_cell()
.add_attribute(match self.fatigue == 0 {
true => Attribute::Hidden,
false => Attribute::NoHidden,
}),
Attribute::Hidden
),
dim_if_not!(
self,
format!("{:.1} [>{:.1}]", self.successes_left, self.threshold)
@ -143,7 +158,7 @@ impl ToRow for DamageReport {
},
)
),
dim_if_not!(self, self.damage_expected.to_cell()),
attr_if_not!(self, self.damage_expected.to_cell(), Attribute::Hidden),
dim_if_not!(
self,
format!("{:.1}/{:.1}", self.armor_loss, self.player_integrity)
@ -160,7 +175,7 @@ impl ToRow for DamageReport {
},
)
),
dim_if_not!(self, self.armor_expected.to_cell()),
attr_if_not!(self, self.armor_expected.to_cell(), Attribute::Hidden),
]
.into()
}
@ -240,6 +255,7 @@ impl ToCell for ProfileStance {
ProfileStance::Defensive => Into::<Cell>::into(format!("{self:?}")).fg(Color::Blue),
ProfileStance::Offensive => Into::<Cell>::into(format!("{self:?}")).fg(Color::Red),
ProfileStance::Neutral => Into::<Cell>::into(format!("{self:?}")).fg(Color::Yellow),
ProfileStance::NoDefense => Into::<Cell>::into(format!("{self:?}")).fg(Color::DarkRed),
}
}
}

View File

@ -498,6 +498,7 @@ pub struct PlayerBalancing {
pub enum ProfileStance {
Defensive,
Offensive,
NoDefense,
#[default]
Neutral,
}

@ -1 +1 @@
Subproject commit 100d805aa2741d86d8fefa2d4916ff398a1a9fcc
Subproject commit d259078b51caee4ddfc9e1f0f44a82451a82ea18