-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuffs.lua
319 lines (305 loc) · 7.34 KB
/
buffs.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
local _, G = ...
local buffSlotSpecification = {
{
buffs = {
{
spell = 'Arcane Intellect',
group = 'Arcane Brilliance',
},
},
},
{
buffs = { { spell = 'Dampen Magic' } },
solo = true,
},
{
buffs = {
{ spell = 'Demon Armor' },
{ spell = 'Demon Skin' },
},
self = true,
},
{
buffs = {
{
spell = 'Divine Spirit',
group = 'Prayer of Spirit',
classes = {
'Paladin',
'Mage',
'Warlock',
'Priest',
'Hunter',
'Druid',
'Shaman',
},
},
},
},
{
buffs = { { spell = 'Ice Barrier' } },
self = true,
},
{
buffs = { { spell = 'Inner Fire' } },
self = true,
},
{
buffs = {
{ spell = 'Mage Armor' },
{ spell = 'Ice Armor' },
{ spell = 'Frost Armor' },
},
self = true,
},
{
buffs = {
{
spell = 'Mark of the Wild',
group = 'Gift of the Wild',
},
},
},
{
buffs = { { spell = 'Omen of Clarity' } },
self = true,
},
{
buffs = {
{
spell = 'Power Word: Fortitude',
group = 'Prayer of Fortitude',
},
},
},
{
buffs = {
{
spell = 'Shadow Protection',
group = 'Prayer of Shadow Protection',
},
},
},
{
buffs = { { spell = 'Thorns' } },
},
{
buffs = { { spell = 'Trueshot Aura' } },
self = true,
},
}
local thebuffdb = (function()
local function rankInfo(rank)
local id, level, reagent = unpack(rank)
return { id = id, level = level, reagent = reagent }
end
local thebuffdb = {}
for _, slotSpec in ipairs(buffSlotSpecification) do
table.insert(thebuffdb, {
buffs = (function()
local buffs = {}
for _, buffSpec in ipairs(slotSpec.buffs) do
table.insert(buffs, {
ranks = (function()
local spellData = G.SpellDB[buffSpec.spell]
local groupData = buffSpec.group and G.SpellDB[buffSpec.group] or {}
assert(#spellData >= #groupData)
local ranks = {}
for i = 1, #spellData do
table.insert(ranks, {
spell = rankInfo(spellData[i]),
group = groupData[i] and rankInfo(groupData[i]) or nil,
})
end
return ranks
end)(),
classes = buffSpec.classes and (function()
local t = {}
for _, class in ipairs(buffSpec.classes) do
t[class] = true
end
return t
end)(),
})
end
return buffs
end)(),
self = slotSpec.self,
solo = slotSpec.solo,
})
end
return thebuffdb
end)()
local function GetUnitBuffs(unit)
local result = {}
local i = 1
local spellid = select(10, UnitBuff(unit, i))
while spellid do
result[spellid] = true
i = i + 1
spellid = select(10, UnitBuff(unit, i))
end
return result
end
local trackingdb = {
{ spell = 2580, texture = 136025 }, -- Find Minerals
{ spell = 2383, texture = 133939 }, -- Find Herbs
{ spell = 2481, texture = 135725 }, -- Find Treasure
}
local function consumeList(db)
local spells = {}
for _, e in ipairs(db) do
local item, _, spell = unpack(e)
if spell then
table.insert(spells, { spell = spell, item = item })
end
end
return spells
end
local conjuredb = {
{ count = 20, spells = consumeList(G.DrinkDB) },
{ count = 10, spells = consumeList(G.FoodDB) },
{ count = 1, spells = consumeList(G.ManaPotionDB) },
{ count = 1, spells = consumeList(G.HealthPotionDB) },
}
local function canCast(spell, unit)
local slot = FindSpellBookSlotBySpellID(spell.id)
return IsSpellKnown(spell.id)
and spell.level - 10 <= UnitLevel(unit)
and (not spell.reagent or GetItemCount(spell.reagent) > 0)
and (not SpellHasRange(slot, 'spell') or IsSpellInRange(slot, 'spell', unit) == 1)
end
local function GetBuffToCast(unit)
local buffs = GetUnitBuffs(unit)
for _, slot in ipairs(thebuffdb) do
local id = (function()
if unit ~= 'player' and (slot.self or slot.solo) then
return nil
end
if slot.solo and IsInGroup() then
return nil
end
for _, buff in ipairs(slot.buffs) do
local id, skip = (function()
if buff.classes and not buff.classes[UnitClass(unit)] then
return nil
end
for _, rank in ipairs(buff.ranks) do
local spell = rank.spell
local group = rank.group
if buffs[spell.id] or group and buffs[group.id] then
return nil, true
end
if group and (UnitInParty(unit) or UnitInRaid(unit)) and canCast(group, unit) then
return group.id
elseif canCast(spell, unit) then
return spell.id
end
end
end)()
if skip then
return nil
elseif id then
return id
end
end
end)()
if id then
return id
end
end
end
local unitsToBuff = (function()
local u = { 'target', 'player' }
for i = 1, 4 do
table.insert(u, 'party' .. i)
end
for i = 1, 40 do
table.insert(u, 'raid' .. i)
end
return u
end)()
local function IsTracking(texture)
if WOW_PROJECT_ID == WOW_PROJECT_CLASSIC then
return GetTrackingTexture() == texture
else
for i = 1, GetNumTrackingTypes() do
local _, tex, active = GetTrackingInfo(i)
if tex == texture then
return active
end
end
return false
end
end
local function GetSpellToCast()
for _, unit in ipairs(unitsToBuff) do
if UnitExists(unit) then
local spell = GetBuffToCast(unit)
if spell then
return spell, unit
end
end
end
for _, c in ipairs(conjuredb) do
for _, s in ipairs(c.spells) do
if IsSpellKnown(s.spell) then
if GetItemCount(s.item) < c.count then
return s.spell, 'player'
end
break
end
end
end
for _, track in ipairs(trackingdb) do
if IsSpellKnown(track.spell) and not IsTracking(track.texture) then
return track.spell, 'player'
end
end
end
local poisons = { -- TODO get this from db2 instead
'Instant Poison VI',
'Instant Poison V',
'Instant Poison IV',
'Instant Poison III',
'Instant Poison II',
'Instant Poison I',
}
local function GetTempEnchant()
if UnitClass('player') ~= 'Rogue' then
return
end
local mainHas, _, _, _, offHas = GetWeaponEnchantInfo()
if mainHas and offHas then
return
end
local poison = nil
for _, p in ipairs(poisons) do
poison = poison or GetItemCount(p) > 0 and p
end
return poison, mainHas and 17 or 16
end
G.PreClickButton('BuffButton', function()
local item, slot = GetTempEnchant()
if item then
return {
item = item,
['target-slot'] = slot,
type = 'item',
}
end
local spell, unit = GetSpellToCast()
if spell and GetSpellCooldown(spell) == 0 and not select(2, IsUsableSpell(spell)) then
local spellName, _, _, castTime = GetSpellInfo(spell)
if castTime == 0 or GetUnitSpeed('player') == 0 then
if not UnitIsUnit('player', unit) then
print('Casting ' .. spellName .. ' on ' .. UnitName(unit) .. '.')
end
return {
spell = spell,
type = 'spell',
unit = unit,
}
end
end
end)