Class: Battle::Logic

Inherits:
Object show all
Defined in:
docs/5_Battle_04_Logic.rb

Overview

Logic part of Pokemon Battle

This class helps to access to the battle information & to process some part of the battle

Defined Under Namespace

Classes: AbilityChangeHandler, BattleEndHandler, BattleInfo, CatchHandler, ChangeHandlerBase, DamageHandler, EndTurnHandler, ExpHandler, FTerrainChangeHandler, FleeHandler, ItemChangeHandler, MegaEvolve, StatChangeHandler, StatusChangeHandler, SwitchHandler, TransformHandler, WeatherChangeHandler

Constant Summary collapse

MOVE_PRIORITY_OFFSET =

Constant giving an offset for the move priority : In RH moves start their priority from 0 (-7) and end at 14 (+7)

-7
# Priority of pursuit when a switch will occur
PURSUIT_PRIORITY =

Priority of pursuit when a switch will occur

7
MEGA_PRIORITY =

Priority of MEGA

8
OTHER_PRIORITY =

Priority of other things

6
ITEM_PRIORITY_BOOST_IN_PRIORITY =

List of move first handler by item held

{quick_claw: :check_priority_trigger_quick_claw, custap_berry: :check_priority_trigger_custap_berry}
ABILITY_PRIORITY_BOOST_IN_PRIORITY =

List of move first handler by ability

{quick_draw: :check_priority_trigger_quick_draw}
VAL_0_25 =

Value that contains 0.25

0.25
CRITICAL_RATES =

List of critical rates according to the current critical count

{0 => 0, 1 => 6_250, 2 => 12_500, 3 => 50_000}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scene) ⇒ Logic

Create a new Logic instance

Parameters:

  • scene (Scene) —

    scene that hold the logic object



55
56
# File 'docs/5_Battle_04_Logic.rb', line 55

def initialize(scene)
end

Instance Attribute Details

#actions ⇒ Array<Actions::Base>

Returns list of the current actions to proccess during the scene.

Returns:

  • (Array<Actions::Base>) —

    list of the current actions to proccess during the scene



9
10
11
# File 'docs/5_Battle_04_Logic.rb', line 9

def actions
  @actions
end

#bags ⇒ Array<Array<PFM::Bag>> (readonly)

Returns bags of each banks.

Returns:

  • (Array<Array<PFM::Bag>>) —

    bags of each banks



18
19
20
# File 'docs/5_Battle_04_Logic.rb', line 18

def bags
  @bags
end

#ball_fetch_on_field ⇒ Array<PFM::PokemonBattler>

All the Pokemon with Ball Fetch on the field sorted by decreasing speed when the player fails the capture

Returns:



49
50
51
# File 'docs/5_Battle_04_Logic.rb', line 49

def ball_fetch_on_field
  @ball_fetch_on_field
end

#bank_effects ⇒ Array<Effects::EffectsHandler> (readonly)

Get the bank effects

Returns:



405
406
407
# File 'docs/5_Battle_04_Logic.rb', line 405

def bank_effects
  @bank_effects
end

#battle_info ⇒ Battle::Logic::BattleInfo (readonly)



20
21
22
# File 'docs/5_Battle_04_Logic.rb', line 20

def battle_info
  @battle_info
end

#battle_result ⇒ Integer

0 : Victory, 1 : Flee, 2 : Defeat, -1 : undef

Returns:

  • (Integer)


16
17
18
# File 'docs/5_Battle_04_Logic.rb', line 16

def battle_result
  @battle_result
end

#current_action ⇒ Actions::Base (readonly)

Returns currently played action.

Returns:



11
12
13
# File 'docs/5_Battle_04_Logic.rb', line 11

def current_action
  @current_action
end

#debug_end_of_battle

If the battle is in debug and forcing the end of it



46
47
48
# File 'docs/5_Battle_04_Logic.rb', line 46

def debug_end_of_battle
  @debug_end_of_battle
end

#evolve_request ⇒ Array<PFM::PokemonBattler> (readonly)

Get the evolve requests

Returns:



23
24
25
# File 'docs/5_Battle_04_Logic.rb', line 23

def evolve_request
  @evolve_request
end

#field_terrain ⇒ Symbol

Get or set the current field terrain type

Returns:

  • (Symbol)


411
412
413
# File 'docs/5_Battle_04_Logic.rb', line 411

def field_terrain
  @field_terrain
end

#generic_rng ⇒ Random (readonly)

Get the generic rng

Returns:



44
45
46
# File 'docs/5_Battle_04_Logic.rb', line 44

def generic_rng
  @generic_rng
