UGCProjects/GZJ/Script/Blueprint/UGCPlayerStartManager.lua

97 lines
4.0 KiB
Lua
Raw Permalink Normal View History

2025-01-08 22:46:12 +08:00
local UGCPlayerStartManager = {};
function UGCPlayerStartManager:GetUGCModePlayerStart(Controller)
if UGCGameSystem.GameState:HasAuthority() == false then
return nil
end
local PlayerState = Controller.PlayerState
if PlayerState == nil then
UE.LogError( "[UGCPlayerStartManager][GetUGCModePlayerStart] Error: PlayerState is nil!")
return nil
end
local AllPlayerStarts = UGCGameSystem.GameState:GetAllPlayerStarts()
local GameStage = UGCGameSystem.GameState.GameStage
local SelectedPlayerStart = nil
if GameStage <= EGameStage.GameReady then
local InArenaPlayerStart = AllPlayerStarts[ETeleportType.InArena]
local FoundedPlayerStart = nil
for _, PlayerStart in pairs(InArenaPlayerStart) do
if not PlayerStart:IsMarkOccupied() then
FoundedPlayerStart = PlayerStart
break
end
end
if FoundedPlayerStart ~= nil and UE.IsValid(FoundedPlayerStart) then
FoundedPlayerStart:SetMarkOccupied()
Controller.InitialPlayerStart = FoundedPlayerStart
local InHangUpRoomPlayerStart = AllPlayerStarts[ETeleportType.InHangupRoom]
for _, PlayerStart in pairs(InHangUpRoomPlayerStart) do
if PlayerStart.PlayerStartID == FoundedPlayerStart.PlayerStartID then
Controller.HangUpRoomPlayerStart = PlayerStart
break
end
end
--将玩家和刷怪器绑定
self:BindSpawnerPlayerKey(FoundedPlayerStart, Controller.PlayerKey)
--将玩家和传送点绑定
self:BindTeleporterPlayerKey(FoundedPlayerStart, Controller.PlayerKey)
SelectedPlayerStart = FoundedPlayerStart
UE.Log("[UGCPlayerStartManager][GetUGCModePlayerStart] Initial: SelectedPlayerStart[%s] BornID[%d] PlayerID[%s]",
KismetSystemLibrary.GetObjectName(SelectedPlayerStart), SelectedPlayerStart.PlayerBornPointID, Controller.PlayerKey)
end
else
if Controller.IsDeadInArena then
SelectedPlayerStart = Controller.InitialPlayerStart
local PlayerPawn = UGCGameSystem.GetPlayerPawnByPlayerKey(Controller.PlayerKey)
PlayerPawn.IsInArena = true
else
SelectedPlayerStart = Controller.HangUpRoomPlayerStart
local PlayerPawn = UGCGameSystem.GetPlayerPawnByPlayerKey(Controller.PlayerKey)
PlayerPawn.IsInArena = false
end
UE.Log("[UGCPlayerStartManager][GetUGCModePlayerStart] IsDeadInArena[%s] SelectedPlayerStart[%s] BornID[%d] PlayerID[%s]",
tostring(Controller.IsDeadInArena), KismetSystemLibrary.GetObjectName(SelectedPlayerStart), SelectedPlayerStart.PlayerBornPointID, Controller.PlayerKey)
end
return SelectedPlayerStart
end
function UGCPlayerStartManager:BindSpawnerPlayerKey(SelectedPlayerStart, InPlayerKey)
local MonsterSpawnerClass = UE.LoadClass(BPClassPath.MonsterSpawner)
if UE.IsValid(MonsterSpawnerClass) then
local PlayerStartID = SelectedPlayerStart:GetPlayerStartID()
local FoundedSpawners = totable(GameplayStatics.GetAllActorsOfClass(self, MonsterSpawnerClass, {}))
for _, Spawner in pairs(FoundedSpawners) do
if PlayerStartID == Spawner:GetSpawnerID() then
Spawner:BindPlayerKey(InPlayerKey)
break
end
end
end
end
function UGCPlayerStartManager:BindTeleporterPlayerKey(SelectedPlayerStart, InPlayerKey)
local TeleporterClass = UE.LoadClass(BPClassPath.Teleporter)
if UE.IsValid(TeleporterClass) then
local PlayerStartID = SelectedPlayerStart:GetPlayerStartID()
local FoundedTeleporters = totable(GameplayStatics.GetAllActorsOfClass(self, TeleporterClass, {}))
for _, Teleporter in pairs(FoundedTeleporters) do
if PlayerStartID == Teleporter:GetTeleporterID() then
Teleporter:SetBindPlayerKey(InPlayerKey)
end
end
end
end
return UGCPlayerStartManager;