-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpummeler.lua
225 lines (207 loc) · 7.8 KB
/
pummeler.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
Pummeler = {};
function Pummeler_OnLoad()
this:RegisterEvent("PLAYER_ENTERING_WORLD");
this:RegisterEvent("ADDON_LOADED");
DEFAULT_CHAT_FRAME:AddMessage("Pummeler addon loaded. Type /pummeler for usage.");
SlashCmdList["PUMMELER"] = function()
local msg = "To use Pummeler addon, create a macro and type /script Pummeler_main();";
local msg2 = "To equip a fully charged Manual Crowd Pummeler, create a separate macro and type /script Pummeler_equipFullyCharged();";
DEFAULT_CHAT_FRAME:AddMessage(msg);
DEFAULT_CHAT_FRAME:AddMessage(msg2);
end;
SLASH_PUMMELER1 = "/pummeler";
end;
Pummeler_Start_HasteBuff_Time = 0;
function Pummeler_main()
createPummelerFrame();
local haste, hasteIndex, numBuffs = Pummeler_isBuffNameActive("Haste");
local slotId = GetInventorySlotInfo("MAINHANDSLOT");
local itemLink = GetInventoryItemLink("player", slotId);
local pummelerWeapon = "Manual Crowd Pummeler";
local weaponTimer, weaponCd = GetInventoryItemCooldown("player", 16);
local gameTime = GetTime();
local timeLeft = 0;
local chargesText = nil;
local charge = 0;
local buffTimeLeft = -1;
local timeBetweenUses = 3;
local bagPummeler, slotPummeler = nil;
local attackSpeed = UnitAttackSpeed("player");
local catForm, bearForm = nil;
--get user's current form
local currentForm = 0;
for i = 1, GetNumShapeshiftForms(), 1
do
_,formName,active = GetShapeshiftFormInfo(i);
if(formName == "Cat Form") then catForm = i; end;
if(string.find(formName, "Bear Form")) then bearForm = i; end;
if(active ~= nil) then currentForm = i; end;
end;
chargesText = Pummeler_getChargesText{};
charge = Pummeler_getChargeNumber(chargesText);
if(Pummeler_Start_HasteBuff_Time ~= 0) then
buffTimeLeft = 30 - math.floor(gameTime - Pummeler_Start_HasteBuff_Time);
end;
if(buffTimeLeft > 0 and (haste == true or (currentForm == bearForm and attackSpeed <= 1.7) or (currentForm == catForm and attackSpeed <= 0.7))) then
--buffTimeLeft = 30 - math.floor(gameTime - Pummeler_Start_HasteBuff_Time);
DEFAULT_CHAT_FRAME:AddMessage("Pummeler: "..itemLink.." Is active for "..buffTimeLeft.." more seconds!");
elseif(buffTimeLeft < 0 and ((haste == false and numBuffs < 32) or (currentForm == bearForm and attackSpeed > 1.7) or (currentForm == catForm and attackSpeed > 0.7))) then
--if(numBuffs < 32 or (currentForm == bearForm and attackSpeed > 1.7) or (currentForm == catForm and attackSpeed > 0.7)) then
if(weaponCd ~= 0) then
timeLeft = weaponCd - math.floor(gameTime - weaponTimer);
DEFAULT_CHAT_FRAME:AddMessage("Pummeler: "..itemLink.." On cooldown, "..timeLeft.." seconds left!");
elseif(itemLink ~= nil and string.find(itemLink, pummelerWeapon) and charge > 0 and weaponCd == 0) then
buffTimeLeft = math.floor(gameTime - Pummeler_Start_HasteBuff_Time);
if(buffTimeLeft >= timeBetweenUses) then
charge = charge - 1;
UseInventoryItem(16);
Pummeler_Start_HasteBuff_Time = gameTime;
DEFAULT_CHAT_FRAME:AddMessage("Pummeler: Using "..itemLink..": "..charge.." charges left!");
end;
else
bagPummeler, slotPummeler = Pummeler_isPummelerInBag("Manual Crowd Pummeler", false);
if(bagPummeler ~= nil and slotPummeler ~= nil) then
UseContainerItem(bagPummeler, slotPummeler, 1);
DEFAULT_CHAT_FRAME:AddMessage("Pummeler: Equipping a "..pummelerWeapon..".");
end;
end;
--end;
--elseif(haste == false and numBuffs >= 32) then
--DEFAULT_CHAT_FRAME:AddMessage("Pummeler: Cannot use "..itemLink.. " due to buff limit!");
end;
end;
function Pummeler_getChargesText(options)
pummelerTooltip:SetOwner( WorldFrame, "ANCHOR_NONE" );
if(options.bag and options.slot) then
pummelerTooltip:SetBagItem(options.bag, options.slot);
else
pummelerTooltip:SetInventoryItem("player", 16);
end;
local charges = nil;
local i = 1;
while (true)
do
text = getglobal("pummelerTooltipTextLeft"..i):GetText();
if(not text) then break;
elseif(string.find(text, "Charge")) then
charges = text;
pummelerTooltip:Hide();
return charges;
end;
i=i+1;
end;
pummelerTooltip:Hide();
return charges;
end;
function Pummeler_getChargeNumber(chargesText)
local charge = 0;
if(chargesText ~= nil) then
for i = 0, 3, 1
do
if(chargesText ~= nil and string.find(chargesText, i)) then
charge = i; break;
end;
end;
end;
return charge;
end;
function Pummeler_isBuffTextureActive(texture)
local i=0;
local g=GetPlayerBuff;
local isBuffActive = false;
while not(g(i) == -1)
do
if(strfind(GetPlayerBuffTexture(g(i)), texture)) then isBuffActive = true; end;
i=i+1
end;
return isBuffActive;
end;
function createPummelerFrame()
if pummelerFrame == nil then
pummelerFrame = CreateFrame("GameTooltip", "pummelerTooltip", nil, "GameTooltipTemplate");
end;
end;
function Pummeler_isBuffNameActive(buff)
local isActive = false;
local index = -1;
local i = 1;
local numBuffs = nil;
local g=UnitBuff;
local textleft1 = nil;
while not(g("player", i) == -1 or g("player", i) == nil)
do
pummelerTooltip:SetOwner( WorldFrame, "ANCHOR_NONE" );
pummelerTooltip:SetUnitBuff("player", i);
textleft1 = getglobal(pummelerTooltip:GetName().."TextLeft1");
if(textleft1 ~= nil and string.find(string.lower(textleft1:GetText()), string.lower(buff))) then
isActive = true;
index = i - 1;
pummelerTooltip:Hide();
break;
end;
pummelerTooltip:Hide();
i=i+1;
end;
if(index == -1) then
numBuffs = 0;
else
numBuffs = i;
end;
return isActive, index, numBuffs;
end;
function Pummeler_isPummelerInBag(itemName, threeChargesFlag)
local itemBag, itemSlot = nil;
local charges = nil;
for bag = 0, 4, 1
do
for slot = 1, GetContainerNumSlots(bag), 1
do local name = GetContainerItemLink(bag,slot)
if name and string.find(name, itemName) then
if string.find(name, itemName) then
charges = Pummeler_getChargeNumber(Pummeler_getChargesText{bag = bag, slot = slot});
if(threeChargesFlag == true) then
if(charges == 3) then
itemBag = bag; itemSlot = slot;
return itemBag, itemSlot;
end;
elseif(charges > 0) then
itemBag = bag; itemSlot = slot;
return itemBag, itemSlot;
end;
end;
end;
end;
end;
return itemBag, itemSlot;
end;
-- Separate macro function to equip a fully charged Pummeler.
function Pummeler_equipFullyCharged()
createPummelerFrame();
local haste, hasteIndex, numBuffs = Pummeler_isBuffNameActive("Haste");
local bagPummeler, slotPummeler = nil;
local pummelerWeapon = "Manual Crowd Pummeler";
local chargesText = nil;
local charge = 0;
local slotId = GetInventorySlotInfo("MAINHANDSLOT");
local itemLink = GetInventoryItemLink("player", slotId);
local buffTimeLeft = nil;
local gameTime = GetTime();
chargesText = Pummeler_getChargesText{};
charge = Pummeler_getChargeNumber(chargesText);
if(haste == true) then
buffTimeLeft = 30 - math.floor(gameTime - Pummeler_Start_HasteBuff_Time);
DEFAULT_CHAT_FRAME:AddMessage("Pummeler: "..itemLink.." Is active for "..buffTimeLeft.." more seconds!");
else
if(charge == 3) then
DEFAULT_CHAT_FRAME:AddMessage("Pummeler: You already have a fully charged "..pummelerWeapon.." equipped.");
else
bagPummeler, slotPummeler = Pummeler_isPummelerInBag("Manual Crowd Pummeler", true);
if(bagPummeler ~= nil and slotPummeler ~= nil) then
UseContainerItem(bagPummeler, slotPummeler, 1);
DEFAULT_CHAT_FRAME:AddMessage("Pummeler: Equipping a fully charged "..pummelerWeapon..".");
else
DEFAULT_CHAT_FRAME:AddMessage("Pummeler: No fully charged "..pummelerWeapon.." found.");
end;
end;
end;
end;