Skip to content

Commit

Permalink
Clamp maximum damage depending of version (2k / 2k3).
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Albeleon authored and fmatthew5876 committed Dec 8, 2018
1 parent c2aa100 commit e33f820
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/game_battlealgorithm.cpp
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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<int>(0, std::min<int>(effect, GetTarget()->GetMaxHp() - GetTarget()->GetHp()));
Expand Down Expand Up @@ -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 /
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e33f820

Please sign in to comment.