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

145 lines
5.0 KiB
Lua
Raw Permalink 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:AsyncLoadRandomMap()
-- 其他逻辑
self:OtherExecuteLogic()
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
self:OtherFinishLogic()
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 MapNameList = 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
self.MapIndex = MapIndex
UGCSendRPCSystem.RPCEvent(nil, EventEnum.LoadMap, MapIndex)
LevelStreamUtil.LoadStreamLevels(MapNameList, {Object = self, Func = self.LoadMapFinish}, false);
end
function EventAction_WaitingPlayer:LoadMapFinish()
UGCLogSystem.Log("[EventAction_WaitingPlayer_LoadMapFinish]")
-- 刷新出生点
UGCEventSystem.SendEvent(EventEnum.UpdatePlayerStartList)
-- 重置所有玩家
UGCGameSystem.SendModeCustomEvent("ResetAllPlayer")
-- 其他逻辑
self:OtherLoadMapFinishLogic()
end
-- 其他逻辑 --------------------------------------------------------------------------------------------
function EventAction_WaitingPlayer:OtherExecuteLogic()
UGCLogSystem.Log("[EventAction_WaitingPlayer_OtherExecuteLogic]")
LevelStreamUtil.LoadStreamLevels(MapConfig.DefaultMaps, {Object = self, Func = self.LoadDefaultMapFinish}, false);
UGCLogSystem.Log("[EventAction_WaitingPlayer_OtherExecuteLogic] Finish")
end
function EventAction_WaitingPlayer:LoadDefaultMapFinish()
UGCLogSystem.Log("[EventAction_WaitingPlayer_LoadDefaultMapFinish]")
-- 刷新出生点
UGCEventSystem.SendEvent(EventEnum.UpdatePlayerStartList)
end
function EventAction_WaitingPlayer:OtherLoadMapFinishLogic()
local MapInfo = MapConfig.MapInfo[self.MapIndex].MiniMapInfo
local MapCentre = MapInfo.MapCentre
-- 注册毒圈信息
SignalCircleConfig.RegisterCircleInfo(6, {X = MapCentre.X, Y = MapCentre.Y}, MapInfo.IsRandomCircle, MapInfo.CircleIndex)
-- 保存载具信息
MyVehicleSystem.SaveAllVehicleTF(self.MapIndex)
end
function EventAction_WaitingPlayer:OtherFinishLogic()
-- 刷新出生点
UGCEventSystem.SendEvent(EventEnum.UpdatePlayerStartList)
-- 根据玩家选择的队伍进行队伍分配
UGCGameSystem.GameState:TeamAllocation()
-- 锁定地图
UGCGameSystem.GameState:MapLock()
-- 显示武器选择界面
UGCSendRPCSystem.ClientShowUI(nil, WidgetConfig.EUIType.WeaponSelect)
end
-- 其他逻辑 --------------------------------------------------------------------------------------------
return EventAction_WaitingPlayer