diff --git a/data/libs/functions/functions.lua b/data/libs/functions/functions.lua index 4b9a94968ca..58538fc1fa8 100644 --- a/data/libs/functions/functions.lua +++ b/data/libs/functions/functions.lua @@ -65,9 +65,14 @@ function getTitle(uid) return false end -function getLootRandom(modifier) - local multi = (configManager.getNumber(configKeys.RATE_LOOT) * SCHEDULE_LOOT_RATE) * (modifier or 1) - return math.random(0, MAX_LOOTCHANCE) * 100 / math.max(1, multi) +function getLootRandom() + local baseRateLoot = configManager.getNumber(configKeys.RATE_LOOT) + local scheduleRate = SCHEDULE_LOOT_RATE + + local multi = math.max(1, baseRateLoot * scheduleRate) + + local randomValue = math.random(0, MAX_LOOTCHANCE) + return randomValue * 100 / multi end local start = os.time() diff --git a/data/libs/functions/monstertype.lua b/data/libs/functions/monstertype.lua index 042fda08276..ee0d6429fbc 100644 --- a/data/libs/functions/monstertype.lua +++ b/data/libs/functions/monstertype.lua @@ -7,9 +7,9 @@ function MonsterType:generateLootRoll(config, resultTable, player) end local monsterLoot = self:getLoot() or {} - local factor = config.factor or 1.0 local uniqueItems = {} + local factor = config.factor or 1.0 if self:isRewardBoss() then factor = factor * SCHEDULE_BOSS_LOOT_RATE / 100 end @@ -17,12 +17,15 @@ function MonsterType:generateLootRoll(config, resultTable, player) local result = resultTable or {} for _, item in ipairs(monsterLoot) do local iType = ItemType(item.itemId) + if config.filter and not config.filter(iType, item.unique) then goto continue end + if uniqueItems[item.itemId] then goto continue end + if not result[item.itemId] then result[item.itemId] = { count = 0, gut = false } end @@ -33,12 +36,15 @@ function MonsterType:generateLootRoll(config, resultTable, player) logger.debug("Final chance for bag you desire: {}, original chance: {}", result[item.itemId].chance, chance) end + local dynamicFactor = factor * (math.random(95, 105) / 100) + local adjustedChance = item.chance * dynamicFactor + if config.gut and iType:getType() == ITEM_TYPE_CREATUREPRODUCT then - chance = math.ceil((chance * GLOBAL_CHARM_GUT) / 100) + adjustedChance = math.ceil((adjustedChance * GLOBAL_CHARM_GUT) / 100) end - local randValue = getLootRandom(factor) - if randValue >= chance then + local randValue = getLootRandom() + if randValue >= adjustedChance then goto continue end