2025-07-02 00:21:32 +08:00
|
|
|
|
-- 装备代理
|
|
|
|
|
local EquipmentProxy = {}
|
|
|
|
|
|
|
|
|
|
--> Services
|
|
|
|
|
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
2025-07-03 01:48:06 +08:00
|
|
|
|
local ServerStorage = game:GetService("ServerStorage")
|
2025-07-02 00:21:32 +08:00
|
|
|
|
|
|
|
|
|
--> Variables
|
|
|
|
|
local Utils = require(ReplicatedStorage.Tools.Utils)
|
2025-07-03 01:48:06 +08:00
|
|
|
|
local ArchiveProxy = require(ServerStorage.Proxy.ArchiveProxy)
|
|
|
|
|
local PlayerInfoProxy = require(ServerStorage.Proxy.PlayerInfoProxy)
|
|
|
|
|
|
|
|
|
|
--> Json
|
|
|
|
|
local JsonEquipment = require(ReplicatedStorage.Json.Equipment)
|
2025-07-14 00:30:47 +08:00
|
|
|
|
local JsonAttributes = require(ReplicatedStorage.Json.Attributes)
|
|
|
|
|
local JsonExAttributes = require(ReplicatedStorage.Json.ExAttributes)
|
2025-07-02 00:21:32 +08:00
|
|
|
|
|
|
|
|
|
--> Constants
|
|
|
|
|
local STORE_NAME = "Equipment"
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
2025-07-03 01:48:06 +08:00
|
|
|
|
-- 获取装备文件夹
|
2025-07-02 00:21:32 +08:00
|
|
|
|
local function GetPlayerEquipmentFolder(Player: Player)
|
|
|
|
|
local pData = Utils:GetPlayerDataFolder(Player)
|
|
|
|
|
if not pData then return end
|
|
|
|
|
local EquipmentFolder = pData:FindFirstChild("Equipment")
|
|
|
|
|
return EquipmentFolder
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
2025-07-03 01:48:06 +08:00
|
|
|
|
-- 初始化玩家
|
2025-07-02 00:21:32 +08:00
|
|
|
|
function EquipmentProxy:InitPlayer(Player: Player)
|
|
|
|
|
local pData = Utils:GetPlayerDataFolder(Player)
|
|
|
|
|
if not pData then return end
|
2025-07-03 01:48:06 +08:00
|
|
|
|
Utils:CreateFolder("Equipment", pData)
|
2025-07-02 00:21:32 +08:00
|
|
|
|
|
2025-07-03 01:48:06 +08:00
|
|
|
|
-- 新玩家数据初始化
|
|
|
|
|
if not ArchiveProxy.pData[Player.UserId][STORE_NAME] then
|
|
|
|
|
ArchiveProxy.pData[Player.UserId][STORE_NAME] = {}
|
2025-07-02 00:21:32 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 初始化装备
|
2025-07-03 01:48:06 +08:00
|
|
|
|
for uniqueId, EquipmentData in ArchiveProxy.pData[Player.UserId][STORE_NAME] do
|
2025-07-12 05:06:14 +08:00
|
|
|
|
Utils:CreateDataInstance(Player, uniqueId, EquipmentData, GetPlayerEquipmentFolder(Player))
|
2025-07-02 00:21:32 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2025-07-12 05:06:14 +08:00
|
|
|
|
-- 一些特殊记录或者不用记录的Key
|
2025-07-03 01:48:06 +08:00
|
|
|
|
local EXCEPT_KEYS = { "id", "orgId", "name", "attributes"}
|
2025-07-02 00:21:32 +08:00
|
|
|
|
-- 添加装备到背包
|
|
|
|
|
function EquipmentProxy:AddEquipment(Player: Player, EquipmentId: number)
|
|
|
|
|
local pData = Utils:GetPlayerDataFolder(Player)
|
|
|
|
|
if not pData then return end
|
|
|
|
|
|
2025-07-03 01:48:06 +08:00
|
|
|
|
local EquipmentData = Utils:GetIdDataFromJson(JsonEquipment, EquipmentId)
|
2025-07-02 00:21:32 +08:00
|
|
|
|
if not EquipmentData then return end
|
|
|
|
|
|
|
|
|
|
local UniqueId = Utils:GenUniqueId(ArchiveProxy.pData[Player.UserId])
|
2025-07-02 00:56:31 +08:00
|
|
|
|
-- 配置表内容
|
2025-07-02 00:21:32 +08:00
|
|
|
|
local ResultData = {}
|
|
|
|
|
for key, value in pairs(EquipmentData) do
|
|
|
|
|
if not table.find(EXCEPT_KEYS, key) then
|
|
|
|
|
ResultData[key] = value
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
ResultData.id = UniqueId
|
|
|
|
|
ResultData.orgId = EquipmentId
|
2025-07-12 05:06:14 +08:00
|
|
|
|
-- 到时候记录穿戴槽位
|
|
|
|
|
ResultData.wearing = 0
|
2025-07-02 00:21:32 +08:00
|
|
|
|
|
2025-07-12 05:06:14 +08:00
|
|
|
|
-- TODO: 其他随机词条内容添加在下面
|
2025-07-14 00:30:47 +08:00
|
|
|
|
|
|
|
|
|
-- 随机生成额外属性数量
|
|
|
|
|
local rng = Random.new()
|
|
|
|
|
|
|
|
|
|
local maxExAttributeNumber = PlayerInfoProxy:GetPlayerInfo(Player).exAttributeNumber or 0
|
|
|
|
|
local exAttributeNumber = rng:NextInteger(0, maxExAttributeNumber)
|
|
|
|
|
ResultData.maxExAttributeNumber = exAttributeNumber
|
|
|
|
|
ResultData.exAttributes = {}
|
|
|
|
|
if exAttributeNumber > 0 then
|
|
|
|
|
local spawnExAttributesId = {}
|
|
|
|
|
for i = 1, exAttributeNumber do
|
|
|
|
|
local newExAttributeId = Utils:GetRandomIdFromJsonWithType(JsonExAttributes, 1, spawnExAttributesId)
|
|
|
|
|
table.insert(spawnExAttributesId, newExAttributeId)
|
|
|
|
|
|
|
|
|
|
local ExAttributeData = Utils:GetIdDataFromJson(JsonExAttributes, newExAttributeId)
|
|
|
|
|
local randomExAttributeValue = rng:NextInteger(ExAttributeData.randomValue[1], ExAttributeData.randomValue[2])
|
|
|
|
|
|
|
|
|
|
local AttributeData = Utils:GetIdDataFromJson(JsonAttributes, newExAttributeId)
|
|
|
|
|
ResultData.exAttributes[AttributeData.name] = randomExAttributeValue
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 随机生成元素属性数量(暂时跟额外属性相同,之后可以改逻辑)
|
|
|
|
|
local maxElementNumber = PlayerInfoProxy:GetPlayerInfo(Player).elementNumber or 0
|
|
|
|
|
local elementNumber = rng:NextInteger(0, maxElementNumber)
|
|
|
|
|
ResultData.maxElementNumber = elementNumber
|
|
|
|
|
ResultData.elements = {}
|
|
|
|
|
if elementNumber > 0 then
|
|
|
|
|
local spawnElementsId = {}
|
|
|
|
|
for i = 1, elementNumber do
|
|
|
|
|
local newElementAttributeId = Utils:GetRandomIdFromJsonWithType(JsonExAttributes, 1, spawnElementsId)
|
|
|
|
|
table.insert(spawnElementsId, newElementAttributeId)
|
|
|
|
|
|
|
|
|
|
local ElementAttributeData = Utils:GetIdDataFromJson(JsonExAttributes, newElementAttributeId)
|
|
|
|
|
local randomElementAttributeValue = rng:NextInteger(ElementAttributeData.randomValue[1], ElementAttributeData.randomValue[2])
|
|
|
|
|
|
|
|
|
|
local AttributeData = Utils:GetIdDataFromJson(JsonAttributes, newElementAttributeId)
|
|
|
|
|
ResultData.elements[AttributeData.name] = randomElementAttributeValue
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 随机生成元素抗性数量
|
|
|
|
|
local maxElementDefNumber = PlayerInfoProxy:GetPlayerInfo(Player).elementDefNumber or 0
|
|
|
|
|
local elementDefNumber = rng:NextInteger(0, maxElementDefNumber)
|
|
|
|
|
ResultData.maxElementDefNumber = elementDefNumber
|
|
|
|
|
ResultData.elementDef = {}
|
|
|
|
|
if elementDefNumber > 0 then
|
|
|
|
|
local spawnElementDefId = {}
|
|
|
|
|
for i = 1, elementDefNumber do
|
|
|
|
|
local newElementDefId = Utils:GetRandomIdFromJsonWithType(JsonExAttributes, 1, spawnElementDefId)
|
|
|
|
|
table.insert(spawnElementDefId, newElementDefId)
|
|
|
|
|
|
|
|
|
|
local ElementDefAttributeData = Utils:GetIdDataFromJson(JsonExAttributes, newElementDefId)
|
|
|
|
|
local randomElementDefAttributeValue = rng:NextInteger(ElementDefAttributeData.randomValue[1], ElementDefAttributeData.randomValue[2])
|
|
|
|
|
|
|
|
|
|
local AttributeData = Utils:GetIdDataFromJson(JsonAttributes, newElementDefId)
|
|
|
|
|
ResultData.elementDef[AttributeData.name] = randomElementDefAttributeValue
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 随机生成技能槽位数量
|
|
|
|
|
local AbilityProxy = require(ServerStorage.Proxy.AbilityProxy)
|
|
|
|
|
|
|
|
|
|
local maxAbilityNumber = PlayerInfoProxy:GetPlayerInfo(Player).abilityNumber or 0
|
|
|
|
|
local abilityNumber = rng:NextInteger(0, maxAbilityNumber)
|
|
|
|
|
ResultData.maxAbilityNumber = abilityNumber
|
|
|
|
|
if abilityNumber > 0 then
|
|
|
|
|
local spawnAbilitiesId = {}
|
|
|
|
|
for i = 1, abilityNumber do
|
|
|
|
|
local newAbilityId = AbilityProxy:GetRandomAbilityId(spawnAbilitiesId)
|
|
|
|
|
table.insert(spawnAbilitiesId, newAbilityId)
|
|
|
|
|
local newAbilityData, newAbilityInstance = AbilityProxy:AddAbility(Player, newAbilityId)
|
|
|
|
|
AbilityProxy:WearAbility(Player, newAbilityData.id, UniqueId)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 随机生成宝石数量
|
|
|
|
|
local GemProxy = require(ServerStorage.Proxy.GemProxy)
|
|
|
|
|
local maxGemNumber = PlayerInfoProxy:GetPlayerInfo(Player).gemNumber or 0
|
|
|
|
|
local gemNumber = rng:NextInteger(0, maxGemNumber)
|
|
|
|
|
ResultData.maxGemNumber = gemNumber
|
|
|
|
|
if gemNumber > 0 then
|
|
|
|
|
local spawnGemsId = {}
|
|
|
|
|
for i = 1, gemNumber do
|
|
|
|
|
local newGemId = GemProxy:GetRandomGemId(spawnGemsId)
|
|
|
|
|
table.insert(spawnGemsId, newGemId)
|
|
|
|
|
local newGemData, newGemInstance = GemProxy:AddGem(Player, newGemId)
|
|
|
|
|
GemProxy:WearGem(Player, newGemData.id, UniqueId)
|
|
|
|
|
end
|
|
|
|
|
end
|
2025-07-02 00:56:31 +08:00
|
|
|
|
|
|
|
|
|
------------------------------------------------------------
|
|
|
|
|
|
2025-07-02 00:21:32 +08:00
|
|
|
|
ArchiveProxy.pData[Player.UserId][UniqueId] = ResultData
|
2025-07-12 05:06:14 +08:00
|
|
|
|
Utils:CreateDataInstance(Player, UniqueId, ResultData, GetPlayerEquipmentFolder(Player))
|
2025-07-02 00:21:32 +08:00
|
|
|
|
end
|
|
|
|
|
|
2025-07-03 01:48:06 +08:00
|
|
|
|
-- 回收装备
|
2025-07-02 00:56:31 +08:00
|
|
|
|
function EquipmentProxy:RecycleEquipment(Player: Player, EquipmentId: number)
|
|
|
|
|
local pData = Utils:GetPlayerDataFolder(Player)
|
|
|
|
|
if not pData then return end
|
|
|
|
|
|
2025-07-03 01:48:06 +08:00
|
|
|
|
local EquipmentData = ArchiveProxy.pData[Player.UserId][STORE_NAME][EquipmentId]
|
2025-07-02 00:56:31 +08:00
|
|
|
|
if not EquipmentData then return end
|
|
|
|
|
|
2025-07-14 00:30:47 +08:00
|
|
|
|
-- TODO:根据对应功能模块生成对应技能
|
|
|
|
|
|
2025-07-02 00:56:31 +08:00
|
|
|
|
-- 回收装备返回金币
|
2025-07-03 01:48:06 +08:00
|
|
|
|
PlayerInfoProxy:ChangeItem(Player, 1, EquipmentData.recycle)
|
2025-07-02 00:56:31 +08:00
|
|
|
|
|
|
|
|
|
ArchiveProxy.pData[Player.UserId][EquipmentId] = nil
|
|
|
|
|
local EquipmentInstance = GetPlayerEquipmentFolder(Player):FindFirstChild(EquipmentId)
|
|
|
|
|
if EquipmentInstance then
|
|
|
|
|
EquipmentInstance:Destroy()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2025-07-03 01:48:06 +08:00
|
|
|
|
-- 穿戴装备
|
2025-07-02 00:56:31 +08:00
|
|
|
|
function EquipmentProxy:WearEquipment(Player: Player, EquipmentId: number)
|
|
|
|
|
local pData = Utils:GetPlayerDataFolder(Player)
|
|
|
|
|
if not pData then return end
|
|
|
|
|
|
|
|
|
|
-- 穿戴装备时再生成模型
|
|
|
|
|
|
|
|
|
|
end
|
2025-07-02 00:21:32 +08:00
|
|
|
|
|
2025-07-12 05:06:14 +08:00
|
|
|
|
-- 获取装备数据
|
|
|
|
|
function EquipmentProxy:GetEquipmentData(Player: Player, EquipmentUniqueId: number)
|
|
|
|
|
local EquipmentData = ArchiveProxy.pData[Player.UserId][STORE_NAME][EquipmentUniqueId]
|
|
|
|
|
return EquipmentData
|
|
|
|
|
end
|
|
|
|
|
|
2025-07-02 00:21:32 +08:00
|
|
|
|
function EquipmentProxy:OnPlayerRemoving(Player: Player)
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2025-07-03 01:48:06 +08:00
|
|
|
|
ReplicatedStorage.Remotes.PlayerRemoving.Event:Connect(function(PlayerUserId: string)
|
|
|
|
|
EquipmentProxy:OnPlayerRemoving(PlayerUserId)
|
|
|
|
|
end)
|
2025-07-02 00:21:32 +08:00
|
|
|
|
|
|
|
|
|
return EquipmentProxy
|