Class: Battle::Actions::Switch

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

Overview

Class describing the usage of switching out a Pokemon

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#valid?

Constructor Details

#initialize(scene, who, with) ⇒ Switch

Create a new switch action

Parameters:



15
16
17
18
19
# File 'scripts/01600 Alpha 25 Battle Engine/03000 Actions/00005 Switch.rb', line 15

def initialize(scene, who, with)
  super(scene)
  @who = who
  @with = with
end

Instance Attribute Details

#whoPFM::PokemonBattler (readonly)

Get the Pokemon who's being switched

Returns:



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

def who
  @who
end

#withPFM::PokemonBattler (readonly)

Get the Pokemon with the Pokemon is being switched

Returns:



10
11
12
# File 'scripts/01600 Alpha 25 Battle Engine/03000 Actions/00005 Switch.rb', line 10

def with
  @with
end

Instance Method Details

#<=>(other) ⇒ Integer

Compare this action with another

Parameters:

  • other (Base)

    other action

Returns:



24
25
26
27
28
29
30
31
# File 'scripts/01600 Alpha 25 Battle Engine/03000 Actions/00005 Switch.rb', line 24

def <=>(other)
  return 1 if other.is_a?(HighPriorityItem)
  return 1 if other.is_a?(Attack) && Attack.from(other).pursuit_enabled
  return 1 if other.is_a?(Item)
  return Switch.from(other).who.spd <=> @who.spd if other.is_a?(Switch)

  return -1
end

#execute

Execute the action



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'scripts/01600 Alpha 25 Battle Engine/03000 Actions/00005 Switch.rb', line 34

def execute
  return if !@who.position || !@who.position.between?(0, $game_temp.vs_type - 1)

  visual = @scene.visual
  # @type [BattleUI::PokemonSprite]
  sprite = visual.battler_sprite(@who.bank, @who.position)
  if @who.alive?
    sprite.go_out
    visual.hide_info_bar(@who)
    switch_out_message unless forced_switch?(who)
    wait_for(sprite, visual)
  end
  # Logically switching the Pokemon
  @scene.logic.switch_battlers(@who, @with)
  # Switching the sprite
  sprite.pokemon = @with
  sprite.visible = false # Ensure there's no glitch with animation (the animation sets visible :))
  sprite.go_in
  visual.show_info_bar(@with)
  switch_in_message unless forced_switch?(who)
  wait_for(sprite, visual)
  @scene.logic.switch_handler.execute_switch_events(@who, @with)
  @scene.logic.request_switch(@with, nil) if @with.dead?
  @who.reset_states
end