diff --git a/Source/objects.cpp b/Source/objects.cpp index b489fa3d7..4f47f6b3f 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -2524,21 +2524,12 @@ void OperateShrineCostOfWisdom(Player &player, SpellID spellId, diablo_message m } } - int maxBase = player._pMaxManaBase; - - if (maxBase < 0) { - // Fix bugged state; do not turn this into a "negative penalty" mana boost. + if (player._pMaxManaBase < 0) player._pMaxManaBase = 0; - maxBase = 0; - } - - const int penalty = maxBase / 10; // 10% of max base mana (>= 0) - player._pMaxManaBase -= penalty; // will remain >= 0 - player._pManaBase -= penalty; // may go negative, allowed - player._pMaxMana -= penalty; // may go negative, allowed - player._pMana -= penalty; // may go negative, allowed + const int penalty = player._pMaxManaBase / 10; + ModifyPlrManaCapacity(player, -penalty, true); RedrawEverything(); InitDiabloMsg(message); } diff --git a/Source/player.cpp b/Source/player.cpp index 1b6f14096..f0dac04eb 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -3374,6 +3374,25 @@ void ModifyPlrVit(Player &player, int l) } } +void ModifyPlrManaCapacity(Player &player, int delta, bool shiftCurrent) +{ + constexpr int MinManaBase = 0; + + const int newMaxBase = std::max(MinManaBase, player._pMaxManaBase + delta); + const int applied = newMaxBase - player._pMaxManaBase; + + player._pMaxManaBase = newMaxBase; + player._pMaxMana += applied; + + if (shiftCurrent) { + player._pManaBase += applied; + player._pMana += applied; + } else { + player._pManaBase = std::min(player._pManaBase, player._pMaxManaBase); + player._pMana = std::min(player._pMana, player._pMaxMana); + } +} + void SetPlayerHitPoints(Player &player, int val) { player._pHitPoints = val; diff --git a/Source/player.h b/Source/player.h index 5cc99ca19..521766150 100644 --- a/Source/player.h +++ b/Source/player.h @@ -990,6 +990,7 @@ void ModifyPlrStr(Player &player, int l); void ModifyPlrMag(Player &player, int l); void ModifyPlrDex(Player &player, int l); void ModifyPlrVit(Player &player, int l); +void ModifyPlrManaCapacity(Player &player, int delta, bool shiftCurrent); void SetPlayerHitPoints(Player &player, int val); void SetPlrStr(Player &player, int v); void SetPlrMag(Player &player, int v);