Class: PFM::GameState

Inherits:
Object show all
Defined in:
scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb,
scripts/01450 Systems/09000 GTS/09000 GTS.rb,
scripts/01450 Systems/00103 Bag/00001 PFM/00300 Bag.rb,
scripts/01450 Systems/00203 Shop/00001 PFM/00700 Shop.rb,
scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb,
scripts/01450 Systems/99990 Global Systems/01500 HoneyTree.rb,
scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb,
scripts/01450 Systems/00105 Options/00001 PFM/00500 Options.rb,
scripts/01450 Systems/00201 Daycare/00001 PFM/01100 Daycare.rb,
scripts/01450 Systems/99991 Wild/00100 Wild Battle (manager).rb,
scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb,
scripts/02000 Nuri Yuri/00001 DynamicLight/00003 DL PokemonParty.rb,
scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb,
scripts/01450 Systems/00000 General/00010 GameState/00201 Management.rb,
scripts/01450 Systems/00202 Environment/00001 PFM/01200 Environnement.rb,
scripts/01450 Systems/00300 Hall of fame/00001 PFM/02000 Hall_of_Fame.rb,
scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00001 MiningGame.rb

Overview

The game informations and Party management

The global object is stored in PFM.game_state

Author:

  • Nuri Yuri

Constant Summary collapse

ON_INITIALIZE =

Constant containing all the proc to call when creating a new GameState object (for battle)

{}
ON_PLAYER_INITIALIZE =

Constant containing all the proc to call when creating a new GameState object (for the player)

{}
ON_EXPAND_GLOBAL_VARIABLES =

Constant containing all the proc to call when expanding the global variables

{}
FASTER_HATCH_ABILITIES =

Abilities that increase the hatch speed

%i[magma_armor flame_body steam_engine]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(battle = false, starting_language = 'en') ⇒ GameState

Create a new Pokemon Party

Parameters:

  • battle (Boolean) (defaults to: false)

    if its a party of a NPC battler

  • starting_language (String) (defaults to: 'en')

    the lang id of the game described by this object



213
214
215
216
217
218
219
220
221
222
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 213

def initialize(battle = false, starting_language = 'en')
  @starting_language = starting_language
  ON_INITIALIZE.each_value do |block|
    instance_exec(&block) if block
  end
  return if battle

  game_state_initialize
  rmxp_boot unless $tester
end

Instance Attribute Details

#actorsArray<PFM::Pokemon>

The Pokemon of the Player

Returns:



39
40
41
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 39

def actors
  @actors
end

#bagPFM::Bag

The bag of the player

Returns:



189
190
191
# File 'scripts/01450 Systems/00103 Bag/00001 PFM/00300 Bag.rb', line 189

def bag
  @bag
end

#berriesHash

The in game berry data

Returns:

  • (Hash)


207
208
209
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 207

def berries
  @berries
end

#daycarePFM::Daycare

The daycare management object

Returns:



516
517
518
# File 'scripts/01450 Systems/00201 Daycare/00001 PFM/01100 Daycare.rb', line 516

def daycare
  @daycare
end

#envPFM::Environment

The environment informations

Returns:



420
421
422
# File 'scripts/01450 Systems/00202 Environment/00001 PFM/01200 Environnement.rb', line 420

def env
  @env
end

#game_actorsGame_Actors

The $game_actors

Returns:



121
122
123
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 121

def game_actors
  @game_actors
end

#game_mapGame_Map

The $game_map

Returns:



141
142
143
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 141

def game_map
  @game_map
end

#game_partyGame_Party

The $game_party

Returns:



130
131
132
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 130

def game_party
  @game_party
end

#game_playerGame_Player

The $game_player

Returns:



150
151
152
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 150

def game_player
  @game_player
end

#game_screenGame_Screen

The $game_screen

Returns:



112
113
114
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 112

def game_screen
  @game_screen
end

#game_self_switchesGame_SelfSwitches

The $game_self_switches

Returns:



85
86
87
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 85

def game_self_switches
  @game_self_switches
end

#game_self_variablesGame_SelfVariables

The $game_self_variables

Returns:



94
95
96
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 94

def game_self_variables
  @game_self_variables
end

#game_switchesGame_Switches

