|
|
|
|
@@ -82,12 +82,119 @@ def setBattleRule(*args)
|
|
|
|
|
raise _INTL("Argument {1} expected a variable after it but didn't have one.", r) if r
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def pbNewBattleScene
|
|
|
|
|
return Battle::Scene.new
|
|
|
|
|
# Used to determine the environment in battle, and also the form of Burmy/
|
|
|
|
|
# Wormadam.
|
|
|
|
|
def pbGetEnvironment
|
|
|
|
|
ret = :None
|
|
|
|
|
map_env = $game_map.metadata&.battle_environment
|
|
|
|
|
ret = map_env if map_env
|
|
|
|
|
if $game_temp.encounter_type &&
|
|
|
|
|
GameData::EncounterType.get($game_temp.encounter_type).type == :fishing
|
|
|
|
|
terrainTag = $game_player.pbFacingTerrainTag
|
|
|
|
|
else
|
|
|
|
|
terrainTag = $game_player.terrain_tag
|
|
|
|
|
end
|
|
|
|
|
tile_environment = terrainTag.battle_environment
|
|
|
|
|
if ret == :Forest && [:Grass, :TallGrass].include?(tile_environment)
|
|
|
|
|
ret = :ForestGrass
|
|
|
|
|
elsif tile_environment
|
|
|
|
|
ret = tile_environment
|
|
|
|
|
end
|
|
|
|
|
return ret
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Sets up various battle parameters and applies special rules.
|
|
|
|
|
def pbPrepareBattle(battle)
|
|
|
|
|
# Record current levels of Pokémon in party, to see if they gain a level during
|
|
|
|
|
# battle and may need to evolve afterwards
|
|
|
|
|
EventHandlers.add(:on_start_battle, :record_party_status,
|
|
|
|
|
proc {
|
|
|
|
|
$game_temp.party_levels_before_battle = []
|
|
|
|
|
$game_temp.party_critical_hits_dealt = []
|
|
|
|
|
$game_temp.party_direct_damage_taken = []
|
|
|
|
|
$player.party.each_with_index do |pkmn, i|
|
|
|
|
|
$game_temp.party_levels_before_battle[i] = pkmn.level
|
|
|
|
|
$game_temp.party_critical_hits_dealt[i] = 0
|
|
|
|
|
$game_temp.party_direct_damage_taken[i] = 0
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def pbCanDoubleBattle?
|
|
|
|
|
return true if $player.able_pokemon_count >= 2
|
|
|
|
|
return $PokemonGlobal.partner && $player.able_pokemon_count >= 1
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def pbCanTripleBattle?
|
|
|
|
|
return true if $player.able_pokemon_count >= 3
|
|
|
|
|
return $PokemonGlobal.partner && $player.able_pokemon_count >= 2
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#===============================================================================
|
|
|
|
|
# Helper methods for setting up and closing down battles
|
|
|
|
|
#===============================================================================
|
|
|
|
|
module BattleCreationHelperMethods
|
|
|
|
|
module_function
|
|
|
|
|
|
|
|
|
|
# Skip battle if the player has no able Pokémon, or if holding Ctrl in Debug mode
|
|
|
|
|
def skip_battle?
|
|
|
|
|
return true if $player.able_pokemon_count == 0
|
|
|
|
|
return true if $DEBUG && Input.press?(Input::CTRL)
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def skip_battle(outcome_variable, trainer_battle = false)
|
|
|
|
|
pbMessage(_INTL("SKIPPING BATTLE...")) if !trainer_battle && $player.pokemon_count > 0
|
|
|
|
|
pbMessage(_INTL("SKIPPING BATTLE...")) if trainer_battle && $DEBUG
|
|
|
|
|
pbMessage(_INTL("AFTER WINNING...")) if trainer_battle && $player.able_pokemon_count > 0
|
|
|
|
|
$game_temp.clear_battle_rules
|
|
|
|
|
$PokemonGlobal.nextBattleBGM = nil
|
|
|
|
|
$PokemonGlobal.nextBattleVictoryBGM = nil
|
|
|
|
|
$PokemonGlobal.nextBattleCaptureME = nil
|
|
|
|
|
$PokemonGlobal.nextBattleBack = nil
|
|
|
|
|
pbMEStop
|
|
|
|
|
outcome = 1 # Win
|
|
|
|
|
outcome = 0 if trainer_battle && $player.able_pokemon_count == 0 # Undecided
|
|
|
|
|
pbSet(outcome_variable, outcome)
|
|
|
|
|
return outcome
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def partner_can_participate?(foe_party)
|
|
|
|
|
return false if !$PokemonGlobal.partner || $game_temp.battle_rules["noPartner"]
|
|
|
|
|
return true if foe_party.length > 1
|
|
|
|
|
if $game_temp.battle_rules["size"]
|
|
|
|
|
return false if $game_temp.battle_rules["size"] == "single" ||
|
|
|
|
|
$game_temp.battle_rules["size"][/^1v/i] # "1v1", "1v2", "1v3", etc.
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Generate information for the player and partner trainer(s)
|
|
|
|
|
def set_up_player_trainers(foe_party)
|
|
|
|
|
trainer_array = [$player]
|
|
|
|
|
ally_items = []
|
|
|
|
|
pokemon_array = $player.party
|
|
|
|
|
party_starts = [0]
|
|
|
|
|
if partner_can_participate?(foe_party)
|
|
|
|
|
ally = NPCTrainer.new($PokemonGlobal.partner[1], $PokemonGlobal.partner[0])
|
|
|
|
|
ally.id = $PokemonGlobal.partner[2]
|
|
|
|
|
ally.party = $PokemonGlobal.partner[3]
|
|
|
|
|
ally_items[1] = ally.items.clone
|
|
|
|
|
trainer_array.push(ally)
|
|
|
|
|
pokemon_array = []
|
|
|
|
|
$player.party.each { |pkmn| pokemon_array.push(pkmn) }
|
|
|
|
|
party_starts.push(pokemon_array.length)
|
|
|
|
|
ally.party.each { |pkmn| pokemon_array.push(pkmn) }
|
|
|
|
|
setBattleRule("double") if $game_temp.battle_rules["size"].nil?
|
|
|
|
|
end
|
|
|
|
|
return trainer_array, ally_items, pokemon_array, party_starts
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def create_battle_scene
|
|
|
|
|
return Battle::Scene.new
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Sets up various battle parameters and applies special rules.
|
|
|
|
|
def prepare_battle(battle)
|
|
|
|
|
battleRules = $game_temp.battle_rules
|
|
|
|
|
# The size of the battle, i.e. how many Pokémon on each side (default: "single")
|
|
|
|
|
battle.setBattleMode(battleRules["size"]) if !battleRules["size"].nil?
|
|
|
|
|
@@ -178,404 +285,9 @@ def pbPrepareBattle(battle)
|
|
|
|
|
battle.time = 0
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Used to determine the environment in battle, and also the form of Burmy/
|
|
|
|
|
# Wormadam.
|
|
|
|
|
def pbGetEnvironment
|
|
|
|
|
ret = :None
|
|
|
|
|
map_env = $game_map.metadata&.battle_environment
|
|
|
|
|
ret = map_env if map_env
|
|
|
|
|
if $game_temp.encounter_type &&
|
|
|
|
|
GameData::EncounterType.get($game_temp.encounter_type).type == :fishing
|
|
|
|
|
terrainTag = $game_player.pbFacingTerrainTag
|
|
|
|
|
else
|
|
|
|
|
terrainTag = $game_player.terrain_tag
|
|
|
|
|
end
|
|
|
|
|
tile_environment = terrainTag.battle_environment
|
|
|
|
|
if ret == :Forest && [:Grass, :TallGrass].include?(tile_environment)
|
|
|
|
|
ret = :ForestGrass
|
|
|
|
|
elsif tile_environment
|
|
|
|
|
ret = tile_environment
|
|
|
|
|
end
|
|
|
|
|
return ret
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Record current levels of Pokémon in party, to see if they gain a level during
|
|
|
|
|
# battle and may need to evolve afterwards
|
|
|
|
|
EventHandlers.add(:on_start_battle, :record_party_status,
|
|
|
|
|
proc {
|
|
|
|
|
$game_temp.party_levels_before_battle = []
|
|
|
|
|
$game_temp.party_critical_hits_dealt = []
|
|
|
|
|
$game_temp.party_direct_damage_taken = []
|
|
|
|
|
$player.party.each_with_index do |pkmn, i|
|
|
|
|
|
$game_temp.party_levels_before_battle[i] = pkmn.level
|
|
|
|
|
$game_temp.party_critical_hits_dealt[i] = 0
|
|
|
|
|
$game_temp.party_direct_damage_taken[i] = 0
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def pbCanDoubleBattle?
|
|
|
|
|
return $PokemonGlobal.partner || $player.able_pokemon_count >= 2
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def pbCanTripleBattle?
|
|
|
|
|
return true if $player.able_pokemon_count >= 3
|
|
|
|
|
return $PokemonGlobal.partner && $player.able_pokemon_count >= 2
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#===============================================================================
|
|
|
|
|
# Start a wild battle
|
|
|
|
|
#===============================================================================
|
|
|
|
|
def pbWildBattleCore(*args)
|
|
|
|
|
outcomeVar = $game_temp.battle_rules["outcomeVar"] || 1
|
|
|
|
|
canLose = $game_temp.battle_rules["canLose"] || false
|
|
|
|
|
# Skip battle if the player has no able Pokémon, or if holding Ctrl in Debug mode
|
|
|
|
|
if $player.able_pokemon_count == 0 || ($DEBUG && Input.press?(Input::CTRL))
|
|
|
|
|
pbMessage(_INTL("SKIPPING BATTLE...")) if $player.pokemon_count > 0
|
|
|
|
|
pbSet(outcomeVar, 1) # Treat it as a win
|
|
|
|
|
$game_temp.clear_battle_rules
|
|
|
|
|
$PokemonGlobal.nextBattleBGM = nil
|
|
|
|
|
$PokemonGlobal.nextBattleVictoryBGM = nil
|
|
|
|
|
$PokemonGlobal.nextBattleCaptureME = nil
|
|
|
|
|
$PokemonGlobal.nextBattleBack = nil
|
|
|
|
|
pbMEStop
|
|
|
|
|
return 1 # Treat it as 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)
|
|
|
|
|
EventHandlers.trigger(:on_start_battle)
|
|
|
|
|
# Generate wild Pokémon based on the species and level
|
|
|
|
|
foeParty = []
|
|
|
|
|
sp = nil
|
|
|
|
|
args.each do |arg|
|
|
|
|
|
if arg.is_a?(Pokemon)
|
|
|
|
|
foeParty.push(arg)
|
|
|
|
|
elsif arg.is_a?(Array)
|
|
|
|
|
species = GameData::Species.get(arg[0]).id
|
|
|
|
|
pkmn = pbGenerateWildPokemon(species, arg[1])
|
|
|
|
|
foeParty.push(pkmn)
|
|
|
|
|
elsif sp
|
|
|
|
|
species = GameData::Species.get(sp).id
|
|
|
|
|
pkmn = pbGenerateWildPokemon(species, arg)
|
|
|
|
|
foeParty.push(pkmn)
|
|
|
|
|
sp = nil
|
|
|
|
|
else
|
|
|
|
|
sp = arg
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
raise _INTL("Expected a level after being given {1}, but one wasn't found.", sp) if sp
|
|
|
|
|
# Calculate who the trainers and their party are
|
|
|
|
|
playerTrainers = [$player]
|
|
|
|
|
playerParty = $player.party
|
|
|
|
|
playerPartyStarts = [0]
|
|
|
|
|
room_for_partner = (foeParty.length > 1)
|
|
|
|
|
if !room_for_partner && $game_temp.battle_rules["size"] &&
|
|
|
|
|
!["single", "1v1", "1v2", "1v3"].include?($game_temp.battle_rules["size"])
|
|
|
|
|
room_for_partner = true
|
|
|
|
|
end
|
|
|
|
|
if $PokemonGlobal.partner && !$game_temp.battle_rules["noPartner"] && room_for_partner
|
|
|
|
|
ally = NPCTrainer.new($PokemonGlobal.partner[1], $PokemonGlobal.partner[0])
|
|
|
|
|
ally.id = $PokemonGlobal.partner[2]
|
|
|
|
|
ally.party = $PokemonGlobal.partner[3]
|
|
|
|
|
playerTrainers.push(ally)
|
|
|
|
|
playerParty = []
|
|
|
|
|
$player.party.each { |pkmn| playerParty.push(pkmn) }
|
|
|
|
|
playerPartyStarts.push(playerParty.length)
|
|
|
|
|
ally.party.each { |pkmn| playerParty.push(pkmn) }
|
|
|
|
|
setBattleRule("double") if !$game_temp.battle_rules["size"]
|
|
|
|
|
end
|
|
|
|
|
# Create the battle scene (the visual side of it)
|
|
|
|
|
scene = pbNewBattleScene
|
|
|
|
|
# Create the battle class (the mechanics side of it)
|
|
|
|
|
battle = Battle.new(scene, playerParty, foeParty, playerTrainers, nil)
|
|
|
|
|
battle.party1starts = playerPartyStarts
|
|
|
|
|
# Set various other properties in the battle class
|
|
|
|
|
pbPrepareBattle(battle)
|
|
|
|
|
$game_temp.clear_battle_rules
|
|
|
|
|
# Perform the battle itself
|
|
|
|
|
decision = 0
|
|
|
|
|
pbBattleAnimation(pbGetWildBattleBGM(foeParty), (foeParty.length == 1) ? 0 : 2, foeParty) {
|
|
|
|
|
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
|
|
|
|
|
# 4 - Wild Pokémon was caught
|
|
|
|
|
# 5 - Draw
|
|
|
|
|
case decision
|
|
|
|
|
when 1, 4 # Won, caught
|
|
|
|
|
$stats.wild_battles_won += 1
|
|
|
|
|
when 2, 3, 5 # Lost, fled, draw
|
|
|
|
|
$stats.wild_battles_lost += 1
|
|
|
|
|
end
|
|
|
|
|
pbSet(outcomeVar, decision)
|
|
|
|
|
return decision
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#===============================================================================
|
|
|
|
|
# Standard methods that start a wild battle of various sizes
|
|
|
|
|
#===============================================================================
|
|
|
|
|
# Used when walking in tall grass, hence the additional code.
|
|
|
|
|
def pbWildBattle(species, level, outcomeVar = 1, canRun = true, canLose = false)
|
|
|
|
|
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]
|
|
|
|
|
EventHandlers.trigger(:on_calling_wild_battle, species, level, handled)
|
|
|
|
|
return handled[0] if !handled[0].nil?
|
|
|
|
|
# Set some battle rules
|
|
|
|
|
setBattleRule("outcomeVar", outcomeVar) if outcomeVar != 1
|
|
|
|
|
setBattleRule("cannotRun") if !canRun
|
|
|
|
|
setBattleRule("canLose") if canLose
|
|
|
|
|
# Perform the battle
|
|
|
|
|
decision = pbWildBattleCore(species, level)
|
|
|
|
|
# Used by the Poké Radar to update/break the chain
|
|
|
|
|
EventHandlers.trigger(:on_wild_battle_end, species, level, decision)
|
|
|
|
|
# Return false if the player lost or drew the battle, and true if any other result
|
|
|
|
|
return (decision != 2 && decision != 5)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def pbDoubleWildBattle(species1, level1, species2, level2,
|
|
|
|
|
outcomeVar = 1, canRun = true, canLose = false)
|
|
|
|
|
# Set some battle rules
|
|
|
|
|
setBattleRule("outcomeVar", outcomeVar) if outcomeVar != 1
|
|
|
|
|
setBattleRule("cannotRun") if !canRun
|
|
|
|
|
setBattleRule("canLose") if canLose
|
|
|
|
|
setBattleRule("double")
|
|
|
|
|
# Perform the battle
|
|
|
|
|
decision = pbWildBattleCore(species1, level1, species2, level2)
|
|
|
|
|
# Return false if the player lost or drew the battle, and true if any other result
|
|
|
|
|
return (decision != 2 && decision != 5)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def pbTripleWildBattle(species1, level1, species2, level2, species3, level3,
|
|
|
|
|
outcomeVar = 1, canRun = true, canLose = false)
|
|
|
|
|
# Set some battle rules
|
|
|
|
|
setBattleRule("outcomeVar", outcomeVar) if outcomeVar != 1
|
|
|
|
|
setBattleRule("cannotRun") if !canRun
|
|
|
|
|
setBattleRule("canLose") if canLose
|
|
|
|
|
setBattleRule("triple")
|
|
|
|
|
# Perform the battle
|
|
|
|
|
decision = pbWildBattleCore(species1, level1, species2, level2, species3, level3)
|
|
|
|
|
# Return false if the player lost or drew the battle, and true if any other result
|
|
|
|
|
return (decision != 2 && decision != 5)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#===============================================================================
|
|
|
|
|
# Start a trainer battle
|
|
|
|
|
#===============================================================================
|
|
|
|
|
def pbTrainerBattleCore(*args)
|
|
|
|
|
outcomeVar = $game_temp.battle_rules["outcomeVar"] || 1
|
|
|
|
|
canLose = $game_temp.battle_rules["canLose"] || false
|
|
|
|
|
# Skip battle if the player has no able Pokémon, or if holding Ctrl in Debug mode
|
|
|
|
|
if $player.able_pokemon_count == 0 || ($DEBUG && Input.press?(Input::CTRL))
|
|
|
|
|
pbMessage(_INTL("SKIPPING BATTLE...")) if $DEBUG
|
|
|
|
|
pbMessage(_INTL("AFTER WINNING...")) if $DEBUG && $player.able_pokemon_count > 0
|
|
|
|
|
pbSet(outcomeVar, ($player.able_pokemon_count == 0) ? 0 : 1) # Treat it as undecided/a win
|
|
|
|
|
$game_temp.clear_battle_rules
|
|
|
|
|
$PokemonGlobal.nextBattleBGM = nil
|
|
|
|
|
$PokemonGlobal.nextBattleVictoryBGM = nil
|
|
|
|
|
$PokemonGlobal.nextBattleCaptureME = nil
|
|
|
|
|
$PokemonGlobal.nextBattleBack = nil
|
|
|
|
|
pbMEStop
|
|
|
|
|
return ($player.able_pokemon_count == 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)
|
|
|
|
|
EventHandlers.trigger(:on_start_battle)
|
|
|
|
|
# Generate trainers and their parties based on the arguments given
|
|
|
|
|
foeTrainers = []
|
|
|
|
|
foeItems = []
|
|
|
|
|
foeEndSpeeches = []
|
|
|
|
|
foeParty = []
|
|
|
|
|
foePartyStarts = []
|
|
|
|
|
args.each do |arg|
|
|
|
|
|
case arg
|
|
|
|
|
when NPCTrainer
|
|
|
|
|
foeTrainers.push(arg)
|
|
|
|
|
foePartyStarts.push(foeParty.length)
|
|
|
|
|
arg.party.each { |pkmn| foeParty.push(pkmn) }
|
|
|
|
|
foeEndSpeeches.push(arg.lose_text)
|
|
|
|
|
foeItems.push(arg.items)
|
|
|
|
|
when Array # [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
|
|
|
|
|
EventHandlers.trigger(:on_trainer_load, trainer)
|
|
|
|
|
foeTrainers.push(trainer)
|
|
|
|
|
foePartyStarts.push(foeParty.length)
|
|
|
|
|
trainer.party.each { |pkmn| foeParty.push(pkmn) }
|
|
|
|
|
foeEndSpeeches.push(arg[3] || trainer.lose_text)
|
|
|
|
|
foeItems.push(trainer.items)
|
|
|
|
|
else
|
|
|
|
|
raise _INTL("Expected NPCTrainer or array of trainer data, got {1}.", arg)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
# Calculate who the player trainer(s) and their party are
|
|
|
|
|
playerTrainers = [$player]
|
|
|
|
|
allyItems = []
|
|
|
|
|
playerParty = $player.party
|
|
|
|
|
playerPartyStarts = [0]
|
|
|
|
|
room_for_partner = (foeParty.length > 1)
|
|
|
|
|
if !room_for_partner && $game_temp.battle_rules["size"] &&
|
|
|
|
|
!["single", "1v1", "1v2", "1v3"].include?($game_temp.battle_rules["size"])
|
|
|
|
|
room_for_partner = true
|
|
|
|
|
end
|
|
|
|
|
if $PokemonGlobal.partner && !$game_temp.battle_rules["noPartner"] && room_for_partner
|
|
|
|
|
ally = NPCTrainer.new($PokemonGlobal.partner[1], $PokemonGlobal.partner[0])
|
|
|
|
|
ally.id = $PokemonGlobal.partner[2]
|
|
|
|
|
ally.party = $PokemonGlobal.partner[3]
|
|
|
|
|
allyItems[1] = ally.items.clone
|
|
|
|
|
playerTrainers.push(ally)
|
|
|
|
|
playerParty = []
|
|
|
|
|
$player.party.each { |pkmn| playerParty.push(pkmn) }
|
|
|
|
|
playerPartyStarts.push(playerParty.length)
|
|
|
|
|
ally.party.each { |pkmn| playerParty.push(pkmn) }
|
|
|
|
|
setBattleRule("double") if !$game_temp.battle_rules["size"]
|
|
|
|
|
end
|
|
|
|
|
# Create the battle scene (the visual side of it)
|
|
|
|
|
scene = pbNewBattleScene
|
|
|
|
|
# Create the battle class (the mechanics side of it)
|
|
|
|
|
battle = Battle.new(scene, playerParty, foeParty, playerTrainers, foeTrainers)
|
|
|
|
|
battle.party1starts = playerPartyStarts
|
|
|
|
|
battle.party2starts = foePartyStarts
|
|
|
|
|
battle.items = foeItems
|
|
|
|
|
battle.ally_items = allyItems
|
|
|
|
|
battle.endSpeeches = foeEndSpeeches
|
|
|
|
|
# Set various other properties in the battle class
|
|
|
|
|
pbPrepareBattle(battle)
|
|
|
|
|
$game_temp.clear_battle_rules
|
|
|
|
|
# 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
|
|
|
|
|
case decision
|
|
|
|
|
when 1 # Won
|
|
|
|
|
$stats.trainer_battles_won += 1
|
|
|
|
|
when 2, 3, 5 # Lost, fled, draw
|
|
|
|
|
$stats.trainer_battles_lost += 1
|
|
|
|
|
end
|
|
|
|
|
pbSet(outcomeVar, decision)
|
|
|
|
|
return decision
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#===============================================================================
|
|
|
|
|
# Standard methods that start a trainer battle of various sizes
|
|
|
|
|
#===============================================================================
|
|
|
|
|
# Used by most trainer events, which can be positioned in such a way that
|
|
|
|
|
# multiple trainer events spot the player at once. The extra code in this method
|
|
|
|
|
# deals with that case and can cause a double trainer battle instead.
|
|
|
|
|
def pbTrainerBattle(trainerID, trainerName, endSpeech = nil,
|
|
|
|
|
doubleBattle = false, trainerPartyID = 0, canLose = false, outcomeVar = 1)
|
|
|
|
|
# If there is another NPC trainer who spotted the player at the same time, and
|
|
|
|
|
# it is possible to have a double battle (the player has 2+ able Pokémon or
|
|
|
|
|
# has a partner trainer), then record this first NPC trainer into
|
|
|
|
|
# $game_temp.waiting_trainer and end this method. That second NPC event will
|
|
|
|
|
# then trigger and cause the battle to happen against this first trainer and
|
|
|
|
|
# themselves.
|
|
|
|
|
if !$game_temp.waiting_trainer && pbMapInterpreterRunning? &&
|
|
|
|
|
($player.able_pokemon_count > 1 ||
|
|
|
|
|
($player.able_pokemon_count > 0 && $PokemonGlobal.partner))
|
|
|
|
|
thisEvent = pbMapInterpreter.get_self
|
|
|
|
|
# Find all other triggered trainer events
|
|
|
|
|
triggeredEvents = $game_player.pbTriggeredTrainerEvents([2], false)
|
|
|
|
|
otherEvent = []
|
|
|
|
|
triggeredEvents.each do |i|
|
|
|
|
|
next if i.id == thisEvent.id
|
|
|
|
|
next if $game_self_switches[[$game_map.map_id, i.id, "A"]]
|
|
|
|
|
otherEvent.push(i)
|
|
|
|
|
end
|
|
|
|
|
# Load the trainer's data, and call an event which might modify it
|
|
|
|
|
trainer = pbLoadTrainer(trainerID, trainerName, trainerPartyID)
|
|
|
|
|
pbMissingTrainer(trainerID, trainerName, trainerPartyID) if !trainer
|
|
|
|
|
return false if !trainer
|
|
|
|
|
EventHandlers.trigger(:on_trainer_load, trainer)
|
|
|
|
|
# If there is exactly 1 other triggered trainer event, and this trainer has
|
|
|
|
|
# 6 or fewer Pokémon, record this trainer for a double battle caused by the
|
|
|
|
|
# other triggered trainer event
|
|
|
|
|
if otherEvent.length == 1 && trainer.party.length <= Settings::MAX_PARTY_SIZE
|
|
|
|
|
trainer.lose_text = endSpeech if endSpeech && !endSpeech.empty?
|
|
|
|
|
$game_temp.waiting_trainer = [trainer, thisEvent.id]
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
# Set some battle rules
|
|
|
|
|
setBattleRule("outcomeVar", outcomeVar) if outcomeVar != 1
|
|
|
|
|
setBattleRule("canLose") if canLose
|
|
|
|
|
setBattleRule("double") if doubleBattle || $game_temp.waiting_trainer
|
|
|
|
|
# Perform the battle
|
|
|
|
|
if $game_temp.waiting_trainer
|
|
|
|
|
decision = pbTrainerBattleCore($game_temp.waiting_trainer[0],
|
|
|
|
|
[trainerID, trainerName, trainerPartyID, endSpeech])
|
|
|
|
|
else
|
|
|
|
|
decision = pbTrainerBattleCore([trainerID, trainerName, trainerPartyID, endSpeech])
|
|
|
|
|
end
|
|
|
|
|
# Finish off the recorded waiting trainer, because they have now been battled
|
|
|
|
|
if decision == 1 && $game_temp.waiting_trainer # Win
|
|
|
|
|
pbMapInterpreter.pbSetSelfSwitch($game_temp.waiting_trainer[1], "A", true)
|
|
|
|
|
end
|
|
|
|
|
$game_temp.waiting_trainer = nil
|
|
|
|
|
# Return true if the player won the battle, and false if any other result
|
|
|
|
|
return (decision == 1)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def pbDoubleTrainerBattle(trainerID1, trainerName1, trainerPartyID1, endSpeech1,
|
|
|
|
|
trainerID2, trainerName2, trainerPartyID2 = 0, endSpeech2 = nil,
|
|
|
|
|
canLose = false, outcomeVar = 1)
|
|
|
|
|
# Set some battle rules
|
|
|
|
|
setBattleRule("outcomeVar", outcomeVar) if outcomeVar != 1
|
|
|
|
|
setBattleRule("canLose") if canLose
|
|
|
|
|
setBattleRule("double")
|
|
|
|
|
# Perform the battle
|
|
|
|
|
decision = pbTrainerBattleCore(
|
|
|
|
|
[trainerID1, trainerName1, trainerPartyID1, endSpeech1],
|
|
|
|
|
[trainerID2, trainerName2, trainerPartyID2, endSpeech2]
|
|
|
|
|
)
|
|
|
|
|
# Return true if the player won the battle, and false if any other result
|
|
|
|
|
return (decision == 1)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def pbTripleTrainerBattle(trainerID1, trainerName1, trainerPartyID1, endSpeech1,
|
|
|
|
|
trainerID2, trainerName2, trainerPartyID2, endSpeech2,
|
|
|
|
|
trainerID3, trainerName3, trainerPartyID3 = 0, endSpeech3 = nil,
|
|
|
|
|
canLose = false, outcomeVar = 1)
|
|
|
|
|
# Set some battle rules
|
|
|
|
|
setBattleRule("outcomeVar", outcomeVar) if outcomeVar != 1
|
|
|
|
|
setBattleRule("canLose") if canLose
|
|
|
|
|
setBattleRule("triple")
|
|
|
|
|
# Perform the battle
|
|
|
|
|
decision = pbTrainerBattleCore(
|
|
|
|
|
[trainerID1, trainerName1, trainerPartyID1, endSpeech1],
|
|
|
|
|
[trainerID2, trainerName2, trainerPartyID2, endSpeech2],
|
|
|
|
|
[trainerID3, trainerName3, trainerPartyID3, endSpeech3]
|
|
|
|
|
)
|
|
|
|
|
# Return true if the player won the battle, and false if any other result
|
|
|
|
|
return (decision == 1)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#===============================================================================
|
|
|
|
|
# After battles
|
|
|
|
|
#===============================================================================
|
|
|
|
|
def pbAfterBattle(decision, canLose)
|
|
|
|
|
def after_battle(outcome, can_lose)
|
|
|
|
|
$player.party.each do |pkmn|
|
|
|
|
|
pkmn.statusCount = 0 if pkmn.status == :POISON # Bad poison becomes regular
|
|
|
|
|
pkmn.makeUnmega
|
|
|
|
|
@@ -589,14 +301,300 @@ def pbAfterBattle(decision, canLose)
|
|
|
|
|
pkmn.makeUnprimal
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if [2, 5].include?(decision) && canLose # if loss or draw
|
|
|
|
|
if [2, 5].include?(outcome) && can_lose # if loss or draw
|
|
|
|
|
$player.party.each { |pkmn| pkmn.heal }
|
|
|
|
|
(Graphics.frame_rate / 4).times { Graphics.update }
|
|
|
|
|
end
|
|
|
|
|
EventHandlers.trigger(:on_end_battle, decision, canLose)
|
|
|
|
|
EventHandlers.trigger(:on_end_battle, outcome, can_lose)
|
|
|
|
|
$game_player.straighten
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
# 4 - Wild Pokémon was caught
|
|
|
|
|
# 5 - Draw
|
|
|
|
|
def set_outcome(outcome, outcome_variable = 1, trainer_battle = false)
|
|
|
|
|
case outcome
|
|
|
|
|
when 1, 4 # Won, caught
|
|
|
|
|
$stats.wild_battles_won += 1 if !trainer_battle
|
|
|
|
|
$stats.trainer_battles_won += 1 if trainer_battle
|
|
|
|
|
when 2, 3, 5 # Lost, fled, draw
|
|
|
|
|
$stats.wild_battles_lost += 1 if !trainer_battle
|
|
|
|
|
$stats.trainer_battles_lost += 1 if trainer_battle
|
|
|
|
|
end
|
|
|
|
|
pbSet(outcome_variable, outcome)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#===============================================================================
|
|
|
|
|
# Wild battles
|
|
|
|
|
#===============================================================================
|
|
|
|
|
class WildBattle
|
|
|
|
|
# Used when walking in tall grass, hence the additional code.
|
|
|
|
|
def self.start(*args, can_override: false)
|
|
|
|
|
foe_party = WildBattle.generate_foes(*args)
|
|
|
|
|
# Potentially call a different WildBattle.start-type method instead (for
|
|
|
|
|
# roaming Pokémon, Safari battles, Bug Contest battles)
|
|
|
|
|
if foe_party.length == 1 && can_override
|
|
|
|
|
handled = [nil]
|
|
|
|
|
EventHandlers.trigger(:on_calling_wild_battle, foe_party[0].species, foe_party[0].level, handled)
|
|
|
|
|
return handled[0] if !handled[0].nil?
|
|
|
|
|
end
|
|
|
|
|
# Perform the battle
|
|
|
|
|
outcome = WildBattle.start_core(*foe_party)
|
|
|
|
|
# Used by the Poké Radar to update/break the chain
|
|
|
|
|
if foe_party.length == 1 && can_override
|
|
|
|
|
EventHandlers.trigger(:on_wild_battle_end, foe_party[0].species, foe_party[0].level, outcome)
|
|
|
|
|
end
|
|
|
|
|
# Return false if the player lost or drew the battle, and true if any other result
|
|
|
|
|
return outcome != 2 && outcome != 5
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def self.start_core(*args)
|
|
|
|
|
outcome_variable = $game_temp.battle_rules["outcomeVar"] || 1
|
|
|
|
|
can_lose = $game_temp.battle_rules["canLose"] || false
|
|
|
|
|
# Skip battle if the player has no able Pokémon, or if holding Ctrl in Debug mode
|
|
|
|
|
if BattleCreationHelperMethods.skip_battle?
|
|
|
|
|
return BattleCreationHelperMethods.skip_battle(outcome_variable)
|
|
|
|
|
end
|
|
|
|
|
# Record information about party Pokémon to be used at the end of battle
|
|
|
|
|
# (e.g. comparing levels for an evolution check)
|
|
|
|
|
EventHandlers.trigger(:on_start_battle)
|
|
|
|
|
# Generate array of foes
|
|
|
|
|
foe_party = WildBattle.generate_foes(*args)
|
|
|
|
|
# Generate information for the player and partner trainer(s)
|
|
|
|
|
player_trainers, ally_items, player_party, player_party_starts = BattleCreationHelperMethods.set_up_player_trainers(foe_party)
|
|
|
|
|
# Create the battle scene (the visual side of it)
|
|
|
|
|
scene = BattleCreationHelperMethods.create_battle_scene
|
|
|
|
|
# Create the battle class (the mechanics side of it)
|
|
|
|
|
battle = Battle.new(scene, player_party, foe_party, player_trainers, nil)
|
|
|
|
|
battle.party1starts = player_party_starts
|
|
|
|
|
battle.ally_items = ally_items
|
|
|
|
|
# Set various other properties in the battle class
|
|
|
|
|
setBattleRule("#{foe_party.length}v#{foe_party.length}") if $game_temp.battle_rules["size"].nil?
|
|
|
|
|
BattleCreationHelperMethods.prepare_battle(battle)
|
|
|
|
|
$game_temp.clear_battle_rules
|
|
|
|
|
# Perform the battle itself
|
|
|
|
|
outcome = 0
|
|
|
|
|
pbBattleAnimation(pbGetWildBattleBGM(foe_party), (foe_party.length == 1) ? 0 : 2, foe_party) {
|
|
|
|
|
pbSceneStandby {
|
|
|
|
|
outcome = battle.pbStartBattle
|
|
|
|
|
}
|
|
|
|
|
BattleCreationHelperMethods.after_battle(outcome, can_lose)
|
|
|
|
|
}
|
|
|
|
|
Input.update
|
|
|
|
|
# Save the result of the battle in a Game Variable (1 by default)
|
|
|
|
|
BattleCreationHelperMethods.set_outcome(outcome, outcome_variable)
|
|
|
|
|
return outcome
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def self.generate_foes(*args)
|
|
|
|
|
ret = []
|
|
|
|
|
species_id = nil
|
|
|
|
|
args.each do |arg|
|
|
|
|
|
case arg
|
|
|
|
|
when Pokemon
|
|
|
|
|
raise _INTL("Species {1} was given but not a level.", species_id) if species_id
|
|
|
|
|
ret.push(arg)
|
|
|
|
|
when Array
|
|
|
|
|
raise _INTL("Species {1} was given but not a level.", species_id) if species_id
|
|
|
|
|
species = GameData::Species.get(arg[0]).id
|
|
|
|
|
pkmn = pbGenerateWildPokemon(species, arg[1])
|
|
|
|
|
ret.push(pkmn)
|
|
|
|
|
else
|
|
|
|
|
if species_id # Expecting level
|
|
|
|
|
if !arg.is_a?(Integer) || !(1..GameData::GrowthRate.max_level).include?(arg)
|
|
|
|
|
raise _INTL("Expected a level (1..{1}) but {2} is not a number or not a valid level.", GameData::GrowthRate.max_level, arg)
|
|
|
|
|
end
|
|
|
|
|
ret.push(pbGenerateWildPokemon(species_id, arg))
|
|
|
|
|
species_id = nil
|
|
|
|
|
else # Expecting species ID
|
|
|
|
|
if !GameData::Species.exists?(arg)
|
|
|
|
|
raise _INTL("Species {1} does not exist.", arg)
|
|
|
|
|
end
|
|
|
|
|
species_id = arg
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
raise _INTL("Species {1} was given but not a level.", species_id) if species_id
|
|
|
|
|
return ret
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#===============================================================================
|
|
|
|
|
# Trainer battles
|
|
|
|
|
#===============================================================================
|
|
|
|
|
class TrainerBattle
|
|
|
|
|
# Used by most trainer events, which can be positioned in such a way that
|
|
|
|
|
# multiple trainer events spot the player at once. The extra code in this
|
|
|
|
|
# method deals with that case and can cause a double trainer battle instead.
|
|
|
|
|
def self.start(*args)
|
|
|
|
|
# If there is another NPC trainer who spotted the player at the same time,
|
|
|
|
|
# and it is possible to have a double battle (the player has 2+ able Pokémon
|
|
|
|
|
# or has a partner trainer), then record this first NPC trainer into
|
|
|
|
|
# $game_temp.waiting_trainer and end this method. That second NPC event will
|
|
|
|
|
# then trigger and cause the battle to happen against this first trainer and
|
|
|
|
|
# themselves.
|
|
|
|
|
if !$game_temp.waiting_trainer && pbMapInterpreterRunning? && pbCanDoubleBattle?
|
|
|
|
|
thisEvent = pbMapInterpreter.get_self
|
|
|
|
|
# Find all other triggered trainer events
|
|
|
|
|
triggeredEvents = $game_player.pbTriggeredTrainerEvents([2], false)
|
|
|
|
|
otherEvent = []
|
|
|
|
|
triggeredEvents.each do |i|
|
|
|
|
|
next if i.id == thisEvent.id
|
|
|
|
|
next if $game_self_switches[[$game_map.map_id, i.id, "A"]]
|
|
|
|
|
otherEvent.push(i)
|
|
|
|
|
end
|
|
|
|
|
# If there is exactly 1 other triggered trainer event, this trainer can be
|
|
|
|
|
# stored up to battle with that one
|
|
|
|
|
if otherEvent.length == 1
|
|
|
|
|
trainers, _items, _end_speeches, _party, _party_starts = TrainerBattle.generate_foes(*args)
|
|
|
|
|
# If this is just 1 trainer with 6 or fewer Pokémon, it can be stored up
|
|
|
|
|
# to battle alongside the other trainer
|
|
|
|
|
if trainers.length == 1 && trainers[0].party.length <= Settings::MAX_PARTY_SIZE
|
|
|
|
|
$game_temp.waiting_trainer = [trainers[0], thisEvent.id]
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
# Perform the battle
|
|
|
|
|
if $game_temp.waiting_trainer
|
|
|
|
|
new_args = args + [$game_temp.waiting_trainer[0]]
|
|
|
|
|
outcome = TrainerBattle.start_core(*new_args)
|
|
|
|
|
pbMapInterpreter.pbSetSelfSwitch($game_temp.waiting_trainer[1], "A", true) if outcome == 1
|
|
|
|
|
$game_temp.waiting_trainer = nil
|
|
|
|
|
else
|
|
|
|
|
outcome = TrainerBattle.start_core(*args)
|
|
|
|
|
end
|
|
|
|
|
# Return true if the player won the battle, and false if any other result
|
|
|
|
|
return outcome == 1
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def self.start_core(*args)
|
|
|
|
|
outcome_variable = $game_temp.battle_rules["outcomeVar"] || 1
|
|
|
|
|
can_lose = $game_temp.battle_rules["canLose"] || false
|
|
|
|
|
# Skip battle if the player has no able Pokémon, or if holding Ctrl in Debug mode
|
|
|
|
|
if BattleCreationHelperMethods.skip_battle?
|
|
|
|
|
return BattleCreationHelperMethods.skip_battle(outcome_variable, true)
|
|
|
|
|
end
|
|
|
|
|
# Record information about party Pokémon to be used at the end of battle (e.g.
|
|
|
|
|
# comparing levels for an evolution check)
|
|
|
|
|
EventHandlers.trigger(:on_start_battle)
|
|
|
|
|
# Generate information for the foes
|
|
|
|
|
foe_trainers, foe_items, end_speeches, foe_party, foe_party_starts = TrainerBattle.generate_foes(*args)
|
|
|
|
|
# Generate information for the player and partner trainer(s)
|
|
|
|
|
player_trainers, ally_items, player_party, player_party_starts = BattleCreationHelperMethods.set_up_player_trainers(foe_party)
|
|
|
|
|
# Create the battle scene (the visual side of it)
|
|
|
|
|
scene = BattleCreationHelperMethods.create_battle_scene
|
|
|
|
|
# Create the battle class (the mechanics side of it)
|
|
|
|
|
battle = Battle.new(scene, player_party, foe_party, player_trainers, foe_trainers)
|
|
|
|
|
battle.party1starts = player_party_starts
|
|
|
|
|
battle.party2starts = foe_party_starts
|
|
|
|
|
battle.ally_items = ally_items
|
|
|
|
|
battle.items = foe_items
|
|
|
|
|
battle.endSpeeches = end_speeches
|
|
|
|
|
# Set various other properties in the battle class
|
|
|
|
|
setBattleRule("#{foe_trainers.length}v#{foe_trainers.length}") if $game_temp.battle_rules["size"].nil?
|
|
|
|
|
BattleCreationHelperMethods.prepare_battle(battle)
|
|
|
|
|
$game_temp.clear_battle_rules
|
|
|
|
|
# Perform the battle itself
|
|
|
|
|
outcome = 0
|
|
|
|
|
pbBattleAnimation(pbGetTrainerBattleBGM(foe_trainers), (battle.singleBattle?) ? 1 : 3, foe_trainers) {
|
|
|
|
|
pbSceneStandby {
|
|
|
|
|
outcome = battle.pbStartBattle
|
|
|
|
|
}
|
|
|
|
|
BattleCreationHelperMethods.after_battle(outcome, can_lose)
|
|
|
|
|
}
|
|
|
|
|
Input.update
|
|
|
|
|
# Save the result of the battle in a Game Variable (1 by default)
|
|
|
|
|
BattleCreationHelperMethods.set_outcome(outcome, outcome_variable, true)
|
|
|
|
|
return outcome
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def self.generate_foes(*args)
|
|
|
|
|
trainer_array = []
|
|
|
|
|
foe_items = []
|
|
|
|
|
end_speeches = []
|
|
|
|
|
pokemon_array = []
|
|
|
|
|
party_starts = []
|
|
|
|
|
trainer_type = nil
|
|
|
|
|
trainer_name = nil
|
|
|
|
|
args.each_with_index do |arg, i|
|
|
|
|
|
case arg
|
|
|
|
|
when NPCTrainer
|
|
|
|
|
raise _INTL("Trainer type {1} was given but not a trainer name.", trainer_type) if trainer_type
|
|
|
|
|
trainer_array.push(arg)
|
|
|
|
|
foe_items.push(arg.items)
|
|
|
|
|
end_speeches.push(arg.lose_text)
|
|
|
|
|
party_starts.push(pokemon_array.length)
|
|
|
|
|
arg.party.each { |pkmn| pokemon_array.push(pkmn) }
|
|
|
|
|
when Array # [trainer type, trainer name, version number, speech (optional)]
|
|
|
|
|
raise _INTL("Trainer type {1} was given but not a trainer name.", trainer_type) if trainer_type
|
|
|
|
|
trainer = pbLoadTrainer(arg[0], arg[1], arg[2])
|
|
|
|
|
pbMissingTrainer(arg[0], arg[1], arg[2]) if !trainer
|
|
|
|
|
trainer = pbLoadTrainer(arg[0], arg[1], arg[2]) if !trainer # Try again
|
|
|
|
|
raise _INTL("Trainer for data '{1}' is not defined.", arg) if !trainer
|
|
|
|
|
EventHandlers.trigger(:on_trainer_load, trainer)
|
|
|
|
|
trainer_array.push(trainer)
|
|
|
|
|
foe_items.push(trainer.items)
|
|
|
|
|
end_speeches.push(arg[3] || trainer.lose_text)
|
|
|
|
|
party_starts.push(pokemon_array.length)
|
|
|
|
|
trainer.party.each { |pkmn| pokemon_array.push(pkmn) }
|
|
|
|
|
else
|
|
|
|
|
if trainer_name # Expecting version number
|
|
|
|
|
if !arg.is_a?(Integer) || arg < 0
|
|
|
|
|
raise _INTL("Expected a trainer version number (0 or higher) but {1} is not a number or not a valid value.", arg)
|
|
|
|
|
end
|
|
|
|
|
trainer = pbLoadTrainer(trainer_type, trainer_name, arg)
|
|
|
|
|
pbMissingTrainer(trainer_type, trainer_name, arg) if !trainer
|
|
|
|
|
trainer = pbLoadTrainer(trainer_type, trainer_name, arg) if !trainer # Try again
|
|
|
|
|
raise _INTL("Trainer for data '{1}, {2}, {3}' is not defined.", trainer_type, trainer_name, arg) if !trainer
|
|
|
|
|
EventHandlers.trigger(:on_trainer_load, trainer)
|
|
|
|
|
trainer_array.push(trainer)
|
|
|
|
|
foe_items.push(trainer.items)
|
|
|
|
|
end_speeches.push(trainer.lose_text)
|
|
|
|
|
party_starts.push(pokemon_array.length)
|
|
|
|
|
trainer.party.each { |pkmn| pokemon_array.push(pkmn) }
|
|
|
|
|
trainer_type = nil
|
|
|
|
|
trainer_name = nil
|
|
|
|
|
elsif trainer_type # Expecting trainer name
|
|
|
|
|
if !arg.is_a?(String) || arg.strip.empty?
|
|
|
|
|
raise _INTL("Expected a trainer name but '{1}' is not a valid name.", arg)
|
|
|
|
|
end
|
|
|
|
|
if args[i + 1].is_a?(Integer) # Version number is next
|
|
|
|
|
trainer_name = arg.strip
|
|
|
|
|
else
|
|
|
|
|
trainer = pbLoadTrainer(trainer_type, arg)
|
|
|
|
|
pbMissingTrainer(trainer_type, arg, 0) if !trainer
|
|
|
|
|
trainer = pbLoadTrainer(trainer_type, arg) if !trainer # Try again
|
|
|
|
|
raise _INTL("Trainer for data '{1}, {2}' is not defined.", trainer_type, arg) if !trainer
|
|
|
|
|
EventHandlers.trigger(:on_trainer_load, trainer)
|
|
|
|
|
trainer_array.push(trainer)
|
|
|
|
|
foe_items.push(trainer.items)
|
|
|
|
|
end_speeches.push(trainer.lose_text)
|
|
|
|
|
party_starts.push(pokemon_array.length)
|
|
|
|
|
trainer.party.each { |pkmn| pokemon_array.push(pkmn) }
|
|
|
|
|
trainer_type = nil
|
|
|
|
|
end
|
|
|
|
|
else # Expecting trainer type
|
|
|
|
|
if !GameData::TrainerType.exists?(arg)
|
|
|
|
|
raise _INTL("Trainer type {1} does not exist.", arg)
|
|
|
|
|
end
|
|
|
|
|
trainer_type = arg
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
raise _INTL("Trainer type {1} was given but not a trainer name.", trainer_type) if trainer_type
|
|
|
|
|
return trainer_array, foe_items, end_speeches, pokemon_array, party_starts
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#===============================================================================
|
|
|
|
|
# After battles
|
|
|
|
|
#===============================================================================
|
|
|
|
|
EventHandlers.add(:on_end_battle, :evolve_and_black_out,
|
|
|
|
|
proc { |decision, canLose|
|
|
|
|
|
# Check for evolutions
|
|
|
|
|
@@ -739,3 +737,103 @@ def pbHoneyGather(pkmn)
|
|
|
|
|
return unless rand(100) < chance
|
|
|
|
|
pkmn.item = :HONEY
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#===============================================================================
|
|
|
|
|
# Deprecated methods
|
|
|
|
|
#===============================================================================
|
|
|
|
|
# @deprecated This method is slated to be removed in v21.
|
|
|
|
|
def pbNewBattleScene
|
|
|
|
|
Deprecation.warn_method("pbNewBattleScene", "v21", "BattleCreationHelperMethods.create_battle_scene")
|
|
|
|
|
return BattleCreationHelperMethods.create_battle_scene
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# @deprecated This method is slated to be removed in v21.
|
|
|
|
|
def pbPrepareBattle(battle)
|
|
|
|
|
Deprecation.warn_method("pbPrepareBattle", "v21", "BattleCreationHelperMethods.prepare_battle(battle)")
|
|
|
|
|
BattleCreationHelperMethods.prepare_battle(battle)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# @deprecated This method is slated to be removed in v21.
|
|
|
|
|
def pbWildBattleCore(*args)
|
|
|
|
|
Deprecation.warn_method("pbWildBattleCore", "v21", "WildBattle.start_core(species, level)")
|
|
|
|
|
return WildBattle.start_core(*args)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# @deprecated This method is slated to be removed in v21.
|
|
|
|
|
def pbWildBattle(species, level, outcomeVar = 1, canRun = true, canLose = false)
|
|
|
|
|
Deprecation.warn_method("pbWildBattle", "v21", "WildBattle.start(species, level)")
|
|
|
|
|
setBattleRule("outcomeVar", outcomeVar) if outcomeVar != 1
|
|
|
|
|
setBattleRule("cannotRun") if !canRun
|
|
|
|
|
setBattleRule("canLose") if canLose
|
|
|
|
|
return WildBattle.start(species, level)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# @deprecated This method is slated to be removed in v21.
|
|
|
|
|
def pbDoubleWildBattle(species1, level1, species2, level2,
|
|
|
|
|
outcomeVar = 1, canRun = true, canLose = false)
|
|
|
|
|
Deprecation.warn_method("pbDoubleWildBattle", "v21", "WildBattle.start(pkmn1, pkmn2)")
|
|
|
|
|
setBattleRule("outcomeVar", outcomeVar) if outcomeVar != 1
|
|
|
|
|
setBattleRule("cannotRun") if !canRun
|
|
|
|
|
setBattleRule("canLose") if canLose
|
|
|
|
|
setBattleRule("double")
|
|
|
|
|
return WildBattle.start(species1, level1, species2, level2)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# @deprecated This method is slated to be removed in v21.
|
|
|
|
|
def pbTripleWildBattle(species1, level1, species2, level2, species3, level3,
|
|
|
|
|
outcomeVar = 1, canRun = true, canLose = false)
|
|
|
|
|
Deprecation.warn_method("pbTripleWildBattle", "v21", "WildBattle.start(pkmn1, pkmn2, pkmn3)")
|
|
|
|
|
setBattleRule("outcomeVar", outcomeVar) if outcomeVar != 1
|
|
|
|
|
setBattleRule("cannotRun") if !canRun
|
|
|
|
|
setBattleRule("canLose") if canLose
|
|
|
|
|
setBattleRule("triple")
|
|
|
|
|
return WildBattle.start(species1, level1, species2, level2, species3, level3)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# @deprecated This method is slated to be removed in v21.
|
|
|
|
|
def pbTrainerBattleCore(*args)
|
|
|
|
|
Deprecation.warn_method("pbTrainerBattleCore", "v21", "TrainerBattle.start_core(trainer_type, trainer_name, trainer_version)")
|
|
|
|
|
return TrainerBattle.start_core(*args)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# @deprecated This method is slated to be removed in v21.
|
|
|
|
|
def pbTrainerBattle(trainerID, trainerName, endSpeech = nil,
|
|
|
|
|
doubleBattle = false, trainerPartyID = 0, canLose = false, outcomeVar = 1)
|
|
|
|
|
Deprecation.warn_method("pbTrainerBattle", "v21", "TrainerBattle.start(trainer_type, trainer_name, trainer_version)")
|
|
|
|
|
setBattleRule("outcomeVar", outcomeVar) if outcomeVar != 1
|
|
|
|
|
setBattleRule("canLose") if canLose
|
|
|
|
|
setBattleRule("double") if doubleBattle
|
|
|
|
|
return TrainerBattle.start(trainerID, trainerName, trainerPartyID)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# @deprecated This method is slated to be removed in v21.
|
|
|
|
|
def pbDoubleTrainerBattle(trainerID1, trainerName1, trainerPartyID1, endSpeech1,
|
|
|
|
|
trainerID2, trainerName2, trainerPartyID2 = 0, endSpeech2 = nil,
|
|
|
|
|
canLose = false, outcomeVar = 1)
|
|
|
|
|
Deprecation.warn_method("pbDoubleTrainerBattle", "v21", "TrainerBattle.start(trainer1, trainer2)")
|
|
|
|
|
setBattleRule("outcomeVar", outcomeVar) if outcomeVar != 1
|
|
|
|
|
setBattleRule("canLose") if canLose
|
|
|
|
|
setBattleRule("double")
|
|
|
|
|
return TrainerBattle.start(trainerID1, trainerName1, trainerPartyID1,
|
|
|
|
|
trainerID2, trainerName2, trainerPartyID2)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# @deprecated This method is slated to be removed in v21.
|
|
|
|
|
def pbTripleTrainerBattle(trainerID1, trainerName1, trainerPartyID1, endSpeech1,
|
|
|
|
|
trainerID2, trainerName2, trainerPartyID2, endSpeech2,
|
|
|
|
|
trainerID3, trainerName3, trainerPartyID3 = 0, endSpeech3 = nil,
|
|
|
|
|
canLose = false, outcomeVar = 1)
|
|
|
|
|
Deprecation.warn_method("pbTripleTrainerBattle", "v21", "TrainerBattle.start(trainer1, trainer2, trainer3)")
|
|
|
|
|
setBattleRule("outcomeVar", outcomeVar) if outcomeVar != 1
|
|
|
|
|
setBattleRule("canLose") if canLose
|
|
|
|
|
setBattleRule("triple")
|
|
|
|
|
return TrainerBattle.start(trainerID1, trainerName1, trainerPartyID1,
|
|
|
|
|
trainerID2, trainerName2, trainerPartyID2,
|
|
|
|
|
trainerID3, trainerName3, trainerPartyID3)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# @deprecated This method is slated to be removed in v21.
|
|
|
|
|
def pbAfterBattle(outcome, can_lose)
|
|
|
|
|
Deprecation.warn_method("pbAfterBattle", "v21", "BattleCreationHelperMethods.after_battle(outcome, can_lose)")
|
|
|
|
|
BattleCreationHelperMethods.after_battle(outcome, can_lose)
|
|
|
|
|
end
|
|
|
|
|
|