-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathThievery.lua
More file actions
373 lines (340 loc) · 12.5 KB
/
Thievery.lua
File metadata and controls
373 lines (340 loc) · 12.5 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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
local T = Thievery_Translate
local addonName, tv = ...
local gameVersion = tv.gameVersion
local SAP_SPELLID = 6770
local PICKPOCKET_SPELLID = 921
local function clearTable(teeburu)
for i, v in pairs(teeburu) do
teeburu[i] = nil
end
end
local isAlliance
local faction = UnitFactionGroup("player")
if faction == "Alliance" then
isAlliance = true
elseif faction == "Horde" then
isAlliance = false
end
local target = Thievery_Target
local UIActive = false
local PPMode = false
local sapMode = false
local Session_EnemyIDTable = {
}
local function getIDFromGUID(guid)
if not guid then return end
local starto = 0
local endo = 0
for i=1,5,1 do
starto, endo = string.find(guid, "(%d+)", endo + 1)
if not endo then
print("Thievery: Faulty GUID, please contact addon author.")
return false
end
end
local npcID = string.sub(guid, starto, endo)
return npcID
end
local function printTargetInfo()
Thievery_BetaPrint("Creature Family: ", UnitCreatureFamily("target"))
Thievery_BetaPrint("Creature Type: ", UnitCreatureType("target"))
Thievery_BetaPrint("Classification: ", UnitClassification("target"))
Thievery_BetaPrint(UnitGUID("target"))
Thievery_BetaPrint(getIDFromGUID(UnitGUID("target")))
end
SLASH_THIEVERYTARGETINFO1 = "/teeftarget"
SlashCmdList["THIEVERYTARGETINFO"] = printTargetInfo
local lastPrint
local ppName = C_Spell.GetSpellName(PICKPOCKET_SPELLID)
local sapName = C_Spell.GetSpellName(SAP_SPELLID)
local handleKeybind
local checkSapAura
-- /dump UnitExists("target")
-- /dump UnitExists("softenemy")
--____________________________________________________________________________
-- Pickpocketing through SecureActionButton + OverrideBindingClick
-- bugs out in Classic
-- use SetOverrideBindingSpell directly instead
--____________________________________________________________________________
if gameVersion == 1 then
handleKeybind = function(mode, button, assignKey)
if mode == "pp" then
button:SetAttribute("macrotext", "/cast " .. ppName)
SetOverrideBindingClick(button, true, assignKey, "Thievery_PickpocketButton")
elseif mode == "sap" then
button:SetAttribute("macrotext", "/cast " .. sapName)
SetOverrideBindingClick(button, true, assignKey, "Thievery_PickpocketButton")
end
end
checkSapAura = function()
local sapped = false
local targetString
if UnitExists("target") then
targetString = "target"
elseif UnitExists("softenemy") then
targetString = "softenemy"
end
if not targetString then return false end
AuraUtil.ForEachAura(targetString, "HARMFUL", nil, function(name, icon, _, _, _, _, _, _, _, spellID, ...)
if spellID == SAP_SPELLID then
sapped = true
end
end)
return sapped
end
elseif gameVersion == 2 or gameVersion == 3 or gameVersion == 4 then
handleKeybind = function(mode, button, assignKey)
if mode == "pp" then
SetOverrideBindingSpell(button, true, assignKey, ppName)
elseif mode == "sap" then
SetOverrideBindingSpell(button, true, assignKey, sapName)
end
end
checkSapAura = function()
local sapped = false
AuraUtil.FindAura(function(criteria, _,_,_,_,_,_,_,_,_,_,_,spellID)
if criteria == spellID then
sapped = true
end
end, "target", "HARMFUL", SAP_SPELLID)
return sapped
end
end
local function setPPMode(self)
local remaining = Thievery_UpdatePPTimers(target.guid)
if remaining then
remaining = string.format("%.0f", remaining)
if remaining ~= lastPrint then
lastPrint = remaining
Thievery_BetaPrint("Can pickpocket again in: " .. remaining)
end
end
if not PPMode then
local parent = self:GetParent()
local assignKey = "E"
if Thievery_Config.ppKey then
assignKey = Thievery_Config.ppKey
end
handleKeybind("pp", self, assignKey)
PPMode = true
sapMode = false
parent.visual:Show()
parent.visual.npcName:SetText(target.name)
parent.visual.promptText:SetText(T["Pickpocket"])
if remaining then
parent.visual.promptText:SetTextColor(0.8, 0.8, 0.8)
parent.visual.throughLine:Show()
Thievery_PPCooldownFrame:SetCooldown(GetTime(), remaining)
else
parent.visual.promptText:SetText(T["Pickpocket"])
parent.visual.promptText:SetTextColor(1, 0, 0)
parent.visual.throughLine:Hide()
end
end
end
local function setSapMode(self)
if not sapMode then
local parent = self:GetParent()
local assignKey = "E"
if Thievery_Config.ppKey then
assignKey = Thievery_Config.ppKey
end
handleKeybind("sap", self, assignKey)
PPMode = true
parent.visual:Show()
parent.visual.promptText:SetText(T["Sap"])
parent.visual.promptText:SetTextColor(1, 0, 0)
parent.visual.throughLine:Hide()
parent.visual.npcName:SetText(target.name)
sapMode = true
PPMode = false
end
end
function Thievery_Activate(self)
if InCombatLockdown() then
print("Thievery: State change occured during combat. Please contact author.")
return
end
UIActive = true
local sapped = checkSapAura()
if Thievery_Config.Checkboxes[1].enableSap == true then
if sapped == false then
setSapMode(self)
else
setPPMode(self)
end
else
setPPMode(self)
end
end
function Thievery_Deactivate(self)
if InCombatLockdown() then
print("Thievery: State change occured during combat. Please contact author.")
return
end
if UIActive == true then
local parent = self:GetParent()
ClearOverrideBindings(self)
parent.visual:Hide()
parent.visual.npcName:SetText(nil)
UIActive = false
PPMode = false
sapMode = false
end
end
function Thievery_CheckTargetLocal(target)
if not target then return false end
local npcID = target.npcID
if not npcID then return false end
if Session_EnemyIDTable[npcID] then
if not PPMode and not sapMode then
Thievery_BetaPrint("session match found!")
end
return true
end
end
local stealthed = false
local validTarget = false
function Thievery_UpdateState(self, resetMode)
if InCombatLockdown() then return end
if resetMode then
PPMode = false
sapMode = false
ClearOverrideBindings(self)
end
local inRange = C_Spell.IsSpellInRange(PICKPOCKET_SPELLID)
if stealthed and validTarget and inRange then
if Thievery_CheckTargetLocal(target) then
Thievery_Activate(self)
elseif Thievery_CheckTargetForPP(target, isAlliance) then
Session_EnemyIDTable[target.npcID] = true
Thievery_Activate(self)
else
Thievery_Deactivate(self)
end
else
Thievery_Deactivate(self)
end
end
-- --------------------------------------------------------------------------
local function checkTarget(unitString)
if not UnitExists(unitString) then
--Thievery_BetaPrint("No eligible target")
return false
end
if UnitIsDead(unitString) or UnitIsCorpse(unitString) then
return false
end
if UnitIsPlayer(unitString) then
return false
end
-- 1)player 2)target ORDER ON PURPOSE. To avoid checking reputations
local reaction = UnitReaction("player", unitString)
if reaction ~= 2 and reaction ~= 4 then
return false
end
return true
end
-- ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣤⣤⣤⣤⣤⣤⣤⣤⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀
-- ⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣿⡿⠛⠉⠙⠛⠛⠛⠛⠻⢿⣿⣷⣤⠀⠀⠀⠀⠀
-- ⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⠋⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⠈⢻⣿⣿⡄⠀⠀⠀⠀
-- ⠀⠀⠀⠀⠀⠀⠀⣸⣿⡏⠀⠀⠀⣠⣶⣾⣿⣿⣿⠿⠿⠿⢿⣿⣿⣿⣄⠀⠀⠀
-- ⠀⠀⠀⠀⠀⠀⠀⣿⣿⠁⠀⠀⢰⣿⣿⣯⠁⠀⠀⠀⠀⠀⠀⠀⠈⠙⢿⣷⠀
-- ⠀⠀⣀⣤⣴⣶⣶⣿⡟⠀⠀⢸⣿⣿⣿ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣷⠀
-- ⠀⢰⣿⡟⠋⠉⣹⣿⡇⠀ ⣿⣿⣿⣿⣷⣦⣤⣤⣤⣶⣶⣶⣶⣿⣿⣿⠀
-- ⠀⢸⣿⡇⠀⠀⣿⣿⡇⠀⠀⠀⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿
-- ⠀⣸⣿⡇⠀⠀⣿⣿⡇⠀⠀⠀⠀⠉⠻⠿⣿⣿⣿⣿⡿⠿⠿⠛⢻⣿⡇
-- ⠀⣿⣿⠁⠀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣧⠀⠀
-- ⠀⣿⣿⠀⠀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⠀⠀
-- ⠀⣿⣿⠀⠀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⠀⠀
-- ⠀⢿⣿⡆⠀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⡇⠀⠀
-- ⠀⠸⣿⣧⡀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⠃⠀⠀
-- ⠀⠀⠛⢿⣿⣿⣿⣿⣇⠀⠀⠀⠀⠀⣰⣿⣿⣷⣶⣶⣶⣶⠶⢠⣿⣿⠀⠀⠀
-- ⠀⠀⠀⠀⠀⠀⠀⣿⣿⠀⠀⠀⠀⠀⣿⣿⡇⠀⣽⣿⡏⠁⠀⠀⢸⣿⡇⠀⠀⠀
-- ⠀⠀⠀⠀⠀⠀⠀⣿⣿⠀⠀⠀⠀⠀⣿⣿⡇⠀⢹⣿⡆⠀⠀⠀⣸⣿⠇⠀⠀⠀
-- ⠀⠀⠀⠀⠀⠀ ⢿⣿⣦⣄⣀⣠⣴⣿⣿⠁⠀⠈⠻⣿⣿⣿⣿⡿⠏⠀⠀⠀⠀
-- ⠀⠀⠀⠀⠀⠀⠀⠈⠛⠻⠿⠿⠿⠿⠋⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
-- sus
local function Thievery_CheckHardOrSoft()
if checkTarget("target") == true then return "target" end
if checkTarget("softenemy") == true then return "softenemy" end
return nil
end
-- --------------------------------------------------------------------------
local function checkAndHandleStealth(self)
if IsStealthed() then
stealthed = true
local erapusuThreshold = 0.3
local erapusuCounter = 0
self:SetScript("OnUpdate", function(self, elapsed)
erapusuCounter = erapusuCounter + elapsed
if erapusuCounter < erapusuThreshold then
return
end
erapusuCounter = 0
if InCombatLockdown() then
self:SetScript("OnUpdate", nil)
end
if stealthed == false then
self:SetScript("OnUpdate", nil)
end
Thievery_UpdateState(self)
end)
else
stealthed = false
Thievery_UpdateState(self)
self:SetScript("OnUpdate", nil)
end
end
function Thievery_Events(self, event, unit)
if event == "PLAYER_SOFT_INTERACT_CHANGED" or event == "PLAYER_SOFT_ENEMY_CHANGED" or event == "PLAYER_TARGET_CHANGED" then
PPMode = false
sapMode = false
clearTable(target)
Thievery_PPCooldownFrame:Clear()
if InCombatLockdown() then return end
local targetType = Thievery_CheckHardOrSoft()
if targetType then
validTarget = true
local guid = Thievery_ScrubSecret(UnitGUID(targetType))
if guid then
target.guid = guid
local npcID = getIDFromGUID(target.guid)
target.npcID = tonumber(npcID)
target.name = UnitName(targetType)
local _
_, target.creatureType = UnitCreatureType(targetType)
target.classification = UnitClassification(targetType)
-- 1)player 2)target ORDER ON PURPOSE, to avoid checking reputations
target.reaction = UnitReaction("player", targetType)
end
else
validTarget = false
end
if not IsTargetLoose() then
--printTargetInfo()
end
checkAndHandleStealth(self)
Thievery_UpdateState(self)
elseif event == "UPDATE_STEALTH" then
checkAndHandleStealth(self)
Thievery_UpdateState(self)
elseif event == "PLAYER_REGEN_DISABLED" then
Thievery_Deactivate(self)
Thievery.configPanel.checkboxes2.lockpicking:Disable()
elseif event == "PLAYER_REGEN_ENABLED" then
Thievery_UpdateState(self)
Thievery.configPanel.checkboxes2.lockpicking:Enable()
end
end
-- /dump C_Spell.IsSpellUsable(PICKPOCKET_SPELLID)
-- /dump SpellCanTargetUnit()
-- /dump SpellCanTargetUnit("target")
local nameToID = {
["ContainerFrame1"] = 1,
["ContainerFrame2"] = 2,
["ContainerFrame3"] = 3,
["ContainerFrame4"] = 4,
["ContainerFrame5"] = 5,
["ContainerFrame6"] = 6,
}