The $game_switches

Returns:



73
74
75
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 73

def game_switches
  @game_switches
end

#game_systemGame_System

The $game_system

Returns:



103
104
105
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 103

def game_system
  @game_system
end

#game_tempGame_Temp

The $game_temp

Returns:



159
160
161
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 159

def game_temp
  @game_temp
end

#game_variablesGame_Variables

The $game_variables

Returns:



61
62
63
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 61

def game_variables
  @game_variables
end

#hall_of_famePFM::Hall_of_Fame

The list of the victory in the Pokemon League

Returns:



36
37
38
# File 'scripts/01450 Systems/00300 Hall of fame/00001 PFM/02000 Hall_of_Fame.rb', line 36

def hall_of_fame
  @hall_of_fame
end

#honey_treesArray<Hash{ Symbol => Integer}> (readonly)

Access to the honey tree information

Returns:

  • (Array<Hash{ Symbol => Integer}>)


140
141
142
# File 'scripts/01450 Systems/99990 Global Systems/01500 HoneyTree.rb', line 140

def honey_trees
  @honey_trees
end

#level_max_limitInteger

Maximum level an allied Pokemon can reach

Returns:



201
202
203
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 201

def level_max_limit
  @level_max_limit
end

#mining_gamePFM::MiningGame

Stats and booleans relative to the Mining Game

Returns:



44
45
46
# File 'scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00001 MiningGame.rb', line 44

def mining_game
  @mining_game
end

#nuri_yuri_dynamic_light

Access to the information of the current dynamic light state (Battle / Save)



4
5
6
# File 'scripts/02000 Nuri Yuri/00001 DynamicLight/00003 DL PokemonParty.rb', line 4

def nuri_yuri_dynamic_light
  @nuri_yuri_dynamic_light
end

#nuzlockeNuzlocke

The nuzlocke logic

Returns:



168
169
170
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 168

def nuzlocke
  @nuzlocke
end

#online_pokemon

Returns the value of attribute online_pokemon.



962
963
964
# File 'scripts/01450 Systems/09000 GTS/09000 GTS.rb', line 962

def online_pokemon
  @online_pokemon
end

#optionsPFM::Options

The game options

Returns:



115
116
117
# File 'scripts/01450 Systems/00105 Options/00001 PFM/00500 Options.rb', line 115

def options
  @options
end

#pathfinding_requestsArray<Object>

The pathfinding requests

Returns:



181
182
183
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 181

def pathfinding_requests
  @pathfinding_requests
end

#pokedexPFM::Pokedex

The Pokedex of the player

Returns:



342
343
344
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 342

def pokedex
  @pokedex
end

#questsPFM::Quests

The player quests informations

Returns:



361
362
363
# File 'scripts/01450 Systems/08000 Quest/00001 PFM_Quest/00001 PFM Quests.rb', line 361

def quests
  @quests
end

#repel_countInteger Also known as: get_repel_count

The number of steps the repel will work

Returns:



51
52
53
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 51

def repel_count
  @repel_count
end

#shopPFM::Shop

The list of the limited shops

Returns:



224
225
226
# File 'scripts/01450 Systems/00203 Shop/00001 PFM/00700 Shop.rb', line 224

def shop
  @shop
end

#stepsInteger

The number of steps the player did

Returns:



56
57
58
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 56

def steps
  @steps
end

#storagePFM::Storage

The PC storage of the player

Returns:



262
263
264
# File 'scripts/01450 Systems/00200 Storage/00001 PFM_Storage/00001 Main.rb', line 262

def storage
  @storage
end

#tint_time_setSymbol?

Name of the time set to use (nil = default)

Returns:

  • (Symbol, nil)


187
188
189
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 187

def tint_time_set
  @tint_time_set
end

#trainerPFM::Trainer

The informations about the player and the game

Returns:



192
193
194
# File 'scripts/01450 Systems/00104 Trainer/00001 PFM/00400 Trainer.rb', line 192

def trainer
  @trainer
end

#user_dataHash (readonly)

User data

Returns:

  • (Hash)


191
192
193
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 191

def user_data
  @user_data
end

#wild_battlePFM::Wild_Battle

The information about the Wild Battle

Returns:



306
307
308
# File 'scripts/01450 Systems/99991 Wild/00100 Wild Battle (manager).rb', line 306

def wild_battle
  @wild_battle
end

Class Method Details

.on_expand_global_variables(name, &block)

Add a new proc on global variable expand

Parameters:

  • name (Symbol)

    name of the block to add

  • block (Proc)

    proc to execute with the GameState context



32
33
34
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 32

def on_expand_global_variables(name, &block)
  ON_EXPAND_GLOBAL_VARIABLES[name] = block
end

.on_initialize(name, &block)

Add a new proc on initialize (for battle)

Parameters:

  • name (Symbol)

    name of the block to add

  • block (Proc)

    proc to execute with the GameState context



18
19
20
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 18

def on_initialize(name, &block)
  ON_INITIALIZE[name] = block
end

.on_player_initialize(name, &block)

Add a new proc on player initialize (for the player)

Parameters:

  • name (Symbol)

    name of the block to add

  • block (Proc)

    proc to execute with the GameState context



25
26
27
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 25

def on_player_initialize(name, &block)
  ON_PLAYER_INITIALIZE[name] = block
end

Instance Method Details

#add_money(n)

Add money

Parameters:

  • n (Integer)

    amount of money to add



373
374
375
376
377
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 373

def add_money(n)
  return lose_money(-n) if n < 0

  $game_party.gold += n
end

#add_pokemon(pkmn) ⇒ Boolean, Integer

Add a Pokemon to the pary (also update the Pokedex Informations)

Parameters:

Returns:

  • (Boolean, Integer)

    Box index if stored in a box, false if failed, true if stored in the Party



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'scripts/01450 Systems/00000 General/00010 GameState/00201 Management.rb', line 66

def add_pokemon(pkmn)
  unless pkmn.egg?
    @pokedex.mark_seen(pkmn.id, pkmn.form, forced: true)
    @pokedex.mark_captured(pkmn.id)
    @pokedex.increase_creature_fought(pkmn.id)
    @pokedex.increase_creature_caught_count(pkmn.id)
  end

  if full?
    return @storage.current_box if @storage.store(pkmn)
    return false
  else
    @actors << pkmn
    return true
  end
end

#alive?Boolean

Is the party able to start a battle ?

Returns:

  • (Boolean)


29
30
31
# File 'scripts/01450 Systems/00000 General/00010 GameState/00201 Management.rb', line 29

def alive?
  return !dead?
end

#battle_starting_update



270
271
272
273
274
275
276
277
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 270

def battle_starting_update
  return if cant_process_event_tasks?

  encounter_count = $game_player.encounter_count
  if !$game_system.encounter_disabled && ((@steps % encounter_count) == 0) && @wild_battle.available?
    $game_system.map_interpreter.launch_common_event(1) unless $game_system.map_interpreter.running?
  end
end

#can_learn?(id) ⇒ Boolean #can_learn?(id, index) ⇒ Integer, false

Checks if one Pokemon of the party can learn the requested skill.

Overloads:

  • #can_learn?(id) ⇒ Boolean

    Parameters:

    • id (Integer, Symbol)

      the id of the skill in the database

    Returns:

    • (Boolean)
  • #can_learn?(id, index) ⇒ Integer, false

    Returns the position of the first pokemon that meets conditions

    Parameters:

    • id (Integer, Symbol)

      the id of the skill in the database

    • index (true)

      indicating to return the index

    Returns:



232
233
234
235
236
237
238
239
240
# File 'scripts/01450 Systems/00000 General/00010 GameState/00201 Management.rb', line 232

def can_learn?(id, index = false)
  id = data_move(id).id if id.is_a?(Symbol)
  @actors.each_with_index do |pokemon, i|
    if pokemon&.can_learn?(id)
      return index ? i : true
    end
  end
  return false
end

#can_learn_index(id) ⇒ Integer, false

Return the index of the Pokemon who can learn the specified skill

Parameters:

  • id (Integer, Symbol)

    the id of the skill in the database

Returns:



245
246
247
# File 'scripts/01450 Systems/00000 General/00010 GameState/00201 Management.rb', line 245

def can_learn_index(id)
  can_learn?(id, true)
end