end

#mega_evolve ⇒ MegaEvolve (readonly)

Get the Mega Evolve helper

Returns:



26
27
28
# File 'docs/5_Battle_04_Logic.rb', line 26

def mega_evolve
  @mega_evolve
end

#messages ⇒ Array<Array> (readonly)

Returns list of messages to send to an interpreter (AI/Scene).

Returns:

  • (Array<Array>) —

    list of messages to send to an interpreter (AI/Scene)



7
8
9
# File 'docs/5_Battle_04_Logic.rb', line 7

def messages
  @messages
end

#move_accuracy_rng ⇒ Random (readonly)

Get the move accuracy rng

Returns:



41
42
43
# File 'docs/5_Battle_04_Logic.rb', line 41

def move_accuracy_rng
  @move_accuracy_rng
end

#move_critical_rng ⇒ Random (readonly)

Get the move critical rng

Returns:



38
39
40
# File 'docs/5_Battle_04_Logic.rb', line 38

def move_critical_rng
  @move_critical_rng
end

#move_damage_rng ⇒ Random (readonly)

Get the move damage rng

Returns:



35
36
37
# File 'docs/5_Battle_04_Logic.rb', line 35

def move_damage_rng
  @move_damage_rng
end

#player_processing_item ⇒ Array<Studio::Item>

Get the IDs of items being processed by the player during this turn

Returns:



52
53
54
# File 'docs/5_Battle_04_Logic.rb', line 52

def player_processing_item
  @player_processing_item
end

#position_effects ⇒ Array<Array<Battle::Effects::EffectsHandler>> (readonly)

Get the position effects

Returns:



408
409
410
# File 'docs/5_Battle_04_Logic.rb', line 408

def position_effects
  @position_effects
end

#scene ⇒ Battle::Scene (readonly)

Get the scene used to instanciate this Logic instance

Returns:



32
33
34
# File 'docs/5_Battle_04_Logic.rb', line 32

def scene
  @scene
end

#switch_request ⇒ Array<Hash> (readonly)

Get the switch requests

Returns:

  • (Array<Hash>)


29
30
31
# File 'docs/5_Battle_04_Logic.rb', line 29

def switch_request
  @switch_request
end

#terrain_effects ⇒ Effects::EffectsHandler (readonly)

Get the terrain effects



402
403
404
# File 'docs/5_Battle_04_Logic.rb', line 402

def terrain_effects
  @terrain_effects
end

#turn_actions ⇒ Array<Actions::Base>

Returns list of all actions that occurs within the current turn.

Returns:

  • (Array<Actions::Base>) —

    list of all actions that occurs within the current turn



13
14
15
# File 'docs/5_Battle_04_Logic.rb', line 13

def turn_actions
  @turn_actions
end

Instance Method Details

#ability_change_handler ⇒ Battle::Logic::AbilityChangeHandler

Get the ability change handler



385
386
# File 'docs/5_Battle_04_Logic.rb', line 385

def ability_change_handler
end

#add_actions(actions)

Add actions to process in the next step

Parameters:



235
236
# File 'docs/5_Battle_04_Logic.rb', line 235

def add_actions(actions)
end

#add_bank_effect(effect)

Add an effect on a bank



431
432
# File 'docs/5_Battle_04_Logic.rb', line 431

def add_bank_effect(effect)
end

#add_position_effect(effect)

Add an effect on a position



427
428
# File 'docs/5_Battle_04_Logic.rb', line 427

def add_position_effect(effect)
end

#adjacent_allies_of(pokemon) ⇒ Array<PFM::PokemonBattler>

Return the adjacent allies

Parameters:

Returns:



102
103
# File 'docs/5_Battle_04_Logic.rb', line 102

def adjacent_allies_of(pokemon)
end

#adjacent_foes_of(pokemon) ⇒ Array<PFM::PokemonBattler>

Return the adjacent foes

Parameters:

Returns:



91
92
# File 'docs/5_Battle_04_Logic.rb', line 91

def adjacent_foes_of(pokemon)
end

#alive_battlers(bank) ⇒ Array<PFM::PokemonBattler>

Return all the alive battler of a bank

Parameters:

  • bank (Integer)

Returns:



113
114
# File 'docs/5_Battle_04_Logic.rb', line 113

def alive_battlers(bank)
end

#alive_battlers_without_check(bank) ⇒ Array<PFM::PokemonBattler>

Return all the alive battler of a bank but don't check can_fight?

Parameters:

  • bank (Integer)

Returns:



118
119
# File 'docs/5_Battle_04_Logic.rb', line 118

