182 lines
6.4 KiB
Lua
182 lines
6.4 KiB
Lua
---@class MiniGameMode_Parkour
|
|
---@field IsGameEnd bool
|
|
---@field PlayerAddScore table<PlayerKey, int32> 玩家获取的分数
|
|
|
|
|
|
---@type MiniGameMode_Parkour
|
|
local MiniGameMode_Parkour = {
|
|
IsGameEnd = false;
|
|
bIsInGame = false;
|
|
-- 给玩家结算添加的得分{[PlayerKey] = AddScore, ...}
|
|
PlayerAddScore = {};
|
|
PlayerCheckPoint = {};
|
|
CheckPoints = {};
|
|
DestinationScore = 4;
|
|
InDestinationPlayers = {};
|
|
}
|
|
|
|
--- 游戏初始化
|
|
function MiniGameMode_Parkour:Init()
|
|
self.MoveFloorPath = MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.Parkour].GameParam.MoveFloorPath
|
|
self.DisappearFloorPath = MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.Parkour].GameParam.DisappearFloorPath
|
|
self.CheckPointPath = MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.Parkour].GameParam.CheckPointPath
|
|
|
|
UGCEventSystem.AddListener(EventEnum.PlayerDropMiniGameKillBox, self.PlayerDropMiniGameKillBox, self)
|
|
UGCEventSystem.AddListener(EventEnum.OverlapCheckPoint, self.OverlapCheckPoint, self)
|
|
|
|
local AllPC = UGCGameSystem.GetAllPlayerController()
|
|
for i, PC in pairs(AllPC) do
|
|
self.PlayerCheckPoint[PC.PlayerKey] = 0
|
|
end
|
|
|
|
|
|
|
|
local AllCheckPoints = GameplayStatics.GetAllActorsOfClass(UGCGameSystem.GameState, UE.LoadClass(self.CheckPointPath), {})
|
|
for i, CheckPoint in pairs(AllCheckPoints) do
|
|
self.CheckPoints[CheckPoint:GetPointIndex()] = CheckPoint
|
|
end
|
|
end
|
|
|
|
--- 准备时间结束游戏开始
|
|
function MiniGameMode_Parkour:GameBegin()
|
|
self.bIsInGame = true
|
|
local AllMoveFloor = GameplayStatics.GetAllActorsOfClass(UGCGameSystem.GameState, UE.LoadClass(self.MoveFloorPath), {})
|
|
for i, Floor in pairs(AllMoveFloor) do
|
|
Floor:ActiveMove()
|
|
end
|
|
local AllDisappearFloor = GameplayStatics.GetAllActorsOfClass(UGCGameSystem.GameState, UE.LoadClass(self.DisappearFloorPath), {})
|
|
for i, Floor in pairs(AllDisappearFloor) do
|
|
Floor:SetIsActivate(true, true)
|
|
end
|
|
|
|
-- Test
|
|
--local AllPawn = UGCGameSystem.GetAllPlayerPawn()
|
|
--for i, v in pairs(AllPawn) do
|
|
-- v:SetPawnTF({X=0,Y=0,Z=-1000}, VectorHelper.RotZero())
|
|
--end
|
|
-- Test
|
|
end
|
|
|
|
function MiniGameMode_Parkour:Update(DeltaTime)
|
|
-- 判断该玩法是否已结束
|
|
if self.IsGameEnd then return end
|
|
|
|
-- Update逻辑
|
|
|
|
|
|
|
|
-- Update逻辑 End
|
|
end
|
|
|
|
--- 设置游戏结束,手动触发会结束该玩法,倒计时结束将自动触发该函数
|
|
function MiniGameMode_Parkour:SetMiniGameModeEnd()
|
|
if not self.IsGameEnd then
|
|
self.IsGameEnd = true
|
|
self:MiniGameEnd()
|
|
end
|
|
end
|
|
|
|
--- 获取当前回合游戏结算,
|
|
---@return "{[PlayerKey] = AddScore, ...}"
|
|
function MiniGameMode_Parkour:GetPlayerAddScore()
|
|
return self.PlayerAddScore
|
|
end
|
|
|
|
--- 外层调用,判断该玩法是否已结束
|
|
function MiniGameMode_Parkour:CheckGameFinish()
|
|
return self.IsGameEnd
|
|
end
|
|
|
|
--- 结束触发
|
|
function MiniGameMode_Parkour:MiniGameEnd()
|
|
self.PlayerAddScore = UGCGameSystem.GameState:GetPlayerMiniGameAddScore()
|
|
UGCEventSystem.RemoveListener(EventEnum.PlayerDropMiniGameKillBox, self.PlayerDropMiniGameKillBox, self)
|
|
UGCEventSystem.RemoveListener(EventEnum.OverlapCheckPoint, self.OverlapCheckPoint, self);
|
|
end
|
|
|
|
------------------------------------------ Player ------------------------------------------
|
|
|
|
--- 玩家死亡
|
|
function MiniGameMode_Parkour:PlayerDead(VictimKey, CauserKey, WeaponID, DamageType, IsHeadShotDamage, Distance, DamageValue, Assister)
|
|
|
|
end
|
|
|
|
--- 玩家伤害修改
|
|
function MiniGameMode_Parkour:PlayerDamageModify(DamageAmount, VictimPawn, CauserPC)
|
|
if VictimPawn ~= nil and CauserPC ~= nil and CauserPC.PlayerKey ~= nil and VictimPawn.PlayerKey ~= CauserPC.PlayerKey then
|
|
SkillConfig.ExeSkill(SkillConfig.ESkillType.Stun, VictimPawn)
|
|
end
|
|
return 0
|
|
end
|
|
|
|
--- 玩家受控时
|
|
function MiniGameMode_Parkour:PlayerPossessed(PlayerKey)
|
|
|
|
end
|
|
|
|
--- 玩家BeginPlay触发
|
|
function MiniGameMode_Parkour:PlayerBeginPlay(PlayerPawn)
|
|
|
|
end
|
|
|
|
---------------------------------------- Player End ----------------------------------------
|
|
|
|
function MiniGameMode_Parkour:PlayerDropMiniGameKillBox(PlayerKey)
|
|
local PointIndex = self.PlayerCheckPoint[PlayerKey]
|
|
if PointIndex == nil then
|
|
self.PlayerCheckPoint[PlayerKey] = 0
|
|
PointIndex = 0
|
|
end
|
|
local CheckPoint = self.CheckPoints[PointIndex]
|
|
if CheckPoint then
|
|
local Pos, Rot = CheckPoint:GetRespawnTF()
|
|
local PlayerPawn = UGCGameSystem.GetPlayerPawnByPlayerKey(PlayerKey)
|
|
if PlayerPawn then
|
|
PlayerPawn:SetPawnTF(Pos, Rot)
|
|
|
|
--if PlayerPawn.CharacterMovement then
|
|
-- PlayerPawn.CharacterMovement.Velocity = VectorHelper.VectorZero()
|
|
--end
|
|
--PlayerPawn:K2_SetActorLocation(Pos)
|
|
--PlayerPawn:K2_SetActorRotation(Rot)
|
|
--PlayerPawn.bShouldDumpCallstackWhenMovingfast = false
|
|
--PlayerPawn:SetClientLocationOrRotation(Pos, Rot, true, false)
|
|
--PlayerPawn.bShouldDumpCallstackWhenMovingfast = true
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
|
|
function MiniGameMode_Parkour:OverlapCheckPoint(PlayerKey, PointIndex, IsDestination)
|
|
local PlayerPointIndex = self.PlayerCheckPoint[PlayerKey]
|
|
if PlayerPointIndex == nil then
|
|
self.PlayerCheckPoint[PlayerKey] = 0
|
|
PlayerPointIndex = 0
|
|
end
|
|
if PlayerPointIndex < PointIndex then
|
|
self.PlayerCheckPoint[PlayerKey] = PointIndex
|
|
if IsDestination then
|
|
UGCGameSystem.GameState:PlayerAddMiniGameScore(PlayerKey, self.DestinationScore)
|
|
self.DestinationScore = self.DestinationScore - 1
|
|
self.InDestinationPlayers[#self.InDestinationPlayers + 1] = PlayerKey
|
|
local AllPC = UGCGameSystem.GetAllPlayerController()
|
|
local IsFinishGame = true
|
|
for _, PC in pairs(AllPC) do
|
|
if not table.hasValue(self.InDestinationPlayers, PC.PlayerKey) then
|
|
IsFinishGame = false
|
|
break
|
|
end
|
|
end
|
|
if IsFinishGame then
|
|
self:SetMiniGameModeEnd()
|
|
end
|
|
local MaxGameTime = MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.Parkour].MaxGameTime
|
|
MiniGameConfig.CheckPlayerTask(PlayerKey, MiniGameConfig.MiniGameType.Parkour, MaxGameTime - UGCGameSystem.GameState:GetGameTime(), true)
|
|
else
|
|
UGCGameSystem.GameState:PlayerAddMiniGameScore(PlayerKey, PointIndex - PlayerPointIndex)
|
|
end
|
|
end
|
|
end
|
|
|
|
return MiniGameMode_Parkour |