Browse Source

Update spell book requirements when refreshing stash items

pull/4930/head
ephphatha 4 years ago committed by Anders Jenbo
parent
commit
65de934b9c
  1. 17
      Source/items.cpp
  2. 11
      Source/items.h
  3. 2
      Source/qol/stash.cpp

17
Source/items.cpp

@ -4623,6 +4623,23 @@ void Item::SetNewAnimation(bool showAnimation)
}
}
void Item::updateRequiredStatsCacheForPlayer(const Player &player)
{
if (_itype == ItemType::Misc && _iMiscId == IMISC_BOOK) {
_iMinMag = spelldata[_iSpell].sMinInt;
int8_t spellLevel = player._pSplLvl[_iSpell];
while (spellLevel != 0) {
_iMinMag += 20 * _iMinMag / 100;
spellLevel--;
if (_iMinMag + 20 * _iMinMag / 100 > 255) {
_iMinMag = 255;
spellLevel = 0;
}
}
}
_iStatFlag = player.CanUseItem(*this);
}
void initItemGetRecords()
{
memset(itemrecord, 0, sizeof(itemrecord));

11
Source/items.h

@ -171,6 +171,9 @@ enum icreateinfo_flag2 {
// All item animation frames have this width.
constexpr int ItemAnimWidth = 96;
// Defined in player.h, forward declared here to allow for functions which operate in the context of a player.
struct Player;
struct Item {
/** Randomly generated identifier */
int32_t _iSeed = 0;
@ -396,6 +399,12 @@ struct Item {
* @param showAnimation Definies if the Animation (Flipping) is shown or if only the final Frame (item on the ground) is shown
*/
void SetNewAnimation(bool showAnimation);
/**
* @brief If this item is a spell book, calculates the magic requirement to learn a new level, then for all items sets _iStatFlag
* @param player Player to compare stats against requirements
*/
void updateRequiredStatsCacheForPlayer(const Player &player);
};
struct ItemGetRecordStruct {
@ -411,8 +420,6 @@ struct CornerStoneStruct {
Item item;
};
struct Player;
/** Contains the items on ground in the current game. */
extern Item Items[MAXITEMS + 1];
extern uint8_t ActiveItems[MAXITEMS];

2
Source/qol/stash.cpp

@ -563,7 +563,7 @@ void StashStruct::PreviousPage(unsigned offset)
void StashStruct::RefreshItemStatFlags()
{
for (auto &item : Stash.stashList) {
item._iStatFlag = MyPlayer->CanUseItem(item);
item.updateRequiredStatsCacheForPlayer(*MyPlayer);
}
}

Loading…
Cancel
Save