local this = class("battleDataManager", G_EventManagerBase)
local _worldBattleZoneTpl = L_GameTpl:getWorldBattleZoneTpl()
local _battleTpl = L_GameTpl:getBattleTpl()
this.event = {
  battleHeroLeave = "battleHeroLeave",
  battleHeroWaringLock = "battleHeroWaringLock",
  battleEntityDying = "battleEntityDying",
  battleEntityDead = "battleEntityDead",
  battleWinWithKillAll = "BattleWinWithKillAll",
  activeNodeWithGroupId = "ActiveNodeWithGroupId",
  switchCD = "SwitchCD",
  skillNotice = "SkillNotice",
  weakBreakNotice = "WeakBreakNotice",
  refreshCombo = "RefreshCombo",
  comboDisappear = "ComboDisappear",
  addShield = "AddShield",
  refreshShield = "RefreshShield",
  removeShield = "RemoveShield",
  battleFinished = "BattleFinished",
  onCastSkill = "OnCastSkill",
  jointStrikeSkill = "JointStrikeSkill",
  refreshAttackStatus = "RefreshAttackStatus",
  cameraLookAtNotice = "CameraLookAtNotice",
  attackAlertNotice = "attackAlertNotice",
  petCatchNotice = "petCatchNotice",
  multiSkillNotice = "multiSkillNotice",
  skillStopNotice = "skillStopNotice",
  skillEventNotice = "skillEventNotice",
  switchSkillNotice = "switchSkillNotice",
  refreshSkillIcon = "RefreshSkillIcon",
  refreshPetSkill = "refreshPetSkill",
  setBattleStartTime = "setBattleStartTime",
  startBattleLimitTime = "startBattleLimitTime",
  leaveWallTime = "leaveWallTime",
  leaveWallBattle = "leaveWallBattle",
  canMountStatusChange = "canMountStatusChange",
  showBossHpNodeStatusChange = "showBossHpNodeStatusChange",
  playerFightStateChange = "playerFightStateChange",
  battleMonsterEntityInfoChange = "battleMonsterEntityInfoChange",
  bossShowSkillProcessBar = "bossShowSkillProcessBar",
  onStopSkill = "onStopSkill",
  triggerCountermeasures = "triggerCountermeasures",
  refreshUIChargingSkill = "refreshUIChargingSkill",
  petResponseSpChange = "petResponseSpChange",
  bossHpIndexChange = "bossHpIndexChange",
  bossAreaEnter = "bossAreaEnter",
  refreshPageMainLeftBottomLayout = "refreshPageMainLeftBottomLayout",
  refreshHeroSettleData = "refreshHeroSettleData"
}
this.battleKey = {
  IsDefaultWin = "IsDefaultWin"
}
local C_EPlayerFightStateEnum = CS.Lens.Gameplay.Modules.BigWorld.EPlayerFightState

function this:ctor()
  this.super.ctor(self)
  L_PlayerManager:addListener(L_PlayerManager.event.playerUnitInit, self.onEvent_playerUnityInit, self)
end

function this:onEvent_playerUnityInit()
  self:playerUnitAddHandler()
end

function this:playerUnitAddHandler()
  function self.playerEventHandle(type, args)
    if type == C_EC2LType.UnderControlWarning then
      self:setHeroWarningLock(args.entityId, args.isControled)
    elseif type == C_EC2LType.SwitchCD then
      self:onEvent_SwitchCD(args)
    elseif type == C_EC2LType.SkillNotice then
      self:onEvent_SkillNotice(args)
    elseif type == C_EC2LType.WeakBreakNotice then
      self:onEvent_WeakBreakNotice(args)
    elseif type == C_EC2LType.CameraLookAtNotice then
      self:onEvent_CameraLookAtNotice(args)
    elseif type == C_EC2LType.AttackAlertNotice then
      self:onEvent_AttackAlertNotice(args)
    elseif type == C_EC2LType.PetCatchNotice then
      self:onEvent_PetCatchNotice(args)
    elseif type == C_EC2LType.MultiSkillNotice then
      self:onEvent_MultiSkillNotice(args)
    elseif type == C_EC2LType.SkillStopNotice then
      self:onEvent_SkillStopNotice(args)
    elseif type == C_EC2LType.SkillEventNotice then
      self:onEvent_SkillEventNotice(args)
    elseif type == C_EC2LType.SwitchSkillNotice then
      self:onEvent_SwitchSkillNotice(args)
    elseif type == C_EC2LType.FightStateChange then
      self:onEvent_FightStateChange(args)
    elseif type == C_EC2LType.Countermeasures then
      self:onEvent_TriggerCountermeasures(args)
    end
  end
  
  L_PlayerManager:getPlayerUnit():getUnitData():addEventC2LHandler(self.playerEventHandle)
end

function this:init()
  self.data = {
    heroLeaveState = {},
    heroWarningLock = {},
    dyingEntityDic = {},
    heroInCd = false,
    isCanMount = true,
    bShowBossHpNode = true,
    battleStartTime = nil,
    limitedTime = nil,
    playerFightState = C_EPlayerFightStateEnum.Idle,
    csMonsterEntityDic = {},
    bossAreaEnterTime = 0,
    bossAreaEnterCD = L_GameTpl:getGameConstTpl():getValue("BOSS_AREA_INTO_TIPS_CD"),
    heroLevelSettleData = {},
    petLevelSettleData = {}
  }
  self.onEvent_HeroLeaveHandle = self.onEvent_HeroLeaveHandle or handler(self, self.onEvent_HeroLeave)
  C_ExternalManager.AddEvent(C_EExternalEventType.HeroLeave, self.onEvent_HeroLeaveHandle)
  C_EntityManager.AddEntityOnRemoveHandler(self.onEvent_EntityRemoveHandle)
  self.entityDeadHandle = self.entityDeadHandle or handler(self, self.onEvent_EntityDead)
  C_EntityManager.RemoveOnEntityDeadHandler(self.entityDeadHandle)
  C_EntityManager.AddOnEntityDeadHandler(self.entityDeadHandle)
  self.entityDyingHandle = self.entityDyingHandle or handler(self, self.onEvent_EntityDying)
  C_EntityManager.AddOnEntityDyingHandler(self.entityDyingHandle)
  self.onEvent_ActiveNodeWithGroupIdHandle = self.onEvent_ActiveNodeWithGroupIdHandle or handler(self, self.onEvent_ActiveNodeWithGroupId)
  C_ExternalManager.AddEvent(C_EExternalEventType.ActiveNodeWithGroupId, self.onEvent_ActiveNodeWithGroupIdHandle)
  self.onEvent_RefreshComboHandle = self.onEvent_RefreshComboHandle or handler(self, self.onEvent_RefreshCombo)
  C_ExternalManager.AddEvent(C_EExternalEventType.RefreshCombo, self.onEvent_RefreshComboHandle)
  self.onEvent_ComboDisappearHandle = self.onEvent_ComboDisappearHandle or handler(self, self.onEvent_ComboDisappear)
  C_ExternalManager.AddEvent(C_EExternalEventType.ComboDisappear, self.onEvent_ComboDisappearHandle)
  self.onEvent_AddShieldHandle = self.onEvent_AddShieldHandle or handler(self, self.onEvent_AddShield)
  C_ExternalManager.AddEvent(C_EExternalEventType.AddShield, self.onEvent_AddShieldHandle)
  self.onEvent_RefreshShieldHandle = self.onEvent_RefreshShieldHandle or handler(self, self.onEvent_RefreshShield)
  C_ExternalManager.AddEvent(C_EExternalEventType.RefreshShield, self.onEvent_RefreshShieldHandle)
  self.onEvent_RemoveShieldHandle = self.onEvent_RemoveShieldHandle or handler(self, self.onEvent_RemoveShield)
  C_ExternalManager.AddEvent(C_EExternalEventType.RemoveShield, self.onEvent_RemoveShieldHandle)
  self.onEvent_onCastSkillHandle = self.onEvent_onCastSkillHandle or handler(self, self.onEvent_onCastSkill)
  C_ExternalManager.AddEvent(C_EExternalEventType.OnCastSkill, self.onEvent_onCastSkillHandle)
  self.onEvent_RefreshSkillIconHandle = self.onEvent_RefreshSkillIconHandle or handler(self, self.onEvent_RefreshSkillIcon)
  C_ExternalManager.AddEvent(C_EExternalEventType.RefreshSkillIcon, self.onEvent_RefreshSkillIconHandle)
  self.onEvent_RefreshPetSkillHandle = self.onEvent_RefreshPetSkillHandle or handler(self, self.onEvent_RefreshPetSkill)
  C_ExternalManager.AddEvent(C_EExternalEventType.RefreshPetSkill, self.onEvent_RefreshPetSkillHandle)
  self.onEvent_onCastJointStrikeSkillHandle = self.onEvent_onCastJointStrikeSkillHandle or handler(self, self.onEvent_onCastJointStrikeSkill)
  C_ExternalManager.AddEvent(C_EExternalEventType.JointStrikeSkill, self.onEvent_onCastJointStrikeSkillHandle)
  self.onEvent_RefreshAttackStatusHandle = self.onEvent_RefreshAttackStatusHandle or handler(self, self.onEvent_RefreshAttackStatus)
  C_ExternalManager.AddEvent(C_EExternalEventType.RefreshAttackStatus, self.onEvent_RefreshAttackStatusHandle)
  self.onEvent_leaveWallTimeHandle = self.onEvent_leaveWallTimeHandle or handler(self, self.onEvent_leaveWallTime)
  C_ExternalManager.AddEvent(C_EExternalEventType.LeaveWallTime, self.onEvent_leaveWallTimeHandle)
  self.onEvent_leaveWallBattleHandle = self.onEvent_leaveWallBattleHandle or handler(self, self.onEvent_leaveWallBattle)
  C_ExternalManager.AddEvent(C_EExternalEventType.LeaveWallBattle, self.onEvent_leaveWallBattleHandle)
  self.onEvent_onCatchSuccessHandle = self.onEvent_onCatchSuccessHandle or handler(self, self.onEvent_onCatchSuccess)
  C_ExternalManager.AddEvent(C_EExternalEventType.ShowPetCatchResult, self.onEvent_onCatchSuccessHandle)
  self.onEvent_StartBattleLimitTimeHandle = self.onEvent_StartBattleLimitTimeHandle or handler(self, self.onEvent_StartBattleLimitTime)
  C_ExternalManager.AddEvent(C_EExternalEventType.StartBattleLimitTime, self.onEvent_StartBattleLimitTimeHandle)
  self.onEvent_SetBattleStartTimeHandle = self.onEvent_SetBattleStartTimeHandle or handler(self, self.onEvent_SetBattleStartTime)
  C_ExternalManager.AddEvent(C_EExternalEventType.SetBattleStartTime, self.onEvent_SetBattleStartTimeHandle)
  self.onEvent_FirstEnterBattleHandle = self.onEvent_FirstEnterBattleHandle or handler(self, self.onEvent_FirstEnterBattle)
  C_ExternalManager.AddEvent(C_EExternalEventType.FirstEnterBattle, self.onEvent_FirstEnterBattleHandle)
  self.onEvent_MonsterInBattleStatusChangeHandle = self.onEvent_MonsterInBattleStatusChangeHandle or handler(self, self.onEvent_MonsterInBattleStatusChange)
  C_ExternalManager.AddEvent(C_EExternalEventType.MonsterInBattleStatusChange, self.onEvent_MonsterInBattleStatusChangeHandle)
  self.onEvent_BossShowSkillProcessBarHandle = self.onEvent_BossShowSkillProcessBarHandle or handler(self, self.onEvent_BossShowSkillProcess)
  C_ExternalManager.AddEvent(C_EExternalEventType.ShowSkillProcessBar, self.onEvent_BossShowSkillProcessBarHandle)
  self.onEvent_OnStopSkillHandle = self.onEvent_OnStopSkillHandle or handler(self, self.onEvent_OnStopSkill)
  C_ExternalManager.AddEvent(C_EExternalEventType.OnStopSkill, self.onEvent_OnStopSkillHandle)
  self.onEvent_RefreshUIChargingSkillHandle = self.onEvent_RefreshUIChargingSkillHandle or handler(self, self.onEvent_RefreshUIChargingSkill)
  C_ExternalManager.AddEvent(C_EExternalEventType.UIChargingSkill, self.onEvent_RefreshUIChargingSkillHandle)
  self.onEvent_PetResponseSpChangeHandle = self.onEvent_PetResponseSpChangeHandle or handler(self, self.onEvent_PetResponseSpChange)
  C_ExternalManager.AddEvent(C_EExternalEventType.PetResponseSpChange, self.onEvent_PetResponseSpChangeHandle)
  self.onEvent_BossHpIndexChangeHandle = self.onEvent_BossHpIndexChangeHandle or handler(self, self.onEvent_BossHpIndexChange)
  C_ExternalManager.AddEvent(C_EExternalEventType.BossHpIndexChange, self.onEvent_BossHpIndexChangeHandle)
  self.onEvent_BossAreaEnterHandle = self.onEvent_BossAreaEnterHandle or handler(self, self.OnEvent_BossAreaEnter)
  C_WorldObjectEvent.instance:Listen(C_EWorldObjectEvent.MonsterInEnterBattleRangeChange, self.onEvent_BossAreaEnterHandle)
