--[[ Evercyan @ March 2023 ServerMain ServerMain requires many important modules for the game to work, as well as housing some miscellaneous code. The modules it requires is under ServerStorage.Modules and the script itself, which makes core features of the game work, such as armor, mobs, and the leveling system. ]] --> Services local ReplicatedStorage = game:GetService("ReplicatedStorage") local ServerStorage = game:GetService("ServerStorage") local Players = game:GetService("Players") -- 加载Proxy目录下的所有代理 local Proxies = {} local ProxyFolder = ServerStorage:FindFirstChild("Proxy") if ProxyFolder then for _, proxyModule in ipairs(ProxyFolder:GetChildren()) do if proxyModule:IsA("ModuleScript") then local success, result = pcall(require, proxyModule) if success then -- 去掉文件名后缀 local name = proxyModule.Name Proxies[name] = result else warn("加载代理模块失败: " .. proxyModule.Name, result) end end end end --> References -- 由ArchiveProxy生成 local PlayerDataFolder = ReplicatedStorage:WaitForChild("PlayerData") --> Dependencies -- local HumanoidAttributes = require(script.HumanoidAttributes) -- local PlayerLeveling = require(script.PlayerLeveling) -- local GameConfig = require(ReplicatedStorage.Data.GameConfig) -- local ContentLibrary = require(ReplicatedStorage.Modules.ContentLibrary) -- local ToolLib = require(ServerStorage.Modules.ToolLib) -- local ArmorLib = require(ServerStorage.Modules.ArmorLib) -- local ArchiveProxy = require(ServerStorage.Proxy.ArchiveProxy) -------------------------------------------------------------------------------- -- Create initial folders local function CreateFolder(Name: string, Parent: Instance) local Folder = Instance.new("Folder") Folder.Name = Name Folder.Parent = Parent return Folder end -- 初始化workspace目录 local Temporary = CreateFolder("Temporary", workspace) local ProjectileCache = CreateFolder("ProjectileCache", Temporary) local Characters = CreateFolder("Characters", workspace) -- Initially require all server-sided & shared modules -- 加载模块 ReplicatedStorage.Modules, ServerStorage.Modules for _, Location in {ReplicatedStorage.Modules, ServerStorage.Modules} do for _, Library in Location:GetChildren() do if Library:IsA("ModuleScript") then task.spawn(require, Library) end end end -------------------------------------------------------------------------------- local function OnPlayerAdded(Player: Player) if not Proxies.ArchiveProxy:IsPlayerDataLoaded(Player) then warn("玩家数据未加载: " .. Player.Name) return end -- 玩家数据加载成功 print("玩家数据加载成功: ", Proxies.ArchiveProxy.pData[Player.UserId]) local pData = Instance.new("Configuration") pData.Name = Player.UserId pData.Parent = PlayerDataFolder -- 初始化玩家数据目录(其他具体内容在Proxy中处理) if not Proxies.ArchiveProxy.pData[Player.UserId] then Proxies.ArchiveProxy.pData[Player.UserId] = {} end -- 加载对应玩家的其他系统代理 Proxies.EquipmentProxy:InitPlayer(Player) Proxies.PlayerInfoProxy:InitPlayer(Player) Proxies.LevelProxy:InitPlayer(Player) end local function OnPlayerRemoving(Player: Player) -- 清理目录(整体数据在ArchiveProxy中清除) local pData = PlayerDataFolder:FindFirstChild(Player.UserId) if pData then pData:Destroy() end end Players.PlayerAdded:Connect(OnPlayerAdded) for _, Player in Players:GetPlayers() do task.spawn(OnPlayerAdded, Player) end Players.PlayerRemoving:Connect(OnPlayerRemoving)