109 lines
3.1 KiB
Lua
Raw Normal View History

2025-01-04 23:00:19 +08:00
local PoisonManager = {};
PoisonManager.PoisonConfigIndex = 6; -- 该数值是在 GameMode->DataManager->DataSources 中配置的
---@type PoisonConfigItem[]
PoisonManager.ConstConfig = {
{
delaytime = 8,
SafeZoneAppeartime = 20,
lasttime = 20,
blueradius = 7500,
whiteradius = 3500,
pain = 1.5,
},
{
delaytime = 8,
SafeZoneAppeartime = 10,
lasttime = 20,
blueradius = 3500,
whiteradius = 1500,
pain = 3,
},
{
delaytime = 5,
SafeZoneAppeartime = 10,
lasttime = 12,
blueradius = 1500,
whiteradius = 500,
pain = 4.5,
},
{
delaytime = 5,
SafeZoneAppeartime = 10,
lasttime = 15,
blueradius = 500,
whiteradius = 0,
pain = 6,
},
};
---@type table<int32, AActor>
PoisonManager.MapCenterActors = {};
PoisonManager.SelectCenterIndex = 0;
--- 选择地图之后,执行
function PoisonManager:Init()
-- 计算当前的位置
UE.FindActorsByClass(ObjectPath.BP_ActorStart, self.MapCenterActors, function(InIndex, InActor)
if InActor:ActorHasTag("Poison") then return InActor.Index; end
return false;
end);
UGCLogSystem.LogTree(string.format("[PoisonManager:Init] self.MapCenterActors ="), self.MapCenterActors)
end
function PoisonManager:SelectMapCenter()
self:Clear();
-- 从中选取一个
self.Config = TableHelper.DeepCopyTable(self.ConstConfig);
-- 选取一个
local Keys = {};
for i, v in pairs(self.MapCenterActors) do
table.insert(Keys, i);
end
self.SelectCenterIndex = Keys[math.random(#Keys)];
local Center = self.MapCenterActors[self.SelectCenterIndex];
local CenterLoc = Center:K2_GetActorLocation();
for i = 1, #self.Config do
local ConfigItem = self.Config[i];
local CirCleCfg = self:CreateNewCirCleCfg()
ConfigItem.bluepoint = VectorHelper.ToLuaTable2D(CenterLoc);
local MinCenter = math.randomCircleInCircle(CenterLoc, ConfigItem.blueradius, ConfigItem.whiteradius);
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;
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:CreateNewCirCleCfg()
return UE.CreateStruct("CirCleCfg");
end
return PoisonManager;