Vendily

Online changes

Nov 15th, 2018
234
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Results of battle:
  2. #    0 - Undecided or aborted
  3. #    1 - Player won
  4. #    2 - Player lost
  5. #    3 - Player or wild Pokémon ran from battle, or player forfeited the match
  6. #    4 - Wild Pokémon was caught
  7. #    5 - Draw
  8. ################################################################################
  9. ################################################################################
  10. # Main battle class.
  11. ################################################################################
  12. class PokeBattle_OnlineBattle < PokeBattle_Battle
  13.  
  14.   def pbSwitch(favorDraws=false)
  15.     if !favorDraws
  16.       return if @decision>0
  17.     else
  18.       return if @decision==5
  19.     end
  20.     pbJudge()
  21.     return if @decision>0
  22.     firstbattlerhp=@battlers[0].hp
  23.     switched=[]
  24.     for index in 0...4
  25.       next if !@doublebattle && pbIsDoubleBattler?(index)
  26.       next if @battlers[index] && !@battlers[index].isFainted?
  27.       next if !pbCanChooseNonActive?(index)
  28.       if @opponent
  29.         newpoke=pbSwitchInBetween(index,true,false)
  30.         newpokename=newpoke
  31.         if isConst?(@party1[newpoke].ability,PBAbilities,:ILLUSION)
  32.           newpokename=pbGetLastPokeInTeam(index)
  33.         end
  34.         pbRecallAndReplace(index,newpoke,newpokename)
  35.         switched.push(index)
  36.       else
  37.         switch=false
  38.         if !pbDisplayConfirm(_INTL("Use next Pokémon?"))
  39.           switch=(pbRun(index,true)<=0)
  40.         else
  41.           switch=true
  42.         end
  43.         if switch
  44.           newpoke=pbSwitchInBetween(index,true,false)
  45.           newpokename=newpoke
  46.           if isConst?(@party1[newpoke].ability,PBAbilities,:ILLUSION)
  47.             newpokename=pbGetLastPokeInTeam(index)
  48.           end
  49.           pbRecallAndReplace(index,newpoke,newpokename)
  50.           switched.push(index)
  51.         end
  52.       end
  53.     end
  54.     if switched.length>0
  55.       priority=pbPriority
  56.       for i in priority
  57.         i.pbAbilitiesOnSwitchIn(true) if switched.include?(i.index)
  58.       end
  59.     end
  60.   end
  61.  
  62. ################################################################################
  63. # Gaining Experience.
  64. ################################################################################
  65.   def pbGainEXP
  66.     return if Options::ONLINEEXPGAIN == false
  67.     super
  68.   end
  69.  
  70.   def pbStartBattleCore(canlose)
  71.     if !@fullparty1 && @party1.length>MAXPARTYSIZE
  72.       raise ArgumentError.new(_INTL("Party 1 has more than {1} Pokémon.",MAXPARTYSIZE))
  73.     end
  74.     if !@fullparty2 && @party2.length>MAXPARTYSIZE
  75.       raise ArgumentError.new(_INTL("Party 2 has more than {1} Pokémon.",MAXPARTYSIZE))
  76.     end
  77.     if !@opponent
  78. #========================
  79. # Initialize wild Pokémon
  80. #========================
  81.       if @party2.length==1
  82.         if @doublebattle
  83.           raise _INTL("Only two wild Pokémon are allowed in double battles")
  84.         end
  85.         wildpoke=@party2[0]
  86.         @battlers[1].pbInitialize(wildpoke,0,false)
  87.         @peer.pbOnEnteringBattle(self,wildpoke)
  88.         pbSetSeen(wildpoke)
  89.         @scene.pbStartBattle(self)
  90.         pbDisplayPaused(_INTL("Wild {1} appeared!",wildpoke.name))
  91.       elsif @party2.length==2
  92.         if !@doublebattle
  93.           raise _INTL("Only one wild Pokémon is allowed in single battles")
  94.         end
  95.         @battlers[1].pbInitialize(@party2[0],0,false)
  96.         @battlers[3].pbInitialize(@party2[1],0,false)
  97.         @peer.pbOnEnteringBattle(self,@party2[0])
  98.         @peer.pbOnEnteringBattle(self,@party2[1])
  99.         pbSetSeen(@party2[0])
  100.         pbSetSeen(@party2[1])
  101.         @scene.pbStartBattle(self)
  102.         pbDisplayPaused(_INTL("Wild {1} and\r\n{2} appeared!",
  103.            @party2[0].name,@party2[1].name))
  104.       else
  105.         raise _INTL("Only one or two wild Pokémon are allowed")
  106.       end
  107.     elsif @doublebattle
  108. #=======================================
  109. # Initialize opponents in double battles
  110. #=======================================
  111.       if @opponent.is_a?(Array)
  112.         if @opponent.length==1
  113.           @opponent=@opponent[0]
  114.         elsif @opponent.length!=2
  115.           raise _INTL("Opponents with zero or more than two people are not allowed")
  116.         end
  117.       end
  118.       if @player.is_a?(Array)
  119.         if @player.length==1
  120.           @player=@player[0]
  121.         elsif @player.length!=2
  122.           raise _INTL("Player trainers with zero or more than two people are not allowed")
  123.         end
  124.       end
  125.       @scene.pbStartBattle(self)
  126.       if @opponent.is_a?(Array)
  127.         pbDisplayPaused(_INTL("{1} and {2} want to battle!",@opponent[0].fullname,@opponent[1].fullname))
  128.         sendout1=pbFindNextUnfainted(@party2,0,pbSecondPartyBegin(1))
  129.         raise _INTL("Opponent 1 has no unfainted Pokémon") if sendout1<0
  130.         sendout2=pbFindNextUnfainted(@party2,pbSecondPartyBegin(1))
  131.         raise _INTL("Opponent 2 has no unfainted Pokémon") if sendout2<0
  132.         pbDisplayBrief(_INTL("{1} sent\r\nout {2}!",@opponent[0].fullname,@party2[sendout1].name))
  133.         @battlers[1].pbInitialize(@party2[sendout1],sendout1,false)
  134.         @battlers[3].pbInitialize(@party2[sendout2],sendout2,false)
  135.         pbSendOut(1,@party2[sendout1])
  136.         pbDisplayBrief(_INTL("{1} sent\r\nout {2}!",@opponent[1].fullname,@party2[sendout2].name))
  137.         pbSendOut(3,@party2[sendout2])
  138.       else
  139.         pbDisplayPaused(_INTL("{1}\r\nwould like to battle!",@opponent.fullname))
  140.         sendout1=pbFindNextUnfainted(@party2,0)
  141.         sendout2=pbFindNextUnfainted(@party2,sendout1+1)
  142.         if sendout1<0 || sendout2<0
  143.           raise _INTL("Opponent doesn't have two unfainted Pokémon")
  144.         end
  145.         pbDisplayBrief(_INTL("{1} sent\r\nout {2} and {3}!",
  146.            @opponent.fullname,@party2[sendout1].name,@party2[sendout2].name))
  147.         @battlers[1].pbInitialize(@party2[sendout1],sendout1,false)
  148.         @battlers[3].pbInitialize(@party2[sendout2],sendout2,false)
  149.         pbSendOut(1,@party2[sendout1])
  150.         pbSendOut(3,@party2[sendout2])
  151.       end
  152.     else
  153. #======================================
  154. # Initialize opponent in single battles
  155. #======================================
  156.       sendout=pbFindNextUnfainted(@party2,0)
  157.       raise _INTL("Trainer has no unfainted Pokémon") if sendout<0
  158.       if @opponent.is_a?(Array)
  159.         raise _INTL("Opponent trainer must be only one person in single battles") if @opponent.length!=1
  160.         @opponent=@opponent[0]
  161.       end
  162.       if @player.is_a?(Array)
  163.         raise _INTL("Player trainer must be only one person in single battles") if @player.length!=1
  164.         @player=@player[0]
  165.       end
  166.       trainerpoke=@party2[0]
  167.       @scene.pbStartBattle(self)
  168.       pbDisplayPaused(_INTL("{1}\r\nwould like to battle!",@opponent.fullname))
  169.       pbDisplayBrief(_INTL("{1} sent\r\nout {2}!",@opponent.fullname,trainerpoke.name))
  170.       @battlers[1].pbInitialize(trainerpoke,sendout,false)
  171.       pbSendOut(1,trainerpoke)
  172.     end
  173. #=====================================
  174. # Initialize players in double battles
  175. #=====================================
  176.     if @doublebattle
  177.       if @player.is_a?(Array)
  178.         sendout1=pbFindNextUnfainted(@party1,0,pbSecondPartyBegin(0))
  179.         raise _INTL("Player 1 has no unfainted Pokémon") if sendout1<0
  180.         sendout2=pbFindNextUnfainted(@party1,pbSecondPartyBegin(0))
  181.         raise _INTL("Player 2 has no unfainted Pokémon") if sendout2<0
  182.         pbDisplayBrief(_INTL("{1} sent\r\nout {2}!  Go! {3}!",
  183.            @player[1].fullname,@party1[sendout2].name,@party1[sendout1].name))
  184.         pbSetSeen(@party1[sendout1])
  185.         pbSetSeen(@party1[sendout2])
  186.       else
  187.         sendout1=pbFindNextUnfainted(@party1,0)
  188.         sendout2=pbFindNextUnfainted(@party1,sendout1+1)
  189.         if sendout1<0 || sendout2<0
  190.           raise _INTL("Player doesn't have two unfainted Pokémon")
  191.         end
  192.         pbDisplayBrief(_INTL("Go! {1} and {2}!",@party1[sendout1].name,@party1[sendout2].name))
  193.       end
  194.       @battlers[0].pbInitialize(@party1[sendout1],sendout1,false)
  195.       @battlers[2].pbInitialize(@party1[sendout2],sendout2,false)
  196.       pbSendOut(0,@party1[sendout1])
  197.       pbSendOut(2,@party1[sendout2])
  198.     else
  199. #====================================
  200. # Initialize player in single battles
  201. #====================================
  202.       sendout=pbFindNextUnfainted(@party1,0)
  203.       if sendout<0
  204.         raise _INTL("Player has no unfainted Pokémon")
  205.       end
  206.       playerpoke=@party1[sendout]
  207.       pbDisplayBrief(_INTL("Go! {1}!",playerpoke.name))
  208.       @battlers[0].pbInitialize(playerpoke,sendout,false)
  209.       pbSendOut(0,playerpoke)
  210.     end
  211. #==================
  212. # Initialize battle
  213. #==================
  214.     if @weather==PBWeather::SUNNYDAY
  215.       pbDisplay(_INTL("The sunlight is strong."))
  216.     elsif @weather==PBWeather::RAINDANCE
  217.       pbDisplay(_INTL("It is raining."))
  218.     elsif @weather==PBWeather::SANDSTORM
  219.       pbDisplay(_INTL("A sandstorm is raging."))
  220.     elsif @weather==PBWeather::HAIL
  221.       pbDisplay(_INTL("Hail is falling."))
  222.     end
  223.     pbOnActiveAll   # Abilities
  224.     @turncount=0
  225.     loop do   # Now begin the battle loop
  226.       if @debug
  227.         if @turncount>=100
  228.           @decision=pbDecisionOnTime()
  229.           PBDebug.log("***[Undecided after 100 rounds]")
  230.           pbAbort
  231.           break
  232.         end
  233.         PBDebug.log("***Round #{@turncount+1}")
  234.       end
  235.       PBDebug.logonerr{
  236.          pbCommandPhase
  237.       }
  238.       batmove=@choices[0][2]
  239.       if batmove.is_a?(PokeBattle_Move)
  240.         @choices[0][2]=nil
  241.       end
  242.       choices = pbMysteryGiftEncrypt(@choices[0]).delete("\n")
  243.       $network.send("<BAT choices=#{choices}>")
  244.       @choices[0][2]=batmove
  245.       loop do
  246.         Graphics.update
  247.         Input.update
  248.         message = $network.listen
  249.         case message
  250.           when /<BAT choices=(.*)>/
  251.             @choices[1] = pbMysteryGiftDecrypt($1)
  252.             @choices[1][2]=@battlers[1].moves[@choices[1][1]] if @choices[1][0]==1
  253.             break
  254.           when /<BAT dead>/
  255.             @decision = 1
  256.             Kernel.pbMessage("Other player disconnected.")
  257.             return pbEndOfBattle
  258.         end
  259.       end
  260.       receive_seed  
  261.       break if @decision>0
  262.       PBDebug.logonerr{
  263.          pbAttackPhase
  264.       }
  265.       break if @decision>0
  266.       PBDebug.logonerr{
  267.          pbEndOfRoundPhase
  268.       }
  269.       break if @decision>0
  270.       @turncount+=1
  271.     end
  272.     return pbEndOfBattle(canlose)
  273.   end
  274. ################################################################################
  275. # End of battle.
  276. ################################################################################
  277.   def pbEndOfBattle(canlose=false)
  278.     case @decision
  279.     ##### WIN #####
  280.     when 1
  281.       PBDebug.log("")
  282.       PBDebug.log("***Player won***")
  283.       if @opponent
  284.         @scene.pbTrainerBattleSuccess
  285.         if @opponent.is_a?(Array)
  286.           pbDisplayPaused(_INTL("{1} defeated {2} and {3}!",self.pbPlayer.name,@opponent[0].fullname,@opponent[1].fullname))
  287.         else
  288.           pbDisplayPaused(_INTL("{1} defeated\r\n{2}!",self.pbPlayer.name,@opponent.fullname))
  289.         end
  290.         @scene.pbShowOpponent(0)
  291.         pbDisplayPaused(@endspeech.gsub(/\\[Pp][Nn]/,self.pbPlayer.name))
  292.         if @opponent.is_a?(Array)
  293.           @scene.pbHideOpponent
  294.           @scene.pbShowOpponent(1)
  295.           pbDisplayPaused(@endspeech2.gsub(/\\[Pp][Nn]/,self.pbPlayer.name))
  296.         end
  297.         # Calculate money gained for winning
  298.         if @internalbattle
  299.           tmoney=0
  300.           if @opponent.is_a?(Array)   # Double battles
  301.             maxlevel1=0; maxlevel2=0; limit=pbSecondPartyBegin(1)
  302.             for i in 0...limit
  303.               if @party2[i]
  304.                 maxlevel1=@party2[i].level if maxlevel1<@party2[i].level
  305.               end
  306.               if @party2[i+limit]
  307.                 maxlevel2=@party2[i+limit].level if maxlevel1<@party2[i+limit].level
  308.               end
  309.             end
  310.             tmoney+=maxlevel1*@opponent[0].moneyEarned
  311.             tmoney+=maxlevel2*@opponent[1].moneyEarned
  312.           else
  313.             maxlevel=0
  314.             for i in @party2
  315.               next if !i
  316.               maxlevel=i.level if maxlevel<i.level
  317.             end
  318.             tmoney+=maxlevel*@opponent.moneyEarned
  319.           end
  320.           # If Amulet Coin/Luck Incense's effect applies, double money earned
  321.           tmoney*=2 if @amuletcoin
  322.           # If Happy Hour's effect applies, double money earned
  323.           tmoney*=2 if @doublemoney
  324.           oldmoney=self.pbPlayer.money
  325.           self.pbPlayer.money+=tmoney
  326.           moneygained=self.pbPlayer.money-oldmoney
  327.           if moneygained>0
  328.             pbDisplayPaused(_INTL("{1} got ${2}\r\nfor winning!",self.pbPlayer.name,tmoney))
  329.           end
  330.         end
  331.       end
  332.       if @internalbattle && @extramoney>0
  333.         @extramoney*=2 if @amuletcoin
  334.         @extramoney*=2 if @doublemoney
  335.         oldmoney=self.pbPlayer.money
  336.         self.pbPlayer.money+=@extramoney
  337.         moneygained=self.pbPlayer.money-oldmoney
  338.         if moneygained>0
  339.           pbDisplayPaused(_INTL("{1} picked up ${2}!",self.pbPlayer.name,@extramoney))
  340.         end
  341.       end
  342.       for pkmn in @snaggedpokemon
  343.         pbStorePokemon(pkmn)
  344.         self.pbPlayer.shadowcaught=[] if !self.pbPlayer.shadowcaught
  345.         self.pbPlayer.shadowcaught[pkmn.species]=true
  346.       end
  347.       @snaggedpokemon.clear
  348.     ##### LOSE, DRAW #####
  349.     when 2, 5
  350.       PBDebug.log("")
  351.       PBDebug.log("***Player lost***") if @decision==2
  352.       PBDebug.log("***Player drew with opponent***") if @decision==5
  353.       if @internalbattle
  354.         pbDisplayPaused(_INTL("{1} is out of usable Pokémon!",self.pbPlayer.name))
  355.         moneylost=pbMaxLevelFromIndex(0)   # Player's Pokémon only, not partner's
  356.         multiplier=[8,16,24,36,48,60,80,100,120]
  357.         moneylost*=multiplier[[multiplier.length-1,self.pbPlayer.numbadges].min]
  358.         moneylost=self.pbPlayer.money if moneylost>self.pbPlayer.money
  359.         moneylost=0 if $game_switches[NO_MONEY_LOSS]
  360.         oldmoney=self.pbPlayer.money
  361.         self.pbPlayer.money-=moneylost
  362.         lostmoney=oldmoney-self.pbPlayer.money
  363.         if @opponent
  364.           if @opponent.is_a?(Array)
  365.             pbDisplayPaused(_INTL("{1} lost against {2} and {3}!",self.pbPlayer.name,@opponent[0].fullname,@opponent[1].fullname))
  366.           else
  367.             pbDisplayPaused(_INTL("{1} lost against\r\n{2}!",self.pbPlayer.name,@opponent.fullname))
  368.           end
  369.           if moneylost>0
  370.             pbDisplayPaused(_INTL("{1} paid ${2}\r\nas the prize money...",self.pbPlayer.name,lostmoney))  
  371.             pbDisplayPaused(_INTL("...")) if !canlose
  372.           end
  373.         else
  374.           if moneylost>0
  375.             pbDisplayPaused(_INTL("{1} panicked and lost\r\n${2}...",self.pbPlayer.name,lostmoney))
  376.             pbDisplayPaused(_INTL("...")) if !canlose
  377.           end
  378.         end
  379.         pbDisplayPaused(_INTL("{1} blacked out!",self.pbPlayer.name)) if !canlose
  380.       elsif @decision==2
  381.         @scene.pbShowOpponent(0)
  382.         pbDisplayPaused(@endspeechwin.gsub(/\\[Pp][Nn]/,self.pbPlayer.name))
  383.         if @opponent.is_a?(Array)
  384.           @scene.pbHideOpponent
  385.           @scene.pbShowOpponent(1)
  386.           pbDisplayPaused(@endspeechwin2.gsub(/\\[Pp][Nn]/,self.pbPlayer.name))
  387.         end
  388.       end
  389.     end
  390.      
  391.     #### PICK UP POKEBALLS ####
  392.       if @decision == 1 || 4
  393.         pbrs = [] #pokeball retrieval service
  394.                   # This array has a pattern. POKEBALLTYPE, Number, POKEBALLTYPE, NUMBER
  395.         if $PokemonGlobal.ballsused[0] != nil #don't use unless there are pokeballs to regain          
  396.           pokeballs=$PokemonGlobal.ballsused
  397.           pokeballs.each do |ball| # This part repeats for each pokeball
  398.             chance=25
  399.             rnd=rand(100)
  400.               if rnd<chance
  401.                 unless pbrs.include?(ball) #unless the array already has the ball
  402.                   pbrs.push(ball)
  403.                   pbrs.push(1)  
  404.                 else
  405.                   temp = pbrs.index(ball) #finds where in the array the pokeball type is
  406.                   pbrs[temp+1] +=1 #adds another ball to the number
  407.                 end
  408.               end
  409.             end
  410.           while pbrs[0] != nil #While there are still pokeballs left to retreive
  411.             balltype = pbrs.shift#destructively removes the first element (in this case, the pokeball name)
  412.             #pbDisplayPaused(_INTL("{1}!",balltype))
  413.             ballnumber = pbrs.shift #remember each even numbered item in the array is the pokeball number
  414.             #pbDisplayPaused(_INTL("{1}!",ballnumber))            
  415.             $PokemonBag.pbStoreItem(balltype,ballnumber)
  416.             if ballnumber>1
  417.               pbDisplayPaused(_INTL("{1} picked up {2} {3} thrown during the battle.", $Trainer.name, ballnumber, PBItems.getNamePlural(balltype)))
  418.             else
  419.               pbDisplayPaused(_INTL("{1} picked up one {2} thrown during the battle.", $Trainer.name, PBItems.getName(balltype)))
  420.             end
  421.           end
  422.         end
  423.     end
  424.     $PokemonGlobal.ballsused=[] #to reset the array after the battle
  425.    
  426.     # Pass on Pokérus within the party
  427.     infected=[]
  428.     for i in 0...$Trainer.party.length
  429.       if $Trainer.party[i].pokerusStage==1
  430.         infected.push(i)
  431.       end
  432.     end
  433.     if infected.length>=1
  434.       for i in infected
  435.         strain=$Trainer.party[i].pokerus/16
  436.         if i>0 && $Trainer.party[i-1].pokerusStage==0
  437.           $Trainer.party[i-1].givePokerus(strain) if rand(3)==0
  438.         end
  439.         if i<$Trainer.party.length-1 && $Trainer.party[i+1].pokerusStage==0
  440.           $Trainer.party[i+1].givePokerus(strain) if rand(3)==0
  441.         end
  442.       end
  443.     end
  444.     @scene.pbEndBattle(@decision)
  445.     for i in @battlers
  446.       i.pbResetForm
  447.       if i.hasWorkingAbility(:NATURALCURE)
  448.         i.status=0
  449.       end
  450.     end
  451.     for i in $Trainer.party
  452.       i.setItem(i.itemInitial)
  453.       i.itemInitial=i.itemRecycle=0
  454.       i.belch=false
  455.     end
  456.     return @decision
  457.   end
  458. end
RAW Paste Data