模块:Tbox:修订间差异
来自乐园数据管理室
创建页面,内容为“local p = {} local getArgs = require("Module:Arguments").getArgs local loadJson = require("Module:JSON").loadJson function itemList(args) local items = {} for i…” |
无编辑摘要 |
||
| 第2行: | 第2行: | ||
local getArgs = require("Module:Arguments").getArgs | local getArgs = require("Module:Arguments").getArgs | ||
local loadJson = require("Module:JSON").loadJson | local loadJson = require("Module:JSON").loadJson | ||
local fsidMap = loadJson("FSID") | |||
function itemList(args) | function itemList(args) | ||
| 第25行: | 第26行: | ||
end | end | ||
return items | 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 | end | ||
| 第52行: | 第91行: | ||
]], args["goldMin"]) | ]], args["goldMin"]) | ||
mw.smw.set { | mw.smw.set { | ||
[" | ["gold"] = {args["goldMin"]} | ||
} | } | ||
else | else | ||
| 第62行: | 第101行: | ||
]], args["goldMin"] .. " ~ " .. args["goldMax"]) | ]], args["goldMin"] .. " ~ " .. args["goldMax"]) | ||
mw.smw.set { | mw.smw.set { | ||
[" | ["gold"] = {args["goldMin"] .. " ~ " .. args["goldMax"]} | ||
} | } | ||
end | end | ||
| 第89行: | 第128行: | ||
local output = "" | local output = "" | ||
output = output .. fsRow(args["FSID2"]) | |||
output = output .. fsRow(args["FSID"]) | |||
return #output > 0 and [[{| class="wikitable" | return #output > 0 and [[{| class="wikitable" | ||
2019年3月22日 (五) 01:51的版本
此模块的文档可以在模块: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"]
}
)
mw.smw.set {
["tboxPop"] = {tostring(itemTitle)},
[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 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