4,951
edits
Falterfire (talk | contribs) (Prevent sorting footer row) |
Falterfire (talk | contribs) (Added range of prices for chest drop tables, fixed column order) |
||
(4 intermediate revisions by the same user not shown) | |||
Line 377: | Line 377: | ||
if monster.lootTable ~= nil then | if monster.lootTable ~= nil then | ||
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100 | local lootChance = monster.lootChance ~= nil and monster.lootChance or 100 | ||
result = result.."'''Loot:'''" | |||
if monster.dropCoins ~= nil then | |||
local gpTxt = Icons.GP(monster.dropCoins[1], monster.dropCoins[2]) | |||
if lootChance == 100 then | |||
result = result.."\r\nIn addition to loot, the monster will also drop "..gpTxt | |||
else | |||
result = result.."\r\nIf loot is received, the monster will also drop "..gpTxt | |||
end | |||
end | |||
local multiDrop = Shared.tableCount(monster.lootTable) > 1 | local multiDrop = Shared.tableCount(monster.lootTable) > 1 | ||
local totalWt = 0 | local totalWt = 0 | ||
Line 382: | Line 394: | ||
totalWt = totalWt + row[2] | totalWt = totalWt + row[2] | ||
end | end | ||
result = result..'\r\n{|class="wikitable sortable"' | result = result..'\r\n{|class="wikitable sortable"' | ||
result = result..'\r\n!Item!!Qty' | result = result..'\r\n!Item!!Qty' | ||
--if multiDrop then result = result..'!!Weight' end | --if multiDrop then result = result..'!!Weight' end | ||
result = result..'!!Chance' | result = result..'!!colspan="2"|Chance' | ||
--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[2] > b[2] end) | table.sort(monster.lootTable, function(a, b) return a[2] > b[2] end) | ||
for i, row in pairs(monster.lootTable) do | for i, row in pairs(monster.lootTable) do | ||
local thisItem = Items.getItemByID(row[1]) | local thisItem = Items.getItemByID(row[1]) | ||
result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})..'||' | result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'}) | ||
if row[3] > 1 then result = result.. '1 - ' | result = result..'||style="text-align:right" data-sort-value="'..row[3]..'"|' | ||
if row[3] > 1 then | |||
result = result.. '1 - ' | |||
end | |||
result = result..Shared.formatnum(row[3]) | |||
local dropChance = (row[2] / totalWt * lootChance) | local dropChance = (row[2] / totalWt * lootChance) | ||
result = result..'||style="text-align:right" data-sort-value="'..row[2]..'"' | |||
result = result..'|'..Shared.fraction(row[2] * lootChance, totalWt * 100) | |||
result = result..'||style="text-align:right"|'..Shared.round(dropChance, 2, 2)..'%' | result = result..'||style="text-align:right"|'..Shared.round(dropChance, 2, 2)..'%' | ||
end | end | ||
if multiDrop then | if multiDrop then | ||
result = result..'\r\n|-class="sortbottom" \r\n!colspan="2"|Total:' | |||
result = result..'\r\n| | if lootChance < 100 then | ||
result = result..'\r\n|style="text-align:right"|'..Shared.fraction(lootChance, 100)..'||' | |||
else | |||
result = result..'\r\n|colspan="2" ' | |||
end | |||
result = result..'style="text-align:right"|'..lootChance..'.00%' | |||
end | end | ||
result = result..'\r\n|}' | result = result..'\r\n|}' | ||
end | |||
return result | |||
end | |||
if | function p.getChestDrops(frame) | ||
local ChestName = frame.args ~= nil and frame.args[1] or frame | |||
if | local chest = Items.getItem(ChestName) | ||
result = result.." | |||
if chest == nil then | |||
return "ERROR: No item named "..ChestName..' found' | |||
end | |||
local result = '' | |||
if chest.dropTable == nil then | |||
return "ERROR: "..ChestName.." does not have a drop table" | |||
else | |||
local lootChance = 100 | |||
local multiDrop = Shared.tableCount(chest.dropTable) > 1 | |||
local totalWt = 0 | |||
for i, row in pairs(chest.dropTable) do | |||
totalWt = totalWt + row[2] | |||
end | |||
result = result..'\r\n{|class="wikitable sortable"' | |||
result = result..'\r\n!Item!!Qty' | |||
result = result..'!!colspan="2"|Chance!!Price' | |||
--Sort the loot table by weight in descending order | |||
table.sort(chest.dropTable, function(a, b) return a[2] > b[2] end) | |||
for i, row in pairs(chest.dropTable) do | |||
local thisItem = Items.getItemByID(row[1]) | |||
local qty = 1 | |||
if chest.dropQty ~= nil then qty = chest.dropQty[i] end | |||
result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'}) | |||
result = result..'||style="text-align:right" data-sort-value="'..qty..'"|' | |||
if qty > 1 then | |||
result = result.. '1 - ' | |||
end | |||
result = result..Shared.formatnum(qty) | |||
local dropChance = (row[2] / totalWt) * 100 | |||
result = result..'||style="text-align:right" data-sort-value="'..row[2]..'"' | |||
result = result..'|'..Shared.fraction(row[2], totalWt) | |||
result = result..'||style="text-align:right"|'..Shared.round(dropChance, 2, 2)..'%' | |||
result = result..'||style="text-align:right" data-sort-value="'..thisItem.sellsFor..'"' | |||
if qty > 1 then | |||
result = result..'|'..Icons.GP(thisItem.sellsFor, thisItem.sellsFor * qty) | |||
else | else | ||
result = result.. | result = result..'|'..Icons.GP(thisItem.sellsFor) | ||
end | end | ||
end | end | ||
result = result..'\r\n|}' | |||
end | end | ||
return result | return result | ||
end | end | ||
return p | return p |