Class: PFM::Daycare

Inherits:
Object show all
Defined in:
scripts/01450 Systems/00201 Daycare/00001 PFM/01100 Daycare.rb

Overview

Daycare management system

The global Daycare manager is stored in $daycare and PFM.game_state.daycare Daycare data Hash format

pokemon: Array # The list of Pokemon in the daycare (PFM::Pokemon or nil)
level: Array # The list of level the Pokemon had when sent to the daycare
layable: Integer # ID of the Pokemon that can be in the egg
rate: Integer # Chance the egg can be layed
egg: Boolean # If an egg has been layed

Author:

  • Nuri Yuri

Defined Under Namespace

Classes: IncenseInfo

Constant Summary collapse

USE_FIRST_FORM_BREED_GROUPS =

Only use the FIRST FORM for breed groups

false
SPECIFIC_FORM_HANDLER =

Specific form handler (system that can force a for according to a code)

{
  myfakepokemon: proc { |_mother, _father| next(rand(10)) } # Returns a random form between 0 and 9
}
NOT_BREEDING =

List of Pokemon that cannot breed (event if the conditions are valid)

%i[phione manaphy]
BREEDING_WITH_DITTO =

List of Pokemon that only breed with Ditto

%i[phione manaphy]
DITTO_GROUP =

ID of the Ditto group

13
NOT_BREEDING_GROUP =

ID of the breed group that forbid breeding

15
PRICE_RATE =

List of price rate for all daycare

Returns:

Hash.new(100)
EGG_RATE =

Egg rate according to the common group, common OT, oval_charm (dig(common_group?, common_OT?, oval_charm?))

[
  [ # No Common Group
    [50, 80], # No Common OT. [no_oval_charm, oval_charm]
    [20, 40]  # Common OT. [no_oval_charm, oval_charm]
  ],
  [ # Common Group
    [70, 88], # No Common OT. [no_oval_charm, oval_charm]
    [50, 80]  # Common OT. [no_oval_charm, oval_charm]
  ]
]
BABY_VARIATION =

“Female” breeder that can have different baby (non-incense condition)

Returns:

  • (Hash{Symbol => Array})
{
  nidoranf: nidoran = %i[nidoranf nidoranm],
  nidoranm: nidoran,
  volbeat: volbeat = %i[volbeat illumise],
  illumise: volbeat,
  tauros: tauros = %i[tauros miltank],
  miltank: tauros
}
INCENSE_BABY =

“Female” that can have different baby if the male hold an incense

{
  marill: azurill = IncenseInfo.new(:sea_incense, :azurill),
  azumarill: azurill,
  wobbuffet: IncenseInfo.new(:lax_incense, :wynaut),
  roselia: budew = IncenseInfo.new(:rose_incense, :budew),
  roserade: budew,
  chimecho: IncenseInfo.new(:pure_incense, :chingling),
  sudowoodo: IncenseInfo.new(:rock_incense, :bonsly),
  mr_mime: IncenseInfo.new(:odd_incense, :mime_jr),
  chansey: happiny = IncenseInfo.new(:luck_incense, :happiny),
  blissey: happiny,
  snorlax: IncenseInfo.new(:full_incense, :munchlax),
  mantine: IncenseInfo.new(:wave_incense, :mantyke)
}
NON_INHERITED_BALL =

Non inherite balls

%i[master_ball cherish_ball]
IV_SET =

IV setter list

%i[iv_hp= iv_dfe= iv_atk= iv_spd= iv_ats= iv_dfs=]
IV_GET =

IV getter list

%i[iv_hp iv_dfe iv_atk iv_spd iv_ats iv_dfs]
IV_POWER_ITEM =

List of power item that transmit IV in the same order than IV_GET/IV_SET

%i[power_weight power_belt power_bracer power_anklet power_lens power_band]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(game_state = PFM.game_state) ⇒ Daycare

Create the daycare manager

Parameters:

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

    variable responsive of containing the whole game state for easier access



85
86
87
88
# File 'scripts/01450 Systems/00201 Daycare/00001 PFM/01100 Daycare.rb', line 85

def initialize(game_state = PFM.game_state)
  @daycares = []
  @game_state = game_state
end

Instance Attribute Details

#game_statePFM::GameState

Get the game state responsive of the whole game state

Returns:



81
82
83
# File 'scripts/01450 Systems/00201 Daycare/00001 PFM/01100 Daycare.rb', line 81

def game_state
  @game_state
end

Instance Method Details

#empty?(id) ⇒ Boolean

If a daycare is empty

Parameters:

  • id (Integer)

    the ID of the daycare

Returns:

  • (Boolean)


199
200
201
# File 'scripts/01450 Systems/00201 Daycare/00001 PFM/01100 Daycare.rb', line 199

def empty?(id)
  return @daycares.dig(id, :pokemon).empty?
end

#full?(id) ⇒ Boolean

If a daycare is full

Parameters:

  • id (Integer)

    the ID of the daycare

Returns:

  • (Boolean)


190
191
192
193
194
# File 'scripts/01450 Systems/00201 Daycare/00001 PFM/01100 Daycare.rb', line 190

def full?(id)
  return false unless (pokemon_list = @daycares.dig(id, :pokemon))

  return pokemon_list.size > 1
end

#get_pokemon(id, index, prop, *args) ⇒ Object

Get a Pokemon information in the daycare

Parameters:

  • id (Integer)

    the ID of the daycare

  • index (Integer)

    the index of the Pokemon in the daycare

  • prop (Symbol)

    the method to call of PFM::Pokemon to get the information

  • args (Array)

    the list of arguments of the property

Returns:



131
132
133
134
# File 'scripts/01450 Systems/00201 Daycare/00001 PFM/01100 Daycare.rb', line 131

def get_pokemon(id, index, prop, *args)
  return nil unless (pokemon = @daycares.dig(id, :pokemon, index))
  return pokemon.send(prop, *args)
end

#layed_egg?(id) ⇒ Boolean Also known as: has_egg?

If an egg was layed in this daycare

Parameters:

  • id (Integer)

    the ID of the daycare

Returns:

  • (Boolean)


182
183
184
# File 'scripts/01450 Systems/00201 Daycare/00001 PFM/01100 Daycare.rb', line 182

def layed_egg?(id)
  return @daycares.dig(id, :egg) == true
end

#parse_poke(var_id, index)

Parse the daycare Pokemon text info

Parameters:

  • var_id (Integer)

    ID of the game variable where the ID of the daycare is stored

  • index (Integer)

    index of the Pokemon in the daycare



206
207
208
209
210
211
212
213
# File 'scripts/01450 Systems/00201 Daycare/00001 PFM/01100 Daycare.rb', line 206

def parse_poke(var_id, index)
  # @type [PFM::Pokemon]
  pokemon = @daycares.dig(game_state.game_variables[var_id], :pokemon, index)
  (text = PFM::Text).set_num3(pokemon.level_text)
  text.set_num3(pokemon.level_text, 1)
  text.set_pkname(pokemon.name)
  parse_text(36, 33 + (pokemon.gender == 0 ? 3 : pokemon.gender))
end

#price(id, index) ⇒ Integer

Price to pay in order to withdraw a Pokemon

Parameters:

  • id (Integer)

    the ID of the daycare

  • index (Integer)

    the index of the Pokemon in the daycare

Returns:



120
121
122
123
# File 'scripts/01450 Systems/00201 Daycare/00001 PFM/01100 Daycare.rb', line 120

def price(id, index)
  return 0 unless (pokemon = @daycares.dig(id, :pokemon, index))
  return PRICE_RATE[id] * (pokemon.level - @daycares.dig(id, :level, index) + 1)
end

#retrieve_egg(id) ⇒ PFM::Pokemon Also known as: retreive_egg

Retrieve the egg layed

Parameters:

  • id (Integer)

    the ID of the daycare

Returns:



165
166
167
168
169
170
171
172
173
174
175
176
# File 'scripts/01450 Systems/00201 Daycare/00001 PFM/01100 Daycare.rb', line 165

def retrieve_egg(id)
  daycare = @daycares[id]
  daycare[:egg] = nil
  layable_check(daycare, daycare[:pokemon])
  log_debug "==== Pension Infos ====\nRate : #{daycare[:rate]}%\nPokémon : #{text_get(0, daycare[:layable])}\n"
  pokemon = PFM::Pokemon.new(daycare[:layable], 1)
  inherit(pokemon, daycare[:pokemon])
  pokemon.hp = pokemon.max_hp
  pokemon.egg_init
  pokemon.memo_text = [28, 31]
  return pokemon
end

#retrieve_egg_rate(id) ⇒ Integer Also known as: retreive_egg_rate

Get the egg rate of a daycare

Parameters:

  • id (Integer)

    the ID of the daycare

Returns:



157
158
159
# File 'scripts/01450 Systems/00201 Daycare/00001 PFM/01100 Daycare.rb', line 157

def retrieve_egg_rate(id)
  return @daycares[id][:rate].to_i
end

#retrieve_pokemon(id, index) ⇒ PFM::Pokemon? Also known as: withdraw_pokemon, retreive_pokemon

Withdraw a Pokemon from a daycare

Parameters:

  • id (Integer)

    the ID of the daycare

  • index (Integer)

    the index of the Pokemon in the daycare

Returns:



140
141
142
143
144
145
146
147
148
149
150
# File 'scripts/01450 Systems/00201 Daycare/00001 PFM/01100 Daycare.rb', line 140

def retrieve_pokemon(id, index)
  return nil unless (daycare = @daycares[id]) && (pokemon = daycare.dig(:pokemon, index))

  daycare[:pokemon][index] = nil
  daycare[:level][index] = nil
  daycare[:pokemon].compact!
  daycare[:level].compact!
  daycare[:rate] = 0
  daycare[:layable] = 0
  return pokemon
end

#store(id, pokemon) ⇒ Boolean

Store a Pokemon to a daycare

Parameters:

  • id (Integer)

    the ID of the daycare

  • pokemon (PFM::Pokemon)

    the pokemon to store in the daycare

Returns:

  • (Boolean)

    if the pokemon could be stored in the daycare



104
105
106
107
108
109
110
111
112
113
114
# File 'scripts/01450 Systems/00201 Daycare/00001 PFM/01100 Daycare.rb', line 104

def store(id, pokemon)
  @daycares[id] ||= { pokemon: [], level: [], layable: 0, rate: 0, egg: nil }
  return false if full?(id)

  daycare = @daycares[id]
  daycare[:level][daycare[:pokemon].size] = pokemon.level
  daycare[:pokemon] << pokemon
  layable_check(daycare, daycare[:pokemon]) if daycare[:pokemon].size == 2
  log_debug "==== Pension Infos ====\nRate : #{daycare[:rate]}%\nPokémon : #{text_get(0, daycare[:layable])}\n"
  return true
end

#update

Update every daycare



91
92
93
94
95
96
97
98
# File 'scripts/01450 Systems/00201 Daycare/00001 PFM/01100 Daycare.rb', line 91

def update
  check_egg = should_check_eggs?
  @daycares.each do |daycare|
    next unless daycare
    daycare[:pokemon].each { |pokemon| exp_pokemon(pokemon) }
    try_to_lay(daycare) if check_egg && (daycare[:layable] || 0) != 0
  end
end