MCPcopy Create free account
hub / github.com/diasurgical/DevilutionX / SpawnOnePremium

Function SpawnOnePremium

Source/items.cpp:1994–2065  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1992}
1993
1994void SpawnOnePremium(Item &premiumItem, int plvl, const Player &player)
1995{
1996 int strength = std::max(player.GetMaximumAttributeValue(CharacterAttribute::Strength), player._pStrength);
1997 int dexterity = std::max(player.GetMaximumAttributeValue(CharacterAttribute::Dexterity), player._pDexterity);
1998 int magic = std::max(player.GetMaximumAttributeValue(CharacterAttribute::Magic), player._pMagic);
1999 strength += strength / 5;
2000 dexterity += dexterity / 5;
2001 magic += magic / 5;
2002
2003 plvl = clamp(plvl, 1, 30);
2004
2005 int maxCount = 150;
2006 const bool unlimited = !gbIsHellfire; // TODO: This could lead to an infinite loop if a suitable item can never be generated
2007 for (int count = 0; unlimited || count < maxCount; count++) {
2008 premiumItem = {};
2009 premiumItem._iSeed = AdvanceRndSeed();
2010 SetRndSeed(premiumItem._iSeed);
2011 _item_indexes itemType = RndPremiumItem(player, plvl / 4, plvl);
2012 GetItemAttrs(premiumItem, itemType, plvl);
2013 GetItemBonus(player, premiumItem, plvl / 2, plvl, true, !gbIsHellfire);
2014
2015 if (!gbIsHellfire) {
2016 if (premiumItem._iIvalue <= MaxVendorValue) {
2017 break;
2018 }
2019 } else {
2020 int itemValue = 0;
2021 switch (premiumItem._itype) {
2022 case ItemType::LightArmor:
2023 case ItemType::MediumArmor:
2024 case ItemType::HeavyArmor: {
2025 const auto *const mostValuablePlayerArmor = player.GetMostValuableItem(
2026 [](const Item &item) {
2027 return IsAnyOf(item._itype, ItemType::LightArmor, ItemType::MediumArmor, ItemType::HeavyArmor);
2028 });
2029
2030 itemValue = mostValuablePlayerArmor == nullptr ? 0 : mostValuablePlayerArmor->_iIvalue;
2031 break;
2032 }
2033 case ItemType::Shield:
2034 case ItemType::Axe:
2035 case ItemType::Bow:
2036 case ItemType::Mace:
2037 case ItemType::Sword:
2038 case ItemType::Helm:
2039 case ItemType::Staff:
2040 case ItemType::Ring:
2041 case ItemType::Amulet: {
2042 const auto *const mostValuablePlayerItem = player.GetMostValuableItem(
2043 [filterType = premiumItem._itype](const Item &item) { return item._itype == filterType; });
2044
2045 itemValue = mostValuablePlayerItem == nullptr ? 0 : mostValuablePlayerItem->_iIvalue;
2046 break;
2047 }
2048 default:
2049 itemValue = 0;
2050 break;
2051 }

Callers 1

SpawnPremiumFunction · 0.85

Calls 9

AdvanceRndSeedFunction · 0.85
SetRndSeedFunction · 0.85
RndPremiumItemFunction · 0.85
GetItemAttrsFunction · 0.85
GetItemBonusFunction · 0.85
IsAnyOfFunction · 0.85
GetMostValuableItemMethod · 0.80
CanUseItemMethod · 0.80

Tested by

no test coverage detected