17,101
edits
(Add support for Strongholds) |
(getMonsterDrops: Exclude loot table entries with zero weights) |
||
Line 1,098: | Line 1,098: | ||
end) | end) | ||
for i, row in ipairs(lootTable) do | for i, row in ipairs(lootTable) do | ||
local thisItem = Items.getItemByID(row.itemID) | if row.weight > 0 then | ||
local thisItem = Items.getItemByID(row.itemID) | |||
currencyID = thisItem.sellsForCurrency or 'melvorD:GP' | |||
if thisItem ~= nil then | |||
result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'}) | |||
else | |||
result = result..'\r\n|-\r\n|Unknown Item[[Category:Pages with script errors]]' | |||
end | |||
result = result..'||style="text-align:right" data-sort-value="'..row.maxQuantity..'"|' | |||
if row.maxQuantity > row.minQuantity then | |||
result = result .. Num.formatnum(row.minQuantity) .. ' - ' | |||
end | |||
result = result .. Num.formatnum(row.maxQuantity) | |||
--Adding price columns | |||
local itemPrice = 0 | |||
if thisItem == nil then | |||
result = result..'||data-sort-value="0"|???' | |||
else | |||
itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0 | |||
result = result..'||'.. Icons._Currency(currencyID, itemPrice * row.minQuantity) | if itemPrice == 0 or row.maxQuantity == row.minQuantity then | ||
result = result..'||'.. Icons._Currency(currencyID, itemPrice * row.minQuantity) | |||
else | |||
result = result..'||'.. Icons._Currency(currencyID, itemPrice * row.minQuantity, itemPrice * row.maxQuantity) | |||
end | |||
end | |||
--Getting the drop chance | |||
local dropChance = (row.weight / totalWt * lootChance) | |||
if dropChance < 100 then | |||
--Show fraction as long as it isn't going to be 1/1 | |||
result = result..'||style="text-align:right" data-sort-value="'..row.weight..'"' | |||
result = result..'|'..Num.fraction(row.weight * lootChance, totalWt * 100) | |||
result = result..'||' | |||
else | else | ||
result = result..'||'.. | result = result..'||colspan="2" data-sort-value="'..row.weight..'"' | ||
end | end | ||
-- If chance is less than 0.10% then show 2 significant figures, otherwise 2 decimal places | |||
local fmt = (dropChance < 0.10 and '%.2g') or '%.2f' | |||
result = result..'style="text-align:right"|'..string.format(fmt, dropChance)..'%' | |||
--Adding to the average loot value based on price & dropchance | |||
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((row.minQuantity + row.maxQuantity) / 2)) | |||
end | end | ||
end | end | ||
if multiDrop then | if multiDrop then |