database_monsters #163

Merged
Dandaedre merged 3 commits from database_monsters into main 2026-07-27 22:40:23 +02:00
7 changed files with 253 additions and 91 deletions

View File

@ -6,7 +6,7 @@ resolver = "3"
# edition = "2024"
# license = "MIT OR Apache-2.0"
[workspace.package]
version = "0.3.23"
version = "0.3.24"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -18,6 +18,7 @@ strum = {workspace = true}
probability = {workspace = true}
comfy-table = "7.2.2"
colored = "3.1.1"
# derive_more = "2.1.1"
[dev-dependencies]
regex = {workspace = true}

View File

@ -2,14 +2,14 @@ use crate::{
monster_analysis::{
DefenseMode, attack_analysis,
helpers::{binomial_dice_distribution, how_much_with_succeses},
monster_analysis_structs,
monster_analysis_structs::{self, Showcase},
},
monster_render::ToTable,
monster_structs::{CreatureBodyPart, FullMonster, PlayerBalancing, ProfileHSE, ProfileStance},
};
use config::monsters::BalanceArgs;
use more_fields::FieldsAsSlice;
use std::collections::HashMap;
use std::{collections::HashMap, ops::AddAssign};
pub(crate) fn display_player_attacks(
args: &BalanceArgs,
@ -17,56 +17,160 @@ pub(crate) fn display_player_attacks(
profiles: &HashMap<ProfileStance, PlayerBalancing>,
mode: DefenseMode,
) {
let _ = args;
let _ = mode;
let r = &creature
let r = report_from_profile(args, creature, profiles);
println!("{}", r.to_table());
}
fn report_from_profile(
args: &BalanceArgs,
creature: &FullMonster,
profiles: &HashMap<ProfileStance, PlayerBalancing>,
) -> Vec<DefenseReport> {
creature
.body_parts
.body_parts
.iter()
.map(|body_part| {
let ratio = creature.balancing.monster_groupsize / creature.balancing.player_groupsize;
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.life_points_p1.unwrap() as f64 / damage_done_p1.hp_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 time_to_kill_through = ratio
* (body_part.life_points_p1.unwrap() as f64
/ (damage_done_p1.damage_through - creature.stats.strength as f64).max(0.)
+ body_part.life_points_p2.unwrap_or(0) as f64
/ (damage_done_p2.damage_through - creature.stats.strength as f64).max(0.));
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(),
damage_through_p1: damage_done_p1.damage_through,
damage_through_p2: damage_done_p2.damage_through,
time_to_kill_through,
.flat_map(|body_part| {
match args.show_extra {
true => vec![
(ProfileStance::Neutral, Showcase::Display),
(ProfileStance::Defensive, Showcase::Balancing),
(ProfileStance::Offensive, Showcase::Balancing),
],
false => vec![(ProfileStance::Neutral, Showcase::Display)],
}
.into_iter()
.map(|(p, show)| damage_report_on_part(creature, &profiles[&p], body_part, show))
.collect::<Vec<DefenseReport>>()
})
.collect::<Vec<DefenseReport>>();
println!("{}", r.to_table());
.collect::<Vec<DefenseReport>>()
}
#[derive(Debug)]
struct ChunkIter {
remaining: f64,
}
impl ChunkIter {
fn new(remaining: f64) -> Self {
Self { remaining }
}
}
impl std::ops::Deref for ChunkIter {
type Target = f64;
fn deref(&self) -> &Self::Target {
&self.remaining
}
}
impl Iterator for ChunkIter {
type Item = f64;
fn next(&mut self) -> Option<Self::Item> {
if self.remaining >= 1.0 {
self.remaining -= 1.0;
Some(1.0)
} else if self.remaining > 0.0 {
// Last piece – whatever is left.
let r = self.remaining;
self.remaining = 0.0;
Some(r)
} else {
None
}
}
}
pub struct DamageTransfer<'a> {
body_part: &'a CreatureBodyPart,
profile: &'a PlayerBalancing,
max_parried: i64,
phase: Phases,
strength: i64,
}
fn damage_report_on_part(
creature: &FullMonster,
profile: &PlayerBalancing,
body_part: &CreatureBodyPart,
display: Showcase,
) -> DefenseReport {
// Every round need to eliminate X dices from the pool
let mut dice_left_to_parry = creature.balancing.average_defensive_dices;
let players = ChunkIter::new(creature.balancing.player_groupsize);
let mut total_damage_done_p1 = DamageDealtByPlayer::default();
let mut total_damage_done_p2 = DamageDealtByPlayer::default();
for player_chunk in players {
let max_parried = dice_left_to_parry.min(profile.successes_off);
let mut damage_done_p1 = damage_done_to_part(&DamageTransfer {
body_part,
profile,
max_parried,
phase: Phases::P1,
strength: creature.stats.strength,
});
let mut damage_done_p2 = damage_done_to_part(&DamageTransfer {
body_part,
profile,
max_parried,
phase: Phases::P2,
strength: creature.stats.strength,
});
dice_left_to_parry = (dice_left_to_parry - max_parried).max(0);
if player_chunk < 1. {
damage_done_p1.mult(player_chunk);
damage_done_p2.mult(player_chunk);
}
total_damage_done_p1 += damage_done_p1;
total_damage_done_p2 += damage_done_p2;
}
let damage_done_p1 = total_damage_done_p1;
let damage_done_p2 = total_damage_done_p2;
let ratio = 1.0;
// let damage_done_p1 = damage_done_to_part(body_part, profile, dice_left_to_parry, Phases::P1);
// let damage_done_p2 = damage_done_to_part(body_part, profile, dice_left_to_parry, Phases::P2);
// let ratio = creature.balancing.monster_groupsize / creature.balancing.player_groupsize;
let time_to_p2 = ratio * body_part.life_points_p1.unwrap() as f64 / damage_done_p1.hp_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 time_to_kill_through = ratio
* (body_part.life_points_p1.unwrap() as f64
/ (damage_done_p1.damage_through - creature.stats.strength as f64).max(0.)
+ body_part.life_points_p2.unwrap_or(0) as f64
/ (damage_done_p2.damage_through - creature.stats.strength as f64).max(0.));
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(),
damage_through_p1: damage_done_p1.damage_through,
damage_through_p2: damage_done_p2.damage_through,
time_to_kill_through,
target_stance: profile.profile_stance,
showcase: display,
}
}
pub fn resist_physical(part: &CreatureBodyPart, mode: DefenseMode) -> i64 {
@ -95,11 +199,11 @@ pub fn value_resist(resist: &Option<String>) -> i64 {
}
}
}
pub(crate) fn damage_done_to_part(
part: &CreatureBodyPart,
profile: &PlayerBalancing,
phase: Phases,
) -> DamageDealtByPlayer {
pub fn damage_done_to_part(info: &DamageTransfer) -> DamageDealtByPlayer {
let part = info.body_part;
let profile = info.profile;
let dice_parried = info.max_parried;
let phase = info.phase;
let threshold = match phase {
Phases::P1 => part.threshold_p1,
Phases::P2 => part.threshold_p2,
@ -124,20 +228,14 @@ pub(crate) fn damage_done_to_part(
// 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) - resist).max(0.);
let damage_b1 = (damage_with_profile(&damage_profile, threshold, profile.successes_off / 2)
- resist)
.max(0.);
let damage_b2 = (damage_with_profile(
&damage_profile,
threshold,
profile.successes_off - profile.successes_off / 2,
) - resist)
.max(0.);
let dt_a = (damage_a - protection as f64).max(0.);
let dt_b1 = (damage_b1 - protection as f64).max(0.);
let dt_b2 = (damage_b2 - protection as f64).max(0.);
let dices = (profile.successes_off - dice_parried).clamp(0, profile.successes_off);
let damage_a = (damage_with_profile(&damage_profile, threshold, dices) - resist).max(0.);
let damage_b1 = (damage_with_profile(&damage_profile, threshold, dices / 2) - resist).max(0.);
let damage_b2 =
(damage_with_profile(&damage_profile, threshold, dices - dices / 2) - resist).max(0.);
let dt_a = (damage_a - protection as f64 - info.strength as f64).max(0.);
let dt_b1 = (damage_b1 - protection as f64 - info.strength as f64).max(0.);
let dt_b2 = (damage_b2 - protection as f64 - info.strength as f64).max(0.);
let ab_a = (damage_a - protection as f64).clamp(0., profile.armor_break as f64);
let ab_b1 = (damage_b1 - protection as f64).clamp(0., profile.armor_break as f64);
@ -164,6 +262,7 @@ pub enum Phases {
P2,
}
#[derive(Default)]
pub struct DamageDealtByPlayer {
pub damage_a: f64,
pub damage_b1: f64,
@ -175,6 +274,33 @@ pub struct DamageDealtByPlayer {
pub ab_t: f64,
pub damage_through: f64,
}
impl AddAssign for DamageDealtByPlayer {
fn add_assign(&mut self, rhs: Self) {
self.damage_a += rhs.damage_a;
self.damage_b1 += rhs.damage_b1;
self.damage_b2 += rhs.damage_b2;
self.ab_a += rhs.ab_a;
self.ab_b1 += rhs.ab_b1;
self.ab_b2 += rhs.ab_b2;
self.hp_t += rhs.hp_t;
self.ab_t += rhs.ab_t;
self.damage_through += rhs.damage_through;
}
}
impl DamageDealtByPlayer {
fn mult(&mut self, rhs: f64) {
self.damage_a *= rhs;
self.damage_b1 *= rhs;
self.damage_b2 *= rhs;
self.ab_a *= rhs;
self.ab_b1 *= rhs;
self.ab_b2 *= rhs;
self.hp_t *= rhs;
self.ab_t *= rhs;
self.damage_through *= rhs;
}
}
pub(crate) fn damage_with_profile(damage_profile: &[i64], threshold: i64, dices: i64) -> f64 {
let damage = binomial_dice_distribution(threshold, dices);
@ -199,9 +325,12 @@ pub struct DefenseReport {
pub name: String,
/// The part of the monster’s body that is currently active
pub part_name: String,
/// (Fixed) HSE profile of the monster.
/// (Fixed) HSE profile of the hunter.
#[SKIP(name = "Profile")]
pub profile_hse: ProfileHSE,
/// (Fixed) Stance of the player.
#[SKIP(name = "Stance")]
pub target_stance: ProfileStance,
/// (Actual) Armor‑breaking damage per turn.
/// This is the rate at which the monster’s armor is degraded during combat.
#[INTEGER(name = "AbPT P1")]
@ -266,6 +395,9 @@ pub struct DefenseReport {
/// (Actual) Time to kill through armor
#[INTEGER(name = "P1 ⇝ P2 ⇝ 🕇")]
pub time_to_kill_through: f64,
/// (Misc) Display name or target of balancing
#[SKIP]
pub showcase: Showcase,
}
pub(crate) fn display_monster_attacks(

View File

@ -100,7 +100,7 @@ impl ToRow for DamageReport {
fn to_row(&self) -> Row {
vec![
match self.showcase {
Showcase::Balancing => shorten_string(&self.name, 24).to_cell().fg(Color::Green),
Showcase::Balancing => shorten_string(&self.name, 22).to_cell().fg(Color::Green),
Showcase::Display => self.stance.to_string().to_cell().fg(Color::DarkGrey),
},
dim_if_not!(
@ -248,27 +248,53 @@ impl ToRow for DefenseReport {
fn to_row(&self) -> comfy_table::Row {
let row: Vec<Cell> = vec![
// format!("{:?}", self.id).to_cell(),
helpers::shorten_string(&self.part_name.to_string(), 18).to_cell(),
format!("{:.1?}/{}", self.armor_break_per_turn, self.integrity_p1)
match self.showcase {
Showcase::Display => {
helpers::shorten_string(&self.part_name.to_string(), 18).to_cell()
}
Showcase::Balancing => self.target_stance.to_cell().fg(Color::DarkGrey),
},
dim_if_not!(
self,
format!("{:.1?}/{}", self.armor_break_per_turn, self.integrity_p1)
.to_cell()
.fg(Color::DarkGrey)
),
dim_if_not!(
self,
compare_vals("t", self.time_to_armorbreak, self.time_to_armorbreak_target)
),
dim_if_not!(
self,
format!("{:.1?}/{}", self.damage_per_turn_p1, self.health_p1)
.to_cell()
.fg(Color::DarkGrey)
),
dim_if_not!(
self,
compare_vals("t", self.time_to_p2, self.time_to_p2_target)
),
dim_if_not!(
self,
format!("{:.1?}/{}", self.damage_per_turn_p2, self.health_p2)
.to_cell()
.fg(Color::DarkGrey)
),
dim_if_not!(
self,
compare_vals("t", self.time_to_kill, self.time_to_kill_target)
),
dim_if_not!(
self,
format!(
"[{:.0} & {:.0}] ⇝ {}",
self.damage_through_p1,
self.damage_per_turn_p2,
fmt_target(self.time_to_kill_through)
)
.to_cell()
.fg(Color::DarkGrey),
compare_vals("t", self.time_to_armorbreak, self.time_to_armorbreak_target),
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),
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),
format!(
"[{:.0} & {:.0}] ⇝ {}",
self.damage_through_p1,
self.damage_per_turn_p2,
fmt_target(self.time_to_kill_through)
)
.to_cell()
.fg(Color::DarkGrey),
.fg(Color::DarkGrey)
),
];
row.into()
}

View File

@ -438,6 +438,9 @@ pub struct CreatureBalancing {
#[REAL]
/// (FIXED) The number of players this fight was designed for
pub player_groupsize: f64,
#[INTEGER]
/// (FIXED) The average number of defence dice the creature will be using
pub average_defensive_dices: i64,
}
/// Balancing info on all the player depending on their level

View File

@ -244,10 +244,10 @@ master_part = '''
\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} & & \rb{Bon. Phy} {{#if stats.elemental_bonus_dmg}}& \rb{Bon. Élém} {{/if}}\\
{{#each init_full}}
{{#if @index}}
\SetCell{font=\footnotesize} $t_{{(plus @index 1)}} $ & ${{{p1_value}}} $ & {{{pt1_actions}}} & ${{{p2_value}}} $ & {{{p2_actions}}} \\
\SetCell{font=\footnotesize} $i_{{(plus @index 1)}} $ & ${{{p1_value}}} $ & {{{pt1_actions}}} & ${{{p2_value}}} $ & {{{p2_actions}}} \\
{{else}}
{{#with ../stats~}}
\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}}} $ & & ${{{physical_bonus_dmg}}} $ {{#if elemental_bonus_dmg}} & ${{elemental_bonus_dmg}} $ {{/if}} \\
\SetCell{font=\footnotesize} $i_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}}} $ & & ${{{physical_bonus_dmg}}} $ {{#if elemental_bonus_dmg}} & ${{elemental_bonus_dmg}} $ {{/if}} \\
{{/with}}
{{/if}}
{{/each}}

@ -1 +1 @@
Subproject commit 6b764e823b4b2d1cff73665c23ae05392063689b
Subproject commit e13cb0197f108b40c51b5ab5a16cc5702d5db8c5