Browse Source

[gamepad] Avoid OOB on empty belt

pull/4246/head
Anders Jenbo 4 years ago
parent
commit
8235380ef9
  1. 22
      Source/controls/plrctrls.cpp

22
Source/controls/plrctrls.cpp

@ -1508,16 +1508,18 @@ void plrctrls_after_game_logic()
void UseBeltItem(int type) void UseBeltItem(int type)
{ {
for (int i = 0; i < MAXBELTITEMS; i++) { for (int i = 0; i < MAXBELTITEMS; i++) {
auto &myPlayer = Players[MyPlayerId]; Item &item = Players[MyPlayerId].SpdList[i];
const int id = AllItemsList[myPlayer.SpdList[i].IDidx].iMiscId; if (item.isEmpty()) {
const int spellId = AllItemsList[myPlayer.SpdList[i].IDidx].iSpell; continue;
if ((type == BLT_HEALING && (id == IMISC_HEAL || id == IMISC_FULLHEAL || (id == IMISC_SCROLL && spellId == SPL_HEAL))) }
|| (type == BLT_MANA && (id == IMISC_MANA || id == IMISC_FULLMANA))
|| id == IMISC_REJUV || id == IMISC_FULLREJUV) { bool isRejuvenation = IsAnyOf(item._iMiscId, IMISC_REJUV, IMISC_FULLREJUV);
if (!myPlayer.SpdList[i].isEmpty()) { bool isHealing = isRejuvenation || IsAnyOf(item._iMiscId, IMISC_HEAL, IMISC_FULLHEAL) || item.IsScrollOf(SPL_HEAL);
UseInvItem(MyPlayerId, INVITEM_BELT_FIRST + i); bool isMana = isRejuvenation || IsAnyOf(item._iMiscId, IMISC_MANA, IMISC_FULLMANA);
break;
} if ((type == BLT_HEALING && isHealing) || (type == BLT_MANA && isMana)) {
UseInvItem(MyPlayerId, INVITEM_BELT_FIRST + i);
break;
} }
} }
} }

Loading…
Cancel
Save