Skip to content

Commit

Permalink
fix: loot factor generate random value
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas committed Dec 17, 2024
1 parent 34b6fa8 commit c71a9fa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
11 changes: 8 additions & 3 deletions data/libs/functions/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 10 additions & 4 deletions data/libs/functions/monstertype.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@ 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

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
Expand All @@ -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

Expand Down

0 comments on commit c71a9fa

Please sign in to comment.