forked from tdymel/OneButtonHunter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOneButtonHunter.lua
More file actions
433 lines (384 loc) · 13 KB
/
OneButtonHunter.lua
File metadata and controls
433 lines (384 loc) · 13 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
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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
local GT = GetTime
OBH = {}
OBH.t = CreateFrame("GameTooltip", "OBH_T", UIParent, "GameTooltipTemplate")
OBH.f = CreateFrame("Frame", "OBH_Events", UIParent)
OBH.f:RegisterEvent("START_AUTOREPEAT_SPELL")
OBH.f:RegisterEvent("STOP_AUTOREPEAT_SPELL")
OBH.auto = false
OBH.next = nil
OBH.debug = false -- toggle with /run OBH.debug = true or false
OBH.f:SetScript("OnEvent", function(self, event)
if OBH.auto then
OBH.auto = false
OBH.next = nil
else
OBH.next = GT() + UnitRangedDamage("player")
OBH.auto = true
end
end)
OBH.f:SetScript("OnUpdate", function(self, elapsed)
if OBH.auto then
local time = GT()
if OBH.next < time then
OBH.next = time + UnitRangedDamage("player")
end
end
end)
-- Localization
if GetLocale() == "deDE" then
OBH.name = {
[1] = "Schnellfeuer",
[2] = "Schnelle Schüsse",
[3] = "Gezielter Schuss",
[4] = "Mehrfachschuss",
[5] = "Automatischer Schuss",
[6] = "Anlegen: Erhöht das Distanzangriffstempo um (%d+)%%%."
}
else
OBH.name = {
[1] = "Rapid Fire",
[2] = "Quick Shots",
[3] = "Aimed Shot",
[4] = "Multi-Shot",
[5] = "Auto Shot",
[6] = "Equip: Increases ranged attack speed by (%d+)%%%."
}
end
-- Quiver speed bonus
OBH.Quiver = nil
function OBH:GetQuiverSpeed()
OBH_T:SetOwner(UIParent, "ANCHOR_NONE")
OBH_T:ClearLines()
OBH_T:SetInventoryItem("player", 23)
local msg = OBH_TTextLeft4:GetText()
if msg then
for a in string.gfind(msg, self.name[6]) do
self.Quiver = 1 + tonumber(a) / 100
end
end
OBH_T:Hide()
end
-- Snapshot talent rank
function OBH:GetSnapshotRank()
for tab = 1, GetNumTalentTabs() do
for i = 1, GetNumTalents(tab) do
local name, _, _, _, rank = GetTalentInfo(tab, i)
if name == "Snapshot" then
return rank or 0
end
end
end
return 0
end
-- Active buff check
function OBH:Active(a)
for i = 0, 32 do
OBH_T:SetOwner(UIParent, "ANCHOR_NONE")
OBH_T:ClearLines()
OBH_T:SetPlayerBuff(GetPlayerBuff(i, "HELPFUL"))
local buff = OBH_TTextLeft1:GetText()
OBH_T:Hide()
if not buff then break end
if string.find(buff, a) then
return true
end
end
return false
end
-- Find action slot (macro or spell)
function OBH:GetActionSlot(a)
for i = 1, 100 do
local macroName = GetActionText(i)
if macroName and (macroName == a or string.find(macroName, a) or string.find(a, macroName)) then
if self.debug then
DEFAULT_CHAT_FRAME:AddMessage("OBH: Found '"..a.."' on macro slot "..i)
end
return i
end
OBH_T:SetOwner(UIParent, "ANCHOR_NONE")
OBH_T:ClearLines()
OBH_T:SetAction(i)
local ab = OBH_TTextLeft1 and OBH_TTextLeft1:GetText()
OBH_T:Hide()
if ab and (ab == a or string.find(ab, a) or string.find(a, ab)) then
if self.debug then
DEFAULT_CHAT_FRAME:AddMessage("OBH: Found '"..a.."' on action slot "..i)
end
return i
end
end
if self.debug then
DEFAULT_CHAT_FRAME:AddMessage("OBH: WARNING - Could not find action for '"..a.."', defaulting to slot 2")
end
return 2
end
-- Core runtime variables
OBH.rf = 1
OBH.qs = 1
OBH.as = 3
OBH.autoSlot = nil
OBH.asSlot = nil
-- Main rotation logic
function OBH:Run()
if not self.autoSlot then self.autoSlot = self:GetActionSlot(self.name[5]) end
if not self.asSlot then self.asSlot = self:GetActionSlot(self.name[3]) end
if self.next then
-- Buff multipliers
self.rf = self:Active(self.name[1]) and 1.3 or 1
self.qs = self:Active(self.name[2]) and 1.3 or 1
-- Get Quiver (affects Auto Shot only)
if not self.Quiver then self:GetQuiverSpeed() end
-- Snapshot modifies Aimed Shot base cast time
local snapshotRank = self:GetSnapshotRank() or 0
local aimedBase = 3.0 - 0.2 * snapshotRank
self.as = aimedBase / ((self.rf or 1) * (self.qs or 1))
local time = GT()
local timeUntilAuto = (self.next or 0) - time
-- Debug output
if self.debug then
DEFAULT_CHAT_FRAME:AddMessage(string.format(
"OBH Debug -> AimedBase: %.2f | Snapshot: %d | RF: %.2f | QS: %.2f | Quiver: %.2f | AS: %.3f | NextAuto: %.2f",
aimedBase, snapshotRank, self.rf or 1, self.qs or 1, self.Quiver or 1, self.as or 0, timeUntilAuto
))
end
-- Decision: safe to cast Aimed Shot?
if timeUntilAuto > self.as and GetActionCooldown(self.asSlot) == 0 then
CastSpellByName(self.name[3]) -- Aimed Shot
if self.debug then
DEFAULT_CHAT_FRAME:AddMessage(string.format(
"OBH: Casting Aimed Shot (%.2fs before next Auto)", timeUntilAuto
))
end
return
else
if self.debug then
DEFAULT_CHAT_FRAME:AddMessage(string.format(
"OBH: Skipping Aimed Shot to avoid clipping (%.2fs left, need > %.2fs)",
timeUntilAuto, self.as
))
end
end
-- Try Multi-Shot if ready
local multiSlot = self:GetActionSlot(self.name[4])
if GetActionCooldown(multiSlot) == 0 then
CastSpellByName(self.name[4])
if self.debug then
DEFAULT_CHAT_FRAME:AddMessage("OBH: Casting Multi-Shot")
end
end
else
-- Toggle Auto Shot on if inactive
if not IsCurrentAction(self.autoSlot) then
UseAction(self.autoSlot)
if self.debug then
DEFAULT_CHAT_FRAME:AddMessage("OBH: Starting Auto Shot")
end
end
end
end
---------------------------------------------------------
-- Find the REAL Auto Attack ability from the spellbook
---------------------------------------------------------
function OBH:FindAttack()
local numTabs = GetNumSpellTabs()
local index = 1
for t = 1, numTabs do
local tabName, _, offset, numSpells = GetSpellTabInfo(t)
for i = 1, numSpells do
local id = offset + i
local name = GetSpellName(id, BOOKTYPE_SPELL)
if name == "Attack" then
if self.debug then
DEFAULT_CHAT_FRAME:AddMessage("OBH Melee: Found true Attack spell at index "..id)
end
return id
end
end
end
if self.debug then
DEFAULT_CHAT_FRAME:AddMessage("OBH Melee: Could NOT find 'Attack' in spellbook!")
end
return nil
end
-------------------------------------------------------
-- MELEE ROTATION: Savage Blow → Mongoose Bite → RS
-- Stand-alone. Does NOT affect ranged Run().
-------------------------------------------------------
function OBH:Run2()
---------------------------------------------------
-- UNIVERSAL TOOLTIP SCANNER (V+ compatible)
---------------------------------------------------
local function FindSpellOnBars(spell)
local needle = string.lower(spell)
for i = 1, 120 do
OBH_T:SetOwner(UIParent, "ANCHOR_NONE")
OBH_T:ClearLines()
OBH_T:SetAction(i)
for line = 1, 8 do
local fs = getglobal("OBH_TTextLeft"..line)
if fs then
local text = fs:GetText()
if text and string.find(string.lower(text), needle) then
if OBH.debug then
DEFAULT_CHAT_FRAME:AddMessage("OBH: Found "..spell.." on slot "..i)
end
OBH_T:Hide()
return i
end
end
end
OBH_T:Hide()
end
if OBH.debug then
DEFAULT_CHAT_FRAME:AddMessage("OBH: Could NOT find "..spell)
end
return nil
end
---------------------------------------------------
-- REAL AUTO ATTACK FROM SPELLBOOK
---------------------------------------------------
if not self.attackSpellIndex then
-- Find "Attack" in the spellbook (General tab)
local numTabs = GetNumSpellTabs()
for t = 1, numTabs do
local tabName, _, offset, numSpells = GetSpellTabInfo(t)
for i = 1, numSpells do
local id = offset + i
local name = GetSpellName(id, BOOKTYPE_SPELL)
if name == "Attack" then
self.attackSpellIndex = id
if self.debug then
DEFAULT_CHAT_FRAME:AddMessage("OBH Melee: Found true Attack at spellbook index "..id)
end
break
end
end
end
end
---------------------------------------------------
-- SAFE AUTO ATTACK (only enable if NOT active)
---------------------------------------------------
local function IsAutoAttacking()
-- Scan all bars for Attack action
for i = 1, 120 do
if IsAttackAction(i) then
return IsCurrentAction(i)
end
end
return false
end
if not IsAutoAttacking() then
if self.attackSpellIndex then
CastSpell(self.attackSpellIndex, BOOKTYPE_SPELL) -- enable only
if self.debug then DEFAULT_CHAT_FRAME:AddMessage("OBH Melee: Auto Attack ON") end
end
end
---------------------------------------------------
-- CACHE MELEE SPELL SLOTS
---------------------------------------------------
if not self.savageSlot then
self.savageSlot = FindSpellOnBars("Savage Blow")
end
if not self.mongooseSlot then
self.mongooseSlot = FindSpellOnBars("Mongoose Bite")
end
if not self.raptorSlot then
self.raptorSlot = FindSpellOnBars("Raptor Strike")
end
---------------------------------------------------
-- SWING TIMER READOUT (Aimed Shot style)
---------------------------------------------------
local now = GetTime()
local mh = UnitAttackSpeed("player") or 2.0
self.mhSpeed = mh
-- Initialize swing timer if missing
if not self.swingNext then
self.swingNext = now + mh
end
local nextSwing = self.swingNext - now
if nextSwing < 0 then nextSwing = 0 end
if self.debug then
DEFAULT_CHAT_FRAME:AddMessage(string.format(
"OBH [Melee] → MHSpeed: %.2f | NextSwing: %.2fs | RS Ready: %s",
mh,
nextSwing,
(GetActionCooldown(self.raptorSlot) == 0) and "yes" or "no"
))
-- Warn if attack speed too fast for reliable RS priming
if mh < 2.10 then
DEFAULT_CHAT_FRAME:AddMessage(string.format(
"OBH [Melee WARNING] → Weapon speed %.2f is very fast (<2.10). RS prime window may be tight.",
mh
))
end
end
---------------------------------------------------
-- PRIORITY SYSTEM
-- 1) Savage Blow
-- 2) Mongoose Bite (reactive)
-- 3) Raptor Strike (prime next hit)
---------------------------------------------------
-- 1) SAVAGE BLOW
if self.savageSlot and GetActionCooldown(self.savageSlot) == 0 then
CastSpellByName("Savage Blow")
if self.debug then
DEFAULT_CHAT_FRAME:AddMessage("OBH Melee: Casting Savage Blow")
end
return
end
-- 2) MONGOOSE BITE (available after dodge)
if self.mongooseSlot
and IsUsableAction(self.mongooseSlot)
and GetActionCooldown(self.mongooseSlot) == 0 then
CastSpellByName("Mongoose Bite")
if self.debug then
DEFAULT_CHAT_FRAME:AddMessage("OBH Melee: Casting Mongoose Bite")
end
return
end
-- 3) RAPTOR STRIKE (prime next swing)
if self.raptorSlot and GetActionCooldown(self.raptorSlot) == 0 then
CastSpellByName("Raptor Strike")
-- Prime next swing precisely
self.swingNext = now + mh
if self.debug then
DEFAULT_CHAT_FRAME:AddMessage("OBH Melee: Casting Raptor Strike (Primed Next Hit)")
end
return
end
end
-- Slash command handler for OBH debug control
SLASH_OBH1 = "/obh"
SlashCmdList["OBH"] = function(msg)
msg = string.lower(msg or "")
if msg == "on" or msg == "1" or msg == "true" then
OBH.debug = true
DEFAULT_CHAT_FRAME:AddMessage("|cff00ff00OBH Debugging Enabled|r")
elseif msg == "off" or msg == "0" or msg == "false" then
OBH.debug = false
DEFAULT_CHAT_FRAME:AddMessage("|cffff0000OBH Debugging Disabled|r")
elseif msg == "help" or msg == "" then
DEFAULT_CHAT_FRAME:AddMessage("|cffffff00OneButtonHunter Commands:|r")
DEFAULT_CHAT_FRAME:AddMessage("|cff00ff00/obh on|r - Enable debug output")
DEFAULT_CHAT_FRAME:AddMessage("|cff00ff00/obh off|r - Disable debug output")
DEFAULT_CHAT_FRAME:AddMessage("Debug Current state: "..(OBH.debug and "|cff00ff00ON|r" or "|cffff0000OFF|r"))
DEFAULT_CHAT_FRAME:AddMessage("|cff00ff00/run OBH:Run()|r - Ranged rotation macro")
DEFAULT_CHAT_FRAME:AddMessage("|cff00ff00/run OBH:Run2()|r - Melee rotation macro")
else
DEFAULT_CHAT_FRAME:AddMessage("|cffff0000Unknown command.|r Type |cff00ff00/obh help|r for options.")
end
end
SLASH_OBHDEBUG1 = "/obhdebug"
SlashCmdList["OBHDEBUG"] = function(msg)
msg = string.lower(msg or "")
if msg == "on" or msg == "1" or msg == "true" then
OBH.debug = true
DEFAULT_CHAT_FRAME:AddMessage("|cff00ff00OBH Debugging Enabled|r")
elseif msg == "off" or msg == "0" or msg == "false" then
OBH.debug = false
DEFAULT_CHAT_FRAME:AddMessage("|cffff0000OBH Debugging Disabled|r")
else
DEFAULT_CHAT_FRAME:AddMessage("|cffffff00Usage: /obhdebug on|off|r")
DEFAULT_CHAT_FRAME:AddMessage("Current state: "..(OBH.debug and "|cff00ff00ON|r" or "|cffff0000OFF|r"))
end
end