-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFishingBuddy.lua
1612 lines (1457 loc) · 49.7 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
-- 5.0.4 has a problem with a global "_" (see some for loops below)
local _
local FL = LibStub("LibFishing-1.0");
local HBD = FL.HBD;
local LO = LibStub("LibOptionsFrame-1.0");
local CurLoc = GetLocale();
local PLANS = FishingBuddy.FishingPlans;
-- 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",
["Seth's Graphite Fishing Pole"] = "25978:0:0:0",
["Nat's Lucky Fishing Pole"] = "45858:0:0:0",
["Mastercraft Kalu'ak Fishing Pole"] = "44050:0:0:0",
["Bone Fishing Pole"] = "45991:0:0:0",
["Jeweled Fishing Pole"] = "45992:0:0:0",
["Staats' Fishing Pole"] = "46337:0:0:0",
["Pandaren Fishing Pole"] = "84660:0:0:0",
["Dragon Fishing Pole"] = "84661:0:0:0",
["Ephemeral Fishing Pole"] = "118381:0:0:0",
["Savage Fishing Pole"] = "116825:0:0:0",
["Draenic Fishing Pole"] = "116826:0:0:0",
["Underlight Angler"] = "133755: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",
["Nat Pagle's Fish Terminator"] = "19944:0:0:0",
["Thruk's Heavy Duty Fishing Pole"] = "120164:0:0:0",
-- one can only hope
["Crafty's Pole"] = "43651:0:0:0"
}
local GeneralOptions = {
["ShowNewFishies"] = {
["text"] = FBConstants.CONFIG_SHOWNEWFISHIES_ONOFF,
["tooltip"] = FBConstants.CONFIG_SHOWNEWFISHIES_INFO,
["v"] = 1,
["default"] = true },
["TurnOffPVP"] = {
["text"] = FBConstants.CONFIG_TURNOFFPVP_ONOFF,
["tooltip"] = FBConstants.CONFIG_TURNOFFPVP_INFO,
["v"] = 1,
["m"] = 1,
["default"] = false },
["SortByPercent"] = {
["text"] = FBConstants.CONFIG_SORTBYPERCENT_ONOFF,
["tooltip"] = FBConstants.CONFIG_SORTBYPERCENT_INFO,
["v"] = 1,
["default"] = true },
["ShowBanner"] = {
["text"] = FBConstants.CONFIG_SHOWBANNER_ONOFF,
["tooltip"] = FBConstants.CONFIG_SHOWBANNER_INFO,
["v"] = 1,
["default"] = true, },
["EnhanceFishingSounds"] = {
["text"] = FBConstants.CONFIG_ENHANCESOUNDS_ONOFF,
["tooltip"] = FBConstants.CONFIG_ENHANCESOUNDS_INFO,
["v"] = 1,
["m"] = 1,
["p"] = 1,
["default"] = false },
["BackgroundSounds"] = {
["text"] = FBConstants.CONFIG_BGSOUNDS_ONOFF,
["tooltip"] = FBConstants.CONFIG_BGSOUNDS_INFO,
["v"] = 1,
["m"] = 1,
["default"] = false,
["parents"] = { ["EnhanceFishingSounds"] = "d" }, },
["TurnOnSound"] = {
["text"] = FBConstants.CONFIG_TURNONSOUND_ONOFF,
["tooltip"] = FBConstants.CONFIG_TURNONSOUND_INFO,
["v"] = 1,
["m"] = 1,
["default"] = false,
["parents"] = { ["EnhanceFishingSounds"] = "d", },
},
["MaxSound"] = {
["tooltip"] = FBConstants.CONFIG_MAXSOUND_INFO,
["parents"] = { ["EnhanceFishingSounds"] = "d", },
["button"] = "FishingBuddyOption_MaxVolumeSlider",
["margin"] = { 12, 8 }, },
["EnhancePools"] = {
["text"] = FBConstants.CONFIG_SPARKLIES_ONOFF,
["tooltip"] = FBConstants.CONFIG_SPARKLIES_INFO,
["v"] = 1,
["default"] = false,
["parents"] = { ["EnhanceFishingSounds"] = "d" },
},
["TownsfolkTracker"] = {
["text"] = FBConstants.CONFIG_TOWNSFOLK_ONOFF,
["tooltip"] = FBConstants.CONFIG_TOWNSFOLK_INFO,
["v"] = 1,
["global"] = true,
["default"] = false
},
};
-- x87bliss has implemented IsFishWardenEnabled as a public function, so
-- we can retire the GUID based check
local function IsWardenEnabled()
-- local FishWarden = FishWarden_79a6ca19_6666_4759_9b8f_a67708694e5b;
local doautoloot = 1;
if ( FiWaAPI_IsFishWardenEnabled and FiWaAPI_IsFishWardenEnabled() ) then
doautoloot = 0;
end
return "d", doautoloot;
end
local function IsFishingAceEnabled()
-- return FishingAce and FishingAce.enabledState;
if ( FishingAce and FishingAce.enabledState ) then
return true;
end
return false;
end
-- we want to do all the magic stuff even when we didn't equip anything
local autopoleframe = CreateFrame("Frame");
autopoleframe:Hide();
local function AreWeFishing()
return (FishingBuddy.StartedFishing ~= nil or autopoleframe:IsShown());
end
FishingBuddy.AreWeFishing = AreWeFishing
local EasyCastInit;
local CastingOptions = {
["EasyCast"] = {
["text"] = FBConstants.CONFIG_EASYCAST_ONOFF,
["tooltip"] = FBConstants.CONFIG_EASYCAST_INFO,
["tooltipd"] = FBConstants.CONFIG_EASYCAST_INFOD,
["enabled"] = function() return (not IsFishingAceEnabled()) and 1 or 0 end,
["init"] = function(o, b) EasyCastInit(o, b); end,
["v"] = 1,
["m"] = 1,
["p"] = 1,
["default"] = true },
["MountedCast"] = {
["text"] = FBConstants.CONFIG_MOUNTEDCAST_ONOFF,
["tooltip"] = FBConstants.CONFIG_MOUNTEDCAST_INFO,
["v"] = 1,
["parents"] = { ["EasyCast"] = "d", },
["active"] = function(i, s, b) return not IsMounted() or b end,
["default"] = false },
["AutoLoot"] = {
["text"] = FBConstants.CONFIG_AUTOLOOT_ONOFF,
["tooltip"] = FBConstants.CONFIG_AUTOLOOT_INFO,
["tooltipd"] = function()
if ( FiWaAPI_IsFishWardenEnabled and not IsFishingAceEnabled() ) then
return FBConstants.CONFIG_AUTOLOOT_INFOD;
end
-- return nil;
end,
["v"] = 1,
["m"] = 1,
["p"] = 1,
["parents"] = { ["EasyCast"] = IsWardenEnabled },
["default"] = false },
["AutoOpen"] = {
["text"] = FBConstants.CONFIG_AUTOOPEN_ONOFF,
["tooltip"] = FBConstants.CONFIG_AUTOOPEN_INFO,
["v"] = 1,
["parents"] = { ["EasyCast"] = "d" },
["default"] = false },
["UseAction"] = {
["text"] = FBConstants.CONFIG_USEACTION_ONOFF,
["tooltip"] = FBConstants.CONFIG_USEACTION_INFO,
["v"] = 1,
["parents"] = { ["EasyCast"] = "d" },
["default"] = false },
["PartialGear"] = {
["text"] = FBConstants.CONFIG_PARTIALGEAR_ONOFF,
["tooltip"] = FBConstants.CONFIG_PARTIALGEAR_INFO,
["v"] = 1,
["parents"] = { ["EasyCast"] = "d" },
["default"] = false },
["WatchBobber"] = {
["text"] = FBConstants.CONFIG_WATCHBOBBER_ONOFF,
["tooltip"] = FBConstants.CONFIG_WATCHBOBBER_INFO,
["v"] = 1,
["parents"] = { ["EasyCast"] = "d" },
["default"] = true
},
["MouseEvent"] = {
["default"] = "RightButtonUp",
["button"] = "FBMouseEvent",
["tooltipd"] = FBConstants.CONFIG_MOUSEEVENT_INFO,
["parents"] = { ["EasyCast"] = "h" },
["alone"] = 1,
["init"] = function(o, b) b.InitMappedMenu(o,b); end,
["setup"] =
function(button)
local gs = FishingBuddy.GetSetting;
FBMouseEvent.menu:SetMappedValue("MouseEvent", gs("MouseEvent"));
end,
},
["EasyLures"] = {
["text"] = FBConstants.CONFIG_EASYLURES_ONOFF,
["tooltip"] = FBConstants.CONFIG_EASYLURES_INFO,
["v"] = 1,
["m"] = 1,
["depends"] = { ["EasyCast"] = "d" },
["default"] = false },
["AlwaysHat"] = {
["text"] = FBConstants.CONFIG_ALWAYSHAT_ONOFF,
["tooltip"] = FBConstants.CONFIG_ALWAYSHAT_INFO,
["v"] = 1,
["m"] = 1,
["parents"] = { ["EasyLures"] = "d" },
["default"] = true },
["AlwaysLure"] = {
["text"] = FBConstants.CONFIG_ALWAYSLURE_ONOFF,
["tooltip"] = FBConstants.CONFIG_ALWAYSLURE_INFO,
["v"] = 1,
["m"] = 1,
["parents"] = { ["EasyLures"] = "d" },
["default"] = false },
["LastResort"] = {
["text"] = FBConstants.CONFIG_LASTRESORT_ONOFF,
["tooltip"] = FBConstants.CONFIG_LASTRESORT_INFO,
["v"] = 1,
["parents"] = { ["EasyLures"] = "d" },
["default"] = false
},
};
local InvisibleOptions = {
-- options not directly manipulatable from the UI
["TooltipInfo"] = {
["text"] = FBConstants.CONFIG_TOOLTIPS_ONOFF,
["tooltip"] = FBConstants.CONFIG_TOOLTIPS_INFO,
["default"] = false },
["GroupByLocation"] = {
["default"] = true,
},
-- bar switching
["ClickToSwitch"] = {
["default"] = true,
},
-- sound enhancement
["EnhanceSound_SFXVolume"] = {
["default"] = 1.0,
},
["EnhanceSound_MasterVolume"] = {
["scale"] = 1,
["default"] = 100,
},
["EnhanceSound_MusicVolume"] = {
["default"] = 0.0,
},
["EnhanceSound_AmbienceVolume"] = {
["default"] = 0.0,
},
["EnhanceMapWaterSounds"] = {
["default"] = false,
},
["EnhanceSound_EnableSoundWhenGameIsInBG"] = {
["default"] = 1.0,
},
["EnhanceSound_EnableAllSound"] = {
["default"] = 1.0,
},
["EnhanceSound_EnableSFX"] = {
["default"] = 1.0,
},
["EnhancegraphicsParticleDensity"] = {
["default"] = 6.0,
},
["MinimapButtonPosition"] = {
["default"] = FBConstants.DEFAULT_MINIMAP_POSITION,
},
["MinimapButtonRadius"] = {
["default"] = FBConstants.DEFAULT_MINIMAP_RADIUS,
},
["CaughtSoFar"] = {
["default"] = 0,
},
["TotalTimeFishing"] = {
["default"] = 1,
},
["FishDebug"] = {
["default"] = false,
},
}
local VolumeSlider =
{
["name"] = "FishingBuddyOption_MaxVolumeSlider",
["format"] = VOLUME.." - %d%%",
["min"] = 0,
["max"] = 100,
["step"] = 5,
["scale"] = 1,
["rightextra"] = 32,
["setting"] = "EnhanceSound_MasterVolume"
};
local function PrepareVolumeSlider()
VolumeSlider['getter'] = FishingBuddy.GetSetting;
VolumeSlider['setter'] = FishingBuddy.SetSetting;
LO:CreateSlider(VolumeSlider);
end
EasyCastInit = function(option, button)
-- prettify drop down?
local check = FBEasyKeys:GetWidth();
if (FishingBuddy.FitInOptionFrame(check)) then
CastingOptions["EasyCast"].layoutright = "EasyCastKeys";
else
CastingOptions["EasyCastKeys"].alone = 1;
end
end
local function GetTableSetting(table, setting)
if not table or not table["Settings"] then
return;
end
local val = table["Settings"][setting];
if ( val == nil and FishingBuddy.GetDefault ) then
val = FishingBuddy.GetDefault(setting);
end
return val;
end
local function SetTableSetting(table, setting, value)
if ( table and setting ) then
local val = nil;
if ( FishingBuddy.GetDefault ) then
val = FishingBuddy.GetDefault(setting);
end
if not table["Settings"] then
table["Settings"] = {}
end
if ( val == value ) then
table["Settings"][setting] = nil;
else
table["Settings"][setting] = value;
end
end
end
-- default FishingBuddy option handlers
FishingBuddy.BaseGetSetting = function(setting)
return GetTableSetting(FishingBuddy_Player, setting);
end
FishingBuddy.BaseSetSetting = function(setting, value)
SetTableSetting(FishingBuddy_Player, setting, value)
end
FishingBuddy.GlobalGetSetting = function(setting)
return GetTableSetting(FishingBuddy_Info, setting);
end
FishingBuddy.GlobalSetSetting = function(setting, value)
SetTableSetting(FishingBuddy_Info, setting, value)
end
FishingBuddy.ByFishie = nil;
FishingBuddy.SortedFishies = nil;
FishingBuddy.StartedFishing = nil;
local OpenThisFishId = {};
local DoAutoOpenLoot = nil;
local isLootClosed = true;
FishingBuddy.OpenThisFishId = OpenThisFishId;
-- handle zone markers
local function zmto(zidx, sidx)
if ( not zidx ) then
return 0;
end
if ( not sidx ) then
sidx = 0;
end
return zidx*1000 + sidx;
end
FishingBuddy.ZoneMarkerTo = zmto;
local function zmex(packed)
local sidx = math.fmod(packed, 1000);
return math.floor(packed/1000), sidx;
end
FishingBuddy.ZoneMarkerEx = zmex;
-- event handling
local function IsFakeEvent(evt)
return (evt == "VARIABLES_LOADED") or FBConstants.FBEvents[evt];
end
-- let's delay bag update when we leave the world
local bagupdateframe = CreateFrame("Frame");
bagupdateframe:Hide();
-- we could watch for UNIT_INVENTORY_CHANGED, if we wanted to check for "player" in the args
local InventoryEvents = {
["BAG_UPDATE"] = true,
["PLAYER_EQUIPMENT_CHANGED"] = true,
}
function bagupdateframe:StartInventory()
for event,_ in pairs(InventoryEvents) do
self.fbframe:RegisterEvent(event)
end
end
function bagupdateframe:StopInventory()
for event,_ in pairs(InventoryEvents) do
self.fbframe:UnregisterEvent(event)
end
end
local LastCastTime = nil;
local FISHINGSPAN = 60;
local function SetLastCastTime()
LastCastTime = GetTime();
end
local function ClearLastCastTime()
LastCastTime = nil
end
local handlerframe = CreateFrame("Frame");
handlerframe:Hide();
local reg_events = {};
local event_handlers = {};
-- allow other parts of the code to watch for events when not fishing
local isunit = "UNIT_";
local function RegisterEvent(event)
if ( not reg_events[event] ) then
if (string.sub(event, 1, string.len(isunit)) == isunit) then
handlerframe:RegisterUnitEvent(event, "player");
else
handlerframe:RegisterEvent(event);
end
reg_events[event] = 1;
end
end
local function AddHandler(event, info)
local func, fake;
if ( not event_handlers[event] ) then
event_handlers[event] = {};
end
fake = IsFakeEvent(event);
if ( type(info) == "function" ) then
func = info;
else
func = info.func;
fake = fake or info.fake;
end
tinsert(event_handlers[event], func);
if ( not fake ) then
-- register the event, if we haven't already
RegisterEvent(event);
end
end
local function RemoveHandler(event, info)
if ( event_handlers[event] ) then
local func;
if ( type(info) == "function" ) then
func = info;
else
func = info.func;
end
local jdx = nil;
for idx,f in ipairs(event_handlers[event]) do
if ( f == func ) then
jdx = idx;
end
end
if ( jdx ) then
table.remove(event_handlers[event], jdx);
end
if ( table.getn(event_handlers[event]) == 0 ) then
event_handlers[event] = nil;
if (reg_events[event]) then
reg_events[event] = nil;
handlerframe:UnregisterEvent(event);
end
end
end
end
local function RegisterHandlers(handlers)
if (not handlers) then
return
end
for evt,info in pairs(handlers) do
AddHandler(evt, info)
end
end
-- these should be internal use only, FBAPI has "constant" interfaces
FishingBuddy.RegisterHandlers = RegisterHandlers;
FishingBuddy.GetHandlers = function(what) return event_handlers[what]; end;
local function RunHandlers(what, ...)
local eh = event_handlers[what];
if ( eh ) then
for idx,func in pairs(eh) do
func(...);
end
end
end
FishingBuddy.RunHandlers = RunHandlers;
-- we want to make sure we handle our registered events for everyone
handlerframe:SetScript("OnEvent", function(self, event, ...)
RunHandlers(event, ...);
RunHandlers("*", ...);
end)
-- look at tooltips
local function LastTooltipText()
return FL:GetLastTooltipText();
end
FishingBuddy.LastTooltipText = LastTooltipText;
local function ClearTooltipText()
FL:ClearLastTooltipText();
end
FishingBuddy.ClearTooltipText = ClearTooltipText;
-- handle option keys for enabling casting
local key_actions = {
[FBConstants.KEYS_NONE] = function(mouse) return mouse ~= "RightButtonUp"; end,
[FBConstants.KEYS_SHIFT] = function(mouse) return IsShiftKeyDown(); end,
[FBConstants.KEYS_CTRL] = function(mouse) return IsControlKeyDown(); end,
[FBConstants.KEYS_ALT] = function(mouse) return IsAltKeyDown(); end,
}
local function CastingKeys()
local setting = FishingBuddy.GetSetting("EasyCastKeys");
local mouse = FishingBuddy.GetSetting("MouseEvent");
if ( setting and key_actions[setting] ) then
return key_actions[setting](mouse);
else
return true;
end
end
local function ReadyForFishing()
local GSB = FishingBuddy.GetSettingBool;
local id = FL:GetMainHandItem(true);
-- if we're holding the spear, assume we're fishing
return (GSB("UseTuskarrSpear") and (id == 88535)) or FL:IsFishingReady(GSB("PartialGear"));
end
FishingBuddy.ReadyForFishing = ReadyForFishing;
local function CheckCastingKeys()
return ReadyForFishing();
end
local QuestLures = {};
QuestLures[58788] = {
["enUS"] = "Overgrown Earthworm", -- Diggin' for Worms
spell = 80534,
};
QuestLures[58949] = {
["enUS"] = "Stag Eye", -- A Staggering Effort
spell = 80868,
};
QuestLures[45902] = {
["enUS"] = "Phantom Ghostfish",
spell = 45902,
};
QuestLures[69907] = {
["enUS"] = "Corpse Worm",
spell = 99315,
};
local AutoFishingItems = {}
local GOGGLES_ID = 167698;
AutoFishingItems[GOGGLES_ID] = {
["enUS"] = "Secret Fishing Goggles",
spell = 293671,
setting = "UseSecretGoggles",
["tooltip"] = FBConstants.CONFIG_SECRET_FISHING_GOGGLES_INFO,
["usable"] = function() return not FishingBuddy.ReadyForFishing(); end,
["default"] = false,
}
-- Get an array of all the lures we have in our inventory, sorted by
-- cost, then bonus
-- We'll want to use the cheapest ones we can until our fish don't get
-- away from us
-- Full combat check function
local function CheckCombat()
return InCombatLockdown() or UnitAffectingCombat("player") or UnitAffectingCombat("pet")
end
FishingBuddy.CheckCombat = CheckCombat;
local function PostCastUpdate()
local LSM = FishingBuddy.LureStateManager;
if ( not CheckCombat() ) then
FL:ResetOverride();
if ( LSM:LuringComplete() ) then
FishingBuddy_PostCastUpdateFrame:Hide();
end
end
end
FishingBuddy.PostCastUpdate = PostCastUpdate;
local function HideAwayAll(self, button, down)
FishingBuddy_PostCastUpdateFrame:Show();
end
local function GetFishingItem(itemtable)
local GSB = FishingBuddy.GetSettingBool;
for itemid, info in pairs(itemtable) do
if ( info.always or (PLANS:HaveThing(itemid, info) and (not info.setting or GSB(info.setting))) ) then
if (not info[CurLoc]) then
info[CurLoc] = GetItemInfo(itemid);
end
if PLANS:CanUseFishingItem(itemid, info) then
local doit = true;
local it = nil;
if ( info.check ) then
doit, itemid, it = info.check(info, info.spell, doit, itemid);
elseif (info.toy) then
_, itemid = C_ToyBox.GetToyInfo(itemid);
end
if ( doit ) then
return doit, itemid, info[CurLoc], it or info.type;
end
end
end
end
-- return nil;
end
local function GetFishieRaw(fishid)
local fi = FishingBuddy_Info["Fishies"][fishid];
if ( not fi or not fi[CurLoc] ) then
local _,_,_,_,it,_,_,_,_,_ = FL:GetItemInfo(fishid);
local color, id, name = FL:SplitLink(fishid, true);
if (not fi) then
return fishid, it, color, 1, nil, name, nil;
else
fi.texture = it;
fi.color = color;
fi.quantity = 1;
fi[CurLoc] = name;
end
end
return fishid,
fi.texture,
fi.color,
fi.quantity,
fi.quality,
fi[CurLoc],
fi.quest;
end
FishingBuddy.GetFishieRaw = GetFishieRaw;
local function GetUpdateLure()
local GSB = FishingBuddy.GetSettingBool;
local LSM = FishingBuddy.LureStateManager;
local lureinventory, _ = FL:GetLureInventory();
-- Let's wait a bit so that the enchant can show up before we lure again
if LSM:LuringCheck() then
return false, 0, nil
end
DoAutoOpenLoot = nil;
local doit, id, name, it;
if autopoleframe:IsShown() then
doit, id, name, it = PLANS:CanUseFishingItems(AutoFishingItems)
if ( doit ) then
return doit, id, name, it;
end
end
doit, id, name, it = PLANS:GetPlan()
if ( doit ) then
return doit, id, name, it;
end
-- look for bonus items, like the Ancient Pandaren Fishing Charm
if ( FishingBuddy.FishingItems ) then
doit, id, name, it = GetFishingItem(FishingBuddy.FishingItems);
if ( doit ) then
return doit, id, name, it;
end
end
if ( GSB("EasyLures") ) then
-- Is this a quest fish we should open up?
if ( GSB("AutoOpen") ) then
while ( table.getn(OpenThisFishId) > 0 ) do
local id = OpenThisFishId[1];
local c = GetItemCount(id);
if (c < 2) then
table.remove(OpenThisFishId, 1);
end
if ( c > 0 ) then
DoAutoOpenLoot = true;
local _,_,_,_,_,name,_ = GetFishieRaw(id);
return true, id, name;
end
end
end
-- look for quest lures
doit, id, name, it = GetFishingItem(QuestLures);
if ( doit ) then
return doit, id, name, it;
end
end
return false;
end
FishingBuddy.GetUpdateLure = GetUpdateLure
local CaptureEvents = {};
local trackedtime = 0;
local TRACKING_DELAY = 0.75;
local function ClearLastLure()
local LSM = FishingBuddy.LureStateManager;
LSM:ClearLastLure()
end
-- we don't want to interrupt ourselves if we're casting.
local fishing_buff = 131474;
local fishing_spellid = 131490;
local current_spell_id = nil
CaptureEvents["UNIT_SPELLCAST_CHANNEL_START"] = function(unit, lineid, spellid)
current_spell_id = spellid
if current_spell_id == fishing_spellid then
SetLastCastTime();
end
end
CaptureEvents["UNIT_SPELLCAST_CHANNEL_STOP"] = function(unit, lineid, spellid)
-- we may want to wait a bit here for any buff to come back...
if current_spell_id == fishing_spellid then
SetLastCastTime();
end
current_spell_id = nil
ClearLastLure()
end
CaptureEvents["UNIT_SPELLCAST_INTERRUPTED"] = function(unit, lineid, spellid)
if current_spell_id == fishing_spellid then
SetLastCastTime();
end
current_spell_id = nil
ClearLastLure()
end
CaptureEvents["UNIT_SPELLCAST_FAILED"] = ClearLastLure;
CaptureEvents["UNIT_SPELLCAST_FAILED_QUIET"] = ClearLastLure;
CaptureEvents["ACTIONBAR_SLOT_CHANGED"] = function()
if ( FishingBuddy.GetSettingBool("UseAction") ) then
FL:GetFishingActionBarID(true);
end
end
CaptureEvents["UNIT_AURA"] = function(arg1)
if ( arg1 == "player" ) then
local hmhe,_,_,_,_,_ = GetWeaponEnchantInfo();
if ( not hmhe ) then
ClearLastLure();
end
end
end
CaptureEvents[FBConstants.OPT_UPDATE_EVT] = function()
FishingBuddyRoot:RegisterEvent("UPDATE_BINDINGS")
end
local function GetCurrentSpell()
return current_spell_id;
end
FishingBuddy.GetCurrentSpell = GetCurrentSpell
local function NormalHijackCheck()
local GSB = FishingBuddy.GetSettingBool;
local GSA = FishingBuddy.ActiveSetting;
local LSM = FishingBuddy.LureStateManager;
if ( not LSM:GetLastLure() and
not CheckCombat() and GSA("FlyingCast") and GSA("MountedCast") and
not IsFishingAceEnabled() and
GSB("EasyCast") and CheckCastingKeys() ) then
return true;
end
end
FishingBuddy.NormalHijackCheck = NormalHijackCheck;
local HijackCheck = NormalHijackCheck;
local function SetHijackCheck(func)
if ( not func ) then
func = NormalHijackCheck;
end
HijackCheck = func;
end
FishingBuddy.SetHijackCheck = SetHijackCheck;
local function NormalStealClick()
-- return nil;
end
local StealClick = NormalStealClick;
local function SetStealClick(func)
if ( not func ) then
func = NormalStealClick;
end
StealClick = func;
end
FishingBuddy.SetStealClick = SetStealClick;
local function CentralCasting()
-- put on a lure if we need to
if ( not StealClick() ) then
autopoleframe:Show();
local update, id, n, target = GetUpdateLure();
if (update and id) then
FL:InvokeLuring(id, target);
else
SetLastCastTime();
if ( not FL:GetLastTooltipText() or not FL:OnFishingBobber() ) then
-- watch for fishing holes
FL:SaveTooltipText();
end
local macrotext = FishingBuddy.CastAndThrow()
if macrotext then
FL:InvokeMacro(macrotext)
else
FL:InvokeFishing(FishingBuddy.GetSettingBool("UseAction"));
end
end
end
FL:OverrideClick(HideAwayAll);
end
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' (self is arg #1!)
local button = select(2, ...);
if ( HijackCheck() ) then
PLANS:ExecutePlans()
if ( FL:CheckForDoubleClick(button) ) then
-- We're stealing the mouse-up event, make sure we exit MouseLook
if ( IsMouselooking() ) then
MouselookStop();
end
CentralCasting();
end
end
if ( SavedWFOnMouseDown ) then
SavedWFOnMouseDown(...);
end
end
local function SafeHookMethod(object, method, newmethod)
local oldValue = object[method];
if ( oldValue ~= _G[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
local skip = {};
skip["mods"] = 1;
skip["texture"] = 1;
skip["quest"] = 1;
skip["level"] = 1;
skip["skill"] = 1;
skip["quality"] = 1;
skip["color"] = 1;
FishingBuddy.GetFishie = function(fishid)
local fi = FishingBuddy_Info["Fishies"][fishid];
if( fi ) then
local name = fi[CurLoc];
if ( not name ) then
-- try a hyperlink
local link = "item:"..fishid;
local n,l,_,_,_,_,_,_ = FL:GetItemInfo(link);
if ( n and l ) then
name = n;
fi[CurLoc] = n;
else
-- try for anything we might be able to display
for k,val in pairs(fi) do
if ( not skip[k] and not name ) then
name = val;
end
end
end
end
if ( not name ) then
name = UNKNOWN;
end
return string.format("%d:0:0:0:0:0:0:0", fishid),
fi.texture,
fi.color,
fi.quantity,
fi.quality,
name,
fi.quest;
end
end
local function PushOptionChanges()
FL:WatchBobber(FishingBuddy.GetSettingBool("WatchBobber"));
FL:SetSAMouseEvent(FishingBuddy.GetSetting("MouseEvent"));
FishingBuddy.WatchUpdate();
end
-- do everything we think is necessary when we start fishing
-- even if we didn't do the switch to a fishing pole
local resetClickToMove = nil;
local function StartFishingMode()
if ( not FishingBuddy.StartedFishing ) then
-- Disable Click-to-Move if we're fishing
if ( BlizzardOptionsPanel_GetCVarSafe("autoInteract") == 1 ) then
resetClickToMove = true;
BlizzardOptionsPanel_SetCVarSafe("autoInteract", 0);
end
FishingBuddy.EnhanceFishingSounds(true);
handlerframe:Show();
local pole, lure = FL:GetPoleBonus();
if ( not lure or lure == 0 ) then
local LSM = FishingBuddy.LureStateManager;
LSM:SetLure({["b"] = lure})
end
FishingBuddy.StartedFishing = GetTime();
RunHandlers(FBConstants.FISHING_ENABLED_EVT);
end
-- we get invoked when items get equipped as well
FL:UpdateLureInventory();
end
local function StopFishingMode(logout)
if ( FishingBuddy.StartedFishing ) then
if ( not logout ) then
FishingBuddy.WatchUpdate();
end
autopoleframe:Hide();
handlerframe:Hide();
local started = FishingBuddy.StartedFishing;
FishingBuddy.StartedFishing = nil;
RunHandlers(FBConstants.FISHING_DISABLED_EVT, started, logout);
end
-- reset everything that we might have set
FishingBuddy.EnhanceFishingSounds(false, logout);
if ( resetClickToMove ) then
-- Re-enable Click-to-Move if we changed it
BlizzardOptionsPanel_SetCVarSafe("autoInteract", 1);
resetClickToMove = nil;
end
ClearLastLure();
end
local function FishingMode()
local ready = ReadyForFishing() or autopoleframe:IsShown();