Moved methods that return item/trainer graphics, refactored evolution helper methods, rearranged some methods

This commit is contained in:
Maruno17
2020-12-13 19:40:17 +00:00
parent d4b5aa0ce7
commit 1ffeddc41c
35 changed files with 582 additions and 548 deletions

View File

@@ -257,163 +257,6 @@ end
#===============================================================================
# Load item icons
# TODO: Put these methods into GameData::Item.
#===============================================================================
def pbItemIconFile(item)
bitmapFileName = nil
if item
itm = GameData::Item.get(item)
bitmapFileName = sprintf("Graphics/Icons/item%s",itm.id.to_s) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Icons/item%03d",itm.id_number)
if !pbResolveBitmap(bitmapFileName) && itm.is_machine?
move = itm.move
type = GameData::Move.get(move).type
bitmapFileName = sprintf("Graphics/Icons/itemMachine%s",type.to_s) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Icons/itemMachine%03d",type)
end
end
bitmapFileName = "Graphics/Icons/item000" if !pbResolveBitmap(bitmapFileName)
end
else
bitmapFileName = sprintf("Graphics/Icons/itemBack")
end
return bitmapFileName
end
def pbHeldItemIconFile(item) # Used in the party screen
return nil if !item || item==0
namebase = (GameData::Item.get(item).is_mail?) ? "mail" : "item"
bitmapFileName = sprintf("Graphics/Pictures/Party/icon_%s_%s",namebase,GameData::Item.get(item).id.to_s) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Pictures/Party/icon_%s_%03d",namebase,item)
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Pictures/Party/icon_%s",namebase)
end
end
return bitmapFileName
end
#===============================================================================
# Load mail background graphics
#===============================================================================
def pbMailBackFile(item)
return nil if !item
bitmapFileName = sprintf("Graphics/Pictures/Mail/mail_%s",GameData::Item.get(item).id.to_s) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Pictures/Mail/mail_%03d",item)
end
return bitmapFileName
end
#===============================================================================
# Load NPC charsets
#===============================================================================
def pbTrainerCharFile(type) # Used by the phone
return nil if !type
tr_type_data = GameData::TrainerType.get(type)
bitmapFileName = sprintf("Graphics/Characters/trchar%s", tr_type_data.id.to_s) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Characters/trchar%03d", tr_type_data.id_number)
end
return bitmapFileName
end
def pbTrainerCharNameFile(type) # Used by Battle Frontier and compiler
return nil if !type
tr_type_data = GameData::TrainerType.get(type)
bitmapFileName = sprintf("trchar%s", tr_type_data.id.to_s) rescue nil
if !pbResolveBitmap(sprintf("Graphics/Characters/" + bitmapFileName))
bitmapFileName = sprintf("trchar%03d", tr_type_data.id_number)
end
return bitmapFileName
end
#===============================================================================
# Load trainer sprites
#===============================================================================
def pbTrainerSpriteFile(type)
return nil if !type
tr_type_data = GameData::TrainerType.get(type)
bitmapFileName = sprintf("Graphics/Trainers/trainer%s", tr_type_data.id.to_s) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Trainers/trainer%03d", tr_type_data.id_number)
end
return bitmapFileName
end
def pbTrainerSpriteBackFile(type)
return nil if !type
tr_type_data = GameData::TrainerType.get(type)
bitmapFileName = sprintf("Graphics/Trainers/trback%s", tr_type_data.id.to_s) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Trainers/trback%03d", tr_type_data.id_number)
end
return bitmapFileName
end
def pbPlayerSpriteFile(type)
return nil if !type
tr_type_data = GameData::TrainerType.get(type)
outfit = ($Trainer) ? $Trainer.outfit : 0
bitmapFileName = sprintf("Graphics/Trainers/trainer%s_%d", tr_type_data.id.to_s, outfit) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Trainers/trainer%03d_%d", tr_type_data.id_number, outfit)
bitmapFileName = pbTrainerSpriteFile(tr_type_data.id) if !pbResolveBitmap(bitmapFileName)
end
return bitmapFileName
end
def pbPlayerSpriteBackFile(type)
return nil if !type
tr_type_data = GameData::TrainerType.get(type)
outfit = ($Trainer) ? $Trainer.outfit : 0
bitmapFileName = sprintf("Graphics/Trainers/trback%s_%d", tr_type_data.id.to_s, outfit) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Trainers/trback%03d_%d", tr_type_data.id_number, outfit)
bitmapFileName = pbTrainerSpriteBackFile(tr_type_data.id) if !pbResolveBitmap(bitmapFileName)
end
return bitmapFileName
end
#===============================================================================
# Load player's head icons (used in the Town Map)
#===============================================================================
def pbTrainerHeadFile(type)
return nil if !type
tr_type_data = GameData::TrainerType.get(type)
bitmapFileName = sprintf("Graphics/Pictures/mapPlayer%s", tr_type_data.id.to_s) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Pictures/mapPlayer%03d", tr_type_data.id_number)
end
return bitmapFileName
end
def pbPlayerHeadFile(type)
return nil if !type
tr_type_data = GameData::TrainerType.get(type)
outfit = ($Trainer) ? $Trainer.outfit : 0
bitmapFileName = sprintf("Graphics/Pictures/mapPlayer%s_%d", tr_type_data.id.to_s, outfit) rescue nil
if !pbResolveBitmap(bitmapFileName)
bitmapFileName = sprintf("Graphics/Pictures/mapPlayer%03d_%d", tr_type_data.id_number, outfit)
bitmapFileName = pbTrainerHeadFile(tr_type_data.id) if !pbResolveBitmap(bitmapFileName)
end
return bitmapFileName
end
#===============================================================================
# Analyse audio files
#===============================================================================

