From 8ff115e593bfafaea34189231373f82a5d0677ac Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Mon, 27 Jul 2026 17:53:48 +0200 Subject: [PATCH] Dodges --- crates/monsters/Cargo.toml | 1 + .../src/monster_analysis/defense_analysis.rs | 148 +++++++++++++++--- crates/monsters/src/monster_structs.rs | 3 + ravenous_databases | 2 +- 4 files changed, 129 insertions(+), 25 deletions(-) diff --git a/crates/monsters/Cargo.toml b/crates/monsters/Cargo.toml index f4c5eec..2f751c8 100644 --- a/crates/monsters/Cargo.toml +++ b/crates/monsters/Cargo.toml @@ -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} diff --git a/crates/monsters/src/monster_analysis/defense_analysis.rs b/crates/monsters/src/monster_analysis/defense_analysis.rs index c0e018f..f393953 100644 --- a/crates/monsters/src/monster_analysis/defense_analysis.rs +++ b/crates/monsters/src/monster_analysis/defense_analysis.rs @@ -8,9 +8,8 @@ use crate::{ monster_structs::{CreatureBodyPart, FullMonster, PlayerBalancing, ProfileHSE, ProfileStance}, }; use config::monsters::BalanceArgs; -use indexmap::IndexMap; use more_fields::FieldsAsSlice; -use std::collections::HashMap; +use std::{collections::HashMap, ops::AddAssign}; pub(crate) fn display_player_attacks( args: &BalanceArgs, @@ -48,15 +47,94 @@ fn report_from_profile( .collect::>() } +#[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 { + 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 { - let ratio = creature.balancing.monster_groupsize / creature.balancing.player_groupsize; - let damage_done_p1 = damage_done_to_part(body_part, profile, Phases::P1); - let damage_done_p2 = damage_done_to_part(body_part, profile, Phases::P2); + // 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 @@ -121,11 +199,11 @@ pub fn value_resist(resist: &Option) -> 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, @@ -150,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); @@ -190,6 +262,7 @@ pub enum Phases { P2, } +#[derive(Default)] pub struct DamageDealtByPlayer { pub damage_a: f64, pub damage_b1: f64, @@ -201,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); diff --git a/crates/monsters/src/monster_structs.rs b/crates/monsters/src/monster_structs.rs index fdf2928..a506003 100644 --- a/crates/monsters/src/monster_structs.rs +++ b/crates/monsters/src/monster_structs.rs @@ -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 diff --git a/ravenous_databases b/ravenous_databases index 6b764e8..e13cb01 160000 --- a/ravenous_databases +++ b/ravenous_databases @@ -1 +1 @@ -Subproject commit 6b764e823b4b2d1cff73665c23ae05392063689b +Subproject commit e13cb0197f108b40c51b5ab5a16cc5702d5db8c5