local this = class("worldBattleZoneTpl")

function this:init(config)
  self.data = config
end

function this:getTplById(id)
  return self.data[id]
end

function this:getBattleId(tpl)
  return tpl.battleId
end

function this:getIdBySceneId(sceneId, position)
  local dis = 0
  local id = 0
  for i, v in pairs(self.data) do
    if v.sceneId == sceneId then
      local v3 = {
        x = tonumber(v.centerPos[1]) or 0,
        y = tonumber(v.centerPos[2]) or 0,
        z = tonumber(v.centerPos[3]) or 0
      }
      if dis ~= 0 and dis > Unity.Vector3.Distance(position, v3) then
        id = v.battleId
        dis = Unity.Vector3.Distance(position, v3)
      elseif dis == 0 then
        id = v.battleId
        dis = Unity.Vector3.Distance(position, v3)
      end
    end
  end
  return id
end

function this:getTplBySceneId(sceneId, position)
  local dis = 0
  local tpl
  for i, v in pairs(self.data) do
    if v.sceneId == sceneId and v.zoneType ~= 1 then
      local v3 = {
        x = tonumber(v.centerPos[1]) or 0,
        y = tonumber(v.centerPos[2]) or 0,
        z = tonumber(v.centerPos[3]) or 0
      }
      if dis ~= 0 and dis > Unity.Vector3.Distance(position, v3) then
        tpl = v
        dis = Unity.Vector3.Distance(position, v3)
      elseif dis == 0 then
        tpl = v
        dis = Unity.Vector3.Distance(position, v3)
      end
    end
  end
  return tpl
end

function this:getCenterPos(tpl)
  return L_Vector3.new(tonumber(tpl.centerPos[1]) or 0, tonumber(tpl.centerPos[2]) or 0, tonumber(tpl.centerPos[3]) or 0)
end

function this:getBoxRadius(tpl)
  return tpl.boxRadius
end

return this
