106 lines
4.2 KiB
Lua
106 lines
4.2 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)
|
||
|
self:UpdatePlayerStartList()
|
||
|
end
|
||
|
|
||
|
function UGCPlayerStartManager:UpdatePlayerStartList()
|
||
|
UGCLogSystem.Log("[UGCPlayerStartManager_UpdatePlayerStartList] Start")
|
||
|
self.PlayerStartDict = {}
|
||
|
self.AllPlayerStart = {}
|
||
|
self.StartPointTypesIndex = {}
|
||
|
local TempAllPlayerStart = GameplayStatics.GetAllActorsOfClass(self, self.PlayerStartClass, {})
|
||
|
for k, TempPlayerStart in pairs(TempAllPlayerStart) do
|
||
|
local PlayerBornPointID = TempPlayerStart.PlayerBornPointID
|
||
|
local PlayerStartType = TempPlayerStart.PlayerStartType
|
||
|
if PlayerStartType ~= nil then
|
||
|
if self.PlayerStartDict[PlayerStartType] == nil then
|
||
|
self.PlayerStartDict[PlayerStartType] = {}
|
||
|
end
|
||
|
if self.PlayerStartDict[PlayerStartType][PlayerBornPointID] == nil then
|
||
|
self.PlayerStartDict[PlayerStartType][PlayerBornPointID] = {}
|
||
|
end
|
||
|
|
||
|
self.PlayerStartDict[PlayerStartType][PlayerBornPointID][#self.PlayerStartDict[PlayerStartType][PlayerBornPointID] + 1] = TempPlayerStart
|
||
|
self.StartPointTypesIndex[PlayerStartType] = 0
|
||
|
end
|
||
|
self.AllPlayerStart[#self.AllPlayerStart + 1] = TempPlayerStart
|
||
|
end
|
||
|
|
||
|
for TeamType, v in pairs(self.PlayerStartDict) do
|
||
|
for PlayerBornPointID, _ in pairs(v) do
|
||
|
table.Shuffle(self.PlayerStartDict[TeamType][PlayerBornPointID])
|
||
|
end
|
||
|
end
|
||
|
table.Shuffle(self.AllPlayerStart)
|
||
|
UGCLogSystem.LogTree("[UGCPlayerStartManager_UpdatePlayerStartList] PlayerStartDict", self.PlayerStartDict)
|
||
|
UGCLogSystem.LogTree("[UGCPlayerStartManager_UpdatePlayerStartList] AllPlayerStart", self.AllPlayerStart)
|
||
|
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)
|
||
|
if self.PlayerStartDict[InPlayerStartType] == nil then return nil end
|
||
|
local StartPointList = self.PlayerStartDict[InPlayerStartType][UGCGameSystem.GameState:GetMapKey()]
|
||
|
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
|
||
|
|
||
|
return UGCPlayerStartManager;
|