Skip to content

Commit

Permalink
Shop prices
Browse files Browse the repository at this point in the history
  • Loading branch information
kphoenix137 committed Nov 12, 2024
1 parent a9849dd commit 9ce6e95
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 30 deletions.
14 changes: 7 additions & 7 deletions Source/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1958,7 +1958,7 @@ void SpawnOnePremium(Item &premiumItem, int plvl, const Player &player)
GetItemBonus(player, premiumItem, plvl / 2, plvl, true, !gbIsHellfire);

if (!gbIsHellfire) {
if (premiumItem._iIvalue <= 140000) {
if (premiumItem._iIvalue <= MAX_VENDOR_VALUE) {
break;
}
} else {
Expand Down Expand Up @@ -1995,7 +1995,7 @@ void SpawnOnePremium(Item &premiumItem, int plvl, const Player &player)
break;
}
itemValue = itemValue * 4 / 5; // avoids forced int > float > int conversion
if (premiumItem._iIvalue <= 200000
if (premiumItem._iIvalue <= MAX_VENDOR_VALUE_HF
&& premiumItem._iMinStr <= strength
&& premiumItem._iMinMag <= magic
&& premiumItem._iMinDex <= dexterity
Expand Down Expand Up @@ -4371,10 +4371,10 @@ void SpawnSmith(int lvl)
{
constexpr int PinnedItemCount = 0;

int maxValue = 140000;
int maxValue = MAX_VENDOR_VALUE;
int maxItems = 19;
if (gbIsHellfire) {
maxValue = 200000;
maxValue = MAX_VENDOR_VALUE_HF;
maxItems = 24;
}

Expand Down Expand Up @@ -4442,7 +4442,7 @@ void SpawnWitch(int lvl)
int bookCount = 0;
const int pinnedBookCount = gbIsHellfire ? RandomIntLessThan(MaxPinnedBookCount) : 0;
const int itemCount = RandomIntBetween(10, gbIsHellfire ? 24 : 17);
const int maxValue = gbIsHellfire ? 200000 : 140000;
const int maxValue = gbIsHellfire ? MAX_VENDOR_VALUE_HF : MAX_VENDOR_VALUE;

for (int i = 0; i < WITCH_ITEMS; i++) {
Item &item = WitchItems[i];
Expand Down Expand Up @@ -4527,7 +4527,7 @@ void SpawnBoy(int lvl)
GetItemBonus(*MyPlayer, BoyItem, lvl, 2 * lvl, true, true);

if (!gbIsHellfire) {
if (BoyItem._iIvalue > 90000) {
if (BoyItem._iIvalue > MAX_BOY_VALUE) {
keepgoing = true; // prevent breaking the do/while loop too early by failing hellfire's condition in while
continue;
}
Expand Down Expand Up @@ -4602,7 +4602,7 @@ void SpawnBoy(int lvl)
}
} while (keepgoing
|| ((
BoyItem._iIvalue > 200000
BoyItem._iIvalue > MAX_BOY_VALUE_HF
|| BoyItem._iMinStr > strength
|| BoyItem._iMinMag > magic
|| BoyItem._iMinDex > dexterity
Expand Down
5 changes: 5 additions & 0 deletions Source/items.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ namespace devilution {
// Item indestructible durability
#define DUR_INDESTRUCTIBLE 255

#define MAX_VENDOR_VALUE 140000
#define MAX_VENDOR_VALUE_HF 200000
#define MAX_BOY_VALUE 90000
#define MAX_BOY_VALUE_HF 200000

enum item_quality : uint8_t {
ITEM_QUALITY_NORMAL,
ITEM_QUALITY_MAGIC,
Expand Down
16 changes: 15 additions & 1 deletion Source/items/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ bool IsTownItemValid(uint16_t iCreateInfo, uint8_t maxCharacterLevel)
return level <= maxTownItemLevel;
}

bool IsShopPriceValid(const Item &item)
{
const int boyPriceLimit = gbIsHellfire ? MAX_BOY_VALUE_HF : MAX_BOY_VALUE;
if ((item._iCreateInfo & CF_BOY) != 0 && item._iIvalue > boyPriceLimit)
return false;

const uint16_t smithOrWitch = CF_SMITH | CF_SMITHPREMIUM | CF_WITCH;
const int smithAndWitchPriceLimit = gbIsHellfire ? MAX_VENDOR_VALUE_HF : MAX_VENDOR_VALUE;
if ((item._iCreateInfo & smithOrWitch) != 0 && item._iIvalue > smithAndWitchPriceLimit)
return false;

return true;
}

bool IsUniqueMonsterItemValid(uint16_t iCreateInfo, uint32_t dwBuff)
{
const uint8_t level = iCreateInfo & CF_LEVEL;
Expand Down Expand Up @@ -127,7 +141,7 @@ bool IsItemValid(const Player &player, const Item &item)
isValid = isValid && IsCreationFlagComboValid(item._iCreateInfo);

if ((item._iCreateInfo & CF_TOWN) != 0)
isValid = isValid && IsTownItemValid(item._iCreateInfo, player.getMaxCharacterLevel());
isValid = isValid && IsTownItemValid(item._iCreateInfo, player.getMaxCharacterLevel()) && IsShopPriceValid(item);
else if ((item._iCreateInfo & CF_USEFUL) == CF_UPER15)
isValid = isValid && IsUniqueMonsterItemValid(item._iCreateInfo, item.dwBuff);

Expand Down
1 change: 1 addition & 0 deletions Source/items/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace devilution {

bool IsCreationFlagComboValid(uint16_t iCreateInfo);
bool IsTownItemValid(uint16_t iCreateInfo, uint8_t maxCharacterLevel);
bool IsShopPriceValid(const Item &item);
bool IsUniqueMonsterItemValid(uint16_t iCreateInfo, uint32_t dwBuff);
bool IsDungeonItemValid(uint16_t iCreateInfo, uint32_t dwBuff);
bool IsItemValid(const Player &player, const Item &item);
Expand Down
22 changes: 0 additions & 22 deletions Source/loadsave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,24 +969,6 @@ bool LevelFileExists(SaveWriter &archive)
return archive.HasFile(szName);
}

bool IsShopPriceValid(const Item &item)
{
const int boyPriceLimit = 90000;
if (!gbIsHellfire && (item._iCreateInfo & CF_BOY) != 0 && item._iIvalue > boyPriceLimit)
return false;

const int premiumPriceLimit = 140000;
if (!gbIsHellfire && (item._iCreateInfo & CF_SMITHPREMIUM) != 0 && item._iIvalue > premiumPriceLimit)
return false;

const uint16_t smithOrWitch = CF_SMITH | CF_WITCH;
const int smithAndWitchPriceLimit = gbIsHellfire ? 200000 : 140000;
if ((item._iCreateInfo & smithOrWitch) != 0 && item._iIvalue > smithAndWitchPriceLimit)
return false;

return true;
}

void LoadMatchingItems(LoadHelper &file, const Player &player, const int n, Item *pItem)
{
Item heroItem;
Expand All @@ -1012,10 +994,6 @@ void LoadMatchingItems(LoadHelper &file, const Player &player, const int n, Item
unpackedItem._iMaxCharges = std::clamp<int>(heroItem._iMaxCharges, 0, unpackedItem._iMaxCharges);
unpackedItem._iCharges = std::clamp<int>(heroItem._iCharges, 0, unpackedItem._iMaxCharges);
}
if (!IsShopPriceValid(unpackedItem)) {
unpackedItem.clear();
continue;
}
if (gbIsHellfire) {
unpackedItem._iPLToHit = ClampToHit(unpackedItem, heroItem._iPLToHit); // Oil of Accuracy
unpackedItem._iMaxDam = ClampMaxDam(unpackedItem, heroItem._iMaxDam); // Oil of Sharpness
Expand Down

0 comments on commit 9ce6e95

Please sign in to comment.