---@type MiniGameMode_Template local MiniGameMode_JumpAndCrouch = { IsGameEnd = false; -- 给玩家结算添加的得分{[PlayerKey] = AddScore, ...} PlayerAddScore = {}; AllActorStarts = {}; JumpCrouchIndies = {}; HitPlayerCount = {}; MoveActors = {}; --- 每次 Pop 的时间 PopTime = 0.8; bOnePlayerFinishGame = true; AddScore = 1; }; --- 游戏初始化 function MiniGameMode_JumpAndCrouch:Init() -- 加载对应的 ActorStart -- 创建一个数组,表示需要蹲 和 跳的,并同步到客户端 local GameTime = 90; local IndiesArr = { 1, 1, 2, }; for i = 1, GameTime do self.JumpCrouchIndies[#self.JumpCrouchIndies + 1] = IndiesArr[math.random(1, #IndiesArr)]; end table.Shuffle(self.JumpCrouchIndies); for i = 1, 10 do table.insert(self.JumpCrouchIndies, 10 * i, 0); end UGCLogSystem.LogTree(string.format("[MiniGameMode_JumpAndCrouch:Init] self.JumpCrouchIndies ="), self.JumpCrouchIndies) self:ReadyActorStart(); for c, v in pairs(self.AllActorStarts) do local Arr = {}; local Index = v.StartIndex for i = 1, 10 do if self.MoveActors[Index] == nil then self.MoveActors[Index] = {}; end local Item = UGCGameSystem.SpawnActor(UGCGameSystem.GameState, self:GetItemClass(), v:K2_GetActorLocation(), VectorHelper.RotZero(), VectorHelper.ScaleOne(), UGCGameSystem.GameState); Item:SetIndex(Index); Item:SetPopIndex(i); Item:SetTolerance(v); self.MoveActors[Index][i] = Item; Arr[i] = true; end v:SetHavingMoveActors(Arr, self.MoveActors[Index]); end UGCEventSystem.AddListener(EventEnum.PlayerDropMiniGameKillBox, self.OnPlayerDropMiniGameKillBox, self) end function MiniGameMode_JumpAndCrouch:GetItemClass() if self.ItemClass == nil then self.ItemClass = UE.LoadClass(UGCGameSystem.GetUGCResourcesFullPath('Asset/Blueprint/MiniLevelActor/JumpAndCrouch/BP_JumpAndCrouch_Actor.BP_JumpAndCrouch_Actor_C')); end return self.ItemClass; end --- 准备时间结束游戏开始 function MiniGameMode_JumpAndCrouch:GameBegin() -- 通知客户端同步发射碰到即后退的圆柱 for i, v in pairs(self.AllActorStarts) do v:ReadyStart(); end -- 所有玩家禁止移动 local PCs = UGCGameSystem.GetAllPlayerController(); for i, PC in pairs(PCs) do PC:SetCinematicMode(true, false, false, true, false); -- UGCSendRPCSystem.ActorRPCNotify(PC.PlayerKey, PC, "BlendToGodCamera"); PC:Server_SetSceneCamera(true) UGCSendRPCSystem.ActorRPCNotify(PC.PlayerKey, PC.Pawn, "ShowPointToSelf", true);; end UGCEventSystem.AddListener(EventEnum.StickOverlapPlayer, self.StickOverlapPlayer, self) end function MiniGameMode_JumpAndCrouch:ReadyActorStart() local AllActors = GameplayStatics.GetAllActorsOfClass(UGCGameSystem.GameState, ObjectPathTable.BP_ActorStart_Class, {}); for i, v in pairs(AllActors) do self.AllActorStarts[#self.AllActorStarts + 1] = v; end UGCLogSystem.LogTree(string.format("[MiniGameMode_JumpAndCrouch_ReadyActorStart] self.AllActorStarts ="), self.AllActorStarts) for i, v in pairs(self.AllActorStarts) do v:SetJumpCrouchIndies(self.JumpCrouchIndies); end end function MiniGameMode_JumpAndCrouch:Update(DeltaTime) -- 判断该玩法是否已结束 if self.IsGameEnd then return end -- 判断是否有玩家退出且场景没有玩家 if self.bIsInGame then if self.LastCheckAliveTime == nil then self.LastCheckAliveTime = 0 end self.LastCheckAliveTime = self.LastCheckAliveTime + DeltaTime if self.LastCheckAliveTime >= 2 then self.LastCheckAliveTime = 0 if UGCSystemLibrary.GetAlivePlayerCount() <= 1 then self:SetMiniGameModeEnd() end end end end --- 设置游戏结束,手动触发会结束该玩法,倒计时结束将自动触发该函数 function MiniGameMode_JumpAndCrouch:SetMiniGameModeEnd() UGCLogSystem.Log("[MiniGameMode_JumpAndCrouch:SetMiniGameModeEnd] 执行") self:MiniGameEnd(); self.IsGameEnd = true; end --- 获取当前回合游戏结算, ---@return "{[PlayerKey] = AddScore, ...}" function MiniGameMode_JumpAndCrouch:GetPlayerAddScore() return self.PlayerAddScore end --- 外层调用,判断该玩法是否已结束 function MiniGameMode_JumpAndCrouch:CheckGameFinish() return self.IsGameEnd end --- 结束触发 function MiniGameMode_JumpAndCrouch:MiniGameEnd() for i, v in pairs(self.AllActorStarts) do v:GameEnd(); end UGCLogSystem.Log("[MiniGameMode_JumpAndCrouch:MiniGameEnd] 执行") for c, Table in pairs(self.MoveActors) do for i, v in pairs(Table) do v:K2_DestroyActor(); end end -- 计算分数 for i, v in pairs(UGCGameSystem.GetAllPlayerController()) do if self.PlayerAddScore[v.PlayerKey] == nil then self.PlayerAddScore[v.PlayerKey] = 4; end end UGCGameSystem.GameState:SetPlayerMiniGameScore(self.PlayerAddScore) local PCs = UGCGameSystem.GetAllPlayerController(); for i, v in pairs(PCs) do v:SetCinematicMode(false, false, false, true, false) end local AllPP = UGCGameSystem.GetAllPlayerPawn() for i, v in pairs(AllPP) do if v:IsAlive() then MiniGameConfig.CheckPlayerTask(v.PlayerKey, MiniGameConfig.MiniGameType.JumpAndCrouch, self.HitPlayerCount[v.PlayerKey], true) end end UGCEventSystem.RemoveListener(EventEnum.StickOverlapPlayer, self.StickOverlapPlayer, self) UGCEventSystem.RemoveListener(EventEnum.PlayerDropMiniGameKillBox, self.OnPlayerDropMiniGameKillBox, self) end ------------------------------------------ Player ------------------------------------------ --- 玩家死亡 function MiniGameMode_JumpAndCrouch:PlayerDead(VictimKey, CauserKey, WeaponID, DamageType, IsHeadShotDamage, Distance, DamageValue, Assister) -- 计算总分 self.PlayerAddScore[VictimKey] = self.AddScore; self.AddScore = self.AddScore + 1; UGCLogSystem.LogTree(string.format("[MiniGameMode_JumpAndCrouch:PlayerDead] self.PlayerAddScore ="), self.PlayerAddScore) -- 改变 UGCLogSystem.Log("[MiniGameMode_JumpAndCrouch:PlayerDead] VictimKey = %s, CauserKey = %s", tostring(VictimKey), tostring(CauserKey)); local AllCount = table.getCount(UGCGameSystem.GetAllPlayerController()); UGCLogSystem.Log("[MiniGameMode_JumpAndCrouch:PlayerDead] AllCount = %s", tostring(AllCount)); if GlobalConfigs.IsDebug then if self.AddScore == AllCount + 1 then self:SetMiniGameModeEnd(); end else if self.AddScore == AllCount then self:SetMiniGameModeEnd(); end end local PC = UGCGameSystem.GetPlayerControllerByPlayerKey(VictimKey); if PC then -- UGCSendRPCSystem.ActorRPCNotify(VictimKey, PC, "BlendToGodCamera"); PC:Server_SetSceneCamera(true) end end --- 玩家伤害修改 ---@param DamageAmount float ---@param VictimPawn UGCPlayerPawn_C ---@param CauserPC UGCPlayerController_C function MiniGameMode_JumpAndCrouch:PlayerDamageModify(DamageAmount, VictimPawn, CauserPC) -- 当前玩家分数 - 1 return DamageAmount; end --- 玩家受控时 function MiniGameMode_JumpAndCrouch:PlayerPossessed(PlayerKey) end function MiniGameMode_JumpAndCrouch:OnPlayerDropMiniGameKillBox(InPlayerKey) local TargetPawn = UGCGameSystem.GetPlayerPawnByPlayerKey(InPlayerKey) if UE.IsValid(TargetPawn) then UGCPawnAttrSystem.SetHealth(TargetPawn, 0) end end ---------------------------------------- Player End ---------------------------------------- function MiniGameMode_JumpAndCrouch:StickOverlapPlayer(PlayerKey) if self.HitPlayerCount[PlayerKey] == nil then self.HitPlayerCount[PlayerKey] = 1 else self.HitPlayerCount[PlayerKey] = self.HitPlayerCount[PlayerKey] + 1 end end return MiniGameMode_JumpAndCrouch;