forked from jp-ganis/JPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jpdata.lua
executable file
·387 lines (328 loc) · 9.81 KB
/
jpdata.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
--[[
JPS - WoW Protected Lua DPS AddOn
Copyright (C) 2011 Jp Ganis
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
]]--
-- JPS Helper Functions
--jpganis
-- Lookup Tables
-- Credit (and thanks!) to BenPhelps
jps.Dispells = {
["Magic"] = {
"Static Disruption", -- Akil'zon
"Consuming Darkness", -- Argaloth
"Emberstrike", -- Erunak Stonespeaker
"Binding Shadows", -- Erudax
"Divine Reckoning", -- Temple Guardian Anhuur
"Static Cling", -- Asaad, noobs shouldn't get hit by this, but get real....
"Pain and Suffering", -- Baron Ashbury
"Cursed Veil" -- Baron Silverlaine
-- "Wither", -- Ammunae
},
["Poison"] = {
"Viscous Poison", -- Lockmaw
},
["Disease"] = {
"Plague of Ages", -- High Prophet Barim
},
["Curse"] = {
"Curse of Blood", -- High Priestess Azil
"Cursed Bullets", -- Lord Godfrey
},
["Enrage"] = { -- hunters pretty much
"Enrage", -- Generic Enrage, used all over the place
}
}
-- Functions
function jps.Cast(spell)
if not jps.Target then jps.Target = "target" end
if not jps.Casting then jps.LastCast = spell end
CastSpellByName(spell,jps.Target)
jps.LastTarget = jps.Target
jps.Target = nil
if jps.IconSpell ~= spell then
jps.set_jps_icon( spell )
if jps.Debug then write(spell, jps.Target) end
end
end
function jps.canDispell( unit, ... )
for _, dtype in pairs(...) do
if jps.Dispells[dtype] ~= nil then
for _, spell in pairs(jps.Dispells[dtype]) do
if ud( unit, spell ) then return true end
end
end
end
return false
end
function jps.cooldown(spell)
local start,duration,_ = GetSpellCooldown(spell)
local cd = start+duration-GetTime()-jps.Lag
if cd < 0 then return 0 end
return cd
end
-- Shorthand
jps.cd = jps.cooldown
function jps.itemCooldown(item)
local start,duration,_ = GetItemCooldown(item)
local cd = start+duration-GetTime()-jps.Lag
if cd < 0 then return 0 end
return cd
end
function jps.glovesCooldown()
local start, duration, enabled = GetInventoryItemCooldown("player", 10)
if enabled==0 then return 9001 end
local cd = start+duration-GetTime()-jps.Lag
if cd < 0 then return 0 end
return cd
end
function jps.petCooldown(index)
local start,duration,_ = GetPetActionCooldown(index)
local cd = start+duration-GetTime()-jps.Lag
if cd < 0 then return 0 end
return cd
end
function jps.buff( spell, unit )
if unit == nil then unit = "player" end
if UnitBuff(unit, spell) then return true end
return false
end
function jps.debuff( spell, unit )
if unit == nil then unit = "target" end
if UnitDebuff(unit, spell) then return true end
return false
end
function jps.myDebuff( spell, unit )
if unit == nil then unit = "target" end
local _,_,_,_,_,_,expire,caster,_,_,_ = UnitDebuff(unit,spell)
if caster~="player" then return false end
return jps.debuff( spell, unit )
end
function jps.buffDuration( spell, unit )
if unit == nil then unit = "player" end
local _,_,_,_,_,_,expire,caster,_,_,_ = UnitBuff(unit,spell)
if caster ~= "player" then return 0 end
if expire == nil then return 0 end
duration = expire-GetTime()-jps.Lag
if duration < 0 then return 0 end
return duration
end
function jps.notmyBuffDuration( spell, unit )
if unit == nil then unit = "target" end
local _,_,_,_,_,_,expire,_,_,_,_ = UnitBuff(unit,spell)
if expire == nil then return 0 end
duration = expire-GetTime()-jps.Lag
if duration < 0 then return 0 end
return duration
end
function jps.debuffDuration( spell, unit )
if unit == nil then unit = "target" end
local _,_,_,_,_,_,duration,caster,_,_ = UnitDebuff(unit,spell)
if caster~="player" then return 0 end
if duration==nil then return 0 end
duration = duration-GetTime()-jps.Lag
if duration < 0 then return 0 end
return duration
end
function jps.notmyDebuffDuration( spell, unit )
if unit == nil then unit = "target" end
local _,_,_,_,_,_,duration,_,caster,_,_ = UnitDebuff(unit,spell)
if duration==nil then return 0 end
duration = duration-GetTime()-jps.Lag
if duration < 0 then return 0 end
return duration
end
function jps.debuffStacks( spell, unit )
if unit == nil then unit = "target" end
local _,_,_,count, _,_,_,caster, _,_ = UnitDebuff(unit,spell)
if caster ~= "player" then return 0 end
if count == nil then count = 0 end
return count
end
function jps.buffStacks( spell, unit )
if unit == nil then unit = "player" end
local _, _, _, count, _, _, _, _, _ = UnitBuff(unit,spell)
if count == nil then count = 0 end
return count
end
function jps.bloodlusting()
return jps.buff("bloodlust") or jps.buff("heroism") or jps.buff("time warp") or jps.buff("ancient hysteria")
end
function jps.castTimeLeft(unit)
if unit == nil then
unit = "player" end
local _,_,_,_,_,endTime,_,_,_ = UnitCastingInfo(unit)
if endTime == nil then return 0 end
return (endTime-GetTime()*1000)/1000
end
function jps.shouldKick(unit)
if unit == nil then unit = "target" end
local target_spell, _, _, _, _, endTime, _, _, unInterruptable = UnitCastingInfo(unit)
local channelling, _, _, _, _, _, _, notInterruptible = UnitChannelInfo(unit)
if target_spell == "Release Aberrations" then return false end
if target_spell and not unInterruptable then
return true
--if not jps.PvP then return true
--else return endTime-GetTime()*1000 < 333+jps.Lag end
elseif chanelling and not notInterruptible then
return true
end
return false
end
function jps.mana(unit,message)
if unit == nil then unit = "player" end
if message == "abs" or message == "absolute" then
return UnitMana(unit)
else
return UnitMana(unit)/UnitManaMax(unit)
end
end
function jps.hp(unit,message)
if unit == nil then unit = "player" end
if message == "abs" or message == "absolute" then
return UnitHealth(unit)
else
return UnitHealth(unit)/UnitHealthMax(unit)
end
end
function jps.hpInc(unit,message)
if unit == nil then unit = "player" end
local hpInc = UnitGetIncomingHeals(unit)
if not hpInc then hpInc = 0 end
if message == "abs" or message == "absolute" then
return UnitHealth(unit) + hpInc
else
return UnitHealth(unit)/UnitHealthMax(unit) + hpInc/UnitHealthMax(unit)
end
end
function jps.lowestInRaidStatus()
local lowestHP = 1
local lowestUnit = nil
for name, details in pairs(jps.RaidStatus) do
if details["hp"] < lowestHP then
lowestHP = details["hp"]
lowestUnit = name
end
end
return lowestUnit
end
-- Racial/Profession CDs Check
function jps.checkProfsAndRacials()
-- Draenei, Dwarf, Worgen, Human, Gnome, Night Elf
-- Tauren, Goblin, Orc, Troll, Forsaken, Blood Elf
local usables = {}
local moves =
{
"lifeblood",
"berserking",
"blood fury",
--"engiGloves",
--"gift of the naaru",
--"stoneform",
--"arcane torrent",
--"will of the forsaken",
}
for _, move in pairs(moves) do
if GetSpellBookItemInfo(move) then
table.insert(usables,move)
end
end
return usables
end
-- Lowest HP in RaidStatus
function jps.lowestFriendly()
local lowestUnit = nil
local lowestHP = UnitHealthMax("player")*100
for unit, unitTable in pairs(jps.RaidStatus) do
local thisHP = jps.hpInc(unit)
if thisHP < lowestHP then
if not UnitIsDeadOrGhost(unit) and UnitIsVisible(unit) and UnitInRange(unit) then
lowestHP = thisHP
lowestUnit = unit
end
end
end
return lowestUnit
end
function jps.targetTargetTank()
if jps.buff("bear form","targettarget") then return true end
if jps.buff("blood presence","targettarget") then return true end
if jps.buff("righteous fury","targettarget") then return true end
local _,_,_,_,_,_,_,caster,_,_ = UnitDebuff("target","Sunder Armor")
if caster ~= nil then
if UnitName("targettarget") == caster then return true end end
return false
end
--PLua
function jps.groundClick()
CameraOrSelectOrMoveStart()
CameraOrSelectOrMoveStop()
end
function jps.faceTarget()
InteractUnit("target")
end
function jps.moveToTarget()
InteractUnit("target")
end
-- Find potential tank
function jps.couldBeTank( unit )
if UnitGroupRolesAssigned(unit) == "TANK" then return true
elseif jps.buff( "righteous fury",unit ) then return true
elseif jps.buff( "blood presence",unit ) then return true
elseif jps.buff( "bear form",unit ) then return true
end
end
function jps.findMeATank()
if UnitExists("focus") then return "focus" end
for unit, _ in pairs(jps.RaidStatus) do
if jps.couldBeTank( unit ) then return unit end
end
return "player"
end
local spellcache = setmetatable({}, {__index=function(t,v) local a = {GetSpellInfo(v)} if GetSpellInfo(v) then t[v] = a end return a end})
local function GetSpellIfo(a)
return unpack(a)
end
-- Ty to CDO for this code.
hooksecurefunc("UseAction", function(...)
if jps.Enabled and select(3, ...) ~= nil then
local stype, id = GetActionInfo( select(1, ...) )
if stype == "spell" then
local name,_,_,_,_,_,_,_,_ = GetSpellInfo(id)
if jps.NextCast ~= name then
jps.NextCast = name
if jps.Combat then write("Set",name,"for next cast.") end
end
end
end
end)
-- BenPhelps' Timer Functions
function jps.createTimer( name, duration )
jps.Timers[name] = duration+GetTime()
end
function jps.checkTimer( name )
if jps.Timers[name] ~= nil then
local now = GetTime()
if jps.Timers[name] < now then
jps.Timers[name] = nil
return 0
else
return jps.Timers[name] - now
end
end
return 0
end
function jps.FindMeADispelTarget(dispeltypes)
for unit, _ in pairs(jps.RaidStatus) do
if jps.canDispell( unit, dispeltypes ) then return unit end
end
end