def alive_battlers_without_check(bank)
end

#all_alive_battlers ⇒ Array<PFM::PokemonBattler>

Return all alive battlers

Returns:



122
123
# File 'docs/5_Battle_04_Logic.rb', line 122

def all_alive_battlers
end

#all_battlers {|battler| ... } ⇒ Enumerable<PFM::PokemonBattler>

Iterate through all battlers

Yield Parameters:

Returns:



175
176
# File 'docs/5_Battle_04_Logic.rb', line 175

def all_battlers
end

#allies_of(pokemon, check_adjacent = false) ⇒ Array<PFM::PokemonBattler>

Return the allies (excluding the pokemon)

Parameters:

Returns:



108
109
# File 'docs/5_Battle_04_Logic.rb', line 108

def allies_of(pokemon, check_adjacent = false)
end

#any_field_ability_active?(db_symbol) ⇒ Array<PFM::PokemonBattler>

Check active abilities on the field

Returns:



192
193
# File 'docs/5_Battle_04_Logic.rb', line 192

def any_field_ability_active?(db_symbol)
end

#bank_count ⇒ Integer

Return the number of bank in the current battle

Returns:

  • (Integer)


63
64
# File 'docs/5_Battle_04_Logic.rb', line 63

def bank_count
end

#battle_end_handler ⇒ Battle::Logic::BattleEndHandler

Get the battle end handler



389
390
# File 'docs/5_Battle_04_Logic.rb', line 389

def battle_end_handler
end

#battle_phase_3v3_automatic_shifting

Automatically reposition battlers in 3v3



313
314
# File 'docs/5_Battle_04_Logic.rb', line 313

def battle_phase_3v3_automatic_shifting
end

#battle_phase_end

Function that distribute the exp to all Pokemon and switch dead pokemon



310
311
# File 'docs/5_Battle_04_Logic.rb', line 310

def battle_phase_end
end

#battle_phase_end_caught

Function that process the battle end when Pokemon was caught



330
331
# File 'docs/5_Battle_04_Logic.rb', line 330

def battle_phase_end_caught
end

#battle_phase_exp

Function that test the experience distribution



319
320
# File 'docs/5_Battle_04_Logic.rb', line 319

def battle_phase_exp
end

#battle_phase_switch_execute(who:, with: nil)

Function that executes the switch request

Parameters:



327
328
# File 'docs/5_Battle_04_Logic.rb', line 327

def battle_phase_switch_execute(who:, with: nil)
end

#battle_phase_switch_exp_check

Function that process the switches and give exp



322
323
# File 'docs/5_Battle_04_Logic.rb', line 322

def battle_phase_switch_exp_check
end

#battler(bank, position) ⇒ PFM::PokemonBattler?

Return the battler of a bank

Parameters:

  • bank (Integer) —

    bank where the Pokemon is

  • position (Integer) —

    position of the Pokemon in the bank

Returns:



81
82
# File 'docs/5_Battle_04_Logic.rb', line 81

def battler(bank, position)
end

#battler_attacks_after?(battler, other) ⇒ Boolean

Test if the battler attacks after another

Parameters:

Returns:

  • (Boolean)


145
146
# File 'docs/5_Battle_04_Logic.rb', line 145

def battler_attacks_after?(battler, other)
end

#battler_attacks_before?(battler, other) ⇒ Boolean

Test if the battler attacks before another

Parameters:

Returns:

  • (Boolean)


139
140
# File 'docs/5_Battle_04_Logic.rb', line 139

def battler_attacks_before?(battler, other)
end

#battler_attacks_first?(battler) ⇒ Boolean

Test if the battler attacks first

Parameters:

Returns:

  • (Boolean)


150
151
# File 'docs/5_Battle_04_Logic.rb', line 150

def battler_attacks_first?(battler)
end

#battler_attacks_last?(battler) ⇒ Boolean

Test if the battler attacks last

Parameters:

Returns:

  • (Boolean)


155
156
# File 'docs/5_Battle_04_Logic.rb', line 155

def battler_attacks_last?(battler)
end

#battler_count(bank) ⇒ Integer

Return the number of battler (alive) in one bank

Parameters:

  • bank (Integer)

Returns:

  • (Integer)


86
87
# File 'docs/5_Battle_04_Logic.rb', line 86

def battler_count(bank)
end

#calc_critical_count(user, target, initial_critical_count) ⇒ Integer

Calculate the critical count (to get the right critical probability)

Parameters:

Returns:

  • (Integer)


306
307
# File 'docs/5_Battle_04_Logic.rb', line 306

