local EventAction_WaitingPlayer = { WaitTime = 40; WaitTeamPlayerNum = 2; WaitFinishEvent = 0; WaitFailureEvent = 0; GameWillBeginWaitTime = 5; } -- 触发器激活时,将执行Action的Execute function EventAction_WaitingPlayer:Execute(...) if not UGCGameSystem.IsServer() then return end UGCGameSystem.GameState:SetGameStateType(CustomEnum.EGameState.Waiting) self.DoOnceGameWillBegin = true; -- 申请玩家加入 UGCGameSystem.GameState:UpdatePlayerJoin() self.LastJudgmentTime = UGCSystemLibrary.GetGameTime() self.bEnableActionTick = true return true end function EventAction_WaitingPlayer:Update(DeltaSeconds) self.WaitTime = self.WaitTime - DeltaSeconds local JoinedPlayerNum = #UGCGameSystem.GetAllPlayerState(false) -- 每秒判断两次 if UGCSystemLibrary.GetGameTime() - self.LastJudgmentTime >= 0.5 then self.LastJudgmentTime = UGCSystemLibrary.GetGameTime() -- 玩家等待时间即将结束,且满足最低开局要求,发送即将开局信息 if (self.DoOnceGameWillBegin and JoinedPlayerNum >= 2 and self.WaitTime < self.GameWillBeginWaitTime) then self.DoOnceGameWillBegin = false UGCGameSystem.GameState:GameWillBeginNotify() end if self:CheckStartEarly(JoinedPlayerNum) then -- 玩家满足直接开局要求,发送即将开局信息 self.DoOnceGameWillBegin = false UGCGameSystem.GameState:GameWillBeginNotify() self.WaitTime = math.min(self.GameWillBeginWaitTime, self.WaitTime) elseif self.WaitTime <= 0 then -- 等待时间结束游戏开局 if JoinedPlayerNum >= 2 then UGCLogSystem.Log("[EventAction_WaitingPlayer_Update] BeginLoadMap") self:WaitPlayerJoinFinishPreload() UGCLogSystem.Log("[EventAction_WaitingPlayer_Update] WaitFinish") else self:WaitPlayJoinFinish(false) end self.bEnableActionTick = false end end --更新GameState.WaitPlayerJoinTime UGCGameSystem.GameState.WaitPlayerJoinTime = math.floor((self.WaitTime > 0 and self.WaitTime or 0 )) end --- 判断提前开始 function EventAction_WaitingPlayer:CheckStartEarly(JoinedPlayerNum) return self.DoOnceGameWillBegin and JoinedPlayerNum >= self.WaitTeamPlayerNum and UGCGameSystem.GameState:SelectedMiniGameCount() >= self.WaitTeamPlayerNum end function EventAction_WaitingPlayer:WaitPlayerJoinFinishPreload() -- self:RandomSelectVoteMap() UGCGameSystem.GameState:SettlementMiniGameList() self:WaitPlayJoinFinish(true) end --- 随机加载三个关卡 function EventAction_WaitingPlayer:RandomAthleticMasterMap() -- 随机加载逻辑 Begin -- 随机加载逻辑 End self:WaitPlayJoinFinish(true) end function EventAction_WaitingPlayer:RandomSelectVoteMap() local PlayerSelectMapList = UGCGameSystem.GameState:GetPlayerSelectMapList() local VoteMapTypes, VoteMapTypes_Set = {}, {} for PlayerKey, MapType in pairs(PlayerSelectMapList) do VoteMapTypes[#VoteMapTypes + 1] = MapType if not table.hasValue(VoteMapTypes_Set, MapType) then VoteMapTypes_Set[#VoteMapTypes_Set + 1] = MapType end end if #VoteMapTypes_Set == 0 then self:AsyncLoadMapFromType(MapConfig.MapType.Random) elseif #VoteMapTypes_Set == 1 then self:AsyncLoadMapFromType(VoteMapTypes_Set[1]) else local RandomVoteMapIndex = math.random(1, #VoteMapTypes) local RandomVoteMapType = VoteMapTypes[RandomVoteMapIndex] UGCSendRPCSystem.RPCEvent(nil, EventEnum.RandomSelectVoteMap, VoteMapTypes, RandomVoteMapIndex) UGCEventSystem.SetTimer(UGCGameSystem.GameState, function() self:AsyncLoadMapFromType(RandomVoteMapType) end, GlobalConfigs.GameSetting.RollMapTime) end end function EventAction_WaitingPlayer:AsyncLoadMapFromType(MapType) UGCGameSystem.GameState:SetMapSelectionResult(MapType) local LoadMapType = UGCGameSystem.GameState:GetMapSelectionFinalResult() --if MapType == MapConfig.MapType.Random then -- local EnableMaps = UGCGameSystem.GameState:GetEnableMapExcludeRandom() -- LoadMapType = table.Rand(EnableMaps) --end UGCLogSystem.Log("[EventAction_WaitingPlayer_AsyncLoadMapFromType] MapType:%s, LoadMapType:%s", tostring(MapType), tostring(LoadMapType)) local MapName = MapConfig.GetMultiModeMapInfo()[LoadMapType].MapName local SpecialModeType = MapConfig.GetMultiModeMapInfo()[LoadMapType].SpecialModeType if SpecialModeType and MapConfig.SpecialModeFunc[SpecialModeType] then MapConfig.SpecialModeFunc[SpecialModeType](MapConfig.GetMultiModeMapInfo()[LoadMapType].SpecialModeParam) end UGCSendRPCSystem.RPCEvent(nil, EventEnum.LoadMap, MapType) LevelStreamUtil.UnLoadStreamLevels(MapConfig.DefaultMaps, {Object = self, Func = self.UnLoadMapFinish}, false); LevelStreamUtil.LoadStreamLevels({MapName}, {Object = self, Func = self.LoadMapFinish}, false); end function EventAction_WaitingPlayer:AsyncLoadMap() local SelectMapType = UGCGameSystem.GameState:GetMapSelectionResult(true) --- 实际地图(若选择的类型为随机,则返回随机出的地图,否则与SelectMapType一致) local MapSelectionFinalType = UGCGameSystem.GameState:GetMapSelectionFinalResult() local MapName = MapConfig.GetMultiModeMapInfo()[MapSelectionFinalType].MapName local SpecialModeType = MapConfig.GetMultiModeMapInfo()[MapSelectionFinalType].SpecialModeType if SpecialModeType and MapConfig.SpecialModeFunc[SpecialModeType] then MapConfig.SpecialModeFunc[SpecialModeType](MapConfig.GetMultiModeMapInfo()[MapSelectionFinalType].SpecialModeParam) end UGCSendRPCSystem.RPCEvent(nil, EventEnum.LoadMap, SelectMapType) LevelStreamUtil.UnLoadStreamLevels(MapConfig.DefaultMaps, {Object = self, Func = self.UnLoadMapFinish}, false); LevelStreamUtil.LoadStreamLevels({MapName}, {Object = self, Func = self.LoadMapFinish}, false); end function EventAction_WaitingPlayer:LoadMapFinish() -- 更新获取新场景的PlayerStart -- UGCGameSystem.GameState:GetPlayerStart() self:WaitPlayJoinFinish(true) end function EventAction_WaitingPlayer:UnLoadMapFinish(bWaitSucceed) UGCLogSystem.Log("[EventAction_WaitingPlayer_UnLoadMapFinish] bWaitSucceed:%s", tostring(bWaitSucceed)) end function EventAction_WaitingPlayer:WaitPlayJoinFinish(bWaitSucceed) if bWaitSucceed then UGCEventSystem.SendEvent(self.WaitFinishEvent) else UGCGameSystem.GameState:SetGameStateType(CustomEnum.EGameState.InsufficientNumberOfPeople) UGCEventSystem.SendEvent(self.WaitFailureEvent) end end return EventAction_WaitingPlayer