Module:Boss Drop Table
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Boss Drop Table/doc
local p = {}
local cargo = mw.ext.cargo
local func = require('Module:Func')
local cfg = require('Module:Config')
function p.fetch_boss_drops(bossName)
local where = string.format("Boss_Name = '%s'", func.encodeName(bossName))
local drops = cargo.query(
'boss_drops',
'Boss_Name, Item_Name, Hell_5, Special_Drop, Special_Drop_Rate',
{ where = where }
)
return drops
end
function p.fetchItem(itemName)
local where = string.format("Item_Name = '%s'", func.encodeName(itemName))
local item = cargo.query(
'items',
'Item_Name, Item_Type',
{ where = where }
)
return item[1]
end
function p.boss_drop(frame)
local bossName = frame.args[1]
--local bossName = "Possessed Luna"
local output = {}
local drops = p.fetch_boss_drops(bossName)
local nonSpecialDrops = {}
local specialDrops = {}
for _, drop in ipairs(drops) do
if drop.Special_Drop == "1" then
table.insert(specialDrops, drop)
else
table.insert(nonSpecialDrops, drop)
end
end
-- Calculate drop rate for non-special items
local dropRate = 100 / #nonSpecialDrops
-- Non-special drops
table.insert(output, "<span>Has a chance depending on [[difficulty]] to drop one of the following items:</span>")
table.insert(output, "<ul>")
for _, drop in ipairs(nonSpecialDrops) do
local item = p.fetchItem(drop.Item_Name)
if drop.Hell_5 == "1" then
table.insert(output, string.format("<li>[[File:%s|link=%s|50x50px]] [[%s]] (Hell 5 Only) - %d%%</li>", cfg.imageFormat(item.Item_Type, item.Item_Name), drop.Item_Name, drop.Item_Name, dropRate))
else
table.insert(output, string.format("<li>[[File:%s|link=%s|50x50px]] [[%s]] - %d%%</li>", cfg.imageFormat(item.Item_Type, item.Item_Name), drop.Item_Name, drop.Item_Name, dropRate))
end
end
table.insert(output, "</ul>")
-- Special drops
if #specialDrops > 0 then
table.insert(output, string.format("<span>%s has a chance to drop an additional item:</span>", bossName))
table.insert(output, "<ul>")
for _, drop in ipairs(specialDrops) do
local item = p.fetchItem(drop.Item_Name)
if drop.Hell_5 == "1" then
table.insert(output, string.format("<li>[[File:%s|link=%s|50x50px]] [[%s]] (Hell 5 Only) - %d%%</li>", cfg.imageFormat(item.Item_Type, item.Item_Name), drop.Item_Name, drop.Item_Name, drop.Special_Drop_Rate))
else
table.insert(output, string.format("<li>[[File:%s|link=%s|50x50px]] [[%s]] - %d%%</li>", cfg.imageFormat(item.Item_Type, item.Item_Name), drop.Item_Name, drop.Item_Name, drop.Special_Drop_Rate))
end
end
table.insert(output, "</ul>")
end
return table.concat(output)
end
return p