89 lines
3.3 KiB
Lua
Raw Normal View History

2025-01-04 23:00:19 +08:00
local EventAction_RoundEnd = {
GameTime = 0;
GameEndEvent = -1;
NewRoundEvent = -1
}
-- 触发器激活时将执行Action的Execute
function EventAction_RoundEnd:Execute(...)
if not UGCGameSystem.IsServer() then return end
self.bEnableActionTick = true
-- 关闭观战
local AllController = UGCGameSystem.GetAllPlayerController()
for i, PC in pairs(AllController) do
UGCGameSystem.LeaveSpectating(PC)
end
-- 获取当前MVP玩家
local MVPPlayer = UGCGameSystem.GameState:GetMVPPlayer()
if MVPPlayer > 0 then
UGCGameSystem.GameState:AddPlayerCoin(MVPPlayer, GlobalConfigs.GameSetting.MVPPlayerAddCoin)
end
-- 停止更新钥匙持有时间
UGCGameSystem.GameState:StopUpdateTeamKeyTime()
-- 根据获胜方及回合数等因素,增加所有玩家的金币数
UGCGameSystem.GameState:RoundFinishAddCoin()
-- 显示获胜方
UGCSendRPCSystem.ClientShowUI(nil, WidgetConfig.EUIType.Winner, true, false, UGCGameSystem.GameState:GetWinner(), MVPPlayer)
-- 初始化游戏时间
self.GameStartTime = UGCSystemLibrary.GetGameTime();
self.LastUpdateRemainTime = self.GameTime
if GlobalConfigs.GameSetting.AutoSwapBornPoint and UGCGameSystem.GameState:GetRoundNum() == GlobalConfigs.GameSetting.MaxRound // 2 then
self.bSwaped = true
UGCEventSystem.SendEvent(EventEnum.SwapBornPoint)
end
-- 发送回合结束事件到客户端
UGCSendRPCSystem.RPCEvent(nil, EventEnum.RoundEnd)
UGCLogSystem.Log("[EventAction_RoundEnd_Execute] Finish")
return true
end
function EventAction_RoundEnd:GameFinish()
self.bEnableActionTick = false
-- 隐藏获胜方UI
UGCSendRPCSystem.ClientShowUI(nil, WidgetConfig.EUIType.Winner, false)
local CTScore = UGCGameSystem.GameState:GetTeamScore(TeamConfig.TeamType.CT)
local TScore = UGCGameSystem.GameState:GetTeamScore(TeamConfig.TeamType.T)
-- 剩余轮次
local RemainingRounds = GlobalConfigs.GameSetting.MaxRound - UGCGameSystem.GameState:GetRoundNum()
-- 达到最大轮次或剩余轮次不足以支持一方获胜
if RemainingRounds <= 0 or RemainingRounds < math.abs(CTScore - TScore) then
UGCGameSystem.GameState:GameFinish()
-- 发送游戏结束事件
UGCEventSystem.SendEvent(self.GameEndEvent)
else
-- 记录存活玩家的背包武器及配件信息
UGCGameSystem.GameState:RecordPlayerBackpackInfo()
-- 触发新的回合事件
UGCEventSystem.SendEvent(self.NewRoundEvent)
end
if self.bSwaped then
UGCSendRPCSystem.RPCEvent(nil, EventEnum.AddTip, TipConfig.TipType.SwapBronPoint)
end
end
function EventAction_RoundEnd:Update(DeltaSeconds)
local CurrentRealTime = UGCSystemLibrary.GetGameTime();
local RemainTime = self.GameTime - (CurrentRealTime - self.GameStartTime);
local CurrentUpdateRemainTime = math.ceil(RemainTime)
-- 更新游戏时间
if self.LastUpdateRemainTime - CurrentUpdateRemainTime >= 1 then
-- 判断游戏时间是否已结束
if CurrentUpdateRemainTime <= 0 then
self.LastUpdateRemainTime = 0
self:GameFinish()
else
self.LastUpdateRemainTime = CurrentUpdateRemainTime
end
end
end
return EventAction_RoundEnd