Advertisement
josbarteling

Broker_Portals-sorted-fixed

May 27th, 2015
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 33.51 KB | None | 0 0
  1. if not LibStub then return end
  2.  
  3. local dewdrop = LibStub('Dewdrop-2.0', true)
  4. local icon = LibStub('LibDBIcon-1.0')
  5.  
  6. local _
  7. local math_floor = math.floor
  8.  
  9. local CreateFrame = CreateFrame
  10. local GetContainerItemCooldown = GetContainerItemCooldown
  11. local GetContainerItemInfo = GetContainerItemInfo
  12. local GetContainerItemLink = GetContainerItemLink
  13. local GetContainerNumSlots = GetContainerNumSlots
  14. local GetBindLocation = GetBindLocation
  15. local GetInventoryItemCooldown = GetInventoryItemCooldown
  16. local GetInventoryItemLink = GetInventoryItemLink
  17. local GetSpellCooldown = GetSpellCooldown
  18. local GetSpellInfo = GetSpellInfo
  19. local GetSpellBookItemName = GetSpellBookItemName
  20. local SendChatMessage = SendChatMessage
  21. local UnitInRaid = UnitInRaid
  22. local GetNumGroupMembers = GetNumGroupMembers
  23. local IsPlayerSpell = IsPlayerSpell
  24.  
  25. local addonName, addonTable = ...
  26. local L = addonTable.L
  27.  
  28. -- IDs of items usable for transportation
  29. local items = {
  30.     -- Dalaran rings
  31.     40586,  -- Band of the Kirin Tor
  32.     48954,  -- Etched Band of the Kirin Tor
  33.     48955,  -- Etched Loop of the Kirin Tor
  34.     48956,  -- Etched Ring of the Kirin Tor
  35.     48957,  -- Etched Signet of the Kirin Tor
  36.     45688,  -- Inscribed Band of the Kirin Tor
  37.     45689,  -- Inscribed Loop of the Kirin Tor
  38.     45690,  -- Inscribed Ring of the Kirin Tor
  39.     45691,  -- Inscribed Signet of the Kirin Tor
  40.     44934,  -- Loop of the Kirin Tor
  41.     44935,  -- Ring of the Kirin Tor
  42.     40585,  -- Signet of the Kirin Tor
  43.     51560,  -- Runed Band of the Kirin Tor
  44.     51558,  -- Runed Loop of the Kirin Tor
  45.     51559,  -- Runed Ring of the Kirin Tor
  46.     51557,  -- Runed Signet of the Kirin Tor
  47.     -- Engineering Gadgets
  48.     30542,  -- Dimensional Ripper - Area 52
  49.     18984,  -- Dimensional Ripper - Everlook
  50.     18986,  -- Ultrasafe Transporter: Gadgetzan
  51.     30544,  -- Ultrasafe Transporter: Toshley's Station
  52.     48933,  -- Wormhole Generator: Northrend
  53.     87215,  -- Wormhole Generator: Pandaria
  54.     112059, -- Wormhole Centrifuge
  55.     -- Seasonal items
  56.     37863,  -- Direbrew's Remote
  57.     21711,  -- Lunar Festival Invitation
  58.     -- Miscellaneous
  59.     46874,  -- Argent Crusader's Tabard
  60.     32757,  -- Blessed Medallion of Karabor
  61.     35230,  -- Darnarian's Scroll of Teleportation
  62.     50287,  -- Boots of the Bay
  63.     52251,  -- Jaina's Locket
  64.     43824,  -- The Schools of Arcane Magic - Mastery
  65.     58487,  -- Potion of Deepholm
  66.     65274,  -- Cloak of Coordination (Horde)
  67.     65360,  -- Cloak of Coordination (Alliance)
  68.     63378,  -- Hellscream's Reach Tabard
  69.     63379,  -- Baradin's Wardens Tabard
  70.     64457,  -- The Last Relic of Argus
  71.     63206,  -- Wrap of Unity (Alliance)
  72.     63207,  -- Wrap of Unity (Horde)
  73.     63352,  -- Shroud of Cooperation (Alliance)
  74.     63353,  -- Shroud of Cooperation (Horde)
  75.     95050,  -- The Brassiest Knuckle (Horde)
  76.     95051,  -- The Brassiest Knuckle (Alliance)
  77.     95567,  -- Kirin Tor Beacon
  78.     95568,  -- Sunreaver Beacon
  79.     17690,  -- Frostwolf Insignia Rank 1 (Horde)
  80.     17905,  -- Frostwolf Insignia Rank 2 (Horde)
  81.     17906,  -- Frostwolf Insignia Rank 3 (Horde)
  82.     17907,  -- Frostwolf Insignia Rank 4 (Horde)
  83.     17908,  -- Frostwolf Insignia Rank 5 (Horde)
  84.     17909,  -- Frostwolf Insignia Rank 6 (Horde)
  85.     17691,  -- Stormpike Insignia Rank 1 (Alliance)
  86.     17900,  -- Stormpike Insignia Rank 2 (Alliance)
  87.     17901,  -- Stormpike Insignia Rank 3 (Alliance)
  88.     17902,  -- Stormpike Insignia Rank 4 (Alliance)
  89.     17903,  -- Stormpike Insignia Rank 5 (Alliance)
  90.     17904,  -- Stormpike Insignia Rank 6 (Alliance)
  91.     22631,  -- Atiesh, Greatstaff of the Guardian
  92.     87548,  -- Lorewalker's Lodestone
  93.     54452,  -- Ethereal Portal
  94.     93672,  -- Dark Portal
  95.     103678, -- Time-Lost Artifact
  96.     110560, -- Garrison Hearthstone
  97.     118663  -- Relic of Karabor
  98. }
  99.  
  100. -- IDs of items usable instead of hearthstone
  101. local scrolls = {
  102.     64488, -- The Innkeeper's Daughter
  103.     28585, -- Ruby Slippers
  104.     6948,  -- Hearthstone
  105.     44315, -- Scroll of Recall III
  106.     44314, -- Scroll of Recall II
  107.     37118  -- Scroll of Recall
  108. }
  109.  
  110. -- Gold Challenge portals
  111. local challengeSpells = {
  112.     { 131204, 'TRUE' }, -- Path of the Jade Serpent
  113.     { 131205, 'TRUE' }, -- Path of the Stout Brew
  114.     { 131206, 'TRUE' }, -- Path of the Shado-Pan
  115.     { 131222, 'TRUE' }, -- Path of the Mogu King
  116.     { 131225, 'TRUE' }, -- Path of the Setting Sun
  117.     { 131231, 'TRUE' }, -- Path of the Scarlet Blade
  118.     { 131229, 'TRUE' }, -- Path of the Scarlet Mitre
  119.     { 131232, 'TRUE' }, -- Path of the Necromancer
  120.     { 131228, 'TRUE' }  -- Path of the Black Ox
  121. }
  122.  
  123. obj = LibStub:GetLibrary('LibDataBroker-1.1'):NewDataObject(addonName, {
  124.     type = 'data source',
  125.     text = L['P'],
  126.     icon = 'Interface\\Icons\\INV_Misc_Rune_06',
  127. })
  128. local obj = obj
  129. local methods = {}
  130. local portals
  131. local frame = CreateFrame('frame')
  132.  
  133. frame:SetScript('OnEvent', function(self, event, ...) if self[event] then return self[event](self, event, ...) end end)
  134. frame:RegisterEvent('PLAYER_LOGIN')
  135. frame:RegisterEvent('SKILL_LINES_CHANGED')
  136.  
  137. local function pairsByKeys(t)
  138.     local a = {}
  139.     for n in pairs(t) do
  140.         table.insert(a, n)
  141.     end
  142.     table.sort(a)
  143.  
  144.     local i = 0
  145.     local iter = function()
  146.         i = i + 1
  147.         if a[i] == nil then
  148.             return nil
  149.         else
  150.             return a[i], t[a[i]]
  151.         end
  152.     end
  153.     return iter
  154. end
  155.  
  156. local function tconcat(t1, t2)
  157.     for i = 1, #t2 do
  158.         t1[#t1 + 1] = t2[i]
  159.     end
  160.     return t1
  161. end
  162.  
  163. function findSpell(spellName)
  164.     local i = 1
  165.     while true do
  166.         local s = GetSpellBookItemName(i, BOOKTYPE_SPELL)
  167.         if not s then
  168.             break
  169.         end
  170.  
  171.         if s == spellName then
  172.             return i
  173.         end
  174.  
  175.         i = i + 1
  176.     end
  177. end
  178.  
  179. -- returns true, if player has item with given ID in inventory or bags and it's not on cooldown
  180. local function hasItem(itemID)
  181.     local item, found, id
  182.     -- scan inventory
  183.     for slotId = 1, 19 do
  184.         item = GetInventoryItemLink('player', slotId)
  185.         if item then
  186.             found, _, id = item:find('^|c%x+|Hitem:(%d+):.+')
  187.             if found and tonumber(id) == itemID then
  188.                 if GetInventoryItemCooldown('player', slotId) ~= 0 then
  189.                     return false
  190.                 else
  191.                     return true
  192.                 end
  193.             end
  194.         end
  195.     end
  196.     -- scan bags
  197.     for bag = 0, 4 do
  198.         for slot = 1, GetContainerNumSlots(bag) do
  199.             item = GetContainerItemLink(bag, slot)
  200.             if item then
  201.                 found, _, id = item:find('^|c%x+|Hitem:(%d+):.+')
  202.                 if found and tonumber(id) == itemID then
  203.                     if GetContainerItemCooldown(bag, slot) ~= 0 then
  204.                         return false
  205.                     else
  206.                         return true
  207.                     end
  208.                 end
  209.             end
  210.         end
  211.     end
  212.  
  213.     return false
  214. end
  215.  
  216. local function getReagentCount(name)
  217.     local count = 0
  218.     for bag = 0, 4 do
  219.         for slot = 1, GetContainerNumSlots(bag) do
  220.             local item = GetContainerItemLink(bag, slot)
  221.             if item then
  222.                 if item:find(name) then
  223.                     local _, itemCount = GetContainerItemInfo(bag, slot)
  224.                     count = count + itemCount
  225.                 end
  226.             end
  227.         end
  228.     end
  229.  
  230.     return count
  231. end
  232.            
  233. local function SetupSpells()
  234.     local spells = {
  235.         Alliance = {          
  236.             { 3561, 'TP_RUNE' },   -- TP:Stormwind
  237.             { 3562, 'TP_RUNE' },   -- TP:Ironforge
  238.             { 3565, 'TP_RUNE' },   -- TP:Darnassus
  239.             { 32271, 'TP_RUNE' },  -- TP:Exodar
  240.             { 49359, 'TP_RUNE' },  -- TP:Theramore
  241.             { 33690, 'TP_RUNE' },  -- TP:Shattrath
  242.             { 53140, 'TP_RUNE' },  -- TP:Dalaran
  243.             { 88342, 'TP_RUNE' },  -- TP:Tol Barad
  244.             { 132621, 'TP_RUNE' }, -- TP:Vale of Eternal Blossoms
  245.             { 120145, 'TP_RUNE' }, -- TP:Ancient Dalaran
  246.             { 176248, 'TP_RUNE' }, -- TP:StormShield
  247.             { 10059, 'P_RUNE' },   -- P:Stormwind
  248.             { 11416, 'P_RUNE' },   -- P:Ironforge
  249.             { 11419, 'P_RUNE' },   -- P:Darnassus
  250.             { 32266, 'P_RUNE' },   -- P:Exodar
  251.             { 49360, 'P_RUNE' },   -- P:Theramore
  252.             { 33691, 'P_RUNE' },   -- P:Shattrath
  253.             { 53142, 'P_RUNE' },   -- P:Dalaran
  254.             { 88345, 'P_RUNE' },   -- P:Tol Barad
  255.             { 120146, 'P_RUNE' },  -- P:Ancient Dalaran
  256.             { 132620, 'P_RUNE' },  -- P:Vale of Eternal Blossoms
  257.             { 176246, 'P_RUNE' }   -- P:StormShield
  258.         },
  259.         Horde = {
  260.             { 3563, 'TP_RUNE' },   -- TP:Undercity
  261.             { 3566, 'TP_RUNE' },   -- TP:Thunder Bluff
  262.             { 3567, 'TP_RUNE' },   -- TP:Orgrimmar
  263.             { 32272, 'TP_RUNE' },  -- TP:Silvermoon
  264.             { 49358, 'TP_RUNE' },  -- TP:Stonard
  265.             { 35715, 'TP_RUNE' },  -- TP:Shattrath
  266.             { 53140, 'TP_RUNE' },  -- TP:Dalaran
  267.             { 88344, 'TP_RUNE' },  -- TP:Tol Barad
  268.             { 132627, 'TP_RUNE' }, -- TP:Vale of Eternal Blossoms
  269.             { 120145, 'TP_RUNE' }, -- TP:Ancient Dalaran
  270.             { 176242, 'TP_RUNE' }, -- TP:Warspear
  271.             { 11418, 'P_RUNE' },   -- P:Undercity
  272.             { 11420, 'P_RUNE' },   -- P:Thunder Bluff
  273.             { 11417, 'P_RUNE' },   -- P:Orgrimmar
  274.             { 32267, 'P_RUNE' },   -- P:Silvermoon
  275.             { 49361, 'P_RUNE' },   -- P:Stonard
  276.             { 35717, 'P_RUNE' },   -- P:Shattrath
  277.             { 53142, 'P_RUNE' },   -- P:Dalaran
  278.             { 88346, 'P_RUNE' },   -- P:Tol Barad
  279.             { 120146, 'P_RUNE' },  -- P:Ancient Dalaran
  280.             { 132626, 'P_RUNE' },  -- P:Vale of Eternal Blossoms
  281.             { 176244, 'P_RUNE' }   -- P:Warspear
  282.         }
  283.     }
  284.  
  285.     local _, class = UnitClass('player')
  286.     if class == 'MAGE' then
  287.             portals = spells[select(1, UnitFactionGroup('player'))]
  288.     elseif class == 'DEATHKNIGHT' then
  289.         portals = {
  290.             { 50977, 'TRUE' } -- Death Gate
  291.         }
  292.     elseif class == 'DRUID' then
  293.         portals = {
  294.             { 18960,  'TRUE' }, -- TP:Moonglade
  295.             { 147420, 'TRUE' }  -- TP:One with Nature
  296.         }
  297.     elseif class == 'SHAMAN' then
  298.         portals = {
  299.             { 556, 'TRUE' } -- Astral Recall
  300.         }
  301.     elseif class == 'MONK' then
  302.         portals = {
  303.             { 126892, 'TRUE' }, -- Zen Pilgrimage
  304.             { 126895, 'TRUE' }  -- Zen Pilgrimage: Return
  305.         }
  306.     else
  307.         portals = {}
  308.     end
  309.  
  310.     spells = nil
  311. end
  312.  
  313. local function GenerateLinks(spells)
  314.     for _, unTransSpell in ipairs(spells) do
  315.         if IsPlayerSpell(unTransSpell[1]) then
  316.             local spell, _, spellIcon = GetSpellInfo(unTransSpell[1])
  317.             local spellid = findSpell(spell)
  318.  
  319.             if spellid then
  320.                 methods[spell] = {
  321.                     spellid = spellid,
  322.                     text = spell,
  323.                     spellIcon = spellIcon,
  324.                     isPortal = unTransSpell[2] == 'P_RUNE',
  325.                     secure = {
  326.                         type = 'spell',
  327.                         spell = spell
  328.                     }
  329.                 }
  330.             end
  331.         end
  332.     end
  333. end
  334.  
  335. local function UpdateSpells()
  336.     if not portals then
  337.         SetupSpells()
  338.     end
  339.  
  340.     if portals then
  341.         GenerateLinks(portals)
  342.     end
  343.  
  344.     GenerateLinks(challengeSpells)
  345. end
  346.  
  347. local function UpdateIcon(icon)
  348.     obj.icon = icon
  349. end
  350.  
  351. local function GetHearthCooldown()
  352.     local cooldown, startTime, duration
  353.  
  354.     for _, item in pairs(scrolls) do
  355.         if GetItemCount(item) > 0 then
  356.             startTime, duration = GetItemCooldown(item)
  357.             cooldown = duration - (GetTime() - startTime)
  358.             if cooldown >= 60 then
  359.                 cooldown = math_floor(cooldown / 60)
  360.                 cooldown = cooldown .. ' ' .. L['MIN']
  361.             elseif cooldown <= 0 then
  362.                 cooldown = L['READY']
  363.             else
  364.                 cooldown = math_floor(cooldown) .. ' ' .. L['SEC']
  365.             end
  366.             return cooldown
  367.         end
  368.     end
  369.  
  370.     return L['N/A']
  371. end
  372.  
  373. local function GetItemCooldowns()
  374.     local cooldown, cooldowns
  375.  
  376.     for _, item in pairs(items) do
  377.         if GetItemCount(item) > 0 then
  378.             startTime, duration = GetItemCooldown(item)
  379.             cooldown = duration - (GetTime() - startTime)
  380.             if cooldown >= 60 then
  381.                 cooldown = math_floor(cooldown / 60)
  382.                 cooldown = cooldown .. ' ' .. L['MIN']
  383.             elseif cooldown <= 0 then
  384.                 cooldown = L['READY']
  385.             else
  386.                 cooldown = math_floor(cooldown) .. ' ' .. L['SEC']
  387.             end
  388.  
  389.             if cooldowns == nil then
  390.                 cooldowns = {}
  391.             end
  392.  
  393.             cooldowns[GetItemInfo(item)] = cooldown
  394.         end
  395.     end
  396.  
  397.     return cooldowns
  398. end
  399.  
  400. local function ShowHearthstone()
  401.     local bindLoc = GetBindLocation()
  402.     local secure, text, icon, name
  403.  
  404.     for _, itemID in ipairs(scrolls) do
  405.         if hasItem(itemID) then
  406.             name, _, _, _, _, _, _, _, _, icon = GetItemInfo(itemID)
  407.             text = L['INN'] .. ' ' .. bindLoc
  408.             secure = {
  409.                 type = 'item',
  410.                 item = name
  411.             }
  412.             break
  413.         end
  414.     end
  415.  
  416.     if secure ~= nil then
  417.         dewdrop:AddLine('text', text,
  418.             'secure', secure,
  419.             'icon', icon,
  420.             'func', function() UpdateIcon(icon) end,
  421.             'closeWhenClicked', true)
  422.         dewdrop:AddLine()
  423.     end
  424. end
  425.  
  426. local function ShowOtherItems()
  427.     local i = 0
  428.  
  429.     for _, itemID in ipairs(items) do
  430.         if hasItem(itemID) then
  431.             local name, _, quality, _, _, _, _, _, _, icon = GetItemInfo(itemID)
  432.             local secure = {
  433.                 type = 'item',
  434.                 item = name
  435.             }
  436.  
  437.             dewdrop:AddLine(
  438.                 'text', name,
  439.                 'textR', ITEM_QUALITY_COLORS[quality].r,
  440.                 'textG', ITEM_QUALITY_COLORS[quality].g,
  441.                 'textB', ITEM_QUALITY_COLORS[quality].b,
  442.                 'secure', secure,
  443.                 'icon', icon,
  444.                 'func', function() UpdateIcon(icon) end,
  445.                 'closeWhenClicked', true)
  446.             i = i + 1
  447.         end
  448.     end
  449.     if i > 0 then
  450.         dewdrop:AddLine()
  451.     end
  452. end
  453.  
  454. local function ToggleMinimap()
  455.     local hide = not PortalsDB.minimap.hide
  456.     PortalsDB.minimap.hide = hide
  457.     if hide then
  458.         icon:Hide('Broker_Portals')
  459.     else
  460.         icon:Show('Broker_Portals')
  461.     end
  462. end
  463.  
  464. local function UpdateMenu(level, value)
  465.     if level == 1 then
  466.         dewdrop:AddLine('text', 'Broker_Portals',
  467.                 'isTitle', true)        
  468.  
  469.         methods = {}
  470.         UpdateSpells()
  471.         dewdrop:AddLine()
  472.         dewdrop:AddLine('text', 'Portals',
  473.                         'isTitle', true)
  474.         dewdrop:AddLine()            
  475.         dewdrop:AddLine('text', 'Eastern Kingdoms',
  476.             'hasArrow', true,
  477.             'value', 'easternp')
  478.         dewdrop:AddLine('text', 'Kalimdor',
  479.             'hasArrow', true,
  480.             'value', 'kalimdorp')
  481.         dewdrop:AddLine('text', 'Outland',
  482.             'hasArrow', true,
  483.             'value', 'outlandp')
  484.         dewdrop:AddLine('text', 'Northrend',
  485.             'hasArrow', true,
  486.             'value', 'northrendp')
  487.         dewdrop:AddLine('text', 'Pandaria',
  488.             'hasArrow', true,
  489.             'value', 'pandariap')
  490.         dewdrop:AddLine('text', 'Draenor',
  491.             'hasArrow', true,
  492.             'value', 'draenorp')
  493.            
  494.         dewdrop:AddLine()        
  495.         dewdrop:AddLine('text', 'Teleport',
  496.                         'isTitle', true)                        
  497.         dewdrop:AddLine()            
  498.         dewdrop:AddLine('text', 'Eastern Kingdoms',
  499.             'hasArrow', true,
  500.             'value', 'easterntp')            
  501.         dewdrop:AddLine('text', 'Kalimdor',
  502.             'hasArrow', true,
  503.             'value', 'kalimdortp')
  504.         dewdrop:AddLine('text', 'Outland',
  505.             'hasArrow', true,
  506.             'value', 'outlandtp')
  507.         dewdrop:AddLine('text', 'Northrend',
  508.             'hasArrow', true,
  509.             'value', 'northrendtp')
  510.         dewdrop:AddLine('text', 'Pandaria',
  511.             'hasArrow', true,
  512.             'value', 'pandariatp')
  513.         dewdrop:AddLine('text', 'Draenor',
  514.             'hasArrow', true,
  515.             'value', 'draenortp')      
  516.  
  517.  
  518.         dewdrop:AddLine()
  519.         ShowHearthstone()
  520.  
  521.         if PortalsDB.showItems then
  522.             ShowOtherItems()
  523.         end
  524.  
  525.         dewdrop:AddLine('text', L['OPTIONS'],
  526.             'hasArrow', true,
  527.             'value', 'options')
  528.  
  529.         dewdrop:AddLine('text', CLOSE,
  530.             'tooltipTitle', CLOSE,
  531.             'tooltipText', CLOSE_DESC,
  532.             'closeWhenClicked', true)
  533.     elseif level == 2 and value == 'options' then
  534.         dewdrop:AddLine('text', L['SHOW_ITEMS'],
  535.             'checked', PortalsDB.showItems,
  536.             'func', function() PortalsDB.showItems = not PortalsDB.showItems end,
  537.             'closeWhenClicked', true)
  538.         dewdrop:AddLine('text', L['SHOW_ITEM_COOLDOWNS'],
  539.             'checked', PortalsDB.showItemCooldowns,
  540.             'func', function() PortalsDB.showItemCooldowns = not PortalsDB.showItemCooldowns end,
  541.             'closeWhenClicked', true)
  542.         dewdrop:AddLine('text', L['ATT_MINIMAP'],
  543.             'checked', not PortalsDB.minimap.hide,
  544.             'func', function() ToggleMinimap() end,
  545.             'closeWhenClicked', true)
  546.         dewdrop:AddLine('text', L['ANNOUNCE'],
  547.             'checked', PortalsDB.announce,
  548.             'func', function() PortalsDB.announce = not PortalsDB.announce end,
  549.             'closeWhenClicked', true)
  550.     end
  551.    
  552. --------portal              
  553.    
  554.     if level == 2 and value == 'easternp' then
  555.         local chatType = (UnitInRaid("player") and "RAID") or (GetNumGroupMembers() > 0 and "PARTY") or nil
  556.         local announce = PortalsDB.announce
  557.         for k, v in pairsByKeys(methods) do
  558.             if v.text:find("Portal: Stormwind")  or
  559.             v.text:find("Portal: Ironforge") or
  560.             v.text:find("Portal: Undercity") or
  561.             v.text:find("Portal: Silvermoon") or
  562.             v.text:find("Portal: Stonard") or
  563.             v.text:find("Portal: Tol") or
  564.             v.text:find("Ancient Portal")then
  565.             if v.secure and GetSpellCooldown(v.text) == 0 then
  566.                 dewdrop:AddLine(                
  567.                     'spellid', v.spellid,
  568.                     'text', v.text,
  569.                     'secure', v.secure,
  570.                     'icon', v.spellIcon,
  571.                     'func', function()
  572.                         UpdateIcon(v.spellIcon)
  573.                         if announce and v.isPortal and chatType then
  574.                             SendChatMessage(L['ANNOUNCEMENT'] .. ' ' .. v.text, chatType)
  575.                         end
  576.                     end,
  577.                     'closeWhenClicked', true)
  578.             end
  579.             end
  580.         end
  581.     end
  582.    
  583.    
  584.     if level == 2 and value == 'kalimdorp' then
  585.         local chatType = (UnitInRaid("player") and "RAID") or (GetNumGroupMembers() > 0 and "PARTY") or nil
  586.         local announce = PortalsDB.announce
  587.         for k, v in pairsByKeys(methods) do
  588.             if v.text:find("Portal: Darnassus") or
  589.             v.text:find("Portal: Exodar") or
  590.             v.text:find("Portal: Orgrimmar") or
  591.             v.text:find("Portal: Thunder") or
  592.             v.text:find("Portal: Theramore") then
  593.             if v.secure and GetSpellCooldown(v.text) == 0 then
  594.                 dewdrop:AddLine(                
  595.                     'spellid', v.spellid,
  596.                     'text', v.text,
  597.                     'secure', v.secure,
  598.                     'icon', v.spellIcon,
  599.                     'func', function()
  600.                         UpdateIcon(v.spellIcon)
  601.                         if announce and v.isPortal and chatType then
  602.                             SendChatMessage(L['ANNOUNCEMENT'] .. ' ' .. v.text, chatType)
  603.                         end
  604.                     end,
  605.                     'closeWhenClicked', true)
  606.             end
  607.             end
  608.         end
  609.     end
  610.  
  611.     if level == 2 and value == 'outlandp' then
  612.         local chatType = (UnitInRaid("player") and "RAID") or (GetNumGroupMembers() > 0 and "PARTY") or nil
  613.         local announce = PortalsDB.announce
  614.         for k, v in pairsByKeys(methods) do
  615.             if v.text:find("Portal: Shattrath") then
  616.             if v.secure and GetSpellCooldown(v.text) == 0 then
  617.                 dewdrop:AddLine(                
  618.                     'spellid', v.spellid,
  619.                     'text', v.text,
  620.                     'secure', v.secure,
  621.                     'icon', v.spellIcon,
  622.                     'func', function()
  623.                         UpdateIcon(v.spellIcon)
  624.                         if announce and v.isPortal and chatType then
  625.                             SendChatMessage(L['ANNOUNCEMENT'] .. ' ' .. v.text, chatType)
  626.                         end
  627.                     end,
  628.                     'closeWhenClicked', true)
  629.             end
  630.             end
  631.         end
  632.     end
  633.  
  634.     if level == 2 and value == 'northrendp' then
  635.         local chatType = (UnitInRaid("player") and "RAID") or (GetNumGroupMembers() > 0 and "PARTY") or nil
  636.         local announce = PortalsDB.announce
  637.         for k, v in pairsByKeys(methods) do
  638.             if v.text:find("Portal: Dalaran") then
  639.             if v.text:find("Ancient") then v = nil
  640.             elseif v.secure and GetSpellCooldown(v.text) == 0 then
  641.                 dewdrop:AddLine(                
  642.                     'spellid', v.spellid,
  643.                     'text', v.text,
  644.                     'secure', v.secure,
  645.                     'icon', v.spellIcon,
  646.                     'func', function()
  647.                         UpdateIcon(v.spellIcon)
  648.                         if announce and v.isPortal and chatType then
  649.                             SendChatMessage(L['ANNOUNCEMENT'] .. ' ' .. v.text, chatType)
  650.                         end
  651.                     end,
  652.                     'closeWhenClicked', true)
  653.             end
  654.             end
  655.         end
  656.     end
  657.    
  658.    
  659.     if level == 2 and value == 'pandariap' then
  660.         local chatType = (UnitInRaid("player") and "RAID") or (GetNumGroupMembers() > 0 and "PARTY") or nil
  661.         local announce = PortalsDB.announce
  662.         for k, v in pairsByKeys(methods) do
  663.             if v.text:find("Portal: Vale") then
  664.             if v.secure and GetSpellCooldown(v.text) == 0 then
  665.                 dewdrop:AddLine(                
  666.                     'spellid', v.spellid,
  667.                     'text', v.text,
  668.                     'secure', v.secure,
  669.                     'icon', v.spellIcon,
  670.                     'func', function()
  671.                         UpdateIcon(v.spellIcon)
  672.                         if announce and v.isPortal and chatType then
  673.                             SendChatMessage(L['ANNOUNCEMENT'] .. ' ' .. v.text, chatType)
  674.                         end
  675.                     end,
  676.                     'closeWhenClicked', true)
  677.             end
  678.             end
  679.         end
  680.     end
  681.  
  682.  
  683.     if level == 2 and value == 'draenorp' then
  684.         local chatType = (UnitInRaid("player") and "RAID") or (GetNumGroupMembers() > 0 and "PARTY") or nil
  685.         local announce = PortalsDB.announce
  686.         for k, v in pairsByKeys(methods) do
  687.             if v.text:find("Portal: Stormshield") or
  688.             v.text:find("Portal: Warspear") then
  689.             if v.secure and GetSpellCooldown(v.text) == 0 then
  690.                 dewdrop:AddLine(                
  691.                     'spellid', v.spellid,
  692.                     'text', v.text,
  693.                     'secure', v.secure,
  694.                     'icon', v.spellIcon,
  695.                     'func', function()
  696.                         UpdateIcon(v.spellIcon)
  697.                         if announce and v.isPortal and chatType then
  698.                             SendChatMessage(L['ANNOUNCEMENT'] .. ' ' .. v.text, chatType)
  699.                         end
  700.                     end,
  701.                     'closeWhenClicked', true)
  702.             end
  703.             end
  704.         end
  705.     end
  706.  
  707.  
  708.    
  709.        
  710. --------teleport
  711.        
  712.     if level == 2 and value == 'easterntp' then
  713.         local chatType = (UnitInRaid("player") and "RAID") or (GetNumGroupMembers() > 0 and "PARTY") or nil
  714.         local announce = PortalsDB.announce
  715.         for k, v in pairsByKeys(methods) do
  716.             if v.text:find("Teleport: Stormwind")  or
  717.             v.text:find("Teleport: Ironforge") or
  718.             v.text:find("Teleport: Undercity") or
  719.             v.text:find("Teleport: Silvermoon") or
  720.             v.text:find("Teleport: Stonard") or
  721.             v.text:find("Teleport: Tol") or
  722.             v.text:find("Ancient Teleport")then
  723.             if v.secure and GetSpellCooldown(v.text) == 0 then
  724.                 dewdrop:AddLine(                
  725.                     'spellid', v.spellid,
  726.                     'text', v.text,
  727.                     'secure', v.secure,
  728.                     'icon', v.spellIcon,
  729.                     'func', function()
  730.                         UpdateIcon(v.spellIcon)
  731.                         if announce and v.isPortal and chatType then
  732.                             SendChatMessage(L['ANNOUNCEMENT'] .. ' ' .. v.text, chatType)
  733.                         end
  734.                     end,
  735.                     'closeWhenClicked', true)
  736.             end
  737.             end
  738.         end
  739.     end
  740.    
  741.    
  742.     if level == 2 and value == 'kalimdortp' then
  743.         local chatType = (UnitInRaid("player") and "RAID") or (GetNumGroupMembers() > 0 and "PARTY") or nil
  744.         local announce = PortalsDB.announce
  745.         for k, v in pairsByKeys(methods) do
  746.             if v.text:find("Teleport: Darnassus") or
  747.             v.text:find("Teleport: Exodar") or
  748.             v.text:find("Teleport: Orgrimmar") or
  749.             v.text:find("Teleport: Thunder") or
  750.             v.text:find("Teleport: Theramore") then
  751.             if v.secure and GetSpellCooldown(v.text) == 0 then
  752.                 dewdrop:AddLine(                
  753.                     'spellid', v.spellid,
  754.                     'text', v.text,
  755.                     'secure', v.secure,
  756.                     'icon', v.spellIcon,
  757.                     'func', function()
  758.                         UpdateIcon(v.spellIcon)
  759.                         if announce and v.isPortal and chatType then
  760.                             SendChatMessage(L['ANNOUNCEMENT'] .. ' ' .. v.text, chatType)
  761.                         end
  762.                     end,
  763.                     'closeWhenClicked', true)
  764.             end
  765.             end
  766.         end
  767.     end
  768.    
  769.     if level == 2 and value == 'outlandtp' then
  770.         local chatType = (UnitInRaid("player") and "RAID") or (GetNumGroupMembers() > 0 and "PARTY") or nil
  771.         local announce = PortalsDB.announce
  772.         for k, v in pairsByKeys(methods) do
  773.             if v.text:find("Teleport: Shattrath") then
  774.             if v.secure and GetSpellCooldown(v.text) == 0 then
  775.                 dewdrop:AddLine(                
  776.                     'spellid', v.spellid,
  777.                     'text', v.text,
  778.                     'secure', v.secure,
  779.                     'icon', v.spellIcon,
  780.                     'func', function()
  781.                         UpdateIcon(v.spellIcon)
  782.                         if announce and v.isPortal and chatType then
  783.                             SendChatMessage(L['ANNOUNCEMENT'] .. ' ' .. v.text, chatType)
  784.                         end
  785.                     end,
  786.                     'closeWhenClicked', true)
  787.             end
  788.             end
  789.         end
  790.     end
  791.  
  792.     if level == 2 and value == 'northrendtp' then
  793.         local chatType = (UnitInRaid("player") and "RAID") or (GetNumGroupMembers() > 0 and "PARTY") or nil
  794.         local announce = PortalsDB.announce
  795.         for k, v in pairsByKeys(methods) do
  796.             if v.text:find("Teleport: Dalaran") then
  797.             if v.text:find("Ancient") then v = nil
  798.             elseif v.secure and GetSpellCooldown(v.text) == 0 then
  799.                 dewdrop:AddLine(                
  800.                     'spellid', v.spellid,
  801.                     'text', v.text,
  802.                     'secure', v.secure,
  803.                     'icon', v.spellIcon,
  804.                     'func', function()
  805.                         UpdateIcon(v.spellIcon)
  806.                         if announce and v.isPortal and chatType then
  807.                             SendChatMessage(L['ANNOUNCEMENT'] .. ' ' .. v.text, chatType)
  808.                         end
  809.                     end,
  810.                     'closeWhenClicked', true)
  811.             end
  812.             end
  813.         end
  814.     end
  815.    
  816.    
  817.     if level == 2 and value == 'pandariatp' then
  818.         local chatType = (UnitInRaid("player") and "RAID") or (GetNumGroupMembers() > 0 and "PARTY") or nil
  819.         local announce = PortalsDB.announce
  820.         for k, v in pairsByKeys(methods) do
  821.             if v.text:find("Teleport: Vale") then
  822.             if v.secure and GetSpellCooldown(v.text) == 0 then
  823.                 dewdrop:AddLine(                
  824.                     'spellid', v.spellid,
  825.                     'text', v.text,
  826.                     'secure', v.secure,
  827.                     'icon', v.spellIcon,
  828.                     'func', function()
  829.                         UpdateIcon(v.spellIcon)
  830.                         if announce and v.isPortal and chatType then
  831.                             SendChatMessage(L['ANNOUNCEMENT'] .. ' ' .. v.text, chatType)
  832.                         end
  833.                     end,
  834.                     'closeWhenClicked', true)
  835.             end
  836.             end
  837.         end
  838.     end
  839.  
  840.  
  841.     if level == 2 and value == 'draenortp' then
  842.         local chatType = (UnitInRaid("player") and "RAID") or (GetNumGroupMembers() > 0 and "PARTY") or nil
  843.         local announce = PortalsDB.announce
  844.         for k, v in pairsByKeys(methods) do
  845.             if v.text:find("Teleport: Stormshield") or
  846.             v.text:find("Teleport: Warspear") then
  847.             if v.secure and GetSpellCooldown(v.text) == 0 then
  848.                 dewdrop:AddLine(                
  849.                     'spellid', v.spellid,
  850.                     'text', v.text,
  851.                     'secure', v.secure,
  852.                     'icon', v.spellIcon,
  853.                     'func', function()
  854.                         UpdateIcon(v.spellIcon)
  855.                         if announce and v.isPortal and chatType then
  856.                             SendChatMessage(L['ANNOUNCEMENT'] .. ' ' .. v.text, chatType)
  857.                         end
  858.                     end,
  859.                     'closeWhenClicked', true)
  860.             end
  861.             end
  862.         end
  863.     end
  864.  
  865. end
  866.  
  867.  
  868. function frame:PLAYER_LOGIN()
  869.     -- PortalsDB.minimap is there for smooth upgrade of SVs from old version
  870.     if (not PortalsDB) or (PortalsDB.version == nil) then
  871.         PortalsDB = {}
  872.         PortalsDB.minimap = {}
  873.         PortalsDB.minimap.hide = false
  874.         PortalsDB.showItems = true
  875.         PortalsDB.showItemCooldowns = true
  876.         PortalsDB.announce = false
  877.         PortalsDB.version = 4
  878.     end
  879.  
  880.     -- upgrade from versions
  881.     if PortalsDB.version == 3 then
  882.         PortalsDB.announce = false
  883.         PortalsDB.version = 4
  884.     elseif PortalsDB.version == 2 then
  885.         PortalsDB.showItemCooldowns = true
  886.         PortalsDB.announce = false
  887.         PortalsDB.version = 4
  888.     elseif PortalsDB.version < 2 then
  889.         PortalsDB.showItems = true
  890.         PortalsDB.showItemCooldowns = true
  891.         PortalsDB.announce = false
  892.         PortalsDB.version = 4
  893.     end
  894.  
  895.     if icon then
  896.         icon:Register('Broker_Portals', obj, PortalsDB.minimap)
  897.     end
  898.  
  899.     self:UnregisterEvent('PLAYER_LOGIN')
  900. end
  901.  
  902. function frame:SKILL_LINES_CHANGED()
  903.     UpdateSpells()
  904. end
  905.  
  906. -- All credit for this func goes to Tekkub and his picoGuild!
  907. local function GetTipAnchor(frame)
  908.     local x, y = frame:GetCenter()
  909.     if not x or not y then return 'TOPLEFT', 'BOTTOMLEFT' end
  910.     local hhalf = (x > UIParent:GetWidth() * 2 / 3) and 'RIGHT' or (x < UIParent:GetWidth() / 3) and 'LEFT' or ''
  911.     local vhalf = (y > UIParent:GetHeight() / 2) and 'TOP' or 'BOTTOM'
  912.     return vhalf .. hhalf, frame, (vhalf == 'TOP' and 'BOTTOM' or 'TOP') .. hhalf
  913. end
  914.  
  915. function obj.OnClick(self, button)
  916.     GameTooltip:Hide()
  917.         if button == 'RightButton' then
  918.             dewdrop:Open(self, 'children',
  919.             function(level, value) UpdateMenu(level, value) end)
  920.         end
  921. end
  922.  
  923. function obj.OnLeave()
  924.     GameTooltip:Hide()
  925. end
  926.  
  927. function obj.OnEnter(self)
  928.     GameTooltip:SetOwner(self, 'ANCHOR_NONE')
  929.     GameTooltip:SetPoint(GetTipAnchor(self))
  930.     GameTooltip:ClearLines()
  931.  
  932.     GameTooltip:AddLine('Broker Portals')
  933.     GameTooltip:AddDoubleLine(L['RCLICK'], L['SEE_SPELLS'], 0.9, 0.6, 0.2, 0.2, 1, 0.2)
  934.     GameTooltip:AddLine(' ')
  935.     GameTooltip:AddDoubleLine(L['HEARTHSTONE'] .. ': ' .. GetBindLocation(), GetHearthCooldown(), 0.9, 0.6, 0.2, 0.2, 1, 0.2)
  936.  
  937.     if PortalsDB.showItemCooldowns then
  938.         local cooldowns = GetItemCooldowns()
  939.         if cooldowns ~= nil then
  940.             GameTooltip:AddLine(' ')
  941.             for name, cooldown in pairs(cooldowns) do
  942.                 GameTooltip:AddDoubleLine(name, cooldown, 0.9, 0.6, 0.2, 0.2, 1, 0.2)
  943.             end
  944.         end
  945.     end
  946.  
  947.     GameTooltip:Show()
  948. end
  949.  
  950. -- slash command definition
  951. SlashCmdList['BROKER_PORTALS'] = function() ToggleMinimap() end
  952. SLASH_BROKER_PORTALS1 = '/portals'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement