Advertisement
Guest User

BuffExplorer

a guest
Mar 6th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.53 KB | None | 0 0
  1. --[[Buff Type]]
  2.  
  3. _G.BUFF_NONE = 0
  4. _G.BUFF_GLOBAL = 1
  5. _G.BUFF_BASIC = 2
  6. _G.BUFF_DEBUFF = 3
  7. _G.BUFF_STUN = 5
  8. _G.BUFF_STEALTH = 6
  9. _G.BUFF_SILENCE = 7
  10. _G.BUFF_TAUNT = 8
  11. _G.BUFF_SLOW = 10
  12. _G.BUFF_ROOT = 11
  13. _G.BUFF_DOT = 12
  14. _G.BUFF_REGENERATION = 13
  15. _G.BUFF_SPEED = 14
  16. _G.BUFF_MAGIC_IMMUNE = 15
  17. _G.BUFF_PHYSICAL_IMMUNE = 16
  18. _G.BUFF_IMMUNE = 17
  19. _G.BUFF_Vision_Reduce = 19
  20. _G.BUFF_FEAR = 21
  21. _G.BUFF_CHARM = 22
  22. _G.BUFF_POISON = 23
  23. _G.BUFF_SUPPRESS = 24
  24. _G.BUFF_BLIND = 25
  25. _G.BUFF_STATS_INCREASE = 26
  26. _G.BUFF_STATS_DECREASE = 27
  27. _G.BUFF_FLEE = 28
  28. _G.BUFF_KNOCKUP = 29
  29. _G.BUFF_KNOCKBACK = 30
  30. _G.BUFF_DISARM = 31
  31.  
  32.   class 'BuffExplorer'
  33.    
  34.    
  35.    
  36.     function BuffExplorer:__init()
  37.         __BuffExplorer = true
  38.         self.Heroes = {}
  39.         self.Buffs  = {}
  40.         self.RemoveBuffCallback = {}
  41.         self.UpdateBuffCallback = {}
  42.         for i = 1, Game.HeroCount() do
  43.             local hero = Game.Hero(i)
  44.             table.insert(self.Heroes, hero)
  45.             self.Buffs[hero.networkID] = {}
  46.         end
  47.         Callback.Add("Tick", function () self:Tick() end)
  48.         print("BuffExplorer Loaded")
  49.     end
  50.  
  51.     function BuffExplorer:RemoveBuff(unit,buff)
  52.         for i, cb in pairs(self.RemoveBuffCallback) do
  53.             cb(unit,buff)
  54.         end
  55.     end
  56.    
  57.     function BuffExplorer:UpdateBuff(unit,buff)
  58.         for i, cb in pairs(self.UpdateBuffCallback) do
  59.             cb(unit,buff)
  60.         end
  61.     end
  62.    
  63.     function BuffExplorer:Tick()
  64.         for _, hero in pairs(self.Heroes) do
  65.             for i = 0, hero.buffCount do
  66.                 local buff = hero:GetBuff(i)
  67.                 if self:Valid(buff) then
  68.                     if not self.Buffs[hero.networkID][buff.name] or (self.Buffs[hero.networkID][buff.name] and self.Buffs[hero.networkID][buff.name].expireTime ~= buff.expireTime) then
  69.                         self.Buffs[hero.networkID][buff.name] = {expireTime = buff.expireTime, sent = true, networkID = buff.sourcenID, buff = buff}
  70.                         self:UpdateBuff(hero,buff)
  71.                     end
  72.                 end
  73.             end
  74.         end
  75.         for _, hero in pairs(self.Heroes) do
  76.             for buffname,buffinfo in pairs(self.Buffs[hero.networkID]) do
  77.                 if buffinfo.expireTime < Game.Timer() then
  78.                     self:RemoveBuff(hero,buffinfo.buff)
  79.                     self.Buffs[hero.networkID][buffname] = nil
  80.                    
  81.                 end
  82.             end
  83.         end
  84.     end
  85.    
  86.     function BuffExplorer:Valid(buff)
  87.         return buff and buff.name and #buff.name > 0 and buff.startTime <= Game.Timer() and buff.expireTime > Game.Timer()
  88.     end
  89.  
  90.  
  91.     if not __BuffExplorer_Loaded then  
  92.         _G.BuffExplorer = BuffExplorer()
  93.     end
  94.    
  95.     OnUpdateBuff = function(cb)
  96.         table.insert(BuffExplorer.UpdateBuffCallback,cb)
  97.     end
  98.     OnRemoveBuff = function(cb)
  99.         table.insert(BuffExplorer.RemoveBuffCallback,cb)
  100.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement