gabestah

gridsinestra color4

Sep 11th, 2011
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.75 KB | None | 0 0
  1.  
  2. --
  3. -- Thanks to evildead & Pastamancer who wrote the
  4. -- original GridStatusKalecgos. This module is
  5. -- written from the ashes of it. With out that
  6. -- we wouldn't have this.
  7. --
  8. -- On that note portions of the oringinal were rewritten
  9. -- to use newer Ace3, Grid APIs, new combat events
  10. -- ...and a few enhancements along the way.
  11. --
  12. -- "Always Kill Purple Dargons"
  13. --
  14.  
  15. --Ghetto localization
  16. local enUs =
  17. {
  18.     ["The Bastion of Twilight"] = "The Bastion of Twilight",
  19.     ["Sinestra Wrack"] = "Sinestra Wrack",
  20.     ["Initial Color"] = "Initial Color",
  21.     ["Initial color for a new duration"] = "Initial color for a new duration",
  22.     ["Color 2"] = "Color 2",
  23.     ["Color 2 Time"] = "Color 2 Time",
  24.     ["Second color to display for a warning duration"] = "Second color to display for a warning duration",
  25.     ["Color 3"] = "Color 3",
  26.     ["Color 3 Time"] = "Color 3 Time",
  27.     ["Color 4"] = "Color 4",
  28.     ["Color 4 Time"] = "Color 4 Time",
  29.     ["Third color to display for the longest duration."] = "Third color to display for the longest duration.",
  30.     ["Fourth color to display for the longest duration."] = "Fourth color to display for the longest duration.",
  31.     ['The Twilight Caverns'] = "The Twilight Caverns",
  32. };
  33.  
  34. L = enUs;
  35.  
  36.    
  37. --Spell info, spell ids, full spell info caches, and a quick hash lookup for testing
  38.  
  39.  
  40. --name->spellid hash
  41. --For future me or future someone else. Just add/change the spell id's here to add/repurpose this addon.
  42. local SPELL_ID = {
  43.     ["Wrack"] = 92956,
  44.     ["Wrack2"] = 92955,
  45. }
  46.  
  47. --name->spell info
  48. local BS = {
  49.     ["Wrack"] = GetSpellInfo(SPELL_ID["Wrack"]) ,
  50.     ["Wrack2"] = GetSpellInfo(SPELL_ID["Wrack2"]),
  51. }
  52.  
  53. --spell name -> true hash check for alerting
  54. local AURAS = {
  55.     [select( 1, GetSpellInfo(SPELL_ID["Wrack"]))] = true,
  56.     [select( 1, GetSpellInfo(SPELL_ID["Wrack2"]))] = true,
  57.     --["Renew"] = true, --test spell
  58. }
  59.  
  60. --name -> icon
  61. local SPELL_ICON = {
  62.     ["Wrack"] = select(3, GetSpellInfo(SPELL_ID["Wrack"])),
  63. }
  64.  
  65.  
  66. --Simple names for things
  67. local GridFrame = Grid:GetModule("GridFrame");
  68. local GridStatus = Grid:GetModule("GridStatus");
  69. local GridStatusSinestra = GridStatus:NewModule("GridStatusSinestra", "AceEvent-3.0", "AceTimer-3.0");
  70.  
  71. --Build basic grid/ace/saved variables parts
  72. GridStatusSinestra.menuName = L["Sinestra Wrack"];
  73. GridStatusSinestra.defaultDB = {
  74.     ["debug"] = false,
  75.     ["alert_Sinestra"] = {
  76.         ["desc"] = BS["Wrack"],
  77.         ["enable"] = true,
  78.         ["priority"] = 90,
  79.         ["range"] = false,
  80.         ["icon"] = SPELL_ICON["Wrack"],
  81.         ["color1"] = {
  82.             r = 0,
  83.             g = 1,
  84.             b = 0,
  85.             a = 1,
  86.         },
  87.         ["color2"] = {
  88.             r = 1,
  89.             g = 1,
  90.             b = 0,
  91.             a = 1,
  92.         },
  93.         ["color3"] = {
  94.             r = 1,
  95.             g = 0,
  96.             b = 0,
  97.             a = 1,
  98.         },
  99.         ["color4"] = {
  100.             r = 1,
  101.             g = 0,
  102.             b = 0,
  103.             a = 1,
  104.         },
  105.         ["color2time"] = 9,
  106.         ["color3time"] = 11,
  107.         ["color4time"] = 11,
  108.     },
  109. }
  110.  
  111. local WrackOptions = {
  112.     ["color"] = false,
  113.     ["color1"] = {
  114.         type = "color",
  115.         name = L["Initial Color"],
  116.         desc = L["Initial color for a new duration"],
  117.         order = 110,
  118.         hasAlpha = true,
  119.         get = function ()
  120.                   local color = GridStatusSinestra.db.profile["alert_Sinestra"].color1
  121.                   return color.r, color.g, color.b, color.a
  122.               end,
  123.         set = function ( _,r, g, b, a)
  124.                   local color = GridStatusSinestra.db.profile["alert_Sinestra"].color1
  125.                   color.r = r
  126.                   color.g = g
  127.                   color.b = b
  128.                   color.a = a or 1
  129.                  
  130.               end,
  131.     },
  132.     ["color2"] = {
  133.         type = "color",
  134.         name = L["Color 2"],
  135.         desc = L["Second color to display for a warning duration"],
  136.         order = 115,
  137.         hasAlpha = true,
  138.         get = function()
  139.                   local color = GridStatusSinestra.db.profile["alert_Sinestra"].color2
  140.                   return color.r, color.g, color.b, color.a
  141.               end,
  142.         set = function ( _, r, g, b, a)
  143.                   local color = GridStatusSinestra.db.profile["alert_Sinestra"].color2
  144.                   color.r = r
  145.                   color.g = g
  146.                   color.b = b
  147.                   color.a = a or 1
  148.               end,
  149.     },
  150.     ["color3"] = {
  151.         type = "color",
  152.         name = L["Color 3"],
  153.         desc = L["Third color to display for the longest duration."],
  154.         order = 120,
  155.         hasAlpha = true,
  156.         get = function()
  157.                   local color = GridStatusSinestra.db.profile["alert_Sinestra"].color3
  158.                   return color.r, color.g, color.b, color.a
  159.               end,
  160.         set = function ( _,r, g, b, a)
  161.                   local color = GridStatusSinestra.db.profile["alert_Sinestra"].color3
  162.                   color.r = r
  163.                   color.g = g
  164.                   color.b = b
  165.                   color.a = a or 1
  166.               end,
  167.     },
  168.     ["color4"] = {
  169.         type = "color",
  170.         name = L["Color 4"],
  171.         desc = L["Third color to display for the longest duration."],
  172.         order = 120,
  173.         hasAlpha = true,
  174.         get = function()
  175.                   local color = GridStatusSinestra.db.profile["alert_Sinestra"].color4
  176.                   return color.r, color.g, color.b, color.a
  177.               end,
  178.         set = function ( _,r, g, b, a)
  179.                   local color = GridStatusSinestra.db.profile["alert_Sinestra"].color4
  180.                   color.r = r
  181.                   color.g = g
  182.                   color.b = b
  183.                   color.a = a or 1
  184.               end,
  185.     }, 
  186.     ["color2time"] =
  187.     {
  188.         type = "range",
  189.         name = "Color 2 Time",
  190.         desc = "Time to switch to color 2",
  191.         order = 105,
  192.         softMin = 0,
  193.         softMax = 60,
  194.         step = 1,
  195.         bigStep = 5,
  196.         get = function() return GridStatusSinestra.db.profile["alert_Sinestra"].color2time end,
  197.         set = function( r, num ) GridStatusSinestra.db.profile["alert_Sinestra"].color2time = num or 0 end,
  198.         isPercent = false,
  199.         width = "full",
  200.     },
  201.     ["color3time"] =
  202.     {
  203.         type = "range",
  204.         name = "Color 3 Time",
  205.         desc = "Time to switch to color 3",
  206.         order = 109,
  207.         softMin = 0,
  208.         softMax = 60,
  209.         step = 1,
  210.         bigStep = 5,
  211.         get = function() return GridStatusSinestra.db.profile["alert_Sinestra"].color3time end,
  212.         set = function( r, num ) GridStatusSinestra.db.profile["alert_Sinestra"].color3time = num or 0 end,
  213.         isPercent = false,
  214.         width = "full",
  215.     },
  216.     ["color4time"] =
  217.     {
  218.         type = "range",
  219.         name = "Color 4 Time",
  220.         desc = "Time to switch to color 4",
  221.         order = 109,
  222.         softMin = 0,
  223.         softMax = 60,
  224.         step = 1,
  225.         bigStep = 5,
  226.         get = function() return GridStatusSinestra.db.profile["alert_Sinestra"].color4time end,
  227.         set = function( r, num ) GridStatusSinestra.db.profile["alert_Sinestra"].color4time = num or 0 end,
  228.         isPercent = false,
  229.         width = "full",
  230.     },
  231. }
  232.  
  233. GridStatusSinestra.options = false
  234.  
  235. -------------------------------------------------------------------------------
  236. -- @override
  237. --
  238. -- Override for default no-op initialization. Registers a Grid Status for
  239. -- sinestra.
  240. --
  241. function GridStatusSinestra:OnInitialize()
  242.     self.super.OnInitialize(self)
  243.     self:RegisterStatus("alert_Sinestra", L["Sinestra Wrack"], WrackOptions, true)
  244. end
  245.  
  246. -------------------------------------------------------------------------------
  247. -- Event handler for zone change. Activates combat log watching only while
  248. -- in the proper zone.
  249. --
  250. function GridStatusSinestra:ZONE_CHANGED_NEW_AREA()
  251.  
  252.     for name, status, statusTbl in self.core:CachedStatusIterator("alert_Sinestra") do
  253.         self.core:SendStatusLost(name, "alert_Sinestra")
  254.     end
  255.    
  256.     self._timers = {};
  257.     GridStatusSinestra:CheckZone()
  258. end
  259.  
  260. function GridStatusSinestra:ZONE_CHANGED_INDOORS()
  261.     GridStatusSinestra:CheckZone()
  262. end
  263.  
  264. function GridStatusSinestra:CheckZone()
  265.     if GetRealZoneText() == L["The Bastion of Twilight"] and GetSubZoneText() == L['The Twilight Caverns'] then
  266.         self:RegisterEvent( "COMBAT_LOG_EVENT_UNFILTERED" );
  267.         print( "'Sinestra Wrack: Always kill purple dargons!' ~ Raegx of Blood Legion @ US-Illidan" );
  268.     else
  269.         self:UnregisterEvent( "COMBAT_LOG_EVENT_UNFILTERED" );
  270.     end
  271. end
  272.  
  273. -------------------------------------------------------------------------------
  274. -- @override
  275. --
  276. -- Override for default no-op enable. Registers a combat log event watcher
  277. -- and sets up empty timer tables.
  278. --
  279. function GridStatusSinestra:OnEnable()
  280.     self:Debug( "----GSS ENABLED" )
  281.    
  282.     self:RegisterEvent( "ZONE_CHANGED_NEW_AREA" );
  283.     self:RegisterEvent( "ZONE_CHANGED_INDOORS" );
  284.     self._timers = {}
  285.     self._timerHandler = nil
  286.     local settings = self.db.profile["alert_Sinestra"]
  287.     if( settings.enabled ) then
  288.         self:Debug( "---GSS settings say its enabled" );
  289.     end
  290.     settings.enable = true;
  291.     for name, status, statusTbl in self.core:CachedStatusIterator("alert_Sinestra") do
  292.         self.core:SendStatusLost(name, "alert_Sinestra")
  293.     end
  294.     GridStatusSinestra:CheckZone()
  295. end
  296.  
  297. -------------------------------------------------------------------------------
  298. -- Watches combat event logs for aura application/removals by name
  299. --
  300. --
  301. function  GridStatusSinestra:COMBAT_LOG_EVENT_UNFILTERED( ... )
  302.     local eventType = select( 3, ... );
  303.     local auraType = select( 14, ... ) or "";
  304.     local auraAmmount = select( 15, ... ) or "";
  305.     local playerName = select( 10, ... );
  306.     if( (UnitInRaid( playerName ) or UnitInParty( playerName )) ) then
  307.         self:Debug( "----wrack applied" );
  308.         if( eventType == "SPELL_AURA_APPLIED" and AURAS[auraType]) then
  309.             self:AuraGained(select( 9, ... ))
  310.         elseif( eventType == "SPELL_AURA_REMOVED" and AURAS[auraType]) then
  311.             self:AuraFaded(select( 9, ... ))
  312.         elseif( eventType =="UNIT_DIED" ) then
  313.             self:AuraFaded(select( 9, ... ))
  314.         end;
  315.     end;
  316.    
  317.  
  318. end
  319.  
  320. -------------------------------------------------------------------------------
  321. -- @override
  322. --
  323. -- Override for default no-op disable. Unregisters event handlers, reset Grid
  324. -- statuses, and clears timers.
  325. --
  326. function GridStatusSinestra:OnDisable()
  327.     self:Debug( "--GSS DISABLED" );
  328.     self:UnregisterEvent( "ZONE_CHANGED_NEW_AREA" );
  329.     if not self:IsEventRegistered("COMBAT_LOG_EVENT_UNFILTERED") then
  330.         return
  331.     end
  332.     self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  333.  
  334.     self:CancelScheduledEvent("GridStatusSinestra_SinestraDebuffTimer")
  335.     self._timers = nil
  336.  
  337.     for name, status, statusTbl in self.core:CachedStatusIterator("alert_Sinestra") do
  338.         self.core:SendStatusLost(name, "alert_Sinestra")
  339.     end
  340. end
  341.  
  342. -------------------------------------------------------------------------------
  343. -- Resets addon state.
  344. --
  345. --
  346. function GridStatusSinestra:Reset()
  347.     self:OnDisable()
  348.     self:OnEnable()
  349. end
  350.  
  351. -------------------------------------------------------------------------------
  352. -- Logic called when an applicable unit obtains a watched aura
  353. --
  354. --
  355.  
  356. function GridStatusSinestra:AuraGained(unit )
  357.  
  358.     if unit == "target" or unit == "focus" then
  359.         return
  360.     end
  361.  
  362.     local settings = self.db.profile["alert_Sinestra"]
  363.  
  364.     --Set initial color
  365.     self.core:SendStatusGained(unit, "alert_Sinestra",
  366.                                settings.priority, false,
  367.                                settings.color1,
  368.                                ("%d"):format(0),
  369.                                0, 30,
  370.                                settings.icon)
  371.  
  372.     --start timers
  373.     self._timers[unit] = GetTime()
  374.     self:StartOrStopTimer()
  375. end
  376.  
  377. -------------------------------------------------------------------------------
  378. -- Logic called when an applicable unit loses a watched aura
  379. --
  380. --
  381. function GridStatusSinestra:AuraFaded(unit)
  382.     if unit == "target" or unit == "focus" then
  383.         return
  384.     end
  385.  
  386.     self._timers[unit] = nil
  387.     self.core:SendStatusLost(unit, "alert_Sinestra")
  388.     self:StartOrStopTimer()
  389. end
  390.  
  391. -------------------------------------------------------------------------------
  392. -- Starts or stops a recurring timer to check auras if auras exist. If all
  393. -- timers expire the timer is stopped.
  394. --
  395. --
  396. function GridStatusSinestra:StartOrStopTimer()
  397.     self:Debug( "----gss start timer" )
  398.    
  399.     if not next(self._timers) then
  400.         if( GridStatusSinestra._timerHandler ) then
  401.             self:Debug( "---stop timer" );
  402.             self:CancelTimer(GridStatusSinestra._timerHandler)
  403.             GridStatusSinestra._timerHandler = nil;
  404.         end
  405.     elseif not GridStatusSinestra._timerHandler then
  406.         self:Debug( "-----start timer" );
  407.         GridStatusSinestra._timerHandler = self:ScheduleRepeatingTimer( function() GridStatusSinestra.DebuffTimer( self ) end, 0.5)
  408.     end
  409. end
  410.  
  411. -------------------------------------------------------------------------------
  412. -- Logic called to check aura times and update status colores.
  413. --
  414. --
  415. function GridStatusSinestra:DebuffTimer()
  416.     local settings = self.db.profile["alert_Sinestra"]
  417.     if not settings.enable then
  418.         self:Debug( "----------------------- disabled" );
  419.         return self:OnDisable()
  420.     end
  421.  
  422.     local now = GetTime()
  423.  
  424.     for unit,time in pairs(self._timers) do
  425.         --aura's current time on target
  426.         local elapsed = now - time
  427.  
  428.         local color = settings.color1
  429.  
  430.         -- swap color properly
  431.         if elapsed >= GridStatusSinestra.db.profile["alert_Sinestra"].color4time then
  432.             color = settings.color4
  433.         elseif elapsed >= GridStatusSinestra.db.profile["alert_Sinestra"].color3time then
  434.             color = settings.color3
  435.         elseif elapsed >= GridStatusSinestra.db.profile["alert_Sinestra"].color2time then
  436.             color = settings.color2
  437.         end
  438.  
  439.         self.core:SendStatusGained(unit, "alert_Sinestra",
  440.                                    settings.priority, false,
  441.                                    color,
  442.                                    ("%d"):format(elapsed),
  443.                                    elapsed, 30,
  444.                                    settings.icon)
  445.     end
  446. end
Advertisement
Add Comment
Please, Sign In to add comment