View File

@@ -237,73 +237,6 @@ end
#===============================================================================
# Choose a Pokémon in the party
#===============================================================================
# Choose a Pokémon/egg from the party.
# Stores result in variable _variableNumber_ and the chosen Pokémon's name in
# variable _nameVarNumber_; result is -1 if no Pokémon was chosen
def pbChoosePokemon(variableNumber,nameVarNumber,ableProc=nil,allowIneligible=false)
chosen = 0
pbFadeOutIn {
scene = PokemonParty_Scene.new
screen = PokemonPartyScreen.new(scene,$Trainer.party)
if ableProc
chosen=screen.pbChooseAblePokemon(ableProc,allowIneligible)
else
screen.pbStartScene(_INTL("Choose a Pokémon."),false)
chosen = screen.pbChoosePokemon
screen.pbEndScene
end
}
pbSet(variableNumber,chosen)
if chosen>=0
pbSet(nameVarNumber,$Trainer.party[chosen].name)
else
pbSet(nameVarNumber,"")
end
end
def pbChooseNonEggPokemon(variableNumber,nameVarNumber)
pbChoosePokemon(variableNumber,nameVarNumber,proc { |pkmn| !pkmn.egg? })
end
def pbChooseAblePokemon(variableNumber,nameVarNumber)
pbChoosePokemon(variableNumber,nameVarNumber,proc { |pkmn| !pkmn.egg? && pkmn.hp>0 })
end
# Same as pbChoosePokemon, but prevents choosing an egg or a Shadow Pokémon.
def pbChooseTradablePokemon(variableNumber,nameVarNumber,ableProc=nil,allowIneligible=false)
chosen = 0
pbFadeOutIn {
scene = PokemonParty_Scene.new
screen = PokemonPartyScreen.new(scene,$Trainer.party)
if ableProc
chosen=screen.pbChooseTradablePokemon(ableProc,allowIneligible)
else
screen.pbStartScene(_INTL("Choose a Pokémon."),false)
chosen = screen.pbChoosePokemon
screen.pbEndScene
end
}
pbSet(variableNumber,chosen)
if chosen>=0
pbSet(nameVarNumber,$Trainer.party[chosen].name)
else
pbSet(nameVarNumber,"")
end
end
def pbChoosePokemonForTrade(variableNumber,nameVarNumber,wanted)
wanted = getID(PBSpecies,wanted)
pbChooseTradablePokemon(variableNumber,nameVarNumber,proc { |pkmn|
next pkmn.species==wanted
})
end
#===============================================================================
# Analyse Pokémon in the party
#===============================================================================
@@ -483,15 +416,15 @@ def pbHasEgg?(species)
species = getID(PBSpecies,species)
return false if !species
# species may be unbreedable, so check its evolution's compatibilities
evoSpecies = pbGetEvolvedFormData(species,true)
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))
baby = pbGetBabySpecies(species)
baby = EvolutionHelper.baby_species(species)
return true if species==baby # Is a basic species
baby = pbGetBabySpecies(species,true)
baby = EvolutionHelper.baby_species(species, true)
return true if species==baby # Is an egg species without incense
return false
end

View File

@@ -681,7 +681,7 @@ def pbGetPlayerGraphic
return "" if id<0 || id>=8
meta = GameData::Metadata.get_player(id)
return "" if !meta
return pbPlayerSpriteFile(meta[0])
return GameData::TrainerType.player_front_sprite_filename(meta[0])
end
def pbGetPlayerTrainerType
@@ -1039,23 +1039,6 @@ def pbMoveTutorChoose(move,movelist=nil,bymachine=false)
return ret # Returns whether the move was learned by a Pokemon
end
def pbChooseMove(pokemon,variableNumber,nameVarNumber)
return if !pokemon
ret = -1
pbFadeOutIn {
scene = PokemonSummary_Scene.new
screen = PokemonSummaryScreen.new(scene)
ret = screen.pbStartForgetScreen([pokemon],0,nil)
}
$game_variables[variableNumber] = ret
if ret>=0
$game_variables[nameVarNumber] = pokemon.moves[ret].name
else
$game_variables[nameVarNumber] = ""
end
$game_map.need_refresh = true if $game_map
end
def pbConvertItemToItem(variable, array)
item = GameData::Item.get(pbGet(variable))
pbSet(variable, nil)