forked from kakaZzzz/AutoEquip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.lua
593 lines (453 loc) · 13.2 KB
/
base.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
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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
local _, SELFAQ = ...
local L = SELFAQ.L
SELFAQ.fixSetBackdrop = function(frame,backdrop)
if frame.SetBackdrop then return frame:SetBackdrop(backdrop) end
Mixin(frame,BackdropTemplateMixin)
frame:SetScript("OnSizeChanged",frame.OnBackdropSizeChanged,0)
frame:SetBackdrop(backdrop)
frame:OnBackdropLoaded()
end
-- 复制table的数据,而不是引用
SELFAQ.clone = function(org)
local function copy(org, res)
for k,v in pairs(org) do
if type(v) ~= "table" then
res[k] = v;
else
res[k] = {};
copy(v, res[k])
end
end
end
local res = {}
copy(org, res)
return res
end
SELFAQ.tableInsert = function(t,v)
if t == nil then
t = {}
end
if v then
table.insert(t,v)
end
return t
end
-- 合并两个数组
SELFAQ.merge = function(...)
local tabs = {...}
if not tabs then
return {}
end
local origin = tabs[1]
for i = 2,#tabs do
if origin then
if tabs[i] then
for k,v in pairs(tabs[i]) do
table.insert(origin,v)
end
end
else
origin = tabs[i]
end
end
return origin
end
-- 去掉重复的值
SELFAQ.diff = function( t1, t2 )
wipe(SELFAQ.empty3)
local new = SELFAQ.empty3
for i,v in ipairs(t1) do
if not tContains(t2, v) then
table.insert(new, v)
end
end
return new
end
SELFAQ.diff2 = function( t1, t2 )
wipe(SELFAQ.empty4)
local new = SELFAQ.empty4
for i,v in ipairs(t1) do
if not tContains(t2, v) then
table.insert(new, v)
end
end
return new
end
SELFAQ.empty = function( t )
if t == nil then
t = {}
end
wipe(t)
end
SELFAQ.findItemsOrder = function( id )
local count = GetItemCount(id)
local order = 1
local find = false
if count == 1 then
elseif count > 1 then
for index=1,count do
if not find then
local fid = (index-1)*1000000 + id
-- print(SELFAQ.itemInBags[fid])
if SELFAQ.itemInBags[fid] == nil then
order = index
find = true
end
end
end
end
return 1000000*(order-1) + id
end
SELFAQ.reverseId = function( id )
if id == nil then
return 0,0
end
local order = math.floor(id/1000000)
local rid = id%1000000
return rid, order
end
SELFAQ.reverseBagSlot = function( id )
local num = SELFAQ.itemInBags[id]
if num == nil then
return -1
end
local bag = math.floor(num/100)
local slot = num%100
return bag, slot
end
SELFAQ.otherSlot = function(slot_id)
local other = 0
if slot_id == 11 or slot_id == 12 then
other = 23 - slot_id
elseif slot_id == 13 or slot_id == 14 then
other = 27 -slot_id
elseif slot_id == 16 or slot_id == 17 then
other = 33 -slot_id
end
return other
end
SELFAQ.loopSlots = function( func )
for k,v in pairs(SELFAQ.needSlots) do
func(v)
end
end
SELFAQ.shortKey = function(v)
local t = {strsplit("-", v)}
local s = ""
for i=1,#t-1 do
s = s..strsub(t[i],1,1)
end
s = s..t[#t]
if strlen(s) > 3 then
s = strsub(s, 1, 3).."..."
end
return s
end
-- 调试函数
SELFAQ.debug = function(t)
if not SELFAQ.enableDebug then
return
end
if type(t) == "table" then
for k,v in pairs(t) do
if type(v) == "table" then
print("@DEBUG: ",k)
SELFAQ.debug(v)
else
print("@KV: ",k.." =>"..tostring(v))
end
end
else
print("@DEBUG: ",t)
end
end
SELFAQ.getCooldownText = function(rest)
local text = math.floor(rest)
if rest > 3600 then
text = "|cFFFFFFFF"..math.ceil(rest/3600).."|rh"
elseif rest > 60 then
text = "|cFFFFFFFF"..math.ceil(rest/60).."|rm"
end
return text
end
SELFAQ.chatInfo = function(s)
if AQSV.hideChatInfo then
return
end
print(L["prefix"]..s)
end
SELFAQ.initSV = function( v, init )
if v == nil then
if type(init) == "table" then
local t = SELFAQ.clone(init)
return t
end
v = init
end
return v
end
SELFAQ.GetItemLink = function( id )
local id, order = SELFAQ.reverseId(id)
if id == 0 then
return L["[Empty]"]
end
local _, link = GetItemInfo(id)
if link == nil then
return ""
end
if order >0 then
link = link.."#"..order
end
return link
end
SELFAQ.GetEnchanitID = function(link)
if link then
local _, enchantId = link:match("item:(%d+):(%d+)")
return enchantId
else
return 0
end
end
SELFAQ.GetItemEquipLoc = function( id )
local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture, itemSellPrice = GetItemInfo(id)
return itemEquipLoc
end
SELFAQ.GetItemSlot = function( id )
local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture, itemSellPrice = GetItemInfo(id)
local slot = 0
if itemEquipLoc == "INVTYPE_TRINKET" then
slot = 13
elseif itemEquipLoc == "INVTYPE_CHEST" or itemEquipLoc == "INVTYPE_ROBE" then
slot = 5
elseif itemEquipLoc == "INVTYPE_HEAD" then
slot = 1
elseif itemEquipLoc == "INVTYPE_NECK" then
slot = 2
elseif itemEquipLoc == "INVTYPE_SHOULDER" then
slot = 3
elseif itemEquipLoc == "INVTYPE_WAIST" then
slot = 6
elseif itemEquipLoc == "INVTYPE_LEGS" then
slot = 7
elseif itemEquipLoc == "INVTYPE_FEET" then
slot = 8
elseif itemEquipLoc == "INVTYPE_WRIST" then
slot = 9
elseif itemEquipLoc == "INVTYPE_HAND" then
slot = 10
elseif itemEquipLoc == "INVTYPE_FINGER" then
slot = 11
elseif itemEquipLoc == "INVTYPE_CLOAK" then
slot = 15
elseif itemEquipLoc == "INVTYPE_WEAPON" then
slot = 16
elseif itemEquipLoc == "INVTYPE_SHIELD" or itemEquipLoc == "INVTYPE_WEAPONOFFHAND" or itemEquipLoc == "INVTYPE_HOLDABLE" then
slot = 17
elseif itemEquipLoc == "INVTYPE_2HWEAPON" or itemEquipLoc == "INVTYPE_WEAPONMAINHAND" then
slot = 16
elseif itemEquipLoc == "INVTYPE_RANGED" or itemEquipLoc == "INVTYPE_THROWN" or itemEquipLoc == "INVTYPE_RANGEDRIGHT" or itemEquipLoc == "INVTYPE_RELIC" then
slot = 18
end
return slot
end
SELFAQ.GetItemTexture = function( id )
id = SELFAQ.reverseId(id)
local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture, itemSellPrice = GetItemInfo(id)
return itemTexture
end
SELFAQ.GetSlotID = function(slot_id)
local id = GetInventoryItemID("player", slot_id)
if id == nil then
id = 0
end
return id
end
SELFAQ.AddonEquipItemByName = function( item_id, slot_id )
if not SELFAQ.playerCanEquip() then
return
end
EquipItemByName(item_id, slot_id)
local link = SELFAQ.GetItemLink(item_id)
SELFAQ.popupInfo(link)
end
SELFAQ.findCarrot = function( id, slot_id, link )
if slot_id == 13 then
-- 优先装备碎天者之鞭
if id == 32863 and UnitLevel("player") >= 70 then
SELFAQ.carrot = id
-- 其次是马鞭
-- 如果已经有碎天者之鞭,则不更换
elseif id == 25653 and UnitLevel("player") >= 69 and SELFAQ.carrot < 25653 then
SELFAQ.carrot = id
-- 最后是萝卜
elseif id == 11122 and SELFAQ.carrot == 0 then
SELFAQ.carrot = id
end
if not tContains(SELFAQ.needSlots, 13) and SELFAQ.carrot > 0 then
table.insert(SELFAQ.needSlots, 13)
end
return
end
local enchantId = SELFAQ.GetEnchanitID(link)
-- 找到带有秘银马刺的鞋子,保存起来
if enchantId == "464" or enchantId == "930" then
SELFAQ["ride"..slot_id] = id
end
if not tContains(SELFAQ.needSlots, slot_id) and SELFAQ["ride"..slot_id]>0 then
table.insert(SELFAQ.needSlots, slot_id)
end
end
SELFAQ.findSwim = function( id, slot_id )
-- 找到水藤或者碧蓝腰带,保存起来
if id == 7052 or id == 9452 or id == 10506 then
SELFAQ["swim"..slot_id] = id
end
if not tContains(SELFAQ.needSlots, slot_id) and SELFAQ["swim"..slot_id]>0 then
table.insert(SELFAQ.needSlots, slot_id)
end
end
SELFAQ.equipByID = function(item_id, slot_id, popup)
if not SELFAQ.playerCanEquip() then
return
end
if popup == nil then
popup = true
end
if item_id > 1000000 then
local bag,slot = SELFAQ.reverseBagSlot(item_id)
if bag == -1 then
return false
end
ClearCursor()
PickupContainerItem(bag,slot)
if CursorHasItem() then
EquipCursorItem(slot_id)
end
else
EquipItemByName(item_id, slot_id)
end
local rid = SELFAQ.reverseId(item_id)
local link = SELFAQ.GetItemLink(rid)
if popup then
SELFAQ.popupInfo(link)
end
end
SELFAQ.infoFrameIndex = 0
SELFAQ.infoTexts = {}
SELFAQ.popupInfo = function(text)
if AQSV.hidePopupInfo then
return
end
if text == nil then
return
end
-- 避免短时的多次显示
-- print(SELFAQ.infoTexts, tostring(text), tContains(SELFAQ.infoTexts, text))
if tContains(SELFAQ.infoTexts, text) then
return
end
-- 最多显示5条
if SELFAQ.infoFrameIndex >= 5 then
return
end
SELFAQ.infoFrameIndex = SELFAQ.infoFrameIndex + 1
if _G["AutoEquip_Popup"..SELFAQ.infoFrameIndex] == nil then
CreateFrame( "GameTooltip", "AutoEquip_Popup"..SELFAQ.infoFrameIndex, UIParent, "GameTooltipTemplate")
end
local f = _G["AutoEquip_Popup"..SELFAQ.infoFrameIndex]
-- if SELFAQ.infoFrame == nil then
-- SELFAQ.infoFrame = CreateFrame( "GameTooltip", "AutoEquip_Popup", UIParent, "GameTooltipTemplate" )
-- end
-- local f= SELFAQ.infoFrame
if f.moveOut then
f.fadeOut:Stop()
f.moveOut:Stop()
end
f:Hide()
f:SetOwner(UIParent, "ANCHOR_NONE")
f:SetPoint("CENTER", UIParent, AQSV.popupX, -40*(SELFAQ.infoFrameIndex - 1) + AQSV.popupY )
SELFAQ.fixSetBackdrop(f, nil)
f:SetBackdropColor(0,0,0,0.8);
if SELFAQ.infoFrameIndex == 5 then
f:SetText("...")
else
f:SetText(text)
table.insert(SELFAQ.infoTexts, text)
end
_G["AutoEquip_Popup"..SELFAQ.infoFrameIndex.."TextLeft1"]:SetFont(STANDARD_TEXT_FONT, 14)
_G["AutoEquip_Popup"..SELFAQ.infoFrameIndex.."TextLeft1"]:SetTextColor(255,255,255)
f:Show()
if not f.moveOut then -- Upgrade to 39
f.moveOut = f:CreateAnimationGroup()
local animOut = f.moveOut:CreateAnimation("Translation")
animOut:SetOrder(1)
animOut:SetDuration(0.3)
-- animOut:SetFromAlpha(1)
-- animOut:SetToAlpha(0)
animOut:SetOffset(0, 20)
animOut:SetStartDelay(2)
f.moveOut:SetScript("OnFinished",function()
f:Hide()
SELFAQ.infoFrameIndex = 0
wipe(SELFAQ.infoTexts)
-- SELFAQ.debug(SELFAQ.infoFrameIndex)
end)
end
if not f.fadeOut then -- Upgrade to 39
f.fadeOut = f:CreateAnimationGroup()
local animOut = f.fadeOut:CreateAnimation("Alpha")
animOut:SetOrder(1)
animOut:SetDuration(0.3)
animOut:SetFromAlpha(1)
animOut:SetToAlpha(0)
animOut:SetStartDelay(2)
f.fadeOut:SetToFinalAlpha(true)
end
f.fadeOut:Play()
f.moveOut:Play()
end
SELFAQ.comma2Table = function(text)
-- 兼容全角逗号
local s = string.gsub(text,",", ",")
local t = { strsplit(",", s) }
for k,v in pairs(t) do
-- 去掉两端空格
v= strtrim(v)
t[k] = v
end
return t
end
SELFAQ.getItemLevel = function(item_id)
local itemName, itemLink, itemRarity, itemLevel = GetItemInfo(item_id)
if itemRarity == 4 then
return "|cffa335ee"..itemLevel.."|r"
elseif itemRarity == 3 then
return "|cff0070dd"..itemLevel.."|r"
elseif itemRarity == 2 then
return "|cff1eff00"..itemLevel.."|r"
elseif itemRarity == 1 then
return "|cffffffff"..itemLevel.."|r"
else
return ""
end
end
SELFAQ.inNaxx = function()
local name, type, difficultyIndex, difficultyName, maxPlayers,
dynamicDifficulty, isDynamic, instanceMapId, lfgID = GetInstanceInfo()
-- naxx应该是533,待验证
if instanceMapId == 533 or instanceMapId == 532 then
return true
else
return false
end
end
SELFAQ.inStsmTL = function()
local name, type, difficultyIndex, difficultyName, maxPlayers,
dynamicDifficulty, isDynamic, instanceMapId, lfgID = GetInstanceInfo()
-- naxx应该是533,待验证
if instanceMapId == 329 or instanceMapId == 289 then
return true
else
return false
end
end