miduo_client/Assets/ManagedResources/~Lua/Modules/Battle/View/Unit/FloatNode.lua

385 lines
14 KiB
Lua
Raw Normal View History

2021-04-20 13:58:00 +08:00
FloatNode = {}
2020-11-01 15:46:48 +08:00
local floatingEffect = "FloatingText"
local buffFloatingEffect = "BuffFloatingText"
local floor = math.floor
2020-11-01 15:46:48 +08:00
-- 普通文字
TextFloatingColor = {
Blue = 1,
Red = 2,
Purple = 3,
Green = 4,
DarkGreen=5,
2020-11-01 15:46:48 +08:00
}
local _FloatingTypeToColor = {
[TextFloatingColor.Blue] = Color.New(31, 237, 255, 255) / 255,
[TextFloatingColor.Red] = Color.New(236, 4, 4, 255) / 255,
[TextFloatingColor.Purple] = Color.New(235, 17, 255, 255) / 255,
[TextFloatingColor.Green] = Color.New(17, 255, 17, 255) / 255,
[TextFloatingColor.DarkGreen] = Color.New(56, 127, 46, 255) / 255,
2020-11-01 15:46:48 +08:00
}
-- 艺术字
ArtFloatingType = {
CritDamage = 1, -- 暴击
Damage = 2,
Treat = 3,
FireDamage = 4,
PoisonDamage = 5,
yujiaAdd = 6,
2021-10-20 21:33:37 +08:00
BleedDamage = 7,
2020-11-01 15:46:48 +08:00
}
local ArtFloatingAnim = {
[1] = "Crit_Attack_Float",
[2] = "Normal_Attack_Float",
[3] = "floatingTextAnim",
[4] = "floatingTextAnim",
[5] = "floatingTextAnim",
}
--角色受到的暴击伤害(无论什么类型) - 红色字体 (字符顺序40-49 ,0-9)(110, -)(111, +)(33, 暴击)(35, 灼烧)
--角色造成的点击技伤害 - 白色字体 (字符顺序50-59 ,0-9)(112, -)(113, +)
--角色造成的滑动技伤害 - 黄色字体 (字符顺序60-69 ,0-9)(114, -)(115, +)
--角色恢复量 - 绿色字体 (字符顺序70-79 ,0-9)(116, -)(117, +)
--角色造成的异妖技伤害 - 紫色字体 (字符顺序80-89 ,0-9)(118, -)(119, +)(34, 中毒)
ArtFloatingColor = {
Red = 0,
White = 1,
Yellow = 2,
Green = 3,
Purple = 4,
Poison = 5,
Fire = 6,
}
function FloatNode.New(unit, root, node)
local o = {}
setmetatable(o, {__index = FloatNode})
o:ctor(unit, root, node)
return o
end
function FloatNode:ctor(unit, root, node)
2021-04-21 13:12:04 +08:00
self.spLoader = SpriteLoader.New()
2020-11-01 15:46:48 +08:00
self.owner = unit
self.RootPanel = root
self.GameObject = node
2023-12-29 23:53:05 +08:00
self.targetPos=node.transform.position
2020-11-01 15:46:48 +08:00
self.LastBuffTextTime = Time.realtimeSinceStartup
self.BuffTextCount = 0
self.LastFloatingTime = Time.realtimeSinceStartup
self.FloatingCount = 0
end
2021-04-21 13:12:04 +08:00
function FloatNode:Dispose()
2023-12-29 18:07:20 +08:00
2021-04-21 13:12:04 +08:00
self.spLoader:Destroy()
end
2020-11-01 15:46:48 +08:00
function FloatNode:TextBuffFloating(type, text)
local color = _FloatingTypeToColor[type]
local go = BattleManager.LoadAsset(buffFloatingEffect)
local baseY = 0
go.transform:SetParent(self.RootPanel.transform)
go.transform.localScale = Vector3.one
go.transform.position = self.GameObject.transform.position
go:SetActive(true)
if Time.realtimeSinceStartup - self.LastBuffTextTime < BattleLogic.GameDeltaTime then
self.BuffTextCount = self.BuffTextCount + 1
else
self.BuffTextCount = 0
end
self.LastBuffTextTime = Time.realtimeSinceStartup
local v2 = go:GetComponent("RectTransform").anchoredPosition
go:GetComponent("RectTransform").anchoredPosition = v2 + Vector2.New(0,baseY + self.BuffTextCount * 60)
local battleSorting = BattleManager.GetBattleSorting()
Util.GetGameObject(go, "anim"):GetComponent("Canvas").sortingOrder = battleSorting + 200
Util.GetGameObject(go, "anim/text"):SetActive(true)
Util.GetGameObject(go, "anim/text"):GetComponent("Text").text = text
Util.GetGameObject(go, "anim/text"):GetComponent("Text").color = color
Util.GetGameObject(go, "anim/grid"):SetActive(false)
BattleManager.AddDelayRecycleRes(buffFloatingEffect, go, 1.3)
end
--
function FloatNode:ImageBuffFloating(textImg, numImg, numTxt,type,isPurple)
2020-11-01 15:46:48 +08:00
local go = BattleManager.LoadAsset(buffFloatingEffect)
local baseY = 0
go.transform:SetParent(self.RootPanel.transform)
go.transform.localScale = Vector3.one
go.transform.position = self.GameObject.transform.position
go:SetActive(true)
if Time.realtimeSinceStartup - self.LastBuffTextTime < BattleLogic.GameDeltaTime then
self.BuffTextCount = self.BuffTextCount + 1
else
self.BuffTextCount = 0
end
self.LastBuffTextTime = Time.realtimeSinceStartup
local v2 = go:GetComponent("RectTransform").anchoredPosition
go:GetComponent("RectTransform").anchoredPosition = v2 + Vector2.New(0,baseY + self.BuffTextCount * 60)
local battleSorting = BattleManager.GetBattleSorting()
Util.GetGameObject(go, "anim"):GetComponent("Canvas").sortingOrder = battleSorting + 200
Util.GetGameObject(go, "anim/text"):SetActive(false)
Util.GetGameObject(go, "anim/grid"):SetActive(true)
local img1 = Util.GetGameObject(go, "anim/grid/Image1"):GetComponent("Image")
local img2 = Util.GetGameObject(go, "anim/grid/Image2"):GetComponent("Image")
local txt3 = Util.GetGameObject(go, "anim/grid/Text"):GetComponent("Text")
local txt4 = Util.GetGameObject(go, "anim/grid/Text1"):GetComponent("Text")
2020-11-01 15:46:48 +08:00
if textImg then
img1.gameObject:SetActive(true)
if type~=nil and type~=0 then
local list = string.split(textImg, "#")
if list and LengthOfTable(list)>1 then
textImg=list[type]
end
end
2021-04-21 13:12:04 +08:00
img1.sprite = self.spLoader:LoadSprite(textImg)
2020-11-01 15:46:48 +08:00
img1:SetNativeSize()
else
img1.gameObject:SetActive(false)
end
if numImg then
img2.gameObject:SetActive(true)
2021-04-21 13:12:04 +08:00
img2.sprite = self.spLoader:LoadSprite(numImg)
2020-11-01 15:46:48 +08:00
img2:SetNativeSize()
else
img2.gameObject:SetActive(false)
end
2020-11-01 15:46:48 +08:00
if numTxt then
txt3.gameObject:SetActive(true)
if isPurple then
txt4.gameObject:SetActive(true)
txt3.gameObject:SetActive(false)
else
txt4.gameObject:SetActive(false)
txt3.gameObject:SetActive(true)
end
2020-11-01 15:46:48 +08:00
txt3.text = numTxt
txt4.text = numTxt
2020-11-01 15:46:48 +08:00
else
txt3.gameObject:SetActive(false)
txt4.gameObject:SetActive(false)
2020-11-01 15:46:48 +08:00
end
BattleManager.AddDelayRecycleRes(buffFloatingEffect, go, 1.3)
end
function FloatNode:GetArtText(type, color, value)
2021-01-26 17:08:39 +08:00
local sp = ""
2020-11-01 15:46:48 +08:00
local text = ""
value=floor(value)
2020-11-01 15:46:48 +08:00
if type == ArtFloatingType.CritDamage then
2021-01-26 17:08:39 +08:00
sp = "r_zhandou_baoji_zh" -- 暴击
2020-11-01 15:46:48 +08:00
text = text .. string.char((color*2)+110) -- 减号
elseif type == ArtFloatingType.Damage then
text = text .. string.char((color*2)+110) -- 减号
elseif type == ArtFloatingType.Treat then
text = text..string.char((color*2)+111) -- 加号
elseif type == ArtFloatingType.FireDamage then
2021-01-26 17:08:39 +08:00
sp = "z_zhandou_zhuoshao_zh" -- 灼烧
-- text = text .. string.char(35) -- 灼烧文字
2020-11-01 15:46:48 +08:00
text = text .. string.char((color*2)+110) -- 减号
elseif type == ArtFloatingType.PoisonDamage then
2021-01-26 17:08:39 +08:00
sp = "z_zhandou_zhongdu_zh" -- 灼烧
-- text = text .. string.char(34) -- 中毒文字
2020-11-01 15:46:48 +08:00
text = text .. string.char((color*2)+110) -- 减号
elseif type == ArtFloatingType.yujiaAdd then
sp = "z_zhandou_yujia_zh" --御甲
text = text .. string.char((color*2)+111) -- 减号
2021-10-20 21:33:37 +08:00
elseif type == ArtFloatingType.BleedDamage then
sp = "z_zhandou_liuxue_zh" -- 流血
text = text .. string.char((color*2)+110) -- 减号
2020-11-01 15:46:48 +08:00
end
-- 数字
local str = tostring(value)
for i=1,#str do
text = text..string.char((string.byte(str,i) - 48) + color*10 + 40)
end
2021-01-26 17:08:39 +08:00
return sp, text
2020-11-01 15:46:48 +08:00
end
2023-12-29 23:53:05 +08:00
-- function FloatNode:ArtFloating(type, color, value,role)
-- local trole= role and role or nil
-- local go = BattleManager.LoadAsset(floatingEffect)
-- go.transform:SetParent(self.RootPanel.transform)
-- go.transform.localScale = Vector3.one * 0.70
-- go.transform.position = self.GameObject.transform.position
-- local index=0
-- local t={}
-- if trole~=nil then
-- local index=0
-- if #trole.DamageTextTable== 0 then
-- trole.DamageTextTable[#trole.DamageTextTable+1]=go
-- index=#trole.DamageTextTable
-- else
-- for key, value in pairs(trole.DamageTextTable) do
-- if trole.DamageTextTable[key] == nil then
-- trole.DamageTextTable[key] =go
-- index =key
-- break
-- end
-- end
-- if index==0 then
-- trole.DamageTextTable[#trole.DamageTextTable+1]=go
-- index=#trole.DamageTextTable
-- end
-- end
-- LogError("index=="..index)
-- go.transform.position =Vector3.New(self.GameObject.transform.position.x,self.GameObject.transform.position.y+0.15*index,self.GameObject.transform.position.z)
-- LogError("goy"..go.transform.position.y)
-- else
-- go.transform.position = self.GameObject.transform.position
-- end
-- -- go.transform.position = self.GameObject.transform.position
-- go:SetActive(true)
-- if Time.realtimeSinceStartup - self.LastFloatingTime < BattleLogic.GameDeltaTime then
-- self.FloatingCount = self.FloatingCount + 1
-- else
-- self.FloatingCount = 0
-- end
-- self.LastFloatingTime = Time.realtimeSinceStartup
-- local v2 = go:GetComponent("RectTransform").anchoredPosition
-- v2 = v2 + Vector2.New(0, self.owner.role.camp * 100 + 100)
-- go:GetComponent("RectTransform").anchoredPosition = v2 + Vector2.New(0, 50) * (self.FloatingCount+1)
-- local sp, text = self:GetArtText(type, color, value)
-- local anim = Util.GetGameObject(go, "anim")
-- -- 伤害文字
-- local img = Util.GetGameObject(anim, "Image"):GetComponent("Image")
-- if sp and sp ~= "" then
-- img.sprite = self.spLoader:LoadSprite(sp)
-- img.gameObject:SetActive(true)
-- else
-- img.gameObject:SetActive(false)
-- end
-- -- 伤害数值
-- local animTxt = Util.GetGameObject(go, "anim/anim")
-- local animTxtC = animTxt:GetComponent("Text")
-- animTxtC.text = text
-- --主要用于给白色字体染色成其他颜色color 参数只能填白色
-- -- 层级和动画
-- anim:GetComponent("Canvas").sortingOrder = BattleManager.GetBattleSorting() + 100
-- anim:GetComponent("Animator"):Play(ArtFloatingAnim[type])
-- BattleManager.AddDelayRecycleRes(floatingEffect, go, 3,function ()
-- if trole then
-- for key, value in pairs(trole.DamageTextTable) do
-- if value == go then
-- trole.DamageTextTable[key] = nil
-- break
-- end
-- end
-- -- LogError(#trole.DamageTextTable)
-- end
-- end)
-- end
function FloatNode:ArtFloating(type, color, value,role,tarGetPos)
2023-12-29 18:07:20 +08:00
local trole= role and role or nil
2023-12-29 23:53:05 +08:00
local ttarGetPos=tarGetPos and tarGetPos or self.GameObject.transform.position
2020-11-01 15:46:48 +08:00
local go = BattleManager.LoadAsset(floatingEffect)
go.transform:SetParent(self.RootPanel.transform)
2023-12-29 23:53:05 +08:00
go.transform.localScale = Vector3.one * 0.70
self.targetPos=self.owner.SingleHitEffectRoot.gameObject.transform.position
go.transform.position = self.targetPos
2023-12-29 18:07:20 +08:00
local index=0
local t={}
if trole~=nil then
2023-12-29 23:53:05 +08:00
local index=0
if #trole== 0 then
trole[#trole+1]=go
index=#trole
else
for key, value in pairs(trole) do
if trole[key] == nil then
trole[key] =go
index =key
break
end
end
if index==0 then
trole[#trole+1]=go
index=#trole
end
end
2023-12-30 00:01:00 +08:00
go.transform.position =Vector3.New(GetPreciseDecimal(tonumber(self.targetPos.x),5),GetPreciseDecimal(self.targetPos.y+0.5+0.10*index,5),GetPreciseDecimal(self.targetPos.z,5))
2023-12-29 23:53:05 +08:00
LogError(index)
-- LogError("Gax"..self.targetPos.x)
-- -- LogError("goy"..go.transform.position.y)
-- LogError("gox"..go.transform.position.x)
2023-12-29 18:07:20 +08:00
else
2023-12-29 23:53:05 +08:00
go.transform.position = self.targetPos
2023-12-29 18:07:20 +08:00
end
-- go.transform.position = self.GameObject.transform.position
2020-11-01 15:46:48 +08:00
go:SetActive(true)
if Time.realtimeSinceStartup - self.LastFloatingTime < BattleLogic.GameDeltaTime then
self.FloatingCount = self.FloatingCount + 1
else
self.FloatingCount = 0
end
self.LastFloatingTime = Time.realtimeSinceStartup
local v2 = go:GetComponent("RectTransform").anchoredPosition
v2 = v2 + Vector2.New(0, self.owner.role.camp * 100 + 100)
2023-12-29 23:53:05 +08:00
--go:GetComponent("RectTransform").anchoredPosition = v2 + Vector2.New(0, 50) * (self.FloatingCount+1)
2020-11-01 15:46:48 +08:00
2021-01-26 17:08:39 +08:00
local sp, text = self:GetArtText(type, color, value)
2020-11-01 15:46:48 +08:00
local anim = Util.GetGameObject(go, "anim")
2021-01-26 17:08:39 +08:00
-- 伤害文字
local img = Util.GetGameObject(anim, "Image"):GetComponent("Image")
if sp and sp ~= "" then
2021-04-21 13:12:04 +08:00
img.sprite = self.spLoader:LoadSprite(sp)
2021-01-26 17:08:39 +08:00
img.gameObject:SetActive(true)
else
img.gameObject:SetActive(false)
end
-- 伤害数值
local animTxt = Util.GetGameObject(go, "anim/anim")
local animTxtC = animTxt:GetComponent("Text")
animTxtC.text = text
--主要用于给白色字体染色成其他颜色color 参数只能填白色
2021-01-26 17:08:39 +08:00
-- 层级和动画
2020-11-01 15:46:48 +08:00
anim:GetComponent("Canvas").sortingOrder = BattleManager.GetBattleSorting() + 100
anim:GetComponent("Animator"):Play(ArtFloatingAnim[type])
2023-12-29 23:53:05 +08:00
BattleManager.AddDelayRecycleRes(floatingEffect, go, 3,function ()
2023-12-29 18:07:20 +08:00
if trole then
2023-12-29 23:53:05 +08:00
for key, value in pairs(trole) do
if value == go then
trole[key] = nil
2023-12-29 18:07:20 +08:00
break
end
end
2023-12-29 23:53:05 +08:00
-- LogError(#trole.DamageTextTable)
2023-12-29 18:07:20 +08:00
end
end)
2020-11-01 15:46:48 +08:00
end
2023-12-29 23:53:05 +08:00
function FloatNode:SetPosition(pos)
self.targetPos=pos
end
2020-11-01 15:46:48 +08:00
return FloatNode