Class: Battle::Actions::Attack

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

Overview

Class describing the Attack Action

Direct Known Subclasses

Encore

Defined Under Namespace

Classes: Encore

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#valid?

Constructor Details

#initialize(scene, move, launcher, target_bank, target_position) ⇒ Attack

Create a new attack action

Parameters:



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

def initialize(scene, move, launcher, target_bank, target_position)
  super(scene)
  @move = move
  @launcher = launcher
  @target_bank = target_bank
  @target_position = target_position
  @pursuit_enabled = false
  @ignore_speed = false
  @sub_launchers = []
end

Instance Attribute Details

#ignore_speedBoolean

Tell if this action can ignore speed of the other pokemon

Returns:

  • (Boolean)


16
17
18
# File 'scripts/01600 Alpha 25 Battle Engine/03000 Actions/00002 Attack.rb', line 16

def ignore_speed
  @ignore_speed
end

#launcherPFM::PokemonBattler (readonly)

Get the user of this move

Returns:



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

def launcher
  @launcher
end

#moveBattle::Move (readonly)

Get the move of this action

Returns:



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

def move
  @move
end

#pursuit_enabledBoolean

Tell if pursuit on this action is enabled

Returns:

  • (Boolean)


13
14
15
# File 'scripts/01600 Alpha 25 Battle Engine/03000 Actions/00002 Attack.rb', line 13

def pursuit_enabled
  @pursuit_enabled
end

#sub_launchersArray (readonly)

List all the sub launcher that will use the same move due to their ability (Dancer)

Returns:

  • (Array)


19
20
21
# File 'scripts/01600 Alpha 25 Battle Engine/03000 Actions/00002 Attack.rb', line 19

def sub_launchers
  @sub_launchers
end

Instance Method Details

#<=>(other) ⇒ Integer

Compare this action with another

Parameters:

  • other (Base)

    other action

Returns:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'scripts/01600 Alpha 25 Battle Engine/03000 Actions/00002 Attack.rb', line 40

def <=>(other)
  return 1 if other.is_a?(HighPriorityItem)

  unless @pursuit_enabled && other.is_a?(Attack) && other.pursuit_enabled
    return -1 if @pursuit_enabled
    return 1 if other.is_a?(Attack) && other.pursuit_enabled
  end
  return -1 if other.is_a?(Flee) && move.relative_priority > 0
  return 1 unless other.is_a?(Attack)

  attack = Attack.from(other)
  return -1 if @ignore_speed && attack.move.priority(attack.launcher) == @move.priority(@launcher)

  priority_return = attack.move.priority(attack.launcher) <=> @move.priority(@launcher)
  return priority_return if priority_return != 0

  return -1 if (@launcher.hold_item?(:lagging_tail) && !attack.launcher.hold_item?(:lagging_tail)) ||
               (@launcher.hold_item?(:full_incense) && !attack.launcher.hold_item?(:full_incense))
  return -1 if @launcher.has_ability?(:stall) && !attack.launcher.has_ability?(:stall)

  trick_room_factor = @scene.logic.terrain_effects.has?(:trick_room) ? -1 : 1
  return (attack.launcher.spd <=> @launcher.spd) * trick_room_factor
end

#execute

Execute the action



82
83
84
85
86
87
88
89
90
# File 'scripts/01600 Alpha 25 Battle Engine/03000 Actions/00002 Attack.rb', line 82

def execute
  # Reset flee attempt count
  @scene.battle_info.flee_attempt_count = 0 if @launcher.from_party?
  @move.proceed(@launcher, @target_bank, @target_position)
  @sub_launchers.each do |launcher|
    @scene.visual.show_ability(launcher)
    @move.dup.proceed(launcher, @target_bank, @target_position)
  end
end

#priorityInteger

Get the priority of the move

Returns:



66
67
68
# File 'scripts/01600 Alpha 25 Battle Engine/03000 Actions/00002 Attack.rb', line 66

def priority
  return @pursuit_enabled ? 999 : @move.priority
end

#targetPFM::PokemonBattler?

Get the target of the move

Returns:



72
73
74
75
76
77
78
79
# File 'scripts/01600 Alpha 25 Battle Engine/03000 Actions/00002 Attack.rb', line 72

def target
  targets = @move.battler_targets(@launcher, @scene.logic).select(&:alive?)
  best_target = targets.select { |battler| battler.position == @target_position && battler.bank == @target_bank }.first
  return best_target if best_target

  best_target = targets.select { |battler| battler.bank == @target_bank }.first
  return best_target || targets.first
end