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}
NO_CRITICAL_ABILITIES =

List of ability preventing the critical hit from happening

%i[battle_armor shell_armor]
UNCONDITIONAL_CRITICAL_ITEMS =

List of items that unconditionally improve critical rate

%i[razor_claw scope_lens]

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



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

def initialize(scene)
end

Instance Attribute Details

#actionsArray<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

#bagsArray<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_fieldArray<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_effectsArray<Effects::EffectsHandler> (readonly)

Get the bank effects

Returns:



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

def bank_effects
  @bank_effects
end

#battle_infoBattle::Logic::BattleInfo (readonly)



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

def battle_info
  @battle_info
end

#battle_resultInteger

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_actionActions::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_requestArray<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_terrainSymbol

Get or set the current field terrain type

Returns:

  • (Symbol)


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

def field_terrain
  @field_terrain
end

#generic_rngRandom (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_evolveMegaEvolve (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

#messagesArray<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_rngRandom (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_rngRandom (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_rngRandom (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

#position_effectsArray<Array<Battle::Effects::EffectsHandler>> (readonly)

Get the position effects

Returns:



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

def position_effects
  @position_effects
end

#sceneBattle::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_requestArray<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_effectsEffects::EffectsHandler (readonly)

Get the terrain effects



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

def terrain_effects
  @terrain_effects
end

#turn_actionsArray<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_handlerBattle::Logic::AbilityChangeHandler

Get the ability change handler



371
372
# File 'docs/5_Battle_04_Logic.rb', line 371

def ability_change_handler
end

#add_actions(actions)

Add actions to process in the next step

Parameters:



218
219
# File 'docs/5_Battle_04_Logic.rb', line 218

def add_actions(actions)
end

#add_bank_effect(effect)

Add an effect on a bank



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

def add_bank_effect(effect)
end

#add_position_effect(effect)

Add an effect on a position



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

def add_position_effect(effect)
end

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

Return the adjacent allies

Parameters:

Returns:



99
100
# File 'docs/5_Battle_04_Logic.rb', line 99

def adjacent_allies_of(pokemon)
end

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

Return the adjacent foes

Parameters:

Returns:



88
89
# File 'docs/5_Battle_04_Logic.rb', line 88

def adjacent_foes_of(pokemon)
end

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

Return all the alive battler of a bank

Parameters:

  • bank (Integer)

Returns:



110
111
# File 'docs/5_Battle_04_Logic.rb', line 110

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:



115
116
# File 'docs/5_Battle_04_Logic.rb', line 115

def alive_battlers_without_check(bank)
end

#all_alive_battlersArray<PFM::PokemonBattler>

Return all alive battlers

Returns:



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

def all_alive_battlers
end

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

Iterate through all battlers

Yield Parameters:

Returns:



162
163
# File 'docs/5_Battle_04_Logic.rb', line 162

def all_battlers
end

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

Return the allies (excluding the pokemon)

Parameters:

Returns:



105
106
# File 'docs/5_Battle_04_Logic.rb', line 105

def allies_of(pokemon, check_adjacent = false)
end

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

Check active abilities on the field

Returns:



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

def any_field_ability_active?(db_symbol)
end

#bank_countInteger

Return the number of bank in the current battle

Returns:

  • (Integer)


60
61
# File 'docs/5_Battle_04_Logic.rb', line 60

def bank_count
end

#battle_end_handlerBattle::Logic::BattleEndHandler

Get the battle end handler



375
376
# File 'docs/5_Battle_04_Logic.rb', line 375

def battle_end_handler
end

#battle_phase_end

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



302
303
# File 'docs/5_Battle_04_Logic.rb', line 302

def battle_phase_end
end

#battle_phase_end_caught

Function that process the battle end when Pokemon was caught



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

def battle_phase_end_caught
end

#battle_phase_exp

Function that test the experience distribution



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

def battle_phase_exp
end

#battle_phase_switch_execute(who:, with: nil)

Function that executes the switch request

Parameters:



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

def battle_phase_switch_execute(who:, with: nil)
end

#battle_phase_switch_exp_check

Function that process the switches and give exp



308
309
# File 'docs/5_Battle_04_Logic.rb', line 308

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:



78
79
# File 'docs/5_Battle_04_Logic.rb', line 78

def battler(bank, position)
end

#battler_attacks_after?(battler, other) ⇒ Boolean

Test if the battler attacks after another

Parameters:

Returns:

  • (Boolean)


142
143
# File 'docs/5_Battle_04_Logic.rb', line 142

def battler_attacks_after?(battler, other)
end

#battler_attacks_before?(battler, other) ⇒ Boolean

Test if the battler attacks before another

Parameters:

Returns:

  • (Boolean)


136
137
# File 'docs/5_Battle_04_Logic.rb', line 136

def battler_attacks_before?(battler, other)
end

#battler_attacks_first?(battler) ⇒ Boolean

Test if the battler attacks first

Parameters:

Returns:

  • (Boolean)


147
148
# File 'docs/5_Battle_04_Logic.rb', line 147

def battler_attacks_first?(battler)
end

#battler_attacks_last?(battler) ⇒ Boolean

Test if the battler attacks last

Parameters:

Returns:

  • (Boolean)


152
153
# File 'docs/5_Battle_04_Logic.rb', line 152

def battler_attacks_last?(battler)
end

#battler_count(bank) ⇒ Integer

Return the number of battler (alive) in one bank

Parameters:

  • bank (Integer)

Returns:

  • (Integer)


83
84
# File 'docs/5_Battle_04_Logic.rb', line 83

def battler_count(bank)
end

