Class: Goby::Escape

Inherits:
BattleCommand show all
Defined in:
lib/goby/battle/escape.rb

Overview

Allows an Entity to try to escape from the opponent.

Constant Summary collapse

SUCCESS =

Text for successful escape.

"Successful escape!\n\n"
FAILURE =

Text for failed escape.

"Unable to escape!\n\n"

Constants inherited from BattleCommand

BattleCommand::NO_ACTION

Instance Attribute Summary

Attributes inherited from BattleCommand

#name

Instance Method Summary collapse

Methods inherited from BattleCommand

#==, #fails?, #to_s

Constructor Details

#initializeEscape

Initializes the Escape command.



14
15
16
# File 'lib/goby/battle/escape.rb', line 14

def initialize
  super(name: "Escape")
end

Instance Method Details

#run(user, enemy) ⇒ Object

Samples a probability to determine if the user will escape from battle.

Parameters:

  • user (Entity)

    the one who is trying to escape.

  • enemy (Entity)

    the one from whom the user wants to escape.



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/goby/battle/escape.rb', line 22

def run(user, enemy)

  # Higher probability of escape when the enemy has low agility.
  if (user.sample_agilities(enemy))
    user.escaped = true
    type(SUCCESS)
    return
  end

  # Should already be false.
  user.escaped = false
  type(FAILURE)
end