Progress on the balancer
This commit is contained in:
parent
264fadfdc8
commit
41fead32a4
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -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::<Vec<PlayerBalancing>>();
|
||||
|
||||
// TODO: This doen't dynamically select profiles !
|
||||
let profile_a = &available_profiles[0];
|
||||
let attacks: Vec<monster_analysis_structs::MonsterBalancingAttack> = 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<ProfileStance, PlayerBalancing> = available_profiles
|
||||
.into_iter()
|
||||
.filter(|v| {
|
||||
v.damage_category != v.damage_expected || v.armor_expected != v.armor_category
|
||||
})
|
||||
.collect::<Vec<DamageReport>>();
|
||||
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<ProfileStance, PlayerBalancing>,
|
||||
) {
|
||||
let attacks: Vec<monster_analysis_structs::MonsterBalancingAttack> = 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<ProfileStance, PlayerBalancing>,
|
||||
mode: DefenseMode,
|
||||
) -> Vec<DamageReport> {
|
||||
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::<Option<Vec<DamageReport>>>()
|
||||
.unwrap();
|
||||
|
||||
balancing.append(&mut v);
|
||||
balancing
|
||||
}
|
||||
|
||||
pub fn attack_player(
|
||||
attack: &monster_analysis_structs::MonsterBalancingAttack,
|
||||
victim: &PlayerBalancing,
|
||||
mode: DefenseMode,
|
||||
showcase: Showcase,
|
||||
) -> Option<DamageReport> {
|
||||
// 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 {
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ pub(crate) fn fetch_all_creature_data(
|
|||
let list_creatures = generic_deserialize::<CreatureData>(
|
||||
connection,
|
||||
"creature",
|
||||
Some("show_to_master=1"),
|
||||
Some("show_to_master=1 AND (id<5)"),
|
||||
Some("id"),
|
||||
)?;
|
||||
let mut finished_creatures = Vec::new();
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit abacba00c4b888241d47bfb2621322d5586f77d4
|
||||
Subproject commit 521c7f3cad4417ec340b6a4d0dbaea92944daa4c
|
||||
Loading…
Reference in New Issue