“模块:Condition”的版本间的差异

(MWBot)
 
(MWBot)
第3行: 第3行:
 
local html = require("Module:Html")
 
local html = require("Module:Html")
 
local loadJson = require("Module:JSON").loadJson
 
local loadJson = require("Module:JSON").loadJson
local conditionType = require("Module:BdatEnums").conditionType
+
local BdatEnums = require("Module:BdatEnums")
 
local Flag = require("Module:Flag")
 
local Flag = require("Module:Flag")
  
local parser = {
+
local function characterLinkById(id, ira)
 +
  local ns = ""
 +
  if id > 2000 then
 +
    ns = "NPC"
 +
  elseif id > 1000 then
 +
    ns = "异刃"
 +
  elseif ira then
 +
    ns = "黄金之国伊拉"
 +
  end
 +
 
 +
  local characterName = QueryHelper.getCharacterName(id)
 +
  if characterName == nil then
 +
    return nil
 +
  end
 +
 
 +
  local title = mw.title.new(characterName, ns)
 +
  return "[[" .. title.fullText .. "|" .. title.text .. "]]"
 +
end
 +
 
 +
local processFunc = {
 
   Scenario = function(subCondition)
 
   Scenario = function(subCondition)
 
     local data = subCondition.data
 
     local data = subCondition.data
第32行: 第51行:
 
     local ira = subCondition.ira
 
     local ira = subCondition.ira
  
     local q1, q1p = Flag.quest(data.QuestFlag1, ira)
+
     local questList = {}
    local q2, q2p = Flag.quest(data.QuestFlag2, ira)
+
    for _, pre in ipairs({"", "Not"}) do
    local q = {
+
      for i = 1, 2 do
      q1p and (q1 .. "#" .. q1p) or q1,
+
        local quest, questPhase = Flag.quest(data[pre .. "QuestFlag" .. i], ira)
       q2p and (q2 .. "#" .. q2p) or q2
+
        if quest then
     }
+
          if questPhase then
 +
            table.insert(questList, quest .. "#" .. questPhase)
 +
          else
 +
            table.insert(questList, quest)
 +
          end
 +
        end
 +
       end
 +
    end
 +
 
 +
    return table.concat(questList, "")
 +
  end,
 +
  -- Env天气
 +
  Env = function(subCondition)
 +
     local data = subCondition.data
  
     local nq1, nq1p = Flag.quest(data.NotQuestFlag1, ira)
+
     local function getWeather(value)
    local nq2, nq2p = Flag.quest(data.NotQuestFlag2, ira)
+
      local bit32 = require("bit32")
    local notq = {
+
      local weather = QueryHelper.getWeatherList()
       nq1p and (nq1 .. "#" .. nq1p) or nq1,
+
      local result = {}
       nq2p and (nq2 .. "#" .. nq2p) or nq2
+
       for i = 0, 14 do
     }
+
        if bit32.extract(value, i) == 1 then
 +
          table.insert(result, p.weather[bit32.lshift(1, i)])
 +
        end
 +
      end
 +
       if #result == 0 then
 +
        result = nil
 +
      end
 +
      return result
 +
     end
  
     local out = ""
+
     local TimeRange = BdatEnums.getTimeRange(data.TimeRange)
 +
    local Weather = getWeather(data.Weather)
 +
    local CloudHeight = BdatEnums.CloudType[data.CloudHeight]
  
     for _, v in pairs(q) do
+
     local result = {}
       out = out  .. v .. " "
+
    if TimeRange then
 +
      table.insert(result, table.concat(TimeRange, ", "))
 +
    end
 +
    if Weather then
 +
       table.insert(result, table.concat(Weather, ", "))
 
     end
 
     end
     for _, v in pairs(notq) do
+
     if Weather then
       out = out .. "<del>" .. v .. "</del> "
+
       table.insert(result, CloudHeight)
 
     end
 
     end
  
     return out
+
     return table.concat(result, ", ")
  end,
 
  -- Env天气
 
  Env = function(subCondition)
 
    return  subCondition.type .. "/" .. subCondition.data.row_id
 
 
   end,
 
   end,
 
   -- Flag标记
 
   -- Flag标记
第81行: 第123行:
 
   -- 道具
 
   -- 道具
 
   Item = function(subCondition)
 
   Item = function(subCondition)
     return subCondition.type .. "/" .. subCondition.data.row_id
+
    local data = subCondition.data
 +
    local ira = subCondition.ira
 +
 
 +
    local ns = "物品"
 +
    if ira then
 +
      ns = "黄金之国物品"
 +
    end
 +
    local itemName = QueryHelper.getItemName(data.ItemID)
 +
 
 +
    local title = mw.title.new(itemName, ns)
 +
     return "持有物品: " .. "[[" .. title.fullText .. "|" .. title.text .. "]] " .. data.Number .. "个"
 
   end,
 
   end,
 
   PT = function(subCondition)
 
   PT = function(subCondition)
     return  subCondition.type .. "/" .. subCondition.data.row_id
+
     local data = subCondition.data
 +
    local characterStatus = BdatEnums.partyConditionType[data.Category]
 +
    local characterList = {}
 +
    for i = 1, 3 do
 +
      local characterId = data["PCID" .. i]
 +
      if characterId > 0 then
 +
        local characterLink = characterLinkById(characterId, subCondition.ira)
 +
        if characterLink then
 +
          table.insert(characterList, characterLink)
 +
        end
 +
      end
 +
    end
 +
    return table.concat(characterList, "、") .. characterStatus
 
   end,
 
   end,
 +
  -- 信赖,基本都是开环时需要的数据,忽略
 
   Idea = function(subCondition)
 
   Idea = function(subCondition)
     return subCondition.type .. "/" .. subCondition.data.row_id
+
     return subCondition.type .. "/" .. subCondition.data.row_id
 
   end,
 
   end,
 +
  -- 表为空,忽略
 
   Level = function(subCondition)
 
   Level = function(subCondition)
     return subCondition.type .. "/" .. subCondition.data.row_id
+
     return subCondition.type .. "/" .. subCondition.data.row_id
 
   end,
 
   end,
 +
  -- 牵绊环
 
   Achievement = function(subCondition)
 
   Achievement = function(subCondition)
     return  subCondition.type .. "/" .. subCondition.data.row_id
+
     local data = subCondition.data
 +
    local achievementName, bladeName = QueryHelper.getAchievementSetName(data.AchievementSetID)
 +
 
 +
    local title = mw.title.new(bladeName .. "/牵绊圆环", "异刃")
 +
 
 +
    return "牵绊环: " ..
 +
      "[[" ..
 +
        title.fullText ..
 +
          "#" .. achievementName .. "|" .. bladeName .. "#" .. achievementName .. "]]" .. "Lv" .. data.Value
 
   end,
 
   end,
 +
  -- 场景技能
 
   FieldSkiiLevel = function(subCondition)
 
   FieldSkiiLevel = function(subCondition)
     return  subCondition.type .. "/" .. subCondition.data.row_id
+
     local data = subCondition.data
 +
    local fieldSkill = QueryHelper.getFieldSkillName(data.FieldSkillID)
 +
    return fieldSkill .. " Lv" .. data.Level
 
   end
 
   end
 
}
 
}
第108行: 第186行:
 
   local result = {relation, list = {}}
 
   local result = {relation, list = {}}
 
   if conditionList.Premise == 0 then
 
   if conditionList.Premise == 0 then
     result.relation = " | "
