Skip to content

Commit

Permalink
Merge pull request #18 from jprzimba/improve-surprise-bags
Browse files Browse the repository at this point in the history
[IMPROVED] Bags System
  • Loading branch information
jprzimba authored Jan 8, 2025
2 parents 41524cc + 11cf14b commit 51d993a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 17 deletions.
5 changes: 5 additions & 0 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,11 @@ defaultRespawnTime = 60
deSpawnRange = 2
deSpawnRadius = 50

-- Surprise Bags
-- NOTE: set dropSurpriseBagsFromMonsters to false to disable drop surprise bags from monsters.
-- NOTE: Read data/items/bags.xml for more info.
dropSurpriseBagsFromMonsters = false

-- Stamina
staminaSystem = true
timeToRegenMinuteStamina = 3 * 60
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ function Morguthiswall.onUse(player, item, fromPosition, target, toPosition)
end

Morguthiswall:aid(10808)
Morguthiswall:register()
Morguthiswall:register()
12 changes: 9 additions & 3 deletions data/items/bags.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,27 @@
* If `chance` equals `maxRange`, the item will always drop.
- `maxRange`: Defines the range in which the item can drop, often used as the upper bound of a random roll.
- `maxAmount`: (Optional) Sets the maximum quantity of the item that can drop, if applicable.
- `monsterClass`: (Optional) Restricts the item drop to certain monster classes.
- `class`: (Optional) Restricts the item drop to certain monster classes.
- `raceId`: (Optional) Links the drop to a specific race or creature.
Examples:
- `<bag itemid="6571" name="Red Surprise Bag" chance="100" maxRange="1000"/>`
This bag has a 100 out of 1000 chance to drop, or 10%.
- `<bag itemid="3079" name="Boots of Haste" chance="100" maxRange="2000" monsterClass="Dragon"/>`
- `<bag itemid="3079" name="Boots of Haste" chance="100" maxRange="2000" class="Dragon"/>`
This item will drop only when a "Dragon" is defeated, with a 5% drop chance (100 out of 2000).
- `<bag itemid="3043" name="Crystal Coin" chance="100" maxAmount="100" maxRange="100"/>`
This bag has a 100 out of 100 chance (100%) to drop, with up to 100 Crystal Coins.
- `<bag itemid="3079" name="Boots of Haste" chance="50" maxRange="1000" raceId="1938"/>`
This item will drop with a 5% chance (50 out of 1000) but only for creatures with the race ID 1938 (Infernal Demon).
-->
<bag itemid="6571" name="Red Surprise Bag" chance="100" maxRange="1000"/>
<bag itemid="6570" name="Blue Surprise Bag" chance="100" maxRange="10000"/>
<bag itemid="3079" name="Boots of Haste" chance="100" maxRange="2000" monsterClass="Dragon"/>
<bag itemid="3079" name="Boots of Haste" chance="100" maxRange="2000" class="Dragon"/>
<bag itemid="6578" name="Party Hat" chance="100" maxAmount="100" maxRange="100" raceId="1938"/> <!-- Infernal Demon -->
<bag itemid="3043" name="Crystal Coin" chance="100" maxAmount="100" maxRange="100"/>
</bags>
2 changes: 1 addition & 1 deletion src/creatures/monsters/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2408,7 +2408,7 @@ void Monster::dropLoot(const std::shared_ptr<Container> &corpse, const std::shar
// Filter out items with chance <= 0
std::vector<const Items::BagItemInfo*> validBagItems;
for (const auto &bagItem : allBagItems) {
if (bagItem->chance > 0 && asLowerCaseString(mType->info.bestiaryClass) == asLowerCaseString(bagItem->monsterClass)) {
if (bagItem->chance > 0 && (asLowerCaseString(mType->info.bestiaryClass) == asLowerCaseString(bagItem->monsterClass) || mType->info.raceid == bagItem->monsterRaceId)) {
validBagItems.push_back(bagItem);
}
}
Expand Down
13 changes: 10 additions & 3 deletions src/items/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,18 @@ bool Items::loadFromXml() {
}

std::string monsterClass = "";
auto monsterClassAttr = nodeBags.attribute("monsterClass");
auto monsterClassAttr = nodeBags.attribute("class");
if (monsterClassAttr) {
monsterClass = monsterClassAttr.as_string();
}

setItemBag(itemId, itemName, chance, minAmount, maxAmount, minRange, maxRange, monsterClass);
uint32_t monsterRaceId = 0;
auto monsterRaceIdAttr = nodeBags.attribute("raceId");
if (monsterRaceIdAttr) {
monsterRaceId = pugi::cast<uint32_t>(monsterRaceIdAttr.value());
}

setItemBag(itemId, itemName, chance, minAmount, maxAmount, minRange, maxRange, monsterClass, monsterRaceId);
}

return true;
Expand Down Expand Up @@ -478,7 +484,7 @@ bool Items::hasItemType(size_t hasId) const {
return false;
}

void Items::setItemBag(uint16_t itemId, const std::string &itemName, uint32_t chance, uint32_t minAmount, uint32_t maxAmount, uint64_t minRange, uint64_t maxRange, const std::string &monsterClass) {
void Items::setItemBag(uint16_t itemId, const std::string &itemName, uint32_t chance, uint32_t minAmount, uint32_t maxAmount, uint64_t minRange, uint64_t maxRange, const std::string &monsterClass, uint32_t monsterRaceId) {
BagItemInfo itemInfo;
itemInfo.name = itemName;
itemInfo.id = itemId;
Expand All @@ -488,6 +494,7 @@ void Items::setItemBag(uint16_t itemId, const std::string &itemName, uint32_t ch
itemInfo.minRange = minRange;
itemInfo.maxRange = maxRange;
itemInfo.monsterClass = monsterClass;
itemInfo.monsterRaceId = monsterRaceId;
bagItems[itemId] = itemInfo;
}

Expand Down
19 changes: 10 additions & 9 deletions src/items/items.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,14 +379,15 @@ class ItemType {
class Items {
public:
struct BagItemInfo {
std::string name;
uint16_t id;
uint32_t chance;
uint32_t minAmount;
uint32_t maxAmount;
uint64_t minRange;
uint64_t maxRange;
std::string monsterClass;
std::string name = "";
uint16_t id = 0;
uint32_t chance = 0;
uint32_t minAmount = 1;
uint32_t maxAmount = 1;
uint64_t minRange = 0;
uint64_t maxRange = 0;
std::string monsterClass = "";
uint32_t monsterRaceId = 0;
};

using NameMap = std::unordered_multimap<std::string, uint16_t>;
Expand Down Expand Up @@ -470,7 +471,7 @@ class Items {
return allBagItems;
}

void setItemBag(uint16_t itemId, const std::string &itemName, uint32_t chance, uint32_t minAmount, uint32_t maxAmount, uint64_t minRange, uint64_t maxRange, const std::string &monsterClass);
void setItemBag(uint16_t itemId, const std::string &itemName, uint32_t chance, uint32_t minAmount, uint32_t maxAmount, uint64_t minRange, uint64_t maxRange, const std::string &monsterClass, uint32_t monsterRaceId);

private:
std::vector<ItemType> items;
Expand Down

0 comments on commit 51d993a

Please sign in to comment.