模块:Collection:修订间差异
来自乐园数据管理室
无编辑摘要 |
无编辑摘要 |
||
| 第23行: | 第23行: | ||
local div = mw.html.create("div") | local div = mw.html.create("div") | ||
local itemTitle = mw.title.new(v["name"], itemNamespace) | local itemTitle = mw.title.new(v["name"], itemNamespace) | ||
itemTitle = "[[" .. tostring(itemTitle) .. "|" .. v["name"] .. | itemTitle = "[[" .. tostring(itemTitle) .. "|" .. v["name"] .. "]]" | ||
div:wikitext(itemTitle .. " ×" .. v["amount"]) | div:wikitext(itemTitle .. " ×" .. v["amount"]) | ||
wikitext = wikitext .. tostring(div) | wikitext = wikitext .. tostring(div) | ||
| 第76行: | 第76行: | ||
parentPage = "黄金之国采集点" | parentPage = "黄金之国采集点" | ||
end | end | ||
return | local backLink = '<div><small><span style="color:#666"><</span> [[' .. parentPage .. "]]</small></div>" | ||
return mw.ustring.format( | |||
[[%s | |||
{| class="wikitable sortable" | {| class="wikitable sortable" | ||
|- | |- | ||
! 采集点类型 !! 数量 !! 道具 !! 概率 !! 道具 !! 概率 !! 道具 !! 概率 !! 道具 !! 概率 | ! 采集点类型 !! 数量 !! 道具 !! 概率 !! 道具 !! 概率 !! 道具 !! 概率 !! 道具 !! 概率 | ||
%s | %s | ||
|}]], backLink, body) | |}]], | ||
backLink, | |||
body | |||
) | |||
end | end | ||
| 第92行: | 第96行: | ||
local gmkId = args["CollectionPointId"] | local gmkId = args["CollectionPointId"] | ||
mw.smw.set {["CollectionPointId"] = gmkId} | |||
local match = 0 | |||
for i, v in ipairs(gmk_collection) do | for i, v in ipairs(gmk_collection) do | ||
if gmkId == v["Name"] then | if gmkId == v["Name"] then | ||
match = match + 1 | |||
mw.smw.subobject( | mw.smw.subobject( | ||
{ | { | ||
| 第104行: | 第112行: | ||
) | ) | ||
end | end | ||
end | |||
if match ~= 1 then | |||
error("No valid collection gmk Id: " .. gmkId) | |||
end | end | ||
end | end | ||
return p | return p | ||
2019年4月8日 (一) 18:28的版本
此模块的文档可以在模块: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 title = mw.title.getCurrentTitle()
local result =
mw.smw.ask {
"[[采集地域::" .. tostring(title) .. "]]",
"?单次采集数量",
"?采集道具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 parentPage = "采集点"
local currentTitle = mw.title.getCurrentTitle()
if "黄金之国" == mw.ustring.sub(tostring(currentTitle), 1, 4) then
parentPage = "黄金之国采集点"
end
local backLink = '<div><small><span style="color:#666"><</span> [[' .. parentPage .. "]]</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