ability.lua 743 B

12345678910111213141516171819202122232425262728293031323334353637
  1. local ability = {}
  2. function ability:getColor()
  3. return { 255, 255, 255 }
  4. end
  5. function ability:getCost()
  6. return self.cost
  7. end
  8. function ability:canPayJuju()
  9. return app.context.objects.muju.juju >= self:getCost()
  10. end
  11. function ability:payJuju()
  12. if self:canPayJuju() then
  13. app.context.objects.muju:spendJuju(self:getCost())
  14. return true
  15. end
  16. return false
  17. end
  18. function ability:getCooldown()
  19. return self.cooldown
  20. end
  21. function ability:isOnCooldown()
  22. return self:getCooldown() and self:timeUntilReady() > 0
  23. end
  24. function ability:timeUntilReady()
  25. if not self.lastCast or not self:getCooldown() then return 0 end
  26. return math.max(self:getCooldown() - (lib.tick.index - self.lastCast) * lib.tick.rate, 0)
  27. end
  28. return ability