Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: loot factor generate random value #3181

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading