17,105
edits
(getSpecAttackMaxHit: Initialize variable to avoid errors) |
(getMonsterDrops: Fix weight sorting & add secondary sort on item name) |
||
Line 757: | Line 757: | ||
--Sort the loot table by weight in descending order | --Sort the loot table by weight in descending order | ||
table.sort( | local lootTable = Shared.shallowClone(monster.lootTable) | ||
for i, row in ipairs( | table.sort(lootTable, function(a, b) | ||
if a.weight == b.weight then | |||
local aItem, bItem = Items.getItemByID(a.itemID), Items.getItemByID(b.itemID) | |||
if aItem ~= nil and bItem ~= nil then | |||
return aItem.name < bItem.name | |||
else | |||
return a.itemID < b.itemID | |||
end | |||
else | |||
return a.weight > b.weight | |||
end | |||
end) | |||
for i, row in ipairs(lootTable) do | |||
local thisItem = Items.getItemByID(row.itemID) | local thisItem = Items.getItemByID(row.itemID) | ||