diff --git a/apps/freeablo/faworld/itemfactory.cpp b/apps/freeablo/faworld/itemfactory.cpp index f1ca6cebb..b98e2edaa 100644 --- a/apps/freeablo/faworld/itemfactory.cpp +++ b/apps/freeablo/faworld/itemfactory.cpp @@ -18,17 +18,20 @@ namespace FAWorld return newItem; } - std::unique_ptr ItemFactory::generateRandomItem(int32_t itemLevel) const + std::unique_ptr ItemFactory::generateRandomItem(int32_t itemLevel, ItemGenerationType generationType) const { - return generateRandomItem(itemLevel, [](const ItemBase&) { return true; }); + return generateRandomItem(itemLevel, generationType, [](const ItemBase&) { return true; }); } - std::unique_ptr ItemFactory::generateRandomItem(int32_t itemLevel, const ItemFilter& filter) const + std::unique_ptr ItemFactory::generateRandomItem(int32_t itemLevel, ItemGenerationType generationType, const ItemFilter& filter) const { + if (DebugSettings::itemGenerationType == DebugSettings::ItemGenerationType::AlwaysMagical) + generationType = ItemGenerationType::AlwaysMagical; + const ItemBase* itemBase = randomItemBase([&](const ItemBase& base) { bool ok = filter(base) && base.mQualityLevel <= itemLevel; - if (DebugSettings::itemGenerationType != DebugSettings::ItemGenerationType::Normal) + if (generationType != ItemGenerationType::Normal) ok = ok && base.getEquipType() != ItemEquipType::none; return ok; @@ -41,8 +44,7 @@ namespace FAWorld if (EquipmentItem* equipmentItem = item->getAsEquipmentItem()) { - bool magical = DebugSettings::itemGenerationType == DebugSettings::ItemGenerationType::AlwaysMagical || mRng.randomInRange(0, 99) <= 10 || - mRng.randomInRange(0, 99) <= itemLevel; + bool magical = generationType == ItemGenerationType::AlwaysMagical || mRng.randomInRange(0, 99) <= 10 || mRng.randomInRange(0, 99) <= itemLevel; if (magical) { diff --git a/apps/freeablo/faworld/itemfactory.h b/apps/freeablo/faworld/itemfactory.h index d939eea04..f465843a7 100644 --- a/apps/freeablo/faworld/itemfactory.h +++ b/apps/freeablo/faworld/itemfactory.h @@ -27,8 +27,15 @@ namespace FAWorld explicit ItemFactory(const DiabloExe::DiabloExe& exe, Random::Rng& rng); std::unique_ptr generateBaseItem(const std::string& id) const; - std::unique_ptr generateRandomItem(int32_t itemLevel) const; - std::unique_ptr generateRandomItem(int32_t itemLevel, const ItemFilter& filter) const; + + enum class ItemGenerationType + { + Normal, + OnlyBaseItems, + AlwaysMagical, + }; + std::unique_ptr generateRandomItem(int32_t itemLevel, ItemGenerationType generationType) const; + std::unique_ptr generateRandomItem(int32_t itemLevel, ItemGenerationType generationType, const ItemFilter& filter) const; const ItemBase* randomItemBase(const ItemFilter& filter) const; const ItemPrefixOrSuffixBase* randomPrefixOrSuffixBase(const ItemPrefixOrSuffixFilter& filter) const; diff --git a/apps/freeablo/faworld/monster.cpp b/apps/freeablo/faworld/monster.cpp index 1a7cf8be9..476255cf4 100644 --- a/apps/freeablo/faworld/monster.cpp +++ b/apps/freeablo/faworld/monster.cpp @@ -144,7 +144,7 @@ namespace FAWorld } else { - item = mWorld.getItemFactory().generateRandomItem(mStats.mLevel); + item = mWorld.getItemFactory().generateRandomItem(mStats.mLevel, ItemFactory::ItemGenerationType::Normal); } getLevel()->dropItemClosestEmptyTile(item, *this, getPos().current(), Misc::Direction(Misc::Direction8::none)); diff --git a/apps/freeablo/faworld/storedata.cpp b/apps/freeablo/faworld/storedata.cpp index 7c6db0152..9dc64a401 100644 --- a/apps/freeablo/faworld/storedata.cpp +++ b/apps/freeablo/faworld/storedata.cpp @@ -8,18 +8,17 @@ namespace FAWorld { StoreData::StoreData(const ItemFactory& itemFactory) : mItemFactory(itemFactory) {} - void StoreData::regenerateGriswoldBasicItems(int32_t ilvl, Random::Rng& rng) + void StoreData::generateGriswoldBasicItems(int32_t itemLevel, Random::Rng& rng) { int32_t count = rng.randomInRange(10, 20); griswoldBasicItems.resize(count); - for (auto& item : griswoldBasicItems) + for (StoreItem& item : griswoldBasicItems) { - const ItemBase* itemBase = mItemFactory.randomItemBase([&](const ItemBase& base) { + item.item = mItemFactory.generateRandomItem(itemLevel, ItemFactory::ItemGenerationType::OnlyBaseItems, [&](const ItemBase& base) { static const auto excludedTypes = {ItemType::misc, ItemType::gold, ItemType::staff, ItemType::ring, ItemType::amulet}; - return base.mQualityLevel <= ilvl && std::count(excludedTypes.begin(), excludedTypes.end(), base.mType) == 0; + return std::count(excludedTypes.begin(), excludedTypes.end(), base.mType) == 0; }); - item.item = itemBase->createItem(); item.item->init(); item.storeId = mNextItemId; mNextItemId++; diff --git a/apps/freeablo/faworld/storedata.h b/apps/freeablo/faworld/storedata.h index f874cda7e..a642bf066 100644 --- a/apps/freeablo/faworld/storedata.h +++ b/apps/freeablo/faworld/storedata.h @@ -24,7 +24,7 @@ namespace FAWorld uint32_t storeId = 0; }; - /// class for storing and regenerating items sold in various stores + /// class for storing items sold in various stores class StoreData { public: @@ -33,7 +33,7 @@ namespace FAWorld void save(FASaveGame::GameSaver& saver) const; void load(FASaveGame::GameLoader& loader); - void regenerateGriswoldBasicItems(int32_t base, Random::Rng& rng); + void generateGriswoldBasicItems(int32_t itemLevel, Random::Rng& rng); public: std::vector griswoldBasicItems; diff --git a/apps/freeablo/faworld/world.cpp b/apps/freeablo/faworld/world.cpp index 15a886c44..e376fdd20 100644 --- a/apps/freeablo/faworld/world.cpp +++ b/apps/freeablo/faworld/world.cpp @@ -33,10 +33,10 @@ namespace FAWorld this->setupObjectIdMappers(); if (mDiabloExe.isLoaded()) - regenerateStoreItems(); + generateStoreItems(); } - void World::regenerateStoreItems() { mStoreData->regenerateGriswoldBasicItems(10 /*placeholder*/, *mRng.get()); } + void World::generateStoreItems() { mStoreData->generateGriswoldBasicItems(10 /*placeholder*/, *mRng.get()); } void World::load(FASaveGame::GameLoader& loader) { diff --git a/apps/freeablo/faworld/world.h b/apps/freeablo/faworld/world.h index 5a6f9e5f6..173f2f530 100644 --- a/apps/freeablo/faworld/world.h +++ b/apps/freeablo/faworld/world.h @@ -74,7 +74,7 @@ namespace FAWorld void setLevel(int32_t levelNum, bool upStairsPos = true); GameLevel* getLevel(size_t level); void insertLevel(size_t level, GameLevel* gameLevel); - void regenerateStoreItems(); + void generateStoreItems(); Actor* getActorAt(const Misc::Point& point);