database_monsters #141
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -1,17 +1,22 @@
|
|||
//! Monster export module
|
||||
#![allow(dead_code)]
|
||||
|
||||
use comfy_table::{Cell, Color, modifiers};
|
||||
use more_fields::FieldsAsSlice;
|
||||
|
||||
use crate::{
|
||||
Config, Connection, MonsterConfig,
|
||||
monster_analysis::monster_analysis_structs::{ArmorBreakCategory, DamageCategory},
|
||||
monster_analysis::{
|
||||
helpers::{binomial_dice_distribution, how_much_with_succeses},
|
||||
monster_analysis_structs::DefenseMode,
|
||||
},
|
||||
monster_database::{fetch_all_creature_data, fetch_all_player_data},
|
||||
monster_render::ToTable,
|
||||
monster_structs::PlayerBalancing,
|
||||
monster_render::{ToCell, ToRow, ToTable},
|
||||
monster_structs::{CreatureBodyPart, FullMonster, PlayerBalancing, ProfileHSE, ProfileStance},
|
||||
};
|
||||
use more_fields::FieldsAsSlice;
|
||||
use probability::distribution::Discrete;
|
||||
use probability::prelude::Binomial;
|
||||
use std::cmp::{max, min};
|
||||
pub mod attack_analysis;
|
||||
mod helpers;
|
||||
use std::collections::HashMap;
|
||||
pub mod monster_analysis_structs;
|
||||
|
||||
/// Shows balancing information for monsters and players.
|
||||
|
|
@ -24,10 +29,24 @@ pub fn show_balancing_data(
|
|||
let data = fetch_all_creature_data(&connection, config)?;
|
||||
let player_data = fetch_all_player_data(&connection, config)?;
|
||||
|
||||
// let table = player_data.to_table();
|
||||
|
||||
for creature in data {
|
||||
println!("{}", creature.name);
|
||||
// println!("{}", creature.name);
|
||||
let mut table = comfy_table::Table::new();
|
||||
table
|
||||
.load_preset(comfy_table::presets::UTF8_FULL_CONDENSED)
|
||||
.apply_modifier(modifiers::UTF8_ROUND_CORNERS)
|
||||
.set_content_arrangement(comfy_table::ContentArrangement::Dynamic);
|
||||
table.add_row(vec![
|
||||
match creature.balancing.monster_groupsize {
|
||||
0 | 1 => creature.name.clone(),
|
||||
n => format!("{} x {}", creature.name, n),
|
||||
}
|
||||
.to_cell()
|
||||
.fg(Color::Blue), // .add_attribute(comfy_table::Attribute::Reverse),
|
||||
]);
|
||||
|
||||
println!("{table}");
|
||||
|
||||
let player_level = &creature.balancing.profile_hse;
|
||||
let available_profiles = player_data
|
||||
.clone()
|
||||
|
|
@ -35,166 +54,333 @@ 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_player_attacks(args, &creature, &profiles, DefenseMode::Worst);
|
||||
display_monster_attacks(args, creature, &profiles, DefenseMode::Best);
|
||||
}
|
||||
// println!("{table}");
|
||||
Ok(())
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub enum DefenseMode {
|
||||
Best,
|
||||
Worst,
|
||||
}
|
||||
|
||||
pub fn attack_player(
|
||||
attack: &monster_analysis_structs::MonsterBalancingAttack,
|
||||
victim: &PlayerBalancing,
|
||||
fn display_player_attacks(
|
||||
args: &MonsterConfig,
|
||||
creature: &FullMonster,
|
||||
profiles: &HashMap<ProfileStance, PlayerBalancing>,
|
||||
mode: DefenseMode,
|
||||
) -> Option<DamageReport> {
|
||||
// How much successes left
|
||||
let threshold = match mode {
|
||||
DefenseMode::Best => max(attack.threshold_parry, attack.threshold_dodge),
|
||||
DefenseMode::Worst => max(attack.threshold_parry, attack.threshold_dodge),
|
||||
} + victim.specialty_def;
|
||||
) {
|
||||
let _ = args;
|
||||
let _ = mode;
|
||||
let r = &creature
|
||||
.body_parts
|
||||
.body_parts
|
||||
.iter()
|
||||
.map(|body_part| {
|
||||
let ratio = creature.balancing.monster_groupsize as f64
|
||||
/ creature.balancing.player_groupsize as f64;
|
||||
let damage_done_p1 =
|
||||
damage_done_to_part(body_part, &profiles[&ProfileStance::Neutral], Phases::P1);
|
||||
let damage_done_p2 =
|
||||
damage_done_to_part(body_part, &profiles[&ProfileStance::Neutral], Phases::P2);
|
||||
let time_to_p2 = ratio * body_part.integrity_p1.unwrap() as f64 / damage_done_p1.ab_t;
|
||||
let time_to_kill = ratio
|
||||
* (body_part.life_points_p1.unwrap() as f64 / damage_done_p1.hp_t
|
||||
+ body_part.life_points_p2.unwrap_or(0) as f64 / damage_done_p2.hp_t);
|
||||
let time_to_armorbreak =
|
||||
ratio * (body_part.integrity_p1.unwrap() as f64 / damage_done_p1.ab_t);
|
||||
|
||||
let bin = binomial_dice_distribution(threshold, victim.successes_def);
|
||||
// let successes_left = attack.successes - thld(victim.successes_def, threshold);
|
||||
let avg_successes_left: f64 = bin
|
||||
.iter()
|
||||
.map(|(dice, p)| (attack.successes - dice) as f64 * p)
|
||||
.sum::<f64>()
|
||||
/ bin.len() as f64;
|
||||
let avg_damage_incomming: f64 = bin
|
||||
.iter()
|
||||
.map(|(dices, p)| {
|
||||
how_much_with_succeses(&attack.damage, attack.successes - dices) as f64 * p
|
||||
DefenseReport {
|
||||
id: creature.balancing.creature_id,
|
||||
name: creature.name.clone(),
|
||||
part_name: body_part.body_part_name.clone(),
|
||||
profile_hse: creature.balancing.profile_hse.clone(),
|
||||
time_to_p2,
|
||||
time_to_p2_target: creature.balancing.time_to_p2,
|
||||
time_to_armorbreak,
|
||||
time_to_player_kill: creature.balancing.time_to_player_kill,
|
||||
monster_groupsize: creature.balancing.monster_groupsize,
|
||||
player_groupsize: creature.balancing.player_groupsize,
|
||||
time_to_kill,
|
||||
time_to_kill_target: creature.balancing.time_to_kill,
|
||||
damage_per_turn_p1: damage_done_p1.hp_t,
|
||||
damage_per_turn_p2: damage_done_p2.hp_t,
|
||||
health_p1: body_part.life_points_p1.unwrap(),
|
||||
health_p2: body_part.life_points_p2.unwrap_or(0),
|
||||
time_to_armorbreak_target: creature.balancing.time_to_armorbreak,
|
||||
armor_break_per_turn: damage_done_p1.ab_t,
|
||||
integrity_p1: body_part.integrity_p1.unwrap(),
|
||||
}
|
||||
})
|
||||
.sum::<f64>();
|
||||
// / bin.len() as f64;
|
||||
.collect::<Vec<DefenseReport>>();
|
||||
println!("{}", r.to_table());
|
||||
}
|
||||
|
||||
// println!(
|
||||
// "{} DMG:{:?} {:.2?} Left[{avg_successes_left:.2}/{} with {}] = {avg_damage_incomming}",
|
||||
// attack.name, attack.damage, bin, attack.successes, victim.successes_def
|
||||
// );
|
||||
// let mut damage_incoming = how_much_with_succeses(&attack.damage, successes_left);
|
||||
let damage_incoming = avg_damage_incomming;
|
||||
let damage_tanked = (damage_incoming - (victim.protection + victim.strength) as f64).max(0.0);
|
||||
let armor_loss =
|
||||
(damage_incoming - victim.protection as f64).clamp(0.0, attack.armor_break as f64);
|
||||
// if avg_successes_left < 0.0 {
|
||||
// damage_incoming = 0.0;
|
||||
// damage_tanked = 0.0;
|
||||
// armor_loss = 0.0;
|
||||
// }
|
||||
let report = DamageReport {
|
||||
damage_incoming,
|
||||
damage_tanked,
|
||||
armor_loss,
|
||||
successes_left: avg_successes_left,
|
||||
damage_category: DamageCategory::from_percent(damage_tanked as f64 / victim.health as f64),
|
||||
armor_expected: attack.target_ab,
|
||||
name: attack.name.clone(),
|
||||
damage_expected: attack.target_damage,
|
||||
armor_category: ArmorBreakCategory::from_percent(
|
||||
armor_loss as f64 / victim.integrity as f64,
|
||||
),
|
||||
player_health: victim.health,
|
||||
player_integrity: victim.integrity,
|
||||
threshold,
|
||||
attack_successes: attack.successes,
|
||||
mode,
|
||||
/// Shorten a string so that its final length (including the three‑dot marker) does not exceed `size`.
|
||||
///
|
||||
/// If `size` is smaller than four the function simply truncates to that length
|
||||
/// (there’s no room for “…”).
|
||||
///
|
||||
/// # Parameters
|
||||
/// * `s` – The string slice to shorten.
|
||||
/// * `size` – Maximum length of the returned string, including the ellipsis.
|
||||
pub fn shorten_string(s: &str, size: usize) -> String {
|
||||
// If it already fits, just return a copy.
|
||||
if s.len() <= size {
|
||||
return s.to_owned();
|
||||
}
|
||||
|
||||
// No room for "…" + at least one char each side → just cut off.
|
||||
if size < 4 {
|
||||
return s.chars().take(size).collect();
|
||||
}
|
||||
|
||||
// How many chars we keep from the front / back?
|
||||
let usable = size - 3; // length available for real characters
|
||||
let half = usable / 2; // baseline number of chars per side
|
||||
let extra = usable % 2; // if odd, give one more to the front
|
||||
|
||||
let front_len = half + extra;
|
||||
let back_len = half;
|
||||
|
||||
// Grab the required portions.
|
||||
let front: String = s.chars().take(front_len).collect();
|
||||
let back: String = s
|
||||
.chars()
|
||||
.rev() // reverse for an easy “take last N”
|
||||
.take(back_len)
|
||||
.collect::<String>()
|
||||
.chars()
|
||||
.rev() // bring them back to normal order
|
||||
.collect();
|
||||
|
||||
format!("{}...{}", front, back)
|
||||
}
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum Phases {
|
||||
P1,
|
||||
P2,
|
||||
}
|
||||
fn damage_done_to_part(
|
||||
part: &CreatureBodyPart,
|
||||
profile: &PlayerBalancing,
|
||||
phase: Phases,
|
||||
) -> DamageDealtByPlayer {
|
||||
let threshold = match phase {
|
||||
Phases::P1 => part.threshold_p1,
|
||||
Phases::P2 => part.threshold_p2,
|
||||
}
|
||||
.unwrap()
|
||||
+ profile.precision;
|
||||
let (_integrity, protection) = match phase {
|
||||
Phases::P1 => (part.integrity_p1.unwrap(), part.protection_p1.unwrap()),
|
||||
Phases::P2 => (part.integrity_p2.unwrap(), part.protection_p2.unwrap()),
|
||||
};
|
||||
Some(report)
|
||||
let damage_profile: Vec<i64> = (1..profile.max_successes_off)
|
||||
.map(|v| (v as f64 * profile.damage_per_s) as i64)
|
||||
.collect();
|
||||
// Pick the best damage out of all scenarios:
|
||||
// Scenario A : One big hit
|
||||
// Scenario B : Two half hits
|
||||
let damage_a = damage_with_profile(&damage_profile, threshold, profile.successes_off);
|
||||
let damage_b1 = damage_with_profile(&damage_profile, threshold, profile.successes_off / 2);
|
||||
let damage_b2 = damage_with_profile(
|
||||
&damage_profile,
|
||||
threshold,
|
||||
profile.successes_off - profile.successes_off / 2,
|
||||
);
|
||||
let ab_a = (damage_a - protection as f64).max(0.);
|
||||
let ab_b1 = (damage_b1 - protection as f64).max(0.);
|
||||
let ab_b2 = (damage_b2 - protection as f64).max(0.);
|
||||
let hp_t = damage_a.max(damage_b1 + damage_b2);
|
||||
let ab_t = ab_a.max(ab_b1 + ab_b2);
|
||||
|
||||
DamageDealtByPlayer {
|
||||
damage_a,
|
||||
damage_b1,
|
||||
damage_b2,
|
||||
ab_a,
|
||||
ab_b1,
|
||||
ab_b2,
|
||||
hp_t,
|
||||
ab_t,
|
||||
}
|
||||
}
|
||||
pub(super) struct DamageDealtByPlayer {
|
||||
damage_a: f64,
|
||||
damage_b1: f64,
|
||||
damage_b2: f64,
|
||||
ab_a: f64,
|
||||
ab_b1: f64,
|
||||
ab_b2: f64,
|
||||
hp_t: f64,
|
||||
ab_t: f64,
|
||||
}
|
||||
|
||||
// Binomial damage distribution
|
||||
// As a (0s, p), (1s, p) etc
|
||||
// can be used to calc avg damage
|
||||
// with avg(dmg_with_successes(i)*j)
|
||||
/// Calculate the binomial distribution and average the damage from there
|
||||
pub(super) fn binomial_dice_distribution(threshold: i64, dices: i64) -> Vec<(i64, f64)> {
|
||||
let p = ((threshold as f64) / 10.).clamp(0. + 1E-10, 1. - 1E-10);
|
||||
let binomial = Binomial::new(dices as usize, p);
|
||||
|
||||
(0..(dices + 1) as usize)
|
||||
.map(|target_dices| {
|
||||
let probability_success = binomial.mass(target_dices);
|
||||
(target_dices as i64, probability_success)
|
||||
})
|
||||
.collect::<Vec<(i64, f64)>>()
|
||||
fn damage_with_profile(damage_profile: &[i64], threshold: i64, dices: i64) -> f64 {
|
||||
let damage = binomial_dice_distribution(threshold, dices);
|
||||
damage
|
||||
.iter()
|
||||
.map(|(d, p)| how_much_with_succeses(damage_profile, *d) as f64 * p)
|
||||
.sum::<f64>()
|
||||
}
|
||||
|
||||
#[derive(Debug, FieldsAsSlice)]
|
||||
pub struct DamageReport {
|
||||
pub name: String,
|
||||
#[INTEGER(name = "dmg_inc")]
|
||||
pub damage_incoming: f64,
|
||||
#[INTEGER(name = "r_left")]
|
||||
pub successes_left: f64,
|
||||
#[INTEGER(name = "dmg_tak")]
|
||||
pub damage_tanked: f64,
|
||||
#[TEXT(name = "dmg_cat")]
|
||||
pub damage_category: DamageCategory,
|
||||
#[TEXT(name = "dmg_expt")]
|
||||
pub damage_expected: DamageCategory,
|
||||
#[INTEGER(name = "arm_loss")]
|
||||
pub armor_loss: f64,
|
||||
#[TEXT(name = "arm_cat")]
|
||||
pub armor_category: ArmorBreakCategory,
|
||||
#[TEXT(name = "arm_expt")]
|
||||
pub armor_expected: ArmorBreakCategory,
|
||||
#[SKIP]
|
||||
pub player_health: i64,
|
||||
#[SKIP]
|
||||
pub player_integrity: i64,
|
||||
#[SKIP]
|
||||
pub threshold: i64,
|
||||
#[SKIP]
|
||||
pub mode: DefenseMode,
|
||||
#[SKIP]
|
||||
pub attack_successes: i64,
|
||||
}
|
||||
|
||||
impl DamageCategory {
|
||||
fn from_percent(percent: f64) -> Self {
|
||||
match percent {
|
||||
..0.01 => Self::None,
|
||||
0.01..0.15 => Self::Chip,
|
||||
0.15..0.5 => Self::Moderate,
|
||||
0.5..0.8 => Self::High,
|
||||
0.8..1.0 => Self::NearDeath,
|
||||
1.0..1.5 => Self::Kill,
|
||||
1.5.. => Self::Overkill,
|
||||
_ => Self::None,
|
||||
}
|
||||
// 🠰
|
||||
impl ToRow for DefenseReport {
|
||||
fn to_row(&self) -> comfy_table::Row {
|
||||
let row: Vec<Cell> = vec![
|
||||
format!("{:?}", self.id).to_cell(),
|
||||
shorten_string(&self.part_name.to_string(), 18).to_cell(),
|
||||
format!("{:.1?}/{}", self.damage_per_turn_p1, self.health_p1)
|
||||
.to_cell()
|
||||
.fg(Color::DarkGrey),
|
||||
compare_vals("t", self.time_to_p2, self.time_to_p2_target as f64),
|
||||
format!("{:.1?}/{}", self.damage_per_turn_p2, self.health_p2)
|
||||
.to_cell()
|
||||
.fg(Color::DarkGrey),
|
||||
compare_vals("t", self.time_to_kill, self.time_to_kill_target as f64),
|
||||
format!("{:.1?}/{}", self.armor_break_per_turn, self.integrity_p1)
|
||||
.to_cell()
|
||||
.fg(Color::DarkGrey),
|
||||
compare_vals(
|
||||
"t",
|
||||
self.time_to_armorbreak,
|
||||
self.time_to_armorbreak_target as f64,
|
||||
),
|
||||
];
|
||||
row.into()
|
||||
}
|
||||
}
|
||||
|
||||
fn thld(r_succeses: i64, threshold_parry: i64) -> i64 {
|
||||
(r_succeses * min(threshold_parry, 10)) / 10
|
||||
}
|
||||
fn fmt_target(v: f64) -> String {
|
||||
const TOO_MUCH: f64 = 1_000_000_000_000_000.0;
|
||||
const TRILLION: f64 = 1_000_000_000_000.0;
|
||||
const BILLION: f64 = 1_000_000_000.0;
|
||||
const MILLION: f64 = 1_000_000.0;
|
||||
const THOUSAND: f64 = 1_000.0;
|
||||
|
||||
fn how_much_with_succeses(damage: &[i64], succeses: i64) -> i64 {
|
||||
if succeses <= 0 {
|
||||
0
|
||||
match v {
|
||||
_ if v >= TOO_MUCH => "⇑⇑⇑⇑B".to_string(),
|
||||
_ if v >= TRILLION => format!("⇑{:.1}T", v / TRILLION),
|
||||
_ if v >= BILLION => format!("⇑{:.1}B", v / BILLION),
|
||||
_ if v >= MILLION => format!("⇑{:.1}M", v / MILLION),
|
||||
_ if v >= THOUSAND => format!("⇑{:.1}k", v / THOUSAND),
|
||||
_ => format!("{:.1}", v),
|
||||
}
|
||||
}
|
||||
fn compare_vals(unit: &str, actual: f64, target: f64) -> Cell {
|
||||
let pct_diff = ((actual - target).abs() / target) * 100.0; // % diff
|
||||
// let actual = 100000000000.;
|
||||
let actual = if pct_diff > 1.0 {
|
||||
fmt_target(actual)
|
||||
} else {
|
||||
damage[(succeses - 1).clamp(0_i64, damage.len() as i64 - 1) as usize]
|
||||
format!("{:.1?}", actual)
|
||||
};
|
||||
format!("{}/{:.0?}{}", actual, target, unit)
|
||||
.to_cell()
|
||||
.fg(pct_diff_to_colour(pct_diff))
|
||||
}
|
||||
|
||||
/// Turn percent‑difference into one of four hard‑coded colours.
|
||||
fn pct_diff_to_colour(pct_diff: f64) -> Color {
|
||||
match pct_diff {
|
||||
p if p < 20.0 => Color::Green,
|
||||
p if p < 30.0 => Color::Blue,
|
||||
p if p < 40.0 => Color::Red,
|
||||
_ => Color::DarkRed,
|
||||
}
|
||||
}
|
||||
/// A snapshot of all defensive metrics for a single monster encounter.
|
||||
/// Each field has one of three semantic labels:
|
||||
/// * **Fixed** – inherent properties that do not change during the fight.
|
||||
/// * **Actual** – metrics computed from a simulation or run‑time analysis.
|
||||
/// * **Goal** – target values you want to achieve in an optimal strategy.
|
||||
#[derive(Debug, FieldsAsSlice)]
|
||||
pub struct DefenseReport {
|
||||
/// Unique identifier for the monster definition.
|
||||
#[INTEGER]
|
||||
pub id: i64,
|
||||
/// Display name of the monster (human‑readable).
|
||||
#[SKIP]
|
||||
pub name: String,
|
||||
/// The part of the monster’s body that is currently active
|
||||
pub part_name: String,
|
||||
/// (Fixed) HSE profile of the monster.
|
||||
#[SKIP(name = "Profile")]
|
||||
pub profile_hse: ProfileHSE,
|
||||
/// Damage per turn while in phase 1.
|
||||
/// Used when the monster changes behaviour between phases.
|
||||
#[INTEGER(name = "DPT P1")]
|
||||
pub damage_per_turn_p1: f64,
|
||||
/// (Actual) Turns needed to reach phase 2.
|
||||
/// Computed from the monster’s health and damage output or from simulation data.
|
||||
#[INTEGER(name = "P1 🠲 P2")]
|
||||
pub time_to_p2: f64,
|
||||
/// (Goal) Desired turns to reach phase 2.
|
||||
/// If the current `time_to_p2` exceeds this value, the fight is considered inefficient.
|
||||
#[SKIP]
|
||||
pub time_to_p2_target: i64,
|
||||
/// Damage per turn while in phase 2.
|
||||
#[INTEGER(name = "DPT P2")]
|
||||
pub damage_per_turn_p2: f64,
|
||||
/// (Actual) Turns needed to kill the monster.
|
||||
/// Derived from its health and damage per turn or from a run‑time simulation.
|
||||
#[INTEGER(name = "P2 ➜ 🕇")]
|
||||
pub time_to_kill: f64,
|
||||
/// (Goal) Desired turns to kill the monster.
|
||||
/// If actual `time_to_kill` is larger, you may need to adjust attack power or strategy.
|
||||
#[SKIP]
|
||||
pub time_to_kill_target: i64,
|
||||
/// (Actual) Armor‑breaking damage per turn.
|
||||
/// This is the rate at which the monster’s armor is degraded during combat.
|
||||
#[INTEGER(name = "AbPT P1")]
|
||||
pub armor_break_per_turn: f64,
|
||||
/// (Actual) Turns until this monster’s armor breaks, i.e. the point
|
||||
/// at which it stops being able to mitigate incoming damage.
|
||||
#[INTEGER(name = "TT AB")]
|
||||
pub time_to_armorbreak: f64,
|
||||
/// (Goal) Desired turns until the monster’s armor breaks.
|
||||
/// A lower value indicates a more aggressive strategy.
|
||||
#[SKIP(name = "ttAB")]
|
||||
pub time_to_armorbreak_target: i64,
|
||||
/// (Goal) Average turns to kill a single player
|
||||
#[SKIP(name = "ttPK")]
|
||||
pub time_to_player_kill: i64,
|
||||
/// (Fixed) The number of monsters in a single group.
|
||||
/// Usually `1`, but can be > 1 for bosses that spawn multiple instances.
|
||||
#[SKIP]
|
||||
pub monster_groupsize: i64,
|
||||
/// (Fixed) Number of players this fight was designed for.
|
||||
#[SKIP]
|
||||
pub player_groupsize: i64,
|
||||
/// (Fixed) Health points during phase 1.
|
||||
#[SKIP]
|
||||
pub health_p1: i64,
|
||||
/// (Fixed) Health points during phase 2.
|
||||
#[SKIP]
|
||||
pub health_p2: i64,
|
||||
/// (Fixed) Integrity points during phase 1, representing how many
|
||||
/// damage points the monster can take before losing its first phase.
|
||||
#[SKIP]
|
||||
pub integrity_p1: i64,
|
||||
}
|
||||
fn display_monster_attacks(
|
||||
args: &MonsterConfig,
|
||||
creature: FullMonster,
|
||||
profiles: &HashMap<ProfileStance, PlayerBalancing>,
|
||||
mode: DefenseMode,
|
||||
) {
|
||||
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 = attack_analysis::all_attacks(args, &attack, profiles, mode);
|
||||
res.append(&mut report);
|
||||
}
|
||||
println!("{}", res.to_table());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,149 @@
|
|||
use crate::{
|
||||
MonsterConfig,
|
||||
monster_analysis::{
|
||||
helpers,
|
||||
monster_analysis_structs::{
|
||||
self, ArmorBreakCategory, DamageCategory, DefenseMode, Showcase,
|
||||
},
|
||||
},
|
||||
monster_structs::{PlayerBalancing, ProfileStance},
|
||||
};
|
||||
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: &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 {
|
||||
DefenseMode::Best => max(attack.threshold_parry, attack.threshold_dodge),
|
||||
DefenseMode::Worst => max(attack.threshold_parry, attack.threshold_dodge),
|
||||
} + victim.specialty_def;
|
||||
|
||||
let bin = helpers::binomial_dice_distribution(threshold, victim.successes_def);
|
||||
// let successes_left = attack.successes - thld(victim.successes_def, threshold);
|
||||
let avg_successes_left: f64 = bin
|
||||
.iter()
|
||||
.map(|(dice, p)| (attack.successes - dice) as f64 * p)
|
||||
.sum::<f64>();
|
||||
// TODO : Pretty sure
|
||||
// / bin.len() as f64;
|
||||
let avg_damage_incomming: f64 = bin
|
||||
.iter()
|
||||
.map(|(dices, p)| {
|
||||
helpers::how_much_with_succeses(&attack.damage, attack.successes - dices) as f64 * p
|
||||
})
|
||||
.sum::<f64>();
|
||||
// / bin.len() as f64;
|
||||
|
||||
// println!(
|
||||
// "{} DMG:{:?} {:.2?} Left[{avg_successes_left:.2}/{} with {}] = {avg_damage_incomming}",
|
||||
// attack.name, attack.damage, bin, attack.successes, victim.successes_def
|
||||
// );
|
||||
// let mut damage_incoming = how_much_with_succeses(&attack.damage, successes_left);
|
||||
let damage_incoming = avg_damage_incomming;
|
||||
let damage_tanked = (damage_incoming - (victim.protection + victim.strength) as f64).max(0.0);
|
||||
let armor_loss =
|
||||
(damage_incoming - victim.protection as f64).clamp(0.0, attack.armor_break as f64);
|
||||
// if avg_successes_left < 0.0 {
|
||||
// damage_incoming = 0.0;
|
||||
// damage_tanked = 0.0;
|
||||
// armor_loss = 0.0;
|
||||
// }
|
||||
let report = DamageReport {
|
||||
damage_incoming,
|
||||
damage_tanked,
|
||||
armor_loss,
|
||||
successes_left: avg_successes_left,
|
||||
damage_category: DamageCategory::from_percent(damage_tanked as f64 / victim.health as f64),
|
||||
armor_expected: attack.target_ab,
|
||||
name: attack.name.clone(),
|
||||
damage_expected: attack.target_damage,
|
||||
armor_category: ArmorBreakCategory::from_percent(
|
||||
armor_loss as f64 / victim.integrity as f64,
|
||||
),
|
||||
player_health: victim.health,
|
||||
player_integrity: victim.integrity,
|
||||
threshold,
|
||||
attack_successes: attack.successes,
|
||||
mode,
|
||||
showcase,
|
||||
stance: victim.profile_stance,
|
||||
};
|
||||
Some(report)
|
||||
}
|
||||
|
||||
#[derive(Debug, FieldsAsSlice)]
|
||||
pub struct DamageReport {
|
||||
pub name: String,
|
||||
#[INTEGER(name = "dmg_inc")]
|
||||
pub damage_incoming: f64,
|
||||
#[INTEGER(name = "r_left")]
|
||||
pub successes_left: f64,
|
||||
#[INTEGER(name = "dmg_tak")]
|
||||
pub damage_tanked: f64,
|
||||
#[TEXT(name = "dmg_cat")]
|
||||
pub damage_category: DamageCategory,
|
||||
#[TEXT(name = "dmg_expt")]
|
||||
pub damage_expected: DamageCategory,
|
||||
#[INTEGER(name = "arm_loss")]
|
||||
pub armor_loss: f64,
|
||||
#[TEXT(name = "arm_cat")]
|
||||
pub armor_category: ArmorBreakCategory,
|
||||
#[TEXT(name = "arm_expt")]
|
||||
pub armor_expected: ArmorBreakCategory,
|
||||
#[SKIP]
|
||||
pub player_health: i64,
|
||||
#[SKIP]
|
||||
pub player_integrity: i64,
|
||||
#[SKIP]
|
||||
pub threshold: i64,
|
||||
#[SKIP]
|
||||
pub mode: DefenseMode,
|
||||
#[SKIP]
|
||||
pub stance: ProfileStance,
|
||||
#[SKIP]
|
||||
pub attack_successes: i64,
|
||||
#[SKIP]
|
||||
pub showcase: monster_analysis_structs::Showcase,
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
use std::cmp::min;
|
||||
|
||||
use probability::distribution::Discrete;
|
||||
use probability::prelude::Binomial;
|
||||
|
||||
// Binomial damage distribution
|
||||
// As a (0s, p), (1s, p) etc
|
||||
// can be used to calc avg damage
|
||||
// with avg(dmg_with_successes(i)*j)
|
||||
/// Calculate the binomial distribution and average the damage from there
|
||||
pub(super) fn binomial_dice_distribution(threshold: i64, dices: i64) -> Vec<(i64, f64)> {
|
||||
let p = ((threshold as f64) / 10.).clamp(0. + 1E-10, 1. - 1E-10);
|
||||
let binomial = Binomial::new(dices as usize, p);
|
||||
|
||||
(0..(dices + 1) as usize)
|
||||
.map(|target_dices| {
|
||||
let probability_success = binomial.mass(target_dices);
|
||||
(target_dices as i64, probability_success)
|
||||
})
|
||||
.collect::<Vec<(i64, f64)>>()
|
||||
}
|
||||
|
||||
pub fn thld(r_succeses: i64, threshold_parry: i64) -> i64 {
|
||||
(r_succeses * min(threshold_parry, 10)) / 10
|
||||
}
|
||||
|
||||
pub fn how_much_with_succeses(damage: &[i64], succeses: i64) -> i64 {
|
||||
if succeses <= 0 {
|
||||
0
|
||||
} else {
|
||||
damage[(succeses - 1).clamp(0_i64, damage.len() as i64 - 1) as usize]
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::monster_structs::{FullMonster, PlayerBalancing, ProfileStance};
|
||||
use more_fields::FieldsAsSlice;
|
||||
use std::str::FromStr;
|
||||
use strum::EnumString;
|
||||
use strum::{Display, EnumString};
|
||||
|
||||
impl From<FullMonster> for Vec<MonsterBalancingAttack> {
|
||||
fn from(creature: FullMonster) -> Self {
|
||||
|
|
@ -119,6 +119,18 @@ pub enum ArmorBreakCategory {
|
|||
Overkill,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum Showcase {
|
||||
Display,
|
||||
Balancing,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Display)]
|
||||
pub enum DefenseMode {
|
||||
Best,
|
||||
Worst,
|
||||
}
|
||||
|
||||
impl ArmorBreakCategory {
|
||||
pub fn from_percent(value: f64) -> Self {
|
||||
match value {
|
||||
|
|
@ -196,3 +208,18 @@ pub(crate) fn from_opt_i64(val: Option<&i64>) -> i64 {
|
|||
None => 0,
|
||||
}
|
||||
}
|
||||
|
||||
impl DamageCategory {
|
||||
pub fn from_percent(percent: f64) -> Self {
|
||||
match percent {
|
||||
..0.01 => Self::None,
|
||||
0.01..0.15 => Self::Chip,
|
||||
0.15..0.5 => Self::Moderate,
|
||||
0.5..0.8 => Self::High,
|
||||
0.8..1.0 => Self::NearDeath,
|
||||
1.0..1.5 => Self::Kill,
|
||||
1.5.. => Self::Overkill,
|
||||
_ => Self::None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
use crate::monster_analysis::monster_analysis_structs::Showcase;
|
||||
use comfy_table::{Color, Table, *};
|
||||
|
||||
use crate::{
|
||||
monster_analysis::{
|
||||
DamageReport,
|
||||
attack_analysis::DamageReport,
|
||||
monster_analysis_structs::{ArmorBreakCategory, DamageCategory, MonsterBalancingAttack},
|
||||
},
|
||||
monster_structs::{PlayerBalancing, ProfileHSE, ProfileStance},
|
||||
|
|
@ -70,44 +71,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 {}
|
||||
|
|
@ -294,12 +294,13 @@ pub struct CreatureBodyPart {
|
|||
pub struct GroupedResists {
|
||||
inner: IndexMap<String, Vec<Option<String>>>,
|
||||
}
|
||||
/// Counts how many items in `list` have a **Some** value for the given `field`.
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// let pierced = count_present!(part_list, piercing);
|
||||
/// ```
|
||||
|
||||
// / Counts how many items in `list` have a **Some** value for the given `field`.
|
||||
// /
|
||||
// / # Example
|
||||
// / ```
|
||||
// / let pierced = count_present!(part_list, piercing);
|
||||
// / ```
|
||||
// macro_rules! count_present {
|
||||
// ($list:expr, $field:ident) => {
|
||||
// // We keep everything inside its own block so that it behaves like a single expression.
|
||||
|
|
@ -423,11 +424,14 @@ pub struct CreatureBalancing {
|
|||
/// (Goal) Turns needed to reach phase 2.
|
||||
pub time_to_p2: i64,
|
||||
#[INTEGER]
|
||||
/// (Goal) Turns needed to kill from phase 2.
|
||||
pub time_to_kill: i64,
|
||||
#[INTEGER]
|
||||
/// (Goal) Turns until the monster’s armor breaks.
|
||||
pub time_to_armorbreak: i64,
|
||||
#[INTEGER]
|
||||
/// (GOAL) Avg. turns to kill a single target.
|
||||
pub time_to_first_kill: i64,
|
||||
pub time_to_player_kill: i64,
|
||||
#[INTEGER]
|
||||
/// (FIXED) Size of a single monster group (usually one).
|
||||
pub monster_groupsize: i64,
|
||||
|
|
@ -454,6 +458,9 @@ pub struct PlayerBalancing {
|
|||
/// Number of offensive successes per round.
|
||||
pub successes_off: i64,
|
||||
#[INTEGER]
|
||||
/// Maximum number of offensive successes per round.
|
||||
pub max_successes_off: i64,
|
||||
#[INTEGER]
|
||||
/// Number of deffensive successes per round.
|
||||
pub successes_def: i64,
|
||||
#[INTEGER]
|
||||
|
|
@ -476,7 +483,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 cd34aa21d07d0bf0bcda0f88e12279b791546a20
|
||||
Loading…
Reference in New Issue