def calc_critical_count(user, target, initial_critical_count)
end

#calc_critical_hit(user, target, initial_critical_count) ⇒ Boolean

Calculate if the current action will be a critical hit

Parameters:

Returns:

  • (Boolean)


299
300
# File 'docs/5_Battle_04_Logic.rb', line 299

def calc_critical_hit(user, target, initial_critical_count)
end

#can_battle_continue? ⇒ Boolean

Tell if the battle can continue

Returns:

  • (Boolean)


67
68
# File 'docs/5_Battle_04_Logic.rb', line 67

def can_battle_continue?
end

#can_battler_be_replaced?(who) ⇒ Boolean

Test if the battler can be replaced

Parameters:

Returns:

  • (Boolean)


180
181
# File 'docs/5_Battle_04_Logic.rb', line 180

def can_battler_be_replaced?(who)
end

#catch_handler ⇒ Battle::Logic::CatchHandler

Get the catch handler



381
382
# File 'docs/5_Battle_04_Logic.rb', line 381

def catch_handler
end

#damage_handler ⇒ Battle::Logic::DamageHandler

Get a new damage handler



357
358
# File 'docs/5_Battle_04_Logic.rb', line 357

def damage_handler
end

#delete_dead_effects

Delete all the dead effect by updating counters & removing them



434
435
# File 'docs/5_Battle_04_Logic.rb', line 434

def delete_dead_effects
end

#each_effects(*battlers) {|| ... } ⇒ Array<Effects::EffectBase>, ...

Note:

This returns an enumerator if no block is given

Note:

If the block returns a Symbol, this methods returns this symbol immediately without processing the other effects

Execute a block on each effect depending on what to select as effect rubocop:disable Metrics/CyclomaticComplexity This is a big chunk that doesn't need to be refactored in several pieces rubocop:disable Metrics/PerceivedComplexity rubocop:disable Metrics/CombinableLoops We know what we do

Parameters:

  • battlers (Array<PFM::PokemonBattler>) —

    list of battlers we want to see their effect executed

Yield Parameters:

Returns:

  • (Array<Effects::EffectBase>, Symbol, Integer, nil) —

    the first block return that was a symbol



423
424
# File 'docs/5_Battle_04_Logic.rb', line 423

def each_effects(*battlers)
end

#end_turn_handler ⇒ Battle::Logic::EndTurnHandler

Get a new switch handler



365
366
# File 'docs/5_Battle_04_Logic.rb', line 365

def end_turn_handler
end

#exp_handler ⇒ Battle::Logic::ExpHandler

Get the exp handler



393
394
# File 'docs/5_Battle_04_Logic.rb', line 393

def exp_handler
end

#field_terrain_effect ⇒ Effects::FieldTerrain

Get the field terrain effect



452
453
# File 'docs/5_Battle_04_Logic.rb', line 452

def field_terrain_effect
end

#flee_handler ⇒ Battle::Logic::FleeHandler

Get the flee handler



377
378
# File 'docs/5_Battle_04_Logic.rb', line 377

def flee_handler
end

#foes_of(pokemon, check_adjacent = false) ⇒ Array<PFM::PokemonBattler>

Return the foes

Parameters:

Returns:



97
98
# File 'docs/5_Battle_04_Logic.rb', line 97

def foes_of(pokemon, check_adjacent = false)
end

#force_sort_actions(&block)

Sort the actions

Parameters:

  • block (Block) —

    block used to sort the actions take |Actions::Base, Actions::Base| as arguments



247
248
# File 'docs/5_Battle_04_Logic.rb', line 247

def force_sort_actions(&block)
end

#fterrain_change_handler ⇒ Battle::Logic::FTerrainChangeHandler

Get a new field terrain change handler



373
374
# File 'docs/5_Battle_04_Logic.rb', line 373

def fterrain_change_handler
end

#get_middle_battler(bank) ⇒ PFM::PokemonBattler

Get the battler at the middle position

Parameters:

  • bank (Integer) —

    the bank of the battler

Returns:



165
166
# File 'docs/5_Battle_04_Logic.rb', line 165

def get_middle_battler(bank)
end

#item_change_handler ⇒ Battle::Logic::ItemChangeHandler

Get a new item change handler



349
350
# File 'docs/5_Battle_04_Logic.rb', line 349

def item_change_handler
end

#load_battlers

Load the battlers from the battle infos



125
126
# File 'docs/5_Battle_04_Logic.rb', line 125

def load_battlers
end

#load_rng(seeds = Hash.new(Random.new_seed))

Load the RNG for the battle logic