end

function this:dispose()
  C_ExternalManager.RemoveEvent(C_EExternalEventType.HeroLeave, self.onEvent_HeroLeaveHandle)
  L_PlayerManager:getPlayerUnit():getUnitData():removeEventC2LHandler(self.playerEventHandle)
  C_EntityManager.RemoveOnEntityDyingHandler(self.entityDyingHandle)
  C_ExternalManager.RemoveEvent(C_EExternalEventType.StartBattleLimitTime, self.onEvent_StartBattleLimitTimeHandle)
  C_ExternalManager.RemoveEvent(C_EExternalEventType.SetBattleStartTime, self.onEvent_SetBattleStartTimeHandle)
  C_ExternalManager.RemoveEvent(C_EExternalEventType.ActiveNodeWithGroupId, self.onEvent_ActiveNodeWithGroupIdHandle)
  C_ExternalManager.RemoveEvent(C_EExternalEventType.ComboDisappear, self.onEvent_ComboDisappear)
  C_ExternalManager.RemoveEvent(C_EExternalEventType.RefreshCombo, self.onEvent_RefreshComboHandle)
  C_ExternalManager.RemoveEvent(C_EExternalEventType.AddShield, self.onEvent_RefreshShieldHandle)
  C_ExternalManager.RemoveEvent(C_EExternalEventType.RefreshShield, self.onEvent_RefreshShieldHandle)
  C_ExternalManager.RemoveEvent(C_EExternalEventType.RemoveShield, self.onEvent_RemoveShieldHandle)
  C_ExternalManager.RemoveEvent(C_EExternalEventType.OnCastSkill, self.onEvent_onCastSkillHandle)
  C_ExternalManager.RemoveEvent(C_EExternalEventType.JointStrikeSkill, self.onEvent_onCastJointStrikeSkillHandle)
  C_ExternalManager.RemoveEvent(C_EExternalEventType.RefreshAttackStatus, self.onEvent_RefreshAttackStatusHandle)
  C_ExternalManager.RemoveEvent(C_EExternalEventType.ShowPetCatchResult, self.onEvent_onCatchSuccessHandle)
  C_ExternalManager.RemoveEvent(C_EExternalEventType.LeaveWallBattle, self.onEvent_leaveWallBattleHandle)
  C_ExternalManager.RemoveEvent(C_EExternalEventType.LeaveWallTime, self.onEvent_leaveWallTimeHandle)
  C_ExternalManager.RemoveEvent(C_EExternalEventType.UIChargingSkill, self.onEvent_RefreshUIChargingSkillHandle)
  C_ExternalManager.RemoveEvent(C_EExternalEventType.PetResponseSpChange, self.onEvent_PetResponseSpChangeHandle)
  C_ExternalManager.RemoveEvent(C_EExternalEventType.BossHpIndexChange, self.onEvent_BossHpIndexChangeHandle)
  C_WorldObjectEvent.instance:Cancel(C_EWorldObjectEvent.MonsterInEnterBattleRangeChange, self.onEvent_BossAreaEnterHandle)
  self.data = nil
