This commit is contained in:
Ggafrik 2025-07-17 00:12:35 +08:00
parent 587690b2fc
commit 2d612189d5
6 changed files with 177 additions and 8 deletions

View File

@ -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

View File

@ -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")

View File

@ -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

View File

@ -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

View File

@ -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