2025-01-18 21:26:02 +08:00

82 lines
2.6 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_CountdownMode = {
GameTime = 0;
GameEndEvent = -1;
}
-- 触发器激活时将执行Action的Execute
function EventAction_CountdownMode:Execute(...)
if not UGCGameSystem.IsServer() then return end
UGCLogSystem.Log("[EventAction_CountdownMode_Execute]")
self.bEnableActionTick = true
-- 设置当前游戏模式
UGCGameSystem.GameState:SetGameStateType(CustomEnum.EGameState.Playing)
-- 显示战斗界面UI
UGCGameSystem.GameState:ShowSimplePlayModeUI(WidgetConfig.EUIType.FightPanel)
-- 显示武器选择界面
local AllPlayerKey = UGCSystemLibrary.GetAllPlayerKeys()
for i, PlayerKey in pairs(AllPlayerKey) do
UGCGameSystem.GameState:ShowPlayerSelectWeaponWidget(PlayerKey)
end
-- 重置所有玩家
UGCGameSystem.SendModeCustomEvent("ResetAllPlayers")
-- 重置玩家积分信息
PlayerScoreSystem.ResetAllPlayerScoreData()
-- 重置和平默认的击杀数
UGCSystemLibrary.ResetAllPlayerKillsAndAssists()
-- 重置队伍得分
UGCGameSystem.GameState:ResetTeamScore()
-- 绑定游戏结束事件
UGCEventSystem.AddListener(EventEnum.GameStateChange, self.GameFinish, self)
-- 初始化游戏时间
self.GameStartTime = UGCSystemLibrary.GatRealTimeSeconds()
UGCGameSystem.GameState:SetGameTime(self.GameTime)
UGCLogSystem.Log("[EventAction_CountdownMode_Execute] Finish")
return true
end
function EventAction_CountdownMode:GameFinish(GameStateType)
UGCLogSystem.Log("[EventAction_CountdownMode_GameFinish]")
if GameStateType == CustomEnum.EGameState.End then
self.bEnableActionTick = false
if self.GameEndEvent then
-- 发送游戏结束事件
UGCEventSystem.SendEvent(self.GameEndEvent)
else
UGCLogSystem.Log("[EventAction_CountdownMode_GameFinish] GameEndEvent is nil")
end
UGCEventSystem.RemoveListener(EventEnum.GameStateChange, self.GameFinish, self)
end
end
function EventAction_CountdownMode:Update(DeltaSeconds)
local NowRealTime = UGCSystemLibrary.GatRealTimeSeconds()
local RemainTime = self.GameTime - (NowRealTime - self.GameStartTime);
-- 更新游戏时间
if self.LastRemainTime ~= RemainTime then
-- 判断游戏时间是否已结束
if RemainTime <= 0 then
self.LastRemainTime = 0
UGCGameSystem.GameState:GameFinish()
else
self.LastRemainTime = RemainTime
end
UGCGameSystem.GameState:SetGameTime(self.LastRemainTime)
end
end
return EventAction_CountdownMode