def pbTrainerBattleCore(*args)
outcomeVar = $PokemonTemp.battleRules["outcomeVar"] || 1
canLose = $PokemonTemp.battleRules["canLose"] || false
# Skip battle if the player has no able Pokémon, or if holding Ctrl in Debug mode
if $Trainer.ablePokemonCount==0 || ($DEBUG && Input.press?(Input::CTRL))
pbMessage(_INTL("SKIPPING BATTLE...")) if $DEBUG
pbMessage(_INTL("AFTER WINNING...")) if $DEBUG && $Trainer.ablePokemonCount>0
pbSet(outcomeVar,($Trainer.ablePokemonCount==0) ? 0 : 1) # Treat it as undecided/a win
$PokemonTemp.clearBattleRules
$PokemonGlobal.nextBattleBGM = nil
$PokemonGlobal.nextBattleME = nil
$PokemonGlobal.nextBattleCaptureME = nil
$PokemonGlobal.nextBattleBack = nil
return ($Trainer.ablePokemonCount==0) ? 0 : 1 # Treat it as undecided/a win
end
# Record information about party Pokémon to be used at the end of battle (e.g.
# comparing levels for an evolution check)
Events.onStartBattle.trigger(nil)
# Generate trainers and their parties based on the arguments given
foeTrainers = []
foeItems = []
foeEndSpeeches = []
foeParty = []
foePartyStarts = []
for arg in args
raise _INTL("Expected an array of trainer data, got {1}.",arg) if !arg.is_a?(Array)
if arg[0].is_a?(PokeBattle_Trainer)
# [trainer object, party, end speech, items]
foeTrainers.push(arg[0])
foePartyStarts.push(foeParty.length)
arg[1].each { |pkmn| foeParty.push(pkmn) }
foeEndSpeeches.push(arg[2])
foeItems.push(arg[3])
else
# [trainer type, trainer name, ID, speech (optional)]
trainer = pbLoadTrainer(arg[0],arg[1],arg[2])
pbMissingTrainer(arg[0],arg[1],arg[2]) if !trainer
return 0 if !trainer
Events.onTrainerPartyLoad.trigger(nil,trainer)
foeTrainers.push(trainer[0])
foePartyStarts.push(foeParty.length)
trainer[2].each { |pkmn| foeParty.push(pkmn) }
foeEndSpeeches.push(arg[3] || trainer[3])
foeItems.push(trainer[1])
end
end
# Calculate who the player trainer(s) and their party are
playerTrainers = [$Trainer]
playerParty = $Trainer.party
playerPartyStarts = [0]
if $PokemonGlobal.partner && !$PokemonTemp.battleRules["noPartner"] && foeParty.length>=1
ally = PokeBattle_Trainer.new($PokemonGlobal.partner[1],$PokemonGlobal.partner[0])
ally.id = $PokemonGlobal.partner[2]
ally.party = $PokemonGlobal.partner[3]
playerTrainers.push(ally)
playerParty = []
$Trainer.party.each { |pkmn| playerParty.push(pkmn) }
playerPartyStarts.push(playerParty.length)
ally.party.each { |pkmn| playerParty.push(pkmn) }
end
if $PokemonGlobal.partner2 && !$PokemonTemp.battleRules["noPartner"] && room_for_partner # &&
# $PokemonTemp.battleRules["battleRoyale"]
ally2 = PokeBattle_Trainer.new($PokemonGlobal.partner2[1],$PokemonGlobal.partner2[0])
ally2.id = $PokemonGlobal.partner2[2]
ally2.party = $PokemonGlobal.partner2[3]
playerTrainers.push(ally2)
playerParty = []
$Trainer.party.each { |pkmn| playerParty.push(pkmn) }
# playerPartyStarts.push(playerParty.length)
ally.party.each { |pkmn| playerParty.push(pkmn) }
playerPartyStarts.push(playerParty.length)
ally2.party.each { |pkmn| playerParty.push(pkmn) }
setBattleRule("triple") if !$PokemonTemp.battleRules["size"]
end
# Create the battle scene (the visual side of it)
scene = pbNewBattleScene
# Create the battle class (the mechanics side of it)
battle = PokeBattle_Battle.new(scene,playerParty,foeParty,playerTrainers,foeTrainers)
battle.party1starts = playerPartyStarts
battle.party2starts = foePartyStarts
battle.items = foeItems
battle.endSpeeches = foeEndSpeeches
# Set various other properties in the battle class
pbPrepareBattle(battle)
$PokemonTemp.clearBattleRules
# End the trainer intro music
Audio.me_stop
# Perform the battle itself
decision = 0
pbBattleAnimation(pbGetTrainerBattleBGM(foeTrainers),(battle.singleBattle?) ? 1 : 3,foeTrainers) {
pbSceneStandby {
decision = battle.pbStartBattle
}
pbAfterBattle(decision,canLose)
}
Input.update
# Save the result of the battle in a Game Variable (1 by default)
# 0 - Undecided or aborted
# 1 - Player won
# 2 - Player lost
# 3 - Player or wild Pokémon ran from battle, or player forfeited the match
# 5 - Draw
pbSet(outcomeVar,decision)
return decision
end