-
Notifications
You must be signed in to change notification settings - Fork 0
/
common_functions.lua
402 lines (353 loc) · 16.1 KB
/
common_functions.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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
-------------------------------------------------------------------------------------------------------------------
-- Common Shared Functions
-------------------------------------------------------------------------------------------------------------------
-- Common Shared Functions - Domain Invasion
-------------------------------------------------------------------------------------------------------------------
domain_job = {
["WAR"] = "heavy", ["PLD"] = "heavy", ["DRK"] = "heavy", ["BST"] = "heavy", ["SAM"] = "heavy", ["DRG"] = "heavy",
["MNK"] = "light", ["THF"] = "light", ["RNG"] = "light", ["NIN"] = "light", ["BLU"] = "light", ["COR"] = "light", ["DNC"] = "light", ["RUN"] = "light",
["WHM"] = "mage", ["BLM"] = "mage", ["RDM"] = "mage", ["BRD"] = "mage", ["SMN"] = "mage", ["PUP"] = "mage", ["SCH"] = "mage", ["GEO"] = "mage",
}
domain_set = {}
domain_set["heavy"] = {
head = "Hervor Galea",
body = "Hervor Haubert",
hands = "Hervor Mouffles",
legs = "Hervor Brayettes",
feet = "Hervor Sollerets",
}
domain_set["light"] = {
head = "Heidrek Mask",
body = "Heidrek Harness",
hands = "Heidrek Gloves",
legs = "Heidrek Brais",
feet = "Heidrek Boots",
}
domain_set["mage"] = {
head = "Angantyr Beret",
body = "Angantyr Robe",
hands = "Angantyr Mittens",
legs = "Angantyr Tights",
feet = "Angantyr Boots",
}
-- Gets the armour set for the job type passed as a parameter
-- Expects the Char(3) string for the job
-- Use example: sets.engeged.Domain = get_domain_set(player.main_job)
function get_domain_set(main_job)
local job_type = domain_job[main_job]
return domain_set[job_type]
end
-------------------------------------------------------------------------------------------------------------------
-- Common Shared Functions - Locking Common Items
-------------------------------------------------------------------------------------------------------------------
-- Equipment Related
local all_gear_slots = {
"main", "sub", "range", "ammo",
"head", "neck", "left_ear", "right_ear",
"body", "hands", "left_ring", "right_ring",
"back", "waist", "legs", "feet",
}
-- Locks all equipment slots
function equipment_lock_all()
equipment_lock_specific(all_gear_slots)
end
-- Locks specific equipment slots
-- Accepts an array of strings equivalent to equipment slots
function equipment_lock_specific(gear_array)
for iterator, slot in ipairs(gear_array) do
disable(slot)
end
end
-- Unlocks all equipment slots
function equipment_unlock_all()
equipment_unlock_specific(all_gear_slots)
end
-- Unlocks specific equipment slots
-- Accepts an array of strings equivalent to equipment slots
function equipment_unlock_specific(gear_array)
for iterator, slot in ipairs(gear_array) do
enable(slot)
end
end
-- Checks to see if a special ring is equipped in either ring slot.
-- Locks the slot while the ring is in there until it is changed.
-- Definition in: common_lists.lua
function check_special_ring_equipped()
if equip_lock_rings:contains(player.equipment.left_ring) then
is_ring_locked = true
equipment_lock_specific({"left_ring",})
elseif equip_lock_rings:contains(player.equipment.right_ring) then
is_ring_locked = true
equipment_lock_specific({"right_ring",})
elseif is_ring_locked then
is_ring_locked = false
equipment_unlock_specific({"left_ring", "right_ring",})
end
end
-- Check if player has CP Mode enabled
-- Locks back piece for extra capacity points
function check_status_cp(statusOn, set_to_equip)
if statusOn then
equip(set_to_equip)
equipment_lock_specific({"back",})
else
equipment_unlock_specific({"back",})
end
end
-- Check if player has Dynamis Mode enabled
-- Locks neck piece for kills to count
function check_status_dynamis(statusOn, set_to_equip)
if statusOn then
equip(set_to_equip)
equipment_lock_specific({"neck",})
else
equipment_unlock_specific({"neck",})
end
end
function check_ammo_pouch_equipped()
if equip_lock_ammo_pouches:contains(player.equipment.waist) then
equipment_lock_specific({'waist',})
is_waist_locked = true
elseif is_waist_locked then
equipment_unlock_specific({'waist',})
end
end
-------------------------------------------------------------------------------------------------------------------
-- Common Shared Functions - Ailment Removal
-------------------------------------------------------------------------------------------------------------------
-- Checks if the player is silenced and trying to cast a spell
-- Remove silence using Catholicon, Echo Drops, then Remedy in that order
function check_debuff_silenced(spell, eventArgs)
-- add_to_chat(060, spell.type .. ' | ' .. spell.action_type)
if spell.action_type == 'Magic' and buffactive['Silence'] then
-- If silenced, use what's available to remove it
cancel_spell()
if player.inventory['Catholicon'] ~= nil then
send_command('input /item "Catholicon" <me>')
send_command('input /echo *!! Silenced ~ Using Catholicon @ '..player.inventory['Catholicon'].count..' Left !!*')
elseif player.inventory['Echo Drops'] ~= nil then
send_command('input /item "Echo Drops" <me>')
send_command('input /echo *!! Silenced ~ Using Echo Drops @ '..player.inventory['Echo Drops'].count..' Left !!*')
elseif player.inventory['Remedy'] ~= nil then
send_command('input /item "Remedy" <me>')
send_command('input /echo *!! Silenced ~ Using Remedy @ '..player.inventory['Remedy'].count..' Left !!*')
else
send_command('input /echo *!! Silenced ~ No items to remove it !!*')
end
eventArgs.cancel = true
return
end
end
-------------------------------------------------------------------------------------------------------------------
-- Common Shared Functions - Ailment vs Job Ability Activation
-------------------------------------------------------------------------------------------------------------------
-- Checks if the ability being used is Sublimation and if the player is weakened
-- Cancels the action if both conditions are met
function check_weakened_sublimation(spell, eventArgs)
if spell.name == "Sublimation" and (buffactive['Weakness'] or player.hpp < 55) then
-- If weakend, don't waste your Sublimation
cancel_spell()
send_command('input /echo *!! Weakend ~ Cancelling Sublimation !!*')
eventArgs.cancel = true
return
end
end
-------------------------------------------------------------------------------------------------------------------
-- Common Shared Functions - Raise & Reraise
-- Can beused for custom shortcuts
-------------------------------------------------------------------------------------------------------------------
function cast_highest_available_raise()
local spell_recasts = windower.ffxi.get_spell_recasts()
local map_ids_raise = {
['Raise'] = 12,
['Raise II'] = 13,
['Raise III'] = 140,
['Arise'] = 494
}
if spell_recasts[map_ids_raise['Arise']] == 0 and player.main_job == 'WHM' then
send_command('@input /ma "Arise" <t>')
elseif spell_recasts[map_ids_raise['Raise III']] == 0 then
send_command('@input /ma "Raise III" <t>')
elseif spell_recasts[map_ids_raise['Raise II']] == 0 then
send_command('@input /ma "Raise II" <t>')
elseif spell_recasts[map_ids_raise['Raise']] == 0 then
send_command('@input /ma "Raise" <t>')
else
add_to_chat(100, 'No Raise spells currently available.')
end
end
function cast_highest_available_reraise()
local spell_recasts = windower.ffxi.get_spell_recasts()
local map_ids_reraise = {
['Reraise'] = 135,
['Reraise II'] = 141,
['Reraise III'] = 142,
['Reraise IV'] = 848
}
if spell_recasts[map_ids_reraise['Reraise IV']] == 0 and player.main_job == 'WHM' then
send_command('@input /ma "Reraise IV" <me>')
elseif spell_recasts[map_ids_reraise['Reraise III']] == 0 then
send_command('@input /ma "Reraise III" <me>')
elseif spell_recasts[map_ids_reraise['Reraise II']] == 0 then
send_command('@input /ma "Reraise II" <me>')
elseif spell_recasts[map_ids_reraise['Reraise']] == 0 then
send_command('@input /ma "Reraise" <me>')
else
add_to_chat(100, 'No Reraise spells currently available.')
end
end
-------------------------------------------------------------------------------------------------------------------
-- Common Shared Functions - Utsusemi Recast
-------------------------------------------------------------------------------------------------------------------
function check_utsusemi_images()
if spellMap == 'Utsusemi' then
if buffactive['Copy Image (3)'] or buffactive['Copy Image (4+)'] then
cancel_spell()
add_to_chat(123, '**!! '..spell.english..' Canceled: [3+ IMAGES] !!**')
eventArgs.handled = true
return
elseif buffactive['Copy Image'] or buffactive['Copy Image (2)'] then
send_command('cancel 66; cancel 444; cancel Copy Image; cancel Copy Image (2)')
end
end
end
-------------------------------------------------------------------------------------------------------------------
-- Common Shared Functions - Setting Haste Groups
-------------------------------------------------------------------------------------------------------------------
function determine_haste_group()
-- Gearswap can't detect the difference between Haste I and Haste II
-- so use winkey-H to manually set Haste spell level.
-- Haste (buffactive[33]) - 15%
-- Haste II (buffactive[33]) - 30%
-- Haste Samba - 5%/10%
-- Victory March +0/+3/+4/+5 9.4%/14%/15.6%/17.1%
-- Advancing March +0/+3/+4/+5 6.3%/10.9%/12.5%/14%
-- Embrava - 30%
-- Mighty Guard (buffactive[604]) - 15%
-- Geo-Haste (buffactive[580]) - 40%
classes.CustomMeleeGroups:clear()
if state.HasteMode.value == 'Haste II' then
if(((buffactive[33] or buffactive[580] or buffactive.embrava) and (buffactive.march or buffactive[604])) or
(buffactive[33] and (buffactive[580] or buffactive.embrava)) or
(buffactive.march == 2 and buffactive[604])) then
--add_to_chat(215, '---------- <<<< | Magic Haste Level: 43% | >>>> ----------')
classes.CustomMeleeGroups:append('MaxHaste')
elseif ((buffactive[33] or buffactive.march == 2 or buffactive[580]) and buffactive['haste samba']) then
--add_to_chat(004, '---------- <<<< | Magic Haste Level: 35% | >>>> ----------')
classes.CustomMeleeGroups:append('HighHaste')
elseif ((buffactive[580] or buffactive[33] or buffactive.march == 2) or
(buffactive.march == 1 and buffactive[604])) then
--add_to_chat(008, '---------- <<<< | Magic Haste Level: 30% | >>>> ----------')
classes.CustomMeleeGroups:append('MidHaste')
elseif (buffactive.march == 1 or buffactive[604]) then
--add_to_chat(007, '---------- <<<< | Magic Haste Level: 15% | >>>> ----------')
classes.CustomMeleeGroups:append('LowHaste')
end
else
if (buffactive[580] and ( buffactive.march or buffactive[33] or buffactive.embrava or buffactive[604]) ) or
(buffactive.embrava and (buffactive.march or buffactive[33] or buffactive[604])) or
(buffactive.march == 2 and (buffactive[33] or buffactive[604])) or
(buffactive[33] and buffactive[604] and buffactive.march ) then
--add_to_chat(215, '---------- <<<< | Magic Haste Level: 43% | >>>> ----------')
classes.CustomMeleeGroups:append('MaxHaste')
elseif ((buffactive[604] or buffactive[33]) and buffactive['haste samba'] and buffactive.march == 1) or
(buffactive.march == 2 and buffactive['haste samba']) or
(buffactive[580] and buffactive['haste samba'] ) then
--add_to_chat(004, '---------- <<<< | Magic Haste Level: 35% | >>>> ----------')
classes.CustomMeleeGroups:append('HighHaste')
elseif (buffactive.march == 2 ) or
((buffactive[33] or buffactive[604]) and buffactive.march == 1 ) or -- MG or haste + 1 march
(buffactive[580] ) or -- geo haste
(buffactive[33] and buffactive[604]) then
--add_to_chat(008, '---------- <<<< | Magic Haste Level: 30% | >>>> ----------')
classes.CustomMeleeGroups:append('MidHaste')
elseif buffactive[33] or buffactive[604] or buffactive.march == 1 then
--add_to_chat(007, '---------- <<<< | Magic Haste Level: 15% | >>>> ----------')
classes.CustomMeleeGroups:append('LowHaste')
end
end
end
-------------------------------------------------------------------------------------------------------------------
-- Common Shared Functions - Refine Waltz
-------------------------------------------------------------------------------------------------------------------
function refine_waltz(spell, action)
local accepted_waltz = S{'Curing Waltz', 'Curing Waltz II', 'Curing Waltz III'}
if not accepted_waltz:contains(spell.name) then
return
end
local newWaltz = spell.english
local waltzID
local missingHP
if spell.target.type == "SELF" then
missingHP = player.max_hp - player.hp
elseif spell.target.isallymember then
local target = find_player_in_alliance(spell.target.name)
local est_max_hp = target.hp / (target.hpp/100)
missingHP = math.floor(est_max_hp - target.hp)
end
if missingHP ~= nil then
if missingHP < 40 and spell.target.name == player.name then
add_to_chat(123,'Full HP!')
cancel_spell()
return
elseif missingHP < 150 then
newWaltz = 'Curing Waltz'
waltzID = 190
elseif missingHP < 300 then
newWaltz = 'Curing Waltz II'
waltzID = 191
else
newWaltz = 'Curing Waltz III'
waltzID = 192
end
end
local waltzTPCost = {['Curing Waltz'] = 20, ['Curing Waltz II'] = 35, ['Curing Waltz III'] = 50, ['Curing Waltz IV'] = 65, ['Curing Waltz V'] = 80}
local tpCost = waltzTPCost[newWaltz]
local downgrade
if player.tp < tpCost and not buffactive.trance then
if player.tp < 20 then
add_to_chat(123, 'Insufficient TP ['..tostring(player.tp)..']. Cancelling.')
cancel_spell()
return
elseif player.tp < 35 then
newWaltz = 'Curing Waltz'
elseif player.tp < 50 then
newWaltz = 'Curing Waltz II'
elseif player.tp < 65 then
newWaltz = 'Curing Waltz III'
elseif player.tp < 80 then
newWaltz = 'Curing Waltz IV'
end
downgrade = 'Insufficient TP ['..tostring(player.tp)..']. Downgrading to '..newWaltz..'.'
end
if newWaltz ~= spell.english then
send_command('@input /ja "'..newWaltz..'" '..tostring(spell.target.raw))
if downgrade then
add_to_chat(158, downgrade)
end
cancel_spell()
return
end
if missingHP > 0 then
add_to_chat(158,'Trying to cure '..tostring(missingHP)..' HP using '..newWaltz..'.')
end
end
function find_player_in_alliance(name)
for i,v in ipairs(alliance) do
for k,p in ipairs(v) do
if p.name == name then
return p
end
end
end
end
-------------------------------------------------------------------------------------------------------------------
-- Common Shared Functions - Checking if the element of the spell matches the element of
-- the day or weather (includes SCH storms)
-------------------------------------------------------------------------------------------------------------------
function check_spell_weather_day_match(spell)
return spell.element == world.weather_element or spell.element == world.day_element
end
function check_spell_weather_match(spell)
return spell.element == world.weather_element
end