Class: PFM::Pokedex

Inherits:
Object show all
Defined in:
scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb

Overview

The Pokedex informations

The main Pokedex object is stored in $pokedex or PFM.game_state.pokedex

All Creature are usually marked as seen or captured in the correct scripts using $pokedex.mark_seen(id) or $pokedex.mark_captured(id).

When the Pokedex is disabled, no Creature can be marked as seen (unless they're added to the party). All caught Creature are marked as captured so if for scenaristic reason you need the trainer to catch Creature before having the Pokedex. Don't forget to call $pokedex.unmark_captured(id) (as well $pokedex.unmark_seen(id))

Author:

  • Nuri Yuri

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(game_state = PFM.game_state) ⇒ Pokedex

Create a new Pokedex object

Parameters:

  • game_state (PFM::GameState) (defaults to: PFM.game_state)

    game state storing this instance



28
29
30
31
32
33
34
35
36
37
38
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 28

def initialize(game_state = PFM.game_state)
  @seen = 0
  @captured = 0
  @has_seen_and_forms = Hash.new(0)
  @has_captured = []
  @nb_fought = Hash.new(0)
  @nb_captured = Hash.new(0)
  @game_state = game_state
  @variant = :regional
  @seen_variants = [@variant]
end

Instance Attribute Details

#game_statePFM::GameState

Get the game state responsive of the whole game state

Returns:



16
17
18
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 16

def game_state
  @game_state
end

#seen_variantsArray<Symbol> (readonly)

Get the list of seen variants

Returns:

  • (Array<Symbol>)


24
25
26
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 24

def seen_variants
  @seen_variants
end

#variantSymbol

Get the current dex variant

Returns:

  • (Symbol)


20
21
22
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 20

def variant
  @variant
end

Instance Method Details

#best_worldmap_for_creature(db_symbol) ⇒ Integer Also known as: best_worldmap_pokemon

Detect the best worldmap to display for the creature

Parameters:

  • db_symbol (Symbol)

    db_symbol of the creature we want the worldmap to display

Returns:



310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 310

def best_worldmap_for_creature(db_symbol)
  default = @game_state.env.get_worldmap
  return default if each_data_world_map.size == 0

  zone_db_symbols = spawn_zones(db_symbol)
  return default if zone_db_symbols.empty?

  world_maps = zone_db_symbols.map { |zone_db_symbol| data_zone(zone_db_symbol).worldmaps }.flatten.compact
  return default if world_maps.empty?

  best_id = world_maps.group_by { |id| id }.map { |k, v| [k, v.size] }.max_by(&:last).first
  return best_id || default
end

#calibrate

Calibrate the Pokedex information (seen/captured)



299
300
301
302
303
304
305
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 299

def calibrate
  @has_seen_and_forms.delete_if { |_, v| v == 0 }
  @seen = @has_seen_and_forms.size
  @captured = @has_captured.size
  @game_state.game_variables[Yuki::Var::Pokedex_Catch] = @captured
  @game_state.game_variables[Yuki::Var::Pokedex_Seen] = @seen
end

#convert_to_dot26

Convert the dex to .26 format



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 41

def convert_to_dot26
  @variant ||= :regional
  @seen_variants ||= [@variant]
  if @has_seen_and_forms.is_a?(Hash)
    @has_seen_and_forms.delete_if { |_, v| v.nil? } if @has_seen_and_forms.value?(nil)
    @nb_fought.delete_if { |_, v| v.nil? } if @nb_fought.value?(nil)
    @nb_captured.delete_if { |_, v| v.nil? } if @nb_captured.value?(nil)
    return
  end

  all_db_symbols = [
    @has_seen_and_forms.size,
    @has_captured.size,
    @nb_fought.size,
    @nb_captured.size
  ].max.times.map { |i| data_creature(i).db_symbol }

  has_seen_and_forms = @has_seen_and_forms.map.with_index { |v, i| !v || v == 0 ? nil : [all_db_symbols[i], v] }.compact.to_h
  has_captured = @has_captured.map.with_index { |v, i| v ? all_db_symbols[i] : nil }.compact
  nb_fought = @nb_fought.map.with_index { |v, i| !v || v == 0 ? nil : [all_db_symbols[i], v] }.compact.to_h
  nb_captured = @nb_captured.map.with_index { |v, i| !v || v == 0 ? nil : [all_db_symbols[i], v] }.compact.to_h

  @has_seen_and_forms = Hash.new(0)
  @has_seen_and_forms.merge!(has_seen_and_forms)
  @has_captured = has_captured
  @nb_fought = Hash.new(0)
  @nb_fought.merge!(nb_fought)
  @nb_captured = Hash.new(0)
  @nb_captured.merge!(nb_captured)
end

#creature_caughtInteger Also known as: pokemon_captured

Return the number of caught Creature

Returns:



125
126
127
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 125

def creature_caught
  return @captured
end

#creature_caught?(db_symbol) ⇒ Boolean Also known as: pokemon_caught?, has_captured?

Has the player caught this Creature

Parameters:

  • db_symbol (Symbol)

    db_symbol of the Creature in the database

Returns:

  • (Boolean)


269
270
271
272
273
274
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 269

def creature_caught?(db_symbol)
  db_symbol = data_creature(db_symbol).db_symbol if db_symbol.is_a?(Integer)
  return false if db_symbol == :__undef__

  return @has_captured.include?(db_symbol)
end

#creature_caught_count(db_symbol) ⇒ Integer

Return the number of Creature captured by specie

Parameters:

  • db_symbol (Symbol)

    db_symbol of the Creature in the database

Returns:



133
134
135
136
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 133

def creature_caught_count(db_symbol)
  db_symbol = data_creature(db_symbol).db_symbol if db_symbol.is_a?(Integer)
  return @nb_captured[db_symbol]
end

#creature_fought(db_symbol) ⇒ Integer

Return the number of Creature fought by specie

Parameters:

  • db_symbol (Symbol)

    db_symbol of the Creature in the database

Returns:



165
166
167
168
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 165

def creature_fought(db_symbol)
  db_symbol = data_creature(db_symbol).db_symbol if db_symbol.is_a?(Integer)
  return @nb_fought[db_symbol]
end

#creature_seenInteger Also known as: pokemon_seen

Return the number of Creature seen

Returns:



118
119
120
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 118

def creature_seen
  return @seen
end

#creature_seen?(db_symbol) ⇒ Boolean Also known as: pokemon_seen?, has_seen?

Has the player seen a Creature

Parameters:

  • db_symbol (Symbol)

    db_symbol of the Creature in the database

Returns:

  • (Boolean)


257
258
259
260
261
262
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 257

def creature_seen?(db_symbol)
  db_symbol = data_creature(db_symbol).db_symbol if db_symbol.is_a?(Integer)
  return false if db_symbol == :__undef__

  return @has_seen_and_forms[db_symbol] != 0
end

#creature_unlocked?(db_symbol) ⇒ Boolean

Tell if the creature is unlocked in the current dex state

Parameters:

  • db_symbol (Symbol)

Returns:

  • (Boolean)


292
293
294
295
296
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 292

def creature_unlocked?(db_symbol)
  return true if national?

  return data_dex(@variant).creatures.any? { |creature| creature.db_symbol == db_symbol }
end

#disable

Disable the Pokedex



84
85
86
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 84

def disable
  @game_state.game_switches[Yuki::Sw::Pokedex] = false
end

#enable

Enable the Pokedex



73
74
75
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 73

def enable
  @game_state.game_switches[Yuki::Sw::Pokedex] = true
end

#enabled?Boolean

Test if the Pokedex is enabled

Returns:

  • (Boolean)


79
80
81
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 79

def enabled?
  @game_state.game_switches[Yuki::Sw::Pokedex]
end

#form_seen(db_symbol) ⇒ Integer Also known as: get_forms

Get the seen forms informations of a Creature

Parameters:

  • db_symbol (Symbol)

    db_symbol of the Creature in the database

Returns:

  • (Integer)

    An interger where int == 1 mean the form has been seen



281
282
283
284
285
286
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 281

def form_seen(db_symbol)
  db_symbol = data_creature(db_symbol).db_symbol if db_symbol.is_a?(Integer)
  return 0 if db_symbol == :__undef__

  return @has_seen_and_forms[db_symbol]
end

#increase_creature_caught_count(db_symbol) Also known as: pokemon_captured_inc

Increase the number of Creature captured by specie

Parameters:

  • db_symbol (Symbol)

    db_symbol of the Creature in the database



152
153
154
155
156
157
158
159
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 152

def increase_creature_caught_count(db_symbol)
  return unless enabled?

  db_symbol = data_creature(db_symbol).db_symbol if db_symbol.is_a?(Integer)
  return if db_symbol == :__undef__

  @nb_captured[db_symbol] += 1
end

#increase_creature_fought(db_symbol) Also known as: pokemon_fought_inc

Increase the number of Creature fought by specie

Parameters:

  • db_symbol (Symbol)

    db_symbol of the Creature in the database



184
185
186
187
188
189
190
191
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 184

def increase_creature_fought(db_symbol)
  return unless enabled?

  db_symbol = data_creature(db_symbol).db_symbol if db_symbol.is_a?(Integer)
  return if db_symbol == :__undef__

  @nb_fought[db_symbol] += 1
end

#mark_captured(db_symbol)

Mark a Creature as captured

Parameters:

  • db_symbol (Symbol)

    db_symbol of the Creature in the database



229
230
231
232
233
234
235
236
237
238
239
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 229

def mark_captured(db_symbol)
  db_symbol = data_creature(db_symbol).db_symbol if db_symbol.is_a?(Integer)
  return if db_symbol == :__undef__
  return unless creature_unlocked?(db_symbol)

  unless @has_captured.include?(db_symbol)
    @has_captured << db_symbol
    @captured += 1
  end
  @game_state.game_variables[Yuki::Var::Pokedex_Catch] = @captured
end

#mark_seen(db_symbol, form = 0, forced: false)

Mark a creature as seen

Parameters:

  • db_symbol (Symbol)

    db_symbol of the Creature in the database

  • form (Integer) (defaults to: 0)

    the specific form of the Creature

  • forced (Boolean) (defaults to: false)

    if the Creature is marked seen even if the Pokedex is disabled (Giving Creature before givin the Pokedex).



199
200
201
202
203
204
205
206
207
208
209
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 199

def mark_seen(db_symbol, form = 0, forced: false)
  return unless enabled? || forced

  db_symbol = data_creature(db_symbol).db_symbol if db_symbol.is_a?(Integer)
  return if db_symbol == :__undef__
  return unless creature_unlocked?(db_symbol) || forced

  @seen += 1 if @has_seen_and_forms[db_symbol] == 0
  @has_seen_and_forms[db_symbol] |= (1 << form)
  @game_state.game_variables[Yuki::Var::Pokedex_Seen] = @seen
end

#national=(mode) Also known as: set_national

Set the national flag of the Pokedex

Parameters:

  • mode (Boolean)

    the flag



90
91
92
93
94
95
96
97
98
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 90

def national=(mode)
  @game_state.game_switches[Yuki::Sw::Pokedex_Nat] = (mode == true)
  if mode
    self.variant = :national
  else
    @seen_variants.delete(:national)
    self.variant = @seen_variants.first || :regional
  end
end

#national?Boolean

Is the Pokedex showing national Creature

Returns:

  • (Boolean)


112
113
114
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 112

def national?
  return @game_state.game_switches[Yuki::Sw::Pokedex_Nat]
end

#set_creature_caught_count(db_symbol, number)

Change the number of Creature captured by specie

Parameters:

  • db_symbol (Symbol)

    db_symbol of the Creature in the database

  • number (Integer)

    the new number



141
142
143
144
145
146
147
148
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 141

def set_creature_caught_count(db_symbol, number)
  return unless enabled?

  db_symbol = data_creature(db_symbol).db_symbol if db_symbol.is_a?(Integer)
  return if db_symbol == :__undef__

  @nb_captured[db_symbol] = number.to_i
end

#set_creature_fought(db_symbol, number)

Change the number of Creature fought by specie

Parameters:

  • db_symbol (Symbol)

    db_symbol of the Creature in the database

  • number (Integer)

    the number of Creature fought in the specified specie



173
174
175
176
177
178
179
180
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 173

def set_creature_fought(db_symbol, number)
  return unless enabled?

  db_symbol = data_creature(db_symbol).db_symbol if db_symbol.is_a?(Integer)
  return if db_symbol == :__undef__

  @nb_fought[db_symbol] = number.to_i
end

#spawn_zones(db_symbol) ⇒ Array<Symbol>

Return the list of the zone id where the creature spawns

Parameters:

  • db_symbol (Symbol)

    db_symbol of the creature we want to know where it spawns

Returns:

  • (Array<Symbol>)


328
329
330
331
332
333
334
335
336
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 328

def spawn_zones(db_symbol)
  # @type [Array<Studio::Zone>]
  zones = each_data_zone.select do |zone|
    # @type [Array<Studio::Group>]
    groups = zone.wild_groups.map { |group_db_symbol| data_group(group_db_symbol) }
    next groups.any? { |group| group.encounters.any? { |encounter| encounter.specie == db_symbol } }
  end
  return zones.map(&:db_symbol)
end

#unmark_captured(db_symbol)

Unmark a Creature as captured

Parameters:

  • db_symbol (Symbol)

    db_symbol of the Creature in the database



243
244
245
246
247
248
249
250
251
252
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 243

def unmark_captured(db_symbol)
  db_symbol = data_creature(db_symbol).db_symbol if db_symbol.is_a?(Integer)
  return if db_symbol == :__undef__

  if @has_captured.include?(db_symbol)
    @has_captured.delete(db_symbol)
    @captured -= 1
  end
  @game_state.game_variables[Yuki::Var::Pokedex_Catch] = @captured
end

#unmark_seen(db_symbol, form: false)

Unmark a creature as seen

Parameters:

  • db_symbol (Symbol)

    db_symbol of the Creature in the database

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

    if false, all form will be unseen, otherwise the specific form will be unseen



214
215
216
217
218
219
220
221
222
223
224
225
# File 'scripts/01450 Systems/00101 Dex/00001 PFM/00100 Pokedex.rb', line 214

def unmark_seen(db_symbol, form: false)
  db_symbol = data_creature(db_symbol).db_symbol if db_symbol.is_a?(Integer)
  return if db_symbol == :__undef__

  if form
    @has_seen_and_forms[db_symbol] &= ~(1 << form)
  else
    @has_seen_and_forms.delete(db_symbol)
  end
  @seen -= 1 if !form || @has_seen_and_forms[db_symbol] == 0
  @game_state.game_variables[Yuki::Var::Pokedex_Seen] = @seen
end