Class: Goby::BattleCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/goby/battle/battle_command.rb

Overview

Commands that are used in the battle system. At each turn, an Entity specifies which BattleCommand to use.

Direct Known Subclasses

Attack, Escape, Use

Constant Summary collapse

NO_ACTION =

Text for when the battle command does nothing.

"Nothing happens.\n\n"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: "BattleCommand") ⇒ BattleCommand

Returns a new instance of BattleCommand.

Parameters:

  • name (String) (defaults to: "BattleCommand")

    the name.



11
12
13
# File 'lib/goby/battle/battle_command.rb', line 11

def initialize(name: "BattleCommand")
  @name = name
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



44
45
46
# File 'lib/goby/battle/battle_command.rb', line 44

def name
  @name
end

Instance Method Details

#==(rhs) ⇒ Boolean

Returns true iff the commands are considered equal.

Parameters:

Returns:

  • (Boolean)

    true iff the commands are considered equal.



40
41
42
# File 'lib/goby/battle/battle_command.rb', line 40

def ==(rhs)
  @name.casecmp(rhs.name).zero?
end

#fails?(user) ⇒ Boolean

This method can prevent the user from using this command based on a defined condition. Override for subclasses.

Parameters:

  • user (Entity)

    the one who is using the command.

Returns:

  • (Boolean)

    true iff the command cannot be used.



20
21
22
# File 'lib/goby/battle/battle_command.rb', line 20

def fails?(user)
  false
end

#run(user, entity) ⇒ Object

The process that runs when this command is used in battle. Override this function for subclasses.

Parameters:

  • user (Entity)

    the one who is using the command.

  • entity (Entity)

    the one on whom the command is used.



29
30
31
# File 'lib/goby/battle/battle_command.rb', line 29

def run(user, entity)
  print NO_ACTION
end

#to_sString

Returns the name of the BattleCommand.

Returns:

  • (String)

    the name of the BattleCommand.



34
35
36
# File 'lib/goby/battle/battle_command.rb', line 34

def to_s
  @name
end