119 lines
4.7 KiB
Plaintext
Raw Normal View History

2025-07-12 05:06:14 +08:00
-- 控制客户端表现管理
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")
2025-07-16 00:45:20 +08:00
local RE_DamagePerformance = EventsFolder:FindFirstChild("RE_DamagePerformance")
local RE_AbilityPerformance = EventsFolder:FindFirstChild("RE_AbilityPerformance")
2025-07-12 05:06:14 +08:00
2025-07-18 01:11:49 +08:00
--> Dependencies
local UIManager = require(script.Parent.Parent.UI.UIManager)
local Signal = require(ReplicatedStorage.Tools.Signal)
2025-07-12 05:06:14 +08:00
--> Variables
local LocalPlayer = game.Players.LocalPlayer
2025-07-16 00:45:20 +08:00
local DamageBoard = require(script.DamageBoard)
2025-07-18 01:11:49 +08:00
local showAbilitySignal = Signal.new(Signal.ENUM.SHOW_ABILITY)
2025-07-12 05:06:14 +08:00
--------------------------------------------------------------------------------
-- 生成本地化表现目录
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
2025-07-22 01:56:56 +08:00
-- print("Init", BehaviourName)
2025-07-12 05:06:14 +08:00
-- 暂时就新增一个表不调用初始化因为服务端不是多个new做的而是多次调用
if not PerformanceClient.pData[UserId][BehaviourName] then
PerformanceClient.pData[UserId][BehaviourName] = {}
end
elseif CastTag == "Show" then
2025-07-22 01:56:56 +08:00
-- print("Show", BehaviourName, Behaviours, Infos)
2025-07-12 05:06:14 +08:00
-- 直接调用init和对应的show(因为服务端只new一次客户端多次调用)
if not PerformanceClient.pData[UserId][BehaviourName] then return end
for _, CastInfo in pairs(Infos) do
2025-07-16 00:45:20 +08:00
-- TODO:这里处理技能cd
2025-07-12 05:06:14 +08:00
local BehaviourTable = PerformanceClient.pData[UserId][BehaviourName]
BehaviourTable[CastInfo.UniqueId] = Behaviours[BehaviourName]:Init(CasterPlayer, CastInfo, delayTime, CastState)
BehaviourTable[CastInfo.UniqueId]:Show(CasterPlayer, CastInfo, delayTime, CastState)
2025-07-18 01:11:49 +08:00
-- 发送更新信号
showAbilitySignal:Fire(BehaviourName, CastInfo)
2025-07-12 05:06:14 +08:00
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)
2025-07-18 01:11:49 +08:00
2025-07-16 00:45:20 +08:00
-- 监听伤害表现事件调用
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)
2025-07-22 01:56:56 +08:00
if not UIManager:IsOpened("AbilityStateWindow") then
UIManager:OpenWindow("AbilityStateWindow", AbilityDetail)
else
UIManager:SetData("AbilityStateWindow", AbilityDetail)
end
2025-07-16 00:45:20 +08:00
end)
2025-07-12 05:06:14 +08:00
-- 清理玩家所有表现数据
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)
2025-07-19 03:03:02 +08:00
-- 打开默认界面
UIManager:OpenWindow("MainWindow")
2025-07-12 05:06:14 +08:00
return PerformanceClient