From 32d39c65246b17fbf6b89d4a914beb04f02ee7e8 Mon Sep 17 00:00:00 2001 From: KPhoenix <68359262+kphoenix137@users.noreply.github.com> Date: Mon, 7 Feb 2022 04:14:54 -0500 Subject: [PATCH] Fix Stat Adjustment (#3898) This fixes a problem related to shrines. When a player with a base Magic or Vitality stat of 0 has their respective stat reduced below 0, they lose Mana/Life, and their stat is corrected to 0 without refunding them the lost Mana/Life. This will prevent stats from being modified to a value less than 0 in the first place. --- Source/player.cpp | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/Source/player.cpp b/Source/player.cpp index b47dfaeef..e20b87be0 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -3792,10 +3792,7 @@ void ModifyPlrStr(int p, int l) } auto &player = Players[p]; - int max = player.GetMaximumAttributeValue(CharacterAttribute::Strength); - if (player._pBaseStr + l > max) { - l = max - player._pBaseStr; - } + l = clamp(l, 0 - player._pBaseStr, player.GetMaximumAttributeValue(CharacterAttribute::Strength) - player._pBaseStr); player._pStrength += l; player._pBaseStr += l; @@ -3814,10 +3811,7 @@ void ModifyPlrMag(int p, int l) } auto &player = Players[p]; - int max = player.GetMaximumAttributeValue(CharacterAttribute::Magic); - if (player._pBaseMag + l > max) { - l = max - player._pBaseMag; - } + l = clamp(l, 0 - player._pBaseStr, player.GetMaximumAttributeValue(CharacterAttribute::Magic) - player._pBaseMag); player._pMagic += l; player._pBaseMag += l; @@ -3850,10 +3844,7 @@ void ModifyPlrDex(int p, int l) } auto &player = Players[p]; - int max = player.GetMaximumAttributeValue(CharacterAttribute::Dexterity); - if (player._pBaseDex + l > max) { - l = max - player._pBaseDex; - } + l = clamp(l, 0 - player._pBaseDex, player.GetMaximumAttributeValue(CharacterAttribute::Dexterity) - player._pBaseDex); player._pDexterity += l; player._pBaseDex += l; @@ -3871,10 +3862,7 @@ void ModifyPlrVit(int p, int l) } auto &player = Players[p]; - int max = player.GetMaximumAttributeValue(CharacterAttribute::Vitality); - if (player._pBaseVit + l > max) { - l = max - player._pBaseVit; - } + l = clamp(l, 0 - player._pBaseVit, player.GetMaximumAttributeValue(CharacterAttribute::Vitality) - player._pBaseVit); player._pVitality += l; player._pBaseVit += l;