#can_learn_or_learnt?(id) ⇒ Boolean #can_learn_or_learnt?(id, index) ⇒ Integer, false

Checks if one Pokemon of the party can learn or has learnt the requested skill.

Overloads:

  • #can_learn_or_learnt?(id) ⇒ Boolean

    Parameters:

    • id (Integer, Symbol)

      the id of the skill in the database

    Returns:

    • (Boolean)
  • #can_learn_or_learnt?(id, index) ⇒ Integer, false

    Returns the position of the first pokemon that meets conditions

    Parameters:

    • id (Integer, Symbol)

      the id of the skill in the database

    • index (true)

      indicating to return the index

    Returns:



258
259
260
261
262
263
264
265
266
267
# File 'scripts/01450 Systems/00000 General/00010 GameState/00201 Management.rb', line 258

def can_learn_or_learnt?(id, index = false)
  id = data_move(id).id if id.is_a?(Symbol)
  @actors.each_with_index do |pokemon, i|
    next unless pokemon
    if pokemon.can_learn?(id) != false
      return index ? i : true
    end
  end
  return false
end

#can_learn_or_learnt_index(id) ⇒ Integer, false

Return the index of the Pokemon who can learn or has learn the specified skill

Parameters:

  • id (Integer, Symbol)

    the id of the skill in the database

Returns:



272
273
274
# File 'scripts/01450 Systems/00000 General/00010 GameState/00201 Management.rb', line 272

def can_learn_or_learnt_index(id)
  can_learn_or_learnt?(id, true)
end

#cant_process_event_tasks?Boolean

Tell if EventTasks can't process

Returns:

  • (Boolean)


339
340
341
342
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 339

def cant_process_event_tasks?
  return ($game_player.move_route_forcing || $game_system.map_interpreter.running? ||
    $game_temp.message_window_showing || $game_player.sliding)
end

#contain_enough_selectable_pokemon?(arr = []) ⇒ Boolean Also known as: has_enough_selectable_pokemon?

Check if the player has enough Pokemon to choose in its party Doesn't count banned Pokemon

Parameters:

  • arr (Array) (defaults to: [])

    ids of the banned Pokemon

Returns:

  • (Boolean)


136
137
138
139
140
141
142
143
144
145
# File 'scripts/01450 Systems/00000 General/00010 GameState/00201 Management.rb', line 136

def contain_enough_selectable_pokemon?(arr = [])
  if arr.any?
    count = @actors.count { |pokemon| !arr.include?(pokemon.id) }
  else
    count = $actors.size
  end

  return false unless $game_variables[Yuki::Var::Max_Pokemon_Select].between(1, size)
  return $game_variables[Yuki::Var::Max_Pokemon_Select] <= count
end

#contain_matching_pokemon?(id, level = nil, form = nil, shiny = nil, index: false) ⇒ Boolean, Integer Also known as: has_pokemon?

Check if the player has a specific Pokemon in its party

Parameters:

  • id (Integer, Symbol)

    id of the Pokemon in the database

  • level (Integer, nil) (defaults to: nil)

    the level required

  • form (Integer, nil) (defaults to: nil)

    the form of the Pokemon

  • shiny (Boolean, nil) (defaults to: nil)

    if the Pokemon should be shiny or not

  • index (Boolean) (defaults to: false)

    if you want an index when found

Returns:

  • (Boolean, Integer)

    if the Pokemon has been found



117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'scripts/01450 Systems/00000 General/00010 GameState/00201 Management.rb', line 117

def contain_matching_pokemon?(id, level = nil, form = nil, shiny = nil, index: false)
  id = data_creature(id).id if id.is_a?(Symbol)
  @actors.each_with_index do |pokemon, i|
    next unless pokemon.id == id
    bool = true
    bool &&= pokemon.level == level if level
    bool &&= pokemon.form == form if form
    bool &&= pokemon.shiny == shiny unless shiny.nil?
    next unless bool
    return i if index
    return true
  end
  return false
end

#contain_pokemon_with_the_ability?(id, index = false) ⇒ Boolean, Integer Also known as: has_ability?

Check if the party has a Pokemon with a specific ability

Parameters:

  • id (Integer, Symbol)

    ID of the ability in the database

  • index (Boolean) (defaults to: false)

    if the method return the index of the Pokemon that has the ability

