forked from aim2kill/FishingBuddy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FishingBuddy.lua
executable file
·1202 lines (1118 loc) · 38.3 KB
/
FishingBuddy.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
-- FishingBuddy
--
-- Everything you wanted support for in your fishing endeavors
-- Information for the stylin' fisherman
local POLES = {
["Fishing Pole"] = "6256:0:0:0",
["Strong Fishing Pole"] = "6365:0:0:0",
["Darkwood Fishing Pole"] = "6366:0:0:0",
["Big Iron Fishing Pole"] = "6367:0:0:0",
["Blump Family Fishing Pole"] = "12225:0:0:0",
["Nat Pagle's Extreme Angler FC-5000"] = "19022:0:0:0",
["Arcanite Fishing Pole"] = "19970:0:0:0",
-- yeah, so you can't really use these (for now :-)
["Dwarven Fishing Pole"] = "3567:0:0:0",
["Goblin Fishing Pole"] = "4598:0:0:0",
}
local FISHINGLURES = {
["6533:0:0:0"] = "Aquadynamic Fish Attractor", -- 100 for 5 mins
["7307:0:0:0"] = "Flesh Eating Worm", -- 75 for 10 mins
["6532:0:0:0"] = "Bright Baubles", -- 75 for 10 mins
["6811:0:0:0"] = "Aquadynamic Fish Lens", -- 50 for 10 mins
["6530:0:0:0"] = "Nightcrawlers", -- 50 for 10 mins
["6529:0:0:0"] = "Shiny Bauble", -- 25 for 10 mins
}
FishingBuddy.OPTIONS = {
{ ["name"] = "ShowNewFishies",
["text"] = FishingBuddy.CONFIG_SHOWNEWFISHIES_ONOFF,
["tooltip"] = FishingBuddy.CONFIG_SHOWNEWFISHIES_INFO,
["default"] = 1 },
{ ["name"] = "WatchFishies",
["text"] = FishingBuddy.CONFIG_FISHWATCH_ONOFF,
["tooltip"] = FishingBuddy.CONFIG_FISHWATCH_INFO,
["default"] = 1 },
{ ["name"] = "WatchCurrentSkill",
["text"] = FishingBuddy.CONFIG_FISHWATCHSKILL_ONOFF,
["tooltip"] = FishingBuddy.CONFIG_FISHWATCHSKILL_INFO,
["default"] = 1 },
{ ["name"] = "WatchCurrentZone",
["text"] = FishingBuddy.CONFIG_FISHWATCHZONE_ONOFF,
["tooltip"] = FishingBuddy.CONFIG_FISHWATCHZONE_INFO,
["default"] = 0 },
{ ["name"] = "WatchOnlyWhenFishing",
["text"] = FishingBuddy.CONFIG_FISHWATCHONLY_ONOFF,
["tooltip"] = FishingBuddy.CONFIG_FISHWATCHONLY_INFO,
["default"] = 1 },
{ ["name"] = "WatchFishPercent",
["text"] = FishingBuddy.CONFIG_FISHWATCHPERCENT_ONOFF,
["tooltip"] = FishingBuddy.CONFIG_FISHWATCHPERCENT_INFO,
["default"] = 1 },
{ ["name"] = "SortByPercent",
["text"] = FishingBuddy.CONFIG_SORTBYPERCENT_ONOFF,
["tooltip"] = FishingBuddy.CONFIG_SORTBYPERCENT_INFO,
["default"] = 1 },
{ ["name"] = "SuitUpFirst",
["text"] = FishingBuddy.CONFIG_SUITUPFIRST_ONOFF,
["tooltip"] = FishingBuddy.CONFIG_SUITUPFIRST_INFO,
["default"] = 0 },
{ ["name"] = "EasyCast",
["text"] = FishingBuddy.CONFIG_EASYCAST_ONOFF,
["tooltip"] = FishingBuddy.CONFIG_EASYCAST_INFO,
["default"] = 1 },
{ ["name"] = "FastCast",
["text"] = FishingBuddy.CONFIG_FASTCAST_ONOFF,
["tooltip"] = FishingBuddy.CONFIG_FASTCAST_INFO,
["default"] = 1 },
{ ["name"] = "EasyLures",
["text"] = FishingBuddy.CONFIG_EASYLURES_ONOFF,
["tooltip"] = FishingBuddy.CONFIG_EASYLURES_INFO,
["default"] = 0 },
{ ["name"] = "STVTimer",
["text"] = FishingBuddy.CONFIG_STVTIMER_ONOFF,
["tooltip"] = FishingBuddy.CONFIG_STVTIMER_INFO,
["default"] = 0 },
{ ["name"] = "UseButtonHole",
["text"] = FishingBuddy.CONFIG_USEBUTTONHOLE_ONOFF,
["tooltip"] = FishingBuddy.CONFIG_USEBUTTONHOLE_INFO,
["default"] = 0,
["check"] = function () return ButtonHole ~= nil; end,
["checkfail"] = 0 },
{ ["name"] = "MinimapButtonVisible",
["text"] = FishingBuddy.CONFIG_MINIMAPBUTTON_ONOFF,
["tooltip"] = FishingBuddy.CONFIG_MINIMAPBUTTON_INFO,
["default"] = 1,
["check"] = function () return not FishingBuddy.UseButtonHole(); end,
["checkfail"] = 1 },
{ ["name"] = "EnhanceFishingSounds",
["text"] = FishingBuddy.CONFIG_ENHANCESOUNDS_ONOFF,
["tooltip"] = FishingBuddy.CONFIG_ENHANCESOUNDS_INFO,
["default"] = 1 },
}
FishingBuddy.ByFishie = nil;
FishingBuddy.SortedFishies = nil;
local ActionStartTime = 0;
local ActionDoubleTime = 0;
local ACTIONDOWNWAIT = 0.2;
local ACTIONDOUBLEWAIT = 0.4;
local SavedAddMessage = nil;
FishingBuddy.SavedToggleMinimap = nil;
local StartedFishing = nil;
local TestingLures = false;
local CastingNow = false;
local AddingLure = false;
local FishingSpellID = nil;
local FishingSkillName = nil;
local gotSetupDone = false;
local playerName = nil;
local realmName = nil;
FishingBuddy.currentFishies = {};
local DEFAULT_MINIMAP_POSITION = 256;
-- Fill in the player name and realm
FishingBuddy.SetupNameInfo = function()
playerName = UnitName("player");
realmName = GetRealmName();
return playerName, realmName;
end
FishingBuddy.GetWasWearing = function()
if FishingBuddy_Player["WasWearing"] then
return FishingBuddy_Player["WasWearing"];
end
end
FishingBuddy.SetWasWearing = function(outfit)
FishingBuddy_Player["WasWearing"] = outfit;
end
FishingBuddy.GetOutfitItem = function(slotName)
if (FishingBuddy_Player["Outfit"]) then
return FishingBuddy_Player["Outfit"][slotName];
end
end
FishingBuddy.GetOutfit = function()
return FishingBuddy_Player["Outfit"];
end
FishingBuddy.SetOutfit = function(outfit)
FishingBuddy_Player["Outfit"] = outfit;
end
local function GetSetting(setting)
if ( not FishingBuddy_Player or
not FishingBuddy_Player["Settings"] ) then
return;
end
return FishingBuddy_Player["Settings"][setting];
end
FishingBuddy.GetSetting = GetSetting;
local function SetSetting(setting, value)
FishingBuddy_Player["Settings"][setting] = value;
end
FishingBuddy.SetSetting = SetSetting;
-- handle option keys for enabling casting
local key_actions = {
[FishingBuddy.KEYS_NONE] = function() return true; end,
[FishingBuddy.KEYS_SHIFT] = function() return IsShiftKeyDown(); end,
[FishingBuddy.KEYS_CTRL] = function() return IsControlKeyDown(); end,
[FishingBuddy.KEYS_ALT] = function() return IsAltKeyDown(); end,
}
local function CastingKeys()
local setting = GetSetting("EasyCastKeys");
if ( key_actions[setting] ) then
return key_actions[setting]();
else
return true;
end
end
-- get our current fishing skill level
local lastSkillIndex = nil;
FishingBuddy.GetCurrentSkill = function()
if ( lastSkillIndex ) then
local name, _, _, rank, _, modifier = GetSkillLineInfo(lastSkillIndex);
if ( name == FishingBuddy.GetFishingSkillName() )then
return rank, modifier;
end
end
local n = GetNumSkillLines();
for i=1,n do
local name, _, _, rank, _, modifier = GetSkillLineInfo(i);
if ( name == FishingBuddy.GetFishingSkillName() ) then
lastSkillIndex = i;
return rank, modifier;
end
end
return 0, 0;
end
FishingBuddy.SetZoneLevel = function(zone, subzone, fishid)
local skill, mods = FishingBuddy.GetCurrentSkill();
local fs = FishingBuddy_Info["FishingSkill"];
if ( not fs[zone] ) then
fs[zone] = {};
end
local skillcheck = skill + mods;
if ( skillcheck > 0 ) then
if ( not fs[zone][subzone] or skillcheck < fs[zone][subzone] ) then
fs[zone][subzone] = skillcheck;
end
if ( fishie ) then
if ( not FishingBuddy_Info["Fishies"][fishid].level or
skillcheck < FishingBuddy_Info["Fishies"][fishid].level ) then
FishingBuddy_Info["Fishies"][fishid].level = skillcheck;
FishingBuddy_Info["Fishies"][fishid].skill = skill;
FishingBuddy_Info["Fishies"][fishid].mods = mods;
end
end
end
end
local OldBindingKey;
local function UpdateBindings(onoff)
if ( onoff ) then
if ( not OldKeyBinding ) then
OldKeyBinding = GetBindingKey("TURNORACTION");
if ( OldKeyBinding ) then
SetBinding(OldKeyBinding, "FISHINGBUDDY_PERFORMCAST");
else
FishingBuddy.UIError(FishingBuddy.TOOMANYFISHERMEN);
end
end
else
if ( OldKeyBinding ) then
SetBinding(OldKeyBinding, "TURNORACTION");
OldKeyBinding = nil;
end
end
end
FishingBuddy.UpdateBindings = UpdateBindings;
-- Shamelessly stolen from TackleBox
local function IsFishingPole()
-- Get the main hand item texture
local slot = GetInventorySlotInfo("MainHandSlot");
local itemTexture = GetInventoryItemTexture("player", slot);
-- If there is infact an item in the main hand, and it's texture
-- that matches the fishing pole texture, then we have a fishing pole
if ( itemTexture and string.find(itemTexture, "INV_Fishingpole") ) then
local link = GetInventoryItemLink("player", slot);
local _, id, _ = FishingBuddy.SplitLink(link);
-- Make sure it's not "Nat Pagle's Fish Terminator"
return (id ~= 19944);
end
return false;
end
FishingBuddy.IsFishingPole = IsFishingPole;
-- override the error message method (need an object as the first arg)
local function UIError_AddMessage( o, msg, a, r, g, b, hold )
-- If we should be hiding the can't use item error, then do so
if ( TestingLures and msg == ERR_CANT_USE_ITEM ) then
-- We have the can't use item error, so abort
return;
end
--Call the original
local obj = SavedAddMessage.obj;
local method = SavedAddMessage.method;
return method( obj, msg, a, r, g, b, hold );
end
FishingBuddy.AddMessage = UIError_AddMessage;
local function HijackCheck()
return ( GetSetting("EasyCast") == 1 and
CastingKeys() and IsFishingPole() );
end
local SavedWFOnMouseUp;
local SavedWFOnMouseDown;
-- handle mouse up and mouse down in the WorldFrame so that we can steal
-- the hardware events to implement 'Easy Cast'
-- Thanks to the Cosmos team for figuring this one out -- I didn't realize
-- that the mouse handler in the WorldFrame got everything first!
local function WF_OnMouseDown()
-- Only steal 'right clicks'
if ( arg1 == "RightButton" and HijackCheck() ) then
FishingBuddy.ActionStartCheck();
end
if ( SavedWFOnMouseDown ) then
SavedWFOnMouseDown();
end
end
-- disable click to move if we're fishing
local resetClickToMove = false;
local function WF_OnMouseUp()
local retval;
if ( SavedWFOnMouseUp ) then
retval = SavedWFOnMouseUp();
end
-- Only steal 'right clicks'
if ( arg1 == "RightButton" ) then
-- we fail if there are multiple modifier keys
if ( IsAltKeyDown() and ( IsShiftKeyDown() or IsControlKeyDown() ) ) then
return retval;
end
if ( IsShiftKeyDown() and IsControlKeyDown() ) then
return retval;
end
if ( HijackCheck() ) then
FishingBuddy.StopCastingCheck();
elseif ( resetClickToMove ) then
-- Re-enable Click-to-Move if we changed it
SetCVar("autointeract", "1");
resetClickToMove = nil;
end
end
return retval;
end
-- Find things in our inventory
local function FindItem(id)
if ( id ) then
local numSlots = 0;
-- check each of the bags on the player
for bag=0, NUM_BAG_FRAMES do
-- get the number of slots in the bag (0 if no bag)
numSlots = GetContainerNumSlots(bag);
if (numSlots > 0) then
-- check each slot in the bag
for slot=1, numSlots do
local link = GetContainerItemLink (bag,slot);
if (link) then
local c, i, n = FishingBuddy.SplitLink(link);
local check = string.gsub(i, "^(%d+):(%d+):(%d+):(%d+)$", "%1:%2:0:0");
if ( check == id ) then
return bag, slot;
end
end
end
end
end
end
return nil, nil;
end
local function SafeHookMethod(object, method, newmethod)
local oldValue = object[method];
if ( oldValue ~= getglobal(newmethod) ) then
object[method] = newmethod;
return true;
end
return false;
end
local function SafeHookScript(frame, handlername, newscript)
local oldValue = frame:GetScript(handlername);
frame:SetScript(handlername, newscript);
return oldValue;
end
-- Something else that should be in a library
FishingBuddy.SplitLink = function(link)
if ( link ) then
local _,_, color, item, name = string.find(link, "|c(%x+)|Hitem:(%d+:%d+:%d+:%d+)|h%[(.-)%]|h|r");
return color, item, name;
end
end
FishingBuddy.SplitFishLink = function(link)
if ( link ) then
local _,_, color, id, name = string.find(link, "|c(%x+)|Hitem:(%d+):%d+:%d+:%d+|h%[(.-)%]|h|r");
return color, tonumber(id), name;
end
end
-- handle the vagaries of zones and subzones
FishingBuddy.GetZoneInfo = function()
local zone = GetRealZoneText();
local subzone = GetSubZoneText();
if ( not zone or zone == "" ) then
zone = FishingBuddy.UNKNOWN;
end
if ( not subzone or subzone == "" ) then
subzone = zone;
end
return zone, subzone;
end
FishingBuddy.AddFishie = function(color, id, name, zone, subzone, texture, quantity, quality)
if ( not FishingBuddy_Info["Fishies"][id] ) then
FishingBuddy_Info["Fishies"][id] = { };
FishingBuddy_Info["Fishies"][id].name = name;
FishingBuddy_Info["Fishies"][id].texture = texture;
FishingBuddy_Info["Fishies"][id].quality = quality;
if ( color ~= "ffffffff" ) then
FishingBuddy_Info["Fishies"][id].color = color;
end
if ( FishingBuddy.SortedFishies ) then
tinsert(FishingBuddy.SortedFishies, { text = name, id = id });
FishingBuddy.FishSort(FishingBuddy.SortedFishies, true);
end
end
if ( not zone ) then
zone = FishingBuddy.UNKNOWN;
end
if ( not subzone ) then
subzone = zone;
end
if ( not FishingBuddy.currentFishies[subzone] ) then
FishingBuddy.currentFishies[subzone] = {};
end
if ( not FishingBuddy.currentFishies[subzone][id] ) then
FishingBuddy.currentFishies[subzone][id] = quantity;
else
FishingBuddy.currentFishies[subzone][id] = FishingBuddy.currentFishies[subzone][id] + quantity;
end
if( not FishingBuddy_Info["FishingHoles"][zone] ) then
FishingBuddy_Info["FishingHoles"][zone] = { };
tinsert(FishingBuddy.SortedZones, zone);
table.sort(FishingBuddy.SortedZones);
end
if( not FishingBuddy_Info["FishingHoles"][zone][subzone] ) then
FishingBuddy_Info["FishingHoles"][zone][subzone] = { };
FishingBuddy.SortedByZone[zone] = {};
tinsert(FishingBuddy.SortedByZone[zone], subzone);
table.sort(FishingBuddy.SortedByZone[zone]);
tinsert(FishingBuddy.SortedSubZones, subzone);
table.sort(FishingBuddy.SortedSubZones);
end
local fh = FishingBuddy_Info["FishingHoles"][zone];
if ( not fh[subzone][id] ) then
fh[subzone][id] = quantity;
if ( GetSetting("ShowNewFishies") == 1 ) then
FishingBuddy.Print(FishingBuddy.ADDFISHIEMSG, name, subzone);
end
else
fh[subzone][id] = fh[subzone][id] + quantity;
end
if ( FishingBuddy.ByFishie ) then
if ( not FishingBuddy.ByFishie[id] ) then
FishingBuddy.ByFishie[id] = {};
end
if ( not FishingBuddy.ByFishie[id][subzone] ) then
FishingBuddy.ByFishie[id][subzone] = quantity;
else
FishingBuddy.ByFishie[id][subzone] = FishingBuddy.ByFishie[id][subzone] + quantity;
end
end
FishingBuddy.Locations.DataChanged(zone, subzone, fishie);
FishingBuddy.WatchUpdate();
end
FishingBuddy.GetFishie = function(fishid)
if( FishingBuddy_Info["Fishies"][fishid] ) then
return string.format("%d:0:0:0", fishid),
FishingBuddy_Info["Fishies"][fishid].texture,
FishingBuddy_Info["Fishies"][fishid].color,
FishingBuddy_Info["Fishies"][fishid].quantity,
FishingBuddy_Info["Fishies"][fishid].quality,
FishingBuddy_Info["Fishies"][fishid].name;
end
end
local function ImportFish()
local oldShowNewFishies = GetSetting("ShowNewFishies");
SetSetting("ShowNewFishies");
if ( FishInfo2DataSub and FishingBuddy_Info["FishInfo2"] == 0 ) then
for toon in FishInfo2DataSub do
if ( not string.find(toon, "|User$") ) then
for fishie in FishInfo2DataSub[toon] do
local texture = FishInfo2DataSub[toon][fishie]["texture"];
local quality = FishInfo2DataSub[toon][fishie]["rarity"];
local fz = FishInfo2DataSub[toon][fishie]["zones"];
local link = FishInfo2DataSub[toon][fishie]["link"];
if ( link ) then
local _,_,id = string.find(link, "^(%d+):");
for zone in fz do
for subzone in fz[zone] do
local quantity = fz[zone][subzone];
FishingBuddy.AddFishie("ffffffff", id, fishie, zone, subzone, texture, quantity, quality)
end
end
end
end
end
end
FishingBuddy_Info["FishInfo2"] = 1;
FishingBuddy.Print(FishingBuddy.IMPORTMSG, "FishInfo2");
-- elseif ( imppfishinfoDB and FishingBuddy_Info["ImppDBLoaded"] == 0 ) then
-- for subzone in imppfishinfoDB do
-- for item in imppfishinfoDB[subzone]["itemnames"] do
-- local quantity = imppfishinfoDB[subzone]["itemnames"][item].number;
-- local texture = imppfishinfoDB[subzone]["itemnames"][item].texture;
-- local quality = imppfishinfoDB[subzone]["itemnames"][item].quality;
-- FishingBuddy.AddFishie(color, id, name, subzone, texture, item, quantity, quality)
-- end
-- end
-- FishingBuddy_Info["ImppDBLoaded"] = 1;
-- FishingBuddy.Print(FishingBuddy.IMPORTMSG, "Impp's fishinfo");
-- elseif ( DataFishDB and FishingBuddy_Info["DataFish"] == 0 ) then
-- for fishie in DataFishDB["catches"] do
-- for zone in DataFishDB["catches"][fishie]["locnames"] do
-- for subzone in DataFishDB["catches"][fishie]["locnames"][zone] do
-- local dfl = DataFishDB["locations"][subzone]["itemnames"][fishie];
-- local quantity = dfl["number"];
-- local texture = dfl["texture"];
-- local quality = dfl["quality"];
-- FishingBuddy.AddFishie(color, id, name, zone, subzone, texture, quantity, quality)
-- end
-- end
-- end
-- FishingBuddy_Info["DataFish"] = 1;
-- FishingBuddy.Print(FishingBuddy.IMPORTMSG, "DataFish");
else
FishingBuddy.Message(FishingBuddy.NOIMPORTMSG);
end
SetSetting("ShowNewFishies", oldShowNewFishies);
end
local function FindSpellID(thisone)
local id = 1;
local spellTexture = GetSpellTexture(id, BOOKTYPE_SPELL);
while (spellTexture) do
if (spellTexture and spellTexture == thisone) then
return id;
end
id = id + 1;
spellTexture = GetSpellTexture(id, BOOKTYPE_SPELL);
end
return nil;
end
local function GetFishingSpellID()
if ( not FishingSpellID or not FishingSkillName) then
FishingSpellID = FindSpellID(FishingBuddy.FISHINGTEXTURE);
end
if ( FishingSpellID and not FishingSkillName ) then
FishingSkillName = GetSpellName(FishingSpellID, BOOKTYPE_SPELL);
end
end
FishingBuddy.GetFishingSkillName = function()
GetFishingSpellID();
if ( not FishingSkillName ) then
return FishingBuddy.FISHINGSKILL;
else
return FishingSkillName;
end
end
local function InvokeFishing()
GetFishingSpellID();
if ( FishingSpellID ) then
CastSpell(FishingSpellID, BOOKTYPE_SPELL);
end
end
-- do everything we think is necessary when we start fishing
-- even if we didn't do the switch to a fishing pole
local function StartFishingMode()
if ( not StartedFishing ) then
StartedFishing = GetTime();
FishingBuddy.EnhanceFishingSounds(true);
FishingBuddy.WatchUpdate();
end
end
FishingBuddy.StartFishingMode = StartFishingMode;
local function StopFishingMode()
if ( StartedFishing ) then
FishingBuddy.EnhanceFishingSounds(false);
FishingBuddy.WatchUpdate();
StartedFishing = nil;
end
if ( resetClickToMove ) then
-- Re-enable Click-to-Move if we changed it
SetCVar("autointeract", "1");
resetClickToMove = nil;
end
end
FishingBuddy.StopFishingMode = StopFishingMode;
local function FishingMode()
if ( IsFishingPole() ) then
StartFishingMode();
else
StopFishingMode();
end
end
FishingBuddy.FishingMode = FishingMode;
local function OnFishingBobber()
if ( GameTooltip:IsVisible() ) then
local text = getglobal("GameTooltipTextLeft1");
if ( text ) then
text = text:GetText();
-- let a partial match work (for translations)
return ( text and string.find(text, FishingBuddy.BOBBER_NAME ) );
end
end
return false;
end
-- Easy lures (borrowed from Mugendai's excellent code)
local function UpdateLure()
-- if the pole has an enchantment, we can assume it's got a lure on it (so far, anyway)
if ( ( GetSetting("EasyLures") == 1 ) and not GetWeaponEnchantInfo() ) then
-- trap message handler if we haven't already
if ( not SavedAddMessage ) then
FishingBuddy.TrapUIErrors();
end
--Check for a lure in the bags, starting with the highest power one
local bag, slot;
for lure in FISHINGLURES do
--If we find this lure in the bag, then use it
bag, slot = FindItem(lure);
if (bag and slot) then
--We need to temporarily disable the cant use item error, incase this item is too high of a level to use
TestingLures = true;
--Temporarily disable error message sounds, incase this item is too high of a level to use
local soundState = GetCVar("EnableErrorSpeech");
if ( soundState == "1" ) then
SetCVar("EnableErrorSpeech", 0);
end
--Try to use the item
UseContainerItem(bag, slot);
-- re-enable the can't use item error message
TestingLures = false;
-- re-enable error message sounds
if ( soundState == "1" ) then
SetCVar("EnableErrorSpeech", 1);
end
-- if we have a targeting cursor, then we succesfully used the lure
if ( SpellIsTargeting() ) then
-- apply the lure to the fishing pole
local mainhandslot = GetInventorySlotInfo("MainHandSlot");
PickupInventoryItem(mainhandslot);
AddingLure = true;
return true;
end
end
end
end
return false;
end
FishingBuddy.ActionStartCheck = function()
-- Disable Click-to-Move if we're fishing
if ( GetCVar("autointeract") == "1" ) then
resetClickToMove = true;
SetCVar("autointeract", "0");
end
-- Don't interrupt putting on a lure, or if we're not fastcasting
if ( AddingLure ) then
ActionStartTime = 0;
else
ActionStartTime = GetTime();
end
end
-- add the double click checking in based on the code is Cosmos
FishingBuddy.StopCastingCheck = function()
if ( not ActionStartTime ) then
ActionStartTime = 0;
end
if ( not ActionDoubleTime ) then
ActionDoubleTime = 0;
end
local time = GetTime();
local pressTime = time - ActionStartTime;
local doubleTime = time - ActionDoubleTime;
-- if we're not putting on a lure and the casting modifiers are good
if ( not SpellIsTargeting() ) then
-- if the click was "short" enough that we're going to treat it
-- as a cast
if ( ActionStartTime > 0 and ACTIONDOWNWAIT >= pressTime) then
-- if we're already casting, enforce double click timing
if ( GetSetting("FastCast") ~= 1 and CastingNow and
( ActionDoubleTime == 0 or ACTIONDOUBLEWAIT < doubleTime ) ) then
ActionDoubleTime = GetTime();
else
ActionDoubleTime = 0;
-- rebind the mouse event
UpdateBindings(true);
end
end
end
end
FishingBuddy.PerformCast = function()
-- We're stealing the mouse-up hardware event, make sure we exit MouseLook
if ( IsMouselooking() ) then
MouselookStop();
end
-- reset the TURNORACTION binding so that everything else works 'right'
UpdateBindings(false);
-- put on a lure if we need to
if ( not UpdateLure() ) then
InvokeFishing();
end
end
FishingBuddy.TrapUIErrors = function()
local temp = {};
temp.obj= UIErrorsFrame;
temp.method = UIErrorsFrame["AddMessage"];
if ( SafeHookMethod(UIErrorsFrame, "AddMessage", FishingBuddy.AddMessage) ) then
SavedAddMessage = temp;
end
end
FishingBuddy.TrapWorldMouse = function()
SavedWFOnMouseUp = SafeHookScript(WorldFrame, "OnMouseUp", WF_OnMouseUp);
SavedWFOnMouseDown = SafeHookScript(WorldFrame, "OnMouseDown", WF_OnMouseDown);
end
-- User interface handling
FishingBuddy.Commands = {};
FishingBuddy.Commands[FishingBuddy.SWITCH] = {};
FishingBuddy.Commands[FishingBuddy.SWITCH].func = function()
FishingBuddy.OutfitManager.Switch();
return true;
end;
FishingBuddy.Commands[FishingBuddy.CURRENT] = {};
FishingBuddy.Commands[FishingBuddy.CURRENT].help = FishingBuddy.CURRENT_HELP;
FishingBuddy.Commands[FishingBuddy.CURRENT].func =
function(what)
if ( what and what == FishingBuddy.RESET) then
FishingBuddy.currentFishies = {};
FishingMode();
return true;
end
end;
FishingBuddy.Commands[FishingBuddy.IMPORT] = {};
FishingBuddy.Commands[FishingBuddy.IMPORT].help = FishingBuddy.IMPORT_HELP;
FishingBuddy.Commands[FishingBuddy.IMPORT].func =
function()
ImportFish();
return true;
end;
FishingBuddy.Commands[FishingBuddy.CLEANUP] = {};
FishingBuddy.Commands[FishingBuddy.CLEANUP].help = FishingBuddy.CLEANUP_HELP;
FishingBuddy.Commands[FishingBuddy.CLEANUP].func =
function(what)
local tabs = { "Settings", "Outfit", "WasWearing" };
local rnames = {};
local onames = {};
if ( not what or what == FishingBuddy.CHECK ) then
if ( FishingBuddy_Info["Settings"] ) then
for name in FishingBuddy_Info["Settings"] do
tinsert(onames, name);
end
end
if ( FishingBuddy_Info[realmName] ) then
local fs = FishingBuddy_Info[realmName]["Settings"];
if ( fs ) then
for name,info in fs do
tinsert(rnames, name);
end
end
end
if ( next(rnames) or next(onames) ) then
if ( next(rnames) ) then
FishingBuddy.Print(FishingBuddy.CLEANUP_WILLMSG, realmName,
FishingBuddy.EnglishList(rnames));
end
if ( next(onames) ) then
FishingBuddy.Print(FishingBuddy.CLEANUP_WILLMSG,
FishingBuddy.NOREALM,
FishingBuddy.EnglishList(onames));
end
else
FishingBuddy.Message(FishingBuddy.CLEANUP_NONEMSG);
end
return true;
else
if ( what == FishingBuddy.NOW ) then
if ( FishingBuddy_Info["Settings"] ) then
for name in FishingBuddy_Info["Settings"] do
tinsert(onames, name);
end
end
if ( FishingBuddy_Info[realmName] ) then
local fs = FishingBuddy_Info[realmName]["Settings"];
if ( fs ) then
for name,info in fs do
tinsert(rnames, name);
end
end
end
else
if ( FishingBuddy_Info["Settings"] and FishingBuddy_Info["Settings"][what] ) then
tinsert(onames, what);
elseif ( FishingBuddy_Info[realmName] and
FishingBuddy_Info[realmName]["Settings"] and
FishingBuddy_Info[realmName]["Settings"][what] ) then
tinsert(rnames, what);
else
FishingBuddy.Print(FishingBuddy.CLEANUP_NOOLDMSG, what);
return true;
end
end
if ( next(rnames) or next(onames) ) then
if ( next(rnames) ) then
for _,name in rnames do
for _,tab in tabs do
if ( FishingBuddy_Info[realmName] and FishingBuddy_Info[realmName][tab] ) then
FishingBuddy_Info[realmName][tab][name] = nil;
if ( next(FishingBuddy_Info[realmName][tab]) == nil ) then
FishingBuddy_Info[realmName][tab] = nil;
end
end
end
end
if ( FishingBuddy_Info[realmName] and next(FishingBuddy_Info[realmName]) == nil ) then
FishingBuddy_Info[realmName] = nil;
end
FishingBuddy.Print(FishingBuddy.CLEANUP_DONEMSG, realmName,
FishingBuddy.EnglishList(rnames));
end
if ( next(onames) ) then
for _,name in onames do
for _,tab in tabs do
if ( FishingBuddy_Info[tab] ) then
FishingBuddy_Info[tab][name] = nil;
if ( next(FishingBuddy_Info[tab]) ) then
FishingBuddy_Info[tab] = nil;
end
end
end
end
FishingBuddy.Print(FishingBuddy.CLEANUP_DONEMSG,
FishingBuddy.NOREALM,
FishingBuddy.EnglishList(onames));
end
else
FishingBuddy.Message(FishingBuddy.CLEANUP_NONEMSG);
end
return true;
end
end;
local function nextarg(msg, pattern)
if ( not msg or not pattern ) then
return nil, nil;
end
local s,e = string.find(msg, pattern);
if ( s ) then
local word = strsub(msg, s, e);
msg = strsub(msg, e+1);
return word, msg;
end
return nil, msg;
end
FishingBuddy.Command = function(msg)
if ( not msg ) then
return;
end
if ( FishingBuddy.IsLoaded() ) then
-- collect arguments (whee, lua string manipulation)
local cmd;
cmd, msg = nextarg(msg, "[%w]+");
-- the empty string gives us no args at all
if ( not cmd ) then
-- toggle window
if ( FishingBuddyFrame:IsVisible() ) then
HideUIPanel(FishingBuddyFrame);
else
ShowUIPanel(FishingBuddyFrame);
end
elseif ( cmd == FishingBuddy.HELP or cmd == "help" ) then
FishingBuddy.Output(FishingBuddy.WINDOW_TITLE);
FishingBuddy.PrintHelp(FishingBuddy.HELPMSG);
else
local command = FishingBuddy.Commands[cmd];
if ( command ) then
local args = {};
local goodargs = true;
if ( command.args ) then
for _,pat in command.args do
local w, msg = nextarg(msg, pat);
if ( not w ) then
goodargs = false;
break;
end
tinsert(args, w);
end
else
local a;
while ( msg ) do
a, msg = nextarg(msg, "[%w]+");
if ( not a ) then
break;
end
tinsert(args, a);
end
end
if ( not goodargs or not command.func(unpack(args)) ) then
if ( command.help ) then
FishingBuddy.PrintHelp(command.help);
else
FishingBuddy.Debug("command failed");
end
end
else
FishingBuddy.Command("help");
end
end
else
FishingBuddy.Error(FishingBuddy.FAILEDINIT);
end
end
FishingBuddy.OnLoad = function()
this:RegisterEvent("PLAYER_LOGIN");
this:RegisterEvent("PLAYER_LOGOUT");
this:RegisterEvent("VARIABLES_LOADED");
this:RegisterEvent("ITEM_LOCK_CHANGED");
this:RegisterEvent("LOOT_OPENED");
this:RegisterEvent("ZONE_CHANGED");
this:RegisterEvent("MINIMAP_ZONE_CHANGED");
this:RegisterEvent("SPELLS_CHANGED");
this:RegisterEvent("SPELLCAST_CHANNEL_START");
this:RegisterEvent("SPELLCAST_CHANNEL_STOP");
this:RegisterEvent("SPELLCAST_START");
this:RegisterEvent("SPELLCAST_STOP");
this:RegisterEvent("SPELLCAST_INTERRUPTED");
this:RegisterEvent("SPELLCAST_FAILED");
this:RegisterEvent("SKILL_LINES_CHANGED");
-- Set up command
SlashCmdList["fishingbuddy"] = FishingBuddy.Command;
SLASH_fishingbuddy1 = "/fishingbuddy";
SLASH_fishingbuddy2 = "/fb";
FishingBuddy.Output(FishingBuddy.WINDOW_TITLE.." loaded");
end
FishingBuddy.OnEvent = function()
local needUpdate = false;
if ( event == "VARIABLES_LOADED" ) then
FishingBuddy.Initialize();
elseif ( event == "PLAYER_LOGIN" ) then
-- set up outfit stuff
FishingBuddy.OutfitManager.Initialize();
FishingMode();
elseif ( event == "PLAYER_LOGOUT" ) then
-- reset the fishing sounds, if we need to
StopFishingMode();
FishingBuddy.SavePlayerInfo();
elseif ( event == "ITEM_LOCK_CHANGED" ) then
FishingMode();
elseif ( event == "LOOT_OPENED" ) then
if ( IsFishingLoot()) then
local zone, subzone = FishingBuddy.GetZoneInfo();
for index = 1, GetNumLootItems(), 1 do
if (LootSlotIsItem(index)) then
local texture, fishie, quantity, quality = GetLootSlotInfo(index);
local link = GetLootSlotLink(index);
local color, id, name = FishingBuddy.SplitFishLink(link);
FishingBuddy.AddFishie(color, id, name, zone, subzone, texture, quantity, quality);
if ( FishingBuddy.AddTracking ) then
FishingBuddy.AddTracking(id, name);
end
FishingBuddy.SetZoneLevel(zone, subzone, id);
end
end
end
elseif ( event == "ZONE_CHANGED" or event == "MINIMAP_ZONE_CHANGED" ) then
if ( not FishingBuddy.IsLoaded() ) then
return;
end
FishingBuddy.currentFishies = {};
needUpdate = true;
elseif ( event == "SKILL_LINES_CHANGED" ) then
if ( GetSetting("WatchCurrentSkill") == 1 ) then
needUpdate = true;
end
elseif ( event == "SPELLS_CHANGED" ) then
-- Fishing might have moved, go look again
FishingSpellID = nil;
else
-- Mugendai is one sharp cookie (shamelessly stealing from TackleBox again)
-- Keep up with whether or not we are casting