local this = class("mapTaskNode", require("ui.manager.map.node.mapNode"))

function this:refreshNodeTraceState()
  if self.curShowRange then
    return
  end
  local curTraceTasks = C_TaskStore.GetTraceTaskList()
  if curTraceTasks.Count > 0 then
    self:stopTraceEffect()
  else
    for i = 0, curTraceTasks.Count - 1 do
      local taskId = curTraceTasks[i]
      if self.id == taskId then
        self:playTraceEffect()
        return
      end
    end
    self:stopTraceEffect()
  end
end

function this:refreshPosByMapData(mapData)
  this.super.refreshPosByMapData(self, mapData)
  if self.showRange then
    local player = L_PlayerManager:getMainControlEntity()
    local playerPos = player:getPosition()
    local distanceSqr = L_Vector3.sqrDistance2(self.configPos.x, 0, self.configPos.z, playerPos.x, 0, playerPos.z)
    local curShowRange = distanceSqr < self.triggerRangeSqr
    if self.curShowRange ~= curShowRange then
      self.curShowRange = curShowRange
      if self.curShowRange then
        self:stopTraceEffect()
        self.areaGuideGo:SetActive(true)
        self.imgNode.enabled = false
        self.imgNodeBg.enabled = false
      else
        self.areaGuideGo:SetActive(false)
        self.imgNode.enabled = true
        self.imgNodeBg.enabled = true
        self:playTraceEffect()
      end
    end
    if self.curShowRange then
      local size = self.showRange * mapData.scale * mapData.imgScale * 2
      self.areaGuideTrans:SetUISize(size, size)
    end
  end
end

return this
