local CustomRoom_Controller = {} local EventSystem = require('Event/EventSystem') local SYNC_SOLO_LIMIT_RANK_LIST = DataSheetManager.ConstData:GetDataByID("PK_SingledFight_EntryLimit").IntListValue local SYNC_TVT_LIMIT_RANK_LIST = DataSheetManager.ConstData:GetDataByID("PK_TeamPVP_EntryLimit").IntListValue local ROOM_CREATE_LENGTH_LIMIT = DataSheetManager.ConstData:GetDataByID("PK_RoomName_Limit").IntValue local private = {} private.executeParam = {isInvited = nil, activityID = nil, roomID = nil, pwd = nil, enterType = nil} CustomRoom_Controller.ActivityTitle = { [901] = UIUtils.GetLocalizedTxt(Const_IDS["IDS_PK_Room_1v1Title"]), [902] = UIUtils.GetLocalizedTxt(Const_IDS["IDS_PK_Room_3v3Title"]), } CustomRoom_Controller.FuncActivityIDIndex = { [MDL.Unlock.FunctionType.SyncSoloPK] = LuaConst.ActivityType.SyncSoloPK, [LuaConst.ActivityType.SyncSoloPK] = MDL.Unlock.FunctionType.SyncSoloPK, [MDL.Unlock.FunctionType.SyncTVTPK] = LuaConst.ActivityType.SyncTVTPK, [LuaConst.ActivityType.SyncTVTPK] = MDL.Unlock.FunctionType.SyncTVTPK, } local PKRoomList_LeftTabData = { [1] = { activityID = LuaConst.ActivityType.SyncSoloPK, desc = UIUtils.GetLocalizedTxt(Const_IDS["IDS_1v1Sync_Title"]), funcID = MDL.Unlock.FunctionType.SyncSoloPK, hasLock = false, playerCount = 2, }, [2] = { activityID = LuaConst.ActivityType.SyncTVTPK, desc = UIUtils.GetLocalizedTxt(Const_IDS["IDS_TVTRank"]), funcID = MDL.Unlock.FunctionType.SyncTVTPK, hasLock = false, playerCount = 6, }, } function CustomRoom_Controller.OnStartup() EventSystem.Regist(EventID.UI_SyncTeamPVP_MatchSuccess, private.CloseMessageBoxInRoom) EventSystem.Regist(EventID.UI_SyncSolo_MatchSuccess, private.CloseMessageBoxInRoom) EventSystem.Regist(EventID.UI_DelayToTownPlay, private.OnEnterLevel) end function CustomRoom_Controller.GetTabUnlockByActivityID(activityID) local funcID = CustomRoom_Controller.FuncActivityIDIndex[activityID] local unlockCfgData = DataSheetManager.FuctionUnlock:GetDataByFucID(funcID) local isUnlock = MDL.Unlock.IsCompleteByUnlockTable(unlockCfgData.Unlock_Table) local unlockText = MDL.Unlock.GetUnlockContent(funcID, "IDS_Barrier_Unlock_Des_2") return isUnlock, unlockText end function CustomRoom_Controller.GetPKRoomListLeftTab() local tabs = {} for i, v in ipairs(PKRoomList_LeftTabData) do local isClientUnlock, desc = CustomRoom_Controller.GetTabUnlockByActivityID(v.activityID) local isServerUnlock = MDL.Unlock.IsServerUnlock(v.funcID) if isServerUnlock then if isClientUnlock then v.hasLock = false else v.hasLock = true end table.insert(tabs, v) end end return tabs end --- 点击进入房间 ---@param roomID int 房间号 ---@param pwd string 密码 function CustomRoom_Controller.OnClickEnterRoom(isInvited, activityID, roomID, pwd, enterType) if MDL.CustomRoom.IsEnteringRoom() then return end if CTL.Team.IsInTeam() then CTL.Tips.AddTipsMsg(Const_IDS["IDS_PK_InRanksToJoinRoom"]) UIManager.CloseView(Const_UI_Lua.UIEnum.UIPKAddInPanel) return end if CTL.GuildEscort.IsTransport() then -- 势力押运中 CTL.Tips.AddTipsMsg(Const_IDS["IDS_Escort_Escorting"]) return end -- 先精准查询时间,等数据有了再判断VALID MDL.CustomRoom.SetEnterRoomLock() local param = MDL.CustomRoom.CreateParam(activityID, nil, roomID, nil) MDL.CustomRoom.QueryCustomRoomReq(param) -- 此处延迟执行进入房间 需要查询的结果回来再执行进入 private.executeParam.isInvited = isInvited private.executeParam.activityID = activityID private.executeParam.roomID = roomID private.executeParam.pwd = pwd private.executeParam.enterType = enterType or MDL.CustomRoom.MemberEnterType_Fighter TimerUtil.Interval(private.ExecuteCheckRoomValid, 0.5, 1) end function private.ExecuteCheckRoomValid() local isInvited = private.executeParam.isInvited local activityID = private.executeParam.activityID local roomID = private.executeParam.roomID local pwd = private.executeParam.pwd local enterType = private.executeParam.enterType local isValid, roomInfo = CustomRoom_Controller.IsValidEnterRoom(roomID, isInvited, enterType) if isValid then local briefInfo = roomInfo.BriefInfo if isInvited then -- 被邀请形式加入房间 MDL.CustomRoom.EnterCustomRoomReq(true, briefInfo.ActivityID, briefInfo.RoomID, nil, enterType) elseif roomInfo.BriefInfo.RequirePassword and enterType == MDL.CustomRoom.MemberEnterType_Fighter then -- 点击房间列表进入房间 if pwd then MDL.CustomRoom.EnterCustomRoomReq(false, briefInfo.ActivityID, roomID, pwd, enterType) else UIManager.CloseView(Const_UI_Lua.UIEnum.UIPKAddInPanel) UIManager.OpenView(Const_UI_Lua.UIEnum.UIPKAddInPanel, { activityID = roomInfo.BriefInfo.ActivityID, roomID = roomID, enterType = enterType }) end else -- 无密码进入房间 MDL.CustomRoom.EnterCustomRoomReq(false, briefInfo.ActivityID, roomID, nil, enterType) end else if isInvited then MDL.CustomRoom.RemoveInvitedInfo(activityID, roomID) end UIManager.CloseView(Const_UI_Lua.UIEnum.UIPKAddInPanel) -- 刷新上次筛选查询 MDL.CustomRoom.QueryCustomRoomReq() end end --- 判断roomId指定房间新状态 ---@return isValid bool 是否Valid ---@return roomInfo table 房间信息 function CustomRoom_Controller.IsValidEnterRoom(roomId, isInvited, enterType) local isSuccess, roomInfo = MDL.CustomRoom.GetRoomInfoInCacheByRoomID(roomId) if not isSuccess then -- 房间不存在 CTL.Tips.AddTipsMsg(Const_IDS["IDS_PK_RoomEnterTips_1"]) return false end local activityID = roomInfo.BriefInfo.ActivityID local score = CustomRoom_Controller.GetLevelByActivityID(activityID) local roomAccessDan = roomInfo.BriefInfo.AccessDan local roomMemberCount = roomInfo.BriefInfo.CurrentNum if enterType == MDL.CustomRoom.MemberEnterType_Fighter and not isInvited and roomAccessDan and score < roomAccessDan then -- 不符合准入要求 CTL.Tips.AddTipsMsg(Const_IDS["IDS_PK_RoomEnterTips_2"]) return false end return true, roomInfo end function CustomRoom_Controller.GetPKLimitRankLevelList(activityID, isFilterShow) local rankLimitList = {} if activityID == LuaConst.ActivityType.SyncSoloPK then for i = #SYNC_SOLO_LIMIT_RANK_LIST, 1, -1 do local lv = SYNC_SOLO_LIMIT_RANK_LIST[i] if lv > 0 then table.insert(rankLimitList, { level = lv, desc = CTL.SyncSolo.GetSyncSoloLevelRankName(lv) }) else table.insert(rankLimitList, { level = 0, desc = CustomRoom_Controller.GetLevelDescByActivityID(activityID, 0, isFilterShow) }) end end return rankLimitList elseif activityID == LuaConst.ActivityType.SyncTVTPK then for i = #SYNC_TVT_LIMIT_RANK_LIST, 1, -1 do local lv = SYNC_TVT_LIMIT_RANK_LIST[i] if lv > 0 then table.insert(rankLimitList, { level = lv, desc = CTL.SyncTeamPVP.GetLevelRankName(lv) }) else table.insert(rankLimitList, { level = 0, desc = CustomRoom_Controller.GetLevelDescByActivityID(activityID, 0, isFilterShow) }) end end return rankLimitList end end --- 返回当前玩法段位描述 ---@param activityID int 活动ID ---@param rankLv int 段位 ---@return desc string 段位描述 function CustomRoom_Controller.GetLevelDescByActivityID(activityID, rankLv, isFilterShow) if rankLv and rankLv == 0 then if isFilterShow then return UIUtils.GetLocalizedTxt(Const_IDS["IDS_PK_Hall_Screening_1"]) else return UIUtils.GetLocalizedTxt(Const_IDS["IDS_PK_Hall_EnterLimit_Null"]) end end if activityID == LuaConst.ActivityType.SyncSoloPK then return CTL.SyncSolo.GetSyncSoloLevelRankName(rankLv) elseif activityID == LuaConst.ActivityType.SyncTVTPK then return CTL.SyncTeamPVP.GetLevelRankName(rankLv) end end -- 当前段位分数 function CustomRoom_Controller.GetLevelByActivityID(activityID) if activityID == LuaConst.ActivityType.SyncSoloPK then return CTL.SyncSolo.GetSyncSoloLevelRank() elseif activityID == LuaConst.ActivityType.SyncTVTPK then return CTL.SyncTeamPVP.GetLevelRank() end end function CustomRoom_Controller.IsRoomMemberFull(activityID, currentNum) if activityID == LuaConst.ActivityType.SyncSoloPK then return currentNum >= 2 elseif activityID == LuaConst.ActivityType.SyncTVTPK then return currentNum >= 6 end end function CustomRoom_Controller.IsValidPWD(pwd) if string.isNilOrEmpty(pwd) then -- 尚未输入密码 CTL.Tips.AddTipsMsg(Const_IDS["IDS_PK_RoomEnterTips_4"]) return false end local intPwd = tonumber(pwd) if intPwd == nil then CTL.Tips.AddTipsMsg(Const_IDS["IDS_PK_CreateRoom_Tips_1"]) return false end if UTL.String.GetStrCharCount(pwd) ~= 6 then CTL.Tips.AddTipsMsg(Const_IDS["IDS_PK_CreateRoom_Tips_2"]) return false end return true end function CustomRoom_Controller.GetLimitRoomName(input) return UTL.String.CutStrByLength(input, ROOM_CREATE_LENGTH_LIMIT) end function CustomRoom_Controller.GetRoomDataTB(briefData, supplementData) local tb = { RoomID = briefData and briefData.RoomID, RoomName = briefData and briefData.RoomName, AccessDan = briefData and briefData.AccessDan, RequirePassword = briefData and briefData.RequirePassword, ActivityID = briefData and briefData.ActivityID, CurrentNum = briefData and briefData.CurrentNum, CurState = briefData and briefData.CurState, ShowInHall = supplementData and supplementData.ShowInHall, Password = supplementData and supplementData.Password, HouseOwnerACID = supplementData and supplementData.HouseOwnerACID, } return tb end function CustomRoom_Controller.JoinPKRoomChatChannel() local roomData = MDL.CustomRoom.GetRoomData() local channelRawData = DataSheetManager.Chat:GetDataByID(MDL.ChannelChat.ChannelCfgId.PKRoom) if roomData then local channelName = channelRawData.ChannelPrefix .. roomData.BriefInfo.ActivityID .. "_" .. roomData.BriefInfo.RoomID if not MDL.ChannelChat.IsJoinChannel(MDL.ChannelChat.ChannelCfgId.PKRoom) then MDL.ChannelChat.JoinChannel(MDL.ChannelChat.ChannelCfgId.PKRoom, channelName) end return MDL.ChannelChat.ChannelCfgId.PKRoom, channelName end end function CustomRoom_Controller.LeavePKRoomChatChannel() CTL.WatchBattle.ShutBullet() local chatCfgID = MDL.ChannelChat.ChannelCfgId.PKRoom if MDL.ChannelChat.ExitChannelByChannelType(chatCfgID) then --需要将该频道的消息清除 MDL.ChannelChat.RemoveDlgMsgChannel(chatCfgID) end end function CustomRoom_Controller.TryOpenRoomPanel(isBackView) MDL.CustomRoom.RemoveFirstSceneInitFlag() if MDL.CustomRoom.IsInRoom() then if not UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIActivitiesMain) then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIActivitiesMain) end if not UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIFairPlayMainPanel) then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIFairPlayMainPanel) end if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIPKRoomList) then UIManager.CloseView(Const_UI_Lua.UIEnum.UIPKRoomList) end UIManager.OpenView(Const_UI_Lua.UIEnum.UIPKRoomList, {needQuery = false, activityID = MDL.CustomRoom.GetRoomData().BriefInfo.ActivityID}) UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIPKRoomBase) elseif isBackView then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIActivitiesMain) UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIFairPlayMainPanel) UIManager.OpenView(Const_UI_Lua.UIEnum.UIPKRoomList, {needQuery = true}) end end function CustomRoom_Controller.CloseRoomRelateView() UIManager.CloseView(Const_UI_Lua.UIEnum.UIPKCreatePanel) UIManager.CloseView(Const_UI_Lua.UIEnum.UIPKAddInPanel) UIManager.CloseView(Const_UI_Lua.UIEnum.UIPKChangeRoomNamePanel) UIManager.CloseView(Const_UI_Lua.UIEnum.UIPKChangeConfirmPanel) UIManager.CloseView(Const_UI_Lua.UIEnum.UIPKInviteInPanel) UIManager.CloseView(Const_UI_Lua.UIEnum.UIChannelChatMain) UIManager.CloseView(Const_UI_Lua.UIEnum.UIFriendBase) UIManager.CloseView(Const_UI_Lua.UIEnum.UIMessageBoxView) EventSystem.Dispatch(EventID.UI_CloseAndRecoverView, Const_UI_Lua.UIEnum.UIPKSoloFormationPanel) EventSystem.Dispatch(EventID.UI_CloseAndRecoverView, Const_UI_Lua.UIEnum.UIPKRoomBase) end function private.CloseMessageBoxInRoom() UIManager.CloseView(Const_UI_Lua.UIEnum.UIMessageBoxView) end function CustomRoom_Controller.IsInCustomRoomChannel(channelId) local chatCfgData = MDL.ChannelChat.GetChatCfgDataByChannelId(channelId) if chatCfgData and chatCfgData.ID == MDL.ChannelChat.ChannelCfgId.PKRoom then return MDL.CustomRoom.GetIsWatcher() end return false end function private.OnEnterLevel() MDL.CustomRoom.ClearCurRoomWatchBattleId() end return CustomRoom_Controller