Class: Battle::AI::Base

Inherits:
Object show all
Includes:
Hooks
Defined in:
scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00100 Base.rb,
scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00104 Item.rb,
scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00105 Flee.rb,
scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00103 Switch.rb,
scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00102 MegaEvolve.rb,
scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00101 MoveActionFor.rb

Overview

Base class of AI, it holds the most important data

Constant Summary collapse

BOOSTING_ITEMS =

List of boosting items

%i[x_attack x_sp_atk x_speed x_defense x_sp_def]
HEALING_ITEMS =

List of healing items

%i[full_restore hyper_potion energy_root moomoo_milk lemonade
super_potion energy_powder soda_pop fresh_water
potion berry_juice sweet_heart sitrus_berry oran_berry]
POISON_HEAL_ITEMS =

List of item that heal from poison

%i[antidote full_heal heal_powder lava_cookie
old_gateau pecha_berry lum_berry casteliacone
lumiose_galette shalour_sable]
BURN_HEAL_ITEMS =

List of item that heals from burn state

%i[burn_heal full_heal heal_powder lava_cookie
old_gateau rawst_berry lum_berry casteliacone
lumiose_galette shalour_sable]
PARALYZE_HEAL_ITEMS =

List of item that heals from paralysis

%i[paralyze_heal full_heal heal_powder lava_cookie
old_gateau cheri_berry lum_berry casteliacone
lumiose_galette shalour_sable]
FREEZE_HEAL_ITEMS =

List of item that heals from frozen state

%i[ice_heal full_heal heal_powder lava_cookie
old_gateau aspear_berry lum_berry casteliacone
lumiose_galette shalour_sable]
WAKE_UP_ITEMS =

List of item that wake the Pokemon up

%i[awakening full_heal heal_powder lava_cookie
old_gateau blue_flute chesto_berry lum_berry
casteliacone lumiose_galette shalour_sable]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Hooks

#exec_hooks, #force_return, included, remove, remove_without_name

Constructor Details

#initialize(scene, bank, party_id, level) ⇒ Base

Create a new AI instance

Parameters:

  • scene (Battle::Scene)

    scene that hold the logic object

  • bank (Integer)

    bank where the AI acts

  • party_id (Integer)

    ID of the party the AI look for Pokemon info

  • level (Integer)

    level of tha AI



25
26
27
28
29
30
31
32
# File 'scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00100 Base.rb', line 25

def initialize(scene, bank, party_id, level)
  @scene = scene
  @bank = bank
  @party_id = party_id
  @level = level
  @move_heuristic_cache = Hash.new { |hash, key| hash[key] = MoveHeuristicBase.new(key.be_method, @level) }
  init_capability
end

Instance Attribute Details

#bankInteger (readonly)

Get the bank the AI controls

Returns:



12
13
14
# File 'scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00100 Base.rb', line 12

def bank
  @bank
end

#party_idInteger (readonly)

Get the party the AI controls

Returns:



15
16
17
# File 'scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00100 Base.rb', line 15

def party_id
  @party_id
end

#sceneBattle::Scene (readonly)

Get the scene that initialized the AI

Returns:



9
10
11
# File 'scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00100 Base.rb', line 9

def scene
  @scene
end

Class Method Details

.register(level, klass)

Register a new AI

Parameters:

  • level (Integer)

    level of the AI

  • klass (Class<Base>)


50
51
52
# File 'scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00100 Base.rb', line 50

def register(level, klass)
  @ai_class_by_level[level] = klass
end

.registered(level) ⇒ Class<Battle::AI::Base>

Get a registered AI

Parameters:

  • level (Integer)

    level of the AI

Returns:



57
58
59
# File 'scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00100 Base.rb', line 57

def registered(level)
  @ai_class_by_level[level] || Base
end

Instance Method Details

#controlled_pokemonArray<PFM::PokemonBattler>

Get all the controlled Pokemon

Returns:



70
71
72
# File 'scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00100 Base.rb', line 70

def controlled_pokemon
  0.upto(@scene.battle_info.vs_type - 1).map { |i| @scene.logic.battler(@bank, i) }.compact.select { |battler| battler.party_id == @party_id }
end

#partyArray<PFM::PokemonBattler>

Get all Pokemon in the party of the AI

Returns:



64
65
66
# File 'scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00100 Base.rb', line 64

def party
  @scene.logic.all_battlers.select { |battler| battler.bank == @bank && battler.party_id == @party_id }
end

#request_switch(who) ⇒ PFM::PokemonBattler?

Function returning pokemon to switch with on request

Parameters:

Returns:



7
8
9
10
11
12
13
14
# File 'scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00103 Switch.rb', line 7

def request_switch(who)
  actions = clean_switch_actions(switch_actions_generate_for(who))
  return nil if actions.empty?

  best = actions.compact.shuffle(random: @scene.logic.generic_rng).max_by(&:first)
  Debug::AiWindow.append(self, actions.compact) if defined?(Debug::AiWindow)
  return best.last.with
end

#triggerArray<Actions::Base>

Get the action the AI wants to do

Returns:



36
37
38
39
40
41
42
43
44
# File 'scripts/01600 Alpha 25 Battle Engine/08000 Battle_AI/00100 Base.rb', line 36

def trigger
  return controlled_pokemon.flat_map do |pokemon|
    # @type [Battle::Effects::ForceNextMove]
    effect = pokemon.effects.get(&:force_next_move?)
    next effect.make_action if effect

    battle_action_for(pokemon)
  end.compact
end