Returns:



205
206
207
208
209
210
211
212
213
# File 'scripts/01450 Systems/00000 General/00010 GameState/00201 Management.rb', line 205

def contain_pokemon_with_the_ability?(id, index = false)
  id = data_ability(id).id if id.is_a?(Symbol)
  @actors.each_with_index do |pokemon, i|
    if pokemon&.ability == id
      return index ? i : true
    end
  end
  return false
end

#contain_pokemon_with_the_skill?(id, index = false) ⇒ Boolean, Integer Also known as: has_skill?

Check if the party has a Pokemon with a specific skill

Parameters:

  • id (Integer, Symbol)

    ID of the skill in the database

  • index (Boolean) (defaults to: false)

    if the method return the index of the Pokemon that has the skill

Returns:



180
181
182
183
184
185
186
187
188
189
190
191
# File 'scripts/01450 Systems/00000 General/00010 GameState/00201 Management.rb', line 180

def contain_pokemon_with_the_skill?(id, index = false)
  id = data_move(id).id if id.is_a?(Symbol)
  @actors.each_with_index do |pokemon, i|
    next unless pokemon
    pokemon.skills_set.each do |skill|
      if skill&.id == id
        return index ? i : true
      end
    end
  end
  return false
end

#dead?Boolean

Is the party not able to start a battle ?

Returns:

  • (Boolean)


23
24
25
# File 'scripts/01450 Systems/00000 General/00010 GameState/00201 Management.rb', line 23

def dead?
  return empty? || @actors.all?(&:dead?)
end

#empty?Boolean

Is the party empty ?

Returns:

  • (Boolean)


11
12
13
# File 'scripts/01450 Systems/00000 General/00010 GameState/00201 Management.rb', line 11

def empty?
  return @actors.empty?
end

#expand_global_var

Expand the global variable with the instance variables of the object



252
253
254
255
256
257
258
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 252

def expand_global_var
  PFM.game_state = self
  $pokemon_party = self
  ON_EXPAND_GLOBAL_VARIABLES.each_value do |block|
    instance_exec(&block) if block
  end
end

#find_pokemon(criteria) ⇒ PFM::Pokemon?

Return the Pokemon that match the specific criteria

Parameters:

  • criteria (Hash)

    list of property linked to a value to check in order to find the Pokemon

Returns:



279
280
281
282
283
284
285
# File 'scripts/01450 Systems/00000 General/00010 GameState/00201 Management.rb', line 279

def find_pokemon(criteria)
  @actors.find do |pokemon|
    criteria.each do |property, value|
      break(false) unless pokemon.send(property) == value
    end
  end
end

#first_pokemon_alive_index

Index of the first pokemon alive in the party



44
45
46
# File 'scripts/01450 Systems/00000 General/00010 GameState/00201 Management.rb', line 44

def first_pokemon_alive_index
  return @actors.index { |pokemon| !pokemon.dead? }
end

#full?Boolean

Is the party full ?

Returns:

  • (Boolean)


17
18
19
# File 'scripts/01450 Systems/00000 General/00010 GameState/00201 Management.rb', line 17

def full?
  return @actors.size == 6
end

#hatch_check_update

Update the remaining steps of all the Egg to hatch



308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 308

def hatch_check_update
  return if cant_process_event_tasks?

  amca = FASTER_HATCH_ABILITIES.include?(@actors[0]&.ability_db_symbol || :__undef__)
  @actors.each do |pokemon|
    next unless pokemon.step_remaining > 0

    pokemon.step_remaining -= 1
    pokemon.step_remaining -= 1 if amca && (pokemon.step_remaining > 0)
    if pokemon.step_remaining == 0
      pokemon.egg_finish
      $scene.delay_display_call(:display_egg_hatch, pokemon)
    end
  end
end

#heal_party

Heal the pokemon in the Party



159
160
161
162
163
164
165
166
167
168
# File 'scripts/01450 Systems/00000 General/00010 GameState/00201 Management.rb', line 159

def heal_party
  @actors.each do |pokemon|
    next unless pokemon
    pokemon.cure
    pokemon.hp = pokemon.max_hp
    pokemon.skills_set.each do |skill|
      skill&.pp = skill.ppmax
    end
  end