#calc_critical_count(user, target, initial_critical_count) ⇒ Integer

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

Parameters:

Returns:

  • (Integer)


291
292
# File 'docs/5_Battle_04_Logic.rb', line 291

def calc_critical_count(user, target, initial_critical_count)
end

#calc_critical_count_item(user) ⇒ Boolean

Tell if the user has an item that increase the critical count

Parameters:

Returns:

  • (Boolean)


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

def calc_critical_count_item(user)
end

#calc_critical_hit(user, target, initial_critical_count) ⇒ Boolean

Calculate if the current action will be a critical hit

Parameters:

Returns:

  • (Boolean)


282
283
# File 'docs/5_Battle_04_Logic.rb', line 282

def calc_critical_hit(user, target, initial_critical_count)
end

#can_battle_continue?Boolean

Tell if the battle can continue

Returns:

  • (Boolean)


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

def can_battle_continue?
end

#can_battler_be_replaced?(who) ⇒ Boolean

Test if the battler can be replaced

Parameters:

Returns:

  • (Boolean)


167
168
# File 'docs/5_Battle_04_Logic.rb', line 167

def can_battler_be_replaced?(who)
end

#catch_handlerBattle::Logic::CatchHandler

Get the catch handler



367
368
# File 'docs/5_Battle_04_Logic.rb', line 367

def catch_handler
end

#damage_handlerBattle::Logic::DamageHandler

Get a new damage handler



343
344
# File 'docs/5_Battle_04_Logic.rb', line 343

def damage_handler
end

#delete_dead_effects

Delete all the dead effect by updating counters & removing them



415
416
# File 'docs/5_Battle_04_Logic.rb', line 415

def delete_dead_effects
end

#each_effects(*pokemons) {|| ... } ⇒ 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

Parameters:

  • pokemons (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



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

def each_effects(*pokemons)
end

#end_turn_handlerBattle::Logic::EndTurnHandler

Get a new switch handler



351
352
# File 'docs/5_Battle_04_Logic.rb', line 351

def end_turn_handler
end

#exp_handlerBattle::Logic::ExpHandler

Get the exp handler



379
380
# File 'docs/5_Battle_04_Logic.rb', line 379

def exp_handler
end

#field_terrain_effectEffects::FieldTerrain

Get the field terrain effect



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

def field_terrain_effect
end

#flee_handlerBattle::Logic::FleeHandler

Get the flee handler



363
364
# File 'docs/5_Battle_04_Logic.rb', line 363

def flee_handler
end

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

Return the foes

Parameters:

Returns:



94
95
# File 'docs/5_Battle_04_Logic.rb', line 94

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



230
231
# File 'docs/5_Battle_04_Logic.rb', line 230

def force_sort_actions(&block)
end

#fterrain_change_handlerBattle::Logic::FTerrainChangeHandler

Get a new field terrain change handler



359
360
# File 'docs/5_Battle_04_Logic.rb', line 359

def fterrain_change_handler
end

#item_change_handlerBattle::Logic::ItemChangeHandler

Get a new item change handler



335
336
# File 'docs/5_Battle_04_Logic.rb', line 335

def item_change_handler
end

#load_battlers

Load the battlers from the battle infos



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

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



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

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

#perform_next_actionBoolean

Execute the next action

Returns:

  • (Boolean)

    if there was an action or not



222
223
# File 'docs/5_Battle_04_Logic.rb', line 222

def perform_next_action
end

#request_switch(who, with)

Add a switch request

Parameters:



127
128
# File 'docs/5_Battle_04_Logic.rb', line 127

def request_switch(who, with)
end

#rng_seedsHash{ Symbol => Integer }

Get the current RNG Seeds

Returns:

  • (Hash{ Symbol => Integer })


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

def rng_seeds
end

#sort_actions

Note:

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

Sort the actions



226
227
# File 'docs/5_Battle_04_Logic.rb', line 226

def sort_actions
end

#stat_change_handlerBattle::Logic::StatChangeHandler

Get a new stat change handler



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

def stat_change_handler
end

#status_change_handlerBattle::Logic::StatusChangeHandler

Get a new item change handler



339
340
# File 'docs/5_Battle_04_Logic.rb', line 339

def status_change_handler
end

#switch_bank_effects(bank1, bank2)

Switch bank effects

Parameters:

  • bank1 (Integer)
  • bank2 (Integer)


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

def switch_bank_effects(bank1, bank2)
end

#switch_battlers(who, with)

Switch two pokemon (logically)

Parameters:



157
158
# File 'docs/5_Battle_04_Logic.rb', line 157

def switch_battlers(who, with)
end

#switch_handlerBattle::Logic::SwitchHandler

Get a new switch handler



347
348
# File 'docs/5_Battle_04_Logic.rb', line 347

def switch_handler
end

#to_s Also known as: inspect

Safe to_s & inspect



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

def to_s
end

#trainer_battlersArray<PFM::PokemonBattler>

List all the trainer Pokemon

Returns:



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

def trainer_battlers
end

#transform_handlerBattle::Logic::TransformHandler

Get the transform handler



383
384
# File 'docs/5_Battle_04_Logic.rb', line 383

def transform_handler
end

#update_battler_turn_count

Update the turn count of all alive battler



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

def update_battler_turn_count
end

#weather_change_handlerBattle::Logic::WeatherChangeHandler

Get a new weather change handler



355
356
# File 'docs/5_Battle_04_Logic.rb', line 355

def weather_change_handler
end

#weather_effectEffects::Weather

Get the weather effect

Returns:



419
420
# File 'docs/5_Battle_04_Logic.rb', line 419

def weather_effect
end