-
Notifications
You must be signed in to change notification settings - Fork 3
/
EventHandler.lua
302 lines (247 loc) · 12.5 KB
/
EventHandler.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
--ActionPacket.open_listener(action_handler)
function action_handler(action)
local actionpacket = ActionPacket.new(action)
local category = actionpacket:get_category_string()
local player = windower.ffxi.get_player()
local spell = actionpacket:get_spell()
if not spell then return end
local debug = false
if debug then
log(category)
log('Actor ID: ' .. actionpacket:get_id())
log('Spell ID: ' .. spell.id .. ' Spell name: ' .. spell.english .. ' Spell type: ' .. (spell.type or 'no type'))
end
-- Rune Fencer's Swipe and Lunge abilities do not have duration but can consume runes. Other similar
-- abilities should go above the duration check as well
if spell.english == 'Lunge' or spell.english == 'Swipe' then
effusion(player, spell)
end
if not spell.duration then return end
local type = spell.type
if category == 'spell_finish' then
local actor_id = actionpacket:get_id()
local skill_name = res.skills[spell.skill].en
local time_cast = socket.gettime()
if skill_name == "Enhancing Magic" then
if actor_id == player.id then
local equipment = windower.ffxi.get_items('equipment')
for target in actionpacket:get_targets() do
local action = target:get_actions()()
local message_id = action:get_message_id()
if no_effect_message_ids:contains(message_id) then
else
local buff = res.buffs[spell.status]
local tracked_buff = TrackedBuff.new(buff, spell, player, target, equipment, time_cast)
tracked_buff:calculate_buff_duration()
if not tracked_mobs[target.id] then
tracked_mobs[target.id] = TrackedMob.new(target)
end
tracked_mobs[target.id]:add_buff(tracked_buff)
tracked_buff:print_log(true)
end
end
else
end
elseif skill_name == "Singing" or skill_name == "Blue Magic" then -- Both are handled exactly the same
if actor_id == player.id then
local equipment = windower.ffxi.get_items('equipment')
for target in actionpacket:get_targets() do
local action = target:get_actions()()
local message_id = action:get_message_id()
if no_effect_message_ids:contains(message_id) then
-- do nothing
else
local buff = res.buffs[action.param]
local tracked_buff = TrackedBuff.new(buff, spell, player, target, equipment, time_cast)
tracked_buff:calculate_buff_duration()
if not tracked_mobs[target.id] then
tracked_mobs[target.id] = TrackedMob.new(target)
end
tracked_mobs[target.id]:add_buff(tracked_buff)
end
end
end
elseif skill_name == "Enfeebling Magic" then
if actor_id == player.id then
local equipment = windower.ffxi.get_items('equipment')
for target in actionpacket:get_targets() do
local action = target:get_actions()()
local message_id = action:get_message_id()
if immunity_message_ids:contains(message_id) then
local target_name = target:get_name()
if mob_data.immunities:contains(target_name) then
if not (mob_data.immunities[target_name]:contains(action.top_level_param)) then
mob_data.immunities[target_name]:append(action.top_level_param)
end
else
mob_data.immunities:append({[target_name] = L{action.top_level_param}})
end
-- TODO: Update mob_data file
elseif no_effect_message_ids:contains(message_id) then
-- TODO: possibly notify player debuff not applied
elseif resist_message_ids:contains(message_id) then
-- TODO: possibly notify player debuff resisted
-- TODO: possibly aggregate resist data?
else
if damage_message_ids:contains(message_id) then
-- TODO: Handle Dia, Bio, Etc.
local buff = res.buffs[spell.status]
local tracked_buff = TrackedBuff.new(buff, spell, player, target, equipment, time_cast)
tracked_buff:calculate_buff_duration()
if not tracked_mobs[target.id] then
tracked_mobs[target.id] = TrackedMob.new(target)
end
if tracked_mobs[target.id]:has_buffs() and tracked_buff.spell.overwrites then
-- TODO: Loop to identify buffs
for _, spell_id in ipairs(tracked_buff.spell.overwrites) do
local status_to_overwrite = (res.spells[spell_id]).status
local removed_buff
for buff_id, current_buff in pairs(tracked_mobs[target.id].buffs) do
if buff_id == status_to_overwrite and spell_id == current_buff:get_spell_id() then
removed_buff = tracked_mobs[target.id]:remove_buff(buff_id)
tracked_mobs[target.id]:add_buff(tracked_buff)
end
end
if removed_buff then
return removed_buff
else
tracked_mobs[target.id]:add_buff(tracked_buff)
end
end
else
tracked_mobs[target.id]:add_buff(tracked_buff)
end
else
local buff = res.buffs[spell.status]
local tracked_buff = TrackedBuff.new(buff, spell, player, target, equipment, time_cast)
tracked_buff:calculate_buff_duration()
if not tracked_mobs[target.id] then
tracked_mobs[target.id] = TrackedMob.new(target)
end
tracked_mobs[target.id]:add_buff(tracked_buff)
--tracked_buff:print_log(true)
--flog(logfilename, table.tovstring(tracked_buff))
--flog(logfilename, table.tovstring(get_equipment_info(tracked_buff.equipment)))
end
end
end
else
end
end
-- Pet Actions
elseif category == 'avatar_tp_finish' and actionpacket:get_id() == windower.ffxi.get_mob_by_target('pet')['id'] then
local buff = res.buffs[spell.status]
local equipment = windower.ffxi.get_items("equipment")
local time_cast = socket.gettime()
for target in actionpacket:get_targets() do
local action = target:get_actions()()
local message_id = action:get_message_id()
if no_effect_message_ids:contains(message_id) then
-- Do nothing
else
local tracked_buff = TrackedBuff.new(buff, spell, player, target, equipment, time_cast)
if not tracked_mobs[target.id] then
tracked_mobs[target.id] = TrackedMob.new(target)
end
tracked_buff:calculate_buff_duration()
tracked_mobs[target.id]:add_buff(tracked_buff)
end
end
elseif type == 'JobAbility' or type == 'CorsairRoll'
or type == 'Jig' or type == 'Samba' or type == 'Step'
or category == 'job_ability_run' or type == 'Rune' then
local actor_id = actionpacket:get_id()
if actor_id == player.id then
local equipment = windower.ffxi.get_items('equipment')
local time_cast = socket.gettime()
local buff = res.buffs[spell.status]
for target in actionpacket:get_targets() do
local action = target:get_actions()()
local message_id = action:get_message_id()
if no_effect_message_ids:contains(message_id) then
-- Do nothing
else
local tracked_buff = TrackedBuff.new(buff, spell, player, target, equipment, time_cast)
if not tracked_mobs[target.id] then
tracked_mobs[target.id] = TrackedMob.new(target)
end
if spell.type == "Rune" then
tracked_buff.calculated_duration = spell.duration
tracked_mobs[target.id]:add_rune_buff(player, tracked_buff)
else
tracked_buff:calculate_buff_duration()
tracked_mobs[target.id]:add_buff(tracked_buff)
end
end
end
end
elseif category == "job_ability" then
local actor_id = actionpacket:get_id()
if actor_id == player.id then
local equipment = windower.ffxi.get_items("equipment")
local time_cast = socket.gettime()
local buff = res.buffs[spell.status]
for target in actionpacket:get_targets() do
local action = target:get_actions()()
local message_id = action:get_message_id()
end
end
end
end
windower.register_event('incoming chunk', function(id, data)
if id == 0x029 then
local action_message = {}
action_message.id = data:unpack('H', 0x19) % 32768
action_message.target_id = data:unpack('I', 0x09)
action_message.param = data:unpack('I', 0x0D)
if mob_death_message_ids:contains(action_message.id) then
-- TODO: Process tracked mob disposal
elseif wears_off_message_ids:contains(action_message.id) then
-- TODO: Process expired debuff
if tracked_mobs[action_message.target_id] then
tracked_mobs[action_message.target_id]:remove_buff(action_message.param)
end
end
end
end)
windower.register_event('target change', function(id)
local target = windower.ffxi.get_mob_by_index(id)
if target then
maintargetbox:clear()
local display_info = target.name .. "\n" .. "---------------\n"
if tracked_mobs[target.id] then
local mob = tracked_mobs[target.id]
if mob:has_buffs() then
for _, buff in pairs(mob.buffs) do
display_info = display_info .. ("\n%-12s : %10s"):format(buff:get_spell_name(), buff:get_remaining_duration_as_timer())
end
end
end
maintargetbox:text(display_info)
maintargetbox:show()
else
maintargetbox:hide()
end
end)
windower.register_event('prerender', function(id)
local target = windower.ffxi.get_mob_by_target("t")
if target then
maintargetbox:clear()
local display_info = target.name .. "\n" .. "---------------\n"
if tracked_mobs[target.id] then
local mob = tracked_mobs[target.id]
if mob:has_buffs() then
for _, buff in pairs(mob.buffs) do
display_info = display_info .. ("\n%-12s : %10s"):format(buff:get_spell_name(), buff:get_remaining_duration_as_timer())
if buff:get_unconfirmed() then
display_info = display_info .. ' (U)'
end
end
end
end
maintargetbox:text(display_info)
maintargetbox:show()
else
maintargetbox:hide()
end
end)