Module:Monsters: Difference between revisions

getMonsterDrops: Exclude loot table entries with zero weights
(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
currencyID = thisItem.sellsForCurrency or 'melvorD:GP'
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'})
if thisItem ~= nil then
else
result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})
result = result..'\r\n|-\r\n|Unknown Item[[Category:Pages with script errors]]'
else
end
result = result..'\r\n|-\r\n|Unknown Item[[Category:Pages with script errors]]'
result = result..'||style="text-align:right" data-sort-value="'..row.maxQuantity..'"|'
end
 
result = result..'||style="text-align:right" data-sort-value="'..row.maxQuantity..'"|'
if row.maxQuantity > row.minQuantity then
result = result .. Num.formatnum(row.minQuantity) .. ' - '
if row.maxQuantity > row.minQuantity then
end
result = result .. Num.formatnum(row.minQuantity) .. ' - '
result = result .. Num.formatnum(row.maxQuantity)
end
 
result = result .. Num.formatnum(row.maxQuantity)
--Adding price columns
local itemPrice = 0
--Adding price columns
if thisItem == nil then
local itemPrice = 0
result = result..'||data-sort-value="0"|???'
if thisItem == nil then
else
result = result..'||data-sort-value="0"|???'
itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0
else
if itemPrice == 0 or row.maxQuantity == row.minQuantity then
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..'||'.. Icons._Currency(currencyID, itemPrice * row.minQuantity, itemPrice * row.maxQuantity)
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
--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
result = result..'||colspan="2" data-sort-value="'..row.weight..'"'
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
if multiDrop then
if multiDrop then