Files
BusyRabbit/Content/Lua/GamePlay/Level/BusyLevelLogicSubSystem.lua
2025-07-09 01:08:35 +08:00

69 lines
2.2 KiB
Lua

local SubSystem = {}
local Reactive = require("Core.Reactive")
local Library = import("BusyGamePlayLibrary")
local GameplayStatics = import("GameplayStatics")
local BusyGamePlayLibrary = import("BusyGamePlayLibrary")
local function CreateItemGenerator(level_config_data)
local Generator = require("GamePlay.Level.BusyLevelItemGenerator")
local item_data = {}
local period = level_config_data.Period
for k, v in pairs(level_config_data.LevelItemIds) do
item_data[k] = v.CountOfPeriod
end
return Generator(period, item_data)
end
function SubSystem:ReceiveSubSystemInitialize()
local world = BusyGamePlayLibrary.K2_GetWorld(self)
self.start_time = GameplayStatics.GetTimeSeconds(world)
self.proxy = Reactive.ReactiveProperty({
current_seconds = 0
})
end
function SubSystem:ReceiveWorldBeginPlay()
local BusyActorManagerSubSystem = import("BusyActorManagerSubSystem").Get(self)
-- 读取关卡配置
local is_suc, row_data = Library.GetLevelBaseConfig("Default", nil)
assert(is_suc == true, "Can't find level base config")
self.level_base_config = row_data
-- 创建物品生成器
self.generator = CreateItemGenerator(row_data)
-- 创建初始篝火
local bonfire = BusyActorManagerSubSystem:SpawnBonfire(row_data.FirstBonfirePosition)
-- 创建角色
local role = BusyActorManagerSubSystem:SpawnRole(bonfire)
GameplayStatics.GetPlayerController(self, 0):Possess(role)
end
function SubSystem:ReceiveSubSystemTick(DeltaTime)
-- local proxy = self.proxy
-- local world = BusyGamePlayLibrary.K2_GetWorld(self)
-- local current_time = GameplayStatics.GetTimeSeconds(world)
-- local escapse_time = math.floor(current_time - self.start_time)
-- if escapse_time > proxy.current_seconds then
-- self:TrySpawnLevelItem()
-- proxy.current_seconds = escapse_time
-- print(proxy.current_seconds)
-- end
end
function SubSystem:TrySpawnLevelItem()
local BusyActorManagerSubSystem = import("BusyActorManagerSubSystem").Get(self)
local items = self.generator:Generate()
for i, item_id in pairs(items) do
BusyActorManagerSubSystem:SpawnLevelItem(item_id)
print(i, item_id)
end
end
return Class(nil, nil, SubSystem)