forked from robertjacobsen/Fishbringer
-
Notifications
You must be signed in to change notification settings - Fork 2
/
fishy.lua
executable file
·617 lines (556 loc) · 14.7 KB
/
fishy.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
local FONT = select(1, GameFontNormalSmall:GetFont())
local fb = CreateFrame"Frame"
local db
local char = string.format("%s - %s", UnitName"player", GetRealmName())
local ADDON_NAME, namespace = ... --localization
local L = namespace.L --localization
local version = GetAddOnMetadata(ADDON_NAME, "Version")
local addoninfo = 'v'..version
local _,_,_,interface = GetBuildInfo()
local classicEra = (interface>10000 and interface<12000)
local classicTBC = (interface>20000 and interface<30000)
local classicWrath = (interface>30000 and interface<40000)
local areaTable = {}
fb:RegisterEvent"PLAYER_ENTERING_WORLD"
fb:RegisterEvent"ADDON_LOADED"
fb:RegisterEvent"COMBAT_LOG_EVENT"
fb:RegisterEvent"SKILL_LINES_CHANGED"
fb:RegisterEvent"LOOT_READY"
fb:RegisterEvent"LOOT_CLOSED"
fb:RegisterEvent"ZONE_CHANGED_NEW_AREA"
fb:RegisterEvent"ZONE_CHANGED"
fb:RegisterEvent"UNIT_INVENTORY_CHANGED"
local function Print(text)
ChatFrame1:AddMessage(string.format("|cffff8000Fishbringer|r: %s", text))
end
local zones = {
[114] = 380,
[115] = 380,
[116] = 380,
[117] = 380,
[118] = 480,
[119] = 430,
[123] = 430,
[125] = 430,
[126] = 430,
[127] = 405,
[170] = 480,
[1411] = -70,
[1412] = -70,
[1413] = -20,
[1416] = 130,
[1417] = 130,
[1420] = -70,
[1421] = -20,
[1422] = 205,
[1423] = 330,
[1424] = 55,
[1425] = 205,
[1426] = -70,
[1428] = 330,
[1429] = -70,
[1430] = 330,
[1431] = 55,
[1432] = -20,
[1433] = 55,
[1434] = 130,
[1435] = 130,
[1436] = -20,
[1437] = 55,
[1438] = -70,
[1439] = -20,
[1440] = 55,
[1441] = 130,
[1442] = 55,
[1443] = 130,
[1444] = 205,
[1445] = 130,
[1446] = 205,
[1447] = 205,
[1448] = 205,
[1449] = 205,
[1450] = 205,
[1451] = 330,
[1452] = 330,
[1453] = -20,
[1454] = -20,
[1455] = -20,
[1456] = -20,
[1457] = -20,
[1458] = -20,
[1941] = -70,
[1942] = -20,
[1943] = -70,
[1944] = 280,
[1946] = 305,
[1947] = -20,
[1948] = 280,
[1950] = -20,
[1951] = 380,
[1952] = 355,
[1953] = 380,
[1954] = -20,
}
local subzones = {
[297] = 205,
[718] = -20, --Wailing Caverns Entrance
[719] = -20, --BFD Entrance
[1112] = 330,
[1222] = 330,
[1227] = 330,
[1477] = 205, -- ST Entrance
[1977] = 330, -- ZG Entrance
[2100] = 205, --Maraudon Entrance
[3140] = 330,
[3614] = 395,
[3621] = 395,
[3653] = 355,
[3656] = 355,
[3658] = 355,
[3679] = 405,
[3690] = 405,
[3691] = 405,
[3692] = 405,
[3979] = 480,
[3859] = 405,
[3974] = 405,
[3975] = 405,
[3976] = 405,
}
local instances = {
[36] = -20,
[43] = -20,
[48] = -20,
[109] = 205,
[309] = 309,
[329] = 330,
[349] = 205,
[548] = 130,
[1001] = 130,
[1004] = 130,
[1007] = 330,
}
local fishingpoles = {
[6256] = true,
[6365] = true,
[6366] = true,
[6367] = true,
[12225] = true,
[19022] = true,
[19970] = true,
[25978] = true,
[44050] = true,
[45120] = true,
[45858] = true,
[45991] = true,
[45992] = true,
}
local function GetNumFishToLevel(skillRank)
local classicScale=25
local expScale=75
local numFishToLevel
if skillRank <= 300 then
numFishToLevel=math.ceil(skillRank / classicScale)-2
if numFishToLevel < 1 then
numFishToLevel = 1
end
else
numFishToLevel=math.ceil((skillRank-315)/expScale)+10
end
return numFishToLevel
end
local function UpdateFishCount(shouldIncrement)
if shouldIncrement and IsFishingLoot() then
db[char].fishCaught = db[char].fishCaught + 1
end
Fishbringer.fishCount:SetFormattedText(
L["%d fish caught at this level"],
db[char].fishCaught
)
end
local finishedLooting = true
local function LootClosed()
finishedLooting = true
end
local function IncrementFishCount()
if finishedLooting then
finishedLooting = false
UpdateFishCount(true)
end
end
local function ResetFishCounter(numFish)
db[char].fishToCatch = numFish
db[char].fishCaught = 0
UpdateFishCount(false)
end
local function populateAreaTable()
local areaName
for areaId=1,10500 do
areaName=C_Map.GetAreaInfo(areaId)
if areaName then
areaTable[areaName]=areaId
end
end
end
--[[ GetExploredAreaIDsAtPosition doesn't always work for many locations - UNRELIABLE
local function getPlayerAreaId()
local areaId
local unit = "Player"
local mapId = C_Map.GetBestMapForUnit(unit)
local mapPos = C_Map.GetPlayerMapPosition(mapId, unit)
areaIds = C_MapExplorationInfo.GetExploredAreaIDsAtPosition(mapId,mapPos)
if areaIds and areaIds[1] then
areaId = areaIds[1]
end
return areaId
end
--]]
local function UpdateCatchInfo()
local zoneText
local zoneSkill
if IsInInstance() then
local _,_,_,_,_,_,_,instanceId = GetInstanceInfo()
zoneSkill = instances[instanceId]
zoneText = GetRealZoneText()
else
zoneText = GetSubZoneText()
if zoneText == "" then
zoneText = GetRealZoneText()
end
local areaId = areaTable[zoneText]
if areaId then
zoneSkill = subzones[areaId]
end
if not zoneSkill then
local mapId = C_Map.GetBestMapForUnit("Player")
if mapId then
zoneText = C_Map.GetMapInfo(mapId).name
zoneSkill = zones[mapId]
end
end
end
-- Sometimes we can trigger this before the player is in any zone
if not zoneText then
return
end
local maxZoneSkill
if not zoneSkill then
zoneSkill = 0
maxZoneSkill = 0
else
maxZoneSkill = zoneSkill + 95
end
FishbringerDB.chance = (
db[char].fishingSkill + db[char].fishingBuff - zoneSkill
) * 0.01 + 0.05
if zoneSkill < 0 then
zoneSkill = 1
end
if FishbringerDB.chance > 1 then
FishbringerDB.chance = 1
elseif FishbringerDB.chance < 0 then
FishbringerDB.chance = 0
end
local color
if FishbringerDB.chance == 0 then
color = "ffff2020"
elseif FishbringerDB.chance <= 0.5 then
color = "ffff8040"
elseif FishbringerDB.chance < 1 then
color = "ffffff00"
else
color = "ff40bf40"
end
if zoneSkill == 0 then
Fishbringer.zoneInfo:SetFormattedText(
L["\124c%s%s\124r\nNo fish in this zone"],
color, zoneText, zoneSkill, maxZoneSkill, FishbringerDB.chance * 100
)
Fishbringer.catchRate:SetText("")
else
Fishbringer.zoneInfo:SetFormattedText(
L["\124c%s%s\124r\n%d skill needed to fish\n(%d needed for 100%% catch rate)"],
color, zoneText, zoneSkill, maxZoneSkill, FishbringerDB.chance * 100
)
Fishbringer.catchRate:SetFormattedText(L["%d%% catch rate"], FishbringerDB.chance * 100)
end
end
local function GetFishingSkill()
for i = 1, GetNumSkillLines() do
local skillName, _, _, skillRank, _, skillModifier, skillMaxRank, _, _, _, _, _, _= GetSkillLineInfo(i)
if skillName == L["Fishing"] then
return skillRank, skillModifier, skillMaxRank
end
end
return
end
local function UpdateSkill(forceResetFishCounter)
if not db then
return
end
local skillRank, skillModifier, skillMaxRank = GetFishingSkill()
if not skillRank then
return
end
db[char].maxFishingSkill = skillMaxRank
local fishNeededText = ""
local skillRankText = skillRank
local fishNeeded = GetNumFishToLevel(skillRank)
local strFishNeeded
if skillRank ~= skillMaxRank then
skillRankText = string.format("%d(%d)", skillRank, skillMaxRank)
if fishNeeded>1 then
if fishNeeded<10 then
strFishNeeded = string.format("%d-%d",fishNeeded-1, fishNeeded)
else
strFishNeeded = string.format("%d-%d",fishNeeded-1, fishNeeded+1)
end
else
strFishNeeded = string.format("%d", fishNeeded)
end
fishNeededText = string.format(L["\n%s fish needed to skill up"], strFishNeeded)
end
local skillModifierText = ""
if skillModifier > 0 then
skillModifierText = string.format("+%d = %d", skillModifier, skillRank+skillModifier)
end
Fishbringer.content:SetFormattedText(
L["%s%s fishing skill%s"],
skillRankText,
skillModifierText,
fishNeededText
)
if forceResetFishCounter or db[char].fishingSkill ~= skillRank then
db[char].fishingSkill = skillRank
ResetFishCounter(fishNeeded)
UpdateCatchInfo()
end
if db[char].fishingBuff ~= skillModifier then
db[char].fishingBuff = skillModifier
UpdateCatchInfo()
end
end
local function Update()
UpdateSkill(false)
UpdateCatchInfo()
end
local function CycleAlignment()
if db[char].alignment == "RIGHT" then
db[char].alignment = "LEFT"
elseif db[char].alignment == "LEFT" then
db[char].alignment = "CENTER"
else
db[char].alignment = "RIGHT"
end
-- Update all
Fishbringer.title:SetJustifyH(db[char].alignment)
Fishbringer.zoneInfo:SetJustifyH(db[char].alignment)
Fishbringer.catchRate:SetJustifyH(db[char].alignment)
Fishbringer.content:SetJustifyH(db[char].alignment)
Fishbringer.fishCount:SetJustifyH(db[char].alignment)
end
local function Toggle()
if db[char].isShown then
Fishbringer:Hide()
db[char].isShown = false
else
Update()
Fishbringer:Show()
db[char].isShown = true
end
end
local function ToggleFishCount()
if db[char].isFishCountShown then
Fishbringer.fishCount:Hide()
db[char].isFishCountShown = false
else
Fishbringer.fishCount:Show()
db[char].isFishCountShown = true
end
end
local function CheckForFishingPole()
local _, _, itemid = string.find(GetInventoryItemLink("player", GetInventorySlotInfo("MainHandSlot")) or "", "item:(%d+):(.+)")
if fishingpoles[tonumber(itemid)] then
Update()
Fishbringer:Show()
db[char].isShown = true
else
Fishbringer:Hide()
db[char].isShown = false
end
end
local function InitializeDB(resetDatabase)
db = FishbringerDB
if not db then
db = {}
FishbringerDB = db
end
populateAreaTable()
if resetDatabase or not db[char] then
db[char] = {
fishingSkill = 0,
fishingBuff = 0,
fishCaught = 0,
fishToCatch = 0,
maxFishingSkill = 0,
isShown = false,
isFishCountShown = true,
alignment = "RIGHT",
isGradiant = true,
}
end
end
local function setTitleText()
local name
if db[char].isGradiant == nil then
db[char].isGradiant = true
end
if db[char].isGradiant then
name = "|cff0000ffF|cff0049ffi|cff0069ffs|cff0083ffh|cff0099ffb|cff00acffr|cff00bfffi|cff00d0ffn|cff00e1ffg|cff00f0ffe|cff00ffffr"
else
name = "Fishbringer"
end
Fishbringer.title:SetText(name)
end
local function toggleColor()
db[char].isGradiant=not db[char].isGradiant
setTitleText()
end
local function InitializeFrame()
-- Frame madness
if Fishbringer then
return
end
local Fishbringer = CreateFrame("Frame", "Fishbringer", UIParent, "BackdropTemplate")
Fishbringer:EnableMouse(true)
Fishbringer:SetMovable(true)
Fishbringer:SetUserPlaced(true)
Fishbringer:SetHeight(150)
Fishbringer:SetWidth(250)
Fishbringer:SetBackdrop({
bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
tile = true,
tileSize = 16,
insets = {
left = 4,
right = 4,
top = 4,
bottom = 4
},
})
Fishbringer:SetBackdropColor(0, 0, 0, 0)
Fishbringer:SetScript("OnMouseDown", function(self)
if IsAltKeyDown() then
self:SetBackdropColor(0, 0, 0, .6)
self:StartMoving()
end
end)
Fishbringer:SetScript("OnMouseUp", function(self)
self:StopMovingOrSizing()
self:SetBackdropColor(0, 0, 0, 0)
end)
Fishbringer:SetPoint("RIGHT", UIParent, "RIGHT", -10, 0)
if not db[char].isShown then
Fishbringer:Hide()
end
local title = Fishbringer:CreateFontString(nil, "OVERLAY")
title:SetHeight(15)
title:SetWidth(Fishbringer:GetWidth() - 10)
title:SetPoint("TOPLEFT", Fishbringer, "TOPLEFT", 3, -10)
title:SetJustifyH(db[char].alignment)
title:SetFont(FONT, 16)
title:SetShadowOffset(1, -1)
Fishbringer.title = title
setTitleText()
local zoneInfo = Fishbringer:CreateFontString(nil, "OVERLAY")
zoneInfo:SetHeight(50)
zoneInfo:SetWidth(Fishbringer:GetWidth() - 10)
zoneInfo:SetPoint("TOP", Fishbringer.title, "BOTTOM", 0, 0)
zoneInfo:SetJustifyH(db[char].alignment)
zoneInfo:SetFont(FONT, 12)
zoneInfo:SetShadowOffset(1, -1)
Fishbringer.zoneInfo = zoneInfo
local catchRate = Fishbringer:CreateFontString(nil, "OVERLAY")
catchRate:SetHeight(15)
catchRate:SetWidth(Fishbringer:GetWidth() - 10)
catchRate:SetPoint("TOP", Fishbringer.zoneInfo, "BOTTOM", 0, 0)
catchRate:SetJustifyH(db[char].alignment)
catchRate:SetFont(FONT, 14)
catchRate:SetShadowOffset(1, -1)
Fishbringer.catchRate = catchRate
local content = Fishbringer:CreateFontString(nil, "OVERLAY")
content:SetHeight(30)
content:SetWidth(Fishbringer:GetWidth() - 10)
content:SetFont(FONT, 12)
content:SetShadowOffset(1, -1)
content:SetJustifyH(db[char].alignment)
content:SetPoint("TOP", Fishbringer.catchRate, "BOTTOM", 0, 0)
Fishbringer.content = content
local fishCount = Fishbringer:CreateFontString(nil, "OVERLAY")
fishCount:SetHeight(15)
fishCount:SetWidth(Fishbringer:GetWidth() - 10)
fishCount:SetFont(FONT, 12)
fishCount:SetShadowOffset(1, -1)
fishCount:SetJustifyH(db[char].alignment)
fishCount:SetPoint("TOP", Fishbringer.content, "BOTTOM", 0, -7)
Fishbringer.fishCount = fishCount
if not db[char].isFishCountShown then
Fishbringer.fishCount:Hide()
end
end
local function UpdateFishingSkill()
return UpdateSkill(false)
end
fb:SetScript("OnEvent", function(self, event, ...)
self[event](self, event, ...)
end)
fb.PLAYER_ENTERING_WORLD = function()
CheckForFishingPole()
UpdateFishCount(false)
end
fb.ADDON_LOADED = function(self, event, addon)
if addon ~= "Fishbringer" then
return
end
InitializeDB(false)
InitializeFrame()
end
fb.COMBAT_LOG_EVENT = UpdateFishingSkill
fb.SKILL_LINES_CHANGED = UpdateFishingSkill
fb.LOOT_READY = IncrementFishCount
fb.LOOT_CLOSED = LootClosed
fb.ZONE_CHANGED_NEW_AREA = UpdateCatchInfo
fb.ZONE_CHANGED = UpdateCatchInfo
fb.UNIT_INVENTORY_CHANGED = CheckForFishingPole
local function ShowHelp()
Print(L["Nat Pagle would be proud of you."])
Print(L["- /fishbringer show - Toggles visibility."])
Print(L["- /fishbringer align - Cycles through text alignment."])
Print(L["- /fishbringer count - Toggles fish count visibility."])
Print(L["- /fishbringer reset - Resets the fish database."])
Print(L["- /fishbringer color - Enables/disables gradient color."])
end
SlashCmdList["FISHBRINGER"] = function(arg)
if arg == "align" then
return CycleAlignment()
elseif arg == "show" or arg == "hide" then
return Toggle()
elseif arg == "count" then
return ToggleFishCount()
elseif arg == "reset" then
InitializeDB(true)
UpdateSkill(true)
UpdateCatchInfo()
return
elseif arg == "color" then
toggleColor()
return
end
return ShowHelp()
end
SLASH_FISHBRINGER1 = "/fishbringer"
-- Hail to Fishing Buddy!
if not select(4, GetAddOnInfo"FishingBuddy") then
SLASH_FISHBRINGER2 = "/fb"
end
Print(L["Pack yer bags, we be leavin' fer fishin'!"])