+
     result.relation = "<br>"
 
   elseif conditionList.Premise == 1 then
 
   elseif conditionList.Premise == 1 then
     result.relation = " 或 "
+
     result.relation = " 或<br>"
 
   end
 
   end
  
 
   for i = 1, 8 do
 
   for i = 1, 8 do
 
     local type = conditionList["ConditionType" .. i]
 
     local type = conditionList["ConditionType" .. i]
     local id = conditionList["Condition" .. i]
+
     local subId = conditionList["Condition" .. i]
 
     if type > 0 then
 
     if type > 0 then
       local conditionDetail = QueryHelper.getSubCondition(conditionType[type], id)
+
       local conditionDetail = QueryHelper.getSubCondition(BdatEnums.conditionType[type], subId)
       table.insert(result.list, {type = conditionType[type], data = conditionDetail, ira = ira})
+
       if conditionDetail then
 +
        table.insert(result.list, {type = BdatEnums.conditionType[type], data = conditionDetail, ira = ira})
 +
      else
 +
        mw.log("找不到condition:" .. id .. " " .. BdatEnums.conditionType[type] .. "/" .. subId)
 +
      end
 
     end
 
     end
 
   end
 
   end
第125行: 第207行:
 
   local out = {}
 
   local out = {}
 
   for _, subCondition in ipairs(result.list) do
 
   for _, subCondition in ipairs(result.list) do
     table.insert(out, parser[subCondition.type](subCondition))
