From 1b3a1f3f3c45949dd2dde5e33ab4a8d63de8226d Mon Sep 17 00:00:00 2001 From: jonisavo Date: Tue, 8 Sep 2020 11:32:36 +0300 Subject: [PATCH 01/11] Further refactoring in PokeBattle_Pokemon --- .../016_Pokemon/001_PokeBattle_Pokemon.rb | 222 +++++++++++------- 1 file changed, 134 insertions(+), 88 deletions(-) diff --git a/Data/Scripts/016_Pokemon/001_PokeBattle_Pokemon.rb b/Data/Scripts/016_Pokemon/001_PokeBattle_Pokemon.rb index 491517874..5404f8d5c 100644 --- a/Data/Scripts/016_Pokemon/001_PokeBattle_Pokemon.rb +++ b/Data/Scripts/016_Pokemon/001_PokeBattle_Pokemon.rb @@ -1,21 +1,36 @@ # 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. 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 + # @return [String] nickname + attr_accessor :name + # @return [Integer] national Pokédex number + attr_reader :species + # @return [Integer] current experience points + attr_reader :exp + # @return [Integer] current HP + attr_reader :hp + # @return [Integer] current Total HP + attr_reader :totalhp + # @return [Integer] current Attack stat + attr_reader :attack + # @return [Integer] current Defense stat + attr_reader :defense + # @return [Integer] current Speed stat + attr_reader :speed + # @return [Integer] current Special Attack stat + attr_reader :spatk + # @return [Integer] current Special Defense stat + attr_reader :spdef + # @return [Integer] status problem (from PBStatus) + attr_accessor :status + # @return [Integer] sleep count / toxic flag + attr_accessor :statusCount + # @return [0, 1, 2] forces the first / second / hidden ability + attr_accessor :abilityflag + # @return [0, 1] forces male (0) or female (1) + attr_accessor :genderflag + # @return [Integer] forces a particular nature (nature ID) + attr_accessor :natureflag attr_accessor :natureOverride # Overrides nature's stat-changing effects attr_accessor :shinyflag # Forces the shininess (true/false) attr_accessor :moves # Moves (PBMove) @@ -59,38 +74,41 @@ class PokeBattle_Pokemon #============================================================================= # Ownership, obtained information #============================================================================= - # Returns the public portion of the original trainer's ID. + + # @return [Integer] 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 trainer and OT 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] 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] 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] time when this Pokémon hatched def timeEggHatched if obtainMode==1 return @timeEggHatched ? Time.at(@timeEggHatched) : Time.gm(2000) @@ -99,7 +117,8 @@ class PokeBattle_Pokemon 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,13 +126,15 @@ 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 return @level end # Sets this Pokémon's level. + # @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)) @@ -123,42 +144,44 @@ class PokeBattle_Pokemon 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) 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) end - # Returns a number between 0 and 1 indicating how much of the current level's - # Exp this Pokémon has. + # @return [Float] 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 + 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) + startexp = PBExperience.pbGetStartExperience(l, gr) + endexp = PBExperience.pbGetStartExperience(l + 1, gr) + return 1.0 * (@exp - startexp) / (endexp - startexp) 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) @@ -168,96 +191,106 @@ class PokeBattle_Pokemon 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)