gabestah

Fixed GridStatusSearingPlasma

Feb 6th, 2012
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.78 KB | None | 0 0
  1. --[[
  2.     Name: GridStatusSearingPlasma
  3.     Revision: $Revision: 10108 $
  4.     Developed by: Kulldon @ US-Hyjal ([email protected])
  5.     Description: Status indicator for remaining absorb value of Searing Plasma for the Spine of Deathwing encounter.
  6. ]]
  7.  
  8. --{{{ Libraries
  9. local L = LibStub("AceLocale-3.0"):GetLocale("GridStatusSearingPlasma")
  10. --}}}
  11.  
  12. local GridRoster = Grid:GetModule("GridRoster")
  13. local GridStatusSearingPlasma = Grid:GetModule("GridStatus"):NewModule("GridStatusSearingPlasma")
  14. GridStatusSearingPlasma.menuName = L["Searing Plasma"]
  15.  
  16. -- Add new valid spells here by spell ID
  17. local validSpells = {
  18.     --17, -- Power Word: Shield
  19.     105479, -- Searing Plasma 10N
  20.     109363, -- Searing Plasma 10H
  21.     109362, -- Searing Plasma 25N
  22.     109364, -- Searing Plasma 25H
  23. };
  24.  
  25.  
  26. --{{{ AceDB defaults
  27. GridStatusSearingPlasma.defaultDB = {
  28.     searingPlasma = {
  29.         enable = true,
  30.         priority = 90,
  31.         color = { r = 1, g = 0, b = 0, a = 1 },
  32.         mark1Color = { r = 0, g = 1, b = 0, a = 1 },
  33.         mark1Threshold = 50000,
  34.         mark2Color = { r = 1, g = 1, b = 0, a = 1 },
  35.         mark2Threshold = 150000,
  36.         mark3Color = { r = 1, g = 0, b = 0, a = 1 },
  37.         mark3Threshold = 280000,       
  38.         useCombatLog = true,
  39.     },
  40. }
  41. --}}}
  42.  
  43. local settings
  44.  
  45. --{{{ Options
  46. local amountOptions = {
  47.     ["mark1threshold"] = {
  48.         type = "range",
  49.         name = L["Low absorb threshold"],
  50.         desc = L["The threshold below which the absorb is considered low."],
  51.         max = 400000,
  52.         min = 1,
  53.         step = 500,
  54.         get = function()
  55.             return settings.searingPlasma.mark1Threshold
  56.         end,
  57.         set = function(_, v)
  58.             settings.searingPlasma.mark1Threshold = v
  59.         end,
  60.         width = 'full',
  61.         order = 87,
  62.     },
  63.     ["mark2threshold"] = {
  64.         type = "range",
  65.         name = L["Medium absorb threshold"],
  66.         desc = L["The threshold below which the absorb is considered medium."],
  67.         max = 400000,
  68.         min = 1,
  69.         step = 500,
  70.         get = function()
  71.             return settings.searingPlasma.mark2Threshold
  72.         end,
  73.         set = function(_, v)
  74.             settings.searingPlasma.mark2Threshold = v
  75.         end,
  76.         width = 'full',
  77.         order = 88,
  78.     },
  79.     ["mark3threshold"] = {
  80.         type = "range",
  81.         name = L["High absorb threshold"],
  82.         desc = L["The threshold below which the absorb is considered high."],
  83.         max = 400000,
  84.         min = 1,
  85.         step = 500,
  86.         get = function()
  87.             return settings.searingPlasma.mark3Threshold
  88.         end,
  89.         set = function(_, v)
  90.             settings.searingPlasma.mark3Threshold = v
  91.         end,
  92.         width = 'full',
  93.         order = 89,
  94.     },
  95.     ["mark1color"] = {
  96.         type = "color",
  97.         name = L["Low absorb color"],
  98.         desc = L["Color for absorb amount below the low absorb threshold."],
  99.         order = 90,
  100.         hasAlpha = true,
  101.         get = function ()
  102.                   local color = settings.searingPlasma.mark1Color
  103.                   return color.r, color.g, color.b, color.a
  104.               end,
  105.         set = function (_, r, g, b, a)
  106.                   local color = settings.searingPlasma.mark1Color
  107.                   color.r = r
  108.                   color.g = g
  109.                   color.b = b
  110.                   color.a = a or 1
  111.               end,
  112.     },
  113.     ["mark2color"] = {
  114.         type = "color",
  115.         name = L["Medium absorb color"],
  116.         desc = L["Color for absorb amount below the medium absorb threshold."],
  117.         order = 91,
  118.         hasAlpha = true,
  119.         get = function ()
  120.                   local color = settings.searingPlasma.mark2Color
  121.                   return color.r, color.g, color.b, color.a
  122.               end,
  123.         set = function (_, r, g, b, a)
  124.                   local color = settings.searingPlasma.mark2Color
  125.                   color.r = r
  126.                   color.g = g
  127.                   color.b = b
  128.                   color.a = a or 1
  129.               end,
  130.     },
  131.     ["mark3color"] = {
  132.         type = "color",
  133.         name = L["High absorb color"],
  134.         desc = L["Color for absorb amount below the high absorb threshold."],
  135.         order = 92,
  136.         hasAlpha = true,
  137.         get = function ()
  138.                   local color = settings.searingPlasma.mark3Color
  139.                   return color.r, color.g, color.b, color.a
  140.               end,
  141.         set = function (_, r, g, b, a)
  142.                   local color = settings.searingPlasma.mark3Color
  143.                   color.r = r
  144.                   color.g = g
  145.                   color.b = b
  146.                   color.a = a or 1
  147.               end,
  148.     }, 
  149. }
  150. --}}}
  151.  
  152. local absorbUnit = {};
  153. local absorbHeal = {};
  154.  
  155. function GridStatusSearingPlasma:OnInitialize()
  156.     self.super.OnInitialize(self)    
  157.     self:RegisterStatus("searingPlasma", L["Searing Plasma"], amountOptions, true)
  158.     settings = GridStatusSearingPlasma.db.profile
  159.     settings.searingPlasma.useCombatLog = true
  160. end
  161.  
  162. function GridStatusSearingPlasma:OnStatusEnable(status)
  163.     if status == "searingPlasma" then
  164.         self:RegisterMessage("Grid_UnitJoined")
  165.         self:CombatLogParsing(true)
  166.     end
  167. end
  168.  
  169. function GridStatusSearingPlasma:OnStatusDisable(status)
  170.     if status == "searingPlasma" then
  171.         self:UnregisterMessage("Grid_UnitJoined")
  172.         self:CombatLogParsing(false)    
  173.     end
  174. end
  175.  
  176. function GridStatusSearingPlasma:CombatLogParsing(enable)
  177.     if enable then
  178.         self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  179.         self:RegisterEvent("PLAYER_REGEN_ENABLED");
  180.     else
  181.         for guid, unitid in GridRoster:IterateRoster() do
  182.             self:Clear(guid)
  183.         end
  184.         self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  185.         self:UnregisterEvent("PLAYER_REGEN_ENABLED");
  186.     end
  187. end
  188.  
  189. function GridStatusSearingPlasma:PLAYER_REGEN_ENABLED()
  190.     GridStatusSearingPlasma:Reset();
  191. end
  192.  
  193. function GridStatusSearingPlasma:Reset()
  194.     self.super.Reset(self)
  195.     absorbUnit = {}
  196.     absorbHeal = {}
  197.     for guid, unitid in GridRoster:IterateRoster() do
  198.         self:Clear(guid)
  199.     end
  200. end
  201.  
  202.  
  203. function GridStatusSearingPlasma:UseCombatLog(useCombatLog)
  204.     settings.searingPlasma.useCombatLog = useCombatLog
  205.     if not settings.searingPlasma.enable then
  206.         return
  207.     end
  208.     if settings.searingPlasma.useCombatLog == useCombatLog then
  209.         return
  210.     end
  211.     self:CombatLogParsing(true)          
  212. end
  213.  
  214. function GridStatusSearingPlasma:Print(...)
  215.     if type(...) == 'table' then
  216.         print("GridStatusSearingPlasma: "..unpack(...))
  217.     else
  218.         print("GridStatusSearingPlasma: ".. ...)
  219.     end
  220. end
  221.  
  222. function GridStatusSearingPlasma:Grid_UnitJoined(_, unitGUID, unitid)
  223.     self:Clear(unitGUID)
  224. end
  225.  
  226.  
  227. function GridStatusSearingPlasma:Clear(unitGUID)
  228.     self.core:SendStatusLost(unitGUID, "searingPlasma")
  229. end
  230.  
  231. function GridStatusSearingPlasma:FormatText(amount)
  232.     local text
  233.     if amount > 999 then
  234.         text = string.format("%d", amount/1000.0)
  235.         --shieldText = string.format("%.1fk", amount/1000.0)
  236.     else
  237.         text = string.format("%3.0f", amount)
  238.     end
  239.     return text
  240. end
  241.  
  242. function GridStatusSearingPlasma:SendAbsorbStatus(unitGUID, amount)
  243.     local color = settings.searingPlasma.color
  244.     if amount < settings.searingPlasma.mark1Threshold then
  245.         color = settings.searingPlasma.mark1Color
  246.     elseif amount < settings.searingPlasma.mark2Threshold then
  247.         color = settings.searingPlasma.mark2Color
  248.     elseif amount < settings.searingPlasma.mark3Threshold then
  249.         color = settings.searingPlasma.mark3Color
  250.     end
  251.     -- DEBUG
  252.     --self:Print("SendAbsorbStatus: " .. unitGUID .. ", " .. amount);
  253.     self.core:SendStatusGained(unitGUID, "searingPlasma",
  254.                 settings.searingPlasma.priority,
  255.                 nil,
  256.                 color,
  257.                 self:FormatText(amount))
  258. end
  259.  
  260. local function isValidSpell(id)
  261.     if id and type(id) == "number" then
  262.         for i,v in pairs(validSpells) do
  263.             if id == v then return true end
  264.         end
  265.     end
  266.     return false
  267. end
  268.  
  269. function GridStatusSearingPlasma:COMBAT_LOG_EVENT_UNFILTERED(_, timestamp, eventType, hideCaster, srcGUID, srcName, srcFlags, srcRaidFlags, dstGUID, dstName, dstFlags, dstRaidFlags, ...)  
  270.     if not GridRoster:IsGUIDInRaid(dstGUID) then
  271.         return
  272.     end
  273.     local spellId, amount, absorbed;
  274.     if eventType == "SPELL_AURA_APPLIED" or eventType == "SPELL_AURA_APPLIED_DOSE" then
  275.         spellId, _, _, _, amount = ...;
  276.         --self:Print(spellId, amount);
  277.         --self:Print(dstGUID .. " " .. spellId .. " " .. (amount or 0))
  278.         self:AddAbsorb(spellId, dstGUID, amount);
  279.     elseif eventType == "SPELL_AURA_REMOVED" then
  280.         spellId, _, _, _, amount = ...;
  281.         --self:Print(spellId, amount);
  282.         self:RemoveAbsorb(spellId, dstGUID, amount);
  283.     elseif eventType == "SPELL_HEAL" or eventType == "SPELL_PERIODIC_HEAL" then
  284.         spellId, _, _, amount, _, absorbed = ...;
  285.         --self:Print(spellId .. ", " .. amount .. ", " .. (absorbed or 0));
  286.         -- DEBUG
  287.         --self:HealAbsorb(dstGUID, amount);
  288.         self:HealAbsorb(dstGUID, absorbed);
  289.     end
  290. end
  291.  
  292. function GridStatusSearingPlasma:AddAbsorb(id, guid, amount)
  293.     -- Check valid spell
  294.     if not isValidSpell(id) then return end
  295.     -- DEBUG
  296.     --self:Print("AddAbsorb -- id: "..id .. ", amount: " .. amount)
  297.     absorbUnit[guid] = amount;
  298.     absorbHeal[guid] = 0;
  299.     self:SendAbsorbStatus(guid, amount)
  300. end
  301.  
  302. function GridStatusSearingPlasma:RemoveAbsorb(id, guid)
  303.     -- Check valid spell
  304.     if not isValidSpell(id) then return end
  305.     -- DEBUG
  306.     --self:Print("RemoveAbsorb -- id: "..id)
  307.     absorbUnit[guid] = nil;
  308.     absorbHeal[guid] = nil;
  309.     self:Clear(guid)
  310. end
  311.  
  312. function GridStatusSearingPlasma:HealAbsorb(guid, absorbed)
  313.     -- Check valid spell
  314.     -- DEBUG
  315.     --self:Print("HealAbsorb -- absorbed: ".. (absorbed or 0))
  316.     if absorbUnit[guid] then
  317.         --self:Print("HealAbsorb -- absorbUnitFound")
  318.         absorbHeal[guid] = absorbHeal[guid] + (absorbed or 0)
  319.         -- Check if remaining value
  320.         local remainder = absorbUnit[guid] - absorbHeal[guid];
  321.         if remainder and remainder > 0 then
  322.             -- DEBUG
  323.             --self:Print("HealAbsorb -- remainder: ".. remainder)
  324.             -- Update
  325.             self:SendAbsorbStatus(guid, remainder)     
  326.         elseif remainder <= 0 then
  327.             self:SendAbsorbStatus(guid, 0)
  328.         end
  329.     end
  330. end
Advertisement
Add Comment
Please, Sign In to add comment