end

function this:getIsInBattle()
  return self:checkPlayerBattle()
end

function this:getIsInCD()
  return self.data and self.data.heroInCd or false
end

function this:getNowAliveHeroCount()
  local heroDic = L_PlayerManager:getPlayerUnit():getAllHero()
  local count = 0
  for i, v in pairs(heroDic) do
    if not self.data.dyingEntityDic[v:getCsEntityId()] then
      count = count + 1
    end
  end
  return count
end

function this:onEvent_leaveWallTime(args)
  self:sendEvent(this.event.leaveWallTime, args)
end

function this:onEvent_leaveWallBattle()
  self:sendEvent(this.event.leaveWallBattle)
end

function this:onEvent_EntityDying(csEntity)
  self:sendEvent(this.event.battleEntityDying, csEntity)
  L_BattleManager:entityDyingFunction(csEntity)
end

function this:onEvent_EntityDead(CsEntity)
  self:sendEvent(this.event.battleEntityDead, CsEntity)
  L_BattleManager:entityDeadFunction(CsEntity)
end

function this:onEvent_SwitchCD(args)
  self.data.heroInCd = not args.canSwitch
  self:sendEvent(this.event.switchCD, args)
end

function this:onEvent_SkillNotice(args)
  self:sendEvent(this.event.skillNotice, args)
