-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfishy.lua
executable file
·486 lines (436 loc) · 12.1 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
FishbringerDB = {}
local FONT = select(1, GameFontNormalSmall:GetFont())
local fb = CreateFrame"Frame"
local db
local char = string.format("%s - %s", UnitName"player", GetRealmName())
fb:RegisterEvent"PLAYER_ENTERING_WORLD"
fb:RegisterEvent"ADDON_LOADED"
fb:RegisterEvent"COMBAT_LOG_EVENT"
fb:RegisterEvent"SKILL_LINES_CHANGED"
fb:RegisterEvent"LOOT_OPENED"
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 = {
["Dun Morogh"] = -70,
["Durotar"] = -70,
["Elwynn Forest"] = -70,
["Mulgore"] = -70,
["Eversong Forest"] = -70,
["Azuremyst Isle"] = -70,
["Teldrassil"] = -70,
["Tirisfal Glades"] = -70,
["Orgrimmar"] = -20,
["Ironforge"] = -20,
["Stormwind City"] = -20,
["Thunder Bluff"] = -20,
["Silvermoon City"] = -20,
["The Exodar"] = -20,
["Darnassus"] = -20,
["Undercity"] = -20,
["The Barrens"] = -20,
["Blackfathom Deeps"] = -20,
["Bloodmyst Isle"] = -20,
["Darkshore"] = -20,
["The Deadmines"] = -20,
["Ghostlands"] = -20,
["Loch Modan"] = -20,
["Silverpine Forest"] = -20,
["The Wailing Caverns"] = -20,
["Westfall"] = -20,
["Ashenvale"] = 55,
["Duskwood"] = 55,
["Hillsbrad Foothills"] = 55,
["Redridge Mountains"] = 55,
["Stonetalon Mountains"] = 55,
["Wetlands"] = 55,
["Alterac Mountains"] = 130,
["Arathi Highlands"] = 130,
["Desolace"] = 130,
["Dustwallow Marsh"] = 130,
["Scarlet Monastery"] = 130,
["Stranglethorn Vale"] = 130,
["Swamp of Sorrows"] = 130,
["Thousand Needles"] = 130,
["Azshara"] = 205,
["Felwood"] = 205,
["Feralas"] = 205,
["The Hinterlands"] = 205,
["Maraudon"] = 205,
["Moonglade"] = 205,
["Tanaris"] = 205,
["The Temple of Atal'Hakkar"] = 205,
["Un'Goro Crater"] = 205,
["Western Plaguelands"] = 205,
["Shadowmoon Valley"] = 280,
["Zangarmarsh"] = 305,
["Burning Steppes"] = 330,
["Deadwind Pass"] = 330,
["Eastern Plaguelands"] = 330,
["Scholomance"] = 330,
["Silithus"] = 330,
["Stratholme"] = 330,
["Winterspring"] = 330,
["Zul'Gurub"] = 330,
["Terokkar Forest"] = 355,
["Nagrand"] = 380,
["Netherstorm"] = 380,
["Borean Tundra"] = 380,
["Dragonblight"] = 380,
["Howling Fjord"] = 380,
["Crystalsong Forest"] = 405,
["Dalaran"] = 430,
["Sholazar Basin"] = 430,
["The Frozen Sea"] = 480,
}
local subzones = {
["Jaguero Isle"] = 205,
["Bay of Storms"] = 330,
["Hetaera's Clutch"] = 330,
["Scalebeard's Cave"] = 330,
["Jademir Lake"] = 330,
["Marshlight Lake"] = 355,
["Sporewind Lake"] = 355,
["Serpent Lake"] = 355,
["Lake Sunspring"] = 395,
["Skysong Lake"] = 395,
["Blackwind Lake"] = 405,
["Lake Ere'Noru"] = 405,
["Lake Jorune"] = 405,
}
local fishingpoles = {
[6256] = true,
[6365] = true,
[6366] = true,
[6367] = true,
[12225] = true,
[19022] = true,
[19970] = true,
[25978] = true,
[44050] = true,
}
local function GetNumFishToLevel(skillRank)
if skillRank <= 75 then
return 1
else
return math.ceil((skillRank - 75) / 25)
end
end
local function UpdateFishCount(shouldIncrement)
if shouldIncrement and IsFishingLoot() then
db[char].fishCaught = db[char].fishCaught + 1
end
Fishbringer.fishCount:SetFormattedText(
"%d fish caught at this level",
db[char].fishCaught
)
end
local function IncrementFishCount()
UpdateFishCount(true)
end
local function ResetFishCounter(numFish)
db[char].fishToCatch = numFish
db[char].fishCaught = 0
UpdateFishCount(false)
end
local function UpdateCatchInfo()
local zoneText = GetSubZoneText()
local zoneSkill = subzones[zoneText]
if not zoneSkill then
zoneText = GetRealZoneText()
zoneSkill = zones[zoneText]
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
local chance = (
(
db[char].fishingSkill + db[char].fishingBuff
) - zoneSkill
) * 0.01 + 0.05
if zoneSkill < 0 then
zoneSkill = 1
end
if chance > 1 then
chance = 1
elseif chance < 0 then
chance = 0
end
local color
if chance == 0 then
color = "ffff2020"
elseif chance <= 0.5 then
color = "ffff8040"
elseif chance < 1 then
color = "ffffff00"
else
color = "ff40bf40"
end
Fishbringer.zoneInfo:SetFormattedText(
"\124c%s%s\124r\n%d skill needed to fish\n(%d needed for 100%% catch rate)",
color, zoneText, zoneSkill, maxZoneSkill, chance * 100
)
Fishbringer.catchRate:SetFormattedText("%d%% catch rate", chance * 100)
end
local function GetFishingSkill()
for i = 1, GetNumSkillLines() do
local skillName, _, _, skillRank, _, skillModifier, skillMaxRank, _, _, _, _, _, _= GetSkillLineInfo(i)
if skillName == "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)
if skillRank ~= skillMaxRank then
skillRankText = string.format("%d/%d", skillRank, skillMaxRank)
fishNeededText = string.format("\n%d fish needed to skill up", fishNeeded)
end
local skillModifierText = ""
if skillModifier > 0 then
skillModifierText = string.format(" (+%d)", skillModifier)
end
Fishbringer.content:SetFormattedText(
"%s%s fishing skill%s",
skillRankText,
skillModifierText,
fishNeededText
)
if forceResetFishCounter or db[char].fishingSkill ~= skillRank then
db[char].fishingSkill = skillRank
ResetFishCounter(fishNeeded)
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 db[char].isShown or 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
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"
}
end
end
local function InitializeFrame()
-- Frame madness
if Fishbringer then
return
end
Fishbringer = CreateFrame("Frame", "Fishbringer", UIParent)
Fishbringer:EnableMouse(true)
Fishbringer:SetMovable(true)
Fishbringer:SetUserPlaced(true)
Fishbringer:SetHeight(150)
Fishbringer:SetWidth(185)
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)
local name
if random(100) < 5 then
name = "Corrupted Fishbringer"
else
name = "Fishbringer"
end
title:SetText(name)
Fishbringer.title = title
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
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 = UpdateSkill
fb.SKILL_LINES_CHANGED = UpdateSkill
fb.LOOT_OPENED = IncrementFishCount
fb.ZONE_CHANGED_NEW_AREA = UpdateCatchInfo
fb.ZONE_CHANGED = UpdateCatchInfo
fb.UNIT_INVENTORY_CHANGED = CheckForFishingPole
local function ShowHelp()
Print("Nat Pagle would be proud of you.")
Print("- /fishbringer show - Toggles visibility.")
Print("- /fishbringer align - Cycles through text alignment.")
Print("- /fishbringer count - Toggles fish count visibility.")
Print("- /fishbringer reset - Resets the fish database.")
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
end
return ShowHelp()
end
SLASH_FISHBRINGER1 = "/fishbringer"
-- Hail to Fishing Buddy!
if not select(4, GetAddOnInfo"Fishing Buddy") then
SLASH_FISHBRINGER2 = "/fb"
end
Print("Pack yer bags, we be leavin' fer fishin'!")