vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 -- Action Objects
2  
3 function lazyr.GetActionNameFromTooltip(actionSlot)
4 LazyRogue_Tooltip:ClearLines()
5 LazyRogue_Tooltip:SetAction(actionSlot)
6 return LazyRogue_TooltipTextLeft1:GetText()
7 end
8  
9 lazyr.Action = {}
10 function lazyr.Action:New(code, name, texture, interrupts)
11 local obj = {}
12 setmetatable(obj, { __index = self })
13 obj.code = code
14 obj.name = name
15 obj.texture = texture
16 obj.interrupts = interrupts
17 obj.slot = nil
18 obj.rank = nil
19 obj.everyTimer = 0
20 return obj
21 end
22 function lazyr.Action:GetSlot()
23 if (not self.slot) then
24 for slot = 1, 120 do
25 local thisTexture = GetActionTexture(slot)
26 if (thisTexture) then
27 --
28 -- Sigh. We need to be careful of localization here. The bad thing about the
29 -- Action class is we don't account for localization (yet), so we have to watch
30 -- when when actually try to match tooltips to self.name.
31 --
32 -- 1. if we have a texture, match it (and it only, no tooltip). Ignore macros.
33 -- This will be the common case of the built-in actions.
34 -- 2. if we don't have a texture, then use tooltips. Macros okay. This will
35 -- be the case for user action=<action> actions.
36 --
37 if (self.texture) then
38 if (not GetActionText(slot)) then -- ignore any Player macros :-)
39 if (thisTexture and string.find(thisTexture, self.texture)) then
40 lazyr.d("found "..self.name.." at slot "..slot)
41 self.slot = slot
42 break
43 end
44 end
45 else
46 if (lazyr.GetActionNameFromTooltip(slot) == self.name) then
47 lazyr.d("found "..self.name.." at slot "..slot)
48 self.slot = slot
49 break
50 end
51 end
52 end
53 end
54 end
55 if (not self.slot) then
56 lazyr.p("Couldn't find "..self.name.." on your action bar, PLEASE ADD IT.")
57 return nil
58 end
59 return self.slot
60 end
61 function lazyr.Action:Use()
62 if (self:GetSlot()) then
63 local inRange = IsActionInRange(self.slot)
64 if (IsUsableAction(self.slot) == 1 and
65 GetActionCooldown(self.slot) == 0 and -- not in cooldown
66 not IsCurrentAction(self.slot) and -- not already being used
67 (inRange == 1 or inRange == nil)) then
68 if (not lazyr.mock) then
69 lazyr.d("Action: "..self.name)
70 UseAction(self.slot)
71 if (self.interrupts and lazyr.interrupt.targetCasting) then
72 lazyr.interrupt.lastSpellInterrupted = lazyr.interrupt.targetCasting
73 lazyr.interrupt.targetCasting = nil
74 end
75 lazyr.recordAction(self.code)
76 self.everyTimer = GetTime()
77 end
78 return true
79 end
80 return false
81 end
82 end
83 function lazyr.Action:GetRank()
84 if (not self.rank) then
85 local i = 1
86 while true do
87 local texture = GetSpellTexture(i, BOOKTYPE_SPELL)
88 if (not texture) then
89 break
90 end
91 if (string.find(texture, self.texture)) then
92 local spellNameEn, spellRank = GetSpellName(i, BOOKTYPE_SPELL)
93 lazyr.re(spellRank, "(%d+)")
94 self.rank = tonumber(lazyr.match1)
95 break
96 end
97 i = i + 1
98 end
99 end
100 if (not self.rank) then
101 lazyr.p("Couldn't find "..self.name.." in your spell book.")
102 return 0
103 end
104 return self.rank
105 end
106  
107 lazyr.actions = {}
108 lazyr.actions.adrenalineRush = lazyr.Action:New("adrenaline", "Adrenaline Rush", "Spell_Shadow_ShadowWordDominate")
109 lazyr.actions.ambush = lazyr.Action:New("ambush", "Ambush", "Ability_Rogue_Ambush")
110 lazyr.actions.berserking = lazyr.Action:New("berserking", "Berserking", "Racial_Troll_Berserk")
111 lazyr.actions.backstab = lazyr.Action:New("bs", "Backstab", "Ability_BackStab")
112 lazyr.actions.bladeFlurry = lazyr.Action:New("bladeFlurry", "Blade Flurry", "Ability_Warrior_PunishingBlow")
113 lazyr.actions.blind = lazyr.Action:New("blind", "Blind", "Spell_Shadow_MindSteal", true)
114 lazyr.actions.cheapShot = lazyr.Action:New("cs", "Cheap Shot", "Ability_CheapShot", true)
115 lazyr.actions.coldBlood = lazyr.Action:New("coldBlood", "Cold Blood", "Spell_Ice_Lament")
116 lazyr.actions.evasion = lazyr.Action:New("evasion", "Evasion", "Spell_Shadow_ShadowWard")
117 lazyr.actions.eviscerate = lazyr.Action:New("evisc", "Eviscerate", "Ability_Rogue_Eviscerate")
118 lazyr.actions.exposeArmor = lazyr.Action:New("expose", "Expose Armor", "Ability_Warrior_Riposte")
119 lazyr.actions.feint = lazyr.Action:New("feint", "Feint", "Ability_Rogue_Feint")
120 lazyr.actions.garrote = lazyr.Action:New("garrote", "Garrote", "Ability_Rogue_Garrote")
121 lazyr.actions.ghostlyStrike = lazyr.Action:New("ghostly", "Ghostly Strike", "Spell_Shadow_Curse")
122 lazyr.actions.gouge = lazyr.Action:New("gouge", "Gouge", "Ability_Gouge", true)
123 lazyr.actions.hemorrhage = lazyr.Action:New("hemo", "Hemorrhage", "Spell_Shadow_LifeDrain")
124 lazyr.actions.kick = lazyr.Action:New("kick", "Kick", "Ability_Kick", true)
125 lazyr.actions.kidneyShot = lazyr.Action:New("ks", "Kidney Shot", "Ability_Rogue_KidneyShot", true)
126 lazyr.actions.pickPocket = lazyr.Action:New("pickPocket", "Pick Pocket", "INV_Misc_Bag_11")
127 lazyr.actions.premeditation = lazyr.Action:New("premeditation", "Premeditation", "Spell_Shadow_Possession")
128 lazyr.actions.preparation = lazyr.Action:New("preparation", "Preparation", "Spell_Shadow_AntiShadow")
129 lazyr.actions.riposte = lazyr.Action:New("riposte", "Riposte", "Ability_Warrior_Challange")
130 lazyr.actions.rupture = lazyr.Action:New("rupture", "Rupture", "Ability_Rogue_Rupture")
131 lazyr.actions.sap = lazyr.Action:New("sap", "Sap", "Ability_Sap")
132 lazyr.actions.sinisterStrike = lazyr.Action:New("ss", "Sinister Strike", "Spell_Shadow_RitualOfSacrifice")
133 lazyr.actions.sliceNDice = lazyr.Action:New("snd", "Slice and Dice", "Ability_Rogue_SliceDice")
134 lazyr.actions.sprint = lazyr.Action:New("sprint", "Sprint", "Ability_Rogue_Sprint")
135 lazyr.actions.stealth = lazyr.Action:New("stealth", "Stealth", "Ability_Stealth")
136 lazyr.actions.vanish = lazyr.Action:New("vanish", "Vanish", "Ability_Vanish")
137 lazyr.actions.humanRacial = lazyr.Action:New("perception", "Perception", "Spell_Nature_Sleep")
138 lazyr.actions.dwarfRacial = lazyr.Action:New("stoneForm", "Stoneform", "Spell_Shadow_UnholyStrength")
139 lazyr.actions.gnomeRacial = lazyr.Action:New("escapeArtist", "Escape Artist", "Ability_Rogue_Trip")
140 lazyr.actions.orcRacial = lazyr.Action:New("bloodFury", "Blood Fury", "Racial_Orc_BerserkerStrength")
141 lazyr.actions.taurenRacial = lazyr.Action:New("warStomp", "War Stomp", "Ability_WarStomp", true)
142 lazyr.actions.undeadRacial = lazyr.Action:New("forsaken", "Will of the Forsaken", "Spell_Shadow_RaiseDead")
143 lazyr.actions.throw = lazyr.Action:New("throw", "Throw", "Ability_Throw")
144 lazyr.actions.bow = lazyr.Action:New("bow", "Shoot Bow", "Ability_Marksmanship")
145 lazyr.actions.gun = lazyr.Action:New("gun", "Shoot Gun", "Ability_Marksmanship")
146 lazyr.actions.crossbow = lazyr.Action:New("crossbow", "Shoot Crossbow", "Ability_Marksmanship")
147 lazyr.actions.cannibalize = lazyr.Action:New("cannibalize", "Cannibalize", "Ability_Racial_Cannibalize")
148  
149 lazyr.otherActions = {}
150  
151 function lazyr.DeCacheActionSlotIds()
152 for idx, action in lazyr.actions do
153 action.slot = nil
154 end
155 for idx, action in lazyr.otherActions do
156 action.slot = nil
157 end
158 end
159 function lazyr.DeCacheActionRanks()
160 for idx, action in lazyr.actions do
161 action.rank = nil
162 end
163 for idx, action in lazyr.otherActions do
164 action.rank = nil
165 end
166 end
167  
168  
169 -- ComboAction Objects
170  
171 lazyr.ComboAction = {}
172 function lazyr.ComboAction:New(code, name, ...)
173 local obj = {}
174 setmetatable(obj, { __index = self })
175 obj.code = code
176 obj.name = name
177 obj.actions = {}
178 for i = 1, arg.n do
179 table.insert(obj.actions, arg[i])
180 end
181 obj.everyTimer = 0
182 return obj
183 end
184 function lazyr.ComboAction:Use()
185 -- first pass, don't really perform the actions, just see if they're all ready
186 local origMock = lazyr.mock
187 lazyr.mock = true
188 for idx, action in self.actions do
189 if (not action:Use()) then
190 lazyr.mock = origMock
191 return false
192 end
193 end
194 lazyr.mock = origMock
195  
196 if (not lazyr.mock) then
197 local first = true
198 for idx, action in self.actions do
199 if (first) then
200 first = false
201 else
202 SpellStopCasting()
203 end
204 action:Use()
205 end
206  
207 lazyr.recordAction(self.code)
208 self.everyTimer = GetTime()
209 end
210  
211 return true
212 end
213  
214 lazyr.comboActions = {}
215 lazyr.comboActions.cbEvisc = lazyr.ComboAction:New("cbEvisc", "CB+Eviscerate", lazyr.actions.coldBlood, lazyr.actions.eviscerate)
216 lazyr.comboActions.cbAmbush = lazyr.ComboAction:New("cbAmbush", "CB+Ambush", lazyr.actions.coldBlood, lazyr.actions.ambush)
217  
218 -- Form Objects
219  
220 lazyr.SetForm = {}
221 function lazyr.SetForm:New(code, name)
222 local obj = {}
223 setmetatable(obj, { __index = self})
224 obj.code = code
225 obj.name = name
226 obj.everyTimer = 0
227 return obj
228 end
229 function lazyr.SetForm:Use()
230 lazyr.SlashCommand("default "..self.name)
231 lazyr.recordAction(self.code)
232 self.everyTimer = GetTime()
233 return true
234 end
235  
236 lazyr.forms = {}
237 lazyr.forms.default = lazyr.SetForm:New("default", "lazy1")
238  
239 -- Equip objects
240  
241 lazyr.EquipItem = {}
242 function lazyr.EquipItem:New(code, name, id, equipSlot)
243 local obj ={}
244 setmetatable(obj, { __index = self })
245 obj.code = code
246 obj.name = name
247 obj.id = id
248 obj.equipSlot = equipSlot
249 obj.everyTimer = 0
250 return obj
251 end
252 function lazyr.EquipItem:Use()
253 local bag, slot
254 for bag = 4, 0, -1 do
255 for slot = 1, GetContainerNumSlots(bag) do
256 local link = GetContainerItemLink(bag, slot)
257 if (link) then
258 local id, name = lazyr.IdAndNameFromLink(link)
259 if (id) then
260 -- self.id might be nil, in which case match by name
261 if ((self.id and id == self.id) or string.lower(name) == string.lower(self.name)) then
262 if (not lazyr.mock) then
263 PickupContainerItem(bag, slot)
264 EquipCursorItem(self.equipSlot)
265 lazyr.recordAction(self.code)
266 self.everyTimer = GetTime()
267 end
268 return true
269 end
270 end
271 end
272 end
273 end
274 return false
275 end
276  
277 lazyr.mainHandItems = {}
278 lazyr.offHandItems = {}
279  
280 -- Item Objects
281  
282 lazyr.Item = {}
283 function lazyr.Item:New(code, name, id, equippedOnly)
284 local obj = {}
285 setmetatable(obj, { __index = self })
286 obj.code = code
287 obj.name = name
288 obj.id = id
289 obj.equippedOnly = equippedOnly
290 obj.everyTimer = 0
291 return obj
292 end
293 function lazyr.Item:Use()
294 -- check equipped items first
295 for slot = 0, 19 do
296 local link = GetInventoryItemLink("player", slot)
297 if (link) then
298 local id, name = lazyr.IdAndNameFromLink(link)
299 if (id) then
300 -- self.id might be nil, in which case match by name
301 if ((self.id and id == self.id) or string.lower(name) == string.lower(self.name)) then
302 if (GetInventoryItemCooldown("player", slot) == 0) then
303 if (not lazyr.mock) then
304 lazyr.d("Using item: "..self.name.."("..lazyr.nonil(self.id)..") at equipped slot: "..slot)
305 UseInventoryItem(slot)
306 lazyr.recordAction(self.code)
307 self.everyTimer = GetTime()
308 if (SpellIsTargeting()) then
309 SpellTargetUnit("player")
310 end
311 end
312 return true
313 end
314 end
315 end
316 end
317 end
318  
319 if (not self.equippedOnly) then
320 local bag, slot
321 for bag = 4, 0, -1 do
322 for slot = 1, GetContainerNumSlots(bag) do
323 local link = GetContainerItemLink(bag, slot)
324 if (link) then
325 local id, name = lazyr.IdAndNameFromLink(link)
326 if (id) then
327 -- self.id might be nil, in which case match by name
328 if ((self.id and id == self.id) or string.lower(name) == string.lower(self.name)) then
329 if (GetContainerItemCooldown(bag, slot) == 0) then
330 if (not lazyr.mock) then
331 lazyr.d("Using item: "..self.name.."("..
332 lazyr.nonil(self.id)..") at bag/slot slot: "..bag.."/"..slot)
333 UseContainerItem(bag,slot)
334 lazyr.recordAction(self.code)
335 self.everyTimer = GetTime()
336 if (SpellIsTargeting()) then
337 SpellTargetUnit("player")
338 end
339 end
340 return true
341 end
342 end
343 end
344 end
345 end
346 end
347 end
348  
349 return false
350 end
351  
352 lazyr.items = {}
353 lazyr.items.thistleTea = lazyr.Item:New("tea", "Thistle Tea", 7676)
354  
355 lazyr.equippedItems = {}
356  
357  
358 -- PseudoAction Objects
359  
360 lazyr.PseudoAction = {}
361 function lazyr.PseudoAction:New(code, name)
362 local obj = {}
363 setmetatable(obj, { __index = self })
364 obj.code = code
365 obj.name = name
366 obj.everyTimer = 0
367 return obj
368 end
369 function lazyr.PseudoAction:Use()
370 -- all PseudoAction instances must define their own Use() method
371 -- remember, reset everyTimer in each
372 end
373  
374 lazyr.pseudoActions = {}
375  
376 lazyr.pseudoActions.targetAssist = lazyr.PseudoAction:New("targetAssist", "Target Assist")
377 function lazyr.pseudoActions.targetAssist:Use()
378 -- this pseudo action always succeeds, so no action after it will be executed
379 if (lazyr.mock) then
380 -- this needs work
381 return false
382 end
383 tmpTarget = UnitName("target")
384 TargetByName(tostring(lazyr.assistName), true)
385 if UnitName("targettarget")==tmpTarget and UnitName("targettarget")~=nil then
386 TargetLastTarget()
387 return false
388 end
389 if lazyr.assistName~=nil then
390 ClearTarget()
391 AssistByName(lazyr.assistName)
392 if UnitName("target")==nil then
393 TargetByName(tostring(lazyr.assistName), true)
394 if UnitExists("target") then
395 lazyr.d("Waiting for target to be chosen...")
396 return true
397 else
398 lazyr.p("Assist target seams to be out of range, please update with /lr assist <assist name>")
399 return false
400 end
401 else
402 lazyr.d("Assisting "..lazyr.assistName)
403 lazyr.recordAction(self.code)
404 self.everyTimer = GetTime()
405 return true
406 end
407  
408 else
409 lazyr.p("Assist target not set please update with /lr assist <assist name>")
410 return false
411 end
412 end
413  
414 lazyr.pseudoActions.targetNearest = lazyr.PseudoAction:New("targetNearest", "Target Nearest")
415 function lazyr.pseudoActions.targetNearest:Use()
416 -- this pseudo action always succeeds, so no action after it will be executed
417 if (lazyr.mock) then
418 -- this needs work
419 return false
420 end
421 TargetNearestEnemy()
422  
423 lazyr.recordAction(self.code)
424 self.everyTimer = GetTime()
425 return true
426 end
427  
428 lazyr.pseudoActions.autoAttack = lazyr.PseudoAction:New("autoAttack", "Auto Target/Attack")
429 function lazyr.pseudoActions.autoAttack:Use()
430 if (not lazyr.IsAutoAttacking()) then
431 if (not lazyr.mock) then
432 lazyr.StartAutoAttack()
433 lazyr.recordAction(self.code)
434 self.everyTimer = GetTime()
435 end
436 return true
437 end
438  
439 return false
440 end
441  
442 lazyr.pseudoActions.stop = lazyr.PseudoAction:New("stop", "Stop")
443 function lazyr.pseudoActions.stop:Use()
444 -- this pseudo action always succeeds, so no action after it will be executed
445 --lazyr.recordAction(self.code)
446 if (not lazyr.mock) then
447 self.everyTimer = GetTime()
448 end
449 return true
450 end
451  
452 lazyr.pseudoActions.stopAll = lazyr.PseudoAction:New("stopAll", "Stop All")
453 function lazyr.pseudoActions.stopAll:Use()
454 if (not lazyr.mock) then
455 if (lazyr.IsAutoAttacking()) then
456 lazyr.d("Stopping auto-attack...")
457 lazyr.StopAutoAttack()
458 end
459 --lazyr.recordAction(self.code)
460 self.everyTimer = GetTime()
461 end
462 return true
463 end
464  
465 lazyr.pseudoActions.dismount = lazyr.PseudoAction:New("dismount", "Dismount")
466 function lazyr.pseudoActions.dismount:Use()
467 if (not lazyr.mock) then
468 local index = lazyr.masks.PlayerMountedIndex()
469 if (index) then
470 CancelPlayerBuff(index)
471 end
472 lazyr.recordAction(self.code)
473 self.everyTimer = GetTime()
474 end
475 return true
476 end
477  
478 -- this pseudo action is just for testing criteria
479 lazyr.pseudoActions.ping = lazyr.PseudoAction:New("ping", "Ping")
480 function lazyr.pseudoActions.ping:Use()
481 if (not lazyr.mock) then
482 lazyr.chat("ping")
483 --lazyr.recordAction(self.code)
484 self.everyTimer = GetTime()
485 end
486 return true
487 end
488  
489  
490 lazyr.pseudoActions.sayIn = lazyr.PseudoAction:New("sayIn", "Say In ...")
491 function lazyr.pseudoActions.sayIn:Use()
492 if (not lazyr.mock) then
493 SendChatMessage(lazyr.sayInMessage,lazyr.sayInChannel)
494 self.everyTimer = GetTime()
495 end
496 return true
497 end
498  
499  
500 function lazyr.PickupPoison(name)
501 local i, itemLink, bagSlots, bagId, icon, quantity;
502 for i=0, 4 do
503 itemLink = nil;
504 bagSlots = GetContainerNumSlots(i);
505 if (bagSlots > 0) then
506 for j=1, bagSlots do
507 itemLink = nil;
508 itemLink = GetContainerItemLink(i, j);
509 if (itemLink) then
510 local _, _, itemName = string.find(itemLink, "%[(.*)%]");
511 if (itemName ~= nil and itemName == name) then
512 lazyr.d("Found "..name);
513 UseContainerItem(i, j);
514 return;
515 end
516 end
517 end
518 end
519 end
520 end
521  
522 lazyr.poisonsUse ={}
523 lazyr.applyPoison ={}
524  
525 function lazyr.applyPoison:New(poisonName, equipSlot)
526 local obj ={}
527 setmetatable(obj, { __index = self })
528 obj.psnName = poisonName
529 obj.psnDst = equipSlot
530 obj.everyTimer = 0
531 return obj
532 end
533  
534 function lazyr.applyPoison:Use()
535 local poison = self.psnName
536 local slotgiven = self.psnDst
537 if (slotgiven == "OffHand") then
538 slot = "SecondaryHandSlot";
539 else
540 slot = "MainHandSlot";
541 end
542 poison=gsub (poison, "[%[%]]", "")
543 lazyr.PickupPoison(poison);
544 PickupInventoryItem(GetInventorySlotInfo(slot));
545 -- If the pickup failed we will now have the weapon on our cursor
546 if (CursorHasItem()) then
547 PickupInventoryItem(GetInventorySlotInfo(slot));
548 end
549 self.everyTimer = GetTime()
550 return true
551 end
552  
553  
554  
555 function lazyr.ResetEveryTimers()
556 local now = GetTime()
557 for idx, action in lazyr.actions do
558 action.everyTimer = now
559 end
560 for idx, action in lazyr.comboActions do
561 action.everyTimer = now
562 end
563 for idx, action in lazyr.items do
564 action.everyTimer = now
565 end
566 for idx, action in lazyr.pseudoActions do
567 action.everyTimer = now
568 end
569 end
570  
571 lazyr.actionHistory = {}
572 function lazyr.recordAction(action)
573 -- add to the front, remove from the end
574 table.insert(lazyr.actionHistory, 1, action)
575 local size = table.getn(lazyr.actionHistory)
576 if (size > 25) then
577 local difference = size - 25
578 local i
579 for i = 1, difference do
580 table.remove(lazyr.actionHistory)
581 end
582 end
583 end
584  
585