end

function this:onEvent_WeakBreakNotice(args)
  self:sendEvent(this.event.weakBreakNotice, args)
end

function this:onEvent_CameraLookAtNotice(args)
  self:sendEvent(this.event.cameraLookAtNotice, args)
end

function this:onEvent_AttackAlertNotice(args)
  self:sendEvent(this.event.attackAlertNotice, args)
end

function this:onEvent_PetCatchNotice(args)
  if args.noticeType == "noticeEnterCatch" then
    L_UI:open("pageBattlePetCatch", {
      petInfo = args.petInfos
    })
  elseif args.noticeType == "noticeTryEnterCatch" then
    if not CS.Lens.Gameplay.Modules.BigWorld.Macro.IsBattleSimulator then
      if not L_SystemUnlockStore:getSystemIsOpen(L_SystemConst.enum.catchPet) then
        return
      end
      if L_PetStore:getPetCountIsOverBox() then
        L_FlyMsgManager:showNormalMsg(L_WordsTpl:getValue("notice_pet_catch_num_limit"))
        return
      end
      local data = L_BagManager:getAllCapturePetBall()
      if data == nil or #data == 0 then
        L_FlyMsgManager:showNormalMsg(L_WordsTpl:getValue("notice_pet_catchitem_not_enough"))
        return
      else
        local have = false
        for i = 1, #data do
          if data[i].num ~= 0 then
            have = true
          end
        end
        if not have then
          L_FlyMsgManager:showNormalMsg(L_WordsTpl:getValue("notice_pet_catchitem_not_enough"))
          return
        end
      end
      local hero = L_PlayerManager:getMainControlEntity()
      if not hero then
        return
      end
      local coolDown = C_EntityManager.MainPlayer.data.catchCoolDown
      if 0 < coolDown then
        L_FlyMsgManager:showNormalMsg(L_WordsTpl:getValue("notice_pet_catchcd"))
        return
      end
    end
    C_EntityManager.EnterPetCatch()
  end
  self:sendEvent(this.event.petCatchNotice, args)
