--世界boss战斗的主UI local UIWorldBossBattle = UIViewClass() local EventSystem = require('Event/EventSystem') local tonumberV1=FP.tonumberV1 local damageUnit = 10000 local ceil = math.ceil local WanUnit local AttackCDTime local PKModel_All_Tips local PKModel_Peace_Tips local WorldBossPKModelIDS = { [1] = Const_IDS.IDS_PKMode_Peace, [2] = Const_IDS.IDS_PKMode_Force, } local CountryWorldBossPKModelIDS = { [1] = Const_IDS.IDS_PKMode_Peace, [2] = Const_IDS.IDS_CountryWorldBoss_BattleType, } local WorldBossPKModel = { [LuaConst.EFightMode.PEACE] = {constIDS = Const_IDS.IDS_PKMode_Peace, iconName = "sjslzd_icon_heping"}, [LuaConst.EFightMode.TEAM_GUILD] = {constIDS = Const_IDS.IDS_PKMode_Force, iconName = "sjslzd_icon_ziyou"}, } local CountryWorldBossPKModel = { [LuaConst.EFightMode.PEACE] = {constIDS = Const_IDS.IDS_PKMode_Peace, iconName = "sjslzd_icon_heping"}, [LuaConst.EFightMode.TEAM_GUILD] = {constIDS = Const_IDS.IDS_CountryWorldBoss_BattleType, iconName = "zd_icon_gjms"}, } local ImageCfg = { MyTeam = { IconBg = "zd_zs_lq02", TextBg = "sj_bg_03" }, Friendly = { IconBg = "zd_zs_lq", TextBg = "sj_bg_01" }, Enemy = { IconBg = "zd_zs_hq", TextBg = "sj_bg_02" } } local FrameTimesUnit = LuaConst.TimeSpanMs local MillionSeconds = 1000 local CheckTime = 0.3 local CheckKillTitleTime = 2 local StartWaitingTime = 10 local StartTipsDialogType = "Tip_Hard_new_300202_10" local SuperGodKillCount = DataSheetManager.ConstData:GetDataByID("WorldBossKillBroadcastMaxInterval").IntValue local GuildId = 1002 local HeadImgPath = ConstAssetPathConfig.HeadImgPath function UIWorldBossBattle:OnOpened() self.PlayerNameList = {} self.PlayerDamageList = {} self.PlayerOccupyTimeList = {} self.PlayerStateList = {} self.AttackPlayers = {} self.DownTeamLeaderNameList = {} -- 是否展开协助者列表 self.loopDataList = {} self.loopPrefabIndexs = {} self.MyDamage = -1 self.MyOccupyTime = -1 self.MyRank = -1 self:RegistSystemEvent(EventID.UIBattle_Level_SetUpBoss, self.SetUpBoss) self:RegistSystemEvent(EventID.UIBattle_MainPlayerFightModeChanged, self.OnFightModeChanged) self:RegistSystemEvent(EventID.UIBattle_MainPlayerForceTargetChanged, self.OnAttackTargetChanged) self:RegistSystemEvent(EventID.MainPlayerGetHurtCurFrame, self.OnPlayerAttackSelf) self:RegistSystemEvent(EventID.UI_WorldBoss_PlayerQuitRoom, self.OnPlayerQuitRoom) -- 有人退出 self:RegistSystemEvent(EventID.WorldBoss_PlayerAllHeroBeKilled, self.OnPlayerKill) self:RegistSystemEvent(EventID.UI_UIBattleCountDownPanel_CloseEvent, self.StartTipsShow) if BattleDataGetter.IsWorldBossLevel() then self.subView:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIWorldBossBattleRank), {parent = self}) elseif BattleDataGetter.IsWarZoneWorldBossLevel() then self.subView:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UICountryWorldBossBattleRank), {parent = self}) end --倒计时 self.totalTime = FP.tonumberV1(LevelManager.LevelTotalTime()) self.waitingStartSeconds = StartWaitingTime - math.floor(BattleDataGetter.GetCurFrameIndex() * FrameTimesUnit / MillionSeconds) if self.waitingStartSeconds > 0 then UIManager.OpenView(Const_UI_Lua.UIEnum.UIBattleCountDownCasualPanel, {nil, "IDS_WorldBoss_CountdownTips", true}) EventSystem.Dispatch(EventID.UI_UIBattleCountDownPanel_SetNumber, self.waitingStartSeconds) else CTL.PlayerGuide.StartGuide(GuildId, 1) end self:UpdateTimeShow() self:StartRepeatFunc(self.OnUpdateFun, CheckTime) self.comboViewRoot:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIBattleCombo), {isShowComboType = LuaConst.ComboType.IsKillHero}) self.progressRoot:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIBattleBossProgress)) WanUnit = UIUtils.GetLocalizedTxt(Const_IDS.IDS_WorldBoss_TenThousand) AttackCDTime = DataSheetManager.ConstData:GetDataByID("WorldBossHurtMeRemindTime").IntValue local curPKModel = BattleDataGetter.GetFightMode() if curPKModel then self:OnFightModeChanged(curPKModel) end UIUtils.SetActive(self.group_KillTip.gameObject, false) self.playKillTitleTimer = -1 -- 提前规划好表长度 以房间中最大人数乘以2 考虑到极限情况场上人员全击杀且都是超神 self.killRecordData = LuaExt.CreateTable(DataSheetManager.ConstData:GetDataByID("WorldBossRoomMax").IntValue * 2) self.killRecordDataPool = LuaExt.CreateTable(DataSheetManager.ConstData:GetDataByID("WorldBossRoomMax").IntValue * 2) end function UIWorldBossBattle:OnUpdateFun(deltaTime, timeSinceUpdate) self:UpdateTimeShow() self:CheckPlayKillTitle(deltaTime) if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIBattleCountDownCasualPanel) then local tmp = StartWaitingTime - math.floor(BattleDataGetter.GetCurFrameIndex() * FrameTimesUnit / MillionSeconds) if tmp <= 0 then UIManager.CloseView(Const_UI_Lua.UIEnum.UIBattleCountDownCasualPanel) -- 战斗开始倒计时 CTL.PlayerGuide.StartGuide(GuildId, 1) else if tmp ~= self.waitingStartSeconds then self.waitingStartSeconds = tmp EventSystem.Dispatch(EventID.UI_UIBattleCountDownPanel_SetNumber, self.waitingStartSeconds) end end end end function UIWorldBossBattle:StartTipsShow() if LevelManager.IsWarZoneWorldBossLevel() then EventSystem.Dispatch(EventID.UI_MainShowDialogue, "Tip_Hard_new_300202_20") else EventSystem.Dispatch(EventID.UI_MainShowDialogue, StartTipsDialogType) end end function UIWorldBossBattle:UpdateTimeShow() local curTimer = BattleDataGetter.GetCurFrameIndex() * FrameTimesUnit / MillionSeconds self.txt_Condition.text = UTL.Time.FormatTimeSeconds(self.totalTime - curTimer) end --玩家离开了房间 function UIWorldBossBattle:OnPlayerQuitRoom(playerID) self.AttackPlayers[playerID] = nil end --别人攻击我 function UIWorldBossBattle:OnPlayerAttackSelf(playerList) for i = 1, #playerList do local playerID = playerList[i]:GetPlayerID() if self.AttackPlayers[playerID] == nil then local name = playerList[i]._logicInitData.Name local str = string.FormatByIdsId(Const_IDS.IDS_WorldBoss_CanFightBack,name) CTL.Tips.AddTipsMsg(str) end self.AttackPlayers[playerID] = true end EventSystem.Dispatch(EventID.UI_WorldBoss_UpdateDamageInfo) --首次被攻击时显示特效 if MDL.WorldBoss.GetIsAttacked() == false and #playerList > 0 then if not CTL.WorldBoss.IsInGuideCopy() then EventSystem.Dispatch(EventID.UI_WorldBoss_PlayHelpEffect) end MDL.WorldBoss.SetIsAttacked(true) end end --达到被攻击时长,结束表现 function UIWorldBossBattle:OnAttackTimeEnd(playerID) self.AttackPlayers[playerID] = nil EventSystem.Dispatch(EventID.UI_WorldBoss_UpdateDamageInfo) end function UIWorldBossBattle:OnFightModeChanged(pkModel) if self.CurPKModel == pkModel then return end self.CurPKModel = pkModel local model if BattleDataGetter.IsWorldBossLevel() then model = WorldBossPKModel elseif BattleDataGetter.IsWarZoneWorldBossLevel() then model = CountryWorldBossPKModel end local constIDS = model[pkModel].constIDS UIUtils.SetLabelText(self.lab_Mode, model[pkModel].constIDS) UTL.Item.SetAtlasSprite(self.img_Point, "UI_Battle", model[pkModel].iconName) --需要恢复将当前攻击的状态 if pkModel == LuaConst.EFightMode.PEACE then if self.AttackTeamId ~= nil then self.AttackTeamId = nil EventSystem.Dispatch(EventID.UI_WorldBoss_UpdateDamageInfo) end if PKModel_Peace_Tips ==nil then PKModel_Peace_Tips = string.FormatByIdsId(Const_IDS["IDS_PKMode_Change"],UIUtils.GetLocalizedTxt(constIDS)) end UIUtils.SetActive(self.img_Select_Peace.gameObject, true) UIUtils.SetActive(self.img_Select_Force.gameObject, false) CTL.Tips.AddTipsMsg(PKModel_Peace_Tips) self:OnAttackTargetChanged(nil,false) else if PKModel_All_Tips ==nil then PKModel_All_Tips = string.FormatByIdsId(Const_IDS["IDS_PKMode_Change"],UIUtils.GetLocalizedTxt(constIDS)) end UIUtils.SetActive(self.img_Select_Peace.gameObject, false) UIUtils.SetActive(self.img_Select_Force.gameObject, true) CTL.Tips.AddTipsMsg(PKModel_All_Tips) end EventSystem.Dispatch(EventID.UI_WorldBoss_UpdateDamageInfo) end function UIWorldBossBattle:SetAttackBossCommand() if self.AttackTeamId then local index = 0 local infoList = {} if BattleDataGetter.IsWorldBossLevel() then infoList = BattleDataGetter.GetDamageList() elseif BattleDataGetter.IsWarZoneWorldBossLevel() then infoList = BattleDataGetter.GetOccupyRankList() end for i,info in ipairs(infoList) do if info.teamId == self.AttackTeamId then index = i - 1 break end end CTL.WorldBoss.SetAttackTarget(index) end end --主动攻击别人,playerID传空则选中boss条目 function UIWorldBossBattle:OnAttackTargetChanged(teamId,isSet) if isSet then self.AttackTeamId = teamId else self.AttackTeamId = nil end EventSystem.Dispatch(EventID.UI_WorldBoss_UpdateDamageInfo) end function UIWorldBossBattle:SetUpBoss(active, monsterId, entityID) if monsterId then local monsterData = DataSheetManager.MonsterData:GetDataByID(monsterId) if monsterData then MDL.WorldBoss.CurAttackBossMonsterData = monsterData end end logging.log(LTAG.LOG,"SetUpBoss ", self.bossHpView == nil) if active then if not self.bossHpView then self.bossHpView = self.bossHPRoot:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIBattleBossBattleInfoView), {entityID = entityID}) else self.bossHpView:ActiveUI({entityID = entityID}) --这里临时先这么改吧 如果有两个boss切换血条 会不正确 end else if self.bossHpView then self.bossHpView:HideUI() end end end function UIWorldBossBattle:IsBeAttackedByTeam(teamId) local playerIDList = BattleDataGetter.GetPlayerIDListOfTeam(teamId) if playerIDList then for i,playerID in ipairs(playerIDList) do if self.AttackPlayers[playerID] ~= nil then return true end end end return false end function UIWorldBossBattle:GetAssistantListByTeamID(teamId) local playerIDList = BattleDataGetter.GetPlayerIDListOfTeam(teamId) local assistantList = {} for _,v in ipairs(playerIDList) do -- 这层是协助者 local assistants = BattleDataGetter.GetWorldBossAssistantListByPlayerID(v) -- 协助者名单 if assistants then for _,assistant in ipairs(assistants) do table.insert(assistantList, assistant) end end end return assistantList end --判断一个队伍是否要红名 function UIWorldBossBattle:IsNeedRedColorByTeamID(teamId, showRed, showBlue) local pkmodel = BattleDataGetter.GetFightMode() local playerIDList = BattleDataGetter.GetPlayerIDListOfTeam(teamId) if playerIDList then if showRed then --判断是否变红 for i,playerID in ipairs(playerIDList) do if pkmodel == LuaConst.EFightMode.PEACE then if self.AttackPlayers[playerID] ~= nil then return true end else local myEntity = BattleDataGetter.GetCurEntity() local teamLeaderEntity = BattleDataGetter.GetTeamLeaderByTeamId(teamId) -- 是敌对阵营 if BattleDataGetter.IsEnemyEntity(myEntity, teamLeaderEntity) then -- 不是可忽略敌人 if not myEntity.components.target:IsIgnoreEnemey(teamLeaderEntity) then return true end end end end elseif showBlue then --判断是否变蓝 local myEntity = BattleDataGetter.GetCurEntity() local teamLeaderEntity = BattleDataGetter.GetTeamLeaderByTeamId(teamId) return BattleDataGetter.IsSameGuildByEntities(myEntity, teamLeaderEntity) end end return false end --判断一个协助者是否要红名 function UIWorldBossBattle:IsAssistantNeedRedColorByPlayerID(playerID, showRed, showBlue) local myEntity = BattleDataGetter.GetCurEntity() local entity = BattleDataGetter.GetPlayerActiveEntity(playerID) if showRed then --判断是否变红 -- 是敌对阵营 if BattleDataGetter.IsEnemyEntity(myEntity, entity) then -- 不是可忽略敌人 if not myEntity.components.target:IsIgnoreEnemey(entity) then return true end end elseif showBlue then --判断是否变蓝 if entity then return BattleDataGetter.IsSameGuildByEntities(myEntity, entity) end end return false end function UIWorldBossBattle:OnClosed() self.AttackPlayers = nil end function UIWorldBossBattle:OnButtonClicked(comp) if comp == self.btn_Change then UIUtils.SetActive(self.panel_ChangeMode.gameObject, true) -- 设置模式 if BattleDataGetter.IsWorldBossLevel() then self.obj_ForceState:SetState(0) elseif BattleDataGetter.IsWarZoneWorldBossLevel() then self.obj_ForceState:SetState(1) end UIUtils.SetActive(self.btn_closeMode.gameObject, true) elseif comp == self.btn_Info then UIUtils.SetActive(self.panel_ChangeMode.gameObject, false) UIUtils.SetActive(self.btn_closeMode.gameObject, true) elseif comp == self.btn_closeMode then UIUtils.SetActive(self.panel_ChangeMode.gameObject, false) UIUtils.SetActive(self.btn_closeMode.gameObject, false) elseif comp == self.btn_Mode_Peace then self:OnClickModeButton(LuaConst.EFightMode.PEACE) elseif comp == self.btn_Mode_Force then self:OnClickModeButton(LuaConst.EFightMode.TEAM_GUILD) elseif comp == self.btn_BattleBoss then self:SetAttackBossCommand() end end function UIWorldBossBattle:OnClickModeButton(mode) UIUtils.SetActive(self.btn_closeMode.gameObject, false) UIUtils.SetActive(self.panel_ChangeMode.gameObject, false) if self.CurPKModel ~= mode then CTL.WorldBoss.ChangePKMode() end end function UIWorldBossBattle:GetDamageShow(damage) if BattleDataGetter.IsWorldBossLevel() then return UTL.String.GetCountStr(ceil(damage)) elseif BattleDataGetter.IsWarZoneWorldBossLevel() then return string.FormatByIdsId(Const_IDS.IDS_SecondsCountdown, damage/LuaConst.LogicFrameRate) end end function UIWorldBossBattle:OnPlayerKill(entity, comboKillNumBeforeDead) if not entity or not entity:IsHero() then return end local killerEntity = entity.components.record.KillerEntity killerEntity = killerEntity:GetMasterEntity() or killerEntity if not killerEntity or not killerEntity:IsHero() then return end self:PopKillRecordData(killerEntity, entity, false) if comboKillNumBeforeDead >= SuperGodKillCount then -- 是否显示终结 self:PopKillRecordData(killerEntity, entity, true) end end function UIWorldBossBattle:PopKillRecordData(killerEntity, deadEntity, isShowSuperGod) local recordData = table.remove(self.killRecordDataPool, 1) if not recordData then recordData = { killerEntity = killerEntity, deadEntity = deadEntity, isShowSuperGod = isShowSuperGod } else recordData.killerEntity = killerEntity recordData.deadEntity = deadEntity recordData.isShowSuperGod = isShowSuperGod end table.insert(self.killRecordData, recordData) end function UIWorldBossBattle:PushKillRecordData() if self.killRecordData[1] then local recordData = table.remove(self.killRecordData, 1) recordData.killerEntity = nil recordData.deadEntity = nil recordData.isShowSuperGod = false table.insert(self.killRecordDataPool, recordData) end end function UIWorldBossBattle:CheckPlayKillTitle(deltaTime) if self.playKillTitleTimer ~= -1 then self.playKillTitleTimer = self.playKillTitleTimer + deltaTime end if self.playKillTitleTimer >= CheckKillTitleTime then if not self.killRecordData[1] then UIUtils.SetActive(self.group_KillTip.gameObject, false) end self.playKillTitleTimer = -1 end if self.playKillTitleTimer == -1 and self.killRecordData[1] then self.playKillTitleTimer = 0 self:SetKillEntityTitle(self.killRecordData[1]) self:PushKillRecordData() end end function UIWorldBossBattle:SetKillEntityTitle(killRecordData) if not killRecordData then return end UIUtils.SetActive(self.group_KillTip.gameObject, true) local myEntity = BattleDataGetter.GetCurEntity() local killerEntity = killRecordData.killerEntity local deadEntity = killRecordData.deadEntity self:SetKillTilePlayer(self.group_KillTip.group_PlayerInfo_1, killerEntity, BattleDataGetter.IsSameTeamByEntities(myEntity, killerEntity) or BattleDataGetter.IsSameGuildByEntities(myEntity, killerEntity)) self:SetKillTilePlayer(self.group_KillTip.group_PlayerInfo_2, deadEntity, BattleDataGetter.IsSameTeamByEntities(myEntity, deadEntity) or BattleDataGetter.IsSameGuildByEntities(myEntity, deadEntity)) self.group_KillTip.group_PlayerInfo_2.effect_KillIcon:PlayUIEffect() -- 显示超神终结击杀 if killRecordData.isShowSuperGod then UIUtils.SetLabelText(self.group_KillTip.txt_KillScore, Const_IDS["IDS_GuildWar_KillBroadcast_Shutdown"]) return end -- 处理击杀结果 if BattleDataGetter.GetPlayerAllHeroDeadCount() == 1 then UIUtils.SetLabelText(self.group_KillTip.txt_KillScore, Const_IDS["IDS_GuildWar_KillBroadcast_FirstBlood"]) else local killerComboKillCount = BattleDataGetter.GetPlayerComboKillNum(killerEntity:GetPlayerID()) if killerComboKillCount > MDL.WorldBoss.MaxComboKillCount then killerComboKillCount = killerComboKillCount % MDL.WorldBoss.MaxComboKillCount killerComboKillCount = killerComboKillCount % SuperGodKillCount == 0 and MDL.WorldBoss.MaxComboKillCount or 0 end local isSuccess, killCfg = DataSheetManager.WorldBossKillBroadcast:TryGetDataByID(killerComboKillCount) if isSuccess then UIUtils.SetLabelText(self.group_KillTip.txt_KillScore, Const_IDS[killCfg.Text]) else UIUtils.SetLabelText(self.group_KillTip.txt_KillScore, Const_IDS["IDS_GuildWar_PlayerKill"]) end end end -- 设置击杀者和被击杀者信息 function UIWorldBossBattle:SetKillTilePlayer(uiComp, entity, isFriendly) if entity:GetPlayerID() == BattleDataGetter.GetCurPlayerID() then UTL.Item.SetAtlasSprite(uiComp.img_CharactorBg, "UI_Battle", ImageCfg.MyTeam.IconBg) UTL.Item.SetAtlasSprite(uiComp.img_NameFrame, "UI_Battle", ImageCfg.MyTeam.TextBg) else UTL.Item.SetAtlasSprite(uiComp.img_CharactorBg, "UI_Battle", isFriendly and ImageCfg.Friendly.IconBg or ImageCfg.Enemy.IconBg) UTL.Item.SetAtlasSprite(uiComp.img_NameFrame, "UI_Battle", isFriendly and ImageCfg.Friendly.TextBg or ImageCfg.Enemy.TextBg) end local playerInfo = BattleDataGetter.GetPlayerInfo(entity:GetPlayerID()) UTL.Item.SetHeroIconByHeroId(uiComp.texture_Head, entity:GetCharacterID(), BattleDataGetter.GetHeroIsAwaken(entity:GetPlayerID(), entity:GetCharacterID())) UIUtils.SetLabel(uiComp.txt_PlayerName, playerInfo.name) end return UIWorldBossBattle