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

@@ -183,7 +183,7 @@ Events.onMapUpdate += proc { |_sender,_e|
last = $PokemonGlobal.pokerusTime
now = pbGetTimeNow
if !last || last.year!=now.year || last.month!=now.month || last.day!=now.day
for i in $Trainer.pokemonParty
for i in $Trainer.pokemon_party
i.lowerPokerusCount
end
$PokemonGlobal.pokerusTime = now
@@ -263,7 +263,7 @@ Events.onStepTaken += proc {
$PokemonGlobal.happinessSteps = 0 if !$PokemonGlobal.happinessSteps
$PokemonGlobal.happinessSteps += 1
if $PokemonGlobal.happinessSteps>=128
for pkmn in $Trainer.ablePokemonParty
for pkmn in $Trainer.able_party
pkmn.changeHappiness("walking") if rand(2)==0
end
$PokemonGlobal.happinessSteps = 0
@@ -276,7 +276,7 @@ Events.onStepTakenTransferPossible += proc { |_sender,e|
next if handled[0]
if $PokemonGlobal.stepcount%4==0 && POISON_IN_FIELD
flashed = false
for i in $Trainer.ablePokemonParty
for i in $Trainer.able_party
if i.status==PBStatuses::POISON && !i.hasAbility?(:IMMUNITY)
if !flashed
$game_screen.start_flash(Color.new(255,0,0,128), 4)
@@ -292,7 +292,7 @@ Events.onStepTakenTransferPossible += proc { |_sender,e|
i.status = PBStatuses::NONE
pbMessage(_INTL("{1} fainted...",i.name))
end
if pbAllFainted
if $Trainer.able_pokemon_count == 0
handled[0] = true
pbCheckAllFainted
end
@@ -302,7 +302,7 @@ Events.onStepTakenTransferPossible += proc { |_sender,e|
}
def pbCheckAllFainted
if pbAllFainted
if $Trainer.able_pokemon_count == 0
pbMessage(_INTL("You have no more Pokémon that can fight!\1"))
pbMessage(_INTL("You blacked out!"))
pbBGMFade(1.0)
@@ -378,7 +378,7 @@ Events.onChangeDirection += proc {
}
def pbBattleOnStepTaken(repel = false)
return if $Trainer.ablePokemonCount == 0
return if $Trainer.able_pokemon_count == 0
encounterType = $PokemonEncounters.pbEncounterType
return if encounterType < 0
return if !$PokemonEncounters.isEncounterPossibleHere?
@@ -387,7 +387,7 @@ def pbBattleOnStepTaken(repel = false)
encounter = EncounterModifier.trigger(encounter)
if $PokemonEncounters.pbCanEncounter?(encounter, repel)
if !$PokemonTemp.forceSingleBattle && !pbInSafari? && ($PokemonGlobal.partner ||
($Trainer.ablePokemonCount > 1 && PBTerrain.isDoubleWildBattle?(pbGetTerrainTag) && rand(100) < 30))
($Trainer.able_pokemon_count > 1 && PBTerrain.isDoubleWildBattle?(pbGetTerrainTag) && rand(100) < 30))
encounter2 = $PokemonEncounters.pbEncounteredPokemon(encounterType)
encounter2 = EncounterModifier.trigger(encounter2)
pbDoubleWildBattle(encounter[0], encounter[1], encounter2[0], encounter2[1])
@@ -909,7 +909,7 @@ def pbFishingEnd
end
def pbFishing(hasEncounter,rodType=1)
speedup = ($Trainer.firstPokemon && [:STICKYHOLD, :SUCTIONCUPS].include?($Trainer.firstPokemon.ability_id))
speedup = ($Trainer.first_pokemon && [:STICKYHOLD, :SUCTIONCUPS].include?($Trainer.first_pokemon.ability_id))
biteChance = 20+(25*rodType) # 45, 70, 95
biteChance *= 1.5 if speedup # 67.5, 100, 100
hookChance = 100
@@ -1059,13 +1059,11 @@ def pbRegisterPartner(tr_type, tr_name, tr_id = 0)
pbCancelVehicles
trainer = pbLoadTrainer(tr_type, tr_name, tr_id)
Events.onTrainerPartyLoad.trigger(nil, trainer)
trainerobject = PokeBattle_Trainer.new(trainer[0].name, tr_type)
trainerobject.setForeignID($Trainer)
for i in trainer[2]
i.owner = Pokemon::Owner.new_from_trainer(trainerobject)
for i in trainer.party
i.owner = Pokemon::Owner.new_from_trainer(trainer)
i.calcStats
end
$PokemonGlobal.partner = [tr_type, trainerobject.name, trainerobject.id, trainer[2]]
$PokemonGlobal.partner = [tr_type, tr_name, trainer.id, trainer.party]
end
def pbDeregisterPartner

View File

@@ -131,7 +131,7 @@ def pbBattleAnimationOverride(viewport,battletype=0,foe=nil)
##### VS. animation, by Luka S.J. #####
##### Tweaked by Maruno #####
if (battletype==1 || battletype==3) && foe.length==1 # Against single trainer
tr_type = foe[0].trainertype
tr_type = foe[0].trainer_type
tr_type_id = GameData::TrainerType.get(tr_type).id_number
if tr_type
tbargraphic = sprintf("Graphics/Transitions/vsBar%s", tr_type.to_s) rescue nil
@@ -139,7 +139,7 @@ def pbBattleAnimationOverride(viewport,battletype=0,foe=nil)
tgraphic = sprintf("Graphics/Transitions/vsTrainer%s", tr_type.to_s) rescue nil
tgraphic = sprintf("Graphics/Transitions/vsTrainer%d", tr_type_id) if !pbResolveBitmap(tgraphic)
if pbResolveBitmap(tbargraphic) && pbResolveBitmap(tgraphic)
player_tr_type = $Trainer.trainertype
player_tr_type = $Trainer.trainer_type
player_tr_type_id = GameData::TrainerType.get(player_tr_type).id_number
outfit = $Trainer.outfit
# Set up
@@ -631,7 +631,7 @@ def pbStartOver(gameover=false)
pbBugContestStartOver
return
end
pbHealAll
$Trainer.heal_party
if $PokemonGlobal.pokecenterMapId && $PokemonGlobal.pokecenterMapId>=0
if gameover
pbMessage(_INTL("\\w[]\\wm\\c[8]\\l[3]After the unfortunate defeat, you scurry back to a Pokémon Center."))
@@ -653,7 +653,7 @@ def pbStartOver(gameover=false)
if $DEBUG
pbMessage(_ISPRINTF("Can't find the map 'Map{1:03d}' in the Data folder. The game will resume at the player's position.",homedata[0]))
end
pbHealAll
$Trainer.heal_party
return
end
if gameover
@@ -672,7 +672,7 @@ def pbStartOver(gameover=false)
$scene.transfer_player if $scene.is_a?(Scene_Map)
$game_map.refresh
else
pbHealAll
$Trainer.heal_party
end
end
pbEraseEscapePoint

View File

@@ -208,12 +208,12 @@ Events.onStartBattle += proc { |_sender|
}
def pbCanDoubleBattle?
return $PokemonGlobal.partner || $Trainer.ablePokemonCount>=2
return $PokemonGlobal.partner || $Trainer.able_pokemon_count >= 2
end
def pbCanTripleBattle?
return true if $Trainer.ablePokemonCount>=3
return $PokemonGlobal.partner && $Trainer.ablePokemonCount>=2
return true if $Trainer.able_pokemon_count >= 3
return $PokemonGlobal.partner && $Trainer.able_pokemon_count >= 2
end
#===============================================================================
@@ -223,8 +223,8 @@ def pbWildBattleCore(*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 $Trainer.pokemonCount>0
if $Trainer.able_pokemon_count == 0 || ($DEBUG && Input.press?(Input::CTRL))
pbMessage(_INTL("SKIPPING BATTLE...")) if $Trainer.pokemon_count > 0
pbSet(outcomeVar,1) # Treat it as a win
$PokemonTemp.clearBattleRules
$PokemonGlobal.nextBattleBGM = nil
@@ -266,7 +266,7 @@ def pbWildBattleCore(*args)
room_for_partner = true
end
if $PokemonGlobal.partner && !$PokemonTemp.battleRules["noPartner"] && room_for_partner
ally = PokeBattle_Trainer.new($PokemonGlobal.partner[1],$PokemonGlobal.partner[0])
ally = NPCTrainer.new($PokemonGlobal.partner[1],$PokemonGlobal.partner[0])
ally.id = $PokemonGlobal.partner[2]
ally.party = $PokemonGlobal.partner[3]
playerTrainers.push(ally)
@@ -360,16 +360,16 @@ 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))
if $Trainer.able_pokemon_count == 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
pbMessage(_INTL("AFTER WINNING...")) if $DEBUG && $Trainer.able_pokemon_count > 0
pbSet(outcomeVar,($Trainer.able_pokemon_count == 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
return ($Trainer.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)
@@ -382,24 +382,23 @@ def pbTrainerBattleCore(*args)
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])
if arg.is_a?(NPCTrainer)
foeTrainers.push(arg)
foePartyStarts.push(foeParty.length)
arg[1].each { |pkmn| foeParty.push(pkmn) }
foeEndSpeeches.push(arg[2])
foeItems.push(arg[3])
arg.party.each { |pkmn| foeParty.push(pkmn) }
foeEndSpeeches.push(arg.lose_text)
foeItems.push(arg.items)
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])
foeTrainers.push(trainer)
foePartyStarts.push(foeParty.length)
trainer[2].each { |pkmn| foeParty.push(pkmn) }
foeEndSpeeches.push(arg[3] || trainer[3])
foeItems.push(trainer[1])
trainer.party.each { |pkmn| foeParty.push(pkmn) }
foeEndSpeeches.push(arg[3] || trainer.lose_text)
foeItems.push(trainer.items)
end
end
# Calculate who the player trainer(s) and their party are
@@ -412,7 +411,7 @@ def pbTrainerBattleCore(*args)
room_for_partner = true
end
if $PokemonGlobal.partner && !$PokemonTemp.battleRules["noPartner"] && room_for_partner
ally = PokeBattle_Trainer.new($PokemonGlobal.partner[1],$PokemonGlobal.partner[0])
ally = NPCTrainer.new($PokemonGlobal.partner[1], $PokemonGlobal.partner[0])
ally.id = $PokemonGlobal.partner[2]
ally.party = $PokemonGlobal.partner[3]
playerTrainers.push(ally)
@@ -469,8 +468,8 @@ def pbTrainerBattle(trainerID, trainerName, endSpeech=nil,
# then trigger and cause the battle to happen against this first trainer and
# themselves.
if !$PokemonTemp.waitingTrainer && pbMapInterpreterRunning? &&
($Trainer.ablePokemonCount>1 ||
($Trainer.ablePokemonCount>0 && $PokemonGlobal.partner))
($Trainer.able_pokemon_count > 1 ||
($Trainer.able_pokemon_count > 0 && $PokemonGlobal.partner))
thisEvent = pbMapInterpreter.get_character(0)
# Find all other triggered trainer events
triggeredEvents = $game_player.pbTriggeredTrainerEvents([2],false)
@@ -488,8 +487,9 @@ def pbTrainerBattle(trainerID, trainerName, endSpeech=nil,
# 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[2].length<=6
$PokemonTemp.waitingTrainer = [trainer,endSpeech || trainer[3],thisEvent.id]
if otherEvent.length == 1 && trainer.party.length <= MAX_PARTY_SIZE
trainer.lose_text = endSpeech if endSpeech && !endSpeech.empty?
$PokemonTemp.waitingTrainer = [trainer, thisEvent.id]
return false
end
end
@@ -500,8 +500,7 @@ def pbTrainerBattle(trainerID, trainerName, endSpeech=nil,
# Perform the battle
if $PokemonTemp.waitingTrainer
waitingTrainer = $PokemonTemp.waitingTrainer
decision = pbTrainerBattleCore(
[waitingTrainer[0][0],waitingTrainer[0][2],waitingTrainer[1],waitingTrainer[0][1]],
decision = pbTrainerBattleCore($PokemonTemp.waitingTrainer,
[trainerID,trainerName,trainerPartyID,endSpeech]
)
else
@@ -509,7 +508,7 @@ def pbTrainerBattle(trainerID, trainerName, endSpeech=nil,
end
# Finish off the recorded waiting trainer, because they have now been battled
if decision==1 && $PokemonTemp.waitingTrainer # Win
pbMapInterpreter.pbSetSelfSwitch($PokemonTemp.waitingTrainer[2],"A",true)
pbMapInterpreter.pbSetSelfSwitch($PokemonTemp.waitingTrainer[1], "A", true)
end
$PokemonTemp.waitingTrainer = nil
# Return true if the player won the battle, and false if any other result
@@ -560,7 +559,7 @@ def pbAfterBattle(decision,canLose)
pkmn.makeUnprimal
end
if $PokemonGlobal.partner
pbHealAll
$Trainer.heal_party
$PokemonGlobal.partner[3].each do |pkmn|
pkmn.heal
pkmn.makeUnmega
@@ -588,7 +587,7 @@ Events.onEndBattle += proc { |_sender,e|
end
case decision
when 1, 4 # Win, capture
$Trainer.pokemonParty.each do |pkmn|
$Trainer.pokemon_party.each do |pkmn|
pbPickup(pkmn)
pbHoneyGather(pkmn)
end

View File

@@ -240,7 +240,7 @@ class PokemonEncounters
# Static/Magnet Pull prefer wild encounters of certain types, if possible.
# If they activate, they remove all Pokémon from the encounter table that do
# not have the type they favor. If none have that type, nothing is changed.
firstPkmn = $Trainer.firstPokemon
firstPkmn = $Trainer.first_pokemon
if firstPkmn && rand(100)<50 # 50% chance of happening
favoredType = nil
if firstPkmn.hasAbility?(:STATIC) && GameData::Type.exists?(:ELECTRIC)
@@ -336,7 +336,7 @@ class PokemonEncounters
encount *= 1.5
end
end
firstPkmn = $Trainer.firstPokemon
firstPkmn = $Trainer.first_pokemon
if firstPkmn
case firstPkmn.item_id
when :CLEANSETAG
@@ -382,7 +382,7 @@ class PokemonEncounters
return false if $DEBUG && Input.press?(Input::CTRL)
if !pbPokeRadarOnShakingGrass
if $PokemonGlobal.repel>0 || repel
firstPkmn = (REPEL_COUNTS_FAINTED_POKEMON) ? $Trainer.firstPokemon : $Trainer.firstAblePokemon
firstPkmn = (REPEL_COUNTS_FAINTED_POKEMON) ? $Trainer.first_pokemon : $Trainer.first_able_pokemon
return false if firstPkmn && encounter[1]<firstPkmn.level
end
end
@@ -400,7 +400,7 @@ def pbGenerateWildPokemon(species,level,isRoamer=false)
genwildpoke = Pokemon.new(species,level)
# Give the wild Pokémon a held item
items = genwildpoke.wildHoldItems
firstPkmn = $Trainer.firstPokemon
firstPkmn = $Trainer.first_pokemon
chances = [50,5,1]
chances = [60,20,5] if firstPkmn && firstPkmn.hasAbility?(:COMPOUNDEYES)
itemrnd = rand(100)

View File

@@ -30,16 +30,13 @@ Events.onWildPokemonCreate += proc { |_sender, e|
end
}
# This is the basis of a trainer modifier. It works both for trainers loaded
# This is the basis of a trainer modifier. It works both for trainers loaded
# when you battle them, and for partner trainers when they are registered.
# Note that you can only modify a partner trainer's Pokémon, and not the trainer
# themselves nor their items this way, as those are generated from scratch
# before each battle.
#Events.onTrainerPartyLoad += proc { |_sender, e|
# if e[0] # Trainer data should exist to be loaded, but may not exist somehow
# trainer = e[0][0] # A PokeBattle_Trainer object of the loaded trainer
# items = e[0][1] # An array of the trainer's items they can use
# party = e[0][2] # An array of the trainer's Pokémon
#Events.onTrainerPartyLoad += proc { |_sender, trainer|
# if trainer # An NPCTrainer object containing party/items/lose text, etc.
# YOUR CODE HERE
# end
#}

View File

@@ -55,7 +55,7 @@ end
def pbCheckHiddenMoveBadge(badge=-1,showmsg=true)
return true if badge<0 # No badge requirement
return true if $DEBUG
if (FIELD_MOVES_COUNT_BADGES) ? $Trainer.numbadges>=badge : $Trainer.badges[badge]
if (FIELD_MOVES_COUNT_BADGES) ? $Trainer.badge_count >= badge : $Trainer.badges[badge]
return true
end
pbMessage(_INTL("Sorry, a new Badge is required.")) if showmsg
@@ -187,7 +187,7 @@ end
#===============================================================================
def pbCut
move = :CUT
movefinder = pbCheckMove(move)
movefinder = $Trainer.get_pokemon_with_move(move)
if !pbCheckHiddenMoveBadge(BADGE_FOR_CUT,false) || (!$DEBUG && !movefinder)
pbMessage(_INTL("This tree looks like it can be cut down."))
return false
@@ -297,7 +297,7 @@ def pbDive
map_metadata = GameData::MapMetadata.try_get($game_map.map_id)
return false if !map_metadata || !map_metadata.dive_map_id
move = :DIVE
movefinder = pbCheckMove(move)
movefinder = $Trainer.get_pokemon_with_move(move)
if !pbCheckHiddenMoveBadge(BADGE_FOR_DIVE,false) || (!$DEBUG && !movefinder)
pbMessage(_INTL("The sea is deep here. A Pokémon may be able to go underwater."))
return false
@@ -333,7 +333,7 @@ def pbSurfacing
end
return if !surface_map_id
move = :DIVE
movefinder = pbCheckMove(move)
movefinder = $Trainer.get_pokemon_with_move(move)
if !pbCheckHiddenMoveBadge(BADGE_FOR_DIVE,false) || (!$DEBUG && !movefinder)
pbMessage(_INTL("Light is filtering down from above. A Pokémon may be able to surface here."))
return false
@@ -536,7 +536,7 @@ def pbHeadbuttEffect(event=nil)
event = $game_player.pbFacingEvent(true) if !event
a = (event.x+(event.x/24).floor+1)*(event.y+(event.y/24).floor+1)
a = (a*2/5)%10 # Even 2x as likely as odd, 0 is 1.5x as likely as odd
b = ($Trainer.publicID)%10 # Practically equal odds of each value
b = $Trainer.public_ID % 10 # Practically equal odds of each value
chance = 1 # ~50%
if a==b; chance = 8 # 10%
elsif a>b && (a-b).abs<5; chance = 5 # ~30.3%
@@ -554,7 +554,7 @@ end
def pbHeadbutt(event=nil)
move = :HEADBUTT
movefinder = pbCheckMove(move)
movefinder = $Trainer.get_pokemon_with_move(move)
if !$DEBUG && !movefinder
pbMessage(_INTL("A Pokémon could be in this tree. Maybe a Pokémon could shake it."))
return false
@@ -599,7 +599,7 @@ end
def pbRockSmash
move = :ROCKSMASH
movefinder = pbCheckMove(move)
movefinder = $Trainer.get_pokemon_with_move(move)
if !pbCheckHiddenMoveBadge(BADGE_FOR_ROCKSMASH,false) || (!$DEBUG && !movefinder)
pbMessage(_INTL("It's a rugged rock, but a Pokémon may be able to smash it."))
return false
@@ -646,7 +646,7 @@ def pbStrength
return false
end
move = :STRENGTH
movefinder = pbCheckMove(move)
movefinder = $Trainer.get_pokemon_with_move(move)
if !pbCheckHiddenMoveBadge(BADGE_FOR_STRENGTH,false) || (!$DEBUG && !movefinder)
pbMessage(_INTL("It's a big boulder, but a Pokémon may be able to push it aside."))
return false
@@ -695,7 +695,7 @@ def pbSurf
return false if $game_player.pbFacingEvent
return false if $game_player.pbHasDependentEvents?
move = :SURF
movefinder = pbCheckMove(move)
movefinder = $Trainer.get_pokemon_with_move(move)
if !pbCheckHiddenMoveBadge(BADGE_FOR_SURF,false) || (!$DEBUG && !movefinder)
return false
end
@@ -947,7 +947,7 @@ end
def pbWaterfall
move = :WATERFALL
movefinder = pbCheckMove(move)
movefinder = $Trainer.get_pokemon_with_move(move)
if !pbCheckHiddenMoveBadge(BADGE_FOR_WATERFALL,false) || (!$DEBUG && !movefinder)
pbMessage(_INTL("A wall of water is crashing down with a mighty roar."))
return false