local WinterStormBlockRange = {}
local BlockGroup = {}
local BlockArea = {}

function WinterStormBlockRange.SetBlockRangeData(idx)
  local data = BlockGroup[idx]
  if data ~= nil then
    BlockArea = data
    return data
  end
  data = require("Util.BattleFieldBlockRange.Winter" .. idx)
  BlockGroup[idx] = data
  BlockArea = data
  return data
end

function WinterStormBlockRange.IsInBlockRange(pointId)
  local posV2 = SceneUtils.IndexToTilePos(toInt(pointId), ForceChangeScene.World)
  local data = BlockArea[posV2.y]
  local t = 0
  if data then
    for _, v in ipairs(data) do
      if posV2.x >= v.f and posV2.x <= v.t then
        t = v.i
        break
      end
    end
  end
  if t == 0 then
    return false
  end
  if t == 1 then
    return true
  end
  local mySide = DataCenter.ActWinterStormManager:GetMySide()
  local checkNum = 0
  if mySide == 1 then
    checkNum = 2
  elseif mySide == 2 then
    checkNum = 3
  end
  return t == checkNum
end

function WinterStormBlockRange.TestBlockRange()
  if not CommonUtil.IsDebug() then
    return
  end
  local ResourceManager = CS.GameEntry.Resource
  for x = 455, 545 do
    for y = 455, 545 do
      local pointId = SceneUtils.TileXYToIndex(x, y, ForceChangeScene.World)
      if WinterStormBlockRange.IsInBlockRange(pointId) then
        do
          local effReq = ResourceManager:InstantiateAsync("Assets/_Art/Effect/prefab/scene/Build/XuanQu/VFX_RoadBlockRed.prefab")
          effReq:completed("+", function(req)
            if req.isError then
              return
            end
            req.gameObject:SetActive(true)
            req.gameObject.transform:SetParent(CS.SceneManager.World.DynamicObjNode)
            req.gameObject.transform.position = SceneUtils.TileIndexToWorld(pointId, ForceChangeScene.World)
          end)
        end
      end
    end
  end
end

return ConstClass("WinterStormBlockRange", WinterStormBlockRange)