end

function this:onEvent_MultiSkillNotice(args)
  self:sendEvent(this.event.multiSkillNotice, args)
end

function this:onEvent_SkillStopNotice(args)
  self:sendEvent(this.event.skillStopNotice, args)
end

function this:onEvent_SkillEventNotice(args)
  self:sendEvent(this.event.skillEventNotice, args)
end

function this:onEvent_SwitchSkillNotice(args)
  self:sendEvent(this.event.switchSkillNotice, args)
end

function this:onEvent_FightStateChange(args)
  printf("\232\167\146\232\137\178\231\138\182\230\128\129\229\143\152\229\140\150 state = " .. tostring(args.state))
  self.data.playerFightState = args.state
  if args.state == C_EPlayerFightStateEnum.Idle then
    self:resetBattleMountState()
    self:resetBattleShowBossHpNodeState()
  end
  self:sendEvent(this.event.playerFightStateChange, args.state)
end

function this:onEvent_TriggerCountermeasures(args)
  self:sendEvent(this.event.triggerCountermeasures, args)
end

function this:onEvent_RefreshUIChargingSkill(args)
  self:sendEvent(this.event.refreshUIChargingSkill, args)
end

function this:onEvent_PetResponseSpChange(args)
  self:sendEvent(this.event.petResponseSpChange, args)
end

function this:onEvent_BossHpIndexChange(args)
  self:sendEvent(this.event.bossHpIndexChange, args)
end

function this:onEvent_MonsterInBattleStatusChange(args)
  local monsterCsEntity = C_EntityManager.GetEntity(args.intArg)
  if not monsterCsEntity then
    return
  end
  local entityScene = monsterCsEntity:GetMonsterScene()
  if entityScene == CS.Lens.Gameplay.Modules.BigWorld.EEntityScene.Battle then
    L_EntityManager:registerCSEntityTriggerStack(monsterCsEntity)
    return
  end
  L_EntityManager:unRegisterCSEntityTriggerStack(monsterCsEntity)
end

function this:onEvent_BossShowSkillProcess(args)
  self:sendEvent(this.event.bossShowSkillProcessBar, args)
end

function this:onEvent_OnStopSkill(args)
  self:sendEvent(this.event.onStopSkill, args)
end

function this:OnEvent_BossAreaEnter(eventId, c_varList)
  local bEnter = c_varList:GetBool(0)
  local monsterId = c_varList:GetInt(2)
  if not bEnter then
    self:sendEvent(this.event.bossAreaEnter, bEnter)
    return
  end
  if C_TimeManager.globalTime - self.data.bossAreaEnterTime <= self.data.bossAreaEnterCD then
    return
  end
  if self:checkPlayerBattle() then
    return
  end
  self.data.bossAreaEnterTime = C_TimeManager.globalTime
  self:sendEvent(this.event.bossAreaEnter, bEnter, monsterId)
end

function this:onStartBattle()
end

function this:onExitBattle(finishType)
  self:sendEvent(self.event.battleFinished, {finishType = finishType})
end

function this:onEvent_ActiveNodeWithGroupId(param)
  errorf("\229\183\178\229\146\140\231\173\150\229\136\146\229\175\185\232\191\135 \228\191\174\230\148\185\228\184\186\231\138\182\230\128\129\230\156\186\229\142\187\229\174\158\231\142\176\228\184\139\228\184\128\228\184\170\230\179\162\230\172\161\231\154\132\230\149\140\228\186\186  \232\175\165\232\138\130\231\130\185\229\138\159\232\131\189\229\183\178\232\162\171\230\155\191\228\187\163 ")
end

function this:onEvent_HeroLeave(param)
  self.data.heroLeaveState[param.entityId] = param.isLeaveStart
  self:sendEvent(this.event.battleHeroLeave, param)
