Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Results of battle:
- # 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
- ################################################################################
- ################################################################################
- # Main battle class.
- ################################################################################
- class PokeBattle_OnlineBattle < PokeBattle_Battle
- def pbSwitch(favorDraws=false)
- if !favorDraws
- return if @decision>0
- else
- return if @decision==5
- end
- pbJudge()
- return if @decision>0
- firstbattlerhp=@battlers[0].hp
- switched=[]
- for index in 0...4
- next if !@doublebattle && pbIsDoubleBattler?(index)
- next if @battlers[index] && !@battlers[index].isFainted?
- next if !pbCanChooseNonActive?(index)
- if @opponent
- newpoke=pbSwitchInBetween(index,true,false)
- newpokename=newpoke
- if isConst?(@party1[newpoke].ability,PBAbilities,:ILLUSION)
- newpokename=pbGetLastPokeInTeam(index)
- end
- pbRecallAndReplace(index,newpoke,newpokename)
- switched.push(index)
- else
- switch=false
- if !pbDisplayConfirm(_INTL("Use next Pokémon?"))
- switch=(pbRun(index,true)<=0)
- else
- switch=true
- end
- if switch
- newpoke=pbSwitchInBetween(index,true,false)
- newpokename=newpoke
- if isConst?(@party1[newpoke].ability,PBAbilities,:ILLUSION)
- newpokename=pbGetLastPokeInTeam(index)
- end
- pbRecallAndReplace(index,newpoke,newpokename)
- switched.push(index)
- end
- end
- end
- if switched.length>0
- priority=pbPriority
- for i in priority
- i.pbAbilitiesOnSwitchIn(true) if switched.include?(i.index)
- end
- end
- end
- ################################################################################
- # Gaining Experience.
- ################################################################################
- def pbGainEXP
- return if Options::ONLINEEXPGAIN == false
- super
- end
- def pbStartBattleCore(canlose)
- if !@fullparty1 && @party1.length>MAXPARTYSIZE
- raise ArgumentError.new(_INTL("Party 1 has more than {1} Pokémon.",MAXPARTYSIZE))
- end
- if !@fullparty2 && @party2.length>MAXPARTYSIZE
- raise ArgumentError.new(_INTL("Party 2 has more than {1} Pokémon.",MAXPARTYSIZE))
- end
- if !@opponent
- #========================
- # Initialize wild Pokémon
- #========================
- if @party2.length==1
- if @doublebattle
- raise _INTL("Only two wild Pokémon are allowed in double battles")
- end
- wildpoke=@party2[0]
- @battlers[1].pbInitialize(wildpoke,0,false)
- @peer.pbOnEnteringBattle(self,wildpoke)
- pbSetSeen(wildpoke)
- @scene.pbStartBattle(self)
- pbDisplayPaused(_INTL("Wild {1} appeared!",wildpoke.name))
- elsif @party2.length==2
- if !@doublebattle
- raise _INTL("Only one wild Pokémon is allowed in single battles")
- end
- @battlers[1].pbInitialize(@party2[0],0,false)
- @battlers[3].pbInitialize(@party2[1],0,false)
- @peer.pbOnEnteringBattle(self,@party2[0])
- @peer.pbOnEnteringBattle(self,@party2[1])
- pbSetSeen(@party2[0])
- pbSetSeen(@party2[1])
- @scene.pbStartBattle(self)
- pbDisplayPaused(_INTL("Wild {1} and\r\n{2} appeared!",
- @party2[0].name,@party2[1].name))
- else
- raise _INTL("Only one or two wild Pokémon are allowed")
- end
- elsif @doublebattle
- #=======================================
- # Initialize opponents in double battles
- #=======================================
- if @opponent.is_a?(Array)
- if @opponent.length==1
- @opponent=@opponent[0]
- elsif @opponent.length!=2
- raise _INTL("Opponents with zero or more than two people are not allowed")
- end
- end
- if @player.is_a?(Array)
- if @player.length==1
- @player=@player[0]
- elsif @player.length!=2
- raise _INTL("Player trainers with zero or more than two people are not allowed")
- end
- end
- @scene.pbStartBattle(self)
- if @opponent.is_a?(Array)
- pbDisplayPaused(_INTL("{1} and {2} want to battle!",@opponent[0].fullname,@opponent[1].fullname))
- sendout1=pbFindNextUnfainted(@party2,0,pbSecondPartyBegin(1))
- raise _INTL("Opponent 1 has no unfainted Pokémon") if sendout1<0
- sendout2=pbFindNextUnfainted(@party2,pbSecondPartyBegin(1))
- raise _INTL("Opponent 2 has no unfainted Pokémon") if sendout2<0
- pbDisplayBrief(_INTL("{1} sent\r\nout {2}!",@opponent[0].fullname,@party2[sendout1].name))
- @battlers[1].pbInitialize(@party2[sendout1],sendout1,false)
- @battlers[3].pbInitialize(@party2[sendout2],sendout2,false)
- pbSendOut(1,@party2[sendout1])
- pbDisplayBrief(_INTL("{1} sent\r\nout {2}!",@opponent[1].fullname,@party2[sendout2].name))
- pbSendOut(3,@party2[sendout2])
- else
- pbDisplayPaused(_INTL("{1}\r\nwould like to battle!",@opponent.fullname))
- sendout1=pbFindNextUnfainted(@party2,0)
- sendout2=pbFindNextUnfainted(@party2,sendout1+1)
- if sendout1<0 || sendout2<0
- raise _INTL("Opponent doesn't have two unfainted Pokémon")
- end
- pbDisplayBrief(_INTL("{1} sent\r\nout {2} and {3}!",
- @opponent.fullname,@party2[sendout1].name,@party2[sendout2].name))
- @battlers[1].pbInitialize(@party2[sendout1],sendout1,false)
- @battlers[3].pbInitialize(@party2[sendout2],sendout2,false)
- pbSendOut(1,@party2[sendout1])
- pbSendOut(3,@party2[sendout2])
- end
- else
- #======================================
- # Initialize opponent in single battles
- #======================================
- sendout=pbFindNextUnfainted(@party2,0)
- raise _INTL("Trainer has no unfainted Pokémon") if sendout<0
- if @opponent.is_a?(Array)
- raise _INTL("Opponent trainer must be only one person in single battles") if @opponent.length!=1
- @opponent=@opponent[0]
- end
- if @player.is_a?(Array)
- raise _INTL("Player trainer must be only one person in single battles") if @player.length!=1
- @player=@player[0]
- end
- trainerpoke=@party2[0]
- @scene.pbStartBattle(self)
- pbDisplayPaused(_INTL("{1}\r\nwould like to battle!",@opponent.fullname))
- pbDisplayBrief(_INTL("{1} sent\r\nout {2}!",@opponent.fullname,trainerpoke.name))
- @battlers[1].pbInitialize(trainerpoke,sendout,false)
- pbSendOut(1,trainerpoke)
- end
- #=====================================
- # Initialize players in double battles
- #=====================================
- if @doublebattle
- if @player.is_a?(Array)
- sendout1=pbFindNextUnfainted(@party1,0,pbSecondPartyBegin(0))
- raise _INTL("Player 1 has no unfainted Pokémon") if sendout1<0
- sendout2=pbFindNextUnfainted(@party1,pbSecondPartyBegin(0))
- raise _INTL("Player 2 has no unfainted Pokémon") if sendout2<0
- pbDisplayBrief(_INTL("{1} sent\r\nout {2}! Go! {3}!",
- @player[1].fullname,@party1[sendout2].name,@party1[sendout1].name))
- pbSetSeen(@party1[sendout1])
- pbSetSeen(@party1[sendout2])
- else
- sendout1=pbFindNextUnfainted(@party1,0)
- sendout2=pbFindNextUnfainted(@party1,sendout1+1)
- if sendout1<0 || sendout2<0
- raise _INTL("Player doesn't have two unfainted Pokémon")
- end
- pbDisplayBrief(_INTL("Go! {1} and {2}!",@party1[sendout1].name,@party1[sendout2].name))
- end
- @battlers[0].pbInitialize(@party1[sendout1],sendout1,false)
- @battlers[2].pbInitialize(@party1[sendout2],sendout2,false)
- pbSendOut(0,@party1[sendout1])
- pbSendOut(2,@party1[sendout2])
- else
- #====================================
- # Initialize player in single battles
- #====================================
- sendout=pbFindNextUnfainted(@party1,0)
- if sendout<0
- raise _INTL("Player has no unfainted Pokémon")
- end
- playerpoke=@party1[sendout]
- pbDisplayBrief(_INTL("Go! {1}!",playerpoke.name))
- @battlers[0].pbInitialize(playerpoke,sendout,false)
- pbSendOut(0,playerpoke)
- end
- #==================
- # Initialize battle
- #==================
- if @weather==PBWeather::SUNNYDAY
- pbDisplay(_INTL("The sunlight is strong."))
- elsif @weather==PBWeather::RAINDANCE
- pbDisplay(_INTL("It is raining."))
- elsif @weather==PBWeather::SANDSTORM
- pbDisplay(_INTL("A sandstorm is raging."))
- elsif @weather==PBWeather::HAIL
- pbDisplay(_INTL("Hail is falling."))
- end
- pbOnActiveAll # Abilities
- @turncount=0
- loop do # Now begin the battle loop
- if @debug
- if @turncount>=100
- @decision=pbDecisionOnTime()
- PBDebug.log("***[Undecided after 100 rounds]")
- pbAbort
- break
- end
- PBDebug.log("***Round #{@turncount+1}")
- end
- PBDebug.logonerr{
- pbCommandPhase
- }
- batmove=@choices[0][2]
- if batmove.is_a?(PokeBattle_Move)
- @choices[0][2]=nil
- end
- choices = pbMysteryGiftEncrypt(@choices[0]).delete("\n")
- $network.send("<BAT choices=#{choices}>")
- @choices[0][2]=batmove
- loop do
- Graphics.update
- Input.update
- message = $network.listen
- case message
- when /<BAT choices=(.*)>/
- @choices[1] = pbMysteryGiftDecrypt($1)
- @choices[1][2]=@battlers[1].moves[@choices[1][1]] if @choices[1][0]==1
- break
- when /<BAT dead>/
- @decision = 1
- Kernel.pbMessage("Other player disconnected.")
- return pbEndOfBattle
- end
- end
- receive_seed
- break if @decision>0
- PBDebug.logonerr{
- pbAttackPhase
- }
- break if @decision>0
- PBDebug.logonerr{
- pbEndOfRoundPhase
- }
- break if @decision>0
- @turncount+=1
- end
- return pbEndOfBattle(canlose)
- end
- ################################################################################
- # End of battle.
- ################################################################################
- def pbEndOfBattle(canlose=false)
- case @decision
- ##### WIN #####
- when 1
- PBDebug.log("")
- PBDebug.log("***Player won***")
- if @opponent
- @scene.pbTrainerBattleSuccess
- if @opponent.is_a?(Array)
- pbDisplayPaused(_INTL("{1} defeated {2} and {3}!",self.pbPlayer.name,@opponent[0].fullname,@opponent[1].fullname))
- else
- pbDisplayPaused(_INTL("{1} defeated\r\n{2}!",self.pbPlayer.name,@opponent.fullname))
- end
- @scene.pbShowOpponent(0)
- pbDisplayPaused(@endspeech.gsub(/\\[Pp][Nn]/,self.pbPlayer.name))
- if @opponent.is_a?(Array)
- @scene.pbHideOpponent
- @scene.pbShowOpponent(1)
- pbDisplayPaused(@endspeech2.gsub(/\\[Pp][Nn]/,self.pbPlayer.name))
- end
- # Calculate money gained for winning
- if @internalbattle
- tmoney=0
- if @opponent.is_a?(Array) # Double battles
- maxlevel1=0; maxlevel2=0; limit=pbSecondPartyBegin(1)
- for i in 0...limit
- if @party2[i]
- maxlevel1=@party2[i].level if maxlevel1<@party2[i].level
- end
- if @party2[i+limit]
- maxlevel2=@party2[i+limit].level if maxlevel1<@party2[i+limit].level
- end
- end
- tmoney+=maxlevel1*@opponent[0].moneyEarned
- tmoney+=maxlevel2*@opponent[1].moneyEarned
- else
- maxlevel=0
- for i in @party2
- next if !i
- maxlevel=i.level if maxlevel<i.level
- end
- tmoney+=maxlevel*@opponent.moneyEarned
- end
- # If Amulet Coin/Luck Incense's effect applies, double money earned
- tmoney*=2 if @amuletcoin
- # If Happy Hour's effect applies, double money earned
- tmoney*=2 if @doublemoney
- oldmoney=self.pbPlayer.money
- self.pbPlayer.money+=tmoney
- moneygained=self.pbPlayer.money-oldmoney
- if moneygained>0
- pbDisplayPaused(_INTL("{1} got ${2}\r\nfor winning!",self.pbPlayer.name,tmoney))
- end
- end
- end
- if @internalbattle && @extramoney>0
- @extramoney*=2 if @amuletcoin
- @extramoney*=2 if @doublemoney
- oldmoney=self.pbPlayer.money
- self.pbPlayer.money+=@extramoney
- moneygained=self.pbPlayer.money-oldmoney
- if moneygained>0
- pbDisplayPaused(_INTL("{1} picked up ${2}!",self.pbPlayer.name,@extramoney))
- end
- end
- for pkmn in @snaggedpokemon
- pbStorePokemon(pkmn)
- self.pbPlayer.shadowcaught=[] if !self.pbPlayer.shadowcaught
- self.pbPlayer.shadowcaught[pkmn.species]=true
- end
- @snaggedpokemon.clear
- ##### LOSE, DRAW #####
- when 2, 5
- PBDebug.log("")
- PBDebug.log("***Player lost***") if @decision==2
- PBDebug.log("***Player drew with opponent***") if @decision==5
- if @internalbattle
- pbDisplayPaused(_INTL("{1} is out of usable Pokémon!",self.pbPlayer.name))
- moneylost=pbMaxLevelFromIndex(0) # Player's Pokémon only, not partner's
- multiplier=[8,16,24,36,48,60,80,100,120]
- moneylost*=multiplier[[multiplier.length-1,self.pbPlayer.numbadges].min]
- moneylost=self.pbPlayer.money if moneylost>self.pbPlayer.money
- moneylost=0 if $game_switches[NO_MONEY_LOSS]
- oldmoney=self.pbPlayer.money
- self.pbPlayer.money-=moneylost
- lostmoney=oldmoney-self.pbPlayer.money
- if @opponent
- if @opponent.is_a?(Array)
- pbDisplayPaused(_INTL("{1} lost against {2} and {3}!",self.pbPlayer.name,@opponent[0].fullname,@opponent[1].fullname))
- else
- pbDisplayPaused(_INTL("{1} lost against\r\n{2}!",self.pbPlayer.name,@opponent.fullname))
- end
- if moneylost>0
- pbDisplayPaused(_INTL("{1} paid ${2}\r\nas the prize money...",self.pbPlayer.name,lostmoney))
- pbDisplayPaused(_INTL("...")) if !canlose
- end
- else
- if moneylost>0
- pbDisplayPaused(_INTL("{1} panicked and lost\r\n${2}...",self.pbPlayer.name,lostmoney))
- pbDisplayPaused(_INTL("...")) if !canlose
- end
- end
- pbDisplayPaused(_INTL("{1} blacked out!",self.pbPlayer.name)) if !canlose
- elsif @decision==2
- @scene.pbShowOpponent(0)
- pbDisplayPaused(@endspeechwin.gsub(/\\[Pp][Nn]/,self.pbPlayer.name))
- if @opponent.is_a?(Array)
- @scene.pbHideOpponent
- @scene.pbShowOpponent(1)
- pbDisplayPaused(@endspeechwin2.gsub(/\\[Pp][Nn]/,self.pbPlayer.name))
- end
- end
- end
- #### PICK UP POKEBALLS ####
- if @decision == 1 || 4
- pbrs = [] #pokeball retrieval service
- # This array has a pattern. POKEBALLTYPE, Number, POKEBALLTYPE, NUMBER
- if $PokemonGlobal.ballsused[0] != nil #don't use unless there are pokeballs to regain
- pokeballs=$PokemonGlobal.ballsused
- pokeballs.each do |ball| # This part repeats for each pokeball
- chance=25
- rnd=rand(100)
- if rnd<chance
- unless pbrs.include?(ball) #unless the array already has the ball
- pbrs.push(ball)
- pbrs.push(1)
- else
- temp = pbrs.index(ball) #finds where in the array the pokeball type is
- pbrs[temp+1] +=1 #adds another ball to the number
- end
- end
- end
- while pbrs[0] != nil #While there are still pokeballs left to retreive
- balltype = pbrs.shift#destructively removes the first element (in this case, the pokeball name)
- #pbDisplayPaused(_INTL("{1}!",balltype))
- ballnumber = pbrs.shift #remember each even numbered item in the array is the pokeball number
- #pbDisplayPaused(_INTL("{1}!",ballnumber))
- $PokemonBag.pbStoreItem(balltype,ballnumber)
- if ballnumber>1
- pbDisplayPaused(_INTL("{1} picked up {2} {3} thrown during the battle.", $Trainer.name, ballnumber, PBItems.getNamePlural(balltype)))
- else
- pbDisplayPaused(_INTL("{1} picked up one {2} thrown during the battle.", $Trainer.name, PBItems.getName(balltype)))
- end
- end
- end
- end
- $PokemonGlobal.ballsused=[] #to reset the array after the battle
- # Pass on Pokérus within the party
- infected=[]
- for i in 0...$Trainer.party.length
- if $Trainer.party[i].pokerusStage==1
- infected.push(i)
- end
- end
- if infected.length>=1
- for i in infected
- strain=$Trainer.party[i].pokerus/16
- if i>0 && $Trainer.party[i-1].pokerusStage==0
- $Trainer.party[i-1].givePokerus(strain) if rand(3)==0
- end
- if i<$Trainer.party.length-1 && $Trainer.party[i+1].pokerusStage==0
- $Trainer.party[i+1].givePokerus(strain) if rand(3)==0
- end
- end
- end
- @scene.pbEndBattle(@decision)
- for i in @battlers
- i.pbResetForm
- if i.hasWorkingAbility(:NATURALCURE)
- i.status=0
- end
- end
- for i in $Trainer.party
- i.setItem(i.itemInitial)
- i.itemInitial=i.itemRecycle=0
- i.belch=false
- end
- return @decision
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement