2025-06-29 23:59:43 +08:00
|
|
|
|
--[[
|
|
|
|
|
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")
|
|
|
|
|
|
2025-07-03 01:48:06 +08:00
|
|
|
|
-- 加载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
|
|
|
|
|
|
2025-06-29 23:59:43 +08:00
|
|
|
|
--> References
|
2025-07-03 01:48:06 +08:00
|
|
|
|
-- 由ArchiveProxy生成
|
|
|
|
|
local PlayerDataFolder = ReplicatedStorage:WaitForChild("PlayerData")
|
2025-06-29 23:59:43 +08:00
|
|
|
|
|
|
|
|
|
--> Dependencies
|
2025-07-03 01:48:06 +08:00
|
|
|
|
-- 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)
|
2025-06-29 23:59:43 +08:00
|
|
|
|
|
2025-07-03 01:48:06 +08:00
|
|
|
|
-- local ArchiveProxy = require(ServerStorage.Proxy.ArchiveProxy)
|
2025-06-29 23:59:43 +08:00
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
-- Create initial folders
|
|
|
|
|
local function CreateFolder(Name: string, Parent: Instance)
|
|
|
|
|
local Folder = Instance.new("Folder")
|
|
|
|
|
Folder.Name = Name
|
|
|
|
|
Folder.Parent = Parent
|
|
|
|
|
return Folder
|
|
|
|
|
end
|
|
|
|
|
|
2025-07-02 00:21:32 +08:00
|
|
|
|
-- 初始化workspace目录
|
2025-06-29 23:59:43 +08:00
|
|
|
|
local Temporary = CreateFolder("Temporary", workspace)
|
|
|
|
|
local ProjectileCache = CreateFolder("ProjectileCache", Temporary)
|
|
|
|
|
local Characters = CreateFolder("Characters", workspace)
|
|
|
|
|
|
|
|
|
|
-- Initially require all server-sided & shared modules
|
2025-06-30 00:06:14 +08:00
|
|
|
|
-- 加载模块 ReplicatedStorage.Modules, ServerStorage.Modules
|
2025-06-29 23:59:43 +08:00
|
|
|
|
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
|
|
|
|
|
|
2025-07-02 00:21:32 +08:00
|
|
|
|
--------------------------------------------------------------------------------
|
2025-06-29 23:59:43 +08:00
|
|
|
|
|
2025-07-02 00:21:32 +08:00
|
|
|
|
local function OnPlayerAdded(Player: Player)
|
|
|
|
|
if not Proxies.ArchiveProxy:IsPlayerDataLoaded(Player) then
|
|
|
|
|
warn("玩家数据未加载: " .. Player.Name)
|
|
|
|
|
return
|
2025-06-29 23:59:43 +08:00
|
|
|
|
end
|
2025-07-03 01:48:06 +08:00
|
|
|
|
-- 玩家数据加载成功
|
|
|
|
|
print("玩家数据加载成功: ", Proxies.ArchiveProxy.pData[Player.UserId])
|
2025-06-29 23:59:43 +08:00
|
|
|
|
|
2025-07-02 00:21:32 +08:00
|
|
|
|
local pData = Instance.new("Configuration")
|
|
|
|
|
pData.Name = Player.UserId
|
|
|
|
|
pData.Parent = PlayerDataFolder
|
2025-07-03 01:48:06 +08:00
|
|
|
|
|
|
|
|
|
-- 初始化玩家数据目录(其他具体内容在Proxy中处理)
|
|
|
|
|
if not Proxies.ArchiveProxy.pData[Player.UserId] then
|
|
|
|
|
Proxies.ArchiveProxy.pData[Player.UserId] = {}
|
|
|
|
|
end
|
|
|
|
|
|
2025-07-02 00:21:32 +08:00
|
|
|
|
-- 加载对应玩家的其他系统代理
|
|
|
|
|
Proxies.EquipmentProxy:InitPlayer(Player)
|
|
|
|
|
Proxies.PlayerInfoProxy:InitPlayer(Player)
|
2025-07-03 01:48:06 +08:00
|
|
|
|
Proxies.LevelProxy:InitPlayer(Player)
|
2025-07-02 00:21:32 +08:00
|
|
|
|
end
|
2025-06-29 23:59:43 +08:00
|
|
|
|
|
2025-07-02 00:21:32 +08:00
|
|
|
|
local function OnPlayerRemoving(Player: Player)
|
2025-07-03 01:48:06 +08:00
|
|
|
|
-- 清理目录(整体数据在ArchiveProxy中清除)
|
2025-07-02 00:21:32 +08:00
|
|
|
|
local pData = PlayerDataFolder:FindFirstChild(Player.UserId)
|
|
|
|
|
if pData then pData:Destroy() end
|
2025-06-29 23:59:43 +08:00
|
|
|
|
end
|
|
|
|
|
|
2025-07-02 00:21:32 +08:00
|
|
|
|
Players.PlayerAdded:Connect(OnPlayerAdded)
|
|
|
|
|
for _, Player in Players:GetPlayers() do
|
|
|
|
|
task.spawn(OnPlayerAdded, Player)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
Players.PlayerRemoving:Connect(OnPlayerRemoving)
|