end

function this:onEvent_RefreshCombo(param)
  self:sendEvent(this.event.refreshCombo, param)
end

function this:onEvent_ComboDisappear(args)
  self:sendEvent(self.event.comboDisappear, args)
end

function this:onEvent_RefreshSkillIcon(args)
  self:sendEvent(self.event.refreshSkillIcon, args)
end

function this:onEvent_RefreshPetSkill(args)
  self:sendEvent(self.event.refreshPetSkill, args)
end

function this:onEvent_AddShield(args)
  self:sendEvent(self.event.addShield, args)
end

function this:onEvent_onCastJointStrikeSkill(args)
  self:sendEvent(self.event.jointStrikeSkill, args)
end

function this:onEvent_RemoveShield(args)
  self:sendEvent(self.event.removeShield, args)
end

function this:onEvent_RefreshShield(args)
  self:sendEvent(self.event.refreshShield, args)
end

function this:onEvent_onCastSkill(args)
  self:sendEvent(self.event.onCastSkill, args)
end

function this:onEvent_RefreshAttackStatus(args)
  self:sendEvent(self.event.refreshAttackStatus, args)
end

function this:onEvent_FirstEnterBattle()
  L_FlyMsgManager:showBattleCutInEffect()
end

function this:onEvent_onCatchSuccess(args)
  local guid = args.GUID
  printf("\230\138\147\230\141\149\229\174\160\231\137\169", guid)
  local entity = L_PetStore:getPetItem(guid)
  if entity then
    local options = {
      pet = entity,
      showType = L_Const.getPetShowType.long,
      closeCallback = function(alreadyGetBefore)
        if not alreadyGetBefore then
          C_EntityManager.CloseCatchResultUI()
        end
        L_RewardManager:showBattlePage(nil, L_Const.FightRewardReason.FRR_Catch)
      end,
      voiceCallBack = function()
        L_PetStore:playPetVoiceSound(entity.id, L_PetConst.PetSystemVoiceType.CaptureSuccess)
      end
    }
    L_PetManager:commonGetPet(options, false, nil, true)
  else
    errorf("\230\138\147\230\141\149\231\154\132\229\174\160\231\137\169\230\178\161\230\156\137\230\149\176\230\141\174,guid=" .. guid)
  end
end

function this:onEvent_SetBattleStartTime(args)
  self.data.battleStartTime = args.floatArg
  self:sendEvent(self.event.setBattleStartTime, args)
end

function this:onEvent_StartBattleLimitTime(args)
  self.data.limitedTime = args.intArg
  self:sendEvent(self.event.startBattleLimitTime, args)
end

function this:getBattleLimitTime()
  return self.data.limitedTime
end

function this:getBattleStartTime()
  return self.data.battleStartTime
end

function this:getHeroLeaveState(entityId)
  return self.data.heroLeaveState[entityId]
end

function this:getCurEnergyPoint()
  return C_EntityManager.MainPlayer.data.switchEnergyPoint
end

function this:setHeroWarningLock(entityId, isControled)
  local entity = C_EntityManager.GetEntity(entityId)
  self.data.heroWarningLock[entity.data.UUID] = isControled
  self:sendEvent(this.event.battleHeroWaringLock, entity.data.UUID)
end

function this:getHeroWarningLock(heroId)
  return self.data.heroWarningLock[heroId] or false
end

function this:getBattleHeroBirthData(battleId)
  local tpl = _battleTpl:getTplById(battleId)
  if tpl then
    local birthPos = _battleTpl:getBirthPosition(tpl)
    local birthRot = _battleTpl:getBirthRotation(tpl)
    return birthPos, birthRot
  end
end

function this:getBattleZoneTpl(sceneId)
  local main = L_PlayerManager:getMainControlEntity()
  local curPos = main:getPosition()
  return _worldBattleZoneTpl:getTplBySceneId(sceneId, curPos)
end

function this:setIsCanMount(flag)
  self.data.isCanMount = flag
  self:sendEvent(self.event.canMountStatusChange, flag)
