Class: Goby::Food
Overview
Recovers HP when used.
Constant Summary
Constants inherited from Item
Instance Attribute Summary collapse
-
#recovers ⇒ Object
readonly
The amount of HP that the food recovers.
Attributes inherited from Item
#consumable, #disposable, #name, #price
Instance Method Summary collapse
-
#initialize(name: "Food", price: 0, consumable: true, disposable: true, recovers: 0) ⇒ Food
constructor
A new instance of Food.
-
#use(user, entity) ⇒ Object
Heals the entity.
Methods inherited from Item
Constructor Details
#initialize(name: "Food", price: 0, consumable: true, disposable: true, recovers: 0) ⇒ Food
Returns a new instance of Food.
13 14 15 16 |
# File 'lib/goby/item/food.rb', line 13 def initialize(name: "Food", price: 0, consumable: true, disposable: true, recovers: 0) super(name: name, price: price, consumable: consumable, disposable: disposable) @recovers = recovers end |
Instance Attribute Details
#recovers ⇒ Object (readonly)
The amount of HP that the food recovers.
45 46 47 |
# File 'lib/goby/item/food.rb', line 45 def recovers @recovers end |
Instance Method Details
#use(user, entity) ⇒ Object
Heals the entity.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/goby/item/food.rb', line 22 def use(user, entity) if entity.stats[:hp] + recovers > entity.stats[:max_hp] this_recover = entity.stats[:max_hp] - entity.stats[:hp] heal_entity(entity, entity.stats[:max_hp]) else current_hp = entity.stats[:hp] this_recover = @recovers heal_entity(entity, current_hp + this_recover) end # Helpful output. print "#{user.name} uses #{name}" if (user == entity) print " and " else print " on #{entity.name}!\n#{entity.name} " end print "recovers #{this_recover} HP!\n\n" print "#{entity.name}'s HP: #{entity.stats[:hp]}/#{entity.stats[:max_hp]}\n\n" end |