diff --git a/Data/Scripts/016_Pokemon/001_PokeBattle_Pokemon.rb b/Data/Scripts/016_Pokemon/001_PokeBattle_Pokemon.rb index 491517874..283cebbbd 100644 --- a/Data/Scripts/016_Pokemon/001_PokeBattle_Pokemon.rb +++ b/Data/Scripts/016_Pokemon/001_PokeBattle_Pokemon.rb @@ -1,105 +1,170 @@ -# This class stores data on each Pokémon. Refer to $Trainer.party for an array -# of each Pokémon in the Trainer's current party. +#=============================================================================== +# Instances of this class are individual Pokémon. +# The player's party Pokémon are stored in the array $Trainer.party. +#=============================================================================== class PokeBattle_Pokemon - attr_accessor :name # Nickname - attr_reader :species # Species (National Pokedex number) - attr_reader :exp # Current experience points - attr_reader :hp # Current HP - attr_reader :totalhp # Current Total HP - attr_reader :attack # Current Attack stat - attr_reader :defense # Current Defense stat - attr_reader :speed # Current Speed stat - attr_reader :spatk # Current Special Attack stat - attr_reader :spdef # Current Special Defense stat - attr_accessor :status # Status problem (PBStatuses) - attr_accessor :statusCount # Sleep count/Toxic flag - attr_accessor :abilityflag # Forces the first/second/hidden (0/1/2) ability - attr_accessor :genderflag # Forces male (0) or female (1) - attr_accessor :natureflag # Forces a particular nature - attr_accessor :natureOverride # Overrides nature's stat-changing effects - attr_accessor :shinyflag # Forces the shininess (true/false) - attr_accessor :moves # Moves (PBMove) - attr_accessor :firstmoves # The moves known when this Pokémon was obtained - attr_accessor :item # Held item - attr_writer :mail # Mail - attr_accessor :fused # The Pokémon fused into this one - attr_accessor :iv # Array of 6 Individual Values for HP, Atk, Def, - # Speed, Sp Atk, and Sp Def - attr_writer :ivMaxed # Array of booleans that max each IV value - attr_accessor :ev # Effort Values - attr_accessor :happiness # Current happiness - attr_accessor :ballused # Ball used - attr_accessor :eggsteps # Steps to hatch egg, 0 if Pokémon is not an egg - attr_writer :markings # Markings - attr_accessor :ribbons # Array of ribbons - attr_accessor :pokerus # Pokérus strain and infection time - attr_accessor :personalID # Personal ID - attr_accessor :trainerID # 32-bit Trainer ID (the secret ID is in the upper - # 16 bits) - attr_accessor :obtainMode # Manner obtained: - # 0 - met, 1 - as egg, 2 - traded, - # 4 - fateful encounter - attr_accessor :obtainMap # Map where obtained - attr_accessor :obtainText # Replaces the obtain map's name if not nil - attr_writer :obtainLevel # Level obtained - attr_accessor :hatchedMap # Map where an egg was hatched - attr_writer :language # Language - attr_accessor :ot # Original Trainer's name - attr_writer :otgender # Original Trainer's gender: - # 0 - male, 1 - female, 2 - mixed, 3 - unknown - # For information only, not used to verify - # ownership of the Pokémon - attr_writer :cool,:beauty,:cute,:smart,:tough,:sheen # Contest stats + # @return [String] the nickname of this Pokémon + attr_accessor :name + # @return [Integer] this Pokémon's national Pokédex number + attr_reader :species + # @return [Integer] the current experience points + attr_reader :exp + # @return [Integer] the current HP + attr_reader :hp + # @return [Integer] the current Total HP + attr_reader :totalhp + # @return [Integer] the current Attack stat + attr_reader :attack + # @return [Integer] the current Defense stat + attr_reader :defense + # @return [Integer] the current Special Attack stat + attr_reader :spatk + # @return [Integer] the current Special Defense stat + attr_reader :spdef + # @return [Integer] the current Speed stat + attr_reader :speed + # If defined, forces the Pokémon's ability to be the first natural (0), + # second natural (1) or a hidden (2-5) ability available to its species. + # It is not possible to give the Pokémon any ability other than those + # defined in the PBS file "pokemon.txt" for its species + # (or "pokemonforms.txt" for its species and form). + # @return [0, 1, 2, 3, 4, 5, nil] forced ability index (nil if none is set) + attr_accessor :abilityflag + # If defined, forces this Pokémon to be male (0) or female (1). + # @return [0, 1, nil] gender to force: male (0) or female (1) (nil if undefined) + attr_accessor :genderflag + # If defined, forces this Pokémon to have a particular nature. + # @return [Integer, nil] ID of the nature to force (nil if undefined) + attr_accessor :natureflag + # If defined, overrides this Pokémon's nature's stat-changing effects. + # @return [Integer, nil] overridden nature stat-changing effects (nil if undefined) + attr_accessor :natureOverride + # If defined, forces the Pokémon to be shiny (true) or not (false). + # @return [Boolean, nil] whether shininess should be forced (nil if undefined) + attr_accessor :shinyflag + # @return [Array] the moves known by this Pokémon + attr_accessor :moves + # @return [Array] the IDs of moves known by this Pokémon when it was obtained + attr_accessor :firstmoves + # @return [Integer] the ID of the item held by this Pokémon (0 = no held item) + attr_accessor :item + # @return [Integer] this Pokémon's current status (from PBStatuses) + attr_reader :status + # @return [Integer] sleep count / toxic flag / 0: + # sleep (number of rounds before waking up), toxic (0 = regular poison, 1 = toxic) + attr_reader :statusCount + # Another Pokémon which has been fused with this Pokémon (or nil if there is none). + # Currently only used by Kyurem, to record a fused Reshiram or Zekrom. + # @return [PokeBattle_Pokemon, nil] the Pokémon fused into this one (nil if there is none) + attr_accessor :fused + # @return [Array] an array of IV values for HP, Atk, Def, Speed, Sp. Atk and Sp. Def + attr_accessor :iv + # @param value [Array] an array of booleans that max each IV value + attr_writer :ivMaxed + # @return [Array] this Pokémon's effort values + attr_accessor :ev + # @return [Integer] this Pokémon's current happiness (an integer between 0 and 255) + attr_accessor :happiness + # @return [Integer] the type of ball used (refer to {$BallTypes} for valid types) + attr_accessor :ballused + # @return [Integer] the number of steps until this Pokémon hatches, 0 if this Pokémon is not an egg + attr_accessor :eggsteps + # @param value [Integer] new markings for this Pokémon + attr_writer :markings + # @return [Array] an array of ribbons owned by this Pokémon + attr_accessor :ribbons + # @return [Integer] the Pokérus strain and infection time + attr_accessor :pokerus + # @return [Integer] this Pokémon's personal ID + attr_accessor :personalID + # The 32-bit ID of this Pokémon's trainer. The secret ID is in the + # upper 16 bits. + # @return [Integer] the ID of this Pokémon's trainer + attr_accessor :trainerID + # @return [Integer] the manner this Pokémon was obtained: + # 0 (met), 1 (as egg), 2 (traded), 4 (fateful encounter) + attr_accessor :obtainMode + # @return [Integer] the ID of the map this Pokémon was obtained in + attr_accessor :obtainMap + # Describes the manner this Pokémon was obtained. If left undefined, + # the obtain map's name is used. + # @return [String] the obtain text + attr_accessor :obtainText + # @param value [Integer] new obtain level + attr_writer :obtainLevel + # If this Pokémon hatched from an egg, returns the map ID where the hatching happened. + # Otherwise returns 0. + # @return [Integer] the map ID where egg was hatched (0 by default) + attr_accessor :hatchedMap + # @param value [Integer] new language + attr_writer :language + # @return [String] the name of the original trainer + attr_accessor :ot + # Changes the gender of the original trainer. This is for information only, + # and is not used to verify ownership of the Pokémon. + # @param value [Integer] new value for the original trainer's gender: + # 0 - male, 1 - female, 2 - mixed, 3 - unknown + attr_writer :otgender + # @param value [Integer] new contest stat + attr_writer :cool,:beauty,:cute,:smart,:tough,:sheen - IV_STAT_LIMIT = 31 # Max total IVs - EV_LIMIT = 510 # Max total EVs - EV_STAT_LIMIT = 252 # Max EVs that a single stat can have - MAX_POKEMON_NAME_SIZE = 10 # Maximum length a Pokémon's nickname can be + # Max total IVs + IV_STAT_LIMIT = 31 + # Max total EVs + EV_LIMIT = 510 + # Max EVs that a single stat can have + EV_STAT_LIMIT = 252 + # Maximum length a Pokémon's nickname can be + MAX_POKEMON_NAME_SIZE = 10 #============================================================================= # Ownership, obtained information #============================================================================= - # Returns the public portion of the original trainer's ID. + + # @return [Integer] the public portion of the original trainer's ID def publicID - return @trainerID&0xFFFF + return @trainerID & 0xFFFF end - # Returns whether the specified Trainer is NOT this Pokémon's original trainer. + # @param trainer [PokeBattle_Trainer] the trainer to compare to the OT + # @return [Boolean] whether the given trainer and this Pokémon's original trainer don't match def foreign?(trainer) - return @trainerID!=trainer.id || @ot!=trainer.name + return @trainerID != trainer.id || @ot != trainer.name end alias isForeign? foreign? - # Returns the gender of this Pokémon's original trainer (2=unknown). + # @return [0, 1, 2] the gender of this Pokémon original trainer (0 = male, 1 = female, 2 = unknown) def otgender return @otgender || 2 end - # Returns this Pokémon's level when this Pokémon was obtained. + # @return [Integer] this Pokémon's level when it was obtained def obtainLevel return @obtainLevel || 0 end - # Returns the time when this Pokémon was obtained. + # @return [Time] the time when this Pokémon was obtained def timeReceived return @timeReceived ? Time.at(@timeReceived) : Time.gm(2000) end - # Sets the time when this Pokémon was obtained (in seconds since Unix epoch). + # Sets the time when this Pokémon was obtained. + # @param value [Integer, Time, #to_i] time in seconds since Unix epoch def timeReceived=(value) @timeReceived = value.to_i end - # Returns the time when this Pokémon hatched. + # @return [Time] the time when this Pokémon hatched def timeEggHatched - if obtainMode==1 + if obtainMode == 1 return @timeEggHatched ? Time.at(@timeEggHatched) : Time.gm(2000) else return Time.gm(2000) end end - # Sets the time when this Pokémon hatched (in seconds since Unix epoch). + # Sets the time when this Pokémon hatched. + # @param value [Integer, Time, #to_i] time in seconds since Unix epoch def timeEggHatched=(value) @timeEggHatched = value.to_i end @@ -107,170 +172,186 @@ class PokeBattle_Pokemon #============================================================================= # Level #============================================================================= - # Returns this Pokémon's level. + + # @return [Integer] this Pokémon's level def level - @level = PBExperience.pbGetLevelFromExperience(@exp,self.growthrate) if !@level + @level = PBExperience.pbGetLevelFromExperience(@exp, self.growthrate) if !@level return @level end - # Sets this Pokémon's level. + # Sets this Pokémon's level. The given level must be between 1 and the + # maximum level (defined in {PBExperience}). + # @param value [Integer] new level (between 1 and the maximum level) def level=(value) - if value<1 || value>PBExperience.maxLevel - raise ArgumentError.new(_INTL("The level number ({1}) is invalid.",value)) + if value < 1 || value > PBExperience.maxLevel + raise ArgumentError.new(_INTL("The level number ({1}) is invalid.", value)) end @level = value - self.exp = PBExperience.pbGetStartExperience(value,self.growthrate) + self.exp = PBExperience.pbGetStartExperience(value, self.growthrate) end # Sets this Pokémon's Exp. Points. + # @param value [Integer] new experience points def exp=(value) @exp = value @level = nil end - # Returns whether this Pokémon is an egg. + # @return [Boolean] whether this Pokémon is an egg def egg? - return @eggsteps>0 + return @eggsteps > 0 end alias isEgg? egg? - # Returns this Pokémon's growth rate. + # @return [Integer] this Pokémon's growth rate (from PBGrowthRates) def growthrate - return pbGetSpeciesData(@species,formSimple,SpeciesGrowthRate) + return pbGetSpeciesData(@species, formSimple, SpeciesGrowthRate) end - # Returns this Pokémon's base Experience value. + # @return [Integer] this Pokémon's base Experience value def baseExp - return pbGetSpeciesData(@species,formSimple,SpeciesBaseExp) + return pbGetSpeciesData(@species, formSimple, SpeciesBaseExp) end - # Returns a number between 0 and 1 indicating how much of the current level's - # Exp this Pokémon has. + # @return [Float] a number between 0 and 1 indicating how much of the current level's + # Exp this Pokémon has def expFraction - l = self.level - return 0.0 if l>=PBExperience.maxLevel - gr = self.growthrate - startexp = PBExperience.pbGetStartExperience(l,gr) - endexp = PBExperience.pbGetStartExperience(l+1,gr) - return 1.0*(@exp-startexp)/(endexp-startexp) + lvl = self.level + return 0.0 if lvl >= PBExperience.maxLevel + growth_rate = self.growthrate + start_exp = PBExperience.pbGetStartExperience(lvl, growth_rate) + end_exp = PBExperience.pbGetStartExperience(lvl + 1, growth_rate) + return 1.0 * (@exp - start_exp) / (end_exp - start_exp) end #============================================================================= # Gender #============================================================================= - # Returns this Pokémon's gender. 0=male, 1=female, 2=genderless + + # @return [0, 1, 2] this Pokémon's gender (0 = male, 1 = female, 2 = genderless) def gender # Return sole gender option for all male/all female/genderless species - genderRate = pbGetSpeciesData(@species,formSimple,SpeciesGenderRate) - case genderRate + gender_rate = pbGetSpeciesData(@species, formSimple, SpeciesGenderRate) + case gender_rate when PBGenderRates::AlwaysMale; return 0 when PBGenderRates::AlwaysFemale; return 1 when PBGenderRates::Genderless; return 2 end # Return gender for species that can be male or female - return @genderflag if @genderflag && (@genderflag==0 || @genderflag==1) - return ((@personalID&0xFF)