Documentation for this module may be created at Module:Items/doc

cdb = require("Module:Crafting_DB")
adb = require("Module:Area_DB")
edb = require("Module:Enemy_DB")
u = require("Module:Util")

local p = {}

function p.used_in_table(name)
    recipes = {}
    for _, e in ipairs(cdb) do
        for _, f in ipairs(e[4]) do
            if f[1] == name then
                table.insert(recipes, {e[1], e[2], e[3], f[2]})
            end
        end
    end
    result = [[
{| class="article-table"
!Item
!Crafting level
!Amount needed
]]
    for _, e in ipairs(recipes) do
        result = result .. [[
|-
|]] .. '[[File: ' .. e[2] .. '.png|35px|link=' .. e[1] .. ']]' .. [[

|]] .. e[3] .. [[

|]] .. u.c(e[4]) .. [[

]]
    end
    return result .. [[
|}
]]
end

function p.dropped_from_table(name)
    recipes = {}
    for _, e in ipairs(adb) do
        for _, f in ipairs(e[9] or {}) do
            if f[1] == name then
                table.insert(recipes, {e[1], e['image'] or e[1], f[2], f[3], f[4], f[6], f[5] and e[1]})
            end
        end
    end
    for _, e in ipairs(edb) do
        for _, f in ipairs(e[7]) do
            if f[1] == name then
                table.insert(recipes, {e[1], e[1] .. ' Monster', f[2], f[3], f[4], f[6], f[5] and e[2]})
            end
        end
    end
    result = [[
{| class="article-table"
!Source
!Amount dropped
!Drop chance
]]
    for _, e in ipairs(recipes) do
        result = result .. [[
|- class="rarity-]] .. u.r(e[5]) .. [["
|]] .. '[[File: ' .. e[2]:gsub(' ', '') .. '.png|35px|link=' .. e[1] .. ']]' .. [[

|]] .. (e[3] == e[4] and u.c(e[3]) or u.c(e[3]) .. ' - ' .. u.c(e[4])) .. [[

|1/]] .. e[5] .. (e[6] and e[6] ~= '' and '*' or '') .. (e[7] and e[7] ~= '' and ([[

|]] .. '[[' .. [[File: ]] .. e[7]:gsub(' ', ''):gsub('%(', ''):gsub('%)', '') .. [[LootingRing.png|20px|link=]] .. e[7] .. [[ Looting Ring|1/]] .. p.floor(tonumber(e[5]) / 2) .. [[ with ]] .. e[7] .. [[ Looting Ring]] .. ']]') or '') .. [[

]]
    end
    return result .. [[
|}
]]
end

function p.tuit(frame)
    return p.used_in_table(frame.args[1] or frame:getParent():getTitle())
end

function p.tdft(frame)
    return p.dropped_from_table(frame.args[1] or frame:getParent():getTitle())
end

return p
Community content is available under CC-BY-SA unless otherwise noted.