end

#increase_stepsArray

Increase the @step and manage events that trigger each steps

Returns:

  • (Array)

    informations about events that has been triggered.



346
347
348
349
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 346

def increase_steps
  @steps += 1
  $game_party.steps = @steps
end

#load_parameters

Load some parameters (audio volume & text)



389
390
391
392
393
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 389

def load_parameters
  Audio.music_volume = @options.music_volume
  Audio.sfx_volume = @options.sfx_volume
  Studio::Text.load
end

#lose_money(n)

Lose money

Parameters:

  • n (Integer)

    amount of money to lose



381
382
383
384
385
386
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 381

def lose_money(n)
  return add_money(-n) if n < 0

  $game_party.gold -= n
  $game_party.gold = 0 if $game_party.gold < 0
end

#loyalty_update

Update the loyalty process of the pokemon



325
326
327
328
329
330
331
332
333
334
335
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 325

def loyalty_update
  return unless (@steps - (@steps / 128) * 128) == 0 && rand(2) == 0
  return if cant_process_event_tasks?

  @actors.each do |pokemon|
    value = pokemon.loyalty < 200 ? 2 : 1
    value *= 2 if data_item(pokemon.captured_with).db_symbol == :luxury_ball
    value *= 1.5 if pokemon.item_db_symbol == :soothe_bell
    pokemon.loyalty += value.floor
  end
end

#max_levelInteger

Return the maximum level of the Pokemon in the Party

Returns:



172
173
174
# File 'scripts/01450 Systems/00000 General/00010 GameState/00201 Management.rb', line 172

def max_level
  @actors.max_by(&:level)&.level || 0
end

#moneyInteger

Return the money the player has

Returns:



361
362
363
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 361

def money
  return $game_party.gold
end

#money=(v)

Change the money the player has

Parameters:



367
368
369
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 367

def money=(v)
  $game_party.gold = v.to_i
end

#online_idInteger

Retrieve the online ID of the trainer

Returns:



966
967
968
969
970
971
972
973
974
975
# File 'scripts/01450 Systems/09000 GTS/09000 GTS.rb', line 966

def online_id
  if @online_id.nil?
    id = GTS::Core.obtain_online_id
    raise('GTS Error: Cannot get Online ID for GTS!') if id == 0
    raise('GTS Error: Cannot set Online ID for GTS!') unless GTS::Core.register_online_id(id)

    @online_id = id
  end
  return @online_id
end

#poison_update

Update the processing of the poison event



280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 280

def poison_update
  return unless (@steps - (@steps / 8) * 8) == 0
  return if cant_process_event_tasks?

  psn_event = false
  @actors.each do |pokemon|
    next unless pokemon.poisoned? || pokemon.toxic?
    next if pokemon.ability_db_symbol == :immunity

    $scene.delay_display_call(:display_poison_animation) unless psn_event
    psn_event = true
    pokemon.hp -= (pokemon.toxic? ? 2 : 1)
    if pokemon.hp <= 0 && $game_switches[::Yuki::Sw::OW_Poison]
      $scene.delay_display_call(:display_poison_faint, pokemon)
    end
    next unless pokemon.hp <= 1 && !$game_switches[::Yuki::Sw::OW_Poison]

    pokemon.hp = 1
    pokemon.cure
    $scene.delay_display_call(:display_poison_end, pokemon)
  end
  nuzlocke.clear_dead_pokemon if nuzlocke.enabled?
end

#pokemon_ability_index(id) ⇒ Integer, false

Get the index of the Pokemon that has the specified ability

Parameters:

  • id (Integer, Symbol)

    ID of the ability in the database

Returns:



219
220
221
# File 'scripts/01450 Systems/00000 General/00010 GameState/00201 Management.rb', line 219

def pokemon_ability_index(id)
  has_ability?(id, true)
end

#pokemon_alive(max = @actors.size)

Number of pokemon alive in the party

Parameters:

  • max (Integer) (defaults to: @actors.size)

    the number of Pokemon to check from the begining of the party



35
36
37
38
39
40
41
# File 'scripts/01450 Systems/00000 General/00010 GameState/00201 Management.rb', line 35

