ambush.lua 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. local Ambush = extend(Ability)
  2. Ambush.cooldown = 8
  3. Ambush.damage = 50
  4. Ambush.spiritRatio = 1
  5. function Ambush:activate()
  6. self.target = nil
  7. self.unit.animation:on('event', function(event)
  8. if event.data.name == 'vanish' then
  9. local target = ctx.target:closest(self.unit, 'enemy', 'unit')
  10. if target then
  11. self.unit.x = target.x - (target.animation.flipped and -1 or 1) * (self.unit.width / 2)
  12. self.unit.target = target
  13. self.unit.animation:set('rend', {force = true})
  14. self.target = target
  15. end
  16. self.unit.untargetable = false
  17. self.unit.casting = false
  18. elseif event.data.name == 'rend' and self.target then
  19. if self.target then
  20. local damage = self.damage + self.spiritRatio * self.unit.spirit
  21. self.target:hurt(damage, self.unit, {})
  22. end
  23. end
  24. end)
  25. end
  26. function Ambush:update()
  27. if ctx.player.dead and self.timer == 0 then
  28. self.timer = self.cooldown
  29. self:fire()
  30. end
  31. end
  32. function Ambush:fire()
  33. self.unit.animation:set('vanish')
  34. self.unit.untargetable = true
  35. self.unit.casting = true
  36. end
  37. function Ambush:bonuses()
  38. local bonuses = {}
  39. local spirit = Unit.getStat('xuju', 'spirit')
  40. if spirit > 0 then
  41. table.insert(bonuses, {'Spirit', math.round(spirit * self.spiritRatio), 'damage'})
  42. end
  43. return bonuses
  44. end
  45. return Ambush