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

(MWBot)
(MWBot)
 
第57行: 第57行:
 
         if quest then
 
         if quest then
 
           if questPhase then
 
           if questPhase then
             table.insert(questList, quest .. "#" .. questPhase)
+
             table.insert(questList, pre .. quest .. "#" .. questPhase)
 
           else
 
           else
             table.insert(questList, quest)
+
             table.insert(questList, pre .. quest)
 
           end
 
           end
 
         end
 
         end
第65行: 第65行:
 
     end
 
     end
  
     return "任务: " .. table.concat(questList, "、")
+
     if #questList > 0 then
 +
      return "任务: " .. table.concat(questList, "、")
 +
    end
 
   end,
 
   end,
 
   -- Env天气
 
   -- Env天气
第207行: 第209行:
 
   local out = {}
 
   local out = {}
 
   for _, subCondition in ipairs(result.list) do
 
   for _, subCondition in ipairs(result.list) do
     table.insert(out, processFunc[subCondition.type](subCondition))
+
     local row = processFunc[subCondition.type](subCondition)
 +
    if row then
 +
      table.insert(out, row)
 +
    end
 +
  end
 +
  if #out > 0 then
 +
    return table.concat(out, result.relation)
 
   end
 
   end
  out = table.concat(out, result.relation)
 
  
   return out
+
   return nil
 
end
 
end
  
 
return p
 
return p

2020年2月10日 (一) 01:55的最新版本

此模块的文档可以在模块: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
    local result
    -- 四个属性都存在,显示两个区间
    if data.ScenarioMin > 0 and data.ScenarioMax > 0 and data.NotScenarioMin > 0 and data.NotScenarioMax > 0 then
      result =
        Flag.scenario(data.ScenarioMin) ..
        " ~ " ..
          Flag.scenario(data.NotScenarioMin) ..
            ", " .. Flag.scenario(data.NotScenarioMax) .. " ~ " .. Flag.scenario(data.ScenarioMax)
    elseif data.NotScenarioMin > 0 and data.NotScenarioMax > 0 then
      result = "~ " .. Flag.scenario(data.NotScenarioMin) .. ", " .. Flag.scenario(data.NotScenarioMax) .. " ~"
    elseif data.ScenarioMin == data.ScenarioMax then
      result = Flag.scenario(data.ScenarioMin)
    else
      result = Flag.scenario(data.ScenarioMin) .. " ~ " .. Flag.scenario(data.ScenarioMax)
    end

    return "剧情: " .. result
  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, pre .. quest .. "#" .. questPhase)
          else
            table.insert(questList, pre .. quest)
          end
        end
      end
    end

    if #questList > 0 then
      return "任务: " .. table.concat(questList, "、")
    end
  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
    local row = processFunc[subCondition.type](subCondition)
    if row then
      table.insert(out, row)
    end
  end
  if #out > 0 then
    return table.concat(out, result.relation)
  end

  return nil
end

return p