[Scaling/Bug Fix] Scaling where min and max damage was bugged (#3514)

* [Scaling/Bug Fix] Scaling where min and max damage were both 0 tossed out min_dmg

* Clamp values so independant calls dont leave us in odd state
This commit is contained in:
Paul Coene 2023-07-31 21:00:48 -04:00 committed by GitHub
parent 2da7ddad57
commit 6cff433d23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 34 deletions

View File

@ -2583,30 +2583,16 @@ void NPC::ModifyNPCStat(const std::string& stat, const std::string& value)
} }
else if (stat_lower == "min_hit") { else if (stat_lower == "min_hit") {
min_dmg = Strings::ToInt(value); min_dmg = Strings::ToInt(value);
// Clamp max_dmg to be >= min_dmg
// TODO: fix DB max_dmg = std::max(min_dmg, max_dmg);
if (min_dmg > max_dmg) {
const auto temporary_damage = max_dmg;
max_dmg = min_dmg;
min_dmg = temporary_damage;
}
base_damage = round((max_dmg - min_dmg) / 1.9); base_damage = round((max_dmg - min_dmg) / 1.9);
min_damage = min_dmg - round(base_damage / 10.0); min_damage = min_dmg - round(base_damage / 10.0);
return; return;
} }
else if (stat_lower == "max_hit") { else if (stat_lower == "max_hit") {
max_dmg = Strings::ToInt(value); max_dmg = Strings::ToInt(value);
// Clamp min_dmg to be <= max_dmg
// TODO: fix DB min_dmg = std::min(min_dmg, max_dmg);
if (max_dmg < min_dmg) {
const auto temporary_damage = min_dmg;
min_dmg = max_dmg;
max_dmg = temporary_damage;
}
base_damage = round((max_dmg - min_dmg) / 1.9); base_damage = round((max_dmg - min_dmg) / 1.9);
min_damage = min_dmg - round(base_damage / 10.0); min_damage = min_dmg - round(base_damage / 10.0);
return; return;

View File

@ -135,31 +135,24 @@ void NpcScaleManager::ScaleNPC(
npc->ModifyNPCStat("phr", std::to_string(scale_data.physical_resist)); npc->ModifyNPCStat("phr", std::to_string(scale_data.physical_resist));
} }
auto min_damage_set = false; // If either is scaled, both need to be. The values for base_damage and min_damage will be in flux until
// both are complete.
if (always_scale || npc->GetMinDMG() == 0) { if (always_scale || npc->GetMinDMG() == 0 || npc->GetMaxDMG() == 0) {
int64 min_dmg = scale_data.min_dmg; int64 min_dmg = scale_data.min_dmg;
int64 max_dmg = scale_data.max_dmg;
if (RuleB(Combat, UseNPCDamageClassLevelMods)) { if (RuleB(Combat, UseNPCDamageClassLevelMods)) {
uint32 class_level_damage_mod = GetClassLevelDamageMod(npc->GetLevel(), npc->GetClass()); uint32 class_level_damage_mod = GetClassLevelDamageMod(npc->GetLevel(), npc->GetClass());
min_dmg = (min_dmg * class_level_damage_mod) / 220; min_dmg = (min_dmg * class_level_damage_mod) / 220;
max_dmg = (max_dmg * class_level_damage_mod) / 220;
LogNPCScaling("ClassLevelDamageMod::min_dmg base: [{}] calc: [{}]", scale_data.min_dmg, min_dmg);
} }
npc->ModifyNPCStat("min_hit", std::to_string(min_dmg)); npc->ModifyNPCStat("min_hit", std::to_string(min_dmg));
min_damage_set = true;
}
if (always_scale || npc->GetMaxDMG() == 0 || min_damage_set) {
int64 max_dmg = scale_data.max_dmg;
if (RuleB(Combat, UseNPCDamageClassLevelMods)) {
uint32 class_level_damage_mod = GetClassLevelDamageMod(npc->GetLevel(), npc->GetClass());
max_dmg = (scale_data.max_dmg * class_level_damage_mod) / 220;
LogNPCScaling("ClassLevelDamageMod::max_dmg base: [{}] calc: [{}]", scale_data.max_dmg, max_dmg);
}
npc->ModifyNPCStat("max_hit", std::to_string(max_dmg)); npc->ModifyNPCStat("max_hit", std::to_string(max_dmg));
LogNPCScaling("ClassLevelDamageMod::min_dmg base: [{}] calc: [{}]", scale_data.min_dmg, min_dmg);
LogNPCScaling("ClassLevelDamageMod::max_dmg base: [{}] calc: [{}]", scale_data.max_dmg, max_dmg);
} }
if (always_scale || (npc->GetHPRegen() == 0 && is_auto_scaled)) { if (always_scale || (npc->GetHPRegen() == 0 && is_auto_scaled)) {