17,101
edits
m (_formatLootTable: Apply secondary sort on item ID in addition to primary sort on drop chance) |
(Revise Thieving NPC drop chances to display effective drop chance per successful attempt) |
||
Line 75: | Line 75: | ||
result = result * 10 | result = result * 10 | ||
elseif stat == 'lootTable' then | elseif stat == 'lootTable' then | ||
return p._formatLootTable(npc['lootTable']) | return p._formatLootTable(npc['lootTable'], 0.75) | ||
elseif stat == 'requirements' then | elseif stat == 'requirements' then | ||
if npc['level'] ~= nil then | if npc['level'] ~= nil then | ||
Line 87: | Line 87: | ||
end | end | ||
function p._formatLootTable(lootTableIn) | function p._formatLootTable(lootTableIn, chanceMultIn) | ||
-- Expects lootTableIn to be in format {{itemID_1, itemWeight_1}, ..., {itemID_n, itemWeight_n}} | -- Expects lootTableIn to be in format {{itemID_1, itemWeight_1}, ..., {itemID_n, itemWeight_n}} | ||
if Shared.tableCount(lootTableIn) == 0 then | if Shared.tableCount(lootTableIn) == 0 then | ||
Line 93: | Line 93: | ||
end | end | ||
local chanceMult = (chanceMultIn or 1) * 100 | |||
local lootTable = Shared.clone(lootTableIn) | local lootTable = Shared.clone(lootTableIn) | ||
-- Sort table from most to least common drop | -- Sort table from most to least common drop | ||
Line 112: | Line 113: | ||
-- Get the length (in characters) of the largest drop chance so that they can be right aligned | -- Get the length (in characters) of the largest drop chance so that they can be right aligned | ||
local maxDropLen = string.len(Shared.round(lootTable[1][2] / totalWeight * | local maxDropLen = string.len(Shared.round(lootTable[1][2] / totalWeight * chanceMult, 2, 2)) | ||
local returnPart = {} | local returnPart = {} | ||
for i, drop in pairs(lootTable) do | for i, drop in pairs(lootTable) do | ||
local item, itemText, dropChance = Items.getItemByID(drop[1]), nil, Shared.round(drop[2] / totalWeight * | local item, itemText, dropChance = Items.getItemByID(drop[1]), nil, Shared.round(drop[2] / totalWeight * chanceMult, 2, 2) | ||
if item == nil then | if item == nil then | ||
itemText = 'Unknown' | itemText = 'Unknown' |