Guest User

casting

a guest
Feb 18th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.78 KB | None | 0 0
  1. local elapsed = 0
  2.  
  3. -- dIsInSeconds is passed by custom clients if they want to save on maths
  4. -- dontRegister is passed by custom clients if they need to call Stop/Failed/Delayed manually
  5. function oCB:SpellStart(s, d, dIsInSeconds, dontRegister)
  6.     self:Debug(string.format("SpellStart - %s | %s (%s)%s", s, d, dIsInSeconds and "s" or "ms", dontRegister and " | Not Registering" or ""))
  7.    
  8.     if not dontRegister then
  9.         self:RegisterEvent("SPELLCAST_STOP", "SpellStop")
  10.         self:RegisterEvent("SPELLCAST_INTERRUPTED","SpellFailed")
  11.         self:RegisterEvent("SPELLCAST_FAILED", "SpellFailed")
  12.         self:RegisterEvent("SPELLCAST_DELAYED", "SpellDelayed")
  13.     end
  14.    
  15.     local c = self.db.profile.Colors.Casting
  16.        
  17.     self.startTime = GetTime()
  18.    
  19.     if not dIsInSeconds then
  20.         d = d/1000
  21.     end
  22.     self.maxValue = self.startTime + d
  23.    
  24.     self.frames.CastingBar.Bar:SetStatusBarColor(c.r, c.g, c.b)
  25.     self.frames.CastingBar.Bar:SetMinMaxValues(1, 100)
  26.     self.frames.CastingBar.Bar:SetValue(1)
  27.     self.frames.CastingBar.Spell:SetText(s)
  28.     self.frames.CastingBar:SetAlpha(1)
  29.     self.frames.CastingBar.Time:SetText("")
  30.     self.frames.CastingBar.Delay:SetText("")
  31.        
  32.     self.holdTime   = 0
  33.     self.delay      = 0
  34.     self.casting        = 1
  35.     self.fadeOut    = nil
  36.    
  37.     self.frames.CastingBar:Show()
  38.     self.frames.CastingBar.Spark:Show()
  39. end
  40.  
  41. -- Arg is for custom clients
  42. function oCB:SpellStop(dontUnregister)
  43.     self:Debug("SpellStop - Stopping cast")    
  44.     local c = self.db.profile.Colors.Complete
  45.    
  46.     self.frames.CastingBar.Bar:SetValue(100)
  47.    
  48.     if not self.channeling then
  49.         self.frames.CastingBar.Bar:SetStatusBarColor(c.r, c.g, c.b)
  50.         self.frames.CastingBar.Spark:Hide()
  51.     end
  52.    
  53.     self.delay      = 0
  54.     self.casting        = nil
  55.     self.fadeOut    = 1
  56.    
  57.     if not dontUnregister then
  58.         self:UnregisterEvent("SPELLCAST_STOP")
  59.         self:UnregisterEvent("SPELLCAST_FAILED")
  60.         self:UnregisterEvent("SPELLCAST_INTERRUPTED")
  61.         self:UnregisterEvent("SPELLCAST_DELAYED")
  62.     end
  63. end
  64.  
  65. function oCB:SpellFailed(dontUnregister)
  66.     local c = self.db.profile.Colors.Failed
  67.  
  68.     self.frames.CastingBar.Bar:SetValue(100)
  69.     self.frames.CastingBar.Bar:SetStatusBarColor(c.r, c.g, c.b)
  70.     self.frames.CastingBar.Spark:Hide()
  71.    
  72.     if (event == "SPELLCAST_FAILED") then
  73.         self.frames.CastingBar.Spell:SetText(FAILED)
  74.     else
  75.         self.frames.CastingBar.Spell:SetText(INTERRUPTED)
  76.     end
  77.    
  78.     self.casting        = nil
  79.     self.channeling     = nil
  80.     self.fadeOut    = 1
  81.     self.holdTime = GetTime() + 1
  82.    
  83.     if not dontUnregister then
  84.         self:UnregisterEvent("SPELLCAST_STOP")
  85.         self:UnregisterEvent("SPELLCAST_FAILED")
  86.         self:UnregisterEvent("SPELLCAST_INTERRUPTED")
  87.         self:UnregisterEvent("SPELLCAST_DELAYED")
  88.     end
  89. end
  90.  
  91. function oCB:SpellDelayed(d)
  92.     self:Debug(string.format("SpellDelayed - Spell delayed with %s", d/1000))
  93.     d = d / 1000
  94.    
  95.     if(self.frames.CastingBar:IsShown()) then
  96.         if self.delay == nil then self.delay = 0 end
  97.        
  98.         self.startTime = self.startTime + d
  99.         self.maxValue = self.maxValue + d
  100.         self.delay = self.delay + d
  101.        
  102.         self.frames.CastingBar.Bar:SetMinMaxValues(1, 100)
  103.     end
  104. end
  105.  
  106. function oCB:SpellChannelStart(d)
  107.     self:Debug("SpellChannelStart - Starting channel")
  108.     d = d / 1000
  109.     local c = self.db.profile.Colors.Channel
  110.    
  111.     self.startTime = GetTime()
  112.     self.endTime = self.startTime + d
  113.     self.maxValue = self.endTime
  114.    
  115.     self.frames.CastingBar.Bar:SetStatusBarColor(c.r, c.g, c.b)
  116.     self.frames.CastingBar.Bar:SetMinMaxValues(1, 100)
  117.     self.frames.CastingBar.Bar:SetValue(1)
  118.     self.frames.CastingBar.Spell:SetText(arg2)
  119.     self.frames.CastingBar.Time:SetText("")
  120.     self.frames.CastingBar.Delay:SetText("")
  121.     self.frames.CastingBar:SetAlpha(1)
  122.    
  123.     self.holdTime   = 0
  124.     self.casting        = nil
  125.     self.channeling     = 1
  126.     self.fadeOut    = nil
  127.    
  128.     self.frames.CastingBar:Show()
  129.     self.frames.CastingBar.Spark:Show()
  130. end
  131.  
  132. function oCB:SpellChannelStop()
  133.     self:Debug("SpellChannelStop - Stopping channel")
  134.     if not self.channeling then return end
  135.     local c = self.db.profile.Colors.Complete
  136.    
  137.     self.frames.CastingBar.Bar:SetValue(100)
  138.     self.frames.CastingBar.Bar:SetStatusBarColor(c.r, c.g, c.b)
  139.     self.frames.CastingBar.Spark:Hide()
  140.    
  141.     self.delay = 0
  142.     self.casting = nil
  143.     self.channeling = nil
  144.     self.fadeOut = 1
  145. end
  146.  
  147. function oCB:SpellChannelUpdate(d)
  148.     self:Debug("SpellChannelUpdate - Updating channel")
  149.     d = d / 1000
  150.    
  151.     if(self.frames.CastingBar:IsShown()) then
  152.         local origDuration = self.endTime - self.startTime
  153.        
  154.         if self.delay == nil then self.delay = 0 end
  155.        
  156.         self.delay = self.delay + d
  157.         self.endTime = GetTime() + d
  158.         self.maxValue = self.endTime
  159.         self.startTime = self.endTime - origDuration
  160.        
  161.         self.frames.CastingBar.Bar:SetMinMaxValues(1,100)
  162.     end
  163. end
  164.  
  165. function oCB:OnCasting()
  166.     elapsed= elapsed + arg1
  167.     if(oCB.casting) then
  168.         local delay, n, sp = false, GetTime(), 0
  169.        
  170.         if ( n > oCB.maxValue ) then n = oCB.maxValue end
  171.        
  172.         oCB.frames.CastingBar.Time:SetText(string.format( "%.1f", math.max(oCB.maxValue - n, 0.0)))
  173.        
  174.         if (oCB.delay ~= 0) then delay = 1 end
  175.         if (delay) then
  176.             oCB.frames.CastingBar.Delay:SetText("+"..string.format("%.1f", oCB.delay or "" ))
  177.         else
  178.             oCB.frames.CastingBar.Delay:SetText("")
  179.         end
  180.        
  181.         local np = ((n - oCB.startTime) / (oCB.maxValue - oCB.startTime)) * 100
  182.         oCB.frames.CastingBar.Bar:SetValue(np)
  183.        
  184.         local w = oCB.frames.CastingBar.Bar:GetWidth()
  185.         sp = ((n - oCB.startTime) / (oCB.maxValue - oCB.startTime)) * w
  186.         if( sp < 0 ) then sp = 0 end
  187.        
  188.         oCB.frames.CastingBar.Spark:SetPoint("CENTER", oCB.frames.CastingBar.Bar, "LEFT", sp, 0)
  189.     elseif (oCB.channeling) then
  190.         local delay, n, sp = false, GetTime(), 0
  191.        
  192.         if (n > oCB.endTime) then n = oCB.endTime end
  193.         if (n == oCB.endTime) then
  194.             oCB.channeling = nil
  195.             oCB.fadeOut = 1
  196.             return
  197.         end
  198.  
  199.         local b = oCB.startTime + (oCB.endTime - n)
  200.        
  201.         oCB.frames.CastingBar.Time:SetText(string.format( "%.1f", math.max(oCB.maxValue - n, 0.0)))
  202.        
  203.         if (oCB.delay and oCB.delay ~= 0) then delay = 1 end
  204.         if (delay) then
  205.             oCB.frames.CastingBar.Delay:SetText("-"..string.format("%.1f", oCB.delay ))
  206.         else
  207.             oCB.frames.CastingBar.Delay:SetText("")
  208.         end
  209.        
  210.         local bp = (b-oCB.startTime) / (oCB.endTime - oCB.startTime) * 100
  211.         oCB.frames.CastingBar.Bar:SetValue(bp)
  212.        
  213.         local w = oCB.frames.CastingBar.Bar:GetWidth()
  214.         sp = ((b - oCB.startTime) / (oCB.endTime - oCB.startTime)) * w
  215.        
  216.         oCB.frames.CastingBar.Spark:SetPoint("CENTER", oCB.frames.CastingBar.Bar, "LEFT", sp, 0)
  217.     elseif(GetTime() < oCB.holdTime) then
  218.         return
  219.     elseif(oCB.fadeOut) then
  220.         local a = this:GetAlpha() - .05
  221.        
  222.         if (a > 0) then
  223.             oCB.frames.CastingBar:SetAlpha(a)
  224.         else
  225.             oCB.fadeOut = nil
  226.             oCB.frames.CastingBar:Hide()
  227.             oCB.frames.CastingBar.Time:SetText("")
  228.             oCB.frames.CastingBar.Delay:SetText("")
  229.             oCB.frames.CastingBar:SetAlpha(1)
  230.         end
  231.     end
  232. end
Add Comment
Please, Sign In to add comment