-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.lua
More file actions
319 lines (257 loc) · 8.07 KB
/
Copy pathutils.lua
File metadata and controls
319 lines (257 loc) · 8.07 KB
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
--[[
Utilities Module for AutoJob
Common utility functions
]]--
local utils = {}
local resources = require('resources')
local res = require('resources')
-------------------------------------------
-- Spell and Ability Lookup
-------------------------------------------
-- Find a spell by name
function utils.find_spell(spell_name)
if not spell_name then return nil end
local lower_name = spell_name:lower()
for id, spell in pairs(res.spells) do
if spell.en and spell.en:lower() == lower_name then
return {
id = id,
name = spell.en,
mp_cost = spell.mp_cost or 0,
cast_time = spell.cast_time or 0,
recast = spell.recast or 0,
skill = spell.skill,
type = spell.type
}
end
end
return nil
end
-- Find a job ability by name
function utils.find_ability(ability_name)
if not ability_name then return nil end
local lower_name = ability_name:lower()
for id, ability in pairs(res.job_abilities) do
if ability.en and ability.en:lower() == lower_name then
return {
id = id,
name = ability.en,
recast = ability.recast or 0,
mp_cost = ability.mp_cost or 0,
tp_cost = ability.tp_cost or 0
}
end
end
return nil
end
-- Find a weapon skill by name
function utils.find_weapon_skill(ws_name)
if not ws_name then return nil end
local lower_name = ws_name:lower()
for id, ws in pairs(res.weapon_skills) do
if ws.en and ws.en:lower() == lower_name then
return {
id = id,
name = ws.en,
skill = ws.skill
}
end
end
return nil
end
-- Find a monster ability by name
function utils.find_monster_ability(ability_name)
if not ability_name then return nil end
local lower_name = ability_name:lower()
for id, ability in pairs(res.monster_abilities) do
if ability.en and ability.en:lower() == lower_name then
return {
id = id,
name = ability.en
}
end
end
return nil
end
-------------------------------------------
-- Player State Utilities
-------------------------------------------
-- Get player's current buffs
function utils.get_buffs()
local player = windower.ffxi.get_player()
if not player or not player.buffs then
return {}
end
local buff_names = {}
for _, buff_id in ipairs(player.buffs) do
if buff_id and buff_id ~= 255 and buff_id ~= 0 then
local buff = res.buffs[buff_id]
if buff then
table.insert(buff_names, buff.en)
end
end
end
return buff_names
end
-- Check if player has a specific buff
function utils.has_buff(buff_name)
local buffs = utils.get_buffs()
local lower_name = buff_name:lower()
for _, name in ipairs(buffs) do
if name:lower() == lower_name then
return true
end
end
return false
end
-- Check if player has any of the specified buffs
function utils.has_any_buff(buff_names)
local buffs = utils.get_buffs()
for _, check_name in ipairs(buff_names) do
local lower_check = check_name:lower()
for _, buff_name in ipairs(buffs) do
if buff_name:lower() == lower_check then
return true
end
end
end
return false
end
-------------------------------------------
-- Target Utilities
-------------------------------------------
-- Get current target info
function utils.get_target()
local target = windower.ffxi.get_mob_by_target('t')
if not target then return nil end
return {
id = target.id,
index = target.index,
name = target.name,
hpp = target.hpp,
distance = target.distance,
is_npc = target.is_npc,
claim_id = target.claim_id
}
end
-- Check if we're in melee range
function utils.in_melee_range(max_distance)
max_distance = max_distance or 6
local target = windower.ffxi.get_mob_by_target('t')
if not target then return false end
return target.distance and math.sqrt(target.distance) <= max_distance
end
-- Check if we're in spell range
function utils.in_spell_range(max_distance)
max_distance = max_distance or 21
local target = windower.ffxi.get_mob_by_target('t')
if not target then return false end
return target.distance and math.sqrt(target.distance) <= max_distance
end
-------------------------------------------
-- Job Utilities
-------------------------------------------
-- Get job abbreviation from ID
function utils.get_job_abbrev(job_id)
local jobs = {
[1] = 'WAR', [2] = 'MNK', [3] = 'WHM', [4] = 'BLM',
[5] = 'RDM', [6] = 'THF', [7] = 'PLD', [8] = 'DRK',
[9] = 'BST', [10] = 'BRD', [11] = 'RNG', [12] = 'SAM',
[13] = 'NIN', [14] = 'DRG', [15] = 'SMN', [16] = 'BLU',
[17] = 'COR', [18] = 'PUP', [19] = 'DNC', [20] = 'SCH',
[21] = 'GEO', [22] = 'RUN'
}
return jobs[job_id] or 'NON'
end
-- Get job ID from abbreviation
function utils.get_job_id(job_abbrev)
local jobs = {
WAR = 1, MNK = 2, WHM = 3, BLM = 4,
RDM = 5, THF = 6, PLD = 7, DRK = 8,
BST = 9, BRD = 10, RNG = 11, SAM = 12,
NIN = 13, DRG = 14, SMN = 15, BLU = 16,
COR = 17, PUP = 18, DNC = 19, SCH = 20,
GEO = 21, RUN = 22
}
return jobs[job_abbrev:upper()] or 0
end
-- Check if player can use a spell based on job/level
function utils.can_use_spell(spell_name)
local spell = utils.find_spell(spell_name)
if not spell then return false end
local player = windower.ffxi.get_player()
if not player then return false end
-- Check if player has the spell in their list
local spells = windower.ffxi.get_spells()
if spells and spells[spell.id] then
return true
end
return false
end
-- Check if player can use an ability
function utils.can_use_ability(ability_name)
local ability = utils.find_ability(ability_name)
if not ability then return false end
local player = windower.ffxi.get_player()
if not player then return false end
-- Check if player has the ability
local abilities = windower.ffxi.get_abilities()
if abilities and abilities.job_abilities then
for _, id in ipairs(abilities.job_abilities) do
if id == ability.id then
return true
end
end
end
return false
end
-------------------------------------------
-- String Utilities
-------------------------------------------
-- Parse quoted string from arguments
function utils.parse_quoted_arg(args, start_index)
if not args[start_index] then return nil, start_index end
local first = args[start_index]
-- Check if it starts with a quote
if first:sub(1, 1) == '"' then
-- Find the closing quote
local result = first:sub(2) -- Remove leading quote
if result:sub(-1) == '"' then
-- Single-word quoted string
return result:sub(1, -2), start_index + 1
end
-- Multi-word quoted string
local i = start_index + 1
while args[i] do
if args[i]:sub(-1) == '"' then
result = result .. ' ' .. args[i]:sub(1, -2)
return result, i + 1
else
result = result .. ' ' .. args[i]
end
i = i + 1
end
return result, i
else
-- Unquoted string
return first, start_index + 1
end
end
-------------------------------------------
-- Time Utilities
-------------------------------------------
-- Format seconds as mm:ss
function utils.format_time(seconds)
local mins = math.floor(seconds / 60)
local secs = math.floor(seconds % 60)
return string.format('%02d:%02d', mins, secs)
end
-- Get current game time
function utils.get_game_time()
local info = windower.ffxi.get_info()
if info then
return info.time or 0
end
return 0
end
return utils