-
Notifications
You must be signed in to change notification settings - Fork 2
/
LibFishing-1.0.lua
2954 lines (2693 loc) · 87.6 KB
/
LibFishing-1.0.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
--[[
Name: LibFishing-1.0
Maintainers: Sutorix <sutorix@hotmail.com>
Description: A library with fishing support routines used by Fishing Buddy, Fishing Ace and FB_Broker.
Copyright (c) by Bob Schumaker
Licensed under a Creative Commons "Attribution Non-Commercial Share Alike" License
--]]
-- 5.0.4 has a problem with a global "_" (see some for loops below)
local _
local MAJOR_VERSION = "LibFishing-1.0"
local MINOR_VERSION = 101110
if not LibStub then error(MAJOR_VERSION .. " requires LibStub") end
local FishLib, lastVersion = LibStub:NewLibrary(MAJOR_VERSION, MINOR_VERSION)
if not FishLib then
return
end
local WOW = {};
if ( GetBuildInfo ) then
local v, b, d, i = GetBuildInfo();
WOW.build = b;
WOW.date = d;
local s,e,maj,min,dot = string.find(v, "(%d+).(%d+).(%d+)");
WOW.major = tonumber(maj);
WOW.minor = tonumber(min);
WOW.dot = tonumber(dot);
WOW.interface = tonumber(i)
else
WOW.major = 1;
WOW.minor = 9;
WOW.dot = 0;
WOW.interface = 10900
end
local function IsRetail()
return (_G.WOW_PROJECT_ID == _G.WOW_PROJECT_MAINLINE)
end
local function IsClassic()
return not IsRetail()
end
local function IsVanilla()
return (_G.WOW_PROJECT_ID == _G.WOW_PROJECT_CLASSIC)
end
local function IsCrusade()
return IsClassic() and WOW.interface >= 20500 and WOW.interface < 30000
end
local function IsWrath()
return not IsRetail() and WOW.interface >= 30400 and WOW.interface < 40000
end
function FishLib:CurrentVersionName()
if self.IsRetail() then
return "Retail"
end
if self.IsClassic() then
return "Classic"
end
if self.IsVanilla() then
return "Classic Era"
end
if self.IsCrusade() then
return "Crusade"
end
if self.IsWrath() then
return "Wrath"
end
return "Unknown ".._G.WOW_PROJECT_ID
end
function FishLib:WOWVersion()
return WOW.major, WOW.minor, WOW.dot, IsClassic();
end
function FishLib:IsRetail()
return IsRetail()
end
function FishLib:IsClassic()
return IsClassic()
end
function FishLib:IsVanilla()
return IsVanilla()
end
function FishLib:IsCrusade()
return IsCrusade()
end
local BlizzardTradeSkillUI
local BlizzardTradeSkillFrame
if IsRetail() then
BlizzardTradeSkillUI = "Blizzard_Professions";
BlizzardTradeSkillFrame = "ProfessionsFrame";
else
BlizzardTradeSkillUI = "Blizzard_TradeSkillUI";
BlizzardTradeSkillFrame = "TradeSkillFrame";
end
-- Some code suggested by the author of LibBabble-SubZone so I don't have
-- to add the overrides myself...
local function FishLib_GetLocaleLibBabble(typ)
local rettab = {}
local tab = LibStub(typ):GetBaseLookupTable()
local loctab = LibStub(typ):GetUnstrictLookupTable()
for k,v in pairs(loctab) do
rettab[k] = v;
end
for k,v in pairs(tab) do
if not rettab[k] then
rettab[k] = v;
end
end
return rettab;
end
local CBH = LibStub("CallbackHandler-1.0")
local BSZ = FishLib_GetLocaleLibBabble("LibBabble-SubZone-3.0");
local BSL = LibStub("LibBabble-SubZone-3.0"):GetBaseLookupTable();
local BSZR = LibStub("LibBabble-SubZone-3.0"):GetReverseLookupTable();
local HBD = LibStub("HereBeDragons-2.0");
local LT
if IsVanilla() then
LT = LibStub("LibTouristClassicEra");
elseif IsClassic() then
LT = LibStub("LibTouristClassic-1.0");
else
LT = LibStub("LibTourist-3.0");
end
FishLib.HBD = HBD
if not lastVersion then
FishLib.caughtSoFar = 0;
FishLib.gearcheck = true
FishLib.hasgear = false;
FishLib.PLAYER_SKILL_READY = "PlayerSkillReady"
FishLib.havedata = IsClassic();
end
FishLib.registered = FishLib.registered or CBH:New(FishLib, nil, nil, false)
-- Secure action button
local SABUTTONNAME = "LibFishingSAButton";
FishLib.UNKNOWN = "UNKNOWN";
-- GetItemInfo indexes
FishLib.ITEM_NAME = 1
FishLib.ITEM_LINK = 2
FishLib.ITEM_QUALITY = 3
FishLib.ITEM_LEVEL = 4
FishLib.ITEM_MINLEVEL = 5
FishLib.ITEM_TYPE = 6
FishLib.ITEM_SUBTYPE = 7
FishLib.ITEM_STACK = 8
FishLib.ITEM_EQUIPLOC = 9
FishLib.ITEM_ICON = 10
function FishLib:GetFishingProfession()
local fishing;
if self:IsClassic() then
fishing, _ = self:GetFishingSpellInfo();
else
_, _, _, fishing, _, _ = GetProfessions();
end
return fishing
end
-- support finding the fishing skill in classic
local function FindSpellID(thisone)
local id = 1;
if IsVanilla() then
getSpellTexture = C_Spell.GetSpellTexture;
else
getSpellTexture = GetSpellTexture;
end
local spellTexture = getSpellTexture(id);
while (spellTexture) do
if (spellTexture and spellTexture == thisone) then
return id;
end
id = id + 1;
spellTexture = getSpellTexture(id);
end
return nil;
end
function FishLib:GetFishingSpellInfo()
if self:IsClassic() then
local spell = FindSpellID("Interface\\Icons\\Trade_Fishing");
if spell then
local name, _, _ = C_Spell.GetSpellInfo(spell);
return spell, name;
end
return 9, PROFESSIONS_FISHING;
end
local fishing = self:GetFishingProfession();
if not fishing then
return 9, PROFESSIONS_FISHING
end
local name, _, _, _, count, offset, _ = GetProfessionInfo(fishing);
local id = nil;
local spellbank = Enum.SpellBookSpellBank.Player;
for i = 1, count do
local spellName, _ = C_SpellBook.GetSpellBookItemName(offset + i, spellbank);
if (spellName == name) then
_, _, id = C_SpellBook.GetSpellBookItemType(offset + i, spellbank);
break;
end
end
return id, name
end
FishLib.continent_fishing = {
{ ["max"] = 300, ["skillid"] = 356, ["cat"] = 1100, ["rank"] = 0 }, -- Default -- 2592?
{ ["max"] = 300, ["skillid"] = 356, ["cat"] = 1100, ["rank"] = 0 },
{ ["max"] = 75, ["skillid"] = 2591, ["cat"] = 1102, ["rank"] = 0 }, -- Outland Fishing
{ ["max"] = 75, ["skillid"] = 2590, ["cat"] = 1104, ["rank"] = 0 }, -- Northrend Fishing
{ ["max"] = 75, ["skillid"] = 2589, ["cat"] = 1106, ["rank"] = 0 }, -- Cataclysm Fishing (Darkmoon Island?)
{ ["max"] = 75, ["skillid"] = 2588, ["cat"] = 1108, ["rank"] = 0 }, -- Pandaria Fishing
{ ["max"] = 100, ["skillid"] = 2587, ["cat"] = 1110, ["rank"] = 0 }, -- Draenor Fishing
{ ["max"] = 100, ["skillid"] = 2586, ["cat"] = 1112, ["rank"] = 0 }, -- Legion Fishing
{ ["max"] = 175, ["skillid"] = 2585, ["cat"] = 1114, ["rank"] = 0 }, -- Kul Tiras Fishing
{ ["max"] = 175, ["skillid"] = 2585, ["cat"] = 1114, ["rank"] = 0 }, -- Zandalar Fishing
{ ["max"] = 200, ["skillid"] = 2754, ["cat"] = 1391, ["rank"] = 0 }, -- Shadowlands Fishing
{ ["max"] = 100, ["skillid"] = 2826, ["cat"] = 1805, ["rank"] = 0 }, -- Dragonflight Fishing
}
local DEFAULT_SKILL = FishLib.continent_fishing[1];
if IsCrusade() then
FishLib.continent_fishing[2].max = 375
end
local FISHING_LEVELS = {
300, -- Classic
375, -- Outland
75, -- Northrend
75, -- Cataclsym
75, -- Pandaria
100, -- Draenor
100, -- Legion
175, -- BfA
200, -- Shadowlands
100, -- Dragonflight
}
local CHECKINTERVAL = 0.5
local itsready = C_TradeSkillUI.IsTradeSkillReady
local OpenTradeSkill = C_TradeSkillUI.OpenTradeSkill
local GetTradeSkillLine = C_TradeSkillUI.GetTradeSkillLine
local GetCategoryInfo = C_TradeSkillUI.GetCategoryInfo
local CloseTradeSkill = C_TradeSkillUI.CloseTradeSkill
function FishLib:UpdateFishingSkillData()
local categories = {C_TradeSkillUI.GetCategories()}
for _, categoryID in pairs(categories) do
for _, info in pairs(self.continent_fishing) do
if (categoryID == info.cat) then
local data = C_TradeSkillUI.GetCategoryInfo(info.cat);
--info.max = data.skillLineMaxLevel
info.rank = data.skillLineCurrentLevel
self.havedata = true
end
end
end
end
local function SkillUpdate(self, elapsed)
if itsready() then
self.lastUpdate = self.lastUpdate + elapsed;
if self.lastUpdate > CHECKINTERVAL then
self.lib:UpdateFishingSkillData()
self.lib.registered:Fire(FishLib.PLAYER_SKILL_READY)
self:Hide()
self.lastUpdate = 0
end
end
end
function FishLib:QueueUpdateFishingSkillData()
if not self.havedata then
local btn = _G[SABUTTONNAME];
if btn then
btn.skillupdate:Show()
end
end
end
-- Open up the tradeskill window and get the current data
local function SkillInitialize(self, elapsed)
self.lastUpdate = self.lastUpdate + elapsed;
if self.lastUpdate > CHECKINTERVAL/2 then
if self.state == 0 then
if TradeSkillFrame then
self.state = self.state + 1
self.tsfpanel = UIPanelWindows[BlizzardTradeSkillFrame]
UIPanelWindows[BlizzardTradeSkillFrame] = nil
self.tsfpos = {}
for idx=1,TradeSkillFrame:GetNumPoints() do
tinsert(self.tsfpos, {TradeSkillFrame:GetPoint(idx)})
end
TradeSkillFrame:ClearAllPoints();
TradeSkillFrame:SetPoint("LEFT", UIParent, "RIGHT", 0, 0);
end
elseif self.state == 1 then
OpenTradeSkill(DEFAULT_SKILL.skillid)
self.selfopened = true
self.state = self.state + 1
elseif self.state == 2 then
if itsready() then
self.lib:UpdateFishingSkillData()
self.state = self.state + 1
end
else
CloseTradeSkill()
if self.tsfpos then
TradeSkillFrame:ClearAllPoints();
for _,point in ipairs(self.tsfpos) do
TradeSkillFrame:SetPoint(unpack(point));
end
end
if self.tsfpanel then
UIPanelWindows[BlizzardTradeSkillFrame] = self.tsfpanel
end
self.tsfpanel = nil
self.tsfpos = nil
self:Hide()
self:SetScript("OnUpdate", SkillUpdate);
self.lib.registered:Fire(FishLib.PLAYER_SKILL_READY)
end
self.lastUpdate = 0
end
end
-- Go ahead and forcibly get the trade skill data
function FishLib:GetTradeSkillData()
if self:IsClassic() then
return
end
local btn = _G[SABUTTONNAME];
if btn then
if (not C_AddOns.IsAddOnLoaded(BlizzardTradeSkillUI)) then
C_AddOns.LoadAddOn(BlizzardTradeSkillUI);
end
btn.skillupdate:SetScript("OnUpdate", SkillInitialize);
btn.skillupdate:Show()
end
end
function FishLib:UpdateFishingSkill()
local fishing = self:GetFishingProfession();
if (fishing) then
local continent, _ = self:GetCurrentMapContinent();
local info = FishLib.continent_fishing[continent];
if (info) then
local _, _, skill, _, _, _, _, _ = GetProfessionInfo(fishing);
skill = skill or 0
if (info.rank < skill) then
info.rank = skill
end
if skill then
self.registered:Fire(FishLib.PLAYER_SKILL_READY)
end
end
end
end
-- get the fishing skill for the specified continent
function FishLib:GetContinentSkill(continent)
local fishing = self:GetFishingProfession();
if (fishing) then
local info = FishLib.continent_fishing[continent];
if (info) then
local name, _, _, skillmax, _, _, _, mods = GetProfessionInfo(fishing);
local _, lure = self:GetPoleBonus();
return info.rank or 0, mods or 0, info.max or 0, lure or 0;
end
end
return 0, 0, 0, 0;
end
-- get our current fishing skill level
function FishLib:GetCurrentSkill()
local continent, _ = self:GetCurrentMapContinent();
return self:GetContinentSkill(continent)
end
-- Lure library
local DRAENOR_HATS = {
["118393"] = {
["enUS"] = "Tentacled Hat",
["b"] = 5,
["spell"] = 174479,
},
["118380"] = {
["n"] = "HightFish Cap",
["b"] = 5,
["spell"] = 118380,
},
}
local NATS_HATS = {
{ ["id"] = 88710,
["enUS"] = "Nat's Hat", -- 150 for 10 mins
spell = 128587,
["b"] = 10,
["s"] = 100,
["d"] = 10,
["w"] = true,
},
{ ["id"] = 117405,
["enUS"] = "Nat's Drinking Hat", -- 150 for 10 mins
spell = 128587,
["b"] = 10,
["s"] = 100,
["d"] = 10,
["w"] = true,
},
{ ["id"] = 33820,
["enUS"] = "Weather-Beaten Fishing Hat", -- 75 for 10 minutes
spell = 43699,
["b"] = 7,
["s"] = 1,
["d"] = 10,
["w"] = true,
},
}
local FISHINGLURES = {
{ ["id"] = 116826,
["enUS"] = "Draenic Fishing Pole", -- 200 for 10 minutes
spell = 175369,
["b"] = 10,
["s"] = 1,
["d"] = 20, -- 20 minute cooldown
["w"] = true,
},
{ ["id"] = 116825,
["enUS"] = "Savage Fishing Pole", -- 200 for 10 minutes
spell = 175369,
["b"] = 10,
["s"] = 1,
["d"] = 20, -- 20 minute cooldown
["w"] = true,
},
{ ["id"] = 34832,
["enUS"] = "Captain Rumsey's Lager", -- 10 for 3 mins
spell = 45694,
["b"] = 5,
["s"] = 1,
["d"] = 3,
["u"] = 1,
},
{ ["id"] = 67404,
["enUS"] = "Glass Fishing Bobber",
spell = 98849,
["b"] = 2,
["s"] = 1,
["d"] = 10,
},
{ ["id"] = 6529,
["enUS"] = "Shiny Bauble", -- 25 for 10 mins
spell = 8087,
["b"] = 3,
["s"] = 1,
["d"] = 10,
},
{ ["id"] = 6811,
["enUS"] = "Aquadynamic Fish Lens", -- 50 for 10 mins
spell = 8532,
["b"] = 5,
["s"] = 50,
["d"] = 10,
},
{ ["id"] = 6530,
["enUS"] = "Nightcrawlers", -- 50 for 10 mins
spell = 8088,
["b"] = 5,
["s"] = 50,
["d"] = 10,
},
{ ["id"] = 7307,
["enUS"] = "Flesh Eating Worm", -- 75 for 10 mins
spell = 9092,
["b"] = 7,
["s"] = 100,
["d"] = 10,
},
{ ["id"] = 6532,
["enUS"] = "Bright Baubles", -- 75 for 10 mins
spell = 8090,
["b"] = 7,
["s"] = 100,
["d"] = 10,
},
{ ["id"] = 34861,
["enUS"] = "Sharpened Fish Hook", -- 100 for 10 minutes
spell = 45731,
["b"] = 9,
["s"] = 100,
["d"] = 10,
},
{ ["id"] = 6533,
["enUS"] = "Aquadynamic Fish Attractor", -- 100 for 10 minutes
spell = 8089,
["b"] = 9,
["s"] = 100,
["d"] = 10,
},
{ ["id"] = 62673,
["enUS"] = "Feathered Lure", -- 100 for 10 minutes
spell = 87646,
["b"] = 9,
["s"] = 100,
["d"] = 10,
},
{ ["id"] = 46006,
["enUS"] = "Glow Worm", -- 100 for 60 minutes
spell = 64401,
["b"] = 9,
["s"] = 100,
["d"] = 60,
["l"] = 1,
},
{ ["id"] = 68049,
["enUS"] = "Heat-Treated Spinning Lure", -- 150 for 5 minutes
spell = 95244,
["b"] = 10,
["s"] = 250,
["d"] = 5,
},
{ ["id"] = 118391,
["enUS"] = "Worm Supreme", -- 200 for 10 mins
spell = 174471,
["b"] = 10,
["s"] = 100,
["d"] = 10,
},
{ ["id"] = 124674,
["enUS"] = "Day-Old Darkmoon Doughnut", -- 200 for 10 mins
spell = 174471,
["b"] = 10,
["s"] = 1,
["d"] = 10,
},
}
local SalmonLure = {
{ ["id"] = 165699,
["enUS"] = "Scarlet Herring Lure", -- Increase chances for Midnight Salmon
spell = 285895,
["b"] = 0,
["s"] = 1,
["d"] = 15,
},
}
local FISHINGHATS = {}
for _,info in ipairs(NATS_HATS) do
tinsert(FISHINGLURES, info)
tinsert(FISHINGHATS, info)
end
for id,info in ipairs(DRAENOR_HATS) do
info["id"] = id
info["n"] = info["enUS"]
tinsert(FISHINGHATS, info)
end
for _,info in ipairs(FISHINGLURES) do
info["n"] = info["enUS"]
end
-- sort ascending bonus and ascending time
-- we may have to treat "Heat-Treated Spinning Lure" differently someday
table.sort(FISHINGLURES,
function(a,b)
if ( a.b == b.b ) then
return a.d < b.d;
else
return a.b < b.b;
end
end);
table.sort(FISHINGHATS,
function(a,b)
return a.b > b.b;
end);
function FishLib:GetLureTable()
return FISHINGLURES;
end
function FishLib:GetHatTable()
return NATS_HATS;
end
function FishLib:GetDraenorHatTable()
return DRAENOR_HATS;
end
function FishLib:IsWorn(itemid)
itemid = tonumber(itemid)
for slot=1,19 do
local id = GetInventoryItemID("player", slot);
if ( itemid == id ) then
return true;
end
end
-- return nil
end
function FishLib:IsItemOneHanded(item)
if ( item ) then
local bodyslot= self:GetItemInfoFields(item, self.ITEM_EQUIPLOC);
if ( bodyslot == "INVTYPE_2HWEAPON" or bodyslot == INVTYPE_2HWEAPON ) then
return false;
end
end
return true;
end
local useinventory = {};
local lureinventory = {};
function FishLib:UpdateLureInventory()
local rawskill, _, _, _ = self:GetCurrentSkill();
useinventory = {};
lureinventory = {};
local b = 0;
for _,lure in ipairs(FISHINGLURES) do
local id = lure.id;
local count = GetItemCount(id);
-- does this lure have to be "worn"
if ( count > 0 ) then
local startTime, _, _ = C_Container.GetItemCooldown(id);
if (startTime == 0) then
if (lure.w and self:IsWorn(id)) then
tinsert(lureinventory, lure);
else
if ( lure.b > b) then
b = lure.b;
if ( lure.u ) then
tinsert(useinventory, lure);
elseif ( lure.s <= rawskill ) then
tinsert(lureinventory, lure);
end
end
end
end
end
end
return lureinventory, useinventory;
end
function FishLib:GetLureInventory()
return lureinventory, useinventory;
end
-- Handle buffs
local BuffWatch = {}
function FishLib:WaitForBuff(buffId)
local btn = _G[SABUTTONNAME];
if ( btn ) then
BuffWatch[buffId] = GetTime() + 0.6
btn.buffupdate:Show()
end
end
local spellidx = nil;
function FishLib:GetBuff(buffId)
if ( buffId ) then
for idx=1,40 do
local current_buff = C_UnitAuras.GetAuraDataByIndex("player", idx);
if current_buff then
local info = {C_UnitAuras.GetAuraDataByIndex("player", idx)};
local spellid = select(10, unpack(info));
if (buffId == spellid) then
return idx, info
end
else
return nil, nil
end
end
end
return nil, nil
end
function FishLib:HasBuff(buffId, skipWait)
if ( buffId ) then
-- if we're waiting, assume we're going to have it
if ( not skipWait and BuffWatch[buffId] ) then
return true, GetTime() + 10
else
local idx, info = self:GetBuff(buffId);
if idx then
local et = select(6, unpack(info));
return true, et;
end
end
end
return nil, nil
end
function FishLib:CancelBuff(buffId)
if buffId then
if BuffWatch[buffId] then
BuffWatch[buffId] = nil
end
local idx, info = self:GetBuff(buffId);
if idx then
CancelUnitBuff("player", idx)
end
end
end
function FishLib:HasAnyBuff(buffs)
for _, buff in pairs(buffs) do
local has, et = self:HasBuff(buff.spell)
if has then
return has, et
end
end
-- return nil
end
function FishLib:FishingForAttention()
return self:HasBuff(394009)
end
function FishLib:HasLureBuff()
for _,lure in ipairs(FISHINGLURES) do
if self:HasBuff(lure.spell) then
return true
end
end
-- return nil
end
function FishLib:HasHatBuff()
for _,hat in ipairs(FISHINGHATS) do
if self:HasBuff(hat.spell) then
return true
end
end
-- return nil
end
-- Deal with lures
function FishLib:UseThisLure(lure, b, enchant, skill, level)
if ( lure ) then
local startTime, _, _ = C_Container.GetItemCooldown(lure.id);
-- already check for skill being nil, so that will skip the whole check with level
-- skill = skill or 0;
level = level or 0;
local bonus = lure.b or 0;
if ( startTime == 0 and (skill and level <= (skill + bonus)) and (bonus > enchant) ) then
if ( not b or bonus > b ) then
return true, bonus;
end
end
return false, bonus;
end
return false, 0;
end
function FishLib:FindNextLure(b, state)
local n = table.getn(lureinventory);
for s=state+1,n,1 do
if ( lureinventory[s] ) then
local id = lureinventory[s].id;
local startTime, _, _ = C_Container.GetItemCooldown(id);
if ( startTime == 0 ) then
if ( not b or lureinventory[s].b > b ) then
return s, lureinventory[s];
end
end
end
end
-- return nil;
end
FishLib.LastUsed = nil;
function FishLib:FindBestLure(b, state, usedrinks, forcemax)
local level = self:GetCurrentFishingLevel();
if ( level and level > 1 ) then
if (forcemax) then
level = 9999;
end
local rank, modifier, skillmax, enchant = self:GetCurrentSkill();
local skill = rank + modifier;
-- don't need this now, LT has the full values
-- level = level + 95; -- for no lost fish
if ( skill <= level ) then
self:UpdateLureInventory();
-- if drinking will work, then we're done
if ( usedrinks and #useinventory > 0 ) then
if ( not self.LastUsed or not self:HasBuff(self.LastUsed.n) ) then
local id = useinventory[1].id;
if ( not self:HasBuff(useinventory[1].n) ) then
if ( level <= (skill + useinventory[1].b) ) then
self.LastUsed = useinventory[1];
return nil, useinventory[1];
end
end
end
end
skill = skill - enchant;
state = state or 0;
local checklure;
local useit;
b = 0;
-- Look for lures we're wearing, first
for s=state+1,#lureinventory,1 do
checklure = lureinventory[s];
if (checklure.w) then
useit, b = self:UseThisLure(checklure, b, enchant, skill, level);
if ( useit and b and b > 0 ) then
return s, checklure;
end
end
end
b = 0;
for s=state+1,#lureinventory,1 do
checklure = lureinventory[s];
useit, b = self:UseThisLure(checklure, b, enchant, skill, level);
if ( useit and b and b > 0 ) then
return s, checklure;
end
end
-- if we ran off the end of the table and we had a valid lure, let's use that one
if ( (not enchant or enchant == 0) and b and (b > 0) and checklure ) then
return #lureinventory, checklure;
end
end
end
-- return nil;
end
function FishLib:FindBestHat()
for _,hat in ipairs(FISHINGHATS) do
local id = hat["id"]
if GetItemCount(id) > 0 and self:IsWorn(id) then
local startTime, _, _ = C_Container.GetItemCooldown(id);
if ( startTime == 0 ) then
return 1, hat;
end
end
end
end
-- Handle events we care about
local canCreateFrame = false;
local FISHLIBFRAMENAME="FishLibFrame";
local fishlibframe = _G[FISHLIBFRAMENAME];
if ( not fishlibframe) then
fishlibframe = CreateFrame("Frame", FISHLIBFRAMENAME);
fishlibframe:RegisterEvent("PLAYER_ENTERING_WORLD");
fishlibframe:RegisterEvent("PLAYER_LEAVING_WORLD");
fishlibframe:RegisterEvent("UPDATE_CHAT_WINDOWS");
fishlibframe:RegisterEvent("LOOT_OPENED");
fishlibframe:RegisterEvent("CHAT_MSG_SKILL");
fishlibframe:RegisterEvent("SKILL_LINES_CHANGED");
fishlibframe:RegisterEvent("UNIT_INVENTORY_CHANGED");
fishlibframe:RegisterEvent("UNIT_SPELLCAST_CHANNEL_START");
fishlibframe:RegisterEvent("UNIT_SPELLCAST_CHANNEL_STOP");
fishlibframe:RegisterEvent("ITEM_LOCK_CHANGED");
fishlibframe:RegisterEvent("ACTIONBAR_SLOT_CHANGED");
fishlibframe:RegisterEvent("PLAYER_REGEN_ENABLED");
fishlibframe:RegisterEvent("PLAYER_REGEN_DISABLED");
fishlibframe:RegisterEvent("TRADE_SKILL_DATA_SOURCE_CHANGED")
fishlibframe:RegisterEvent("TRADE_SKILL_LIST_UPDATE")
fishlibframe:RegisterEvent("EQUIPMENT_SWAP_FINISHED");
end
fishlibframe.fl = FishLib;
fishlibframe:SetScript("OnEvent", function(self, event, ...)
local arg1 = select(1, ...);
if ( event == "UPDATE_CHAT_WINDOWS" ) then
canCreateFrame = true;
self:UnregisterEvent(event);
elseif ( event == "UNIT_INVENTORY_CHANGED" and arg1 == "player" ) then
self.fl:UpdateLureInventory();
-- we can't actually rely on EQUIPMENT_SWAP_FINISHED, it appears
self.fl:ForceGearCheck();
elseif (event == "ITEM_LOCK_CHANGED" or event == "EQUIPMENT_SWAP_FINISHED" ) then
-- Did something we're wearing change?
self.fl:ForceGearCheck();
elseif (event == "SKILL_LINES_CHANGED") then
self.fl:UpdateFishingSkill()
elseif ( event == "CHAT_MSG_SKILL" ) then
self.fl.caughtSoFar = 0;
elseif ( event == "LOOT_OPENED" ) then
if (IsFishingLoot()) then
self.fl.caughtSoFar = self.fl.caughtSoFar + 1;
end
elseif ( event == "UNIT_SPELLCAST_CHANNEL_START" or event == "UNIT_SPELLCAST_CHANNEL_STOP" ) then
if (arg1 == "player" ) then
self.fl:UpdateLureInventory();
end
elseif ( event == "PLAYER_ENTERING_WORLD" ) then
self:RegisterEvent("ITEM_LOCK_CHANGED")
self:RegisterEvent("PLAYER_EQUIPMENT_CHANGED")
self:RegisterEvent("SPELLS_CHANGED")
elseif ( event == "PLAYER_LEAVING_WORLD" ) then
self:UnregisterEvent("ITEM_LOCK_CHANGED")
self:UnregisterEvent("PLAYER_EQUIPMENT_CHANGED")
self:UnregisterEvent("SPELLS_CHANGED")
elseif (event == "TRADE_SKILL_DATA_SOURCE_CHANGED" or event == "TRADE_SKILL_LIST_UPDATE") then
self.fl:QueueUpdateFishingSkillData();
elseif (event == "ACTIONBAR_SLOT_CHANGED") then
self.fl:GetFishingActionBarID(true)
elseif (event == "PLAYER_REGEN_DISABLED") then
self.fl:SetCombat(true)
elseif (event == "PLAYER_REGEN_ENABLED") then
self.fl:SetCombat(false)
end
end);
fishlibframe:Show();
-- set up a table of slot mappings for looking up item information
local FISHING_TOOL_SLOT = "FishingToolSlot"
local INVSLOT_FISHING_TOOL = 28;
local slotinfo = {
[1] = { name = "HeadSlot", tooltip = HEADSLOT, id = INVSLOT_HEAD, transmog = true },
[2] = { name = "NeckSlot", tooltip = NECKSLOT, id = INVSLOT_NECK, transmog = false },
[3] = { name = "ShoulderSlot", tooltip = SHOULDERSLOT, id = INVSLOT_SHOULDER, transmog = true },
[4] = { name = "BackSlot", tooltip = BACKSLOT, id = INVSLOT_BACK, transmog = true },
[5] = { name = "ChestSlot", tooltip = CHESTSLOT, id = INVSLOT_CHEST, transmog = true },
[6] = { name = "ShirtSlot", tooltip = SHIRTSLOT, id = INVSLOT_BODY, transmog = true },
[7] = { name = "TabardSlot", tooltip = TABARDSLOT, id = INVSLOT_TABARD, transmog = true },
[8] = { name = "WristSlot", tooltip = WRISTSLOT, id = INVSLOT_WRIST, transmog = true },
[9] = { name = "HandsSlot", tooltip = HANDSSLOT, id = INVSLOT_HAND, transmog = true },
[10] = { name = "WaistSlot", tooltip = WAISTSLOT, id = INVSLOT_WAIST, transmog = true },
[11] = { name = "LegsSlot", tooltip = LEGSSLOT, id = INVSLOT_LEGS, transmog = true },
[12] = { name = "FeetSlot", tooltip = FEETSLOT, id = INVSLOT_FEET, transmog = true },
[13] = { name = "Finger0Slot", tooltip = FINGER0SLOT, id = INVSLOT_FINGER1, transmog = false },
[14] = { name = "Finger1Slot", tooltip = FINGER1SLOT, id = INVSLOT_FINGER2, transmog = false },
[15] = { name = "Trinket0Slot", tooltip = TRINKET0SLOT, id = INVSLOT_TRINKET1, transmog = false },
[16] = { name = "Trinket1Slot", tooltip = TRINKET1SLOT, id = INVSLOT_TRINKET2, transmog = false },
[17] = { name = FISHING_TOOL_SLOT, tooltip = FISHINGTOOLSLOT, id = INVSLOT_FISHING_TOOL, transmog = false },
[18] = { name = "SecondaryHandSlot", tooltip = SECONDARYHANDSLOT, id = INVSLOT_OFFHAND, transmog = true },
}
-- A map of item types to locations
local slotmap = {
["INVTYPE_AMMO"] = { INVSLOT_AMMO },
["INVTYPE_HEAD"] = { INVSLOT_HEAD },
["INVTYPE_NECK"] = { INVSLOT_NECK },
["INVTYPE_SHOULDER"] = { INVSLOT_SHOULDER },
["INVTYPE_BODY"] = { INVSLOT_BODY },
["INVTYPE_CHEST"] = { INVSLOT_CHEST },
["INVTYPE_ROBE"] = { INVSLOT_CHEST },
["INVTYPE_CLOAK"] = { INVSLOT_CHEST },
["INVTYPE_WAIST"] = { INVSLOT_WAIST },
["INVTYPE_LEGS"] = { INVSLOT_LEGS },
["INVTYPE_FEET"] = { INVSLOT_FEET },
["INVTYPE_WRIST"] = { INVSLOT_WRIST },
["INVTYPE_HAND"] = { INVSLOT_HAND },
["INVTYPE_FINGER"] = { INVSLOT_FINGER1,INVSLOT_FINGER2 },
["INVTYPE_TRINKET"] = { INVSLOT_TRINKET1,INVSLOT_TRINKET2 },
["INVTYPE_WEAPON"] = { INVSLOT_MAINHAND,INVSLOT_OFFHAND },
["INVTYPE_SHIELD"] = { INVSLOT_OFFHAND },
["INVTYPE_2HWEAPON"] = { INVSLOT_MAINHAND },
["INVTYPE_WEAPONMAINHAND"] = { INVSLOT_MAINHAND },
["INVTYPE_WEAPONOFFHAND"] = { INVSLOT_OFFHAND },
["INVTYPE_HOLDABLE"] = { INVSLOT_OFFHAND },
["INVTYPE_RANGED"] = { INVSLOT_RANGED },
["INVTYPE_THROWN"] = { INVSLOT_RANGED },
["INVTYPE_RANGEDRIGHT"] = { INVSLOT_RANGED },
["INVTYPE_RELIC"] = { INVSLOT_RANGED },
["INVTYPE_TABARD"] = { INVSLOT_TABARD },
["INVTYPE_BAG"] = { 20,21,22,23 },
["INVTYPE_QUIVER"] = { 20,21,22,23 },