Module:Monsters: Difference between revisions

getMonsterDrops: Fix weight sorting & add secondary sort on item name
(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(monster.lootTable, function(a, b) return a.weight > b.weight end)
local lootTable = Shared.shallowClone(monster.lootTable)
for i, row in ipairs(monster.lootTable) do
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)