mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-06 06:01:46 +00:00
Created and implemented GameData::Species
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user