vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | local _DEBUG = false; |
2 | local downTime = nil; |
||
3 | local fe = nil; |
||
4 | local profile = nil; |
||
5 | local fishingID = nil; |
||
6 | local mainHandSlotID = nil; |
||
7 | local offHandSlotID = nil; |
||
8 | local gloveSlotID = nil; |
||
9 | local hatSlotID = nil; |
||
10 | local bootSlotID = nil; |
||
11 | local clickToMove = nil; |
||
12 | |||
13 | local function Print(msg) |
||
14 | if (not msg) then return; end |
||
15 | if( DEFAULT_CHAT_FRAME ) then |
||
16 | DEFAULT_CHAT_FRAME:AddMessage(msg,1.0,1.0,1.0); |
||
17 | end |
||
18 | end |
||
19 | local function Debug(msg) |
||
20 | if (not _DEBUG) then return; end |
||
21 | if (not msg) then return; end |
||
22 | if( DEFAULT_CHAT_FRAME ) then |
||
23 | DEFAULT_CHAT_FRAME:AddMessage("FE: "..GetTime()..": "..msg,1.0,0.0,0.0); |
||
24 | end |
||
25 | end |
||
26 | |||
27 | function FE_OnLoad() |
||
28 | |||
29 | Old_TurnOrActionStart = TurnOrActionStart; |
||
30 | TurnOrActionStart = FE_TurnOrActionStart; |
||
31 | Old_TurnOrActionStop = TurnOrActionStop; |
||
32 | TurnOrActionStop = FE_TurnOrActionStop; |
||
33 | |||
34 | -- create slash commands |
||
35 | SlashCmdList["FESLASH"] = FE_ChatCommandHandler; |
||
36 | SLASH_FESLASH1 = "/fishease"; |
||
37 | SLASH_FESLASH2 = "/fe"; |
||
38 | |||
39 | this:RegisterEvent("VARIABLES_LOADED"); |
||
40 | this:RegisterEvent("SPELLS_CHANGED"); |
||
41 | |||
42 | end |
||
43 | |||
44 | local function FE_LearnFishingSkill() |
||
45 | -- reset the fishingID in case they un-learned it |
||
46 | fishingID = nil; |
||
47 | |||
48 | --Loop through only the General tab looking for the Fishing skill |
||
49 | local _, _, off, num = GetSpellTabInfo(1); |
||
50 | local sIcon = nil; |
||
51 | for i=(off+1), (off+num) do |
||
52 | sIcon = GetSpellTexture(i,1); |
||
53 | if (sIcon and sIcon == "Interface\\Icons\\Trade_Fishing") then |
||
54 | fishingID = i; |
||
55 | break; |
||
56 | end |
||
57 | end |
||
58 | end |
||
59 | |||
60 | function FE_OnEvent(event) |
||
61 | if (event == "VARIABLES_LOADED") then |
||
62 | |||
63 | if (not fe) then |
||
64 | |||
65 | if (not FishEase_Cfg) then |
||
66 | FishEase_Cfg = {}; |
||
67 | end |
||
68 | |||
69 | if (FishEase_Cfg['version'] ~= FE_ADDON_VER) then |
||
70 | -- do older version cleanup here? |
||
71 | FishEase_Cfg['version'] = FE_ADDON_VER; |
||
72 | end |
||
73 | |||
74 | profile = UnitName("player").." of "..GetCVar("RealmName"); |
||
75 | if (not FishEase_Cfg[profile]) then |
||
76 | FishEase_Cfg[profile] = { |
||
77 | ['EasyCast'] = true, |
||
78 | ['FastCast'] = true, |
||
79 | ['ShiftCast'] = false, |
||
80 | }; |
||
81 | Debug("Setting FishEase defaults"); |
||
82 | end |
||
83 | fe = FishEase_Cfg[profile]; |
||
84 | end |
||
85 | |||
86 | mainHandSlotID = GetInventorySlotInfo("MainHandSlot"); |
||
87 | offHandSlotID = GetInventorySlotInfo("SecondaryHandSlot"); |
||
88 | gloveSlotID = GetInventorySlotInfo("HandsSlot"); |
||
89 | hatSlotID = GetInventorySlotInfo("HeadSlot"); |
||
90 | bootSlotID = GetInventorySlotInfo("FeetSlot"); |
||
91 | |||
92 | FE_LearnFishingSkill(); |
||
93 | |||
94 | elseif (event == "SPELLS_CHANGED") then |
||
95 | |||
96 | FE_LearnFishingSkill(); |
||
97 | |||
98 | end |
||
99 | end |
||
100 | |||
101 | local function FE_ShowToggleStatus(optName, optOutString) |
||
102 | if (fe[optName]) then |
||
103 | Print(string.format(FE_OUT_ENABLED, optOutString)); |
||
104 | else |
||
105 | Print(string.format(FE_OUT_DISABLED, optOutString)); |
||
106 | end |
||
107 | end |
||
108 | |||
109 | -- FishEase command handler |
||
110 | function FE_ChatCommandHandler(msg) |
||
111 | if (not msg) then return; end |
||
112 | local args = {}; |
||
113 | for arg in string.gfind(msg, "([%w]+)") do |
||
114 | table.insert(args, arg); |
||
115 | end |
||
116 | if (not args[1]) then |
||
117 | FE_ShowToggleStatus('EasyCast', FE_OUT_EASYCAST); |
||
118 | FE_ShowToggleStatus('FastCast', FE_OUT_FASTCAST); |
||
119 | FE_ShowToggleStatus('ShiftCast', FE_OUT_SHIFTCAST); |
||
120 | elseif (args[1] and args[1] == FE_CMD_EASYCAST) then |
||
121 | FE_OptionToggle(args[2], 'EasyCast', FE_SYNTAX_EASYCAST, FE_OUT_EASYCAST); |
||
122 | elseif (args[1] and args[1] == FE_CMD_FASTCAST) then |
||
123 | FE_OptionToggle(args[2], 'FastCast', FE_SYNTAX_FASTCAST, FE_OUT_FASTCAST); |
||
124 | elseif (args[1] and args[1] == FE_CMD_SHIFTCAST) then |
||
125 | FE_OptionToggle(args[2], 'ShiftCast', FE_SYNTAX_SHIFTCAST, FE_OUT_SHIFTCAST); |
||
126 | elseif (args[1] and args[1] == FE_CMD_SWITCH) then |
||
127 | FE_Switch(); |
||
128 | elseif (args[1] and args[1] == FE_CMD_RESET) then |
||
129 | FE_Reset(); |
||
130 | elseif (args[1] and args[1] == "debug") then |
||
131 | FE_ToggleDebug(); |
||
132 | else |
||
133 | for index, value in FE_COMMAND_HELP do |
||
134 | Print(value); |
||
135 | end |
||
136 | end |
||
137 | end |
||
138 | |||
139 | function FE_OptionToggle(togVar, optName, optSyntax, optOutString) |
||
140 | if (not togVar) then |
||
141 | fe[optName] = not fe[optName]; |
||
142 | elseif (string.lower(togVar) == "on") then |
||
143 | fe[optName] = true; |
||
144 | elseif (togVar == "off") then |
||
145 | fe[optName] = false; |
||
146 | else |
||
147 | Print(FE_SYNTAX_ERROR); |
||
148 | Print(optSyntax); |
||
149 | return; |
||
150 | end |
||
151 | if (fe[optName]) then |
||
152 | Print(string.format(FE_OUT_ENABLED, optOutString)); |
||
153 | else |
||
154 | Print(string.format(FE_OUT_DISABLED, optOutString)); |
||
155 | end |
||
156 | end |
||
157 | |||
158 | --[[ Keeping this for reference |
||
159 | FE_POLES = { |
||
160 | 6256, -- Fishing Pole |
||
161 | 6365, -- Strong Fishing Pole |
||
162 | 6366, -- Darkwood Fishing Pole |
||
163 | 6367, -- Big Iron Fishing Pole |
||
164 | 12225, -- Blump Family Fishing Pole |
||
165 | 19022, -- Nat Pagle\'s Extreme Angler FC-5000 |
||
166 | 19970, -- Arcanite Fishing Pole |
||
167 | }]] |
||
168 | local function FE_IsFishingPoleEquipped() |
||
169 | local itemIcon = GetInventoryItemTexture("player", mainHandSlotID); |
||
170 | if (itemIcon and string.find(itemIcon, "INV_Fishingpole")) then |
||
171 | return true; |
||
172 | else |
||
173 | return nil; |
||
174 | end |
||
175 | end |
||
176 | |||
177 | local function FE_GetInvSlotItemID(slotID) |
||
178 | local link = GetInventoryItemLink("player", slotID); |
||
179 | local id = nil; |
||
180 | if (link) then |
||
181 | for id in string.gfind(link, "item:(%d+):") do |
||
182 | return tonumber(id); |
||
183 | end |
||
184 | end |
||
185 | return id; |
||
186 | end |
||
187 | |||
188 | local function FE_GetEquipped() |
||
189 | local mainHandID, offHandID, gloveID, hatID, bootID = nil, nil, nil, nil, nil; |
||
190 | mainHandID = FE_GetInvSlotItemID(mainHandSlotID); |
||
191 | offHandID = FE_GetInvSlotItemID(offHandSlotID); |
||
192 | gloveID = FE_GetInvSlotItemID(gloveSlotID); |
||
193 | hatID = FE_GetInvSlotItemID(hatSlotID); |
||
194 | bootID = FE_GetInvSlotItemID(bootSlotID); |
||
195 | return mainHandID, offHandID, gloveID, hatID, bootID; |
||
196 | end |
||
197 | |||
198 | function FE_TurnOrActionStart(arg1) |
||
199 | |||
200 | -- Disable Click-to-Move if they have a fishing pole equipped |
||
201 | if (fe['EasyCast'] and GetCVar("autointeract") == "1" and FE_IsFishingPoleEquipped()) then |
||
202 | clickToMove = "1"; |
||
203 | SetCVar("autointeract", "0"); |
||
204 | end |
||
205 | |||
206 | -- Pass the call through |
||
207 | if (Old_TurnOrActionStart) then |
||
208 | Old_TurnOrActionStart(arg1); |
||
209 | end |
||
210 | |||
211 | -- Set the mouse down time |
||
212 | if (fe['EasyCast']) then |
||
213 | if (not fe['FastCast'] and (GameTooltip:IsVisible() and (getglobal("GameTooltipTextLeft1"):GetText() == FE_BOBBER_NAME))) then |
||
214 | downTime = 0; |
||
215 | else |
||
216 | downTime = GetTime(); |
||
217 | end |
||
218 | end |
||
219 | end |
||
220 | |||
221 | function FE_TurnOrActionStop(arg1) |
||
222 | |||
223 | -- Pass the call through |
||
224 | if (Old_TurnOrActionStop) then |
||
225 | Old_TurnOrActionStop(arg1); |
||
226 | end |
||
227 | |||
228 | -- Cast if we need to |
||
229 | if (fe['EasyCast']) then |
||
230 | local pressTime = GetTime() - downTime; |
||
231 | if (fishingID and pressTime <= 0.2) then |
||
232 | if (not fe['ShiftCast'] or (fe['ShiftCast'] and IsShiftKeyDown())) then |
||
233 | if (FE_IsFishingPoleEquipped()) then |
||
234 | CastSpell(fishingID, BOOKTYPE_SPELL); |
||
235 | end |
||
236 | end |
||
237 | end |
||
238 | end |
||
239 | |||
240 | -- Re-enable Click-to-Move if we changed it |
||
241 | if (clickToMove and (GetCVar("autointeract") == "0")) then |
||
242 | SetCVar("autointeract", "1"); |
||
243 | end |
||
244 | end |
||
245 | |||
246 | function FE_FindContainerItem(itemID, searchReverse) |
||
247 | if (not itemID) then return nil,nil; end |
||
248 | |||
249 | local foundBag = nil; |
||
250 | local foundSlot = nil; |
||
251 | local numSlots = 0; |
||
252 | |||
253 | local startBag, endBag, bagStep = 0, NUM_BAG_FRAMES, 1; |
||
254 | if (searchReverse) then |
||
255 | startBag, endBag, bagStep = NUM_BAG_FRAMES, 0, -1; |
||
256 | end |
||
257 | |||
258 | -- check each of the bags on the player |
||
259 | for i=startBag, endBag, bagStep do |
||
260 | |||
261 | -- get the number of slots in the bag (0 if no bag) |
||
262 | numSlots = GetContainerNumSlots(i); |
||
263 | if (numSlots > 0) then |
||
264 | |||
265 | -- check each slot in the bag |
||
266 | local startSlot, endSlot, slotStep = 1, numSlots, 1; |
||
267 | if (searchReverse) then |
||
268 | startSlot, endSlot, slotStep = numSlots, 1, -1; |
||
269 | end |
||
270 | for j=startSlot, endSlot, slotStep do |
||
271 | |||
272 | itemLink = GetContainerItemLink(i,j); |
||
273 | if (itemLink) then |
||
274 | |||
275 | -- check for the specified itemID |
||
276 | if (string.find(itemLink, "item:"..itemID..":")) then |
||
277 | foundBag = i; |
||
278 | foundSlot = j; |
||
279 | Debug("Found "..itemLink.." at bag"..foundBag.." slot"..foundSlot); |
||
280 | -- break out of the slot loop |
||
281 | break; |
||
282 | end |
||
283 | |||
284 | end |
||
285 | end |
||
286 | |||
287 | -- break out of the bag loop if we found the item |
||
288 | if (foundBag) then break; end |
||
289 | end |
||
290 | end |
||
291 | |||
292 | return foundBag, foundSlot; |
||
293 | end |
||
294 | |||
295 | local function FE_Equip(itemID, equipSlot) |
||
296 | -- fail if something's on the cursor |
||
297 | if (CursorHasItem()) then |
||
298 | return false; |
||
299 | end |
||
300 | -- make sure it's not already equipped |
||
301 | local currentLink = GetInventoryItemLink("player",equipSlot); |
||
302 | if (currentLink and string.find(currentLink, "item:"..itemID..":")) then |
||
303 | return true; |
||
304 | end |
||
305 | -- try to find the item in their bags |
||
306 | local bag, slot; |
||
307 | if (equipSlot == mainHandSlotID and fe['normMain'] == fe['normOff']) then |
||
308 | bag, slot = FE_FindContainerItem(itemID, true); |
||
309 | else |
||
310 | bag, slot = FE_FindContainerItem(itemID); |
||
311 | end |
||
312 | if (bag and slot) then |
||
313 | PickupContainerItem(bag, slot); |
||
314 | if (equipSlot) then |
||
315 | PickupInventoryItem(equipSlot); |
||
316 | else |
||
317 | AutoEquipCursorItem(); |
||
318 | end |
||
319 | return true; |
||
320 | end |
||
321 | return false; |
||
322 | end |
||
323 | |||
324 | local function FE_SaveSwitchItem(itemID, slotID, saveName, setString) |
||
325 | if (itemID and itemID ~= fe[saveName]) then |
||
326 | fe[saveName] = itemID; |
||
327 | if (itemID) then |
||
328 | Print(string.format(setString,GetInventoryItemLink("player",slotID))); |
||
329 | end |
||
330 | end |
||
331 | end |
||
332 | |||
333 | local function FE_SwapSlot(saveName, slotID, setString) |
||
334 | if (fe[saveName]) then |
||
335 | if (not FE_Equip(fe[saveName],slotID)) then |
||
336 | -- couldn't equip item |
||
337 | Debug("couldn't equip "..saveName.."("..fe[saveName]..") into slot "..slotID); |
||
338 | fe[saveName] = nil; |
||
339 | end |
||
340 | end |
||
341 | if (not fe[saveName] and setString) then |
||
342 | Print(setString); |
||
343 | end |
||
344 | end |
||
345 | |||
346 | function FE_Switch() |
||
347 | |||
348 | local mainHandID, offHandID, gloveID, hatID, bootID = FE_GetEquipped(); |
||
349 | |||
350 | if (FE_IsFishingPoleEquipped()) then |
||
351 | |||
352 | -- Save our current fishing gear |
||
353 | FE_SaveSwitchItem(mainHandID, mainHandSlotID, 'fishPole', FE_OUT_SET_POLE); |
||
354 | FE_SaveSwitchItem(gloveID, gloveSlotID, 'fishGlove', FE_OUT_SET_FISHING_GLOVES); |
||
355 | FE_SaveSwitchItem(hatID, hatSlotID, 'fishHat', FE_OUT_SET_FISHING_HAT); |
||
356 | FE_SaveSwitchItem(bootID, bootSlotID, 'fishBoot', FE_OUT_SET_FISHING_BOOT); |
||
357 | |||
358 | -- Swap to normal gear |
||
359 | FE_SwapSlot('normMain', mainHandSlotID, FE_OUT_NEED_SET_NORMAL); |
||
360 | FE_SwapSlot('normOff', offHandSlotID, nil); |
||
361 | FE_SwapSlot('normGlove', gloveSlotID, nil); |
||
362 | FE_SwapSlot('normHat', hatSlotID, nil); |
||
363 | FE_SwapSlot('normBoot', bootSlotID, nil); |
||
364 | |||
365 | else |
||
366 | |||
367 | -- Save our current normal gear |
||
368 | FE_SaveSwitchItem(mainHandID, mainHandSlotID, 'normMain', FE_OUT_SET_MAIN); |
||
369 | FE_SaveSwitchItem(offHandID, offHandSlotID, 'normOff', FE_OUT_SET_SECONDARY); |
||
370 | FE_SaveSwitchItem(gloveID, gloveSlotID, 'normGlove', FE_OUT_SET_GLOVES); |
||
371 | FE_SaveSwitchItem(hatID, hatSlotID, 'normHat', FE_OUT_SET_HAT); |
||
372 | FE_SaveSwitchItem(bootID, bootSlotID, 'normBoot', FE_OUT_SET_BOOT); |
||
373 | |||
374 | -- Swap to fishing gear |
||
375 | FE_SwapSlot('fishPole', mainHandSlotID, FE_OUT_NEED_SET_POLE); |
||
376 | FE_SwapSlot('fishGlove', gloveSlotID, nil); |
||
377 | FE_SwapSlot('fishHat', hatSlotID, nil); |
||
378 | FE_SwapSlot('fishBoot', bootSlotID, nil); |
||
379 | |||
380 | end |
||
381 | end |
||
382 | |||
383 | function FE_CastPole() |
||
384 | |||
385 | -- switch to pole if needed |
||
386 | if (not FE_IsFishingPoleEquipped()) then |
||
387 | FE_Switch(); |
||
388 | else |
||
389 | CastSpell(fishingID, BOOKTYPE_SPELL); |
||
390 | end |
||
391 | |||
392 | end |
||
393 | |||
394 | function FE_Reset() |
||
395 | fe['normMain'] = nil; |
||
396 | fe['normOff'] = nil; |
||
397 | fe['normGlove'] = nil; |
||
398 | fe['normHat'] = nil; |
||
399 | fe['fishPole'] = nil; |
||
400 | fe['fishGlove'] = nil; |
||
401 | fe['fishHat'] = nil; |
||
402 | fe['fishBoot'] = nil; |
||
403 | Print(FE_OUT_RESET); |
||
404 | end |
||
405 | |||
406 | function FE_ToggleDebug() |
||
407 | _DEBUG = not _DEBUG; |
||
408 | if (_DEBUG) then |
||
409 | Print("Debug output is now on."); |
||
410 | else |
||
411 | Print("Debug output is now off."); |
||
412 | end |
||
413 | end |
||
414 |