Class: Battle::Logic

Inherits:
Object show all
Defined in:
docs/01600_Alpha_25_Battle_Engine_00200_Battle_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



50
51
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 50

def initialize(scene)
end

Instance Attribute Details

#actionsArray<Actions::Base> (readonly)

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/01600_Alpha_25_Battle_Engine_00200_Battle_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



16
17
18
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 16

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:



47
48
49
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 47

def ball_fetch_on_field
  @ball_fetch_on_field
end

#bank_effectsArray<Effects::EffectsHandler> (readonly)

Get the bank effects

Returns:



389
390
391
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 389

def bank_effects
  @bank_effects
end

#battle_infoBattle::Logic::BattleInfo (readonly)



18
19
20
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 18

def battle_info
  @battle_info
end

#battle_resultInteger

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

Returns:

  • (Integer)


14
15
16
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 14

def battle_result
  @battle_result
end

#debug_end_of_battle

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



44
45
46
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 44

def debug_end_of_battle
  @debug_end_of_battle
end

#evolve_requestArray<PFM::PokemonBattler> (readonly)

Get the evolve requests

Returns:



21
22
23
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 21

def evolve_request
  @evolve_request
end

#field_terrainSymbol

Get or set the current field terrain type

Returns:

  • (Symbol)


395
396
397
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 395

def field_terrain
  @field_terrain
end

#generic_rngRandom (readonly)

Get the generic rng

Returns:



42
43
44
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 42

def generic_rng
  @generic_rng
end

#mega_evolveMegaEvolve (readonly)

Get the Mega Evolve helper

Returns:



24
25
26
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 24

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/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 7

def messages
  @messages
end

#move_accuracy_rngRandom (readonly)

Get the move accuracy rng

Returns:



39
40
41
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 39

def move_accuracy_rng
  @move_accuracy_rng
end

#move_critical_rngRandom (readonly)

Get the move critical rng

Returns:



36
37
38
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 36

def move_critical_rng
  @move_critical_rng
end

#move_damage_rngRandom (readonly)

Get the move damage rng

Returns:



33
34
35
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 33

def move_damage_rng
  @move_damage_rng
end

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

Get the position effects

Returns:



392
393
394
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 392

def position_effects
  @position_effects
end

#sceneBattle::Scene (readonly)

Get the scene used to instanciate this Logic instance

Returns:



30
31
32
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 30

def scene
  @scene
end

#switch_requestArray<Hash> (readonly)

Get the switch requests

Returns:

  • (Array<Hash>)


27
28
29
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 27

def switch_request
  @switch_request
end

#terrain_effectsEffects::EffectsHandler (readonly)

Get the terrain effects



386
387
388
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 386

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



11
12
13
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 11

def turn_actions
  @turn_actions
end

Instance Method Details

#ability_change_handlerBattle::Logic::AbilityChangeHandler

Get the ability change handler



369
370
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 369

def ability_change_handler
end

#add_actions(actions)

Add actions to process in the next step

Parameters:



216
217
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 216

def add_actions(actions)
end

#add_bank_effect(effect)

Add an effect on a bank



410
411
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 410

def add_bank_effect(effect)
end

#add_position_effect(effect)

Add an effect on a position



406
407
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 406

def add_position_effect(effect)
end

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

Return the adjacent allies

Parameters:

Returns:



97
98
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 97

def adjacent_allies_of(pokemon)
end

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

Return the adjacent foes

Parameters:

Returns:



86
87
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 86

def adjacent_foes_of(pokemon)
end

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

Return all the alive battler of a bank

Parameters:

  • bank (Integer)

Returns:



108
109
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 108

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:



113
114
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 113

def alive_battlers_without_check(bank)
end

#all_alive_battlersArray<PFM::PokemonBattler>

Return all alive battlers

Returns:



117
118
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 117

def all_alive_battlers
end

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

Iterate through all battlers

Yield Parameters:

Returns:



160
161
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 160

def all_battlers
end

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

Return the allies (excluding the pokemon)

Parameters:

Returns:



103
104
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 103

def allies_of(pokemon, check_adjacent = false)
end

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

Check active abilities on the field

Returns:



173
174
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 173

def any_field_ability_active?(db_symbol)
end

#bank_countInteger

Return the number of bank in the current battle

Returns:

  • (Integer)


58
59
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 58

def bank_count
end

#battle_end_handlerBattle::Logic::BattleEndHandler

Get the battle end handler



373
374
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 373

def battle_end_handler
end

#battle_phase_end

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



300
301
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 300

def battle_phase_end
end

#battle_phase_end_caught

Function that process the battle end when Pokemon was caught



314
315
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 314

def battle_phase_end_caught
end

#battle_phase_exp

Function that test the experience distribution



303
304
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 303

def battle_phase_exp
end

#battle_phase_switch_execute(who:, with: nil)

Function that executes the switch request

Parameters:



