frostbite.lua 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. local Frostbite = extend(Spell)
  2. local g = love.graphics
  3. function Frostbite:activate()
  4. local ability, unit = self:getAbility(), self:getUnit()
  5. local level = unit:upgradeLevel('frostbite')
  6. self.timer = 2 + level
  7. self.dps = 2 + 2 * level + ability.runeDamage
  8. self.y = ctx.map.height - ctx.map.groundHeight
  9. self.team = unit.team
  10. self.tundra = unit:upgradeLevel('tundra') > 0
  11. self.width = 125 * (self.tundra and 1.5 or 1) * (1 + ability.runeSize)
  12. self.threshold = self.timer - 1
  13. self.damages = {}
  14. self.dead = false
  15. self.alpha = 1
  16. self.prevAlpha = self.alpha
  17. ctx.sound:play(data.media.sounds.kuju.frostbite)
  18. ctx.event:emit('view.register', {object = self})
  19. end
  20. function Frostbite:deactivate()
  21. ctx.event:emit('view.unregister', {object = self})
  22. end
  23. function Frostbite:update()
  24. local ability, unit = self:getAbility(), self:getUnit()
  25. if self.dead then
  26. self.prevAlpha = self.alpha
  27. self.alpha = self.alpha - ls.tickrate
  28. if self.alpha <= 0 then ctx.spells:remove(self) end
  29. return
  30. end
  31. self.timer = self.timer - ls.tickrate
  32. if self.timer < self.threshold then
  33. local touched = {}
  34. local targets = ctx.target:inRange(self, self.width / 2, 'enemy', 'unit')
  35. table.each(targets, function(target)
  36. self.damages[target.viewId] = (self.damages[target.viewId] or 0) + self.dps
  37. touched[target.viewId] = true
  38. target:hurt(self.damages[target.viewId], unit, {'spell'})
  39. ctx.particles:emit('frostbite', target.x, self.y, 4)
  40. if unit:upgradeLevel('brainfreeze') > 0 then
  41. target.buffs:add('brainfreeze', {timer = 1})
  42. end
  43. local wintersblight = unit:upgradeLevel('wintersblight')
  44. if wintersblight > 0 then
  45. target:hurt(target.health * (.08 * wintersblight), unit, {'spell'})
  46. end
  47. end)
  48. if #targets > 0 then
  49. ctx.sound:play(data.media.sounds.kuju.frostbitetick)
  50. end
  51. for k, v in pairs(self.damages) do
  52. if not touched[k] then
  53. self.damages[k] = nil
  54. end
  55. end
  56. if self.threshold > 0 then self.threshold = self.threshold - 1
  57. else self.dead = true end
  58. end
  59. end
  60. function Frostbite:draw()
  61. local image = data.media.graphics.spell.frostbite
  62. local scale = self.width / image:getWidth()
  63. g.setColor(255, 255, 255, math.lerp(self.prevAlpha, self.alpha, ls.accum / ls.tickrate) * 255)
  64. g.draw(image, self.x, self.y, 0, scale, scale, image:getWidth() / 2, image:getHeight() - 20)
  65. end
  66. return Frostbite