160 lines
4.8 KiB
Lua
160 lines
4.8 KiB
Lua
|
local ActorStartManager = {};
|
|||
|
|
|||
|
--[[
|
|||
|
Tag 说明
|
|||
|
Poison: 表示地图中心点,等于 MapCenter/Center 等
|
|||
|
--]]
|
|||
|
|
|||
|
---@type table<int32, BP_ActorStart_C>
|
|||
|
ActorStartManager.AllStarts = {};
|
|||
|
---@type table<string, table<int32, BP_ActorStart_C>>
|
|||
|
ActorStartManager.TagStarts = {};
|
|||
|
---@type table<int32, BP_ActorStart_C>
|
|||
|
ActorStartManager.NoTagStarts = {};
|
|||
|
---@type table<string, table<int32, AActor>>
|
|||
|
ActorStartManager.SpawnActors = {};
|
|||
|
|
|||
|
ActorStartManager.LoadType = {
|
|||
|
SpawnActor = 1;
|
|||
|
LoadAsPoison = 2,
|
|||
|
}
|
|||
|
|
|||
|
ActorStartManager.LoadConfig = {
|
|||
|
["Hold"] = {
|
|||
|
Type = ActorStartManager.LoadType.SpawnActor,
|
|||
|
Func = function(Start)
|
|||
|
return UGCGameSystem.SpawnActor(GameState, ObjectPath.BP_HoldPoint, Start:K2_GetActorLocation(), Start:K2_GetActorRotation(), VectorHelper.MakeVector1(1), GameState);
|
|||
|
end
|
|||
|
},
|
|||
|
["Vehicle"] = {
|
|||
|
Type = ActorStartManager.LoadType.SpawnActor,
|
|||
|
Func = function(Start)
|
|||
|
local Index = Start.Index
|
|||
|
local Path = nil;
|
|||
|
if VehicleTable.Car[Index] then
|
|||
|
Path = VehicleTable.Car[Index].Path;
|
|||
|
else
|
|||
|
Index = math.random(table.getCount(VehicleTable.Car));
|
|||
|
if VehicleTable.Car[Index] then
|
|||
|
Path = VehicleTable.Car[Index].Path
|
|||
|
end
|
|||
|
end
|
|||
|
if Path then
|
|||
|
return UGCVehicleSystem.SpawnVehicleNew(Path, Start:K2_GetActorLocation(), Start:K2_GetActorRotation(), true, true);
|
|||
|
end
|
|||
|
return nil;
|
|||
|
end,
|
|||
|
},
|
|||
|
["Poison"] = {
|
|||
|
Type = ActorStartManager.LoadType.LoadAsPoison,
|
|||
|
Func = function(Start)
|
|||
|
-- 设置进去
|
|||
|
PoisonManager.MapCenterActors[Start.Index] = Start;
|
|||
|
-- 检查是否有 Holds
|
|||
|
UGCLogSystem.Log("[Poison] 执行")
|
|||
|
for i, Hold in pairs(Resources["TotalHoldPoint"]) do
|
|||
|
local Dis = VectorHelper.GetDistance2D(Hold, Start);
|
|||
|
if Dis < DefaultSettings.MaxStartCenterDis * 2 then
|
|||
|
Hold.CenterIndex = Start.Index;
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
},
|
|||
|
["Team"] = {
|
|||
|
Type = ActorStartManager.LoadType.LoadAsPoison,
|
|||
|
Func = function(Start)
|
|||
|
-- 说明是最初的玩家出生点,寻找一下
|
|||
|
if Resources["InitTeamStart"] == nil then Resources["InitTeamStart"] = {}; end
|
|||
|
Resources["InitTeamStart"][Start.Index] = Start;
|
|||
|
UGCLogSystem.LogTree(string.format("InitTeamStart ="), Resources["InitTeamStart"]);
|
|||
|
end
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
-- 当选择了地图中心点之后
|
|||
|
function ActorStartManager:OnSelectMapCenter(InCenterIndex, InCenter)
|
|||
|
|
|||
|
end
|
|||
|
|
|||
|
function ActorStartManager:OnMapLoadComplete()
|
|||
|
-- 加载地图上的所有 ActorStart
|
|||
|
if IsServer then
|
|||
|
UGCLogSystem.Log("[ActorStartManager:OnMapLoadComplete] 开始加载")
|
|||
|
if #self.AllStarts == 0 then
|
|||
|
self.NoTagStarts = {};
|
|||
|
self.AllStarts = {};
|
|||
|
self.TagStarts = {};
|
|||
|
self:ClearAllActors();
|
|||
|
ObjectPath.AddFunc("BP_ActorStart", function(TargetClass)
|
|||
|
UE.FindActorsByClass(TargetClass, self.AllStarts);
|
|||
|
self.TagStarts = {};
|
|||
|
for _, Start in pairs(self.AllStarts) do
|
|||
|
-- 针对不同的
|
|||
|
if Start.Tags:Num() == 0 then
|
|||
|
-- 加载到 NoTagStarts
|
|||
|
table.insert(self.NoTagStarts, Start);
|
|||
|
else
|
|||
|
for i, Tag in pairs(Start.Tags) do
|
|||
|
--Tag = string.lower(Tag); -- 全部转换成小写
|
|||
|
if self.TagStarts[Tag] == nil then self.TagStarts[Tag] = {}; end
|
|||
|
table.insert(self.TagStarts[Tag], Start);
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
self:SpawnAllActors();
|
|||
|
end);
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function ActorStartManager:SpawnAllActors()
|
|||
|
for Tag, Starts in pairs(self.TagStarts) do self:SpawnActorsByTag(Tag); end
|
|||
|
UGCLogSystem.LogTree(string.format("[ActorStartManager:SpawnAllActors] SpawnActors ="), self.SpawnActors)
|
|||
|
end
|
|||
|
|
|||
|
function ActorStartManager:SpawnActorsByTag(Tag)
|
|||
|
local Starts = self.TagStarts[Tag];
|
|||
|
if table.isEmpty(Starts) then return ; end
|
|||
|
for _, Start in pairs(Starts) do
|
|||
|
local Config = self.LoadConfig[Tag];
|
|||
|
if Config ~= nil then
|
|||
|
if Config.Type == self.LoadType.SpawnActor then
|
|||
|
local Actor = Config.Func(Start);
|
|||
|
if Actor then
|
|||
|
if self.SpawnActors[Tag] == nil then self.SpawnActors[Tag] = {}; end
|
|||
|
table.insert(self.SpawnActors[Tag], Actor);
|
|||
|
else
|
|||
|
UGCLogSystem.Log("[ActorStartManager:SpawnActorsByTag] 无法加载 Tag = %s 的 Class", Tag);
|
|||
|
end
|
|||
|
else
|
|||
|
Config.Func(Start);
|
|||
|
end
|
|||
|
else
|
|||
|
UGCLogSystem.Log("[ActorStartManager:SpawnActorsByTag] 无法找到 Tag = %s 的配置", Tag)
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function ActorStartManager:ClearActorsByTag(Tag)
|
|||
|
if self.SpawnActors[Tag] then
|
|||
|
for i, v in pairs(self.SpawnActors[Tag]) do v:K2_DestroyActor(); end
|
|||
|
end
|
|||
|
self.SpawnActors[Tag] = {};
|
|||
|
end
|
|||
|
|
|||
|
function ActorStartManager:RespawnActorsByTag(Tag)
|
|||
|
self:ClearActorsByTag();
|
|||
|
self:SpawnActorsByTag(Tag);
|
|||
|
UGCLogSystem.LogTree(string.format("[ActorStartManager:RespawnActorsByTag] Tag = %s, SpawnActors", Tag), self.SpawnActors[Tag])
|
|||
|
end
|
|||
|
|
|||
|
function ActorStartManager:ClearAllActors()
|
|||
|
for Tag, ActorList in pairs(self.SpawnActors) do
|
|||
|
for _, Start in pairs(ActorList) do
|
|||
|
Start:K2_DestroyActor();
|
|||
|
end
|
|||
|
end
|
|||
|
self.SpawnActors = {};
|
|||
|
end
|
|||
|
|
|||
|
return ActorStartManager;
|