-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathGatherer.lua
executable file
·2233 lines (1971 loc) · 78.5 KB
/
Gatherer.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
-- Gatherer
-- Written by Chandora
GATHERER_VERSION="1.0.0";
--
-- Look, seriously a full half of this code is from MapNotes.
-- The only reason I pinched it and put it in here is I couldn't
-- work out how to extend MapNotes to do what I wanted it to do
-- without actually editing the MapNotes files.
--
-- Full credit to the MapNotes guys
--
-- Global variables
GATHERNOTE_UPDATE_INTERVAL = 0.25;
GATHERNOTE_CHECK_INTERVAL = 5.0;
GATHERER_MAXNUMNOTES = 25;
GATHERER_LOADED = false;
GATHERER_CLOSESTCHECK=0.4;
Gatherer_RecordFlag=0;
Gatherer_currentNode="";
Gatherer_currentAction="";
GatherMap_InCity = false;
Gatherer_LoadCount = 0;
Gatherer_MapOpen = false;
Gatherer_UpdateWorldMap = -1;
Gatherer_InWorld = false;
GatherItems = { };
GatherSkills = { };
GatherZoneData = { }; -- Dict[ZoneName, Tuple[Continent, Zone]]
GatherMainMapItem = { };
-- UI variables
Gatherer_WorldMapDetailFrameWidth = 0;
Gatherer_WorldMapDetailFrameHeight = 0;
Gatherer_WorldMapPlayerFrameLevel = 0;
Gather_Player = UnitName("player");
StaticPopupDialogs["GATHERER_VERSION_DIALOG"] = {
text = TEXT(GATHERER_VERSION_WARNING),
button1 = TEXT(OKAY),
showAlert = 1,
timeout = 0,
};
--- ************************************************************************
-- Utilities
function Gatherer_Round(x)
if( x - math.floor(x) > 0.5) then
x = x + 0.5;
end
return math.floor(x);
end
function Gatherer_GetMenuName(inputName)
local name, info;
if (inputName) then
local firstLetter = string.sub(inputName, 1, 2);
local carReplace = {["\195\160"] = "a", ["\195\161"] = "a", ["\195\162"] = "a", ["\195\163"] = "a", ["\195\164"] = "a",
["\195\168"] = "e", ["\195\169"] = "e", ["\195\170"] = "e", ["\195\171"] = "e",
["\195\180"] = "i", ["\195\173"] = "i", ["\195\174"] = "i", ["\195\175"] = "i",
["\195\179"] = "o", ["\195\180"] = "o", ["\195\181"] = "o", ["\195\182"] = "o",
["\195\185"] = "u", ["\195\186"] = "u", ["\195\187"] = "u", ["\195\188"] = "u"}
local found;
for code, repl in carReplace do
firstLetter, found = string.gsub(firstLetter, code, repl);
if (found > 0) then
break;
end
end
if (found > 0) then
name = string.upper(firstLetter)..(string.sub(inputName, 3) or "");
else
if (GetLocale()=="ruRU") then
name = inputName;
else
name = string.upper(string.sub(inputName, 1, 1))..(string.sub(inputName, 2) or "");
end
end
local iconName, _ = Gatherer_GetDB_IconByGatherName(inputName);
iconName = iconName or inputName;
for _, rareMatch in Gather_RareMatch do
if (iconName == rareMatch) then
name = name.." ["..TYPE_RARE.."]";
break;
end
end
if (Gather_SkillLevel[iconName]) then
name = name.." ["..Gather_SkillLevel[iconName].."]";
end
end
return name, info;
end
-- *************************************************************************
-- Init and command line handler
function Gatherer_OnLoad()
this:RegisterEvent("WORLD_MAP_UPDATE");
this:RegisterEvent("CLOSE_WORLD_MAP"); -- never triggered apparently
this:RegisterEvent("LEARNED_SPELL_IN_TAB"); -- follow current skills
this:RegisterEvent("SPELLS_CHANGED"); -- follow current skills
this:RegisterEvent("SKILL_LINES_CHANGED"); -- follow current skills
this:RegisterEvent("SPELLCAST_START");
this:RegisterEvent("SPELLCAST_STOP");
this:RegisterEvent("SPELLCAST_FAILED");
this:RegisterEvent("CHAT_MSG_ADDON");
-- Events for off world non processing
this:RegisterEvent("PLAYER_ENTERING_WORLD");
this:RegisterEvent("PLAYER_LEAVING_WORLD");
-- Addon Loaded and player login/logout events
this:RegisterEvent("ADDON_LOADED");
this:RegisterEvent("PLAYER_LOGIN");
this:RegisterEvent("PLAYER_LOGOUT");
Gatherer_LoadZoneData();
SLASH_GATHER1 = "/gather";
SLASH_GATHER2 = "/gatherer";
SlashCmdList["GATHER"] = function(msg)
Gatherer_Command(msg);
end
end
function Gatherer_Command(command)
local SETTINGS = Gatherer_Settings;
local i,j, cmd, param = string.find(command, "^([^ ]+) (.+)$");
if (not cmd) then cmd = command; end
if (not cmd) then cmd = ""; end
if (not param) then param = ""; end
if ((cmd == "") or (cmd == "help")) then
local useMinimap = "Off";
if (SETTINGS.useMinimap) then useMinimap = "On"; end
local useMainmap = "Off";
if (SETTINGS.useMainmap) then useMainmap = "On"; end
local mapMinder = "Off";
if (SETTINGS.mapMinder) then mapMinder = "On"; end
local minderTime = "5s";
if (SETTINGS.minderTime) then minderTime = SETTINGS.minderTime.."s"; end
Gatherer_ChatPrint("Usage:");
Gatherer_ChatPrint(" |cffffffff/gather (on|off|toggle)|r |cff2040ff["..useMinimap.."]|r - turns the gather minimap display on and off");
Gatherer_ChatPrint(" |cffffffff/gather mainmap (on|off|toggle)|r |cff2040ff["..useMainmap.."]|r - turns the gather mainmap display on and off");
Gatherer_ChatPrint(" |cffffffff/gather minder (on|off|toggle|<n>)|r |cff2040ff["..mapMinder.."]|r - turns the gather map minder on and off (remembers and reopens your last open main map; within "..minderTime..")");
Gatherer_ChatPrint(" |cffffffff/gather dist <n>|r |cff2040ff["..SETTINGS.maxDist.."]|r - sets the maximum search distance for display (0=infinite(default), typical=10)");
Gatherer_ChatPrint(" |cffffffff/gather num <n>|r |cff2040ff["..SETTINGS.number.."]|r - sets the maximum number of items to display (default=10, up to 25)");
Gatherer_ChatPrint(" |cffffffff/gather fdist <n>|r |cff2040ff["..SETTINGS.fadeDist.."]|r - sets a fade distance (in units) for the icons to fade out by (default = 20)");
Gatherer_ChatPrint(" |cffffffff/gather fperc <n>|r |cff2040ff["..SETTINGS.fadePerc.."]|r - sets the percentage for fade at max fade distance (default = 80 [=80% faded])");
Gatherer_ChatPrint(" |cffffffff/gather theme <name>|r |cff2040ff["..SETTINGS.iconSet.."]|r - sets the icon theme: original, shaded (default), iconic or iconshade");
Gatherer_ChatPrint(" |cffffffff/gather idist <n>|r |cff2040ff["..SETTINGS.miniIconDist.."]|r - sets the minimap distance at which the gather icon will become iconic (0 = off, 1-60 = pixel radius on minimap, default = 40)");
Gatherer_ChatPrint(" |cffffffff/gather herbs (on|off|toggle|auto)|r |cff2040ff["..Gatherer_GetFilterVal("herbs").."]|r - select whether to show herb data on the minimap");
Gatherer_ChatPrint(" |cffffffff/gather mining (on|off|toggle|auto)|r |cff2040ff["..Gatherer_GetFilterVal("mining").."]|r - select whether to show mining data on the minimap");
Gatherer_ChatPrint(" |cffffffff/gather treasure (on|off|toggle|auto)|r |cff2040ff["..Gatherer_GetFilterVal("treasure").."]|r - select whether to show treasure data on the minimap");
Gatherer_ChatPrint(" |cffffffff/gather options|r - show/hide UI Options dialog.");
Gatherer_ChatPrint(" |cffffffff/gather report|r - show/hide report dialog.");
Gatherer_ChatPrint(" |cffffffff/gather search|r - show/hide search dialog.");
Gatherer_ChatPrint(" |cffffffff/gather loginfo (on|off)|r - show/hide logon information.");
Gatherer_ChatPrint(" |cffffffff/gather filterrec (herbs|mining|treasure)|r - link display filter to recording for selected gathering type");
Gatherer_ChatPrint(" |cffffffff/gather debug ([on]|off)|r |cff2040ff["..Gatherer_EBoolean[SETTINGS.debug].."]|r - show/hide debug messages");
Gatherer_ChatPrint(" |cffffffff/gather p2p ([on]|off)|r |cff2040ff["..Gatherer_EBoolean[SETTINGS.p2p].."]|r - enable/disable peer-to-peer functions");
elseif (cmd == "options" ) then
if ( GathererUI_DialogFrame:IsVisible() ) then
GathererUI_HideOptions();
else
GathererUI_ShowOptions();
end
elseif (cmd == "debug") then
if (not param or param == "" or param == "on") then
SETTINGS.debug = true;
Gatherer_ChatPrint("Debug messages enabled");
elseif (param == "off") then
SETTINGS.debug = false;
Gatherer_ChatPrint("Debug messages disabled");
end
elseif (cmd == "p2p") then
if (not param or param == "" or param == "on") then
SETTINGS.p2p = true;
Gatherer_ChatPrint("Peer-to-peer functions enabled");
elseif (param == "off") then
SETTINGS.p2p = false;
Gatherer_ChatPrint("Peer-to-peer functions disabled");
end
elseif (cmd == "report" ) then
showGathererInfo(1);
elseif (cmd == "search" ) then
showGathererInfo(2);
elseif (cmd == "loginfo" ) then
local value;
if (not param or param == "") then value = "on"; else value = param; end
Gatherer_ChatPrint("Setting log information display to "..value);
SETTINGS.logInfo = value;
elseif ( cmd == "filterrec" ) then
local value=-1;
if (not param) then
return;
end;
if ( param == "treasure" ) then
value = 0;
elseif ( param == "herbs" ) then
value = 1;
elseif ( param == "mining" ) then
value = 2;
end
if ( value > -1 ) then
if ( SETTINGS.filterRecording[value] ) then
SETTINGS.filterRecording[value] = nil;
Gatherer_ChatPrint("Turned filter/recording link for "..param.." off.");
else
SETTINGS.filterRecording[value] = 1;
Gatherer_ChatPrint("Turned filter/recording link for "..param.." on.");
end
end
elseif (cmd == "on") then
SETTINGS.useMinimap = true;
Gatherer_OnUpdate(0, true);
SETTINGS.useMinimapText = "on";
Gatherer_ChatPrint("Turned gather minimap display on");
elseif (cmd == "off") then
SETTINGS.useMinimap = false;
SETTINGS.useMinimapText = "off";
Gatherer_OnUpdate(0, true);
Gatherer_ChatPrint("Turned gather minimap display off (still collecting)");
elseif (cmd == "toggle") then
SETTINGS.useMinimap = not SETTINGS.useMinimap;
Gatherer_OnUpdate(0, true);
if (SETTINGS.useMinimap) then
Gatherer_ChatPrint("Turned gather minimap display on");
SETTINGS.useMinimapText = "on";
else
Gatherer_ChatPrint("Turned gather minimap display off (still collecting)");
SETTINGS.useMinimapText = "off";
end
elseif (cmd == "dist") then
local i,j, value = string.find(param, "(%d+)");
if (not value) then value = 0; else value = value + 0.0; end
if (value <= 0) then
SETTINGS.maxDist = 0;
else
SETTINGS.maxDist = value + 0.0;
end
Gatherer_ChatPrint("Setting maximum note distance to "..SETTINGS.maxDist);
Gatherer_OnUpdate(0, true);
elseif (cmd == "fdist") then
local i,j, value = string.find(param, "(%d+)");
if (not value) then value = 0; else value = value + 0.0; end
if (value <= 0) then
SETTINGS.fadeDist = 0;
else
SETTINGS.fadeDist = value + 0.0;
end
Gatherer_ChatPrint("Setting fade distance to "..SETTINGS.fadeDist);
Gatherer_OnUpdate(0, true);
elseif (cmd == "fperc") then
local i,j, value = string.find(param, "(%d+)");
if (not value) then value = 0; else value = value + 0.0; end
if (value <= 0) then
SETTINGS.fadePerc = 0;
else
SETTINGS.fadePerc = value + 0.0;
end
Gatherer_ChatPrint("Setting fade percent at fade distance to "..SETTINGS.fadePerc);
Gatherer_OnUpdate(0, true);
elseif ((cmd == "idist") or (cmd == "icondist")) then
local i,j, value = string.find(param, "(%d+)");
if (not value) then value = 0; else value = value + 0; end
if (value <= 0) then
SETTINGS.miniIconDist = 0;
else
SETTINGS.miniIconDist = value + 0;
end
Gatherer_ChatPrint("Setting iconic distance to "..SETTINGS.miniIconDist);
Gatherer_OnUpdate(0, true);
elseif (cmd == "theme") then
if (Gather_IconSet[param]) then
SETTINGS.iconSet = param;
Gatherer_ChatPrint("Gatherer theme set to "..SETTINGS.iconSet);
else
Gatherer_ChatPrint("Unknown theme: "..param);
end
Gatherer_OnUpdate(0, true);
elseif ((cmd == "num") or (cmd == "number")) then
local i,j, value = string.find(param, "(%d+)");
if (not value) then value = 0; else value = value + 0; end
if (value < 0) then
SETTINGS.number = 10;
elseif (value <= GATHERER_MAXNUMNOTES) then
SETTINGS.number = math.floor(value + 0);
else
SETTINGS.number = GATHERER_MAXNUMNOTES;
end
if (SETTINGS.number == 0) then
SETTINGS.useMinimap = false;
SETTINGS.useMinimapText = "off";
Gatherer_OnUpdate(0, true);
Gatherer_ChatPrint("Turned gather minimap display off (still collecting)");
else
if ((SETTINGS.number > 0) and (SETTINGS.useMinimap == false)) then
SETTINGS.useMinimap = true;
SETTINGS.useMinimapText = "on";
Gatherer_ChatPrint("Turned gather minimap display on");
end
Gatherer_ChatPrint("Displaying "..SETTINGS.number.." notes at once");
Gatherer_OnUpdate(0, true);
end
elseif (cmd == "mainmap") then
if ((param == "false") or (param == "off") or (param == "no") or (param == "0")) then
SETTINGS.useMainmap = false;
elseif (param == "toggle") then
SETTINGS.useMainmap = not SETTINGS.useMainmap;
else
SETTINGS.useMainmap = true;
end
if (SETTINGS.useMainmap) then
Gatherer_ChatPrint("Displaying notes in main map");
Gatherer_WorldMapDisplay:SetText("Hide Items");
else
Gatherer_ChatPrint("Not displaying notes in main map");
Gatherer_WorldMapDisplay:SetText("Show Items");
end
if (SETTINGS.useMainmap and SETTINGS.showWorldMapFilters and SETTINGS.showWorldMapFilters == 1) then
GathererWD_DropDownFilters:Show();
end
elseif (cmd == "minder") then
if ((param == "false") or (param == "off") or (param == "no") or (param == "0")) then
SETTINGS.mapMinder = false;
elseif (param == "toggle") then
SETTINGS.mapMinder = not SETTINGS.mapMinder;
elseif (param == "on") then
SETTINGS.mapMinder = true;
else
local i,j, value = string.find(param, "(%d+)");
if (not value) then value = 0; else value = value + 0; end
if (value <= 0) then
SETTINGS.mapMinder = false;
SETTINGS.minderTime = 0;
else
SETTINGS.mapMinder = true;
SETTINGS.minderTime = value + 0;
end
Gatherer_ChatPrint("Setting map minder timeout to "..SETTINGS.minderTime);
end
if (SETTINGS.mapMinder) then
Gatherer_ChatPrint("Map minder activated at "..SETTINGS.minderTime);
else
Gatherer_ChatPrint("Not minding your map");
end
elseif ((cmd == "herbs") or (cmd == "mining") or (cmd == "treasure")) then
if ((param == "false") or (param == "off") or (param == "no") or (param == "0")) then
Gatherer_SetFilter(cmd, "off");
Gatherer_ChatPrint("Not displaying "..cmd.." notes in minimap");
elseif (param == "on" or param == "On" ) then
Gatherer_SetFilter(cmd, "on");
Gatherer_ChatPrint("Displaying "..cmd.." notes in minimap");
elseif (param == "toggle" or param == "") then
local cur = Gatherer_GetFilterVal(cmd);
if ((cur == "on") or (cur == "auto")) then
cur = "off";
Gatherer_SetFilter(cmd, "off");
Gatherer_ChatPrint("Not displaying "..cmd.." notes in minimap");
else
cur = "on";
Gatherer_SetFilter(cmd, "on");
Gatherer_ChatPrint("Displaying "..cmd.." notes in minimap");
end
else
Gatherer_SetFilter(cmd, "auto");
Gatherer_ChatPrint("Displaying "..cmd.." notes in minimap based on ability");
end
Gatherer_OnUpdate(0, true);
GatherMain_Draw();
end
end
-- *************************************************************************
-- Events Handler
function Gatherer_OnEvent(event)
if (not event) then return; end;
-- Enable/Disable event processing for zoning
if (event == "PLAYER_ENTERING_WORLD" ) then
this:RegisterEvent("CHAT_MSG_SPELL_SELF_BUFF"); -- standard gathering event
this:RegisterEvent("UI_ERROR_MESSAGE"); -- event added for impossible to gather item
this:RegisterEvent("CHAT_MSG_LOOT"); -- event added for fishing node
Gatherer_InWorld = true;
elseif (event == "PLAYER_LEAVING_WORLD" ) then
this:UnregisterEvent("CHAT_MSG_SPELL_SELF_BUFF"); -- standard gathering event
this:UnregisterEvent("UI_ERROR_MESSAGE"); -- event added for impossible to gather item
this:UnregisterEvent("CHAT_MSG_LOOT"); -- event added for fishing node
Gatherer_InWorld = false;
-- process loot received message for fishing node trigger
elseif ( event == "CHAT_MSG_LOOT" ) then
local _, _, fishItem = string.find(arg1, GATHERER_ReceivesLoot );
local gfishTooltip = Gatherer_ExtractItemFromTooltip()
if ( fishItem and not UnitExists("mouseover") ) then
Gatherer_ReadBuff(event, fishItem, gfishTooltip);
end
-- process event to record, normally not possible gather (low/inexistant skill)
elseif ( event == "UI_ERROR_MESSAGE" ) then
-- process gather error message
-- need to be in standard gather range to get the correct message to process.
if (arg1 and
(strfind(arg1, GATHERER_REQUIRE.." "..OLD_TRADE_HERBALISM) or strfind(arg1, GATHERER_NOSKILL.." "..OLD_TRADE_HERBALISM) or
strfind(arg1, OLD_TRADE_HERBALISM.." "..GATHERER_NOSKILL) or strfind(arg1, GATHERER_REQUIRE.." "..TRADE_MINING) or
strfind(arg1, GATHERER_NOSKILL.." "..TRADE_MINING) or strfind(arg1, TRADE_MINING.." "..GATHERER_NOSKILL))) then
Gatherer_ReadBuff(event);
end
-- process chatmessages
elseif ( event == "CHAT_MSG_SPELL_SELF_BUFF" ) then
Gatherer_ReadBuff(event);
-- process AddOn communication
elseif strfind(event, "CHAT_MSG_ADDON") then
Gatherer_AddonMessageEvent(arg1, arg2, arg3);
-- process tooltips text for 1.12
elseif ( event == "SPELLCAST_START" ) then
if ( arg1 and (arg1 == GATHER_HERBALISM or arg1 == TRADE_MINING or arg1 == TRADE_OPENING or arg1 =="") ) then
Gatherer_Debug("|cffffffffEvent :|r "..event.." => "..arg1);
Gatherer_currentNode = GameTooltipTextLeft1:GetText();
Gatherer_currentAction = arg1;
Gatherer_Debug("Current node: "..(Gatherer_currentNode or "nil"));
Gatherer_RecordFlag=1;
end
elseif ( event == "SPELLCAST_STOP" and Gatherer_RecordFlag == 1 ) then
Gatherer_ReadBuff(event);
Gatherer_currentNode=nil;
elseif ( event == "SPELLCAST_STOP" and Gatherer_RecordFlag == 0 ) then
Gatherer_currentNode=nil;
Gatherer_RecordFlag = 0;
elseif ( event == "SPELLCAST_FAILED" ) then
Gatherer_RecordFlag = 0;
elseif (event == "WORLD_MAP_UPDATE") then
if (WorldMapFrame:IsVisible()) then
local serverTime = GetTime();
if (Gatherer_Settings.mapMinder == true and Gatherer_MapOpen == false) then
-- Enhancement to open to last opened map if we were there less than a minute ago
-- Otherwise, go to the player's current position
local startContinent, startZone;
if (Gatherer_CloseMap and (serverTime - Gatherer_CloseMap.time < Gatherer_Settings.minderTime)) then
startContinent = Gatherer_CloseMap.continent;
startZone = Gatherer_CloseMap.zone;
else
startContinent, startZone = Gatherer_GetCurrentZone();
end
Gatherer_MapOpen = true;
if ( GetCurrentMapContinent()>0 and startZone and startZone > 0 ) then
SetMapZoom(startContinent, startZone);
end
end
Gatherer_MapOpen = true;
local mapContinent = GetCurrentMapContinent();
local mapZone = GetCurrentMapZone();
Gatherer_CloseMap = { continent = mapContinent, zone = mapZone, time = GetTime() };
GatherMain_Draw();
elseif (Gatherer_MapOpen) then
Gatherer_MapOpen = false;
Gatherer_ChangeMap();
GatherMain_Draw();
end
elseif ( event == "CLOSE_WORLD_MAP") then
-- never called apparently
Gatherer_MapOpen = false;
Gatherer_ChangeMap()
GatherMain_Draw();
elseif( event == "ADDON_LOADED") then
if ( myAddOnsFrame_Register ) then
-- myAddons Support
GathererDetails["name"] = "Gatherer";
GathererDetails["version"] = GATHERER_VERSION;
GathererDetails["author"] = "Norganna";
GathererDetails["website"] = "http://gathereraddon.com";
GathererDetails["category"] = MYADDONS_CATEGORY_PROFESSIONS;
GathererDetails["frame"] = "Gatherer";
GathererDetails["optionsframe"] = "GathererUI_DialogFrame";
-- Register the addon in myAddOns
if(myAddOnsFrame_Register) then
myAddOnsFrame_Register(GathererDetails, GathererHelp);
end
end
if (arg1 and string.lower(arg1) == "gatherer") then
Gatherer_Configuration.Load();
GATHERER_LOADED = true;
Gatherer_sanitizeDatabase(GatherItems)
Gatherer_OnUpdate(0, true);
Gatherer_Print("Gatherer p2p v"..GATHERER_VERSION.." -- Loaded!");
if (Gatherer_Settings.useMainmap == true) then
Gatherer_WorldMapDisplay:SetText("Hide Items");
else
Gatherer_WorldMapDisplay:SetText("Show Items");
end
-- Warning at logon on Gatherer Version number change to check for localization zone change (commented, not needed in 1.12)
--if ( GetLocale() == "deDE" and (not Gatherer_Settings.Version or (Gatherer_Settings.Version and Gatherer_Settings.Version ~= GATHERER_VERSION ))) then
-- StaticPopup_Show("GATHERER_VERSION_DIALOG");
--end
-- record current version number in order to identify the data for backup utilities
Gatherer_Settings.Version = GATHERER_VERSION;
-- Get values for World Map once for all
Gatherer_WorldMapDetailFrameWidth = WorldMapDetailFrame:GetWidth();
Gatherer_WorldMapDetailFrameHeight = WorldMapDetailFrame:GetHeight();
Gatherer_WorldMapPlayerFrameLevel = WorldMapPlayer:GetFrameLevel();
-- New backup format allows the user to permenantly save their data
-- in an automatically restoring file "GatherBase.lua"
-- All data in this file will be loaded "under" the saved data every
-- time the addon loads so that in the event of a savedVariables wipe
-- the next time they run WoW, their data will be back to the last
-- backed up point. (This utility will appear in a later version of
-- Gatherer as a Java applet)
if (GatherItemBase ~= nil) then
for c, cd in GatherItems do
for z, zd in cd do
for n,nd in zd do
for i,id in nd do
local matched = 0;
local max = 0;
for j,jd in GatherItemBase[c][z][n] do
if (math.abs(id.x- jd.y) < 0.05) then
matched = j;
end
max = j;
end
if (matched > 0) then
GatherItemBase[c][z][n][matched] = id;
else
GatherItemBase[c][z][n][max+1] = id;
end
end
end
end
end
GatherItems = GatherItemBase;
end
end
elseif ( event == "PLAYER_LOGIN" ) then
local SETTINGS = Gatherer_Settings;
local useMinimap = (SETTINGS.useMinimap) and "On" or "Off";
local useMainmap = (SETTINGS.useMainmap) and "On" or "Off";
local mapMinder = (SETTINGS.mapMinder) and "On" or "Off";
local minderTime = SETTINGS.minderTime.."s";
if ( SETTINGS.logInfo and SETTINGS.logInfo == "on" ) then
Gatherer_Print("[Player: "..Gather_Player..", Theme: "..SETTINGS.iconSet..", Mainmap: "..useMainmap..", Minimap: "..useMinimap..", MaxDist: "..SETTINGS.maxDist.." units, NoteCount: "..SETTINGS.number..", Fade: "..SETTINGS.fadePerc.."% at "..SETTINGS.fadeDist.." units, IconDist: "..SETTINGS.miniIconDist.."px on minimap, MapMinder: "..mapMinder.." ("..minderTime.."), Filters: herbs="..Gatherer_GetFilterVal("herbs")..", mining="..Gatherer_GetFilterVal("mining")..", treasure="..Gatherer_GetFilterVal("treasure").."]");
end
elseif ( event == "PLAYER_LOGOUT" ) then
Gatherer_Configuration.Save();
elseif ( event == "LEARNED_SPELL_IN_TAB" or event == "SPELLS_CHANGED" ) then
local numSkills = tonumber(GetNumSkillLines());
if ( GetNumSkillLines() > 0 ) then
Gatherer_GetSkills();
end
elseif ( event == "SKILL_LINES_CHANGED" ) then
local numSkills = tonumber(GetNumSkillLines());
if ( GetNumSkillLines() > 0 ) then
Gatherer_GetSkills();
end
else
Gatherer_ChatPrint("Gatherer Unknown event: "..event);
end
end
-- *************************************************************************
-- Filter related functions
local filterConversion = {
["herbs"] = 1,
["mining"] = 2,
["treasure"] = 0,
[0] = 0,
[1] = 1,
[2] = 2,
}
function Gatherer_SetFilter(type, value)
local type = filterConversion[type];
if ( type ) then
Gatherer_Settings.filters[type] = value;
end
end
function Gatherer_GetFilterVal(type)
local type = filterConversion[type];
value = Gatherer_Settings.filters[type];
if (not value) then return "auto"; end
return value;
end
function Gatherer_GetFilter(filter)
local value = Gatherer_GetFilterVal(filter);
local filterVal = false;
if (value == "on") then
filterVal = true;
elseif (value == "off") then
filterVal = false;
elseif (value == "auto") then
if (filter == "treasure") then
filterVal = true;
end
if (not GatherSkills) then
filterVal = true;
end
if ((GatherSkills[filter]) and (GatherSkills[filter] > 0)) then
filterVal = true;
end
end
return filterVal;
end
function Gatherer_GetSkills()
local GatherExpandedHeaders = {};
local i, j;
if ( not GatherSkills ) then GatherSkills = {}; end;
Gatherer:UnregisterEvent("SKILL_LINES_CHANGED");
-- search the skill tree for gathering skills
for i=0, GetNumSkillLines(), 1 do
local skillName, header, isExpanded, skillRank, _, _, _, _, _, _, _, _ = GetSkillLineInfo(i);
-- expand the header if necessary
if ( header and not isExpanded ) then
GatherExpandedHeaders[i] = skillName;
end
end
ExpandSkillHeader(0);
for i=1, GetNumSkillLines(), 1 do
local skillName, header, _, skillRank, _, _, _, _, _, _, _, _ = GetSkillLineInfo(i);
-- check for the skill name
if (skillName and not header) then
if (skillName == TRADE_HERBALISM) then
GatherSkills.herbs = skillRank;
elseif (skillName == TRADE_MINING) then
GatherSkills.mining = skillRank;
end
end
-- once we got both, no need to look the rest
if ( GatherSkills.herbs and GatherSkills.mining ) then
break;
end
end
-- close headers expanded during search process
for i=0, GetNumSkillLines() do
local skillName, header, isExpanded, _, _, _, _, _, _, _, _, _ = GetSkillLineInfo(i);
for j in GatherExpandedHeaders do
if ( header and skillName == GatherExpandedHeaders[j] ) then
CollapseSkillHeader(i);
GatherExpandedHeaders[j] = nil;
end
end
end
end
local function random_choice(t)
if not t then return end
local choiceI = nil;
local choiceO = nil;
local n = 0;
for i, o in pairs(t) do
n = n + 1
if math.random() < (1/n) then
choiceI, choiceO = i, o
end
end
return choiceI, choiceO
end
local function selectRandomGather()
-- type: () -> Tuple[GatherName, Gatherer_EGatherType, Continent, Zone, float, float, IconName, EGatherEventType]
-- returns the arguments set for the Gatherer_BroadcastGather function
local randomContinent, continentData = random_choice(GatherItems);
local randomZone, zoneData = random_choice(continentData);
local randomGather, gatherNodes = random_choice(zoneData);
local nodeIndex, randomNode = random_choice(gatherNodes);
Gatherer_ChatNotify('randomly selected: '..table.concat(
{randomContinent, randomZone, randomGather, nodeIndex}, ', '
), Gatherer_ENotificationType.debug);
if not nodeIndex then
return nil
end
local eventType = 1; -- EGatherEventType.no_skill
-- values don't matter, I just hate lua
local FISHING_GATHERS = {['floating wreckage']=0, ['school']=''};
if FISHING_GATHERS[randomGather] then
eventType = 2; -- EGatherEventType.fishing
end
return
randomGather, randomNode.gtype, randomContinent, randomZone, randomNode.x, randomNode.y,
randomNode.icon, eventType
end
-- *************************************************************************
-- Update related functions
local Gatherer_UpdateTicker = 0.0;
local Gatherer_AnnouncePeriod = 10;
local Gatherer_CycleCount = 0;
local Gatherer_SecondsToAnnounce = Gatherer_AnnouncePeriod;
function Gatherer_TimeCheck(timeDelta)
if (not GatherNotes) then
GatherNotes = { timeDiff=0, checkDiff=0 };
else
GatherNotes.checkDiff = GatherNotes.checkDiff + timeDelta;
if (GatherNotes.checkDiff > GATHERNOTE_CHECK_INTERVAL) then
GatherNotes.checkDiff = 0;
Gatherer_OnUpdate(0,true);
end
end
Gatherer_UpdateTicker = Gatherer_UpdateTicker + arg1;
if( Gatherer_UpdateTicker < 1 ) then
return
end
-- reset seconds counter
Gatherer_UpdateTicker = 0.0;
-- the code below will run not more frequently
-- than once a second
Gatherer_SecondsToAnnounce = Gatherer_SecondsToAnnounce - 1
-- Gatherer_Print('Every second '..Gatherer_SecondsToAnnounce..' seconds.')
if Gatherer_SecondsToAnnounce > 0 then
return
end
-- the code below will run not more frequently
-- than once Gatherer_AnnouncePeriod seconds
if Gatherer_Settings.p2p then
local args = {selectRandomGather()};
-- if failed to get a random node skip cycle
if not args[1] then
return
end
Gatherer_CycleCount = Gatherer_CycleCount + 1
if Gatherer_Settings.debug then
Gatherer_ChatPrint('Gatherer: Cycle #'..Gatherer_CycleCount);
Gatherer_ChatNotify(
'Sending random node once in '..Gatherer_AnnouncePeriod..' seconds.',
Gatherer_ENotificationType.sending
);
Gatherer_ChatNotify(
'args to send: '..table.concat(args, ', '), Gatherer_ENotificationType.sending
);
end
Gatherer_BroadcastGather(unpack(args))
end
Gatherer_SecondsToAnnounce = Gatherer_AnnouncePeriod
end
function Gatherer_OnUpdate(timeDelta, force)
if (not GATHERER_LOADED) then
Gatherer_Print("Gatherer not loaded");
return;
end
local SETTINGS = Gatherer_Settings;
if (Gatherer_InWorld == false ) then
return;
end
if (not SETTINGS.useMinimap) then
Gatherer_HideAll();
return;
end
local recalculate = false;
local needsUpdate = false;
if (not GatherNotes) then
GatherNotes = { timeDiff=0, checkDiff=0 };
needsUpdate = true;
else
GatherNotes.timeDiff = GatherNotes.timeDiff + timeDelta;
if (GatherNotes.timeDiff > GATHERNOTE_UPDATE_INTERVAL) then
needsUpdate = true;
end
end
if (force) then
needsUpdate = true;
recalculate = true;
end
if (needsUpdate) then
GatherNotes.timeDiff = 0;
-- Find the closest gathers
local continent, zone = Gatherer_GetCurrentZone();
if ((continent == 0) or (zone == 0)) then
Gatherer_HideAll();
return;
end
local inCity = GatherMap_InCity;
local zoomLevel = Minimap:GetZoom();
local px, py = Gatherer_PlayerPos();
if ((px == 0) and (py == 0)) then
return;
end
local xMovement = 0; if (ClosestGathers and ClosestGathers.px) then xMovement = math.abs(ClosestGathers.px - px); end
local yMovement = 0; if (ClosestGathers and ClosestGathers.py) then yMovement = math.abs(ClosestGathers.py - py); end
if (not ClosestGathers
or ClosestGathers.playerC ~= continent
or ClosestGathers.playerZ ~= zone
or xMovement + yMovement > 0.01) then
recalculate = true;
end
local displayNumber = 10;
if (SETTINGS.number and SETTINGS.number > 0) then
displayNumber = SETTINGS.number;
end
local playerDeltaX = 0;
local playerDeltaY = 0;
if (recalculate == true) then
ClosestGathers = {};
ClosestGathers = Gatherer_FindClosest(displayNumber);
if (ClosestGathers.count > 0) then
ClosestGathers.inCity = inCity;
ClosestGathers.zoomLevel = zoomLevel;
ClosestGathers.scaleX, ClosestGathers.scaleY = Gatherer_GetMapScale(continent, zone, inCity, zoomLevel);
end
else
if ((inCity ~= ClosestGathers.inCity) or (zoomLevel ~= ClosestGathers.zoomLevel)) then
ClosestGathers.inCity = inCity;
ClosestGathers.zoomLevel = zoomLevel;
ClosestGathers.scaleX, ClosestGathers.scaleY = Gatherer_GetMapScale(continent, zone, inCity, zoomLevel);
end
local absX, absY = Gatherer_AbsCoord(continent, zone, px, py);
playerDeltaX = ClosestGathers.playerX - absX;
playerDeltaY = ClosestGathers.playerY - absY;
end
local maxPos = 0;
if (ClosestGathers and ClosestGathers.count > 0) then
local closestPos, closestGather, closestID;
local currentPos = 1;
for closestPos, closestGather in ClosestGathers.items do
local skip_node = 0;
if ( currentPos > SETTINGS.number ) then skip_node =1; end
if ( skip_node == 0 ) then
-- need to position and label the corresponding button
local gatherNote = getglobal("GatherNote"..currentPos);
local gatherNoteTexture = getglobal("GatherNote"..currentPos.."Texture");
local itemDeltaX = closestGather.deltax+playerDeltaX;
local itemDeltaY = closestGather.deltay+playerDeltaY;
local offsX, offsY, gDist = Gatherer_MiniMapPos(itemDeltaX, itemDeltaY, ClosestGathers.scaleX, ClosestGathers.scaleY);
gatherNote:SetPoint("CENTER", Minimap, "CENTER", offsX, -offsY);
local iconSet = SETTINGS.iconSet;
local iDist = SETTINGS.miniIconDist;
if (not iconSet) then iconSet = "shaded"; end
if (not iDist) then iDist = 38; end
local _, _, sDist = Gatherer_MiniMapPos(iDist/10000, 0, ClosestGathers.scaleX, ClosestGathers.scaleY);
if ((iDist > 0) and (gDist > (math.floor(sDist)-1))) then
iconSet = "iconic";
end
local fadeDist = SETTINGS.fadeDist / 1000;
local fadePerc = SETTINGS.fadePerc / 100;
local alpha = 1.0;
local objDist = Gatherer_Pythag(itemDeltaX, itemDeltaY);
if ((fadeDist > 0) and (fadePerc > 0)) then
local distRatio = objDist / fadeDist ;
alpha = 1.0 - (math.min(1.0, math.max(0.0, distRatio)) * fadePerc);
end
local textureType = closestGather.item.gtype;
local textureIcon = closestGather.item.icon;
if ( type(textureType) == "number" ) then
textureType = Gatherer_EGatherType[textureType];
end
if ( type(textureIcon) == "number" ) then
textureIcon = Gatherer_GetDB_IconIndex(textureIcon, textureType);
end
if (not textureIcon) then textureIcon = "default"; end;
if (SETTINGS.iconSet == "iconshade" )
then
iconSet="iconic";
if ( gDist < (math.floor(sDist)-1) )
then
alpha=0.4;
end
end
if (not Gather_IconSet[iconSet]) then iconSet = "shaded"; end
if (not Gather_IconSet[iconSet][textureType]) then textureType = "Default"; end
local selectedTexture = Gather_IconSet[iconSet][textureType][textureIcon];
if (not selectedTexture) then
selectedTexture = Gather_IconSet[iconSet][textureType]["default"];
end
gatherNoteTexture:SetTexture(selectedTexture);
gatherNote:SetFrameLevel(MiniMapTrackingFrame:GetFrameLevel());
gatherNote:SetAlpha(alpha);
-- Added to allow hiding if under min distance
if ( SETTINGS.NoIconOnMinDist ~= nil and SETTINGS.NoIconOnMinDist == 1 ) then
if ( gDist < (math.floor(sDist)-1) ) then
gatherNote:Hide();
else
gatherNote:Show();
end
elseif ( (not SETTINGS.NoIconOnMinDist or SETTINGS.NoIconOnMinDist == 0) and SETTINGS.alphaUnderMinIcon and gDist < (math.floor(sDist)-1) ) then
if ( SETTINGS.iconSet and SETTINGS.iconSet ~= "iconshade" ) then
gatherNote:SetAlpha(SETTINGS.alphaUnderMinIcon / 100);
end
gatherNote:Show();
else
gatherNote:Show();
end
if (currentPos > maxPos) then maxPos = currentPos; end
currentPos = currentPos + 1;
end
skip_node = 0;
end
end
while (maxPos < GATHERER_MAXNUMNOTES) do
maxPos = maxPos+1;
local gatherNote = getglobal("GatherNote"..maxPos);
if ( gatherNote:IsShown() ) then
gatherNote:Hide();
end
end
end
end
-- *************************************************************************
-- UI related functions
function Gatherer_OnClick() -- function changed to be able to ping through the MiniNote (mostly direct copy) (only change: this -> Minimap)
local x, y = GetCursorPosition();
if ( Minimap.GetEffectiveScale ~= nil ) then
x = x / Minimap:GetEffectiveScale();
y = y / Minimap:GetEffectiveScale();
else
x = x / Minimap:GetScale();
y = y / Minimap:GetScale();
end
local cx, cy = Minimap:GetCenter();
x = x + CURSOR_OFFSET_X - cx;
y = y + CURSOR_OFFSET_Y - cy;
if ( sqrt(x * x + y * y) < (Minimap:GetWidth() / 2) ) then
Minimap:PingLocation(x, y);
end
end
-- *************************************************************************
-- Display functions
function Gatherer_HideAll()
local mmPos = 0;
while (mmPos < GATHERER_MAXNUMNOTES) do
mmPos = mmPos+1;
local gatherNote = getglobal("GatherNote"..mmPos);
gatherNote:Hide();
end