From e33f820e43cf394eb76c19b320c62eb274098945 Mon Sep 17 00:00:00 2001 From: Albeleon Date: Tue, 17 Jul 2018 19:38:04 +0200 Subject: [PATCH] Clamp maximum damage depending of version (2k / 2k3). Problem: Damage or healing isn't clamped. In 2k it's 999 and in 2k3 it's 9999. Solution: Add a MaxDamageValue in Game_Battler that distinguises and returns each version, and then put in every damage, skill or healing aspect it's needed. --- src/game_battlealgorithm.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/game_battlealgorithm.cpp b/src/game_battlealgorithm.cpp index cd12370d61..e55c873b46 100644 --- a/src/game_battlealgorithm.cpp +++ b/src/game_battlealgorithm.cpp @@ -41,6 +41,10 @@ #include "sprite_battler.h" #include "utils.h" +static inline int MaxDamageValue() { + return Player::IsRPG2k() ? 999 : 9999; +} + static inline int ToHitPhysical(Game_Battler *source, Game_Battler *target, int to_hit) { // If target has Restriction "do_nothing", the attack always hits if (target->GetSignificantRestriction() == RPG::State::Restriction_do_nothing) { @@ -921,9 +925,6 @@ bool Game_BattleAlgorithm::Normal::Execute() { int change = (int)(std::ceil(effect * act_perc / 100.0)); effect += change; effect *= multiplier; - if(effect < 0) { - effect = 0; - } if (critical_hit) { effect *= 3; } else if(source->IsCharged()) { @@ -936,6 +937,9 @@ bool Game_BattleAlgorithm::Normal::Execute() { effect /= 2; } } + + effect = Utils::Clamp(effect, 0, MaxDamageValue()); + this->hp = effect; if (GetTarget()->GetHp() - this->hp <= 0) { @@ -1112,8 +1116,7 @@ bool Game_BattleAlgorithm::Skill::Execute() { effect += (effect * Utils::GetRandomNumber(-skill.variance, skill.variance) / 10); - if (effect < 0) - effect = 0; + effect = Utils::Clamp(effect, 0, MaxDamageValue()); if (skill.affect_hp) this->hp = std::max(0, std::min(effect, GetTarget()->GetMaxHp() - GetTarget()->GetHp())); @@ -1154,9 +1157,7 @@ bool Game_BattleAlgorithm::Skill::Execute() { effect += (effect * Utils::GetRandomNumber(-skill.variance, skill.variance) / 10); - if (effect < 0) { - effect = 0; - } + effect = Utils::Clamp(effect, 0, MaxDamageValue()); if (skill.affect_hp) { this->hp = effect / @@ -1692,11 +1693,11 @@ bool Game_BattleAlgorithm::SelfDestruct::Execute() { int change = (int)(std::ceil(effect * act_perc / 100.0)); effect += change; - if (effect < 0) - effect = 0; + effect /= GetTarget()->IsDefending() ? GetTarget()->HasStrongDefense() ? 4 : 2 : 1; + + effect = Utils::Clamp(effect, 0, MaxDamageValue()); - this->hp = effect / ( - GetTarget()->IsDefending() ? GetTarget()->HasStrongDefense() ? 4 : 2 : 1); + this->hp = effect; if (GetTarget()->GetHp() - this->hp <= 0) { // Death state