2025-02-05 00:23:25 +08:00

322 lines
8.3 KiB
Lua

local PoisonManager = {};
PoisonManager.PoisonConfigIndex = 7; -- 该数值是在 GameMode->DataManager->DataSources 中配置的
PoisonManager.EnableRandom = false;
---@type PoisonConfigItem[]
PoisonManager.ConstConfig = {
-- SLXLC
["Map_SLXLC"] = {
{
delaytime = 20,
SafeZoneAppeartime = 10,
lasttime = 8,
blueradius = 4000,
whiteradius = 2900,
pain = 8,
},
{
delaytime = 30,
SafeZoneAppeartime = 30,
lasttime = 20,
blueradius = 2900,
whiteradius = 2000,
pain = 8,
},
{
delaytime = 30,
SafeZoneAppeartime = 30,
lasttime = 30,
blueradius = 2000,
whiteradius = 1500,
pain = 8,
},
},
-- SMDJ
["Map_SMDJ"] = {
{
delaytime = 3,
SafeZoneAppeartime = 5,
lasttime = 8,
blueradius = 6500,
whiteradius = 3800,
pain = 8,
},
{
delaytime = 30,
SafeZoneAppeartime = 30,
lasttime = 20,
blueradius = 3800,
whiteradius = 2500,
pain = 8,
},
{
delaytime = 30,
SafeZoneAppeartime = 30,
lasttime = 30,
blueradius = 2500,
whiteradius = 1500,
pain = 8,
},
},
["Map_HDDJ"] = {
{
delaytime = 10,
SafeZoneAppeartime = 10,
lasttime = 10,
blueradius = 3500,
whiteradius = 2500,
pain = 8,
},
{
delaytime = 30,
SafeZoneAppeartime = 30,
lasttime = 20,
blueradius = 2500,
whiteradius = 2000,
pain = 8,
},
{
delaytime = 30,
SafeZoneAppeartime = 30,
lasttime = 30,
blueradius = 2000,
whiteradius = 1500,
pain = 8,
},
},
["Map_JCK"] = {
{
delaytime = 20,
SafeZoneAppeartime = 20,
lasttime = 30,
blueradius = 2500,
whiteradius = 1500,
pain = 8,
},
{
delaytime = 30,
SafeZoneAppeartime = 30,
lasttime = 30,
blueradius = 1500,
whiteradius = 1000,
pain = 8,
},
},
["Map_SCL"] = {
{
delaytime = 10,
SafeZoneAppeartime = 10,
lasttime = 20,
blueradius = 2500,
whiteradius = 1500,
pain = 8,
},
{
delaytime = 30,
SafeZoneAppeartime = 30,
lasttime = 20,
blueradius = 1500,
whiteradius = 1000,
pain = 8,
},
},
["Map_DBL"] = {
{
delaytime = 20,
SafeZoneAppeartime = 10,
lasttime = 30,
blueradius = 2500,
whiteradius = 1500,
pain = 8,
},
{
delaytime = 30,
SafeZoneAppeartime = 30,
lasttime = 20,
blueradius = 1500,
whiteradius = 1000,
pain = 8,
},
},
["Map_NewYear"] = {
{
delaytime = 20,
SafeZoneAppeartime = 30,
lasttime = 30,
blueradius = 7000,
whiteradius = 4500,
pain = 8,
},
{
delaytime = 30,
SafeZoneAppeartime = 30,
lasttime = 20,
blueradius = 4500,
whiteradius = 2500,
pain = 8,
},
{
delaytime = 30,
SafeZoneAppeartime = 30,
lasttime = 20,
blueradius = 2500,
whiteradius = 1500,
pain = 8,
},
},
-- 大仓
["Map_DC"] = {
{
delaytime = 3,
SafeZoneAppeartime = 5,
lasttime = 8,
blueradius = 6500,
whiteradius = 3800,
pain = 8,
},
{
delaytime = 30,
SafeZoneAppeartime = 30,
lasttime = 20,
blueradius = 3800,
whiteradius = 2500,
pain = 8,
},
{
delaytime = 30,
SafeZoneAppeartime = 30,
lasttime = 30,
blueradius = 2500,
whiteradius = 1500,
pain = 8,
},
},
};
---@type table<int32, AActor>
PoisonManager.MapCenterActors = {};
PoisonManager.SelectCenterIndex = 0;
--- 选择地图之后,执行
function PoisonManager:Init()
-- 计算当前的位置
self.MapCenterActors = {};
local AllActors = {};
if ObjectPath.BP_ActorStart then
UGCLogSystem.Log("[PoisonManager:Init] ObjectPath.BP_ActorStart = %s", UE.GetName(ObjectPath.BP_ActorStart));
end
UE.FindActorsByClass(ObjectPath.BP_ActorStart, AllActors, function(InIndex, InActor)
return InActor:ActorHasTag("Poison");
end);
for i, v in pairs(AllActors) do
self.MapCenterActors[v.Index] = v;
end
UGCLogSystem.LogTree(string.format("[PoisonManager:Init] self.MapCenterActors ="), self.MapCenterActors)
end
--- 选择一个地图中心点进行刷圈
function PoisonManager:SelectMapCenter()
self:Clear();
-- 选取一个
if table.isEmpty(self.MapCenterActors) then
self:Init();
if table.isEmpty(self.MapCenterActors) then
UGCLogSystem.Log("[PoisonManager:SelectMapCenter] 加载不到地图中心点")
return ;
end
end
local Keys = {};
for i, v in pairs(self.MapCenterActors) do table.insert(Keys, i); end
self.SelectCenterIndex = table.func(MiniManager, "SelectMapCenter", self.MapCenterActors);
if self.SelectCenterIndex == nil then
self.SelectCenterIndex = Keys[math.random(#Keys)];
end
local Center = self.MapCenterActors[self.SelectCenterIndex];
if Center then
UGCLogSystem.Log("[PoisonManager:SelectMapCenter] 找到 Center = %s", UE.GetName(Center))
else
UGCLogSystem.Log("[PoisonManager:SelectMapCenter] 无法找到 Center")
end
local CenterLoc = Center:K2_GetActorLocation();
-- 从中选取一个
if GameState.LoadMapName ~= nil and self.ConstConfig[GameState.LoadMapName] then
self.Config = TableHelper.DeepCopyTable(self.ConstConfig[GameState.LoadMapName]);
else
self.Config = TableHelper.DeepCopyTable(self.ConstConfig["Map_SLXLC"]);
end
if table.isEmpty(self.Config) then return; end
UGCLogSystem.LogTree(string.format("[PoisonManager:SelectMapCenter] self.Config ="), self.Config)
for i = 1, #self.Config do
local ConfigItem = self.Config[i];
local CirCleCfg = self:CreateNewCirCleCfg()
ConfigItem.bluepoint = VectorHelper.ToLuaTable2D(CenterLoc);
local MinCenter = VectorHelper.ToLuaTable2D(CenterLoc);
if self.EnableRandom then
MinCenter = math.randomCircleInCircle(CenterLoc, ConfigItem.blueradius, ConfigItem.whiteradius);
end
for Index, config in pairs(ConfigItem) do
CirCleCfg[Index] = config;
end
CirCleCfg.bUseCustomBluePoint = true;
CirCleCfg.bUseCustomWhitePoint = true;
CirCleCfg.whitepoint = MinCenter;
UGCGameSystem.GameMode.DataManager.DataSources[self.PoisonConfigIndex].CircleConfigs:Add(CirCleCfg);
CenterLoc = MinCenter;
UGCLogSystem.Log("[PoisonManager:SelectMapCenter] 配置完一个~")
end
UGCLogSystem.Log("[PoisonManager:SelectMapCenter] self.SelectCenterIndex = %d", self.SelectCenterIndex)
end
--- 游戏正式开始的时候调用
function PoisonManager:Toggle(Enable)
UGCLogSystem.Log("[PoisonManager:Toggle] 启动")
if Enable then self:SelectMapCenter(); end
UGCBlueprintFunctionLibrary.TogglePoisonCircle(GameState, Enable);
end
function PoisonManager:GetSelectMapIndex()
return self.SelectCenterIndex;
end
function PoisonManager:Clear()
UGCGameSystem.GameMode.DataManager.DataSources[self.PoisonConfigIndex].CircleConfigs:Empty();
UGCLogSystem.Log("[PoisonManager:Clear] 清空")
end
function PoisonManager:GetRadiationActor()
return GameState:GetRadiationActor();
end
--- 判断一个 Actor 是否在圈内
---@param InActor AActor
function PoisonManager:IsActorInCircle(InActor)
if self:GetRadiationActor() == nil then return end
local Dis = VectorHelper.GetActorDis2D(self:GetRadiationActor(), InActor)
local Scale = self:GetRadiationActor():GetActorScale3D().X
return Dis / 100 <= Scale;
end
function PoisonManager:CreateNewCirCleCfg()
return UE.CreateStruct("CirCleCfg");
end
function PoisonManager:GetMapCenterActors()
return self.MapCenterActors;
end
function PoisonManager:GetMapCenterActor(InIndex)
return self.MapCenterActors[InIndex];
end
function PoisonManager:GetCurrCenter()
return self.MapCenterActors[self.SelectCenterIndex];
end
return PoisonManager;