UGCProjects/ProjectTemp_T/Script/Blueprint/UGCPlayerStartManager.lua

101 lines
3.5 KiB
Lua
Raw Normal View History

2025-01-04 23:00:19 +08:00
---@class UGCPlayerStartManager_C:BP_PlayerStartManager_C
---@field PlayerStartClass UClass
--Edit Below--
---@type UGCPlayerStartManager_C
local UGCPlayerStartManager = {
-- 所有玩家控制器
---@type table<int32, table<int32, BP_STPlayerStart_C>>
AllPlayerStarts = {};
};
function UGCPlayerStartManager:ReceiveBeginPlay()
self.SuperClass.ReceiveBeginPlay(self);
UGCLogSystem.Log("[UGCPlayerStartManager:ReceiveBeginPlay] 执行")
UGCEventSystem.AddListener(EventTypes.MapLoadFinish, self.OnMapLoadFinish, self)
self:LoadAllPlayerStarts();
end
function UGCPlayerStartManager:OnMapLoadFinish()
self:LoadAllPlayerStarts();
end
--- 加载所有的玩家出生点
function UGCPlayerStartManager:LoadAllPlayerStarts()
self.AllPlayerStarts = {};
local Actors = {};
GameplayStatics.GetAllActorsOfClass(self, self.PlayerStartClass, Actors);
UGCLogSystem.LogTree(string.format("[UGCPlayerStartManager:LoadAllPlayerStarts] Actors ="), Actors)
for i, v in pairs(Actors) do
local PointId = v.PlayerBornPointID % 1000;
if PointId ~= nil then
if self.AllPlayerStarts[PointId] == nil then self.AllPlayerStarts[PointId] = {}; end
table.insert(self.AllPlayerStarts[PointId], v);
end
end
UGCLogSystem.LogTree("[UGCPlayerStartManager:LoadAllPlayerStarts] self.AllPlayerStarts = ", self.AllPlayerStarts);
return self.AllPlayerStarts;
end
---@param Controller UGCPlayerController_C
--- @return BP_STPlayerStart_C
function UGCPlayerStartManager:GetUGCModePlayerStart(Controller)
local PlayerKey = Controller.PlayerKey;
local TeamId = UGCPlayerStateSystem.GetTeamID(PlayerKey);
UGCLogSystem.Log(string.format('[UGCPlayerStartManager:GetUGCModePlayerStart] PlayerKey = %d, TeamId = %d', PlayerKey, TeamId))
-- 首先检查状态:
local State = UGCGameSystem.GameState.RoundInfo.RoundState;
local CurrRoundTime = UGCGameSystem.GameState.RoundInfo.CurrRoundTime;
UGCLogSystem.Log("[UGCPlayerStartManager:GetUGCModePlayerStart] CurrRoundTime = %s", tostring(CurrRoundTime))
if CurrRoundTime == 0 then return self:GetPlayerStart(TeamId, true); end
-- 是否是单数局
local IsDan = (CurrRoundTime % 2 == 1);
return self:GetPlayerStart(TeamId, IsDan);
end
function UGCPlayerStartManager:GetPlayerStart(TeamId, IsNormal)
-- 直接出生点
local PlayerStartId = 1;
if IsNormal then
PlayerStartId = TeamId == 1 and 1 or 2
else
PlayerStartId = TeamId == 1 and 2 or 1;
end
UGCLogSystem.Log("[UGCPlayerStartManager:GetPlayerStart] TeamId = %d, PlayerStartId = %d, PoisonConfig.SelectIndex = %s", TeamId, PlayerStartId, tostring(PoisonConfig.SelectIndex));
if PoisonConfig.SelectIndex > 0 then
return self:GetPlayerStart_Internal(PlayerStartId + PoisonConfig.SelectIndex * 10);
else
return nil;
end
end
function UGCPlayerStartManager:GetPlayerStart_Internal(InId)
UGCLogSystem.Log("[UGCPlayerStartManager:GetPlayerStart_Internal] InId = %d", InId);
if table.isEmpty(self.AllPlayerStarts[InId]) then
self:LoadAllPlayerStarts();
end
if table.isEmpty(self.AllPlayerStarts[InId]) then
for i, v in pairs(self.AllPlayerStarts) do
if i % 100 == InId then
InId = i;
break;
end
end
end
--UGCLogSystem.LogTree(string.format("[UGCPlayerStartManager:GetPlayerStart_Internal] self.AllPlayerStarts ="), self.AllPlayerStarts)
local Num = math.random(1, #self.AllPlayerStarts[InId]);
local PlayerStart = self.AllPlayerStarts[InId][Num];
if UE.IsValid(PlayerStart) then
UGCLogSystem.Log("[UGCPlayerStartManager:GetPlayerStart_Internal] PlayerStartName = %s", UE.GetName(PlayerStart));
return PlayerStart;
end
return nil;
end
return UGCPlayerStartManager;