end

function this:getIsCanMount()
  if self.data then
    return self.data.isCanMount == true
  end
  return true
end

function this:setShowBossHpNode(bHide)
  self.data.bShowBossHpNode = not bHide
  self:sendEvent(self.event.showBossHpNodeStatusChange)
end

function this:getShowBossHpNode()
  if self.data then
    return self.data.bShowBossHpNode
  end
  return true
end

function this:setCapturePetBallData(saveData)
  if saveData.sphereId == 0 then
    return
  end
  local capturePetBallData = {}
  capturePetBallData.id = saveData.sphereId
  capturePetBallData.quality = saveData.quality
  capturePetBallData.cnt = saveData.cnt
  self.data.capturePetBallData = capturePetBallData
  local itemTpl = L_GameTpl:getCommonItemTpl():getTplById(capturePetBallData.id)
  if itemTpl then
    C_EntityManager.SetBattleCatchBall(L_GameTpl:getCommonItemTpl():getSubId(itemTpl), capturePetBallData.id)
  end
end

function this:getCapturePetBallData()
  return self.data.capturePetBallData
end

function this:resetPlayerBattleState()
  self.data.playerFightState = C_EPlayerFightStateEnum.Idle
  self:resetBattleMountState()
  self:resetBattleShowBossHpNodeState()
end

function this:resetBattleMountState()
  self.data.isCanMount = true
  self.data.battleStartTime = nil
  self.data.limitedTime = nil
end

function this:resetBattleShowBossHpNodeState()
  self.data.bShowBossHpNode = true
end

function this:checkPlayerBattle()
  return self.data.playerFightState == C_EPlayerFightStateEnum.Fighting
end

function this:getMonsterCsEntityDic()
  return self.data.csMonsterEntityDic
end

function this:addMonsterCsEntity(entityId, bAdd, csEntity)
  AzurWorld.UIBattleDataMgr:AddMonsterEntity(entityId, bAdd, csEntity)
  if not bAdd then
    self.data.csMonsterEntityDic[entityId] = nil
    self:sendEvent(this.event.battleMonsterEntityInfoChange, false, entityId)
    return
  end
  self.data.csMonsterEntityDic[entityId] = csEntity
  self:sendEvent(this.event.battleMonsterEntityInfoChange, true, entityId)
end

local _fightProhibitTbl = L_GameTpl:getFightProhibitTpl()

function this:getBattleBlockTips(blockTypeId)
  local cfg = _fightProhibitTbl:getTplById(blockTypeId)
  return _fightProhibitTbl:getBlockTips(cfg)
end

function this:getHeroLevelSettleData(heroGuid)
  if math.isEmpty(heroGuid) then
    return {}
  end
  return self.data.heroLevelSettleData[heroGuid] or {}
end

function this:getPetLevelSettleData(petGuid)
  if math.isEmpty(petGuid) then
    return {}
  end
  return self.data.petLevelSettleData[petGuid] or {}
end

function this:setLevelSettleData(roleType, guid, key)
  if roleType == L_Const.roleType.pet then
    self.data.petLevelSettleData[guid] = self.data.petLevelSettleData[guid] or {}
    self.data.petLevelSettleData[guid][key] = true
  elseif roleType == L_Const.roleType.hero then
    self.data.heroLevelSettleData[guid] = self.data.heroLevelSettleData[guid] or {}
    self.data.heroLevelSettleData[guid][key] = true
  end
  self:sendEvent(self.event.refreshHeroSettleData, roleType, guid)
end

function this:clearLevelSettleDataByGuid(roleType, guid)
  if roleType == L_Const.roleType.pet then
    self.data.petLevelSettleData[guid] = nil
  elseif roleType == L_Const.roleType.hero then
    self.data.heroLevelSettleData[guid] = nil
  end
end

function this:clearLevelSettleData()
  self.data.heroLevelSettleData = {}
  self.data.petLevelSettleData = {}
end

return this
