local UISoloFightBattle = UIViewClass() local WINIMAGEPATH = "UI_PVP/1v1_msz_sl.png" local FAILEDIMAGEPATH = "UI_PVP/1v1_msz_sb.png" local EventSystem = require('Event/EventSystem') local curRoundIDS= { [1] = "IDS_OfflineSoloFight_First", [2] = "IDS_OfflineSoloFight_Second", [3] = "IDS_OfflineSoloFight_Third" } local INTERVAL_TIME = 5 -- STANDALONE_PLAYER_PlayID = 1, --单机战斗玩家的playidInRoom -- STANDALONE_ENEMYPLAYER1_PLAYID = 2, --单机战斗敌人1 id function UISoloFightBattle:OnOpened(context) self:SetPushStyle(LuaConst.PushStyleEnum.HIDE) self.ownScore = 0 self.enemyScore = 0 self:RegistSystemEvent(EventID.Battle_Solofight_HeroDead,self.OnHeroDead) self:RegistSystemEvent(EventID.Battle_Solofight_HeroSwitched,self.OnHeroSwitch) self:RegistSystemEvent(EventID.Battle_Solofight_Win,self.OnWin) self:RegistSystemEvent(EventID.Battle_Solofight_Fail,self.OnFail) self:RegistSystemEvent(EventID.UI_UpdateBuff_OtherHero,self.UpdateEnemyBuffShow) self:RegistSystemEvent(EventID.UI_UpdateBuff_Self,self.UpdateOwnBuffShow) self.ownBuffPanel = self.info_PlayerOwn.buffItem_Own:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIBattleBuffPanel), {buffType = LuaConst.UIBuffShowType.PlayerSelf, entityId = BattleDataGetter.GetPlayerActiveEntity(LuaConst.STANDALONE_PLAYER_PlayID):GetEntityID()}) self.enemyBuffPanel = self.info_PlayerEnemy.buffItem_Enemy:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIBattleBuffPanel), {buffType = LuaConst.UIBuffShowType.PlayerOthers, entityId = BattleDataGetter.GetPlayerActiveEntity(LuaConst.STANDALONE_ENEMYPLAYER1_PLAYID):GetEntityID()}, "Battle/UIBattleBuffOppositePanel") self.ownHead= self.info_PlayerOwn.ownSubHeadInfo:OpenView( GetViewClass(Const_UI_Lua.UIEnum.UIBattlePlayerHeadPinSoloFight), {playerID = LuaConst.STANDALONE_PLAYER_PlayID}, "Battle/UIBattlePlayerHeadPin" ) self.enemyHead = self.info_PlayerEnemy.enemySubHeadInfo:OpenView( GetViewClass(Const_UI_Lua.UIEnum.UIBattlePlayerHeadPinSoloFight), {playerID = LuaConst.STANDALONE_ENEMYPLAYER1_PLAYID, isReverse = true}, "Battle/UIBattlePlayerHeadPinMirror" ) self:OnUpdateFun() self:StartRepeatFunc(self.OnUpdateFun, 1) self.txt_Score.text = "0:0" self.curRound = 1 --self.battleInfo = {} self.info_PlayerEnemy.lab_RoleName.text = BattleDataGetter.GetEnemyPlayerName() self.info_PlayerOwn.lab_RoleName.text = BattleDataGetter.GetPlayerName() self:InitBattleInfo() self:CountDown() end function UISoloFightBattle:UpdateEnemyBuffShow(entity, buffData, time, layer, sourceEntityId) self.enemyBuffPanel:UpdateBuffShow(buffData, time, layer, sourceEntityId) end function UISoloFightBattle:UpdateOwnBuffShow(entity, buffData, time, layer, sourceEntityId) self.ownBuffPanel:UpdateBuffShow(buffData, time, layer, sourceEntityId) end function UISoloFightBattle:InitBattleInfo() local ownEntityList = BattleDataGetter.GetHeroEntityTable(LuaConst.STANDALONE_PLAYER_PlayID) local enemyEntityList = BattleDataGetter.GetHeroEntityTable(LuaConst.STANDALONE_ENEMYPLAYER1_PLAYID) self.battleInfo = {} for i,v in ipairs(ownEntityList) do self.battleInfo[i] = {} local ownAdjutantEntity = v.components.adjutant.AdjutantEntity local enemyAdjutantEntity = enemyEntityList[i].components.adjutant.AdjutantEntity local ownGs = v:GetGs() local enemyGs = enemyEntityList[i]:GetGs() local ownAwaken1, ownAwaken2 = BattleDataGetter.GetHeroIsAwaken(v:GetPlayerID(), v:GetCharacterID()) self.battleInfo[i].own = { v:GetCharacterID(), CTL.HeroSelect.GetHeroIdByFuJiangRelate(ownAdjutantEntity:GetCharacterID()), ownGs, ownAwaken1, ownAwaken2 } local enemyAwaken1, enemyAwaken2 = BattleDataGetter.GetHeroIsAwaken(enemyEntityList[i]:GetPlayerID(), enemyEntityList[i]:GetCharacterID()) self.battleInfo[i].enemy = { enemyEntityList[i]:GetCharacterID(), CTL.HeroSelect.GetHeroIdByFuJiangRelate(enemyAdjutantEntity:GetCharacterID()), enemyGs, enemyAwaken1, enemyAwaken2 } end end function UISoloFightBattle:RefreshHp(entity,realDelta,value) if entity._logicInitData.PlayerIDInRoom == LuaConst.STANDALONE_PLAYER_PlayID then self.info_PlayerOwn.img_HpFg.fillAmount = FP.tonumberV1(entity.components.attr:HitPointPercents()) elseif entity._logicInitData.PlayerIDInRoom == LuaConst.STANDALONE_ENEMYPLAYER1_PLAYID then self.info_PlayerEnemy.img_HpFg.fillAmount = FP.tonumberV1(entity.components.attr:HitPointPercents()) end end function UISoloFightBattle:OnHeroDead(entity) local isWin = entity._logicInitData.PlayerIDInRoom == LuaConst.STANDALONE_ENEMYPLAYER1_PLAYID if isWin then self.ownHead:UpdateHeroRoundInfo(self.battleInfo[self.curRound].own[1], true) self.enemyHead:UpdateHeroRoundInfo(self.battleInfo[self.curRound].enemy[1], false) self.ownScore = self.ownScore + 1 CTL.Sound.PlayGameSound("UI_victory_v1") else self.enemyHead:UpdateHeroRoundInfo(self.battleInfo[self.curRound].enemy[1], true) --传递回合信息给头像界面 self.ownHead:UpdateHeroRoundInfo(self.battleInfo[self.curRound].own[1], false) self.enemyScore = self.enemyScore + 1 CTL.Sound.PlayGameSound("UI_failed_v1") end --通用结算UI显示 self.summaryTemplateEffectHandle1,self.summaryTemplateEffectHandle2 = CTL.LevelSelect.ShowCommonSummaryTemplate(self,isWin) self.battleInfo[self.curRound].isWin = isWin self.curRound = self.curRound + 1 self.txt_Score.text = self.ownScore..":"..self.enemyScore self.group_Result.gameObject:SetActive(true) self.resultShow = true self.resultShowTime = INTERVAL_TIME self.lab_Tips.text = nil end function UISoloFightBattle:CountDown() self.group_Result.gameObject:SetActive(false) self.resultShow = false self.countDownNum = 3 CTL.LevelSelect.CloseCommonSummaryTemplate(self) UIManager.OpenView(Const_UI_Lua.UIEnum.UIBattleCountDownFormalPanel) EventSystem.Dispatch(EventID.UI_UIBattleCountDownPanel_SetNumber , self.countDownNum) end function UISoloFightBattle:OnUpdateFun() if self.resultShow then self.resultShowTime = self.resultShowTime - 1 if self.resultShowTime <= 3 then self.lab_Tips.text = string.FormatByIdsId(Const_IDS.IDS_OfflineSoloFight_UIshowBetweenTwoBattles,self.resultShowTime) end if self.resultShowTime <= 0 then LuaInputManager.EnqueueSpecialCommand(LuaConst.SpecialCommandType.SoloFightNextRound) self.resultShow = false CTL.LevelSelect.CloseCommonSummaryTemplate(self) end elseif self.countDownNum then self.countDownNum = self.countDownNum - 1 EventSystem.Dispatch(EventID.UI_UIBattleCountDownPanel_SetNumber , self.countDownNum) if self.countDownNum <= 0 then UIManager.CloseView(Const_UI_Lua.UIEnum.UIBattleCountDownFormalPanel) --logging.log(LTAG.LOG," SoloFightSwitchHero ") self:RoundBegin() self.countDownNum = nil end end local curTimer = BattleDataGetter.GetRemainTime() UIUtils.SetLabel(self.txt_Time, UTL.Time.FormatTimeBySeconds(curTimer)) end function UISoloFightBattle:OnHeroSwitch( ) self.group_Result.gameObject:SetActive(false) self:RoundBegin() self.enemyBuffPanel:OnEntityChange(BattleDataGetter.GetPlayerActiveEntity(LuaConst.STANDALONE_ENEMYPLAYER1_PLAYID):GetEntityID()) end function UISoloFightBattle:OnWin() self.battleInfo[self.curRound].isWin = true self.ownScore = self.ownScore + 1 self.txt_Score.text = self.ownScore..":"..self.enemyScore CTL.SoloFight.SetBattleSummaryInfo({battleInfo = self.battleInfo,isWin = true , score = self.txt_Score.text}) end function UISoloFightBattle:OnFail( isNoTimeOut ) if isNoTimeOut then self.battleInfo[self.curRound].isWin = false self.enemyScore = self.enemyScore + 1 self.txt_Score.text = self.ownScore..":"..self.enemyScore CTL.SoloFight.SetBattleSummaryInfo({battleInfo = self.battleInfo,score = self.txt_Score.text}) else self:OnTimeOut() end end function UISoloFightBattle:OnTimeOut() self.battleInfo[self.curRound].isWin = false self.enemyScore = 2 self.txt_Score.text = self.ownScore..":"..self.enemyScore CTL.SoloFight.SetBattleSummaryInfo({battleInfo = self.battleInfo,score = self.txt_Score.text}) end function UISoloFightBattle:RoundBegin( ) self.txt_Num.text= string.format(UIUtils.GetLocalizedTxt(Const_IDS[curRoundIDS[self.curRound]])) self:PlayUIAnimation("enterMap") CTL.Sound.PlayGameSound("UI_begin") end function UISoloFightBattle:OnButtonClicked(comp) if comp == self.btn_close then if self.resultShow then if self.resultShowTime <= 3 then self.resultShow = false CTL.LevelSelect.CloseCommonSummaryTemplate(self) LuaInputManager.EnqueueSpecialCommand(LuaConst.SpecialCommandType.SoloFightNextRound) end end elseif comp == self.btn_Setting then UIManager.OpenView(Const_UI_Lua.UIEnum.UISettingMainPanel) elseif comp == self.btn_Exit then CTL.Setting.BackToTown() end end function UISoloFightBattle:OnClosed() CTL.LevelSelect.RemoveSummaryTemplateEffect(self) end return UISoloFightBattle