From 0e56e52c75544a93905c6ff615cac3431e379cdc Mon Sep 17 00:00:00 2001 From: vladtepesch <1601159+vladtepesch@users.noreply.github.com> Date: Wed, 11 Aug 2021 21:52:00 +0200 Subject: [PATCH] fixes casting level 0 spell says "not enough mana" (#2568) --- Source/control.cpp | 4 ++-- Source/player.cpp | 17 ++++++++++++++--- Source/spells.cpp | 15 +++++++++------ Source/spells.h | 9 ++++++++- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/Source/control.cpp b/Source/control.cpp index 74ec923fd..26d32996e 100644 --- a/Source/control.cpp +++ b/Source/control.cpp @@ -491,7 +491,7 @@ spell_type GetSBookTrans(spell_id ii, bool townok) st = RSPLTYPE_SKILL; } if (st == RSPLTYPE_SPELL) { - if (!CheckSpell(MyPlayerId, ii, st, true)) { + if (CheckSpell(MyPlayerId, ii, st, true) != SpellCheckResult::Success) { st = RSPLTYPE_INVALID; } if ((char)(myPlayer._pSplLvl[ii] + myPlayer._pISplLvlAdd) <= 0) { @@ -668,7 +668,7 @@ void DrawSpell(const Surface &out) // BUGFIX: Move the next line into the if statement to avoid OOB (SPL_INVALID is -1) (fixed) if (st == RSPLTYPE_SPELL && spl != SPL_INVALID) { int tlvl = myPlayer._pISplLvlAdd + myPlayer._pSplLvl[spl]; - if (!CheckSpell(MyPlayerId, spl, st, true)) + if (CheckSpell(MyPlayerId, spl, st, true) != SpellCheckResult::Success) st = RSPLTYPE_INVALID; if (tlvl <= 0) st = RSPLTYPE_INVALID; diff --git a/Source/player.cpp b/Source/player.cpp index 331e3ced6..2e363e835 100644 --- a/Source/player.cpp +++ b/Source/player.cpp @@ -3556,11 +3556,12 @@ void CheckPlrSpell() return; } } - + SpellCheckResult spellcheck = SpellCheckResult::Success; switch (myPlayer._pRSplType) { case RSPLTYPE_SKILL: case RSPLTYPE_SPELL: - addflag = CheckSpell(MyPlayerId, rspell, myPlayer._pRSplType, false); + spellcheck = CheckSpell(MyPlayerId, rspell, myPlayer._pRSplType, false); + addflag = spellcheck == SpellCheckResult::Success; break; case RSPLTYPE_SCROLL: addflag = UseScroll(); @@ -3574,7 +3575,17 @@ void CheckPlrSpell() if (!addflag) { if (myPlayer._pRSplType == RSPLTYPE_SPELL) { - myPlayer.Say(HeroSpeech::NotEnoughMana); + switch (spellcheck) { + case SpellCheckResult::Fail_NoMana: + myPlayer.Say(HeroSpeech::NotEnoughMana); + break; + case SpellCheckResult::Fail_Level0: + myPlayer.Say(HeroSpeech::ICantCastThatYet); + break; + default: + myPlayer.Say(HeroSpeech::ICantDoThat); + break; + } LastMouseButtonAction = MouseActionType::None; } return; diff --git a/Source/spells.cpp b/Source/spells.cpp index ea62d8d4b..e77b5bc5a 100644 --- a/Source/spells.cpp +++ b/Source/spells.cpp @@ -196,28 +196,31 @@ void EnsureValidReadiedSpell(PlayerStruct &player) } } -bool CheckSpell(int id, spell_id sn, spell_type st, bool manaonly) +SpellCheckResult CheckSpell(int id, spell_id sn, spell_type st, bool manaonly) { #ifdef _DEBUG if (debug_mode_key_inverted_v) - return true; + return SpellCheckResult::Success; #endif if (!manaonly && pcurs != CURSOR_HAND) { - return false; + return SpellCheckResult::Fail_Busy; } if (st == RSPLTYPE_SKILL) { - return true; + return SpellCheckResult::Success; } if (GetSpellLevel(id, sn) <= 0) { - return false; + return SpellCheckResult::Fail_Level0; } auto &player = Players[id]; + if (player._pMana < GetManaAmount(player, sn)) { + return SpellCheckResult::Fail_NoMana; + } - return player._pMana >= GetManaAmount(player, sn); + return SpellCheckResult::Success; } void CastSpell(int id, int spl, int sx, int sy, int dx, int dy, int spllvl) diff --git a/Source/spells.h b/Source/spells.h index 92185f36a..8a6e113e3 100644 --- a/Source/spells.h +++ b/Source/spells.h @@ -9,9 +9,16 @@ namespace devilution { +enum class SpellCheckResult : uint8_t { + Success, + Fail_NoMana, + Fail_Level0, + Fail_Busy, +}; + int GetManaAmount(PlayerStruct &player, spell_id sn); void UseMana(int id, spell_id sn); -bool CheckSpell(int id, spell_id sn, spell_type st, bool manaonly); +SpellCheckResult CheckSpell(int id, spell_id sn, spell_type st, bool manaonly); void EnsureValidReadiedSpell(PlayerStruct &player); void CastSpell(int id, int spl, int sx, int sy, int dx, int dy, int spllvl); void DoResurrect(int pnum, int rid);