Module:Elderfield/Drops
Jump to navigation
Jump to search
-- Module:Elderfield/Drops
--
-- Drop tables from the data modules: what an enemy drops (Data/Enemies, drops) and which
-- enemies drop an item (Data/Items, Weapons or Armor, droppedBy). The generator writes every
-- cell from the game's own loot tables, played the way the game plays them, so this module
-- only lays the tables out. How the chances are worked out is explained at Help:Drop chances.
local u = require('Module:Elderfield/Utility')
local p = {}
local DOMAIN = { item = 'Items', weapon = 'Weapons', armor = 'Armor' }
-- One table: its caption, the table, and the note under it.
local function draw(t)
local out = {}
if t.caption then out[#out + 1] = "'''" .. t.caption .. "'''" end
out[#out + 1] = u.table(t.columns or {}, t.rows or {}, t.collapsible and 'mw-collapsible mw-collapsed' or nil)
if t.note then out[#out + 1] = "''" .. t.note .. "''" end
return table.concat(out, '\n')
end
--- {{#invoke:Elderfield/Drops|enemy|id=58}} from {{Drop table|id=58}}: the enemy's drop
-- tables, one per group of fights that pay the same.
function p.enemy(frame)
local id = u.arg(frame, 'id')
local rec = u.get('Enemies', id)
if not rec then return u.missing('Enemy', id) end
-- A page only carries the template when there are drops, so none here means the data
-- module is older than the page: said, rather than drawn as nothing.
if not rec.drops then return u.missing('Drop table for enemy', id) end
local out = {}
for _, t in ipairs(rec.drops) do out[#out + 1] = draw(t) end
return u.text(frame, table.concat(out, '\n\n'))
end
--- {{#invoke:Elderfield/Drops|item|id=107}} from {{Dropped by|id=107}}: the enemies that
-- drop it. Weapons and armor pass kind=weapon or kind=armor.
function p.item(frame)
local id = u.arg(frame, 'id')
local kind = u.arg(frame, 'kind', 'item')
local rec = u.get(DOMAIN[kind] or 'Items', id)
if not rec then return u.missing('Item', id) end
if not rec.droppedBy then return u.missing('Dropped by table for ' .. kind, id) end
return u.text(frame, draw(rec.droppedBy))
end
return p