From d671dcb0414495b72a27d3303f82b613c6f654e1 Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Sat, 3 Jan 2026 17:13:50 -0500 Subject: [PATCH 1/4] New Fn: ModifyPlrManaCapacity Used in OperateShrineCostOfWisdom --- Source/objects.cpp | 15 ++------------- Source/player.cpp | 18 ++++++++++++++++++ Source/player.h | 1 + 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Source/objects.cpp b/Source/objects.cpp index f4c89389f..471343ef3 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -2524,21 +2524,10 @@ 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. - player._pMaxManaBase = 0; - maxBase = 0; - } - + const int maxBase = std::max(0, player._pMaxManaBase); 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 - + ModifyPlrManaCapacity(player, -penalty); RedrawEverything(); InitDiabloMsg(message); } diff --git a/Source/player.cpp b/Source/player.cpp index 045070092..563339d1b 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -3372,6 +3372,24 @@ void ModifyPlrVit(Player &player, int l) } } +void ModifyPlrManaCapacity(Player &player, int l) +{ + // Repair bugged base; do not propagate this "fix" to other fields. + if (player._pMaxManaBase < 0) + player._pMaxManaBase = 0; + + // Clamp so base never goes below 0 after applying l. + const int newMaxBase = std::max(0, player._pMaxManaBase + l); + const int applied = newMaxBase - player._pMaxManaBase; // actual l after clamp + + player._pMaxManaBase = newMaxBase; + + // Apply the same actual l to the other mana fields (may go negative, allowed). + player._pManaBase += applied; + player._pMaxMana += applied; + player._pMana += applied; +} + void SetPlayerHitPoints(Player &player, int val) { player._pHitPoints = val; diff --git a/Source/player.h b/Source/player.h index 1758e2207..8a9f2d466 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 l); void SetPlayerHitPoints(Player &player, int val); void SetPlrStr(Player &player, int v); void SetPlrMag(Player &player, int v); From 39064741fc73d0b94a862eda4b7d9384c28081ab Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Sat, 3 Jan 2026 19:16:07 -0500 Subject: [PATCH 2/4] update --- Source/player.cpp | 26 +++++++++++++++----------- Source/player.h | 2 +- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Source/player.cpp b/Source/player.cpp index 563339d1b..21a7e7dfb 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -3372,22 +3372,26 @@ void ModifyPlrVit(Player &player, int l) } } -void ModifyPlrManaCapacity(Player &player, int l) +void ModifyPlrManaCapacity(Player &player, int delta, bool shiftCurrent) { - // Repair bugged base; do not propagate this "fix" to other fields. - if (player._pMaxManaBase < 0) - player._pMaxManaBase = 0; + constexpr int MinManaBase = 0; - // Clamp so base never goes below 0 after applying l. - const int newMaxBase = std::max(0, player._pMaxManaBase + l); - const int applied = newMaxBase - player._pMaxManaBase; // actual l after clamp + const int newMaxBase = std::max(MinManaBase, player._pMaxManaBase + delta); + const int applied = newMaxBase - player._pMaxManaBase; player._pMaxManaBase = newMaxBase; - - // Apply the same actual l to the other mana fields (may go negative, allowed). - player._pManaBase += applied; player._pMaxMana += applied; - player._pMana += 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); + } + + if (&player == MyPlayer) + RedrawComponent(PanelDrawComponent::Mana); } void SetPlayerHitPoints(Player &player, int val) diff --git a/Source/player.h b/Source/player.h index 8a9f2d466..8a5fce29a 100644 --- a/Source/player.h +++ b/Source/player.h @@ -990,7 +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 l); +void ModifyPlrManaCapacity(Player &player, int l, bool shiftCurrent); void SetPlayerHitPoints(Player &player, int val); void SetPlrStr(Player &player, int v); void SetPlrMag(Player &player, int v); From 089e157b4412412ced317c82b9ecfd6f2ee1fb7e Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Sat, 3 Jan 2026 19:17:57 -0500 Subject: [PATCH 3/4] Update player.h --- Source/player.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/player.h b/Source/player.h index 8a5fce29a..780a7dbff 100644 --- a/Source/player.h +++ b/Source/player.h @@ -990,7 +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 l, bool shiftCurrent); +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); From d0f0ba1fbd47116bc9e76c12d80e2209a040fbce Mon Sep 17 00:00:00 2001 From: Eric Robinson Date: Sat, 3 Jan 2026 19:24:47 -0500 Subject: [PATCH 4/4] update --- Source/objects.cpp | 8 +++++--- Source/player.cpp | 3 --- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Source/objects.cpp b/Source/objects.cpp index 471343ef3..b17260919 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -2524,10 +2524,12 @@ void OperateShrineCostOfWisdom(Player &player, SpellID spellId, diablo_message m } } - const int maxBase = std::max(0, player._pMaxManaBase); - const int penalty = maxBase / 10; // 10% of max base mana (>= 0) + if (player._pMaxManaBase < 0) + player._pMaxManaBase = 0; - ModifyPlrManaCapacity(player, -penalty); + const int penalty = player._pMaxManaBase / 10; + + ModifyPlrManaCapacity(player, -penalty, true); RedrawEverything(); InitDiabloMsg(message); } diff --git a/Source/player.cpp b/Source/player.cpp index 21a7e7dfb..e3c2cb110 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -3389,9 +3389,6 @@ void ModifyPlrManaCapacity(Player &player, int delta, bool shiftCurrent) player._pManaBase = std::min(player._pManaBase, player._pMaxManaBase); player._pMana = std::min(player._pMana, player._pMaxMana); } - - if (&player == MyPlayer) - RedrawComponent(PanelDrawComponent::Mana); } void SetPlayerHitPoints(Player &player, int val)