Module:Monster
-- Module:Monster local p = {} local data = require('Module:MonsterData')
-- Helper: Format drops -- two_columns: boolean, whether to make it 2-column (row) or 1-column (infobox)
local function formatDrops(drops, frame, two_columns)
if not drops then return "—" end if type(drops) ~= "table" then return drops end
local lines = {}
for _, drop in ipairs(drops) do
local drop_icon = drop.name
if frame and frame.expandTemplate then
drop_icon = frame:expandTemplate{
title = "FaviconPaste",
args = { Name = drop.name }
}
end
local quantity = drop.quantity and (" " .. drop.quantity) or ""
local chance = drop.chance and (" – " .. drop.chance) or ""
local line = (two_columns and "
" or "") table.insert(lines, line) end if two_columns then return "
- "
.. table.concat(lines, "") .. "
"
else
return "
- \n" .. table.concat(lines, "\n") .. "\n
"
end
end
-- Return a single stat
function p.get(frame)
local args = frame.args local name = args.name or args[1] local stat = args.stat or args[2]
local e = data[name]
if not e then
return "Monster not found: " .. tostring(name)
end
if not stat or e[stat] == nil then
return "Stat not found: " .. tostring(stat)
end
return e[stat]
end
-- Return a single wikitable row (2-column drops)
function p.row(frame)
local args = frame.args local name = args.name or args[1] local e = data[name]
if not e then
return "Monster not found: " .. tostring(name)
end
-- Format drops (2 columns) local drops_html = formatDrops(e.drops, frame, true)
-- Format element
local element = e.element and string.format('%s', e.element, e.element) or '—'
-- Image with name below image local image_and_name = e.image and string.format(
'
',
e.image, name, name ) or
return string.format(
'|-\n| %s || %s || %s || %s || %s || %s || %s || %s || %s || %s',
image_and_name,
element,
e.level or ,
e.exp or ,
e.hp or ,
e.atk or ,
e.def or ,
e.mp or ,
e.spd or ,
drops_html
)
end
-- Return only drops (single-column)
function p.drops(frame)
local args = frame.args local name = args.name or args[1] local e = data[name]
if not e then
return "Monster not found: " .. tostring(name)
end
return formatDrops(e.drops, frame, false)
end
-- Generate a Portable Infobox (single-column drops)
function p.infobox(frame)
local args = frame.args local name = args.name or args[1] local e = data[name]
if not e then
return "Monster not found: " .. tostring(name)
end
local infobox_params = {
name = string.format('%s', name, e.name or name),
image = e.image and string.format('File:%s', e.image, name) or "",
element = e.element and string.format('%s', e.element, e.element) or "—",
level = e.level or "—",
exp = e.exp or "—",
hp = e.hp or "—",
atk = e.atk or "—",
def = e.def or "—",
mp = e.mp or "—",
spd = e.spd or "—",
drops = formatDrops(e.drops, frame, false)
}
return frame:expandTemplate{
title = "Monster/Infobox",
args = infobox_params
}
end
return p