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

136 lines
4.8 KiB
Lua

---@class UGCPlayerStartManager_C:BP_PlayerStartManager_C
---@field PlayerStartClass UClass
--Edit Below--
---@type UGCPlayerStartManager_C
local UGCPlayerStartManager = {};
--- 所有的,只会加载一次
---@type table<int32, BP_STPlayerStart_C>
UGCPlayerStartManager.AllPlayerStarts = {};
-- 排完序的列表,从中挨个选择
UGCPlayerStartManager.InOrderPlayerStarts = {};
--- 测试用
UGCPlayerStartManager.TestPlayerStart = nil;
---@type table<int32, BP_PlayerStartBase_C>
UGCPlayerStartManager.TargetPlayerStarts = {};
---@type table<int32, table<int32, BP_PlayerStartBase_C>> 玩家初始化所在的出生点
UGCPlayerStartManager.InitPlayerStarts = {}
function UGCPlayerStartManager:ReceiveBeginPlay()
self.SuperClass.ReceiveBeginPlay(self);
UGCEventSystem.AddListener(EventTypes.ClientAlready, self.OnMapLoaded, self);
UGCEventSystem.AddListener(EventTypes.SelectMapCenter, self.OnSelectMapCenter, self);
GlobalStartManager = self;
RegTool:Register(RegTool.Enums.CheckBigWorldSubLevelLoad, self.CheckBigWorldLoadSuccess, self);
end
function UGCPlayerStartManager:CheckBigWorldLoadSuccess()
self:LoadPlayerStarts()
return not table.isEmpty(self.AllPlayerStarts);
end
function UGCPlayerStartManager:LoadPlayerStarts()
if table.isEmpty(self.AllPlayerStarts) then
UE.FindActorsByClass(self.PlayerStartClass, self.AllPlayerStarts);
UGCLogSystem.LogTree(string.format("[UGCPlayerStartManager:LoadPlayerStarts] self.AllPlayerStarts ="), self.AllPlayerStarts)
for i, v in pairs(self.AllPlayerStarts) do
UGCLogSystem.Log("[UGCPlayerStartManager:LoadPlayerStarts] PlayerBornPoint", v.PlayerBornPointID);
end
end
end
function UGCPlayerStartManager:OnSelectMapCenter(Index, Center)
self:LoadPlayerStarts();
self.TargetPlayerStarts = {};
for i, PlayerStart in pairs(self.AllPlayerStarts) do
if VectorHelper.GetActorDis2D(Center, PlayerStart) < DefaultSettings.MaxStartCenterDis then
-- 找到附近的出生点
table.insert(self.TargetPlayerStarts, PlayerStart);
end
end
UGCLogSystem.LogTree(string.format("[UGCPlayerStartManager:OnSelectMapCenter] self.TargetPlayerStarts ="), self.TargetPlayerStarts)
end
function UGCPlayerStartManager:OnMapLoaded(LoadedMapIndex, IsLoad)
self:LoadPlayerStarts();
end
---@param Controller UGCPlayerController_C
---@return BP_STPlayerStart_C
function UGCPlayerStartManager:GetUGCModePlayerStart(Controller)
if table.isEmpty(self.AllPlayerStarts) then self:LoadPlayerStarts() end
local PlayerStart = table.func(UGCGameSystem.GameState.MiniGameManager, "SelectPlayerStart", self.AllPlayerStarts, Controller);
if PlayerStart and UE.IsValid(PlayerStart) then return PlayerStart; end
return self:GetInitPlayerStart(Controller);
--if table.isEmpty(self.AllPlayerStarts) then return nil; end
--
--if DefaultSettings.EnableTest then
-- if self.TestPlayerStart then return self.TestPlayerStart; end
--end
--
--PlayerStart = self:GetPlayerStartInternal(Controller);
--if DefaultSettings.EnableTest then self.TestPlayerStart = PlayerStart; end
--return PlayerStart;
end
function UGCPlayerStartManager:GetInitPlayerStart(Controller)
local TeamId = UGCPlayerControllerSystem.GetTeamID(Controller);
if self.InitPlayerStarts[TeamId] then
UGCLogSystem.Log("[UGCPlayerStartManager:GetInitPlayerStart] 此时是 Init Player Start")
return self.InitPlayerStarts[TeamId][math.random(#(self.InitPlayerStarts[TeamId]))];
end
UGCLogSystem.Log("[UGCPlayerStartManager:GetInitPlayerStart] 此时还不存在 InitPlayerStarts");
end
function UGCPlayerStartManager:GetPlayerStartInternal(Controller)
-- 出生的时候默认使用
local PlayerKey = Controller.PlayerKey;
-- 检查是否存在
if DefaultSettings.RandomSelectStart then
if table.isEmpty(self.TargetPlayerStarts) then
return self.AllPlayerStarts[math.random(#self.AllPlayerStarts)];
else
return self.TargetPlayerStarts[math.random(#self.TargetPlayerStarts)];
end
end
if table.isEmpty(self.InOrderPlayerStarts[PlayerKey]) then
if table.isEmpty(self.TargetPlayerStarts) then
self.InOrderPlayerStarts[PlayerKey] = TableHelper.DeepCopyTable(self.AllPlayerStarts);
else
self.InOrderPlayerStarts[PlayerKey] = TableHelper.DeepCopyTable(self.TargetPlayerStarts);
end
table.Shuffle(self.InOrderPlayerStarts[PlayerKey]);
end
local PlayerStart = self.InOrderPlayerStarts[PlayerKey][1];
table.remove(self.InOrderPlayerStarts[PlayerKey]);
return PlayerStart;
end
--[[
function UGCPlayerStartManager:ReceiveTick(DeltaTime)
self.SuperClass.ReceiveTick(self, DeltaTime);
end
--]]
--[[
function UGCPlayerStartManager:ReceiveEndPlay()
self.SuperClass.ReceiveEndPlay(self);
end
--]]
--[[
function UGCPlayerStartManager:GetReplicatedProperties()
return
end
--]]
--[[
function UGCPlayerStartManager:GetAvailableServerRPCs()
return
end
--]]
return UGCPlayerStartManager;