def pokemon_alive(max = @actors.size)
  alive = 0
  max.times do |i|
    alive += 1 if @actors[i] && !@actors[i].dead?
  end
  return alive
end

#pokemon_index(id, level = nil, form = nil, shiny = nil) ⇒ Integer, false

Find a specific Pokemon index in the party

Parameters:

  • id (Integer, Symbol)

    id of the Pokemon in the database

  • level (Integer, nil) (defaults to: nil)

    the level required

  • form (Integer, nil) (defaults to: nil)

    the form of the Pokemon

  • shiny (Boolean, nil) (defaults to: nil)

    if the Pokemon should be shiny or not

Returns:

  • (Integer, false)

    index of the Pokemon in the party



154
155
156
# File 'scripts/01450 Systems/00000 General/00010 GameState/00201 Management.rb', line 154

def pokemon_index(id, level = nil, form = nil, shiny = nil)
  has_pokemon?(id, level, form, shiny, index: true)
end

#pokemon_skill_index(id) ⇒ Integer, false

Get the index of the Pokemon that has the specified skill

Parameters:

  • id (Integer, Symbol)

    ID of the skill in the database

Returns:



197
198
199
# File 'scripts/01450 Systems/00000 General/00010 GameState/00201 Management.rb', line 197

def pokemon_skill_index(id)
  has_skill?(id, true)
end

#raw_online_idInteger?

The raw_online_id doesn't have the checksum to get a new ID, this is used for when you do new game.

Returns:



980
981
982
# File 'scripts/01450 Systems/09000 GTS/09000 GTS.rb', line 980

def raw_online_id
  @online_id
end

#remove_pokemon(var, by_id = false, all = false)

Remove a pokemon from the party

Parameters:

  • var (Integer, Symbol)

    the var value (index or id)

  • by_id (Boolean) (defaults to: false)

    if the pokemon are removed by their id

  • all (Boolean) (defaults to: false)

    if every pokemon that has the id are removed



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'scripts/01450 Systems/00000 General/00010 GameState/00201 Management.rb', line 87

def remove_pokemon(var, by_id = false, all = false)
  var = data_creature(var).id if var.is_a?(Symbol)
  if by_id
    @actors.each_with_index do |pokemon, index|
      if pokemon.id == var
        @actors[index] = nil
        break unless all
      end
    end
  else
    @actors[var] = nil
  end
  @actors.compact!
end

#repel_update

Update the processing of the repel



261
262
263
264
265
266
267
268
# File 'scripts/01450 Systems/00000 General/00010 GameState/00200 Accessors.rb', line 261

def repel_update
  return if cant_process_event_tasks?

  if @repel_count > 0
    @repel_count -= 1
    $scene.delay_display_call(:display_repel_check) if @repel_count == 0
  end
end

#sizeInteger

Return the size of the party

Returns:



5
6
7
# File 'scripts/01450 Systems/00000 General/00010 GameState/00201 Management.rb', line 5

def size
  return @actors.size
end

#specific_alive?(id) ⇒ Boolean

Test if a specific Pokémon is able to fight or not

Examples:

Checking if Pikachu is alive in the party

PFM.game_state.specific_alive?(25)

Checking if alolan Meowth is alive in the party

PFM.game_state.specific_alive?(52) { |pokemon| pokemon.form == 1 }

Parameters:

  • id (Integer)

    ID of the Pokemon

Returns:

  • (Boolean)


55
56
57
58
59
60
61
# File 'scripts/01450 Systems/00000 General/00010 GameState/00201 Management.rb', line 55

def specific_alive?(id)
  if block_given?
    return @actors.any? { |pokemon| !pokemon.dead? && (pokemon.id == id || !id) && yield(pokemon) }
  else
    return @actors.any? { |pokemon| !pokemon.dead? && pokemon.id == id }
  end
end

#switch_pokemon(first, second)

Switch pokemon in the party

Parameters:

  • first (Integer)

    index of the first pokemon to switch

  • second (Integer)

    index of the second pokemon to switch



105
106
107
108
# File 'scripts/01450 Systems/00000 General/00010 GameState/00201 Management.rb', line 105

def switch_pokemon(first, second)
  @actors[first], @actors[second] = @actors[second], @actors[first]
  @actors.compact!
end