tenacity.lua 956 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. local Tenacity = {}
  2. ----------------
  3. -- Meta
  4. ----------------
  5. Tenacity.name = 'Tenacity'
  6. Tenacity.code = 'tenacity'
  7. Tenacity.text = 'Wrexx gains lifesteal based on missing health.'
  8. Tenacity.type = 'passive'
  9. ----------------
  10. -- Behavior
  11. ----------------
  12. function Tenacity:activate(owner)
  13. --
  14. end
  15. function Tenacity:update(owner)
  16. local enemies = 0
  17. ctx.players:each(function(p)
  18. if p.team ~= owner.team and math.distance(p.x, p.y, owner.x, owner.y) < 300 then
  19. enemies = enemies + 1
  20. end
  21. end)
  22. local buff = ctx.buffs:get(owner, 'tenacity')
  23. if not buff and enemies == 0 then return end
  24. if not buff then
  25. buff = ctx.buffs:add(owner, 'tenacity')
  26. end
  27. if enemies > buff.stacks then
  28. for i = 1, enemies - buff.stacks do
  29. ctx.buffs:add(owner, 'tenacity')
  30. end
  31. elseif enemies < buff.stacks then
  32. for i = 1, buff.stacks - enemies do
  33. ctx.buffs:remove(owner, 'tenacity', true)
  34. end
  35. end
  36. end
  37. return Tenacity