Split PokeBattle_Trainer into PlayerTrainer and NPCTrainer

This commit is contained in:
Maruno17
2021-01-24 17:55:39 +00:00
parent 7de034957b
commit 4098b1cd11
60 changed files with 748 additions and 648 deletions

View File

@@ -30,7 +30,7 @@ def pbSetUpSystem
game_system = Marshal.load(f)
pokemonSystem = Marshal.load(f)
}
raise "Corrupted file" if !trainer.is_a?(PokeBattle_Trainer)
raise "Corrupted file" if !trainer.is_a?(PlayerTrainer)
raise "Corrupted file" if !framecount.is_a?(Numeric)
raise "Corrupted file" if !game_system.is_a?(Game_System)
raise "Corrupted file" if !pokemonSystem.is_a?(PokemonSystem)

View File

@@ -73,7 +73,7 @@ def pbPlayTrainerIntroME(trainer_type)
pbMEPlay(bgm)
end
def pbGetTrainerBattleBGM(trainer) # can be a PokeBattle_Trainer or an array of them
def pbGetTrainerBattleBGM(trainer) # can be a PlayerTrainer, NPCTrainer or an array of them
if $PokemonGlobal.nextBattleBGM
return $PokemonGlobal.nextBattleBGM.clone
end
@@ -81,7 +81,7 @@ def pbGetTrainerBattleBGM(trainer) # can be a PokeBattle_Trainer or an array o
music = nil
trainerarray = (trainer.is_a?(Array)) ? trainer : [trainer]
trainerarray.each do |t|
trainer_type_data = GameData::TrainerType.get(t.trainertype)
trainer_type_data = GameData::TrainerType.get(t.trainer_type)
music = trainer_type_data.battle_BGM if trainer_type_data.battle_BGM
end
ret = pbStringToAudioFile(music) if music && music!=""
@@ -123,14 +123,14 @@ def pbGetTrainerBattleBGMFromType(trainertype)
return ret
end
def pbGetTrainerVictoryME(trainer) # can be a PokeBattle_Trainer or an array of them
def pbGetTrainerVictoryME(trainer) # can be a PlayerTrainer, NPCTrainer 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)
trainer_type_data = GameData::TrainerType.get(t.trainer_type)
music = trainer_type_data.victory_ME if trainer_type_data.victory_ME
end
ret = nil

View File

@@ -53,8 +53,8 @@ def pbNicknameAndStore(pkmn)
pbMessage(_INTL("The Pokémon Boxes are full and can't accept any more!"))
return
end
$Trainer.seen[pkmn.species] = true
$Trainer.owned[pkmn.species] = true
$Trainer.set_seen(pkmn.species)
$Trainer.set_owned(pkmn.species)
pbNickname(pkmn)
pbStorePokemon(pkmn)
end
@@ -80,8 +80,8 @@ end
def pbAddPokemonSilent(pkmn, level = 1, see_form = true)
return false if !pkmn || pbBoxesFull?
pkmn = Pokemon.new(pkmn, level) if !pkmn.is_a?(Pokemon)
$Trainer.seen[pkmn.species] = true
$Trainer.owned[pkmn.species] = true
$Trainer.set_seen(pkmn.species)
$Trainer.set_owned(pkmn.species)
pbSeenForm(pkmn) if see_form
pkmn.record_first_moves
if $Trainer.party_full?
@@ -108,8 +108,8 @@ end
def pbAddToPartySilent(pkmn, level = nil, see_form = true)
return false if !pkmn || $Trainer.party_full?
pkmn = Pokemon.new(pkmn, level) if !pkmn.is_a?(Pokemon)
$Trainer.seen[pkmn.species] = true
$Trainer.owned[pkmn.species] = true
$Trainer.set_seen(pkmn.species)
$Trainer.set_owned(pkmn.species)
pbSeenForm(pkmn) if see_form
pkmn.record_first_moves
$Trainer.party[$Trainer.party.length] = pkmn
@@ -131,8 +131,8 @@ def pbAddForeignPokemon(pkmn, level = 1, owner_name = nil, nickname = nil, owner
pbMessage(_INTL("\\me[Pkmn get]{1} received a Pokémon.\1", $Trainer.name))
end
pbStorePokemon(pkmn)
$Trainer.seen[pkmn.species] = true
$Trainer.owned[pkmn.species] = true
$Trainer.set_seen(pkmn.species)
$Trainer.set_owned(pkmn.species)
pbSeenForm(pkmn) if see_form
return true
end
@@ -152,27 +152,12 @@ 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
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 !have_able
$Trainer.party.delete_at(index)
return true
end
#===============================================================================
# Recording Pokémon forms as seen
#===============================================================================
def pbSeenForm(species, gender = 0, form = 0)
$Trainer.formseen = {} if !$Trainer.formseen
$Trainer.formlastseen = {} if !$Trainer.formlastseen
$Trainer.seen_forms = {} if !$Trainer.seen_forms
$Trainer.last_seen_forms = {} if !$Trainer.last_seen_forms
if species.is_a?(Pokemon)
species_data = species.species_data
gender = species.gender
@@ -188,87 +173,34 @@ def pbSeenForm(species, gender = 0, form = 0)
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.seen_forms[species] = [[], []] if !$Trainer.seen_forms[species]
$Trainer.seen_forms[species][gender][form] = true
$Trainer.last_seen_forms[species] = [] if !$Trainer.last_seen_forms[species]
$Trainer.last_seen_forms[species] = [gender, form] if $Trainer.last_seen_forms[species] == []
end
def pbUpdateLastSeenForm(pkmn)
$Trainer.formlastseen = {} if !$Trainer.formlastseen
$Trainer.last_seen_forms = {} if !$Trainer.last_seen_forms
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]
$Trainer.last_seen_forms[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)
def pbFirstAblePokemon(variable_ID)
$Trainer.party.each_with_index do |pkmn, i|
next if pkmn.egg? || pkmn.hp == 0
pbSet(variableNumber, i)
next if !pkmn.able?
pbSet(variable_ID, i)
return pkmn
end
pbSet(variableNumber, -1)
pbSet(variable_ID, -1)
return nil
end
# Checks whether the player would still have an unfainted Pokémon if the
# 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
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)
$Trainer.pokemonParty.each do |pkmn|
return true if pkmn.isSpecies?(species) && (form < 0 || pkmn.form == form)
end
return false
end
# Returns true if there is a fatefully met Pokémon of the given species in the
# player's party.
def pbHasFatefulSpecies?(species)
$Trainer.pokemonParty.each do |pkmn|
return true if pkmn.isSpecies?(species) && pkmn.obtain_method == 4
end
return false
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
$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 { |pkmn| return pkmn if pkmn.hasMove?(move) }
return nil
end
#===============================================================================
# Fully heal all Pokémon in the party
#===============================================================================
def pbHealAll
$Trainer.party.each { |pkmn| pkmn.heal }
end
#===============================================================================
# Return a level value based on Pokémon in a party
#===============================================================================

