-
Notifications
You must be signed in to change notification settings - Fork 4
/
core.lua
1342 lines (1015 loc) · 40.3 KB
/
core.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
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local _, SELFAQ = ...
local debug = SELFAQ.debug
local clone = SELFAQ.clone
local diff = SELFAQ.diff
local diff2 = SELFAQ.diff2
local L = SELFAQ.L
local player = SELFAQ.player
local initSV = SELFAQ.initSV
local GetItemTexture = SELFAQ.GetItemTexture
local GetItemEquipLoc = SELFAQ.GetItemEquipLoc
local tableInsert = SELFAQ.tableInsert
local loopSlots = SELFAQ.loopSlots
local GetItemLink = SELFAQ.GetItemLink
local GetEnchanitID = SELFAQ.GetEnchanitID
local findCarrot = SELFAQ.findCarrot
local findSwim = SELFAQ.findSwim
local chatInfo = SELFAQ.chatInfo
local popupInfo = SELFAQ.popupInfo
local AddonEquipItemByName = SELFAQ.AddonEquipItemByName
-- 初始化插件
function SELFAQ.addonInit()
SELFAQ.buildBlockTable()
SELFAQ.addItems()
SELFAQ.updateAllItems( )
SELFAQ.settingInit()
SELFAQ.superInit()
SELFAQ.suitInit()
end
function SELFAQ.updateAllItems( )
-- 检查pvp饰品
for k,v in pairs(SELFAQ.pvpSet) do
if GetItemCount(v) > 0 then
table.insert(SELFAQ.pvp, v)
end
end
SELFAQ.undeadTrinket = 0
for k,v in pairs({13209, 19812, 23206, 23207}) do
if GetItemCount(v) > 0 then
SELFAQ.undeadTrinket = v
end
end
SELFAQ.checkUsable()
loopSlots(SELFAQ.initGroupCheckbox)
SELFAQ.checkItems()
end
function aetest( )
-- local t1 = loadstring("function t2() print(1234) end")
-- local res, info = pcall(t1)
-- if res then
-- t1()
-- t1 = nil
-- else
-- print(info)
-- end
-- print(1)
-- res, info = pcall(t2)
-- print(res)
-- if res then
-- -- t2()
-- t2 = nil
-- else
-- print(info)
-- end
-- local t1 = loadstring("function t2() print(5678) end")
-- res, info = pcall(t1)
-- if res then
-- t1()
-- t1 = nil
-- else
-- print(info)
-- end
-- res, info = pcall(t2)
-- print(res)
-- if res then
-- t2()
-- t2 = nil
-- else
-- print(info)
-- end
-- print(GetUnitName("target"))
local name, type, difficultyIndex, difficultyName, maxPlayers,
dynamicDifficulty, isDynamic, instanceMapId, lfgID = GetInstanceInfo()
print(name, type, difficultyIndex, difficultyName, maxPlayers,
dynamicDifficulty, isDynamic, instanceMapId, lfgID)
-- print(GetItemCooldown(21180))
-- print(GetSpellInfo(1973))
-- print(SELFAQ.getItemLevel(21180))
-- SELFAQ.putSuit2Bank(4)
-- print(GetItemTexture(19339))
-- debug(GetNumBankSlots())
-- debug(UnitCreatureType("target"))
end
SELFAQ.buildBlockTable =function()
SELFAQ.blockTable = {}
local str = string.gsub(AQSV.blockItems,",", ",")
local t = {strsplit(",", strtrim(str))}
for k,v in pairs(t) do
v = tonumber(v)
if v then
table.insert(SELFAQ.blockTable, v)
end
end
end
SELFAQ.addItems = function()
-- 兼容全角逗号
AQSV.additionItems = string.gsub(AQSV.additionItems,",", ",")
local t = { strsplit(",", AQSV.additionItems) }
for k,v in pairs(t) do
-- 去掉两端空格
v= strtrim(v)
local id, time = strsplit("/", v)
-- 避免非数字的情况
id = tonumber(id)
time = tonumber(time)
-- 避免nil的情况
if id then
local slot_id = SELFAQ.GetItemSlot(id)
if slot_id > 0 then
if SELFAQ.usable[slot_id] == nil then
SELFAQ.usable[slot_id] = {}
end
if not tContains(SELFAQ.usable[slot_id], id) and id and time then
table.insert(SELFAQ.usable[slot_id], id)
SELFAQ.buffTime[id] = time
if AQSV.pvpTrinkets[id] == nil then
AQSV.pvpTrinkets[id] = false
end
if AQSV.pveTrinkets[id] == nil then
AQSV.pveTrinkets[id] = false
end
end
-- 手动修改buff持续时间
if id and time then
SELFAQ.buffTime[id] = time
end
end
end
end
end
SELFAQ.initGroupCheckbox = function(slot_id)
for k,v in pairs(SELFAQ.pvp) do
if AQSV.pveTrinkets[v] == nil then
AQSV.pveTrinkets[v] = false
end
end
for k,v in pairs(AQSV.usableItems[slot_id]) do
if AQSV.pvpTrinkets[v] == nil then
AQSV.pvpTrinkets[v] = false
end
if AQSV.pveTrinkets[v] == nil then
AQSV.pveTrinkets[v] = false
end
if AQSV.queue13[v] == nil then
AQSV.queue13[v] = true
end
if AQSV.queue14[v] == nil then
AQSV.queue14[v] = true
end
end
end
-- 检查主动饰品
SELFAQ.checkUsable = function()
-- 删除没有或者放在银行里的主动饰品,并保持优先级不变
SELFAQ.needSlots = {}
for sid,items in pairs(SELFAQ.usable) do
local new = {}
if not AQSV.usableItems[sid] then
AQSV.usableItems[sid] = {}
end
for i,v in pairs(AQSV.usableItems[sid]) do
if GetItemCount(v) > 0 and not tContains(new, v) and tContains(SELFAQ.usable[sid], v) then
table.insert(new, v)
end
-- debug(new)
end
AQSV.usableItems[sid] = new
-- 获得新饰品,或者从银行取出,保持优先级不变,追加到最后
for i,v in ipairs(SELFAQ.usable[sid]) do
if GetItemCount(v) > 0 and not tContains(AQSV.usableItems[sid], v) then
table.insert(AQSV.usableItems[sid], v)
end
end
if #AQSV.usableItems[sid] > 0 then
table.insert(SELFAQ.needSlots, sid)
end
end
table.sort(SELFAQ.needSlots)
local new = {}
for k,v in pairs(SELFAQ.needSlots) do
if v == 13 then
table.insert(new, 1, v)
else
table.insert(new, v)
end
end
SELFAQ.needSlots = new
SELFAQ.updateButtonSwitch()
end
-- 检查角色身上所有的饰品
SELFAQ.checkItems = function( )
wipe(SELFAQ.empty6)
SELFAQ.items = SELFAQ.empty6
wipe(SELFAQ.empty7)
-- 保存饰品在背包中的位置
SELFAQ.itemInBags = SELFAQ.empty7
for i=1,18 do
if i ~= 4 then
SELFAQ.items[i] = tableInsert(SELFAQ.items[i], 0)
local id = GetInventoryItemID("player", i)
if id then
-- 保存身上的装备
SELFAQ.itemInBags[id] = 1000*i
tableInsert(SELFAQ.items[i], id)
if i == 11 or i == 13 then
SELFAQ.items[i+1] = tableInsert(SELFAQ.items[i+1], id)
elseif i == 12 or i == 14 then
SELFAQ.items[i-1] = tableInsert(SELFAQ.items[i-1], id)
elseif i == 16 or i == 17 then
if(GetItemEquipLoc(id) == "INVTYPE_WEAPON") then
SELFAQ.items[33-i] = tableInsert(SELFAQ.items[33-i], id)
end
end
if i == 8 or i == 10 then
local link = GetInventoryItemLink("player",i)
findCarrot(id, i, link)
elseif i == 13 or i == 14 then
findCarrot(id, 13)
elseif i == 1 and i == 6 or i == 16 then
findSwim(id, i)
end
end
end
end
for i=0,NUM_BAG_SLOTS do
local count = GetContainerNumSlots(i)
for s=1,count do
if GetContainerItemInfo(i,s) then
-- fix:背包槽位是空的时候,会中断循环
local id = GetContainerItemID(i,s)
-- 不在屏蔽列表里
if not tContains(SELFAQ.blockTable, id) then
local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture, itemSellPrice = GetItemInfo(id)
-- debug(itemEquipLoc)
-- if id == 7961 then
-- print(itemEquipLoc)
-- end
if itemEquipLoc ~= "" and itemEquipLoc ~= "INVTYPE_AMMO" then
-- 拥有物品的个数,计算出内部id
id = SELFAQ.findItemsOrder(id)
SELFAQ.itemInBags[id] = i*100 + s
end
if itemEquipLoc == "INVTYPE_TRINKET" then
table.insert(SELFAQ.items[13], id)
table.insert(SELFAQ.items[14], id)
findCarrot(id, 13)
elseif itemEquipLoc == "INVTYPE_CHEST" or itemEquipLoc == "INVTYPE_ROBE" then
table.insert(SELFAQ.items[5], id)
elseif itemEquipLoc == "INVTYPE_HEAD" then
table.insert(SELFAQ.items[1], id)
findSwim(id, 1)
elseif itemEquipLoc == "INVTYPE_NECK" then
table.insert(SELFAQ.items[2], id)
elseif itemEquipLoc == "INVTYPE_SHOULDER" then
table.insert(SELFAQ.items[3], id)
elseif itemEquipLoc == "INVTYPE_WAIST" then
table.insert(SELFAQ.items[6], id)
findSwim(id, 6)
elseif itemEquipLoc == "INVTYPE_LEGS" then
table.insert(SELFAQ.items[7], id)
elseif itemEquipLoc == "INVTYPE_FEET" then
table.insert(SELFAQ.items[8], id)
local link = GetContainerItemLink(i, s)
findCarrot(id, 8, link)
elseif itemEquipLoc == "INVTYPE_WRIST" then
table.insert(SELFAQ.items[9], id)
elseif itemEquipLoc == "INVTYPE_HAND" then
table.insert(SELFAQ.items[10], id)
local link = GetContainerItemLink(i, s)
findCarrot(id, 10, link)
elseif itemEquipLoc == "INVTYPE_FINGER" then
table.insert(SELFAQ.items[11], id)
table.insert(SELFAQ.items[12], id)
elseif itemEquipLoc == "INVTYPE_CLOAK" then
table.insert(SELFAQ.items[15], id)
elseif itemEquipLoc == "INVTYPE_WEAPON" then
table.insert(SELFAQ.items[16], id)
table.insert(SELFAQ.items[17], id)
elseif itemEquipLoc == "INVTYPE_SHIELD" or itemEquipLoc == "INVTYPE_WEAPONOFFHAND" or itemEquipLoc == "INVTYPE_HOLDABLE" then
table.insert(SELFAQ.items[17], id)
elseif itemEquipLoc == "INVTYPE_2HWEAPON" or itemEquipLoc == "INVTYPE_WEAPONMAINHAND" then
table.insert(SELFAQ.items[16], id)
-- 水藤是双手武器
findSwim(id, 16)
elseif itemEquipLoc == "INVTYPE_RANGED" or itemEquipLoc == "INVTYPE_THROWN" or itemEquipLoc == "INVTYPE_RANGEDRIGHT" or itemEquipLoc == "INVTYPE_RELIC" then
table.insert(SELFAQ.items[18], id)
end
end
end
end
end
-- loopSlots(function(slot_id)
-- -- 去掉主动饰品
-- -- SELFAQ.items[slot_id] = diff2(SELFAQ.items[slot_id], AQSV.usableItems[slot_id])
-- -- 降幂排序,序号大的正常来看是等级高的饰品
-- table.sort(SELFAQ.items[slot_id], function(a, b)
-- -- 报错:table必须是从1到n连续的,即中间不能有nil,否则会报错
-- return a > b
-- end)
-- end)
-- debug(SELFAQ.itemInBags)
end
SELFAQ.updateItemInBags = function()
for i=0,NUM_BAG_SLOTS do
local count = GetContainerNumSlots(i)
for s=1,count do
if GetContainerItemInfo(i,s) then
-- fix:背包槽位是空的时候,会中断循环
local id = GetContainerItemID(i,s)
-- if id ~= "" then
local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture, itemSellPrice = GetItemInfo(id)
if itemEquipLoc ~= "" then
if SELFAQ.itemInBags[id] then
SELFAQ.itemInBags[id][1] = i
SELFAQ.itemInBags[id][2] = s
else
SELFAQ.itemInBags[id] = {i,s}
end
end
end
end
end
end
-- 获取当前装备饰品的状态
SELFAQ.getTrinketStatusBySlotId = function( slot_id, queue )
wipe(SELFAQ["e"..(slot_id%2)])
local slot = SELFAQ["e"..(slot_id%2)]
slot["id"] = GetInventoryItemID("player", slot_id)
-- 修正slot为空时出现的问题
if slot["id"] == nil then
slot["id"] = 0
end
-- 获取饰品的冷却状态
slot["start"], slot["duration"], slot["enable"] = GetItemCooldown(slot["id"])
-- 剩余冷却时间
slot["rest"] = slot["duration"] - GetTime() + slot["start"]
-- buff已经持续的时长
slot["buff"] = GetTime() - slot["start"]
slot["busy"] = false
if slot_id == 13 or slot_id == 14 then
if tContains(queue, slot["id"]) and AQSV["queue"..slot_id][slot["id"]] then
slot["busy"] = true
end
else
if tContains(queue, slot["id"]) then
slot["busy"] = true
end
end
if AQSV.slotStatus[slot_id].locked then
slot["busy"] = true
end
-- 如果buff时间没有记录,默认为0
if SELFAQ.buffTime[slot["id"]] == nil then
SELFAQ.buffTime[slot["id"]] = 0
end
-- 如果当前饰品可用,或者剩余时间30秒之内,取消CD锁
-- 主动换饰品后,延迟5秒判断,避免出现实际判断的是上一个饰品
-- 增加cd锁判断,避免一直取消cd锁
if (slot["duration"] <= 30 or slot["rest"] <30) and (GetTime() - AQSV.slotStatus[slot_id].lockedTime) > 5 and AQSV.slotStatus[slot_id].lockedCD then
debug("unlock cd")
AQSV.slotStatus[slot_id].lockedCD = false
AQSV.slotStatus[slot_id].lockedTime = 0
end
-- 饰品已经使用,并且超过了buff时间
-- 剩余时间要大于30,避免饰品使用后,但是cd快到了,还被换下
-- 主动CD锁判断
if slot["duration"] > 30 and slot["buff"] > SELFAQ.buffTime[slot["id"]] and slot["rest"] > 30 and not AQSV.slotStatus[slot_id].lockedCD then
slot["busy"] = false
-- 饰品使用后,取消锁定
SELFAQ.cancelLocker( slot_id )
end
-- 饰品已经使用
-- buff大于5秒,避免延时误判
if slot["duration"] > 30 and slot["buff"] > 5 and slot["buff"] <= SELFAQ.buffTime[slot["id"]] then
local spellName = GetItemSpell(slot["id"])
if spellName then
local index = 1
local find = false
local name, icon, count, debuffType, duration, expire = UnitBuff("player", index)
while name do
if spellName == name then
name = nil
find = true
else
index = index + 1
name, icon, count, debuffType, duration, expire = UnitBuff("player", index)
end
end
-- 找不到buff名称
if not find then
debug("not find")
slot["busy"] = false
SELFAQ.cancelLocker( slot_id )
end
end
end
-- 使用busy属性,控制饰品槽是否参与更换逻辑
-- 禁用14的话,总是返回busy
if slot_id == 14 and AQSV.disableSlot14 then
slot["busy"] = true
end
-- 自动换萝卜
if slot_id == 14
and (not AQSV.slotStatus[14].locked or AQSV.forceAcc)
and AQSV.enableCarrot
and SELFAQ.carrot > 0
then
-- 不用处理下马逻辑,因为更换主动饰品逻辑直接起效
if(IsMounted()
and not UnitOnTaxi("player")
and not (AQSV.pauseAccWhenTarget and SELFAQ.targetEnemy)
and not (AQSV.pauseAccWhenTargetFriend and SELFAQ.targetFriend)
and not (AQSV.pauseAccWhenTargetMember and SELFAQ.targetEnemyMember)
) then
-- 战场判断放这里,不然进战场不会换下
-- 副本里也不使用
-- if not SELFAQ.inInstance() then
if (not SELFAQ.inInstance()) -- 不在副本里
or AQSV.enableAccInstance -- 副本生效
then
if slot["id"] ~= SELFAQ.carrot then
AQSV.carrotBackup = slot["id"]
AddonEquipItemByName(SELFAQ.carrot, 14)
-- collectgarbage("collect")
end
-- 骑马时一直busy,中断更换主动饰品的逻辑
slot["busy"] = true
slot["priority"] = 0
end
elseif slot["id"] == SELFAQ.carrot and (AQSV.disableSlot14 or AQSV.slotStatus[14].locked or (#queue== 0 and AQSV.slotStatus[14].backup == 0)) then
-- 禁用14的时候,主动饰品是空的时候,需要追加换下萝卜的逻辑
-- 避免不停更换萝卜
if AQSV.carrotBackup == SELFAQ.carrot then
AQSV.carrotBackup = 0
end
if AQSV.carrotBackup == slot["id"] then
AQSV.carrotBackup = 0
end
-- print(AQSV.disableSlot14, #queue)
if AQSV.carrotBackup > 0 then
debug("carrot")
AddonEquipItemByName(AQSV.carrotBackup, 14)
end
end
end
-- 自动换手套或靴子
if tContains({8,10}, slot_id) and SELFAQ["ride"..slot_id] >0 and (not AQSV.slotStatus[slot_id].locked or AQSV.forceAcc) and AQSV.enableCarrot then
local link = GetInventoryItemLink("player",slot_id)
local enchantId = GetEnchanitID(link)
-- 不用处理下马逻辑,因为更换主动饰品逻辑直接起效
if(IsMounted()
and not UnitOnTaxi("player")
and not (AQSV.pauseAccWhenTarget and SELFAQ.targetEnemy)
and not (AQSV.pauseAccWhenTargetFriend and SELFAQ.targetFriend)
and not (AQSV.pauseAccWhenTargetMember and SELFAQ.targetEnemyMember)
) then
-- 战场判断放这里,不然进战场不会换下
-- 副本里也不使用
if (not SELFAQ.inInstance()) -- 不在副本里
or AQSV.enableAccInstance -- 副本生效
or (AQSV.enableAccTAQ and SELFAQ.inTAQ()) -- TAQ生效功能
then
if enchantId ~= "930" and enchantId ~= "464" and SELFAQ["ride"..slot_id] > 0 then
AQSV["backup"..slot_id] = slot["id"]
-- 存在两个相同物品的可能
SELFAQ.equipByID(SELFAQ["ride"..slot_id], slot_id)
-- collectgarbage("collect")
end
-- 骑马时一直busy,中断更换主动饰品的逻辑
slot["busy"] = true
slot["priority"] = 0
end
elseif AQSV["backup"..slot_id] > 0 and (AQSV.slotStatus[slot_id].locked or (#queue== 0 and AQSV.slotStatus[slot_id].backup == 0)) then
-- print( AQSV["backup"..slot_id], SELFAQ["ride"..slot_id])
-- 禁用14的时候,主动饰品是空的时候,需要追加换下萝卜的逻辑
-- 避免不停更换萝卜
if AQSV["backup"..slot_id] == SELFAQ["ride"..slot_id] then
AQSV["backup"..slot_id] = 0
end
if AQSV["backup"..slot_id] == slot["id"] then
AQSV["backup"..slot_id] = 0
end
if AQSV["backup"..slot_id] > 0 then
AddonEquipItemByName(AQSV["backup"..slot_id], slot_id)
end
end
end
-- 自动换水藤
if tContains({1,6,16}, slot_id) and SELFAQ["swim"..slot_id] >0 and (not AQSV.slotStatus[slot_id].locked or AQSV.forceAcc) and AQSV.enableSwim then
-- 不用处理下马逻辑,因为更换主动饰品逻辑直接起效
if
IsSwimming()
and not (AQSV.pauseAccWhenTarget and SELFAQ.targetEnemy)
and not (AQSV.pauseAccWhenTargetFriend and SELFAQ.targetFriend)
and not (AQSV.pauseAccWhenTargetMember and SELFAQ.targetEnemyMember)
then
if (not SELFAQ.inInstance()) -- 不在副本里
or AQSV.enableAccInstance -- 副本生效
then
if slot["id"] ~= SELFAQ["swim"..slot_id] and SELFAQ["swim"..slot_id] > 0 then
AQSV["backup"..slot_id] = slot["id"]
if slot_id == 16 then
local slot17 = GetInventoryItemID("player", 17)
-- 修正slot为空时出现的问题
if slot17 == nil then
slot17 = 0
end
AQSV["backup17"] = slot17
end
-- 存在两个相同物品的可能
SELFAQ.equipByID(SELFAQ["swim"..slot_id], slot_id)
end
-- 骑马时一直busy,中断更换主动饰品的逻辑
slot["busy"] = true
slot["priority"] = 0
end
elseif AQSV["backup"..slot_id] > 0 and (AQSV.forceAcc or (#queue== 0 and AQSV.slotStatus[slot_id].backup == 0)) then
if AQSV["backup"..slot_id] > 0 then
AddonEquipItemByName(AQSV["backup"..slot_id], slot_id)
if slot_id == 16 and AQSV["backup17"] > 0 then
AddonEquipItemByName(AQSV["backup17"], 17)
end
end
if AQSV["backup"..slot_id] == SELFAQ["swim"..slot_id] then
if slot_id == 16 then
AQSV["backup17"] = 0
end
AQSV["backup"..slot_id] = 0
end
if AQSV["backup"..slot_id] == slot["id"] then
AQSV["backup"..slot_id] = 0
if slot_id == 16 then
AQSV["backup17"] = 0
end
end
end
end
return slot
end
function SELFAQ.buildQueueRealtime(slot_id)
wipe(SELFAQ.empty1)
if not AQSV.enable then
return SELFAQ.empty1
end
local queue = SELFAQ.empty1
local inBattleground = UnitInBattleground("player")
if not AQSV.usableItems[slot_id] then
return queue
end
for k,v in pairs(AQSV.usableItems[slot_id]) do
if inBattleground or AQSV.pvpMode then
SELFAQ.pvpIcon:Show()
if AQSV.pvpTrinkets[v] then
table.insert(queue, v)
end
elseif AQSV.enableRaidQueue and SELFAQ.inInstance() then
if AQSV.raidTrinkets[v] then
table.insert(queue, v)
end
else
SELFAQ.pvpIcon:Hide()
if AQSV.pveTrinkets[v] then
table.insert(queue, v)
end
end
end
return queue
end
function SELFAQ.changeTrinket()
-- 主要代码部分 --
local queue = SELFAQ.buildQueueRealtime(13)
-- 获取当前饰品的状态
local slot13 = SELFAQ.getTrinketStatusBySlotId(13, queue)
local slot14 = SELFAQ.getTrinketStatusBySlotId(14, queue)
-- 如果没有主动饰品,则停止更换饰品
-- if #queue == 0 then
-- return
-- end
-- 强制优先级处理
if AQSV.forcePriority then
-- 找到13、14的优先级
slot13["priority"] = 1000
if slot14["priority"] == nil then
slot14["priority"] = 1000
end
for k,v in pairs(queue) do
if v == slot13["id"] then
slot13["priority"] = k
end
if v == slot14["id"] then
slot14["priority"] = k
end
-- 获取队列里饰品的冷却状态
local start, duration, enable = GetItemCooldown(v)
-- 剩余冷却时间
local rest = duration - GetTime() + start
-- 饰品是可用状态,或者剩余时间30秒之内
if (duration == 0 or rest < 30) and v ~= slot13["id"] and v ~= slot14["id"] then
if k < slot13["priority"] and not AQSV.slotStatus[13].locked and AQSV.queue13[v] then
AddonEquipItemByName(v, 13)
slot13["busy"] = true
slot13["priority"] = k
-- SELFAQ.cancelLocker( 13 )
elseif k < slot14["priority"] and not AQSV.slotStatus[14].locked and not AQSV.disableSlot14 and AQSV.queue14[v] then
AddonEquipItemByName(v, 14)
slot14["busy"] = true
slot14["priority"] = k
-- SELFAQ.cancelLocker( 14 )
end
end
end
end
-- 13、14都装备主动饰品,退出函数
if slot13["busy"] and slot14["busy"] then
return
end
-- 遍历饰品队列
if not AQSV.forcePriority then
for i,v in ipairs(queue) do
-- 获取队列里饰品的冷却状态
local start, duration, enable = GetItemCooldown(v)
-- 剩余冷却时间
local rest = duration - GetTime() + start
-- 饰品是可用状态,或者剩余时间30秒之内
if duration == 0 or rest < 30 then
-- 当前不在13或14槽里
if v ~= slot13["id"] and v ~= slot14["id"] then
-- 优先13
if not slot13["busy"] and AQSV.queue13[v] then
AddonEquipItemByName(v, 13)
slot13["busy"] = true
elseif not slot14["busy"] and AQSV.queue14[v] then
AddonEquipItemByName(v, 14)
slot14["busy"] = true
end
end
end
-- 13、14都装备主动饰品,退出函数
if slot13["busy"] and slot14["busy"] then
return
end
end
end
-- 处理银色黎明饰品
-- if SELFAQ.targetUndead then
-- if slot13["id"] ~= 13209 or slot14["id"] ~= 13209 then
-- if not slot13["busy"] and 13209 ~= slot13["id"] then
-- AddonEquipItemByName(13209, 13)
-- slot13["busy"] = true
-- end
-- if not slot14["busy"] and 13209 ~= slot14["id"] then
-- AddonEquipItemByName(13209, 14)
-- slot14["busy"] = true
-- end
-- end
-- end
-- 遍历发现没有可用的主动饰品,则更换被动饰品
if AQSV.enableFixedPosition then
-- 备选饰品固定位置
-- if not slot13["busy"] and AQSV.slotStatus[13].backup ~= slot13["id"] and AQSV.slotStatus[13].backup >0 then
-- AddonEquipItemByName(AQSV.slotStatus[13].backup, 13)
-- end
if (AQSV.enableTargetUndead and SELFAQ.targetUndead
or (AQSV.enableInUndeadInstance and SELFAQ.inStsmTL() )
or (AQSV.enableInUndeadInstance and SELFAQ.inNaxx() and not SELFAQ.targetNotUndead) )
and SELFAQ.undeadTrinket > 0
and AQSV.undeadPosition == 1
then
if not slot13["busy"] and SELFAQ.undeadTrinket ~= slot13["id"] then
AddonEquipItemByName(SELFAQ.undeadTrinket, 13)
end
else
if not slot13["busy"] and AQSV.slotStatus[13].backup ~= slot13["id"] and AQSV.slotStatus[13].backup >0 then
AddonEquipItemByName(AQSV.slotStatus[13].backup, 13)
end
end
if (AQSV.enableTargetUndead and SELFAQ.targetUndead
or (AQSV.enableInUndeadInstance and SELFAQ.inStsmTL() )
or (AQSV.enableInUndeadInstance and SELFAQ.inNaxx() and not SELFAQ.targetNotUndead) )
and SELFAQ.undeadTrinket > 0
and AQSV.undeadPosition == 2
then
if not slot14["busy"] and SELFAQ.undeadTrinket ~= slot14["id"] then
AddonEquipItemByName(SELFAQ.undeadTrinket, 14)
end
else
if not slot14["busy"] and AQSV.slotStatus[14].backup ~= slot14["id"] and AQSV.slotStatus[14].backup >0 then
AddonEquipItemByName(AQSV.slotStatus[14].backup, 14)
end
end
else
-- 备选饰品优先级模式
local b1 = AQSV.slotStatus[13].backup
local b2 = AQSV.slotStatus[14].backup
-- debug( SELFAQ.inStsmTL())
-- 银色黎明自动换
if (AQSV.enableTargetUndead and SELFAQ.targetUndead
or (AQSV.enableInUndeadInstance and SELFAQ.inStsmTL() )
or (AQSV.enableInUndeadInstance and SELFAQ.inNaxx() and not SELFAQ.targetNotUndead) )
and SELFAQ.undeadTrinket > 0 then
if AQSV.undeadPosition == 1 then
b2 = b1
b1 = SELFAQ.undeadTrinket
end
if AQSV.undeadPosition == 2 then
b2 = SELFAQ.undeadTrinket
end
end
if b1 >0 and b1 ~= slot13["id"] and b1 ~= slot14["id"] then
if not slot13["busy"] then
AddonEquipItemByName(b1, 13)
slot13["busy"] = true
elseif not slot14["busy"] then
AddonEquipItemByName(b1, 14)
slot14["busy"] = true
end
end
if b2 >0 and b2 ~= slot13["id"] and b2 ~= slot14["id"] then
if not slot13["busy"] and b1 ~= slot13["id"] then
AddonEquipItemByName(b2, 13)
slot13["busy"] = true
elseif not slot14["busy"] and b1 ~= slot14["id"] then
AddonEquipItemByName(b2, 14)
slot14["busy"] = true
end
end
end
end
function SELFAQ.changeItem(slot_id)
-- 主要代码部分 --
-- debug(slot_id)
local queue = SELFAQ.buildQueueRealtime(slot_id)
-- 获取当前饰品的状态
local slot13 = SELFAQ.getTrinketStatusBySlotId(slot_id, queue)
-- 如果没有主动饰品,则停止更换饰品
-- if #queue == 0 then
-- return
-- end
-- 强制优先级处理
if AQSV.forcePriority then
-- 找到13、14的优先级
slot13["priority"] = 1000
for k,v in pairs(queue) do
if v == slot13["id"] then
slot13["priority"] = k
end
-- 获取队列里饰品的冷却状态
local start, duration, enable = GetItemCooldown(v)
-- 剩余冷却时间
local rest = duration - GetTime() + start
-- 饰品是可用状态,或者剩余时间30秒之内
if (duration == 0 or rest < 30) and v ~= slot13["id"] then
if k < slot13["priority"] and not AQSV.slotStatus[slot_id].locked then
AddonEquipItemByName(v, slot_id)
slot13["busy"] = true
slot13["priority"] = k
end
end
end