This commit is contained in:
Maruno17
2020-09-20 17:00:41 +01:00
committed by GitHub
parent 3728afa634
commit 1fe0d36454

View File

@@ -1,5 +1,7 @@
# 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
# @return [String] the nickname of this Pokémon
attr_accessor :name
@@ -15,18 +17,18 @@ class PokeBattle_Pokemon
attr_reader :attack
# @return [Integer] the current Defense stat
attr_reader :defense
# @return [Integer] the current Speed stat
attr_reader :speed
# @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 hidden (2) ability available to its species.
# 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, nil] forced ability index (nil if none is set)
# @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)
@@ -46,6 +48,11 @@ class PokeBattle_Pokemon
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)
@@ -209,12 +216,12 @@ class PokeBattle_Pokemon
# @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
#=============================================================================
@@ -224,24 +231,24 @@ class PokeBattle_Pokemon
# @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) < PBGenderRates.genderByte(genderRate)) ? 1 : 0
return ((@personalID & 0xFF) < PBGenderRates.genderByte(gender_rate)) ? 1 : 0
end
# @return [Boolean] whether this Pokémon species is restricted to only ever being one
# gender (or genderless)
def singleGendered?
genderRate = pbGetSpeciesData(@species,formSimple,SpeciesGenderRate)
return genderRate == PBGenderRates::AlwaysMale ||
genderRate == PBGenderRates::AlwaysFemale ||
genderRate == PBGenderRates::Genderless
gender_rate = pbGetSpeciesData(@species, formSimple, SpeciesGenderRate)
return gender_rate == PBGenderRates::AlwaysMale ||
gender_rate == PBGenderRates::AlwaysFemale ||
gender_rate == PBGenderRates::Genderless
end
alias isSingleGendered? singleGendered?
@@ -629,22 +636,34 @@ class PokeBattle_Pokemon
#=============================================================================
# @return [Integer] this Pokémon's cool contest attribute
def cool; return @cool || 0; end
def cool
return @cool || 0
end
# @return [Integer] this Pokémon's beauty contest attribute
def beauty; return @beauty || 0; end
def beauty
return @beauty || 0
end
# @return [Integer] this Pokémon's cute contest attribute
def cute; return @cute || 0; end
def cute
return @cute || 0
end
# @return [Integer] this Pokémon's smart contest attribute
def smart; return @smart || 0; end
def smart
return @smart || 0
end
# @return [Integer] this Pokémon's tough contest attribute
def tough; return @tough || 0; end
def tough;
return @tough || 0
end
# @return [Integer] this Pokémon's sheen contest attribute
def sheen; return @sheen || 0; end
def sheen
return @sheen || 0
end
# @return [Integer] the number of ribbons this Pokémon has
def ribbonCount
@@ -727,7 +746,7 @@ class PokeBattle_Pokemon
# Gives an item to this Pokémon. Passing 0 as the argument removes the held item.
# @param item_id [Integer, Symbol, String] id of the item to give to this Pokémon (0 removes held item)
def setItem(item_id)
self.item = item_id.is_a?(Integer) ? item_id : getID(PBItems,item_id)
self.item = getID(PBItems, item_id) || 0
end
# @return [Array<Integer>] the items this species can be found holding in the wild
@@ -760,39 +779,14 @@ class PokeBattle_Pokemon
# Status
#=============================================================================
# Returns the current status of this Pokémon. See {PBStatuses} for all possible
# status effects.
# @return [Integer] current status (from PBStatuses)
def status
return @status
end
# Sets this Pokémon's status. See {PBStatuses} for all possible status effects.
# @param new_status [Integer, Symbol, String] status to set (from PBStatuses)
def status=(new_status)
if new_status.is_a?(Integer)
def status=(value)
new_status = getID(PBStatuses, value)
if !new_status
raise ArgumentError, _INTL('Attempted to set {1} as Pokémon status', value.class.name)
end
@status = new_status
else
if !new_status.is_a?(Symbol) && !new_status.is_a?(String)
raise ArgumentError, _INTL('Attempted to set a {1} as Pokémon status',new_status.class.name)
end
@status = getID(PBStatuses,new_status)
end
end
# Is 0, except if the Pokémon is:
#
# - Asleep: Is the number of rounds the Pokémon will remain asleep.
# This number is set when the Pokémon is made to fall asleep.
#
# - Badly poisoned: If the Pokémon is Poisoned and this is "1", the
# Pokémon is badly poisoned instead (which affects how much poison
# damage it takes in battle). When the Pokémon leaves battle while
# badly poisoned, this value is set to 0 and it becomes regular Poisoned
# (even in later battles).
# @return [Integer] sleep count / toxic flag
def statusCount
return @statusCount
end
# Sets a new status count. See {#statusCount} for more information.
@@ -826,7 +820,7 @@ class PokeBattle_Pokemon
@statusCount = 0
end
# Heals all PP of this Pokémon. If a move index is given, heals the PP
# Restores all PP of this Pokémon. If a move index is given, restores the PP
# of the move in that index.
# @param move_index [Integer] index of the move to heal (-1 if all moves
# should be healed)
@@ -854,9 +848,9 @@ class PokeBattle_Pokemon
# Changes the Pokémon's species and re-calculates its statistics.
# @param species_id [Integer] id of the species to change this Pokémon to
def species=(species_id)
hasNickname = nicknamed?
has_nickname = nicknamed?
@species = species_id
@name = PBSpecies.getName(@species) unless hasNickname
@name = PBSpecies.getName(@species) unless has_nickname
@level = nil # In case growth rate is different for the new species
@forcedForm = nil
calcStats
@@ -880,10 +874,14 @@ class PokeBattle_Pokemon
end
# @return [Integer] this Pokémon's language
def language; return @language || 0; end
def language
return @language || 0
end
# @return [Integer] the markings this Pokémon has
def markings; return @markings || 0; end
def markings
return @markings || 0
end
# @return [String] a string stating the Unown form of this Pokémon
def unownShape
@@ -895,14 +893,14 @@ class PokeBattle_Pokemon
return pbGetSpeciesData(@species, formSimple, SpeciesHeight)
end
# @return [Integer] the weight of this Pokémon in hectograms (0.1 grams)
# @return [Integer] the weight of this Pokémon in hectograms (0.1 kilograms)
def weight
return pbGetSpeciesData(@species, formSimple, SpeciesWeight)
end
# Returns an array of booleans indicating whether a stat is made to have
# maximum IVs (for Hyper Training). Set like @ivMaxed[PBStats::ATTACK] = true
# @return [Array<Boolean>] array indicating whether a stat has maximum IVs
# @return [Array<Boolean>] array indicating whether each stat has maximum IVs
def ivMaxed
return @ivMaxed || []
end
@@ -995,7 +993,7 @@ class PokeBattle_Pokemon
end
#=============================================================================
# Stat calculations, Pokémon creation
# Stat calculations
#=============================================================================
# @return [Array<Integer>] this Pokémon's base stats, an array of six values
@@ -1007,12 +1005,12 @@ class PokeBattle_Pokemon
# @return [Integer] the maximum HP of this Pokémon
def calcHP(base, level, iv, ev)
return 1 if base == 1 # For Shedinja
return ((base * 2 + iv + (ev >> 2)) * level / 100).floor + level + 10
return ((base * 2 + iv + (ev / 4)) * level / 100).floor + level + 10
end
# @return [Integer] the specified stat of this Pokémon (not used for total HP)
def calcStat(base, level, iv, ev, pv)
return ((((base*2+iv+(ev>>2))*level/100).floor+5)*pv/100).floor
return ((((base * 2 + iv + (ev / 4)) * level / 100).floor + 5) * pv / 100).floor
end
# Recalculates this Pokémon's stats.
@@ -1041,6 +1039,10 @@ class PokeBattle_Pokemon
@speed = stats[PBStats::SPEED]
end
#=============================================================================
# Pokémon creation
#=============================================================================
# Creates a copy of this Pokémon and returns it.
# @return [PokeBattle_Pokemon] a copy of this Pokémon
def clone
@@ -1069,10 +1071,7 @@ class PokeBattle_Pokemon
end
@species = realSpecies
@name = PBSpecies.getName(@species)
@personalID = rand(256)
@personalID |= rand(256)<<8
@personalID |= rand(256)<<16
@personalID |= rand(256)<<24
@personalID = rand(2**32)
@hp = 1
@totalhp = 1
@iv = []
@@ -1122,13 +1121,16 @@ class PokeBattle_Pokemon
end
end
#===============================================================================
#
#===============================================================================
# Creates a new Pokémon object.
# @param species [Integer, Symbol, String] Pokémon species
# @param level [Integer] Pokémon level
# @param owner [PokeBattle_Trainer] object for the original trainer
# @param withMoves [Boolean] whether the Pokémon should have moves
def pbNewPkmn(species,level,owner=nil,withMoves=true)
owner = $Trainer if !owner
def pbNewPkmn(species, level, owner = $Trainer, withMoves = true)
return PokeBattle_Pokemon.new(species, level, owner, withMoves)
end
alias pbGenPkmn pbNewPkmn