nowmax.rb 615 B

123456789101112131415161718192021222324252627282930313233
  1. script 'model/nowvalue'
  2. # Nowmax is a class used to model values that have a current value "now" and
  3. # a maximum value "max", such as HP, NP, etc...
  4. # 0 is considered the minimum value for each of these
  5. class Nowmax
  6. include Nowvalue
  7. attr_reader :max
  8. def initalize(n, m)
  9. super(n)
  10. @max = m
  11. end
  12. # Clamps value between 0 and max
  13. def clamp(value)
  14. return @max if value > @max
  15. return 0 if value < 0
  16. return value
  17. end
  18. # Makes a new Nowmax value with the given value and self.max as maximum.
  19. def make(value)
  20. return self.class.new(clamp(value), self.max)
  21. end
  22. end