Advertisement
Guest User

main.lua fixed 1.2

a guest
Aug 5th, 2014
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.01 KB | None | 0 0
  1. --[[ Version: 1.2
  2.  
  3.     This is based on "AffDots Mage r3" and has been modified by Hendrikto to contain fixes to make the module work properly for Arcane Mages.
  4.     Nothing has been changed except for what is clearly indicated in the source code. I don't take credit for any code I have not written myself.
  5.     The module was originally developed by "Xab3r".
  6.    
  7.     1.0:
  8.     + added:
  9.         + Rune of Power tracking
  10.         + Mastery: Mana Adept tracking
  11.    
  12.     1.1:
  13.     + fixed:
  14.         + Mastery will now be ignored for non Arcane Mages
  15.        
  16.     1.2:
  17.     + changed:
  18.         + Dot strength will be calculated on every Combat Log Event to track Mana Adept more accurately
  19. ]]
  20.  
  21. local o
  22. local me, spec
  23. local protect = 1
  24. local timer, throttle       = 0, 0.1
  25. local dot_damage, targets   = AffDots.dot_damage, AffDots.targets
  26. local dot_damage_ext = { }
  27. local durSaved = { }
  28. local dot_ticks = { }
  29.  
  30. function onUpdate(self,elapsed)
  31.     timer = timer + elapsed;
  32.     if timer >= throttle then
  33.         for k,v in pairs(AffDots.track) do
  34.             AffDots.track[k].update(AffDots.track[k])
  35.             AffDots:FrameDraw(AffDots.track[k])
  36.         end
  37.         if o.tidyplates.enable and TidyPlates then AffDots:Tidy() end
  38.         timer = 0
  39.     end
  40. end
  41.  
  42. local dotSpells = {
  43.     lb  =
  44.     {
  45.         Id = 44457,
  46.         Info = GetSpellInfo(44457),
  47.         InitialTicksCount = 4,
  48.         InitialDuration = 12,
  49.         RawTickDmg =  function ( spd)
  50.             return 1072+spd*0.8036
  51.         end,
  52.         ExistsInCurrentSpec = function()
  53.             local _,_,_,_,selected = GetTalentInfo(14)
  54.             return selected
  55.         end
  56.     }, -- Living Bomb
  57.     nt  =
  58.     {
  59.         Id = 114923,
  60.         Info = GetSpellInfo(114923),
  61.         InitialTicksCount = 12,
  62.         InitialDuration = 12,
  63.         RawTickDmg =  function ( spd)
  64.             return 325+spd*0.2436
  65.         end,
  66.         ExistsInCurrentSpec = function()
  67.             local _,_,_,_,selected = GetTalentInfo(13)
  68.             return selected
  69.         end
  70.     }, -- Nether Tempest
  71. }
  72.  
  73. local buffSpells = {
  74.     invocationBuff = {Id = 116257, Info = GetSpellInfo(116257), Dmg = 0.15},
  75.     ropBuff = {Id = 116011, Info = GetSpellInfo(116011), Dmg = 0.15} -- Hendrikto: fixed RoP
  76. }
  77.  
  78.  
  79.  
  80. local function GetDmgBuffsUpdate()
  81.     local dmg_buff = 1
  82.     for k,v in pairs(buffSpells) do
  83.         local auraInfo = UnitBuff("player", v.Info, nil)
  84.         if (auraInfo) then  dmg_buff = dmg_buff + v.Dmg  end
  85.     end
  86.     if spec == 1 then dmg_buff = dmg_buff + ((GetMasteryEffect() / 100) * (UnitMana("Player") / UnitManaMax("Player"))) end -- Hendrikto: fixed Mana Adept
  87.     --print("DmgBuff "..dmg_buff)
  88.     return dmg_buff
  89. end
  90.  
  91. local function Round(num) return math.floor(num+.5) end
  92. local function SecondsRound(num)
  93.     if num > 2 then return math.floor(num+.5)
  94.     else return math.floor(num*10+.5)/10 end
  95. end
  96.  
  97. function AffDots:FindColor(GUID,time_left,spell,pandemic)          
  98.     if not targets[GUID..spell] or not dot_damage[spell] then
  99.         return 7
  100.     end
  101.     local current       = dot_damage[spell][1]
  102.     local on_target     = targets[GUID..spell][1]
  103.     if      on_target  < current then color = 1
  104.     elseif  on_target == current then color = 2
  105.     elseif  on_target  > current then color = 6
  106.     end
  107.     return color
  108. end
  109.  
  110. AffDots.Update = {
  111.     dot = function(f)
  112.         local guid = UnitGUID(f.target)
  113.         local _,_,_,_,_,duration,expires = UnitDebuff(f.target,f.name,f.rank,"player")
  114.         if duration and guid and targets[guid..f.spell] then
  115.             if(math.abs(expires-f.timer)>1) then
  116.                 f.datanew.expires = expires
  117.                 f.datanew.duration = duration
  118.                 f.datanew.setcd = true
  119.                 f.timer = expires
  120.             end
  121.             f.datanew.color = o["color"..AffDots:FindColor(guid,expires - GetTime(),f.spell,f.pandemic)]
  122.             f.datanew.tick = targets[guid..f.spell][3]
  123.             f.datanew.t2 = SecondsRound(f.timer-GetTime())
  124.             local spellText = Round(dot_damage[f.spell][1]*100/targets[guid..f.spell][1]).."%"
  125.             f.datanew.t1 = spellText
  126.         else
  127.             f.datanew.color = o.color7
  128.             f.datanew.t1 = 0
  129.             f.datanew.t2 = ""
  130.             f.datanew.tick = 0
  131.             f.timer = 0
  132.             f.datanew.hidecd = true
  133.         end
  134.     end,
  135. }
  136. local GetDotDmgFunc = function()
  137.         haste, crit, spd = UnitSpellHaste("player"), GetSpellCritChance(6), GetSpellBonusDamage(6)
  138.         if crit > 100 then crit = 100 end
  139.         critDamageBonus     = (1+crit/100)
  140.  
  141.         dmgBuff = GetDmgBuffsUpdate()
  142.         for k,v in pairs(dotSpells) do
  143.  
  144.             tick_every          = v.InitialTicksCount/(1+(haste/100))
  145.             ticks               = Round(v.InitialDuration/tick_every)
  146.             duration            = ticks * tick_every           
  147.             dmgPerTick          = v.RawTickDmg(spd)
  148.             totalDamage         = dmgPerTick*ticks*critDamageBonus*dmgBuff
  149.             dps                 = Round(totalDamage/duration)
  150.             dot_damage[v.Id]        = {dps, tick_every, duration, ticks}
  151.             --print( string.format("%s: dmg=%f; perTick=%f",v.Info, totalDamage, dmgPerTick))
  152.         end
  153.     end
  154.  
  155. local function GetDotDur(arg1)
  156.     local spellname = GetSpellInfo(arg1)
  157.     local duration =    select(6, UnitAura("target", spellname, nil, "PLAYER|HARMFUL")) or 0
  158.     local expiration =  select(7, UnitAura("target", spellname, nil, "PLAYER|HARMFUL")) or GetTime()
  159.            
  160.     local testtime = expiration-duration
  161.    
  162.     return duration, expiration, testtime
  163. end
  164.  
  165. local function GetDotTicks(spellID, destGUID)
  166.    
  167.     if dot_ticks[destGUID..""..spellID] and dot_ticks[destGUID..""..spellID] == 0 then
  168.         return true
  169.     else
  170.         return false
  171.     end
  172. end
  173.  
  174. local function RemoveDotTic(spellID, destGUID)
  175.     if dot_ticks[destGUID..""..spellID] and dot_ticks[destGUID..""..spellID] > 0 then
  176.         dot_ticks[destGUID..""..spellID] = dot_ticks[destGUID..""..spellID] - 1
  177.     end
  178. end
  179.  
  180. local CombatLogFunc = function(_,_,_,event_type,_,source_GUID,_,_,_,dest_GUID,_,_,_, ...)      
  181.         spellId = select(1, ...)
  182.         --[[ Hendrikto: fixed Mana Adept
  183.         if dest_GUID == UnitGUID("player") and spellId == 137590 then
  184.             AffDots:GetDotDmg()
  185.         end
  186.         --]]
  187.         AffDots:GetDotDmg() -- Hendrikto: fixed Mana Adept
  188.         if source_GUID ~= me then return end
  189.  
  190.         local spellMustBeProcessed = false
  191.         for k,v in pairs(dotSpells) do
  192.             if v.Id == spellId then
  193.                 spellMustBeProcessed = true
  194.                 break
  195.             end
  196.         end
  197.  
  198.         if event_type == "SPELL_SUMMON" then
  199.             saGUID[dest_GUID] = me
  200.         end
  201.  
  202.         if (spellMustBeProcessed) then
  203.             if (event_type == "SPELL_AURA_APPLIED" or (event_type == "SPELL_AURA_REFRESH" and  GetTime() - protect > 0.5)) then
  204.                 if UnitGUID("target") ==  dest_GUID then
  205.                     durSaved[dest_GUID..spellId] = { select(2, GetDotDur(spellId)), GetSpellBonusDamage(6), GetDmgBuffsUpdate() }
  206.                 else
  207.                     durSaved[dest_GUID..spellId] = { dot_damage[spellId][2] , GetSpellBonusDamage(6), GetDmgBuffsUpdate() }
  208.                 end
  209.                 targets[dest_GUID..spellId] = {dot_damage[spellId][1],GetTime(),dot_damage[spellId][2]}
  210.                 dot_ticks[dest_GUID..spellId] = dot_damage[spellId][4]
  211.             elseif event_type == "SPELL_DAMAGE" then
  212.                 protect = GetTime()
  213.             elseif event_type == "SPELL_PERIODIC_DAMAGE" then
  214.                 RemoveDotTic(spellId, dest_GUID)
  215.             end
  216.         end
  217.  
  218.     end
  219.        
  220.  
  221.  
  222. function AffDots:InitSpec()
  223.     AffDots:ReleaseFrames()
  224.     wipe(AffDots.track)
  225.    
  226.     AffDots.execute_percent = 0
  227.     local index = 0
  228.     for k,v in pairs(dotSpells) do
  229.         if (v.ExistsInCurrentSpec()) then
  230.             AffDots:Track( v.Id, AffDots.Update.dot, "target",   v.InitialDuration,  0, index,  true)
  231.             index = index + 1
  232.         end
  233.     end
  234.     AffDots:InitFrames()
  235. end
  236.  
  237. function AffDots:InitClass()
  238.     AffDots:RegisterEvent("PLAYER_TALENT_UPDATE", "InitClass")
  239.     me = UnitGUID("player")
  240.     o = self.db.profile
  241.     AffDots:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  242.     AffDots:UnregisterEvent("COMBAT_RATING_UPDATE")
  243.     AffDots:UnregisterEvent("SPELL_POWER_CHANGED")
  244.     AffDots:UnregisterEvent("UNIT_STATS")
  245.     AffDots:UnregisterEvent("PLAYER_DAMAGE_DONE_MODS")
  246.     AffDots:UnregisterEvent("PLAYER_REGEN_ENABLED")
  247.     AffDots:UnregisterEvent("PLAYER_REGEN_DISABLED")
  248.     AffDots:UnregisterEvent("PLAYER_FOCUS_CHANGED")
  249.     AffDots:UnregisterEvent("MODIFIER_STATE_CHANGED")
  250.     AffDotsTarget:SetScript("OnUpdate", nil)
  251.     AffDotsTarget:Hide(); AffDotsFocus:Hide(); AffDotsBurst:Hide()
  252.     spec = GetSpecialization() or ""
  253.     o = self.db.profile
  254.     AffDots.GetDotDmg = GetDotDmgFunc
  255.     AffDots.CombatLog = CombatLogFunc
  256.     AffDots:GetDotDmg()
  257.     AffDots:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED", "CombatLog")
  258.     --[[ Hendrikto: fixed Mana Adept
  259.     AffDots:RegisterEvent("COMBAT_RATING_UPDATE", "GetDotDmg")
  260.     AffDots:RegisterEvent("SPELL_POWER_CHANGED", "GetDotDmg")
  261.     AffDots:RegisterEvent("UNIT_STATS", "GetDotDmg")
  262.     AffDots:RegisterEvent("PLAYER_DAMAGE_DONE_MODS", "GetDotDmg")
  263.     AffDots:RegisterEvent("UNIT_SPELL_HASTE", "GetDotDmg")
  264.     AffDots:RegisterEvent("PLAYER_AURAS_CHANGED", "GetDotDmg")
  265.     --]]
  266.     AffDots:RegisterEvent("PLAYER_REGEN_ENABLED")
  267.     AffDots:RegisterEvent("PLAYER_REGEN_DISABLED")
  268.     AffDots:RegisterEvent("PLAYER_FOCUS_CHANGED")
  269.     AffDots:RegisterEvent("MODIFIER_STATE_CHANGED")
  270.     AffDotsTarget:SetScript("OnUpdate", onUpdate)
  271.     AffDots:InitSpec()
  272. end
  273.  
  274. function AffDots:GetSpecOptions(spec)
  275.     if string.match(spec,"MAGE") then  
  276.             self.options.args.spec.name = "Mage"
  277.             self.options.args.spec.args = {
  278.             spacer1 = {
  279.                 order = 1,type = "description",name="You are "..spec, width="full",
  280.             },
  281.         }
  282.         AffDots:InitClass()
  283.     else   
  284.         self.options.args.spec.name = "Specialization"
  285.         self.options.args.spec.args = {
  286.             spacer1 = {
  287.                 order = 1,type = "description",name="You are not mage", width="full",
  288.             },
  289.         }
  290.     end
  291. end
  292.  
  293.  
  294. function AffDots:OnEnable()
  295.     AffDots:InitClass()
  296. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement