模块:Tbox
来自乐园数据管理室
此模块的文档可以在模块:Tbox/doc创建
local p = {}
local getArgs = require("Module:Arguments").getArgs
local loadJson = require("Module:JSON").loadJson
local fsidMap = loadJson("FSID")
function itemList(args)
local items = {}
for i = 1, 6 do
if args["itm" .. i .. "ID"] then -- filter nil
local itemName = args["itm" .. i .. "ID"]
local itemTitle = getItemTitle(itemName)
local itemPage = "[[" .. tostring(itemTitle) .. "|" .. itemName .. "]]"
table.insert(
items,
{
itemPage,
args["itm" .. i .. "Num"]
}
)
local numString = ""
if args["itm" .. i .. "Num"] ~= "1" then
numString = " ×" .. args["itm" .. i .. "Num"]
end
mw.smw.set {
tboxPop = {tostring(itemTitle)},
tboxPopDisplay = {itemName .. numString},
tboxPopLinkDisplay = {"[[" .. itemTitle.fullText .. "|" .. itemTitle.text .. "]]" .. numString},
[tostring(itemTitle) .. "PopNum"] = {args["itm" .. i .. "Num"]}
}
end
end
return items
end
function fsRow(fsid)
local output = ""
if fsid then
local fs = fsidMap[tonumber(fsid)]
local firstSkill = fs.FieldSkillID1 .. "Lv" .. fs.FieldSkillLevel1
local secondSkill
if fs.FieldSkillLevel2 == 0 then
secondSkill = "-"
else
secondSkill = fs.FieldSkillID2 .. "Lv" .. fs.FieldSkillLevel2
end
output =
mw.ustring.format(
[[|-
| rowspan="2" | %s
| %s
|-
| %s
]],
fs.Name,
firstSkill,
secondSkill
)
if secondSkill == "-" then
secondSkill = ""
else
secondSkill = " + " .. secondSkill
end
mw.smw.set {
FieldSkill = {firstSkill .. secondSkill}
}
end
return output
end
function getItemTitle(itemName)
local itemTitle
if mw.title.new(itemName, "物品").exists then
itemTitle = mw.title.new(itemName, "物品")
elseif mw.title.new(itemName, "黄金之国物品").exists then
itemTitle = mw.title.new(itemName, "黄金之国物品")
else
itemTitle = mw.title.new(itemName, "物品")
end
return itemTitle
end
function p.popTable(frame)
local args = getArgs(frame)
local gmk_tbox = loadJson("Gmk/tbox")
for i, v in ipairs(gmk_tbox) do
if args.name == v.Name then
local areas = {}
for _, v in ipairs(v.areas) do
table.insert(areas, mw.ustring.lower(v))
end
local mapinfo = loadJson("Mapinfo/" .. areas[1])
mw.smw.set {
PosX = v.PosX,
PosY = v.PosY,
PosZ = v.PosZ,
Areas = areas,
["地域"] = mapinfo.mapName,
zoneDisplay = mapinfo.mapName .. "・" .. mapinfo.menuGroup
}
end
end
local goldRow
if args.goldMin == "0" then
goldRow = ""
elseif args.goldMin == args.goldMax then
goldRow = mw.ustring.format([[
|-
! 金币
| %s G
]], args.goldMin)
mw.smw.set {
gold = {args.goldMin}
}
else
goldRow = mw.ustring.format([[
|-
! 金币
| %s G
]], args.goldMin .. " ~ " .. args.goldMax)
mw.smw.set {
gold = {args.goldMin .. " ~ " .. args.goldMax}
}
end
local itemRow = ""
local itemPopList = itemList(args)
if #itemPopList > 0 then
local items = {}
for i, v in ipairs(itemPopList) do
table.insert(items, v[2] == "1" and v[1] or v[1] .. " ×" .. v[2])
end
itemRow = mw.ustring.format([[|-
! 物品
| %s
]], table.concat(items, "<br>"))
end
return [[{| class="wikitable"
! colspan="2" |宝箱内容
]] .. goldRow .. itemRow .. [[|}]]
end
function p.fsInfo(frame)
local args = getArgs(frame)
local output = ""
output = output .. fsRow(args.FSID2)
output = output .. fsRow(args.FSID)
return #output > 0 and [[{| class="wikitable"
! colspan="2" |所需场景技能
]] .. output .. "|}" or ""
end
function p.appearCondition(frame)
local args = getArgs(frame)
local output = ""
if args["出现条件"] then
output = mw.ustring.format([[{| class="wikitable"
! 出现条件
|-
| %s
|}
]], args["出现条件"])
end
return output
end
return p