Created and implemented GameData::Species

This commit is contained in:
Maruno17
2020-12-24 21:25:16 +00:00
parent 1ffeddc41c
commit ad21fc92cb
91 changed files with 6733 additions and 7963 deletions
-6
View File
@@ -12,12 +12,6 @@ def pbGetExceptionMessage(e,_script="")
filename = emessage.sub("No such file or directory - ", "")
emessage = "File #{filename} not found."
end
if emessage && !safeExists?("Game.rgssad") && !safeExists?("Game.rgss2a")
emessage = emessage.gsub(/uninitialized constant PBSpecies\:\:(\S+)$/) {
"The Pokemon species '#{$1}' is not valid. Please\r\nadd the species to the PBS/pokemon.txt file.\r\nSee the wiki for more information." }
emessage = emessage.gsub(/undefined method `(\S+?)' for PBSpecies\:Module/) {
"The Pokemon species '#{$1}' is not valid. Please\r\nadd the species to the PBS/pokemon.txt file.\r\nSee the wiki for more information." }
end
emessage.gsub!(/Section(\d+)/) { $RGSS_SCRIPTS[$1.to_i][1] }
return emessage
end
@@ -199,10 +199,7 @@ end
class SpeciesHandlerHash < HandlerHash
def initialize
super(:PBSpecies)
end
class SpeciesHandlerHash < HandlerHash2
end
@@ -40,6 +40,14 @@ def safeGlob(dir,wildcard)
return (block_given?) ? nil : ret
end
def pbResolveAudioSE(file)
return nil if !file
if RTP.exists?("Audio/SE/"+file,["",".wav",".mp3",".ogg"])
return RTP.getPath("Audio/SE/"+file,["",".wav",".mp3",".ogg"])
end
return nil
end
# Finds the real path for an image file. This includes paths in encrypted
# archives. Returns nil if the path can't be found.
def pbResolveBitmap(x)
@@ -28,9 +28,7 @@ end
class AnimatedBitmap
def initialize(file,hue=0)
if file==nil
raise "Filename is nil (missing graphic)\r\n\r\n"+
"If you see this error in the Continue/New Game screen, you may be loading another game's save file. "+
"Check your project's title (\"Game > Change Title...\" in RMXP).\r\n"
raise "Filename is nil (missing graphic)."
end
if file.split(/[\\\/]/)[-1][/^\[\d+(?:,\d+)?]/] # Starts with 1 or more digits in square brackets
@bitmap = PngAnimatedBitmap.new(file,hue)
+6 -4
View File
@@ -67,8 +67,9 @@ class IntroEventScene < EventScene
onUpdate.clear
onCTrigger.clear
# Play random cry
cry = pbCryFile(1+rand(PBSpecies.maxValue))
pbSEPlay(cry,80,100) if cry
species_keys = GameData::Species::DATA.keys
species_data = GameData::Species.get(species_keys[rand(species_keys.length)])
GameData::Species.play_cry_from_species(species_data.species, species_data.form)
@pic.moveXY(0,20,0,0)
pictureWait
# Fade out
@@ -87,8 +88,9 @@ class IntroEventScene < EventScene
onUpdate.clear
onCTrigger.clear
# Play random cry
cry = pbCryFile(1+rand(PBSpecies.maxValue))
pbSEPlay(cry,80,100) if cry
species_keys = GameData::Species::DATA.keys
species_data = GameData::Species.get(species_keys[rand(species_keys.length)])
GameData::Species.play_cry_from_species(species_data.species, species_data.form)
@pic.moveXY(0,20,0,0)
pictureWait
# Fade out
-115
View File
@@ -2,18 +2,11 @@
# Data caches.
#===============================================================================
class PokemonTemp
attr_accessor :metadata
attr_accessor :townMapData
attr_accessor :encountersData
attr_accessor :phoneData
attr_accessor :regionalDexes
attr_accessor :speciesData
attr_accessor :speciesEggMoves
attr_accessor :speciesMetrics
attr_accessor :speciesMovesets
attr_accessor :speciesTMData
attr_accessor :speciesShadowMovesets
attr_accessor :pokemonFormToSpecies
attr_accessor :trainersData
attr_accessor :moveToAnim
attr_accessor :battleAnims
@@ -21,18 +14,11 @@ end
def pbClearData
if $PokemonTemp
$PokemonTemp.metadata = nil
$PokemonTemp.townMapData = nil
$PokemonTemp.encountersData = nil
$PokemonTemp.phoneData = nil
$PokemonTemp.regionalDexes = nil
$PokemonTemp.speciesData = nil
$PokemonTemp.speciesEggMoves = nil
$PokemonTemp.speciesMetrics = nil
$PokemonTemp.speciesMovesets = nil
$PokemonTemp.speciesTMData = nil
$PokemonTemp.speciesShadowMovesets = nil
$PokemonTemp.pokemonFormToSpecies = nil
$PokemonTemp.trainersData = nil
$PokemonTemp.moveToAnim = nil
$PokemonTemp.battleAnims = nil
@@ -95,96 +81,6 @@ def pbLoadRegionalDexes
return $PokemonTemp.regionalDexes
end
#===============================================================================
# Methods to get Pokémon species data.
#===============================================================================
def pbLoadSpeciesData
$PokemonTemp = PokemonTemp.new if !$PokemonTemp
if !$PokemonTemp.speciesData
$PokemonTemp.speciesData = load_data("Data/species.dat") || []
end
return $PokemonTemp.speciesData
end
def pbGetSpeciesData(species, form = 0, species_data_type = -1)
species = getID(PBSpecies, species)
s = pbGetFSpeciesFromForm(species, form)
species_data = pbLoadSpeciesData
if species_data_type < 0
return species_data[s] || []
end
return species_data[s][species_data_type] if species_data[s] && species_data[s][species_data_type]
case species_data_type
when SpeciesData::TYPE2
return nil
when SpeciesData::BASE_STATS
return [1, 1, 1, 1, 1, 1]
when SpeciesData::EFFORT_POINTS
return [0, 0, 0, 0, 0, 0]
when SpeciesData::STEPS_TO_HATCH, SpeciesData::HEIGHT, SpeciesData::WEIGHT
return 1
end
return 0
end
#===============================================================================
# Methods to get egg moves data.
#===============================================================================
def pbLoadEggMovesData
$PokemonTemp = PokemonTemp.new if !$PokemonTemp
if !$PokemonTemp.speciesEggMoves
$PokemonTemp.speciesEggMoves = load_data("Data/species_eggmoves.dat") || []
end
return $PokemonTemp.speciesEggMoves
end
def pbGetSpeciesEggMoves(species, form = 0)
species = getID(PBSpecies, species)
s = pbGetFSpeciesFromForm(species, form)
egg_moves_data = pbLoadEggMovesData
return egg_moves_data[s] || []
end
#===============================================================================
# Method to get Pokémon species metrics (sprite positioning) data.
#===============================================================================
def pbLoadSpeciesMetrics
$PokemonTemp = PokemonTemp.new if !$PokemonTemp
if !$PokemonTemp.speciesMetrics
$PokemonTemp.speciesMetrics = load_data("Data/species_metrics.dat") || []
end
return $PokemonTemp.speciesMetrics
end
#===============================================================================
# Methods to get Pokémon moveset data.
#===============================================================================
def pbLoadMovesetsData
$PokemonTemp = PokemonTemp.new if !$PokemonTemp
if !$PokemonTemp.speciesMovesets
$PokemonTemp.speciesMovesets = load_data("Data/species_movesets.dat") || []
end
return $PokemonTemp.speciesMovesets
end
def pbGetSpeciesMoveset(species, form = 0)
species = getID(PBSpecies, species)
s = pbGetFSpeciesFromForm(species, form)
movesets_data = pbLoadMovesetsData
return movesets_data[s] || []
end
#===============================================================================
# Method to get TM/Move Tutor compatibility data.
#===============================================================================
def pbLoadSpeciesTMData
$PokemonTemp = PokemonTemp.new if !$PokemonTemp
if !$PokemonTemp.speciesTMData
$PokemonTemp.speciesTMData = load_data("Data/tm.dat") || {}
end
return $PokemonTemp.speciesTMData
end
#===============================================================================
# Method to get Shadow Pokémon moveset data.
#===============================================================================
@@ -196,17 +92,6 @@ def pbLoadShadowMovesets
return $PokemonTemp.speciesShadowMovesets
end
#===============================================================================
# Method to get array that converts species + form to and from fSpecies values.
#===============================================================================
def pbLoadFormToSpecies
$PokemonTemp = PokemonTemp.new if !$PokemonTemp
if !$PokemonTemp.pokemonFormToSpecies
$PokemonTemp.pokemonFormToSpecies = load_data("Data/form2species.dat")
end
return $PokemonTemp.pokemonFormToSpecies
end
#===============================================================================
# Methods to get data about individual trainers.
#===============================================================================
@@ -125,5 +125,7 @@ module GameData
MapMetadata.load
Move.load
TrainerType.load
Type.load
Species.load
end
end
@@ -115,8 +115,8 @@ module GameData
def can_hold?; return !is_important?; end
def unlosable?(species, ability)
return false if isConst?(species, PBSpecies, :ARCEUS) && ability != :MULTITYPE
return false if isConst?(species, PBSpecies, :SILVALLY) && ability != :RKSSYSTEM
return false if species == :ARCEUS && ability != :MULTITYPE
return false if species == :SILVALLY && ability != :RKSSYSTEM
combos = {
:ARCEUS => [:FISTPLATE, :FIGHTINIUMZ,
:SKYPLATE, :FLYINIUMZ,
@@ -157,11 +157,7 @@ module GameData
:KYOGRE => [:BLUEORB],
:GROUDON => [:REDORB]
}
combos.each do |comboSpecies, items|
next if !isConst?(species, PBSpecies, comboSpecies)
return items.include?(@id)
end
return false
return combos[species] && combos[species].include?(@id)
end
end
end
@@ -0,0 +1,339 @@
module GameData
class Species
attr_reader :id
attr_reader :id_number
attr_reader :species
attr_reader :form
attr_reader :real_name
attr_reader :real_form_name
attr_reader :real_category
attr_reader :real_pokedex_entry
attr_reader :pokedex_form
attr_reader :type1
attr_reader :type2
attr_reader :base_stats
attr_reader :evs
attr_reader :base_exp
attr_reader :growth_rate
attr_reader :gender_rate
attr_reader :catch_rate
attr_reader :happiness
attr_reader :moves
attr_reader :tutor_moves
attr_reader :egg_moves
attr_reader :abilities
attr_reader :hidden_abilities
attr_reader :wild_item_common
attr_reader :wild_item_uncommon
attr_reader :wild_item_rare
attr_reader :egg_groups
attr_reader :hatch_steps
attr_reader :incense
attr_reader :evolutions
attr_reader :height
attr_reader :weight
attr_reader :color
attr_reader :shape
attr_reader :habitat
attr_reader :generation
attr_reader :mega_stone
attr_reader :mega_move
attr_reader :unmega_form
attr_reader :mega_message
attr_accessor :back_sprite_x
attr_accessor :back_sprite_y
attr_accessor :front_sprite_x
attr_accessor :front_sprite_y
attr_accessor :front_sprite_altitude
attr_accessor :shadow_x
attr_accessor :shadow_size
DATA = {}
DATA_FILENAME = "species.dat"
extend ClassMethods
include InstanceMethods
# @param species [Symbol, self, String, Integer]
# @param form [Integer]
# @return [self, nil]
def self.get_species_form(species, form)
return nil if !species || !form
validate species => [Symbol, self, String, Integer]
validate form => Integer
# if other.is_a?(Integer)
# p "Please switch to symbols, thanks."
# end
species = species.species if species.is_a?(self)
species = DATA[species].species if species.is_a?(Integer)
species = species.to_sym if species.is_a?(String)
trial = sprintf("%s_%d", species, form).to_sym
species_form = (DATA[trial].nil?) ? species : trial
return (DATA.has_key?(species_form)) ? DATA[species_form] : nil
end
# TODO: Needs tidying up.
def self.schema(compiling_forms = false)
ret = {
"FormName" => [0, "q"],
"Kind" => [0, "s"],
"Pokedex" => [0, "q"],
"Type1" => [0, "e", :Type],
"Type2" => [0, "e", :Type],
"BaseStats" => [0, "vvvvvv"],
"EffortPoints" => [0, "uuuuuu"],
"BaseEXP" => [0, "v"],
"Rareness" => [0, "u"],
"Happiness" => [0, "u"],
"Moves" => [0, "*ue", nil, :Move],
"TutorMoves" => [0, "*e", :Move],
"EggMoves" => [0, "*e", :Move],
"Abilities" => [0, "*e", :Ability],
"HiddenAbility" => [0, "*e", :Ability],
"WildItemCommon" => [0, "e", :Item],
"WildItemUncommon" => [0, "e", :Item],
"WildItemRare" => [0, "e", :Item],
"Compatibility" => [0, "*e", :PBEggGroups],
"StepsToHatch" => [0, "v"],
"Height" => [0, "f"],
"Weight" => [0, "f"],
"Color" => [0, "e", :PBColors],
"Shape" => [0, "u"],
"Habitat" => [0, "e", :PBHabitats],
"Generation" => [0, "i"],
"BattlerPlayerX" => [0, "i"],
"BattlerPlayerY" => [0, "i"],
"BattlerEnemyX" => [0, "i"],
"BattlerEnemyY" => [0, "i"],
"BattlerAltitude" => [0, "i"],
"BattlerShadowX" => [0, "i"],
"BattlerShadowSize" => [0, "u"]
}
if compiling_forms
ret["PokedexForm"] = [0, "u"]
ret["Evolutions"] = [0, "*ees", :Species, :PBEvolution, nil]
ret["MegaStone"] = [0, "e", :Item]
ret["MegaMove"] = [0, "e", :Move]
ret["UnmegaForm"] = [0, "u"]
ret["MegaMessage"] = [0, "u"]
else
ret["InternalName"] = [0, "n"]
ret["Name"] = [0, "s"]
ret["GrowthRate"] = [0, "e", :PBGrowthRates]
ret["GenderRate"] = [0, "e", :PBGenderRates]
ret["Incense"] = [0, "e", :Item]
ret["Evolutions"] = [0, "*ses", nil, :PBEvolution, nil]
end
return ret
end
def initialize(hash)
@id = hash[:id]
@id_number = hash[:id_number] || -1
@species = hash[:species] || @id
@form = hash[:form] || 0
@real_name = hash[:name] || "Unnamed"
@real_form_name = hash[:form_name]
@real_category = hash[:category] || "???"
@real_pokedex_entry = hash[:pokedex_entry] || "???"
@pokedex_form = hash[:pokedex_form] || @form
@type1 = hash[:type1] || :NORMAL
@type2 = hash[:type2] || @type1
@base_stats = hash[:base_stats] || [1, 1, 1, 1, 1, 1]
@evs = hash[:evs] || [0, 0, 0, 0, 0, 0]
@base_exp = hash[:base_exp] || 100
@growth_rate = hash[:growth_rate] || PBGrowthRates::Medium
@gender_rate = hash[:gender_rate] || PBGenderRates::Female50Percent
@catch_rate = hash[:catch_rate] || 255
@happiness = hash[:happiness] || 70
@moves = hash[:moves] || []
@tutor_moves = hash[:tutor_moves] || []
@egg_moves = hash[:egg_moves] || []
@abilities = hash[:abilities] || []
@hidden_abilities = hash[:hidden_abilities] || []
@wild_item_common = hash[:wild_item_common]
@wild_item_uncommon = hash[:wild_item_uncommon]
@wild_item_rare = hash[:wild_item_rare]
@egg_groups = hash[:egg_groups] || [PBEggGroups::Undiscovered]
@hatch_steps = hash[:hatch_steps] || 1
@incense = hash[:incense]
@evolutions = hash[:evolutions] || []
@height = hash[:height] || 1
@weight = hash[:weight] || 1
@color = hash[:color] || PBColors::Red
@shape = hash[:shape] || 1
@habitat = hash[:habitat] || PBHabitats::None
@generation = hash[:generation] || 0
@mega_stone = hash[:mega_stone]
@mega_move = hash[:mega_move]
@unmega_form = hash[:unmega_form] || 0
@mega_message = hash[:mega_message] || 0
@back_sprite_x = hash[:back_sprite_x] || 0
@back_sprite_y = hash[:back_sprite_y] || 0
@front_sprite_x = hash[:front_sprite_x] || 0
@front_sprite_y = hash[:front_sprite_y] || 0
@front_sprite_altitude = hash[:front_sprite_altitude] || 0
@shadow_x = hash[:shadow_x] || 0
@shadow_size = hash[:shadow_size] || 2
end
# @return [String] the translated name of this species
def name
return pbGetMessage(MessageTypes::Species, @id_number)
end
# @return [String] the translated name of this form of this species
def form_name
return pbGetMessage(MessageTypes::FormNames, @id_number)
end
# @return [String] the translated Pokédex category of this species
def category
return pbGetMessage(MessageTypes::Kinds, @id_number)
end
# @return [String] the translated Pokédex entry of this species
def pokedex_entry
return pbGetMessage(MessageTypes::Entries, @id_number)
end
end
def apply_metrics_to_sprite(sprite, index, shadow = false)
if shadow
if (index & 1) == 1 # Foe Pokémon
sprite.x += @shadow_x * 2
end
else
if (index & 1) == 0 # Player's Pokémon
sprite.x += @back_sprite_x * 2
sprite.y += @back_sprite_y * 2
else # Foe Pokémon
sprite.x += @front_sprite_x * 2
sprite.y += @front_sprite_y * 2
sprite.y -= @front_sprite_altitude * 2
end
end
end
def shows_shadow?
return true
# return @front_sprite_altitude > 0
end
end
#===============================================================================
# Deprecated methods
#===============================================================================
module SpeciesData
TYPE1 = 0
TYPE2 = 1
BASE_STATS = 2
GENDER_RATE = 3
GROWTH_RATE = 4
BASE_EXP = 5
EFFORT_POINTS = 6
RARENESS = 7
HAPPINESS = 8
ABILITIES = 9
HIDDEN_ABILITY = 10
COMPATIBILITY = 11
STEPS_TO_HATCH = 12
HEIGHT = 13
WEIGHT = 14
COLOR = 15
SHAPE = 16
HABITAT = 17
WILD_ITEM_COMMON = 18
WILD_ITEM_UNCOMMON = 19
WILD_ITEM_RARE = 20
INCENSE = 21
POKEDEX_FORM = 22 # For alternate forms
MEGA_STONE = 23 # For alternate forms
MEGA_MOVE = 24 # For alternate forms
UNMEGA_FORM = 25 # For alternate forms
MEGA_MESSAGE = 26 # For alternate forms
METRIC_PLAYER_X = 27
METRIC_PLAYER_Y = 28
METRIC_ENEMY_X = 29
METRIC_ENEMY_Y = 30
METRIC_ALTITUDE = 31
METRIC_SHADOW_X = 32
METRIC_SHADOW_SIZE = 33
end
#===============================================================================
# Methods to get Pokémon species data.
#===============================================================================
def pbGetSpeciesData(species, form = 0, species_data_type = -1)
Deprecation.warn_method('pbGetSpeciesData', 'v20', 'GameData::Species.get_species_form(species, form).something')
ret = GameData::Species.get_species_form(species, form)
return ret if species_data_type == -1
case species_data_type
when SpeciesData::TYPE1 then return ret.type1
when SpeciesData::TYPE2 then return ret.type2
when SpeciesData::BASE_STATS then return ret.base_stats
when SpeciesData::GENDER_RATE then return ret.gender_rate
when SpeciesData::GROWTH_RATE then return ret.growth_rate
when SpeciesData::BASE_EXP then return ret.base_exp
when SpeciesData::EFFORT_POINTS then return ret.evs
when SpeciesData::RARENESS then return ret.catch_rate
when SpeciesData::HAPPINESS then return ret.happiness
when SpeciesData::ABILITIES then return ret.abilities
when SpeciesData::HIDDEN_ABILITY then return ret.hidden_abilities
when SpeciesData::COMPATIBILITY then return ret.egg_groups
when SpeciesData::STEPS_TO_HATCH then return ret.hatch_steps
when SpeciesData::HEIGHT then return ret.height
when SpeciesData::WEIGHT then return ret.weight
when SpeciesData::COLOR then return ret.color
when SpeciesData::SHAPE then return ret.shape
when SpeciesData::HABITAT then return ret.habitat
when SpeciesData::WILD_ITEM_COMMON then return ret.wild_item_common
when SpeciesData::WILD_ITEM_UNCOMMON then return ret.wild_item_uncommon
when SpeciesData::WILD_ITEM_RARE then return ret.wild_item_rare
when SpeciesData::INCENSE then return ret.incense
when SpeciesData::POKEDEX_FORM then return ret.pokedex_form
when SpeciesData::MEGA_STONE then return ret.mega_stone
when SpeciesData::MEGA_MOVE then return ret.mega_move
when SpeciesData::UNMEGA_FORM then return ret.unmega_form
when SpeciesData::MEGA_MESSAGE then return ret.mega_message
when SpeciesData::METRIC_PLAYER_X then return ret.back_sprite_x
when SpeciesData::METRIC_PLAYER_Y then return ret.back_sprite_y
when SpeciesData::METRIC_ENEMY_X then return ret.front_sprite_x
when SpeciesData::METRIC_ENEMY_Y then return ret.front_sprite_y
when SpeciesData::METRIC_ALTITUDE then return ret.front_sprite_altitude
when SpeciesData::METRIC_SHADOW_X then return ret.shadow_x
when SpeciesData::METRIC_SHADOW_SIZE then return ret.shadow_size
end
return 0
end
#===============================================================================
# Methods to get Pokémon moves data.
#===============================================================================
def pbGetSpeciesEggMoves(species, form = 0)
Deprecation.warn_method('pbGetSpeciesEggMoves', 'v20', 'GameData::Species.get_species_form(species, form).egg_moves')
return GameData::Species.get_species_form(species, form).egg_moves
end
def pbGetSpeciesMoveset(species, form = 0)
Deprecation.warn_method('pbGetSpeciesMoveset', 'v20', 'GameData::Species.get_species_form(species, form).moves')
return GameData::Species.get_species_form(species, form).moves
end
def pbGetEvolutionData(species)
Deprecation.warn_method('pbGetEvolutionData', 'v20', 'GameData::Species.get(species).evolutions')
return GameData::Species.get(species).evolutions
end
#===============================================================================
# Method to get Pokémon species metrics (sprite positioning) data.
#===============================================================================
def pbApplyBattlerMetricsToSprite(sprite, index, species_data, shadow = false, metrics = nil)
Deprecation.warn_method('pbApplyBattlerMetricsToSprite', 'v20', 'GameData::Species.get(species).apply_metrics_to_sprite')
GameData::Species.get(species).apply_metrics_to_sprite(sprite, index, shadow)
end
def showShadow?(species)
Deprecation.warn_method('showShadow?', 'v20', 'GameData::Species.get(species).shows_shadow?')
return GameData::Species.get(species).shows_shadow?
end
@@ -0,0 +1,341 @@
module GameData
class Species
def self.check_graphic_file(path, species, form = 0, gender = 0, shiny = false, shadow = false, back = false)
species_data = self.get_species_form(species, form)
species_id = sprintf("%03d", (species_data) ? self.get(species_data.species).id_number : 0)
try_species = species
try_form = (form > 0) ? sprintf("_%d", form) : ""
try_gender = (gender == 1) ? "f" : ""
try_shiny = (shiny) ? "s" : ""
try_shadow = (shadow) ? "_shadow" : ""
try_back = (back) ? "b" : ""
factors = []
factors.push([4, try_shadow, ""]) if shadow
factors.push([2, try_gender, ""]) if gender == 1
factors.push([3, try_shiny, ""]) if shiny
factors.push([1, try_form, ""]) if form > 0
factors.push([0, try_species, "000"])
# Go through each combination of parameters in turn to find an existing sprite
for i in 0...2 ** factors.length
# Set try_ parameters for this combination
factors.each_with_index do |factor, index|
value = ((i / (2 ** index)) % 2 == 0) ? factor[1] : factor[2]
case factor[0]
when 0 then try_species = value
when 1 then try_form = value
when 2 then try_gender = value
when 3 then try_shiny = value
when 4 then try_shadow = value
end
end
# Look for a graphic matching this combination's parameters
for j in 0...2 # Try using the species' ID symbol and then its ID number
next if !try_species || (try_species == "000" && j == 1)
try_species_text = (j == 0) ? try_species : species_id
ret = pbResolveBitmap(sprintf("%s%s%s%s%s%s%s", path,
try_species_text, try_gender, try_shiny, try_back, try_form, try_shadow))
return ret if ret
end
end
return nil
end
def self.check_egg_graphic_file(path, species, form)
species_data = self.get_species_form(species, form)
return nil if species_data.nil?
species_id = self.get(species_data.species).id_number
if form > 0
ret = pbResolveBitmap(sprintf("%s%segg_%d", path, species_data.species, form))
return ret if ret
ret = pbResolveBitmap(sprintf("%s%03degg_%d", path, species_id, form))
return ret if ret
end
ret = pbResolveBitmap(sprintf("%s%segg", path, species_data.species))
return ret if ret
return pbResolveBitmap(sprintf("%s%03degg", path, species_id))
end
def self.front_sprite_filename(species, form = 0, gender = 0, shiny = false, shadow = false)
return self.check_graphic_file("Graphics/Battlers/", species, form, gender, shiny, shadow)
end
def self.back_sprite_filename(species, form = 0, gender = 0, shiny = false, shadow = false)
return self.check_graphic_file("Graphics/Battlers/", species, form, gender, shiny, shadow, true)
end
def self.egg_sprite_filename(species, form)
ret = self.check_egg_graphic_file("Graphics/Battlers/", species, form)
return (ret) ? ret : pbResolveBitmap("Graphics/Battlers/egg")
end
def self.sprite_filename(species, form = 0, gender = 0, shiny = false, shadow = false, back = false, egg = false)
return self.egg_sprite_filename(species, form) if egg
return self.back_sprite_filename(species, form, gender, shiny, shadow) if back
return self.front_sprite_filename(species, form, gender, shiny, shadow)
end
def self.front_sprite_bitmap(species, form = 0, gender = 0, shiny = false, shadow = false)
filename = self.front_sprite_filename(species, form, gender, shiny, shadow)
return (filename) ? AnimatedBitmap.new(filename) : nil
end
def self.back_sprite_bitmap(species, form = 0, gender = 0, shiny = false, shadow = false)
filename = self.back_sprite_filename(species, form, gender, shiny, shadow)
return (filename) ? AnimatedBitmap.new(filename) : nil
end
def self.egg_sprite_bitmap(species, form = 0)
filename = self.egg_sprite_filename(species, form)
return (filename) ? AnimatedBitmap.new(filename) : nil
end
def self.sprite_bitmap(species, form = 0, gender = 0, shiny = false, shadow = false, back = false, egg = false)
return self.egg_sprite_bitmap(species, form) if egg
return self.back_sprite_bitmap(species, form, gender, shiny, shadow) if back
return self.front_sprite_bitmap(species, form, gender, shiny, shadow)
end
def self.sprite_bitmap_from_pokemon(pkmn, back = false, species = nil)
species = pkmn.species if !species
species = GameData::Species.get(species).species # Just to be sure it's a symbol
return self.egg_sprite_bitmap(species, pkmn.form) if pkmn.egg?
if back
ret = self.back_sprite_bitmap(species, pkmn.form, pkmn.gender, pkmn.shiny?, pkmn.shadowPokemon?)
else
ret = self.front_sprite_bitmap(species, pkmn.form, pkmn.gender, pkmn.shiny?, pkmn.shadowPokemon?)
end
alter_bitmap_function = MultipleForms.getFunction(species, "alterBitmap")
if ret && alter_bitmap_function
new_ret = ret.copy
ret.dispose
new_ret.each { |bitmap| alter_bitmap_function.call(pkmn, bitmap) }
ret = new_ret
end
return ret
end
#===========================================================================
def self.egg_icon_filename(species, form)
ret = self.check_egg_graphic_file("Graphics/Icons/icon", species, form)
return (ret) ? ret : pbResolveBitmap("Graphics/Icons/iconEgg")
end
def self.icon_filename(species, form = 0, gender = 0, shiny = false, shadow = false, egg = false)
return self.egg_icon_filename(species, form) if egg
return self.check_graphic_file("Graphics/Icons/icon", species, form, gender, shiny, shadow)
end
def self.icon_filename_from_pokemon(pkmn)
return self.icon_filename(pkmn.species, pkmn.form, pkmn.gender, pkmn.shiny?, pkmn.shadowPokemon?, pkmn.egg?)
end
def self.egg_icon_bitmap(species, form)
filename = self.egg_icon_filename(species, form)
return (filename) ? AnimatedBitmap.new(filename).deanimate : nil
end
def self.icon_bitmap(species, form = 0, gender = 0, shiny = false, shadow = false)
filename = self.icon_filename(species, form, gender,shiny, shadow)
return (filename) ? AnimatedBitmap.new(filename).deanimate : nil
end
def self.icon_bitmap_from_pokemon(pkmn)
return self.icon_bitmap(pkmn.species, pkmn.form, pkmn.gender, pkmn.shiny?, pkmn.shadowPokemon?, pkmn.egg?)
end
#===========================================================================
def self.footprint_filename(species, form = 0)
species_data = self.get_species_form(species, form)
return nil if species_data.nil?
species_id = self.get(species_data.species).id_number
if form > 0
ret = pbResolveBitmap(sprintf("Graphics/Icons/Footprints/footprint%s_%d", species_data.species, form))
return ret if ret
ret = pbResolveBitmap(sprintf("Graphics/Icons/Footprints/footprint%03d_%d", species_id, form))
return ret if ret
end
ret = pbResolveBitmap(sprintf("Graphics/Icons/Footprints/footprint%s", species_data.species))
return ret if ret
return pbResolveBitmap(sprintf("Graphics/Icons/Footprints/footprint%03d", species_id))
end
#===========================================================================
def self.shadow_filename(species, form = 0)
species_data = self.get_species_form(species, form)
return nil if species_data.nil?
species_id = self.get(species_data.species).id_number
# Look for species-specific shadow graphic
if form > 0
ret = pbResolveBitmap(sprintf("Graphics/Battlers/%s_%d_battleshadow", species_data.species, form))
return ret if ret
ret = pbResolveBitmap(sprintf("Graphics/Battlers/%03d_%d_battleshadow", species_id, form))
return ret if ret
end
ret = pbResolveBitmap(sprintf("Graphics/Battlers/%s_battleshadow", species_data.species))
return ret if ret
ret = pbResolveBitmap(sprintf("Graphics/Battlers/%03d_battleshadow", species_id))
return ret if ret
# Use general shadow graphic
return pbResolveBitmap(sprintf("Graphics/Pictures/Battle/battler_shadow_%d", species_data.shadow_size))
end
def self.shadow_bitmap(species, form = 0)
filename = self.shadow_filename(species, form)
return (filename) ? AnimatedBitmap.new(filename) : nil
end
def self.shadow_bitmap_from_pokemon(pkmn)
filename = self.shadow_filename(pkmn.species, pkmn.form)
return (filename) ? AnimatedBitmap.new(filename) : nil
end
#===========================================================================
def self.check_cry_file(species, form)
species_data = self.get_species_form(species, form)
return nil if species_data.nil?
species_id = self.get(species_data.species).id_number
if form > 0
ret = sprintf("Cries/%sCry_%d", species_data.species, form)
return ret if pbResolveAudioSE(ret)
ret = sprintf("Cries/%03dCry_%d", species_id, form)
return ret if pbResolveAudioSE(ret)
end
ret = sprintf("Cries/%sCry", species_data.species)
return ret if pbResolveAudioSE(ret)
ret = sprintf("Cries/%03dCry", species_id)
return (pbResolveAudioSE(ret)) ? ret : nil
end
def self.cry_filename(species, form = 0)
return self.check_cry_file(species, form)
end
def self.cry_filename_from_pokemon(pkmn)
return self.check_cry_file(pkmn.species, pkmn.form)
end
def self.play_cry_from_species(species, form = 0, volume = 90, pitch = 100)
filename = self.cry_filename(species, form)
return if !filename
pbSEPlay(RPG::AudioFile.new(filename, volume, pitch)) rescue nil
end
def self.play_cry_from_pokemon(pkmn, volume = 90, pitch = nil)
return if !pkmn || pkmn.egg?
if pkmn.respond_to?("chatter") && pkmn.chatter
pkmn.chatter.play
return
end
filename = self.cry_filename_from_pokemon(pkmn)
return if !filename
pitch ||= 75 + (pkmn.hp * 25 / pkmn.totalhp)
pbSEPlay(RPG::AudioFile.new(filename, volume, pitch)) rescue nil
end
def self.play_cry(pkmn, volume = 90, pitch = nil)
if pkmn.is_a?(Pokemon)
self.play_cry_from_pokemon(pkmn, volume, pitch)
else
self.play_cry_from_species(pkmn, nil, volume, pitch)
end
end
def self.cry_length(species, form = 0, pitch = 100)
return 0 if !species || pitch <= 0
pitch = pitch.to_f / 100
ret = 0.0
if species.is_a?(Pokemon)
if !species.egg?
if species.respond_to?("chatter") && species.chatter
ret = species.chatter.time
pitch = 1.0
else
filename = pbResolveAudioSE(GameData::Species.cry_filename_from_pokemon(species))
ret = getPlayTime(filename) if filename
end
end
else
filename = pbResolveAudioSE(GameData::Species.cry_filename(species, form))
ret = getPlayTime(filename) if filename
end
ret /= pitch # Sound played at a lower pitch lasts longer
return (ret * Graphics.frame_rate).ceil + 4 # 4 provides a buffer between sounds
end
end
end
#===============================================================================
# Deprecated
#===============================================================================
def pbLoadSpeciesBitmap(species, gender = 0, form = 0, shiny = false, shadow = false, back = false , egg = false)
Deprecation.warn_method('pbLoadSpeciesBitmap', 'v20', 'GameData::Species.sprite_bitmap(species, form, gender, shiny, shadow, back, egg)')
return GameData::Species.sprite_bitmap(species, form, gender, shiny, shadow, back, egg)
end
def pbLoadPokemonBitmap(pkmn, back = false)
Deprecation.warn_method('pbLoadPokemonBitmap', 'v20', 'GameData::Species.sprite_bitmap_from_pokemon(pkmn)')
return GameData::Species.sprite_bitmap_from_pokemon(pkmn, back)
end
def pbLoadPokemonBitmapSpecies(pkmn, species, back = false)
Deprecation.warn_method('pbLoadPokemonBitmapSpecies', 'v20', 'GameData::Species.sprite_bitmap_from_pokemon(pkmn, back, species)')
return GameData::Species.sprite_bitmap_from_pokemon(pkmn, back, species)
end
def pbPokemonIconFile(pkmn)
Deprecation.warn_method('pbPokemonIconFile', 'v20', 'GameData::Species.icon_filename_from_pokemon(pkmn)')
return GameData::Species.icon_filename_from_pokemon(pkmn)
end
def pbLoadPokemonIcon(pkmn)
Deprecation.warn_method('pbLoadPokemonIcon', 'v20', 'GameData::Species.icon_bitmap_from_pokemon(pkmn)')
return GameData::Species.icon_bitmap_from_pokemon(pkmn)
end
def pbPokemonFootprintFile(species, form = 0)
Deprecation.warn_method('pbPokemonFootprintFile', 'v20', 'GameData::Species.footprint_filename(species, form)')
return GameData::Species.footprint_filename(species, form)
end
def pbCheckPokemonShadowBitmapFiles(species, form = 0)
Deprecation.warn_method('pbCheckPokemonShadowBitmapFiles', 'v20', 'GameData::Species.shadow_filename(species, form)')
return GameData::Species.shadow_filename(species, form)
end
def pbLoadPokemonShadowBitmap(pkmn)
Deprecation.warn_method('pbLoadPokemonShadowBitmap', 'v20', 'GameData::Species.shadow_bitmap_from_pokemon(pkmn)')
return GameData::Species.shadow_bitmap_from_pokemon(pkmn)
end
def pbCryFile(species, form = 0)
if species.is_a?(Pokemon)
Deprecation.warn_method('pbCryFile', 'v20', 'GameData::Species.cry_filename_from_pokemon(pkmn)')
return GameData::Species.cry_filename_from_pokemon(species)
end
Deprecation.warn_method('pbCryFile', 'v20', 'GameData::Species.cry_filename(species, form)')
return GameData::Species.cry_filename(species, form)
end
def pbPlayCry(pkmn, volume = 90, pitch = nil)
Deprecation.warn_method('pbPlayCry', 'v20', 'GameData::Species.play_cry(pkmn)')
GameData::Species.play_cry(pkmn, volume, pitch)
end
def pbPlayCrySpecies(species, form = 0, volume = 90, pitch = nil)
Deprecation.warn_method('pbPlayCrySpecies', 'v20', 'GameData::Species.play_cry_from_species(species, form)')
GameData::Species.play_cry_from_species(species, form, volume, pitch)
end
def pbPlayCryPokemon(pkmn, volume = 90, pitch = nil)
Deprecation.warn_method('pbPlayCryPokemon', 'v20', 'GameData::Species.play_cry_from_pokemon(pkmn)')
GameData::Species.play_cry_from_pokemon(pkmn, volume, pitch)
end
def pbCryFrameLength(species, form = 0, pitch = 100)
Deprecation.warn_method('pbCryFrameLength', 'v20', 'GameData::Species.cry_length(species, form)')
return GameData::Species.cry_length(species, form, pitch)
end
-133
View File
@@ -1,133 +0,0 @@
#===============================================================================
# Phone data
#===============================================================================
class PhoneDatabase
attr_accessor :generics
attr_accessor :greetings
attr_accessor :greetingsMorning
attr_accessor :greetingsEvening
attr_accessor :bodies1
attr_accessor :bodies2
attr_accessor :battleRequests
attr_accessor :trainers
def initialize
@generics = []
@greetings = []
@greetingsMorning = []
@greetingsEvening = []
@bodies1 = []
@bodies2 = []
@battleRequests = []
@trainers = []
end
end
module PhoneMsgType
Generic = 0
Greeting = 1
Body = 2
BattleRequest = 3
end
#===============================================================================
# Pokémon data
#===============================================================================
module SpeciesData
TYPE1 = 0
TYPE2 = 1
BASE_STATS = 2
GENDER_RATE = 3
GROWTH_RATE = 4
BASE_EXP = 5
EFFORT_POINTS = 6
RARENESS = 7
HAPPINESS = 8
ABILITIES = 9
HIDDEN_ABILITY = 10
COMPATIBILITY = 11
STEPS_TO_HATCH = 12
HEIGHT = 13
WEIGHT = 14
COLOR = 15
SHAPE = 16
HABITAT = 17
WILD_ITEM_COMMON = 18
WILD_ITEM_UNCOMMON = 19
WILD_ITEM_RARE = 20
INCENSE = 21
POKEDEX_FORM = 22 # For alternate forms
MEGA_STONE = 23 # For alternate forms
MEGA_MOVE = 24 # For alternate forms
UNMEGA_FORM = 25 # For alternate forms
MEGA_MESSAGE = 26 # For alternate forms
METRIC_PLAYER_X = 0
METRIC_PLAYER_Y = 1
METRIC_ENEMY_X = 2
METRIC_ENEMY_Y = 3
METRIC_ALTITUDE = 4
METRIC_SHADOW_X = 5
METRIC_SHADOW_SIZE = 6
def self.requiredValues(compilingForms = false)
ret = {
"Type1" => [TYPE1, "e", :Type],
"BaseStats" => [BASE_STATS, "vvvvvv"],
"BaseEXP" => [BASE_EXP, "v"],
"EffortPoints" => [EFFORT_POINTS, "uuuuuu"],
"Rareness" => [RARENESS, "u"],
"Happiness" => [HAPPINESS, "u"],
"Compatibility" => [COMPATIBILITY, "eE", :PBEggGroups, :PBEggGroups],
"StepsToHatch" => [STEPS_TO_HATCH, "v"],
"Height" => [HEIGHT, "f"],
"Weight" => [WEIGHT, "f"],
"Color" => [COLOR, "e", :PBColors],
"Shape" => [SHAPE, "u"],
"Moves" => [0, "*ue", nil, :Move],
"Kind" => [0, "s"],
"Pokedex" => [0, "q"]
}
if !compilingForms
ret["GenderRate"] = [GENDER_RATE, "e", :PBGenderRates]
ret["GrowthRate"] = [GROWTH_RATE, "e", :PBGrowthRates]
ret["Name"] = [0, "s"]
ret["InternalName"] = [0, "n"]
end
return ret
end
def self.optionalValues(compilingForms = false)
ret = {
"Type2" => [TYPE2, "e", :Type],
"Abilities" => [ABILITIES, "eE", :Ability, :Ability],
"HiddenAbility" => [HIDDEN_ABILITY, "eEEE", :Ability, :Ability,
:Ability, :Ability],
"Habitat" => [HABITAT, "e", :PBHabitats],
"WildItemCommon" => [WILD_ITEM_COMMON, "e", :Item],
"WildItemUncommon" => [WILD_ITEM_UNCOMMON, "e", :Item],
"WildItemRare" => [WILD_ITEM_RARE, "e", :Item],
"BattlerPlayerX" => [METRIC_PLAYER_X, "i"],
"BattlerPlayerY" => [METRIC_PLAYER_Y, "i"],
"BattlerEnemyX" => [METRIC_ENEMY_X, "i"],
"BattlerEnemyY" => [METRIC_ENEMY_Y, "i"],
"BattlerAltitude" => [METRIC_ALTITUDE, "i"],
"BattlerShadowX" => [METRIC_SHADOW_X, "i"],
"BattlerShadowSize" => [METRIC_SHADOW_SIZE, "u"],
"EggMoves" => [0, "*e", :Move],
"FormName" => [0, "q"],
"Evolutions" => [0, "*ses", nil, :PBEvolution, nil]
}
if compilingForms
ret["PokedexForm"] = [POKEDEX_FORM, "u"]
ret["MegaStone"] = [MEGA_STONE, "e", :Item]
ret["MegaMove"] = [MEGA_MOVE, "e", :Move]
ret["UnmegaForm"] = [UNMEGA_FORM, "u"]
ret["MegaMessage"] = [MEGA_MESSAGE, "u"]
else
ret["Incense"] = [INCENSE, "e", :Item]
ret["RegionalNumbers"] = [0, "*u"]
end
return ret
end
end
+31
View File
@@ -0,0 +1,31 @@
#===============================================================================
# Phone data
#===============================================================================
class PhoneDatabase
attr_accessor :generics
attr_accessor :greetings
attr_accessor :greetingsMorning
attr_accessor :greetingsEvening
attr_accessor :bodies1
attr_accessor :bodies2
attr_accessor :battleRequests
attr_accessor :trainers
def initialize
@generics = []
@greetings = []
@greetingsMorning = []
@greetingsEvening = []
@bodies1 = []
@bodies2 = []
@battleRequests = []
@trainers = []
end
end
module PhoneMsgType
Generic = 0
Greeting = 1
Body = 2
BattleRequest = 3
end
@@ -1,8 +1,8 @@
module PBGrowthRates
Medium = MediumFast = 0
MediumFast = Medium = 0
Erratic = 1
Fluctuating = 2
Parabolic = MediumSlow = 3
MediumSlow = Parabolic = 3
Fast = 4
Slow = 5
@@ -33,8 +33,7 @@ end
class PokeBattle_Move_003 < PokeBattle_SleepMove
def pbMoveFailed?(user,targets)
if NEWEST_BATTLE_MECHANICS && @id == :DARKVOID
if !user.isSpecies?(:DARKRAI) &&
!isConst?(user.effects[PBEffects::TransformSpecies],PBSpecies,:DARKRAI)
if !user.isSpecies?(:DARKRAI) && user.effects[PBEffects::TransformSpecies] != :DARKRAI
@battle.pbDisplay(_INTL("But {1} can't use the move!",user.pbThis))
return true
end
@@ -53,7 +53,7 @@ module PokeBattle_BattleCommon
end
# Record a Shadow Pokémon's species as having been caught
if pkmn.shadowPokemon?
pbPlayer.shadowcaught = [] if !pbPlayer.shadowcaught
pbPlayer.shadowcaught = {} if !pbPlayer.shadowcaught
pbPlayer.shadowcaught[pkmn.species] = true
end
# Store caught Pokémon
@@ -65,7 +65,7 @@ module PokeBattle_BattleCommon
#=============================================================================
# Throw a Poké Ball
#=============================================================================
def pbThrowPokeBall(idxBattler,ball,rareness=nil,showPlayer=false)
def pbThrowPokeBall(idxBattler,ball,catch_rate=nil,showPlayer=false)
# Determine which Pokémon you're throwing the Poké Ball at
battler = nil
if opposes?(idxBattler)
@@ -105,7 +105,7 @@ module PokeBattle_BattleCommon
# Calculate the number of shakes (4=capture)
pkmn = battler.pokemon
@criticalCapture = false
numShakes = pbCaptureCalc(pkmn,battler,rareness,ball)
numShakes = pbCaptureCalc(pkmn,battler,catch_rate,ball)
PBDebug.log("[Threw Poké Ball] #{itemName}, #{numShakes} shakes (4=capture)")
# Animation of Ball throw, absorb, shake and capture/burst out
@scene.pbThrow(ball,numShakes,@criticalCapture,battler.index,showPlayer)
@@ -162,33 +162,23 @@ module PokeBattle_BattleCommon
#=============================================================================
# Calculate how many shakes a thrown Poké Ball will make (4 = capture)
#=============================================================================
def pbCaptureCalc(pkmn,battler,rareness,ball)
def pbCaptureCalc(pkmn,battler,catch_rate,ball)
return 4 if $DEBUG && Input.press?(Input::CTRL)
# Get a rareness if one wasn't provided
if !rareness
rareness = pbGetSpeciesData(pkmn.species,pkmn.form,SpeciesData::RARENESS)
end
# Modify rareness depending on the Poké Ball's effect
ultraBeast = (battler.isSpecies?(:NIHILEGO) ||
battler.isSpecies?(:BUZZWOLE) ||
battler.isSpecies?(:PHEROMOSA) ||
battler.isSpecies?(:XURKITREE) ||
battler.isSpecies?(:CELESTEELA) ||
battler.isSpecies?(:KARTANA) ||
battler.isSpecies?(:GUZZLORD) ||
battler.isSpecies?(:POIPOLE) ||
battler.isSpecies?(:NAGANADEL) ||
battler.isSpecies?(:STAKATAKA) ||
battler.isSpecies?(:BLACEPHALON))
# Get a catch rate if one wasn't provided
catch_rate = pkmn.species_data.catch_rate if !catch_rate
# Modify catch_rate depending on the Poké Ball's effect
ultraBeast = [:NIHILEGO, :BUZZWOLE, :PHEROMOSA, :XURKITREE, :CELESTEELA,
:KARTANA, :GUZZLORD, :POIPOLE, :NAGANADEL, :STAKATAKA,
:BLACEPHALON].include?(pkmn.species)
if !ultraBeast || ball == :BEASTBALL
rareness = BallHandlers.modifyCatchRate(ball,rareness,self,battler,ultraBeast)
catch_rate = BallHandlers.modifyCatchRate(ball,catch_rate,self,battler,ultraBeast)
else
rareness /= 10
catch_rate /= 10
end
# First half of the shakes calculation
a = battler.totalhp
b = battler.hp
x = ((3*a-2*b)*rareness.to_f)/(3*a)
x = ((3*a-2*b)*catch_rate.to_f)/(3*a)
# Calculation modifiers
if battler.status==PBStatuses::SLEEP || battler.status==PBStatuses::FROZEN
x *= 2.5
@@ -148,7 +148,7 @@ class PokeBattle_Battle
pbCommonAnimation("MegaEvolution2",battler)
megaName = battler.pokemon.megaName
if !megaName || megaName==""
megaName = _INTL("Mega {1}",PBSpecies.getName(battler.pokemon.species))
megaName = _INTL("Mega {1}", battler.pokemon.speciesName)
end
pbDisplay(_INTL("{1} has Mega Evolved into {2}!",battler.pbThis,megaName))
side = battler.idxOwnSide
@@ -668,10 +668,10 @@ class BattlerFaintAnimation < PokeBattle_Animation
# Animation
# Play cry
delay = 10
cry = pbCryFile(batSprite.pkmn)
cry = GameData::Species.cry_filename_from_pokemon(batSprite.pkmn)
if cry
battler.setSE(0,pbCryFile(batSprite.pkmn),nil,75) # 75 is pitch
delay = pbCryFrameLength(batSprite.pkmn)*20/Graphics.frame_rate
battler.setSE(0, cry, nil, 75) # 75 is pitch
delay = GameData::Species.cry_length(batSprite.pkmn) * 20 / Graphics.frame_rate
end
# Sprite drops down
shadow.setVisible(delay,false)
@@ -540,13 +540,13 @@ class PokemonBattlerSprite < RPG::Sprite
@spriteX = p[0]
@spriteY = p[1]
# Apply metrics
pbApplyBattlerMetricsToSprite(self,@index,@pkmn.fSpecies)
@pkmn.species_data.apply_metrics_to_sprite(self, @index)
end
def setPokemonBitmap(pkmn,back=false)
@pkmn = pkmn
@_iconBitmap.dispose if @_iconBitmap
@_iconBitmap = pbLoadPokemonBitmap(@pkmn,back)
@_iconBitmap = GameData::Species.sprite_bitmap_from_pokemon(@pkmn, back)
self.bitmap = (@_iconBitmap) ? @_iconBitmap.bitmap : nil
pbSetPosition
end
@@ -557,8 +557,7 @@ class PokemonBattlerSprite < RPG::Sprite
# @battleAnimations array.
def pbPlayIntroAnimation(pictureEx=nil)
return if !@pkmn
cry = pbCryFile(@pkmn)
pbSEPlay(cry) if cry
GameData::Species.play_cry_from_pokemon(@pkmn)
end
QUARTER_ANIM_PERIOD = Graphics.frame_rate*3/20
@@ -637,13 +636,13 @@ class PokemonBattlerShadowSprite < RPG::Sprite
self.x = p[0]
self.y = p[1]
# Apply metrics
pbApplyBattlerMetricsToSprite(self,@index,@pkmn.fSpecies,true)
@pkmn.species_data.apply_metrics_to_sprite(self, @index, true)
end
def setPokemonBitmap(pkmn)
@pkmn = pkmn
@_iconBitmap.dispose if @_iconBitmap
@_iconBitmap = pbLoadPokemonShadowBitmap(@pkmn)
@_iconBitmap = GameData::Species.shadow_bitmap_from_pokemon(@pkmn)
self.bitmap = (@_iconBitmap) ? @_iconBitmap.bitmap : nil
pbSetPosition
end
@@ -323,9 +323,7 @@ class PokeBattle_Scene
pkmnSprite.setPokemonBitmap(pkmn,back)
shadowSprite.setPokemonBitmap(pkmn)
# Set visibility of battler's shadow
if shadowSprite && !back
shadowSprite.visible = showShadow?(pkmn.fSpecies)
end
shadowSprite.visible = pkmn.species_data.shows_shadow? if shadowSprite && !back
end
def pbResetMoveIndex(idxBattler)
@@ -504,9 +504,8 @@ class PBAnimation < Array
when 0 # Play SE
if i.name && i.name!=""
pbSEPlay("Anim/"+i.name,i.volume,i.pitch)
else
poke = (user && user.pokemon) ? user.pokemon : 1
name = (pbCryFile(poke) rescue nil)
elsif user && user.pokemon
name = GameData::Species.cry_filename_from_pokemon(user.pokemon)
pbSEPlay(name,i.volume,i.pitch) if name
end
# if sprite
@@ -410,28 +410,28 @@ class PokeBattle_SafariZone
#=============================================================================
# Safari battle-specific methods
#=============================================================================
def pbEscapeRate(rareness)
return 125 if rareness<=45 # Escape factor 9 (45%)
return 100 if rareness<=60 # Escape factor 7 (35%)
return 75 if rareness<=120 # Escape factor 5 (25%)
return 50 if rareness<=250 # Escape factor 3 (15%)
return 25 # Escape factor 2 (10%)
def pbEscapeRate(catch_rate)
return 125 if catch_rate <= 45 # Escape factor 9 (45%)
return 100 if catch_rate <= 60 # Escape factor 7 (35%)
return 75 if catch_rate <= 120 # Escape factor 5 (25%)
return 50 if catch_rate <= 250 # Escape factor 3 (15%)
return 25 # Escape factor 2 (10%)
end
def pbStartBattle
begin
wildpoke = @party2[0]
self.pbPlayer.seen[wildpoke.species] = true
pbSeenForm(wildpoke)
pkmn = @party2[0]
self.pbPlayer.seen[pkmn.species] = true
pbSeenForm(pkmn)
@scene.pbStartBattle(self)
pbDisplayPaused(_INTL("Wild {1} appeared!",wildpoke.name))
pbDisplayPaused(_INTL("Wild {1} appeared!",pkmn.name))
@scene.pbSafariStart
@scene.pbCommonAnimation(PBWeather.animationName(@weather))
safariBall = GameData::Item.get(:SAFARIBALL).id
rareness = pbGetSpeciesData(wildpoke.species,wildpoke.form,SpeciesData::RARENESS)
catchFactor = (rareness*100)/1275
catch_rate = pkmn.species_data.catch_rate
catchFactor = (catch_rate*100)/1275
catchFactor = [[catchFactor,3].max,20].min
escapeFactor = (pbEscapeRate(rareness)*100)/1275
escapeFactor = (pbEscapeRate(catch_rate)*100)/1275
escapeFactor = [[escapeFactor,2].max,20].min
loop do
cmd = @scene.pbSafariCommandMenu(0)
@@ -452,12 +452,12 @@ class PokeBattle_SafariZone
end
end
when 1 # Bait
pbDisplayBrief(_INTL("{1} threw some bait at the {2}!",self.pbPlayer.name,wildpoke.name))
pbDisplayBrief(_INTL("{1} threw some bait at the {2}!",self.pbPlayer.name,pkmn.name))
@scene.pbThrowBait
catchFactor /= 2 if pbRandom(100)<90 # Harder to catch
escapeFactor /= 2 # Less likely to escape
when 2 # Rock
pbDisplayBrief(_INTL("{1} threw a rock at the {2}!",self.pbPlayer.name,wildpoke.name))
pbDisplayBrief(_INTL("{1} threw a rock at the {2}!",self.pbPlayer.name,pkmn.name))
@scene.pbThrowRock
catchFactor *= 2 # Easier to catch
escapeFactor *= 2 if pbRandom(100)<90 # More likely to escape
@@ -475,14 +475,14 @@ class PokeBattle_SafariZone
@decision = 2
elsif pbRandom(100)<5*escapeFactor
pbSEPlay("Battle flee")
pbDisplay(_INTL("{1} fled!",wildpoke.name))
pbDisplay(_INTL("{1} fled!",pkmn.name))
@decision = 3
elsif cmd==1 # Bait
pbDisplay(_INTL("{1} is eating!",wildpoke.name))
pbDisplay(_INTL("{1} is eating!",pkmn.name))
elsif cmd==2 # Rock
pbDisplay(_INTL("{1} is angry!",wildpoke.name))
pbDisplay(_INTL("{1} is angry!",pkmn.name))
else
pbDisplay(_INTL("{1} is watching carefully!",wildpoke.name))
pbDisplay(_INTL("{1} is watching carefully!",pkmn.name))
end
# Weather continues
@scene.pbCommonAnimation(PBWeather.animationName(@weather))
@@ -51,6 +51,19 @@ class PokeBattle_RealBattlePeer
def pbBoxName(box)
return (box<0) ? "" : $PokemonStorage[box].name
end
def pbOnEnteringBattle(_battle,pkmn,wild=false)
f = MultipleForms.call("getFormOnEnteringBattle",pkmn,wild)
pkmn.form = f if f
end
# For switching out, including due to fainting, and for the end of battle
def pbOnLeavingBattle(battle,pkmn,usedInBattle,endBattle=false)
return if !pkmn
f = MultipleForms.call("getFormOnLeavingBattle",pkmn,battle,usedInBattle,endBattle)
pkmn.form = f if f && pkmn.form!=f
pkmn.hp = pkmn.totalhp if pkmn.hp>pkmn.totalhp
end
end
@@ -863,8 +863,10 @@ BattleHandlers::DamageCalcTargetItem.add(:EVIOLITE,
# means it also cares about the Pokémon's form. Some forms cannot
# evolve even if the species generally can, and such forms are not
# affected by Eviolite.
evos = EvolutionHelper.evolutions(target.pokemon.fSpecies, true)
mults[DEF_MULT] *= 1.5 if evos && evos.length>0
evos = target.pokemon.species_data.evolutions
if evos.any? { |e| e[1] != PBEvolution::None && !e[3] } # Not a "None", not a prevolution
mults[DEF_MULT] *= 1.5 if evos && evos.length > 0
end
}
)
@@ -143,10 +143,10 @@ BallHandlers::ModifyCatchRate.add(:QUICKBALL,proc { |ball,catchRate,battle,battl
})
BallHandlers::ModifyCatchRate.add(:FASTBALL,proc { |ball,catchRate,battle,battler,ultraBeast|
baseStats = pbGetSpeciesData(battler.species,battler.form,SpeciesData::BASE_STATS)
baseStats = battler.pokemon.baseStats
baseSpeed = baseStats[PBStats::SPEED]
catchRate *= 4 if baseSpeed>=100
next [catchRate,255].min
catchRate *= 4 if baseSpeed >= 100
next [catchRate, 255].min
})
BallHandlers::ModifyCatchRate.add(:LEVELBALL,proc { |ball,catchRate,battle,battler,ultraBeast|
@@ -241,11 +241,11 @@ def pbWildBattleCore(*args)
if arg.is_a?(Pokemon)
foeParty.push(arg)
elsif arg.is_a?(Array)
species = getID(PBSpecies,arg[0])
species = GameData::Species.get(arg[0]).id
pkmn = pbGenerateWildPokemon(species,arg[1])
foeParty.push(pkmn)
elsif sp
species = getID(PBSpecies,sp)
species = GameData::Species.get(sp).id
pkmn = pbGenerateWildPokemon(species,arg)
foeParty.push(pkmn)
sp = nil
@@ -307,7 +307,7 @@ end
#===============================================================================
# Used when walking in tall grass, hence the additional code.
def pbWildBattle(species, level, outcomeVar=1, canRun=true, canLose=false)
species = getID(PBSpecies,species)
species = GameData::Species.get(species).id
# Potentially call a different pbWildBattle-type method instead (for roaming
# Pokémon, Safari battles, Bug Contest battles)
handled = [nil]
@@ -605,7 +605,7 @@ def pbEvolutionCheck(currentLevels)
next if !pkmn || (pkmn.hp==0 && !NEWEST_BATTLE_MECHANICS)
next if currentLevels[i] && pkmn.level==currentLevels[i]
newSpecies = pbCheckEvolution(pkmn)
next if newSpecies<=0
next if !newSpecies
evo = PokemonEvolutionScene.new
evo.pbStartScreen(pkmn,newSpecies)
evo.pbEvolution
@@ -251,11 +251,11 @@ class PokemonEncounters
if favoredType
newEncList = []
newChances = []
speciesData = pbLoadSpeciesData
for i in 0...encList.length
t1 = speciesData[encList[i][0]][SpeciesData::TYPE1]
t2 = speciesData[encList[i][0]][SpeciesData::TYPE2]
next if t1!=favoredType && (!t2 || t2!=favoredType)
speciesData = GameData::Species.get(encList[i][0])
t1 = speciesData.type1
t2 = speciesData.type2
next if t1 != favoredType && (!t2 || t2 != favoredType)
newEncList.push(encList[i])
newChances.push(chances[i])
end
@@ -26,7 +26,7 @@ end
# Gets the roaming areas for a particular Pokémon.
def pbRoamingAreas(idxRoamer)
# [species symbol, level, Game Switch, encounter type, battle BGM, area maps hash]
# [species ID, level, Game Switch, encounter type, battle BGM, area maps hash]
roamData = ROAMING_SPECIES[idxRoamer]
return roamData[5] if roamData && roamData[5]
return ROAMING_AREAS
@@ -46,8 +46,7 @@ def pbRoamPokemon
if !$PokemonGlobal.roamPosition
$PokemonGlobal.roamPosition = {}
for i in 0...ROAMING_SPECIES.length
species = getID(PBSpecies,ROAMING_SPECIES[i][0])
next if !species || species<=0
next if !GameData::Species.exists?(i[0])
keys = pbRoamingAreas(i).keys
$PokemonGlobal.roamPosition[i] = keys[rand(keys.length)]
end
@@ -61,12 +60,10 @@ end
# Makes a single roaming Pokémon roam to another map. Doesn't roam if it isn't
# currently possible to encounter it (i.e. its Game Switch is off).
def pbRoamPokemonOne(idxRoamer)
# [species symbol, level, Game Switch, encounter type, battle BGM, area maps hash]
# [species ID, level, Game Switch, encounter type, battle BGM, area maps hash]
roamData = ROAMING_SPECIES[idxRoamer]
return if roamData[2]>0 && !$game_switches[roamData[2]] # Game Switch is off
# Ensure species is a number rather than a string/symbol
species = getID(PBSpecies,roamData[0])
return if !species || species<=0
return if !GameData::Species.exists?(roamData[0])
# Get hash of area patrolled by the roaming Pokémon
mapIDs = pbRoamingAreas(idxRoamer).keys
return if !mapIDs || mapIDs.length==0 # No roaming area defined somehow
@@ -163,13 +160,11 @@ EncounterModifier.register(proc { |encounter|
# encounter it
roamerChoices = []
for i in 0...ROAMING_SPECIES.length
# [species symbol, level, Game Switch, encounter type, battle BGM, area maps hash]
# [species ID, level, Game Switch, encounter type, battle BGM, area maps hash]
roamData = ROAMING_SPECIES[i]
next if roamData[2]>0 && !$game_switches[roamData[2]] # Game Switch is off
next if $PokemonGlobal.roamPokemon[i]==true # Roaming Pokémon has been caught
# Ensure species is a number rather than a string/symbol
species = getID(PBSpecies,roamData[0])
next if !species || species<=0
next if !GameData::Species.exists?(roamData[0])
# Get the roaming Pokémon's current map
roamerMap = $PokemonGlobal.roamPosition[i]
if !roamerMap
@@ -191,7 +186,7 @@ EncounterModifier.register(proc { |encounter|
# Check whether the roaming Pokémon's category of encounter is currently possible
next if !pbRoamingMethodAllowed(roamData[3])
# Add this roaming Pokémon to the list of possible roaming Pokémon to encounter
roamerChoices.push([i,species,roamData[1],roamData[4]])
roamerChoices.push([i,roamData[0],roamData[1],roamData[4]])
end
# No encounterable roaming Pokémon were found, just have the regular encounter
next encounter if roamerChoices.length==0
@@ -119,7 +119,7 @@ def pbHiddenMoveAnimation(pokemon)
sprite.visible=true
if ptinterp.done?
phase=3
pbPlayCry(pokemon)
GameData::Species.play_cry_from_pokemon(pokemon)
frames=0
end
when 3 # Wait
@@ -105,14 +105,10 @@ end
# Check compatibility of Pokémon in the Day Care.
#===============================================================================
def pbIsDitto?(pkmn)
compat = pbGetSpeciesData(pkmn.species,pkmn.form,SpeciesData::COMPATIBILITY)
if compat.is_a?(Array)
return compat.include?(getConst(PBEggGroups,:Ditto))
end
return compat && isConst?(compat,PBEggGroups,:Ditto)
return pkmn.species_data.egg_groups.include?(PBEggGroups::Ditto)
end
def pbDayCareCompatibleGender(pkmn1,pkmn2)
def pbDayCareCompatibleGender(pkmn1, pkmn2)
return true if pkmn1.female? && pkmn2.male?
return true if pkmn1.male? && pkmn2.female?
ditto1 = pbIsDitto?(pkmn1)
@@ -123,44 +119,28 @@ def pbDayCareCompatibleGender(pkmn1,pkmn2)
end
def pbDayCareGetCompat
return 0 if pbDayCareDeposited!=2
return 0 if pbDayCareDeposited != 2
pkmn1 = $PokemonGlobal.daycare[0][0]
pkmn2 = $PokemonGlobal.daycare[1][0]
return 0 if pkmn1.shadowPokemon?
return 0 if pkmn2.shadowPokemon?
# Insert code here if certain forms of certain species cannot breed
compat1 = pbGetSpeciesData(pkmn1.species,pkmn1.form,SpeciesData::COMPATIBILITY)
if compat1.is_a?(Array)
compat10 = compat1[0] || 0
compat11 = compat1[1] || compat10
else
compat10 = compat11 = compat || 0
end
compat2 = pbGetSpeciesData(pkmn2.species,pkmn2.form,SpeciesData::COMPATIBILITY)
if compat2.is_a?(Array)
compat20 = compat2[0] || 0
compat21 = compat2[1] || compat20
else
compat20 = compat21 = compat || 0
end
return 0 if isConst?(compat10,PBEggGroups,:Undiscovered) ||
isConst?(compat11,PBEggGroups,:Undiscovered) ||
isConst?(compat20,PBEggGroups,:Undiscovered) ||
isConst?(compat21,PBEggGroups,:Undiscovered)
if compat10==compat20 || compat11==compat20 ||
compat10==compat21 || compat11==compat21 ||
isConst?(compat10,PBEggGroups,:Ditto) ||
isConst?(compat11,PBEggGroups,:Ditto) ||
isConst?(compat20,PBEggGroups,:Ditto) ||
isConst?(compat21,PBEggGroups,:Ditto)
if pbDayCareCompatibleGender(pkmn1,pkmn2)
ret = 1
ret += 1 if pkmn1.species == pkmn2.species
ret += 1 if pkmn1.owner.id != pkmn2.owner.id
return ret
end
end
return 0
# Shadow Pokémon cannot breed
return 0 if pkmn1.shadowPokemon? || pkmn2.shadowPokemon?
# Pokémon in the Undiscovered egg group cannot breed
egg_groups1 = pkmn1.species_data.egg_groups
egg_groups2 = pkmn2.species_data.egg_groups
return 0 if egg_groups1.include?(PBEggGroups::Undiscovered) ||
egg_groups2.include?(PBEggGroups::Undiscovered)
# Pokémon that don't share an egg group (and neither is in the Ditto group)
# cannot breed
return 0 if !egg_groups1.include?(PBEggGroups::Ditto) &&
!egg_groups2.include?(PBEggGroups::Ditto) &&
(egg_groups1 & egg_groups2).length == 0
# Pokémon with incompatible genders cannot breed
return 0 if !pbDayCareCompatibleGender(pkmn1, pkmn2)
# Pokémon can breed; calculate a compatibility factor
ret = 1
ret += 1 if pkmn1.species == pkmn2.species
ret += 1 if pkmn1.owner.id != pkmn2.owner.id
return ret
end
def pbDayCareGetCompatibility(variable)
@@ -173,36 +153,37 @@ end
# Generate an Egg based on Pokémon in the Day Care.
#===============================================================================
def pbDayCareGenerateEgg
return if pbDayCareDeposited!=2
raise _INTL("Can't store the egg") if $Trainer.party.length>=6
pokemon0 = $PokemonGlobal.daycare[0][0]
pokemon1 = $PokemonGlobal.daycare[1][0]
return if pbDayCareDeposited != 2
raise _INTL("Can't store the egg.") if $Trainer.party.length >= 6
pkmn0 = $PokemonGlobal.daycare[0][0]
pkmn1 = $PokemonGlobal.daycare[1][0]
mother = nil
father = nil
babyspecies = 0
ditto0 = pbIsDitto?(pokemon0)
ditto1 = pbIsDitto?(pokemon1)
if pokemon0.female? || ditto0
babyspecies = (ditto0) ? pokemon1.species : pokemon0.species
mother = pokemon0
father = pokemon1
babyspecies = nil
ditto0 = pbIsDitto?(pkmn0)
ditto1 = pbIsDitto?(pkmn1)
if pkmn0.female? || ditto0
mother = pkmn0
father = pkmn1
babyspecies = (ditto0) ? father.species : mother.species
else
babyspecies = (ditto1) ? pokemon0.species : pokemon1.species
mother = pokemon1
father = pokemon0
mother = pkmn1
father = pkmn0
babyspecies = (ditto1) ? father.species : mother.species
end
# Determine the egg's species
babyspecies = EvolutionHelper.baby_species(babyspecies, true, mother.item_id, father.item_id)
if isConst?(babyspecies,PBSpecies,:MANAPHY) && hasConst?(PBSpecies,:PHIONE)
babyspecies = getConst(PBSpecies,:PHIONE)
elsif (isConst?(babyspecies,PBSpecies,:NIDORANfE) && hasConst?(PBSpecies,:NIDORANmA)) ||
(isConst?(babyspecies,PBSpecies,:NIDORANmA) && hasConst?(PBSpecies,:NIDORANfE))
babyspecies = [getConst(PBSpecies,:NIDORANmA),
getConst(PBSpecies,:NIDORANfE)][rand(2)]
elsif (isConst?(babyspecies,PBSpecies,:VOLBEAT) && hasConst?(PBSpecies,:ILLUMISE)) ||
(isConst?(babyspecies,PBSpecies,:ILLUMISE) && hasConst?(PBSpecies,:VOLBEAT))
babyspecies = [getConst(PBSpecies,:VOLBEAT),
getConst(PBSpecies,:ILLUMISE)][rand(2)]
case babyspecies
when :MANAPHY
babyspecies = :PHIONE if GameData::Species.exists?(:PHIONE)
when :NIDORANfE, :NIDORANmA
if GameData::Species.exists?(:NIDORANfE) && GameData::Species.exists?(:NIDORANmA)
babyspecies = [:NIDORANfE, :NIDORANmA][rand(2)]
end
when :VOLBEAT, :ILLUMISE
if GameData::Species.exists?(:VOLBEAT) && GameData::Species.exists?(:ILLUMISE)
babyspecies = [:VOLBEAT, :ILLUMISE][rand(2)]
end
end
# Generate egg
egg = Pokemon.new(babyspecies,EGG_LEVEL)
@@ -211,26 +192,13 @@ def pbDayCareGenerateEgg
pid |= (rand(65536)<<16)
egg.personalID = pid
# Inheriting form
if isConst?(babyspecies,PBSpecies,:BURMY) ||
isConst?(babyspecies,PBSpecies,:SHELLOS) ||
isConst?(babyspecies,PBSpecies,:BASCULIN) ||
isConst?(babyspecies,PBSpecies,:FLABEBE) ||
isConst?(babyspecies,PBSpecies,:PUMPKABOO) ||
isConst?(babyspecies,PBSpecies,:ORICORIO) ||
isConst?(babyspecies,PBSpecies,:ROCKRUFF) ||
isConst?(babyspecies,PBSpecies,:MINIOR)
if [:BURMY, :SHELLOS, :BASCULIN, :FLABEBE, :PUMPKABOO, :ORICORIO, :ROCKRUFF, :MINIOR].include?(babyspecies)
newForm = mother.form
newForm = 0 if mother.isSpecies?(:MOTHIM)
egg.form = newForm
end
# Inheriting Alolan form
if isConst?(babyspecies,PBSpecies,:RATTATA) ||
isConst?(babyspecies,PBSpecies,:SANDSHREW) ||
isConst?(babyspecies,PBSpecies,:VULPIX) ||
isConst?(babyspecies,PBSpecies,:DIGLETT) ||
isConst?(babyspecies,PBSpecies,:MEOWTH) ||
isConst?(babyspecies,PBSpecies,:GEODUDE) ||
isConst?(babyspecies,PBSpecies,:GRIMER)
if [:RATTATA, :SANDSHREW, :VULPIX, :DIGLETT, :MEOWTH, :GEODUDE, :GRIMER].include?(babyspecies)
if mother.form==1
egg.form = 1 if mother.hasItem?(:EVERSTONE)
elsif EvolutionHelper.baby_species(father.species, true, mother.item_id, father.item_id) == babyspecies
@@ -240,17 +208,18 @@ def pbDayCareGenerateEgg
# Inheriting Moves
moves = []
othermoves = []
movefather = father; movemother = mother
movefather = father
movemother = mother
if pbIsDitto?(movefather) && !mother.female?
movefather = mother; movemother = father
movefather = mother
movemother = father
end
# Initial Moves
initialmoves = egg.getMoveList
for k in initialmoves
if k[0]<=EGG_LEVEL
moves.push(k[1])
else
next if !mother.hasMove?(k[1]) || !father.hasMove?(k[1])
elsif mother.hasMove?(k[1]) && father.hasMove?(k[1])
othermoves.push(k[1])
end
end
@@ -269,7 +238,7 @@ def pbDayCareGenerateEgg
end
end
# Inheriting Egg Moves
babyEggMoves = pbGetSpeciesEggMoves(egg.species,egg.form)
babyEggMoves = egg.species_data.egg_moves
if movefather.male?
babyEggMoves.each { |m| moves.push(m) if movefather.hasMove?(m) }
end
@@ -286,7 +255,7 @@ def pbDayCareGenerateEgg
mother.hasItem?(:LIGHTBALL)
lightball = true
end
if lightball && isConst?(babyspecies,PBSpecies,:PICHU) && GameData::Move.exists?(:VOLTTACKLE)
if lightball && babyspecies == :PICHU && GameData::Move.exists?(:VOLTTACKLE)
moves.push(:VOLTTACKLE)
end
moves = moves.reverse
@@ -378,18 +347,12 @@ def pbDayCareGenerateEgg
end
# Set all stats
egg.happiness = 120
egg.iv[0] = ivs[0]
egg.iv[1] = ivs[1]
egg.iv[2] = ivs[2]
egg.iv[3] = ivs[3]
egg.iv[4] = ivs[4]
egg.iv[5] = ivs[5]
egg.iv = ivs
egg.moves = finalmoves
egg.calcStats
egg.obtainText = _INTL("Day-Care Couple")
egg.name = _INTL("Egg")
eggSteps = pbGetSpeciesData(babyspecies,egg.form,SpeciesData::STEPS_TO_HATCH)
egg.eggsteps = eggSteps
egg.eggsteps = egg.species_data.hatch_steps
egg.givePokerus if rand(65536)<POKERUS_CHANCE
# Add egg to party
$Trainer.party[$Trainer.party.length] = egg
@@ -153,14 +153,9 @@ class PokeBattle_Trainer
def pokedexSeen(region = -1) # Number of Pokémon seen
ret = 0
if region == -1
for i in 1..PBSpecies.maxValue
ret += 1 if @seen[i]
end
GameData::Species.each { |s| ret += 1 if s.form == 0 && @seen[s.species] }
else
regionlist = pbAllRegionalSpecies(region)
for i in regionlist
ret += 1 if i > 0 && @seen[i]
end
pbAllRegionalSpecies(region).each { |s| ret += 1 if s && @seen[s] }
end
return ret
end
@@ -168,22 +163,19 @@ class PokeBattle_Trainer
def pokedexOwned(region = -1) # Number of Pokémon owned
ret = 0
if region == -1
for i in 0..PBSpecies.maxValue
ret += 1 if @owned[i]
end
GameData::Species.each { |s| ret += 1 if s.form == 0 && @owned[s.species] }
else
regionlist = pbAllRegionalSpecies(region)
for i in regionlist
ret += 1 if @owned[i]
end
pbAllRegionalSpecies(region).each { |s| ret += 1 if s && @owned[s] }
end
return ret
end
def numFormsSeen(species)
species = getID(PBSpecies, species)
return 0 if species <= 0
species_data = GameData::Species.try_get(species)
return 0 if !species_data
species = species_data.species
ret = 0
@formseen[species] = [[], []] if !@formseen[species]
array = @formseen[species]
for i in 0...[array[0].length, array[1].length].max
ret += 1 if array[0][i] || array[1][i]
@@ -192,38 +184,32 @@ class PokeBattle_Trainer
end
def seen?(species)
species = getID(PBSpecies, species)
return species > 0 ? @seen[species] : false
species_data = GameData::Species.try_get(species)
return (species_data) ? @seen[species_data.species] : false
end
alias hasSeen? seen?
def owned?(species)
species = getID(PBSpecies, species)
return species > 0 ? @owned[species] : false
species_data = GameData::Species.try_get(species)
return (species_data) ? @owned[species_data.species] : false
end
alias hasOwned? owned?
def setSeen(species)
species = getID(PBSpecies, species)
@seen[species] = true if species > 0
species_data = GameData::Species.try_get(species)
@seen[species_data.species] = true if species_data
end
def setOwned(species)
species = getID(PBSpecies, species)
@owned[species] = true if species > 0
species_data = GameData::Species.try_get(species)
@owned[species_data.species] = true if species_data
end
def clearPokedex
@seen = []
@owned = []
@formseen = []
@formlastseen = []
for i in 1..PBSpecies.maxValue
@seen[i] = false
@owned[i] = false
@formlastseen[i] = []
@formseen[i] = [[], []]
end
@seen = {}
@owned = {}
@formseen = {}
@formlastseen = {}
end
#=============================================================================
@@ -239,10 +225,7 @@ class PokeBattle_Trainer
@pokegear = false
@pokedex = false
clearPokedex
@shadowcaught = []
for i in 1..PBSpecies.maxValue
@shadowcaught[i] = false
end
@shadowcaught = {}
@badges = []
for i in 0...8
@badges[i] = false
@@ -22,7 +22,7 @@ module TrainerData
SCHEMA = {
"Items" => [0, "eEEEEEEE", :Item, :Item, :Item, :Item,
:Item, :Item, :Item, :Item],
"Pokemon" => [SPECIES, "ev", :PBSpecies, nil], # Species, level
"Pokemon" => [SPECIES, "ev", :Species, nil], # Species, level
"Item" => [ITEM, "e", :Item],
"Moves" => [MOVES, "eEEE", :Move, :Move, :Move, :Move],
"Ability" => [ABILITY, "u"],
@@ -69,7 +69,7 @@ def pbLoadTrainer(tr_type, tr_name, tr_id = 0)
opponent.setForeignID($Trainer)
# Load up each Pokémon in the trainer's party
for poke in trainer[3]
species = pbGetSpeciesFromFSpecies(poke[TrainerData::SPECIES])[0]
species = GameData::Species.get(poke[TrainerData::SPECIES]).species
level = poke[TrainerData::LEVEL]
pokemon = Pokemon.new(species,level,opponent,false)
if poke[TrainerData::FORM]
@@ -84,14 +84,15 @@ def pbLoadTrainer(tr_type, tr_name, tr_id = 0)
else
pokemon.resetMoves
end
pokemon.setAbility(poke[TrainerData::ABILITY] || 0)
pokemon.setAbility(poke[TrainerData::ABILITY])
g = (poke[TrainerData::GENDER]) ? poke[TrainerData::GENDER] : (opponent.female?) ? 1 : 0
pokemon.setGender(g)
(poke[TrainerData::SHINY]) ? pokemon.makeShiny : pokemon.makeNotShiny
if poke[TrainerData::NATURE]
n = poke[TrainerData::NATURE]
else
n = (pokemon.species + GameData::TrainerType.get(opponent.trainertype).id_number) % (PBNatures.maxValue + 1)
n = pokemon.species_data.id_number + GameData::TrainerType.get(opponent.trainertype).id_number
n = n % (PBNatures.maxValue + 1)
end
pokemon.setNature(n)
for i in 0...6
@@ -143,17 +144,17 @@ def pbNewTrainer(tr_type, tr_name, tr_id, savechanges = true)
end
loop do
species = pbChooseSpeciesList
if species<=0
break if i>0
pbMessage(_INTL("This trainer must have at least 1 Pokémon!"))
else
if species
params = ChooseNumberParams.new
params.setRange(1,PBExperience.maxLevel)
params.setDefaultValue(10)
level = pbMessageChooseNumber(_INTL("Set the level for {1} (max. #{PBExperience.maxLevel}).",
PBSpecies.getName(species)),params)
GameData::Species.get(species).name),params)
pokemon.push([species,level])
break
else
break if i>0
pbMessage(_INTL("This trainer must have at least 1 Pokémon!"))
end
end
end
+2 -9
View File
@@ -178,7 +178,7 @@ def pbChangeLevel(pkmn,newlevel,scene)
end
# Check for evolution
newspecies = pbCheckEvolution(pkmn)
if newspecies>0
if newspecies
pbFadeOutInWithMusic {
evo = PokemonEvolutionScene.new
evo.pbStartScreen(pkmn,newspecies)
@@ -458,13 +458,6 @@ def pbForgetMove(pkmn,moveToLearn)
return ret
end
def pbSpeciesCompatible?(species,move)
return false if species<=0
data = pbLoadSpeciesTMData
return false if !data[move]
return data[move].any? { |item| item==species }
end
#===============================================================================
# Use an item from the Bag and/or on a Pokémon
#===============================================================================
@@ -498,7 +491,7 @@ def pbUseItem(bag,item,bagscene=nil)
if itm.is_evolution_stone?
annot = []
for pkmn in $Trainer.party
elig = pbCheckEvolution(pkmn,item)>0
elig = pbCheckEvolution(pkmn,item)
annot.push((elig) ? _INTL("ABLE") : _INTL("NOT ABLE"))
end
end
@@ -349,22 +349,21 @@ ItemHandlers::UseOnPokemon.addIf(proc { |item| GameData::Item.get(item).is_evolu
next false
end
newspecies = pbCheckEvolution(pkmn,item)
if newspecies<=0
scene.pbDisplay(_INTL("It won't have any effect."))
next false
else
if newspecies
pbFadeOutInWithMusic {
evo = PokemonEvolutionScene.new
evo.pbStartScreen(pkmn,newspecies)
evo.pbEvolution(false)
evo.pbEndScreen
if scene.is_a?(PokemonPartyScreen)
scene.pbRefreshAnnotations(proc { |p| pbCheckEvolution(p,item)>0 })
scene.pbRefreshAnnotations(proc { |p| !pbCheckEvolution(p,item).nil? })
scene.pbRefresh
end
}
next true
end
scene.pbDisplay(_INTL("It won't have any effect."))
next false
}
)
+2 -2
View File
@@ -260,7 +260,7 @@ def pbEncounterSpecies(phonenum)
species = pbRandomEncounterSpecies(enctypes[EncounterTypes::LandNight]) if species==0
species = pbRandomEncounterSpecies(enctypes[EncounterTypes::Water]) if species==0
return "" if species==0
return PBSpecies.getName(species)
return GameData::Species.get(species).name
end
def pbTrainerSpecies(phonenum)
@@ -269,7 +269,7 @@ def pbTrainerSpecies(phonenum)
trainer = pbGetTrainerData(phonenum[1],phonenum[2],partyid)
return "" if !trainer || trainer[3].length==0
rndpoke = trainer[3][rand(trainer[3].length)]
return PBSpecies.getName(rndpoke[0])
return GameData::Species.get(rndpoke[0]).name
end
def pbTrainerMapName(phonenum)
@@ -128,7 +128,7 @@ def pbPokeRadarGetEncounter(rarity=0)
map = $game_map.map_id rescue 0
array = []
for enc in POKE_RADAR_ENCOUNTERS
array.push(enc) if enc.length>=4 && enc[0]==map && getID(PBSpecies,enc[2])>0
array.push(enc) if enc.length>=4 && enc[0]==map && GameData::Species.exists?(enc[2])
end
# If there are any exclusives, first have a chance of encountering those
if array.length>0
@@ -137,9 +137,8 @@ def pbPokeRadarGetEncounter(rarity=0)
for enc in array
chance += enc[1]
if rnd<chance
upper = (enc[4]!=nil) ? enc[4] : enc[3]
level = enc[3]+rand(1+upper-enc[3])
return [getID(PBSpecies,enc[2]),level]
level = (enc[4] && enc[4] > enc[3]) ? rand(enc[3], enc[4]) : enc[3]
return [enc[2], level]
end
end
end
+6 -3
View File
@@ -42,19 +42,22 @@ def pbDisplayMail(mail,_bearer=nil)
if GameData::Item.get(mail.item).is_icon_mail?
if mail.poke1
sprites["bearer"] = IconSprite.new(64,288,viewport)
bitmapFileName = pbCheckPokemonIconFiles(mail.poke1,mail.poke1[5])
bitmapFileName = GameData::Species.icon_filename(mail.poke1[0],
mail.poke1[3], mail.poke1[1], mail.poke1[2], mail.poke1[4], mail.poke1[5])
sprites["bearer"].setBitmap(bitmapFileName)
sprites["bearer"].src_rect.set(0,0,64,64)
end
if mail.poke2
sprites["bearer2"] = IconSprite.new(144,288,viewport)
bitmapFileName = pbCheckPokemonIconFiles(mail.poke2,mail.poke2[5])
bitmapFileName = GameData::Species.icon_filename(mail.poke2[0],
mail.poke2[3], mail.poke2[1], mail.poke2[2], mail.poke2[4], mail.poke2[5])
sprites["bearer2"].setBitmap(bitmapFileName)
sprites["bearer2"].src_rect.set(0,0,64,64)
end
if mail.poke3
sprites["bearer3"] = IconSprite.new(224,288,viewport)
bitmapFileName = pbCheckPokemonIconFiles(mail.poke3,mail.poke3[5])
bitmapFileName = GameData::Species.icon_filename(mail.poke3[0],
mail.poke3[3], mail.poke3[1], mail.poke3[2], mail.poke3[4], mail.poke3[5])
sprites["bearer3"].setBitmap(bitmapFileName)
sprites["bearer3"].src_rect.set(0,0,64,64)
end
+284 -260
View File
@@ -7,6 +7,13 @@ class Pokemon
attr_accessor :name
# @return [Integer] this Pokémon's national Pokédex number
attr_reader :species
# If defined, is the time (in Integer form) when this Pokémon's form was set.
# @return [Integer, nil] the time this Pokémon's form was set
attr_accessor :formTime
# If defined, this Pokémon's form will be this value even if a MultipleForms
# handler tries to say otherwise.
# @return [Integer, nil] this Pokémon's form
attr_accessor :forcedForm
# @return [Integer] the current experience points
attr_reader :exp
# @return [Integer] the current HP
@@ -196,12 +203,12 @@ class Pokemon
# @return [Integer] this Pokémon's growth rate (from PBGrowthRates)
def growthrate
return pbGetSpeciesData(@species, formSimple, SpeciesData::GROWTH_RATE)
return species_data.growth_rate
end
# @return [Integer] this Pokémon's base Experience value
def baseExp
return pbGetSpeciesData(@species, formSimple, SpeciesData::BASE_EXP)
return species_data.base_exp
end
# @return [Float] a number between 0 and 1 indicating how much of the current level's
@@ -221,8 +228,8 @@ class Pokemon
# @return [0, 1, 2] this Pokémon's gender (0 = male, 1 = female, 2 = genderless)
def gender
gender_rate = species_data.gender_rate
# Return sole gender option for all male/all female/genderless species
gender_rate = pbGetSpeciesData(@species, formSimple, SpeciesData::GENDER_RATE)
case gender_rate
when PBGenderRates::AlwaysMale then return 0
when PBGenderRates::AlwaysFemale then return 1
@@ -236,7 +243,7 @@ class Pokemon
# @return [Boolean] whether this Pokémon species is restricted to only ever being one
# gender (or genderless)
def singleGendered?
gender_rate = pbGetSpeciesData(@species, formSimple, SpeciesData::GENDER_RATE)
gender_rate = species_data.gender_rate
return gender_rate == PBGenderRates::AlwaysMale ||
gender_rate == PBGenderRates::AlwaysFemale ||
gender_rate == PBGenderRates::Genderless
@@ -272,122 +279,6 @@ class Pokemon
# Makes this Pokémon female.
def makeFemale; setGender(1); end
#=============================================================================
# Ability
#=============================================================================
# @return [Integer] the index of this Pokémon's ability
def abilityIndex
return @abilityflag || (@personalID & 1)
end
# @return [GameData::Ability, nil] an Ability object corresponding to this Pokémon's ability
def ability
ret = ability_id
return GameData::Ability.try_get(ret)
end
# @return [Symbol, nil] the ability symbol of this Pokémon's ability
def ability_id
abilIndex = abilityIndex
# Hidden ability
if abilIndex >= 2
hiddenAbil = pbGetSpeciesData(@species, formSimple, SpeciesData::HIDDEN_ABILITY)
if hiddenAbil.is_a?(Array)
ret = hiddenAbil[abilIndex - 2]
return ret if GameData::Ability.exists?(ret)
elsif abilIndex == 2
return hiddenAbil if GameData::Ability.exists?(hiddenAbil)
end
abilIndex = (@personalID & 1)
end
# Natural ability
abilities = pbGetSpeciesData(@species, formSimple, SpeciesData::ABILITIES)
if abilities.is_a?(Array)
ret = abilities[abilIndex]
ret = abilities[(abilIndex + 1) % 2] if !GameData::Ability.exists?(ret)
return ret
end
return abilities
end
# Returns whether this Pokémon has a particular ability. If no value
# is given, returns whether this Pokémon has an ability set.
# @param check_ability [Symbol, GameData::Ability, Integer] ability ID to check
# @return [Boolean] whether this Pokémon has a particular ability or
# an ability at all
def hasAbility?(check_ability = nil)
current_ability = self.ability
return !current_ability.nil? if check_ability.nil?
return current_ability == check_ability
end
# Sets this Pokémon's ability index.
# @param value [Integer] new ability index
def setAbility(value)
@abilityflag = value
end
# @return [Boolean] whether this Pokémon has a hidden ability
def hasHiddenAbility?
abil = abilityIndex
return abil >= 2
end
# @return [Array<Array<Integer>>] the list of abilities this Pokémon can have,
# where every element is [ability ID, ability index]
def getAbilityList
ret = []
abilities = pbGetSpeciesData(@species, formSimple, SpeciesData::ABILITIES)
if abilities.is_a?(Array)
abilities.each_with_index { |a, i| ret.push([a, i]) if a }
else
ret.push([abilities, 0]) if abilities > 0
end
hiddenAbil = pbGetSpeciesData(@species, formSimple, SpeciesData::HIDDEN_ABILITY)
if hiddenAbil.is_a?(Array)
hiddenAbil.each_with_index { |a, i| ret.push([a, i + 2]) if a }
else
ret.push([hiddenAbil, 2]) if hiddenAbil > 0
end
return ret
end
#=============================================================================
# Nature
#=============================================================================
# @return [Integer] the ID of this Pokémon's nature
def nature
return @natureflag || (@personalID % 25)
end
# Returns the calculated nature, taking into account things that change its
# stat-altering effect (i.e. Gen 8 mints). Only used for calculating stats.
# @return [Integer] this Pokémon's calculated nature
def calcNature
return @natureOverride if @natureOverride
return self.nature
end
# Returns whether this Pokémon has a particular nature. If no value
# is given, returns whether this Pokémon has a nature set.
# @param nature [Integer] nature ID to check
# @return [Boolean] whether this Pokémon has a particular nature or
# a nature at all
def hasNature?(nature = -1)
current_nature = self.nature
return current_nature >= 0 if nature < 0
return current_nature == getID(PBNatures, nature)
end
# Sets this Pokémon's nature to a particular nature.
# @param value [Integer, String, Symbol] nature to change to
def setNature(value)
@natureflag = getID(PBNatures, value)
calcStats
end
#=============================================================================
# Shininess
#=============================================================================
@@ -413,71 +304,26 @@ class Pokemon
@shinyflag = false
end
#=============================================================================
# Pokérus
#=============================================================================
# @return [Integer] the Pokérus infection stage for this Pokémon
def pokerusStrain
return @pokerus / 16
end
# Returns the Pokérus infection stage for this Pokémon. The possible stages are
# 0 (not infected), 1 (infected) and 2 (cured)
# @return [0, 1, 2] current Pokérus infection stage
def pokerusStage
return 0 if !@pokerus || @pokerus == 0
return 2 if @pokerus > 0 && (@pokerus % 16) == 0
return 1
end
# Gives this Pokémon Pokérus (either the specified strain or a random one).
# @param strain [Integer] Pokérus strain to give
def givePokerus(strain = 0)
return if self.pokerusStage == 2 # Can't re-infect a cured Pokémon
strain = 1 + rand(15) if strain <= 0 || strain >= 16
time = 1 + (strain % 4)
@pokerus = time
@pokerus |= strain << 4
end
# Resets the infection time for this Pokémon's Pokérus (even if cured).
def resetPokerusTime
return if @pokerus == 0
strain = @pokerus % 16
time = 1 + (strain % 4)
@pokerus = time
@pokerus |= strain << 4
end
# Reduces the time remaining for this Pokémon's Pokérus (if infected).
def lowerPokerusCount
return if self.pokerusStage != 1
@pokerus -= 1
end
#=============================================================================
# Types
#=============================================================================
# @return [Integer] this Pokémon's first type
def type1
return pbGetSpeciesData(@species, formSimple, SpeciesData::TYPE1)
return species_data.type1
end
# @return [Integer] this Pokémon's second type, or the first type if none is defined
def type2
ret = pbGetSpeciesData(@species, formSimple, SpeciesData::TYPE2)
ret = pbGetSpeciesData(@species, formSimple, SpeciesData::TYPE1) if !ret
return ret
sp_data = species_data
return sp_data.type2 || sp_data.type1
end
# @return [Array<Integer>] an array of this Pokémon's types
def types
ret1 = pbGetSpeciesData(@species, formSimple, SpeciesData::TYPE1)
ret2 = pbGetSpeciesData(@species, formSimple, SpeciesData::TYPE2)
ret = [ret1]
ret.push(ret2) if ret2 && ret2 != ret1
sp_data = species_data
ret = [sp_data.type1]
ret.push(sp_data.type2) if sp_data.type2 && sp_data.type2 != sp_data.type1
return ret
end
@@ -488,6 +334,69 @@ class Pokemon
return self.types.include?(type)
end
#=============================================================================
# Ability
#=============================================================================
# @return [Integer] the index of this Pokémon's ability
def abilityIndex
return @abilityflag || (@personalID & 1)
end
# @return [GameData::Ability, nil] an Ability object corresponding to this Pokémon's ability
def ability
ret = ability_id
return GameData::Ability.try_get(ret)
end
# @return [Symbol, nil] the ability symbol of this Pokémon's ability
def ability_id
sp_data = species_data
abil_index = abilityIndex
# Hidden ability
if abil_index >= 2
ret = sp_data.hidden_abilities[abil_index - 2]
return ret if ret
abil_index = (@personalID & 1)
end
# Natural ability
ret = sp_data.abilities[abil_index]
return ret || sp_data.abilities[0]
end
# Returns whether this Pokémon has a particular ability. If no value
# is given, returns whether this Pokémon has an ability set.
# @param check_ability [Symbol, GameData::Ability, Integer] ability ID to check
# @return [Boolean] whether this Pokémon has a particular ability or
# an ability at all
def hasAbility?(check_ability = nil)
current_ability = self.ability
return !current_ability.nil? if check_ability.nil?
return current_ability == check_ability
end
# Sets this Pokémon's ability index.
# @param value [Integer] new ability index
def setAbility(value)
@abilityflag = value
end
# @return [Boolean] whether this Pokémon has a hidden ability
def hasHiddenAbility?
abil = abilityIndex
return abil >= 2
end
# @return [Array<Array<Symbol,Integer>>] the abilities this Pokémon can have,
# where every element is [ability ID, ability index]
def getAbilityList
ret = []
sp_data = species_data
sp_data.abilities.each_with_index { |a, i| ret.push([a, i]) if a }
sp_data.hidden_abilities.each_with_index { |a, i| ret.push([a, i + 2]) if a }
return ret
end
#=============================================================================
# Moves
#=============================================================================
@@ -507,9 +416,9 @@ class Pokemon
alias knowsMove? hasMove?
# Returns the list of moves this Pokémon can learn by levelling up.
# @return [Array<Array<Integer>>] this Pokémon's move list, where every element is [level, move ID]
# @return [Array<Array<Integer,Symbol>>] this Pokémon's move list, where every element is [level, move ID]
def getMoveList
return pbGetSpeciesMoveset(@species, formSimple)
return species_data.moves
end
# Sets this Pokémon's movelist to the default movelist it originally had.
@@ -597,7 +506,138 @@ class Pokemon
# @param move [Integer, Symbol, String] ID of the move to check
# @return [Boolean] whether the Pokémon is compatible with the given move
def compatibleWithMove?(move_id)
return pbSpeciesCompatible?(self.fSpecies, move_id)
move_data = GameData::Move.try_get(move_id)
return move_data && species_data.tutor_moves.include?(move_data.id)
end
#=============================================================================
# Items
#=============================================================================
# @return [GameData::Item, nil] an Item object corresponding to this Pokémon's item
def item
ret = @item_id
return GameData::Item.try_get(ret)
end
# Returns whether this Pokémon is holding an item. If an item id is passed,
# returns whether the Pokémon is holding that item.
# @param check_item [Symbol, GameData::Item, Integer] item ID to check
# @return [Boolean] whether the Pokémon is holding the specified item or
# an item at all
def hasItem?(check_item = nil)
current_item = self.item
return !current_item.nil? if check_item.nil?
return current_item == check_item
end
# Gives an item to this Pokémon. Passing 0 as the argument removes the held item.
# @param value [Symbol, GameData::Item, Integer] id of the item to give to this
# Pokémon (a non-valid value sets it to nil)
def setItem(value)
new_item = GameData::Item.try_get(value)
@item_id = (new_item) ? new_item.id : nil
end
# @return [Array<Integer>] the items this species can be found holding in the wild
def wildHoldItems
sp_data = species_data
return [sp_data.wild_item_common, sp_data.wild_item_uncommon, sp_data.wild_item_rare]
end
# @return [PokemonMail, nil] mail held by this Pokémon (nil if there is none)
def mail
return nil if !@mail
@mail = nil if !@mail.item || !hasItem?(@mail.item)
return @mail
end
# If mail is a PokemonMail object, gives that mail to this Pokémon. If nil is given,
# removes the held mail.
# @param mail [PokemonMail, nil] mail to be held by this Pokémon (nil if mail is to be removed)
def mail=(mail)
if !mail.nil? && !mail.is_a?(PokemonMail)
raise ArgumentError, _INTL('Invalid value {1} given', mail.inspect)
end
@mail = mail
end
#=============================================================================
# Nature
#=============================================================================
# @return [Integer] the ID of this Pokémon's nature
def nature
return @natureflag || (@personalID % 25)
end
# Returns the calculated nature, taking into account things that change its
# stat-altering effect (i.e. Gen 8 mints). Only used for calculating stats.
# @return [Integer] this Pokémon's calculated nature
def calcNature
return @natureOverride if @natureOverride
return self.nature
end
# Returns whether this Pokémon has a particular nature. If no value
# is given, returns whether this Pokémon has a nature set.
# @param nature [Integer] nature ID to check
# @return [Boolean] whether this Pokémon has a particular nature or
# a nature at all
def hasNature?(nature = -1)
current_nature = self.nature
return current_nature >= 0 if nature < 0
return current_nature == getID(PBNatures, nature)
end
# Sets this Pokémon's nature to a particular nature.
# @param value [Integer, String, Symbol] nature to change to
def setNature(value)
@natureflag = getID(PBNatures, value)
calcStats
end
#=============================================================================
# Pokérus
#=============================================================================
# @return [Integer] the Pokérus infection stage for this Pokémon
def pokerusStrain
return @pokerus / 16
end
# Returns the Pokérus infection stage for this Pokémon. The possible stages are
# 0 (not infected), 1 (infected) and 2 (cured)
# @return [0, 1, 2] current Pokérus infection stage
def pokerusStage
return 0 if !@pokerus || @pokerus == 0
return 2 if @pokerus > 0 && (@pokerus % 16) == 0
return 1
end
# Gives this Pokémon Pokérus (either the specified strain or a random one).
# @param strain [Integer] Pokérus strain to give
def givePokerus(strain = 0)
return if self.pokerusStage == 2 # Can't re-infect a cured Pokémon
strain = 1 + rand(15) if strain <= 0 || strain >= 16
time = 1 + (strain % 4)
@pokerus = time
@pokerus |= strain << 4
end
# Resets the infection time for this Pokémon's Pokérus (even if cured).
def resetPokerusTime
return if @pokerus == 0
strain = @pokerus % 16
time = 1 + (strain % 4)
@pokerus = time
@pokerus |= strain << 4
end
# Reduces the time remaining for this Pokémon's Pokérus (if infected).
def lowerPokerusCount
return if self.pokerusStage != 1
@pokerus -= 1
end
#=============================================================================
@@ -625,7 +665,7 @@ class Pokemon
end
# @return [Integer] this Pokémon's tough contest attribute
def tough;
def tough
return @tough || 0
end
@@ -697,61 +737,6 @@ class Pokemon
@ribbons = []
end
#=============================================================================
# Items
#=============================================================================
# @return [GameData::Item, nil] an Item object corresponding to this Pokémon's item
def item
ret = @item_id
return GameData::Item.try_get(ret)
end
# Returns whether this Pokémon is holding an item. If an item id is passed,
# returns whether the Pokémon is holding that item.
# @param check_item [Symbol, GameData::Item, Integer] item ID to check
# @return [Boolean] whether the Pokémon is holding the specified item or
# an item at all
def hasItem?(check_item = nil)
current_item = self.item
return !current_item.nil? if check_item.nil?
return current_item == check_item
end
# Gives an item to this Pokémon. Passing 0 as the argument removes the held item.
# @param value [Symbol, GameData::Item, Integer] id of the item to give to this
# Pokémon (a non-valid value sets it to nil)
def setItem(value)
new_item = GameData::Item.try_get(value)
@item_id = (new_item) ? new_item.id : nil
end
# @return [Array<Integer>] the items this species can be found holding in the wild
def wildHoldItems
ret = []
ret.push(pbGetSpeciesData(@species, formSimple, SpeciesData::WILD_ITEM_COMMON))
ret.push(pbGetSpeciesData(@species, formSimple, SpeciesData::WILD_ITEM_UNCOMMON))
ret.push(pbGetSpeciesData(@species, formSimple, SpeciesData::WILD_ITEM_RARE))
return ret
end
# @return [PokemonMail, nil] mail held by this Pokémon (nil if there is none)
def mail
return nil if !@mail
@mail = nil if !@mail.item || !hasItem?(@mail.item)
return @mail
end
# If mail is a PokemonMail object, gives that mail to this Pokémon. If nil is given,
# removes the held mail.
# @param mail [PokemonMail, nil] mail to be held by this Pokémon (nil if mail is to be removed)
def mail=(mail)
if !mail.nil? && !mail.is_a?(PokemonMail)
raise ArgumentError, _INTL('Invalid value {1} given', mail.inspect)
end
@mail = mail
end
#=============================================================================
# Status
#=============================================================================
@@ -819,15 +804,17 @@ class Pokemon
end
#=============================================================================
# Other
# Species and form
#=============================================================================
# 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)
new_species_data = GameData::Species.get(species_id)
return if @species == new_species_data.species
has_nickname = nicknamed?
@species, new_form = pbGetSpeciesFromFSpecies(species_id)
@form = new_form if @species != value
@species = new_species_data.species
@form = new_species_data.form if new_species_data.form != 0
@name = speciesName unless has_nickname
@level = nil # In case growth rate is different for the new species
@forcedForm = nil
@@ -836,14 +823,51 @@ class Pokemon
# @param species [Integer, Symbol, String] id of the species to check for
# @return [Boolean] whether this Pokémon is of the specified species
def isSpecies?(species)
species = getID(PBSpecies, species)
return species && @species == species
def isSpecies?(check_species)
return @species == check_species || @species == GameData::Species.get(check_species).species
end
def form
return @forcedForm if !@forcedForm.nil?
return @form if $game_temp.in_battle
v = MultipleForms.call("getForm", self)
self.form = v if v != nil && (!@form || v != @form)
return @form
end
def formSimple
return @forcedForm || @form
end
def form=(value)
oldForm = @form
@form = value
yield if block_given?
MultipleForms.call("onSetForm", self, value, oldForm)
calcStats
pbSeenForm(self)
end
def setForm(value)
self.form = value
end
def formSimple=(value)
@form = value
calcStats
end
def species_data
return GameData::Species.get_species_form(@species, formSimple)
end
#=============================================================================
# Other
#=============================================================================
# @return [String] the species name of this Pokémon
def speciesName
return PBSpecies.getName(@species)
return species_data.name
end
# @return [Boolean] whether this Pokémon has been nicknamed
@@ -863,12 +887,17 @@ class Pokemon
# @return [Integer] the height of this Pokémon in decimetres (0.1 metres)
def height
return pbGetSpeciesData(@species, formSimple, SpeciesData::HEIGHT)
return species_data.height
end
# @return [Integer] the weight of this Pokémon in hectograms (0.1 kilograms)
def weight
return pbGetSpeciesData(@species, formSimple, SpeciesData::WEIGHT)
return species_data.weight
end
# @return [Array<Integer>] the EV yield of this Pokémon (an array of six values)
def evYield
return species_data.evs.clone
end
# Returns an array of booleans indicating whether a stat is made to have
@@ -889,12 +918,6 @@ class Pokemon
return ret
end
# @return [Array<Integer>] the EV yield of this Pokémon (an array of six values)
def evYield
ret = pbGetSpeciesData(@species, formSimple, SpeciesData::EFFORT_POINTS)
return ret.clone
end
# Sets the Pokémon's health.
# @param value [Integer] new hp value
def hp=(value)
@@ -971,8 +994,7 @@ class Pokemon
# @return [Array<Integer>] this Pokémon's base stats, an array of six values
def baseStats
ret = pbGetSpeciesData(@species, formSimple, SpeciesData::BASE_STATS)
return ret.clone
return species_data.base_stats.clone
end
# @return [Integer] the maximum HP of this Pokémon
@@ -1031,21 +1053,16 @@ class Pokemon
end
# Creates a new Pokémon object.
# @param species [Integer, Symbol, String] Pokémon species
# @param species [Symbol, String, Integer] Pokémon species
# @param level [Integer] Pokémon level
# @param owner [Owner, PokeBattle_Trainer] Pokémon owner (the player by default)
# @param withMoves [Boolean] whether the Pokémon should have moves
def initialize(species, level, owner = $Trainer, withMoves = true)
ospecies = species.to_s
species = getID(PBSpecies, species)
cname = getConstantName(PBSpecies, species) rescue nil
realSpecies = pbGetSpeciesFromFSpecies(species)[0] if species && species > 0
if !species || species <= 0 || realSpecies > PBSpecies.maxValue || !cname
raise ArgumentError.new(_INTL("The species given ({1}) is invalid.", ospecies))
end
@species = realSpecies
@name = speciesName
@personalID = rand(2**16) | rand(2**16) << 16
species_data = GameData::Species.get(species)
@species = species_data.species
@form = species_data.form
@name = species_data.name
@personalID = rand(2 ** 16) | rand(2 ** 16) << 16
@hp = 1
@totalhp = 1
@iv = []
@@ -1081,7 +1098,14 @@ class Pokemon
self.level = level
calcStats
@hp = @totalhp
@happiness = pbGetSpeciesData(@species, formSimple, SpeciesData::HAPPINESS)
self.resetMoves if withMoves
@happiness = species_data.happiness
resetMoves if withMoves
if @form == 0
f = MultipleForms.call("getFormOnCreation", self)
if f
self.form = f
resetMoves
end
end
end
end
+3 -75
View File
@@ -1,75 +1,3 @@
class Pokemon
attr_accessor :formTime # Time when Furfrou's/Hoopa's form was set
attr_accessor :forcedForm
def form
return @forcedForm if @forcedForm!=nil
return (@form || 0) if $game_temp.in_battle
v = MultipleForms.call("getForm",self)
self.form = v if v!=nil && (!@form || v!=@form)
return @form || 0
end
def form=(value)
setForm(value)
end
def setForm(value)
oldForm = @form
@form = value
yield if block_given?
MultipleForms.call("onSetForm",self,value,oldForm)
self.calcStats
pbSeenForm(self)
end
def formSimple
return @forcedForm if @forcedForm!=nil
return @form || 0
end
def formSimple=(value)
@form = value
self.calcStats
end
def fSpecies
return pbGetFSpeciesFromForm(@species,formSimple)
end
alias __mf_initialize initialize
def initialize(*args)
@form = (pbGetSpeciesFromFSpecies(args[0])[1] rescue 0)
__mf_initialize(*args)
if @form==0
f = MultipleForms.call("getFormOnCreation",self)
if f
self.form = f
self.resetMoves
end
end
end
end
class PokeBattle_RealBattlePeer
def pbOnEnteringBattle(_battle,pkmn,wild=false)
f = MultipleForms.call("getFormOnEnteringBattle",pkmn,wild)
pkmn.form = f if f
end
# For switching out, including due to fainting, and for the end of battle
def pbOnLeavingBattle(battle,pkmn,usedInBattle,endBattle=false)
return if !pkmn
f = MultipleForms.call("getFormOnLeavingBattle",pkmn,battle,usedInBattle,endBattle)
pkmn.form = f if f && pkmn.form!=f
pkmn.hp = pkmn.totalhp if pkmn.hp>pkmn.totalhp
end
end
module MultipleForms
@@formSpecies = SpeciesHandlerHash.new
@@ -86,13 +14,13 @@ module MultipleForms
end
def self.hasFunction?(pkmn,func)
spec = (pkmn.is_a?(Numeric)) ? pkmn : pkmn.species
spec = (pkmn.is_a?(Pokemon)) ? pkmn.species : pkmn
sp = @@formSpecies[spec]
return sp && sp[func]
end
def self.getFunction(pkmn,func)
spec = (pkmn.is_a?(Numeric)) ? pkmn : pkmn.species
spec = (pkmn.is_a?(Pokemon)) ? pkmn.species : pkmn
sp = @@formSpecies[spec]
return (sp && sp[func]) ? sp[func] : nil
end
@@ -364,7 +292,7 @@ MultipleForms.register(:ARCEUS,{
ret = f
break
end
break if ret>0
break if ret > 0
end
next ret
}
@@ -3,62 +3,53 @@
# NOTE: These are treated as form changes in Essentials.
#===============================================================================
class Pokemon
def getMegaForm(checkItemOnly=false)
formData = pbLoadFormToSpecies
return 0 if !formData[@species] || formData[@species].length==0
def getMegaForm(checkItemOnly = false)
ret = 0
speciesData = pbLoadSpeciesData
for i in 0...formData[@species].length
fSpec = formData[@species][i]
next if !fSpec || fSpec<=0
megaStone = speciesData[fSpec][SpeciesData::MEGA_STONE]
if megaStone && self.hasItem?(megaStone)
ret = i; break
end
if !checkItemOnly
megaMove = speciesData[fSpec][SpeciesData::MEGA_MOVE]
if self.hasMove?(megaMove)
ret = i; break
end
GameData::Species.each do |data|
next if data.species != @species
if data.mega_stone && hasItem?(data.mega_stone)
ret = data.form
break
elsif !checkItemOnly && data.mega_move && hasMove?(data.mega_move)
ret = data.form
break
end
end
return ret # form number, or 0 if no accessible Mega form
end
def getUnmegaForm
return -1 if !mega?
unmegaForm = pbGetSpeciesData(@species,formSimple,SpeciesData::UNMEGA_FORM)
return unmegaForm # form number
return (mega?) ? species_data.unmega_form : -1
end
def hasMegaForm?
megaForm = self.getMegaForm
return megaForm>0 && megaForm!=self.formSimple
return megaForm > 0 && megaForm != self.formSimple
end
def mega?
megaForm = self.getMegaForm
return megaForm>0 && megaForm==self.formSimple
return megaForm > 0 && megaForm == self.formSimple
end
alias isMega? mega?
def makeMega
megaForm = self.getMegaForm
self.form = megaForm if megaForm>0
self.form = megaForm if megaForm > 0
end
def makeUnmega
unmegaForm = self.getUnmegaForm
self.form = unmegaForm if unmegaForm>=0
self.form = unmegaForm if unmegaForm >= 0
end
def megaName
formName = pbGetMessage(MessageTypes::FormNames,self.fSpecies)
return (formName && formName!="") ? formName : _INTL("Mega {1}",PBSpecies.getName(@species))
formName = species_data.form_name
return (formName && !formName.empty?) ? formName : _INTL("Mega {1}", species_data.name)
end
def megaMessage # 0=default message, 1=Rayquaza message
return pbGetSpeciesData(@species,getMegaForm,SpeciesData::MEGA_MESSAGE)
return species_data.mega_message
end
end
@@ -50,9 +50,8 @@ def pbPurify(pokemon,scene)
pbChangeLevel(pokemon,newlevel,scene) # for convenience
pokemon.exp = newexp
end
speciesname = PBSpecies.getName(pokemon.species)
if scene.pbConfirm(_INTL("Would you like to give a nickname to {1}?",speciesname))
newname = pbEnterPokemonName(_INTL("{1}'s nickname?",speciesname),
if scene.pbConfirm(_INTL("Would you like to give a nickname to {1}?", pokemon.speciesName))
newname = pbEnterPokemonName(_INTL("{1}'s nickname?", pokemon.speciesName),
0, Pokemon::MAX_NAME_SIZE, "", pokemon)
pokemon.name = newname if newname!=""
end
@@ -281,8 +280,8 @@ class Pokemon
self.savedev = [0,0,0,0,0,0]
self.shadowmoves = []
# Retrieve Shadow moveset for this Pokémon
shadow_moveset = pbLoadShadowMovesets[self.fSpecies]
shadow_moveset = pbLoadShadowMovesets[self.species] if !shadow_moveset || shadow_moveset.length == 0
shadow_moveset = pbLoadShadowMovesets[species_data.id]
shadow_moveset = pbLoadShadowMovesets[@species] if !shadow_moveset || shadow_moveset.length == 0
# Record this Pokémon's Shadow moves
if shadow_moveset && shadow_moveset.length > 0
for i in 0...[shadow_moveset.length, MAX_MOVES].min
@@ -98,33 +98,6 @@ module PBEvolution
end
end
#===============================================================================
# Evolutions data cache
#===============================================================================
class PokemonTemp
attr_accessor :evolutionsData
end
def pbLoadEvolutionsData
$PokemonTemp = PokemonTemp.new if !$PokemonTemp
if !$PokemonTemp.evolutionsData
$PokemonTemp.evolutionsData = load_data("Data/species_evolutions.dat") || []
end
return $PokemonTemp.evolutionsData
end
def pbGetEvolutionData(species)
species = getID(PBSpecies,species)
evosData = pbLoadEvolutionsData
return evosData[species] || nil
end
alias __evolutionsData__pbClearData pbClearData
def pbClearData
$PokemonTemp.evolutionsData = nil if $PokemonTemp
__evolutionsData__pbClearData
end
#===============================================================================
# Evolution helper functions
#===============================================================================
@@ -133,7 +106,7 @@ module EvolutionHelper
def evolutions(species, ignore_none = false)
ret = []
evoData = pbGetEvolutionData(species)
evoData = GameData::Species.get(species).evolutions
return ret if !evoData || evoData.length == 0
evoData.each do |evo|
next if evo[3] # Is the prevolution
@@ -143,9 +116,10 @@ module EvolutionHelper
return ret
end
def family_evolutions(species)
evos = self.evolutions(species, true)
def family_evolutions(species, ignore_none = true)
evos = self.evolutions(species, ignore_none)
return nil if evos.length == 0
evos.sort! { |a, b| GameData::Species.get(a[2]).id_number <=> GameData::Species.get(b[2]).id_number }
ret = []
for i in 0...evos.length
ret.push([species].concat(evos[i]))
@@ -155,8 +129,15 @@ module EvolutionHelper
return ret
end
def all_related_species(species)
species = self.baby_species(species)
evos = self.family_evolutions(species, false)
return [species] if !evos || evos.length == 0
return [species].concat(evos.map { |e| e[3] }).uniq
end
def previous_species(species)
evoData = pbGetEvolutionData(species)
evoData = GameData::Species.get(species).evolutions
return species if !evoData || evoData.length == 0
evoData.each do |evo|
return evo[0] if evo[3] # Is the prevolution
@@ -166,12 +147,12 @@ module EvolutionHelper
def baby_species(species, check_items = false, item1 = nil, item2 = nil)
ret = species
evoData = pbGetEvolutionData(species)
evoData = GameData::Species.get(species).evolutions
return ret if !evoData || evoData.length == 0
evoData.each do |evo|
next if !evo[3] # Not the prevolution
if check_items
incense = pbGetSpeciesData(evo[0], 0, SpeciesData::INCENSE)
incense = GameData::Species.get(evo[0]).incense
ret = evo[0] if !incense || item1 == incense || item2 == incense
else
ret = evo[0] # Species of prevolution
@@ -183,7 +164,7 @@ module EvolutionHelper
end
def minimum_level(species)
evoData = pbGetEvolutionData(species)
evoData = GameData::Species.get(species).evolutions
return 1 if !evoData || evoData.length == 0
ret = -1
evoData.each do |evo|
@@ -203,11 +184,11 @@ module EvolutionHelper
return false if !evos || evos.length == 0
for evo in evos
if method.is_a?(Array)
next if !method.include?(evo[0])
next if !method.include?(evo[1])
elsif method >= 0
next if evo[0] != method
next if evo[1] != method
end
next if param && evo[1] != param
next if param && evo[2] != param
return true
end
return false
@@ -270,39 +251,40 @@ end
#===============================================================================
def pbMiniCheckEvolution(pkmn, method, parameter, new_species)
success = PBEvolution.call("levelUpCheck", method, pkmn, parameter)
return (success) ? new_species : -1
return (success) ? new_species : nil
end
def pbMiniCheckEvolutionItem(pkmn, method, parameter, new_species, item)
success = PBEvolution.call("itemCheck", method, pkmn, parameter, item)
return (success) ? new_species : -1
return (success) ? new_species : nil
end
# Checks whether a Pokemon can evolve now. If a block is given, calls the block
# with the following parameters:
# Pokemon to check; evolution method; parameter; ID of the new species
def pbCheckEvolutionEx(pokemon)
return -1 if pokemon.species<=0 || pokemon.egg? || pokemon.shadowPokemon?
return -1 if pokemon.hasItem?(:EVERSTONE)
return -1 if pokemon.hasAbility?(:BATTLEBOND)
ret = -1
for form in EvolutionHelper.evolutions(pbGetFSpeciesFromForm(pokemon.species,pokemon.form), true)
ret = yield pokemon,form[0],form[1],form[2]
break if ret>0
def pbCheckEvolutionEx(pkmn)
return nil if !pkmn.species || pokemon.egg? || pokemon.shadowPokemon?
return nil if pkmn.hasItem?(:EVERSTONE)
return nil if pkmn.hasAbility?(:BATTLEBOND)
ret = nil
pkmn.species_data.evolutions.each do |evo|
next if evo[3] # Prevolution
ret = yield pkmn, evo[1], evo[2], evo[0] # pkmn, method, parameter, new_species
break if ret
end
return ret
end
# Checks whether a Pokemon can evolve now. If an item is used on the Pokémon,
# checks whether the Pokemon can evolve with the given item.
def pbCheckEvolution(pokemon,item=nil)
def pbCheckEvolution(pkmn, item = nil)
if item
return pbCheckEvolutionEx(pokemon) { |pokemon,evonib,level,poke|
next pbMiniCheckEvolutionItem(pokemon,evonib,level,poke,item)
return pbCheckEvolutionEx(pkmn) { |pkmn, method, parameter, new_species|
next pbMiniCheckEvolutionItem(pkmn, method, parameter, new_species, item)
}
else
return pbCheckEvolutionEx(pokemon) { |pokemon,evonib,level,poke|
next pbMiniCheckEvolution(pokemon,evonib,level,poke)
return pbCheckEvolutionEx(pkmn) { |pkmn, method, parameter, new_species|
next pbMiniCheckEvolution(pkmn, method, parameter, new_species)
}
end
end
@@ -662,7 +644,7 @@ PBEvolution.register(:HasMoveType, {
PBEvolution.register(:HasInParty, {
"minimumLevel" => 1, # Needs any level up
"parameterType" => :PBSpecies,
"parameterType" => :Species,
"levelUpCheck" => proc { |pkmn, parameter|
next pbHasSpecies?(parameter)
}
@@ -779,7 +761,7 @@ PBEvolution.register(:TradeItem, {
})
PBEvolution.register(:TradeSpecies, {
"parameterType" => :PBSpecies,
"parameterType" => :Species,
"tradeCheck" => proc { |pkmn, parameter, other_pkmn|
next pkmn.species == parameter && !other_pkmn.hasItem?(:EVERSTONE)
}
@@ -5,7 +5,7 @@ end
def pbChatter(pokemon)
iconwindow=PictureWindow.new(pbLoadPokemonBitmap(pokemon))
iconwindow=PictureWindow.new(GameData::Species.sprite_bitmap_from_pokemon(pokemon))
iconwindow.x=(Graphics.width/2)-(iconwindow.width/2)
iconwindow.y=((Graphics.height-96)/2)-(iconwindow.height/2)
if pokemon.chatter
@@ -40,7 +40,7 @@ HiddenMoveHandlers::UseMove.add(:CHATTER,proc { |move,pokemon|
class PokeBattle_Scene
def pbChatter(user,_target)
pbPlayCry(user.pokemon,90,100) if user.pokemon
GameData::Species.play_cry_from_pokemon(user.pokemon, nil, 100) if user.pokemon
Graphics.frame_rate.times do
Graphics.update
Input.update
@@ -48,7 +48,7 @@ class PokemonSprite < SpriteWrapper
def setPokemonBitmap(pokemon,back=false)
@_iconbitmap.dispose if @_iconbitmap
@_iconbitmap = (pokemon) ? pbLoadPokemonBitmap(pokemon,back) : nil
@_iconbitmap = (pokemon) ? GameData::Species.sprite_bitmap_from_pokemon(pokemon, back) : nil
self.bitmap = (@_iconbitmap) ? @_iconbitmap.bitmap : nil
self.color = Color.new(0,0,0,0)
changeOrigin
@@ -56,14 +56,14 @@ class PokemonSprite < SpriteWrapper
def setPokemonBitmapSpecies(pokemon,species,back=false)
@_iconbitmap.dispose if @_iconbitmap
@_iconbitmap = (pokemon) ? pbLoadPokemonBitmapSpecies(pokemon,species,back) : nil
@_iconbitmap = (pokemon) ? GameData::Species.sprite_bitmap_from_pokemon(pokemon, back, species) : nil
self.bitmap = (@_iconbitmap) ? @_iconbitmap.bitmap : nil
changeOrigin
end
def setSpeciesBitmap(species,female=false,form=0,shiny=false,shadow=false,back=false,egg=false)
def setSpeciesBitmap(species, gender = 0, form = 0, shiny = false, shadow = false, back = false, egg = false)
@_iconbitmap.dispose if @_iconbitmap
@_iconbitmap = pbLoadSpeciesBitmap(species,female,form,shiny,shadow,back,egg)
@_iconbitmap = GameData::Species.sprite_bitmap(species, form, gender, shiny, shadow, back, egg)
self.bitmap = (@_iconbitmap) ? @_iconbitmap.bitmap : nil
changeOrigin
end
@@ -129,7 +129,7 @@ class PokemonIconSprite < SpriteWrapper
@counter = 0
return
end
@animBitmap = AnimatedBitmap.new(pbPokemonIconFile(value))
@animBitmap = AnimatedBitmap.new(GameData::Species.icon_filename_from_pokemon(value))
self.bitmap = @animBitmap.bitmap
self.src_rect.width = @animBitmap.height
self.src_rect.height = @animBitmap.height
@@ -307,12 +307,13 @@ class PokemonSpeciesIconSprite < SpriteWrapper
def refresh
@animBitmap.dispose if @animBitmap
@animBitmap = nil
bitmapFileName = pbCheckPokemonIconFiles([@species,(@gender==1),@shiny,@form,false])
bitmapFileName = GameData::Species.icon_filename(@species, @form, @gender, @shiny)
return if !bitmapFileName
@animBitmap = AnimatedBitmap.new(bitmapFileName)
self.bitmap = @animBitmap.bitmap
self.src_rect.width = @animBitmap.height
self.src_rect.height = @animBitmap.height
@numFrames = @animBitmap.width/@animBitmap.height
@numFrames = @animBitmap.width / @animBitmap.height
@currentFrame = 0 if @currentFrame>=@numFrames
changeOrigin
end
@@ -331,34 +332,3 @@ class PokemonSpeciesIconSprite < SpriteWrapper
self.src_rect.x = self.src_rect.width*@currentFrame
end
end
#===============================================================================
# Sprite position adjustments
#===============================================================================
def pbApplyBattlerMetricsToSprite(sprite,index,species,shadow=false,metrics=nil)
metrics = pbLoadSpeciesMetrics if !metrics
if shadow
if (index&1)==1 # Foe Pokémon
sprite.x += (metrics[SpeciesData::METRIC_SHADOW_X][species] || 0)*2
end
else
if (index&1)==0 # Player's Pokémon
sprite.x += (metrics[SpeciesData::METRIC_PLAYER_X][species] || 0)*2
sprite.y += (metrics[SpeciesData::METRIC_PLAYER_Y][species] || 0)*2
else # Foe Pokémon
sprite.x += (metrics[SpeciesData::METRIC_ENEMY_X][species] || 0)*2
sprite.y += (metrics[SpeciesData::METRIC_ENEMY_Y][species] || 0)*2
sprite.y -= (metrics[SpeciesData::METRIC_ALTITUDE][species] || 0)*2
end
end
end
# NOTE: The species parameter here is typically the fSpecies, which contains
# information about both the species and the form.
def showShadow?(species)
return true
# metrics = pbLoadSpeciesMetrics
# return (metrics[SpeciesData::METRIC_ALTITUDE][species] || 0)>0
end
+1 -1
View File
@@ -128,7 +128,7 @@ class PokemonPauseMenu
elsif pbInBugContest?
if pbBugContestState.lastPokemon
@scene.pbShowInfo(_INTL("Caught: {1}\nLevel: {2}\nBalls: {3}",
PBSpecies.getName(pbBugContestState.lastPokemon.species),
pbBugContestState.lastPokemon.speciesName,
pbBugContestState.lastPokemon.level,
pbBugContestState.ballcount))
else
@@ -103,7 +103,7 @@ class PokemonPokedexMenuScreen
commands[i] = dexnames[index]
end
end
index = -1 if index>=$PokemonGlobal.pokedexUnlocked.length-1
index = -1 if index >= $PokemonGlobal.pokedexUnlocked.length - 1
commands2[i] = [$Trainer.pokedexSeen(index),
$Trainer.pokedexOwned(index),
pbGetRegionalDexLength(index)]
+31 -34
View File
@@ -300,45 +300,39 @@ class PokemonPokedex_Scene
return index
end
def pbCanAddForModeList?(mode,nationalSpecies)
def pbCanAddForModeList?(mode, species)
case mode
when MODENUMERICAL
return true
when MODEATOZ
return $Trainer.seen[nationalSpecies]
return $Trainer.seen[species]
when MODEHEAVIEST, MODELIGHTEST, MODETALLEST, MODESMALLEST
return $Trainer.owned[nationalSpecies]
return $Trainer.owned[species]
end
return true # For MODENUMERICAL
end
def pbGetDexList
dexlist = []
speciesData = pbLoadSpeciesData
region = pbGetPokedexRegion
regionalSpecies = pbAllRegionalSpecies(region)
if regionalSpecies.length==1
# If no Regional Dex defined for the given region, use National Pokédex
for i in 1..PBSpecies.maxValue
regionalSpecies.push(i)
end
if !regionalSpecies || regionalSpecies.length == 0
# If no Regional Dex defined for the given region, use the National Pokédex
regionalSpecies = []
GameData::Species.each { |s| regionalSpecies.push(s.id) if s.form == 0 }
end
for i in 1...regionalSpecies.length
nationalSpecies = regionalSpecies[i]
if pbCanAddForModeList?($PokemonGlobal.pokedexMode,nationalSpecies)
form = $Trainer.formlastseen[nationalSpecies][1] || 0
fspecies = pbGetFSpeciesFromForm(nationalSpecies,form)
color = speciesData[fspecies][SpeciesData::COLOR] || 0
type1 = speciesData[fspecies][SpeciesData::TYPE1]
type2 = speciesData[fspecies][SpeciesData::TYPE2] || type1
shape = speciesData[fspecies][SpeciesData::SHAPE] || 0
height = speciesData[fspecies][SpeciesData::HEIGHT] || 1
weight = speciesData[fspecies][SpeciesData::WEIGHT] || 1
shift = DEXES_WITH_OFFSETS.include?(region)
dexlist.push([nationalSpecies,PBSpecies.getName(nationalSpecies),
height,weight,i,shift,type1,type2,color,shape])
end
shift = DEXES_WITH_OFFSETS.include?(region)
ret = []
regionalSpecies.each_with_index do |species, i|
next if !species
next if !pbCanAddForModeList?($PokemonGlobal.pokedexMode, species)
species_data = GameData::Species.get(species)
color = species_data.color
type1 = species_data.type1
type2 = species_data.type2 || type1
shape = species_data.shape
height = species_data.height
weight = species_data.weight
ret.push([species, species_data.name, height, weight, i + 1, shift, type1, type2, color, shape])
end
return dexlist
return ret
end
def pbRefreshDexList(index=0)
@@ -348,7 +342,8 @@ class PokemonPokedex_Scene
# Hide the Dex number 0 species if unseen
dexlist[0] = nil if dexlist[0][5] && !$Trainer.seen[dexlist[0][0]]
# Remove unseen species from the end of the list
i = dexlist.length-1; loop do break unless i>=0
i = dexlist.length-1
loop do break unless i>=0
break if !dexlist[i] || $Trainer.seen[dexlist[i][0]]
dexlist[i] = nil
i -= 1
@@ -385,7 +380,7 @@ class PokemonPokedex_Scene
base = Color.new(88,88,80)
shadow = Color.new(168,184,184)
iconspecies = @sprites["pokedex"].species
iconspecies = 0 if !$Trainer.seen[iconspecies]
iconspecies = nil if !$Trainer.seen[iconspecies]
# Write various bits of text
dexname = _INTL("Pokédex")
if $PokemonGlobal.pokedexUnlocked.length>1
@@ -397,7 +392,7 @@ class PokemonPokedex_Scene
textpos = [
[dexname,Graphics.width/2,2,2,Color.new(248,248,248),Color.new(0,0,0)]
]
textpos.push([PBSpecies.getName(iconspecies),112,52,2,base,shadow]) if iconspecies>0
textpos.push([GameData::Species.get(iconspecies).name,112,52,2,base,shadow]) if iconspecies
if @searchResults
textpos.push([_INTL("Search results"),112,308,2,base,shadow])
textpos.push([@dexlist.length.to_s,112,340,2,base,shadow])
@@ -678,9 +673,11 @@ class PokemonPokedex_Scene
end
def setIconBitmap(species)
gender = ($Trainer.formlastseen[species][0] rescue 0)
form = ($Trainer.formlastseen[species][1] rescue 0)
@sprites["icon"].setSpeciesBitmap(species,(gender==1),form)
$Trainer.formlastseen = {} if !$Trainer.formlastseen
$Trainer.formlastseen[species] = [] if !$Trainer.formlastseen[species]
gender = $Trainer.formlastseen[species][0] || 0
form = $Trainer.formlastseen[species][1] || 0
@sprites["icon"].setSpeciesBitmap(species, gender, form)
end
def pbSearchDexList(params)
+97 -108
View File
@@ -54,7 +54,7 @@ class PokemonPokedexInfo_Scene
@sprites["formback"] = PokemonSprite.new(@viewport)
@sprites["formback"].setOffset(PictureOrigin::Bottom)
@sprites["formback"].x = 382 # y is set below as it depends on metrics
@sprites["formicon"] = PokemonSpeciesIconSprite.new(0,@viewport)
@sprites["formicon"] = PokemonSpeciesIconSprite.new(nil, @viewport)
@sprites["formicon"].setOffset(PictureOrigin::Center)
@sprites["formicon"].x = 82
@sprites["formicon"].y = 328
@@ -79,20 +79,18 @@ class PokemonPokedexInfo_Scene
def pbStartSceneBrief(species) # For standalone access, shows first page only
@viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
@viewport.z = 99999
# @region = 0
dexnum = species
dexnumshift = false
if $PokemonGlobal.pokedexUnlocked[$PokemonGlobal.pokedexUnlocked.length-1]
dexnumshift = true if DEXES_WITH_OFFSETS.include?(-1)
if $PokemonGlobal.pokedexUnlocked[$PokemonGlobal.pokedexUnlocked.length - 1]
dexnumshift = true if DEXES_WITH_OFFSETS.include?(-1) # National Dex
else
dexnum = 0
for i in 0...$PokemonGlobal.pokedexUnlocked.length-1
for i in 0...$PokemonGlobal.pokedexUnlocked.length - 1 # Regional Dexes
next if !$PokemonGlobal.pokedexUnlocked[i]
num = pbGetRegionalNumber(i,species)
next if num<=0
next if num <= 0
dexnum = num
dexnumshift = true if DEXES_WITH_OFFSETS.include?(i)
# @region = pbDexNames[i][1] if pbDexNames[i].is_a?(Array)
break
end
end
@@ -132,17 +130,19 @@ class PokemonPokedexInfo_Scene
def pbUpdateDummyPokemon
@species = @dexlist[@index][0]
@gender = ($Trainer.formlastseen[@species][0] rescue 0)
@form = ($Trainer.formlastseen[@species][1] rescue 0)
@sprites["infosprite"].setSpeciesBitmap(@species,(@gender==1),@form)
$Trainer.formlastseen = {} if !$Trainer.formlastseen
$Trainer.formlastseen[@species] = [] if !$Trainer.formlastseen[@species]
@gender = $Trainer.formlastseen[@species][0] || 0
@form = $Trainer.formlastseen[@species][1] || 0
species_data = GameData::Species.get_species_form(@species, @form)
@sprites["infosprite"].setSpeciesBitmap(@species,@gender,@form)
if @sprites["formfront"]
@sprites["formfront"].setSpeciesBitmap(@species,(@gender==1),@form)
@sprites["formfront"].setSpeciesBitmap(@species,@gender,@form)
end
if @sprites["formback"]
@sprites["formback"].setSpeciesBitmap(@species,(@gender==1),@form,false,false,true)
@sprites["formback"].setSpeciesBitmap(@species,@gender,@form,false,false,true)
@sprites["formback"].y = 256
fSpecies = pbGetFSpeciesFromForm(@species,@form)
@sprites["formback"].y += (pbLoadSpeciesMetrics[SpeciesData::METRIC_PLAYER_Y][fSpecies] || 0)*2
@sprites["formback"].y += species_data.back_sprite_y * 2
end
if @sprites["formicon"]
@sprites["formicon"].pbSetParams(@species,@gender,@form)
@@ -150,53 +150,44 @@ class PokemonPokedexInfo_Scene
end
def pbGetAvailableForms
available = [] # [name, gender, form]
formdata = pbLoadFormToSpecies
possibleforms = []
multiforms = false
if formdata[@species]
for i in 0...formdata[@species].length
fSpecies = pbGetFSpeciesFromForm(@species,i)
formname = pbGetMessage(MessageTypes::FormNames,fSpecies)
genderRate = pbGetSpeciesData(@species,i,SpeciesData::GENDER_RATE)
if i==0 || (formname && formname!="")
multiforms = true if i>0
case genderRate
when PBGenderRates::AlwaysMale,
PBGenderRates::AlwaysFemale,
PBGenderRates::Genderless
gendertopush = (genderRate==PBGenderRates::AlwaysFemale) ? 1 : 0
if $Trainer.formseen[@species][gendertopush][i] || DEX_SHOWS_ALL_FORMS
gendertopush = 2 if genderRate==PBGenderRates::Genderless
possibleforms.push([i,gendertopush,formname])
end
else # Both male and female
for g in 0...2
if $Trainer.formseen[@species][g][i] || DEX_SHOWS_ALL_FORMS
possibleforms.push([i,g,formname])
break if (formname && formname!="")
end
end
end
ret = []
multiple_forms = false
# Find all genders/forms of @species that have been seen
GameData::Species.each do |sp|
next if sp.species != @species
next if sp.form != 0 && (!sp.real_form_name || sp.real_form_name.empty?)
next if sp.pokedex_form != sp.form
multiple_forms = true if sp.form > 0
$Trainer.formseen[@species] = [[], []] if !$Trainer.formseen[@species]
case sp.gender_rate
when PBGenderRates::AlwaysMale, PBGenderRates::AlwaysFemale, PBGenderRates::Genderless
real_gender = (sp.gender_rate == PBGenderRates::AlwaysFemale) ? 1 : 0
next if !$Trainer.formseen[@species][real_gender][sp.form] && !DEX_SHOWS_ALL_FORMS
real_gender = 2 if sp.gender_rate == PBGenderRates::Genderless
ret.push([sp.form_name, real_gender, sp.form])
else # Both male and female
for real_gender in 0...2
next if !$Trainer.formseen[@species][real_gender][sp.form] && !DEX_SHOWS_ALL_FORMS
ret.push([sp.form_name, real_gender, sp.form])
break if sp.form_name && !sp.form_name.empty? # Only show 1 entry for each non-0 form
end
end
end
for thisform in possibleforms
if thisform[2] && thisform[2]!="" # Has a form name
thisformname = thisform[2]
else # Necessarily applies only to form 0
case thisform[1]
when 0 then thisformname = _INTL("Male")
when 1 then thisformname = _INTL("Female")
# Sort all entries
ret.sort! { |a, b| (a[2] == b[2]) ? a[1] <=> b[1] : a[2] <=> b[2] }
# Create form names for entries if they don't already exist
ret.each do |entry|
if !entry[0] || entry[0].empty? # Necessarily applies only to form 0
case entry[1]
when 0 then entry[0] = _INTL("Male")
when 1 then entry[0] = _INTL("Female")
else
thisformname = (multiforms) ? _INTL("One Form") : _INTL("Genderless")
entry[0] = (multiple_forms) ? _INTL("One Form") : _INTL("Genderless")
end
end
# Push to available array
gendertopush = (thisform[1]==2) ? 0 : thisform[1]
available.push([thisformname,gendertopush,thisform[0]])
entry[1] = 0 if entry[1] == 2 # Genderless entries are treated as male
end
return available
return ret
end
def drawPage(page)
@@ -221,82 +212,78 @@ class PokemonPokedexInfo_Scene
def drawPageInfo
@sprites["background"].setBitmap(_INTL("Graphics/Pictures/Pokedex/bg_info"))
overlay = @sprites["overlay"].bitmap
base = Color.new(88,88,80)
shadow = Color.new(168,184,184)
base = Color.new(88, 88, 80)
shadow = Color.new(168, 184, 184)
imagepos = []
if @brief
imagepos.push([_INTL("Graphics/Pictures/Pokedex/overlay_info"),0,0])
imagepos.push([_INTL("Graphics/Pictures/Pokedex/overlay_info"), 0, 0])
end
species_data = GameData::Species.get_species_form(@species, @form)
# Write various bits of text
indexText = "???"
if @dexlist[@index][4]>0
if @dexlist[@index][4] > 0
indexNumber = @dexlist[@index][4]
indexNumber -= 1 if @dexlist[@index][5]
indexText = sprintf("%03d",indexNumber)
indexText = sprintf("%03d", indexNumber)
end
textpos = [
[_INTL("{1}{2} {3}",indexText," ",PBSpecies.getName(@species)),
246,42,0,Color.new(248,248,248),Color.new(0,0,0)],
[_INTL("Height"),314,158,0,base,shadow],
[_INTL("Weight"),314,190,0,base,shadow]
[_INTL("{1}{2} {3}", indexText, " ", species_data.name),
246, 42, 0, Color.new(248, 248, 248), Color.new(0, 0, 0)],
[_INTL("Height"), 314, 158, 0, base, shadow],
[_INTL("Weight"), 314, 190, 0, base, shadow]
]
if $Trainer.owned[@species]
speciesData = pbGetSpeciesData(@species,@form)
fSpecies = pbGetFSpeciesFromForm(@species,@form)
# Write the kind
kind = pbGetMessage(MessageTypes::Kinds,fSpecies)
kind = pbGetMessage(MessageTypes::Kinds,@species) if !kind || kind==""
textpos.push([_INTL("{1} Pokémon",kind),246,74,0,base,shadow])
# Write the category
textpos.push([_INTL("{1} Pokémon", species_data.category), 246, 74, 0, base, shadow])
# Write the height and weight
height = speciesData[SpeciesData::HEIGHT] || 1
weight = speciesData[SpeciesData::WEIGHT] || 1
if pbGetCountry==0xF4 # If the user is in the United States
inches = (height/0.254).round
pounds = (weight/0.45359).round
textpos.push([_ISPRINTF("{1:d}'{2:02d}\"",inches/12,inches%12),460,158,1,base,shadow])
textpos.push([_ISPRINTF("{1:4.1f} lbs.",pounds/10.0),494,190,1,base,shadow])
height = species_data.height
weight = species_data.weight
if pbGetCountry == 0xF4 # If the user is in the United States
inches = (height / 0.254).round
pounds = (weight / 0.45359).round
textpos.push([_ISPRINTF("{1:d}'{2:02d}\"", inches / 12, inches % 12), 460, 158, 1, base, shadow])
textpos.push([_ISPRINTF("{1:4.1f} lbs.", pounds / 10.0), 494, 190, 1, base, shadow])
else
textpos.push([_ISPRINTF("{1:.1f} m",height/10.0),470,158,1,base,shadow])
textpos.push([_ISPRINTF("{1:.1f} kg",weight/10.0),482,190,1,base,shadow])
textpos.push([_ISPRINTF("{1:.1f} m", height / 10.0), 470, 158, 1, base, shadow])
textpos.push([_ISPRINTF("{1:.1f} kg", weight / 10.0), 482, 190, 1, base, shadow])
end
# Draw the Pokédex entry text
entry = pbGetMessage(MessageTypes::Entries,fSpecies)
entry = pbGetMessage(MessageTypes::Entries,@species) if !entry || entry==""
drawTextEx(overlay,40,240,Graphics.width-(40*2),4,entry,base,shadow)
drawTextEx(overlay, 40, 240, Graphics.width - (40 * 2), 4, # overlay, x, y, width, num lines
species_data.pokedex_entry, base, shadow)
# Draw the footprint
footprintfile = pbPokemonFootprintFile(@species,@form)
footprintfile = GameData::Species.footprint_filename(@species, @form)
if footprintfile
footprint = BitmapCache.load_bitmap(footprintfile)
overlay.blt(226,138,footprint,footprint.rect)
overlay.blt(226, 138, footprint, footprint.rect)
footprint.dispose
end
# Show the owned icon
imagepos.push(["Graphics/Pictures/Pokedex/icon_own",212,44])
imagepos.push(["Graphics/Pictures/Pokedex/icon_own", 212, 44])
# Draw the type icon(s)
type1 = speciesData[SpeciesData::TYPE1]
type2 = speciesData[SpeciesData::TYPE2] || type1
type1 = species_data.type1
type2 = species_data.type2
type1_number = GameData::Type.get(type1).id_number
type2_number = GameData::Type.get(type2).id_number
type1rect = Rect.new(0,type1_number*32,96,32)
type2rect = Rect.new(0,type2_number*32,96,32)
overlay.blt(296,120,@typebitmap.bitmap,type1rect)
overlay.blt(396,120,@typebitmap.bitmap,type2rect) if type1!=type2
type1rect = Rect.new(0, type1_number * 32, 96, 32)
type2rect = Rect.new(0, type2_number * 32, 96, 32)
overlay.blt(296, 120, @typebitmap.bitmap, type1rect)
overlay.blt(396, 120, @typebitmap.bitmap, type2rect) if type1 != type2
else
# Write the kind
textpos.push([_INTL("????? Pokémon"),246,74,0,base,shadow])
# Write the category
textpos.push([_INTL("????? Pokémon"), 246, 74, 0, base, shadow])
# Write the height and weight
if pbGetCountry()==0xF4 # If the user is in the United States
textpos.push([_INTL("???'??\""),460,158,1,base,shadow])
textpos.push([_INTL("????.? lbs."),494,190,1,base,shadow])
if pbGetCountry == 0xF4 # If the user is in the United States
textpos.push([_INTL("???'??\""), 460, 158, 1, base, shadow])
textpos.push([_INTL("????.? lbs."), 494, 190, 1, base, shadow])
else
textpos.push([_INTL("????.? m"),470,158,1,base,shadow])
textpos.push([_INTL("????.? kg"),482,190,1,base,shadow])
textpos.push([_INTL("????.? m"), 470, 158, 1, base, shadow])
textpos.push([_INTL("????.? kg"), 482, 190, 1, base, shadow])
end
end
# Draw all text
pbDrawTextPositions(@sprites["overlay"].bitmap,textpos)
pbDrawTextPositions(overlay, textpos)
# Draw all images
pbDrawImagePositions(overlay,imagepos)
pbDrawImagePositions(overlay, imagepos)
end
def drawPageArea
@@ -374,7 +361,7 @@ class PokemonPokedexInfo_Scene
textpos.push([_INTL("Area unknown"),Graphics.width/2,Graphics.height/2,2,base,shadow])
end
textpos.push([pbGetMessage(MessageTypes::RegionNames,@region),414,44,2,base,shadow])
textpos.push([_INTL("{1}'s area",PBSpecies.getName(@species)),
textpos.push([_INTL("{1}'s area",GameData::Species.get(@species).name),
Graphics.width/2,352,2,base,shadow])
pbDrawTextPositions(overlay,textpos)
end
@@ -392,7 +379,7 @@ class PokemonPokedexInfo_Scene
end
end
textpos = [
[PBSpecies.getName(@species),Graphics.width/2,Graphics.height-88,2,base,shadow],
[GameData::Species.get(@species).name,Graphics.width/2,Graphics.height-88,2,base,shadow],
[formname,Graphics.width/2,Graphics.height-56,2,base,shadow],
]
# Draw all text
@@ -432,6 +419,8 @@ class PokemonPokedexInfo_Scene
oldindex = -1
loop do
if oldindex!=index
$Trainer.formlastseen = {} if !$Trainer.formlastseen
$Trainer.formlastseen[@species] = [] if !$Trainer.formlastseen
$Trainer.formlastseen[@species][0] = @available[index][1]
$Trainer.formlastseen[@species][1] = @available[index][2]
pbUpdateDummyPokemon
@@ -462,7 +451,7 @@ class PokemonPokedexInfo_Scene
end
def pbScene
pbPlayCrySpecies(@species,@form)
GameData::Species.play_cry_from_species(@species, @form)
loop do
Graphics.update
Input.update
@@ -470,7 +459,7 @@ class PokemonPokedexInfo_Scene
dorefresh = false
if Input.trigger?(Input::A)
pbSEStop
pbPlayCrySpecies(@species,@form) if @page==1
GameData::Species.play_cry_from_species(@species, @form) if @page == 1
elsif Input.trigger?(Input::B)
pbPlayCloseMenuSE
break
@@ -491,7 +480,7 @@ class PokemonPokedexInfo_Scene
pbUpdateDummyPokemon
@available = pbGetAvailableForms
pbSEStop
(@page==1) ? pbPlayCrySpecies(@species,@form) : pbPlayCursorSE
(@page==1) ? GameData::Species.play_cry_from_species(@species, @form) : pbPlayCursorSE
dorefresh = true
end
elsif Input.trigger?(Input::DOWN)
@@ -501,7 +490,7 @@ class PokemonPokedexInfo_Scene
pbUpdateDummyPokemon
@available = pbGetAvailableForms
pbSEStop
(@page==1) ? pbPlayCrySpecies(@species,@form) : pbPlayCursorSE
(@page==1) ? GameData::Species.play_cry_from_species(@species, @form) : pbPlayCursorSE
dorefresh = true
end
elsif Input.trigger?(Input::LEFT)
@@ -531,14 +520,14 @@ class PokemonPokedexInfo_Scene
end
def pbSceneBrief
pbPlayCrySpecies(@species,@form)
GameData::Species.play_cry_from_species(@species, @form)
loop do
Graphics.update
Input.update
pbUpdate
if Input.trigger?(Input::A)
pbSEStop
pbPlayCrySpecies(@species,@form)
GameData::Species.play_cry_from_species(@species, @form)
elsif Input.trigger?(Input::B)
pbPlayCloseMenuSE
break
@@ -574,7 +563,7 @@ class PokemonPokedexInfoScreen
end
dexnum = pbGetRegionalNumber(region,species)
dexnumshift = DEXES_WITH_OFFSETS.include?(region)
dexlist = [[species,PBSpecies.getName(species),0,0,dexnum,dexnumshift]]
dexlist = [[species,GameData::Species.get(species).name,0,0,dexnum,dexnumshift]]
@scene.pbStartScene(dexlist,0,region)
@scene.pbScene
@scene.pbEndScene
+1 -1
View File
@@ -1395,7 +1395,7 @@ def pbChooseTradablePokemon(variableNumber,nameVarNumber,ableProc=nil,allowIneli
end
def pbChoosePokemonForTrade(variableNumber,nameVarNumber,wanted)
wanted = getID(PBSpecies,wanted)
wanted = GameData::Species.get(wanted).species
pbChooseTradablePokemon(variableNumber,nameVarNumber,proc { |pkmn|
next pkmn.species==wanted
})
+4 -4
View File
@@ -374,7 +374,7 @@ class PokemonSummary_Scene
textpos = [
[_INTL("Dex No."),238,80,0,base,shadow],
[_INTL("Species"),238,112,0,base,shadow],
[PBSpecies.getName(@pokemon.species),435,112,2,Color.new(64,64,64),Color.new(176,176,176)],
[@pokemon.speciesName,435,112,2,Color.new(64,64,64),Color.new(176,176,176)],
[_INTL("Type"),238,144,0,base,shadow],
[_INTL("OT"),238,176,0,base,shadow],
[_INTL("ID No."),238,208,0,base,shadow],
@@ -898,7 +898,7 @@ class PokemonSummary_Scene
@sprites["pokemon"].setPokemonBitmap(@pokemon)
@sprites["itemicon"].item = @pokemon.item_id
pbSEStop
pbPlayCry(@pokemon)
GameData::Species.play_cry_from_pokemon(@pokemon)
end
def pbMoveSelection
@@ -1235,7 +1235,7 @@ class PokemonSummary_Scene
end
def pbScene
pbPlayCry(@pokemon)
GameData::Species.play_cry_from_pokemon(@pokemon)
loop do
Graphics.update
Input.update
@@ -1243,7 +1243,7 @@ class PokemonSummary_Scene
dorefresh = false
if Input.trigger?(Input::A)
pbSEStop
pbPlayCry(@pokemon)
GameData::Species.play_cry_from_pokemon(@pokemon)
elsif Input.trigger?(Input::B)
pbPlayCloseMenuSE
break
@@ -29,7 +29,7 @@ class PokemonBoxIcon < IconSprite
def refresh
return if !@pokemon
self.setBitmap(pbPokemonIconFile(@pokemon))
self.setBitmap(GameData::Species.icon_filename_from_pokemon(@pokemon))
self.src_rect = Rect.new(0,0,self.bitmap.height,self.bitmap.height)
end
+9 -10
View File
@@ -24,15 +24,14 @@ class PokemonEggHatch_Scene
@sprites["pokemon"].setOffset(PictureOrigin::Bottom)
@sprites["pokemon"].x = Graphics.width/2
@sprites["pokemon"].y = 264+56 # 56 to offset the egg sprite
@sprites["pokemon"].setSpeciesBitmap(@pokemon.species,@pokemon.female?,
(@pokemon.form rescue 0),@pokemon.shiny?,
false,false,true) # Egg sprite
@sprites["pokemon"].setSpeciesBitmap(@pokemon.species, @pokemon.gender,
@pokemon.form, @pokemon.shiny?,
false, false, true) # Egg sprite
# Load egg cracks bitmap
crackfilename=sprintf("Graphics/Battlers/%seggCracks",
getConstantName(PBSpecies,@pokemon.species)) rescue nil
crackfilename = sprintf("Graphics/Battlers/%seggCracks", @pokemon.species)
if !pbResolveBitmap(crackfilename)
crackfilename=sprintf("Graphics/Battlers/%03deggCracks",@pokemon.species)
crackfilename=sprintf("Graphics/Battlers/eggCracks") if !pbResolveBitmap(crackfilename)
crackfilename = sprintf("Graphics/Battlers/%03deggCracks", @pokemon.species_data.id_number)
crackfilename = sprintf("Graphics/Battlers/eggCracks") if !pbResolveBitmap(crackfilename)
end
crackfilename=pbResolveBitmap(crackfilename)
@hatchSheet=AnimatedBitmap.new(crackfilename)
@@ -90,7 +89,7 @@ class PokemonEggHatch_Scene
@sprites["pokemon"].setPokemonBitmap(@pokemon) # Pokémon sprite
@sprites["pokemon"].x = Graphics.width/2
@sprites["pokemon"].y = 264
pbApplyBattlerMetricsToSprite(@sprites["pokemon"],1,@pokemon.fSpecies)
@pokemon.species_data.apply_metrics_to_sprite(@sprites["pokemon"], 1)
@sprites["hatch"].visible=false
for i in 1..fadeTime
@sprites["pokemon"].tone=Tone.new(255-i*toneDiff,255-i*toneDiff,255-i*toneDiff)
@@ -100,8 +99,8 @@ class PokemonEggHatch_Scene
@sprites["pokemon"].tone=Tone.new(0,0,0)
@sprites["overlay"].opacity=0
# Finish scene
frames=pbCryFrameLength(@pokemon)
pbPlayCry(@pokemon)
frames = GameData::Species.cry_length(@pokemon)
GameData::Species.play_cry_from_pokemon(@pokemon)
updateScene(frames)
pbBGMStop()
pbMEPlay("Evolution success")
+7 -7
View File
@@ -532,7 +532,7 @@ class PokemonEvolutionScene
metaplayer1.play
metaplayer2.play
pbBGMStop
pbPlayCry(@pokemon)
GameData::Species.play_cry_from_pokemon(@pokemon)
pbMessageDisplay(@sprites["msgwindow"],
_INTL("\\se[]What? {1} is evolving!\\^",@pokemon.name)) { pbUpdate }
pbMessageWaitForInput(@sprites["msgwindow"],50,true) { pbUpdate }
@@ -567,17 +567,17 @@ class PokemonEvolutionScene
def pbEvolutionSuccess
# Play cry of evolved species
frames = pbCryFrameLength(@newspecies,@pokemon.form)
frames = GameData::Species.cry_length(@newspecies, @pokemon.form)
pbBGMStop
pbPlayCrySpecies(@newspecies,@pokemon.form)
GameData::Species.play_cry_from_species(@newspecies, @pokemon.form)
frames.times do
Graphics.update
pbUpdate
end
# Success jingle/message
pbMEPlay("Evolution success")
newspeciesname = PBSpecies.getName(@newspecies)
oldspeciesname = PBSpecies.getName(@pokemon.species)
newspeciesname = GameData::Species.get(@newspecies).name
is_nicknamed = @pokemon.nicknamed?
pbMessageDisplay(@sprites["msgwindow"],
_INTL("\\se[]Congratulations! Your {1} evolved into {2}!\\wt[80]",
@pokemon.name,newspeciesname)) { pbUpdate }
@@ -586,7 +586,7 @@ class PokemonEvolutionScene
pbEvolutionMethodAfterEvolution
# Modify Pokémon to make it evolved
@pokemon.species = @newspecies
@pokemon.name = newspeciesname if @pokemon.name==oldspeciesname
@pokemon.name = newspeciesname if !is_nicknamed
@pokemon.form = 0 if @pokemon.isSpecies?(:MOTHIM)
@pokemon.calcStats
# See and own evolved species
@@ -611,7 +611,7 @@ class PokemonEvolutionScene
def self.pbDuplicatePokemon(pkmn, new_species)
new_pkmn = pkmn.clone
new_pkmn.species = new_species
new_pkmn.name = PBSpecies.getName(new_species)
new_pkmn.name = GameData::Species.get(new_species).name
new_pkmn.markings = 0
new_pkmn.ballused = 0
new_pkmn.setItem(nil)
+14 -16
View File
@@ -41,14 +41,14 @@ class PokemonTrade_Scene
@sprites["rsprite1"].x = Graphics.width/2
@sprites["rsprite1"].y = 264
@sprites["rsprite1"].z = 10
pbApplyBattlerMetricsToSprite(@sprites["rsprite1"],1,@pokemon.fSpecies)
@pokemon.species_data.apply_metrics_to_sprite(@sprites["rsprite1"], 1)
@sprites["rsprite2"] = PokemonSprite.new(@viewport)
@sprites["rsprite2"].setPokemonBitmap(@pokemon2,false)
@sprites["rsprite2"].setOffset(PictureOrigin::Bottom)
@sprites["rsprite2"].x = Graphics.width/2
@sprites["rsprite2"].y = 264
@sprites["rsprite2"].z = 10
pbApplyBattlerMetricsToSprite(@sprites["rsprite2"],1,@pokemon2.fSpecies)
@pokemon2.species_data.apply_metrics_to_sprite(@sprites["rsprite2"], 1)
@sprites["rsprite2"].visible = false
@sprites["msgwindow"] = pbCreateMessageWindow(@viewport)
pbFadeInAndShow(@sprites)
@@ -139,8 +139,8 @@ class PokemonTrade_Scene
# Return Pokémon's color to normal and play cry
delay = picturePoke.totalDuration
picturePoke.moveColor(delay,5,Color.new(31*8,22*8,30*8,0))
cry = pbCryFile(@pokemon2)
picturePoke.setSE(delay,cry) if pbResolveAudioSE(cry)
cry = GameData::Species.cry_filename_from_pokemon(@pokemon2)
picturePoke.setSE(delay,cry) if cry
# Play animation
pbRunPictures(
[picturePoke,pictureBall],
@@ -155,7 +155,7 @@ class PokemonTrade_Scene
pbDisposeSpriteHash(@sprites)
@viewport.dispose
newspecies = pbTradeCheckEvolution(@pokemon2,@pokemon)
if newspecies>0
if newspecies
evo = PokemonEvolutionScene.new
evo.pbStartScreen(@pokemon2,newspecies)
evo.pbEvolution(false)
@@ -165,9 +165,9 @@ class PokemonTrade_Scene
def pbTrade
pbBGMStop
pbPlayCry(@pokemon)
speciesname1=PBSpecies.getName(@pokemon.species)
speciesname2=PBSpecies.getName(@pokemon2.species)
GameData::Species.play_cry_from_pokemon(@pokemon)
speciesname1=GameData::Species.get(@pokemon.species).name
speciesname2=GameData::Species.get(@pokemon2.species).name
pbMessageDisplay(@sprites["msgwindow"],
_ISPRINTF("{1:s}\r\nID: {2:05d} OT: {3:s}\\wtnp[0]",
@pokemon.name,@pokemon.owner.public_id,@pokemon.owner.name)) { pbUpdate }
@@ -193,17 +193,16 @@ def pbStartTrade(pokemonIndex,newpoke,nickname,trainerName,trainerGender=0)
myPokemon = $Trainer.party[pokemonIndex]
opponent = PokeBattle_Trainer.new(trainerName,trainerGender)
opponent.setForeignID($Trainer)
yourPokemon = nil; resetmoves = true
yourPokemon = nil
resetmoves = true
if newpoke.is_a?(Pokemon)
newpoke.owner = Pokemon::Owner.new_from_trainer(opponent)
yourPokemon = newpoke
resetmoves = false
else
if newpoke.is_a?(String) || newpoke.is_a?(Symbol)
raise _INTL("Species does not exist ({1}).",newpoke) if !hasConst?(PBSpecies,newpoke)
newpoke = getID(PBSpecies,newpoke)
end
yourPokemon = Pokemon.new(newpoke,myPokemon.level,opponent)
species_data = GameData::Species.try_get(newpoke)
raise _INTL("Species does not exist ({1}).", newpoke) if !species_data
yourPokemon = Pokemon.new(species_data.id, myPokemon.level, opponent)
end
yourPokemon.name = nickname
yourPokemon.obtainMode = 2 # traded
@@ -225,9 +224,8 @@ end
# Evolution methods
#===============================================================================
def pbTradeCheckEvolution(pkmn, other_pkmn)
ret = pbCheckEvolutionEx(pkmn) { |pkmn, method, parameter, new_species|
return pbCheckEvolutionEx(pkmn) { |pkmn, method, parameter, new_species|
success = PBEvolution.call("tradeCheck", method, pkmn, parameter, other_pkmn)
next (success) ? new_species : -1
}
return ret
end
@@ -1,10 +1,4 @@
def pbEachNaturalMove(pokemon)
movelist=pokemon.getMoveList
for i in movelist
yield i[1],i[0]
end
end
# Unused
def pbHasRelearnableMove?(pokemon)
return pbGetRelearnableMoves(pokemon).length>0
end
@@ -12,11 +6,10 @@ end
def pbGetRelearnableMoves(pokemon)
return [] if !pokemon || pokemon.egg? || pokemon.shadowPokemon?
moves=[]
pbEachNaturalMove(pokemon) { |move,level|
if level<=pokemon.level && !pokemon.hasMove?(move)
moves.push(move) if !moves.include?(move)
end
}
pokemon.getMoveList.each do |m|
next if m[0] > pokemon.level || pokemon.hasMove?(m[1])
moves.push(m[1]) if !moves.include?(m[1])
end
tmoves=[]
if pokemon.firstmoves
for i in pokemon.firstmoves
@@ -211,14 +211,12 @@ class PurifyChamber # German: der Kryptorbis
end
def debugAddShadow(set,species)
species=getID(PBSpecies,species)
pkmn=Pokemon.new(species,1)
pkmn.makeShadow
setShadow(set,pkmn)
end
def debugAddNormal(set,species)
species=getID(PBSpecies,species)
pkmn=Pokemon.new(species,1)
insertAfter(set,setCount(set),pkmn)
end
@@ -236,7 +236,7 @@ def pbRefreshMGCommands(master, online)
for gift in master
itemname = "BLANK"
if gift[1] == 0
itemname = PBSpecies.getName(gift[2].species)
itemname = gift[2].speciesName
elsif gift[1] > 0
itemname = GameData::Item.get(gift[2]).name + sprintf(" x%d", gift[1])
end
@@ -294,7 +294,7 @@ class HallOfFame_Scene
overlay=@sprites["overlay"].bitmap
overlay.clear
pokename=pokemon.name
speciesname=PBSpecies.getName(pokemon.species)
speciesname=pokemon.speciesName
if pokemon.male?
speciesname+=""
elsif pokemon.female?
@@ -373,7 +373,7 @@ class HallOfFame_Scene
if @battlerIndex<=@hallEntry.size
# If it is a pokémon, write the pokémon text, wait the
# ENTRYWAITTIME and goes to the next battler
pbPlayCry(@hallEntry[@battlerIndex-1])
GameData::Species.play_cry_from_pokemon(@hallEntry[@battlerIndex - 1])
writePokemonData(@hallEntry[@battlerIndex-1])
(ENTRYWAITTIME*Graphics.frame_rate/20).times do
Graphics.update
@@ -428,7 +428,7 @@ class HallOfFame_Scene
createBattlers(false)
end
# Change the pokemon
pbPlayCry(@hallEntry[@battlerIndex])
GameData::Species.play_cry_from_pokemon(@hallEntry[@battlerIndex])
setPokemonSpritesOpacity(@battlerIndex,OPACITY)
hallNumber=$PokemonGlobal.hallOfFameLastNumber + @hallIndex -
$PokemonGlobal.hallOfFame.size + 1
@@ -10,52 +10,48 @@ class TriadCard
attr_reader :north, :east, :south, :west
attr_reader :type
def initialize(species,form=0)
def initialize(species, form = 0)
@species = species
@form = form
baseStats = pbGetSpeciesData(species,form,SpeciesData::BASE_STATS)
species_data = GameData::Species.get_species_form(@species, @form)
baseStats = species_data.base_stats
hp = baseStats[PBStats::HP]
attack = baseStats[PBStats::ATTACK]
defense = baseStats[PBStats::DEFENSE]
spAtk = baseStats[PBStats::SPATK]
spDef = baseStats[PBStats::SPDEF]
speed = baseStats[PBStats::SPEED]
@type = pbGetSpeciesData(species,form,SpeciesData::TYPE1)
if @type == :NORMAL
type2 = pbGetSpeciesData(species,form,SpeciesData::TYPE2)
@type = type2 if type2
end
@west = baseStatToValue(attack+speed/3)
@east = baseStatToValue(defense+hp/3)
@north = baseStatToValue(spAtk+speed/3)
@south = baseStatToValue(spDef+hp/3)
@type = species_data.type1
@type = species_data.type2 if @type == :NORMAL && species_data.type2
@west = baseStatToValue(attack + speed / 3)
@east = baseStatToValue(defense + hp / 3)
@north = baseStatToValue(spAtk + speed / 3)
@south = baseStatToValue(spDef + hp / 3)
end
def baseStatToValue(stat)
return 10 if stat>=189
return 9 if stat>=160
return 8 if stat>=134
return 7 if stat>=115
return 6 if stat>=100
return 5 if stat>=86
return 4 if stat>=73
return 3 if stat>=60
return 2 if stat>=45
return 10 if stat >= 189
return 9 if stat >= 160
return 8 if stat >= 134
return 7 if stat >= 115
return 6 if stat >= 100
return 5 if stat >= 86
return 4 if stat >= 73
return 3 if stat >= 60
return 2 if stat >= 45
return 1
end
def attack(panel)
return [@west,@east,@north,@south][panel]
return [@west, @east, @north, @south][panel]
end
def defense(panel)
return [@east,@west,@south,@north][panel]
return [@east, @west, @south, @north][panel]
end
def bonus(opponent)
aType = @type
oType = opponent.type
case PBTypes.getEffectiveness(aType,oType)
case PBTypes.getEffectiveness(@type, opponent.type)
when PBTypeEffectiveness::INEFFECTIVE then return -2
when PBTypeEffectiveness::NOT_EFFECTIVE_ONE then return -1
when PBTypeEffectiveness::SUPER_EFFECTIVE_ONE then return 1
@@ -64,64 +60,63 @@ class TriadCard
end
def price
maxValue = [@north,@east,@south,@west].max
ret = @north*@north + @east*@east + @south*@south + @west*@west
ret += maxValue*maxValue*2
maxValue = [@north, @east, @south, @west].max
ret = @north * @north + @east * @east + @south * @south + @west * @west
ret += maxValue * maxValue * 2
ret *= maxValue
ret *= (@north+@east+@south+@west)
ret *= (@north + @east + @south + @west)
ret /= 10 # Ranges from 2 to 24,000
# Quantize prices to the next highest "unit"
if ret>10000; ret = (1+ret/1000)*1000
elsif ret>5000; ret = (1+ret/500)*500
elsif ret>1000; ret = (1+ret/100)*100
elsif ret>500; ret = (1+ret/50)*50
else; ret = (1+ret/10)*10
if ret > 10000; ret = (1 + ret / 1000) * 1000
elsif ret > 5000; ret = (1 + ret / 500) * 500
elsif ret > 1000; ret = (1 + ret / 100) * 100
elsif ret > 500; ret = (1 + ret / 50) * 50
else; ret = (1 + ret / 10) * 10
end
return ret
end
def self.createBack(type = nil, noback = false)
bitmap = BitmapWrapper.new(80,96)
bitmap = BitmapWrapper.new(80, 96)
if !noback
cardbitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/triad_card_opponent"))
bitmap.blt(0,0,cardbitmap.bitmap,Rect.new(0,0,cardbitmap.width,cardbitmap.height))
bitmap.blt(0, 0, cardbitmap.bitmap, Rect.new(0, 0, cardbitmap.width, cardbitmap.height))
cardbitmap.dispose
end
if type
typebitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/types"))
type_number = GameData::Type.get(type).id_number
typerect = Rect.new(0, type_number * 28, 64, 28)
bitmap.blt(8,50,typebitmap.bitmap,typerect,192)
bitmap.blt(8, 50, typebitmap.bitmap, typerect, 192)
typebitmap.dispose
end
return bitmap
end
def createBitmap(owner)
return TriadCard.createBack if owner==0
bitmap = BitmapWrapper.new(80,96)
if owner==2 # Opponent
return TriadCard.createBack if owner == 0
bitmap = BitmapWrapper.new(80, 96)
if owner == 2 # Opponent
cardbitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/triad_card_opponent"))
else # Player
else # Player
cardbitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/triad_card_player"))
end
typebitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/types"))
iconfile = pbCheckPokemonIconFiles([@species,0,false,@form,false])
iconbitmap = AnimatedBitmap.new(iconfile)
iconbitmap = AnimatedBitmap.new(GameData::Species.icon_filename(@species, @form))
numbersbitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/triad_numbers"))
# Draw card background
bitmap.blt(0,0,cardbitmap.bitmap,Rect.new(0,0,cardbitmap.width,cardbitmap.height))
bitmap.blt(0, 0, cardbitmap.bitmap, Rect.new(0, 0, cardbitmap.width, cardbitmap.height))
# Draw type icon
type_number = GameData::Type.get(@type).id_number
typerect = Rect.new(0,type_number*28,64,28)
bitmap.blt(8,50,typebitmap.bitmap,typerect,192)
typerect = Rect.new(0, type_number * 28, 64, 28)
bitmap.blt(8, 50, typebitmap.bitmap, typerect, 192)
# Draw Pokémon icon
bitmap.blt(8,24,iconbitmap.bitmap,Rect.new(0,0,64,64))
bitmap.blt(8, 24, iconbitmap.bitmap, Rect.new(0, 0, 64, 64))
# Draw numbers
bitmap.blt(8,16,numbersbitmap.bitmap,Rect.new(@west*16,0,16,16))
bitmap.blt(22,6,numbersbitmap.bitmap,Rect.new(@north*16,0,16,16))
bitmap.blt(36,16,numbersbitmap.bitmap,Rect.new(@east*16,0,16,16))
bitmap.blt(22,26,numbersbitmap.bitmap,Rect.new(@south*16,0,16,16))
bitmap.blt(8, 16, numbersbitmap.bitmap, Rect.new(@west * 16, 0, 16, 16))
bitmap.blt(22, 6, numbersbitmap.bitmap, Rect.new(@north * 16, 0, 16, 16))
bitmap.blt(36, 16, numbersbitmap.bitmap, Rect.new(@east * 16, 0, 16, 16))
bitmap.blt(22, 26, numbersbitmap.bitmap, Rect.new(@south * 16, 0, 16, 16))
cardbitmap.dispose
typebitmap.dispose
iconbitmap.dispose
@@ -218,7 +213,7 @@ class TriadScene
def pbDisplay(text)
@sprites["helpwindow"].text = text
(Graphics.frame_rate*3/2).times do
(Graphics.frame_rate*1.5).floor.times do
Graphics.update
Input.update
pbUpdate
@@ -254,7 +249,7 @@ class TriadScene
commands = []
chosenCards = []
for item in cardStorage
commands.push(_INTL("{1} x{2}",PBSpecies.getName(item[0]),item[1]))
commands.push(_INTL("{1} x{2}", GameData::Species.get(item[0]).name, item[1]))
end
command = Window_CommandPokemonEx.newWithSize(commands,0,0,Graphics.width/2,Graphics.height-64,@viewport)
@sprites["helpwindow"].text = _INTL("Choose {1} cards to use for this duel.",@battle.maxCards)
@@ -288,7 +283,7 @@ class TriadScene
@battle.pbAdd(cardStorage,item)
commands = []
for item in cardStorage
commands.push(_INTL("{1} x{2}",PBSpecies.getName(item[0]),item[1]))
commands.push(_INTL("{1} x{2}", GameData::Species.get(item[0]).name, item[1]))
end
command.commands = commands
index = -1
@@ -310,7 +305,7 @@ class TriadScene
@battle.pbSubtract(cardStorage,item[0])
commands = []
for item in cardStorage
commands.push(_INTL("{1} x{2}",PBSpecies.getName(item[0]),item[1]))
commands.push(_INTL("{1} x{2}", GameData::Species.get(item[0]).name, item[1]))
end
command.commands = commands
command.index = commands.length-1 if command.index>=commands.length
@@ -670,11 +665,6 @@ class TriadScreen
# -2 - Immune
# attack += attacker.bonus(defender)
end
# p [attacker.card.north,attacker.card.west,
# attacker.card.east,attacker.card.south],
# [defender.card.north,defender.card.west,
# defender.card.east,defender.card.south],
# [attack,defense,attacker.bonus(defender)] if attackerParam==nil
if attack>defense || (attack==defense && @sameWins)
flips.push([defenderX,defenderY])
if attackerParam==nil
@@ -736,8 +726,9 @@ class TriadScreen
if @elements
loop do
trial_type = type_keys[rand(type_keys.length)]
break if !PBTypes.isPseudoType?(trial_type)
next if PBTypes.isPseudoType?(trial_type)
square.type = GameData::Type.get(trial_type).id
break
end
end
@board.push(square)
@@ -765,40 +756,35 @@ class TriadScreen
if oppdeck && oppdeck.is_a?(Array) && oppdeck.length==self.maxCards # Preset
opponentCards = []
for i in oppdeck
card = getID(PBSpecies,i)
if card<=0
species_data = GameData::Species.try_get(i)
if !species_data
@scene.pbDisplayPaused(_INTL("Opponent has an illegal card, \"{1}\".",i))
@scene.pbEndScene
return 0
end
opponentCards.push(card)
opponentCards.push(species_data.id)
end
else
species_keys = GameData::Species::DATA.keys
candidates = []
while candidates.length<200
card = 0
loop do
card = rand(PBSpecies.maxValue)+1
cname = getConstantName(PBSpecies,card) rescue nil
break if cname
end
while candidates.length < 200
card = species_keys[rand(species_keys.length)]
card = GameData::Species.get(card).id # Make sure it's a symbol
triad = TriadCard.new(card)
total = triad.north+triad.south+triad.east+triad.west
total = triad.north + triad.south + triad.east + triad.west
# Add random species and its total point count
candidates.push([card,total])
if candidates.length<200 && $Trainer.owned[card]
# Add again if Trainer owns the species
candidates.push([card,total])
candidates.push([card, total])
if candidates.length < 200 && $Trainer.owned[card]
# Add again if player owns the species
candidates.push([card, total])
end
end
# sort by total point count
candidates.sort! { |a,b| a[1]<=>b[1] }
minIndex = minLevel*20
maxIndex = maxLevel*20+20
candidates.sort! { |a,b| a[1] <=> b[1] }
opponentCards = []
self.maxCards.times do
# generate random card based on level
index = minIndex+rand(maxIndex-minIndex)
# Choose random card from candidates based on trainer's level
index = minLevel + rand(20)
opponentCards.push(candidates[index][0])
end
end
@@ -808,13 +794,8 @@ class TriadScreen
@scene.pbShowOpponentCards(opponentCards)
@scene.pbDisplay(_INTL("Choosing the starting player..."))
@scene.pbUpdateScore
playerTurn = false
if rand(2)==0
@scene.pbDisplay(_INTL("{1} will go first.",@playerName))
playerTurn = true
else
@scene.pbDisplay(_INTL("{1} will go first.",@opponentName))
end
playerTurn = (rand(2) == 0)
@scene.pbDisplay(_INTL("{1} will go first.", (playerTurn) ? @playerName : @opponentName))
for i in 0...@width*@height
position = nil
triadCard = nil
@@ -896,7 +877,8 @@ class TriadScreen
end
for i in 0...@width*@height
if board[i].owner==1
$PokemonGlobal.triads.pbStoreItem(board[i].card.species)
card = GameData::Species.get_species_form(board[i].card.species, board[i].card.form).id
$PokemonGlobal.triads.pbStoreItem(card)
end
end
@scene.pbDisplayPaused(_INTL("Kept all cards of your color."))
@@ -905,17 +887,16 @@ class TriadScreen
@scene.pbDisplayPaused(_INTL("{1} won against {2}.",@playerName,@opponentName))
result = 1
if prize
card = getID(PBSpecies,prize)
if card>0 && $PokemonGlobal.triads.pbStoreItem(card)
cardname = PBSpecies.getName(card)
@scene.pbDisplayPaused(_INTL("Got opponent's {1} card.",cardname))
species_data = GameData::Species.try_get(prize)
if species_data && $PokemonGlobal.triads.pbStoreItem(species_data.id)
@scene.pbDisplayPaused(_INTL("Got opponent's {1} card.", species_data.name))
end
else
case @trade
when 0 # Gain 1 random card from opponent's deck
card = originalOpponentCards[rand(originalOpponentCards.length)]
if $PokemonGlobal.triads.pbStoreItem(card)
cardname = PBSpecies.getName(card)
cardname = GameData::Species.get(card).name
@scene.pbDisplayPaused(_INTL("Got opponent's {1} card.",cardname))
end
when 1 # Keep only cards of your color
@@ -927,7 +908,8 @@ class TriadScreen
end
for i in 0...@width*@height
if board[i].owner==1
$PokemonGlobal.triads.pbStoreItem(board[i].card.species)
card = GameData::Species.get_species_form(board[i].card.species, board[i].card.form).id
$PokemonGlobal.triads.pbStoreItem(card)
end
end
@scene.pbDisplayPaused(_INTL("Kept all cards of your color."))
@@ -945,7 +927,7 @@ class TriadScreen
when 0 # Lose 1 random card from your deck
card = originalCards[rand(originalCards.length)]
$PokemonGlobal.triads.pbDeleteItem(card)
cardname = PBSpecies.getName(card)
cardname = GameData::Species.get(card).name
@scene.pbDisplayPaused(_INTL("Opponent won your {1} card.",cardname))
when 1 # Keep only cards of your color
for card in originalCards
@@ -956,7 +938,8 @@ class TriadScreen
end
for i in 0...@width*@height
if board[i].owner==1
$PokemonGlobal.triads.pbStoreItem(board[i].card.species)
card = GameData::Species.get_species_form(board[i].card.species, board[i].card.form).id
$PokemonGlobal.triads.pbStoreItem(card)
end
end
@scene.pbDisplayPaused(_INTL("Kept all cards of your color.",cardname))
@@ -1009,51 +992,45 @@ class TriadStorage
end
def maxSize
return PBSpecies.getCount
return @items.length + 1
end
def maxPerSlot
return 99
return 999
end
def empty?
return @items.length==0
return @items.length == 0
end
def length
@items.length
return @items.length
end
def [](i)
@items[i]
return @items[i]
end
def getItem(index)
if index<0 || index>=@items.length
return 0
else
return @items[index][0]
end
return nil if index < 0 || index >= @items.length
return @items[index][0]
end
def getCount(index)
if index<0 || index>=@items.length
return 0
else
return @items[index][1]
end
return 0 if index < 0 || index >= @items.length
return @items[index][1]
end
def pbQuantity(item)
return ItemStorageHelper.pbQuantity(@items, item)
end
def pbCanStore?(item,qty=1)
return ItemStorageHelper.pbCanStore?(@items,self.maxSize,self.maxPerSlot,item,qty)
def pbCanStore?(item, qty = 1)
return ItemStorageHelper.pbCanStore?(@items, self.maxSize, self.maxPerSlot, item, qty)
end
def pbStoreItem(item,qty=1)
return ItemStorageHelper.pbStoreItem(@items,self.maxSize,self.maxPerSlot,item,qty)
def pbStoreItem(item, qty = 1)
return ItemStorageHelper.pbStoreItem(@items, self.maxSize, self.maxPerSlot, item, qty)
end
def pbDeleteItem(item, qty = 1)
@@ -1069,20 +1046,17 @@ end
def pbBuyTriads
commands = []
realcommands = []
for i in 1..PBSpecies.maxValue
next if !$Trainer.owned[i]
speciesname = PBSpecies.getName(i)
next if !speciesname
GameData::Species.each do |s|
next if s.form != 0
next if !$Trainer.owned[s.id]
price = TriadCard.new(i).price
visprice = price.to_s_formatted
commands.push([price,speciesname,_INTL("{1} - ${2}",speciesname,visprice),i])
commands.push([price, s.name, _INTL("{1} - ${2}", s.name, price.to_s_formatted), s.id])
end
if commands.length==0
if commands.length == 0
pbMessage(_INTL("There are no cards that you can buy."))
return
end
commands.sort! { |a,b| a[1]<=>b[1] } # name
# commands.sort! { |a,b| (a[0]==b[0]) ? a[1]<=>b[1] : a[0]<=>b[0] } # name : price
commands.sort! { |a, b| a[1] <=> b[1] } # Sort alphabetically
for command in commands
realcommands.push(command[2])
end
@@ -1164,8 +1138,8 @@ def pbSellTriads
commands = []
for i in 0...$PokemonGlobal.triads.length
item = $PokemonGlobal.triads[i]
speciesname = PBSpecies.getName(item[0])
commands.push(_INTL("{1} x{2}",speciesname,item[1]))
speciesname = GameData::Species.get(item[0]).name
commands.push(_INTL("{1} x{2}", speciesname, item[1]))
end
commands.push(_INTL("CANCEL"))
if commands.length==1
@@ -1188,7 +1162,7 @@ def pbSellTriads
preview.z = 4
item = $PokemonGlobal.triads.getItem(cmdwindow.index)
preview.bitmap = TriadCard.new(item).createBitmap(1)
olditem = commands[cmdwindow.index][3]
olditem = $PokemonGlobal.triads.getItem(cmdwindow.index)
done = false
Graphics.frame_reset
while !done
@@ -1199,9 +1173,9 @@ def pbSellTriads
cmdwindow.update
goldwindow.update
item = $PokemonGlobal.triads.getItem(cmdwindow.index)
if item!=olditem
if olditem != item
preview.bitmap.dispose if preview.bitmap
if item>0
if item
preview.bitmap = TriadCard.new(item).createBitmap(1)
end
olditem = item
@@ -1216,7 +1190,7 @@ def pbSellTriads
break
end
item = $PokemonGlobal.triads.getItem(cmdwindow.index)
itemname = PBSpecies.getName(item)
itemname = GameData::Species.get(item).name
quantity = $PokemonGlobal.triads.pbQuantity(item)
price = TriadCard.new(item).price
if price==0
@@ -1244,7 +1218,7 @@ def pbSellTriads
commands = []
for i in 0...$PokemonGlobal.triads.length
item = $PokemonGlobal.triads[i]
speciesname = PBSpecies.getName(item[0])
speciesname = GameData::Species.get(item[0]).name
commands.push(_INTL("{1} x{2}",speciesname,item[1]))
end
commands.push(_INTL("CANCEL"))
@@ -1268,7 +1242,7 @@ def pbTriadList
commands = []
for i in 0...$PokemonGlobal.triads.length
item = $PokemonGlobal.triads[i]
speciesname = PBSpecies.getName(item[0])
speciesname = GameData::Species.get(item[0]).name
commands.push(_INTL("{1} x{2}",speciesname,item[1]))
end
commands.push(_INTL("CANCEL"))
@@ -1315,10 +1289,10 @@ end
#===============================================================================
# Give the player a particular card
#===============================================================================
def pbGiveTriadCard(species,quantity=1)
species = getID(PBSpecies,species)
return false if !species || species<=0
return false if !$PokemonGlobal.triads.pbCanStore?(species,quantity)
$PokemonGlobal.triads.pbStoreItem(species,quantity)
def pbGiveTriadCard(species, quantity = 1)
sp = GameData::Species.try_get(species)
return false if !sp
return false if !$PokemonGlobal.triads.pbCanStore?(sp.id, quantity)
$PokemonGlobal.triads.pbStoreItem(sp.id, quantity)
return true
end
@@ -135,16 +135,12 @@ class BugContestState
else
$game_variables[1]=ContestantNames[cont]
end
$game_variables[2]=PBSpecies.getName(@places[place][1])
$game_variables[2]=GameData::Species.get(@places[place][1]).name
$game_variables[3]=@places[place][2]
end
def pbClearIfEnded
if !@inProgress
if !(@start && @start[0]==$game_map.map_id)
clear
end
end
clear if !@inProgress && (!@start || @start[0] != $game_map.map_id)
end
def pbStartJudging
@@ -263,18 +259,17 @@ end
# Returns a score for this Pokemon in the Bug Catching Contest.
# Not exactly the HGSS calculation, but it should be decent enough.
def pbBugContestScore(pokemon)
levelscore=pokemon.level*4
ivscore=0
for i in pokemon.iv; ivscore+=i; end
ivscore=(ivscore*100/186).floor
hpscore=(100*pokemon.hp/pokemon.totalhp).floor
rareness = pbGetSpeciesData(pokemon.species,pokemon.form,SpeciesData::RARENESS)
rarescore=60
rarescore+=20 if rareness<=120
rarescore+=20 if rareness<=60
score=levelscore+ivscore+hpscore+rarescore
return score
def pbBugContestScore(pkmn)
levelscore = pkmn.level * 4
ivscore = 0
pkmn.iv.each { |iv| ivscore += iv.to_f / Pokemon::IV_STAT_LIMIT }
ivscore = (ivscore * 100).floor
hpscore = (100.0 * pkmn.hp / pkmn.totalhp).floor
catch_rate = pkmn.species_data.catch_rate
rarescore = 60
rarescore += 20 if catch_rate <= 120
rarescore += 20 if catch_rate <= 60
return levelscore + ivscore + hpscore + rarescore
end
def pbBugContestState
@@ -32,10 +32,7 @@ class PBPokemon
def self.fromInspected(str)
insp=str.gsub(/^\s+/,"").gsub(/\s+$/,"")
pieces=insp.split(/\s*;\s*/)
species=1
if (PBSpecies.const_defined?(pieces[0]) rescue false)
species=PBSpecies.const_get(pieces[0])
end
species = (GameData::Species.exists?(pieces[0])) ? GameData::Species.get(pieces[0]).id : nil
item = (GameData::Item.exists?(pieces[1])) ? GameData::Item.get(pieces[1]).id : nil
nature=PBNatures.const_get(pieces[2])
ev=pieces[3].split(/\s*,\s*/)
@@ -95,7 +92,7 @@ class PBPokemon
def self.fromstring(str)
s=str.split(/\s*,\s*/)
species=self.constFromStr(PBSpecies,s[1])
species=GameData::Species.get(s[1]).id
item=s[2].to_sym
nature=self.constFromStr(PBNatures,s[3])
move1=GameData::Move.get(s[4]).id
@@ -129,8 +126,8 @@ class PBPokemon
=end
def inspect
c1=getConstantName(PBSpecies,@species)
c2=(@item) ? GameData::Item.get(@item).id_to_s : ""
c1=GameData::Species.get(@species).id.to_s
c2=(@item) ? GameData::Item.get(@item).id.to_s : ""
c3=getConstantName(PBNatures,@nature)
evlist=""
for i in 0...@ev
@@ -1,26 +1,22 @@
def pbBaseStatTotal(species)
baseStats = pbGetSpeciesData(species,0,SpeciesData::BASE_STATS)
baseStats = GameData::Species.get(species).base_stats
ret = 0
baseStats.each { |s| ret += s }
return ret
end
def pbBalancedLevelFromBST(species)
return (113-(pbBaseStatTotal(species)*0.072)).round
return (113 - (pbBaseStatTotal(species) * 0.072)).round
end
def pbTooTall?(pkmn,maxHeightInMeters)
species = (pkmn.is_a?(Pokemon)) ? pkmn.species : pkmn
form = (pkmn.is_a?(Pokemon)) ? pkmn.form : 0
height = pbGetSpeciesData(species,form,SpeciesData::HEIGHT)
return height>(maxHeightInMeters*10).round
def pbTooTall?(pkmn, maxHeightInMeters)
height = (pkmn.is_a?(Pokemon)) ? pkmn.height : GameData::Species.get(pkmn).height
return height > (maxHeightInMeters * 10).round
end
def pbTooHeavy?(pkmn,maxWeightInKg)
species = (pkmn.is_a?(Pokemon)) ? pkmn.species : pkmn
form = (pkmn.is_a?(Pokemon)) ? pkmn.form : 0
weight = pbGetSpeciesData(species,form,SpeciesData::WEIGHT)
return weight>(maxWeightInKg*10).round
def pbTooHeavy?(pkmn, maxWeightInKg)
weight = (pkmn.is_a?(Pokemon)) ? pkmn.weight : GameData::Species.get(pkmn).weight
return weight > (maxWeightInKg * 10).round
end
@@ -287,10 +283,7 @@ class SpeciesRestriction
end
def isSpecies?(species,specieslist)
for s in specieslist
return true if isConst?(species,PBSpecies,s)
end
return false
return specieslist.include?(species)
end
def isValid?(pokemon)
@@ -310,10 +303,7 @@ class BannedSpeciesRestriction
end
def isSpecies?(species,specieslist)
for s in specieslist
return true if isConst?(species,PBSpecies,s)
end
return false
return specieslist.include?(species)
end
def isValid?(pokemon)
@@ -328,17 +318,17 @@ end
class BannedItemRestriction
def initialize(*specieslist)
@specieslist=specieslist.clone
def initialize(*itemlist)
@itemlist=itemlist.clone
end
def isSpecies?(species,specieslist)
return specieslist.any? { |s| species == s }
def isSpecies?(item,itemlist)
return itemlist.include?(item)
end
def isValid?(pokemon)
count=0
if pokemon.item && isSpecies?(pokemon.item,@specieslist)
if pokemon.item && isSpecies?(pokemon.item,@itemlist)
count+=1
end
return count==0
@@ -354,10 +344,7 @@ class RestrictedSpeciesRestriction
end
def isSpecies?(species,specieslist)
for s in specieslist
return true if isConst?(species,PBSpecies,s)
end
return false
return specieslist.include?(species)
end
def isValid?(team)
@@ -390,29 +377,22 @@ end
class StandardRestriction
def isValid?(pokemon)
return false if !pokemon || pokemon.egg?
def isValid?(pkmn)
return false if !pkmn || pkmn.egg?
# Species with disadvantageous abilities are not banned
abilities = pbGetSpeciesData(pokemon.species,pokemon.form,SpeciesData::ABILITIES)
abilities = [abilities] if !abilities.is_a?(Array)
abilities.each do |a|
return true if [:TRUANT, :SLOWSTART].include?(a)
pkmn.species_data.abilities.each do |a|
return true if [:TRUANT, :SLOWSTART].include?(a[0])
end
# Certain named species are not banned
speciesWhitelist = [:DRAGONITE,:SALAMENCE,:TYRANITAR]
for i in speciesWhitelist
return true if pokemon.isSpecies?(i)
end
speciesWhitelist = [:DRAGONITE, :SALAMENCE, :TYRANITAR]
return true if speciesWhitelist.include?(pkmn.species)
# Certain named species are banned
speciesBlacklist = [:WYNAUT,:WOBBUFFET]
for i in speciesBlacklist
return false if pokemon.isSpecies?(i)
end
speciesBlacklist = [:WYNAUT, :WOBBUFFET]
return false if speciesBlacklist.include?(pkmn.species)
# Species with total base stat 600 or more are banned
baseStats = pbGetSpeciesData(pokemon.species,pokemon.form,SpeciesData::BASE_STATS)
bst = 0
baseStats.each { |s| bst += s }
return false if bst>=600
pkmn.baseStats.each { |s| bst += s }
return false if bst >= 600
# Is valid
return true
end
@@ -632,28 +612,23 @@ end
module NicknameChecker
@@names={}
@@namesMaxValue=0
@@names = {}
def getName(species)
n=@@names[species]
n = @@names[species]
return n if n
n=PBSpecies.getName(species)
@@names[species]=n.upcase
n = GameData::Species.get(species).name
@@names[species] = n.upcase
return n
end
def check(name,species)
name=name.upcase
return true if name==getName(species)
if @@names.values.include?(name)
return false
end
for i in @@namesMaxValue..PBSpecies.maxValue
if i!=species
n=getName(i)
return false if n==name
end
def check(name, species)
name = name.upcase
return true if name == getName(species)
return false if @@names.values.include?(name)
GameData::Species.each do |species_data|
next if species_data.species == species || species_data.form != 0
return false if getName(species_data.id) == name
end
return true
end
@@ -40,35 +40,31 @@ def addMove(moves,move,base)
end
end
$legalMoves = []
$legalMoves = {}
$legalMovesLevel = 0
$baseStatTotal = []
$minimumLevel = []
$babySpecies = []
$evolutions = []
$baseStatTotal = {}
$minimumLevel = {}
$babySpecies = {}
$evolutions = {}
$tmMoves = nil
def pbGetLegalMoves2(species,maxlevel)
moves=[]
return moves if !species || species<=0
moveset = pbGetSpeciesMoveset(species)
moveset.each { |m| addMove(moves,m[1],2) if m[0]<=maxlevel }
tmData=pbLoadSpeciesTMData
species_data = GameData::Species.get(species)
moves = []
return moves if !species_data
# Populate available moves array (moves)
species_data.moves.each { |m| addMove(moves, m[1], 2) if m[0] <= maxlevel }
if !$tmMoves
$tmMoves=[]
GameData::Item.each do |i|
$tmMoves.push(i.move) if i.move && tmData[i.move]
end
end
for atk in $tmMoves
addMove(moves,atk,0) if tmData[atk].include?(species)
$tmMoves = []
GameData::Item.each { |i| $tmMoves.push(i.move) if i.is_machine? }
end
species_data.tutor_moves.each { |m| addMove(moves, m, 0) if $tmMoves.include?(m) }
babyspecies = babySpecies(species)
babyEggMoves = pbGetSpeciesEggMoves(babyspecies)
babyEggMoves.each { |m| addMove(moves,m,2) }
movedatas=[]
GameData::Species.get(babyspecies).egg_moves.each { |m| addMove(moves, m, 2) }
#
movedatas = []
for move in moves
movedatas.push([move,GameData::Move.get(move)])
movedatas.push([move, GameData::Move.get(move)])
end
# Delete less powerful moves
deleteAll=proc { |a,item|
@@ -101,32 +97,24 @@ def pbGetLegalMoves2(species,maxlevel)
return moves
end
def baseStatTotal(move)
if !$baseStatTotal[move]
$baseStatTotal[move]=pbBaseStatTotal(move)
end
return $baseStatTotal[move]
def baseStatTotal(species)
$baseStatTotal[species] = pbBaseStatTotal(species) if !$baseStatTotal[species]
return $baseStatTotal[species]
end
def babySpecies(move)
if !$babySpecies[move]
$babySpecies[move]=EvolutionHelper.baby_species(move)
end
return $babySpecies[move]
def babySpecies(species)
$babySpecies[species] = EvolutionHelper.baby_species(species) if !$babySpecies[species]
return $babySpecies[species]
end
def minimumLevel(move)
if !$minimumLevel[move]
$minimumLevel[move]=EvolutionHelper.minimum_level(move)
end
return $minimumLevel[move]
$minimumLevel[species] = EvolutionHelper.minimum_level(species) if !$minimumLevel[species]
return $minimumLevel[species]
end
def evolutions(move)
if !$evolutions[move]
$evolutions[move]=EvolutionHelper.evolutions(move, true)
end
return $evolutions[move]
def evolutions(species)
$evolutions[species] = EvolutionHelper.evolutions(species, true) if !$evolutions[species]
return $evolutions[species]
end
=begin
@@ -147,13 +135,14 @@ end
class BaseStatRestriction
def initialize(mn,mx)
@mn=mn;@mx=mx
def initialize(mn, mx)
@mn = mn
@mx = mx
end
def isValid?(pkmn)
bst=baseStatTotal(pkmn.species)
return bst>=@mn && bst<=@mx
bst = baseStatTotal(pkmn.species)
return bst >= @mn && bst <= @mx
end
end
@@ -162,9 +151,7 @@ end
class NonlegendaryRestriction
def isValid?(pkmn)
return true if !pkmn.genderless?
compatibility = pbGetSpeciesData(pkmn.species,pkmn.form,SpeciesData::COMPATIBILITY)
compatibility = [compatibility] if !compatibility.is_a?(Array)
compatibility.each { |c| return false if isConst?(c,PBEggGroups,:Undiscovered) }
return false if pkmn.species_data.egg_groups.include?(PBEggGroups::Undiscovered)
return true
end
end
@@ -260,14 +247,13 @@ def pbRandomPokemonFromRule(rule,trainer)
iteration=-1
loop do
iteration+=1
species=0
species=nil
level=rule.ruleset.suggestedLevel
keys = GameData::Species::DATA.keys.sort
loop do
species=0
loop do
species=rand(PBSpecies.maxValue)+1
cname=getConstantName(PBSpecies,species) rescue nil
break if cname
species = keys[rand(keys.length)]
break if GameData::Species.get(species).form == 0
end
r=rand(20)
bst=baseStatTotal(species)
@@ -299,7 +285,7 @@ def pbRandomPokemonFromRule(rule,trainer)
break
end
item = nil
$legalMoves=[] if level!=$legalMovesLevel
$legalMoves={} if level!=$legalMovesLevel
$legalMoves[species]=pbGetLegalMoves2(species,level) if !$legalMoves[species]
itemlist=[
:ORANBERRY,:SITRUSBERRY,:ADAMANTORB,:BABIRIBERRY,
@@ -322,38 +308,33 @@ def pbRandomPokemonFromRule(rule,trainer)
next if !item
case item
when :LIGHTBALL
next if !isConst?(species,PBSpecies,:PIKACHU)
next if species != :PIKACHU
when :SHEDSHELL
next if !isConst?(species,PBSpecies,:FORRETRESS) ||
!isConst?(species,PBSpecies,:SKARMORY)
next if species != :FORRETRESS && species != :SKARMORY
when :SOULDEW
next if !isConst?(species,PBSpecies,:LATIOS) ||
!isConst?(species,PBSpecies,:LATIAS)
next if species != :LATIOS && species != :LATIAS
when :FOCUSSASH
next if baseStatTotal(species)>450 && rand(10)<8
when :ADAMANTORB
next if !isConst?(species,PBSpecies,:DIALGA)
next if species != :DIALGA
when :PASSHOBERRY
next if !isConst?(species,PBSpecies,:STEELIX)
next if species != :STEELIX
when :BABIRIBERRY
next if !isConst?(species,PBSpecies,:TYRANITAR)
next if species != :TYRANITAR
when :HABANBERRY
next if !isConst?(species,PBSpecies,:GARCHOMP)
next if species != :GARCHOMP
when :OCCABERRY
next if !isConst?(species,PBSpecies,:METAGROSS)
next if species != :METAGROSS
when :CHOPLEBERRY
next if !isConst?(species,PBSpecies,:UMBREON)
next if species != :UMBREON
when :YACHEBERRY
next if !isConst?(species,PBSpecies,:TORTERRA) &&
!isConst?(species,PBSpecies,:GLISCOR) &&
!isConst?(species,PBSpecies,:DRAGONAIR)
next if species != :TORTERRA && species != :GLISCOR && species != :DRAGONAIR
when :SHUCABERRY
next if !isConst?(species,PBSpecies,:HEATRAN)
next if species != :HEATRAN
when :DEEPSEATOOTH
next if !isConst?(species,PBSpecies,:CLAMPERL)
next if species != :CLAMPERL
when :THICKCLUB
next if !isConst?(species,PBSpecies,:CUBONE) &&
!isConst?(species,PBSpecies,:MAROWAK)
next if species != :CUBONE && species != :MAROWAK
end
if item == :LIECHIBERRY && (ev&0x02)==0
next if rand(2)==0
@@ -459,8 +440,8 @@ def pbRandomPokemonFromRule(rule,trainer)
item = :LEFTOVERS
end
if item == :BLACKSLUDGE
type1 = pbGetSpeciesData(species,0,SpeciesData::TYPE1)
type2 = pbGetSpeciesData(species,0,SpeciesData::TYPE2) || type1
type1 = GameData::Species.get(species).type1
type2 = GameData::Species.get(species).type2 || type1
item = :LEFTOVERS if type1 != :POISON && type2 != :POISON
end
if item == :HEATROCK && !moves.any? { |m| m == :SUNNYDAY }
@@ -912,9 +893,10 @@ def pbRuledBattle(team1,team2,rule)
end
def getTypes(species)
type1 = pbGetSpeciesData(species,0,SpeciesData::TYPE1)
type2 = pbGetSpeciesData(species,0,SpeciesData::TYPE2) || type1
return type1==type2 ? [type1] : [type1,type2]
species_data = GameData::Species.get(species)
type1 = species_data.type1
type2 = species_data.type2
return (type1 == type2) ? [type1] : [type1, type2]
end
def pbTrainerInfo(pokemonlist,trfile,rules)
@@ -72,19 +72,15 @@ class BattleSwapScene
UIHelper.pbConfirm(@sprites["msgwindow"],message) { pbUpdate }
end
def pbGetCommands(list,choices)
commands=[]
def pbGetCommands(list, choices)
commands = []
for i in 0...list.length
pkmn=list[i]
kind=pbGetMessage(MessageTypes::Kinds,pbGetFSpeciesFromForm(pkmn.species,pkn.form))
selected=shadowctagFromColor(Color.new(232,0,0))
if choices.any?{ |item| item==i }
commands.push(selected+_INTL("{1} - {2} POKéMON",
PBSpecies.getName(pkmn.species),kind))
else
commands.push(_INTL("{1} - {2} POKéMON",
PBSpecies.getName(pkmn.species),kind))
end
pkmn = list[i]
category = pkmn.species_data.category
selected = shadowctagFromColor(Color.new(232, 0, 0))
cmd = _INTL("{1} - {2} Pokémon", pkmn.speciesName, category)
cmd = selected + cmd if choices.include?(i)
commands.push(cmd)
end
return commands
end
@@ -0,0 +1,154 @@
#===============================================================================
# Load various wild battle music
#===============================================================================
def pbGetWildBattleBGM(_wildParty) # wildParty is an array of Pokémon objects
if $PokemonGlobal.nextBattleBGM
return $PokemonGlobal.nextBattleBGM.clone
end
ret = nil
if !ret
# Check map metadata
music = GameData::MapMetadata.get($game_map.map_id).wild_battle_BGM
ret = pbStringToAudioFile(music) if music && music!=""
end
if !ret
# Check global metadata
music = GameData::Metadata.get.wild_battle_BGM
ret = pbStringToAudioFile(music) if music && music!=""
end
ret = pbStringToAudioFile("Battle wild") if !ret
return ret
end
def pbGetWildVictoryME
if $PokemonGlobal.nextBattleME
return $PokemonGlobal.nextBattleME.clone
end
ret = nil
if !ret
# Check map metadata
music = GameData::MapMetadata.get($game_map.map_id).wild_victory_ME
ret = pbStringToAudioFile(music) if music && music!=""
end
if !ret
# Check global metadata
music = GameData::Metadata.get.wild_victory_ME
ret = pbStringToAudioFile(music) if music && music!=""
end
ret = pbStringToAudioFile("Battle victory") if !ret
ret.name = "../../Audio/ME/"+ret.name
return ret
end
def pbGetWildCaptureME
if $PokemonGlobal.nextBattleCaptureME
return $PokemonGlobal.nextBattleCaptureME.clone
end
ret = nil
if !ret
# Check map metadata
music = GameData::MapMetadata.get($game_map.map_id).wild_capture_ME
ret = pbStringToAudioFile(music) if music && music!=""
end
if !ret
# Check global metadata
music = GameData::Metadata.get.wild_capture_ME
ret = pbStringToAudioFile(music) if music && music!=""
end
ret = pbStringToAudioFile("Battle capture success") if !ret
ret.name = "../../Audio/ME/"+ret.name
return ret
end
#===============================================================================
# Load/play various trainer battle music
#===============================================================================
def pbPlayTrainerIntroME(trainer_type)
trainer_type_data = GameData::TrainerType.get(trainer_type)
return if !trainer_type_data.intro_ME || trainer_type_data.intro_ME == ""
bgm = pbStringToAudioFile(trainer_type_data.intro_ME)
pbMEPlay(bgm)
end
def pbGetTrainerBattleBGM(trainer) # can be a PokeBattle_Trainer or an array of them
if $PokemonGlobal.nextBattleBGM
return $PokemonGlobal.nextBattleBGM.clone
end
ret = nil
music = nil
trainerarray = (trainer.is_a?(Array)) ? trainer : [trainer]
trainerarray.each do |t|
trainer_type_data = GameData::TrainerType.get(t.trainertype)
music = trainer_type_data.battle_BGM if trainer_type_data.battle_BGM
end
ret = pbStringToAudioFile(music) if music && music!=""
if !ret
# Check map metadata
music = GameData::MapMetadata.get($game_map.map_id).trainer_battle_BGM
if music && music!=""
ret = pbStringToAudioFile(music)
end
end
if !ret
# Check global metadata
music = GameData::Metadata.get.trainer_battle_BGM
if music && music!=""
ret = pbStringToAudioFile(music)
end
end
ret = pbStringToAudioFile("Battle trainer") if !ret
return ret
end
def pbGetTrainerBattleBGMFromType(trainertype)
if $PokemonGlobal.nextBattleBGM
return $PokemonGlobal.nextBattleBGM.clone
end
trainer_type_data = GameData::TrainerType.get(trainertype)
ret = trainer_type_data.battle_BGM if trainer_type_data.battle_BGM
if !ret
# Check map metadata
music = GameData::MapMetadata.get($game_map.map_id).trainer_battle_BGM
ret = pbStringToAudioFile(music) if music && music!=""
end
if !ret
# Check global metadata
music = GameData::Metadata.get.trainer_battle_BGM
ret = pbStringToAudioFile(music) if music && music!=""
end
ret = pbStringToAudioFile("Battle trainer") if !ret
return ret
end
def pbGetTrainerVictoryME(trainer) # can be a PokeBattle_Trainer or an array of them
if $PokemonGlobal.nextBattleME
return $PokemonGlobal.nextBattleME.clone
end
music = nil
trainerarray = (trainer.is_a?(Array)) ? trainer : [trainer]
trainerarray.each do |t|
trainer_type_data = GameData::TrainerType.get(t.trainertype)
music = trainer_type_data.victory_ME if trainer_type_data.victory_ME
end
ret = nil
if music && music!=""
ret = pbStringToAudioFile(music)
end
if !ret
# Check map metadata
music = GameData::MapMetadata.get($game_map.map_id).trainer_victory_ME
if music && music!=""
ret = pbStringToAudioFile(music)
end
end
if !ret
# Check global metadata
music = GameData::Metadata.get.trainer_victory_ME
if music && music!=""
ret = pbStringToAudioFile(music)
end
end
ret = pbStringToAudioFile("Battle victory") if !ret
ret.name = "../../Audio/ME/"+ret.name
return ret
end
@@ -1,521 +0,0 @@
#===============================================================================
# Load Pokémon sprites
#===============================================================================
def pbLoadPokemonBitmap(pokemon,back=false)
return pbLoadPokemonBitmapSpecies(pokemon,pokemon.species,back)
end
# NOTE: Returns an AnimatedBitmap, not a Bitmap
def pbLoadPokemonBitmapSpecies(pokemon,species,back=false)
ret = nil
if pokemon.egg?
bitmapFileName = sprintf("Graphics/Battlers/%segg_%d",getConstantName(PBSpecies,species),pokemon.form) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Battlers/%03degg_%d",species,pokemon.form)
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Battlers/%segg",getConstantName(PBSpecies,species)) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Battlers/%03degg",species)
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Battlers/egg")
end
end
end
end
bitmapFileName = pbResolveBitmap(bitmapFileName)
else
bitmapFileName = pbCheckPokemonBitmapFiles([species,back,(pokemon.female?),
pokemon.shiny?,(pokemon.form rescue 0),pokemon.shadowPokemon?])
# Alter bitmap if supported
alterBitmap = (MultipleForms.getFunction(species,"alterBitmap") rescue nil)
end
if bitmapFileName && alterBitmap
animatedBitmap = AnimatedBitmap.new(bitmapFileName)
copiedBitmap = animatedBitmap.copy
animatedBitmap.dispose
copiedBitmap.each { |bitmap| alterBitmap.call(pokemon,bitmap) }
ret = copiedBitmap
elsif bitmapFileName
ret = AnimatedBitmap.new(bitmapFileName)
end
return ret
end
# NOTE: Returns an AnimatedBitmap, not a Bitmap
def pbLoadSpeciesBitmap(species,female=false,form=0,shiny=false,shadow=false,back=false,egg=false)
ret = nil
if egg
bitmapFileName = sprintf("Graphics/Battlers/%segg_%d",getConstantName(PBSpecies,species),form) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Battlers/%03degg_%d",species,form)
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Battlers/%segg",getConstantName(PBSpecies,species)) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Battlers/%03degg",species)
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Battlers/egg")
end
end
end
end
bitmapFileName = pbResolveBitmap(bitmapFileName)
else
bitmapFileName = pbCheckPokemonBitmapFiles([species,back,female,shiny,form,shadow])
end
if bitmapFileName
ret = AnimatedBitmap.new(bitmapFileName)
end
return ret
end
def pbCheckPokemonBitmapFiles(params)
factors = []
factors.push([5,params[5],false]) if params[5] && params[5]!=false # shadow
factors.push([2,params[2],false]) if params[2] && params[2]!=false # gender
factors.push([3,params[3],false]) if params[3] && params[3]!=false # shiny
factors.push([4,params[4],0]) if params[4] && params[4]!=0 # form
factors.push([0,params[0],0]) # species
trySpecies = 0
tryGender = false
tryShiny = false
tryBack = params[1]
tryForm = 0
tryShadow = false
for i in 0...2**factors.length
factors.each_with_index do |factor,index|
newVal = ((i/(2**index))%2==0) ? factor[1] : factor[2]
case factor[0]
when 0 then trySpecies = newVal
when 2 then tryGender = newVal
when 3 then tryShiny = newVal
when 4 then tryForm = newVal
when 5 then tryShadow = newVal
end
end
for j in 0...2 # Try using the species' internal name and then its ID number
next if trySpecies==0 && j==0
trySpeciesText = (j==0) ? getConstantName(PBSpecies,trySpecies) : sprintf("%03d",trySpecies)
bitmapFileName = sprintf("Graphics/Battlers/%s%s%s%s%s%s",
trySpeciesText,
(tryGender) ? "f" : "",
(tryShiny) ? "s" : "",
(tryBack) ? "b" : "",
(tryForm!=0) ? "_"+tryForm.to_s : "",
(tryShadow) ? "_shadow" : "") rescue nil
ret = pbResolveBitmap(bitmapFileName)
return ret if ret
end
end
return nil
end
def pbLoadPokemonShadowBitmap(pokemon)
bitmapFileName = pbCheckPokemonShadowBitmapFiles(pokemon.species,pokemon.form)
return AnimatedBitmap.new(pbResolveBitmap(bitmapFileName)) if bitmapFileName
return nil
end
def pbLoadPokemonShadowBitmapSpecies(pokemon,species)
bitmapFileName = pbCheckPokemonShadowBitmapFiles(species,pokemon.form)
return AnimatedBitmap.new(pbResolveBitmap(bitmapFileName)) if bitmapFileName
return nil
end
def pbCheckPokemonShadowBitmapFiles(species,form,fullmetrics=nil)
if form>0
bitmapFileName = sprintf("Graphics/Battlers/%s_%d_battleshadow",getConstantName(PBSpecies,species),form) rescue nil
ret = pbResolveBitmap(bitmapFileName)
return bitmapFileName if ret
bitmapFileName = sprintf("Graphics/Battlers/%03d_%d_battleshadow",species,form)
ret = pbResolveBitmap(bitmapFileName)
return bitmapFileName if ret
end
bitmapFileName = sprintf("Graphics/Battlers/%s_battleshadow",getConstantName(PBSpecies,species)) rescue nil
ret = pbResolveBitmap(bitmapFileName)
return bitmapFileName if ret
bitmapFileName = sprintf("Graphics/Battlers/%03d_battleshadow",species)
ret = pbResolveBitmap(bitmapFileName)
return bitmapFileName if ret
# Load metrics and use that graphic
fullmetrics = pbLoadSpeciesMetrics if !fullmetrics
size = (fullmetrics[SpeciesData::METRIC_SHADOW_SIZE][pbGetFSpeciesFromForm(species,form)] || 2)
bitmapFileName = sprintf("Graphics/Pictures/Battle/battler_shadow_%d",size)
return bitmapFileName if pbResolveBitmap(bitmapFileName)
return nil
end
#===============================================================================
# Load Pokémon icons
#===============================================================================
def pbLoadPokemonIcon(pokemon)
return AnimatedBitmap.new(pbPokemonIconFile(pokemon)).deanimate
end
def pbPokemonIconFile(pokemon)
return pbCheckPokemonIconFiles([pokemon.species,pokemon.female?,
pokemon.shiny?,(pokemon.form rescue 0),pokemon.shadowPokemon?],
pokemon.egg?)
end
def pbCheckPokemonIconFiles(params,egg=false)
species = params[0]
if egg
bitmapFileName = sprintf("Graphics/Icons/icon%segg_%d",getConstantName(PBSpecies,species),params[3]) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Icons/icon%03degg_%d",species,params[3])
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Icons/icon%segg",getConstantName(PBSpecies,species)) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Icons/icon%03degg",species)
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Icons/iconEgg")
end
end
end
end
return pbResolveBitmap(bitmapFileName)
end
factors = []
factors.push([4,params[4],false]) if params[4] && params[4]!=false # shadow
factors.push([1,params[1],false]) if params[1] && params[1]!=false # gender
factors.push([2,params[2],false]) if params[2] && params[2]!=false # shiny
factors.push([3,params[3],0]) if params[3] && params[3]!=0 # form
factors.push([0,params[0],0]) # species
trySpecies = 0
tryGender = false
tryShiny = false
tryForm = 0
tryShadow = false
for i in 0...2**factors.length
factors.each_with_index do |factor,index|
newVal = ((i/(2**index))%2==0) ? factor[1] : factor[2]
case factor[0]
when 0 then trySpecies = newVal
when 1 then tryGender = newVal
when 2 then tryShiny = newVal
when 3 then tryForm = newVal
when 4 then tryShadow = newVal
end
end
for j in 0...2 # Try using the species' internal name and then its ID number
next if trySpecies==0 && j==0
trySpeciesText = (j==0) ? getConstantName(PBSpecies,trySpecies) : sprintf("%03d",trySpecies)
bitmapFileName = sprintf("Graphics/Icons/icon%s%s%s%s%s",
trySpeciesText,
(tryGender) ? "f" : "",
(tryShiny) ? "s" : "",
(tryForm!=0) ? "_"+tryForm.to_s : "",
(tryShadow) ? "_shadow" : "") rescue nil
ret = pbResolveBitmap(bitmapFileName)
return ret if ret
end
end
return nil
end
#===============================================================================
# Load Pokémon footprint graphics
#===============================================================================
def pbPokemonFootprintFile(pokemon,form=0) # Used by the Pokédex
return nil if !pokemon
if pokemon.is_a?(Numeric)
bitmapFileName = sprintf("Graphics/Icons/Footprints/footprint%s_%d",
getConstantName(PBSpecies,pokemon),form) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Icons/Footprints/footprint%03d_%d",
pokemon,form) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Icons/Footprints/footprint%s",
getConstantName(PBSpecies,pokemon)) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Icons/Footprints/footprint%03d",pokemon)
end
end
end
else
bitmapFileName = sprintf("Graphics/Icons/Footprints/footprint%s_%d",
getConstantName(PBSpecies,pokemon.species),(pokemon.form rescue 0)) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Icons/Footprints/footprint%03d_%d",
pokemon.species,(pokemon.form rescue 0)) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Icons/Footprints/footprint%s",
getConstantName(PBSpecies,pokemon.species)) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Icons/Footprints/footprint%03d",
pokemon.species)
end
end
end
end
return pbResolveBitmap(bitmapFileName)
end
#===============================================================================
# Analyse audio files
#===============================================================================
def pbResolveAudioSE(file)
return nil if !file
if RTP.exists?("Audio/SE/"+file,["",".wav",".mp3",".ogg"])
return RTP.getPath("Audio/SE/"+file,["",".wav",".mp3",".ogg"])
end
return nil
end
def pbCryFrameLength(pokemon,form=0,pitch=nil)
return 0 if !pokemon
pitch = 100 if !pitch
pitch = pitch.to_f/100
return 0 if pitch<=0
playtime = 0.0
if pokemon.is_a?(Numeric)
pkmnwav = pbResolveAudioSE(pbCryFile(pokemon,form))
playtime = getPlayTime(pkmnwav) if pkmnwav
elsif !pokemon.egg?
if pokemon.respond_to?("chatter") && pokemon.chatter
playtime = pokemon.chatter.time
pitch = 1.0
else
pkmnwav = pbResolveAudioSE(pbCryFile(pokemon))
playtime = getPlayTime(pkmnwav) if pkmnwav
end
end
playtime /= pitch # sound is lengthened the lower the pitch
# 4 is added to provide a buffer between sounds
return (playtime*Graphics.frame_rate).ceil+4
end
#===============================================================================
# Load/play Pokémon cry files
#===============================================================================
def pbPlayCry(pokemon,volume=90,pitch=nil)
return if !pokemon
if pokemon.is_a?(Numeric) || pokemon.is_a?(String) || pokemon.is_a?(Symbol)
pbPlayCrySpecies(pokemon,0,volume,pitch)
elsif pokemon.is_a?(Pokemon)
pbPlayCryPokemon(pokemon,volume,pitch)
end
end
def pbPlayCrySpecies(pokemon,form=0,volume=90,pitch=nil)
return if !pokemon
pokemon = getID(PBSpecies,pokemon)
return if !pokemon.is_a?(Numeric)
pkmnwav = pbCryFile(pokemon,form)
if pkmnwav
pitch ||= 100
pbSEPlay(RPG::AudioFile.new(pkmnwav,volume,pitch)) rescue nil
end
end
def pbPlayCryPokemon(pokemon,volume=90,pitch=nil)
return if !pokemon || pokemon.egg?
if pokemon.respond_to?("chatter") && pokemon.chatter
pokemon.chatter.play
return
end
pkmnwav = pbCryFile(pokemon)
if pkmnwav
pitch ||= (pokemon.hp*25/pokemon.totalhp)+75
pbSEPlay(RPG::AudioFile.new(pkmnwav,volume,pitch)) rescue nil
end
end
def pbCryFile(pokemon,form=0)
return nil if !pokemon
pokemon = getID(PBSpecies,pokemon)
if pokemon.is_a?(Numeric)
filename = sprintf("Cries/%sCry_%d",getConstantName(PBSpecies,pokemon),form) rescue nil
if !pbResolveAudioSE(filename)
filename = sprintf("Cries/%03dCry_%d",pokemon,form)
if !pbResolveAudioSE(filename)
filename = sprintf("Cries/%sCry",getConstantName(PBSpecies,pokemon)) rescue nil
if !pbResolveAudioSE(filename)
filename = sprintf("Cries/%03dCry",pokemon)
end
end
end
return filename if pbResolveAudioSE(filename)
elsif !pokemon.egg?
form = (pokemon.form rescue 0)
filename = sprintf("Cries/%sCry_%d",getConstantName(PBSpecies,pokemon.species),form) rescue nil
if !pbResolveAudioSE(filename)
filename = sprintf("Cries/%03dCry_%d",pokemon.species,form)
if !pbResolveAudioSE(filename)
filename = sprintf("Cries/%sCry",getConstantName(PBSpecies,pokemon.species)) rescue nil
if !pbResolveAudioSE(filename)
filename = sprintf("Cries/%03dCry",pokemon.species)
end
end
end
return filename if pbResolveAudioSE(filename)
end
return nil
end
#===============================================================================
# Load various wild battle music
#===============================================================================
def pbGetWildBattleBGM(_wildParty) # wildParty is an array of Pokémon objects
if $PokemonGlobal.nextBattleBGM
return $PokemonGlobal.nextBattleBGM.clone
end
ret = nil
if !ret
# Check map metadata
music = GameData::MapMetadata.get($game_map.map_id).wild_battle_BGM
ret = pbStringToAudioFile(music) if music && music!=""
end
if !ret
# Check global metadata
music = GameData::Metadata.get.wild_battle_BGM
ret = pbStringToAudioFile(music) if music && music!=""
end
ret = pbStringToAudioFile("Battle wild") if !ret
return ret
end
def pbGetWildVictoryME
if $PokemonGlobal.nextBattleME
return $PokemonGlobal.nextBattleME.clone
end
ret = nil
if !ret
# Check map metadata
music = GameData::MapMetadata.get($game_map.map_id).wild_victory_ME
ret = pbStringToAudioFile(music) if music && music!=""
end
if !ret
# Check global metadata
music = GameData::Metadata.get.wild_victory_ME
ret = pbStringToAudioFile(music) if music && music!=""
end
ret = pbStringToAudioFile("Battle victory") if !ret
ret.name = "../../Audio/ME/"+ret.name
return ret
end
def pbGetWildCaptureME
if $PokemonGlobal.nextBattleCaptureME
return $PokemonGlobal.nextBattleCaptureME.clone
end
ret = nil
if !ret
# Check map metadata
music = GameData::MapMetadata.get($game_map.map_id).wild_capture_ME
ret = pbStringToAudioFile(music) if music && music!=""
end
if !ret
# Check global metadata
music = GameData::Metadata.get.wild_capture_ME
ret = pbStringToAudioFile(music) if music && music!=""
end
ret = pbStringToAudioFile("Battle capture success") if !ret
ret.name = "../../Audio/ME/"+ret.name
return ret
end
#===============================================================================
# Load/play various trainer battle music
#===============================================================================
def pbPlayTrainerIntroME(trainer_type)
trainer_type_data = GameData::TrainerType.get(trainer_type)
return if !trainer_type_data.intro_ME || trainer_type_data.intro_ME == ""
bgm = pbStringToAudioFile(trainer_type_data.intro_ME)
pbMEPlay(bgm)
end
def pbGetTrainerBattleBGM(trainer) # can be a PokeBattle_Trainer or an array of them
if $PokemonGlobal.nextBattleBGM
return $PokemonGlobal.nextBattleBGM.clone
end
ret = nil
music = nil
trainerarray = (trainer.is_a?(Array)) ? trainer : [trainer]
trainerarray.each do |t|
trainer_type_data = GameData::TrainerType.get(t.trainertype)
music = trainer_type_data.battle_BGM if trainer_type_data.battle_BGM
end
ret = pbStringToAudioFile(music) if music && music!=""
if !ret
# Check map metadata
music = GameData::MapMetadata.get($game_map.map_id).trainer_battle_BGM
if music && music!=""
ret = pbStringToAudioFile(music)
end
end
if !ret
# Check global metadata
music = GameData::Metadata.get.trainer_battle_BGM
if music && music!=""
ret = pbStringToAudioFile(music)
end
end
ret = pbStringToAudioFile("Battle trainer") if !ret
return ret
end
def pbGetTrainerBattleBGMFromType(trainertype)
if $PokemonGlobal.nextBattleBGM
return $PokemonGlobal.nextBattleBGM.clone
end
trainer_type_data = GameData::TrainerType.get(trainertype)
ret = trainer_type_data.battle_BGM if trainer_type_data.battle_BGM
if !ret
# Check map metadata
music = GameData::MapMetadata.get($game_map.map_id).trainer_battle_BGM
ret = pbStringToAudioFile(music) if music && music!=""
end
if !ret
# Check global metadata
music = GameData::Metadata.get.trainer_battle_BGM
ret = pbStringToAudioFile(music) if music && music!=""
end
ret = pbStringToAudioFile("Battle trainer") if !ret
return ret
end
def pbGetTrainerVictoryME(trainer) # can be a PokeBattle_Trainer or an array of them
if $PokemonGlobal.nextBattleME
return $PokemonGlobal.nextBattleME.clone
end
music = nil
trainerarray = (trainer.is_a?(Array)) ? trainer : [trainer]
trainerarray.each do |t|
trainer_type_data = GameData::TrainerType.get(t.trainertype)
music = trainer_type_data.victory_ME if trainer_type_data.victory_ME
end
ret = nil
if music && music!=""
ret = pbStringToAudioFile(music)
end
if !ret
# Check map metadata
music = GameData::MapMetadata.get($game_map.map_id).trainer_victory_ME
if music && music!=""
ret = pbStringToAudioFile(music)
end
end
if !ret
# Check global metadata
music = GameData::Metadata.get.trainer_victory_ME
if music && music!=""
ret = pbStringToAudioFile(music)
end
end
ret = pbStringToAudioFile("Battle victory") if !ret
ret.name = "../../Audio/ME/"+ret.name
return ret
end
@@ -2,279 +2,240 @@
# Nicknaming and storing Pokémon
#===============================================================================
def pbBoxesFull?
return ($Trainer.party.length==6 && $PokemonStorage.full?)
return ($Trainer.party.length == 6 && $PokemonStorage.full?)
end
def pbNickname(pokemon)
speciesname = PBSpecies.getName(pokemon.species)
if pbConfirmMessage(_INTL("Would you like to give a nickname to {1}?",speciesname))
helptext = _INTL("{1}'s nickname?",speciesname)
newname = pbEnterPokemonName(helptext, 0, Pokemon::MAX_NAME_SIZE, "", pokemon)
pokemon.name = newname if newname!=""
def pbNickname(pkmn)
species_name = pkmn.speciesName
if pbConfirmMessage(_INTL("Would you like to give a nickname to {1}?", species_name))
new_name = pbEnterPokemonName(_INTL("{1}'s nickname?", species_name),
0, Pokemon::MAX_NAME_SIZE, "", pkmn)
pkmn.name = new_name if new_name != ""
end
end
def pbStorePokemon(pokemon)
def pbStorePokemon(pkmn)
if pbBoxesFull?
pbMessage(_INTL("There's no more room for Pokémon!\1"))
pbMessage(_INTL("The Pokémon Boxes are full and can't accept any more!"))
return
end
pokemon.pbRecordFirstMoves
if $Trainer.party.length<6
$Trainer.party[$Trainer.party.length] = pokemon
pkmn.pbRecordFirstMoves
if $Trainer.party.length < 6
$Trainer.party[$Trainer.party.length] = pkmn
else
oldcurbox = $PokemonStorage.currentBox
storedbox = $PokemonStorage.pbStoreCaught(pokemon)
storedbox = $PokemonStorage.pbStoreCaught(pkmn)
curboxname = $PokemonStorage[oldcurbox].name
boxname = $PokemonStorage[storedbox].name
creator = nil
creator = pbGetStorageCreator if $PokemonGlobal.seenStorageCreator
if storedbox!=oldcurbox
if storedbox != oldcurbox
if creator
pbMessage(_INTL("Box \"{1}\" on {2}'s PC was full.\1",curboxname,creator))
pbMessage(_INTL("Box \"{1}\" on {2}'s PC was full.\1", curboxname, creator))
else
pbMessage(_INTL("Box \"{1}\" on someone's PC was full.\1",curboxname))
pbMessage(_INTL("Box \"{1}\" on someone's PC was full.\1", curboxname))
end
pbMessage(_INTL("{1} was transferred to box \"{2}.\"",pokemon.name,boxname))
pbMessage(_INTL("{1} was transferred to box \"{2}.\"", pkmn.name, boxname))
else
if creator
pbMessage(_INTL("{1} was transferred to {2}'s PC.\1",pokemon.name,creator))
pbMessage(_INTL("{1} was transferred to {2}'s PC.\1", pkmn.name, creator))
else
pbMessage(_INTL("{1} was transferred to someone's PC.\1",pokemon.name))
pbMessage(_INTL("{1} was transferred to someone's PC.\1", pkmn.name))
end
pbMessage(_INTL("It was stored in box \"{1}.\"",boxname))
pbMessage(_INTL("It was stored in box \"{1}.\"", boxname))
end
end
end
def pbNicknameAndStore(pokemon)
def pbNicknameAndStore(pkmn)
if pbBoxesFull?
pbMessage(_INTL("There's no more room for Pokémon!\1"))
pbMessage(_INTL("The Pokémon Boxes are full and can't accept any more!"))
return
end
$Trainer.seen[pokemon.species] = true
$Trainer.owned[pokemon.species] = true
pbNickname(pokemon)
pbStorePokemon(pokemon)
$Trainer.seen[pkmn.species] = true
$Trainer.owned[pkmn.species] = true
pbNickname(pkmn)
pbStorePokemon(pkmn)
end
#===============================================================================
# Giving Pokémon to the player (will send to storage if party is full)
#===============================================================================
def pbAddPokemon(pokemon,level=nil,seeform=true)
return if !pokemon
def pbAddPokemon(pkmn, level = 1, see_form = true)
return false if !pkmn
if pbBoxesFull?
pbMessage(_INTL("There's no more room for Pokémon!\1"))
pbMessage(_INTL("The Pokémon Boxes are full and can't accept any more!"))
return false
end
pokemon = getID(PBSpecies,pokemon)
if pokemon.is_a?(Integer) && level.is_a?(Integer)
pokemon = Pokemon.new(pokemon,level)
end
speciesname = PBSpecies.getName(pokemon.species)
pbMessage(_INTL("{1} obtained {2}!\\me[Pkmn get]\\wtnp[80]\1",$Trainer.name,speciesname))
pbNicknameAndStore(pokemon)
pbSeenForm(pokemon) if seeform
pkmn = Pokemon.new(pkmn, level) if !pkmn.is_a?(Pokemon)
species_name = pkmn.speciesName
pbMessage(_INTL("{1} obtained {2}!\\me[Pkmn get]\\wtnp[80]\1", $Trainer.name, species_name))
pbNicknameAndStore(pkmn)
pbSeenForm(pkmn) if see_form
return true
end
def pbAddPokemonSilent(pokemon,level=nil,seeform=true)
def pbAddPokemonSilent(pkmn, level = 1, see_form = true)
return false if !pokemon || pbBoxesFull?
pokemon = getID(PBSpecies,pokemon)
if pokemon.is_a?(Integer) && level.is_a?(Integer)
pokemon = Pokemon.new(pokemon,level)
end
$Trainer.seen[pokemon.species] = true
$Trainer.owned[pokemon.species] = true
pbSeenForm(pokemon) if seeform
pokemon.pbRecordFirstMoves
if $Trainer.party.length<6
$Trainer.party[$Trainer.party.length] = pokemon
pkmn = Pokemon.new(pkmn, level) if !pkmn.is_a?(Pokemon)
$Trainer.seen[pkmn.species] = true
$Trainer.owned[pkmn.species] = true
pbSeenForm(pkmn) if see_form
pkmn.pbRecordFirstMoves
if $Trainer.party.length < 6
$Trainer.party[$Trainer.party.length] = pkmn
else
$PokemonStorage.pbStoreCaught(pokemon)
$PokemonStorage.pbStoreCaught(pkmn)
end
return true
end
#===============================================================================
# Giving Pokémon/eggs to the player (can only add to party)
#===============================================================================
def pbAddToParty(pokemon,level=nil,seeform=true)
return false if !pokemon || $Trainer.party.length>=6
pokemon = getID(PBSpecies,pokemon)
if pokemon.is_a?(Integer) && level.is_a?(Integer)
pokemon = Pokemon.new(pokemon,level)
end
speciesname = PBSpecies.getName(pokemon.species)
pbMessage(_INTL("{1} obtained {2}!\\me[Pkmn get]\\wtnp[80]\1",$Trainer.name,speciesname))
pbNicknameAndStore(pokemon)
pbSeenForm(pokemon) if seeform
def pbAddToParty(pkmn, level = 1, see_form = true)
return false if !pkmn || $Trainer.party.length >= 6
pkmn = Pokemon.new(pkmn, level) if !pkmn.is_a?(Pokemon)
species_name = pkmn.speciesName
pbMessage(_INTL("{1} obtained {2}!\\me[Pkmn get]\\wtnp[80]\1", $Trainer.name, species_name))
pbNicknameAndStore(pkmn)
pbSeenForm(pkmn) if see_form
return true
end
def pbAddToPartySilent(pokemon,level=nil,seeform=true)
return false if !pokemon || $Trainer.party.length>=6
pokemon = getID(PBSpecies,pokemon)
if pokemon.is_a?(Integer) && level.is_a?(Integer)
pokemon = Pokemon.new(pokemon,level)
end
$Trainer.seen[pokemon.species] = true
$Trainer.owned[pokemon.species] = true
pbSeenForm(pokemon) if seeform
pokemon.pbRecordFirstMoves
$Trainer.party[$Trainer.party.length] = pokemon
def pbAddToPartySilent(pkmn, level = nil, see_form = true)
return false if !pkmn || $Trainer.party.length >= 6
pkmn = Pokemon.new(pkmn, level) if !pkmn.is_a?(Pokemon)
$Trainer.seen[pkmn.species] = true
$Trainer.owned[pkmn.species] = true
pbSeenForm(pkmn) if see_form
pkmn.pbRecordFirstMoves
$Trainer.party[$Trainer.party.length] = pkmn
return true
end
def pbAddForeignPokemon(pokemon,level=nil,ownerName=nil,nickname=nil,ownerGender=0,seeform=true)
return false if !pokemon || $Trainer.party.length>=6
pokemon = getID(PBSpecies,pokemon)
if pokemon.is_a?(Integer) && level.is_a?(Integer)
pokemon = Pokemon.new(pokemon,level)
end
def pbAddForeignPokemon(pkmn, level = 1, owner_name = nil, nickname = nil, owner_gender = 0, see_form = true)
return false if !pkmn || $Trainer.party.length>=6
pkmn = Pokemon.new(pkmn, level) if !pkmn.is_a?(Pokemon)
# Set original trainer to a foreign one
pokemon.owner = Pokemon::Owner.new_foreign(ownerName || "", ownerGender)
pkmn.owner = Pokemon::Owner.new_foreign(owner_name || "", owner_gender)
# Set nickname
pokemon.name = nickname[0, Pokemon::MAX_NAME_SIZE] if nickname && nickname!=""
pkmn.name = nickname[0, Pokemon::MAX_NAME_SIZE] if nickname && nickname!=""
# Recalculate stats
pokemon.calcStats
if ownerName
pbMessage(_INTL("\\me[Pkmn get]{1} received a Pokémon from {2}.\1",$Trainer.name,ownerName))
pkmn.calcStats
if owner_name
pbMessage(_INTL("\\me[Pkmn get]{1} received a Pokémon from {2}.\1", $Trainer.name, owner_name))
else
pbMessage(_INTL("\\me[Pkmn get]{1} received a Pokémon.\1",$Trainer.name))
pbMessage(_INTL("\\me[Pkmn get]{1} received a Pokémon.\1", $Trainer.name))
end
pbStorePokemon(pokemon)
$Trainer.seen[pokemon.species] = true
$Trainer.owned[pokemon.species] = true
pbSeenForm(pokemon) if seeform
pbStorePokemon(pkmn)
$Trainer.seen[pkmn.species] = true
$Trainer.owned[pkmn.species] = true
pbSeenForm(pkmn) if see_form
return true
end
def pbGenerateEgg(pokemon,text="")
return false if !pokemon || $Trainer.party.length>=6
pokemon = getID(PBSpecies,pokemon)
if pokemon.is_a?(Integer)
pokemon = Pokemon.new(pokemon,EGG_LEVEL)
end
# Get egg steps
eggSteps = pbGetSpeciesData(pokemon.species,pokemon.form,SpeciesData::STEPS_TO_HATCH)
def pbGenerateEgg(pkmn, text = "")
return false if !pkmn || $Trainer.party.length >= 6
pkmn = Pokemon.new(pkmn, EGG_LEVEL) if !pkmn.is_a?(Pokemon)
# Set egg's details
pokemon.name = _INTL("Egg")
pokemon.eggsteps = eggSteps
pokemon.obtainText = text
pokemon.calcStats
pkmn.name = _INTL("Egg")
pkmn.eggsteps = pkmn.species_data.hatch_steps
pkmn.obtainText = text
pkmn.calcStats
# Add egg to party
$Trainer.party[$Trainer.party.length] = pokemon
$Trainer.party[$Trainer.party.length] = pkmn
return true
end
alias pbAddEgg pbGenerateEgg
alias pbGenEgg pbGenerateEgg
#===============================================================================
# Removing Pokémon from the party (fails if trying to remove last able Pokémon)
#===============================================================================
def pbRemovePokemonAt(index)
return false if index<0 || index>=$Trainer.party.length
haveAble = false
for i in 0...$Trainer.party.length
next if i==index
haveAble = true if $Trainer.party[i].hp>0 && !$Trainer.party[i].egg?
return false if index < 0 || index >= $Trainer.party.length
have_able = false
$Trainer.party.each_with_index do |pkmn, i|
have_able = true if i != index && !pkmn.egg? && pkmn.hp > 0
break if have_able
end
return false if !haveAble
return false if !have_able
$Trainer.party.delete_at(index)
return true
end
#===============================================================================
# Recording Pokémon forms as seen
#===============================================================================
def pbSeenForm(pkmn,gender=0,form=0)
$Trainer.formseen = [] if !$Trainer.formseen
$Trainer.formlastseen = [] if !$Trainer.formlastseen
if pkmn.is_a?(Pokemon)
gender = pkmn.gender
form = (pkmn.form rescue 0)
species = pkmn.species
def pbSeenForm(species, gender = 0, form = 0)
$Trainer.formseen = {} if !$Trainer.formseen
$Trainer.formlastseen = {} if !$Trainer.formlastseen
if species.is_a?(Pokemon)
species_data = species.species_data
gender = species.gender
else
species = getID(PBSpecies,pkmn)
species_data = GameData::Species.get_species_form(species, form)
end
return if !species || species<=0
fSpecies = pbGetFSpeciesFromForm(species,form)
species, form = pbGetSpeciesFromFSpecies(fSpecies)
gender = 0 if gender>1
dexForm = pbGetSpeciesData(species,form,SpeciesData::POKEDEX_FORM)
form = dexForm if dexForm>0
fSpecies = pbGetFSpeciesFromForm(species,form)
formName = pbGetMessage(MessageTypes::FormNames,fSpecies)
form = 0 if !formName || formName==""
$Trainer.formseen[species] = [[],[]] if !$Trainer.formseen[species]
return if !species_data
species = species_data.species
gender = 0 if gender >= 2
form = species_data.form
if form != species_data.pokedex_form
species_data = GameData::Species.get_species_form(species, species_data.pokedex_form)
form = species_data.form
end
form = 0 if species_data.form_name.nil? || species_data.form_name.empty?
$Trainer.formseen[species] = [[], []] if !$Trainer.formseen[species]
$Trainer.formseen[species][gender][form] = true
$Trainer.formlastseen[species] = [] if !$Trainer.formlastseen[species]
$Trainer.formlastseen[species] = [gender,form] if $Trainer.formlastseen[species]==[]
$Trainer.formlastseen[species] = [gender, form] if $Trainer.formlastseen[species] == []
end
def pbUpdateLastSeenForm(pkmn)
$Trainer.formlastseen = [] if !$Trainer.formlastseen
form = (pkmn.form rescue 0)
dexForm = pbGetSpeciesData(pkmn.species,pkmn.form,SpeciesData::POKEDEX_FORM)
form = dexForm if dexForm>0
formName = pbGetMessage(MessageTypes::FormNames,pkmn.fSpecies)
form = 0 if !formName || formName==""
$Trainer.formlastseen[pkmn.species] = [] if !$Trainer.formlastseen[pkmn.species]
$Trainer.formlastseen[pkmn.species] = [pkmn.gender,form]
$Trainer.formlastseen = {} if !$Trainer.formlastseen
species_data = pkmn.species_data
form = species_data.pokedex_form
form = 0 if species_data.form_name.nil? || species_data.form_name.empty?
$Trainer.formlastseen[pkmn.species] = [pkmn.gender, form]
end
#===============================================================================
# Analyse Pokémon in the party
#===============================================================================
# Returns the first unfainted, non-egg Pokémon in the player's party.
def pbFirstAblePokemon(variableNumber)
for i in 0...$Trainer.party.length
p = $Trainer.party[i]
if p && !p.egg? && p.hp>0
pbSet(variableNumber,i)
return $Trainer.party[i]
end
$Trainer.party.each_with_index do |pkmn, i|
next if pkmn.egg? || pkmn.hp == 0
pbSet(variableNumber, i)
return pkmn
end
pbSet(variableNumber,-1)
pbSet(variableNumber, -1)
return nil
end
# Checks whether the player would still have an unfainted Pokémon if the
# Pokémon given by _pokemonIndex_ were removed from the party.
def pbCheckAble(pokemonIndex)
for i in 0...$Trainer.party.length
next if i==pokemonIndex
p = $Trainer.party[i]
return true if p && !p.egg? && p.hp>0
# Pokémon given by _index_ were removed from the party.
def pbCheckAble(index)
$Trainer.party.each_with_index do |pkmn, i|
return true if i != index && !pkmn.egg? && pkmn.hp > 0
end
return false
end
# Returns true if there are no usable Pokémon in the player's party.
def pbAllFainted
return $Trainer.ablePokemonCount==0
return $Trainer.ablePokemonCount == 0
end
# Returns true if there is a Pokémon of the given species in the player's party.
# You may also specify a particular form it should be.
def pbHasSpecies?(species,form=-1)
species = getID(PBSpecies,species)
for pokemon in $Trainer.pokemonParty
return true if pokemon.species==species && (form<0 || form==pokemon.form)
def pbHasSpecies?(species, form = -1)
$Trainer.pokemonParty.each do |pkmn|
return true if pkmn.isSpecies?(species) && (form < 0 || pkmn.form == form)
end
return false
end
@@ -282,9 +243,8 @@ end
# Returns true if there is a fatefully met Pokémon of the given species in the
# player's party.
def pbHasFatefulSpecies?(species)
species = getID(PBSpecies,species)
for pokemon in $Trainer.pokemonParty
return true if pokemon.species==species && pokemon.obtainMode==4
$Trainer.pokemonParty.each do |pkmn|
return true if pkmn.isSpecies?(species) && pkmn.obtainMode == 4
end
return false
end
@@ -292,23 +252,17 @@ end
# Returns true if there is a Pokémon with the given type in the player's party.
def pbHasType?(type)
type = GameData::Type.get(type).id
for pokemon in $Trainer.pokemonParty
return true if pokemon.hasType?(type)
end
$Trainer.pokemonParty.each { |pkmn| return true if pkmn.hasType?(type) }
return false
end
# Checks whether any Pokémon in the party knows the given move, and returns
# the first Pokémon it finds with that move, or nil if no Pokémon has that move.
def pbCheckMove(move)
$Trainer.pokemonParty.each do |pkmn|
return pkmn if pkmn.hasMove?(move)
end
$Trainer.pokemonParty.each { |pkmn| return pkmn if pkmn.hasMove?(move) }
return nil
end
#===============================================================================
# Fully heal all Pokémon in the party
#===============================================================================
@@ -316,39 +270,37 @@ def pbHealAll
$Trainer.party.each { |pkmn| pkmn.heal }
end
#===============================================================================
# Return a level value based on Pokémon in a party
#===============================================================================
def pbBalancedLevel(party)
return 1 if party.length==0
return 1 if party.length == 0
# Calculate the mean of all levels
sum = 0
party.each { |p| sum += p.level }
return 1 if sum==0
return 1 if sum == 0
mLevel = PBExperience.maxLevel
average = sum.to_f/party.length.to_f
average = sum.to_f / party.length.to_f
# Calculate the standard deviation
varianceTimesN = 0
for i in 0...party.length
deviation = party[i].level-average
varianceTimesN += deviation*deviation
party.each do |pkmn|
deviation = pkmn.level - average
varianceTimesN += deviation * deviation
end
# NOTE: This is the "population" standard deviation calculation, since no
# sample is being taken.
stdev = Math.sqrt(varianceTimesN/party.length)
stdev = Math.sqrt(varianceTimesN / party.length)
mean = 0
weights = []
# Skew weights according to standard deviation
for i in 0...party.length
weight = party[i].level.to_f/sum.to_f
if weight<0.5
weight -= (stdev/mLevel.to_f)
weight = 0.001 if weight<=0.001
party.each do |pkmn|
weight = pkmn.level.to_f / sum.to_f
if weight < 0.5
weight -= (stdev / mLevel.to_f)
weight = 0.001 if weight <= 0.001
else
weight += (stdev/mLevel.to_f)
weight = 0.999 if weight>=0.999
weight += (stdev / mLevel.to_f)
weight = 0.999 if weight >= 0.999
end
weights.push(weight)
end
@@ -356,75 +308,68 @@ def pbBalancedLevel(party)
weights.each { |w| weightSum += w }
# Calculate the weighted mean, assigning each weight to each level's
# contribution to the sum
for i in 0...party.length
mean += party[i].level*weights[i]
end
party.each_with_index { |pkmn, i| mean += pkmn.level * weights[i] }
mean /= weightSum
# Round to nearest number
mean = mean.round
# Adjust level to minimum
mean = 1 if mean<1
mean = 1 if mean < 1
# Add 2 to the mean to challenge the player
mean += 2
# Adjust level to maximum
mean = mLevel if mean>mLevel
mean = mLevel if mean > mLevel
return mean
end
#===============================================================================
# Calculates a Pokémon's size (in millimeters)
#===============================================================================
def pbSize(pkmn)
baseheight = pbGetSpeciesData(pkmn.species,pkmn.form,SpeciesData::HEIGHT)
hpiv = pkmn.iv[0]&15
ativ = pkmn.iv[1]&15
dfiv = pkmn.iv[2]&15
spiv = pkmn.iv[3]&15
saiv = pkmn.iv[4]&15
sdiv = pkmn.iv[5]&15
m = pkmn.personalID&0xFF
n = (pkmn.personalID>>8)&0xFF
s = (((ativ^dfiv)*hpiv)^m)*256+(((saiv^sdiv)*spiv)^n)
baseheight = pkmn.height
hpiv = pkmn.iv[0] & 15
ativ = pkmn.iv[1] & 15
dfiv = pkmn.iv[2] & 15
spiv = pkmn.iv[3] & 15
saiv = pkmn.iv[4] & 15
sdiv = pkmn.iv[5] & 15
m = pkmn.personalID & 0xFF
n = (pkmn.personalID >> 8) & 0xFF
s = (((ativ ^ dfiv) * hpiv) ^ m) * 256 + (((saiv ^ sdiv) * spiv) ^ n)
xyz = []
if s<10; xyz = [ 290, 1, 0]
elsif s<110; xyz = [ 300, 1, 10]
elsif s<310; xyz = [ 400, 2, 110]
elsif s<710; xyz = [ 500, 4, 310]
elsif s<2710; xyz = [ 600, 20, 710]
elsif s<7710; xyz = [ 700, 50, 2710]
elsif s<17710; xyz = [ 800, 100, 7710]
elsif s<32710; xyz = [ 900, 150, 17710]
elsif s<47710; xyz = [1000, 150, 32710]
elsif s<57710; xyz = [1100, 100, 47710]
elsif s<62710; xyz = [1200, 50, 57710]
elsif s<64710; xyz = [1300, 20, 62710]
elsif s<65210; xyz = [1400, 5, 64710]
elsif s<65410; xyz = [1500, 2, 65210]
else; xyz = [1700, 1, 65510]
if s < 10; xyz = [ 290, 1, 0]
elsif s < 110; xyz = [ 300, 1, 10]
elsif s < 310; xyz = [ 400, 2, 110]
elsif s < 710; xyz = [ 500, 4, 310]
elsif s < 2710; xyz = [ 600, 20, 710]
elsif s < 7710; xyz = [ 700, 50, 2710]
elsif s < 17710; xyz = [ 800, 100, 7710]
elsif s < 32710; xyz = [ 900, 150, 17710]
elsif s < 47710; xyz = [1000, 150, 32710]
elsif s < 57710; xyz = [1100, 100, 47710]
elsif s < 62710; xyz = [1200, 50, 57710]
elsif s < 64710; xyz = [1300, 20, 62710]
elsif s < 65210; xyz = [1400, 5, 64710]
elsif s < 65410; xyz = [1500, 2, 65210]
else; xyz = [1700, 1, 65510]
end
return (((s-xyz[2])/xyz[1]+xyz[0]).floor*baseheight/10).floor
return (((s - xyz[2]) / xyz[1] + xyz[0]).floor * baseheight / 10).floor
end
#===============================================================================
# Returns true if the given species can be legitimately obtained as an egg
#===============================================================================
def pbHasEgg?(species)
species = getID(PBSpecies,species)
return false if !species
species_data = GameData::Species.try_get(species)
return false if !species_data
species = species_data.species
# species may be unbreedable, so check its evolution's compatibilities
evoSpecies = EvolutionHelper.evolutions(species, true)
compatSpecies = (evoSpecies && evoSpecies[0]) ? evoSpecies[0][2] : species
compat = pbGetSpeciesData(compatSpecies,0,SpeciesData::COMPATIBILITY)
compat = [compat] if !compat.is_a?(Array)
return false if compat.include?(getConst(PBEggGroups,:Undiscovered))
return false if compat.include?(getConst(PBEggGroups,:Ditto))
species_data = GameData::Species.try_get(compatSpecies)
compat = species_data.egg_groups
return false if compat.include?(PBEggGroups::Undiscovered)
return false if compat.include?(PBEggGroups::Ditto)
baby = EvolutionHelper.baby_species(species)
return true if species==baby # Is a basic species
return true if species == baby # Is a basic species
baby = EvolutionHelper.baby_species(species, true)
return true if species==baby # Is an egg species without incense
return true if species == baby # Is an egg species without incense
return false
end
@@ -203,6 +203,7 @@ end
#===============================================================================
# Constants utilities
#===============================================================================
# Unused
def isConst?(val,mod,constant)
begin
return false if !mod.const_defined?(constant.to_sym)
@@ -212,6 +213,7 @@ def isConst?(val,mod,constant)
return (val==mod.const_get(constant.to_sym))
end
# Unused
def hasConst?(mod,constant)
return false if !mod || !constant || constant==""
return mod.const_defined?(constant.to_sym) rescue false
@@ -828,97 +830,49 @@ end
#===============================================================================
# fSpecies utilities
#===============================================================================
def pbGetFSpeciesFromForm(species,form=0)
return species if form==0
ret = species
species = pbGetSpeciesFromFSpecies(species)[0] if species>PBSpecies.maxValue
formData = pbLoadFormToSpecies
if formData[species] && formData[species][form] && formData[species][form]>0
ret = formData[species][form]
end
return ret
end
def pbGetSpeciesFromFSpecies(species)
return [species,0] if species<=PBSpecies.maxValue
formdata = pbLoadFormToSpecies
for i in 1...formdata.length
next if !formdata[i]
for j in 0...formdata[i].length
return [i,j] if formdata[i][j]==species
end
end
return [species,0]
end
#===============================================================================
# Regional and National Pokédexes utilities
#===============================================================================
# Gets the ID number for the current region based on the player's current
# position. Returns the value of "defaultRegion" (optional, default is -1) if
# no region was defined in the game's metadata. The ID numbers returned by
# this function depend on the current map's position metadata.
def pbGetCurrentRegion(defaultRegion=-1)
mappos = ($game_map) ? GameData::MapMetadata.get($game_map.map_id).town_map_position : nil
return (mappos) ? mappos[0] : defaultRegion
# Returns the ID number of the region containing the player's current location,
# as determined by the current map's metadata.
def pbGetCurrentRegion(default = -1)
map_pos = ($game_map) ? GameData::MapMetadata.get($game_map.map_id).town_map_position : nil
return (map_pos) ? map_pos[0] : default
end
# Gets the Regional Pokédex number of the national species for the specified
# Regional Dex. The parameter "region" is zero-based. For example, if two
# regions are defined, they would each be specified as 0 and 1.
def pbGetRegionalNumber(region,nationalSpecies)
if nationalSpecies<=0 || nationalSpecies>PBSpecies.maxValue
# Return 0 if national species is outside range
return 0
end
dexList = pbLoadRegionalDexes[region]
return 0 if !dexList || dexList.length==0
return dexList[nationalSpecies] || 0
end
# Gets the National Pokédex number of the specified species and region. The
# parameter "region" is zero-based. For example, if two regions are defined,
# they would each be specified as 0 and 1.
def pbGetNationalNumber(region,regionalSpecies)
dexList = pbLoadRegionalDexes[region]
return 0 if !dexList || dexList.length==0
for i in 0...dexList.length
return i if dexList[i]==regionalSpecies
# Returns the Regional Pokédex number of the given species in the given Regional
# Dex. The parameter "region" is zero-based. For example, if two regions are
# defined, they would each be specified as 0 and 1.
def pbGetRegionalNumber(region, species)
dex_list = pbLoadRegionalDexes[region]
return 0 if !dex_list || dex_list.length == 0
species_data = GameData::Species.try_get(species)
return 0 if !species_data
dex_list.each_with_index do |s, index|
return index + 1 if s == species_data.species
end
return 0
end
# Gets an array of all national species within the given Regional Dex, sorted by
# Regional Dex number. The number of items in the array should be the
# number of species in the Regional Dex plus 1, since index 0 is considered
# to be empty. The parameter "region" is zero-based. For example, if two
# regions are defined, they would each be specified as 0 and 1.
def pbAllRegionalSpecies(region)
ret = [0]
return ret if region<0
dexList = pbLoadRegionalDexes[region]
return ret if !dexList || dexList.length==0
for i in 0...dexList.length
ret[dexList[i]] = i if dexList[i] && dexList[i] > 0
end
ret.map! { |e| e ? e : 0 } # Replace nils with 0s
return ret
# Returns an array of all species in the given Regional Dex in that Dex's order.
def pbAllRegionalSpecies(region_dex)
return nil if region_dex < 0
dex_list = pbLoadRegionalDexes[region_dex]
return nil if !dex_list || dex_list.length == 0
return dex_list.clone
end
def pbGetRegionalDexLength(region)
return PBSpecies.maxValue if region<0
ret = 0
dexList = pbLoadRegionalDexes[region]
return ret if !dexList || dexList.length==0
for i in 0...dexList.length
ret = dexList[i] if dexList[i] && dexList[i]>ret
# Returns the number of species in the given Regional Dex. Returns 0 if that
# Regional Dex doesn't exist. If region_dex is a negative number, returns the
# number of species in the National Dex (i.e. all species).
def pbGetRegionalDexLength(region_dex)
if region_dex < 0
ret = 0
GameData::Species.each { |s| ret += 1 if s.form == 0 }
return ret
end
return ret
dex_list = pbLoadRegionalDexes[region_dex]
return (dex_list) ? dex_list.length : 0
end
# Decides which Dex lists are able to be viewed (i.e. they are unlocked and have
@@ -991,7 +945,7 @@ def pbMoveTutorAnnotations(move, movelist = nil)
# Checked data from movelist given in parameter
ret[i] = _INTL("ABLE")
elsif pkmn.compatibleWithMove?(move)
# Checked data from PBS/tm.txt
# Checked data from Pokémon's tutor moves in pokemon.txt
ret[i] = _INTL("ABLE")
else
ret[i] = _INTL("NOT ABLE")
@@ -1049,12 +1003,12 @@ def pbConvertItemToItem(variable, array)
end
end
def pbConvertItemToPokemon(variable,array)
def pbConvertItemToPokemon(variable, array)
item = GameData::Item.get(pbGet(variable))
pbSet(variable, 0)
for i in 0...(array.length/2)
for i in 0...(array.length / 2)
next if item != array[2 * i]
pbSet(variable,getID(PBSpecies,array[2*i+1]))
pbSet(variable, GameData::Species.get(array[2 * i + 1]).id)
return
end
end
+37 -44
View File
@@ -294,12 +294,12 @@ def pbDebugMenuActions(cmd="",sprites=nil,viewport=nil)
#=============================================================================
when "testwildbattle"
species = pbChooseSpeciesList
if species!=0
if species
params = ChooseNumberParams.new
params.setRange(1,PBExperience.maxLevel)
params.setInitialValue(5)
params.setCancelValue(0)
level = pbMessageChooseNumber(_INTL("Set the wild {1}'s level.",PBSpecies.getName(species)),params)
level = pbMessageChooseNumber(_INTL("Set the wild {1}'s level.", GameData::Species.get(species).name), params)
if level>0
$PokemonTemp.encounterType = -1
pbWildBattle(species,level)
@@ -343,12 +343,12 @@ def pbDebugMenuActions(cmd="",sprites=nil,viewport=nil)
size0 = newSize if newSize>0
elsif pkmnCmd==pkmnCmds.length-3 # Add Pokémon
species = pbChooseSpeciesList
if species!=0
if species
params = ChooseNumberParams.new
params.setRange(1,PBExperience.maxLevel)
params.setInitialValue(5)
params.setCancelValue(0)
level = pbMessageChooseNumber(_INTL("Set the wild {1}'s level.",PBSpecies.getName(species)),params)
level = pbMessageChooseNumber(_INTL("Set the wild {1}'s level.", GameData::Species.get(species).name), params)
if level>0
pkmn.push(Pokemon.new(species,level))
end
@@ -524,7 +524,7 @@ def pbDebugMenuActions(cmd="",sprites=nil,viewport=nil)
#=============================================================================
when "addpokemon"
species = pbChooseSpeciesList
if species!=0
if species
params = ChooseNumberParams.new
params.setRange(1,PBExperience.maxLevel)
params.setInitialValue(5)
@@ -548,48 +548,41 @@ def pbDebugMenuActions(cmd="",sprites=nil,viewport=nil)
end
pbMessage(_INTL("All eggs in your party now require one step to hatch."))
when "fillboxes"
$Trainer.formseen = [] if !$Trainer.formseen
$Trainer.formlastseen = [] if !$Trainer.formlastseen
added = 0; completed = true
speciesData = pbLoadSpeciesData
formdata = pbLoadFormToSpecies
for i in 1..PBSpecies.maxValue
if added>=NUM_STORAGE_BOXES*30
completed = false; break
end
cname = getConstantName(PBSpecies,i) rescue nil
next if !cname
pkmn = Pokemon.new(i,50)
$PokemonStorage[(i-1)/$PokemonStorage.maxPokemon(0),
(i-1)%$PokemonStorage.maxPokemon(0)] = pkmn
# Record all forms of this Pokémon as seen and owned
$Trainer.seen[i] = true
$Trainer.owned[i] = true
$Trainer.formseen[i] = [[],[]]
formdata[i] = [i] if !formdata[i]
for form in 0...formdata[i].length
next if !formdata[i][form] || formdata[i][form]==0
fSpecies = pbGetFSpeciesFromForm(i,form)
formname = pbGetMessage(MessageTypes::FormNames,fSpecies)
genderRate = speciesData[i][SpeciesData::GENDER_RATE] || 0
gender = (genderRate==PBGenderRates::AlwaysFemale) ? 1 : 0
if form==0
case genderRate
when PBGenderRates::AlwaysMale,
PBGenderRates::AlwaysFemale,
PBGenderRates::Genderless
$Trainer.formseen[i][gender][form] = true
$Trainer.formlastseen[i] = [gender,form]
else # Both male and female
$Trainer.formseen[i][0][form] = true
$Trainer.formseen[i][1][form] = true
$Trainer.formlastseen[i] = [0,form]
end
elsif formname && formname!=""
$Trainer.formseen[i][gender][form] = true
$Trainer.formseen = {} if !$Trainer.formseen
$Trainer.formlastseen = {} if !$Trainer.formlastseen
added = 0
box_qty = $PokemonStorage.maxPokemon(0)
completed = true
GameData::Species.each do |species_data|
sp = species_data.species
f = species_data.form
# Record each form of each species as seen and owned
$Trainer.formseen[sp] = [[], []] if !$Trainer.formseen[sp]
if f == 0
$Trainer.seen[sp] = true
$Trainer.owned[sp] = true
if [PBGenderRates::AlwaysMale, PBGenderRates::AlwaysFemale,
PBGenderRates::Genderless].include?(species_data.gender_rate)
g = (species_data.gender_rate == PBGenderRates::AlwaysFemale) ? 1 : 0
$Trainer.formseen[sp][g][f] = true
$Trainer.formlastseen[sp] = [g, f] if f == 0
else # Both male and female
$Trainer.formseen[sp][0][f] = true
$Trainer.formseen[sp][1][f] = true
$Trainer.formlastseen[i] = [0, f] if f == 0
end
elsif species_data.real_form_name && !species_data.real_form_name.empty?
g = (species_data.gender_rate == PBGenderRates::AlwaysFemale) ? 1 : 0
$Trainer.formseen[sp][g][f] = true
end
# Add Pokémon (if form 0)
next if f != 0
if added >= NUM_STORAGE_BOXES * box_qty
completed = false
next
end
added += 1
$PokemonStorage[(added - 1) / box_qty, (added - 1) % box_qty] = Pokemon.new(sp, 50)
end
pbMessage(_INTL("Storage boxes were filled with one Pokémon of each species."))
if !completed
+27 -21
View File
@@ -237,7 +237,7 @@ def pbDebugDayCare
pkmn = $PokemonGlobal.daycare[i][0]
initlevel = $PokemonGlobal.daycare[i][1]
leveldiff = pkmn.level-initlevel
textpos.push([pkmn.name+" ("+PBSpecies.getName(pkmn.species)+")",8+i*Graphics.width/2,y,0,base,shadow])
textpos.push(["#{pkmn.name} (#{pkmn.speciesName})",8+i*Graphics.width/2,y,0,base,shadow])
y += 32
if pkmn.male?
textpos.push([_INTL("Male ♂"),8+i*Graphics.width/2,y,0,Color.new(128,192,248),shadow])
@@ -347,8 +347,7 @@ def pbDebugDayCare
pbDayCareGenerateEgg
$PokemonGlobal.daycareEgg = 0
$PokemonGlobal.daycareEggSteps = 0
pbMessage(_INTL("Collected the {1} egg.",
PBSpecies.getName($Trainer.lastParty.species)))
pbMessage(_INTL("Collected the {1} egg.", $Trainer.lastParty.speciesName))
refresh = true
end
end
@@ -401,7 +400,7 @@ class SpriteWindow_DebugRoamers < Window_DrawableCommand
self.shadowtext(_INTL("[Clear all current roamer locations]"),rect.x,rect.y,nameWidth,rect.height)
else
pkmn = ROAMING_SPECIES[index]
name = PBSpecies.getName(getID(PBSpecies,pkmn[0]))+" (Lv. #{pkmn[1]})"
name = GameData::Species.get(pkmn[0]).name + " (Lv. #{pkmn[1]})"
status = ""
statuscolor = 0
if pkmn[2]<=0 || $game_switches[pkmn[2]]
@@ -528,32 +527,39 @@ end
#===============================================================================
def pbCreatePokemon
party = []
species = [:PIKACHU,:PIDGEOTTO,:KADABRA,:GYARADOS,:DIGLETT,:CHANSEY]
species = [:PIKACHU, :PIDGEOTTO, :KADABRA, :GYARADOS, :DIGLETT, :CHANSEY]
for id in species
party.push(getConst(PBSpecies,id)) if hasConst?(PBSpecies,id)
party.push(id) if GameData::Species.exists?(id)
end
# Species IDs of the Pokémon to be created
for i in 0...party.length
species = party[i]
# Generate Pokémon with species and level 20
$Trainer.party[i] = Pokemon.new(species,20)
$Trainer.seen[species] = true # Set this species to seen and owned
$Trainer.party[i] = Pokemon.new(species, 20)
$Trainer.seen[species] = true
$Trainer.owned[species] = true
pbSeenForm($Trainer.party[i])
case species
when :PIDGEOTTO
$Trainer.party[i].pbLearnMove(:FLY)
when :KADABRA
$Trainer.party[i].pbLearnMove(:FLASH)
$Trainer.party[i].pbLearnMove(:TELEPORT)
when :GYARADOS
$Trainer.party[i].pbLearnMove(:SURF)
$Trainer.party[i].pbLearnMove(:DIVE)
$Trainer.party[i].pbLearnMove(:WATERFALL)
when :DIGLETT
$Trainer.party[i].pbLearnMove(:DIG)
$Trainer.party[i].pbLearnMove(:CUT)
$Trainer.party[i].pbLearnMove(:HEADBUTT)
$Trainer.party[i].pbLearnMove(:ROCKSMASH)
when :CHANSEY
$Trainer.party[i].pbLearnMove(:SOFTBOILED)
$Trainer.party[i].pbLearnMove(:STRENGTH)
$Trainer.party[i].pbLearnMove(:SWEETSCENT)
end
end
$Trainer.party[1].pbLearnMove(:FLY)
$Trainer.party[2].pbLearnMove(:FLASH)
$Trainer.party[2].pbLearnMove(:TELEPORT)
$Trainer.party[3].pbLearnMove(:SURF)
$Trainer.party[3].pbLearnMove(:DIVE)
$Trainer.party[3].pbLearnMove(:WATERFALL)
$Trainer.party[4].pbLearnMove(:DIG)
$Trainer.party[4].pbLearnMove(:CUT)
$Trainer.party[4].pbLearnMove(:HEADBUTT)
$Trainer.party[4].pbLearnMove(:ROCKSMASH)
$Trainer.party[5].pbLearnMove(:SOFTBOILED)
$Trainer.party[5].pbLearnMove(:STRENGTH)
$Trainer.party[5].pbLearnMove(:SWEETSCENT)
for i in 0...party.length
$Trainer.party[i].pbRecordFirstMoves
end
+20 -21
View File
@@ -533,7 +533,7 @@ module PokemonDebugMixin
case cmd
when 0 # Set species
species = pbChooseSpeciesList(pkmn.species)
if species!=0 && species!=pkmn.species
if species && species != pkmn.species
pkmn.species = species
pkmn.calcStats
pbSeenForm(pkmn) if !settingUpBattle
@@ -541,25 +541,24 @@ module PokemonDebugMixin
end
when 1 # Set form
cmd2 = 0
formcmds = [[],[]]
formdata = pbLoadFormToSpecies
formdata[pkmn.species] = [pkmn.species] if !formdata[pkmn.species]
for form in 0...formdata[pkmn.species].length
fSpecies = pbGetFSpeciesFromForm(pkmn.species,form)
formname = pbGetMessage(MessageTypes::FormNames,fSpecies)
formname = _INTL("Unnamed form") if !formname || formname==""
formname = _INTL("{1}: {2}",form,formname)
formcmds[0].push(form); formcmds[1].push(formname)
cmd2 = form if pkmn.form==form
formcmds = [[], []]
GameData::Species.each do |sp|
next if sp.species != pkmn.species
form_name = sp.form_name
form_name = _INTL("Unnamed form") if !form_name || form_name.empty?
form_name = sprintf("%d: %s", sp.form, form_name)
formcmds[0].push(sp.form)
formcmds[1].push(form_name)
cmd2 = sp.form if pkmn.form == sp.form
end
if formcmds[0].length<=1
pbDisplay(_INTL("Species {1} only has one form.",pkmn.speciesName))
if formcmds[0].length <= 1
pbDisplay(_INTL("Species {1} only has one form.", pkmn.speciesName))
else
cmd2 = pbShowCommands(_INTL("Set the Pokémon's form."),formcmds[1],cmd2)
next if cmd2<0
cmd2 = pbShowCommands(_INTL("Set the Pokémon's form."), formcmds[1], cmd2)
next if cmd2 < 0
f = formcmds[0][cmd2]
if f!=pkmn.form
if MultipleForms.hasFunction?(pkmn,"getForm")
if f != pkmn.form
if MultipleForms.hasFunction?(pkmn, "getForm")
next if !pbConfirm(_INTL("This species decides its own form. Override?"))
pkmn.forcedForm = f
end
@@ -599,7 +598,7 @@ module PokemonDebugMixin
when "setnickname"
cmd = 0
loop do
speciesname = PBSpecies.getName(pkmn.species)
speciesname = pkmn.speciesName
msg = [_INTL("{1} has the nickname {2}.",speciesname,pkmn.name),
_INTL("{1} has no nickname.",speciesname)][pkmn.name==speciesname ? 1 : 0]
cmd = pbShowCommands(msg,[
@@ -722,18 +721,18 @@ module PokemonDebugMixin
case cmd
when 0 # Make egg
if !pkmn.egg? && (pbHasEgg?(pkmn.species) ||
pbConfirm(_INTL("{1} cannot legally be an egg. Make egg anyway?",PBSpecies.getName(pkmn.species))))
pbConfirm(_INTL("{1} cannot legally be an egg. Make egg anyway?", pkmn.speciesName)))
pkmn.level = EGG_LEVEL
pkmn.calcStats
pkmn.name = _INTL("Egg")
pkmn.eggsteps = pbGetSpeciesData(pkmn.species,pkmn.form,SpeciesData::STEPS_TO_HATCH)
pkmn.eggsteps = pkmn.species_data.hatch_steps
pkmn.hatchedMap = 0
pkmn.obtainMode = 1
pbRefreshSingle(pkmnid)
end
when 1 # Make Pokémon
if pkmn.egg?
pkmn.name = PBSpecies.getName(pkmn.species)
pkmn.name = pkmn.speciesName
pkmn.eggsteps = 0
pkmn.hatchedMap = 0
pkmn.obtainMode = 0
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+20 -16
View File
@@ -263,16 +263,16 @@ end
module SpeciesProperty
def self.set(_settingname,oldsetting)
ret = pbChooseSpeciesList((oldsetting) ? oldsetting : 1)
return (ret<=0) ? (oldsetting) ? oldsetting : 0 : ret
ret = pbChooseSpeciesList(oldsetting || nil)
return ret || oldsetting
end
def self.defaultValue
return 0
return nil
end
def self.format(value)
return (value) ? PBSpecies.getName(value) : "-"
return (value && GameData::Species.exists?(value)) ? GameData::Species.get(value).real_name : "-"
end
end
@@ -1258,15 +1258,17 @@ class EvolutionsProperty
param_type = PBEvolution.getFunction(realcmds[i][0], "parameterType")
has_param = !PBEvolution.hasFunction?(realcmds[i][0], "parameterType") || param_type != nil
if has_param
if param_type
level = (Object.const_get(param_type).getName(level) rescue getConstantName(param_type, level) rescue level)
if param_type && !GameData.const_defined?(param_type.to_sym)
level = getConstantName(param_type, level)
else
level = level.to_s
end
level = "???" if !level
level = "???" if !level || level.empty?
commands.push(_INTL("{1}: {2}, {3}",
PBSpecies.getName(realcmds[i][2]),@methods[realcmds[i][0]],level.to_s))
GameData::Species.get(realcmds[i][2]).name, @methods[realcmds[i][0]], level.to_s))
else
commands.push(_INTL("{1}: {2}",
PBSpecies.getName(realcmds[i][2]),@methods[realcmds[i][0]]))
GameData::Species.get(realcmds[i][2]).name, @methods[realcmds[i][0]]))
end
end
cmd[1] = i if oldsel>=0 && realcmds[i][3]==oldsel
@@ -1290,7 +1292,7 @@ class EvolutionsProperty
if entry[0]==-1 # Add new evolution path
pbMessage(_INTL("Choose an evolved form, method and parameter."))
newspecies = pbChooseSpeciesList
if newspecies>0
if newspecies
newmethod = pbMessage(_INTL("Choose an evolution method."),@methods,-1)
if newmethod>0
newparam = -1
@@ -1303,7 +1305,7 @@ class EvolutionsProperty
newparam = pbChooseItemList
when :Move
newparam = pbChooseMoveList
when :PBSpecies
when :Species
newparam = pbChooseSpeciesList
when :Type
newparam = pbChooseTypeList
@@ -1343,7 +1345,7 @@ class EvolutionsProperty
_INTL("Change parameter"),_INTL("Delete"),_INTL("Cancel")],5)
if cmd2==0 # Change species
newspecies = pbChooseSpeciesList(entry[2])
if newspecies>0
if newspecies
havemove = -1
for i in 0...realcmds.length
havemove = realcmds[i][3] if realcmds[i][0]==entry[0] &&
@@ -1391,7 +1393,7 @@ class EvolutionsProperty
newparam = pbChooseItemList(entry[1])
when :Move
newparam = pbChooseMoveList(entry[1])
when :PBSpecies
when :Species
newparam = pbChooseSpeciesList(entry[1])
when :Type
newparam = pbChooseTypeList(entry[1])
@@ -1464,11 +1466,13 @@ class EvolutionsProperty
ret << "," if i>0
param = value[i][1]
param_type = PBEvolution.getFunction(value[i][0], "parameterType")
if param_type
param = (Object.const_get(param_type).getName(param) rescue getConstantName(param_type, param) rescue param)
if param_type && !GameData.const_defined?(param_type.to_sym)
param = getConstantName(param_type, param)
else
param = param.to_s
end
param = "" if !param
ret << sprintf("#{PBSpecies.getName(value[i][2])},#{@methods[value[i][0]]},#{param}")
ret << sprintf("#{GameData::Species.get(value[i][2]).name},#{@methods[value[i][0]]},#{param}")
end
return ret
end
+12 -15
View File
@@ -326,12 +326,11 @@ end
#
#===============================================================================
class SpeciesLister
def initialize(selection,includeNew=false)
def initialize(selection = 0, includeNew = false)
@selection = selection
@commands = []
@ids = []
@includeNew = includeNew
@trainers = nil
@index = 0
end
@@ -346,28 +345,27 @@ class SpeciesLister
@commands.clear
@ids.clear
cmds = []
for i in 1..PBSpecies.maxValue
cname = getConstantName(PBSpecies,i) rescue next
name = PBSpecies.getName(i)
cmds.push([i,name]) if name && name!=""
GameData::Species.each do |species|
next if species.form != 0
cmds.push([species.id_number, species.id, species.real_name])
end
cmds.sort! { |a,b| a[1]<=>b[1] }
cmds.sort! { |a, b| a[2].downcase <=> b[2].downcase }
if @includeNew
@commands.push(_INTL("[NEW SPECIES]"))
@ids.push(-1)
@ids.push(true)
end
for i in cmds
@commands.push(sprintf("%03d: %s",i[0],i[1]))
@ids.push(i[0])
@commands.push(sprintf("%03d: %s", i[0], i[2]))
@ids.push(i[1])
end
@index = @selection
@index = @commands.length-1 if @index>=@commands.length
@index = 0 if @index<0
@index = @commands.length - 1 if @index >= @commands.length
@index = 0 if @index < 0
return @commands
end
def value(index)
return nil if index<0
return nil if index < 0
return @ids[index]
end
@@ -385,7 +383,6 @@ class ItemLister
@commands = []
@ids = []
@includeNew = includeNew
@trainers = nil
@index = 0
end
@@ -593,7 +590,7 @@ class TrainerBattleLister
if !@includeNew || index>0
@trainers[(@includeNew) ? index-1 : index][3].each_with_index do |p,i|
text += "\r\n" if i>0
text += sprintf("%s Lv.%d",PBSpecies.getName(p[TrainerData::SPECIES]),p[TrainerData::LEVEL])
text += sprintf("%s Lv.%d",GameData::Species.get(p[TrainerData::SPECIES]).name, p[TrainerData::LEVEL])
end
end
@pkmnList.text = text
+15 -27
View File
@@ -1,17 +1,12 @@
def pbGetLegalMoves(species)
species_data = GameData::Species.get(species)
moves = []
return moves if !species || species<=0
moveset = pbGetSpeciesMoveset(species)
moveset.each { |m| moves.push(m[1]) }
tmdat = pbLoadSpeciesTMData
GameData::Item.each do |i|
next if !i.move
moves.push(i.move) if tmdat[i.move] && tmdat[i.move].include?(species)
end
return moves if !species_data
species_data.moves.each { |m| moves.push(m[1]) }
species_data.tutor_moves.each { |m| moves.push(m[1]) }
babyspecies = EvolutionHelper.baby_species(species)
eggMoves = pbGetSpeciesEggMoves(babyspecies)
eggMoves.each { |m| moves.push(m) }
moves |= []
GameData::Species.get(babyspecies).egg_moves.each { |m| moves.push(m) }
moves |= [] # Remove duplicates
return moves
end
@@ -215,26 +210,19 @@ def pbGetHabitatConst(i)
return ret
end
def pbGetSpeciesConst(i)
return MakeshiftConsts.get(MessageTypes::Species,i,PBSpecies)
end
#===============================================================================
# List all members of a class
#===============================================================================
# Displays a list of all Pokémon species, and returns the ID of the species
# selected (or 0 if the selection was canceled). "default", if specified, is the
# ID of the species to initially select. Pressing Input::A will toggle the list
# sorting between numerical and alphabetical.
def pbChooseSpeciesList(default=0)
# selected (or nil if the selection was canceled). "default", if specified, is
# the ID of the species to initially select. Pressing Input::A will toggle the
# list sorting between numerical and alphabetical.
def pbChooseSpeciesList(default = nil)
commands = []
for i in 1..PBSpecies.maxValue
cname = getConstantName(PBSpecies,i) rescue nil
commands.push([i,PBSpecies.getName(i)]) if cname
end
return pbChooseList(commands,default,0,-1)
GameData::Species.each { |s| commands.push([s.id_number, s.real_name, s.id]) if s.form == 0 }
return pbChooseList(commands, default, nil, -1)
end
# Displays a list of all moves, and returns the ID of the move selected (or nil
@@ -243,7 +231,7 @@ end
# numerical and alphabetical.
def pbChooseMoveList(default = nil)
commands = []
GameData::Move.each { |i| commands.push([i.id_number, i.name, i.id]) }
GameData::Move.each { |i| commands.push([i.id_number, i.real_name, i.id]) }
return pbChooseList(commands, default, nil, -1)
end
@@ -407,10 +395,10 @@ def pbCommands3(cmdwindow,commands,cmdIfCancel,defaultindex=-1,noresize=false)
elsif Input.repeat?(Input::DOWN)
command = [2,cmdwindow.index]
break
elsif Input.press?(Input::LEFT)
elsif Input.trigger?(Input::LEFT)
command = [3,cmdwindow.index]
break
elsif Input.press?(Input::RIGHT)
elsif Input.trigger?(Input::RIGHT)
command = [4,cmdwindow.index]
break
end
@@ -4,50 +4,45 @@
def findBottom(bitmap)
return 0 if !bitmap
for i in 1..bitmap.height
for j in 0..bitmap.width-1
return bitmap.height-i if bitmap.get_pixel(j,bitmap.height-i).alpha>0
for j in 0..bitmap.width - 1
return bitmap.height - i if bitmap.get_pixel(j, bitmap.height - i).alpha > 0
end
end
return 0
end
def pbAutoPositionAll
metrics = pbLoadSpeciesMetrics
for i in 1..PBSpecies.maxValueF
s = pbGetSpeciesFromFSpecies(i)
Graphics.update if i%50==0
bitmap1 = pbLoadSpeciesBitmap(s[0],false,s[1],false,false,true)
bitmap2 = pbLoadSpeciesBitmap(s[0],false,s[1])
metrics[SpeciesData::METRIC_PLAYER_X][i] = 0 # Player's x
GameData::Species.each do |sp|
Graphics.update if sp.id_number % 50 == 0
bitmap1 = GameData::Species.sprite_bitmap(sp.species, sp.form, nil, nil, nil, true)
bitmap2 = GameData::Species.sprite_bitmap(sp.species, sp.form)
if bitmap1 && bitmap1.bitmap # Player's y
metrics[SpeciesData::METRIC_PLAYER_Y][i] = (bitmap1.height-(findBottom(bitmap1.bitmap)+1))/2
sp.back_sprite_x = 0
sp.back_sprite_y = (bitmap1.height - (findBottom(bitmap1.bitmap) + 1)) / 2
end
metrics[SpeciesData::METRIC_ENEMY_X][i] = 0 # Foe's x
if bitmap2 && bitmap2.bitmap # Foe's y
metrics[SpeciesData::METRIC_ENEMY_Y][i] = (bitmap2.height-(findBottom(bitmap2.bitmap)+1))/2
metrics[SpeciesData::METRIC_ENEMY_Y][i] += 4 # Just because
sp.front_sprite_x = 0
sp.front_sprite_y = (bitmap2.height - (findBottom(bitmap2.bitmap) + 1)) / 2
sp.front_sprite_y += 4 # Just because
end
metrics[SpeciesData::METRIC_ALTITUDE][i] = 0 # Foe's altitude, not used now
metrics[SpeciesData::METRIC_SHADOW_X][i] = 0 # Shadow's x
metrics[SpeciesData::METRIC_SHADOW_SIZE][i] = 2 # Shadow size
sp.front_sprite_altitude = 0 # Shouldn't be used
sp.shadow_x = 0
sp.shadow_size = 2
bitmap1.dispose if bitmap1
bitmap2.dispose if bitmap2
end
save_data(metrics,"Data/species_metrics.dat")
$PokemonTemp.speciesMetrics = nil
GameData::Species.save
pbSavePokemonData
pbSavePokemonFormsData
end
#===============================================================================
#
#===============================================================================
class SpritePositioner
def pbOpen
@sprites = {}
@viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
@viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
@viewport.z = 99999
battlebg = "Graphics/Battlebacks/indoor1_bg"
playerbase = "Graphics/Battlebacks/indoor1_base0"
@@ -56,21 +51,21 @@ class SpritePositioner
@sprites["battle_bg"].setBitmap(battlebg)
@sprites["battle_bg"].z = 0
baseX, baseY = PokeBattle_SceneConstants.pbBattlerPosition(0)
@sprites["base_0"] = IconSprite.new(baseX,baseY,@viewport)
@sprites["base_0"] = IconSprite.new(baseX, baseY, @viewport)
@sprites["base_0"].setBitmap(playerbase)
@sprites["base_0"].x -= @sprites["base_0"].bitmap.width/2 if @sprites["base_0"].bitmap
@sprites["base_0"].x -= @sprites["base_0"].bitmap.width / 2 if @sprites["base_0"].bitmap
@sprites["base_0"].y -= @sprites["base_0"].bitmap.height if @sprites["base_0"].bitmap
@sprites["base_0"].z = 1
baseX, baseY = PokeBattle_SceneConstants.pbBattlerPosition(1)
@sprites["base_1"] = IconSprite.new(baseX,baseY,@viewport)
@sprites["base_1"] = IconSprite.new(baseX, baseY, @viewport)
@sprites["base_1"].setBitmap(enemybase)
@sprites["base_1"].x -= @sprites["base_1"].bitmap.width/2 if @sprites["base_1"].bitmap
@sprites["base_1"].y -= @sprites["base_1"].bitmap.height/2 if @sprites["base_1"].bitmap
@sprites["base_1"].x -= @sprites["base_1"].bitmap.width / 2 if @sprites["base_1"].bitmap
@sprites["base_1"].y -= @sprites["base_1"].bitmap.height / 2 if @sprites["base_1"].bitmap
@sprites["base_1"].z = 1
@sprites["messageBox"] = IconSprite.new(0,Graphics.height-96,@viewport)
@sprites["messageBox"] = IconSprite.new(0, Graphics.height - 96, @viewport)
@sprites["messageBox"].setBitmap("Graphics/Pictures/Battle/debug_message")
@sprites["messageBox"].z = 2
@sprites["shadow_1"] = IconSprite.new(0,0,@viewport)
@sprites["shadow_1"] = IconSprite.new(0, 0, @viewport)
@sprites["shadow_1"].z = 3
@sprites["pokemon_0"] = PokemonSprite.new(@viewport)
@sprites["pokemon_0"].setOffset(PictureOrigin::Bottom)
@@ -82,19 +77,18 @@ class SpritePositioner
@sprites["info"].viewport = @viewport
@sprites["info"].visible = false
@oldSpeciesIndex = 0
@species = 0
@metrics = pbLoadSpeciesMetrics
@species = nil # This can be a species_form
@metricsChanged = false
refresh
@starting = true
end
def pbClose
if @metricsChanged
if pbConfirmMessage(_INTL("Some metrics have been edited. Save changes?"))
pbSaveMetrics
@metricsChanged = false
end
if @metricsChanged && pbConfirmMessage(_INTL("Some metrics have been edited. Save changes?"))
pbSaveMetrics
@metricsChanged = false
else
GameData::Species.load # Clear all changes to metrics
end
pbFadeOutAndHide(@sprites) { update }
pbDisposeSpriteHash(@sprites)
@@ -102,8 +96,7 @@ class SpritePositioner
end
def pbSaveMetrics
save_data(@metrics,"Data/species_metrics.dat")
$PokemonTemp.speciesMetrics = nil
GameData::Species.save
pbSavePokemonData
pbSavePokemonFormsData
end
@@ -113,44 +106,46 @@ class SpritePositioner
end
def refresh
if @species<=0
if !@species
@sprites["pokemon_0"].visible = false
@sprites["pokemon_1"].visible = false
@sprites["shadow_1"].visible = false
return
end
species_data = GameData::Species.get(@species)
for i in 0...2
pos = PokeBattle_SceneConstants.pbBattlerPosition(i,1)
pos = PokeBattle_SceneConstants.pbBattlerPosition(i, 1)
@sprites["pokemon_#{i}"].x = pos[0]
@sprites["pokemon_#{i}"].y = pos[1]
pbApplyBattlerMetricsToSprite(@sprites["pokemon_#{i}"],i,@species,false,@metrics)
species_data.apply_metrics_to_sprite(@sprites["pokemon_#{i}"], i)
@sprites["pokemon_#{i}"].visible = true
if i==1
if i == 1
@sprites["shadow_1"].x = pos[0]
@sprites["shadow_1"].y = pos[1]
if @sprites["shadow_1"].bitmap
@sprites["shadow_1"].x -= @sprites["shadow_1"].bitmap.width/2
@sprites["shadow_1"].y -= @sprites["shadow_1"].bitmap.height/2
@sprites["shadow_1"].x -= @sprites["shadow_1"].bitmap.width / 2
@sprites["shadow_1"].y -= @sprites["shadow_1"].bitmap.height / 2
end
pbApplyBattlerMetricsToSprite(@sprites["shadow_1"],i,@species,true,@metrics)
species_data.apply_metrics_to_sprite(@sprites["shadow_1"], i, true)
@sprites["shadow_1"].visible = true
end
end
end
def pbAutoPosition
oldmetric1 = (@metrics[SpeciesData::METRIC_PLAYER_Y][@species] || 0)
oldmetric3 = (@metrics[SpeciesData::METRIC_ENEMY_Y][@species] || 0)
oldmetric4 = (@metrics[SpeciesData::METRIC_ALTITUDE][@species] || 0)
species_data = GameData::Species.get(@species)
old_back_y = species_data.back_sprite_y
old_front_y = species_data.front_sprite_y
old_front_altitude = species_data.front_sprite_altitude
bitmap1 = @sprites["pokemon_0"].bitmap
bitmap2 = @sprites["pokemon_1"].bitmap
newmetric1 = (bitmap1.height-(findBottom(bitmap1)+1))/2
newmetric3 = (bitmap2.height-(findBottom(bitmap2)+1))/2
newmetric3 += 4 # Just because
if newmetric1!=oldmetric1 || newmetric3!=oldmetric3 || oldmetric4!=0
@metrics[SpeciesData::METRIC_PLAYER_Y][@species] = newmetric1
@metrics[SpeciesData::METRIC_ENEMY_Y][@species] = newmetric3
@metrics[SpeciesData::METRIC_ALTITUDE][@species] = 0
new_back_y = (bitmap1.height - (findBottom(bitmap1) + 1)) / 2
new_front_y = (bitmap2.height - (findBottom(bitmap2) + 1)) / 2
new_front_y += 4 # Just because
if new_back_y != old_back_y || new_front_y != old_front_y || old_front_altitude != 0
species_data.back_sprite_y = new_back_y
species_data.front_sprite_y = new_front_y
species_data.front_sprite_altitude = 0
@metricsChanged = true
refresh
end
@@ -158,25 +153,32 @@ class SpritePositioner
def pbChangeSpecies(species)
@species = species
spe,frm = pbGetSpeciesFromFSpecies(@species)
@sprites["pokemon_0"].setSpeciesBitmap(spe,false,frm,false,false,true)
@sprites["pokemon_1"].setSpeciesBitmap(spe,false,frm,false,false,false)
@sprites["shadow_1"].setBitmap(pbCheckPokemonShadowBitmapFiles(spe,frm,@metrics))
species_data = GameData::Species.try_get(@species)
return if !species_data
spe = species_data.species
frm = species_data.form
@sprites["pokemon_0"].setSpeciesBitmap(spe, 0, frm, false, false, true)
@sprites["pokemon_1"].setSpeciesBitmap(spe, 0, frm)
# TODO
@sprites["shadow_1"].setBitmap(GameData::Species.shadow_filename(spe, frm))
end
def pbShadowSize
pbChangeSpecies(@species)
refresh
oldval = (@metrics[SpeciesData::METRIC_SHADOW_SIZE][@species] || 2)
cmdvals = [0]; commands = [_INTL("None")]
species_data = GameData::Species.get(@species)
oldval = species_data.shadow_size
cmdvals = [0]
commands = [_INTL("None")]
defindex = 0
i = 0
loop do
i += 1
fn = sprintf("Graphics/Pictures/Battle/battler_shadow_%d",i)
fn = sprintf("Graphics/Pictures/Battle/battler_shadow_%d", i)
break if !pbResolveBitmap(fn)
cmdvals.push(i); commands.push(i.to_s)
defindex = cmdvals.length-1 if oldval==i
cmdvals.push(i)
commands.push(i.to_s)
defindex = cmdvals.length - 1 if oldval == i
end
cw = Window_CommandPokemon.new(commands)
cw.index = defindex
@@ -188,19 +190,19 @@ class SpritePositioner
Input.update
cw.update
self.update
if cw.index!=oldindex
if cw.index != oldindex
oldindex = cw.index
@metrics[SpeciesData::METRIC_SHADOW_SIZE][@species] = cmdvals[cw.index]
species_data.shadow_size = cmdvals[cw.index]
pbChangeSpecies(@species)
refresh
end
if Input.trigger?(Input::A) # Cycle to next option
pbPlayDecisionSE
@metricsChanged = true if @metrics[SpeciesData::METRIC_SHADOW_SIZE][@species]!=oldval
@metricsChanged = true if species_data.shadow_size != oldval
ret = true
break
elsif Input.trigger?(Input::B)
@metrics[SpeciesData::METRIC_SHADOW_SIZE][@species] = oldval
species_data.shadow_size = oldval
pbPlayCancelSE
break
elsif Input.trigger?(Input::C)
@@ -213,25 +215,25 @@ class SpritePositioner
end
def pbSetParameter(param)
return if @species<=0
if param==2
return pbShadowSize
elsif param==4
return if !@species
return pbShadowSize if param == 2
if param == 4
pbAutoPosition
return false
end
species_data = GameData::Species.get(@species)
case param
when 0
sprite = @sprites["pokemon_0"]
xpos = (@metrics[SpeciesData::METRIC_PLAYER_X][@species] || 0)
ypos = (@metrics[SpeciesData::METRIC_PLAYER_Y][@species] || 0)
xpos = species_data.back_sprite_x
ypos = species_data.back_sprite_y
when 1
sprite = @sprites["pokemon_1"]
xpos = (@metrics[SpeciesData::METRIC_ENEMY_X][@species] || 0)
ypos = (@metrics[SpeciesData::METRIC_ENEMY_Y][@species] || 0)
xpos = species_data.front_sprite_x
ypos = species_data.front_sprite_y
when 3
sprite = @sprites["shadow_1"]
xpos = (@metrics[SpeciesData::METRIC_SHADOW_X][@species] || 0)
xpos = species_data.shadow_x
ypos = 0
end
oldxpos = xpos
@@ -239,7 +241,7 @@ class SpritePositioner
@sprites["info"].visible = true
ret = false
loop do
sprite.visible = (Graphics.frame_count%16)<12
sprite.visible = (Graphics.frame_count % 16) < 12 # Flash the selected sprite
Graphics.update
Input.update
self.update
@@ -248,59 +250,44 @@ class SpritePositioner
when 1 then @sprites["info"].setTextToFit("Enemy Position = #{xpos},#{ypos}")
when 3 then @sprites["info"].setTextToFit("Shadow Position = #{xpos}")
end
if Input.repeat?(Input::UP) && param!=3
ypos -= 1
if (Input.repeat?(Input::UP) || Input.repeat?(Input::DOWN)) && param != 3
ypos += (Input.repeat?(Input::DOWN)) ? 1 : -1
case param
when 0 then @metrics[SpeciesData::METRIC_PLAYER_Y][@species] = ypos
when 1 then @metrics[SpeciesData::METRIC_ENEMY_Y][@species] = ypos
end
refresh
elsif Input.repeat?(Input::DOWN) && param!=3
ypos += 1
case param
when 0 then @metrics[SpeciesData::METRIC_PLAYER_Y][@species] = ypos
when 1 then @metrics[SpeciesData::METRIC_ENEMY_Y][@species] = ypos
when 0 then species_data.back_sprite_y = ypos
when 1 then species_data.front_sprite_y = ypos
end
refresh
end
if Input.repeat?(Input::LEFT)
xpos -= 1
if Input.repeat?(Input::LEFT) || Input.repeat?(Input::RIGHT)
xpos += (Input.repeat?(Input::RIGHT)) ? 1 : -1
case param
when 0 then @metrics[SpeciesData::METRIC_PLAYER_X][@species] = xpos
when 1 then @metrics[SpeciesData::METRIC_ENEMY_X][@species] = xpos
when 3 then @metrics[SpeciesData::METRIC_SHADOW_X][@species] = xpos
end
refresh
elsif Input.repeat?(Input::RIGHT)
xpos += 1
case param
when 0 then @metrics[SpeciesData::METRIC_PLAYER_X][@species] = xpos
when 1 then @metrics[SpeciesData::METRIC_ENEMY_X][@species] = xpos
when 3 then @metrics[SpeciesData::METRIC_SHADOW_X][@species] = xpos
when 0 then species_data.back_sprite_x = xpos
when 1 then species_data.front_sprite_x = xpos
when 3 then species_data.shadow_x = xpos
end
refresh
end
if Input.repeat?(Input::A) && param!=3 # Cycle to next option
@metricsChanged = true if xpos!=oldxpos || ypos!=oldypos
if Input.repeat?(Input::A) && param != 3 # Cycle to next option
@metricsChanged = true if xpos != oldxpos || ypos != oldypos
ret = true
pbPlayDecisionSE
break
elsif Input.repeat?(Input::B)
case param
when 0
@metrics[SpeciesData::METRIC_PLAYER_X][@species] = oldxpos
@metrics[SpeciesData::METRIC_PLAYER_Y][@species] = oldypos
species_data.back_sprite_x = oldxpos
species_data.back_sprite_y = oldypos
when 1
@metrics[SpeciesData::METRIC_ENEMY_X][@species] = oldxpos
@metrics[SpeciesData::METRIC_ENEMY_Y][@species] = oldypos
species_data.front_sprite_x = oldxpos
species_data.front_sprite_y = oldypos
when 3
@metrics[SpeciesData::METRIC_SHADOW_X][@species] = oldxpos
species_data.shadow_x = oldxpos
end
pbPlayCancelSE
refresh
break
elsif Input.repeat?(Input::C)
@metricsChanged = true if xpos!=oldxpos || (param!=3 && ypos!=oldypos)
@metricsChanged = true if xpos != oldxpos || (param != 3 && ypos != oldypos)
pbPlayDecisionSE
break
end
@@ -320,8 +307,8 @@ class SpritePositioner
_INTL("Set Shadow Position"),
_INTL("Auto-Position Sprites")
])
cw.x = Graphics.width-cw.width
cw.y = Graphics.height-cw.height
cw.x = Graphics.width - cw.width
cw.y = Graphics.height - cw.height
cw.viewport = @viewport
ret = -1
loop do
@@ -347,55 +334,49 @@ class SpritePositioner
pbFadeInAndShow(@sprites) { update }
@starting = false
end
cw = Window_CommandPokemonEx.newEmpty(0,0,260,32+24*6,@viewport)
cw = Window_CommandPokemonEx.newEmpty(0, 0, 260, 32 + 24 * 6, @viewport)
cw.rowHeight = 24
pbSetSmallFont(cw.contents)
cw.x = Graphics.width-cw.width
cw.y = Graphics.height-cw.height
cw.x = Graphics.width - cw.width
cw.y = Graphics.height - cw.height
allspecies = []
GameData::Species.each do |sp|
name = (sp.form == 0) ? sp.name : _INTL("{1} (form {2})", sp.real_name, sp.form)
allspecies.push([sp.id, sp.species, name]) if name && !name.empty?
end
allspecies.sort! { |a, b| a[2] <=> b[2] }
commands = []
for i in 1..PBSpecies.maxValueF
s = pbGetSpeciesFromFSpecies(i)
name = PBSpecies.getName(s[0])
name = _INTL("{1} (form {2})",name,s[1]) if s[1]>0
allspecies.push([i,s[0],name]) if name!=""
end
allspecies.sort! { |a,b| a[1]==b[1] ? a[0]<=>b[0] : a[2]<=>b[2] }
for s in allspecies
commands.push(_INTL("{1} - {2}",s[1],s[2]))
end
allspecies.each { |sp| commands.push(sp[2]) }
cw.commands = commands
cw.index = @oldSpeciesIndex
species = 0
ret = nil
oldindex = -1
loop do
Graphics.update
Input.update
cw.update
if cw.index!=oldindex
if cw.index != oldindex
oldindex = cw.index
pbChangeSpecies(allspecies[cw.index][0])
refresh
end
self.update
if Input.trigger?(Input::B)
pbChangeSpecies(0)
pbChangeSpecies(nil)
refresh
break
elsif Input.trigger?(Input::C)
pbChangeSpecies(allspecies[cw.index][0])
species = allspecies[cw.index][0]
ret = allspecies[cw.index][0]
break
end
end
@oldSpeciesIndex = cw.index
cw.dispose
return species
return ret
end
end
#===============================================================================
#
#===============================================================================
@@ -408,14 +389,14 @@ class SpritePositionerScreen
@scene.pbOpen
loop do
species = @scene.pbChooseSpecies
break if species<=0
break if !species
loop do
command = @scene.pbMenu(species)
break if command<0
break if command < 0
loop do
par = @scene.pbSetParameter(command)
break if !par
command = (command+1)%3
command = (command + 1) % 3
end
end
end
@@ -1,3 +1,4 @@
# NOTE: Everything in here is unused.
#===============================================================================
# Serial record
#===============================================================================
@@ -277,6 +278,7 @@ end
#===============================================================================
# Scripted constants
#===============================================================================
# Unused
def pbFindScript(a,name)
a.each { |i|
next if !i
@@ -285,7 +287,7 @@ def pbFindScript(a,name)
return nil
end
# TODO: Will be unused once PBSpecies is abolished. Method above only used by this one.
# Unused
def pbAddScript(script,sectionname)
begin
scripts = load_data("Data/Constants.rxdata")
+27 -21
View File
@@ -109,10 +109,10 @@ module Compiler
end
end
lineno += 1
Graphics.update if lineno%500==0
Graphics.update if lineno%200==0
pbSetWindowText(_INTL("Processing {1} line {2}",FileLineData.file,lineno)) if lineno%50==0
}
yield lastsection,sectionname if havesection
yield lastsection,sectionname if havesection
end
# Used for pokemon.txt
@@ -566,18 +566,22 @@ module Compiler
clonitem.sub!(/\s*$/, "")
itm = GameData::Item.try_get(clonitem)
if !itm
raise _INTL("Undefined item constant name: {1}\r\nName must consist only of letters, numbers and\r\nunderscores, and can't begin with a number.\r\nMake sure the item is defined in\r\nPBS/items.txt.\r\n{2}", item, FileLineData.linereport)
raise _INTL("Undefined item constant name: {1}\r\nMake sure the item is defined in PBS/items.txt.\r\n{2}", item, FileLineData.linereport)
end
return itm.id
end
def parseSpecies(item)
clonitem = item.upcase
clonitem.gsub!(/^[\s\n]*/,"")
clonitem.gsub!(/[\s\n]*$/,"")
clonitem = "NIDORANmA" if clonitem=="NIDORANMA"
clonitem = "NIDORANfE" if clonitem=="NIDORANFE"
return pbGetConst(PBSpecies,clonitem,_INTL("Undefined species constant name: [%s]\r\nName must consist only of letters, numbers, and\r\nunderscores and can't begin with a number.\r\nMake sure the name is defined in\r\nPBS/pokemon.txt.\r\n{1}",FileLineData.linereport))
def parseSpecies(species)
clonspecies = species.upcase
clonspecies.gsub!(/^\s*/, "")
clonspecies.gsub!(/\s*$/, "")
clonspecies = "NIDORANmA" if clonspecies == "NIDORANMA"
clonspecies = "NIDORANfE" if clonspecies == "NIDORANFE"
spec = GameData::Species.try_get(clonspecies)
if !spec
raise _INTL("Undefined species constant name: {1}\r\nMake sure the species is defined in PBS/pokemon.txt.\r\n{2}", species, FileLineData.linereport)
end
return spec.id
end
def parseMove(move, skip_unknown = false)
@@ -587,7 +591,7 @@ module Compiler
mov = GameData::Move.try_get(clonmove)
if !mov
return nil if skip_unknown
raise _INTL("Undefined move constant name: {1}\r\nName must consist only of letters, numbers and\r\nunderscores, and can't begin with a number.\r\nMake sure the move is defined in\r\nPBS/moves.txt.\r\n{2}", move, FileLineData.linereport)
raise _INTL("Undefined move constant name: {1}\r\nMake sure the move is defined in PBS/moves.txt.\r\n{2}", move, FileLineData.linereport)
end
return mov.id
end
@@ -595,9 +599,9 @@ module Compiler
# Unused
def parseNature(item)
clonitem = item.upcase
clonitem.sub!(/^\s*/,"")
clonitem.sub!(/\s*$/,"")
return pbGetConst(PBNatures,clonitem,_INTL("Undefined nature constant name: %s\r\nName must consist only of letters, numbers, and\r\nunderscores and can't begin with a number.\r\nMake sure the name is defined in\r\nthe script section PBNatures.\r\n{1}",FileLineData.linereport))
clonitem.sub!(/^\s*/, "")
clonitem.sub!(/\s*$/, "")
return pbGetConst(PBNatures, clonitem, _INTL("Undefined nature constant name: {1}\r\nMake sure the name is defined in the script section PBNatures.\r\n{1}", item, FileLineData.linereport))
end
# Unused
@@ -607,7 +611,7 @@ module Compiler
clontype.sub!(/\s*$/, "")
typ = GameData::TrainerType.try_get(clontype)
if !typ
raise _INTL("Undefined Trainer type constant name: {1}\r\nName must consist only of letters, numbers and\r\nunderscores, and can't begin with a number.\r\nMake sure the trainer type is defined in\r\ntrainertypes.txt.\r\n{2}", type, FileLineData.linereport)
raise _INTL("Undefined Trainer type constant name: {1}\r\nMake sure the trainer type is defined in PBS/trainertypes.txt.\r\n{2}", type, FileLineData.linereport)
end
return typ.id
end
@@ -638,13 +642,13 @@ module Compiler
yield(_INTL("Compiling Pokémon data"))
compile_pokemon # Depends on Move, Item, Type, Ability
yield(_INTL("Compiling Pokémon forms data"))
compile_pokemon_forms # Depends on PBSpecies, Move, Item, Type, Ability
compile_pokemon_forms # Depends on Species, Move, Item, Type, Ability
yield(_INTL("Compiling machine data"))
compile_move_compatibilities # Depends on PBSpecies, Move
compile_move_compatibilities # Depends on Species, Move
yield(_INTL("Compiling Trainer type data"))
compile_trainer_types # No dependencies
yield(_INTL("Compiling Trainer data"))
compile_trainers # Depends on PBSpecies, Item, Move
compile_trainers # Depends on Species, Item, Move
yield(_INTL("Compiling phone data"))
compile_phone
yield(_INTL("Compiling metadata"))
@@ -652,9 +656,11 @@ module Compiler
yield(_INTL("Compiling battle Trainer data"))
compile_trainer_lists # Depends on TrainerType
yield(_INTL("Compiling encounter data"))
compile_encounters # Depends on PBSpecies
compile_encounters # Depends on Species
yield(_INTL("Compiling shadow moveset data"))
compile_shadow_movesets # Depends on PBSpecies, Move
compile_shadow_movesets # Depends on Species, Move
yield(_INTL("Compiling Regional Dexes"))
compile_regional_dexes # Depends on Species
yield(_INTL("Compiling animations"))
compile_animations
yield(_INTL("Converting events"))
@@ -704,8 +710,8 @@ module Compiler
"phone.txt",
"pokemon.txt",
"pokemonforms.txt",
"regionaldexes.txt",
"shadowmoves.txt",
"tm.txt",
"townmap.txt",
"trainerlists.txt",
"trainers.txt",
+382 -428
View File
@@ -262,8 +262,8 @@ module Compiler
# Read a whole section's lines at once, then run through this code.
# contents is a hash containing all the XXX=YYY lines in that section, where
# the keys are the XXX and the values are the YYY (as unprocessed strings).
schema = GameData::Type::SCHEMA
pbEachFileSection(f) { |contents, type_number|
schema = GameData::Type::SCHEMA
# Go through schema hash of compilable data and compile this section
for key in schema.keys
FileLineData.setSection(type_number, key, contents[key]) # For error reporting
@@ -555,506 +555,460 @@ module Compiler
# Compile Pokémon
#=============================================================================
def compile_pokemon
# Get schemas.
requiredValues = SpeciesData.requiredValues
optionalValues = SpeciesData.optionalValues
# Prepare arrays for compiled data.
speciesData = []
movesets = []
eggMoves = []
regionalDexes = []
spriteMetrics = []
evolutions = []
speciesNames = []
formNames = []
pokedexKinds = []
pokedexEntries = []
# Prepare variables used to record scripted constants.
constants = ""
maxValue = 0 # Highest species ID
# Read from PBS file.
File.open("PBS/pokemon.txt","rb") { |f|
GameData::Species::DATA.clear
species_names = []
species_form_names = []
species_categories = []
species_pokedex_entries = []
# Read from PBS file
File.open("PBS/pokemon.txt", "rb") { |f|
FileLineData.file = "PBS/pokemon.txt" # For error reporting
# Read a whole section's lines at once, then run through this code.
# contents is a hash containing all the XXX=YYY lines in that section, where
# the keys are the XXX and the values are the YYY (as unprocessed strings).
pbEachFileSection(f) { |contents,speciesID|
# Raise an error if the species ID is 0.
if speciesID==0
schema = GameData::Species.schema
pbEachFileSection(f) { |contents, species_number|
FileLineData.setSection(species_number, "header", nil) # For error reporting
# Raise an error if a species number is invalid or used twice
if species_number == 0
raise _INTL("A Pokémon species can't be numbered 0 (PBS/pokemon.txt).")
elsif GameData::Species::DATA[species_number]
raise _INTL("Species ID number '{1}' is used twice.\r\n{2}", species_number, FileLineData.linereport)
end
# Raise an error if the species ID has already been defined.
if speciesData[speciesID]
raise _INTL("Species ID number '{1}' is used twice.\r\n{2}",speciesID,FileLineData.linereport)
end
# Create array to store compiled data in.
speciesData[speciesID] = []
# Copy Type1 into Type2 if Type2 is undefined. (All species must have two
# defined types; if both are the same, it is treated as single typed.)
if !contents["Type2"] || contents["Type2"]==""
if !contents["Type1"] || contents["Type1"]==""
raise _INTL("No Pokémon type is defined in section {1} (PBS/pokemon.txt)",speciesID.to_s)
# Go through schema hash of compilable data and compile this section
for key in schema.keys
# Skip empty properties, or raise an error if a required property is
# empty
if contents[key].nil? || contents[key] == ""
if ["Name", "InternalName"].include?(key)
raise _INTL("The entry {1} is required in PBS/pokemon.txt section {2}.", key, species_number)
end
contents[key] = nil
next
end
contents["Type2"] = contents["Type1"].clone
end
# Go through hashes of compilable data and compile this section.
[requiredValues,optionalValues].each do |hash|
for key in hash.keys
FileLineData.setSection(speciesID,key,contents[key]) # For error reporting
maxValue = [maxValue,speciesID].max # Set highest species ID
next if hash[key][0]<0 # Property is not to be compiled; skip it
# Skip empty optional properties, or raise an error if a required
# property is empty.
if !contents[key] || contents[key]==""
raise _INTL("Required entry {1} is missing or empty in section {2} (PBS/pokemon.txt)",
key,speciesID.to_s) if hash==requiredValues
next
# Raise an error if a species internal name is used twice
FileLineData.setSection(species_number, key, contents[key]) # For error reporting
if GameData::Species::DATA[contents["InternalName"].to_sym]
raise _INTL("Species ID '{1}' is used twice.\r\n{2}", contents["InternalName"], FileLineData.linereport)
end
# Compile value for key
value = pbGetCsvRecord(contents[key], key, schema[key])
value = nil if value.is_a?(Array) && value.length == 0
contents[key] = value
# Sanitise data
case key
when "Height", "Weight"
# Convert height/weight to 1 decimal place and multiply by 10
value = (value * 10).round
if value <= 0
raise _INTL("Value for '{1}' can't be less than or close to 0 (section {2}, PBS/pokemon.txt)", key, species_number)
end
# Compile value for key.
schema = hash[key]
value = pbGetCsvRecord(contents[key],key,schema)
# Modify value as required.
case key
when "Height", "Weight"
# Convert height/weight to 1 decimal place and multiply by 10.
value = (value*10).round
if value<=0
raise _INTL("Value for '{1}' can't be less than or close to 0 (section {2}, PBS/pokemon.txt)",key,speciesID)
end
contents[key] = value
when "Moves"
move_array = []
for i in 0...value.length / 2
move_array.push([value[i * 2], value[i * 2 + 1], i])
end
# Add value to appropriate array for saving.
case key
when "Moves"
speciesMoves = []
for i in 0...value.length/2
speciesMoves.push([value[i*2],value[i*2+1],i])
end
speciesMoves.sort! { |a,b| (a[0]==b[0]) ? a[2]<=>b[2] : a[0]<=>b[0] }
for i in speciesMoves; i.pop; end
movesets[speciesID] = speciesMoves
when "EggMoves"
if value.is_a?(Array); eggMoves[speciesID] = value
else; eggMoves[speciesID] = [value]
end
when "RegionalNumbers"
if value.is_a?(Array)
value.each_with_index do |num,dexID|
regionalDexes[dexID] = [] if !regionalDexes[dexID]
regionalDexes[dexID][speciesID] = num
end
else
regionalDexes[0] = [] if !regionalDexes[0]
regionalDexes[0][speciesID] = value
end
when "BattlerPlayerX", "BattlerPlayerY",
"BattlerEnemyX", "BattlerEnemyY",
"BattlerAltitude", "BattlerShadowX", "BattlerShadowSize"
spriteMetrics[schema[0]] = [] if !spriteMetrics[schema[0]]
spriteMetrics[schema[0]][speciesID] = value
when "Evolutions"
speciesEvolutions = []
for i in 0...value.length/3
speciesEvolutions.push([value[i*3],value[i*3+1],value[i*3+2],false])
end
evolutions[speciesID] = speciesEvolutions
when "Name"
speciesNames[speciesID] = value
when "FormName"
formNames[speciesID] = value
when "Kind"
pokedexKinds[speciesID] = value
when "Pokedex"
pokedexEntries[speciesID] = value
when "InternalName"
constants += "#{value}=#{speciesID}\r\n"
else # All other data
speciesData[speciesID][schema[0]] = value
move_array.sort! { |a, b| (a[0] == b[0]) ? a[2] <=> b[2] : a[0] <=>b [0] }
move_array.each { |arr| arr.pop }
contents[key] = move_array
when "TutorMoves", "EggMoves", "Abilities", "HiddenAbility", "Compatibility"
contents[key] = [contents[key]] if !contents[key].is_a?(Array)
contents[key].compact!
when "Evolutions"
evo_array = []
for i in 0...value.length / 3
evo_array.push([value[i * 3], value[i * 3 + 1], value[i * 3 + 2], false])
end
contents[key] = evo_array
end
end
# Construct species hash
species_symbol = contents["InternalName"].to_sym
species_hash = {
:id => species_symbol,
:id_number => species_number,
:name => contents["Name"],
:form_name => contents["FormName"],
:category => contents["Kind"],
:pokedex_entry => contents["Pokedex"],
:type1 => contents["Type1"],
:type2 => contents["Type2"],
:base_stats => contents["BaseStats"],
:evs => contents["EffortPoints"],
:base_exp => contents["BaseEXP"],
:growth_rate => contents["GrowthRate"],
:gender_rate => contents["GenderRate"],
:catch_rate => contents["Rareness"],
:happiness => contents["Happiness"],
:moves => contents["Moves"],
:tutor_moves => contents["TutorMoves"],
:egg_moves => contents["EggMoves"],
:abilities => contents["Abilities"],
:hidden_abilities => contents["HiddenAbility"],
:wild_item_common => contents["WildItemCommon"],
:wild_item_uncommon => contents["WildItemUncommon"],
:wild_item_rare => contents["WildItemRare"],
:egg_groups => contents["Compatibility"],
:hatch_steps => contents["StepsToHatch"],
:incense => contents["Incense"],
:evolutions => contents["Evolutions"],
:height => contents["Height"],
:weight => contents["Weight"],
:color => contents["Color"],
:shape => contents["Shape"],
:habitat => contents["Habitat"],
:generation => contents["Generation"],
:back_sprite_x => contents["BattlerPlayerX"],
:back_sprite_y => contents["BattlerPlayerY"],
:front_sprite_x => contents["BattlerEnemyX"],
:front_sprite_y => contents["BattlerEnemyY"],
:front_sprite_altitude => contents["BattlerAltitude"],
:shadow_x => contents["BattlerShadowX"],
:shadow_size => contents["BattlerShadowSize"]
}
# Add species' data to records
GameData::Species::DATA[species_number] = GameData::Species::DATA[species_symbol] = GameData::Species.new(species_hash)
species_names[species_number] = species_hash[:name]
species_form_names[species_number] = species_hash[:form_name]
species_categories[species_number] = species_hash[:category]
species_pokedex_entries[species_number] = species_hash[:pokedex_entry]
}
}
# All data is compiled now, just need to save it.
raise _INTL("No Pokémon species are defined (PBS/pokemon.txt)") if speciesData.length==0
# Write all constants and some helpful code for PBSpecies.
count = speciesData.compact.length
code = "module PBSpecies\r\n#{constants}"
code += "def PBSpecies.getName(id)\r\n"
code += "id=getID(PBSpecies,id)\r\n"
code += "return pbGetMessage(MessageTypes::Species,id); end\r\n"
code += "def PBSpecies.getCount; return #{count}; end\r\n"
code += "def PBSpecies.maxValue; return #{maxValue}; end\r\n"
code += "end\r\n"
eval(code, TOPLEVEL_BINDING)
pbAddScript(code,"PBSpecies")
# Save main species data.
save_data(speciesData,"Data/species.dat")
# Save movesets data.
save_data(movesets,"Data/species_movesets.dat")
# Save egg moves data.
save_data(eggMoves,"Data/species_eggmoves.dat")
# Save regional dexes data.
save_data(regionalDexes,"Data/regional_dexes.dat")
# Save metrics data.
for i in 0...7
defaultValue = (i==SpeciesData::METRIC_SHADOW_SIZE) ? 2 : 0 # Shadow size 2, other metrics 0
for j in 0..maxValue
spriteMetrics[i] = [] if !spriteMetrics[i]
spriteMetrics[i][j] ||= defaultValue
end
end
save_data(spriteMetrics,"Data/species_metrics.dat")
# Evaluate evolution data (has to be done after all species are read).
for e in 0...evolutions.length
next if !evolutions[e]
evolutions[e].each_with_index do |evo,i|
FileLineData.setSection(i,"Evolutions","")
evo[0] = csvEnumField!(evo[0],PBSpecies,"Evolutions",i) # Species
#p GameData::Species::DATA.keys
# Enumerate all evolution species and parameters (this couldn't be done earlier)
GameData::Species.each do |species|
FileLineData.setSection(species.id_number, "Evolutions", nil) # For error reporting
Graphics.update if species.id_number % 200 == 0
pbSetWindowText(_INTL("Processing {1} evolution line {2}", FileLineData.file, species.id_number)) if species.id_number % 50 == 0
species.evolutions.each do |evo|
evo[0] = csvEnumField!(evo[0], :Species, "Evolutions", species.id_number)
param_type = PBEvolution.getFunction(evo[1], "parameterType")
if param_type
evo[2] = csvEnumField!(evo[2], param_type, "Evolutions", i)
evo[2] = csvEnumField!(evo[2], param_type, "Evolutions", species.id_number)
elsif evo[2] && !evo[2].empty?
evo[2] = csvInt!(evo[2])
else
evo[2] = csvInt!(evo[2]) if evo[2] && evo[2] != ""
evo[2] = nil
end
end
end
# Add prevolution data to all species as the first "evolution method".
for sp in 1..maxValue
preSpecies = -1
evoData = nil
# Check for another species that evolves into sp.
for f in 0...evolutions.length
next if !evolutions[f] || f==sp
evolutions[f].each do |evo|
next if evo[0]!=sp || evo[3] # Evolved species isn't sp or is a prevolution
preSpecies = f # f evolves into sp
evoData = evo
# Add prevolution "evolution" entry for all evolved species
GameData::Species.each do |species|
found_prevolution = false
Graphics.update if species.id_number % 200 == 0
pbSetWindowText(_INTL("Processing {1} prevolution line {2}", FileLineData.file, species.id_number)) if species.id_number % 50 == 0
GameData::Species.each do |other_species|
other_species.evolutions.each do |evo|
next if evo[0] != species.species || evo[3]
species.evolutions.push([other_species.species, evo[1], evo[2], true])
found_prevolution = true
break
end
break if evoData
break if found_prevolution
end
next if !evoData # evoData[1]=method, evoData[2]=level - both are unused
# Found a species that evolves into e, record it as a prevolution.
evolutions[sp] = [] if !evolutions[sp]
evolutions[sp] = [[preSpecies,evoData[1],evoData[2],true]].concat(evolutions[sp])
end
# Save evolutions data.
save_data(evolutions,"Data/species_evolutions.dat")
# Save all messages.
speciesNames.map! { |name| name || "????????" }
MessageTypes.setMessages(MessageTypes::Species,speciesNames)
MessageTypes.setMessages(MessageTypes::FormNames,formNames)
MessageTypes.setMessages(MessageTypes::Kinds,pokedexKinds)
MessageTypes.setMessages(MessageTypes::Entries,pokedexEntries)
# Save all data
GameData::Species.save
MessageTypes.setMessages(MessageTypes::Species, species_names)
MessageTypes.setMessages(MessageTypes::FormNames, species_form_names)
MessageTypes.setMessages(MessageTypes::Kinds, species_categories)
MessageTypes.setMessages(MessageTypes::Entries, species_pokedex_entries)
Graphics.update
end
#=============================================================================
# Compile Pokémon forms
#=============================================================================
def compile_pokemon_forms
# Get schemas.
requiredValues = SpeciesData.requiredValues(true)
optionalValues = SpeciesData.optionalValues(true)
# Prepare arrays for compiled data.
speciesData = pbLoadSpeciesData
movesets = []
eggMoves = []
spriteMetrics = []
evolutions = []
formNames = []
pokedexKinds = []
pokedexEntries = []
formToSpecies = [] # Saved
speciesToForm = [] # Only used in this method
for i in 1..PBSpecies.maxValue
formToSpecies[i] = [i]
speciesToForm[i] = i
species_names = []
species_form_names = []
species_categories = []
species_pokedex_entries = []
used_forms = {}
# Get maximum species ID number
form_number = 0
GameData::Species.each do |species|
form_number = species.id_number if form_number < species.id_number
end
# Prepare variables used to record scripted constants.
constants = ""
maxValue = PBSpecies.maxValue # Highest species ID
# Read from PBS file.
File.open("PBS/pokemonforms.txt","rb") { |f|
# Read from PBS file
File.open("PBS/pokemonforms.txt", "rb") { |f|
FileLineData.file = "PBS/pokemonforms.txt" # For error reporting
# Read a whole section's lines at once, then run through this code.
# contents is a hash containing all the XXX=YYY lines in that section, where
# the keys are the XXX and the values are the YYY (as unprocessed strings).
pbEachFileSection2(f) { |contents,sectionName|
# Split sectionName into a species number and form number.
splitSectionName = sectionName.split(/[-,\s]/)
if splitSectionName.length!=2
raise _INTL("Section name {1} is invalid (PBS/pokemonforms.txt). Expected syntax like [XXX,Y] (XXX=internal name, Y=form number).",sectionName)
schema = GameData::Species.schema(true)
pbEachFileSection2(f) { |contents, section_name|
FileLineData.setSection(section_name, "header", nil) # For error reporting
# Split section_name into a species number and form number
split_section_name = section_name.split(/[-,\s]/)
if split_section_name.length != 2
raise _INTL("Section name {1} is invalid (PBS/pokemonforms.txt). Expected syntax like [XXX,Y] (XXX=internal name, Y=form number).", sectionName)
end
baseSpeciesID = parseSpecies(splitSectionName[0])
form = csvInt!(splitSectionName[1])
# Ensure this is a valid form and not a duplicate.
if form==0
raise _INTL("Form {1} is invalid (PBS/pokemonforms.txt). Form 0 data should be defined in \"PBS/pokemon.txt\".",sectionName)
species_symbol = csvEnumField!(split_section_name[0], :Species, nil, nil)
form = csvPosInt!(split_section_name[1])
# Raise an error if a species is undefined, the form number is invalid or
# a species/form combo is used twice
if !GameData::Species.exists?(species_symbol)
raise _INTL("Species ID '{1}' is not defined in pokemon.txt.\r\n{2}", species_symbol, FileLineData.linereport)
elsif form == 0
raise _INTL("A form cannot be defined with a form number of 0.\r\n{1}", FileLineData.linereport)
elsif used_forms[species_symbol] && used_forms[species_symbol].include?(form)
raise _INTL("Form {1} for species ID {2} is defined twice.\r\n{3}", form, species_symbol, FileLineData.linereport)
end
if formToSpecies[baseSpeciesID] && formToSpecies[baseSpeciesID][form]
raise _INTL("Form {1} is defined at least twice (PBS/pokemonforms.txt). It should only be defined once.",sectionName)
end
# Record new species number in formToSpecies.
speciesID = baseSpeciesID
if form>0
maxValue += 1
speciesID = maxValue
formToSpecies[baseSpeciesID] = [] if !formToSpecies[baseSpeciesID]
formToSpecies[baseSpeciesID][form] = speciesID
speciesToForm[speciesID] = baseSpeciesID
end
# Generate internal name for this form.
cName = getConstantName(PBSpecies,baseSpeciesID).to_s+"_"+form.to_s
constants += "#{cName}=#{speciesID}\r\n"
# Create array to store compiled data in.
speciesData[speciesID] = []
# Clone data from base form as a starting point.
speciesData[baseSpeciesID].each_with_index do |val,i|
speciesData[speciesID][i] = (val.is_a?(Array)) ? val.clone : val
end
# Copy Type1 into Type2 if if Type1 is defined but Type2 isn't. (Shouldn't
# inherit either of the base form's types if Type1 is defined for a form.)
if contents["Type1"] && contents["Type1"]!=""
if !contents["Type2"] || contents["Type2"]==""
contents["Type2"] = contents["Type1"].clone
used_forms[species_symbol] = [] if !used_forms[species_symbol]
used_forms[species_symbol].push(form)
form_number += 1
base_data = GameData::Species.get(species_symbol)
# Go through schema hash of compilable data and compile this section
for key in schema.keys
# Skip empty properties (none are required)
if contents[key].nil? || contents[key] == ""
contents[key] = nil
next
end
FileLineData.setSection(section_name, key, contents[key]) # For error reporting
# Compile value for key
value = pbGetCsvRecord(contents[key], key, schema[key])
value = nil if value.is_a?(Array) && value.length == 0
contents[key] = value
# Sanitise data
case key
when "Height", "Weight"
# Convert height/weight to 1 decimal place and multiply by 10
value = (value * 10).round
if value <= 0
raise _INTL("Value for '{1}' can't be less than or close to 0 (section {2}, PBS/pokemonforms.txt)", key, section_name)
end
contents[key] = value
when "Moves"
move_array = []
for i in 0...value.length / 2
move_array.push([value[i * 2], value[i * 2 + 1], i])
end
move_array.sort! { |a, b| (a[0] == b[0]) ? a[2] <=> b[2] : a[0] <=>b [0] }
move_array.each { |arr| arr.pop }
contents[key] = move_array
when "TutorMoves", "EggMoves", "Abilities", "HiddenAbility", "Compatibility"
contents[key] = [contents[key]] if !contents[key].is_a?(Array)
contents[key].compact!
when "Evolutions"
evo_array = []
for i in 0...value.length / 3
param_type = PBEvolution.getFunction(value[i * 3 + 1], "parameterType")
param = value[i * 3 + 2]
if param_type
param = csvEnumField!(param, param_type, "Evolutions", section_name)
elsif param && !param.empty?
param = csvInt!(param)
else
param = nil
end
evo_array.push([value[i * 3], value[i * 3 + 1], param, false])
end
contents[key] = evo_array
end
end
# If any held item is defined for this form, clear default data for all
# three held items.
if (contents["WildItemCommon"] && contents["WildItemCommon"]!="") ||
(contents["WildItemUncommon"] && contents["WildItemUncommon"]!="") ||
(contents["WildItemRare"] && contents["WildItemRare"]!="")
speciesData[speciesID][SpeciesData::WILD_ITEM_COMMON] = nil
speciesData[speciesID][SpeciesData::WILD_ITEM_UNCOMMON] = nil
speciesData[speciesID][SpeciesData::WILD_ITEM_RARE] = nil
# Construct species hash
form_symbol = sprintf("%s_%d", species_symbol.to_s, form).to_sym
moves = contents["Moves"]
if !moves
moves = []
base_data.moves.each { |m| moves.push(m.clone) }
end
# Go through hashes of compilable data and compile this section.
[requiredValues,optionalValues].each do |hash|
for key in hash.keys
FileLineData.setSection(speciesID,key,contents[key]) # For error reporting
next if hash[key][0]<0 # Property is not to be compiled; skip it
# Skip empty properties (none are required).
next if !contents[key] || contents[key]==""
# Compile value for key.
schema = hash[key]
value = pbGetCsvRecord(contents[key],key,schema)
# Modify value as required.
case key
when "Height", "Weight"
# Convert height/weight to 1 decimal place and multiply by 10.
value = (value*10).round
if value<=0
raise _INTL("Value for '{1}' can't be less than or close to 0 (section {2}, PBS/pokemonforms.txt)",key,speciesID)
end
end
# Add value to appropriate array for saving.
case key
when "Moves"
speciesMoves = []
for i in 0...value.length/2
speciesMoves.push([value[i*2],value[i*2+1],i])
end
speciesMoves.sort! { |a,b| (a[0]==b[0]) ? a[2]<=>b[2] : a[0]<=>b[0] }
for i in speciesMoves; i.pop; end
movesets[speciesID] = speciesMoves
when "EggMoves"
if value.is_a?(Array); eggMoves[speciesID] = value
else; eggMoves[speciesID] = [value]
end
when "BattlerPlayerX", "BattlerPlayerY",
"BattlerEnemyX", "BattlerEnemyY",
"BattlerAltitude", "BattlerShadowX", "BattlerShadowSize"
spriteMetrics[schema[0]] = [] if !spriteMetrics[schema[0]]
spriteMetrics[schema[0]][speciesID] = value
when "Evolutions"
speciesEvolutions = []
for i in 0...value.length/3
speciesEvolutions.push([value[i*3],value[i*3+1],value[i*3+2],false])
end
evolutions[speciesID] = speciesEvolutions
when "FormName"
formNames[speciesID] = value
when "Kind"
pokedexKinds[speciesID] = value
when "Pokedex"
pokedexEntries[speciesID] = value
else # All other data
speciesData[speciesID][schema[0]] = value
end
end
evolutions = contents["Evolutions"]
if !evolutions
evolutions = []
base_data.evolutions.each { |e| evolutions.push(e.clone) }
end
species_hash = {
:id => form_symbol,
:id_number => form_number,
:species => species_symbol,
:form => form,
:name => base_data.real_name,
:form_name => contents["FormName"],
:category => contents["Kind"] || base_data.real_category,
:pokedex_entry => contents["Pokedex"] || base_data.real_pokedex_entry,
:pokedex_form => contents["PokedexForm"],
:type1 => contents["Type1"] || base_data.type1,
:type2 => contents["Type2"] || base_data.type2,
:base_stats => contents["BaseStats"] || base_data.base_stats,
:evs => contents["EffortPoints"] || base_data.evs,
:base_exp => contents["BaseEXP"] || base_data.base_exp,
:catch_rate => contents["Rareness"] || base_data.catch_rate,
:happiness => contents["Happiness"] || base_data.happiness,
:moves => moves,
:tutor_moves => contents["TutorMoves"] || base_data.tutor_moves.clone,
:egg_moves => contents["EggMoves"] || base_data.egg_moves.clone,
:abilities => contents["Abilities"] || base_data.abilities.clone,
:hidden_abilities => contents["HiddenAbility"] || base_data.hidden_abilities.clone,
:wild_item_common => contents["WildItemCommon"] || base_data.wild_item_common,
:wild_item_uncommon => contents["WildItemUncommon"] || base_data.wild_item_uncommon,
:wild_item_rare => contents["WildItemRare"] || base_data.wild_item_rare,
:egg_groups => contents["Compatibility"] || base_data.egg_groups.clone,
:hatch_steps => contents["StepsToHatch"] || base_data.hatch_steps,
:evolutions => evolutions,
:height => contents["Height"] || base_data.height,
:weight => contents["Weight"] || base_data.weight,
:color => contents["Color"] || base_data.color,
:shape => contents["Shape"] || base_data.shape,
:habitat => contents["Habitat"] || base_data.habitat,
:generation => contents["Generation"] || base_data.generation,
:mega_stone => contents["MegaStone"],
:mega_move => contents["MegaMove"],
:unmega_form => contents["UnmegaForm"],
:mega_message => contents["MegaMessage"],
:back_sprite_x => contents["BattlerPlayerX"] || base_data.back_sprite_x,
:back_sprite_y => contents["BattlerPlayerY"] || base_data.back_sprite_y,
:front_sprite_x => contents["BattlerEnemyX"] || base_data.front_sprite_x,
:front_sprite_y => contents["BattlerEnemyY"] || base_data.front_sprite_y,
:front_sprite_altitude => contents["BattlerAltitude"] || base_data.front_sprite_altitude,
:shadow_x => contents["BattlerShadowX"] || base_data.shadow_x,
:shadow_size => contents["BattlerShadowSize"] || base_data.shadow_size
}
# If form is single-typed, ensure it remains so if base species is dual-typed
species_hash[:type2] = contents["Type1"] if contents["Type1"] && !contents["Type2"]
# If form has any wild items, ensure none are inherited from base species
if contents["WildItemCommon"] || contents["WildItemUncommon"] || contents["WildItemRare"]
species_hash[:wild_item_common] = contents["WildItemCommon"]
species_hash[:wild_item_uncommon] = contents["WildItemUncommon"]
species_hash[:wild_item_rare] = contents["WildItemRare"]
end
# Add form's data to records
GameData::Species::DATA[form_number] = GameData::Species::DATA[form_symbol] = GameData::Species.new(species_hash)
species_names[form_number] = species_hash[:name]
species_form_names[form_number] = species_hash[:form_name]
species_categories[form_number] = species_hash[:category]
species_pokedex_entries[form_number] = species_hash[:pokedex_entry]
}
}
# All data is compiled now, just need to save it.
# Write all constants and some helpful code for PBSpecies.
code = "module PBSpecies\r\n#{constants}"
code += "def PBSpecies.maxValueF; return #{maxValue}; end\r\n"
code += "end\r\n"
eval(code, TOPLEVEL_BINDING)
pbAddScript(code,"PBSpecies")
# Save main species data.
save_data(speciesData,"Data/species.dat")
# Save conversions of form to species data.
save_data(formToSpecies,"Data/form2species.dat")
# Inherit base form moveset.
newMovesets = pbLoadMovesetsData
append_to_base_form_data(PBSpecies.maxValue+1,maxValue,newMovesets,movesets,speciesToForm,true)
save_data(newMovesets,"Data/species_movesets.dat")
$PokemonTemp.speciesMovesets = nil if $PokemonTemp
# Inherit base form egg moves.
newEggMoves = pbLoadEggMovesData
append_to_base_form_data(PBSpecies.maxValue+1,maxValue,newEggMoves,eggMoves,speciesToForm,false)
save_data(newEggMoves,"Data/species_eggmoves.dat")
$PokemonTemp.speciesEggMoves = nil if $PokemonTemp
# Inherit base form metrics data.
newSpriteMetrics = pbLoadSpeciesMetrics
for i in 0...7
defaultValue = (i==SpeciesData::METRIC_SHADOW_SIZE) ? 2 : 0 # Shadow size 2, other metrics 0
append_to_base_form_data(PBSpecies.maxValue+1,maxValue,newSpriteMetrics[i],
spriteMetrics[i] || [],speciesToForm,false,defaultValue)
end
save_data(newSpriteMetrics,"Data/species_metrics.dat")
# Evaluate evolution data (has to be done after all species are read).
for e in 0...evolutions.length
next if !evolutions[e]
evolutions[e].each_with_index do |evo,i|
FileLineData.setSection(i,"Evolutions","")
evo[0] = csvEnumField!(evo[0],PBSpecies,"Evolutions",i) # Species
param_type = PBEvolution.getFunction(evo[1], "parameterType")
if param_type
evo[2] = csvEnumField!(evo[2], param_type, "Evolutions", i)
else
evo[2] = csvPosInt!(evo[2]) if evo[2] && evo[2] != ""
end
end
end
# Inherit base form evolution methods.
newEvolutions = pbLoadEvolutionsData
append_to_base_form_data(PBSpecies.maxValue+1,maxValue,newEvolutions,evolutions,speciesToForm,true)
# Add prevolution data to all species as the first "evolution method".
for i in (PBSpecies.maxValue+1)..maxValue
baseSpecies = speciesToForm[i]
preSpecies = -1
evoData = nil
# Check for another species that evolves into baseSpecies.
for f in 0...newEvolutions.length
next if !newEvolutions[f] || speciesToForm[f]==baseSpecies
newEvolutions[f].each do |evo|
next if evo[0]!=baseSpecies || evo[3] # Evolved species isn't baseSpecies or is a prevolution
preSpecies = speciesToForm[f] # f evolves into baseSpecies
evoData = evo
# Add prevolution "evolution" entry for all evolved forms that define their
# own evolution methods (and thus won't have a prevolution listed already)
GameData::Species.each do |species|
next if species.form == 0 # Looking at alternate forms only
next if species.evolutions.any? { |evo| evo[3] } # Already has prevo listed
found_prevolution = false
Graphics.update if species.id_number % 200 == 0
pbSetWindowText(_INTL("Processing {1} prevolution line {2}", FileLineData.file, species.id_number)) if species.id_number % 50 == 0
GameData::Species.each do |other_species|
other_species.evolutions.each do |evo|
next if evo[0] != species.species || evo[3]
species.evolutions.push([other_species.species, evo[1], evo[2], true])
found_prevolution = true
break
end
break if evoData
end
next if !evoData # evoData[1]=method, evoData[2]=level - both are unused
# Found a species that evolves into e, record it as a prevolution.
if newEvolutions[i]
newEvolutions[i] = [[preSpecies,evoData[1],evoData[2],true]].concat(newEvolutions[i])
else
newEvolutions[i] = [[preSpecies,evoData[1],evoData[2],true]]
end
end
# Save evolutions data.
save_data(newEvolutions,"Data/species_evolutions.dat")
$PokemonTemp.evolutionsData = nil if $PokemonTemp
# Save all messages.
MessageTypes.addMessages(MessageTypes::FormNames,formNames)
MessageTypes.addMessages(MessageTypes::Kinds,pokedexKinds)
MessageTypes.addMessages(MessageTypes::Entries,pokedexEntries)
end
def append_to_base_form_data(idxStart,idxEnd,baseData,extraData,speciesToForm,clone=false,defaultValue=nil)
for i in idxStart..idxEnd
if extraData[i]
baseData[i] = extraData[i]
else
species = speciesToForm[i]
if baseData[species]
if clone
baseData[i] = []
baseData[species].each { |datum| baseData[i].push(datum.clone) }
elsif baseData[species].is_a?(Array)
baseData[i] = baseData[species].clone
else
baseData[i] = baseData[species]
end
else
baseData[i] = defaultValue
end
break if found_prevolution
end
end
# Save all data
GameData::Species.save
MessageTypes.addMessages(MessageTypes::Species, species_names)
MessageTypes.addMessages(MessageTypes::FormNames, species_form_names)
MessageTypes.addMessages(MessageTypes::Kinds, species_categories)
MessageTypes.addMessages(MessageTypes::Entries, species_pokedex_entries)
Graphics.update
end
#=============================================================================
# Compile TM/TM/Move Tutor compatibilities
#=============================================================================
def compile_move_compatibilities
lineno = 1
havesection = false
move_id = nil
sections = {}
if safeExists?("PBS/tm.txt")
f = File.open("PBS/tm.txt","rb")
FileLineData.file = "PBS/tm.txt"
f.each_line { |line|
if lineno==1 && line[0]==0xEF && line[1]==0xBB && line[2]==0xBF
line = line[3,line.length-3]
return if !safeExists?("PBS/tm.txt")
species_hash = {}
move = nil
pbCompilerEachCommentedLine("PBS/tm.txt") { |line, line_no|
Graphics.update if line_no % 50 == 0
if line[/^\s*\[\s*(\S+)\s*\]\s*$/]
move = parseMove($~[1])
pbSetWindowText(_INTL("Processing {1} section [{2}]", FileLineData.file, move))
else
raise _INTL("Expected a section at the beginning of the file.\r\n{1}", FileLineData.linereport) if !move
species_list = line.split(",")
for species in species_list
next if !species || species.empty?
s = parseSpecies(species)
species_hash[s] = [] if !species_hash[s]
species_hash[s].push(move)
end
FileLineData.setLine(line,lineno)
if !line[/^\#/] && !line[/^\s*$/]
if line[/^\s*\[\s*(.*)\s*\]\s*$/]
move_id = parseMove($~[1])
if sections[move_id]
raise _INTL("TM section [{1}] is defined twice.\r\n{2}",move_id.to_s,FileLineData.linereport)
end
sections[move_id] = []
havesection = true
else
if !move_id
raise _INTL("Expected a section at the beginning of the file. This error may also occur if the file was not saved in UTF-8.\r\n{1}",
FileLineData.linereport)
end
specieslist = line.sub(/\s+$/,"").split(",")
for species in specieslist
next if !species || species==""
sec = sections[move_id]
sec[sec.length] = parseSpecies(species)
end
end
end
lineno += 1
Graphics.update if lineno%50==0
pbSetWindowText(_INTL("Processing {1} line {2}",FileLineData.file,lineno)) if lineno%50==0
}
f.close
end
}
GameData::Species.each do |species_data|
next if !species_hash[species_data.id]
species_hash[species_data.id].sort! { |a, b| a.to_s <=> b.to_s }
species_hash[species_data.id].each { |move| species_data.tutor_moves.push(move) }
end
GameData::Species.save
pbSavePokemonData
pbSavePokemonFormsData
begin
File.delete("PBS/tm.txt")
rescue SystemCallError
end
save_data(sections,"Data/tm.dat")
end
#=============================================================================
# Compile Shadow movesets
#=============================================================================
def compile_shadow_movesets
sections = []
sections = {}
if File.exists?("PBS/shadowmoves.txt")
pbCompilerEachCommentedLine("PBS/shadowmoves.txt") { |line,_lineno|
if line[ /^\s*(\w+)\s*=\s*(.*)$/ ]
pbCompilerEachCommentedLine("PBS/shadowmoves.txt") { |line, _line_no|
if line[/^\s*(\w+)\s*=\s*(.*)$/]
key = $1
value = $2
value = value.split(",")
species = parseSpecies(key)
moves = []
for i in 0...[Pokemon::MAX_MOVES,value.length].min
for i in 0...[Pokemon::MAX_MOVES, value.length].min
move = parseMove(value[i], true)
moves.push(move) if move
end
moves.compact!
sections[species] = moves if moves.length>0
sections[species] = moves if moves.length > 0
end
}
end
save_data(sections,"Data/shadow_movesets.dat")
save_data(sections, "Data/shadow_movesets.dat")
end
#=============================================================================
# Compile Regional Dexes
#=============================================================================
def compile_regional_dexes
dex_lists = []
section = nil
pbCompilerEachPreppedLine("PBS/regionaldexes.txt") { |line, line_no|
Graphics.update if line_no % 200 == 0
if line[/^\s*\[\s*(\d+)\s*\]\s*$/]
section = $~[1].to_i
if dex_lists[section]
raise _INTL("Dex list number {1} is defined at least twice.\r\n{2}", section, FileLineData.linereport)
end
dex_lists[section] = []
pbSetWindowText(_INTL("Processing {1} section [{2}]", FileLineData.file, section))
else
raise _INTL("Expected a section at the beginning of the file.\r\n{1}", FileLineData.linereport) if !section
species_list = line.split(",")
for species in species_list
next if !species || species.empty?
s = parseSpecies(species)
dex_lists[section].push(s)
end
end
}
# Check for duplicate species in a Regional Dex
dex_lists.each_with_index do |list, index|
unique_list = list.uniq
next if list == unique_list
list.each_with_index do |s, i|
next if unique_list[i] == s
raise _INTL("Dex list number {1} has species {2} listed twice.\r\n{3}", index, s, FileLineData.linereport)
end
end
# Save all data
save_data(dex_lists, "Data/regional_dexes.dat")
Graphics.update
end
#=============================================================================
@@ -1349,7 +1303,7 @@ module Compiler
pokemonindex += 1
trainers[trainerindex][3][pokemonindex] = []
record = pbGetCsvRecord(line,lineno,
[0,"evEEEEEUEUBEUUSBU",PBSpecies,nil,:Item,:Move,:Move,:Move,:Move,
[0,"evEEEEEUEUBEUUSBU",Species,nil,:Item,:Move,:Move,:Move,:Move,
nil,{"M"=>0,"m"=>0,"Male"=>0,"male"=>0,
"0"=>0,"F"=>1,"f"=>1,"Female"=>1,"female"=>1,
"1"=>1},nil,nil,PBNatures,nil,nil,nil,nil,nil])