View File

@@ -223,48 +223,43 @@ end
#===============================================================================
# Player-related utilities, random name generator
#===============================================================================
def pbChangePlayer(id)
return false if id<0 || id>=8
meta = GameData::Metadata.get_player(id)
return false if !meta
$Trainer.trainertype = meta[0] if $Trainer
$game_player.character_name = meta[1]
$game_player.character_hue = 0
$PokemonGlobal.playerID = id
$Trainer.metaID = id if $Trainer
end
def pbGetPlayerGraphic
id = $PokemonGlobal.playerID
return "" if id<0 || id>=8
return "" if id < 0 || id >= 8
meta = GameData::Metadata.get_player(id)
return "" if !meta
return GameData::TrainerType.player_front_sprite_filename(meta[0])
end
def pbGetPlayerTrainerType
meta = GameData::Metadata.get_player($PokemonGlobal.playerID)
return (meta) ? meta[0] : nil
end
def pbGetTrainerTypeGender(trainer_type)
return GameData::TrainerType.get(trainer_type).gender
end
def pbTrainerName(name=nil,outfit=0)
pbChangePlayer(0) if $PokemonGlobal.playerID<0
trainertype = pbGetPlayerTrainerType
trname = name
$Trainer = PokeBattle_Trainer.new(trname,trainertype)
$Trainer.outfit = outfit
if trname==nil
trname = pbEnterPlayerName(_INTL("Your name?"),0,MAX_PLAYER_NAME_SIZE)
if trname==""
gender = pbGetTrainerTypeGender(trainertype)
trname = pbSuggestTrainerName(gender)
def pbChangePlayer(id)
return false if id < 0 || id >= 8
meta = GameData::Metadata.get_player(id)
return false if !meta
$Trainer.trainer_type = meta[0] if $Trainer
$game_player.character_name = meta[1]
$PokemonGlobal.playerID = id
$Trainer.character_ID = id if $Trainer
end
def pbTrainerName(name = nil, outfit = 0)
pbChangePlayer(0) if $PokemonGlobal.playerID < 0
player_metadata = GameData::Metadata.get_player($PokemonGlobal.playerID)
trainer_type = (player_metadata) ? player_metadata[0] : nil
$Trainer = PlayerTrainer.new(name, trainer_type)
$Trainer.outfit = outfit
$Trainer.character_ID = $PokemonGlobal.playerID
if name.nil?
name = pbEnterPlayerName(_INTL("Your name?"), 0, MAX_PLAYER_NAME_SIZE)
if name.nil? || name.empty?
gender = pbGetTrainerTypeGender(trainer_type)
name = pbSuggestTrainerName(gender)
end
end
$Trainer.name = trname
$Trainer.name = name
$PokemonBag = PokemonBag.new
$PokemonTemp.begunNewGame = true
end
@@ -444,18 +439,18 @@ def pbSetViableDexes
if USE_CURRENT_REGION_DEX
region = pbGetCurrentRegion
region = -1 if region>=$PokemonGlobal.pokedexUnlocked.length-1
$PokemonGlobal.pokedexViable[0] = region if $Trainer.pokedexSeen(region)>0
$PokemonGlobal.pokedexViable[0] = region if $Trainer.seen_any?(region)
else
numDexes = $PokemonGlobal.pokedexUnlocked.length
if numDexes==1 # National Dex only
if numDexes==1 # National Dex only
if $PokemonGlobal.pokedexUnlocked[0]
$PokemonGlobal.pokedexViable.push(0) if $Trainer.pokedexSeen>0
$PokemonGlobal.pokedexViable.push(0) if $Trainer.seen_any?
end
else # Regional dexes + National Dex
else # Regional dexes + National Dex
for i in 0...numDexes
regionToCheck = (i==numDexes-1) ? -1 : i
if $PokemonGlobal.pokedexUnlocked[i]
$PokemonGlobal.pokedexViable.push(i) if $Trainer.pokedexSeen(regionToCheck)>0
$PokemonGlobal.pokedexViable.push(i) if $Trainer.seen_any?(regionToCheck)
end
end
end