模块:Tbox:修订间差异

来自乐园数据管理室
ヒカリ​(留言 | 贡献)
判断宝箱金币掉落数为0的情况
ヒカリ​(留言 | 贡献)
无编辑摘要
第3行: 第3行:
local loadJson = require("Module:JSON").loadJson
local loadJson = require("Module:JSON").loadJson
local fsidMap = loadJson("FSID")
local fsidMap = loadJson("FSID")
local gmk_tbox = loadJson("Gmk/tbox")


function itemList(args)
function itemList(args)
第88行: 第89行:
function p.popTable(frame)
function p.popTable(frame)
   local args = getArgs(frame)
   local args = getArgs(frame)
  for i, v in ipairs(gmk_tbox) do
    if args["name"] == v["Name"] then
      mw.smw.set {
        ["PosX"] = {v["PosX"]},
        ["PosY"] = {v["PosY"]},
        ["PosZ"] = {v["PosZ"]},
        ["areas"] = v["areas"]
      }
    end
  end


   local goldRow
   local goldRow
   if args["goldMin"] == "0" or args["goldPopMin"] == "0" then
   if args["goldMin"] == "0" then
     goldRow = ""
     goldRow = ""
   elseif args["goldMin"] == args["goldMax"] then
   elseif args["goldMin"] == args["goldMax"] then

2019年4月8日 (一) 01:46的版本

此模块的文档可以在模块:Tbox/doc创建

local p = {}
local getArgs = require("Module:Arguments").getArgs
local loadJson = require("Module:JSON").loadJson
local fsidMap = loadJson("FSID")
local gmk_tbox = loadJson("Gmk/tbox")

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)

  for i, v in ipairs(gmk_tbox) do
    if args["name"] == v["Name"] then
      mw.smw.set {
        ["PosX"] = {v["PosX"]},
        ["PosY"] = {v["PosY"]},
        ["PosZ"] = {v["PosZ"]},
        ["areas"] = v["areas"]
      }
    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