Class: Battle::Actions::Flee

Inherits:
Base show all
Defined in:
scripts/01600 Alpha 25 Battle Engine/03000 Actions/00006 Flee.rb

Overview

Class describing the Flee action

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#valid?

Constructor Details

#initialize(scene, target) ⇒ Flee

Create a new flee action

Parameters:



11
12
13
14
# File 'scripts/01600 Alpha 25 Battle Engine/03000 Actions/00006 Flee.rb', line 11

def initialize(scene, target)
  super(scene)
  @target = target
end

Instance Attribute Details

#targetPFM::PokemonBattler (readonly)

Get the pokemon trying to flee

Returns:



7
8
9
# File 'scripts/01600 Alpha 25 Battle Engine/03000 Actions/00006 Flee.rb', line 7

def target
  @target
end

Instance Method Details

#<=>(other) ⇒ Integer

Compare this action with another

Parameters:

  • other (Base)

    other action

Returns:



19
20
21
22
23
# File 'scripts/01600 Alpha 25 Battle Engine/03000 Actions/00006 Flee.rb', line 19

def <=>(other)
  return 1 if other.is_a?(Attack) && Attack.from(other).move.relative_priority > 0

  return -1
end

#execute(from_scene = false)

Execute the action

Parameters:

  • from_scene (Boolean) (defaults to: false)

    if the action was triggered during the player choice



27
28
29
30
31
32
33
34
35
# File 'scripts/01600 Alpha 25 Battle Engine/03000 Actions/00006 Flee.rb', line 27

def execute(from_scene = false)
  if from_scene
    execute_from_scene
  elsif @scene.logic.switch_handler.can_switch?(@target)
    @scene.display_message_and_wait(parse_text_with_pokemon(19, 767, @target))
    @scene.logic.battle_result = 1
    @scene.next_update = :battle_end
  end
end