vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 ----------------------------------------------------------------------------
2 -- $Id: Sea.wow.spellbook.lua 3673 2006-06-17 03:58:57Z Miravlix $
3 --
4 -- WoW Spellbook cache
5 ----------------------------------------------------------------------------
6  
7 local VERSION = 1.4
8 SeaSpellbook_debug = false
9  
10 if not SeaSpellbook_ID then
11 SeaSpellbook_ID = "SeaSpellbook"
12 SeaSpellbook_KEY = "spellbook"
13 end
14  
15  
16 --
17 -- Setup all our variables and tables
18 --
19 Sea.versions[SeaSpellbook_ID] = VERSION
20  
21 Sea.wow[SeaSpellbook_KEY] = {
22 firstRun = true,
23  
24 scholars = {},
25 [BOOKTYPE_SPELL] = {},
26 [BOOKTYPE_PET] = {},
27 textures = { [BOOKTYPE_SPELL] = {}, [BOOKTYPE_PET] = {}, },
28 }
29 table.setn( Sea.wow[SeaSpellbook_KEY].scholars, 0 )
30 table.setn( Sea.wow[SeaSpellbook_KEY][BOOKTYPE_SPELL], 0 )
31 table.setn( Sea.wow[SeaSpellbook_KEY][BOOKTYPE_PET], 0 )
32 table.setn( Sea.wow[SeaSpellbook_KEY].textures[BOOKTYPE_SPELL], 0 )
33 table.setn( Sea.wow[SeaSpellbook_KEY].textures[BOOKTYPE_PET], 0 )
34  
35 local SeaSpellbook_Compare, SeaSpellbook_FindPattern
36  
37 --
38 -- Create a new frame if none exist
39 --
40 if not Sea.wow.spellbook.FRAME then
41 Sea.wow.spellbook.FRAME = CreateFrame("Frame", "SeaSpellbookFrame")
42 end
43  
44  
45 --
46 -- Create tooltip frame
47 --
48 -- Disabled due to being broken in 1.10.1
49 --[[
50 if not Sea.wow.spellbook.TOOLTIP then
51 Sea.wow.spellbook.TOOLTIP = CreateFrame("GameTooltip", "SeaSpellbookTooltip")
52 for i = 1, 30 do
53 SeaSpellbookTooltip:CreateFontString("SeaSpellbookTooltipTextRight" .. i)
54 SeaSpellbookTooltip:CreateFontString("SeaSpellbookTooltipTextLeft" .. i)
55 end
56 end
57 ]]--
58  
59  
60 --
61 -- OnEvent handler
62 --
63 -- We monitor a few events to get our data.
64 Sea.wow[SeaSpellbook_KEY].OnEvent = function()
65 Sea.wow.spellbook.dprint(SeaSpellbook_debug, "Sea spellbook: ", event, " ", arg1)
66  
67 -- Pet spellbook update
68 -- UNIT_PET - Call/Dismiss
69 -- UNIT_PET_TRAINING_POINTS - Training pet
70 if event == "UNIT_PET" and arg1 == "player" or
71 event == "UNIT_PET_TRAINING_POINTS" then
72  
73 if HasPetSpells() then
74 if GetTime() - Sea.wow.spellbook.petTimer > 3 then
75 Sea.wow.spellbook[BOOKTYPE_PET] = {}
76 SeaSpellbook[BOOKTYPE_PET] = Sea.wow.spellbook[BOOKTYPE_PET]
77 Sea.wow.spellbook[BOOKTYPE_PET].petName = UnitName("pet")
78 Sea.wow.spellbook.ReadSpellbook( BOOKTYPE_PET )
79 Sea.wow.spellbook.petTimer = GetTime()
80 end
81 else
82 Sea.wow.spellbook[BOOKTYPE_PET].petName = nil
83 end
84  
85 -- When the spellbook change this event is fired
86 elseif event == "LEARNED_SPELL_IN_TAB" then
87 Sea.wow.spellbook.ReadSpellTab( BOOKTYPE_SPELL, arg1)
88 Sea.wow.spellbook.CallScholars( BOOKTYPE_SPELL )
89  
90 -- Mana cost changes for some spells on level up
91 -- Talents effects the spellbook
92 elseif event == "PLAYER_LEVEL_UP" or
93 event == "CHARACTER_POINTS_CHANGED" and arg1 == -1 then
94 Sea.wow.spellbook.ReadSpellbook( BOOKTYPE_SPELL )
95  
96 -- First event where we can always read the spellbook
97 elseif event == "PLAYER_ENTERING_WORLD" then
98 Sea.wow.spellbook.Pew()
99  
100 -- Handle Blizzards Zoning nonsense
101 elseif event == "PLAYER_LEAVING_WORLD" then
102 this:UnregisterEvent("UNIT_PET")
103  
104 -- Initialization
105 elseif event == "VARIABLES_LOADED" then
106 Sea.wow.spellbook.variablesLoaded = true
107 SeaSpellbookTooltip:SetOwner(SeaSpellbookTooltip, "ANCHOR_NONE")
108 Sea.wow.spellbook.petTimer = GetTime()
109  
110 local _, eClass = UnitClass("player")
111 if eClass == "WARLOCK" or eClass == "HUNTER" then
112 Sea.wow.spellbook.petClass = true
113 end
114  
115 this:RegisterEvent("PLAYER_ENTERING_WORLD")
116 end
117 end
118  
119  
120 --
121 -- Register our OnEvent handler with the frame.
122 --
123 Sea.wow.spellbook.FRAME:SetScript("OnEvent", Sea.wow.spellbook.OnEvent)
124  
125  
126 --
127 -- Setup our initialization event
128 --
129 Sea.wow.spellbook.FRAME:RegisterEvent("VARIABLES_LOADED")
130  
131  
132 --
133 -- Pew()
134 --
135 -- PLAYER_ENTERING_WORLD
136 Sea.wow[SeaSpellbook_KEY].Pew = function()
137 Sea.wow.spellbook.pew = true
138  
139 -- If no one has registered with us, we don't do any work
140 if table.getn( Sea.wow.spellbook.scholars ) > 0 then
141 -- Only do the setup once
142 if Sea.wow.spellbook.firstRun then
143 Sea.wow.spellbook.firstRun = false
144  
145 Sea.wow.spellbook.ReadSpellbook( BOOKTYPE_SPELL )
146  
147 if Sea.wow.spellbook.petClass and HasPetSpells() then
148 Sea.wow.spellbook[BOOKTYPE_PET].petName = UnitName("pet")
149 Sea.wow.spellbook.ReadSpellbook( BOOKTYPE_PET )
150 Sea.wow.spellbook.petTimer = GetTime()
151 end
152  
153 -- Register our events now we are ready to handle them
154 this:RegisterEvent("PLAYER_LEVEL_UP")
155 this:RegisterEvent("LEARNED_SPELL_IN_TAB")
156 this:RegisterEvent("CHARACTER_POINTS_CHANGED")
157  
158 if Sea.wow.spellbook.petClass then
159 this:RegisterEvent("UNIT_PET_TRAINING_POINTS")
160 else
161 this:UnregisterEvent("PLAYER_ENTERING_WORLD")
162 end
163 end
164  
165 -- Zone event overload fix
166 if Sea.wow.spellbook.petClass then
167 this:RegisterEvent("UNIT_PET")
168  
169 if Sea.wow.spellbook[BOOKTYPE_PET].petName then
170 Sea.wow.spellbook.petTimer = GetTime()
171 end
172 end
173  
174 end
175  
176 end
177  
178  
179 --
180 -- RegisterScholar( { scholar } )
181 -- scholar - table
182 -- {
183 -- id - Unique id for the scholar
184 -- callback - callback function
185 -- callback( bookType )
186 --
187 -- bookType - 1 spellbook, 2 petbook, 3 both
188 --
189 -- feedback - table
190 -- {
191 -- spell = true, - Set this to get called when the spellbook updates
192 -- pet = true, - And for petbook updates.
193 -- }
194 --
195 -- description - description string
196 -- }
197 --
198 -- Register a scholar with the specified id, that will be informed when the spellbook change
199 Sea.wow[SeaSpellbook_KEY].RegisterScholar = function( scholar )
200 -- Are we ready to rumble!
201 if not Sea.wow.spellbook.variablesLoaded then
202 Sea.wow.spellbook.print("SeaSpellbook: ", this:GetName(), " called us before we where initialized")
203 return false
204 end
205  
206 -- Check that scholar seems correct
207 if not Sea.wow.spellbook.VerifyScholar( scholar ) then
208 return false
209 end
210  
211 local scholars = Sea.wow.spellbook.scholars
212  
213 -- Avoid that the same function is registered multiple times
214 if table.getn( scholars ) > 0 then
215 for i=1, table.getn( scholars ) do
216 if scholars[i].id == scholar.id then
217 Sea.wow.spellbook.print("SeaSpellbook: ", this:GetName(), " tried to register an already registered scholar.id")
218 return false
219 end
220 end
221 end
222  
223 tinsert( scholars, scholar )
224  
225 -- Call the newly created Scholar
226 if Sea.wow.spellbook.pew and Sea.wow.spellbook.firstRun then
227 Sea.wow.spellbook.Pew()
228 elseif Sea.wow.spellbook.pew and not Sea.wow.spellbook.firstRun then
229 local success, result = pcall( scholar.callback, bookType )
230 if not success then
231 message( result )
232 Sea.wow.spellbook.print( "SeaSpellbook: Failed calling ", scholar.id )
233 tremove(scholars, table.getn(scholars) )
234  
235 return false
236 end
237 end
238  
239 return true
240 end
241  
242  
243 --
244 -- UnregisterScholar( id )
245 --
246 --
247 -- Remove a registered Scholar
248 Sea.wow[SeaSpellbook_KEY].UnregisterScholar = function( id )
249 local scholars = Sea.wow.spellbook.scholars
250  
251 if table.getn( scholars ) > 0 then
252 for i=1, table.getn( scholars ) do
253 if scholars[i].id == id then
254 tremove( scholars, i )
255 return true
256 end
257 end
258 end
259  
260 Sea.wow.spellbook.print("SeaSpellbook: ", this:GetName(), " tried to unregister unknown scholar id.")
261 return false
262 end
263  
264  
265 --
266 -- CallScholars( bookType )
267 --
268 -- Call the registered Scholars
269 Sea.wow[SeaSpellbook_KEY].CallScholars = function( bookType )
270 local scholars = Sea.wow.spellbook.scholars
271  
272 for key, value in scholars do
273 if value.feedback[bookType] then
274 local success, result = pcall( value.callback, bookType )
275 if not success then
276 message( result )
277 Sea.wow.spellbook.print( "SeaSpellbook: Failed calling ", value.id )
278 tremove(scholars, key)
279 end
280 end
281 end
282 end
283  
284  
285 --
286 -- VerifyScholar( scholar )
287 --
288 -- Verify's that a correct scholar table has been submitted to us
289 Sea.wow[SeaSpellbook_KEY].VerifyScholar = function( scholar )
290 if type(scholar) ~= "table" then
291 Sea.wow.spellbook.print("SeaSpellbook: ", this:GetName(), " called us with an incorrect scholar.")
292 return false
293 end
294  
295 if not scholar.id then
296 Sea.wow.spellbook.print("SeaSpellbook: ", this:GetName(), " called us with missing scholar.id.")
297 return false
298 end
299  
300 if not scholar.callback then
301 Sea.wow.spellbook.print("SeaSpellbook: ", this:GetName(), " called us with missing scholar.callback.")
302 return false
303 end
304  
305 if type(scholar.callback) ~= "function" then
306 Sea.wow.spellbook.print("SeaSpellbook: ", this:GetName(), " called us with incorrect scholar.callback.")
307 return false
308 end
309  
310 if not scholar.feedback then
311 Sea.wow.spellbook.print("SeaSpellbook: ", this:GetName(), " called us with missing scholar.feedback.")
312 return false
313 end
314  
315 if type(scholar.feedback) ~= "table" then
316 Sea.wow.spellbook.print("SeaSpellbook: ", this:GetName(), " called us with incorrect scholar.feedback.")
317 return false
318 end
319  
320 if not scholar.feedback.pet and not scholar.feedback.spell then
321 Sea.wow.spellbook.print("SeaSpellbook: ", this:GetName(), " called us with no known feedback selection.")
322 return false
323 end
324  
325 if not scholar.description then
326 Sea.wow.spellbook.print("SeaSpellbook: ", this:GetName(), " called us with missing scholar.description")
327 return false
328 end
329  
330 if type(scholar.description) ~= "string" then
331 Sea.wow.spellbook.print("SeaSpellbook: ", this:GetName(), " called us with incorrect scholar.description.")
332 return false
333 end
334  
335 return true
336 end
337  
338  
339 --
340 -- ReadSpellbook( spellTab )
341 -- No arguments and it reads all tabs
342 -- spellTab # - To only update that tab
343 --
344 -- Function to decide how much of the spellbook we should read.
345 Sea.wow[SeaSpellbook_KEY].ReadSpellbook = function( bookType, spellTab )
346 if bookType == BOOKTYPE_SPELL then
347 for i=1, GetNumSpellTabs() do
348 Sea.wow.spellbook.ReadSpellTab( bookType, i )
349 end
350 else
351 Sea.wow.spellbook.ReadSpellTab(bookType)
352 end
353  
354 Sea.wow.spellbook.CallScholars( bookType )
355 end
356  
357  
358 --
359 -- ReadSpellTab( bookType, tabIndex )
360 -- bookType = "spell" or "pet"
361 -- tabIndex = Spellbook tab #
362 --
363 -- Reads a tab in the spellbook into our table
364 Sea.wow[SeaSpellbook_KEY].ReadSpellTab = function( bookType, tabIndex, forceTooltip )
365 local startIndex = 1
366 local i = 1
367 local maxIndex, _
368  
369 -- Shortcuts for easy access to our tables
370 local spells = Sea.wow.spellbook[bookType]
371 local textures = Sea.wow.spellbook.textures[bookType]
372  
373 if bookType == BOOKTYPE_SPELL then
374 -- Get the spell index we should start with.
375 while i < tabIndex do
376 local _, _, _, numSpells = GetSpellTabInfo( i )
377 startIndex = startIndex + numSpells
378 i = i + 1
379 end
380  
381 -- Get the number of spells we should read
382 local _, _, _, numSpells = GetSpellTabInfo( tabIndex )
383  
384 -- Since we calculated up to this point already, we reuse
385 -- startIndex, but has to subtract 1.
386 maxIndex = ( startIndex - 1 ) + numSpells
387 else
388 maxIndex, _ = HasPetSpells()
389 end
390  
391 -- Do the work of reading the choosen list of spells
392 for index=startIndex, maxIndex do
393 local spellName, spellRank = GetSpellName( index, bookType )
394 local spellTexture = GetSpellTexture( index, bookType )
395  
396 -- This code removes anything that isn't numbers, so even while spellRank
397 -- isn't localized, we should still always parse it correctly.
398 local rank, _ = gsub( spellRank, "(%D+)", "", 1 )
399 rank = tonumber( rank )
400  
401 -- Unranked?
402 if not rank then
403 rank = 0
404 end
405  
406 -- Main database of spells initialization
407 if not spells[spellName] then
408 spells[spellName] = {}
409 table.setn( spells, table.getn(spells) + 1 )
410 end
411  
412 if not spells[spellName][rank] then
413 spells[spellName][rank] = {}
414 spells[spellName][rank].ID = index
415  
416 elseif spells[spellName][rank].ID ~= index then
417 spells[spellName][rank].ID = index
418 end
419  
420 spells[spellName].spellTexture = spellTexture
421  
422 -- Pet spells AutoCast status
423 if bookType == BOOKTYPE_PET then
424 local autoCast, _ = GetSpellAutocast( index, BOOKTYPE_PET )
425 if autoCast then
426 spells[spellName].autoCast = true
427 end
428 end
429  
430 -- texture database for searching quicker
431 local found = false
432 if not textures[spellTexture] then
433 textures[spellTexture] = {}
434 else
435 -- No need to add double textures for multi rank spells
436 for i=1, table.getn( textures[spellTexture] ) do
437 if textures[spellTexture][i] == spellName then
438 found = true
439 break
440 end
441 end
442 end
443 if not found then
444 tinsert( textures[spellTexture], spellName )
445 end
446  
447 -- The very slow tooltip scanning
448 Sea.wow.spellbook.GetSpellDetails( index, bookType, spells[spellName][rank] )
449 spells[spellName][rank].rank = spellRank
450  
451 if rank ~= 0 then
452 spells[spellName][0] = spells[spellName][rank]
453 end
454 end
455 end
456  
457  
458 --
459 -- GetSpellDetails( index, bookType, spellType )
460 -- index = Spell Index
461 -- bookType = "spell" or "pet"
462 -- spellTable = Where we store the data
463 --
464 -- Returns a table: {
465 -- ID - SpellID for the spell in the spellbook
466 -- castTime - positive secs of cast time
467 -- - 0 Channeled
468 -- - -1 Instant Cast
469 -- - -2 Instant
470 -- - -3 Next melee / Next Ranged
471 -- crit - x.x% crit chance
472 -- manaCost - Mana cost
473 -- energyCost - Energy cost
474 -- rageCost - Rage cost
475 -- minRange - Casting min range to target
476 -- maxRange - Casting max range to target
477 -- cooldown - cooldown between casts in seconds
478 -- These variables aren't localized
479 -- requires - What is required before the spell can be cast?
480 -- tools - Tools required to cast the spell
481 -- reagents - Reagents required to cast the spell
482 -- description - Description
483 --
484 -- Read the tooltip to get detailed information about a spell
485 Sea.wow[SeaSpellbook_KEY].GetSpellDetails = function( index, bookType, spellTable )
486 spellTable.ID = index
487  
488 -- Clear the tooltip so we don't have old data
489 SeaSpellbookTooltip:ClearLines()
490  
491 -- ClearLines() doesn't clear the Right
492 SeaSpellbookTooltipTextRight1:SetText()
493 SeaSpellbookTooltipTextRight2:SetText()
494 SeaSpellbookTooltipTextRight3:SetText()
495 SeaSpellbookTooltipTextRight4:SetText()
496 SeaSpellbookTooltipTextRight5:SetText()
497  
498 -- Set the tooltip with a spell
499 SeaSpellbookTooltip:SetSpell( index, bookType )
500  
501 local tooltipText, temp
502 -- L1 name
503 -- Ignored
504  
505 for runSide = 1, 2 do
506 if runSide == 1 then
507 tooltipSide = "Left"
508 else
509 tooltipSide = "Right"
510 end
511  
512 for runLevel = 2, 6 do
513 tooltipText = getglobal("SeaSpellbookTooltipText" .. tooltipSide .. runLevel):GetText()
514  
515 if tooltipText == nil then
516 -- Do nothing
517  
518 -- Instant
519 elseif runLevel >= 2 and runLevel <= 3 and runSide == 1 and
520 SEASPELLBOOK_INSTANT.func( tooltipText, SEASPELLBOOK_INSTANT.string ) then
521 spellTable.castTime = -2
522  
523 -- Instant cast
524 elseif runLevel == 3 and runSide == 1 and
525 SEASPELLBOOK_INSTANTCAST.func( tooltipText, SEASPELLBOOK_INSTANTCAST.string ) then
526  
527 spellTable.castTime = -1
528  
529 -- Channeled
530 elseif runLevel == 3 and runSide == 1 and
531 SEASPELLBOOK_CHANNELED.func( tooltipText, SEASPELLBOOK_CHANNELED.string ) then
532  
533 spellTable.castTime = 0
534  
535 -- Next melee
536 elseif runLevel == 3 and runSide == 1 and
537 SEASPELLBOOK_NEXTMELEE.func( tooltipText, SEASPELLBOOK_NEXTMELEE.string ) then
538  
539 spellTable.castTime = -3
540  
541 -- Attack Speed
542 elseif runLevel == 3 and runSide == 1 and
543 SEASPELLBOOK_NEXTRANGED.func( tooltipText, SEASPELLBOOK_NEXTRANGED.string ) then
544  
545 spellTable.castTime = -3
546  
547 -- #.#% chance to crit
548 elseif runLevel == 2 and runSide == 1 and
549 SEASPELLBOOK_CRITCHANCE.func( tooltipText, SEASPELLBOOK_CRITCHANCE.string ) then
550  
551 temp, _ = gsub(tooltipText, SEASPELLBOOK_CRITCHANCE.string, "%1")
552 spellTable.crit = tonumber( temp )
553  
554 -- #.#% chance to parry
555 elseif runLevel == 3 and runSide == 1 and
556 SEASPELLBOOK_PARRYCHANCE.func( tooltipText, SEASPELLBOOK_PARRYCHANCE.string ) then
557  
558 temp, _ = gsub(tooltipText, SEASPELLBOOK_PARRYCHANCE.string, "%1")
559 spellTable.parry = tonumber( temp )
560  
561 -- #.#% chance to block
562 elseif runLevel == 3 and runSide == 1 and
563 SEASPELLBOOK_BLOCKCHANCE.func( tooltipText, SEASPELLBOOK_BLOCKCHANCE.string ) then
564  
565 temp, _ = gsub(tooltipText, SEASPELLBOOK_BLOCKCHANCE.string, "%1")
566 spellTable.block = tonumber( temp )
567  
568 -- #.#% chance to dodge
569 elseif runLevel == 2 and runSide == 1 and
570 SEASPELLBOOK_DODGECHANCE.func( tooltipText, SEASPELLBOOK_DODGECHANCE.string ) then
571  
572 temp, _ = gsub(tooltipText, SEASPELLBOOK_DODGECHANCE.string, "%1")
573 spellTable.dodge = tonumber( temp )
574  
575 -- # Mana
576 elseif runLevel == 2 and runSide == 1 and
577 SEASPELLBOOK_MANA.func(tooltipText, SEASPELLBOOK_MANA.string ) then
578  
579 temp, _ = gsub(tooltipText, SEASPELLBOOK_MANA.string, "%1")
580 spellTable.manaCost = tonumber( temp )
581  
582 -- # Focus
583 elseif runLevel == 2 and runSide == 1 and
584 SEASPELLBOOK_FOCUS.func(tooltipText, SEASPELLBOOK_FOCUS.string ) then
585  
586 temp, _ = gsub(tooltipText, SEASPELLBOOK_FOCUS.string, "%1")
587 spellTable.focusCost = tonumber( temp )
588  
589 -- Uses 100% mana
590 elseif runLevel == 4 and runSide == 1 and
591 SEASPELLBOOK_MANAALL.func(tooltipText, SEASPELLBOOK_MANAALL.string ) then
592  
593 spellTable.manaCost = -1
594  
595 -- # Energy
596 elseif runLevel == 2 and runSide == 1 and
597 SEASPELLBOOK_ENERGY.func(tooltipText, SEASPELLBOOK_ENERGY.string ) then
598  
599 temp, _ = gsub(tooltipText, SEASPELLBOOK_ENERGY.string, "%1")
600 spellTable.energyCost = tonumber( temp )
601  
602 -- # Rage
603 elseif runLevel == 2 and runSide == 1 and
604 SEASPELLBOOK_RAGE.func(tooltipText, SEASPELLBOOK_RAGE.string ) then
605  
606 temp, _ = gsub(tooltipText, SEASPELLBOOK_RAGE.string, "%1")
607 spellTable.rageCost = tonumber( temp )
608  
609 -- 10 sec cast
610 elseif runLevel >= 2 and runLevel <= 3 and runSide == 1 and
611 SEASPELLBOOK_CASTTIME.func( tooltipText, SEASPELLBOOK_CASTTIME.string ) then
612  
613 temp, _ = gsub( tooltipText, SEASPELLBOOK_CASTTIME.string, "%1" )
614 spellTable.castTime = tonumber( temp )
615  
616 -- 8-25 yd range
617 elseif ( runLevel == 2 and runSide == 1 or runSide == 2 ) and
618 SEASPELLBOOK_RANGEMINMAX.func( tooltipText, SEASPELLBOOK_RANGEMINMAX.string ) then
619  
620 _, _, spellTable.minRange, spellTable.maxRange = string.find( tooltipText, SEASPELLBOOK_RANGEMINMAX.string )
621  
622 spellTable.maxRange = tonumber( spellTable.maxRange )
623 spellTable.minRange = tonumber( spellTable.minRange )
624  
625 -- 5 yd range
626 elseif ( runLevel == 2 and runSide == 1 or runSide == 2 ) and
627 SEASPELLBOOK_RANGE.func( tooltipText, SEASPELLBOOK_RANGE.string ) then
628  
629 temp, _ = gsub( tooltipText, SEASPELLBOOK_RANGE.string, "%1" )
630 spellTable.maxRange = tonumber( temp )
631  
632 -- Requires Cat Form
633 elseif runLevel >= 2 and runLevel <= 5 and runSide == 1 and
634 SEASPELLBOOK_REQUIRES.func( tooltipText, SEASPELLBOOK_REQUIRES.string ) then
635  
636 if spellTable.requires then
637 spellTable.requires = spellTable.requires .. ", " .. gsub( tooltipText, SEASPELLBOOK_REQUIRES.string, "%1" )
638 else
639 spellTable.requires = gsub( tooltipText, SEASPELLBOOK_REQUIRES.string, "%1" )
640 end
641  
642 -- Tools: |cffff2020Flint and Tinder|r
643 elseif runLevel >= 3 and runLevel <= 4 and runSide == 1 and
644 SEASPELLBOOK_TOOLS.func( tooltipText, SEASPELLBOOK_TOOLS.string ) then
645  
646 spellTable.tools = gsub( tooltipText, SEASPELLBOOK_TOOLS.string, "%1" )
647  
648 -- Reagents: |cffff2020Simple Wood|r
649 elseif runLevel >= 3 and runLevel <= 4 and runSide == 1 and
650 SEASPELLBOOK_REAGENTS.func( tooltipText, SEASPELLBOOK_REAGENTS.string ) then
651  
652 spellTable.reagents = gsub( tooltipText, SEASPELLBOOK_REAGENTS.string, "%1" )
653  
654 -- # min cooldown
655 elseif runSide == 2 and
656 SEASPELLBOOK_COOLDOWN_MIN.func( tooltipText, SEASPELLBOOK_COOLDOWN_MIN.string ) then
657  
658 _, _, spellTable.cooldown, _ = string.find( tooltipText, SEASPELLBOOK_COOLDOWN_MIN.string )
659 spellTable.cooldown = 60 * spellTable.cooldown
660  
661 -- # sec cooldown
662 elseif runSide == 2 and
663 SEASPELLBOOK_COOLDOWN_SEC.func( tooltipText, SEASPELLBOOK_COOLDOWN_SEC.string ) then
664  
665 _, _, spellTable.cooldown, _ = string.find( tooltipText, SEASPELLBOOK_COOLDOWN_SEC.string )
666 spellTable.cooldown = tonumber( spellTable.cooldown )
667  
668 -- Description
669 elseif runLevel >= 2 and runLevel <= 6 and runSide == 1 then
670 spellTable.description = tooltipText
671  
672 end
673 end
674 end
675  
676 if SeaSpellbook_debug then
677 spellTable.debug = {}
678 for i = 1, SeaSpellbookTooltip:NumLines() do
679 spellTable.debug["R"..i] = getglobal( "SeaSpellbookTooltipTextRight" .. i):GetText()
680 spellTable.debug["L"..i] = getglobal( "SeaSpellbookTooltipTextLeft" .. i):GetText()
681 end
682 end
683 end
684  
685 --
686 -- GetSpellIDByName( name )
687 -- name: local spell name.
688 --
689 Sea.wow[SeaSpellbook_KEY].GetSpellIDByName = function( name, booktype, rank )
690 if not Sea.wow.spellbook.spell[name] or
691 ( booktype and booktype ~= BOOKTYPE_SPELL and booktype ~= BOOKTYPE_PET ) or
692 rank and not tonumber( rank )
693 then
694 return null
695 end
696 if not booktype then
697 booktype = BOOKTYPE_SPELL
698 end
699 if not rank then
700 rank = 0
701 end
702  
703 return Sea.wow.spellbook[booktype][name][rank].ID
704 end
705  
706  
707 --
708 -- Optional Sea.io support
709 --
710 if Sea.IO then
711 Sea.wow[SeaSpellbook_KEY].print = Sea.IO.print
712 Sea.wow[SeaSpellbook_KEY].dprint = Sea.IO.dprint
713 else
714 local function nilFunction() end
715 Sea.wow[SeaSpellbook_KEY].print = nilFunction
716 Sea.wow[SeaSpellbook_KEY].dprint = nilFunction
717 end
718  
719  
720 --
721 -- ShortCut
722 --
723 SeaSpellbook = Sea.wow.spellbook
724  
725  
726 --
727 -- Compare two values and return true or false
728 --
729 local function SeaSpellbook_Compare(var1, var2)
730 if var1 == var2 then
731 return true
732 else
733 return false
734 end
735 end
736  
737 --
738 -- Find pattern var2 in var1
739 --
740 local function SeaSpellbook_FindPattern(var1, var2)
741 if string.find(var1, var2) then
742 return true
743 else
744 return false
745 end
746 end
747  
748 --
749 -- Everything here is localized by using GlobalStrings.lua
750 --
751 SEASPELLBOOK_INSTANT = {
752 string = SPELL_CAST_TIME_INSTANT_NO_MANA,
753 func = SeaSpellbook_Compare,
754 }
755 SEASPELLBOOK_INSTANTCAST = {
756 string = SPELL_CAST_TIME_INSTANT,
757 func = SeaSpellbook_Compare,
758 }
759 SEASPELLBOOK_NEXTMELEE = {
760 string = SPELL_ON_NEXT_SWING,
761 func = SeaSpellbook_Compare,
762 }
763 SEASPELLBOOK_NEXTRANGED = {
764 string = SPELL_ON_NEXT_RANGED,
765 func = SeaSpellbook_Compare,
766 }
767 SEASPELLBOOK_CRITCHANCE = {
768 string = gsub(CHANCE_TO_CRIT, "%%%.2f%%%%", "(%%d+.%%d+)%%%%"),
769 func = SeaSpellbook_FindPattern,
770 }
771 SEASPELLBOOK_DODGECHANCE = {
772 string = gsub(CHANCE_TO_DODGE, "%%%.2f%%%%", "(%%d+.%%d+)%%%%"),
773 func = SeaSpellbook_FindPattern,
774 }
775 SEASPELLBOOK_PARRYCHANCE = {
776 string = gsub(CHANCE_TO_PARRY, "%%%.2f%%%%", "(%%d+.%%d+)%%%%"),
777 func = SeaSpellbook_FindPattern,
778 }
779 SEASPELLBOOK_BLOCKCHANCE = {
780 string = gsub(CHANCE_TO_BLOCK, "%%%.2f%%%%", "(%%d+.%%d+)%%%%"),
781 func = SeaSpellbook_FindPattern,
782 }
783 SEASPELLBOOK_MANA = {
784 string = gsub(MANA_COST, "%%d", "(%%d)"),
785 func = SeaSpellbook_FindPattern,
786 }
787 SEASPELLBOOK_FOCUS = {
788 string = gsub(FOCUS_COST, "%%d", "(%%d)"),
789 func = SeaSpellbook_FindPattern,
790 }
791 SEASPELLBOOK_MANAALL = {
792 string = SPELL_USE_ALL_MANA,
793 func = SeaSpellbook_Compare,
794 }
795 SEASPELLBOOK_ENERGY = {
796 string = gsub(ENERGY_COST, "%%d", "(%%d)"),
797 func = SeaSpellbook_FindPattern,
798 }
799 SEASPELLBOOK_RAGE = {
800 string = gsub(RAGE_COST, "%%d", "(%%d)"),
801 func = SeaSpellbook_FindPattern,
802 }
803 SEASPELLBOOK_CASTTIME = {
804 string = gsub(SPELL_CAST_TIME_SEC, "%%%.3g", "(%%d%%%.%?%%d%*)"),
805 func = SeaSpellbook_FindPattern,
806 }
807 SEASPELLBOOK_RANGE = {
808 string = gsub(SPELL_RANGE, "%%s", "(%%d)"),
809 func = SeaSpellbook_FindPattern,
810 }
811 SEASPELLBOOK_REQUIRES = {
812 string = "^" .. gsub(SPELL_EQUIPPED_ITEM, "%%s", "(.+)"),
813 func = SeaSpellbook_FindPattern,
814 }
815 SEASPELLBOOK_TOOLS = {
816 string = SPELL_TOTEMS .. "(.+)",
817 func = SeaSpellbook_FindPattern,
818 }
819 SEASPELLBOOK_REAGENTS = {
820 string = SPELL_REAGENTS .. "(.+)",
821 func = SeaSpellbook_FindPattern,
822 }
823 SEASPELLBOOK_RANGEMINMAX = {
824 string = gsub(SPELL_RANGE, "%%s", "(%%d+)%%-(%%d+)"),
825 func = SeaSpellbook_FindPattern,
826 }
827 SEASPELLBOOK_COOLDOWN_MIN = {
828 string = gsub(SPELL_RECAST_TIME_MIN, "%%.3g", "(%%d*.*%%d)"),
829 func = SeaSpellbook_FindPattern,
830 }
831 SEASPELLBOOK_COOLDOWN_SEC = {
832 string = gsub(SPELL_RECAST_TIME_SEC, "%%.3g", "(%%d*.*%%d)"),
833 func = SeaSpellbook_FindPattern,
834 }
835 SEASPELLBOOK_CHANNELED = {
836 string = SPELL_CAST_CHANNELED,
837 func = SeaSpellbook_Compare,
838 }