+
     table.insert(out, processFunc[subCondition.type](subCondition))
 
   end
 
   end
 
   out = table.concat(out, result.relation)
 
   out = table.concat(out, result.relation)

2020年2月10日 (一) 01:00的版本

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

local p = {}
local QueryHelper = require("Module:Xb2QueryHelper")
local html = require("Module:Html")
local loadJson = require("Module:JSON").loadJson
local BdatEnums = require("Module:BdatEnums")
local Flag = require("Module:Flag")

local function characterLinkById(id, ira)
  local ns = ""
  if id > 2000 then
    ns = "NPC"
  elseif id > 1000 then
    ns = "异刃"
  elseif ira then
    ns = "黄金之国伊拉"
  end

  local characterName = QueryHelper.getCharacterName(id)
  if characterName == nil then
    return nil
  end

  local title = mw.title.new(characterName, ns)
  return "[[" .. title.fullText .. "|" .. title.text .. "]]"
end

local processFunc = {
  Scenario = function(subCondition)
    local data = subCondition.data
    -- 四个属性都存在,显示两个区间
    if data.ScenarioFlagMin > 0 and data.ScenarioFlagMax > 0 and data.NotScenarioMin > 0 and data.NotScenarioMax > 0 then
      return Flag.scenario(data.ScenarioFlagMin) ..
        " ~ " ..
          Flag.scenario(data.NotScenarioMin) ..
            ", " .. Flag.scenario(data.NotScenarioMax) .. " ~ " .. Flag.scenario(data.ScenarioFlagMax)
    end

    if data.NotScenarioMin > 0 and data.NotScenarioMax > 0 then
      return "~ " .. Flag.scenario(data.NotScenarioMin) .. ", " .. Flag.scenario(data.ScenarioFlagMin) .. " ~"
    end

    if data.ScenarioFlagMin == data.ScenarioFlagMax then
      return Flag.scenario(data.ScenarioFlagMin)
    else
      return Flag.scenario(data.ScenarioFlagMin) .. " ~ " .. Flag.scenario(data.ScenarioFlagMax)
    end
  end,
  -- Quest
  Quest = function(subCondition)
    local data = subCondition.data
    local ira = subCondition.ira

    local questList = {}
    for _, pre in ipairs({"", "Not"}) do
      for i = 1, 2 do
        local quest, questPhase = Flag.quest(data[pre .. "QuestFlag" .. i], ira)
        if quest then
          if questPhase then
            table.insert(questList, quest .. "#" .. questPhase)
          else
            table.insert(questList, quest)
          end
        end
      end
    end

    return table.concat(questList, "、")
  end,
  -- Env天气
  Env = function(subCondition)
    local data = subCondition.data

    local function getWeather(value)
      local bit32 = require("bit32")
      local weather = QueryHelper.getWeatherList()
      local result = {}
      for i = 0, 14 do
        if bit32.extract(value, i) == 1 then
          table.insert(result, p.weather[bit32.lshift(1, i)])
        end
      end
      if #result == 0 then
        result = nil
      end
      return result
    end

    local TimeRange = BdatEnums.getTimeRange(data.TimeRange)
    local Weather = getWeather(data.Weather)
    local CloudHeight = BdatEnums.CloudType[data.CloudHeight]

    local result = {}
    if TimeRange then
      table.insert(result, table.concat(TimeRange, ", "))
    end
    if Weather then
      table.insert(result, table.concat(Weather, ", "))
    end
    if Weather then
      table.insert(result, CloudHeight)
    end

    return table.concat(result, ", ")
  end,
  -- Flag标记
  Flag = function(subCondition)
    local data = subCondition.data
    local FlagID = tostring(data.FlagID)
    local title = mw.title.new(FlagID, "FLAG")
    local content = title:getContent()

    local value
    if data.FlagMin == data.FlagMax then
      value = data.FlagMin
    else
      value = data.FlagMin .. "~" .. data.FlagMax
    end
    if content then
      return content .. ": " .. value
    end
    return "[[" .. title.fullText .. "]]" .. ": " .. value
  end,
  -- 道具
  Item = function(subCondition)
    local data = subCondition.data
    local ira = subCondition.ira

    local ns = "物品"
    if ira then
      ns = "黄金之国物品"
    end
    local itemName = QueryHelper.getItemName(data.ItemID)

    local title = mw.title.new(itemName, ns)
    return "持有物品: " .. "[[" .. title.fullText .. "|" .. title.text .. "]] " .. data.Number .. "个"
  end,
  PT = function(subCondition)
    local data = subCondition.data
    local characterStatus = BdatEnums.partyConditionType[data.Category]
    local characterList = {}
    for i = 1, 3 do
      local characterId = data["PCID" .. i]
      if characterId > 0 then
        local characterLink = characterLinkById(characterId, subCondition.ira)
        if characterLink then
          table.insert(characterList, characterLink)
        end
      end
    end
    return table.concat(characterList, "、") .. characterStatus
  end,
  -- 信赖,基本都是开环时需要的数据,忽略
  Idea = function(subCondition)
    return subCondition.type .. "/" .. subCondition.data.row_id
  end,
  -- 表为空,忽略
  Level = function(subCondition)
    return subCondition.type .. "/" .. subCondition.data.row_id
  end,
  -- 牵绊环
  Achievement = function(subCondition)
    local data = subCondition.data
    local achievementName, bladeName = QueryHelper.getAchievementSetName(data.AchievementSetID)

    local title = mw.title.new(bladeName .. "/牵绊圆环", "异刃")

    return "牵绊环: " ..
      "[[" ..
        title.fullText ..
          "#" .. achievementName .. "|" .. bladeName .. "#" .. achievementName .. "]]" .. "Lv" .. data.Value
  end,
  -- 场景技能
  FieldSkiiLevel = function(subCondition)
    local data = subCondition.data
    local fieldSkill = QueryHelper.getFieldSkillName(data.FieldSkillID)
    return fieldSkill .. " Lv" .. data.Level
  end
}

function p.getById(id, ira)
  if id <= 0 then
    return nil
  end

  local conditionList = QueryHelper.getConditonList(id)
  local result = {relation, list = {}}
  if conditionList.Premise == 0 then
    result.relation = "<br>"
  elseif conditionList.Premise == 1 then
    result.relation = " 或<br>"
  end

  for i = 1, 8 do
    local type = conditionList["ConditionType" .. i]
    local subId = conditionList["Condition" .. i]
    if type > 0 then
      local conditionDetail = QueryHelper.getSubCondition(BdatEnums.conditionType[type], subId)
      if conditionDetail then
        table.insert(result.list, {type = BdatEnums.conditionType[type], data = conditionDetail, ira = ira})
      else
        mw.log("找不到condition:" .. id .. " " .. BdatEnums.conditionType[type] .. "/" .. subId)
      end
    end
  end

  -- process result
  local out = {}
  for _, subCondition in ipairs(result.list) do
    table.insert(out, processFunc[subCondition.type](subCondition))
  end
  out = table.concat(out, result.relation)

  return out
end

return p