local UIFairSoloTournamentBanSelect = UIViewClass() local STATE_BAN = 0 --禁阶段 local STATE_PICK = 1 --选阶段 local STATE_ADJUST = 2 --调整顺序阶段 local STATE_READY_BATTLE = 3 --进战斗倒计时阶段 --武将几个选中状态 local HERO_STATE_LEFT_BAN = 1 local HERO_STATE_LEFT_PICK = 2 local HERO_STATE_RIGHT_BAN = 3 local HERO_STATE_RIGHT_PICK = 4 local HERO_STATE_ALL_PICK = 5 --双方都选中 local HERO_STATE_ALL_BAN = 6 --双方都禁止 --选将置灰状态 local LOCK_STATE_SHOW_1 = 0 --第1行亮 local LOCK_STATE_SHOW_2 = 1 --第1、2行亮 local LOCK_STATE_SHOW_3 = 2 --第2、3行亮 local LOCK_STATE_SHOW_4 = 3 --第3行亮 local LOCK_STATE_SHOW_ALL = 4 --全部亮 local LOCK_STATE_HIDE_ALL = 5 --全部置灰 local OFFSET_DEGREE = 2 --2s误差 local CountryIconName = { [LuaConst.EHeroKingdomType.WEI] = "gb_msz_wei.png", [LuaConst.EHeroKingdomType.SHU] = "gb_msz_shu.png", [LuaConst.EHeroKingdomType.WU] = "gb_msz_wu.png", [LuaConst.EHeroKingdomType.QUN] = "gb_msz_qun.png", } local CountryBGPath = { [LuaConst.EHeroKingdomType.WEI] = ConstAssetPathConfig.Path24, [LuaConst.EHeroKingdomType.SHU] = ConstAssetPathConfig.AssetPath128, [LuaConst.EHeroKingdomType.WU] = ConstAssetPathConfig.AssetPath129, [LuaConst.EHeroKingdomType.QUN] = ConstAssetPathConfig.AssetPath130, } local HeroHalfCardImagePath = ConstAssetPathConfig.HeroPicPath local FIRST_HAND_LEFT = 1 local FIRST_HAND_RIGHT = 2 local FairTournamentBanNum = DataSheetManager.ConstData:GetDataByID("FairTournamentBanNum").IntValue local FairTournamentSuperHeroCount = DataSheetManager.ConstData:GetDataByID("FairTournamenPick22HeroNum").IntValue function UIFairSoloTournamentBanSelect:OnCreated() UIUtils.SetActive(self.btn_Close, false) self.dragParentTrans = self.obj_DragParent.transform self.hasInit = false self.logList = {} self.isLeftRound = false self.leftSuperGolderHeroCfgIdArr = {} UIUtils.SetLabel(self.txt_BanSelectTip, string.FormatByIdsKey("IDS_FairTournament_CaiJinHero", FairTournamentSuperHeroCount)) UIUtils.SetActive(self.btn_Confirm, false) end function UIFairSoloTournamentBanSelect:OnOpened(context) NetManager.OpenLog = true logging.crit(LTAG.NET, "OpenLog") self.firstHandType = nil --哪一方先手 self.formationHeroIdList = { 0, 0, 0, 0, 0, 0 } self.enemyConstFormationHeroIdList = { 0, 0, 0, 0, 0, 0 } self.banHeroIdList = {} self.leftBPInfo = nil self.rightBPInfo = nil self:RegistSystemEvent(EventID.UI_FairSoloTournament_NoticeBPInfo, self.OnBPInfoNotice) self:RegistSystemEvent(EventID.UI_FairSoloTournament_RefreshStageInfo, self.OnStageChanged) self:RegistSystemEvent(EventID.UI_FairSoloTournament_RefreshPlayerInfo, self.UpdatePlayerInfo) if MDL.FairSoloTournament.GetCurMatchTimeID() == MDL.FairSoloTournament.Enum_BigStage.FairScreening then self.isBlindBan = true --是否提前盲ban else self.isBlindBan = false end if self.context.isWatch == false then UIUtils.SetActive(self.btn_Close, false) for i, v in ipairs(self.group_Left.group_SelectHero) do self:RegistTriggerEvent(v.btn_FormationHero, UIEventTriggerType.BeginDrag) self:RegistTriggerEvent(v.btn_FormationHero, UIEventTriggerType.Drag) self:RegistTriggerEvent(v.btn_FormationHero, UIEventTriggerType.EndDrag) self:RegistTriggerEvent(v.btn_FormationHero, UIEventTriggerType.Drop) self:RegistTriggerEvent(v.img_Empty, UIEventTriggerType.Drop) end else UIUtils.SetActive(self.btn_Close, true) end MDL.FairSoloTournament.C2GFairTournamentBP(self.context.groupId, false) --每隔1s输出日志 self:StartRepeatFunc(self.ShowBPLog, 1) end function UIFairSoloTournamentBanSelect:UpdatePlayerInfo() self:SetBasicInfo(self.group_Left, self.leftBPInfo.Acid) self:SetBasicInfo(self.group_Right, self.rightBPInfo.Acid) end function UIFairSoloTournamentBanSelect:OnBPInfoNotice(bpInfos) if self.hasInit == false then self:UpdateBPData(bpInfos) if MDL.FairSoloTournament.GetPlayerShowInfo(self.leftBPInfo.Acid) == nil or MDL.FairSoloTournament.GetPlayerShowInfo(self.rightBPInfo.Acid) == nil then MDL.FairSoloTournament.TryFairTournamentGetAllPlayerInfoReq(true) else self:UpdatePlayerInfo() end self:UpdateBPState() if self.bpState then self.heroList = CTL.FairSoloTournament.GetAllSortedHeroList() self.group_BanSelect.loop_bpHero:ReloadAll(self.heroList) end self.hasInit = true else self:UpdateBPData(bpInfos) self:UpdateBPState() self.group_BanSelect.loop_bpHero:ReloadAll(self.heroList) end end function UIFairSoloTournamentBanSelect:UpdateBPData(bpInfos) --因为服务器推过来的数组排序不是稳定的,因此会偶现观战视角看的是对方的情况 local leftAcid if self.context.isWatch == false then --参赛者左边一定是自己 leftAcid = BattleDataGetter.GetAcID() else --观战者左边是观战的人 leftAcid = self.context.watchAcid end --bpInfos长度为2,我一定是在左边 for i, bpInfo in ipairs(bpInfos) do if bpInfo.Acid == leftAcid then self.leftBPInfo = bpInfo if i == 1 then self.rightBPInfo = bpInfos[2] else self.rightBPInfo = bpInfos[1] end break end end if self.leftBPInfo == nil then self.leftBPInfo = bpInfos[1] self.rightBPInfo = bpInfos[2] end if self.leftBPInfo == nil or self.rightBPInfo == nil then logging.error(LTAG.ERROR, "[天下会武]bp异常,出现数据为空的情况", self.leftBPInfo, self.rightBPInfo) return end if self.firstHandType == nil then --不确定后续推送带过来的骰子数Dice是否正确,只缓存第一次的结果 if self.leftBPInfo.Dice > self.rightBPInfo.Dice then self.firstHandType = FIRST_HAND_LEFT else self.firstHandType = FIRST_HAND_RIGHT end end for i, v in ipairs(self.leftBPInfo.PickHero) do self.formationHeroIdList[i] = v self:RefreshSingleHeroCell(i) end self.leftSuperGolderHeroCfgIdArr = {} for i, v in ipairs(self.leftBPInfo.PickHero) do if v>0 and CTL.HeroSelect.IsSuperGoldHero(v) then table.insert(self.leftSuperGolderHeroCfgIdArr, v) end end if self.context.isWatch == false then table.clear(self.banHeroIdList) table.removebyvalue(self.leftBPInfo.BanHero, 0) for i, v in ipairs(self.leftBPInfo.BanHero) do if v > 0 then table.insert(self.banHeroIdList, v) end end end end function UIFairSoloTournamentBanSelect:ShowBPLog() if self.firstHandType == nil then return end table.clearArray(self.logList) table.insert(self.logList, self.leftBPInfo.Acid) table.insert(self.logList, self.leftBPInfo.Dice) for i, v in ipairs(self.leftBPInfo.BanHero) do table.insert(self.logList, v) end for i, v in ipairs(self.leftBPInfo.PickHero) do table.insert(self.logList, v) end table.insert(self.logList, self.rightBPInfo.Acid) table.insert(self.logList, self.rightBPInfo.Dice) for i, v in ipairs(self.rightBPInfo.BanHero) do table.insert(self.logList, v) end for i, v in ipairs(self.rightBPInfo.PickHero) do table.insert(self.logList, v) end local leftTime = self.context.endTime - UTL.Time.GetServerTimestamp() --bp剩余时间 table.insert(self.logList, leftTime) --bp详情 local isLeftRound, roundLeftTime, roundNum = self:GetBPRoundDetail() table.insert(self.logList, isLeftRound) table.insert(self.logList, roundLeftTime) table.insert(self.logList, roundNum) table.insert(self.logList, self.isDefaultShow) table.insert(self.logList, self.bpState) --当前赛事ID table.insert(self.logList, MDL.FairSoloTournament.GetCurStageID()) table.insert(self.logList, self.context.round) table.insert(self.logList, UTL.Time.GetServerTimestamp()) table.insert(self.logList, self.context.watchAcid) logging.warn(LTAG.WARN, table.unpack(self.logList)) end function UIFairSoloTournamentBanSelect:OnDefaultShow(leftTime) UIUtils.SetActive(self.group_Info, true) self.state_Middle:SetState(0) UIUtils.SetActive(self.group_BanSelect.group_TitleBan, false) UIUtils.SetActive(self.group_BanSelect.group_TitleSelect, true) self.bpState = STATE_PICK local isLeftRound, roundLeftTime, roundNum = true, leftTime, 1 self.group_BanSelect.cdTimer_BP:ResetAndBeginCustomTimer(false, roundLeftTime, 0, "{0}s", 1) if MDL.FairSoloTournament.GetCurMatchTimeID() == MDL.FairSoloTournament.Enum_BigStage.FairScreening then self:UpdateBPDesc(false, isLeftRound, 6) else self:UpdateBPDesc(false, isLeftRound, 2) end self:UpdateBPDetail(self.group_Left, self.leftBPInfo, true, isLeftRound, roundNum) self:UpdateBPDetail(self.group_Right, self.rightBPInfo, false, isLeftRound, roundNum) self.group_Left.state_Lock:SetState(LOCK_STATE_HIDE_ALL) self.group_Right.state_Lock:SetState(LOCK_STATE_HIDE_ALL) self.isDefaultShow = true end function UIFairSoloTournamentBanSelect:UpdateBPState() self.isDefaultShow = false self:StopRepeatFunc(self.UpdateBPState) self.stageEndTime = 0 local matchTimeCfg = DataSheetManager.FairMatchTime:GetDataByID(MDL.FairSoloTournament.GetCurMatchTimeID()) local leftTime = self.context.endTime - UTL.Time.GetServerTimestamp() if leftTime <= 0 then self.bpState = nil return end local configTotalTime = matchTimeCfg.ChooseHeroTime + matchTimeCfg.ChangeHeroPlace + matchTimeCfg.WaitBattle + matchTimeCfg.BanHeroTime if leftTime > configTotalTime then --可能有精度误差 if leftTime > configTotalTime then local stageInfo = MDL.FairSoloTournament.GetStageInfo(MDL.FairSoloTournament.GetCurStageID()) local offset = leftTime - configTotalTime if offset > 2 then logging.error(LTAG.ERROR, "[天下会武]bp阶段总时长大于了配置的时长:", configTotalTime, offset, MDL.FairSoloTournament.GetCurStageID(), self.context.round, stageInfo.stateEndTime, UTL.Time.GetServerTimestamp()) end self:StartRepeatFunc(self.UpdateBPState, offset, 1) self:OnDefaultShow(offset) return end end local nextTime = 0 if leftTime <= matchTimeCfg.WaitBattle then self.bpState = STATE_READY_BATTLE self.stageEndTime = leftTime nextTime = self.stageEndTime elseif leftTime > matchTimeCfg.WaitBattle and leftTime <= matchTimeCfg.ChangeHeroPlace + matchTimeCfg.WaitBattle then self.bpState = STATE_ADJUST self.stageEndTime = leftTime - matchTimeCfg.WaitBattle nextTime = self.stageEndTime elseif leftTime > matchTimeCfg.ChangeHeroPlace + matchTimeCfg.WaitBattle and leftTime <= matchTimeCfg.ChooseHeroTime + matchTimeCfg.ChangeHeroPlace + matchTimeCfg.WaitBattle then self.bpState = STATE_PICK self.stageEndTime = leftTime - (matchTimeCfg.ChangeHeroPlace + matchTimeCfg.WaitBattle) local isLeftRound, roundLeftTime = self:GetBPRoundDetail() self.isLeftRound = isLeftRound nextTime = roundLeftTime self.group_BanSelect.loop_bpHero:RefreshCells(false) elseif leftTime > matchTimeCfg.ChooseHeroTime + matchTimeCfg.ChangeHeroPlace + matchTimeCfg.WaitBattle and leftTime <= matchTimeCfg.ChooseHeroTime + matchTimeCfg.ChangeHeroPlace + matchTimeCfg.WaitBattle + matchTimeCfg.BanHeroTime then self.bpState = STATE_BAN self.stageEndTime = leftTime - (matchTimeCfg.ChooseHeroTime + matchTimeCfg.ChangeHeroPlace + matchTimeCfg.WaitBattle) local _, roundLeftTime = self:GetBPRoundDetail() nextTime = roundLeftTime else --大于配置时间,是个异常状态,防止表现异常,切到pick状态,表现是pick时间变长了 self.bpState = STATE_PICK self.stageEndTime = leftTime - (matchTimeCfg.ChooseHeroTime + matchTimeCfg.ChangeHeroPlace + matchTimeCfg.WaitBattle) nextTime = self.stageEndTime end self:StartRepeatFunc(self.UpdateBPState, nextTime, 1) --处于pick阶段时,需要保存对方的阵容,用于在adjust阶段显示,调整过程中对方不可见 if self.bpState == STATE_PICK then for i, v in ipairs(self.rightBPInfo.PickHero) do self.enemyConstFormationHeroIdList[i] = v end end self:OnBPStateChanged() end function UIFairSoloTournamentBanSelect:UpdateBPDesc(isBan, isLeft, heroNum) if isBan then local playerName = "" if isLeft then playerName = self.group_Left.txt_Name.text else playerName = self.group_Right.txt_Name.text end self.txt_Info.text = string.FormatByIdsId(Const_IDS.IDS_FairTournament_AliveBan, playerName, FairTournamentBanNum) else if heroNum == 6 then if self.context.isWatch then UIUtils.SetLabelText(self.txt_Info, Const_IDS["IDS_FairTournament_QuickHero2"]) else UIUtils.SetLabelText(self.txt_Info, Const_IDS["IDS_FairTournament_QuickHero"]) end else local playerName = "" if isLeft then playerName = self.group_Left.txt_Name.text else playerName = self.group_Right.txt_Name.text end self.txt_Info.text = string.FormatByIdsId(Const_IDS.IDS_FairTournament_PlayerPickHero, playerName, heroNum) end end end function UIFairSoloTournamentBanSelect:OnBPStateChanged() if self.bpState then local isLeftRound, roundLeftTime, roundNum = self:GetBPRoundDetail() if self.bpState == STATE_BAN then self.state_Middle:SetState(0) UIUtils.SetActive(self.group_Info, true) UIUtils.SetActive(self.group_BanSelect.group_TitleBan, true) UIUtils.SetActive(self.group_BanSelect.group_TitleSelect, false) self.group_BanSelect.cdTimer_BP:ResetAndBeginCustomTimer(false, roundLeftTime, 0, "{0}s", 1) if isLeftRound then UIUtils.SetLabelText(self.group_Left.lab_Empty, Const_IDS.IDS_FairTournament_WaitBan) self.group_Right.lab_Empty.text = nil self.group_BanSelect.lab_Title.text = string.FormatByIdsId(Const_IDS.IDS_FairTournament_BanHeroChoose, #self.leftBPInfo.BanHero.."/"..FairTournamentBanNum) else UIUtils.SetLabelText(self.group_Right.lab_Empty, Const_IDS.IDS_FairTournament_WaitBan) self.group_Left.lab_Empty.text = nil self.group_BanSelect.lab_Title.text = string.FormatByIdsId(Const_IDS.IDS_FairTournament_BanHeroChoose, #self.rightBPInfo.BanHero.."/"..FairTournamentBanNum) end self:UpdateBPDesc(true, isLeftRound, nil) elseif self.bpState == STATE_PICK then UIUtils.SetActive(self.group_Info, true) UIUtils.SetActive(self.banSelectTip, true) self.state_Middle:SetState(0) UIUtils.SetActive(self.group_BanSelect.group_TitleBan, false) UIUtils.SetActive(self.group_BanSelect.group_TitleSelect, true) self.group_BanSelect.cdTimer_BP:ResetAndBeginCustomTimer(false, roundLeftTime, 0, "{0}s", 1) if MDL.FairSoloTournament.GetCurMatchTimeID() == MDL.FairSoloTournament.Enum_BigStage.FairScreening then self:UpdateBPDesc(false, isLeftRound, 6) else if roundNum == 1 then self:UpdateBPDesc(false, isLeftRound, 2) elseif roundNum == 2 then self:UpdateBPDesc(false, isLeftRound, 4) elseif roundNum == 3 then self:UpdateBPDesc(false, isLeftRound, 4) elseif roundNum == 4 then self:UpdateBPDesc(false, isLeftRound, 2) end end elseif self.bpState == STATE_ADJUST then UIUtils.SetActive(self.group_Info, false) UIUtils.SetActive(self.banSelectTip, false) self.state_Middle:SetState(2) self.group_Adjustment.cdTimer_Adjustment:ResetAndBeginCustomTimer(false, self.stageEndTime, 0, "{0}s", 1) elseif self.bpState == STATE_READY_BATTLE then UIUtils.SetActive(self.group_Info, false) UIUtils.SetActive(self.banSelectTip, false) self.state_Middle:SetState(1) self.group_Prepare.cdTimer_Prepare:ResetAndBeginCustomTimer(false, self.stageEndTime, 0, "{0}s", 1) end self:UpdateBPDetail(self.group_Left, self.leftBPInfo, true, isLeftRound, roundNum) self:UpdateBPDetail(self.group_Right, self.rightBPInfo, false, isLeftRound, roundNum) end end function UIFairSoloTournamentBanSelect:ShowSelectBanHero(comp, heroId) local heroData = DataSheetManager.HeroNum:GetDataByID(heroId) comp.img_HeroShow.rectTransform:SetLocalPosition(0, 0, 0) UIUtils.SetSpritePivotPos(comp.img_HeroShow, string.format(HeroHalfCardImagePath, heroData.HalfCardImage), 0.9) local heroData = DataSheetManager.HeroNum:GetDataByID(heroId) UIUtils.SetLabelText(comp.txt_HeroName, Const_IDS[heroData.NameIDS]) UTL.Item.SetLocalizationImage(nil, comp.img_MSZ, CountryIconName[heroData.Kingdom]) UIUtils.SetImageByAssetBundle(comp.img_Country, CountryBGPath[heroData.Kingdom]) CTL.HeroSelect.SetHeroProfession(heroId, comp.obj_Profession, true) end function UIFairSoloTournamentBanSelect:UpdateBPDetail(comp, bpInfo, isLeft, isLeftRound, roundNum) if self.bpState == STATE_BAN then UIUtils.SetActive(comp.group_Ban, false) UIUtils.SetActive(comp.group_Select, true) if bpInfo.BanHero and #bpInfo.BanHero > 0 then UIUtils.SetActive(comp.group_Empty, false) UIUtils.SetActive(comp.group_Hero, true) local banHeroID = bpInfo.BanHero[1] if banHeroID and banHeroID > 0 then self:ShowSelectBanHero(comp, banHeroID) end UIUtils.SetGray(comp.img_HeroShow, true) UIUtils.SetActive(comp.img_Ban, true) else UIUtils.SetActive(comp.group_Empty, true) UIUtils.SetActive(comp.group_Hero, false) end for i, cell in ipairs(comp.group_SelectHero) do self:RefreshHeroCell(cell, 0) UIUtils.SetActive(cell.img_Select, false) end comp.state_Lock:SetState(LOCK_STATE_HIDE_ALL) elseif self.bpState == STATE_PICK then if isLeft then for i, cell in ipairs(comp.group_SelectHero) do local heroId = bpInfo.PickHero[i] self:RefreshHeroCell(cell, heroId) end else --小组赛是盲选,参赛者不同步对方选的内容,只同步是否选将 if MDL.FairSoloTournament.GetCurMatchTimeID() == MDL.FairSoloTournament.Enum_BigStage.FairScreening and self.context.isWatch == false then for i, cell in ipairs(comp.group_SelectHero) do self:RefreshHeroCell(cell, 0) local heroId = bpInfo.PickHero[i] if heroId and heroId > 0 then UIUtils.SetActive(cell.img_Select, true) else UIUtils.SetActive(cell.img_Select, false) end end else for i, cell in ipairs(comp.group_SelectHero) do local heroId = bpInfo.PickHero[i] self:RefreshHeroCell(cell, heroId) UIUtils.SetActive(cell.img_Select, false) end end end UIUtils.SetActive(comp.group_Ban, false) UIUtils.SetActive(comp.group_Select, true) --小组赛pick不用先后手,小组赛之后才需要先后手 if MDL.FairSoloTournament.GetCurMatchTimeID() == MDL.FairSoloTournament.Enum_BigStage.FairScreening then if isLeft == false and self.context.isWatch == false then comp.state_Lock:SetState(LOCK_STATE_HIDE_ALL) else comp.state_Lock:SetState(LOCK_STATE_SHOW_ALL) end else --先Ban武将的一方,先选第一组主副将;后Ban的一方再选第一、二组主副将;先Ban的一方再选第二、三组主副将;后Ban的一方再选第三组主副将 if roundNum == 1 then --第一轮pick,pick那一方亮第一行,另一方全部置灰 if isLeftRound then if isLeft then comp.state_Lock:SetState(LOCK_STATE_SHOW_1) else comp.state_Lock:SetState(LOCK_STATE_HIDE_ALL) end else if isLeft then comp.state_Lock:SetState(LOCK_STATE_HIDE_ALL) else comp.state_Lock:SetState(LOCK_STATE_SHOW_1) end end elseif roundNum == 2 then --第二轮pick,pick那一方亮1、2行,另一方全部置灰 if isLeftRound then if isLeft then comp.state_Lock:SetState(LOCK_STATE_SHOW_2) else comp.state_Lock:SetState(LOCK_STATE_HIDE_ALL) end else if isLeft then comp.state_Lock:SetState(LOCK_STATE_HIDE_ALL) else comp.state_Lock:SetState(LOCK_STATE_SHOW_2) end end elseif roundNum == 3 then --第三轮pick,pick那一方亮2、3行,另一方全部置灰 if isLeftRound then if isLeft then comp.state_Lock:SetState(LOCK_STATE_SHOW_3) else comp.state_Lock:SetState(LOCK_STATE_HIDE_ALL) end else if isLeft then comp.state_Lock:SetState(LOCK_STATE_HIDE_ALL) else comp.state_Lock:SetState(LOCK_STATE_SHOW_3) end end elseif roundNum == 4 then --第四轮pick,pick那一方亮第3行,另一方全部置灰 if isLeftRound then if isLeft then comp.state_Lock:SetState(LOCK_STATE_SHOW_4) else comp.state_Lock:SetState(LOCK_STATE_HIDE_ALL) end else if isLeft then comp.state_Lock:SetState(LOCK_STATE_HIDE_ALL) else comp.state_Lock:SetState(LOCK_STATE_SHOW_4) end end end end elseif self.bpState == STATE_ADJUST then if isLeft then for i, cell in ipairs(comp.group_SelectHero) do local heroId = bpInfo.PickHero[i] self:RefreshHeroCell(cell, heroId) end else if self.context.isWatch then for i, cell in ipairs(comp.group_SelectHero) do local heroId = bpInfo.PickHero[i] self:RefreshHeroCell(cell, heroId) UIUtils.SetActive(cell.img_Select, false) end else --参赛者无法看到对方调整顺序 for i, cell in ipairs(comp.group_SelectHero) do local heroId = self.enemyConstFormationHeroIdList[i] self:RefreshHeroCell(cell, heroId) UIUtils.SetActive(cell.img_Select, false) end end end comp.state_Lock:SetState(LOCK_STATE_SHOW_ALL) UIUtils.SetActive(comp.group_Ban, false) UIUtils.SetActive(comp.group_Select, true) elseif self.bpState == STATE_READY_BATTLE then for i, cell in ipairs(comp.group_SelectHero) do local heroId = bpInfo.PickHero[i] self:RefreshHeroCell(cell, heroId) if isLeft == false then UIUtils.SetActive(cell.img_Select, false) end end comp.state_Lock:SetState(LOCK_STATE_SHOW_ALL) UIUtils.SetActive(comp.group_Ban, false) UIUtils.SetActive(comp.group_Select, true) end end function UIFairSoloTournamentBanSelect:SetBasicInfo(comp, acid) local showInfo = MDL.FairSoloTournament.GetPlayerShowInfo(acid) if showInfo.acid == BattleDataGetter.GetAcID() then comp.txt_Name.text = UTL.Color.FormatTextByColor("fff08b", showInfo.name) else comp.txt_Name.text = showInfo.name end UIUtils.SetLabel(comp.txt_Server, CTL.CrossServer.GetServerShowStr(showInfo.ShowServerId)) UIUtils.SetLabel(comp.txt_GuildName, showInfo.guildName) CTL.Character.SetPortraitAndFrame(comp.UIHeroHead, showInfo.PortraitId, showInfo.FrameId) end function UIFairSoloTournamentBanSelect:GetBPRoundDetail() local isLeftRound = false local roundLeftTime = 0 local roundNum = 0 --是否先手 local isLeftFirst = false if self.firstHandType == FIRST_HAND_LEFT then --第一轮先手 第二轮后手 依次类推 if self.context.round % 2 ~= 0 then isLeftFirst = true end else if self.context.round % 2 == 0 then isLeftFirst = true end end local matchTimeCfg = DataSheetManager.FairMatchTime:GetDataByID(MDL.FairSoloTournament.GetCurMatchTimeID()) if self.bpState == STATE_BAN then if self.isBlindBan then isLeftRound = true roundNum = 1 roundLeftTime = self.stageEndTime else local perBanTime = matchTimeCfg.BanHeroTime / 2 --两轮ban if self.stageEndTime > perBanTime then --第一轮ban isLeftRound = isLeftFirst roundLeftTime = self.stageEndTime - perBanTime roundNum = 1 else --第二轮ban isLeftRound = not isLeftFirst roundLeftTime = self.stageEndTime roundNum = 2 end end elseif self.bpState == STATE_PICK then if MDL.FairSoloTournament.GetCurMatchTimeID() == MDL.FairSoloTournament.Enum_BigStage.FairScreening then isLeftRound = true roundNum = 1 roundLeftTime = self.stageEndTime else local perPickTime = matchTimeCfg.ChooseHeroTime / 4 --四轮pick --先Ban武将的一方,先选第一组主副将;后Ban的一方再选第一、二组主副将;先Ban的一方再选第二、三组主副将;后Ban的一方再选第三组主副将 if self.stageEndTime > perPickTime * 3 then --第一轮pick isLeftRound = isLeftFirst roundLeftTime = self.stageEndTime - perPickTime * 3 roundNum = 1 elseif self.stageEndTime > perPickTime * 2 and self.stageEndTime <= perPickTime * 3 then --第二轮pick isLeftRound = not isLeftFirst roundLeftTime = self.stageEndTime - perPickTime * 2 roundNum = 2 elseif self.stageEndTime > perPickTime and self.stageEndTime <= perPickTime * 2 then --第三轮pick isLeftRound = isLeftFirst roundLeftTime = self.stageEndTime - perPickTime roundNum = 3 else --第四轮pick isLeftRound = not isLeftFirst roundLeftTime = self.stageEndTime roundNum = 4 end end end return isLeftRound, roundLeftTime, roundNum end --获取武将bp情况 function UIFairSoloTournamentBanSelect:GetHeroState(heroId) local leftPick = false local leftBan = false local rightPick = false local rightBan = false if self.leftBPInfo then if self:GetIndexByHeroId(self.leftBPInfo.BanHero, heroId) then leftBan = true end if self:GetIndexByHeroId(self.leftBPInfo.PickHero, heroId) then leftPick = true end end if self.rightBPInfo then if self:GetIndexByHeroId(self.rightBPInfo.BanHero, heroId) then rightBan = true end if self:GetIndexByHeroId(self.rightBPInfo.PickHero, heroId) then rightPick = true end end if leftPick and rightPick then return HERO_STATE_ALL_PICK elseif leftPick and rightPick == false then return HERO_STATE_LEFT_PICK elseif leftPick == false and rightPick then return HERO_STATE_RIGHT_PICK end if leftBan and rightBan then return HERO_STATE_ALL_BAN elseif leftBan and rightBan == false then return HERO_STATE_LEFT_BAN elseif leftBan == false and rightBan then return HERO_STATE_RIGHT_BAN end return nil end function UIFairSoloTournamentBanSelect:OnCellInit(scrollRect, index, cellTable, data) UTL.Item.SetHeroIconByHeroId(cellTable.img_HeroHead, CTL.HeroAwaken.DecodeHeroId(data)) UIUtils.SetActive(cellTable.img_experience01, false) local state = self:GetHeroState(data) if state == nil then UIUtils.SetActive(cellTable.img_Mask_Ban, false) UIUtils.SetActive(cellTable.img_Mask_Select, false) UIUtils.SetGray(cellTable.img_HeroHead, false) else --bp需要给头像加个置灰 UIUtils.SetGray(cellTable.img_HeroHead, true) if state == HERO_STATE_ALL_BAN then UIUtils.SetActive(cellTable.img_BanSelect, false) UIUtils.SetActive(cellTable.img_Mask_Select, false) UIUtils.SetActive(cellTable.img_Mask_Ban, true) UIUtils.SetActive(cellTable.img_BanRed, true) UIUtils.SetActive(cellTable.img_BanBlue, true) elseif state == HERO_STATE_ALL_PICK then UIUtils.SetActive(cellTable.img_BanSelect, false) UIUtils.SetActive(cellTable.img_Mask_Ban, false) --小组赛双方pick的将,只显示自己的选将 if self.bpState == STATE_PICK and MDL.FairSoloTournament.GetCurMatchTimeID() == MDL.FairSoloTournament.Enum_BigStage.FairScreening and self.context.isWatch == false then UIUtils.SetActive(cellTable.img_Mask_Select, true) UIUtils.SetActive(cellTable.img_SelectBlue, true) UIUtils.SetActive(cellTable.img_SelectRed, false) else UIUtils.SetActive(cellTable.img_Mask_Select, true) UIUtils.SetActive(cellTable.img_SelectRed, true) UIUtils.SetActive(cellTable.img_SelectBlue, true) end elseif state == HERO_STATE_LEFT_BAN then UIUtils.SetActive(cellTable.img_BanSelect, false) UIUtils.SetActive(cellTable.img_Mask_Select, false) UIUtils.SetActive(cellTable.img_Mask_Ban, true) UIUtils.SetActive(cellTable.img_BanRed, false) UIUtils.SetActive(cellTable.img_BanBlue, true) elseif state == HERO_STATE_LEFT_PICK then UIUtils.SetActive(cellTable.img_BanSelect, false) UIUtils.SetActive(cellTable.img_Mask_Select, true) UIUtils.SetActive(cellTable.img_Mask_Ban, false) UIUtils.SetActive(cellTable.img_SelectRed, false) UIUtils.SetActive(cellTable.img_SelectBlue, true) elseif state == HERO_STATE_RIGHT_BAN then UIUtils.SetActive(cellTable.img_BanSelect, false) UIUtils.SetActive(cellTable.img_Mask_Select, false) UIUtils.SetActive(cellTable.img_Mask_Ban, true) UIUtils.SetActive(cellTable.img_BanRed, true) UIUtils.SetActive(cellTable.img_BanBlue, false) elseif state == HERO_STATE_RIGHT_PICK then UIUtils.SetActive(cellTable.img_BanSelect, false) UIUtils.SetActive(cellTable.img_Mask_Ban, false) --小组赛pick阶段不显示对方选将 if self.bpState == STATE_PICK and MDL.FairSoloTournament.GetCurMatchTimeID() == MDL.FairSoloTournament.Enum_BigStage.FairScreening and self.context.isWatch == false then UIUtils.SetActive(cellTable.img_Mask_Select, false) UIUtils.SetGray(cellTable.img_HeroHead, false) else UIUtils.SetActive(cellTable.img_Mask_Select, true) UIUtils.SetActive(cellTable.img_SelectRed, true) UIUtils.SetActive(cellTable.img_SelectBlue, false) end end end if not self.context.isWatch and self.bpState == STATE_PICK then if self.isLeftRound then if #self.leftSuperGolderHeroCfgIdArr>=FairTournamentSuperHeroCount and not table.containValue(self.leftSuperGolderHeroCfgIdArr, data) and CTL.HeroSelect.IsSuperGoldHero(data) then UIUtils.SetGray(cellTable.img_HeroHead, true) end end end --觉醒前后只能选一个 if self:GetIndexByHeroId(self.leftBPInfo.PickHero, CTL.HeroAwaken.TranslateHeroId(data)) or (MDL.FairSoloTournament.GetCurMatchTimeID() ~= MDL.FairSoloTournament.Enum_BigStage.FairScreening and self:GetIndexByHeroId(self.rightBPInfo.PickHero, CTL.HeroAwaken.TranslateHeroId(data))) then UIUtils.SetGray(cellTable.img_HeroHead, true) end end function UIFairSoloTournamentBanSelect:OnCellClicked(scrollRect, index, cellTable, target, data) if self.isDefaultShow then --保护期间不允许选将 return end if self.context.isWatch then return end if self.bpState == STATE_READY_BATTLE then return end local isLeftRound, _, roundNum = self:GetBPRoundDetail() if isLeftRound == false then --不在自己的阶段,不许操作 return end if self.bpState == STATE_BAN then if self.selectBPCell then UIUtils.SetActive(self.selectBPCell.img_BanSelect, false) end UIUtils.SetActive(cellTable.img_BanSelect, true) self.selectBPCell = cellTable if table.containValue(self.banHeroIdList, data) then table.removebyvalue(self.banHeroIdList, data) elseif self.rightBPInfo and table.containValue(self.rightBPInfo.BanHero, data) then return else if #self.banHeroIdList >= FairTournamentBanNum then return end table.insert(self.banHeroIdList, data) end UIUtils.SetActive(self.group_Left.group_Empty, false) UIUtils.SetActive(self.group_Left.group_Hero, true) self:ShowSelectBanHero(self.group_Left, data) UIUtils.SetGray(self.group_Left.img_HeroShow, false) UIUtils.SetActive(self.group_Left.img_Ban, false) if #self.banHeroIdList == 0 then self.banHeroIdList = {0} end MDL.FairSoloTournament.C2GFairTournamentBP(self.context.groupId, false, self.banHeroIdList) elseif self.bpState == STATE_PICK then local state = self:GetHeroState(data) if state == HERO_STATE_LEFT_BAN or state == HERO_STATE_RIGHT_BAN or state == HERO_STATE_ALL_BAN then CTL.Tips.AddTipsMsg(Const_IDS["IDS_FairTournament_Baned"]) return end --非小组赛不能选被pick的武将 if state == HERO_STATE_RIGHT_PICK and MDL.FairSoloTournament.GetCurMatchTimeID() ~= MDL.FairSoloTournament.Enum_BigStage.FairScreening then logging.warn(LTAG.WARN,"hero has picked:" .. data) return end local index = self:GetIndexByHeroId(self.formationHeroIdList, data) if index then if self:CheckIfReplace(roundNum, index) == false then logging.warn(LTAG.WARN, "clicked illegal index:" .. index) return end if self.selectBPCell then UIUtils.SetActive(self.selectBPCell.img_BanSelect, false) end self:NotifyPickHero(index, 0) UIUtils.SetActive(cellTable.img_BanSelect, false) self.selectBPCell = nil else local emptyIndex for i, v in ipairs(self.formationHeroIdList) do if not v or v <= 0 then emptyIndex = i break end end if emptyIndex == nil then CTL.Tips.AddTipsMsg(Const_IDS["IDS_BossChallenge_ChooseHero_FullHero"]) else if #self.leftSuperGolderHeroCfgIdArr>=FairTournamentSuperHeroCount and CTL.HeroSelect.IsSuperGoldHero(data) then return end if self:GetIndexByHeroId(self.leftBPInfo.PickHero, CTL.HeroAwaken.TranslateHeroId(data)) then return end if MDL.FairSoloTournament.GetCurMatchTimeID() ~= MDL.FairSoloTournament.Enum_BigStage.FairScreening and self:GetIndexByHeroId(self.rightBPInfo.PickHero, CTL.HeroAwaken.TranslateHeroId(data)) then return end local range1, range2 = self:GetRoundRange(roundNum) if emptyIndex > range2 then return end if emptyIndex < range1 then for i = range1, range2 do if self.formationHeroIdList[i] == nil or self.formationHeroIdList[i] <= 0 then emptyIndex = i break end end end if self:CheckIfReplace(roundNum, emptyIndex) == false then logging.warn(LTAG.WARN, "clicked illegal emptyIndex:" .. emptyIndex) return end if self.selectBPCell then UIUtils.SetActive(self.selectBPCell.img_BanSelect, false) end UIUtils.SetActive(cellTable.img_BanSelect, true) self.selectBPCell = cellTable self:NotifyPickHero(emptyIndex, data) end end end end function UIFairSoloTournamentBanSelect:GetRoundRange(roundNum) if MDL.FairSoloTournament.GetCurMatchTimeID() == MDL.FairSoloTournament.Enum_BigStage.FairScreening then return 1, 6 end if roundNum == 1 then return 1, 2 end if roundNum == 2 then --我是第二轮,只能操作前四个武将位置 return 1, 4 end if roundNum == 3 then --我是第三轮,只能操作后四个武将位置 return 3, 6 end if roundNum == 4 then --我是第四轮,只能操作后两个武将位置 return 5, 6 end end function UIFairSoloTournamentBanSelect:CheckIfReplace(roundNum, index) if MDL.FairSoloTournament.GetCurMatchTimeID() == MDL.FairSoloTournament.Enum_BigStage.FairScreening then return true end if roundNum == 1 and index > 2 then --我是第一轮,只能操作前两个武将位置 return false end if roundNum == 2 and index > 4 then --我是第二轮,只能操作前四个武将位置 return false end if roundNum == 3 and index <= 2 then --我是第三轮,只能操作后四个武将位置 return false end if roundNum == 4 and index <= 4 then --我是第四轮,只能操作后两个武将位置 return false end return true end --选中即通知 function UIFairSoloTournamentBanSelect:NotifyPickHero(pos, heroId) self.formationHeroIdList[pos] = heroId self:RefreshSingleHeroCell(pos) MDL.FairSoloTournament.C2GFairTournamentBP(self.context.groupId, false, nil, self.formationHeroIdList) end function UIFairSoloTournamentBanSelect:OnStageChanged() if self.context.isWatch then local stageInfo = MDL.FairSoloTournament.GetStageInfo(MDL.FairSoloTournament.GetCurStageID()) if stageInfo and stageInfo.state == MDL.FairSoloTournament.Enum_State.Battle then for i, groupInfo in ipairs(stageInfo.groupInfos) do if groupInfo.groupId == self.context.groupId then --观战者只有当房间创建之后才可以后续观战 if groupInfo.isBattleEnd == false then CTL.FairSoloTournament.TryWatchBattle(groupInfo) end break end end end end end function UIFairSoloTournamentBanSelect:OnButtonClicked(comp) if comp == self.btn_Close then NetManager.OpenLog = false logging.crit(LTAG.NET, "CloseLog") self:CloseView() MDL.FairSoloTournament.FairTournamentBPWatchReq(MDL.FairSoloTournament.WATCHTYPE_CANCEL, self.context.groupId) else if self.context.isWatch == false then local isLeftRound = self:GetBPRoundDetail() if isLeftRound == false then return end if self.bpState == STATE_READY_BATTLE then return end local index = self:GetIndexByInteractiveItem(comp) if index then local isLeftRound, _, roundNum = self:GetBPRoundDetail() if isLeftRound and self:CheckIfReplace(roundNum, index) == false then return end self:NotifyPickHero(index, 0) if self.selectBPCell then UIUtils.SetActive(self.selectBPCell.img_BanSelect, false) self.selectBPCell = nil end end end end end function UIFairSoloTournamentBanSelect:RefreshSingleHeroCell(index) if index <= 6 then local heroId = self.formationHeroIdList[index] local cell = self.group_Left.group_SelectHero[index] self:RefreshHeroCell(cell, heroId) else logging.error(LTAG.ERROR, "传入的index: ", index, ", 超过了6,请检查!") end end function UIFairSoloTournamentBanSelect:RefreshHeroCell(cell, heroId) if heroId and heroId > 0 then UTL.Item.SetHeroIconByHeroId(cell.img_HeroHead, CTL.HeroAwaken.DecodeHeroId(heroId)) UIUtils.SetActive(cell.group_FormationHero, true) UIUtils.SetActive(cell.img_Empty, false) else UIUtils.SetActive(cell.group_FormationHero, false) UIUtils.SetActive(cell.img_Empty, true) end end function UIFairSoloTournamentBanSelect:OnBeginDrag(comp, eventData) if self.bpState ~= STATE_ADJUST then return end self.dragItem = GameObject.Instantiate(comp.transform.parent.parent.gameObject) self.dragItem.transform:SetParent(self.dragParentTrans, false) self.dragItem.transform:GetChild(0):GetComponentInChildren(typeof(Image)).raycastTarget = false self.dragIndex = self:GetIndexByInteractiveItem(comp) self.dragItemId = self.formationHeroIdList[self.dragIndex] end function UIFairSoloTournamentBanSelect:OnDrag(comp, eventData) if self.dragItem then UIUtils.ScreenPointToWorldPointInRectangle(self.dragItem, eventData) end end function UIFairSoloTournamentBanSelect:OnEndDrag(comp, eventData) self.dragIndex = nil self.dragItemId = nil if self.dragItem then GameObject.Destroy(self.dragItem) self.dragItem = nil end end function UIFairSoloTournamentBanSelect:OnDrop(comp, eventData) if not eventData.pointerEnter or not self.dragItemId or self.dragItemId <= 0 then self.dragIndex = nil self.dragItemId = nil if self.dragItem then GameObject.Destroy(self.dragItem) self.dragItem = nil end return end local dropIndex = self:GetIndexByInteractiveItem(comp) if dropIndex and dropIndex ~= self.dragIndex then local dragIndex = self:GetIndexByHeroId(self.formationHeroIdList, self.dragItemId) local loopDragIndex = self:GetIndexByHeroId(self.heroList, self.dragItemId) local loopDropIndex = self:GetIndexByHeroId(self.heroList, self.formationHeroIdList[dropIndex]) self.formationHeroIdList[dragIndex] = self.formationHeroIdList[dropIndex] self.formationHeroIdList[dropIndex] = self.dragItemId self:RefreshSingleHeroCell(dragIndex) self:RefreshSingleHeroCell(dropIndex) self.group_BanSelect.loop_bpHero:UpdateIndex(loopDragIndex - 1) if loopDropIndex then self.group_BanSelect.loop_bpHero:UpdateIndex(loopDropIndex - 1) end MDL.FairSoloTournament.C2GFairTournamentBP(self.context.groupId, false, nil, self.formationHeroIdList) end self.dragIndex = nil self.dragItemId = nil if self.dragItem then GameObject.Destroy(self.dragItem) self.dragItem = nil end end function UIFairSoloTournamentBanSelect:GetIndexByHeroId(list, id) for i, v in ipairs(list) do if v == id then return i end end return nil end function UIFairSoloTournamentBanSelect:GetIndexByInteractiveItem(comp) for i, v in ipairs(self.group_Left.group_SelectHero) do if comp == v.btn_FormationHero or comp == v.img_Empty then return i end end return nil end return UIFairSoloTournamentBanSelect