100 lines
3.3 KiB
Lua
100 lines
3.3 KiB
Lua
|
local EventAction_WaitingPlayer = {
|
|||
|
-- 最大等待时间
|
|||
|
WaitTime = 30;
|
|||
|
WaitFinishEvent = 0;
|
|||
|
WaitFailureEvent = 0;
|
|||
|
-- 至少等待的时间
|
|||
|
AtLeastWaitingTime = 5;
|
|||
|
-- 即将开始的提示
|
|||
|
GameWillBeginWaitTime = 5;
|
|||
|
}
|
|||
|
|
|||
|
-- 触发器激活时,将执行Action的Execute
|
|||
|
function EventAction_WaitingPlayer:Execute(...)
|
|||
|
if not UGCGameSystem.IsServer() then return end
|
|||
|
|
|||
|
UGCGameSystem.GameState:SetGameStateType(CustomEnum.EGameState.Waiting)
|
|||
|
|
|||
|
-- 显示等待界面UI
|
|||
|
UGCGameSystem.GameState:ShowSimplePlayModeUI(WidgetConfig.EUIType.WaitingTime)
|
|||
|
-- 随机加载关卡
|
|||
|
if GlobalConfigs.GameSetting.RandomLoadMap then
|
|||
|
self:AsyncLoadRandomMap()
|
|||
|
end
|
|||
|
|
|||
|
self.DoOnceGameWillBegin = true;
|
|||
|
self.JoinedPlayerNum = 0
|
|||
|
|
|||
|
self.bEnableActionTick = true
|
|||
|
return true
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
function EventAction_WaitingPlayer:Update(DeltaSeconds)
|
|||
|
self.WaitTime = self.WaitTime - DeltaSeconds
|
|||
|
-- 判断是否要发送游戏即将开始提示
|
|||
|
if self.WaitTime <= self.GameWillBeginWaitTime and not self.DoOnceNotifyWillBegin then
|
|||
|
self.DoOnceNotifyWillBegin = true
|
|||
|
UGCSendRPCSystem.RPCEvent(nil, EventEnum.GameWillBegin)
|
|||
|
end
|
|||
|
|
|||
|
-- 获取玩家数量
|
|||
|
self.JoinedPlayerNum = #UGCGameSystem.GetAllPlayerController()
|
|||
|
|
|||
|
-- 判断玩家数是否满足
|
|||
|
if self.JoinedPlayerNum >= GlobalConfigs.GameModeSetting.MaxPlayerNum then
|
|||
|
self.WaitTime = math.min(self.AtLeastWaitingTime, self.WaitTime)
|
|||
|
end
|
|||
|
|
|||
|
if self.WaitTime <= 0 then
|
|||
|
self.WaitTime = 0
|
|||
|
self:WaitPlayJoinFinish(self.JoinedPlayerNum >= GlobalConfigs.GameModeSetting.MinPlayerNum)
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
|
|||
|
-- 更新时间
|
|||
|
UGCGameSystem.GameState:SetGameTime(math.floor(self.WaitTime))
|
|||
|
end
|
|||
|
|
|||
|
|
|||
|
function EventAction_WaitingPlayer:WaitPlayJoinFinish(bWaitSucceed)
|
|||
|
self.bEnableActionTick = false
|
|||
|
if bWaitSucceed then
|
|||
|
UGCEventSystem.SendEvent(self.WaitFinishEvent)
|
|||
|
else
|
|||
|
UGCGameSystem.GameState:SetGameStateType(CustomEnum.EGameState.InsufficientNumberOfPeople)
|
|||
|
UGCEventSystem.SendEvent(self.WaitFailureEvent)
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function EventAction_WaitingPlayer:AsyncLoadRandomMap()
|
|||
|
|
|||
|
local MapIndex = 1
|
|||
|
local ProbabilityOfPlayingList = {}
|
|||
|
for i, v in pairs(MapConfig.MapInfo) do
|
|||
|
ProbabilityOfPlayingList[i] = v.ProbabilityOfPlaying
|
|||
|
end
|
|||
|
MapIndex = UGCSystemLibrary.RandomIndex(ProbabilityOfPlayingList)
|
|||
|
UGCGameSystem.GameState:SetMapKey(MapIndex)
|
|||
|
|
|||
|
local MapName = MapConfig.MapInfo[MapIndex].MapName
|
|||
|
UGCLogSystem.Log("[EventAction_WaitingPlayer_AsyncLoadMapFromType] MapIndex:%s, LoadMapIndex:%s, MapName:%s", tostring(MapIndex), tostring(MapIndex), MapName)
|
|||
|
|
|||
|
local SpecialModeType = MapConfig.MapInfo[MapIndex].SpecialModeType
|
|||
|
if SpecialModeType and MapConfig.SpecialModeFunc[SpecialModeType] then
|
|||
|
MapConfig.SpecialModeFunc[SpecialModeType](MapConfig.MapInfo[MapIndex].SpecialModeParam)
|
|||
|
end
|
|||
|
|
|||
|
UGCSendRPCSystem.RPCEvent(nil, EventEnum.LoadMap, MapIndex)
|
|||
|
LevelStreamUtil.LoadStreamLevels({MapName}, {Object = self, Func = self.LoadMapFinish}, false);
|
|||
|
end
|
|||
|
|
|||
|
function EventAction_WaitingPlayer:LoadMapFinish()
|
|||
|
-- 刷新出生点
|
|||
|
UGCEventSystem.SendEvent(EventEnum.UpdatePlayerStartList)
|
|||
|
-- 重置所有玩家
|
|||
|
UGCGameSystem.SendModeCustomEvent("ResetAllPlayer")
|
|||
|
end
|
|||
|
|
|||
|
return EventAction_WaitingPlayer
|