UGCProjects/AthleticMasters/Script/Global/MiniGame/MiniGameMode/MiniGameMode_BePromotedStepByStep.lua
2025-01-04 23:00:19 +08:00

272 lines
12 KiB
Lua

---@class MiniGameMode_BePromotedStepByStep
---@field IsGameEnd bool
---@field PlayerAddScore table<PlayerKey, int32> 玩家获取的分数
---@type MiniGameMode_BePromotedStepByStep
local MiniGameMode_BePromotedStepByStep = {
IsGameEnd = false;
bIsInGame = false;
-- 给玩家结算添加的得分{[PlayerKey] = AddScore, ...}
PlayerAddScore = {};
PlayerCheckPoint = {};
MiniGameScore = {};
CheckPoints = {};
CheckPointsHeight = {};
DestinationScore = 4;
InDestinationPlayers = {};
ZeroHeight = 0.;
PlayerMaxHeight = {};
LastUpdateHeightTime = 0;
}
--- 游戏初始化
function MiniGameMode_BePromotedStepByStep:Init()
self.PlayerGravityScale = MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.BePromotedStepByStep].GameParam.GravityScale
self.JumpScale = MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.BePromotedStepByStep].GameParam.JumpVelocityScale
self.PlayerJumpZVelocity = self.JumpScale * 443.0
self.MoveFloorPath = MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.BePromotedStepByStep].GameParam.MoveFloorPath
self.DisappearFloorPath = MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.BePromotedStepByStep].GameParam.DisappearFloorPath
self.RotatorAttachPath = MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.BePromotedStepByStep].GameParam.RotatorAttachPath
self.CheckPointPath = MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.BePromotedStepByStep].GameParam.CheckPointPath
self.ZeroHeightPointPath = MiniGameConfig.MiniGameInfo[MiniGameConfig.MiniGameType.BePromotedStepByStep].GameParam.ZeroHeightPointPath
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.MiniGameScore[PC.PlayerKey] = 0
self.PlayerCheckPoint[PC.PlayerKey] = 0
self.PlayerMaxHeight[PC.PlayerKey] = 0
end
-- UGCSendRPCSystem.RPCEvent(nil, EventEnum.UpdateMiniGameAllPlayerScore, self.PlayerMaxHeight)
local AllCheckPoints = GameplayStatics.GetAllActorsOfClass(UGCGameSystem.GameState, UE.LoadClass(self.CheckPointPath), {})
for i, CheckPoint in pairs(AllCheckPoints) do
self.CheckPoints[CheckPoint:GetPointIndex()] = CheckPoint
self.CheckPointsHeight[CheckPoint:GetPointIndex()] = CheckPoint:K2_GetActorLocation().Z
end
self.ZeroHeightPoint = UGCSystemLibrary.GetUniqueInstanceFromPath(self.ZeroHeightPointPath)
if self.ZeroHeightPoint then
self.ZeroHeight = self.ZeroHeightPoint:K2_GetActorLocation().Z
end
end
--- 准备时间结束游戏开始
function MiniGameMode_BePromotedStepByStep: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
local AllRotatorAttach = GameplayStatics.GetAllActorsOfClass(UGCGameSystem.GameState, UE.LoadClass(self.RotatorAttachPath), {})
for i, FloorAttach in pairs(AllRotatorAttach) do
FloorAttach:StartRotator(true)
end
local AllPawn = UGCGameSystem.GetAllPlayerPawn()
for i, v in pairs(AllPawn) do
if v.PlayerKey then
v:SetNowCameraType(CustomEnum.EPlayerPawnCameraType.JumpCamera)
-- UGCSendRPCSystem.ActorRPCNotify(v.PlayerKey, v, "SetJumpCamera", true)
end
end
end
function MiniGameMode_BePromotedStepByStep:Update(DeltaTime)
-- 判断该玩法是否已结束
if self.IsGameEnd then return end
-- Update逻辑
local AllPawn = UGCGameSystem.GetAllPlayerPawn()
for i, PlayerPawn in pairs(AllPawn) do
local PlayerWorldHeight = PlayerPawn:K2_GetActorLocation().Z
if PlayerWorldHeight < self.CheckPointsHeight[self.PlayerCheckPoint[PlayerPawn.PlayerKey]] - 5 then
self:PlayerDropMiniGameKillBox(PlayerPawn.PlayerKey)
end
if self.PlayerMaxHeight[PlayerPawn.PlayerKey] == nil then
self.PlayerMaxHeight[PlayerPawn.PlayerKey] = 0.
end
self.PlayerMaxHeight[PlayerPawn.PlayerKey] = math.max(KismetMathLibrary.Round((PlayerWorldHeight - self.ZeroHeight) / 100.), self.PlayerMaxHeight[PlayerPawn.PlayerKey])
end
self.LastUpdateHeightTime = self.LastUpdateHeightTime + DeltaTime
if self.LastUpdateHeightTime > 1 then
self.LastUpdateHeightTime = 0
UGCGameSystem.GameState:SetPlayerMiniGameScore(self.PlayerMaxHeight)
-- UGCSendRPCSystem.RPCEvent(nil, EventEnum.UpdateMiniGameAllPlayerScore, self.PlayerMaxHeight)
for PlayerKey, MaxHeight in pairs(self.PlayerMaxHeight) do
MiniGameConfig.CheckPlayerTask(PlayerKey, MiniGameConfig.MiniGameType.BePromotedStepByStep, MaxHeight, false)
end
end
-- Update逻辑 End
end
--- 设置游戏结束,手动触发会结束该玩法,倒计时结束将自动触发该函数
function MiniGameMode_BePromotedStepByStep:SetMiniGameModeEnd()
if not self.IsGameEnd then
self.IsGameEnd = true
self:MiniGameEnd()
end
end
--- 获取当前回合游戏结算,
---@return "{[PlayerKey] = AddScore, ...}"
function MiniGameMode_BePromotedStepByStep:GetPlayerAddScore()
return self.PlayerAddScore
end
--- 外层调用,判断该玩法是否已结束
function MiniGameMode_BePromotedStepByStep:CheckGameFinish()
return self.IsGameEnd
end
--- 结束触发
function MiniGameMode_BePromotedStepByStep:MiniGameEnd()
-- UGCSendRPCSystem.RPCEvent(nil, EventEnum.UpdateMiniGameAllPlayerScore, self.PlayerMaxHeight)
local PlayerScoreInfo = {}
for i, v in pairs(self.PlayerMaxHeight) 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
UGCEventSystem.RemoveListener(EventEnum.PlayerDropMiniGameKillBox, self.PlayerDropMiniGameKillBox, self)
UGCEventSystem.RemoveListener(EventEnum.OverlapCheckPoint, self.OverlapCheckPoint, self);
end
------------------------------------------ Player ------------------------------------------
--- 玩家死亡
function MiniGameMode_BePromotedStepByStep:PlayerDead(VictimKey, CauserKey, WeaponID, DamageType, IsHeadShotDamage, Distance, DamageValue, Assister)
end
--- 玩家伤害修改
function MiniGameMode_BePromotedStepByStep: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_BePromotedStepByStep:PlayerPossessed(PlayerKey)
end
--- 玩家BeginPlay触发
function MiniGameMode_BePromotedStepByStep:PlayerBeginPlay(PlayerPawn)
UGCLogSystem.Log("[MiniGameMode_BePromotedStepByStep_PlayerBeginPlay] JumpZVelocity:%s, JumpScale:%s", tostring(UGCPawnAttrSystem.GetJumpZVelocity(PlayerPawn)), tostring(self.JumpScale))
-- PlayerPawn:SetCustomJumpZVelocity(443 * self.JumpScale)
PlayerPawn:SetCustomJumpZVelocity(443 * self.JumpScale)
UGCLogSystem.Log("[MiniGameMode_BePromotedStepByStep_PlayerBeginPlay] JumpZVelocity End:%s", tostring(UGCPawnAttrSystem.GetJumpZVelocity(PlayerPawn)))
PlayerPawn:SetGravityScale(self.PlayerGravityScale)
UGCLogSystem.Log("[MiniGameMode_BePromotedStepByStep_PlayerBeginPlay] PlayerGravityScale:%s", tostring(self.PlayerGravityScale))
UGCEventSystem.SetTimer(UGCGameSystem.GameState, function()
if UE.IsValid(PlayerPawn) then
UGCLogSystem.Log("[MiniGameMode_BePromotedStepByStep_PlayerBeginPlay] JumpZVelocity:%s, JumpScale:%s", tostring(UGCPawnAttrSystem.GetJumpZVelocity(PlayerPawn)), tostring(self.JumpScale))
-- PlayerPawn:SetCustomJumpZVelocity(443 * self.JumpScale)
PlayerPawn:SetCustomJumpZVelocity(443 * self.JumpScale)
UGCLogSystem.Log("[MiniGameMode_BePromotedStepByStep_PlayerBeginPlay] JumpZVelocity End:%s", tostring(UGCPawnAttrSystem.GetJumpZVelocity(PlayerPawn)))
PlayerPawn:SetGravityScale(self.PlayerGravityScale)
end
end, 1)
end
--function MiniGameMode_BePromotedStepByStep:CheckPlayerMovementParam()
-- local AllPawn = UGCGameSystem.GetAllPlayerPawn()
-- for i, v in pairs(AllPawn) do
-- if UGCPawnAttrSystem.GetJumpZVelocity(v) ~= self.PlayerJumpZVelocity then
-- UGCPawnAttrSystem.SetJumpZVelocity(v, self.PlayerJumpZVelocity)
-- end
-- end
--end
---------------------------------------- Player End ----------------------------------------
function MiniGameMode_BePromotedStepByStep: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)
end
end
end
--function MiniGameMode_BePromotedStepByStep: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_BePromotedStepByStep: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
-- self: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
else
-- self:PlayerAddMiniGameScore(PlayerKey, PointIndex - PlayerPointIndex)
end
end
end
return MiniGameMode_BePromotedStepByStep