Class: Goby::Use
- Inherits:
-
BattleCommand
- Object
- BattleCommand
- Goby::Use
- Defined in:
- lib/goby/battle/use.rb
Overview
Allows an Entity to use an Item in battle.
Constant Summary
Constants inherited from BattleCommand
Instance Attribute Summary
Attributes inherited from BattleCommand
Instance Method Summary collapse
-
#fails?(user) ⇒ Boolean
Returns true iff the user’s inventory is empty.
-
#initialize ⇒ Use
constructor
Initializes the Use command.
-
#run(user, enemy) ⇒ Object
Uses the specified Item on the specified Entity.
Methods inherited from BattleCommand
Constructor Details
#initialize ⇒ Use
Initializes the Use command.
9 10 11 |
# File 'lib/goby/battle/use.rb', line 9 def initialize super(name: "Use") end |
Instance Method Details
#fails?(user) ⇒ Boolean
Returns true iff the user’s inventory is empty.
17 18 19 20 21 22 23 |
# File 'lib/goby/battle/use.rb', line 17 def fails?(user) empty = user.inventory.empty? if empty print "#{user.name}'s inventory is empty!\n\n" end return empty end |
#run(user, enemy) ⇒ Object
Uses the specified Item on the specified Entity. Note that enemy is not necessarily on whom the Item is used.
30 31 32 33 34 35 |
# File 'lib/goby/battle/use.rb', line 30 def run(user, enemy) # Determine the item and on whom to use the item. pair = user.choose_item_and_on_whom(enemy) return if (!pair) user.use_item(pair.first, pair.second) end |