UGCProjects/BombingTheStarrySky/Script/Blueprint/UGCPlayerStartManager.lua
2025-01-04 23:00:19 +08:00

117 lines
4.4 KiB
Lua

---@class UGCPlayerStartManager_C:BP_PlayerStartManager_C
---@field PlayerStartClass UClass
--Edit Below--
---@type UGCPlayerStartManager_C
local UGCPlayerStartManager = {
AllPlayerStart = {};
ResStartPointIndex = 0;
Team1PlayerStarts = {};
PlayerStartIndexT1 = 0;
PlayerStartDict = {};
StartPointTypesIndex = {};
TempGameState = -1;
};
function UGCPlayerStartManager:ReceiveBeginPlay()
self.SuperClass.ReceiveBeginPlay(self)
UGCEventSystem.AddListener(EventEnum.UpdatePlayerStartList, self.UpdatePlayerStartList, self)
UGCEventSystem.AddListener(EventEnum.ResetPlayerTransformToPlayerStart, self.ResetPlayerTransformToPlayerStart, self)
self:UpdatePlayerStartList()
end
function UGCPlayerStartManager:UpdatePlayerStartList()
self.PlayerStartDict = {}
self.AllPlayerStart = {}
self.StartPointTypesIndex = {}
local TempAllPlayerStart = GameplayStatics.GetAllActorsOfClass(self, self.PlayerStartClass, {})
for k, TempPlayerStart in pairs(TempAllPlayerStart) do
local PlayerStartType = TempPlayerStart.PlayerStartType
if PlayerStartType ~= nil then
if self.PlayerStartDict[PlayerStartType] == nil then
self.PlayerStartDict[PlayerStartType] = {TempPlayerStart}
else
self.PlayerStartDict[PlayerStartType][#self.PlayerStartDict[PlayerStartType] + 1] = TempPlayerStart
end
self.StartPointTypesIndex[PlayerStartType] = 0
end
self.AllPlayerStart[#self.AllPlayerStart + 1] = TempPlayerStart
end
for i, v in pairs(self.PlayerStartDict) do
table.Shuffle(self.PlayerStartDict[i])
end
table.Shuffle(self.AllPlayerStart)
UGCLogSystem.LogTree("[UGCPlayerStartManager_UpdatePlayerStartList]", self.PlayerStartDict)
end
function UGCPlayerStartManager:GetUGCModePlayerStart(Controller)
-- 获取重写的出生点函数返回的出生点,若没有则执行常规流程
local OverridePlayerStart = self:GetOverridePlayerStart(Controller)
if UE.IsValid(OverridePlayerStart) then
return OverridePlayerStart
end
local PlayerStartType = Controller:GetStartPointType()
local ResPlayerStart = self:GetPlayerStartFromPlayerStartType(PlayerStartType)
if ResPlayerStart == nil then
ResPlayerStart = self:GetPlayerStartFromAllPlayerStart()
UGCLogSystem.LogError("[UGCPlayerStartManager_GetUGCModePlayerStart] 没有此类型的出生点 PlayerStartType:%s ", tostring(PlayerStartType))
end
return ResPlayerStart
end
function UGCPlayerStartManager:GetPlayerStartFromPlayerStartType(InPlayerStartType)
local StartPointList = self.PlayerStartDict[InPlayerStartType]
local StartPointIndex = self.StartPointTypesIndex[InPlayerStartType]
if StartPointList == nil or StartPointIndex == nil then return nil end
local ResPlayerStart = StartPointList[StartPointIndex + 1]
self.StartPointTypesIndex[InPlayerStartType] = (StartPointIndex + 1) % #StartPointList
return ResPlayerStart
end
function UGCPlayerStartManager:GetPlayerStartFromAllPlayerStart()
local ResPlayerStart = self.AllPlayerStart[self.ResStartPointIndex + 1]
self.ResStartPointIndex = (self.ResStartPointIndex + 1) % #self.AllPlayerStart
return ResPlayerStart
end
function UGCPlayerStartManager:PlayerStartOverride(Func, Obj)
self.OverrideFunc = Func
self.OverrideObj = Obj
end
function UGCPlayerStartManager:GetOverridePlayerStart(PC)
if self.OverrideFunc then
if self.OverrideObj then
return self.OverrideFunc(self.OverrideObj, PC)
else
return self.OverrideFunc(PC)
end
end
return nil
end
--- 用于将玩家刷新到出生点的事件
function UGCPlayerStartManager:ResetPlayerTransformToPlayerStart(InPC, InPawn)
UGCLogSystem.Log("[UGCPlayerStartManager_ResetPlayerTransformToPlayerStart]")
if UE.IsValid(InPC) and UE.IsValid(InPawn) then
local TargetPlayerStart = self:GetUGCModePlayerStart(InPC)
if UE.IsValid(TargetPlayerStart) then
local Pos = TargetPlayerStart:K2_GetActorLocation()
local Rot = TargetPlayerStart:K2_GetActorRotation()
InPawn:K2_SetActorLocation(Pos)
InPC:ClientSetControlRotation(Rot)
else
UGCLogSystem.LogError("[UGCPlayerStartManager_ResetPlayerTransformToPlayerStart] 没有对应出生点")
end
end
end
return UGCPlayerStartManager;