Sonicover

Pokemon Class code

Aug 12th, 2024
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 42.88 KB | None | 0 0
  1. #===============================================================================
  2. # Instances of this class are individual Pokémon.
  3. # The player's party Pokémon are stored in the array $player.party.
  4. #===============================================================================
  5. class Pokemon
  6.   # @return [Symbol] this Pokémon's species
  7.   attr_reader   :species
  8.   # If defined, this Pokémon's form will be this value even if a MultipleForms
  9.   # handler tries to say otherwise.
  10.   # @return [Integer, nil] this Pokémon's form
  11.   attr_accessor :forced_form
  12.   # If defined, is the time (in Integer form) when this Pokémon's form was set.
  13.   # @return [Integer, nil] the time this Pokémon's form was set
  14.   attr_accessor :time_form_set
  15.   # @return [Integer] the current experience points
  16.   attr_reader   :exp
  17.   # @return [Integer] the number of steps until this Pokémon hatches, 0 if this Pokémon is not an egg
  18.   attr_accessor :steps_to_hatch
  19.   # @return [Integer] the current HP
  20.   attr_reader   :hp
  21.   # @return [Symbol] this Pokémon's current status (see GameData::Status)
  22.   attr_reader   :status
  23.   # @return [Integer] sleep count / toxic flag / 0:
  24.   #   sleep (number of rounds before waking up), toxic (0 = regular poison, 1 = toxic)
  25.   attr_accessor :statusCount
  26.   # This Pokémon's shininess (true, false, nil). Is recalculated if made nil.
  27.   # @param value [Boolean, nil] whether this Pokémon is shiny
  28.   attr_writer   :shiny
  29.   # @return [Array<Pokemon::Move>] the moves known by this Pokémon
  30.   attr_accessor :moves
  31.   # @return [Array<Symbol>] the IDs of moves known by this Pokémon when it was obtained
  32.   attr_accessor :first_moves
  33.   # @return [Array<Symbol>] an array of ribbons owned by this Pokémon
  34.   attr_accessor :ribbons
  35.   # @return [Integer] contest stats
  36.   attr_accessor :cool, :beauty, :cute, :smart, :tough, :sheen
  37.   # @return [Integer] the Pokérus strain and infection time
  38.   attr_accessor :pokerus
  39.   # @return [Integer] this Pokémon's current happiness (an integer between 0 and 255)
  40.   attr_accessor :happiness
  41.   # @return [Symbol] the item ID of the Poké Ball this Pokémon is in
  42.   attr_accessor :poke_ball
  43.   # @return [Array<Integer>] this Pokémon's markings, one value per mark
  44.   attr_accessor :markings
  45.   # @return [Hash<Integer>] a hash of IV values for HP, Atk, Def, Speed, Sp. Atk and Sp. Def
  46.   attr_accessor :iv
  47.   # An array of booleans indicating whether a stat is made to have maximum IVs
  48.   # (for Hyper Training). Set like @ivMaxed[:ATTACK] = true
  49.   # @return [Hash<Boolean>] a hash of booleans that max each IV value
  50.   attr_accessor :ivMaxed
  51.   # @return [Hash<Integer>] this Pokémon's effort values
  52.   attr_accessor :ev
  53.   # @return [Integer] calculated stats
  54.   attr_reader   :totalhp, :attack, :defense, :spatk, :spdef, :speed
  55.   # @return [Owner] this Pokémon's owner
  56.   attr_reader   :owner
  57.   # @return [Integer] the manner this Pokémon was obtained:
  58.   #   0 (met), 1 (as egg), 2 (traded), 4 (fateful encounter)
  59.   attr_accessor :obtain_method
  60.   # @return [Integer] the ID of the map this Pokémon was obtained in
  61.   attr_accessor :obtain_map
  62.   # Describes the manner this Pokémon was obtained. If left undefined,
  63.   # the obtain map's name is used.
  64.   # @return [String] the obtain text
  65.   attr_accessor :obtain_text
  66.   # @return [Integer] the level of this Pokémon when it was obtained
  67.   attr_accessor :obtain_level
  68.   # If this Pokémon hatched from an egg, returns the map ID where the hatching happened.
  69.   # Otherwise returns 0.
  70.   # @return [Integer] the map ID where egg was hatched (0 by default)
  71.   attr_accessor :hatched_map
  72.   # Another Pokémon which has been fused with this Pokémon (or nil if there is none).
  73.   # Currently only used by Kyurem, to record a fused Reshiram or Zekrom.
  74.   # @return [Pokemon, nil] the Pokémon fused into this one (nil if there is none)
  75.   attr_accessor :fused
  76.   # @return [Integer] this Pokémon's personal ID
  77.   attr_accessor :personalID
  78.   # Used by Galarian Yamask to remember that it took sufficient damage from a
  79.   # battle and can evolve.
  80.   attr_accessor :ready_to_evolve
  81.   # Whether this Pokémon can be deposited in storage/Day Care
  82.   attr_accessor :cannot_store
  83.   # Whether this Pokémon can be released
  84.   attr_accessor :cannot_release
  85.   # Whether this Pokémon can be traded
  86.   attr_accessor :cannot_trade
  87.  
  88.   # Max total IVs
  89.   IV_STAT_LIMIT = 31
  90.   # Max total EVs
  91.   EV_LIMIT      = 510
  92.   # Max EVs that a single stat can have
  93.   EV_STAT_LIMIT = 252
  94.   # Maximum length a Pokémon's nickname can be
  95.   MAX_NAME_SIZE = 10
  96.   # Maximum number of moves a Pokémon can know at once
  97.   MAX_MOVES     = 4
  98.  
  99.   def self.play_cry(species, form = 0, volume = 90, pitch = 100)
  100.     GameData::Species.play_cry_from_species(species, form, volume, pitch)
  101.   end
  102.  
  103.   def play_cry(volume = 90, pitch = nil)
  104.     GameData::Species.play_cry_from_pokemon(self, volume, pitch)
  105.   end
  106.  
  107.   def inspect
  108.     str = super.chop
  109.     str << sprintf(" %s Lv.%s>", @species, @level.to_s || "???")
  110.     return str
  111.   end
  112.  
  113.   def species_data
  114.     return GameData::Species.get_species_form(@species, form_simple)
  115.   end
  116.  
  117.   #=============================================================================
  118.   # Species and form
  119.   #=============================================================================
  120.  
  121.   # Changes the Pokémon's species and re-calculates its statistics.
  122.   # @param species_id [Symbol, String, GameData::Species] ID of the species to change this Pokémon to
  123.   def species=(species_id)
  124.     new_species_data = GameData::Species.get(species_id)
  125.     return if @species == new_species_data.species
  126.     @species     = new_species_data.species
  127.     default_form = new_species_data.default_form
  128.     if default_form >= 0
  129.       @form      = default_form
  130.     elsif new_species_data.form > 0
  131.       @form      = new_species_data.form
  132.     end
  133.     @forced_form = nil
  134.     @gender      = nil if singleGendered?
  135.     @level       = nil   # In case growth rate is different for the new species
  136.     @ability     = nil
  137.     calc_stats
  138.   end
  139.  
  140.   # @param check_species [Symbol, String, GameData::Species] ID of the species to check for
  141.   # @return [Boolean] whether this Pokémon is of the specified species
  142.   def isSpecies?(check_species)
  143.     return @species == check_species || (GameData::Species.exists?(check_species) &&
  144.                                         @species == GameData::Species.get(check_species).species)
  145.   end
  146.  
  147.   def form
  148.     return @forced_form if !@forced_form.nil?
  149.     return @form if $game_temp.in_battle || $game_temp.in_storage
  150.     calc_form = MultipleForms.call("getForm", self)
  151.     self.form = calc_form if calc_form && calc_form != @form
  152.     return @form
  153.   end
  154.  
  155.   def form_simple
  156.     return @forced_form || @form
  157.   end
  158.  
  159.   def form=(value)
  160.     oldForm = @form
  161.     @form = value
  162.     @ability = nil
  163.     MultipleForms.call("onSetForm", self, value, oldForm)
  164.     calc_stats
  165.     $player&.pokedex&.register(self)
  166.   end
  167.  
  168.   # The same as def form=, but yields to a given block in the middle so that a
  169.   # message about the form changing can be shown before calling "onSetForm"
  170.   # which may have its own messages, e.g. learning a move.
  171.   def setForm(value)
  172.     oldForm = @form
  173.     @form = value
  174.     @ability = nil
  175.     yield if block_given?
  176.     MultipleForms.call("onSetForm", self, value, oldForm)
  177.     calc_stats
  178.     $player&.pokedex&.register(self)
  179.   end
  180.  
  181.   def form_simple=(value)
  182.     @form = value
  183.     calc_stats
  184.   end
  185.  
  186.   #=============================================================================
  187.   # Level
  188.   #=============================================================================
  189.  
  190.   # @return [Integer] this Pokémon's level
  191.   def level
  192.     @level = growth_rate.level_from_exp(@exp) if !@level
  193.     return @level
  194.   end
  195.  
  196.   # Sets this Pokémon's level. The given level must be between 1 and the
  197.   # maximum level (defined in {GameData::GrowthRate}).
  198.   # @param value [Integer] new level (between 1 and the maximum level)
  199.   def level=(value)
  200.     if value < 1 || value > GameData::GrowthRate.max_level
  201.       raise ArgumentError.new(_INTL("The level number ({1}) is invalid.", value))
  202.     end
  203.     @exp = growth_rate.minimum_exp_for_level(value)
  204.     @level = value
  205.   end
  206.  
  207.   # Sets this Pokémon's Exp. Points.
  208.   # @param value [Integer] new experience points
  209.   def exp=(value)
  210.     @exp = value
  211.     @level = nil
  212.   end
  213.  
  214.   # @return [Boolean] whether this Pokémon is an egg
  215.   def egg?
  216.     return @steps_to_hatch > 0
  217.   end
  218.  
  219.   # @return [GameData::GrowthRate] this Pokémon's growth rate
  220.   def growth_rate
  221.     return GameData::GrowthRate.get(species_data.growth_rate)
  222.   end
  223.  
  224.   # @return [Integer] this Pokémon's base Experience value
  225.   def base_exp
  226.     return species_data.base_exp
  227.   end
  228.  
  229.   # @return [Float] a number between 0 and 1 indicating how much of the current level's
  230.   #   Exp this Pokémon has
  231.   def exp_fraction
  232.     lvl = self.level
  233.     return 0.0 if lvl >= GameData::GrowthRate.max_level
  234.     g_rate = growth_rate
  235.     start_exp = g_rate.minimum_exp_for_level(lvl)
  236.     end_exp   = g_rate.minimum_exp_for_level(lvl + 1)
  237.     return (@exp - start_exp).to_f / (end_exp - start_exp)
  238.   end
  239.  
  240.   #=============================================================================
  241.   # Status
  242.   #=============================================================================
  243.  
  244.   # Sets the Pokémon's health.
  245.   # @param value [Integer] new HP value
  246.   def hp=(value)
  247.     @hp = value.clamp(0, @totalhp)
  248.     heal_status if @hp == 0
  249.     @ready_to_evolve = false if @hp == 0
  250.   end
  251.  
  252.   # Sets this Pokémon's status. See {GameData::Status} for all possible status effects.
  253.   # @param value [Symbol, String, GameData::Status] status to set
  254.   def status=(value)
  255.     return if !able?
  256.     new_status = GameData::Status.try_get(value)
  257.     if !new_status
  258.       raise ArgumentError, _INTL("Attempted to set {1} as Pokémon status", value.class.name)
  259.     end
  260.     @status = new_status.id
  261.   end
  262.  
  263.   # @return [Boolean] whether the Pokémon is not fainted and not an egg
  264.   def able?
  265.     return !egg? && @hp > 0
  266.   end
  267.  
  268.   # @return [Boolean] whether the Pokémon is fainted
  269.   def fainted?
  270.     return !egg? && @hp <= 0
  271.   end
  272.  
  273.   # Heals all HP of this Pokémon.
  274.   def heal_HP
  275.     return if egg?
  276.     @hp = @totalhp
  277.   end
  278.  
  279.   # Heals the status problem of this Pokémon.
  280.   def heal_status
  281.     return if egg?
  282.     @status      = :NONE
  283.     @statusCount = 0
  284.   end
  285.  
  286.   # Restores all PP of this Pokémon. If a move index is given, restores the PP
  287.   # of the move in that index.
  288.   # @param move_index [Integer] index of the move to heal (-1 if all moves
  289.   #   should be healed)
  290.   def heal_PP(move_index = -1)
  291.     return if egg?
  292.     if move_index >= 0
  293.       @moves[move_index].pp = @moves[move_index].total_pp
  294.     else
  295.       @moves.each { |m| m.pp = m.total_pp }
  296.     end
  297.   end
  298.  
  299.   # Heals all HP, PP, and status problems of this Pokémon.
  300.   def heal
  301.     return if egg?
  302.     heal_HP
  303.     heal_status
  304.     heal_PP
  305.     @ready_to_evolve = false
  306.   end
  307.  
  308.   #=============================================================================
  309.   # Types
  310.   #=============================================================================
  311.  
  312.   # @return [Array<Symbol>] an array of this Pokémon's types
  313.   def types
  314.     return species_data.types.clone
  315.   end
  316.  
  317.   # @deprecated This method is slated to be removed in v22.
  318.   def type1
  319.     Deprecation.warn_method("type1", "v22", "pkmn.types")
  320.     return types[0]
  321.   end
  322.  
  323.   # @deprecated This method is slated to be removed in v22.
  324.   def type2
  325.     Deprecation.warn_method("type2", "v22", "pkmn.types")
  326.     return types[1] || types[0]
  327.   end
  328.  
  329.   # @param type [Symbol, String, GameData::Type] type to check
  330.   # @return [Boolean] whether this Pokémon has the specified type
  331.   def hasType?(type)
  332.     type = GameData::Type.get(type).id
  333.     return self.types.include?(type)
  334.   end
  335.  
  336.   #=============================================================================
  337.   # Gender
  338.   #=============================================================================
  339.  
  340.   # @return [0, 1, 2] this Pokémon's gender (0 = male, 1 = female, 2 = genderless)
  341.   def gender
  342.     if !@gender
  343.       if species_data.single_gendered?
  344.         case species_data.gender_ratio
  345.         when :AlwaysMale   then @gender = 0
  346.         when :AlwaysFemale then @gender = 1
  347.         else                    @gender = 2
  348.         end
  349.       else
  350.         female_chance = GameData::GenderRatio.get(species_data.gender_ratio).female_chance
  351.         @gender = ((@personalID & 0xFF) < female_chance) ? 1 : 0
  352.       end
  353.     end
  354.     return @gender
  355.   end
  356.  
  357.   # Sets this Pokémon's gender to a particular gender (if possible).
  358.   # @param value [0, 1] new gender (0 = male, 1 = female)
  359.   def gender=(value)
  360.     return if singleGendered?
  361.     @gender = value if value.nil? || value == 0 || value == 1
  362.   end
  363.  
  364.   # Makes this Pokémon male.
  365.   def makeMale; self.gender = 0; end
  366.  
  367.   # Makes this Pokémon female.
  368.   def makeFemale; self.gender = 1; end
  369.  
  370.   # @return [Boolean] whether this Pokémon is male
  371.   def male?; return self.gender == 0; end
  372.  
  373.   # @return [Boolean] whether this Pokémon is female
  374.   def female?; return self.gender == 1; end
  375.  
  376.   # @return [Boolean] whether this Pokémon is genderless
  377.   def genderless?; return self.gender == 2; end
  378.  
  379.   # @return [Boolean] whether this Pokémon species is restricted to only ever being one
  380.   #   gender (or genderless)
  381.   def singleGendered?
  382.     return species_data.single_gendered?
  383.   end
  384.  
  385.   #=============================================================================
  386.   # Shininess
  387.   #=============================================================================
  388.  
  389.   # @return [Boolean] whether this Pokémon is shiny (differently colored)
  390.   def shiny?
  391.     if @shiny.nil?
  392.       a = @personalID ^ @owner.id
  393.       b = a & 0xFFFF
  394.       c = (a >> 16) & 0xFFFF
  395.       d = b ^ c
  396.       @shiny = d < Settings::SHINY_POKEMON_CHANCE
  397.     end
  398.     return @shiny
  399.   end
  400.  
  401.   # @return [Boolean] whether this Pokémon is super shiny (differently colored,
  402.   #   square sparkles)
  403.   def super_shiny?
  404.     if @super_shiny.nil?
  405.       a = @personalID ^ @owner.id
  406.       b = a & 0xFFFF
  407.       c = (a >> 16) & 0xFFFF
  408.       d = b ^ c
  409.       @super_shiny = (d == 0)
  410.     end
  411.     return @super_shiny
  412.   end
  413.  
  414.   # @param value [Boolean] whether this Pokémon is super shiny
  415.   def super_shiny=(value)
  416.     @super_shiny = value
  417.     @shiny = true if @super_shiny
  418.   end
  419.  
  420.   #=============================================================================
  421.   # Ability
  422.   #=============================================================================
  423.  
  424.   # The index of this Pokémon's ability (0, 1 are natural abilities, 2+ are
  425.   # hidden abilities) as defined for its species/form. An ability may not be
  426.   # defined at this index. Is recalculated (as 0 or 1) if made nil.
  427.   # @return [Integer] the index of this Pokémon's ability
  428.   def ability_index
  429.     @ability_index = (@personalID & 1) if !@ability_index
  430.     return @ability_index
  431.   end
  432.  
  433.   # @param value [Integer, nil] forced ability index (nil if none is set)
  434.   def ability_index=(value)
  435.     @ability_index = value
  436.     @ability = nil
  437.   end
  438.  
  439.   # @return [GameData::Ability, nil] an Ability object corresponding to this Pokémon's ability
  440.   def ability
  441.     return GameData::Ability.try_get(ability_id)
  442.   end
  443.  
  444.   # @return [Symbol, nil] the ability symbol of this Pokémon's ability
  445.   def ability_id
  446.     if !@ability
  447.       sp_data = species_data
  448.       abil_index = ability_index
  449.       if abil_index >= 2   # Hidden ability
  450.         @ability = sp_data.hidden_abilities[abil_index - 2]
  451.         abil_index = (@personalID & 1) if !@ability
  452.       end
  453.       if !@ability   # Natural ability or no hidden ability defined
  454.         @ability = sp_data.abilities[abil_index] || sp_data.abilities[0]
  455.       end
  456.     end
  457.     return @ability
  458.   end
  459.  
  460.   # @param value [Symbol, String, GameData::Ability, nil] ability to set
  461.   def ability=(value)
  462.     return if value && !GameData::Ability.exists?(value)
  463.     @ability = (value) ? GameData::Ability.get(value).id : value
  464.   end
  465.  
  466.   # Returns whether this Pokémon has a particular ability. If no value
  467.   # is given, returns whether this Pokémon has an ability set.
  468.   # @param check_ability [Symbol, String, GameData::Ability, nil] ability ID to check
  469.   # @return [Boolean] whether this Pokémon has a particular ability or
  470.   #   an ability at all
  471.   def hasAbility?(check_ability = nil)
  472.     current_ability = self.ability
  473.     return !current_ability.nil? if check_ability.nil?
  474.     return current_ability == check_ability
  475.   end
  476.  
  477.   # @return [Boolean] whether this Pokémon has a hidden ability
  478.   def hasHiddenAbility?
  479.     return ability_index >= 2
  480.   end
  481.  
  482.   # @return [Array<Array<Symbol,Integer>>] the abilities this Pokémon can have,
  483.   #   where every element is [ability ID, ability index]
  484.   def getAbilityList
  485.     ret = []
  486.     sp_data = species_data
  487.     sp_data.abilities.each_with_index { |a, i| ret.push([a, i]) if a }
  488.     sp_data.hidden_abilities.each_with_index { |a, i| ret.push([a, i + 2]) if a }
  489.     return ret
  490.   end
  491.  
  492.   #=============================================================================
  493.   # Nature
  494.   #=============================================================================
  495.  
  496.   # @return [GameData::Nature, nil] a Nature object corresponding to this Pokémon's nature
  497.   def nature
  498.     if !@nature
  499.       idx = @personalID % GameData::Nature.count
  500.       @nature = GameData::Nature.get(GameData::Nature.keys[idx]).id
  501.     end
  502.     return GameData::Nature.try_get(@nature)
  503.   end
  504.  
  505.   def nature_id
  506.     return @nature
  507.   end
  508.  
  509.   # Sets this Pokémon's nature to a particular nature.
  510.   # @param value [Symbol, String, GameData::Nature, nil] nature to change to
  511.   def nature=(value)
  512.     return if value && !GameData::Nature.exists?(value)
  513.     @nature = (value) ? GameData::Nature.get(value).id : value
  514.     calc_stats if !@nature_for_stats
  515.   end
  516.  
  517.   # Returns the calculated nature, taking into account things that change its
  518.   # stat-altering effect (i.e. Gen 8 mints). Only used for calculating stats.
  519.   # @return [GameData::Nature, nil] this Pokémon's calculated nature
  520.   def nature_for_stats
  521.     return GameData::Nature.try_get(@nature_for_stats) if @nature_for_stats
  522.     return self.nature
  523.   end
  524.  
  525.   def nature_for_stats_id
  526.     return @nature_for_stats
  527.   end
  528.  
  529.   # If defined, this Pokémon's nature is considered to be this when calculating stats.
  530.   # @param value [Symbol, String, GameData::Nature, nil] ID of the nature to use for calculating stats
  531.   def nature_for_stats=(value)
  532.     return if value && !GameData::Nature.exists?(value)
  533.     @nature_for_stats = (value) ? GameData::Nature.get(value).id : value
  534.     calc_stats
  535.   end
  536.  
  537.   # Returns whether this Pokémon has a particular nature. If no value is given,
  538.   # returns whether this Pokémon has a nature set.
  539.   # @param check_nature [Symbol, String, GameData::Nature, nil] nature ID to check
  540.   # @return [Boolean] whether this Pokémon has a particular nature or a nature
  541.   #   at all
  542.   def hasNature?(check_nature = nil)
  543.     return !@nature.nil? if check_nature.nil?
  544.     return self.nature == check_nature
  545.   end
  546.  
  547.   #=============================================================================
  548.   # Items
  549.   #=============================================================================
  550.  
  551.   # @return [GameData::Item, nil] an Item object corresponding to this Pokémon's item
  552.   def item
  553.     return GameData::Item.try_get(@item)
  554.   end
  555.  
  556.   def item_id
  557.     return @item
  558.   end
  559.  
  560.   # Gives an item to this Pokémon to hold.
  561.   # @param value [Symbol, String, GameData::Item, nil] ID of the item to give
  562.   #   to this Pokémon
  563.   def item=(value)
  564.     return if value && !GameData::Item.exists?(value)
  565.     @item = (value) ? GameData::Item.get(value).id : value
  566.   end
  567.  
  568.   # Returns whether this Pokémon is holding an item. If an item id is passed,
  569.   # returns whether the Pokémon is holding that item.
  570.   # @param check_item [Symbol, String, GameData::Item, nil] item ID to check
  571.   # @return [Boolean] whether the Pokémon is holding the specified item or
  572.   #   an item at all
  573.   def hasItem?(check_item = nil)
  574.     return !@item.nil? if check_item.nil?
  575.     held_item = self.item
  576.     return held_item && held_item == check_item
  577.   end
  578.  
  579.   # @return [Array<Array<Symbol>>] the items this species can be found holding in the wild
  580.   def wildHoldItems
  581.     sp_data = species_data
  582.     return [sp_data.wild_item_common, sp_data.wild_item_uncommon, sp_data.wild_item_rare]
  583.   end
  584.  
  585.   # @return [Mail, nil] mail held by this Pokémon (nil if there is none)
  586.   def mail
  587.     @mail = nil if @mail && (!@mail.item || !hasItem?(@mail.item))
  588.     return @mail
  589.   end
  590.  
  591.   # If mail is a Mail object, gives that mail to this Pokémon. If nil is given,
  592.   # removes the held mail.
  593.   # @param mail [Mail, nil] mail to be held by this Pokémon
  594.   def mail=(mail)
  595.     if !mail.nil? && !mail.is_a?(Mail)
  596.       raise ArgumentError, _INTL("Invalid value {1} given", mail.inspect)
  597.     end
  598.     @mail = mail
  599.   end
  600.  
  601.   #=============================================================================
  602.   # Moves
  603.   #=============================================================================
  604.  
  605.   # @return [Integer] the number of moves known by the Pokémon
  606.   def numMoves
  607.     return @moves.length
  608.   end
  609.  
  610.   # @param move_id [Symbol, String, GameData::Move] ID of the move to check
  611.   # @return [Boolean] whether the Pokémon knows the given move
  612.   def hasMove?(move_id)
  613.     move_data = GameData::Move.try_get(move_id)
  614.     return false if !move_data
  615.     return @moves.any? { |m| m.id == move_data.id }
  616.   end
  617.  
  618.   # Returns the list of moves this Pokémon can learn by levelling up.
  619.   # @return [Array<Array<Integer,Symbol>>] this Pokémon's move list, where every element is [level, move ID]
  620.   def getMoveList
  621.     return species_data.moves
  622.   end
  623.  
  624.   # Sets this Pokémon's movelist to the default movelist it originally had.
  625.   def reset_moves
  626.     this_level = self.level
  627.     # Find all level-up moves that self could have learned
  628.     moveset = self.getMoveList
  629.     knowable_moves = []
  630.     moveset.each { |m| knowable_moves.push(m[1]) if m[0] <= this_level }
  631.     # Remove duplicates (retaining the latest copy of each move)
  632.     knowable_moves = knowable_moves.reverse
  633.     knowable_moves |= []
  634.     knowable_moves = knowable_moves.reverse
  635.     # Add all moves
  636.     @moves.clear
  637.     first_move_index = knowable_moves.length - MAX_MOVES
  638.     first_move_index = 0 if first_move_index < 0
  639.     (first_move_index...knowable_moves.length).each do |i|
  640.       @moves.push(Pokemon::Move.new(knowable_moves[i]))
  641.     end
  642.   end
  643.  
  644.   # Silently learns the given move. Will erase the first known move if it has to.
  645.   # @param move_id [Symbol, String, GameData::Move] ID of the move to learn
  646.   def learn_move(move_id)
  647.     move_data = GameData::Move.try_get(move_id)
  648.     return if !move_data
  649.     # Check if self already knows the move; if so, move it to the end of the array
  650.     @moves.each_with_index do |m, i|
  651.       next if m.id != move_data.id
  652.       @moves.push(m)
  653.       @moves.delete_at(i)
  654.       return
  655.     end
  656.     # Move is not already known; learn it
  657.     @moves.push(Pokemon::Move.new(move_data.id))
  658.     # Delete the first known move if self now knows more moves than it should
  659.     @moves.shift if numMoves > MAX_MOVES
  660.   end
  661.  
  662.   # Deletes the given move from the Pokémon.
  663.   # @param move_id [Symbol, String, GameData::Move] ID of the move to delete
  664.   def forget_move(move_id)
  665.     move_data = GameData::Move.try_get(move_id)
  666.     return if !move_data
  667.     @moves.delete_if { |m| m.id == move_data.id }
  668.   end
  669.  
  670.   # Deletes the move at the given index from the Pokémon.
  671.   # @param index [Integer] index of the move to be deleted
  672.   def forget_move_at_index(index)
  673.     @moves.delete_at(index)
  674.   end
  675.  
  676.   # Deletes all moves from the Pokémon.
  677.   def forget_all_moves
  678.     @moves.clear
  679.   end
  680.  
  681.   # Copies currently known moves into a separate array, for Move Relearner.
  682.   def record_first_moves
  683.     clear_first_moves
  684.     @moves.each { |m| @first_moves.push(m.id) }
  685.   end
  686.  
  687.   # Adds a move to this Pokémon's first moves.
  688.   # @param move_id [Symbol, String, GameData::Move] ID of the move to add
  689.   def add_first_move(move_id)
  690.     move_data = GameData::Move.try_get(move_id)
  691.     @first_moves.push(move_data.id) if move_data && !@first_moves.include?(move_data.id)
  692.   end
  693.  
  694.   # Removes a move from this Pokémon's first moves.
  695.   # @param move_id [Symbol, String, GameData::Move] ID of the move to remove
  696.   def remove_first_move(move_id)
  697.     move_data = GameData::Move.try_get(move_id)
  698.     @first_moves.delete(move_data.id) if move_data
  699.   end
  700.  
  701.   # Clears this Pokémon's first moves.
  702.   def clear_first_moves
  703.     @first_moves.clear
  704.   end
  705.  
  706.   # @param move_id [Symbol, String, GameData::Move] ID of the move to check
  707.   # @return [Boolean] whether the Pokémon is compatible with the given move
  708.   def compatible_with_move?(move_id)
  709.     move_data = GameData::Move.try_get(move_id)
  710.     return false if !move_data
  711.     return true if species_data.tutor_moves.include?(move_data.id)
  712.     return true if getMoveList.any? { |m| m[1] == move_data.id }
  713.     return true if species_data.get_egg_moves.include?(move_data.id)
  714.     return false
  715.   end
  716.  
  717.   def can_relearn_move?
  718.     return false if egg? || shadowPokemon?
  719.     this_level = self.level
  720.     getMoveList.each { |m| return true if m[0] <= this_level && !hasMove?(m[1]) }
  721.     @first_moves.each { |m| return true if !hasMove?(m) }
  722.     return false
  723.   end
  724.  
  725.   #=============================================================================
  726.   # Ribbons
  727.   #=============================================================================
  728.  
  729.   # @return [Integer] the number of ribbons this Pokémon has
  730.   def numRibbons
  731.     return @ribbons.length
  732.   end
  733.  
  734.   # @param ribbon [Symbol, String, GameData::Ribbon] ribbon ID to check for
  735.   # @return [Boolean] whether this Pokémon has the specified ribbon
  736.   def hasRibbon?(ribbon)
  737.     ribbon_data = GameData::Ribbon.try_get(ribbon)
  738.     return ribbon_data && @ribbons.include?(ribbon_data.id)
  739.   end
  740.  
  741.   # Gives a ribbon to this Pokémon.
  742.   # @param ribbon [Symbol, String, GameData::Ribbon] ID of the ribbon to give
  743.   def giveRibbon(ribbon)
  744.     ribbon_data = GameData::Ribbon.try_get(ribbon)
  745.     return if !ribbon_data || @ribbons.include?(ribbon_data.id)
  746.     @ribbons.push(ribbon_data.id)
  747.   end
  748.  
  749.   # Replaces one ribbon with the next one along, if possible. If none of the
  750.   # given ribbons are owned, give the first one.
  751.   # @return [Symbol, String, GameData::Ribbon] ID of the ribbon that was gained
  752.   def upgradeRibbon(*args)
  753.     args.each_with_index do |ribbon, i|
  754.       this_ribbon_data = GameData::Ribbon.try_get(ribbon)
  755.       next if !this_ribbon_data
  756.       @ribbons.length.times do |j|
  757.         next if @ribbons[j] != this_ribbon_data.id
  758.         next_ribbon_data = GameData::Ribbon.try_get(args[i + 1])
  759.         next if !next_ribbon_data
  760.         @ribbons[j] = next_ribbon_data.id
  761.         return @ribbons[j]
  762.       end
  763.     end
  764.     first_ribbon_data = GameData::Ribbon.try_get(args.first)
  765.     last_ribbon_data = GameData::Ribbon.try_get(args.last)
  766.     if first_ribbon_data && last_ribbon_data && !hasRibbon?(last_ribbon_data.id)
  767.       giveRibbon(first_ribbon_data.id)
  768.       return first_ribbon_data.id
  769.     end
  770.     return nil
  771.   end
  772.  
  773.   # Removes the specified ribbon from this Pokémon.
  774.   # @param ribbon [Symbol, String, GameData::Ribbon] ID of the ribbon to remove
  775.   def takeRibbon(ribbon)
  776.     ribbon_data = GameData::Ribbon.try_get(ribbon)
  777.     return if !ribbon_data
  778.     @ribbons.delete_at(@ribbons.index(ribbon_data.id))
  779.   end
  780.  
  781.   # Removes all ribbons from this Pokémon.
  782.   def clearAllRibbons
  783.     @ribbons.clear
  784.   end
  785.  
  786.   #=============================================================================
  787.   # Pokérus
  788.   #=============================================================================
  789.  
  790.   # @return [Integer] the Pokérus infection stage for this Pokémon
  791.   def pokerusStrain
  792.     return @pokerus / 16
  793.   end
  794.  
  795.   # Returns the Pokérus infection stage for this Pokémon. The possible stages are
  796.   # 0 (not infected), 1 (infected) and 2 (cured).
  797.   # @return [0, 1, 2] current Pokérus infection stage
  798.   def pokerusStage
  799.     return 0 if @pokerus == 0
  800.     return ((@pokerus % 16) == 0) ? 2 : 1
  801.   end
  802.  
  803.   # Gives this Pokémon Pokérus (either the specified strain or a random one).
  804.   # @param strain [Integer] Pokérus strain to give (1-15 inclusive, or 0 for random)
  805.   def givePokerus(strain = 0)
  806.     return if self.pokerusStage == 2   # Can't re-infect a cured Pokémon
  807.     $stats.pokerus_infections += 1
  808.     strain = rand(1...16) if strain <= 0 || strain >= 16
  809.     time = 1 + (strain % 4)
  810.     @pokerus = time
  811.     @pokerus |= strain << 4
  812.   end
  813.  
  814.   # Resets the infection time for this Pokémon's Pokérus (even if cured).
  815.   def resetPokerusTime
  816.     return if @pokerus == 0
  817.     strain = @pokerus / 16
  818.     time = 1 + (strain % 4)
  819.     @pokerus = time
  820.     @pokerus |= strain << 4
  821.   end
  822.  
  823.   # Reduces the time remaining for this Pokémon's Pokérus (if infected).
  824.   def lowerPokerusCount
  825.     return if self.pokerusStage != 1
  826.     @pokerus -= 1
  827.   end
  828.  
  829.   # Cures this Pokémon's Pokérus (if infected).
  830.   def curePokerus
  831.     @pokerus -= @pokerus % 16
  832.   end
  833.  
  834.   #=============================================================================
  835.   # Ownership, obtained information
  836.   #=============================================================================
  837.  
  838.   # Changes this Pokémon's owner.
  839.   # @param new_owner [Owner] the owner to change to
  840.   def owner=(new_owner)
  841.     validate new_owner => Owner
  842.     @owner = new_owner
  843.   end
  844.  
  845.   # @param trainer [Player, NPCTrainer, nil] the trainer to compare to the original trainer
  846.   # @return [Boolean] whether the given trainer is not this Pokémon's original trainer
  847.   def foreign?(trainer = $player)
  848.     return @owner.id != trainer.id || @owner.name != trainer.name
  849.   end
  850.  
  851.   # @return [Time] the time when this Pokémon was obtained
  852.   def timeReceived
  853.     return Time.at(@timeReceived)
  854.   end
  855.  
  856.   # Sets the time when this Pokémon was obtained.
  857.   # @param value [Integer, Time, #to_i] time in seconds since Unix epoch
  858.   def timeReceived=(value)
  859.     @timeReceived = value.to_i
  860.   end
  861.  
  862.   # @return [Time] the time when this Pokémon hatched
  863.   def timeEggHatched
  864.     return (obtain_method == 1) ? Time.at(@timeEggHatched) : nil
  865.   end
  866.  
  867.   # Sets the time when this Pokémon hatched.
  868.   # @param value [Integer, Time, #to_i] time in seconds since Unix epoch
  869.   def timeEggHatched=(value)
  870.     @timeEggHatched = value.to_i
  871.   end
  872.  
  873.   #=============================================================================
  874.   # Other
  875.   #=============================================================================
  876.  
  877.   # @return [String] the name of this Pokémon
  878.   def name
  879.     return (nicknamed?) ? @name : speciesName
  880.   end
  881.  
  882.   # @param value [String] the nickname of this Pokémon
  883.   def name=(value)
  884.     value = nil if !value || value.empty? || value == speciesName
  885.     @name = value
  886.   end
  887.  
  888.   # @return [Boolean] whether this Pokémon has been nicknamed
  889.   def nicknamed?
  890.     return @name && !@name.empty?
  891.   end
  892.  
  893.   # @return [String] the species name of this Pokémon
  894.   def speciesName
  895.     return species_data.name
  896.   end
  897.  
  898.   # @return [Integer] the height of this Pokémon in decimetres (0.1 metres)
  899.   def height
  900.     return species_data.height
  901.   end
  902.  
  903.   # @return [Integer] the weight of this Pokémon in hectograms (0.1 kilograms)
  904.   def weight
  905.     return species_data.weight
  906.   end
  907.  
  908.   # @return [Hash<Integer>] the EV yield of this Pokémon (a hash with six key/value pairs)
  909.   def evYield
  910.     this_evs = species_data.evs
  911.     ret = {}
  912.     GameData::Stat.each_main { |s| ret[s.id] = this_evs[s.id] }
  913.     return ret
  914.   end
  915.  
  916.   def affection_level
  917.     case @happiness
  918.     when 0...100   then return 0
  919.     when 100...150 then return 1
  920.     when 150...200 then return 2
  921.     when 200...230 then return 3
  922.     when 230...255 then return 4
  923.     end
  924.     return 5   # 255
  925.   end
  926.  
  927.   # Changes the happiness of this Pokémon depending on what happened to change it.
  928.   # @param method [String] the happiness changing method (e.g. 'walking')
  929.   def changeHappiness(method)
  930.     gain = 0
  931.     happiness_range = @happiness / 100
  932.     case method
  933.     when "walking"
  934.       gain = [2, 2, 1][happiness_range]
  935.     when "levelup"
  936.       gain = [5, 4, 3][happiness_range]
  937.     when "groom"
  938.       gain = [10, 10, 4][happiness_range]
  939.     when "evberry"
  940.       gain = [10, 5, 2][happiness_range]
  941.     when "vitamin"
  942.       gain = [5, 3, 2][happiness_range]
  943.     when "wing"
  944.       gain = [3, 2, 1][happiness_range]
  945.     when "machine", "battleitem"
  946.       gain = [1, 1, 0][happiness_range]
  947.     when "faint"
  948.       gain = -1
  949.     when "faintbad"   # Fainted against an opponent that is 30+ levels higher
  950.       gain = [-5, -5, -10][happiness_range]
  951.     when "powder"
  952.       gain = [-5, -5, -10][happiness_range]
  953.     when "energyroot"
  954.       gain = [-10, -10, -15][happiness_range]
  955.     when "revivalherb"
  956.       gain = [-15, -15, -20][happiness_range]
  957.     else
  958.       raise _INTL("Unknown happiness-changing method: {1}", method.to_s)
  959.     end
  960.     if gain > 0
  961.       gain += 1 if @obtain_map == $game_map.map_id
  962.       gain += 1 if @poke_ball == :LUXURYBALL
  963.       gain -= 1 if @poke_ball == :LETARGOBALL
  964.       gain = (gain * 1.5).floor if hasItem?(:SOOTHEBELL)
  965.       if Settings::APPLY_HAPPINESS_SOFT_CAP && method != "evberry"
  966.         gain = (@happiness >= 179) ? 0 : gain.clamp(0, 179 - @happiness)
  967.       end
  968.     end
  969.     @happiness = (@happiness + gain).clamp(0, 255)
  970.   end
  971.  
  972.   #=============================================================================
  973.   # Evolution checks
  974.   #=============================================================================
  975.   # Checks whether this Pokemon can evolve because of levelling up.
  976.   # @return [Symbol, nil] the ID of the species to evolve into
  977.   def check_evolution_on_level_up
  978.     return check_evolution_internal do |pkmn, new_species, method, parameter|
  979.       success = GameData::Evolution.get(method).call_level_up(pkmn, parameter)
  980.       next (success) ? new_species : nil
  981.     end
  982.   end
  983.  
  984.   # Checks whether this Pokemon can evolve because of using an item on it.
  985.   # @param item_used [Symbol, GameData::Item, nil] the item being used
  986.   # @return [Symbol, nil] the ID of the species to evolve into
  987.   def check_evolution_on_use_item(item_used)
  988.     return check_evolution_internal do |pkmn, new_species, method, parameter|
  989.       success = GameData::Evolution.get(method).call_use_item(pkmn, parameter, item_used)
  990.       next (success) ? new_species : nil
  991.     end
  992.   end
  993.  
  994.   # Checks whether this Pokemon can evolve because of being traded.
  995.   # @param other_pkmn [Pokemon] the other Pokémon involved in the trade
  996.   # @return [Symbol, nil] the ID of the species to evolve into
  997.   def check_evolution_on_trade(other_pkmn)
  998.     return check_evolution_internal do |pkmn, new_species, method, parameter|
  999.       success = GameData::Evolution.get(method).call_on_trade(pkmn, parameter, other_pkmn)
  1000.       next (success) ? new_species : nil
  1001.     end
  1002.   end
  1003.  
  1004.   # Checks whether this Pokemon can evolve after a battle.
  1005.   # @return [Symbol, nil] the ID of the species to evolve into
  1006.   def check_evolution_after_battle(party_index)
  1007.     return check_evolution_internal do |pkmn, new_species, method, parameter|
  1008.       success = GameData::Evolution.get(method).call_after_battle(pkmn, party_index, parameter)
  1009.       next (success) ? new_species : nil
  1010.     end
  1011.   end
  1012.  
  1013.   # Checks whether this Pokemon can evolve by a triggered event.
  1014.   # @param value [Integer] a value that may be used by the evolution method
  1015.   # @return [Symbol, nil] the ID of the species to evolve into
  1016.   def check_evolution_by_event(value = 0)
  1017.     return check_evolution_internal do |pkmn, new_species, method, parameter|
  1018.       success = GameData::Evolution.get(method).call_event(pkmn, parameter, value)
  1019.       next (success) ? new_species : nil
  1020.     end
  1021.   end
  1022.  
  1023.   # Called after this Pokémon evolves, to remove its held item (if the evolution
  1024.   # required it to have a held item) or duplicate this Pokémon (Shedinja only).
  1025.   # @param new_species [Symbol] the species that this Pokémon evolved into
  1026.   def action_after_evolution(new_species)
  1027.     species_data.get_evolutions(true).each do |evo|   # [new_species, method, parameter]
  1028.       break if GameData::Evolution.get(evo[1]).call_after_evolution(self, evo[0], evo[2], new_species)
  1029.     end
  1030.   end
  1031.  
  1032.   # The core method that performs evolution checks. Needs a block given to it,
  1033.   # which will provide either a GameData::Species ID (the species to evolve
  1034.   # into) or nil (keep checking).
  1035.   # @return [Symbol, nil] the ID of the species to evolve into
  1036.   def check_evolution_internal
  1037.     return nil if egg? || shadowPokemon?
  1038.     return nil if hasItem?(:EVERSTONE)
  1039.     return nil if hasAbility?(:BATTLEBOND)
  1040.     species_data.get_evolutions(true).each do |evo|   # [new_species, method, parameter, boolean]
  1041.       next if evo[3]   # Prevolution
  1042.       ret = yield self, evo[0], evo[1], evo[2]   # pkmn, new_species, method, parameter
  1043.       return ret if ret
  1044.     end
  1045.     return nil
  1046.   end
  1047.  
  1048.   def trigger_event_evolution(number)
  1049.     new_species = check_evolution_by_event(number)
  1050.     if new_species
  1051.       pbFadeOutInWithMusic do
  1052.         evo = PokemonEvolutionScene.new
  1053.         evo.pbStartScreen(self, new_species)
  1054.         evo.pbEvolution
  1055.         evo.pbEndScreen
  1056.       end
  1057.       return true
  1058.     end
  1059.     return false
  1060.   end
  1061.  
  1062.   #=============================================================================
  1063.   # Stat calculations
  1064.   #=============================================================================
  1065.  
  1066.   # @return [Hash<Integer>] this Pokémon's base stats, a hash with six key/value pairs
  1067.   def baseStats
  1068.     this_base_stats = species_data.base_stats
  1069.     ret = {}
  1070.     GameData::Stat.each_main { |s| ret[s.id] = this_base_stats[s.id] }
  1071.     return ret
  1072.   end
  1073.  
  1074.   # Returns this Pokémon's effective IVs, taking into account Hyper Training.
  1075.   # Only used for calculating stats.
  1076.   # @return [Hash<Integer>] hash containing this Pokémon's effective IVs
  1077.   def calcIV
  1078.     this_ivs = self.iv
  1079.     ret = {}
  1080.     GameData::Stat.each_main do |s|
  1081.       ret[s.id] = (@ivMaxed[s.id]) ? IV_STAT_LIMIT : this_ivs[s.id]
  1082.     end
  1083.     return ret
  1084.   end
  1085.  
  1086.   # @return [Integer] the maximum HP of this Pokémon
  1087.   def calcHP(base, level, iv, ev)
  1088.     return 1 if base == 1   # For Shedinja
  1089.     iv = ev = 0 if Settings::DISABLE_IVS_AND_EVS
  1090.     return (((base * 2) + iv + (ev / 4)) * level / 100).floor + level + 10
  1091.   end
  1092.  
  1093.   # @return [Integer] the specified stat of this Pokémon (not used for total HP)
  1094.   def calcStat(base, level, iv, ev, nat)
  1095.     iv = ev = 0 if Settings::DISABLE_IVS_AND_EVS
  1096.     return (((((base * 2) + iv + (ev / 4)) * level / 100).floor + 5) * nat / 100).floor
  1097.   end
  1098.  
  1099.   # Recalculates this Pokémon's stats.
  1100.   def calc_stats
  1101.     base_stats = self.baseStats
  1102.     this_level = self.level
  1103.     this_IV    = self.calcIV
  1104.     # Format stat multipliers due to nature
  1105.     nature_mod = {}
  1106.     GameData::Stat.each_main { |s| nature_mod[s.id] = 100 }
  1107.     this_nature = self.nature_for_stats
  1108.     if this_nature
  1109.       this_nature.stat_changes.each { |change| nature_mod[change[0]] += change[1] }
  1110.     end
  1111.     # Calculate stats
  1112.     stats = {}
  1113.     GameData::Stat.each_main do |s|
  1114.       if s.id == :HP
  1115.         stats[s.id] = calcHP(base_stats[s.id], this_level, this_IV[s.id], @ev[s.id])
  1116.       else
  1117.         stats[s.id] = calcStat(base_stats[s.id], this_level, this_IV[s.id], @ev[s.id], nature_mod[s.id])
  1118.       end
  1119.     end
  1120.     hp_difference = stats[:HP] - @totalhp
  1121.     @totalhp = stats[:HP]
  1122.     self.hp = [@hp + hp_difference, 1].max if @hp > 0 || hp_difference > 0
  1123.     @attack  = stats[:ATTACK]
  1124.     @defense = stats[:DEFENSE]
  1125.     @spatk   = stats[:SPECIAL_ATTACK]
  1126.     @spdef   = stats[:SPECIAL_DEFENSE]
  1127.     @speed   = stats[:SPEED]
  1128.   end
  1129.  
  1130.   #=============================================================================
  1131.   # Pokémon creation
  1132.   #=============================================================================
  1133.  
  1134.   # Creates a copy of this Pokémon and returns it.
  1135.   # @return [Pokemon] a copy of this Pokémon
  1136.   def clone
  1137.     ret = super
  1138.     ret.iv          = {}
  1139.     ret.ivMaxed     = {}
  1140.     ret.ev          = {}
  1141.     GameData::Stat.each_main do |s|
  1142.       ret.iv[s.id]      = @iv[s.id]
  1143.       ret.ivMaxed[s.id] = @ivMaxed[s.id]
  1144.       ret.ev[s.id]      = @ev[s.id]
  1145.     end
  1146.     ret.moves       = []
  1147.     @moves.each_with_index { |m, i| ret.moves[i] = m.clone }
  1148.     ret.first_moves = @first_moves.clone
  1149.     ret.owner       = @owner.clone
  1150.     ret.ribbons     = @ribbons.clone
  1151.     return ret
  1152.   end
  1153.  
  1154.   # Creates a new Pokémon object.
  1155.   # @param species [Symbol, String, GameData::Species] Pokémon species
  1156.   # @param level [Integer] Pokémon level
  1157.   # @param owner [Owner, Player, NPCTrainer] Pokémon owner (the player by default)
  1158.   # @param withMoves [Boolean] whether the Pokémon should have moves
  1159.   # @param recheck_form [Boolean] whether to auto-check the form
  1160.   def initialize(species, level, owner = $player, withMoves = true, recheck_form = true)
  1161.     species_data = GameData::Species.get(species)
  1162.     @species          = species_data.species
  1163.     @form             = species_data.base_form
  1164.     @forced_form      = nil
  1165.     @time_form_set    = nil
  1166.     self.level        = level
  1167.     @steps_to_hatch   = 0
  1168.     heal_status
  1169.     @gender           = nil
  1170.     @shiny            = nil
  1171.     @ability_index    = nil
  1172.     @ability          = nil
  1173.     @nature           = nil
  1174.     @nature_for_stats = nil
  1175.     @item             = nil
  1176.     @mail             = nil
  1177.     @moves            = []
  1178.     reset_moves if withMoves
  1179.     @first_moves      = []
  1180.     @ribbons          = []
  1181.     @cool             = 0
  1182.     @beauty           = 0
  1183.     @cute             = 0
  1184.     @smart            = 0
  1185.     @tough            = 0
  1186.     @sheen            = 0
  1187.     @pokerus          = 0
  1188.     @name             = nil
  1189.     @happiness        = species_data.happiness
  1190.     @poke_ball        = :POKEBALL
  1191.     @markings         = []
  1192.     @iv               = {}
  1193.     @ivMaxed          = {}
  1194.     @ev               = {}
  1195.     GameData::Stat.each_main do |s|
  1196.       @iv[s.id]       = rand(IV_STAT_LIMIT + 1)
  1197.       @ev[s.id]       = 0
  1198.     end
  1199.     case owner
  1200.     when Owner
  1201.       @owner = owner
  1202.     when Player, NPCTrainer
  1203.       @owner = Owner.new_from_trainer(owner)
  1204.     else
  1205.       @owner = Owner.new(0, "", 2, 2)
  1206.     end
  1207.     @obtain_method    = 0   # Met
  1208.     @obtain_method    = 4 if $game_switches && $game_switches[Settings::FATEFUL_ENCOUNTER_SWITCH]
  1209.     @obtain_map       = ($game_map) ? $game_map.map_id : 0
  1210.     @obtain_text      = nil
  1211.     @obtain_level     = level
  1212.     @hatched_map      = 0
  1213.     @timeReceived     = Time.now.to_i
  1214.     @timeEggHatched   = nil
  1215.     @fused            = nil
  1216.     @personalID       = rand(2**16) | (rand(2**16) << 16)
  1217.     @hp               = 1
  1218.     @totalhp          = 1
  1219.     calc_stats
  1220.     if @form == 0 && recheck_form
  1221.       f = MultipleForms.call("getFormOnCreation", self)
  1222.       if f
  1223.         self.form = f
  1224.         reset_moves if withMoves
  1225.       end
  1226.     end
  1227.   end
  1228. end
  1229.  
Advertisement
Add Comment
Please, Sign In to add comment