127 lines
4.0 KiB
Lua
127 lines
4.0 KiB
Lua
local PoisonManager = {};
|
|
|
|
-- 该数值是在 GameMode->DataManager->DataSources 中配置的;
|
|
PoisonManager.PoisonConfigIndex = 7;
|
|
|
|
---@type PoisonConfigItem[]
|
|
PoisonManager.ConstConfig = {
|
|
{
|
|
delaytime = 8,
|
|
SafeZoneAppeartime = 30,
|
|
lasttime = 40,
|
|
blueradius = 250 * 100,
|
|
whiteradius = 235 * 100,
|
|
pain = 1.5,
|
|
},
|
|
--{
|
|
-- delaytime = 20,
|
|
-- SafeZoneAppeartime = 30,
|
|
-- lasttime = 40,
|
|
-- blueradius = 6500,
|
|
-- whiteradius = 5000,
|
|
-- pain = 3,
|
|
--},
|
|
};
|
|
|
|
---@type table<int32, AActor>
|
|
PoisonManager.MapCenterActors = {};
|
|
PoisonManager.SelectCenterIndex = 0;
|
|
PoisonManager.CenterActor = nil;
|
|
|
|
--- 选择地图之后,执行
|
|
function PoisonManager:Init()
|
|
if table.isEmpty(self.MapCenterActors) then
|
|
-- 如果为空,重新加载一遍
|
|
UGCLogSystem.Log("[PoisonManager:Init] 重新加载一边")
|
|
ActorStartManager:OnMapLoadComplete();
|
|
end
|
|
if table.isEmpty(self.MapCenterActors) then return; end
|
|
UGCLogSystem.LogTree(string.format("[PoisonManager:Init] self.MapCenterActors ="), self.MapCenterActors)
|
|
end
|
|
|
|
--- 选择一个地图中心点进行刷圈
|
|
function PoisonManager:SelectMapCenter()
|
|
self:Clear();
|
|
|
|
-- 从中选取一个
|
|
self.Config = TableHelper.DeepCopyTable(self.ConstConfig);
|
|
-- 选取一个
|
|
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(GlobalMiniMode, "SelectMapCenter", self.MapCenterActors);
|
|
if self.SelectCenterIndex == nil then
|
|
self.SelectCenterIndex = Keys[math.random(#Keys)];
|
|
GameState:SetCenterIndex(self.SelectCenterIndex);
|
|
end
|
|
self.CenterActor = self.MapCenterActors[self.SelectCenterIndex];
|
|
-- 现在是确定了的地图中心
|
|
PluginManager:OnSelectMapCenter(self.SelectCenterIndex, self.CenterActor);
|
|
|
|
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 = nil;
|
|
if DefaultSettings.RandomPoison then
|
|
MinCenter = math.randomCircleInCircle(CenterLoc, ConfigItem.blueradius, ConfigItem.whiteradius);
|
|
else
|
|
MinCenter = VectorHelper.ToLuaTable2D(CenterLoc);
|
|
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;
|
|
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
|
|
|
|
return PoisonManager; |