forked from haimanman/jx3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHM_CombatText.lua
107 lines (99 loc) · 2.94 KB
/
HM_CombatText.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
-- 海鳗插件:战斗浮动信息显示释放者名字
--
HM_CombatText = {
bShowName = true,
bExcludeSelf = true,
}
HM.RegisterCustomData("HM_CombatText")
---------------------------------------------------------------------
-- 本地函数和变量
---------------------------------------------------------------------
local _HM_CombatText = {
tList = {}, -- 待处理文本列表
}
-- set text replace
_HM_CombatText.SetText = function(txt, szText)
txt:__SetText(szText)
txt.arg0, txt.arg1 = arg0, arg1
-- force to check buff
local tar = HM.GetPlayer(arg0)
if tar then
for i = 1, tar.GetBuffCount() do
local dwID, nLevel, _, _, _, _, dwSkillSrcID = tar.GetBuff(i - 1)
if dwID == arg2 and nLevel == arg3 then
txt.arg0 = dwSkillSrcID or 0
txt.arg1 = tar.dwID
break
end
end
end
if not HM_CombatText.bExcludeSelf or txt.arg0 ~= UI_GetClientPlayerID() then
table.insert(_HM_CombatText.tList, txt)
end
end
-- hook
_HM_CombatText.Hook = function(nLevel)
local handle = Station.Lookup("Lowest/CombatText", "Handle_Level" .. nLevel)
if handle and not handle.bHookByHM then
handle.bHookByHM = true
for i = 0, handle:GetItemCount() - 1 do
local txt = handle:Lookup(i)
txt.__SetText = txt.SetText
txt.SetText = _HM_CombatText.SetText
end
handle.__AppendItemFromString = handle.AppendItemFromString
handle.AppendItemFromString = function(h, szMsg)
h:__AppendItemFromString(szMsg)
local txt = h:Lookup(h.nUseCount)
txt.__SetText = txt.SetText
txt.SetText = _HM_CombatText.SetText
end
end
end
-- unhook
_HM_CombatText.UnHook = function(nLevel)
local handle = Station.Lookup("Lowest/CombatText", "Handle_Level" .. nLevel)
if handle and handle.bHookByHM then
handle.bHookByHM = nil
handle.AppendItemFromString = handle.__AppendItemFromString
handle.AppendItemFromString = nil
for i = 0, handle:GetItemCount() - 1, 1 do
local txt = handle:Lookup(i)
txt.SetText = txt.__SetText
txt.__SetText = nil
end
end
end
-- breathe
_HM_CombatText.OnBreathe = function()
_HM_CombatText.Hook(0)
_HM_CombatText.Hook(1)
if #_HM_CombatText.tList == 0 then
return
end
for _, v in ipairs(_HM_CombatText.tList) do
if not v.bFree and v.arg0 ~= 0 and v.arg1 == v.dwCharacterID and v:IsValid() then
local tar = GetPlayer(v.arg0)
if tar then
v:__SetText(string.gsub(tar.szName, "@.*$", "") .. _L["-"] .. v:GetText())
end
end
end
_HM_CombatText.tList = {}
end
---------------------------------------------------------------------
-- 对外函数
---------------------------------------------------------------------
HM_CombatText.Switch = function(bEnable)
if bEnable == nil then
bEnable = not HM_CombatText.bShowName
end
HM_CombatText.bShowName = bEnable
_HM_CombatText.UnHook(0)
_HM_CombatText.UnHook(1)
if bEnable then
HM.BreatheCall("HM_CombatText", _HM_CombatText.OnBreathe)
else
HM.BreatheCall("HM_CombatText", nil)
end
end