charge.lua 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. local Charge = extend(Spell)
  2. function Charge:activate()
  3. self.unit = self:getUnit()
  4. self.startx = self.unit.x
  5. self.damaged = {}
  6. ctx.event:emit('view.register', {object = self})
  7. end
  8. function Charge:deactivate()
  9. ctx.event:emit('view.unregister', {object = self})
  10. end
  11. function Charge:update()
  12. local direction = self.ability:getUnitDirection()
  13. local charging = math.abs(self.startx - self.unit.x) < self.ability.range
  14. if charging then
  15. self.unit.x = self.unit.x + direction * self.speed * ls.tickrate
  16. table.each(ctx.target:inRange(self.unit, 1, 'enemy', 'unit'), function(target)
  17. if not self.damaged[target.id] then
  18. target:hurt(self.damage)
  19. self.damaged[target.id] = true
  20. if self.ability:hasUpgrade('trample') then
  21. target.buffs:add('chargestun', {stun = self.duration, timer = self.duration})
  22. else
  23. target.buffs:add('chargeslow', {timer = self.duration, slow = self.slow})
  24. end
  25. end
  26. end)
  27. else
  28. ctx.spells:remove(self)
  29. end
  30. end
  31. function Charge:draw()
  32. -- Nothing yet
  33. end
  34. return Charge