forked from Adirelle/ezFishing
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Core.lua
296 lines (263 loc) · 8.13 KB
/
Core.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
--------------------------------------------------------------------------------
-- Constants
--------------------------------------------------------------------------------
local defaults = { profile = {
autoLure = true,
autoLoot = true,
enhanceSounds = true,
}}
local fishingSkill = GetSpellInfo(7620)
local mainHandSlot = 16
local cvarOverrides = {
enhanceSounds = {
--Sound_MasterVolume = 1.0,
Sound_SFXVolume = 1.0,
Sound_MusicVolume = 0.0,
Sound_AmbienceVolume = 0.0,
},
always = {
autointeract = 0,
},
autoLoot = {
autoLootDefault = 1,
},
}
local poles = {
[ 6256] = true, -- Fishing Pole
[ 6365] = true, -- Strong Fishing Pole
[ 6366] = true, -- Darkwood Fishing Pole
[ 6367] = true, -- Big Iron Fishing Pole
[12225] = true, -- Blump Family Fishing Pole
[19022] = true, -- Nat Pagle's Extreme Angler FC-5000
[19970] = true, -- Arcanite Fishing Pole
[25978] = true, -- Seth's Graphite Fishing Pole
[44050] = true, -- Mastercraft Kalu'ak Fishing Pole
[45858] = true, -- Nat's Lucky Fishing Pole
[45991] = true, -- Bone Fishing Pole
[45992] = true, -- Jeweled Fishing Pole
}
local lures = {
-- [Item Id] = { required skill, bonus, duration(m) }
[ 6529] = { 0, 25, 10 }, -- Shiny Bauble
[ 6530] = { 50, 50, 10 }, -- Nightcrawlers
[ 6532] = { 100, 75, 10 }, -- Bright Baubles
[ 6533] = { 100, 100, 10 }, -- Aquadynamic Fish Attractor
[ 6811] = { 50, 50, 10 }, -- Aquadynamic Fish Lens
[ 7307] = { 100, 75, 10 }, -- Flesh Eating Worm
[33820] = { 0, 75, 10 }, -- Weather-Beaten Fishing Hat
[34861] = { 100, 100, 10 }, -- Sharpened Fish Hook
[46006] = { 100, 100, 60 }, -- Glow Worm
}
local db
--------------------------------------------------------------------------------
-- Lure handling
--------------------------------------------------------------------------------
local function GetFishingSkill()
local _, _, _, fishing, _, _ = GetProfessions()
local name, _, rank, _, _, _, _, modifier = GetProfessionInfo(fishing)
if (not modifier) then
return rank
else
return rank + modifier
end
return 0
end
local function GetBestLure()
local skill, lure
local score = 0
for itemId, info in pairs(lures) do
if GetItemCount(itemId) > 0 then
local requiredSkill, bonus, duration = unpack(info)
local thisScore = bonus * duration
skill = skill or GetFishingSkill()
if skill >= requiredSkill and thisScore > score then
lure, score = itemId, thisScore
end
end
end
return lure
end
--------------------------------------------------------------------------------
-- teh frame
--------------------------------------------------------------------------------
local frame = CreateFrame("Frame")
frame:Hide()
--------------------------------------------------------------------------------
-- Core
--------------------------------------------------------------------------------
local button = CreateFrame("Button", "ezFishingButton", UIParent, "SecureActionButtonTemplate")
button:EnableMouse(true)
button:SetFrameStrata("LOW")
button:RegisterForClicks("RightButtonUp")
button:SetPoint("TOP", UIParent, "BOTTOM", 0, -5)
button:SetScript("PreClick", function(self)
if UnitCastingInfo("player") then
return
end
if db.profile.autoLure and not GetWeaponEnchantInfo() then
local lure = GetBestLure()
if lure then
if GetItemCooldown(lure) == 0 then
self:SetAttribute("type", "item")
self:SetAttribute("item", "item:"..lure)
self:SetAttribute("target-slot", INVSLOT_MAINHAND)
end
return
end
end
local fishingMacroIndex = GetMacroIndexByName(fishingSkill)
if fishingMacroIndex ~= 0 then
self:SetAttribute("type", "macro")
self:SetAttribute("macro", fishingMacroIndex)
else
self:SetAttribute("type", "spell")
self:SetAttribute("spell", fishingSkill)
end
end)
button:SetScript("PostClick", function(self)
ClearOverrideBindings(frame)
self:SetAttribute("type", nil)
self:SetAttribute("item", nil)
self:SetAttribute("target-slot", nil)
self:SetAttribute("spell", nil)
self:SetAttribute("macro", nil)
end)
local lastClickTime = 0
local function OnMouseDown_Hook(_, button)
if frame:IsShown() and button == "RightButton" then
local now = GetTime()
local delay = now - lastClickTime
lastClickTime = now
if delay < 0.4 then
SetOverrideBindingClick(frame, true, "BUTTON2", "ezFishingButton")
end
end
end
--------------------------------------------------------------------------------
-- Enabling/disabling fishing mode
--------------------------------------------------------------------------------
local cvarBackup = {}
local function OverrideCVars(values)
for name, value in pairs(values) do
local currentValue = tonumber(GetCVar(name))
if currentValue ~= value then
cvarBackup[name] = currentValue
SetCVar(name, value)
end
end
end
frame:SetScript('OnShow', function(self)
OverrideCVars(cvarOverrides.always)
if db.profile.autoLoot then
OverrideCVars(cvarOverrides.autoLoot)
end
if db.profile.enhanceSounds then
OverrideCVars(cvarOverrides.enhanceSounds)
end
end)
frame:SetScript('OnHide', function(self)
ClearOverrideBindings(frame)
for name, value in pairs(cvarBackup) do
SetCVar(name, value)
end
wipe(cvarBackup)
end)
function frame:CheckActivation()
if not InCombatLockdown() then
local mainHandId = tonumber(GetInventoryItemID("player", INVSLOT_MAINHAND) or nil)
if mainHandId and poles[mainHandId] then
self:Show()
return
end
end
self:Hide()
end
--------------------------------------------------------------------------------
-- Option handling
--------------------------------------------------------------------------------
local options
local function GetOptions()
if not options then
options = {
name = 'ezFishing',
type = 'group',
set = function(info, value)
local shown = frame:IsShown()
if shown then
frame:Hide()
end
db.profile[info[#info]] = value
if shown then
frame:Show()
end
end,
get = function(info)
return db.profile[info[#info]]
end,
args = {
autoLure = {
name = 'Apply lure',
desc = 'Automatically apply a lure when need be.',
type = 'toggle',
},
autoLoot = {
name = 'Autoloot',
desc = 'Enable autolooting when a fishing pole is equipped.',
type = 'toggle',
},
enhanceSounds = {
name = 'Enhanced sounds',
desc = 'Change sound settings to ease fishing when a fishing pole is equipped.',
type = 'toggle',
},
}
}
end
return options
end
--------------------------------------------------------------------------------
-- Slash commands
--------------------------------------------------------------------------------
SlashCmdList["EZFISHING"] = function()
InterfaceOptionsFrame_OpenToCategory("ezFishing")
end
SLASH_EZFISHING1 = "/ezfishing"
SLASH_EZFISHING2 = "/ezfish"
--------------------------------------------------------------------------------
-- Event handling
--------------------------------------------------------------------------------
frame:SetScript('OnEvent', function(self, event, ...)
if type(self[event]) == "function" then
return self[event](self, event, ...)
--@debug@
else
print("ezFishing: no handler for ", event)
--@end-debug@
end
end)
function frame:UNIT_INVENTORY_CHANGED(_, unit)
if unit == 'player' then
self:CheckActivation()
end
end
function frame:ADDON_LOADED(_, addon)
if addon:lower() ~= "ezfishing" then return end
self:UnregisterEvent('ADDON_LOADED')
if LibStub and LibStub("AceDB-3.0", true) and LibStub("AceConfigDialog-3.0", true) then
db = LibStub('AceDB-3.0'):New('ezFishingDB', defaults, true)
LibStub("AceConfig-3.0"):RegisterOptionsTable('ezFishing', GetOptions)
LibStub("AceConfigDialog-3.0"):AddToBlizOptions('ezFishing', 'ezFishing')
else
db = defaults
end
WorldFrame:HookScript('OnMouseDown', OnMouseDown_Hook)
self:CheckActivation()
end
frame.PLAYER_LOGOUT = frame.Hide
frame.PLAYER_REGEN_DISABLED = frame.Hide
frame.PLAYER_REGEN_ENABLED = frame.CheckActivation
frame:RegisterEvent('PLAYER_LOGOUT')
frame:RegisterEvent('PLAYER_REGEN_DISABLED')
frame:RegisterEvent('PLAYER_REGEN_ENABLED')
frame:RegisterEvent('UNIT_INVENTORY_CHANGED')
frame:RegisterEvent('ADDON_LOADED')