forked from Auctionator/Auctionator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Auctionator.lua
executable file
·5257 lines (3553 loc) · 139 KB
/
Auctionator.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
AuctionatorVersion = "???"; -- set from toc upon loading
AuctionatorAuthor = "Borjamacare";
AuctionatorLoaded = false;
AuctionatorInited = false;
local addonName, addonTable = ...;
local ZT = addonTable.ztt.ZT;
local zc = addonTable.zc;
local zz = zc.md;
local _
local ItemUpgradeInfo = LibStub( 'LibItemUpgradeInfo-1.0' )
gAtrZC = addonTable.zc; -- share with AuctionatorDev
-----------------------------------------
local recommendElements = {};
AUCTIONATOR_ENABLE_ALT = 1;
AUCTIONATOR_SHOW_ST_PRICE = 0;
AUCTIONATOR_SHOW_TIPS = 1;
AUCTIONATOR_SHOW_ACTIONS_TIPS = 0;
AUCTIONATOR_DEF_DURATION = "N"; -- none
AUCTIONATOR_V_TIPS = 1;
AUCTIONATOR_A_TIPS = 1;
AUCTIONATOR_AVG_TIPS = 1;
AUCTIONATOR_AVG_TIPS_DAYS = 14; -- must be less than AUCTIONATOR_DB_MAXHIST_DAYS
AUCTIONATOR_D_TIPS = 1;
AUCTIONATOR_SHIFT_TIPS = 1;
AUCTIONATOR_DE_DETAILS_TIPS = 4; -- off by default
AUCTIONATOR_DEFTAB = 1;
AUCTIONATOR_DB_MAXITEM_AGE = 180;
AUCTIONATOR_DB_MAXHIST_AGE = 28; -- obsolete - just needed for migration
AUCTIONATOR_DB_MAXHIST_DAYS = 28;
AUCTIONATOR_OPEN_FIRST = 0; -- obsolete - just needed for migration
AUCTIONATOR_OPEN_BUY = 0; -- obsolete - just needed for migration
local SELL_TAB = 1;
local MORE_TAB = 2;
local BUY_TAB = 3;
-- saved variables - amounts to undercut
local auctionator_savedvars_defaults = {
["_5000000"] = 10000; -- amount to undercut buyouts over 500 gold
["_1000000"] = 2500;
["_200000"] = 1000;
["_50000"] = 500;
["_10000"] = 200;
["_2000"] = 100;
["_500"] = 5;
["STARTING_DISCOUNT"] = 5; -- PERCENT
["LOG_DE_DATA_X"] = true;
}
-----------------------------------------
local auctionator_orig_AuctionFrameTab_OnClick;
local auctionator_orig_ContainerFrameItemButton_OnModifiedClick;
local auctionator_orig_AuctionFrameAuctions_Update;
local auctionator_orig_CanShowRightUIPanel;
local auctionator_orig_ChatEdit_InsertLink;
local auctionator_orig_ChatFrame_OnEvent;
local gForceMsgAreaUpdate = true;
local gAtr_ClickAuctionSell = false;
local gTimeZero;
local gTimeTightZero;
local cslots = {};
local gEmptyBScached = nil;
local gAutoSingleton = 0;
local gTradeSkillFrameModded = false
-- set to the last item posted, even after the posting so that message and icon can be displayed
local gJustPosted = { ItemName=nil, ItemLink=nil, BuyoutPrice=0, StackSize=0, NumStacks=0 }
local auctionator_pending_message = nil;
local kBagIDs = {};
local Atr_Confirm_Proc_Yes = nil;
local gStartingTime = time();
local gHentryTryAgain = nil;
local gCondensedThisSession = {};
local gAtr_Owner_Item_Indices = {};
local ITEM_HIST_NUM_LINES = 20;
local gActiveAuctions = {};
local gHlistNeedsUpdate = false;
local gAtr_SellTriggeredByAuctionator = false;
local gSellPane;
local gMorePane;
local gActivePane;
local gShopPane;
local gCurrentPane;
local gHistoryItemList = {};
local ATR_CACT_NULL = 0;
local ATR_CACT_READY = 1;
local ATR_CACT_PROCESSING = 2;
local ATR_CACT_WAITING_ON_CANCEL_CONFIRM = 3;
gATR_BattlePetIconCache = {};
local gItemPostingInProgress = false;
gAtr_ptime = nil; -- a more precise timer but may not be updated very frequently
gAtr_ScanDB = nil;
gAtr_PriceHistDB = nil;
-----------------------------------------
ATR_SK_GLYPHS = "*_glyphs";
ATR_SK_GEMS_CUT = "*_gemscut";
ATR_SK_GEMS_UNCUT = "*_gemsuncut";
ATR_SK_ITEM_ENH = "*_itemenh";
ATR_SK_POT_ELIX = "*_potelix";
ATR_SK_FLASKS = "*_flasks";
ATR_SK_HERBS = "*_herbs";
-----------------------------------------
local roundPriceDown, ToTightTime, FromTightTime, monthDay;
-----------------------------------------
function Atr_RegisterEvents(self)
Auctionator.Debug.Message( 'Atr_RegisterEvents' )
self:RegisterEvent("VARIABLES_LOADED");
self:RegisterEvent("ADDON_LOADED");
self:RegisterEvent("AUCTION_ITEM_LIST_UPDATE");
self:RegisterEvent("AUCTION_OWNED_LIST_UPDATE");
self:RegisterEvent("AUCTION_MULTISELL_START");
self:RegisterEvent("AUCTION_MULTISELL_UPDATE");
self:RegisterEvent("AUCTION_MULTISELL_FAILURE");
self:RegisterEvent("AUCTION_HOUSE_SHOW");
self:RegisterEvent("AUCTION_HOUSE_CLOSED");
self:RegisterEvent("NEW_AUCTION_UPDATE");
self:RegisterEvent("CHAT_MSG_ADDON");
self:RegisterEvent("PLAYER_ENTERING_WORLD");
end
-----------------------------------------
function Atr_EventHandler(self, event, ...)
-- Auctionator.Debug.Message( 'Atr_EventHandler', event, ... )
if (event == "VARIABLES_LOADED") then Atr_OnLoad(); end;
if (event == "ADDON_LOADED") then Atr_OnAddonLoaded(...); end;
if (event == "AUCTION_ITEM_LIST_UPDATE") then Atr_OnAuctionUpdate(...); end;
if (event == "AUCTION_OWNED_LIST_UPDATE") then Atr_OnAuctionOwnedUpdate(); end;
if (event == "AUCTION_MULTISELL_START") then Atr_OnAuctionMultiSellStart(); end;
if (event == "AUCTION_MULTISELL_UPDATE") then Atr_OnAuctionMultiSellUpdate(...); end;
if (event == "AUCTION_MULTISELL_FAILURE") then Atr_OnAuctionMultiSellFailure(); end;
if (event == "AUCTION_HOUSE_SHOW") then Atr_OnAuctionHouseShow(); end;
if (event == "AUCTION_HOUSE_CLOSED") then Atr_OnAuctionHouseClosed(); end;
if (event == "NEW_AUCTION_UPDATE") then Atr_OnNewAuctionUpdate(); end;
if (event == "CHAT_MSG_ADDON") then Atr_OnChatMsgAddon(...); end;
if (event == "PLAYER_ENTERING_WORLD") then Atr_OnPlayerEnteringWorld(); end;
if (event == "UNIT_SPELLCAST_SENT") then Atr_OnSpellCastSent(...); end;
if (event == "UNIT_SPELLCAST_SUCCEEDED") then Atr_OnSpellCastSucess(...); end;
if (event == "BAG_UPDATE") then Atr_OnBagUpdate(...); end;
end
-----------------------------------------
function Atr_SetupHookFunctionsEarly ()
Auctionator.Debug.Message( 'Atr_SetupHookFunctionsEarly' )
if (Atr_Dev_SetupEarlyHooks) then
Atr_Dev_SetupEarlyHooks();
end
Atr_Hook_OnTooltipAddMoney ();
end
-----------------------------------------
local auctionator_orig_GetAuctionItemInfo;
function Atr_SetupHookFunctions ()
Auctionator.Debug.Message( 'Atr_SetupHookFunctions' )
auctionator_orig_AuctionFrameTab_OnClick = AuctionFrameTab_OnClick;
AuctionFrameTab_OnClick = Atr_AuctionFrameTab_OnClick;
auctionator_orig_ContainerFrameItemButton_OnModifiedClick = ContainerFrameItemButton_OnModifiedClick;
ContainerFrameItemButton_OnModifiedClick = Atr_ContainerFrameItemButton_OnModifiedClick;
auctionator_orig_AuctionFrameAuctions_Update = AuctionFrameAuctions_Update;
AuctionFrameAuctions_Update = Atr_AuctionFrameAuctions_Update;
auctionator_orig_CanShowRightUIPanel = CanShowRightUIPanel;
CanShowRightUIPanel = auctionator_CanShowRightUIPanel;
auctionator_orig_ChatEdit_InsertLink = ChatEdit_InsertLink;
ChatEdit_InsertLink = auctionator_ChatEdit_InsertLink;
auctionator_orig_ChatFrame_OnEvent = ChatFrame_OnEvent;
ChatFrame_OnEvent = auctionator_ChatFrame_OnEvent;
end
-----------------------------------------
function GetRealmFacInfoString()
Auctionator.Debug.Message( 'GetRealmFacInfoString' )
local realm_fac, data
local rf_string = ""
if (AUCTIONATOR_PRICE_DATABASE) then
for realm_fac, data in pairs (AUCTIONATOR_PRICE_DATABASE) do
if (realm_fac and not zc.StringStartsWith (realm_fac, "__")) then
rf_string = rf_string..", "..realm_fac
local c = 0;
if (data) then
for n, v in pairs (data) do
c = c + 1;
end
end
rf_string = rf_string.." ("..c..")"
end
end
end
return rf_string
end
-----------------------------------------
local function IsCataEnchanting (prof)
Auctionator.Debug.Message( 'IsCataEnchanting' )
if (prof) then
local profname, _, skillLevel = GetProfessionInfo (prof)
if (zc.StringSame ("enchanting", profname) and skillLevel >= 450) then
return true
end
end
return false
end
-----------------------------------------
local function IsCataEnchanter()
Auctionator.Debug.Message( 'IsCataEnchanter' )
--[[
local prof1, prof2 = GetProfessions()
if (IsCataEnchanting (prof1) or IsCataEnchanting (prof2)) then
return true
end
]]--
return false
end
-----------------------------------------
local checkVerString = nil;
local versionReminderCalled = false; -- make sure we don't bug user more than once
-----------------------------------------
local function VersionStringToInt( versionString )
Auctionator.Debug.Message( 'VersionStringToInt', versionString )
local major, minor, patch = strsplit( '.', versionString )
return ( tonumber( major ) or -1 ),
( tonumber( minor ) or -1 ),
( tonumber( patch ) or -1 )
end
local function CheckVersion( verString )
if checkVerString == nil then
checkVerString = AuctionatorVersion
end
Auctionator.Debug.Message( 'CheckVersion', verString, checkVerString )
local userMajor, userMinor, userPatch = VersionStringToInt( checkVerString )
local otherMajor, otherMinor, otherPatch = VersionStringToInt( verString )
-- TODO is this needed? kept it in, not sure if it was here for backwards compatibility?
if userMajor == nil or userMinor == nil or userPatch == nil then
return false
end
return userMajor < otherMajor or
( userMajor == otherMajor and userMinor < otherMinor ) or
( userMajor == otherMajor and userMinor == otherMinor and userPatch < otherPatch )
end
-----------------------------------------
function Atr_VersionReminder ()
Auctionator.Debug.Message( 'Atr_VersionReminder' )
if (not versionReminderCalled) then
versionReminderCalled = true;
zc.msg_anm (ZT("There is a more recent version of Auctionator: VERSION").." "..checkVerString);
end
end
-----------------------------------------
local VREQ_sent = 0;
-----------------------------------------
function Atr_SendAddon_VREQ (type, target)
Auctionator.Debug.Message( 'Atr_SendAddon_VREQ', type, target )
VREQ_sent = time()
if (not zc.StringSame (type, "WHISPER")) then
zz ("sending vreq to", type)
end
C_ChatInfo.SendAddonMessage( "ATR", "VREQ_"..AuctionatorVersion, type, target )
end
-----------------------------------------
function Atr_OnChatMsgAddon (...)
local prefix, msg, distribution, sender = ...
if prefix == "ATR" then
Auctionator.Debug.Message( 'Atr_OnChatMsgAddon', ... )
local s = string.format(
"%s %s |cff88ffff %s |cffffffaa %s|r", prefix, distribution, sender, msg
)
if zc.StringStartsWith( msg, "VREQ_" ) then
C_ChatInfo.SendAddonMessage( "ATR", "V_"..AuctionatorVersion, "WHISPER", sender )
end
if zc.StringStartsWith (msg, "IREQ_") then
collectgarbage( "collect" )
UpdateAddOnMemoryUsage()
local mem = math.floor( GetAddOnMemoryUsage("Auctionator") )
C_ChatInfo.SendAddonMessage( "ATR", "I_" .. Atr_GetDBsize() .. "_" .. mem .. "_" .. #AUCTIONATOR_SHOPPING_LISTS.."_"..GetRealmFacInfoString(), "WHISPER", sender)
end
if zc.StringStartsWith( msg, "V_" ) and time() - VREQ_sent < 5 then
local herVerString = string.sub( msg, 3 )
local outOfDate = CheckVersion( herVerString )
if outOfDate then
zc.AddDeferredCall( 3, "Atr_VersionReminder", nil, nil, "VR" )
end
end
end
Atr_OnChatMsgAddon_ShoppingListCmds( prefix, msg, distribution, sender )
end
-----------------------------------------
function Atr_GetAuctionatorMemString(msg)
Auctionator.Debug.Message( 'Atr_GetAuctionatorMemString', msg )
collectgarbage ("collect");
UpdateAddOnMemoryUsage();
local mem = GetAddOnMemoryUsage("Auctionator");
return string.format ("%6i KB", math.floor(mem));
end
-----------------------------------------
local function Atr_RestoreDElog()
Auctionator.Debug.Message( 'Atr_RestoreDElog' )
if (AUCTIONATOR_DE_DATA_BAK and #AUCTIONATOR_DE_DATA_BAK > 0) then
AUCTIONATOR_DE_DATA = {}
zc.CopyDeep (AUCTIONATOR_DE_DATA, AUCTIONATOR_DE_DATA_BAK)
zc.msg_anm (ZT("Disenchant data restored. Number of entries:"), #AUCTIONATOR_DE_DATA_BAK);
else
zc.msg_anm (ZT("No data available to be restored."));
end
end
-----------------------------------------
local function Atr_DumpDElog()
Auctionator.Debug.Message( 'Atr_DumpDElog' )
if (AUCTIONATOR_DE_DATA == nil or #AUCTIONATOR_DE_DATA == 0) then
zc.msg_anm ("no data has been collected");
return
end
AUCTIONATOR_DE_DATA_BAK = {}
zc.CopyDeep (AUCTIONATOR_DE_DATA_BAK, AUCTIONATOR_DE_DATA)
AUCTIONATOR_DE_DATA = {}
zc.msg_anm ("Disenchant data cleared.");
Atr_LUA_explanation:SetText ("");
local n
local x = 0;
for n = 1,#AUCTIONATOR_DE_DATA_BAK do
local a, b = strsplit ("_", AUCTIONATOR_DE_DATA_BAK[n])
x = x + tonumber (a) + tonumber (b)
end
local msg = "DISENCHANT "..time().." "..x.." "..UnitName("player").."\n"
for n = 1,#AUCTIONATOR_DE_DATA_BAK do
msg = msg..AUCTIONATOR_DE_DATA_BAK[n].."\n"
end
end
-----------------------------------------
function Atr_ClearItemStackingPrefs ()
Auctionator.Debug.Message( 'Atr_ClearItemStackingPrefs' )
local text, spinfo;
for text, spinfo in pairs (AUCTIONATOR_STACKING_PREFS) do
if (not zc.StringContains (text, "_")) then
AUCTIONATOR_STACKING_PREFS[text] = nil
end
end
end
-----------------------------------------
local function Atr_ClearPostHistory ()
Auctionator.Debug.Message( 'Atr_ClearPostHistory' )
AUCTIONATOR_PRICING_HISTORY = {};
zc.msg_anm (ZT("posting history cleared"));
end
-----------------------------------------
local function Atr_ClearFullScanDB ()
Auctionator.Debug.Message( 'Atr_ClearFullScanDB' )
gAtr_ScanDB = nil;
AUCTIONATOR_PRICE_DATABASE = nil;
Atr_InitScanDB();
zc.msg_anm (ZT("full scan database cleared"));
end
-----------------------------------------
local function Atr_SlashCmdFunction(msg)
Auctionator.Debug.Message( 'Atr_SlashCmdFunction', msg )
local cmd, param1u, param2u, param3u = zc.words (msg);
if (cmd == nil or type (cmd) ~= "string") then
return;
end
cmd = cmd and cmd:lower() or nil;
local param1 = param1u and param1u:lower() or nil;
local param2 = param2u and param2u:lower() or nil;
local param3 = param3u and param3u:lower() or nil;
if (cmd == "mem") then
UpdateAddOnMemoryUsage();
for i = 1, GetNumAddOns() do
local mem = GetAddOnMemoryUsage(i);
local name = GetAddOnInfo(i);
if (mem > 0) then
local s = string.format ("%6i KB %s", math.floor(mem), name);
zc.msg_yellow (s);
end
end
elseif (cmd == "share" and param1 == "lists") then
Atr_Send_ShareShoppingListRequest(param2)
elseif (cmd == "locale") then
Atr_PickLocalizationTable (param1u);
elseif (cmd == "fsc") then
if (param1) then
AUCTIONATOR_FS_CHUNK = tonumber(param1);
end
if (AUCTIONATOR_FS_CHUNK == nil) then
zc.msg_anm ("full scan chunk size: ", gDefaultFullScanChunkSize, " (default)");
else
zc.msg_anm ("full scan chunk size: ", AUCTIONATOR_FS_CHUNK);
end
elseif (cmd == "generr") then
local y = 5 + nil;
elseif (cmd == "vsl") then
Atr_ShpList_Validate()
elseif (cmd == "delog") then
AUCTIONATOR_SAVEDVARS.LOG_DE_DATA_X = zc.Negate (AUCTIONATOR_SAVEDVARS.LOG_DE_DATA_X)
EnableDisableDElogging ()
elseif (cmd == "dedump") then
Atr_DumpDElog()
elseif (cmd == "derestore") then
Atr_RestoreDElog()
elseif (cmd == "declear") then
AUCTIONATOR_DE_DATA = nil
AUCTIONATOR_DE_DATA_BAK = nil
zc.msg_anm ("Disenchant data cleared");
elseif (cmd == "clear") then
zc.msg_anm ("memory usage: "..Atr_GetAuctionatorMemString());
if (param1 == "fullscandb") then Atr_ClearFullScanDB()
elseif (param1 == "posthistory") then Atr_ClearPostHistory()
elseif (param1 == "ssprefs") then
Atr_ClearItemStackingPrefs()
zc.msg_anm (ZT("selling preferences cleared"))
end
collectgarbage ("collect");
zc.msg_anm ("memory usage: "..Atr_GetAuctionatorMemString());
elseif (Atr_HandleDevCommands and Atr_HandleDevCommands (cmd, param1, param2)) then
-- do nothing
else
zc.msg_anm (ZT("unrecognized command"));
end
end
-----------------------------------------
function EnableDisableDElogging ()
Auctionator.Debug.Message( 'EnableDisableDElogging' )
if (not IsCataEnchanter()) then
return
end
if (AUCTIONATOR_SAVEDVARS and (AUCTIONATOR_SAVEDVARS.LOG_DE_DATA_X or AUCTIONATOR_SAVEDVARS.LOG_DE_DATA_X == nil)) then
Atr_core:RegisterEvent("UNIT_SPELLCAST_START");
Atr_core:RegisterEvent("UNIT_SPELLCAST_SENT");
Atr_core:RegisterEvent("UNIT_SPELLCAST_STOP");
Atr_core:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED");
Atr_core:RegisterEvent("BAG_UPDATE");
local num = AUCTIONATOR_DE_DATA and #AUCTIONATOR_DE_DATA or 0
zz ("Disenchanting info is being logged. Current number of entries:", num)
else
Atr_core:UnregisterEvent("UNIT_SPELLCAST_START");
Atr_core:UnregisterEvent("UNIT_SPELLCAST_SENT");
Atr_core:UnregisterEvent("UNIT_SPELLCAST_STOP");
Atr_core:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED");
Atr_core:UnregisterEvent("BAG_UPDATE");
zz ("disenchanting info is NOT being logged")
end
end
-----------------------------------------
local function Atr_OnClickTradeSkillBut()
Auctionator.Debug.Message( 'Atr_OnClickTradeSkillBut' )
if (not AuctionFrame or not AuctionFrame:IsShown()) then
Atr_Error_Display (ZT("When the Auction House is open\nclicking this button tells Auctionator\nto scan for the item and all its reagents."))
return
end
Atr_SelectPane (BUY_TAB);
local index = TradeSkillFrame.RecipeList:GetSelectedRecipeID()
local link = C_TradeSkillUI.GetRecipeItemLink(index)
local _, _, _, _, _, itemType = GetItemInfo (link);
local numReagents = C_TradeSkillUI.GetRecipeNumReagents(index)
local reagentId
local shoppingListName = GetItemInfo (link)
if (shoppingListName == nil) then
shoppingListName = C_TradeSkillUI.GetRecipeInfo(index).name
end
local items = {}
if (shoppingListName) then
table.insert (items, shoppingListName)
end
for reagentId = 1, numReagents do
local reagentName = C_TradeSkillUI.GetRecipeReagentInfo(index, reagentId)
if (reagentName and not zc.StringSame(reagentName, "Crystal Vial")) then
table.insert (items, reagentName)
end
end
Atr_SearchAH (shoppingListName, items, itemType)
end
-----------------------------------------
local function Atr_ModTradeSkillFrame()
Auctionator.Debug.Message( 'Atr_ModTradeSkillFrame' )
if (gTradeSkillFrameModded) then
return
end
--[[
if (TradeSkillFrame) then
gTradeSkillFrameModded = true
local button = CreateFrame("BUTTON", "Auctionator_Search", TradeSkillFrame, "UIPanelButtonTemplate");
button:SetPoint("RIGHT", "TradeSkillFrame", "RIGHT", -65, -20);
button:SetHeight (20)
button:SetText(ZT("AH"))
button:SetNormalFontObject(_G["GameFontNormalSmall"])
button:SetHighlightFontObject(_G["GameFontNormalSmall"])
button:SetDisabledFontObject(_G["GameFontNormalSmall"])
button:SetScript ("OnClick", Atr_OnClickTradeSkillBut)
zz ("TradeSkillFrame modded")
else
zz ("TradeSkillFrame not loaded")
end
]]--
end
-----------------------------------------
function Atr_InitScanDB()
Auctionator.Debug.Message( 'Atr_InitScanDB' )
local realm_Faction = GetRealmName().."_"..UnitFactionGroup ("player");
if (AUCTIONATOR_PRICE_DATABASE and AUCTIONATOR_PRICE_DATABASE["__dbversion"] == nil) then -- migrate version 1 to version 2
local temp = {};
zc.CopyDeep (temp, AUCTIONATOR_PRICE_DATABASE);
AUCTIONATOR_PRICE_DATABASE = {};
AUCTIONATOR_PRICE_DATABASE["__dbversion"] = 2;
AUCTIONATOR_PRICE_DATABASE[realm_Faction] = {};
zc.CopyDeep (AUCTIONATOR_PRICE_DATABASE[realm_Faction], temp);
temp = {};
end
if (AUCTIONATOR_PRICE_DATABASE and AUCTIONATOR_PRICE_DATABASE["__dbversion"] == 2) then -- migrate version 2 to version 3
local temp_price_db = {};
for realm_fac, data in pairs (AUCTIONATOR_PRICE_DATABASE) do
if (type(data) == "table") then
temp_price_db[realm_fac] = {};
zc.md ("migrating Auctionator db to version 3 for:", realm_fac);
local name, price;
local count = 0;
for name, price in pairs (data) do
if (type(price) == "table") then -- this is to fix the bug where I didn't set the dbversion correctly for NEW dbs
temp_price_db[realm_fac][name] = price;
else
Atr_UpdateScanDBprice (name, price, temp_price_db[realm_fac]);
end
count = count + 1;
end
zc.md (count, "entries migrated");
end
end
AUCTIONATOR_PRICE_DATABASE = temp_price_db;
AUCTIONATOR_PRICE_DATABASE["__dbversion"] = 3;
end
-- migrate version 3 to version 4
if (AUCTIONATOR_PRICE_DATABASE and AUCTIONATOR_PRICE_DATABASE["__dbversion"] == 3) then
for realm_fac, data in pairs (AUCTIONATOR_PRICE_DATABASE) do
if (type(data) == "table") then
zc.md ("migrating Auctionator db to version 4 for:", realm_fac);
local name, itemInfo;
for name, itemInfo in pairs (data) do
if (type(itemInfo) == "table") then
itemInfo["po"] = 1; -- flag for deletion after the first full scan
end
end
end
end
AUCTIONATOR_PRICE_DATABASE["__dbversion"] = 4;
end
if (AUCTIONATOR_PRICE_DATABASE == nil) then
AUCTIONATOR_PRICE_DATABASE = {};
AUCTIONATOR_PRICE_DATABASE["__dbversion"] = 4;
end
if (AUCTIONATOR_PRICE_DATABASE[realm_Faction] == nil) then
AUCTIONATOR_PRICE_DATABASE[realm_Faction] = {};
end
gAtr_ScanDB = AUCTIONATOR_PRICE_DATABASE[realm_Faction];
Atr_PruneScanDB ();
Atr_PrunePostDB ();
Atr_Broadcast_DBupdated (#gAtr_ScanDB, "dbinited");
end
-----------------------------------------
function Atr_OnLoad()
Auctionator.Debug.Message( 'Atr_OnLoad' )
AuctionatorVersion = GetAddOnMetadata("Auctionator", "Version");
gTimeZero = time({year=2000, month=1, day=1, hour=0});
gTimeTightZero = time({year=2008, month=8, day=1, hour=0});
local x;
for x = 0, NUM_BAG_SLOTS do
kBagIDs[x+1] = x;
end
kBagIDs[NUM_BAG_SLOTS+2] = KEYRING_CONTAINER;
AuctionatorLoaded = true;
SlashCmdList["Auctionator"] = Atr_SlashCmdFunction;
SLASH_Auctionator1 = "/auctionator";
SLASH_Auctionator2 = "/atr";
Atr_InitScanDB ();
if (AUCTIONATOR_PRICING_HISTORY == nil) then -- the old history of postings
AUCTIONATOR_PRICING_HISTORY = {};
end
if (AUCTIONATOR_TOONS == nil) then
AUCTIONATOR_TOONS = {};
end
if (AUCTIONATOR_STACKING_PREFS == nil) then
Atr_StackingPrefs_Init();
end
if (AUCTIONATOR_SAVEDVARS == nil) then
Atr_ResetSavedVars()
end
local playerName = UnitName("player");
if (not AUCTIONATOR_TOONS[playerName]) then
AUCTIONATOR_TOONS[playerName] = {};
AUCTIONATOR_TOONS[playerName].firstSeen = time();
AUCTIONATOR_TOONS[playerName].firstVersion = AuctionatorVersion;
end
AUCTIONATOR_TOONS[playerName].guid = UnitGUID ("player");
if (AUCTIONATOR_SCAN_MINLEVEL == nil) then
AUCTIONATOR_SCAN_MINLEVEL = 1; -- poor (all) items
end
if (AUCTIONATOR_SHOW_TIPS == 0) then -- migrate old option to new ones
AUCTIONATOR_V_TIPS = 0;
AUCTIONATOR_A_TIPS = 0;
AUCTIONATOR_D_TIPS = 0;
AUCTIONATOR_SHOW_TIPS = 2;
end
if (AUCTIONATOR_OPEN_FIRST < 2) then -- set to 2 to indicate it's been migrated
if (AUCTIONATOR_OPEN_FIRST == 1) then AUCTIONATOR_DEFTAB = 1;
elseif (AUCTIONATOR_OPEN_BUY == 1) then AUCTIONATOR_DEFTAB = 2;
else AUCTIONATOR_DEFTAB = 0; end;
AUCTIONATOR_OPEN_FIRST = 2;
end
-- Migrate old version of shopping lists to new adv
if AUCTIONATOR_SHOPPING_LISTS and AUCTIONATOR_SHOPPING_LISTS_MIGRATED_V2 == nil then
for index, list in ipairs( AUCTIONATOR_SHOPPING_LISTS ) do
local fixedList = {}
for itemIndex, itemName in ipairs( list.items ) do
local replacement = itemName:gsub( "|", ";" )
table.insert( fixedList, replacement )
end
AUCTIONATOR_SHOPPING_LISTS[ index ].items = fixedList
end
AUCTIONATOR_SHOPPING_LISTS_MIGRATED_V2 = true
end
Atr_SetupHookFunctionsEarly();
------------------
local atrtt1 = CreateFrame( "GameTooltip", "AtrScanningTooltip", nil, "GameTooltipTemplate" ); -- Tooltip name cannot be nil
if (atrtt1 == nil) then
zc.msg_anm ("Unable to create AtrScanningTooltip");
end
AtrScanningTooltip:SetOwner( WorldFrame, "ANCHOR_NONE" );
local atrtt2 = CreateFrame( "GameTooltip", "AtrScanningTooltip2", nil, "GameTooltipTemplate" ); -- Tooltip name cannot be nil
if (atrtt2 == nil) then
zc.msg_anm ("Unable to create AtrScanningTooltip2");
end
AtrScanningTooltip2:SetOwner( WorldFrame, "ANCHOR_NONE" );
------------------
Atr_ShoppingListsInit();
EnableDisableDElogging ()
if ( IsAddOnLoaded("Blizzard_AuctionUI") ) then -- need this for AH_QuickSearch since that mod forces Blizzard_AuctionUI to load at a startup
Atr_Init();
end
Atr_ModTradeSkillFrame()
end
-----------------------------------------
local gPrevTime = 0;
function Atr_OnAddonLoaded(...)
Auctionator.Debug.Message( 'Atr_OnAddonLoaded', ... )
local addonName = select (1, ...);
if (zc.StringSame (addonName, "blizzard_auctionui")) then
Atr_Init();
end
Atr_Check_For_Conflicts (addonName);
local now = time();
gPrevTime = now;
if (zc.StringSame (addonName, "blizzard_tradeskillui")) then
Atr_ModTradeSkillFrame();
end
end
-----------------------------------------
auctionatorInited = false
-----------------------------------------
function Atr_OnPlayerEnteringWorld()
Auctionator.Debug.Message( 'Atr_OnPlayerEnteringWorld' )
zz ("auctionatorInited = ", auctionatorInited);
if (auctionatorInited == false) then
auctionatorInited = true;
Atr_InitOptionsPanels()
Atr_InitToolTips()
if (RegisterAddonMessagePrefix) then
RegisterAddonMessagePrefix ("ATR")
end
end
end
-----------------------------------------
local preDEmats;
local preDEgear;
local gDisenchantTime = 0;
-----------------------------------------
function Atr_ScanBags (mats, gear)
Auctionator.Debug.Message( 'Atr_ScanBags', mats, gear )
local bagID, slotID, numslots;
for bagID = 0, NUM_BAG_SLOTS do
local numslots = GetContainerNumSlots (bagID);
for slotID = 1,numslots do
local itemLink = GetContainerItemLink(bagID, slotID);
if (itemLink) then
local texture, itemCount, locked, quality = GetContainerItemInfo(bagID, slotID);
local itemName, _, itemRarity, _, _, itemType, itemSubType, _, _, _, _, itemClassID, itemSubClassID = GetItemInfo( itemLink )
local itemLevel = ItemUpgradeInfo:GetUpgradedItemLevel( itemLink )
if ( Atr_IsWeaponType( itemClassID ) or Atr_IsArmorType( itemClassID ) ) and itemLevel > 271 then
local key = itemType.."_"..itemSubType.."_"..itemRarity.."_"..itemLevel;
if (gear[key]) then
gear[key].count = gear[key].count + 1;
else
local q = "X";
if (itemRarity == 2) then q = "G"; end
if (itemRarity == 3) then q = "B"; end
if (itemRarity == 4) then q = "P"; end
gear[key] = { t=itemType, s=itemSubType, q=q, lev=itemLevel, count=itemCount };
end
end