local EventAction_RoundBegining = { GameTime = 0; --- 准备阶段时间 PreparationTime = 0; GameEndEvent = -1; } -- 触发器激活时,将执行Action的Execute function EventAction_RoundBegining:Execute(...) if not UGCGameSystem.IsServer() then return end self.bEnableActionTick = true -- 初始化游戏时间 self.GameStartTime = UGCSystemLibrary.GetGameTime() self.LastUpdateRemainTime = self.GameTime self.RoundCurrentGameTime = 0. UGCGameSystem.GameState:SetGameTime(self.GameTime) -- 设置当前游戏模式 UGCGameSystem.GameState:SetGameStateType(CustomEnum.EGameState.Playing) -- 设置为下一个回合 UGCGameSystem.GameState:NewRound() -- 准备阶段启用房间阻挡 UGCGameSystem.GameState:EnableHouseBlock(true) -- 重置钥匙 if UGCGameSystem.GameState:GetRoundNum() > 1 then UGCGameSystem.GameState:ResetKey() else UGCGameSystem.GameState:ResetReadKey() end -- 重置队伍钥匙持有时间 UGCGameSystem.GameState:ResetHoldsTheKeyTime() -- 循环更新钥匙持有时间 UGCGameSystem.GameState:LoopUpdateTeamKeyTime() -- 重置所有玩家 local TempPlayerControllers = UGCGameSystem.GetAllPlayerController() -- 给予上轮未死亡玩家的背包物品 UGCGameSystem.GameState:EnableLoopAddPlayerRecordBackpack() -- 清空死亡盒子和可拾取物 UGCSystemLibrary.RemoveActorFromClassName("PlayerTombBox") UGCSystemLibrary.RemoveActorFromClassName("PickUpWrapperActor") -- 记录当前玩家的隐藏分 UGCGameSystem.GameState:RecordPlayerScore() for _,PlayerController in pairs(TempPlayerControllers) do if UE.IsValid(PlayerController.Pawn) then PlayerController.Pawn:K2_DestroyActor() end UGCGameSystem.GetRespawnComponent():AddRespawnPlayer(PlayerController.PlayerKey, 0) PlayerController.PlayerState:ResetInjuryInfo() -- 禁止移动 if GlobalConfigs.GameSetting.ReadyCanNotMove then PlayerController:SetCinematicMode(true, false, false, true, false) end end -- 显示控制UI UGCSendRPCSystem.ActorRPCNotify(nil, UGCGameSystem.GameState, "ShowControlPanel") -- 显示回合准备UI -- UGCSendRPCSystem.ClientShowUI(nil, WidgetConfig.EUIType.RoundReady) -- 客户端发送回合重置事件 UGCSendRPCSystem.RPCEvent(nil, EventEnum.RoundBegining) UGCLogSystem.Log("[EventAction_RoundBegining_Execute] Finish") return true end function EventAction_RoundBegining:RoundFinish() self.bEnableActionTick = false if self.GameEndEvent then -- 发送回合结束事件 UGCEventSystem.SendEvent(self.GameEndEvent) end end function EventAction_RoundBegining:Update(DeltaSeconds) local CurrentRealTime = UGCSystemLibrary.GetGameTime(); self.RoundCurrentGameTime = CurrentRealTime - self.GameStartTime local RemainTime = self.GameTime - self.RoundCurrentGameTime; local CurrentUpdateRemainTime = math.ceil(RemainTime) -- 判断是否存在获胜队伍 if self:DetectionWinner() then self:RoundFinish() return end -- 更新游戏时间 if self.LastUpdateRemainTime - CurrentUpdateRemainTime >= 1 then -- 判断游戏时间是否已结束 if CurrentUpdateRemainTime <= 0 then self.LastUpdateRemainTime = 0 self:RoundFinish() else self.LastUpdateRemainTime = CurrentUpdateRemainTime end UGCGameSystem.GameState:SetGameTime(self.LastUpdateRemainTime) if self.RoundCurrentGameTime >= self.PreparationTime and self.DoOnceDisHouseBlock == nil then self.DoOnceDisHouseBlock = true UGCLogSystem.Log("[EventAction_RoundBegining_Update]") -- 准备阶段结束关闭房间阻挡 UGCGameSystem.GameState:EnableHouseBlock(false) UGCGameSystem.GameState:ReadyTimeFinish() -- 若准备阶段不能行动则设置玩家移动速度缩放 if GlobalConfigs.GameSetting.ReadyCanNotMove then local AllPC = UGCGameSystem.GetAllPlayerController() for i, v in pairs(AllPC) do v:SetCinematicMode(false, false, false, true, false) end end -- 发送准备时间结束到客户端 UGCSendRPCSystem.RPCEvent(nil, EventEnum.RoundReadyFinish) end end end function EventAction_RoundBegining:DetectionWinner() if self.RoundCurrentGameTime >= self.PreparationTime then local CTTeamAlive, TTeamAlive = false, false local CTPlayers = UGCTeamSystem.GetPlayerKeysByTeamID(TeamConfig.TeamType.CT) local TPlayers = UGCTeamSystem.GetPlayerKeysByTeamID(TeamConfig.TeamType.T) for i, v in pairs(CTPlayers) do local TempPawn = UGCGameSystem.GetPlayerPawnByPlayerKey(v) if TempPawn and TempPawn:IsAlive() then CTTeamAlive = true break end end for i, v in pairs(TPlayers) do local TempPawn = UGCGameSystem.GetPlayerPawnByPlayerKey(v) if TempPawn and TempPawn:IsAlive() then TTeamAlive = true break end end --UGCLogSystem.Log("[EventAction_RoundBegining_DetectionWinner] CTTeamAlive:%s, TTeamAlive:%s", tostring(CTTeamAlive), tostring(TTeamAlive)) if CTTeamAlive and TTeamAlive then local CTHoldsTheKeyTime = UGCGameSystem.GameState:GetTeamHoldsTheKeyTimeFormTeamID(TeamConfig.TeamType.CT) local THoldsTheKeyTime = UGCGameSystem.GameState:GetTeamHoldsTheKeyTimeFormTeamID(TeamConfig.TeamType.T) --UGCLogSystem.Log("[EventAction_RoundBegining_DetectionWinner] CTHoldsTheKeyTime:%s, THoldsTheKeyTime:%s", tostring(CTHoldsTheKeyTime), tostring(THoldsTheKeyTime)) if math.max(CTHoldsTheKeyTime, THoldsTheKeyTime) >= GlobalConfigs.GameSetting.TeamNeedHoldsTheKeyTime then if CTHoldsTheKeyTime > THoldsTheKeyTime then UGCGameSystem.GameState:SetWinner(TeamConfig.TeamType.CT) else UGCGameSystem.GameState:SetWinner(TeamConfig.TeamType.T) end else return false end elseif CTTeamAlive then UGCGameSystem.GameState:SetWinner(TeamConfig.TeamType.CT) elseif TTeamAlive then UGCGameSystem.GameState:SetWinner(TeamConfig.TeamType.T) end UGCLogSystem.Log("[EventAction_RoundBegining_DetectionWinner] Finish") return true end end return EventAction_RoundBegining