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

142 lines
4.8 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_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 UGCGameSystem.GameState:GetRoundNum() == GlobalConfigs.GameSetting.MaxRound // 2 then
self.bSwaped = true
UGCEventSystem.SendEvent(EventEnum.SwapBornPoint)
end
-- 设置无敌状态
local AllPawn = UGCGameSystem.GetAllPlayerPawn()
for i, v in pairs(AllPawn) do
UGCPawnSystem.SetIsInvincible(v, true)
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) or self:CheckGameEnd() 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
--- 检查玩法人数是否足够
function EventAction_RoundEnd:CheckGameEnd()
local PlayerNum = #UGCGameSystem.GetAllPlayerController()
if PlayerNum == 0 then
return true
end
local TeamModeType = GlobalConfigs.GameModeSetting.TeamModeType
if TeamModeType == CustomEnum.ETeamMode.PersonalWarfare then
if PlayerNum <= 1 then
return true
end
elseif TeamModeType == CustomEnum.ETeamMode.PartyMode then
return false
elseif TeamModeType == CustomEnum.ETeamMode.TeamSports or TeamModeType == CustomEnum.ETeamMode.BurstMode then
local TeamIDs = UGCTeamSystem.GetTeamIDs()
if #TeamIDs <= 1 then
return true
end
local Team1Player = UGCTeamSystem.GetPlayerKeysByTeamID(1)
local Team2Player = UGCTeamSystem.GetPlayerKeysByTeamID(2)
local Team1HasPlayer, Team2HasPlayer = false, false
for i, v in pairs(Team1Player) do
if UGCGameSystem.GetPlayerControllerByPlayerKey(v) then
Team1HasPlayer = true
break
end
end
if not Team1HasPlayer then
return true
end
for i, v in pairs(Team2Player) do
if UGCGameSystem.GetPlayerControllerByPlayerKey(v) then
Team2HasPlayer = true
break
end
end
if not Team2HasPlayer then
return true
end
end
return false
end
return EventAction_RoundEnd