forked from lenonk/Timers
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdebuffs.lua
222 lines (189 loc) · 7.76 KB
/
debuffs.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
--[[
* timers - Copyright (c) 2022 The Mystic
*
* This file is part of Timers for Ashita.
*
* Timers is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Timers is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Timers. If not, see <https://www.gnu.org/licenses/>.
--]]
require('timer_group')
require('action_packets')
require('timer_common')
local debuffs = {
debuffs = {},
};
local Overwrites = require('overwrites')
local EffectOverride = T{
-- Dia
[23] = T{status=134}, -- I
[24] = T{status=134}, -- II
[25] = T{status=134}, -- III
[26] = T{status=134}, -- IV
[27] = T{status=134}, -- V
-- Bio
[230] = T{status=135}, -- I
[231] = T{status=135}, -- II
[232] = T{status=135}, -- III
[233] = T{status=135}, -- IV
[234] = T{status=135}, -- V
-- Steps
[201] = T{status=386}, -- Quickstep
[202] = T{status=391}, -- Box Step
[203] = T{status=396}, -- Stutter Step
[312] = T{status=448}, -- Feather Step
}
local function GetEffectOverride(spell, default)
if EffectOverride:haskey(spell) then
return EffectOverride[spell].status
end
return default
end
local function CanApplyEffect(spell, target)
for id, effect in pairs(debuffs.debuffs[target].effects) do
-- Check if there is an existing debuff that this spell overwrites
if Overwrites:haskey(spell) and Overwrites[spell].overwrites:hasval(effect.spell) then
debuffs.debuffs[target].effects[id] = nil
return true
-- Check if there is an existing debuff that overwrites this spell
elseif Overwrites:haskey(effect.spell) and Overwrites[effect.spell].overwrites:hasval(spell) then
return false
end
end
return true
end
local function ApplyDebuff(target, effect, spell, actor, type, param)
if not debuffs.debuffs[target] then
debuffs.debuffs[target] = {}
debuffs.debuffs[target].effects = {}
end
local resMan = AshitaCore:GetResourceManager()
-- Create timer
local duration = nil
local name = nil
if T{ 201,202,203,312 }:hasval(spell) and type == 14 then
-- Steps
duration = gDuration.GetAbilityDuration(spell, target)
duration = (duration and duration * 60) or nil
local a = resMan:GetAbilityById(spell + 512)
name = (a and a.Name[1]) or 'Unknown'
name = ('%s [%d]'):fmt(name, param)
if debuffs.debuffs[target].effects[effect] and duration then
local e = debuffs.debuffs[target].effects[effect]
duration = math.min(120 * 60, e.duration + (30 * 60))
end
elseif type == 3 or type == 14 then
duration = gDuration.GetAbilityDuration(spell, target)
duration = (duration and duration * 60) or nil
local a = resMan:GetAbilityById(spell + 512)
name = (a and a.Name[1]) or 'Unknown'
elseif type == 4 then
duration = gDuration.GetSpellDuration(spell, target)
duration = (duration and duration * 60) or nil
local s = resMan:GetSpellById(spell)
name = (s and s.Name[1]) or 'Unknown'
else
local t = GetEntity(GetTargetIndex(actor))
local name = (t and t.Name) or nil
print(('Unknown action [%d] with type [%d] used by %s'):fmt(spell, type, name or 'Unknown'))
end
if not duration then return end
if CanApplyEffect(spell, target) then
debuffs.debuffs[target].effects[effect] = {name=name, spell=spell, o_time=ashita.time.clock()['ms'],
duration=duration, actor=actor,
t_index=GetTargetIndex(target)}
end
end
local function HandleAction(act)
if #act.targets == 0 then return end
if #act.targets[1].actions == 0 then return end
local message = act.targets[1].actions[1].message
if not ActionIsLocal(act.actor_id) then return end
-- Spells
-- 2,252 Are damaging spells
-- 236,237,268,271 Are Non-damaging spells
-- 127,519,520 Are abilities
-- 327 is BLU magic
if T{ 2,252,127,236,237,268,271,519,520 }:hasval(message) then
local spell = act.param
local target = act.targets[1].id
local actor = act.actor_id
local type = act['type']
local effect = GetEffectOverride(spell, act.targets[1].actions[1].param)
-- effect and param are usually the same, but sometimes they're not.
-- In those cases, param is usually not needed, but sometimes it is. /sigh SE...
local param = act.targets[1].actions[1].param
--print(('%d, %d, %d, %d'):fmt(spell, type, act.targets[1].actions[1].effect, effect))
if effect then
ApplyDebuff(target, effect, spell, actor, type, param)
end
end
end
local function HandleActionMessage(data)
local message = {}
message.target_id = struct.unpack('I', data, 0x09)
message.param_1 = struct.unpack('I', data, 0x0D)
message.message_id = struct.unpack('H', data, 0x19) % 32768
local db_target = debuffs.debuffs[message.target_id] or nil
-- Target died
if T{6, 20, 113, 406, 605, 646}:hasval(message.message_id) then
debuffs.debuffs[message.target_id] = nil
-- Debuff expired
elseif T{64, 204, 206, 350, 531}:hasval(message.message_id) then
if db_target and db_target.effects[message.param_1] then
db_target.effects[message.param_1].duration = -1
db_target.effects[message.param_1].o_time = ashita.time.clock()['ms']
end
end
end
local function HandlePacket(e)
if e.blocked then return end
if e.id == 0x028 then
HandleAction(ParseActionPacket(e.data_modified))
elseif e.id == 0x029 then
HandleActionMessage(e.data_modified)
elseif e.id == 0x000A then -- Zone Enter
debuffs.debuffs = {}
end
end
local function UpdateDebuffs(timers)
local bars = {}
for target, data in pairs(debuffs.debuffs) do
if data then
for id, effect in pairs(data.effects) do
local t_entity = GetEntity(effect.t_index)
local t_name = (t_entity and t_entity.Name) or 'Unknown'
local timer_name = ("%s (%s)"):fmt(effect.name, t_name)
local diff = ((ashita.time.clock()['ms'] - effect.o_time) / 1000.0) * 60.0
if effect.duration == -1 and diff > 120 then -- 2 seconds
-- Being an elseif, this causes us to lose one frame of display. I don't think it's an
-- issue though
debuffs.debuffs[target].effects[id].duration = -2
elseif effect.duration == -2 and diff > 720 then
-- Wait an additional 10 seconds before retiring the debuff from the display
debuffs.debuffs[target].effects[id] = nil
else
local e = AshitaCore:GetMemoryManager():GetEntity()
if bit.band(e:GetRenderFlags0(effect.t_index), 0x200) == 0x200 then
local remains = effect.duration - diff
table.insert(bars, { name=timer_name, duration=effect.duration,
remains=remains, key=target, icon_id=id })
end
end
end
end
end
timers:render(bars)
end
debuffs.Update = UpdateDebuffs
debuffs.HandlePacket = HandlePacket
return debuffs