17,101
edits
(getMonsterDrops: Exclude loot table entries with zero weights) |
(getMonsterDrops: Fix logic for excluding zero weighted drops, and only include table of drops when loot table isn't empty) |
||
Line 1,074: | Line 1,074: | ||
end | end | ||
local multiDrop = Shared.tableCount( | local lootTable = GameData.getEntities(monster.lootTable, | ||
function(loot) | |||
mw.logObject(loot) | |||
return lootChance > 0 and loot.weight ~= nil and loot.weight > 0 | |||
end) | |||
if not Shared.tableIsEmpty(lootTable) then | |||
local multiDrop = Shared.tableCount(lootTable) > 1 | |||
local totalWt = 0 | |||
for i, row in ipairs(monster.lootTable) do | |||
totalWt = totalWt + row.weight | |||
end | |||
result = result..'\r\n{|class="wikitable sortable" id="itemdrops"' | |||
result = result..'\r\n!Item!!Qty' | |||
result = result..'!!Price!!colspan="2"|Chance' | |||
--Sort the loot table by weight in descending order | |||
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 | else | ||
return a. | return a.weight > b.weight | ||
end | end | ||
end) | |||
for i, row in ipairs(lootTable) do | |||
local thisItem = Items.getItemByID(row.itemID) | local thisItem = Items.getItemByID(row.itemID) | ||
currencyID = thisItem.sellsForCurrency or 'melvorD:GP' | currencyID = thisItem.sellsForCurrency or 'melvorD:GP' | ||
Line 1,144: | Line 1,149: | ||
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((row.minQuantity + row.maxQuantity) / 2)) | lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((row.minQuantity + row.maxQuantity) / 2)) | ||
end | end | ||
if multiDrop then | |||
result = result..'\r\n|-class="sortbottom" \r\n!colspan="3"|Total:' | |||
if lootChance < 100 then | |||
result = result..'\r\n|style="text-align:right"|'..Num.fraction(lootChance, 100)..'||' | |||
else | |||
result = result..'\r\n|colspan="2" ' | |||
end | |||
result = result..'style="text-align:right"|'..Num.round(lootChance, 2, 2)..'%' | |||
end | end | ||
result = result..' | result = result..'\r\n|}' | ||
result = result..'\r\nThe loot dropped by the average kill is worth '.. Icons._Currency(currencyID, Num.round(lootValue, 2, 0)).." if sold." | |||
end | end | ||
if avgGp > 0 then | if avgGp > 0 then | ||
result = result.."<br/>Including "..(currencyID == 'melvorD:GP' and 'GP' or 'AP') | result = result.."<br/>Including "..(currencyID == 'melvorD:GP' and 'GP' or 'AP') |