Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove vendor price limits #7690

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 64 additions & 83 deletions Source/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1966,51 +1966,47 @@ void SpawnOnePremium(Item &premiumItem, int plvl, const Player &player)
GetItemAttrs(premiumItem, itemType, plvl);
GetItemBonus(player, premiumItem, plvl / 2, plvl, true, !gbIsHellfire);

if (!gbIsHellfire) {
if (premiumItem._iIvalue <= MaxVendorValue) {
break;
}
} else {
int itemValue = 0;
switch (premiumItem._itype) {
case ItemType::LightArmor:
case ItemType::MediumArmor:
case ItemType::HeavyArmor: {
const auto *const mostValuablePlayerArmor = player.GetMostValuableItem(
[](const Item &item) {
return IsAnyOf(item._itype, ItemType::LightArmor, ItemType::MediumArmor, ItemType::HeavyArmor);
});

itemValue = mostValuablePlayerArmor == nullptr ? 0 : mostValuablePlayerArmor->_iIvalue;
break;
}
case ItemType::Shield:
case ItemType::Axe:
case ItemType::Bow:
case ItemType::Mace:
case ItemType::Sword:
case ItemType::Helm:
case ItemType::Staff:
case ItemType::Ring:
case ItemType::Amulet: {
const auto *const mostValuablePlayerItem = player.GetMostValuableItem(
[filterType = premiumItem._itype](const Item &item) { return item._itype == filterType; });

itemValue = mostValuablePlayerItem == nullptr ? 0 : mostValuablePlayerItem->_iIvalue;
break;
}
default:
itemValue = 0;
break;
}
itemValue = itemValue * 4 / 5; // avoids forced int > float > int conversion
if (premiumItem._iIvalue <= MaxVendorValueHf
&& premiumItem._iMinStr <= strength
&& premiumItem._iMinMag <= magic
&& premiumItem._iMinDex <= dexterity
&& premiumItem._iIvalue >= itemValue) {
break;
}
if (!gbIsHellfire)
break;

int itemValue = 0;
switch (premiumItem._itype) {
case ItemType::LightArmor:
case ItemType::MediumArmor:
case ItemType::HeavyArmor: {
const auto *const mostValuablePlayerArmor = player.GetMostValuableItem(
[](const Item &item) {
return IsAnyOf(item._itype, ItemType::LightArmor, ItemType::MediumArmor, ItemType::HeavyArmor);
});

itemValue = mostValuablePlayerArmor == nullptr ? 0 : mostValuablePlayerArmor->_iIvalue;
break;
}
case ItemType::Shield:
case ItemType::Axe:
case ItemType::Bow:
case ItemType::Mace:
case ItemType::Sword:
case ItemType::Helm:
case ItemType::Staff:
case ItemType::Ring:
case ItemType::Amulet: {
const auto *const mostValuablePlayerItem = player.GetMostValuableItem(
[filterType = premiumItem._itype](const Item &item) { return item._itype == filterType; });

itemValue = mostValuablePlayerItem == nullptr ? 0 : mostValuablePlayerItem->_iIvalue;
break;
}
default:
itemValue = 0;
break;
}
itemValue = itemValue * 4 / 5; // avoids forced int > float > int conversion
if (premiumItem._iMinStr <= strength
&& premiumItem._iMinMag <= magic
&& premiumItem._iMinDex <= dexterity
&& premiumItem._iIvalue >= itemValue) {
break;
}
}
premiumItem._iCreateInfo = plvl | CF_SMITHPREMIUM;
Expand Down Expand Up @@ -4390,24 +4386,19 @@ void SpawnSmith(int lvl)
{
constexpr int PinnedItemCount = 0;

int maxValue = MaxVendorValue;
int maxItems = 19;
if (gbIsHellfire) {
maxValue = MaxVendorValueHf;
if (gbIsHellfire)
maxItems = 24;
}

int iCnt = RandomIntBetween(10, maxItems);
for (int i = 0; i < iCnt; i++) {
Item &newItem = SmithItems[i];

do {
newItem = {};
newItem._iSeed = AdvanceRndSeed();
SetRndSeed(newItem._iSeed);
_item_indexes itemData = RndSmithItem(*MyPlayer, lvl);
GetItemAttrs(newItem, itemData, lvl);
} while (newItem._iIvalue > maxValue);
newItem = {};
newItem._iSeed = AdvanceRndSeed();
SetRndSeed(newItem._iSeed);
_item_indexes itemData = RndSmithItem(*MyPlayer, lvl);
GetItemAttrs(newItem, itemData, lvl);

newItem._iCreateInfo = lvl | CF_SMITH;
newItem._iIdentified = true;
Expand Down Expand Up @@ -4461,7 +4452,6 @@ 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 ? MaxVendorValueHf : MaxVendorValue;

for (int i = 0; i < WITCH_ITEMS; i++) {
Item &item = WitchItems[i];
Expand Down Expand Up @@ -4496,20 +4486,18 @@ void SpawnWitch(int lvl)
continue;
}

do {
item = {};
item._iSeed = AdvanceRndSeed();
SetRndSeed(item._iSeed);
_item_indexes itemData = RndWitchItem(*MyPlayer, lvl);
GetItemAttrs(item, itemData, lvl);
int maxlvl = -1;
if (GenerateRnd(100) <= 5)
maxlvl = 2 * lvl;
if (maxlvl == -1 && item._iMiscId == IMISC_STAFF)
maxlvl = 2 * lvl;
if (maxlvl != -1)
GetItemBonus(*MyPlayer, item, maxlvl / 2, maxlvl, true, true);
} while (item._iIvalue > maxValue);
item = {};
item._iSeed = AdvanceRndSeed();
SetRndSeed(item._iSeed);
_item_indexes itemData = RndWitchItem(*MyPlayer, lvl);
GetItemAttrs(item, itemData, lvl);
int maxlvl = -1;
if (GenerateRnd(100) <= 5)
maxlvl = 2 * lvl;
if (maxlvl == -1 && item._iMiscId == IMISC_STAFF)
maxlvl = 2 * lvl;
if (maxlvl != -1)
GetItemBonus(*MyPlayer, item, maxlvl / 2, maxlvl, true, true);

item._iCreateInfo = lvl | CF_WITCH;
item._iIdentified = true;
Expand Down Expand Up @@ -4537,21 +4525,15 @@ void SpawnBoy(int lvl)
if (BoyItemLevel >= (lvl / 2) && !BoyItem.isEmpty())
return;
do {
keepgoing = false;
BoyItem = {};
BoyItem._iSeed = AdvanceRndSeed();
SetRndSeed(BoyItem._iSeed);
_item_indexes itype = RndBoyItem(*MyPlayer, lvl);
GetItemAttrs(BoyItem, itype, lvl);
GetItemBonus(*MyPlayer, BoyItem, lvl, 2 * lvl, true, true);

if (!gbIsHellfire) {
if (BoyItem._iIvalue > MaxBoyValue) {
keepgoing = true; // prevent breaking the do/while loop too early by failing hellfire's condition in while
continue;
}
if (!gbIsHellfire)
break;
}

ivalue = 0;

Expand Down Expand Up @@ -4619,14 +4601,13 @@ void SpawnBoy(int lvl)
break;
}
}
} while (keepgoing
|| ((
BoyItem._iIvalue > MaxBoyValueHf
|| BoyItem._iMinStr > strength
} while (
(
BoyItem._iMinStr > strength
|| BoyItem._iMinMag > magic
|| BoyItem._iMinDex > dexterity
|| BoyItem._iIvalue < ivalue)
&& count < 250));
&& count < 250);
BoyItem._iCreateInfo = lvl | CF_BOY;
BoyItem._iIdentified = true;
BoyItemLevel = lvl / 2;
Expand Down
5 changes: 0 additions & 5 deletions Source/items.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ namespace devilution {
// Item indestructible durability
#define DUR_INDESTRUCTIBLE 255

constexpr int MaxVendorValue = 140000;
constexpr int MaxVendorValueHf = 200000;
constexpr int MaxBoyValue = 90000;
constexpr int MaxBoyValueHf = 200000;

enum item_quality : uint8_t {
ITEM_QUALITY_NORMAL,
ITEM_QUALITY_MAGIC,
Expand Down
20 changes: 1 addition & 19 deletions Source/items/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,6 @@ bool IsTownItemValid(uint16_t iCreateInfo, const Player &player)
return level <= maxTownItemLevel;
}

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

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

const uint16_t smithOrWitch = CF_SMITH | CF_WITCH;
const int smithAndWitchPriceLimit = gbIsHellfire ? MaxVendorValueHf : MaxVendorValue;
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 @@ -163,7 +145,7 @@ bool IsItemValid(const Player &player, const Item &item)
if (item.IDidx != IDI_GOLD && !IsCreationFlagComboValid(item._iCreateInfo))
return false;
if ((item._iCreateInfo & CF_TOWN) != 0)
return IsTownItemValid(item._iCreateInfo, player) && IsShopPriceValid(item);
return IsTownItemValid(item._iCreateInfo, player);
if ((item._iCreateInfo & CF_USEFUL) == CF_UPER15)
return IsUniqueMonsterItemValid(item._iCreateInfo, item.dwBuff);
if ((item.dwBuff & CF_HELLFIRE) != 0 && AllItemsList[item.IDidx].iMiscId == IMISC_BOOK)
Expand Down
1 change: 0 additions & 1 deletion Source/items/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace devilution {

bool IsCreationFlagComboValid(uint16_t iCreateInfo);
bool IsTownItemValid(uint16_t iCreateInfo, const Player &player);
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
Loading