---@class MiniGameMode_LoopRacing ---@field IsGameEnd bool ---@field PlayerAddScore table 玩家获取的分数 ---@type MiniGameMode_LoopRacing local MiniGameMode_LoopRacing = { IsGameEnd = false; bIsInGame = false; -- 给玩家结算添加的得分{[PlayerKey] = AddScore, ...} PlayerAddScore = {}; MiniGameScore = {}; } --- 游戏初始化 function MiniGameMode_LoopRacing:Init() self:InitMiniGameScore() end --- 准备时间结束游戏开始 function MiniGameMode_LoopRacing:GameBegin() self.bIsInGame = true end function MiniGameMode_LoopRacing:Update(DeltaTime) -- 判断该玩法是否已结束 if self.IsGameEnd then return end -- Update逻辑 -- Update逻辑 End end --- 设置游戏结束,手动触发会结束该玩法,倒计时结束将自动触发该函数 function MiniGameMode_LoopRacing:SetMiniGameModeEnd() if not self.IsGameEnd then self.IsGameEnd = true self:MiniGameEnd() end end --- 获取当前回合游戏结算, ---@return "{[PlayerKey] = AddScore, ...}" function MiniGameMode_LoopRacing:GetPlayerAddScore() return self.PlayerAddScore end --- 外层调用,判断该玩法是否已结束 function MiniGameMode_LoopRacing:CheckGameFinish() return self.IsGameEnd end --- 结束触发 function MiniGameMode_LoopRacing:MiniGameEnd() self:UpdatePlayerAddScore() end ------------------------------------------ Player ------------------------------------------ --- 玩家死亡 function MiniGameMode_LoopRacing:PlayerDead(VictimKey, CauserKey, WeaponID, DamageType, IsHeadShotDamage, Distance, DamageValue, Assister) end --- 玩家伤害修改 function MiniGameMode_LoopRacing:PlayerDamageModify(DamageAmount, VictimPawn, CauserPC) return DamageAmount end --- 玩家受控时 function MiniGameMode_LoopRacing:PlayerPossessed(PlayerKey) end --- 玩家BeginPlay触发 function MiniGameMode_LoopRacing:PlayerBeginPlay(PlayerPawn) end ---------------------------------------- Player End ---------------------------------------- ------------------------------------------ Score ------------------------------------------ function MiniGameMode_LoopRacing:InitMiniGameScore() local AllPC = UGCGameSystem.GetAllPlayerController() for i, PC in pairs(AllPC) do self.MiniGameScore[PC.PlayerKey] = 0 end UGCSendRPCSystem.RPCEvent(nil, EventEnum.UpdateMiniGameAllPlayerScore, self.MiniGameScore) end function MiniGameMode_LoopRacing:PlayerAddMiniGameScore(PlayerKey, AddScore) if self.MiniGameScore[PlayerKey] then self.MiniGameScore[PlayerKey] = self.MiniGameScore[PlayerKey] + AddScore else self.MiniGameScore[PlayerKey] = AddScore end UGCSendRPCSystem.RPCEvent(nil, EventEnum.UpdateMiniGameAllPlayerScore, self.MiniGameScore) end function MiniGameMode_LoopRacing:UpdatePlayerAddScore() local PlayerScoreInfo = {} for i, v in pairs(self.MiniGameScore) do PlayerScoreInfo[#PlayerScoreInfo + 1] = {PlayerKey = i, Score = v} end table.sort(PlayerScoreInfo, function(a, b) return a.Score > b.Score end) local LastScore = nil local LastAddScore = 4 for i, v in pairs(PlayerScoreInfo) do if v.Score == LastScore then self.PlayerAddScore[v.PlayerKey] = LastAddScore else LastAddScore = 5 - i self.PlayerAddScore[v.PlayerKey] = LastAddScore LastScore = v.Score end end local AllPC = UGCGameSystem.GetAllPlayerController() for i, v in pairs(AllPC) do if self.PlayerAddScore[v.PlayerKey] == nil then self.PlayerAddScore[v.PlayerKey] = 1 end end end ---------------------------------------- Score End ---------------------------------------- return MiniGameMode_LoopRacing