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

160 lines
4.9 KiB
Lua

---@class MiniGameMode_AvoidBall
---@field IsGameEnd bool
---@field PlayerAddScore table<PlayerKey, int32> 玩家获取的分数
---@type MiniGameMode_AvoidBall
local MiniGameMode_AvoidBall = {
IsGameEnd = false;
bIsInGame = false;
SphereCirclePath = UGCGameSystem.GetUGCResourcesFullPath('Asset/Blueprint/MiniLevelActor/AvoidBall/BP_RadiationCircle.BP_RadiationCircle_C'),
-- 给玩家结算添加的得分{[PlayerKey] = AddScore, ...}
PlayerAddScore = {};
AddScore = 1;
PlayerList = {};
PlayerStunEnemyCount = {};
}
---@type BP_RadiationCircle_C
MiniGameMode_AvoidBall.SphereCircle = nil;
--- 游戏初始化
function MiniGameMode_AvoidBall:Init()
self.SphereCircle = UGCSystemLibrary.GetUniqueInstanceFromPath(self.SphereCirclePath);
for i, v in pairs(UGCGameSystem.GetAllPlayerController()) do
self.PlayerList[#self.PlayerList + 1] = v.PlayerKey;
end
end
MiniGameMode_AvoidBall.FireGunActors = {};
--- 准备时间结束游戏开始
function MiniGameMode_AvoidBall:GameBegin()
self.bIsInGame = true
if UE.IsValid(self.SphereCircle) then
self.SphereCircle = UGCSystemLibrary.GetUniqueInstanceFromPath(self.SphereCirclePath);
end
if self.SphereCircle then
self.SphereCircle:ActiveGame();
end
local AllPawn = UGCGameSystem.GetAllPlayerPawn()
for i, v in pairs(AllPawn) do
if v.PlayerKey then
v:SetNowCameraType(CustomEnum.EPlayerPawnCameraType.TopCamera)
-- UGCSendRPCSystem.ActorRPCNotify(v.PlayerKey, v, "SetTopCamera", true)
end
end
end
function MiniGameMode_AvoidBall:Update(DeltaTime)
-- 判断该玩法是否已结束
if self.IsGameEnd then return end
-- Update逻辑
-- Update逻辑 End
end
--- 设置游戏结束,手动触发会结束该玩法,倒计时结束将自动触发该函数
function MiniGameMode_AvoidBall:SetMiniGameModeEnd()
if not self.IsGameEnd then
self.IsGameEnd = true
self:MiniGameEnd()
end
end
--- 获取当前回合游戏结算,
---@return table<PlayerKey, int32> "{[PlayerKey] = AddScore, ...}"
function MiniGameMode_AvoidBall:GetPlayerAddScore()
return self.PlayerAddScore
end
--- 外层调用,判断该玩法是否已结束
function MiniGameMode_AvoidBall:CheckGameFinish()
return self.IsGameEnd
end
--- 结束触发
function MiniGameMode_AvoidBall:MiniGameEnd()
-- 计算分数
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)
self.SphereCircle:StopGame();
self.SphereCircle:ClearGunAndBullet()
end
------------------------------------------ Player ------------------------------------------
--- 玩家死亡
function MiniGameMode_AvoidBall:PlayerDead(VictimKey, CauserKey, WeaponID, DamageType, IsHeadShotDamage, Distance, DamageValue, Assister)
self.PlayerAddScore[VictimKey] = self.AddScore;
self.AddScore = self.AddScore + 1;
local RemoveIndex = 0;
for i, v in pairs(self.PlayerList) do
if v == VictimKey then
RemoveIndex = i;
end
end
table.remove(self.PlayerList, RemoveIndex);
-- 改变
local AllCount = table.getCount(UGCGameSystem.GetAllPlayerController());
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
--- 玩家伤害修改
function MiniGameMode_AvoidBall:PlayerDamageModify(DamageAmount, VictimPawn, CauserPC)
-- 判断玩家受到伤害之后的反应
-- 受到其他玩家的伤害
if VictimPawn ~= nil and CauserPC ~= nil and CauserPC.PlayerKey ~= nil and VictimPawn.PlayerKey ~= CauserPC.PlayerKey then
if SkillConfig.ExeSkill(SkillConfig.ESkillType.Stun, VictimPawn) then
if self.PlayerStunEnemyCount[CauserPC.PlayerKey] == nil then
self.PlayerStunEnemyCount[CauserPC.PlayerKey] = 1
else
self.PlayerStunEnemyCount[CauserPC.PlayerKey] = 1 + self.PlayerStunEnemyCount[CauserPC.PlayerKey]
end
MiniGameConfig.CheckPlayerTask(CauserPC.PlayerKey, MiniGameConfig.MiniGameType.AvoidBall, self.PlayerStunEnemyCount[CauserPC.PlayerKey], false)
end
UGCLogSystem.Log("[MiniGameMode_Colorful_PlayerDamageModify]")
return 0
end
return DamageAmount
end
--- 玩家受控时
function MiniGameMode_AvoidBall:PlayerPossessed(PlayerKey)
end
--- 玩家BeginPlay触发
function MiniGameMode_AvoidBall:PlayerBeginPlay(PlayerPawn)
end
---------------------------------------- Player End ----------------------------------------
return MiniGameMode_AvoidBall