311
312
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 311

def battle_phase_switch_execute(who:, with: nil)
end

#battle_phase_switch_exp_check

Function that process the switches and give exp



306
307
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 306

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:



76
77
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 76

def battler(bank, position)
end

#battler_attacks_after?(battler, other) ⇒ Boolean

Test if the battler attacks after another

Parameters:

Returns:

  • (Boolean)


140
141
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 140

def battler_attacks_after?(battler, other)
end

#battler_attacks_before?(battler, other) ⇒ Boolean

Test if the battler attacks before another

Parameters:

Returns:

  • (Boolean)


134
135
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 134

def battler_attacks_before?(battler, other)
end

#battler_attacks_first?(battler) ⇒ Boolean

Test if the battler attacks first

Parameters:

Returns:

  • (Boolean)


145
146
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 145

def battler_attacks_first?(battler)
end

#battler_attacks_last?(battler) ⇒ Boolean

Test if the battler attacks last

Parameters:

Returns:

  • (Boolean)


150
151
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 150

def battler_attacks_last?(battler)
end

#battler_count(bank) ⇒ Integer

Return the number of battler (alive) in one bank

Parameters:

  • bank (Integer)

Returns:

  • (Integer)


81
82
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 81

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)


289
290
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 289

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)


296
297
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 296

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)


280
281
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 280

def calc_critical_hit(user, target, initial_critical_count)
end

#can_battle_continue?Boolean

Tell if the battle can continue

Returns:

  • (Boolean)


62
63
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 62

def can_battle_continue?
end

#can_battler_be_replaced?(who) ⇒ Boolean

Test if the battler can be replaced

Parameters:

Returns:

  • (Boolean)


165
166
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 165

def can_battler_be_replaced?(who)
end

#catch_handlerBattle::Logic::CatchHandler

Get the catch handler



365
366
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 365

def catch_handler
end

#damage_handlerBattle::Logic::DamageHandler

Get a new damage handler



341
342
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 341

def damage_handler
end

#delete_dead_effects

Delete all the dead effect by updating counters & removing them



413
414
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 413

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



402
403
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 402

def each_effects(*pokemons)
end

#end_turn_handlerBattle::Logic::EndTurnHandler

Get a new switch handler



349
350
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 349

def end_turn_handler
end

#exp_handlerBattle::Logic::ExpHandler

Get the exp handler



377
378
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 377

def exp_handler
end

#field_terrain_effectEffects::FieldTerrain

Get the field terrain effect



421
422
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 421

def field_terrain_effect
end

#flee_handlerBattle::Logic::FleeHandler

Get the flee handler



361
362
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 361

def flee_handler
end

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

Return the foes

Parameters:

Returns:



92
93
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 92

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



228
229
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 228

def force_sort_actions(&block)
end

#fterrain_change_handlerBattle::Logic::FTerrainChangeHandler

Get a new field terrain change handler



357
358
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 357

def fterrain_change_handler
end

#item_change_handlerBattle::Logic::ItemChangeHandler

Get a new item change handler



333
334
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 333

def item_change_handler
end

#load_battlers

Load the battlers from the battle infos



120
121
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 120

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



66
67
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 66

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



220
221
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 220

def perform_next_action
end

#request_switch(who, with)

Add a switch request

Parameters:



125
126
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 125

def request_switch(who, with)
end

#rng_seedsHash{ Symbol => Integer }

Get the current RNG Seeds

Returns:

  • (Hash{ Symbol => Integer })


70
71
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 70

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



224
225
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 224

def sort_actions
end

#stat_change_handlerBattle::Logic::StatChangeHandler

Get a new stat change handler



329
330
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 329

def stat_change_handler
end

#status_change_handlerBattle::Logic::StatusChangeHandler

Get a new item change handler



337
338
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 337

def status_change_handler
end

#switch_battlers(who, with)

Switch two pokemon (logically)

Parameters:



155
156
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 155

def switch_battlers(who, with)
end

#switch_handlerBattle::Logic::SwitchHandler

Get a new switch handler



345
346
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 345

def switch_handler
end

#to_s Also known as: inspect

Safe to_s & inspect



53
54
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 53

def to_s
end

#trainer_battlersArray<PFM::PokemonBattler>

List all the trainer Pokemon

Returns:



169
170
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 169

def trainer_battlers
end

#transform_handlerBattle::Logic::TransformHandler

Get the transform handler



381
382
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 381

def transform_handler
end

#update_battler_turn_count

Update the turn count of all alive battler



128
129
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 128

def update_battler_turn_count
end

#weather_change_handlerBattle::Logic::WeatherChangeHandler

Get a new weather change handler



353
354
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 353

def weather_change_handler
end

#weather_effectEffects::Weather

Get the weather effect

Returns:



417
418
# File 'docs/01600_Alpha_25_Battle_Engine_00200_Battle_Logic.rb', line 417

def weather_effect
end