diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6f6de96 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true, + "[lua]": { + "editor.defaultFormatter": "Koihik.vscode-lua-format" + } +} diff --git a/COE_TotemData.lua b/COE_TotemData.lua index 51bbf83..9b55c11 100644 --- a/COE_TotemData.lua +++ b/COE_TotemData.lua @@ -2,30 +2,26 @@ CALL OF ELEMENTS The All-In-One Shaman Addon - - by Wyverex (2006) - - - Totem Module Data - -]] ---[[ ---------------------------------------------------------------- + by Wyverex (2006) + + + Totem Module Data + +]] --[[ ---------------------------------------------------------------- COE.TotemData contains a list of totem classes that are returned by COE:CreateTotem For every available totem the player has, one object is added to this list --------------------------------------------------------------------]] -COE["TotemData"] = {}; +-------------------------------------------------------------------]] COE["TotemData"] = + {}; COE["TotemCount"] = 0; - --[[ ---------------------------------------------------------------- COE.MaxTotems stores the maximum number of totems per element This is taken right from the current game content -------------------------------------------------------------------]] -COE["MaxTotems"] = { Earth = 5, Fire = 5, Water = 7, Air = 7 }; - +COE["MaxTotems"] = {Earth = 5, Fire = 5, Water = 7, Air = 7}; --[[ ---------------------------------------------------------------- COE.TotemsAvailable contains the number of totems available @@ -37,7 +33,6 @@ COE.TotemsAvailable["Fire"] = 0; COE.TotemsAvailable["Water"] = 0; COE.TotemsAvailable["Air"] = 0; - --[[ ---------------------------------------------------------------- COE.ActiveTotems contains a pointer to the active totem of each element @@ -50,778 +45,815 @@ COE.TotemsAvailable["Air"] = 0; to prevent actions that trigger SPELLCAST_STOP and are not hooked from activating the timer accidentally -------------------------------------------------------------------]] -COE["ActiveTotems"] = { Earth = nil, Fire = nil, Water = nil, Air = nil }; -COE["TotemPending"] = { Totem = nil, UseRank = 0, Timeout = 0.75 }; - +COE["ActiveTotems"] = {Earth = nil, Fire = nil, Water = nil, Air = nil}; +COE["TotemPending"] = {Totem = nil, UseRank = 0, Timeout = 0.75}; --[[ ---------------------------------------------------------------- COE.CleansingTotems stores pointers to the buttons and totems that are able to cleanse poisons, diseases and sleep, charm or fear effects -------------------------------------------------------------------]] -COE["CleansingTotems"] = { -Poison = { Totem = nil, Button = nil, Warn = false }, -Disease = { Totem = nil, Button = nil, Warn = false }, -Tremor = { Totem = nil, Button = nil, Warn = false } }; - +COE["CleansingTotems"] = { + Poison = {Totem = nil, Button = nil, Warn = false}, + Disease = {Totem = nil, Button = nil, Warn = false}, + Tremor = {Totem = nil, Button = nil, Warn = false} +}; --[[ ---------------------------------------------------------------- COE.TotemSets contains the totem pointers for each set and element -------------------------------------------------------------------]] COE["TotemSetCount"] = 0; -COE["TotemSets"] = { } - +COE["TotemSets"] = {} --[[ ---------------------------------------------------------------- COE.SetCycle stores which totem of the active set have already been thrown -------------------------------------------------------------------]] -COE["SetCycle"] = { Earth = false, Fire = false, Water = false, Air = false }; - +COE["SetCycle"] = {Earth = false, Fire = false, Water = false, Air = false}; --[[ ---------------------------------------------------------------- COE.NoTotem is a placeholder for an empty anchor button -------------------------------------------------------------------]] -COE["NoTotem"] = { SpellName = "", Element = "", Texture = "Interface\\Icons\\INV_Misc_Idol_03.blp", - ToolPresent = false, Ranks = { SpellID = 0, Mana = 0, Duration = 0, Health = 0, Cooldown = 0 }, - MaxRank = 1, isActive = false, CurDuration = 0, CurHealth = 0, CurCooldown = 0 }; - +COE["NoTotem"] = { + SpellName = "", + Element = "", + Texture = "Interface\\Icons\\INV_Misc_Idol_03.blp", + ToolPresent = false, + Ranks = {SpellID = 0, Mana = 0, Duration = 0, Health = 0, Cooldown = 0}, + MaxRank = 1, + isActive = false, + CurDuration = 0, + CurHealth = 0, + CurCooldown = 0 +}; --[[ ---------------------------------------------------------------- METHOD: COE:CreateTotem - + PURPOSE: Returns the totem class for a new totem -------------------------------------------------------------------]] function COE:CreateTotem() - return { SpellName = "", Element = "", Texture = "", - ToolPresent = false, Ranks = {}, MaxRank = 0, isActive = false, - CurDuration = 0, CurHealth = 0, CurCooldown = 0, - isTrinket = false, TrinketSlot = nil }; + return { + SpellName = "", + Element = "", + Texture = "", + ToolPresent = false, + Ranks = {}, + MaxRank = 0, + isActive = false, + CurDuration = 0, + CurHealth = 0, + CurCooldown = 0, + isTrinket = false, + TrinketSlot = nil + }; end - --[[ ---------------------------------------------------------------- METHOD: COE:CreateTotemRank - + PURPOSE: Returns the class for a new totem rank -------------------------------------------------------------------]] function COE:CreateTotemRank() - return { SpellID = 0, Mana = 0, Duration = 0, Health = 0, Cooldown = 0 }; + return {SpellID = 0, Mana = 0, Duration = 0, Health = 0, Cooldown = 0}; end - --[[ ---------------------------------------------------------------- METHOD: COE:ElementFromTool - + PURPOSE: Returns the element corresponding to a totem tool. This is needed for the french version to work. In the english and german versions it just returns the input -------------------------------------------------------------------]] -function COE:ElementFromTool( element ) +function COE:ElementFromTool(element) - if element == COESTR_TOTEMTOOLS_EARTH then - return COESTR_ELEMENT_EARTH; - elseif element == COESTR_TOTEMTOOLS_FIRE then - return COESTR_ELEMENT_FIRE; - elseif element == COESTR_TOTEMTOOLS_WATER then - return COESTR_ELEMENT_WATER; - elseif element == COESTR_TOTEMTOOLS_AIR then - return COESTR_ELEMENT_AIR; - end + if element == COESTR_TOTEMTOOLS_EARTH then + return COESTR_ELEMENT_EARTH; + elseif element == COESTR_TOTEMTOOLS_FIRE then + return COESTR_ELEMENT_FIRE; + elseif element == COESTR_TOTEMTOOLS_WATER then + return COESTR_ELEMENT_WATER; + elseif element == COESTR_TOTEMTOOLS_AIR then + return COESTR_ELEMENT_AIR; + end end - --[[ ---------------------------------------------------------------- METHOD: COE:LocalizedElement - + PURPOSE: Translates a localized element name into english -------------------------------------------------------------------]] -function COE:LocalizedElement( element ) +function COE:LocalizedElement(element) + + if (element == COESTR_ELEMENT_EARTH) then + return "Earth"; + elseif (element == COESTR_ELEMENT_FIRE) then + return "Fire"; + elseif (element == COESTR_ELEMENT_WATER) then + return "Water"; + elseif (element == COESTR_ELEMENT_AIR) then + return "Air"; + end - if( element == COESTR_ELEMENT_EARTH ) then - return "Earth"; - elseif( element == COESTR_ELEMENT_FIRE ) then - return "Fire"; - elseif( element == COESTR_ELEMENT_WATER ) then - return "Water"; - elseif( element == COESTR_ELEMENT_AIR ) then - return "Air"; - end - end - --[[ ---------------------------------------------------------------- METHOD: COE:ScanTotems - + PURPOSE: Scans the spellbook for available totems and populates the COE.TotemData list -------------------------------------------------------------------]] function COE:ScanTotems() - COE:DebugMessage( "Scanning Totems..." ); - - -- delete existing totem objects - -- ------------------------------ - COE.TotemData = {}; - COE.TotemCount = 0; - COE.TotemsAvailable.Earth = 0; - COE.TotemsAvailable.Fire = 0; - COE.TotemsAvailable.Water = 0; - COE.TotemsAvailable.Air = 0; + COE:DebugMessage("Scanning Totems..."); - -- iterate over all spells in the spellbook - -- ----------------------------------------- - local i, k = 1; - while true do - - local SpellName, SpellRank = GetSpellName( i, BOOKTYPE_SPELL ); - if not SpellName or SpellName == "Totemic Recall" then - do break end; - end - - -- is this a totem? - -- ----------------- - if( string.find( SpellName, COESTR_SCANTOTEMS ) ~= nil ) then - - local newtotem = true; - local totem = nil; - - -- get the rank value - -- ------------------- - local _,_,rank = string.find( SpellRank, COESTR_TOTEMRANK ); - if( not rank ) then - rank = 1; - else - rank = tonumber( rank ); - end + -- delete existing totem objects + -- ------------------------------ + COE.TotemData = {}; + COE.TotemCount = 0; + COE.TotemsAvailable.Earth = 0; + COE.TotemsAvailable.Fire = 0; + COE.TotemsAvailable.Water = 0; + COE.TotemsAvailable.Air = 0; - -- ======================================================================= - -- check if totem already exists with another rank in the list - -- ======================================================================= - for k = 1, COE.TotemCount do - if( SpellName == COE.TotemData[k].SpellName ) then - -- use existing totem object - -- -------------------------- - totem = COE.TotemData[k]; - newtotem = false; - break; - end - end + -- iterate over all spells in the spellbook + -- ----------------------------------------- + local i = 1; + while true do - COETotemTT:SetSpell( i, BOOKTYPE_SPELL ); + local SpellName, SpellRank = GetSpellName(i, BOOKTYPE_SPELL); + if not SpellName then do break end end - -- ======================================================================= - -- create new totem object if not found - -- ======================================================================= - if( not totem ) then - totem = COE:CreateTotem(); - - -- set totem spell name - -- --------------------- - totem.SpellName = SpellName; - - -- get totem school from tooltip - -- ------------------------------ - local text = COETotemTTTextLeft4; - if( text and text:GetText() ) then - - local _,_, element = string.find( text:GetText(), COESTR_TOTEMTOOLS ); - if( element ) then - - -- if element starts with a |, the player does - -- not possess the needed totem for this spell - -- extract the color code before using the element - -- ------------------------------------------------ - if( string.sub( element, 1, 1 ) == "|" ) then - element = string.sub( element, 11 ); - end - - -- get element from tool - -- ---------------------- - element = COE:ElementFromTool( element ); - - -- translate element to english - -- ----------------------------- - element = COE:LocalizedElement( element ); - -- valid element? - -- --------------- - if( COE.TotemsAvailable[element] ~= nil ) then - totem.Element = element; - COE.TotemsAvailable[element] = COE.TotemsAvailable[element] + 1; - else - COE:Message( COESTR_INVALIDELEMENT .. SpellName ); - end - end - end - - -- get totem texture - -- ------------------ - totem.Texture = GetSpellTexture( i, BOOKTYPE_SPELL ); - - -- get tool presence - -- ------------------ - totem.ToolPresent = COE:IsToolPresent( i ); - end + -- is this a totem? + -- ----------------- + if (SpellName ~= "Totemic Recall" and + string.find(SpellName, COESTR_SCANTOTEMS) ~= nil) then - -- ======================================================================= - -- create new totem rank - -- ======================================================================= - local totemrank = COE:CreateTotemRank(); - - -- set totem spell id - -- ------------------- - totemrank.SpellID = i; - - -- get totem mana cost from tooltip - -- --------------------------------- - text = COETotemTTTextLeft2; - if( text and text:GetText() ) then - - local _,_, mana = string.find( text:GetText(), COESTR_TOTEMMANA ); - if( mana ) then - totemrank.Mana = tonumber( mana ); - end - end - - -- get totem duration and health - -- ------------------------------ - totemrank.Duration, totemrank.Health, totemrank.Cooldown = COE:GetTotemDurationAndHealth( i ); - - -- store rank in totem - -- -------------------- - totem.Ranks[rank] = totemrank; - if( rank > totem.MaxRank ) then - totem.MaxRank = rank; - end - - -- is this a new totem? - -- --------------------- - if( newtotem ) then - -- store totem - -- ------------ - COE.TotemCount = COE.TotemCount + 1; - COE.TotemData[COE.TotemCount] = totem; + local newtotem = true; + local totem = nil; - - -- check if it's a cleansing totem - -- -------------------------------- - if( SpellName == COESTR_TOTEMPOISON ) then - COE.CleansingTotems.Poison.Totem = totem; - elseif( SpellName == COESTR_TOTEMDISEASE ) then - COE.CleansingTotems.Disease.Totem = totem; - elseif( SpellName == COESTR_TOTEMTREMOR ) then - COE.CleansingTotems.Tremor.Totem = totem; - end - - COE:DebugMessage( "Found totem: " .. SpellName ); - end - - -- ======================================================================= - -- check visibility options - -- ======================================================================= + -- get the rank value + -- ------------------- + local _, _, rank = string.find(SpellRank, COESTR_TOTEMRANK); + if (not rank) then + rank = 1; + else + rank = tonumber(rank); + end - if( COE_DisplayedTotems[SpellName] == nil ) then - -- perhaps a new totem. set it to default visible - -- and reorder it when the element count is known - -- ----------------------------------------------- - COE_DisplayedTotems[SpellName] = { Order = 0, Element = totem.Element, Visible = true }; - else - -- update old saved variables versions by adding the element - -- ---------------------------------------------------------- - COE_DisplayedTotems[SpellName]["Element"] = totem.Element; - end - end - - i = i + 1; - end + -- ======================================================================= + -- check if totem already exists with another rank in the list + -- ======================================================================= + for k = 1, COE.TotemCount do + if (SpellName == COE.TotemData[k].SpellName) then + -- use existing totem object + -- -------------------------- + totem = COE.TotemData[k]; + newtotem = false; + break + end + end - -- ==================================== - -- Trinket support - -- ==================================== - - -- create the trinket totem even if the player doesn't have it. - -- this makes handling it much simpler and the player can choose - -- to make it invisible anyway - -- the player needs to have at least one water totem though - -- -------------------------------------------------------------- - if( COE.TotemsAvailable.Water > 0 ) then - local trinket = COE:CreateTotem(); - trinket.SpellName = "Trinket"; - trinket.Element = "Water"; - trinket.Texture = "Interface\\Icons\\INV_Wand_01"; - trinket.isTrinket = true; - trinket.ToolPresent, trinket.TrinketSlot = COE:IsTrinketPresent(); - trinket.Ranks[0] = COE:CreateTotemRank(); - trinket.Ranks[0].Duration = 24; - trinket.Ranks[0].Health = 5; - trinket.Ranks[0].Cooldown = 180; - - -- store totem - -- ------------ - COE.TotemsAvailable.Water = COE.TotemsAvailable.Water + 1; - COE.TotemCount = COE.TotemCount + 1; - COE.TotemData[COE.TotemCount] = trinket; + COETotemTT:SetSpell(i, BOOKTYPE_SPELL); - if( COE_DisplayedTotems[trinket.SpellName] == nil ) then - -- perhaps a new totem. set it to default visible - -- and reorder it when the element count is known - -- ----------------------------------------------- - COE_DisplayedTotems[trinket.SpellName] = { Order = 0, Visible = true }; - end - end + -- ======================================================================= + -- create new totem object if not found + -- ======================================================================= + if (not totem) then + totem = COE:CreateTotem(); + + -- set totem spell name + -- --------------------- + totem.SpellName = SpellName; + + -- get totem school from tooltip + -- ------------------------------ + local text = COETotemTTTextLeft4; + if (text and text:GetText()) then + + local _, _, element = + string.find(text:GetText(), COESTR_TOTEMTOOLS); + if (element) then + + -- if element starts with a |, the player does + -- not possess the needed totem for this spell + -- extract the color code before using the element + -- ------------------------------------------------ + if (string.sub(element, 1, 1) == "|") then + element = string.sub(element, 11); + end + + -- get element from tool + -- ---------------------- + element = COE:ElementFromTool(element); + + -- translate element to english + -- ----------------------------- + element = COE:LocalizedElement(element); + -- valid element? + -- --------------- + if (COE.TotemsAvailable[element] ~= nil) then + totem.Element = element; + COE.TotemsAvailable[element] = + COE.TotemsAvailable[element] + 1; + else + COE:Message(COESTR_INVALIDELEMENT .. SpellName); + end + end + end + + -- get totem texture + -- ------------------ + totem.Texture = GetSpellTexture(i, BOOKTYPE_SPELL); + + -- get tool presence + -- ------------------ + totem.ToolPresent = COE:IsToolPresent(i); + end + + -- ======================================================================= + -- create new totem rank + -- ======================================================================= + local totemrank = COE:CreateTotemRank(); + + -- set totem spell id + -- ------------------- + totemrank.SpellID = i; + + -- get totem mana cost from tooltip + -- --------------------------------- + text = COETotemTTTextLeft2; + if (text and text:GetText()) then + + local _, _, mana = string.find(text:GetText(), COESTR_TOTEMMANA); + if (mana) then totemrank.Mana = tonumber(mana); end + end + + -- get totem duration and health + -- ------------------------------ + totemrank.Duration, totemrank.Health, totemrank.Cooldown = + COE:GetTotemDurationAndHealth(i); + + -- store rank in totem + -- -------------------- + totem.Ranks[rank] = totemrank; + if (rank > totem.MaxRank) then totem.MaxRank = rank; end + + -- is this a new totem? + -- --------------------- + if (newtotem) then + -- store totem + -- ------------ + COE.TotemCount = COE.TotemCount + 1; + COE.TotemData[COE.TotemCount] = totem; + + -- check if it's a cleansing totem + -- -------------------------------- + if (SpellName == COESTR_TOTEMPOISON) then + COE.CleansingTotems.Poison.Totem = totem; + elseif (SpellName == COESTR_TOTEMDISEASE) then + COE.CleansingTotems.Disease.Totem = totem; + elseif (SpellName == COESTR_TOTEMTREMOR) then + COE.CleansingTotems.Tremor.Totem = totem; + end + + COE:DebugMessage("Found totem: " .. SpellName); + end + + -- ======================================================================= + -- check visibility options + -- ======================================================================= + + if (COE_DisplayedTotems[SpellName] == nil) then + -- perhaps a new totem. set it to default visible + -- and reorder it when the element count is known + -- ----------------------------------------------- + COE_DisplayedTotems[SpellName] = { + Order = 0, + Element = totem.Element, + Visible = true + }; + else + -- update old saved variables versions by adding the element + -- ---------------------------------------------------------- + COE_DisplayedTotems[SpellName]["Element"] = totem.Element; + end + end + + i = i + 1; + end + + -- ==================================== + -- Trinket support + -- ==================================== + + -- create the trinket totem even if the player doesn't have it. + -- this makes handling it much simpler and the player can choose + -- to make it invisible anyway + -- the player needs to have at least one water totem though + -- -------------------------------------------------------------- + if (COE.TotemsAvailable.Water > 0) then + local trinket = COE:CreateTotem(); + trinket.SpellName = "Trinket"; + trinket.Element = "Water"; + trinket.Texture = "Interface\\Icons\\INV_Wand_01"; + trinket.isTrinket = true; + trinket.ToolPresent, trinket.TrinketSlot = COE:IsTrinketPresent(); + trinket.Ranks[0] = COE:CreateTotemRank(); + trinket.Ranks[0].Duration = 24; + trinket.Ranks[0].Health = 5; + trinket.Ranks[0].Cooldown = 180; + + -- store totem + -- ------------ + COE.TotemsAvailable.Water = COE.TotemsAvailable.Water + 1; + COE.TotemCount = COE.TotemCount + 1; + COE.TotemData[COE.TotemCount] = trinket; + + if (COE_DisplayedTotems[trinket.SpellName] == nil) then + -- perhaps a new totem. set it to default visible + -- and reorder it when the element count is known + -- ----------------------------------------------- + COE_DisplayedTotems[trinket.SpellName] = {Order = 0, Visible = true}; + end + end + + -- =================================== + -- Finish + -- =================================== + + COE:DebugMessage( + "Found " .. COE.TotemCount .. " totems in spellbook" .. "(" .. + COE.TotemsAvailable.Earth .. " Earth, " .. COE.TotemsAvailable.Fire .. + " Fire, " .. COE.TotemsAvailable.Water .. " Water, " .. + COE.TotemsAvailable.Air .. " Air)"); + + -- reorder new totems + -- ------------------- + COE:ReorderNewTotems(); - -- =================================== - -- Finish - -- =================================== - - COE:DebugMessage( "Found " .. COE.TotemCount .. " totems in spellbook" .. - "(" .. COE.TotemsAvailable.Earth .. " Earth, " .. - COE.TotemsAvailable.Fire .. " Fire, " .. COE.TotemsAvailable.Water .. " Water, " .. - COE.TotemsAvailable.Air .. " Air)" ); - - -- reorder new totems - -- ------------------- - COE:ReorderNewTotems(); - end - --[[ ---------------------------------------------------------------- METHOD: COE:GetTotemDurationAndHealth - + PURPOSE: Extracts the duration of the totem out of the tooltip When there is more than one time specification present, the one with the longer duration is used since this is the totem duration then Also the health and the cooldown of the totem are returned -------------------------------------------------------------------]] -function COE:GetTotemDurationAndHealth( spellid ) +function COE:GetTotemDurationAndHealth(spellid) - COETotemTTTextRight3:SetText( nil ); - COETotemTT:SetSpell( spellid, BOOKTYPE_SPELL ); - text = COETotemTTTextLeft5:GetText(); - - if( not text ) then - COE:DebugMessage( "nil text with id: " .. spellid ); - return 0, 0; - end - - local duration = 0; - local health = 0; - local cooldown = 0; + COETotemTTTextRight3:SetText(nil); + COETotemTT:SetSpell(spellid, BOOKTYPE_SPELL); + text = COETotemTTTextLeft5:GetText(); - -- =============================================================== - -- Duration - -- =============================================================== + if (not text) then + COE:DebugMessage("nil text with id: " .. spellid); + return 0, 0; + end - -- first search for a minute specification - -- if we find one it is surely the totem duration - -- ----------------------------------------------- - local _,_,minutetext = string.find( text, COESTR_MINUTEDURATION ); - if( minutetext ) then - -- calculate the duration in seconds - -- ---------------------------------- - local min = tonumber( string.sub( minutetext, 1, 1 ) ); - local sec = tonumber( string.sub( minutetext, 3, 4 ) ) / 100 * 60; - - duration = min * 60 + sec; - else - _,_,minutetext = string.find( text, COESTR_MINUTEDURATION_INT ); - if( minutetext ) then - duration = tonumber( minutetext ) * 60; - else - -- now test for a duration in seconds - -- ----------------------------------- - local _,b,sectext1 = string.find( text, COESTR_SECDURATION ); - if( sectext1 ) then - - -- look if there are two second specifications - -- if so, take the greate one - -- -------------------------------------------- - local _,_,sectext2 = string.find( string.sub( text, b ), COESTR_SECDURATION ); - - if( sectext2 ) then - duration = math.max( tonumber( sectext1 ), tonumber( sectext2 ) ); - else - duration = tonumber( sectext1 ); - end - end - end - end - - -- =============================================================== - -- Health - -- =============================================================== + local duration = 0; + local health = 0; + local cooldown = 0; - for num, regex in COESTR_TOTEMHEALTH do - local match = { string.gfind( text, regex )() }; - if ( table.getn(match) >= 1 ) then + -- =============================================================== + -- Duration + -- =============================================================== - health = tonumber( match[1] ); - break; - end - end - - -- =============================================================== - -- Cooldown - -- =============================================================== + -- first search for a minute specification + -- if we find one it is surely the totem duration + -- ----------------------------------------------- + local _, _, minutetext = string.find(text, COESTR_MINUTEDURATION); + if (minutetext) then + -- calculate the duration in seconds + -- ---------------------------------- + local min = tonumber(string.sub(minutetext, 1, 1)); + local sec = tonumber(string.sub(minutetext, 3, 4)) / 100 * 60; - text = COETotemTTTextRight3:GetText(); - - if( not text ) then - cooldown = 0; - else - _,_,cooldown = string.find( text, COESTR_SECDURATION ); - if( cooldown ) then - cooldown = tonumber( cooldown ); - else - _,_,cooldown = string.find( text, COESTR_MINUTEDURATION_INT ); - if( cooldown ) then - cooldown = tonumber( cooldown ) * 60; - else - cooldown = 0; - end - end - end + duration = min * 60 + sec; + else + _, _, minutetext = string.find(text, COESTR_MINUTEDURATION_INT); + if (minutetext) then + duration = tonumber(minutetext) * 60; + else + -- now test for a duration in seconds + -- ----------------------------------- + local _, b, sectext1 = string.find(text, COESTR_SECDURATION); + if (sectext1) then - return duration, health, cooldown; + -- look if there are two second specifications + -- if so, take the greate one + -- -------------------------------------------- + local _, _, sectext2 = string.find(string.sub(text, b), + COESTR_SECDURATION); + + if (sectext2) then + duration = math.max(tonumber(sectext1), tonumber(sectext2)); + else + duration = tonumber(sectext1); + end + end + end + end + + -- =============================================================== + -- Health + -- =============================================================== + + for num, regex in COESTR_TOTEMHEALTH do + local match = {string.gfind(text, regex)()}; + if (table.getn(match) >= 1) then + + health = tonumber(match[1]); + break + end + end + + -- =============================================================== + -- Cooldown + -- =============================================================== + + text = COETotemTTTextRight3:GetText(); + + if (not text) then + cooldown = 0; + else + _, _, cooldown = string.find(text, COESTR_SECDURATION); + if (cooldown) then + cooldown = tonumber(cooldown); + else + _, _, cooldown = string.find(text, COESTR_MINUTEDURATION_INT); + if (cooldown) then + cooldown = tonumber(cooldown) * 60; + else + cooldown = 0; + end + end + end + + return duration, health, cooldown; end - --[[ ---------------------------------------------------------------- METHOD: COE:IsToolPresent - + PURPOSE: Checks if the player has the totem of the specified element in his inventory - + This is done by testing the color of the "Tools:" section in the totem tooltip -------------------------------------------------------------------]] -function COE:IsToolPresent( spellid ) +function COE:IsToolPresent(spellid) - -- get totem tooltip - -- ------------------ - COETotemTT:SetSpell( spellid, BOOKTYPE_SPELL ); + -- get totem tooltip + -- ------------------ + COETotemTT:SetSpell(spellid, BOOKTYPE_SPELL); - -- test for presence of the totem tool - -- ------------------------------------ - local text = COETotemTTTextLeft4; - if( text and text:GetText() ) then - - local _,_, element = string.find( text:GetText(), COESTR_TOTEMTOOLS ); - if( element ) then - - -- if element doesn't start with a |, the player - -- possesses the needed totem for this spell - -- ------------------------------------------------ - if( string.sub( element, 1, 1 ) ~= "|" ) then - return true; - end - end - end + -- test for presence of the totem tool + -- ------------------------------------ + local text = COETotemTTTextLeft4; + if (text and text:GetText()) then - return false; + local _, _, element = string.find(text:GetText(), COESTR_TOTEMTOOLS); + if (element) then + + -- if element doesn't start with a |, the player + -- possesses the needed totem for this spell + -- ------------------------------------------------ + if (string.sub(element, 1, 1) ~= "|") then return true; end + end + end + + return false; end - --[[ ---------------------------------------------------------------- METHOD: COE:IsTrinketPresent - - PURPOSE: Checks if the player has the enamored water spirit + + PURPOSE: Checks if the player has the enamored water spirit trinket equipped and returns the trinket slot - - RETURNS: equipped, slot + + RETURNS: equipped, slot -------------------------------------------------------------------]] function COE:IsTrinketPresent() - for i = 0, 1 do - local slot = GetInventorySlotInfo( "Trinket" .. i .. "Slot" ); - local item = GetInventoryItemLink( "player", slot ); + for i = 0, 1 do + local slot = GetInventorySlotInfo("Trinket" .. i .. "Slot"); + local item = GetInventoryItemLink("player", slot); - if( item ) then - local itemname = string.find( item, COESTR_TRINKET ); - if( itemname ) then - -- trinket is equipped - -- -------------------- - return true, slot; - end - end - end - - return false, nil; + if (item) then + local itemname = string.find(item, COESTR_TRINKET); + if (itemname) then + -- trinket is equipped + -- -------------------- + return true, slot; + end + end + end + + return false, nil; end - --[[ ---------------------------------------------------------------- METHOD: COE:ReorderNewTotems - + PURPOSE: Assigns each COE_DisplayedTotems entry with a zero order a valid order depending on the number of available totems in this element -------------------------------------------------------------------]] function COE:ReorderNewTotems() + COE:DebugMessage("Executing ReorderNewTotems"); - local nextslot = { Earth = COE.TotemsAvailable.Earth, Fire = COE.TotemsAvailable.Fire, - Water = COE.TotemsAvailable.Water, Air = COE.TotemsAvailable.Air }; - - local used = { Earth = {}, Fire = {}, Water = {}, Air = {} }; - local bError = false; + local nextslot = { + Earth = COE.TotemsAvailable.Earth, + Fire = COE.TotemsAvailable.Fire, + Water = COE.TotemsAvailable.Water, + Air = COE.TotemsAvailable.Air + }; - local k; - for k = 1, COE.TotemCount do - - local totem = COE.TotemData[k]; - if( COE_DisplayedTotems[totem.SpellName] ~= nil ) then - if( COE_DisplayedTotems[totem.SpellName].Order == 0 ) then + local used = {Earth = {}, Fire = {}, Water = {}, Air = {}}; + local bError = false; - -- this totem has just been added - -- assign the currently free slot - -- ------------------------------- - COE_DisplayedTotems[totem.SpellName].Order = nextslot[totem.Element]; - nextslot[totem.Element] = nextslot[totem.Element] - 1; - end + COE:DebugMessage("ReorderNewTotems COE.TotemCount: " .. COE.TotemCount); - -- register that this slot of the element is now in use - -- mark as error if already in use - -- ----------------------------------------------------- - if( used[totem.Element][COE_DisplayedTotems[totem.SpellName].Order] == nil ) then - used[totem.Element][COE_DisplayedTotems[totem.SpellName].Order] = true; - else - bError = true; - end - end - end - - -- are there multiple entries for one slot? - -- ----------------------------------------- - if( bError ) then - -- there is something wrong with the saved variables - -- reset all ordering and reassign it - -- -------------------------------------------------- - for k = 1, COE.TotemCount do + for k = 1, COE.TotemCount do - local totem = COE.TotemData[k]; - if( COE_DisplayedTotems[totem.SpellName] ~= nil ) then - COE_DisplayedTotems[totem.SpellName].Order = 0; - end - end + local totem = COE.TotemData[k]; + COE:DebugMessage( + "ReorderNewTotems processing totem: " .. totem.Element .. " " .. + totem.SpellName); - COE:ReorderNewTotems(); - - end + if (COE_DisplayedTotems[totem.SpellName] ~= nil) then + if (COE_DisplayedTotems[totem.SpellName].Order == 0) then + + -- this totem has just been added + -- assign the currently free slot + -- ------------------------------- + if (not nextslot[totem.Element]) then + COE:DebugMessage( + "ReorderNewTotems nextslot[totem.Element] is nil"); + end + + COE_DisplayedTotems[totem.SpellName].Order = + nextslot[totem.Element]; + nextslot[totem.Element] = nextslot[totem.Element] - 1; + end + + -- register that this slot of the element is now in use + -- mark as error if already in use + -- ----------------------------------------------------- + if (used[totem.Element][COE_DisplayedTotems[totem.SpellName].Order] == + nil) then + used[totem.Element][COE_DisplayedTotems[totem.SpellName].Order] = + true; + else + bError = true; + end + end + end + + -- are there multiple entries for one slot? + -- ----------------------------------------- + if (bError) then + -- there is something wrong with the saved variables + -- reset all ordering and reassign it + -- -------------------------------------------------- + for k = 1, COE.TotemCount do + + local totem = COE.TotemData[k]; + if (COE_DisplayedTotems[totem.SpellName] ~= nil) then + COE_DisplayedTotems[totem.SpellName].Order = 0; + end + end + + COE:ReorderNewTotems(); + + end end - --[[ ---------------------------------------------------------------- METHOD: COE:InitTotemSets - + PURPOSE: Fills the COE.TotemSets list with the totem objects corresponding to the spell names saved in COEOPT_TOTEMSETS -------------------------------------------------------------------]] function COE:InitTotemSets() - local indices = { "Earth", "Fire", "Water", "Air" }; + local indices = {"Earth", "Fire", "Water", "Air"}; - COE.TotemSets = {}; + COE.TotemSets = {}; - -- for each standard set - -- ---------------------- - local set; - for set = 1, table.getn( COE_SavedTotemSets ) do + -- for each standard set + -- ---------------------- + for set = 1, table.getn(COE_SavedTotemSets) do - COE.TotemSets[set] = { Earth = nil, Fire = nil, Water = nil, Air = nil, - CastOrder = COE_SavedTotemSets[set].CastOrder }; - - -- for each element - -- ----------------- - local k, totem; - for k = 1,4 do + COE.TotemSets[set] = { + Earth = nil, + Fire = nil, + Water = nil, + Air = nil, + CastOrder = COE_SavedTotemSets[set].CastOrder + }; - if( COE_SavedTotemSets[set][indices[k]] ~= "" ) then - - -- iterate over all totems - -- ------------------------ - for totem in COE.TotemData do - - if( COE.TotemData[totem].SpellName == COE_SavedTotemSets[set][indices[k]] ) then - COE.TotemSets[set][indices[k]] = COE.TotemData[totem]; - end - end - end - end - end + -- for each element + -- ----------------- + for k = 1, 4 do - -- for each custom set - -- -------------------- - for set = 1, table.getn( COE_CustomTotemSets ) do - - COE.TotemSets[COESET_DEFAULT + set] = { Earth = nil, Fire = nil, Water = nil, Air = nil, - CastOrder = COE_CustomTotemSets[set].CastOrder }; + if (COE_SavedTotemSets[set][indices[k]] ~= "") then - -- for each element - -- ----------------- - local k, totem; - for k = 1,4 do + -- iterate over all totems + -- ------------------------ + for totem in COE.TotemData do - if( COE_CustomTotemSets[set][indices[k]] ~= "" ) then - - -- iterate over all totems - -- ------------------------ - for totem in COE.TotemData do - - if( COE.TotemData[totem].SpellName == COE_CustomTotemSets[set][indices[k]] ) then - COE.TotemSets[COESET_DEFAULT + set][indices[k]] = COE.TotemData[totem]; - end - end - end - end - end + if (COE.TotemData[totem].SpellName == + COE_SavedTotemSets[set][indices[k]]) then + COE.TotemSets[set][indices[k]] = COE.TotemData[totem]; + end + end + end + end + end + + -- for each custom set + -- -------------------- + for set = 1, table.getn(COE_CustomTotemSets) do + + COE.TotemSets[COESET_DEFAULT + set] = { + Earth = nil, + Fire = nil, + Water = nil, + Air = nil, + CastOrder = COE_CustomTotemSets[set].CastOrder + }; + + -- for each element + -- ----------------- + local k, totem; + for k = 1, 4 do + + if (COE_CustomTotemSets[set][indices[k]] ~= "") then + + -- iterate over all totems + -- ------------------------ + for totem in COE.TotemData do + + if (COE.TotemData[totem].SpellName == + COE_CustomTotemSets[set][indices[k]]) then + COE.TotemSets[COESET_DEFAULT + set][indices[k]] = + COE.TotemData[totem]; + end + end + end + end + end + + COE.TotemSetCount = table.getn(COE.TotemSets); - COE.TotemSetCount = table.getn( COE.TotemSets ); - end - --[[ ============================================================================================= - F I X E S + F I X E S ================================================================================================]] --[[ ---------------------------------------------------------------- METHOD: COE:Fix_CastOrderLocalization - - PURPOSE: Correctly localizes the element names in the + + PURPOSE: Correctly localizes the element names in the cast order in COE_SavedTotemSets -------------------------------------------------------------------]] function COE:Fix_CastOrderLocalization() - -- for each standard set - -- ---------------------- - local set, k; - for set = 1, table.getn( COE_SavedTotemSets ) do - - for k = 1, 4 do - if( COE_SavedTotemSets[set].CastOrder[k] == "Earth" ) then - COE_SavedTotemSets[set].CastOrder[k] = COESTR_ELEMENT_EARTH; - - elseif( COE_SavedTotemSets[set].CastOrder[k] == "Fire" ) then - COE_SavedTotemSets[set].CastOrder[k] = COESTR_ELEMENT_FIRE; - - elseif( COE_SavedTotemSets[set].CastOrder[k] == "Water" ) then - COE_SavedTotemSets[set].CastOrder[k] = COESTR_ELEMENT_WATER; - - elseif( COE_SavedTotemSets[set].CastOrder[k] == "Air" ) then - COE_SavedTotemSets[set].CastOrder[k] = COESTR_ELEMENT_AIR; - end - end - end + -- for each standard set + -- ---------------------- + local set, k; + for set = 1, table.getn(COE_SavedTotemSets) do + + for k = 1, 4 do + if (COE_SavedTotemSets[set].CastOrder[k] == "Earth") then + COE_SavedTotemSets[set].CastOrder[k] = COESTR_ELEMENT_EARTH; + + elseif (COE_SavedTotemSets[set].CastOrder[k] == "Fire") then + COE_SavedTotemSets[set].CastOrder[k] = COESTR_ELEMENT_FIRE; + + elseif (COE_SavedTotemSets[set].CastOrder[k] == "Water") then + COE_SavedTotemSets[set].CastOrder[k] = COESTR_ELEMENT_WATER; + + elseif (COE_SavedTotemSets[set].CastOrder[k] == "Air") then + COE_SavedTotemSets[set].CastOrder[k] = COESTR_ELEMENT_AIR; + end + end + end + + -- notify user + -- ------------ + COE:Message(COESTR_FIXEDSETS); - -- notify user - -- ------------ - COE:Message( COESTR_FIXEDSETS ); - end - --[[ ---------------------------------------------------------------- METHOD: COE:Fix_DisplayedTotems - + PURPOSE: Fixes errors in the COE_DisplayedTotems array -------------------------------------------------------------------]] function COE:Fix_DisplayedTotems() - local i; - local fixed = false; - foreach( COE_DisplayedTotems, function( index, value ) + local i; + local fixed = false; + foreach(COE_DisplayedTotems, function(index, value) - -- is this an old-style entry? - -- ---------------------------- - if( type( value ) == "boolean" ) then - COE_DisplayedTotems[index] = { Order = 0, Visible = value }; - fixed = true; - - elseif( type( value ) == "table" ) then - if( COE_DisplayedTotems[index].Visible == nil ) then - COE_DisplayedTotems[index].Visible = true; - fixed = true; - end - - if( COE_DisplayedTotems[index].Order == nil ) then - COE_DisplayedTotems[index].Order = 0; - fixed = true; - end - - else - COE_DisplayedTotems[index] = { Order = 0, Visible = value }; - fixed = true; - end - - end ); + -- is this an old-style entry? + -- ---------------------------- + if (type(value) == "boolean") then + COE_DisplayedTotems[index] = {Order = 0, Visible = value}; + fixed = true; - -- notify user - -- ------------ - if( fixed ) then - COE:Message( COESTR_FIXEDDISPLAY ); - end + elseif (type(value) == "table") then + if (COE_DisplayedTotems[index].Visible == nil) then + COE_DisplayedTotems[index].Visible = true; + fixed = true; + end + + if (COE_DisplayedTotems[index].Order == nil) then + COE_DisplayedTotems[index].Order = 0; + fixed = true; + end + + else + COE_DisplayedTotems[index] = {Order = 0, Visible = value}; + fixed = true; + end + + end); + + -- notify user + -- ------------ + if (fixed) then COE:Message(COESTR_FIXEDDISPLAY); end end - --[[ ---------------------------------------------------------------- METHOD: COE:Fix_CastOrderLocalization2 - - PURPOSE: Correctly localizes the element names in the + + PURPOSE: Correctly localizes the element names in the cast order in COE_SavedTotemSets -------------------------------------------------------------------]] function COE:Fix_CastOrderLocalization2() - -- for each standard set - -- ---------------------- - local set, k; - for set = 1, table.getn( COE_SavedTotemSets ) do - - for k = 1, 4 do - if( COE_SavedTotemSets[set].CastOrder[k] == COESTR_TOTEMTOOLS_EARTH ) then - COE_SavedTotemSets[set].CastOrder[k] = COESTR_ELEMENT_EARTH; - - elseif( COE_SavedTotemSets[set].CastOrder[k] == COESTR_TOTEMTOOLS_FIRE ) then - COE_SavedTotemSets[set].CastOrder[k] = COESTR_ELEMENT_FIRE; - - elseif( COE_SavedTotemSets[set].CastOrder[k] == COESTR_TOTEMTOOLS_WATER ) then - COE_SavedTotemSets[set].CastOrder[k] = COESTR_ELEMENT_WATER; - - elseif( COE_SavedTotemSets[set].CastOrder[k] == COESTR_TOTEMTOOLS_AIR ) then - COE_SavedTotemSets[set].CastOrder[k] = COESTR_ELEMENT_AIR; - end - end - end + -- for each standard set + -- ---------------------- + local set, k; + for set = 1, table.getn(COE_SavedTotemSets) do - -- for each custom set - -- -------------------- - for set = 1, table.getn( COE_CustomTotemSets ) do - - for k = 1, 4 do - if( COE_CustomTotemSets[set].CastOrder[k] == COESTR_TOTEMTOOLS_EARTH ) then - COE_CustomTotemSets[set].CastOrder[k] = COESTR_ELEMENT_EARTH; - - elseif( COE_CustomTotemSets[set].CastOrder[k] == COESTR_TOTEMTOOLS_FIRE ) then - COE_CustomTotemSets[set].CastOrder[k] = COESTR_ELEMENT_FIRE; - - elseif( COE_CustomTotemSets[set].CastOrder[k] == COESTR_TOTEMTOOLS_WATER ) then - COE_CustomTotemSets[set].CastOrder[k] = COESTR_ELEMENT_WATER; - - elseif( COE_CustomTotemSets[set].CastOrder[k] == COESTR_TOTEMTOOLS_AIR ) then - COE_CustomTotemSets[set].CastOrder[k] = COESTR_ELEMENT_AIR; - end - end - end + for k = 1, 4 do + if (COE_SavedTotemSets[set].CastOrder[k] == COESTR_TOTEMTOOLS_EARTH) then + COE_SavedTotemSets[set].CastOrder[k] = COESTR_ELEMENT_EARTH; + + elseif (COE_SavedTotemSets[set].CastOrder[k] == + COESTR_TOTEMTOOLS_FIRE) then + COE_SavedTotemSets[set].CastOrder[k] = COESTR_ELEMENT_FIRE; + + elseif (COE_SavedTotemSets[set].CastOrder[k] == + COESTR_TOTEMTOOLS_WATER) then + COE_SavedTotemSets[set].CastOrder[k] = COESTR_ELEMENT_WATER; + + elseif (COE_SavedTotemSets[set].CastOrder[k] == + COESTR_TOTEMTOOLS_AIR) then + COE_SavedTotemSets[set].CastOrder[k] = COESTR_ELEMENT_AIR; + end + end + end + + -- for each custom set + -- -------------------- + for set = 1, table.getn(COE_CustomTotemSets) do + + for k = 1, 4 do + if (COE_CustomTotemSets[set].CastOrder[k] == COESTR_TOTEMTOOLS_EARTH) then + COE_CustomTotemSets[set].CastOrder[k] = COESTR_ELEMENT_EARTH; + + elseif (COE_CustomTotemSets[set].CastOrder[k] == + COESTR_TOTEMTOOLS_FIRE) then + COE_CustomTotemSets[set].CastOrder[k] = COESTR_ELEMENT_FIRE; + + elseif (COE_CustomTotemSets[set].CastOrder[k] == + COESTR_TOTEMTOOLS_WATER) then + COE_CustomTotemSets[set].CastOrder[k] = COESTR_ELEMENT_WATER; + + elseif (COE_CustomTotemSets[set].CastOrder[k] == + COESTR_TOTEMTOOLS_AIR) then + COE_CustomTotemSets[set].CastOrder[k] = COESTR_ELEMENT_AIR; + end + end + end end diff --git a/CallOfElements.lua b/CallOfElements.lua index c849487..9d00881 100644 --- a/CallOfElements.lua +++ b/CallOfElements.lua @@ -2,14 +2,10 @@ CALL OF ELEMENTS The All-In-One Shaman Addon - + by Wyverex (2006) -]] - -if( not COE ) then - COE = {}; -end +]] if (not COE) then COE = {}; end COE_VERSION = 2.6 @@ -32,14 +28,13 @@ COE["EventPrintMode"] = false; --[[ ---------------------------------------------------------------- These variables control frame updates - UpdateInterval sets the interval in seconds after which a + UpdateInterval sets the interval in seconds after which a frame is updated ForceUpdate can be used as input into Update handlers to force an update regardless of the current timer -------------------------------------------------------------------]] COE["UpdateInterval"] = 0.1; -COE["ForceUpdate"] = COE.UpdateInterval * 2; - +COE["ForceUpdate"] = COE.UpdateInterval * 2; --[[ ---------------------------------------------------------------- The AdvisorInterval controls how often the party/raid is @@ -50,270 +45,261 @@ COE["ForceUpdate"] = COE.UpdateInterval * 2; COE["AdvisorInterval"] = 1; COE["AdvisorWarningInterval"] = 7; - --[[ ---------------------------------------------------------------- METHOD: COE:Init - + PURPOSE: Loads submodules and initializes data -------------------------------------------------------------------]] function COE:Init() - COE:Message( "Call of Elements v" .. COE_VERSION ); - - -- load only for shamans - -- ---------------------- - local _, EnglishClass = UnitClass( "player" ); - if( EnglishClass ~= "SHAMAN" ) then - COE:Message( COESTR_NOTASHAMAN ); - COE.Initialized = false; - else - COE.Initialized = true; + COE:Message("Call of Elements v" .. COE_VERSION); - this:RegisterEvent( "VARIABLES_LOADED" ); - this:RegisterEvent("CHAT_MSG_SPELL_SELF_BUFF"); - - -- register shell command - -- ----------------------- - SlashCmdList["COE"] = COEProcessShellCommand; - SLASH_COE1="/coe"; - - end + -- load only for shamans + -- ---------------------- + local _, EnglishClass = UnitClass("player"); + if (EnglishClass ~= "SHAMAN") then + COE:Message(COESTR_NOTASHAMAN); + COE.Initialized = false; + else + COE.Initialized = true; + + this:RegisterEvent("VARIABLES_LOADED"); + this:RegisterEvent("CHAT_MSG_SPELL_SELF_BUFF"); + + -- register shell command + -- ----------------------- + SlashCmdList["COE"] = COEProcessShellCommand; + SLASH_COE1 = "/coe"; + + end end --[[ ---------------------------------------------------------------- METHOD: COE:FindSpellId - - PURPOSE: Utility function that can provide spell ID from name. + + PURPOSE: Utility function that can provide spell ID from name. Run in client chat with '/script COE:FindSpellName("a_spell_name")'. -------------------------------------------------------------------]] -function COE:FindSpellId(spellNameTarget) - local spellName; - for i = 1, 1000 do - spellName = GetSpellName(i, BOOKTYPE_SPELL); - if (spellName == spellNameTarget) then - print(spellName .. "is id: " .. i); +function COE:FindSpellId(spellNameTarget) + local spellName; + for i = 1, 1000 do + spellName = GetSpellName(i, BOOKTYPE_SPELL); + if (spellName == spellNameTarget) then + print(spellName .. "is id: " .. i); - end - end + end + end end --[[ ---------------------------------------------------------------- METHOD: COE:OnEvent - + PURPOSE: Handles frame events -------------------------------------------------------------------]] -function COE:OnEvent( event ) +function COE:OnEvent(event) - if( event == "VARIABLES_LOADED" ) then - -- fix saved variables if this update has to do so - -- ------------------------------------------------ - COE:FixSavedVariables(); + if (event == "VARIABLES_LOADED") then + -- fix saved variables if this update has to do so + -- ------------------------------------------------ + COE:FixSavedVariables(); - elseif (event == "CHAT_MSG_SPELL_SELF_BUFF") then - if (string.find(arg1, "Mana from Totemic Recall")) then - COE:DebugMessage("Totemic Recall initiating reset of timers."); - COE_Totem:ResetTimers(); - end + elseif (event == "CHAT_MSG_SPELL_SELF_BUFF") then + if (string.find(arg1, "Mana from Totemic Recall")) then + COE:DebugMessage("Totemic Recall initiating reset of timers."); + COE_Totem:ResetTimers(); + end - elseif (COE.EventPrintMode) then - COE:DebugMessage(event); + elseif (COE.EventPrintMode) then + COE:DebugMessage(event); - end + end end --[[ ---------------------------------------------------------------- METHOD: COE:Message - + PURPOSE: Adds a message to the default chat frame -------------------------------------------------------------------]] -function COE:Message( msg ) - DEFAULT_CHAT_FRAME:AddMessage( "[COE] " .. msg, 0.93, 0.83, 0.45 ); -end; - +function COE:Message(msg) + DEFAULT_CHAT_FRAME:AddMessage("[COE] " .. msg, 0.93, 0.83, 0.45); +end --[[ ---------------------------------------------------------------- METHOD: COE:DebugMessage - + PURPOSE: Adds a debug message to the default chat frame if debug mode is enabled -------------------------------------------------------------------]] -function COE:DebugMessage( msg ) - if( COE.DebugMode ) then - DEFAULT_CHAT_FRAME:AddMessage( "[COE] " .. msg, 1, 0, 0 ); - end -end; - +function COE:DebugMessage(msg) + if (COE.DebugMode) then + DEFAULT_CHAT_FRAME:AddMessage("[COE] " .. msg, 1, 0, 0); + end +end --[[ ---------------------------------------------------------------- METHOD: COE:Notification - + PURPOSE: Adds a message to the error frame in the upper screen center -------------------------------------------------------------------]] -function COE:Notification( msg, color ) +function COE:Notification(msg, color) - local col; + local col; - -- choose color - -- ------------- - if( color == COECOL_TOTEMWARNING ) then - col = { r = 0, g = 0.6, b = 1 }; - elseif( color == COECOL_TOTEMDESTROYED ) then - col = { r = 1, g = 0.4, b = 0 }; - elseif( color == COECOL_TOTEMCLEANSING ) then - col = { r = 0, g = 1, b = 0.4 }; - else - col = { r = 1, g = 1, b = 1 }; - end + -- choose color + -- ------------- + if (color == COECOL_TOTEMWARNING) then + col = {r = 0, g = 0.6, b = 1}; + elseif (color == COECOL_TOTEMDESTROYED) then + col = {r = 1, g = 0.4, b = 0}; + elseif (color == COECOL_TOTEMCLEANSING) then + col = {r = 0, g = 1, b = 0.4}; + else + col = {r = 1, g = 1, b = 1}; + end - -- add message - -- ------------ - UIErrorsFrame:AddMessage( msg, col.r, col.g, col.b, 1.0, UIERRORS_HOLD_TIME ); - -end; + -- add message + -- ------------ + UIErrorsFrame:AddMessage(msg, col.r, col.g, col.b, 1.0, UIERRORS_HOLD_TIME); +end --[[ ---------------------------------------------------------------- METHOD: COE:ToggleConfigFrame - + PURPOSE: Toggles the configuration dialog -------------------------------------------------------------------]] function COE:ToggleConfigFrame() - - if( COE_ConfigFrame:IsVisible() ) then - COE_Config:CloseDialog() - else - COE_ConfigFrame:Show(); - end - PlaySound( "igMainMenuOption" ); + if (COE_ConfigFrame:IsVisible()) then + COE_Config:CloseDialog() + else + COE_ConfigFrame:Show(); + end + + PlaySound("igMainMenuOption"); end - --[[ ---------------------------------------------------------------- METHOD: COEProcessShellCommand - + PURPOSE: Executes the entered shell command -------------------------------------------------------------------]] -function COEProcessShellCommand( msg ) +function COEProcessShellCommand(msg) - if( msg == "" or msg == "config" ) then - COE:ToggleConfigFrame(); - - elseif( msg == "list" ) then - COE:DisplayShellCommands(); - - elseif( msg == "nextset" ) then - COE_Totem:SwitchToNextSet(); - - elseif( msg == "priorset" ) then - COE_Totem:SwitchToPriorSet(); + if (msg == "" or msg == "config") then + COE:ToggleConfigFrame(); - elseif( msg == "throwset" ) then - COE_Totem:ThrowSet(); - - elseif( msg == "restartset" ) then - COE_Totem:ResetSetCycle(); - - elseif( msg == "reset" ) then - COE_Totem:ResetTimers(); - - elseif( msg == "reload" ) then - COE_Totem:Rescan(); - - elseif( msg == "resetframes" ) then - COE_Totem:ResetFrames(); + elseif (msg == "list") then + COE:DisplayShellCommands(); - elseif( msg == "advised" ) then - COE_Totem:ThrowAdvisedTotem(); - - elseif( msg == "resetordering" ) then - COE_DisplayedTotems = {}; - COE_Totem:Rescan(); - - elseif( msg == "bestheal" ) then - COE_Heal:BestHeal(); - - elseif( msg == "battleheal" ) then - COE_Heal:BattleHeal(); + elseif (msg == "nextset") then + COE_Totem:SwitchToNextSet(); - else - local _,_,arg = string.find( msg, "set (.*)" ); - if( arg ) then - COE_Totem:SwitchToSet( arg ); - end - end + elseif (msg == "priorset") then + COE_Totem:SwitchToPriorSet(); + + elseif (msg == "throwset") then + COE_Totem:ThrowSet(); + + elseif (msg == "restartset") then + COE_Totem:ResetSetCycle(); + + elseif (msg == "reset") then + COE_Totem:ResetTimers(); + + elseif (msg == "reload") then + COE_Totem:Rescan(); + + elseif (msg == "resetframes") then + COE_Totem:ResetFrames(); + + elseif (msg == "advised") then + COE_Totem:ThrowAdvisedTotem(); + + elseif (msg == "resetordering") then + COE_DisplayedTotems = {}; + COE_Totem:Rescan(); + + elseif (msg == "bestheal") then + COE_Heal:BestHeal(); + + elseif (msg == "battleheal") then + COE_Heal:BattleHeal(); + + else + local _, _, arg = string.find(msg, "set (.*)"); + if (arg) then COE_Totem:SwitchToSet(arg); end + end end - --[[ ---------------------------------------------------------------- METHOD: COE:DisplayShellCommands - + PURPOSE: Shows a list of all shell commands -------------------------------------------------------------------]] function COE:DisplayShellCommands() - COE:Message( COESHELL_INTRO ); - COE:Message( COESHELL_CONFIG ); - COE:Message( COESHELL_LIST ); - COE:Message( COESHELL_NEXTSET ); - COE:Message( COESHELL_PRIORSET ); - COE:Message( COESHELL_SET ); - COE:Message( COESHELL_RESTARTSET ); - COE:Message( COESHELL_RESET ); - COE:Message( COESHELL_RESETFRAMES ); - COE:Message( COESHELL_RESETORDERING ); - COE:Message( COESHELL_RELOAD ); - COE:Message( COESHELL_MACRONOTE ); - COE:Message( COESHELL_THROWSET ); - COE:Message( COESHELL_ADVISED ); + COE:Message(COESHELL_INTRO); + COE:Message(COESHELL_CONFIG); + COE:Message(COESHELL_LIST); + COE:Message(COESHELL_NEXTSET); + COE:Message(COESHELL_PRIORSET); + COE:Message(COESHELL_SET); + COE:Message(COESHELL_RESTARTSET); + COE:Message(COESHELL_RESET); + COE:Message(COESHELL_RESETFRAMES); + COE:Message(COESHELL_RESETORDERING); + COE:Message(COESHELL_RELOAD); + COE:Message(COESHELL_MACRONOTE); + COE:Message(COESHELL_THROWSET); + COE:Message(COESHELL_ADVISED); end - --[[ ---------------------------------------------------------------- METHOD: COE:FixSavedVariables - + PURPOSE: If this addon version is higher than the one in the saved variables, check if we have to fix the saved variables due to fixed bugs -------------------------------------------------------------------]] function COE:FixSavedVariables() - -- is the version stored in the saved variables? - -- ---------------------------------------------- - if( not COE_Config:GetSaved( COEOPT_VERSION ) ) then - -- this is version <= v1.6 - -- ------------------------ - COE_Config:SetOption( COEOPT_VERSION, 1.6 ); - end - - local version = COE_Config:GetSaved( COEOPT_VERSION ); - - if( version == 1.6 ) then - -- fix localized cast order in 1.7 - -- -------------------------------- - COE:Fix_CastOrderLocalization(); - - COE:Message( COESTR_UDATEDSAVED .. "1.7" ); - COE_Config:SetOption( COEOPT_VERSION, 1.7 ); - version = COE_Config:GetSaved( COEOPT_VERSION ); - end + -- is the version stored in the saved variables? + -- ---------------------------------------------- + if (not COE_Config:GetSaved(COEOPT_VERSION)) then + -- this is version <= v1.6 + -- ------------------------ + COE_Config:SetOption(COEOPT_VERSION, 1.6); + end - if( version == 1.7 ) then - -- fix cast order again to due to a typo - -- -------------------------------------- - COE:Fix_CastOrderLocalization(); - - COE:Message( COESTR_UDATEDSAVED .. "1.8" ); - COE_Config:SetOption( COEOPT_VERSION, 1.8 ); - version = COE_Config:GetSaved( COEOPT_VERSION ); - end - - -- fix totem set element strings - -- ------------------------------ - COE:Fix_CastOrderLocalization2(); + local version = COE_Config:GetSaved(COEOPT_VERSION); - COE_Config:SetOption( COEOPT_VERSION, 2.1 ); + if (version == 1.6) then + -- fix localized cast order in 1.7 + -- -------------------------------- + COE:Fix_CastOrderLocalization(); + + COE:Message(COESTR_UDATEDSAVED .. "1.7"); + COE_Config:SetOption(COEOPT_VERSION, 1.7); + version = COE_Config:GetSaved(COEOPT_VERSION); + end + + if (version == 1.7) then + -- fix cast order again to due to a typo + -- -------------------------------------- + COE:Fix_CastOrderLocalization(); + + COE:Message(COESTR_UDATEDSAVED .. "1.8"); + COE_Config:SetOption(COEOPT_VERSION, 1.8); + version = COE_Config:GetSaved(COEOPT_VERSION); + end + + -- fix totem set element strings + -- ------------------------------ + COE:Fix_CastOrderLocalization2(); + + COE_Config:SetOption(COEOPT_VERSION, 2.1); end