85 lines
3.3 KiB
Lua
85 lines
3.3 KiB
Lua
local Action_WaitPlayerJoin = {
|
||
WaitTime = 0;
|
||
WaitTeamPlayerNum = 2;
|
||
WaitFinishEvent = "";
|
||
WaitFailureEvent = "";
|
||
AtLeastWaitingTime = 20;
|
||
GameWillBeginWaitTime = 8;
|
||
}
|
||
|
||
-- 触发器激活时,将执行Action的Execute
|
||
function Action_WaitPlayerJoin:Execute(...)
|
||
UGCGameSystem.GameState:SetGameStateType(Enum.EGameState.Waiting)
|
||
|
||
self.DoOnceGameWillBegin = true;
|
||
self.EnterStateTime = GameplayStatics.GetRealTimeSeconds(self)
|
||
self.ModifiableWaitTime = self.WaitTime
|
||
self.LastUpdateRemainTime = self.WaitTime
|
||
self.JoinedPlayerNum = 0
|
||
|
||
-- 申请玩家加入
|
||
UGCGameSystem.GameState:UpdatePlayerJoin()
|
||
|
||
self.bEnableActionTick = true
|
||
return true
|
||
end
|
||
|
||
|
||
function Action_WaitPlayerJoin:Update(DeltaSeconds)
|
||
local CurrentRealTime = GameplayStatics.GetRealTimeSeconds(self);
|
||
local RemainTime = self.ModifiableWaitTime - (CurrentRealTime - self.EnterStateTime);
|
||
RemainTime = RemainTime >= 0 and RemainTime or 0
|
||
|
||
local CurrentUpdateRemainTime = math.ceil(RemainTime)
|
||
|
||
self.JoinedPlayerNum = #UGCGameSystem.GetAllPlayerState(false)
|
||
|
||
if self.LastUpdateRemainTime - CurrentUpdateRemainTime >= 1 then
|
||
self.LastUpdateRemainTime = CurrentUpdateRemainTime
|
||
end
|
||
-- UGCLogSystem.Log("[Action_WaitPlayerJoin_Update]CurrentRealTime:%f, RemainTime:%f, CurrentUpdateRemainTime:%f, LastUpdateRemainTime:%f, EnterStateTime:%f, ModifiableWaitTime:%f",
|
||
-- CurrentRealTime, RemainTime, CurrentUpdateRemainTime, self.LastUpdateRemainTime, self.EnterStateTime, self.ModifiableWaitTime
|
||
-- )
|
||
|
||
local NowWaitTime = CurrentRealTime - self.EnterStateTime
|
||
|
||
-- 玩家等待时间即将结束,且满足最低开局要求,发送即将开局信息
|
||
if (self.DoOnceGameWillBegin and self.JoinedPlayerNum >= 2 and self.LastUpdateRemainTime < self.GameWillBeginWaitTime) then
|
||
self.DoOnceGameWillBegin = false
|
||
UGCGameSystem.GameState:GameWillBeginNotify()
|
||
self.EnterStateTime = GameplayStatics.GetRealTimeSeconds(self)
|
||
self.ModifiableWaitTime = self.LastUpdateRemainTime
|
||
end
|
||
-- 玩家满足直接开局要求,发送即将开局信息
|
||
if self.JoinedPlayerNum >= self.WaitTeamPlayerNum
|
||
and NowWaitTime >= self.AtLeastWaitingTime then
|
||
|
||
self.LastUpdateRemainTime = math.min(self.GameWillBeginWaitTime, self.LastUpdateRemainTime)
|
||
if self.DoOnceGameWillBegin then
|
||
self.DoOnceGameWillBegin = false
|
||
UGCGameSystem.GameState:GameWillBeginNotify()
|
||
|
||
self.EnterStateTime = GameplayStatics.GetRealTimeSeconds(self)
|
||
self.ModifiableWaitTime = self.LastUpdateRemainTime
|
||
|
||
end
|
||
-- 等待时间结束游戏开局
|
||
elseif CurrentUpdateRemainTime <= 0 then
|
||
if self.JoinedPlayerNum >= 2 then
|
||
UGCGameSystem.SendModeCustomEvent(self.WaitFinishEvent)
|
||
self.LastUpdateRemainTime = 0
|
||
UGCLogSystem.Log("[Action_WaitPlayerJoin_Update] WaitFinish")
|
||
else
|
||
UGCGameSystem.GameState:SetGameStateType(Enum.EGameState.InsufficientNumberOfPeople)
|
||
UGCGameSystem.SendModeCustomEvent(self.WaitFailureEvent)
|
||
end
|
||
|
||
self.bEnableActionTick = false
|
||
end
|
||
|
||
--更新GameState.WaitPlayerJoinTime
|
||
UGCGameSystem.GameState.WaitPlayerJoinTime = self.LastUpdateRemainTime
|
||
end
|
||
|
||
|
||
return Action_WaitPlayerJoin |