UGCProjects/AthleticMasters/Script/Global/MiniGame/MiniGameMode/MiniGameMode_BreakingIceCubes.lua

143 lines
4.8 KiB
Lua
Raw Normal View History

2025-01-04 23:00:19 +08:00
local MiniGameMode_BreakingIceCubes = {
IsGameEnd = false;
-- 给玩家结算添加的得分{[PlayerKey] = AddScore, ...}
PlayerAddScore = {};
-- 目标得分
-- TargetHitScore = 50;
-- 玩家当前击靶得分
MiniGameScore = {};
-- 玩家完成目标的时间{[PlayerKey] = Time, ...}
PlayerFinishMiniGameTime = {};
LastUpdatePlayerScoreTime = 0.;
PlayerScoreIsChange = false;
LastCheckPlayerBackPack = 0.;
bIsInGame = false;
}
function MiniGameMode_BreakingIceCubes:Init()
UGCEventSystem.AddListener(EventEnum.BreakingIceCubes, self.BreakingIceCubesAddScore, self)
self.DefaultBackPack = MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.BreakingIceCubes].GameParam.DefaultBackPack
self.MatrixTargetManagerPath = MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.BreakingIceCubes].GameParam.MatrixTargetManagerPath
self.MatrixTargetManager = UGCSystemLibrary.GetUniqueInstanceFromPath(self.MatrixTargetManagerPath)
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_BreakingIceCubes:GameBegin()
self.bIsInGame = true
self.MatrixTargetManager:StartGame()
end
function MiniGameMode_BreakingIceCubes:Update(DeltaTime)
-- 判断该玩法是否已结束
if self.IsGameEnd then return end
-- Update逻辑
---- 更新玩家得分
--self.LastUpdatePlayerScoreTime = self.LastUpdatePlayerScoreTime + DeltaTime
---- 这里做了个减少RPC发送频率的处理
--if self.PlayerScoreIsChange and self.LastUpdatePlayerScoreTime >= 0.2 then
-- self.LastUpdatePlayerScoreTime = 0.
-- self.PlayerScoreIsChange = false
-- UGCSendRPCSystem.RPCEvent(nil, EventEnum.UpdateMiniGameAllPlayerScore, self.MiniGameScore)
--end
-- 验证背包
self.LastCheckPlayerBackPack = self.LastCheckPlayerBackPack + DeltaTime
if self.LastCheckPlayerBackPack >= 2. then
self.LastCheckPlayerBackPack = 0.
self:CheckBackPack()
end
-- Update逻辑 End
end
--- 设置游戏结束,手动触发会结束该玩法,倒计时结束将自动触发该函数
function MiniGameMode_BreakingIceCubes:SetMiniGameModeEnd()
if not self.IsGameEnd then
self.IsGameEnd = true
self:MiniGameEnd()
end
end
--- 获取当前回合游戏结算,
---@return "{[PlayerKey] = AddScore, ...}"
function MiniGameMode_BreakingIceCubes:GetPlayerAddScore()
return self.PlayerAddScore
end
--- 外层调用,判断该玩法是否已结束
function MiniGameMode_BreakingIceCubes:CheckGameFinish()
return self.IsGameEnd
end
--- 结束触发
function MiniGameMode_BreakingIceCubes:MiniGameEnd()
self.PlayerAddScore = UGCGameSystem.GameState:GetPlayerMiniGameAddScore()
UGCEventSystem.RemoveListener(EventEnum.BreakingIceCubes, self.BreakingIceCubesAddScore, self)
end
--- 玩家BeginPlay触发
function MiniGameMode_BreakingIceCubes:PlayerBeginPlay(PlayerPawn)
end
------------------------------------------ Player ------------------------------------------
function MiniGameMode_BreakingIceCubes:PlayerDead(VictimKey, CauserKey, WeaponID, DamageType, IsHeadShotDamage, Distance, DamageValue, Assister)
end
function MiniGameMode_BreakingIceCubes:PlayerDamageModify(DamageAmount, VictimPawn, CauserPC)
return 0
end
function MiniGameMode_BreakingIceCubes:PlayerPossessed(PlayerPawn, Controller)
end
---------------------------------------- Player End ----------------------------------------
function MiniGameMode_BreakingIceCubes:BreakingIceCubesAddScore(PlayerKey, ID, Score)
if Score == nil then
Score = 1
end
if self.bIsInGame then
-- self.MiniGameScore[PlayerKey] = (self.MiniGameScore[PlayerKey] and self.MiniGameScore[PlayerKey] or 0) + 1
UGCGameSystem.GameState:PlayerAddMiniGameScore(PlayerKey, Score)
MiniGameConfig.CheckPlayerTask(PlayerKey, MiniGameConfig.MiniGameType.BreakingIceCubes, UGCGameSystem.GameState:GetPlayerMiniGameScore(PlayerKey), false)
-- self.PlayerScoreIsChange = true
end
end
--- 验证背包
function MiniGameMode_BreakingIceCubes:CheckBackPack()
local AllPawn = UGCGameSystem.GetAllPlayerPawn()
for _, PlayerPawn in pairs(AllPawn) do
for i, ItemID in pairs(self.DefaultBackPack) do
if ItemID > 0 and UGCBackPackSystem.GetItemCount(PlayerPawn, ItemID) == 0 then
UGCBackPackSystem.AddItem(PlayerPawn, ItemID, 1)
end
end
for i, TheEnum in pairs(ShootWeaponEnums) do
local Weapon = UGCWeaponManagerSystem.GetWeaponBySlot(PlayerPawn, TheEnum);
if Weapon then
UGCGunSystem.EnableInfiniteBullets(Weapon, true)
end
end
end
end
return MiniGameMode_BreakingIceCubes