def pbCommandPhase
@scene.pbBeginCommandPhase
# @scene.pbResetCommandIndices
for i in 0...4 # Reset choices if commands can be shown
@battlers[i].effects[PBEffects::SkipTurn]=false
if pbCanShowCommands?(i) || @battlers[i].fainted?
@choices[i][0]=0
@choices[i][1]=0
@choices[i][2]=nil
@choices[i][3]=-1
else
unless !@doublebattle && pbIsDoubleBattler?(i)
PBDebug.log("[Reusing commands] #{@battlers[i].pbThis(true)}")
end
end
end
# Reset choices to perform Mega Evolution if it wasn't done somehow
if !$forceMegaEvo
for i in 0...2
for j in 0...@megaEvolution[i].length
@megaEvolution[i][j]=-1 if @megaEvolution[i][j]>=0
end
end
end
for i in 0...@zMove[0].length
@zMove[0][i]=-1 if @zMove[0][i]>=0
end
for i in 0...@zMove[1].length
@zMove[1][i]=-1 if @zMove[1][i]>=0
end
for i in 0...4
break if @decision!=0
next if @choices[i][0]!=0
if !pbOwnedByPlayer?(i) || @controlPlayer
if !@battlers[i].isFainted? && pbCanShowCommands?(i)
@scene.pbChooseEnemyCommand(i) if !@forceSwitching && !@skipturn
pbEnemyShouldWithdrawEx?(i,true) if @forceSwitching
end
else
commandDone=false
commandEnd=false
if pbCanShowCommands?(i)
loop do
cmd=pbCommandMenu(i)
if cmd==0 # Fight
if pbCanShowFightMenu?(i)
commandDone=true if pbAutoFightMenu(i)
until commandDone
index=@scene.pbFightMenu(i)
if index<0
side=(pbIsOpposing?(i)) ? 1 : 0
owner=pbGetOwnerIndex(i)
if @megaEvolution[side][owner]==i
@megaEvolution[side][owner]=-1
end
if @zMove[side][owner]==i
@zMove[side][owner]=-1
end
break
end
next if !pbRegisterMove(i,index)
if @doublebattle
thismove=@battlers[i].moves[index]
target=@battlers[i].pbTarget(thismove)
if target==PBTargets::SingleNonUser # single non-user
target=@scene.pbChooseTarget(i,target)
next if target<0
pbRegisterTarget(i,target)
elsif target==PBTargets::UserOrPartner # Acupressure
target=@scene.pbChooseTarget(i,target)
next if target<0 || (target&1)==1
pbRegisterTarget(i,target)
end
end
commandDone=true
end
else
pbAutoChooseMove(i)
commandDone=true
end
elsif cmd!=0 && @battlers[i].effects[PBEffects::SkyDrop]
pbDisplay(_INTL("Sky Drop won't let {1} go!",@battlers[i].pbThis(true)))
elsif cmd==1 # Bag
if !@internalbattle
if pbOwnedByPlayer?(i)
pbDisplay(_INTL("Items can't be used here."))
end
else
item=pbItemMenu(i)
if item[0]>0
if pbRegisterItem(i,item[0],item[1])
commandDone=true
end
end
end
elsif cmd==2 # Pokémon
pkmn=pbSwitchPlayer(i,false,true)
if pkmn>=0
commandDone=true if pbRegisterSwitch(i,pkmn)
end
elsif cmd==3 # Run
run=pbRun(i)
if run>0
commandDone=true
return
elsif run<0
commandDone=true
side=(pbIsOpposing?(i)) ? 1 : 0
owner=pbGetOwnerIndex(i)
if @megaEvolution[side][owner]==i
@megaEvolution[side][owner]=-1
end
if @zMove[side][owner]==i
@zMove[side][owner]=-1
end
end
elsif cmd==4 # Call
thispkmn=@battlers[i]
@choices[i][0]=4 # "Call Pokémon"
@choices[i][1]=0
@choices[i][2]=nil
side=(pbIsOpposing?(i)) ? 1 : 0
owner=pbGetOwnerIndex(i)
if @megaEvolution[side][owner]==i
@megaEvolution[side][owner]=-1
end
if @zMove[side][owner]==i
@zMove[side][owner]=-1
end
commandDone=true
elsif cmd==5 # Debug
pbBattlerDebug
commandDone=true if (@battlers[i].effects[PBEffects::SkipTurn])
elsif cmd==-1 # Go back to first battler's choice
@megaEvolution[0][0]=-1 if @megaEvolution[0][0]>=0
@megaEvolution[1][0]=-1 if @megaEvolution[1][0]>=0
@zMove[0][0]=-1 if @zMove[0][0]>=0
@zMove[1][0]=-1 if @zMove[1][0]>=0
# Restore the item the player's first Pokémon was due to use
if @choices[0][0]==3 && $PokemonBag && $PokemonBag.pbCanStore?(@choices[0][1])
$PokemonBag.pbStoreItem(@choices[0][1])
end
pbCommandPhase
return
end
break if commandDone
end
end
end
end
end