-- 控制客户端表现管理 local PerformanceClient = {} PerformanceClient.pData = {} --> Services local ReplicatedStorage = game:GetService("ReplicatedStorage") --> Events local EventsFolder = ReplicatedStorage:FindFirstChild("Events") local RE_PerformanceEvent = EventsFolder:FindFirstChild("RE_PerformanceEvent") local RE_CleanPlayerPerformance = EventsFolder:FindFirstChild("RE_CleanPlayerPerformance") local RE_DamagePerformance = EventsFolder:FindFirstChild("RE_DamagePerformance") local RE_AbilityPerformance = EventsFolder:FindFirstChild("RE_AbilityPerformance") local RE_ShowGetEquipments = EventsFolder:FindFirstChild("RE_ShowGetEquipments") --> Dependencies local UIManager = require(script.Parent.Parent.UI.UIManager) local Signal = require(ReplicatedStorage.Tools.Signal) --> Variables local LocalPlayer = game.Players.LocalPlayer local DamageBoard = require(script.DamageBoard) local showAbilitySignal = Signal.new(Signal.ENUM.SHOW_ABILITY) -------------------------------------------------------------------------------- -- 生成本地化表现目录 local PerformanceFolder = Instance.new("Folder") PerformanceFolder.Name = "Performance" PerformanceFolder.Parent = game.Workspace -- 加载所有客户端行为 local Behaviours = {} local BehaviourFolder = ReplicatedStorage:FindFirstChild("Modules"):FindFirstChild("BehavioursClient") if BehaviourFolder then for _, behaviourModule in ipairs(BehaviourFolder:GetChildren()) do if behaviourModule:IsA("ModuleScript") then local success, result = pcall(require, behaviourModule) if success then -- 去掉文件名后缀 local name = behaviourModule.Name Behaviours[name] = result else warn("加载代理模块失败: " .. behaviourModule.Name, result) end end end end -- 监听表现事件调用 RE_PerformanceEvent.OnClientEvent:Connect(function(ServerTime: number, CastTag: string, CasterPlayer: Player, BehaviourName: string, CastState: boolean, Infos: table) -- 初始化玩家存储 local UserId = CasterPlayer.UserId if not PerformanceClient.pData[UserId] then PerformanceClient.pData[UserId] = {} end local delayTime = ServerTime - tick() if CastTag == "Init" then -- 暂时就新增一个表,不调用初始化,因为服务端不是多个new做的,而是多次调用 if not PerformanceClient.pData[UserId][BehaviourName] then PerformanceClient.pData[UserId][BehaviourName] = {} end elseif CastTag == "Show" then -- print("Show", BehaviourName, Behaviours, Infos) -- 直接调用init和对应的show(因为服务端只new一次,客户端多次调用) if not PerformanceClient.pData[UserId][BehaviourName] then return end for _, CastInfo in pairs(Infos) do -- TODO:这里处理技能cd local BehaviourTable = PerformanceClient.pData[UserId][BehaviourName] BehaviourTable[CastInfo.UniqueId] = Behaviours[BehaviourName]:Init(CasterPlayer, CastInfo, delayTime, CastState) BehaviourTable[CastInfo.UniqueId]:Show(CasterPlayer, CastInfo, delayTime, CastState) -- 发送更新信号 showAbilitySignal:Fire(BehaviourName, CastInfo) end elseif CastTag == "Destroy" then if not PerformanceClient.pData[UserId][BehaviourName] then return end for _, CastInfo in pairs(Infos) do local Behaviour = PerformanceClient.pData[UserId][BehaviourName][CastInfo.UniqueId] if Behaviour and Behaviour.Destroy then Behaviour:Destroy() end end end end) -- 监听伤害表现事件调用 RE_DamagePerformance.OnClientEvent:Connect(function(ServerTime: number, CastTag: string, CastPlayer: Player, DamageDetail: table) -- print("DamagePerformance", ServerTime, CastTag, CastPlayer, DamageDetail) DamageBoard:CreateNormalDamageBoard(DamageDetail) end) -- 这里主要是初始化 RE_AbilityPerformance.OnClientEvent:Connect(function(ServerTime: number, CastTag: string, CastPlayer: Player, AbilityDetail: table) print("AbilityPerformance", ServerTime, CastTag, CastPlayer, AbilityDetail) if not UIManager:IsOpened("AbilityStateWindow") then UIManager:OpenWindow("AbilityStateWindow", AbilityDetail) else UIManager:SetData("AbilityStateWindow", AbilityDetail) end end) -- 清理玩家所有表现数据 RE_CleanPlayerPerformance.OnClientEvent:Connect(function(CleanedPlayer: Player) local UserId = CleanedPlayer.UserId if not PerformanceClient.pData[UserId] then return end for _, BehaviourList in pairs(PerformanceClient.pData[UserId]) do for _, Behaviour in pairs(BehaviourList) do Behaviour:Destroy() end end PerformanceClient.pData[UserId] = nil end) -- 监听获取装备事件调用 RE_ShowGetEquipments.OnClientEvent:Connect(function(EquipmentDetail: table) if not UIManager:IsOpened("GetEquipmentsWindow") then UIManager:OpenWindow("GetEquipmentsWindow", EquipmentDetail) end end) -- 打开默认界面 UIManager:OpenWindow("MainWindow") UIManager:OpenWindow("TipsWindow") return PerformanceClient