模块:Collection
来自乐园数据管理室
此模块的文档可以在模块:Collection/doc创建
local p = {}
local getArgs = require("Module:Arguments").getArgs
local loadJson = require("Module:JSON").loadJson
function p.craftMaterials(frame)
local args = getArgs(frame)
local items = {}
local i = 1
while (args[i] and args[i + 1]) do
table.insert(items, {name = args[i], amount = args[i + 1]})
i = i + 2
end
local itemNamespace = "物品"
local currentTitle = mw.title.getCurrentTitle()
if "黄金之国" == mw.ustring.sub(tostring(currentTitle), 1, 4) then
itemNamespace = "黄金之国物品"
end
local wikitext = ""
for i, v in ipairs(items) do
local div = mw.html.create("div")
local itemTitle = mw.title.new(v["name"], itemNamespace)
itemTitle = "[[" .. tostring(itemTitle) .. "|" .. v["name"] .. "]]"
div:wikitext(itemTitle .. " ×" .. v["amount"])
wikitext = wikitext .. tostring(div)
end
return wikitext
end
function p.popList()
local namespace = "采集点"
local currentTitle = mw.title.getCurrentTitle()
if "黄金之国" == mw.ustring.sub(tostring(currentTitle), 1, 4) then
namespace = "黄金之国采集点"
end
local result =
mw.smw.ask {
"[[" .. namespace .. ":+]][[地域::" .. tostring(currentTitle.text) .. "]]",
"?单次采集数量",
"?采集道具1",
"?采集概率1",
"?采集道具2",
"?采集概率2",
"?采集道具3",
"?采集概率3",
"?采集道具4",
"?采集概率4",
"limit=200",
"sort=CollectionTableId"
}
local body = ""
for i, v in ipairs(result) do
local page = mw.ustring.gsub(v[1], "|.+/", "|")
body =
body ..
mw.ustring.format(
[[|-
| %s || %s || %s || %s || %s || %s || %s || %s || %s || %s
]],
page,
v["单次采集数量"],
v["采集道具1"] or "",
v["采集概率1"] or "",
v["采集道具2"] or "",
v["采集概率2"] or "",
v["采集道具3"] or "",
v["采集概率3"] or "",
v["采集道具4"] or "",
v["采集概率4"] or ""
)
end
local backLink = '<div><small><span style="color:#666"><</span> [[' .. namespace .. "]]</small></div>"
return mw.ustring.format(
[[%s
{| class="wikitable sortable"
|-
! 采集点类型 !! 数量 !! 道具 !! 概率 !! 道具 !! 概率 !! 道具 !! 概率 !! 道具 !! 概率
%s
|}]],
backLink,
body
)
end
function p.setGmkData(frame)
local args = getArgs(frame)
local gmk_collection = loadJson("Gmk/collection")
local gmkId = args["CollectionPointId"]
mw.smw.set {["CollectionPointId"] = gmkId}
local match = 0
for i, v in ipairs(gmk_collection) do
if gmkId == v["Name"] then
match = match + 1
mw.smw.subobject(
{
["PosX"] = {v["PosX"]},
["PosY"] = {v["PosY"]},
["PosZ"] = {v["PosZ"]},
["areas"] = v["areas"]
},
gmkId
)
end
end
if match ~= 1 then
error("No valid collection gmk Id: " .. gmkId)
end
end
return p