199 lines
6.6 KiB
Lua
199 lines
6.6 KiB
Lua
local MiniGameMode_DoNotFallDown2 = {
|
|
IsGameEnd = false;
|
|
-- 给玩家结算添加的得分{[PlayerKey] = AddScore, ...}
|
|
PlayerAddScore = {};
|
|
Score = 1;
|
|
bIsInGame = false;
|
|
LastCheckPlayerBackPack = 0.;
|
|
ChaoticWarScore = {};
|
|
PlayerGravityScale = 1;
|
|
StarManagerPath = "";
|
|
DeadPC = {};
|
|
PlayerStepThroughFloorCount = {};
|
|
}
|
|
|
|
--- 游戏初始化
|
|
function MiniGameMode_DoNotFallDown2:Init()
|
|
self.JumpScale = MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.DoNotFallDown2].GameParam.JumpVelocityScale
|
|
self.PlayerGravityScale = MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.DoNotFallDown2].GameParam.GravityScale
|
|
self.FloorManagerPath = MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.DoNotFallDown2].GameParam.FloorManagerPath
|
|
self.FloorManager = UGCSystemLibrary.GetUniqueInstanceFromPath(self.FloorManagerPath)
|
|
|
|
|
|
UGCEventSystem.AddListener(EventEnum.PlayerDropMiniGameKillBox, self.PlayerDropTrap, self)
|
|
|
|
local AllPC = UGCGameSystem.GetAllPlayerController()
|
|
for i, PC in pairs(AllPC) do
|
|
self.ChaoticWarScore[PC.PlayerKey] = 0
|
|
end
|
|
|
|
end
|
|
|
|
--- 准备时间结束游戏开始
|
|
function MiniGameMode_DoNotFallDown2:GameBegin()
|
|
self.bIsInGame = true
|
|
-- 二次赋值
|
|
if not UE.IsValid(self.FloorManager) then
|
|
self.FloorManager = UGCSystemLibrary.GetUniqueInstanceFromPath(self.FloorManagerPath)
|
|
end
|
|
self.FloorManager:SetAllFloorActive(true)
|
|
|
|
UGCEventSystem.SendEvent(EventEnum.UpdateBlockFloorCollision, false)
|
|
UGCEventSystem.AddListener(EventEnum.PlayerStepThroughFloor, self.PlayerStepThroughFloor, self)
|
|
UGCLogSystem.Log("[MiniGameMode_DoNotFallDown2_GameBegin]")
|
|
end
|
|
|
|
function MiniGameMode_DoNotFallDown2:Update(DeltaTime)
|
|
-- 判断该玩法是否已结束
|
|
if self.IsGameEnd then return end
|
|
|
|
-- Update逻辑
|
|
|
|
-- 验证背包
|
|
--self.LastCheckPlayerBackPack = self.LastCheckPlayerBackPack + DeltaTime
|
|
--if self.LastCheckPlayerBackPack >= 1. then
|
|
-- self.LastCheckPlayerBackPack = 0.
|
|
-- self:CheckBackPack()
|
|
--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
|
|
|
|
-- Update逻辑 End
|
|
end
|
|
|
|
--- 设置游戏结束,手动触发会结束该玩法,倒计时结束将自动触发该函数
|
|
function MiniGameMode_DoNotFallDown2:SetMiniGameModeEnd()
|
|
if not self.IsGameEnd then
|
|
self.IsGameEnd = true
|
|
self:MiniGameEnd()
|
|
end
|
|
end
|
|
|
|
--- 获取当前回合游戏结算,
|
|
---@return "{[PlayerKey] = AddScore, ...}"
|
|
function MiniGameMode_DoNotFallDown2:GetPlayerAddScore()
|
|
return self.PlayerAddScore
|
|
end
|
|
|
|
--- 外层调用,判断该玩法是否已结束
|
|
function MiniGameMode_DoNotFallDown2:CheckGameFinish()
|
|
return self.IsGameEnd
|
|
end
|
|
|
|
|
|
--- 结束触发
|
|
function MiniGameMode_DoNotFallDown2:MiniGameEnd()
|
|
-- 给存活玩家+4分
|
|
for i, v in pairs(UGCGameSystem.GetAllPlayerController()) do
|
|
if UGCGameSystem.GameState:GetPlayerMiniGameScore(v.PlayerKey) == 0 then
|
|
UGCGameSystem.GameState:PlayerAddMiniGameScore(v.PlayerKey, 4)
|
|
end
|
|
end
|
|
|
|
self.PlayerAddScore = UGCGameSystem.GameState:GetPlayerMiniGameAddScore()
|
|
|
|
self.FloorManager:SetAllFloorActive(false)
|
|
|
|
UGCEventSystem.RemoveListener(EventEnum.PlayerStepThroughFloor, self.PlayerStepThroughFloor, self)
|
|
UGCEventSystem.RemoveListener(EventEnum.PlayerDropMiniGameKillBox, self.PlayerDropTrap, self)
|
|
end
|
|
|
|
|
|
|
|
------------------------------------------ Player ------------------------------------------
|
|
|
|
--- 玩家死亡
|
|
function MiniGameMode_DoNotFallDown2:PlayerDead(VictimKey, CauserKey, WeaponID, DamageType, IsHeadShotDamage, Distance, DamageValue, Assister)
|
|
end
|
|
|
|
--- 玩家伤害修改
|
|
function MiniGameMode_DoNotFallDown2:PlayerDamageModify(DamageAmount, VictimPawn, CauserPC)
|
|
if CauserPC ~= UGCGameSystem.GetControllerByPawn(VictimPawn) then
|
|
return 0.
|
|
end
|
|
return DamageAmount
|
|
end
|
|
|
|
--- 玩家受控时
|
|
function MiniGameMode_DoNotFallDown2:PlayerPossessed(PlayerKey)
|
|
|
|
end
|
|
|
|
--- 玩家BeginPlay触发
|
|
function MiniGameMode_DoNotFallDown2:PlayerBeginPlay(PlayerPawn)
|
|
PlayerPawn:SetGravityScale(self.PlayerGravityScale)
|
|
PlayerPawn:SetCustomJumpZVelocity(443 * self.JumpScale)
|
|
UGCEventSystem.SetTimer(UGCGameSystem.GameState, function()
|
|
if UE.IsValid(PlayerPawn) then
|
|
PlayerPawn:SetGravityScale(self.PlayerGravityScale)
|
|
PlayerPawn:SetCustomJumpZVelocity(443 * self.JumpScale)
|
|
UGCLogSystem.Log("[MiniGameMode_DoNotFallDown2_AvoidingSpikeStick_PlayerBeginPlay]")
|
|
end
|
|
end, 1)
|
|
end
|
|
|
|
---------------------------------------- Player End ----------------------------------------
|
|
|
|
|
|
|
|
function MiniGameMode_DoNotFallDown2:InsideCheckMiniGameEnd()
|
|
local AllPC = UGCGameSystem.GetAllPlayerController()
|
|
local AliveNum = 0
|
|
for i, v in pairs(AllPC) do
|
|
if self.DeadPC[v.PlayerKey] == nil then
|
|
AliveNum = AliveNum + 1
|
|
end
|
|
end
|
|
if AliveNum <= (GlobalConfigs.IsDebug and 0 or 1) then
|
|
return true
|
|
else
|
|
return false
|
|
end
|
|
--if AliveNum <= 1 then
|
|
-- return true
|
|
--else
|
|
-- return false
|
|
--end
|
|
end
|
|
|
|
function MiniGameMode_DoNotFallDown2:PlayerDropTrap(PlayerKey)
|
|
if self.DeadPC[PlayerKey] then return end
|
|
self.DeadPC[PlayerKey] = 1
|
|
UGCGameSystem.GameState:PlayerAddMiniGameScore(PlayerKey, self.Score)
|
|
-- self:PlayerAddMiniGameScore(PlayerKey, self.Score)
|
|
self.Score = self.Score + 1
|
|
local PC = UGCGameSystem.GetPlayerControllerByPlayerKey(PlayerKey)
|
|
local PP = UGCGameSystem.GetPlayerPawnByPlayerKey(PlayerKey)
|
|
UGCPawnAttrSystem.SetHealth(PP, -1);
|
|
if PC then
|
|
-- UGCSendRPCSystem.ActorRPCNotify(PlayerKey, PC, "BlendToGodCamera")
|
|
PC:Server_SetSceneCamera(true)
|
|
end
|
|
if self:InsideCheckMiniGameEnd() then
|
|
self:SetMiniGameModeEnd()
|
|
end
|
|
end
|
|
|
|
function MiniGameMode_DoNotFallDown2:PlayerStepThroughFloor(PlayerKey)
|
|
if self.PlayerStepThroughFloorCount[PlayerKey] == nil then
|
|
self.PlayerStepThroughFloorCount[PlayerKey] = 1
|
|
else
|
|
self.PlayerStepThroughFloorCount[PlayerKey] = self.PlayerStepThroughFloorCount[PlayerKey] + 1
|
|
end
|
|
MiniGameConfig.CheckPlayerTask(PlayerKey, MiniGameConfig.MiniGameType.DoNotFallDown2, self.PlayerStepThroughFloorCount[PlayerKey], false)
|
|
end
|
|
|
|
|
|
return MiniGameMode_DoNotFallDown2 |