-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCast.lua
More file actions
356 lines (318 loc) · 11.3 KB
/
Copy pathCast.lua
File metadata and controls
356 lines (318 loc) · 11.3 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
-------------------------------------------------------------------------------
-- SmartBuff Cast
-------------------------------------------------------------------------------
local SG = SMARTBUFF_GLOBALS;
-- SMARTBUFF_doCast
-- Validates whether a spell can be cast on the given unit before buffing.
-- Parameters:
-- unit (string) Unit token to buff (e.g. "player", "party1")
-- id (number) Spell ID; nil returns code 9
-- spellName (string) Localized spell name used for cooldown/range/mana checks
-- levels (table) Rank/level data (passed through from caller; unused here)
-- type (number) Buff type constant (SMARTBUFF_CONST_*)
-- Returns:
-- (number) 0 = castable
-- 1 = spell on cooldown
-- 3 = target out of range
-- 4 = cooldown exceeds SG.maxSkipCoolDown
-- 6 = not enough mana/rage/energy
-- 7 = another tracking ability is already active
-- 9 = spell ID is nil
function SMARTBUFF_doCast(unit, id, spellName, levels, type)
if (id == nil) then return 9; end
if (type == SMARTBUFF_CONST_TRACK and (GetTrackingTexture() ~= "Interface\\Minimap\\Tracking\\None")) then
return 7;
end
-- check if spell has cooldown (remaining time, not raw duration)
local cdStart, cdDuration = GetSpellCooldown(spellName);
local cd = 0;
if (cdStart and cdStart > 0 and cdDuration) then
cd = (cdStart + cdDuration) - GetTime();
if (cd < 0) then
cd = 0;
end
end
if (cd > SG.maxSkipCoolDown) then
return 4;
elseif (cd > 0) then
return 1;
end
-- Rangecheck
if (type == SMARTBUFF_CONST_GROUP or type == SMARTBUFF_CONST_ITEMGROUP) then
if (C_Spell.SpellHasRange(spellName)) then
if (not C_Spell.IsSpellInRange(spellName, unit)) then
return 3;
end
else
if (UnitInRange(unit) ~= 1) then
return 3;
end
end
end
-- check if you have enough mana/energy/rage to cast
local isUsable, notEnoughMana = IsUsableSpell(spellName);
if (notEnoughMana) then
return 6;
end
return 0;
end
-- SMARTBUFF_InitActionButtonPos
-- Restores the SmartBuff action button position from saved options or defaults.
-- Parameters: none
-- Returns: nothing (no-op while in combat lockdown)
function SMARTBUFF_InitActionButtonPos()
if (InCombatLockdown()) then return end
SG.isInitBtn = true;
if (SG.O.ActionBtnX == nil) then
SMARTBUFF_SetButtonPos(SmartBuff_KeyButton);
else
SmartBuff_KeyButton:ClearAllPoints();
SmartBuff_KeyButton:SetPoint("TOPLEFT", UIParent, "TOPLEFT", SG.O.ActionBtnX, SG.O.ActionBtnY);
end
end
-- SMARTBUFF_ResetAll
-- Wipes all saved buff templates and options, then reloads the UI.
-- Parameters: none
-- Returns: nothing
function SMARTBUFF_ResetAll()
wipe(SMARTBUFF_Buffs);
wipe(SMARTBUFF_Options);
ReloadUI();
end
-- SMARTBUFF_SetButtonPos
-- Saves the current screen position of a frame to SG.O.ActionBtnX / ActionBtnY.
-- Parameters:
-- self (Frame) Frame whose top-left corner position is stored
-- Returns: nothing
function SMARTBUFF_SetButtonPos(self)
local x, y = self:GetLeft(), self:GetTop() - UIParent:GetHeight();
SG.O.ActionBtnX = x;
SG.O.ActionBtnY = y;
end
-- SMARTBUFF_RebindKeys
-- Applies override key bindings for the SmartBuff secure action button.
-- Binds SMARTBUFF_BIND_TRIGGER and optional mouse-wheel scroll buffing.
-- Parameters: none
-- Returns: nothing (no-op while in combat lockdown)
function SMARTBUFF_RebindKeys()
if (InCombatLockdown()) then return; end
local i;
SG.isRebinding = true;
local key1, key2;
for i = 1, GetNumBindings(), 1 do
local command, k1, k2 = GetBinding(i);
if (k1 and k1 == "MOUSEWHEELUP" and command ~= "SmartBuff_KeyButton") then
SG.O.OldWheelUp = command;
elseif (k1 and k1 == "MOUSEWHEELDOWN" and command ~= "SmartBuff_KeyButton") then
SG.O.OldWheelDown = command;
end
if (command and command == "SMARTBUFF_BIND_TRIGGER") then
key1, key2 = k1, k2;
break;
end
end
-- Use override bindings so the key triggers the secure button (works in combat, doesn't alter saved bindings)
ClearOverrideBindings(SmartBuffFrame);
if (key1) then
SetOverrideBindingClick(SmartBuffFrame, false, key1, "SmartBuff_KeyButton", "LeftButton");
end
if (key2) then
SetOverrideBindingClick(SmartBuffFrame, false, key2, "SmartBuff_KeyButton", "LeftButton");
end
if (SG.O.ScrollWheelUp) then
SG.isKeyUpChanged = true;
SetOverrideBindingClick(SmartBuffFrame, false, "MOUSEWHEELUP", "SmartBuff_KeyButton", "MOUSEWHEELUP");
else
if (SG.isKeyUpChanged) then
SG.isKeyUpChanged = false;
SetOverrideBinding(SmartBuffFrame, false, "MOUSEWHEELUP");
end
end
if (SG.O.ScrollWheelDown) then
SG.isKeyDownChanged = true;
SetOverrideBindingClick(SmartBuffFrame, false, "MOUSEWHEELDOWN", "SmartBuff_KeyButton", "MOUSEWHEELDOWN");
else
if (SG.isKeyDownChanged) then
SG.isKeyDownChanged = false;
SetOverrideBinding(SmartBuffFrame, false, "MOUSEWHEELDOWN");
end
end
SG.isRebinding = false;
end
-- SMARTBUFF_ResetBindings
-- Restores saved mouse-wheel bindings and reapplies SmartBuff override bindings.
-- Parameters: none
-- Returns: nothing
function SMARTBUFF_ResetBindings()
if (not SG.isRebinding) then
SG.isRebinding = true;
if (SG.O.OldWheelUp == "SmartBuff_KeyButton") then
SetBinding("MOUSEWHEELUP", "CAMERAZOOMIN");
else
SetBinding("MOUSEWHEELUP", SG.O.OldWheelUp);
end
if (SG.O.OldWheelDown == "SmartBuff_KeyButton") then
SetBinding("MOUSEWHEELDOWN", "CAMERAZOOMOUT");
else
SetBinding("MOUSEWHEELDOWN", SG.O.OldWheelDown);
end
SaveBindings(GetCurrentBindingSet());
SMARTBUFF_RebindKeys();
end
end
-- SmartBuff commandline menu ---------------------------------------------------------------------------------------
-- SMARTBUFF_ShowSAButton
-- Shows or hides the SmartBuff action button based on the HideSAButton option.
-- Parameters: none
-- Returns: nothing (no-op while in combat lockdown)
function SMARTBUFF_ShowSAButton()
if (not InCombatLockdown()) then
if (SG.O.HideSAButton) then
SmartBuff_KeyButton:Hide();
else
SmartBuff_KeyButton:Show();
end
end
end
local sScript;
-- SMARTBUFF_OnClick
-- Debug handler for direct clicks on the SmartBuff action button.
-- Parameters:
-- obj (Frame) Button frame that received the click
-- Returns: nothing
function SMARTBUFF_OnClick(obj)
SMARTBUFF_AddMsgD("OnClick");
end
local lastBuffType = "";
local cvarChanged = false;
-- SMARTBUFF_OnPreClick
-- Secure pre-click handler: runs SMARTBUFF_Check and sets button attributes for the cast.
-- Supports left-click (mode 0) and scroll-wheel buffing (mode 5).
-- Parameters:
-- self (Button) SmartBuff_KeyButton secure action button
-- button (string) Mouse button name (e.g. "LeftButton", "MOUSEWHEELUP")
-- down (boolean) True if the button was pressed, false if released
-- Returns: nothing
function SMARTBUFF_OnPreClick(self, button, down)
if (not SG.isInit) then return end
local mode = 0;
local unitsLevel = nil
if (button) then
if (button == "MOUSEWHEELUP" or button == "MOUSEWHEELDOWN") then
mode = 5;
end
end
if (not InCombatLockdown()) then
self:SetAttribute("type", nil);
self:SetAttribute("unit", nil);
self:SetAttribute("spell", nil);
self:SetAttribute("item", nil);
self:SetAttribute("macrotext", nil);
self:SetAttribute("target-slot", nil);
self:SetAttribute("target-item", nil);
self:SetAttribute("action", nil);
end
-- we need to adjust the cvar to enable scroll buffing, we
-- only need to do this if the cvar is set to 0 and the user has enabled the fix.
if (SG.O.FixCasting and C_CVar.GetCVar("ActionButtonUseKeyDown") == "0") then
C_CVar.SetCVar("ActionButtonUseKeyDown", 1);
cvarChanged = true;
end
local td;
if (lastBuffType == "") then
td = 0.8;
else
td = SG.GlobalCd;
end
if (UnitCastingInfo("player")) then
SG.tAutoBuff = GetTime() + 0.7;
return;
end
if (GetTime() < (SG.tAutoBuff + td)) then return end
SG.tAutoBuff = GetTime();
lastBuffType = "";
SG.currentUnit = nil;
SG.currentSpell = nil;
if (not InCombatLockdown()) then
local ret, actionType, spellName, slot, unit, buffType = SMARTBUFF_Check(mode);
if (ret and ret == 0 and actionType and spellName and unit) then
lastBuffType = buffType;
self:SetAttribute("type", actionType);
self:SetAttribute("unit", unit);
if (actionType == SMARTBUFF_ACTION_SPELL) then
if (slot and slot > 0 and unit == "player") then
self:SetAttribute("type", "macro");
self:SetAttribute("macrotext", string.format("/use %s\n/use %i\n/click StaticPopup1Button1", spellName, slot));
SMARTBUFF_AddMsgD("Weapon buff "..spellName..", "..slot);
else
self:SetAttribute("spell", spellName);
end
if (SG.cBuffIndex[spellName]) then
SG.currentUnit = unit;
SG.currentSpell = spellName;
end
elseif (actionType == SMARTBUFF_ACTION_ITEM and slot) then
self:SetAttribute("item", spellName);
if (slot > 0) then
self:SetAttribute("type", "macro");
self:SetAttribute("macrotext", string.format("/use %s\n/use %i\n/click StaticPopup1Button1", spellName, slot));
end
elseif (actionType == "action" and slot) then
self:SetAttribute("action", slot);
else
SMARTBUFF_AddMsgD("Preclick: not supported actiontype -> " .. actionType);
end
SG.tLastCheck = GetTime() - SG.O.AutoTimer + SG.GlobalCd;
end
end
end
-- SMARTBUFF_OnPostClick
-- Secure post-click handler: clears button attributes, restores camera zoom and CVars.
-- Parameters:
-- self (Button) SmartBuff_KeyButton secure action button
-- button (string) Mouse button name
-- down (boolean) True if the button was pressed, false if released
-- Returns: nothing
function SMARTBUFF_OnPostClick(self, button, down)
if (not SG.isInit) then return end
if (button and not SG.isPrompting) then
if (button == "MOUSEWHEELUP") then
CameraZoomIn(1);
elseif (button == "MOUSEWHEELDOWN") then
CameraZoomOut(1);
end
end
if (InCombatLockdown()) then return end
self:SetAttribute("type", nil);
self:SetAttribute("unit", nil);
self:SetAttribute("spell", nil);
self:SetAttribute("item", nil);
self:SetAttribute("target-slot", nil);
self:SetAttribute("target-item", nil);
self:SetAttribute("macrotext", nil);
self:SetAttribute("action", nil);
if not SG.O.HideSAButtonNoAction and not SG.O.HideSAButton then
SMARTBUFF_SetButtonTexture(SmartBuff_KeyButton, SG.imgSB);
end
-- if cvarChanged is true then it was originally set to 0, we need to put it back.
if (cvarChanged) then
C_CVar.SetCVar("ActionButtonUseKeyDown", 0);
cvarChanged = false;
end
end
-- SMARTBUFF_SetButtonTexture
-- Updates the SmartBuff action button icon when the texture changes.
-- Parameters:
-- button (Button) Button frame to update
-- texture (string) Texture path or file ID for the normal texture
-- text (string) Optional label text (currently unused)
-- Returns: nothing
function SMARTBUFF_SetButtonTexture(button, texture, text)
if (button and texture and texture ~= SG.sLastTexture) then
SG.sLastTexture = texture;
button:SetNormalTexture(texture);
if (text) then
--button.title:SetText(spell);
end
end
end