headbutt.lua 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. local Headbutt = extend(Ability)
  2. ----------------
  3. -- Data
  4. ----------------
  5. Headbutt.cooldown = 5
  6. Headbutt.knockbackDistance = 100
  7. Headbutt.damageModifier = 1.25
  8. ----------------
  9. -- Behavior
  10. ----------------
  11. function Headbutt:activate()
  12. self.unit.animation:on('event', function(event)
  13. if event.data.name == 'headbutt' then
  14. local targets = ctx.target:inRange(self.unit, self.unit.width / 2 + 32, 'enemy', 'unit', 'player')
  15. local count = table.count(targets)
  16. local damage = (self.unit.damage * self.damageModifier) / count
  17. table.each(targets, function(target)
  18. if math.sign(target.x - self.unit.x) == self:getUnitDirection() then
  19. if isa(target, Unit) and target.buffs then target.buffs:add('headbutt', {offset = self.knockbackDistance * self:getUnitDirection()}) end
  20. target:hurt(damage, self.unit, {'spell'})
  21. end
  22. end)
  23. if self.unit.target then
  24. local x, y = self.unit:attackParticlePosition(self.unit.target)
  25. ctx.particles:emit(self.unit.class.code .. 'attack', x, y, self.unit.class.attackParticleCount or 5)
  26. end
  27. end
  28. end)
  29. end
  30. function Headbutt:use()
  31. if self.unit.target and isa(self.unit.target, Unit) then
  32. self.unit.animation:set('headbutt')
  33. self.unit.casting = true
  34. self.timer = self.cooldown
  35. end
  36. end
  37. return Headbutt