Browse Source

fixes casting level 0 spell says "not enough mana" (#2568)

pull/2440/head
vladtepesch 5 years ago committed by GitHub
parent
commit
0e56e52c75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      Source/control.cpp
  2. 17
      Source/player.cpp
  3. 15
      Source/spells.cpp
  4. 9
      Source/spells.h

4
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;

17
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;

15
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)

9
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);

Loading…
Cancel
Save