2025-01-04 23:00:19 +08:00

70 lines
2.1 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
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
-- 打乱防守方顺序
UGCGameSystem.GameState:ShuffleAllDefender()
UGCEventSystem.SendEvent(self.WaitFinishEvent)
else
UGCGameSystem.GameState:SetGameStateType(CustomEnum.EGameState.InsufficientNumberOfPeople)
UGCEventSystem.SendEvent(self.WaitFailureEvent)
end
end
return EventAction_WaitingPlayer