Parameters:

  • seeds (Hash) (defaults to: Hash.new(Random.new_seed)) —

    seeds for the RNG



71
72
# File 'docs/5_Battle_04_Logic.rb', line 71

def load_rng(seeds = Hash.new(Random.new_seed))
end

#perform_next_action ⇒ Boolean

Execute the next action

Returns:

  • (Boolean) —

    if there was an action or not



239
240
# File 'docs/5_Battle_04_Logic.rb', line 239

def perform_next_action
end

#raw_weather_effect ⇒ Effects::Weather

Get the raw weather effect, regardless of whether weather effects are disabled Used internally to ensure animations and turn counters still tick during Air Lock

Returns:



444
445
# File 'docs/5_Battle_04_Logic.rb', line 444

def raw_weather_effect
end

#request_switch(who, with)

Add a switch request

Parameters:



130
131
# File 'docs/5_Battle_04_Logic.rb', line 130

def request_switch(who, with)
end

#retrieve_party_from_battler(battler) ⇒ Array<PFM::PokemonBattler>

List all the battlers of the trainer from a battler

Returns:



188
189
# File 'docs/5_Battle_04_Logic.rb', line 188

def retrieve_party_from_battler(battler)
end

#rng_seeds ⇒ Hash{ Symbol => Integer }

Get the current RNG Seeds

Returns:

  • (Hash{ Symbol => Integer })


75
76
# File 'docs/5_Battle_04_Logic.rb', line 75

def rng_seeds
end

#shift_battlers(who, with)

Shift two pokemon (logically)

Parameters:



170
171
# File 'docs/5_Battle_04_Logic.rb', line 170

def shift_battlers(who, with)
end

#sort_actions

Note:

The last action in the stack is the first action to pop out from the stack

Sort the actions



243
244
# File 'docs/5_Battle_04_Logic.rb', line 243

def sort_actions
end

#stat_change_handler ⇒ Battle::Logic::StatChangeHandler

Get a new stat change handler



345
346
# File 'docs/5_Battle_04_Logic.rb', line 345

def stat_change_handler
end

#status_change_handler ⇒ Battle::Logic::StatusChangeHandler

Get a new item change handler



353
354
# File 'docs/5_Battle_04_Logic.rb', line 353

def status_change_handler
end

#switch_bank_effects(bank1, bank2)

Switch bank effects

Parameters:

  • bank1 (Integer)
  • bank2 (Integer)


457
458
# File 'docs/5_Battle_04_Logic.rb', line 457

def switch_bank_effects(bank1, bank2)
end

#switch_battlers(who, with)

Switch two pokemon (logically)

Parameters:



160
161
# File 'docs/5_Battle_04_Logic.rb', line 160

def switch_battlers(who, with)
end

#switch_handler ⇒ Battle::Logic::SwitchHandler

Get a new switch handler



361
362
# File 'docs/5_Battle_04_Logic.rb', line 361

def switch_handler
end

#to_s Also known as: inspect

Safe to_s & inspect



58
59
# File 'docs/5_Battle_04_Logic.rb', line 58

def to_s
end

#trainer_battlers ⇒ Array<PFM::PokemonBattler>

List all the trainer Pokemon

Returns:



184
185
# File 'docs/5_Battle_04_Logic.rb', line 184

def trainer_battlers
end

#transform_handler ⇒ Battle::Logic::TransformHandler

Get the transform handler



397
398
# File 'docs/5_Battle_04_Logic.rb', line 397

def transform_handler
end

#unmark_shifted_pokemon

Unmark the Pokemon which have been marked as having just shifted in 3v3



316
317
# File 'docs/5_Battle_04_Logic.rb', line 316

def unmark_shifted_pokemon
end

#update_battler_turn_count

Update the turn count of all alive battler



133
134
# File 'docs/5_Battle_04_Logic.rb', line 133

def update_battler_turn_count
end

#weather_change_handler ⇒ Battle::Logic::WeatherChangeHandler

Get a new weather change handler



369
370
# File 'docs/5_Battle_04_Logic.rb', line 369

def weather_change_handler
end

#weather_effect ⇒ Effects::Weather

Get the weather effect Returns a neutral :none weather when weather effects are disabled (Air Lock / Cloud Nine)

Returns:



439
440
# File 'docs/5_Battle_04_Logic.rb', line 439

def weather_effect
end

#weather_effects_disabled? ⇒ Boolean

Check if weather effects are currently disabled (e.g. by Air Lock or Cloud Nine)

Returns:

  • (Boolean)


448
449
# File 'docs/5_Battle_04_Logic.rb', line 448

def weather_effects_disabled?
end