From 2d612189d53bb843be045ebef86e60c9c0a0ea1b Mon Sep 17 00:00:00 2001 From: Ggafrik <906823881@qq.com> Date: Thu, 17 Jul 2025 00:12:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Modules/Behaviours/SwordWave.luau | 19 ++++ src/ServerStorage/Proxy/DamageProxy.luau | 14 +++ src/ServerStorage/Proxy/MobsProxy/AI.luau | 3 +- src/StarterPlayerScripts/Base/UIWindow.luau | 101 ++++++++++++++++++ .../PerformanceClient/DamageBoard.luau | 48 +++++++-- src/StarterPlayerScripts/UI/UIManager.luau | 0 6 files changed, 177 insertions(+), 8 deletions(-) create mode 100644 src/StarterPlayerScripts/Base/UIWindow.luau create mode 100644 src/StarterPlayerScripts/UI/UIManager.luau diff --git a/src/ServerStorage/Modules/Behaviours/SwordWave.luau b/src/ServerStorage/Modules/Behaviours/SwordWave.luau index 35b3cfb..f3244b7 100644 --- a/src/ServerStorage/Modules/Behaviours/SwordWave.luau +++ b/src/ServerStorage/Modules/Behaviours/SwordWave.luau @@ -97,6 +97,25 @@ function SwordWave:OnHit(Victim: TypeList.Character) Damage = 30, Type = DamageProxy.DamageType.SKILL, Tag = DamageProxy.DamageTag.NORMAL, + ElementType = DamageProxy.ElementType.NONE, + }, + { + Damage = 5, + Type = DamageProxy.DamageType.SKILL, + Tag = DamageProxy.DamageTag.NORMAL, + ElementType = DamageProxy.ElementType.FIRE, + }, + { + Damage = 5, + Type = DamageProxy.DamageType.SKILL, + Tag = DamageProxy.DamageTag.NORMAL, + ElementType = DamageProxy.ElementType.ICE, + }, + { + Damage = 5, + Type = DamageProxy.DamageType.SKILL, + Tag = DamageProxy.DamageTag.NORMAL, + ElementType = DamageProxy.ElementType.SHADOW, } }) return false diff --git a/src/ServerStorage/Proxy/DamageProxy.luau b/src/ServerStorage/Proxy/DamageProxy.luau index 4201a87..c8030a6 100644 --- a/src/ServerStorage/Proxy/DamageProxy.luau +++ b/src/ServerStorage/Proxy/DamageProxy.luau @@ -24,17 +24,27 @@ local DamageTag = { NORMAL = "Normal", -- 普攻 CRIT = "Crit", -- 暴击 } +local ElementType = { + NONE = "None", -- 无 + FIRE = "Fire", + ICE = "Ice", -- 冰 + SHADOW = "Shadow", -- 暗影 + LIGHT = "Light", -- 光 +} export type DamageTag = "Normal" | "Critical" export type DamageType = "Normal" | "Skill" +export type ElementType = "Fire" | "Ice" | "Shadow" | "Light" export type DamageInfo = { Damage: number, Type: DamageType, Tag: DamageTag, + ElementType: ElementType, } DamageProxy.DamageType = DamageType DamageProxy.DamageTag = DamageTag +DamageProxy.ElementType = ElementType -------------------------------------------------------------------------------- @@ -125,9 +135,13 @@ function DamageProxy:TakeDamage(Caster: TypeList.Character, Victim: TypeList.Cha clientDamageInfos.DamageInfos = Utils:DeepCopyTable(DamageInfos) for _, DamageInfo in DamageInfos do + if not Victim then continue end + if Victim:GetState("Died") then continue end + local Damage = DamageInfo.Damage local DamageType = DamageInfo.DamageType local DamageTag = DamageInfo.DamageTag + local ElementType = DamageInfo.ElementType -- 伤害计算 local VictimHealth = Victim:GetAttributeValue("hp") diff --git a/src/ServerStorage/Proxy/MobsProxy/AI.luau b/src/ServerStorage/Proxy/MobsProxy/AI.luau index 12fb314..cc77bf9 100644 --- a/src/ServerStorage/Proxy/MobsProxy/AI.luau +++ b/src/ServerStorage/Proxy/MobsProxy/AI.luau @@ -98,7 +98,8 @@ task.defer(function() { Damage = Mob.Config.attack, DamageType = DamageProxy.DamageType.PHYSICAL, - DamageTag = DamageProxy.DamageTag.NORMAL + DamageTag = DamageProxy.DamageTag.NORMAL, + ElementType = DamageProxy.ElementType.NONE, } }) end diff --git a/src/StarterPlayerScripts/Base/UIWindow.luau b/src/StarterPlayerScripts/Base/UIWindow.luau new file mode 100644 index 0000000..da73f46 --- /dev/null +++ b/src/StarterPlayerScripts/Base/UIWindow.luau @@ -0,0 +1,101 @@ +local UIWindow = {} +UIWindow.__index = UIWindow + +--> Services +local ReplicatedStorage = game:GetService("ReplicatedStorage") + +--> Variables +local FolderWindows = ReplicatedStorage:WaitForChild("UI"):WaitForChild("Windows") + +local LocalPlayer = game.Players.LocalPlayer +local FolderPlayerGui = LocalPlayer:WaitForChild("PlayerGui") + +-------------------------------------------------------------------------------- + +-- 递归查找 +local function FindInDescendants(root, name) + if root:FindFirstChild(name) then + return root:FindFirstChild(name) + end + for _, child in ipairs(root:GetChildren()) do + local found = FindInDescendants(child, name) + if found then + return found + end + end + return nil +end + +-- 非递归查找 +local function FindInRoot(root, name) + return root:FindFirstChild(name) +end + +-------------------------------------------------------------------------------- + +function UIWindow:Init(Data: table?) + local self = {} + self.Data = Data + self.Variables = {} + self.UIRootName = nil + self.UIParentName = nil + + + self.UIRoot = nil + self.AutoInject = false + + return self +end + +function UIWindow:SetData(Data: table?) + self.Data = Data + self:OnDataChanged() +end + +function UIWindow:OnOpenWindow() + + if not self.UIRoot then + -- 创建UI根节点 + self.UIRoot = FolderWindows:FindFirstChild(self.UIRootName):Clone() + self.UIRoot.Parent = FolderPlayerGui:FindFirstChild(self.UIParentName) + end + + -- 自动注入 + if not self.AutoInject then + for varName, _ in pairs(self.Variables) do + if typeof(varName) == "string" then + local firstChar = string.sub(varName, 1, 1) + local secondChar = string.sub(varName, 2, 2) + local target + + if firstChar == "_" then + if secondChar == "_" then + -- __开头,只查根目录 + target = FindInRoot(self.UIRoot, varName) + else + -- _开头,递归查找 + target = FindInDescendants(self.UIRoot, varName) + end + + if not target then + error("自动注入失败:未找到UI节点 " .. varName) + end + + self[varName] = target + end + end + end + self.AutoInject = true + end +end + +function UIWindow:OnCloseWindow() + +end + +--> 覆盖用 +function UIWindow:OnDataChanged() end + +function UIWindow:Refresh() end + +return UIWindow \ No newline at end of file diff --git a/src/StarterPlayerScripts/ClientMain/PerformanceClient/DamageBoard.luau b/src/StarterPlayerScripts/ClientMain/PerformanceClient/DamageBoard.luau index a0b592c..b411820 100644 --- a/src/StarterPlayerScripts/ClientMain/PerformanceClient/DamageBoard.luau +++ b/src/StarterPlayerScripts/ClientMain/PerformanceClient/DamageBoard.luau @@ -6,6 +6,21 @@ local ReplicatedStorage = game:GetService("ReplicatedStorage") --> Variables local FolderDamageBoard = ReplicatedStorage.UI.DamageBoard +local sort_order = { + ["None"] = 1, + ["Fire"] = 2, + ["Ice"] = 3, + ["Shadow"] = 4, + ["Light"] = 5, +} +local element_color = { + ["None"] = Color3.fromRGB(218, 218, 218), + ["Fire"] = Color3.fromRGB(255, 65, 65), + ["Ice"] = Color3.fromRGB(64, 217, 255), + ["Shadow"] = Color3.fromRGB(165, 65, 252), + ["Light"] = Color3.fromRGB(215, 215, 57), +} + local LocalPlayer = game.Players.LocalPlayer local Boards = {} @@ -19,16 +34,35 @@ function DamageBoard:GetBoard(Name: string) end function DamageBoard:CreateNormalDamageBoard(DamageDetail: table) - print(DamageDetail) + local DamageInitPos = DamageDetail.DamagePosition + local BiasPos = Vector3.new(0, 3, 0) + local MultPos = Vector3.new(0, 1, 0) + + -- 根据元素类型排序 + local DamageInfos = DamageDetail["DamageInfos"] + table.sort(DamageInfos, function(a, b) + local a_order = sort_order[a.ElementType] or 99 + local b_order = sort_order[b.ElementType] or 99 + return a_order < b_order + end) + + local index = 0 local BoardInstance = Boards["Board1"]:Clone() - BoardInstance.Parent = game.Workspace - -- local biasPos = (LocalPlayer.Character.HumanoidRootPart.Position - DamageDetail.DamagePosition).Unit * 2 - BoardInstance.Position = DamageDetail.DamagePosition + Vector3.new(0, 3, 0) + for _, DamageInfo in DamageInfos do + local BoardCanvas = BoardInstance:FindFirstChild("BillboardGui"):FindFirstChild("Canvas") + local DamageInstance = BoardCanvas:FindFirstChild("Damage") + + local ElementInstance = BoardCanvas:FindFirstChild("Element") + ElementInstance.ImageColor3 = element_color[DamageInfo.ElementType] - local DamageInstance = BoardInstance:FindFirstChild("BillboardGui"):FindFirstChild("Canvas"):FindFirstChild("Damage") - DamageInstance.Text = DamageDetail["DamageInfos"][1].Damage + DamageInstance.Text = DamageInfo.Damage + DamageInstance.TextColor3 = element_color[DamageInfo.ElementType] - game.Debris:AddItem(BoardInstance, 1) + BoardInstance.Position = DamageInitPos + BiasPos + MultPos * index + BoardInstance.Parent = game.Workspace + game.Debris:AddItem(BoardInstance, 1) + index = index + 1 + end end diff --git a/src/StarterPlayerScripts/UI/UIManager.luau b/src/StarterPlayerScripts/UI/UIManager.luau new file mode 100644 index 0000000..e69de29