class Goby::Use
Public Class Methods
new()
click to toggle source
Initializes the Use
command.
Calls superclass method
Goby::BattleCommand::new
# File lib/goby/battle/use.rb, line 9 def initialize super(name: "Use") end
Public Instance Methods
fails?(user)
click to toggle source
Returns true iff the user's inventory is empty.
@param [Entity] user the one who is using the command. @return [Boolean] status of the user's inventory.
# 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)
click to toggle source
Uses the specified Item
on the specified Entity
. Note that enemy is not necessarily on whom the Item
is used.
@param [Entity] user the one who is using the command. @param [Entity] enemy the one on whom the command is used.
# 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