local PlaceAllianceCenterEffectManager = BaseClass("PlaceAllianceCenterEffectManager", Singleton)
local ResourceManager = CS.GameEntry.Resource
local __init = function(self)
  self:AddListener()
  self.placeLevelList = {}
  self.OnCreateTips = {}
  self.canPlaceEmpty = false
end
local __delete = function(self)
  self.placeLevelList = {}
  self.canPlaceEmpty = false
  self:RemoveListener()
  self:RemoveAllEffect()
end
local AddListener = function(self)
  EventManager:GetInstance():AddListener(EventId.PveLevelEnter, self.RemoveAllTips)
  EventManager:GetInstance():AddListener(EventId.OnEnterWorld, self.OnEnterWorld)
  EventManager:GetInstance():AddListener(EventId.OnEnterCity, self.OnEnterCity)
end
local RemoveListener = function(self)
  EventManager:GetInstance():RemoveListener(EventId.PveLevelEnter, self.RemoveAllTips)
  EventManager:GetInstance():RemoveListener(EventId.OnEnterWorld, self.OnEnterWorld)
  EventManager:GetInstance():RemoveListener(EventId.OnEnterCity, self.OnEnterCity)
end
local RemoveAllTips = function(data)
  PlaceAllianceCenterEffectManager:GetInstance():RemoveAllEffect()
end
local OnEnterWorld = function(data)
end
local OnEnterCity = function(data)
  PlaceAllianceCenterEffectManager:GetInstance():RemoveAllEffect()
end
local ShowDesertSignal = function(data)
  PlaceAllianceCenterEffectManager:GetInstance():CheckShowDesert(tonumber(data))
end
local HideDesertSignal = function(data)
  PlaceAllianceCenterEffectManager:GetInstance():RemoveOneEffect(tonumber(data))
end
local EnterPlaceAllianceCenterMode = function(self, needList, canPlaceEmpty)
  self.placeLevelList = needList
  self.canPlaceEmpty = canPlaceEmpty
  if CS.SceneManager.World.GetDesertPointList ~= nil then
    local desertMap = CS.SceneManager.World:GetDesertPointList()
    if desertMap ~= nil and desertMap.Count > 0 then
      for k, v in pairs(desertMap) do
        local desertData = v:GetWorldDesertInfo()
        if desertData ~= nil then
          local playerType = desertData:GetPlayerType()
          if playerType == CS.PlayerType.PlayerNone and self.canPlaceEmpty == true or playerType == CS.PlayerType.PlayerSelf or playerType == CS.PlayerType.PlayerAlliance or playerType == CS.PlayerType.PlayerAllianceLeader then
            local desertId = desertData.desertId
            local desertLevel = GetTableData(TableName.Desert, desertId, "desert_level")
            if desertId ~= nil and self.placeLevelList[desertLevel] ~= nil then
              self:ShowOneEffect(desertData.uuid, desertData.pointIndex)
            end
          end
        end
      end
    end
  end
end
local QuitPlaceAllianceCenterMode = function(self)
  self:RemoveAllEffect()
  self.placeLevelList = {}
  self.canPlaceEmpty = false
end
local CheckShowDesert = function(self, uuid)
  if SceneUtils.GetIsInWorld() == false then
    return
  end
  if CS.SceneManager.World.GetDesertInfoByUuid == nil then
    return
  end
  local desertData = CS.SceneManager.World:GetDesertInfoByUuid(uuid)
  if desertData ~= nil then
    local playerType = desertData:GetPlayerType()
    if playerType == CS.PlayerType.PlayerNone and self.canPlaceEmpty == true or playerType == CS.PlayerType.PlayerSelf or playerType == CS.PlayerType.PlayerAlliance or playerType == CS.PlayerType.PlayerAllianceLeader then
      local desertId = desertData.desertId
      local desertLevel = GetTableData(TableName.Desert, desertId, "desert_level")
      if desertId ~= nil and self.placeLevelList[desertLevel] ~= nil then
        self:ShowOneEffect(uuid, desertData.pointIndex)
      end
    end
  end
end
local ShowOneEffect = function(self, uuid, pointIndex)
  if SceneUtils.GetIsInWorld() == false then
    return
  end
  if self.OnCreateTips[uuid] == nil then
    local modelName = "Assets/Main/Prefabs/BuildEffect/CanPutEffect.prefab"
    local request = ResourceManager:InstantiateAsync(modelName)
    self.OnCreateTips[uuid] = request
    request:completed("+", function()
      if request.isError then
        return
      end
      request.gameObject:SetActive(true)
      request.gameObject.transform:SetParent(CS.SceneManager.World.DynamicObjNode)
      request.gameObject.transform:Set_localScale(ResetScale.x, ResetScale.y, ResetScale.z)
      local posV3 = SceneUtils.TileIndexToWorld(pointIndex, ForceChangeScene.World)
      request.gameObject.transform.position = posV3
    end)
  end
end
local RemoveOneEffect = function(self, uuid)
  local request = self.OnCreateTips[uuid]
  if request ~= nil then
    request:Destroy()
    self.OnCreateTips[uuid] = nil
  end
end
local RemoveAllEffect = function(self)
  if self.OnCreateTips ~= nil then
    for k, v in pairs(self.OnCreateTips) do
      v:Destroy()
    end
    self.OnCreateTips = {}
  end
end
PlaceAllianceCenterEffectManager.OnEnterWorld = OnEnterWorld
PlaceAllianceCenterEffectManager.OnEnterCity = OnEnterCity
PlaceAllianceCenterEffectManager.__init = __init
PlaceAllianceCenterEffectManager.__delete = __delete
PlaceAllianceCenterEffectManager.AddListener = AddListener
PlaceAllianceCenterEffectManager.RemoveListener = RemoveListener
PlaceAllianceCenterEffectManager.RemoveOneEffect = RemoveOneEffect
PlaceAllianceCenterEffectManager.RemoveAllTips = RemoveAllTips
PlaceAllianceCenterEffectManager.RemoveAllEffect = RemoveAllEffect
PlaceAllianceCenterEffectManager.ShowOneEffect = ShowOneEffect
PlaceAllianceCenterEffectManager.CheckShowDesert = CheckShowDesert
PlaceAllianceCenterEffectManager.QuitPlaceAllianceCenterMode = QuitPlaceAllianceCenterMode
PlaceAllianceCenterEffectManager.EnterPlaceAllianceCenterMode = EnterPlaceAllianceCenterMode
PlaceAllianceCenterEffectManager.ShowDesertSignal = ShowDesertSignal
PlaceAllianceCenterEffectManager.HideDesertSignal = HideDesertSignal
return PlaceAllianceCenterEffectManager
