Advertisement
pokeminer20

Essentials V17 Party Plus

Dec 17th, 2019
995
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 162.99 KB | None | 0 0
  1. #==============================================================================#
  2. #                                  Party Plus                                  #
  3. #                                by Pokeminer20                                #
  4. #==============================================================================#
  5. #   This script alters the normal properties of essentials to allow the player #
  6. #          and the foes to use 8 pokemon as opposed to the normal 6            #
  7. #                                                                              #
  8. #     Not sure how this'll affect the mata of certain games but that's not my  #
  9. #                             concern. Enjoy the script                        #
  10. #==============================================================================#
  11. # Aside from adding this above main, you will need to go to                    #
  12. # Class PokeBattle_Trainer and insert "attr_accessor(:partyplus)" anywhere     #
  13. # between the start of the class and 'def trainerTypeName' as well as add      #
  14. # "@partyplus=false" between 'def initialize(name,trainertype)' and            #
  15. # 'for i in 1..PBSpecies.maxValue'                                             #
  16. #==============================================================================#
  17. # To actually activate the script use "$Trainer.partyplus=true' in an event    #
  18. # The 3 scenarios I personally see this being used in is as followed.          #
  19. # 1: The script is turned on at the start of the game and is always active.    #
  20. # 2: The script is Toggled depending on the story, On when outside of a Gym    #
  21. #    Challenge, 8 everywhere else                                              #
  22. # 3: The script is used with the $Trainer.hardmode function included to create #
  23. #    4 seperate difficulty modes accessed after one playthrough.               #
  24. #==============================================================================#
  25. # Diffuculty Modes:PP=Party Plus,HM=Hard Mode,!PP/!HM=Not Hardmode/Partyplus   #
  26. # Easy Mode = PP/!MH: Foes use 6 mons, Player use 8                            #
  27. # Normal Mode = !PP/!HM: All trainers use 6 Mons                               #
  28. # Hard = !PP/HM:  PLayer use 6 mons, Foes use 8                                #
  29. # Insane = PP/HM:  All trainers use 8 Mons                                     #
  30. #==============================================================================#
  31. # For modification past a limit of 8 locate most instances where               #
  32. # $Trainer.party.limit correlates to 8 and increase it's value to whatever     #
  33. # number you want. just be sure that values dictated under $Trainer.partyplus  #
  34. # is also increased by the same value (Ex. if party is 12, add 4 to values)    #
  35. #==============================================================================#
  36. #==============================================================================#
  37. #                    Please give credit when using this.                       #
  38. #==============================================================================#
  39. # Locate 'MAXPARTYSIZE = 6' and change it to 'MAXPARTYSIZE = 8'
  40. ################################################################################
  41. # Pokemon Storing                                                              #
  42. ################################################################################
  43. class PokeBattle_NullBattlePeer
  44.   def pbOnEnteringBattle(battle,pokemon)
  45.   end
  46.  
  47.   def pbStorePokemon(player,pokemon)
  48.   if $Trainer.partyplus
  49.     if player.party.length<8
  50.       player.party[player.party.length]=pokemon
  51.     end
  52.   else
  53.     if player.party.length<6
  54.       player.party[player.party.length]=pokemon
  55.     end
  56.   end
  57.  
  58.     return -1
  59.   end
  60.  
  61.   def pbGetStorageCreator()
  62.     return nil
  63.   end
  64.  
  65.   def pbCurrentBox()
  66.     return -1
  67.   end
  68.  
  69.   def pbBoxName(box)
  70.     return ""
  71.   end
  72. end
  73.  
  74. class PokeBattle_RealBattlePeer
  75.   def pbStorePokemon(player,pokemon)
  76.   if $Trainer.partyplus
  77.     if player.party.length<8
  78.       player.party[player.party.length]=pokemon
  79.       return -1
  80.     else
  81.       pokemon.heal
  82.       oldcurbox=$PokemonStorage.currentBox
  83.       storedbox=$PokemonStorage.pbStoreCaught(pokemon)
  84.       if storedbox<0
  85.         pbDisplayPaused(_INTL("Can't catch any more..."))
  86.         return oldcurbox
  87.       else
  88.         return storedbox
  89.       end
  90.     end
  91.   else
  92.     if player.party.length<6
  93.       player.party[player.party.length]=pokemon
  94.       return -1
  95.     else
  96.       pokemon.heal
  97.       oldcurbox=$PokemonStorage.currentBox
  98.       storedbox=$PokemonStorage.pbStoreCaught(pokemon)
  99.       if storedbox<0
  100.         pbDisplayPaused(_INTL("Can't catch any more..."))
  101.         return oldcurbox
  102.       else
  103.         return storedbox
  104.       end
  105.     end
  106.   end
  107.   end
  108.  
  109.   def pbGetStorageCreator()
  110.     creator=nil
  111.     if $PokemonGlobal && $PokemonGlobal.seenStorageCreator
  112.       creator=Kernel.pbGetStorageCreator
  113.     end
  114.     return creator
  115.   end
  116.  
  117.   def pbCurrentBox()
  118.     return $PokemonStorage.currentBox
  119.   end
  120.  
  121.   def pbBoxName(box)
  122.    return box<0 ? "" : $PokemonStorage[box].name
  123.   end
  124. end
  125.  
  126. ################################################################################
  127. # Daycare Methods                                                              #
  128. ################################################################################
  129. def pbDayCareWithdraw(index)
  130.  if $Trainer.partyplus
  131.   if !$PokemonGlobal.daycare[index][0]
  132.     raise _INTL("There's no Pokémon here...")
  133.   elsif $Trainer.party.length>=8
  134.     raise _INTL("Can't store the Pokémon...")
  135.   else
  136.     $Trainer.party[$Trainer.party.length]=$PokemonGlobal.daycare[index][0]
  137.     $PokemonGlobal.daycare[index][0]=nil
  138.     $PokemonGlobal.daycare[index][1]=0
  139.     $PokemonGlobal.daycareEgg=0
  140.   end  
  141.  else
  142.   if !$PokemonGlobal.daycare[index][0]
  143.     raise _INTL("There's no Pokémon here...")
  144.   elsif $Trainer.party.length>=6
  145.     raise _INTL("Can't store the Pokémon...")
  146.   else
  147.     $Trainer.party[$Trainer.party.length]=$PokemonGlobal.daycare[index][0]
  148.     $PokemonGlobal.daycare[index][0]=nil
  149.     $PokemonGlobal.daycare[index][1]=0
  150.     $PokemonGlobal.daycareEgg=0
  151.   end  
  152.  end
  153. end
  154.  
  155. def pbDayCareGenerateEgg
  156.   return if pbDayCareDeposited!=2
  157. if $Trainer.partyplus
  158.   if $Trainer.party.length>=8
  159.     raise _INTL("Can't store the egg")
  160.   end
  161. else
  162.   if $Trainer.party.length>=6
  163.     raise _INTL("Can't store the egg")
  164.   end
  165. end
  166.   pokemon0=$PokemonGlobal.daycare[0][0]
  167.   pokemon1=$PokemonGlobal.daycare[1][0]
  168.   mother=nil
  169.   father=nil
  170.   babyspecies=0
  171.   ditto0=pbIsDitto?(pokemon0)
  172.   ditto1=pbIsDitto?(pokemon1)
  173.   if pokemon0.isFemale? || ditto0
  174.     babyspecies=(ditto0) ? pokemon1.species : pokemon0.species
  175.     mother=pokemon0
  176.     father=pokemon1
  177.   else
  178.     babyspecies=(ditto1) ? pokemon0.species : pokemon1.species
  179.     mother=pokemon1
  180.     father=pokemon0
  181.   end
  182.   babyspecies=pbGetBabySpecies(babyspecies,mother.item,father.item)
  183.   if isConst?(babyspecies,PBSpecies,:MANAPHY) && hasConst?(PBSpecies,:PHIONE)
  184.     babyspecies=getConst(PBSpecies,:PHIONE)
  185.   elsif (isConst?(babyspecies,PBSpecies,:NIDORANfE) && hasConst?(PBSpecies,:NIDORANmA)) ||
  186.         (isConst?(babyspecies,PBSpecies,:NIDORANmA) && hasConst?(PBSpecies,:NIDORANfE))
  187.     babyspecies=[getConst(PBSpecies,:NIDORANmA),
  188.                  getConst(PBSpecies,:NIDORANfE)][rand(2)]
  189.   elsif (isConst?(babyspecies,PBSpecies,:VOLBEAT) && hasConst?(PBSpecies,:ILLUMISE)) ||
  190.         (isConst?(babyspecies,PBSpecies,:ILLUMISE) && hasConst?(PBSpecies,:VOLBEAT))
  191.     babyspecies=[getConst(PBSpecies,:VOLBEAT),
  192.                  getConst(PBSpecies,:ILLUMISE)][rand(2)]
  193.   end
  194.   # Generate egg
  195.   egg=PokeBattle_Pokemon.new(babyspecies,EGGINITIALLEVEL,$Trainer)
  196.   # Randomise personal ID
  197.   pid=rand(65536)
  198.   pid|=(rand(65536)<<16)
  199.   egg.personalID=pid
  200.   # Inheriting form
  201.   if isConst?(babyspecies,PBSpecies,:BURMY) ||
  202.      isConst?(babyspecies,PBSpecies,:SHELLOS) ||
  203.      isConst?(babyspecies,PBSpecies,:BASCULIN) ||
  204.      isConst?(babyspecies,PBSpecies,:FLABEBE) ||
  205.      isConst?(babyspecies,PBSpecies,:PUMPKABOO) ||
  206.      isConst?(babyspecies,PBSpecies,:ORICORIO) ||
  207.      isConst?(babyspecies,PBSpecies,:MINIOR)
  208.     egg.form=mother.form
  209.   end
  210.   # Inheriting Moves
  211.   moves=[]
  212.   othermoves=[]
  213.   movefather=father; movemother=mother
  214.   if pbIsDitto?(movefather) && !mother.isFemale?
  215.     movefather=mother; movemother=father
  216.   end
  217.   # Initial Moves
  218.   initialmoves=egg.getMoveList
  219.   for k in initialmoves
  220.     if k[0]<=EGGINITIALLEVEL
  221.       moves.push(k[1])
  222.     else
  223.       othermoves.push(k[1]) if mother.hasMove?(k[1]) && father.hasMove?(k[1])
  224.     end
  225.   end
  226.   # Inheriting Natural Moves
  227.   for move in othermoves
  228.     moves.push(move)
  229.   end
  230.   # Inheriting Machine Moves
  231.   if !USENEWBATTLEMECHANICS
  232.     for i in 0...$ItemData.length
  233.       next if !$ItemData[i]
  234.       atk=$ItemData[i][ITEMMACHINE]
  235.       next if !atk || atk==0
  236.       if egg.isCompatibleWithMove?(atk)
  237.         moves.push(atk) if movefather.hasMove?(atk)
  238.       end
  239.     end
  240.   end
  241.   # Inheriting Egg Moves
  242.   if movefather.isMale?
  243.     pbRgssOpen("Data/eggEmerald.dat","rb"){|f|
  244.        f.pos=(egg.fSpecies-1)*8
  245.        offset=f.fgetdw
  246.        length=f.fgetdw
  247.        if length>0
  248.          f.pos=offset
  249.          i=0; loop do break unless i<length
  250.            atk=f.fgetw
  251.            moves.push(atk) if movefather.hasMove?(atk)
  252.            i+=1
  253.          end
  254.        end
  255.     }
  256.   end
  257.   if USENEWBATTLEMECHANICS
  258.     pbRgssOpen("Data/eggEmerald.dat","rb"){|f|
  259.        f.pos=(egg.fSpecies-1)*8
  260.        offset=f.fgetdw
  261.        length=f.fgetdw
  262.        if length>0
  263.          f.pos=offset
  264.          i=0; loop do break unless i<length
  265.            atk=f.fgetw
  266.            moves.push(atk) if movemother.hasMove?(atk)
  267.            i+=1
  268.          end
  269.        end
  270.     }
  271.   end
  272.   # Volt Tackle
  273.   lightball=false
  274.   if (isConst?(father.species,PBSpecies,:PIKACHU) ||
  275.       isConst?(father.species,PBSpecies,:RAICHU)) &&
  276.       isConst?(father.item,PBItems,:LIGHTBALL)
  277.     lightball=true
  278.   end
  279.   if (isConst?(mother.species,PBSpecies,:PIKACHU) ||
  280.       isConst?(mother.species,PBSpecies,:RAICHU)) &&
  281.       isConst?(mother.item,PBItems,:LIGHTBALL)
  282.     lightball=true
  283.   end
  284.   if lightball && isConst?(babyspecies,PBSpecies,:PICHU) &&
  285.      hasConst?(PBMoves,:VOLTTACKLE)
  286.     moves.push(getConst(PBMoves,:VOLTTACKLE))
  287.   end
  288.   moves|=[] # remove duplicates
  289.   # Assembling move list
  290.   finalmoves=[]
  291.   listend=moves.length-4
  292.   listend=0 if listend<0
  293.   j=0
  294.   for i in listend..listend+3
  295.     moveid=(i>=moves.length) ? 0 : moves[i]
  296.     finalmoves[j]=PBMove.new(moveid)
  297.     j+=1
  298.   end
  299.   # Inheriting Individual Values
  300.   ivs=[]
  301.   for i in 0...6
  302.     ivs[i]=rand(32)
  303.   end
  304.   ivinherit=[]
  305.   for i in 0...2
  306.     parent=[mother,father][i]
  307.     ivinherit[i]=PBStats::HP if isConst?(parent.item,PBItems,:POWERWEIGHT)
  308.     ivinherit[i]=PBStats::ATTACK if isConst?(parent.item,PBItems,:POWERBRACER)
  309.     ivinherit[i]=PBStats::DEFENSE if isConst?(parent.item,PBItems,:POWERBELT)
  310.     ivinherit[i]=PBStats::SPEED if isConst?(parent.item,PBItems,:POWERANKLET)
  311.     ivinherit[i]=PBStats::SPATK if isConst?(parent.item,PBItems,:POWERLENS)
  312.     ivinherit[i]=PBStats::SPDEF if isConst?(parent.item,PBItems,:POWERBAND)
  313.   end
  314.   num=0; r=rand(2)
  315.   for i in 0...2
  316.     if ivinherit[r]!=nil
  317.       parent=[mother,father][r]
  318.       ivs[ivinherit[r]]=parent.iv[ivinherit[r]]
  319.       num+=1
  320.       break
  321.     end
  322.     r=(r+1)%2
  323.   end
  324.   stats=[PBStats::HP,PBStats::ATTACK,PBStats::DEFENSE,
  325.          PBStats::SPEED,PBStats::SPATK,PBStats::SPDEF]
  326.   limit=(USENEWBATTLEMECHANICS && (isConst?(mother.item,PBItems,:DESTINYKNOT) ||
  327.          isConst?(father.item,PBItems,:DESTINYKNOT))) ? 5 : 3
  328.   loop do
  329.     freestats=[]
  330.     for i in stats
  331.       freestats.push(i) if !ivinherit.include?(i)
  332.     end
  333.     break if freestats.length==0
  334.     r=freestats[rand(freestats.length)]
  335.     parent=[mother,father][rand(2)]
  336.     ivs[r]=parent.iv[r]
  337.     ivinherit.push(r)
  338.     num+=1
  339.     break if num>=limit
  340.   end
  341.   # Inheriting nature
  342.   newnatures=[]
  343.   newnatures.push(mother.nature) if isConst?(mother.item,PBItems,:EVERSTONE)
  344.   newnatures.push(father.nature) if isConst?(father.item,PBItems,:EVERSTONE)
  345.   if newnatures.length>0
  346.     egg.setNature(newnatures[rand(newnatures.length)])
  347.   end
  348.   # Masuda method and Shiny Charm
  349.   shinyretries=0
  350.   shinyretries+=5 if father.language!=mother.language
  351.   shinyretries+=2 if hasConst?(PBItems,:SHINYCHARM) &&
  352.                      $PokemonBag.pbHasItem?(:SHINYCHARM)
  353.   if shinyretries>0
  354.     for i in 0...shinyretries
  355.       break if egg.isShiny?
  356.       egg.personalID=rand(65536)|(rand(65536)<<16)
  357.     end
  358.   end
  359.   # Inheriting ability from the mother
  360.   if (!ditto0 && !ditto1)
  361.     if mother.hasHiddenAbility?
  362.       egg.setAbility(mother.abilityIndex) if rand(10)<6
  363.     else
  364.       if rand(10)<8
  365.         egg.setAbility(mother.abilityIndex)
  366.       else
  367.         egg.setAbility((mother.abilityIndex+1)%2)
  368.       end
  369.     end
  370.   elsif ((!ditto0 && ditto1) || (!ditto1 && ditto0)) && USENEWBATTLEMECHANICS
  371.     parent=(!ditto0) ? mother : father
  372.     if parent.hasHiddenAbility?
  373.       egg.setAbility(parent.abilityIndex) if rand(10)<6
  374.     end
  375.   end
  376.   # Inheriting Poké Ball from the mother
  377.   if mother.isFemale? &&
  378.      !isConst?(pbBallTypeToBall(mother.ballused),PBItems,:MASTERBALL) &&
  379.      !isConst?(pbBallTypeToBall(mother.ballused),PBItems,:CHERISHBALL)
  380.     egg.ballused=mother.ballused
  381.   end
  382.   egg.iv[0]=ivs[0]
  383.   egg.iv[1]=ivs[1]
  384.   egg.iv[2]=ivs[2]
  385.   egg.iv[3]=ivs[3]
  386.   egg.iv[4]=ivs[4]
  387.   egg.iv[5]=ivs[5]
  388.   egg.moves[0]=finalmoves[0]
  389.   egg.moves[1]=finalmoves[1]
  390.   egg.moves[2]=finalmoves[2]
  391.   egg.moves[3]=finalmoves[3]
  392.   egg.calcStats
  393.   egg.obtainText=_INTL("Day-Care Couple")
  394.   egg.name=_INTL("Egg")
  395.   dexdata=pbOpenDexData
  396.   pbDexDataOffset(dexdata,babyspecies,21)
  397.   eggsteps=dexdata.fgetw
  398.   dexdata.close
  399.   egg.eggsteps=eggsteps
  400.   if rand(65536)<POKERUSCHANCE
  401.     egg.givePokerus
  402.   end
  403.   $Trainer.party[$Trainer.party.length]=egg
  404. end
  405.  
  406. ################################################################################
  407. # Item Reworking                                                               #
  408. ################################################################################
  409. ItemHandlers::UseOnPokemon.add(:DNASPLICERS,proc{|item,pokemon,scene|
  410. if $Trainer.partyplus
  411.      if isConst?(pokemon.species,PBSpecies,:KYUREM)
  412.      if pokemon.hp>0
  413.        if pokemon.fused!=nil
  414.          if $Trainer.party.length>=8
  415.            scene.pbDisplay(_INTL("You have no room to separate the Pokémon."))
  416.            next false
  417.          else
  418.            $Trainer.party[$Trainer.party.length]=pokemon.fused
  419.            pokemon.fused=nil
  420.            pokemon.form=0
  421.            scene.pbHardRefresh
  422.            scene.pbDisplay(_INTL("{1} changed Forme!",pokemon.name))
  423.            next true
  424.          end
  425.        else
  426.          chosen=scene.pbChoosePokemon(_INTL("Fuse with which Pokémon?"))
  427.          if chosen>=0
  428.            poke2=$Trainer.party[chosen]
  429.            if (isConst?(poke2.species,PBSpecies,:RESHIRAM) ||
  430.               isConst?(poke2.species,PBSpecies,:ZEKROM)) && poke2.hp>0 && !poke2.egg?
  431.              pokemon.form=1 if isConst?(poke2.species,PBSpecies,:RESHIRAM)
  432.              pokemon.form=2 if isConst?(poke2.species,PBSpecies,:ZEKROM)
  433.              pokemon.fused=poke2
  434.              pbRemovePokemonAt(chosen)
  435.              scene.pbHardRefresh
  436.              scene.pbDisplay(_INTL("{1} changed Forme!",pokemon.name))
  437.              next true
  438.            elsif poke2.egg?
  439.              scene.pbDisplay(_INTL("It cannot be fused with an Egg."))
  440.            elsif poke2.hp<=0
  441.              scene.pbDisplay(_INTL("It cannot be fused with that fainted Pokémon."))
  442.            elsif pokemon==poke2
  443.              scene.pbDisplay(_INTL("It cannot be fused with itself."))
  444.            else
  445.              scene.pbDisplay(_INTL("It cannot be fused with that Pokémon."))
  446.            end
  447.          else
  448.            next false
  449.          end
  450.        end
  451.      else
  452.        scene.pbDisplay(_INTL("This can't be used on the fainted Pokémon."))
  453.      end
  454.    else
  455.      scene.pbDisplay(_INTL("It had no effect."))
  456.      next false
  457.    end
  458. else
  459.    if isConst?(pokemon.species,PBSpecies,:KYUREM)
  460.      if pokemon.hp>0
  461.        if pokemon.fused!=nil
  462.          if $Trainer.party.length>=6
  463.            scene.pbDisplay(_INTL("You have no room to separate the Pokémon."))
  464.            next false
  465.          else
  466.            $Trainer.party[$Trainer.party.length]=pokemon.fused
  467.            pokemon.fused=nil
  468.            pokemon.form=0
  469.            scene.pbHardRefresh
  470.            scene.pbDisplay(_INTL("{1} changed Forme!",pokemon.name))
  471.            next true
  472.          end
  473.        else
  474.          chosen=scene.pbChoosePokemon(_INTL("Fuse with which Pokémon?"))
  475.          if chosen>=0
  476.            poke2=$Trainer.party[chosen]
  477.            if (isConst?(poke2.species,PBSpecies,:RESHIRAM) ||
  478.               isConst?(poke2.species,PBSpecies,:ZEKROM)) && poke2.hp>0 && !poke2.egg?
  479.              pokemon.form=1 if isConst?(poke2.species,PBSpecies,:RESHIRAM)
  480.              pokemon.form=2 if isConst?(poke2.species,PBSpecies,:ZEKROM)
  481.              pokemon.fused=poke2
  482.              pbRemovePokemonAt(chosen)
  483.              scene.pbHardRefresh
  484.              scene.pbDisplay(_INTL("{1} changed Forme!",pokemon.name))
  485.              next true
  486.            elsif poke2.egg?
  487.              scene.pbDisplay(_INTL("It cannot be fused with an Egg."))
  488.            elsif poke2.hp<=0
  489.              scene.pbDisplay(_INTL("It cannot be fused with that fainted Pokémon."))
  490.            elsif pokemon==poke2
  491.              scene.pbDisplay(_INTL("It cannot be fused with itself."))
  492.            else
  493.              scene.pbDisplay(_INTL("It cannot be fused with that Pokémon."))
  494.            end
  495.          else
  496.            next false
  497.          end
  498.        end
  499.      else
  500.        scene.pbDisplay(_INTL("This can't be used on the fainted Pokémon."))
  501.      end
  502.    else
  503.      scene.pbDisplay(_INTL("It had no effect."))
  504.      next false
  505.    end
  506.   end
  507. })
  508.  
  509. ItemHandlers::BattleUseOnBattler.addIf(proc{|item|
  510.                 pbIsPokeBall?(item)},proc{|item,battler,scene|  # Any Poké Ball
  511.    battle=battler.battle
  512.    if !battler.pbOpposing1.isFainted? && !battler.pbOpposing2.isFainted?
  513.      if !pbIsSnagBall?(item)
  514.        scene.pbDisplay(_INTL("It's no good! It's impossible to aim when there are two Pokémon!"))
  515.        return false
  516.      end
  517.    end
  518. if $Trainer.partyplus
  519.    if battle.pbPlayer.party.length>=8 && $PokemonStorage.full?
  520.      scene.pbDisplay(_INTL("There is no room left in the PC!"))
  521.      return false
  522.    end
  523. else
  524.    if battle.pbPlayer.party.length>=6 && $PokemonStorage.full?
  525.      scene.pbDisplay(_INTL("There is no room left in the PC!"))
  526.      return false
  527.    end
  528. end
  529.    return true
  530. })
  531.  
  532. ################################################################################
  533. # Evolution                                                                    #
  534. ################################################################################
  535.   def pbEvolutionSuccess
  536.     # Play cry of evolved species
  537.     frames = pbCryFrameLength(@newspecies,@pokemon.form)
  538.     pbBGMStop
  539.     pbPlayCrySpecies(@newspecies,@pokemon.form)
  540.     frames.times do
  541.       Graphics.update
  542.       pbUpdate
  543.     end
  544.     # Success jingle/message
  545.     pbMEPlay("ME Item 2")
  546.     newspeciesname = PBSpecies.getName(@newspecies)
  547.     oldspeciesname = PBSpecies.getName(@pokemon.species)
  548.     Kernel.pbMessageDisplay(@sprites["msgwindow"],
  549.        _INTL("\\se[]Congratulations! Your {1} evolved into {2}!\\wt[80]",
  550.        @pokemon.name,newspeciesname)) { pbUpdate }
  551.     @sprites["msgwindow"].text = ""
  552.     # Check for consumed item and Pokémon duplication (i.e. Shedinja)
  553.     removeItem = false
  554.     createSpecies = pbCheckEvolutionEx(@pokemon){|pokemon,evonib,level,poke|
  555.        case evonib
  556.        when PBEvolution::Shedinja
  557.          next poke if $PokemonBag.pbHasItem?(getConst(PBItems,:POKEBALL))
  558.        when PBEvolution::TradeItem,PBEvolution::DayHoldItem,PBEvolution::NightHoldItem
  559.          removeItem = true if poke==@newspecies   # Item is now consumed
  560.        end
  561.        next -1
  562.     }
  563.     @pokemon.setItem(0) if removeItem
  564.     # Modify Pokémon to make it evolved
  565.     @pokemon.species = @newspecies
  566.     @pokemon.name    = newspeciesname if @pokemon.name==oldspeciesname
  567.     @pokemon.form    = 0 if isConst?(@pokemon.species,PBSpecies,:MOTHIM)
  568.     @pokemon.calcStats
  569.     # See and own evolved species
  570.     $Trainer.seen[@newspecies]  = true
  571.     $Trainer.owned[@newspecies] = true
  572.     pbSeenForm(@pokemon)
  573.     # Learn moves upon evolution for evolved species
  574.     movelist = @pokemon.getMoveList
  575.     for i in movelist
  576.       if i[0]==0 || i[0]==@pokemon.level          # Learned a new move
  577.         pbLearnMove(@pokemon,i[1],true) { pbUpdate }
  578.       end
  579.     end
  580.     # Duplicate Pokémon (i.e. Shedinja)
  581. if $Trainer.partyplus
  582.       if createSpecies>0 && $Trainer.party.length<8
  583.       newpokemon = @pokemon.clone
  584.       newpokemon.species = createSpecies
  585.       newpokemon.name    = PBSpecies.getName(createSpecies)
  586.       newpokemon.iv      = @pokemon.iv.clone
  587.       newpokemon.ev      = @pokemon.ev.clone
  588.       newpokemon.markings = 0
  589.       newpokemon.ballused = 0
  590.       newpokemon.setItem(0)
  591.       newpokemon.clearAllRibbons
  592.       newpokemon.calcStats
  593.       newpokemon.heal
  594.       # Add duplicate Pokémon to party
  595.       $Trainer.party.push(newpokemon)
  596.       # See and own duplicate Pokémon
  597.       $Trainer.seen[createSpecies]  = true
  598.       $Trainer.owned[createSpecies] = true
  599.       pbSeenForm(newpokemon)
  600.       # Consume Poké Ball
  601.       $PokemonBag.pbDeleteItem(getConst(PBItems,:POKEBALL))
  602.     end
  603. else
  604.       if createSpecies>0 && $Trainer.party.length<6
  605.       newpokemon = @pokemon.clone
  606.       newpokemon.species = createSpecies
  607.       newpokemon.name    = PBSpecies.getName(createSpecies)
  608.       newpokemon.iv      = @pokemon.iv.clone
  609.       newpokemon.ev      = @pokemon.ev.clone
  610.       newpokemon.markings = 0
  611.       newpokemon.ballused = 0
  612.       newpokemon.setItem(0)
  613.       newpokemon.clearAllRibbons
  614.       newpokemon.calcStats
  615.       newpokemon.heal
  616.       # Add duplicate Pokémon to party
  617.       $Trainer.party.push(newpokemon)
  618.       # See and own duplicate Pokémon
  619.       $Trainer.seen[createSpecies]  = true
  620.       $Trainer.owned[createSpecies] = true
  621.       pbSeenForm(newpokemon)
  622.       # Consume Poké Ball
  623.       $PokemonBag.pbDeleteItem(getConst(PBItems,:POKEBALL))
  624.     end
  625.    end
  626.   end
  627.  
  628. ################################################################################
  629. # Party                                                                        #
  630. ################################################################################
  631. #===============================================================================
  632. # Pokémon party panels
  633. #===============================================================================
  634. class PokemonPartyBlankPanel < SpriteWrapper
  635.   attr_accessor :text
  636.  
  637.   def initialize(pokemon,index,viewport=nil)
  638.    if $Trainer.partyplus
  639.     super(viewport)
  640.     self.x = [0,256,0,256,0,256,0,256][index]
  641.     self.y = [-8,-8,72,72,152,152,232,232][index]
  642.     @panelbgsprite = AnimatedBitmap.new("Graphics/Pictures/Party/Pluspanel_blank")
  643.     self.bitmap = @panelbgsprite.bitmap
  644.     @text = nil
  645.   else
  646.     super(viewport)
  647.     self.x = [0,256,0,256,0,256][index]
  648.     self.y = [0,16,96,112,192,208][index]
  649.     @panelbgsprite = AnimatedBitmap.new("Graphics/Pictures/Party/panel_blank")
  650.     self.bitmap = @panelbgsprite.bitmap
  651.     @text = nil
  652.     end
  653.   end
  654.  
  655.   def dispose
  656.     @panelbgsprite.dispose
  657.     super
  658.   end
  659.  
  660.   def selected; return false; end
  661.   def selected=(value); end
  662.   def preselected; return false; end
  663.   def preselected=(value); end
  664.   def switching; return false; end
  665.   def switching=(value); end
  666.   def refresh; end
  667. end
  668.  
  669. class PokemonPartyPanel < SpriteWrapper
  670.   attr_reader :pokemon
  671.   attr_reader :active
  672.   attr_reader :selected
  673.   attr_reader :preselected
  674.   attr_reader :switching
  675.   attr_accessor :text
  676.  
  677.   def initialize(pokemon,index,viewport=nil)
  678.   if $Trainer.partyplus
  679.     super(viewport)
  680.     @pokemon = pokemon
  681.     @active = (index==0)   # true = rounded panel, false = rectangular panel
  682.     @refreshing = true
  683.     self.x = [0,256,0,256,0,256,0,256][index]
  684.     self.y = [-8,-8,72,72,152,152,232,232][index]
  685.     @panelbgsprite = ChangelingSprite.new(0,0,viewport)
  686.     @panelbgsprite.z = self.z
  687.     if @active   # Rounded panel
  688.       @panelbgsprite.addBitmap("able","Graphics/Pictures/Party/Pluspanel_round")
  689.       @panelbgsprite.addBitmap("ablesel","Graphics/Pictures/Party/Pluspanel_round_sel")
  690.       @panelbgsprite.addBitmap("fainted","Graphics/Pictures/Party/Pluspanel_round_faint")
  691.       @panelbgsprite.addBitmap("faintedsel","Graphics/Pictures/Party/Pluspanel_round_faint_sel")
  692.       @panelbgsprite.addBitmap("swap","Graphics/Pictures/Party/Pluspanel_round_swap")
  693.       @panelbgsprite.addBitmap("swapsel","Graphics/Pictures/Party/Pluspanel_round_swap_sel")
  694.       @panelbgsprite.addBitmap("swapsel2","Graphics/Pictures/Party/Pluspanel_round_swap_sel2")
  695.     else   # Rectangular panel
  696.       @panelbgsprite.addBitmap("able","Graphics/Pictures/Party/Pluspanel_rect")
  697.       @panelbgsprite.addBitmap("ablesel","Graphics/Pictures/Party/Pluspanel_rect_sel")
  698.       @panelbgsprite.addBitmap("fainted","Graphics/Pictures/Party/Pluspanel_rect_faint")
  699.       @panelbgsprite.addBitmap("faintedsel","Graphics/Pictures/Party/Pluspanel_rect_faint_sel")
  700.       @panelbgsprite.addBitmap("swap","Graphics/Pictures/Party/Pluspanel_rect_swap")
  701.       @panelbgsprite.addBitmap("swapsel","Graphics/Pictures/Party/Pluspanel_rect_swap_sel")
  702.       @panelbgsprite.addBitmap("swapsel2","Graphics/Pictures/Party/Pluspanel_rect_swap_sel2")
  703.     end
  704.     @hpbgsprite = ChangelingSprite.new(0,0,viewport)
  705.     @hpbgsprite.z = self.z+1
  706.     @hpbgsprite.addBitmap("able","Graphics/Pictures/Party/Plusoverlay_hp_back")
  707.     @hpbgsprite.addBitmap("fainted","Graphics/Pictures/Party/Plusoverlay_hp_back_faint")
  708.     @hpbgsprite.addBitmap("swap","Graphics/Pictures/Party/Plusoverlay_hp_back_swap")
  709.     @ballsprite = ChangelingSprite.new(0,0,viewport)
  710.     @ballsprite.z = self.z+1
  711.     @ballsprite.addBitmap("desel","Graphics/Pictures/Party/Plusicon_ball")
  712.     @ballsprite.addBitmap("sel","Graphics/Pictures/Party/Plusicon_ball_sel")
  713.     @pkmnsprite = PokemonIconSprite.new(pokemon,viewport)
  714.     @pkmnsprite.active = @active
  715.     @pkmnsprite.z      = self.z+2
  716.     @helditemsprite = HeldItemIconSprite.new(0,0,@pokemon,viewport)
  717.     @helditemsprite.z = self.z+3
  718.     @overlaysprite = BitmapSprite.new(Graphics.width,Graphics.height,viewport)
  719.     @overlaysprite.z = self.z+4
  720.     @hpbar    = AnimatedBitmap.new("Graphics/Pictures/Party/Plusoverlay_hp")
  721.     @statuses = AnimatedBitmap.new(_INTL("Graphics/Pictures/statuses"))
  722.     @selected      = false
  723.     @preselected   = false
  724.     @switching     = false
  725.     @text          = nil
  726.     @refreshBitmap = true
  727.     @refreshing    = false
  728.     refresh
  729.    else
  730.     super(viewport)
  731.     @pokemon = pokemon
  732.     @active = (index==0)   # true = rounded panel, false = rectangular panel
  733.     @refreshing = true
  734.     self.x = [0,256,0,256,0,256][index]
  735.     self.y = [0,16,96,112,192,208][index]
  736.     @panelbgsprite = ChangelingSprite.new(0,0,viewport)
  737.     @panelbgsprite.z = self.z
  738.     if @active   # Rounded panel
  739.       @panelbgsprite.addBitmap("able","Graphics/Pictures/Party/panel_round")
  740.       @panelbgsprite.addBitmap("ablesel","Graphics/Pictures/Party/panel_round_sel")
  741.       @panelbgsprite.addBitmap("fainted","Graphics/Pictures/Party/panel_round_faint")
  742.       @panelbgsprite.addBitmap("faintedsel","Graphics/Pictures/Party/panel_round_faint_sel")
  743.       @panelbgsprite.addBitmap("swap","Graphics/Pictures/Party/panel_round_swap")
  744.       @panelbgsprite.addBitmap("swapsel","Graphics/Pictures/Party/panel_round_swap_sel")
  745.       @panelbgsprite.addBitmap("swapsel2","Graphics/Pictures/Party/panel_round_swap_sel2")
  746.     else   # Rectangular panel
  747.       @panelbgsprite.addBitmap("able","Graphics/Pictures/Party/panel_rect")
  748.       @panelbgsprite.addBitmap("ablesel","Graphics/Pictures/Party/panel_rect_sel")
  749.       @panelbgsprite.addBitmap("fainted","Graphics/Pictures/Party/panel_rect_faint")
  750.       @panelbgsprite.addBitmap("faintedsel","Graphics/Pictures/Party/panel_rect_faint_sel")
  751.       @panelbgsprite.addBitmap("swap","Graphics/Pictures/Party/panel_rect_swap")
  752.       @panelbgsprite.addBitmap("swapsel","Graphics/Pictures/Party/panel_rect_swap_sel")
  753.       @panelbgsprite.addBitmap("swapsel2","Graphics/Pictures/Party/panel_rect_swap_sel2")
  754.     end
  755.     @hpbgsprite = ChangelingSprite.new(0,0,viewport)
  756.     @hpbgsprite.z = self.z+1
  757.     @hpbgsprite.addBitmap("able","Graphics/Pictures/Party/overlay_hp_back")
  758.     @hpbgsprite.addBitmap("fainted","Graphics/Pictures/Party/overlay_hp_back_faint")
  759.     @hpbgsprite.addBitmap("swap","Graphics/Pictures/Party/overlay_hp_back_swap")
  760.     @ballsprite = ChangelingSprite.new(0,0,viewport)
  761.     @ballsprite.z = self.z+1
  762.     @ballsprite.addBitmap("desel","Graphics/Pictures/Party/icon_ball")
  763.     @ballsprite.addBitmap("sel","Graphics/Pictures/Party/icon_ball_sel")
  764.     @pkmnsprite = PokemonIconSprite.new(pokemon,viewport)
  765.     @pkmnsprite.active = @active
  766.     @pkmnsprite.z      = self.z+2
  767.     @helditemsprite = HeldItemIconSprite.new(0,0,@pokemon,viewport)
  768.     @helditemsprite.z = self.z+3
  769.     @overlaysprite = BitmapSprite.new(Graphics.width,Graphics.height,viewport)
  770.     @overlaysprite.z = self.z+4
  771.     @hpbar    = AnimatedBitmap.new("Graphics/Pictures/Party/overlay_hp")
  772.     @statuses = AnimatedBitmap.new(_INTL("Graphics/Pictures/statuses"))
  773.     @selected      = false
  774.     @preselected   = false
  775.     @switching     = false
  776.     @text          = nil
  777.     @refreshBitmap = true
  778.     @refreshing    = false
  779.     refresh
  780.    end
  781.   end
  782.  
  783.   def dispose
  784.     @panelbgsprite.dispose
  785.     @hpbgsprite.dispose
  786.     @ballsprite.dispose
  787.     @pkmnsprite.dispose
  788.     @helditemsprite.dispose
  789.     @overlaysprite.bitmap.dispose
  790.     @overlaysprite.dispose
  791.     @hpbar.dispose
  792.     @statuses.dispose
  793.     super
  794.   end
  795.  
  796.   def x=(value)
  797.     super
  798.     refresh
  799.   end
  800.  
  801.   def y=(value)
  802.     super
  803.     refresh
  804.   end
  805.  
  806.   def color=(value)
  807.     super
  808.     refresh
  809.   end
  810.  
  811.   def text=(value)
  812.     if @text!=value
  813.       @text = value
  814.       @refreshBitmap = true
  815.       refresh
  816.     end
  817.   end
  818.  
  819.   def pokemon=(value)
  820.     @pokemon = value
  821.     @pkmnsprite.pokemon = value if @pkmnsprite && !@pkmnsprite.disposed?
  822.     @helditemsprite.pokemon = value if @helditemsprite && !@helditemsprite.disposed?
  823.     @refreshBitmap = true
  824.     refresh
  825.   end
  826.  
  827.   def selected=(value)
  828.     if @selected!=value
  829.       @selected = value
  830.       refresh
  831.     end
  832.   end
  833.  
  834.   def preselected=(value)
  835.     if @preselected!=value
  836.       @preselected = value
  837.       refresh
  838.     end
  839.   end
  840.  
  841.   def switching=(value)
  842.     if @switching!=value
  843.       @switching = value
  844.       refresh
  845.     end
  846.   end
  847.  
  848.   def hp; return @pokemon.hp; end
  849.  
  850.   def refresh
  851.     return if disposed?
  852.     return if @refreshing
  853.     @refreshing = true
  854.     if @panelbgsprite && !@panelbgsprite.disposed?
  855.       if self.selected
  856.         if self.preselected;     @panelbgsprite.changeBitmap("swapsel2")
  857.         elsif @switching;        @panelbgsprite.changeBitmap("swapsel")
  858.         elsif @pokemon.isFainted?; @panelbgsprite.changeBitmap("faintedsel")
  859.         else;                    @panelbgsprite.changeBitmap("ablesel")
  860.         end
  861.       else
  862.         if self.preselected;     @panelbgsprite.changeBitmap("swap")
  863.         elsif @pokemon.isFainted?; @panelbgsprite.changeBitmap("fainted")
  864.         else;                    @panelbgsprite.changeBitmap("able")
  865.         end
  866.       end
  867.       @panelbgsprite.x     = self.x
  868.       @panelbgsprite.y     = self.y
  869.       @panelbgsprite.color = self.color
  870.     end
  871.     if @hpbgsprite && !@hpbgsprite.disposed?
  872.       @hpbgsprite.visible = (!@pokemon.egg? && !(@text && @text.length>0))
  873.       if @hpbgsprite.visible
  874.         if self.preselected || (self.selected && @switching); @hpbgsprite.changeBitmap("swap")
  875.         elsif @pokemon.isFainted?;                              @hpbgsprite.changeBitmap("fainted")
  876.         else;                                                 @hpbgsprite.changeBitmap("able")
  877.         end
  878.         @hpbgsprite.x     = self.x+96
  879.         @hpbgsprite.y     = self.y+50
  880.         @hpbgsprite.color = self.color
  881.       end
  882.     end
  883.     if @ballsprite && !@ballsprite.disposed?
  884.       @ballsprite.changeBitmap((self.selected) ? "sel" : "desel")
  885.       @ballsprite.x     = self.x+10
  886.       @ballsprite.y     = self.y
  887.       @ballsprite.color = self.color
  888.     end
  889.     if @pkmnsprite && !@pkmnsprite.disposed?
  890.       @pkmnsprite.x        = self.x+28
  891.       @pkmnsprite.y        = self.y
  892.       @pkmnsprite.color    = self.color
  893.       @pkmnsprite.selected = self.selected
  894.     end
  895.     if @helditemsprite && !@helditemsprite.disposed?
  896.       if @helditemsprite.visible
  897.         @helditemsprite.x     = self.x+62
  898.         @helditemsprite.y     = self.y+48
  899.         @helditemsprite.color = self.color
  900.       end
  901.     end
  902.     if @overlaysprite && !@overlaysprite.disposed?
  903.       @overlaysprite.x     = self.x
  904.       @overlaysprite.y     = self.y
  905.       @overlaysprite.color = self.color
  906.     end
  907.     if @refreshBitmap
  908.       @refreshBitmap = false
  909.       @overlaysprite.bitmap.clear if @overlaysprite.bitmap
  910.       basecolor   = Color.new(248,248,248)
  911.       shadowcolor = Color.new(40,40,40)
  912.       pbSetSystemFont(@overlaysprite.bitmap)
  913.       textpos = []
  914.       # Draw Pokémon name
  915.       textpos.push([@pokemon.name,96,16,0,basecolor,shadowcolor])
  916.       if !@pokemon.egg?
  917.         if !@text || @text.length==0
  918.           # Draw HP numbers
  919.           textpos.push([sprintf("% 3d /% 3d",@pokemon.hp,@pokemon.totalhp),224,60,1,basecolor,shadowcolor])
  920.           # Draw HP bar
  921.           if @pokemon.hp>0
  922.             hpzone = 0
  923.             hpzone = 1 if @pokemon.hp<=(@pokemon.totalhp/2).floor
  924.             hpzone = 2 if @pokemon.hp<=(@pokemon.totalhp/4).floor
  925.             hprect = Rect.new(0,hpzone*8,[@pokemon.hp*96/@pokemon.totalhp,2].max,8)
  926.             @overlaysprite.bitmap.blt(128,52,@hpbar.bitmap,hprect)
  927.           end
  928.           # Draw status
  929.           status = -1
  930.           status = 6 if @pokemon.pokerusStage==1
  931.           status = @pokemon.status-1 if @pokemon.status>0
  932.           status = 5 if @pokemon.hp<=0
  933.           if status>=0
  934.             statusrect = Rect.new(0,16*status,44,16)
  935.             @overlaysprite.bitmap.blt(78,68,@statuses.bitmap,statusrect)
  936.           end
  937.         end
  938.         # Draw gender icon
  939.         if @pokemon.isMale?
  940.           textpos.push([_INTL("♂"),224,16,0,Color.new(0,112,248),Color.new(120,184,232)])
  941.         elsif @pokemon.isFemale?
  942.           textpos.push([_INTL("♀"),224,16,0,Color.new(232,32,16),Color.new(248,168,184)])
  943.         end
  944.       end
  945.       pbDrawTextPositions(@overlaysprite.bitmap,textpos)
  946.       # Draw level text
  947.       if !@pokemon.egg?
  948.         pbDrawImagePositions(@overlaysprite.bitmap,[[
  949.            "Graphics/Pictures/Party/Plusoverlay_lv",20,70,0,0,22,14]])
  950.         pbSetSmallFont(@overlaysprite.bitmap)
  951.         pbDrawTextPositions(@overlaysprite.bitmap,[
  952.            [@pokemon.level.to_s,42,62,0,basecolor,shadowcolor]
  953.         ])
  954.       end
  955.       # Draw annotation text
  956.       if @text && @text.length>0
  957.         pbSetSystemFont(@overlaysprite.bitmap)
  958.         pbDrawTextPositions(@overlaysprite.bitmap,[
  959.            [@text,96,58,0,basecolor,shadowcolor]
  960.         ])
  961.       end
  962.     end
  963.     @refreshing = false
  964.   end
  965.  
  966.   def update
  967.     super
  968.     @panelbgsprite.update if @panelbgsprite && !@panelbgsprite.disposed?
  969.     @hpbgsprite.update if @hpbgsprite && !@hpbgsprite.disposed?
  970.     @ballsprite.update if @ballsprite && !@ballsprite.disposed?
  971.     @pkmnsprite.update if @pkmnsprite && !@pkmnsprite.disposed?
  972.     @helditemsprite.update if @helditemsprite && !@helditemsprite.disposed?
  973.   end
  974. end
  975.  
  976. #===============================================================================
  977. # Pokémon party visuals
  978. #===============================================================================
  979. class PokemonParty_Scene
  980.   def pbStartScene(party,starthelptext,annotations=nil,multiselect=false)
  981.    if $Trainer.partyplus
  982.     @sprites = {}
  983.     @party = party
  984.     @viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  985.     @viewport.z = 99999
  986.     @multiselect = multiselect
  987.     addBackgroundPlane(@sprites,"partybg","Party/Plusbg",@viewport)
  988.     @sprites["messagebox"] = Window_AdvancedTextPokemon.new("")
  989.     @sprites["messagebox"].viewport       = @viewport
  990.     @sprites["messagebox"].visible        = false
  991.     @sprites["messagebox"].letterbyletter = true
  992.     pbBottomLeftLines(@sprites["messagebox"],2)
  993.     @sprites["helpwindow"] = Window_UnformattedTextPokemon.new(starthelptext)
  994.     @sprites["helpwindow"].viewport = @viewport
  995.     @sprites["helpwindow"].visible  = true
  996.     pbBottomLeftLines(@sprites["helpwindow"],1)
  997.     pbSetHelpText(starthelptext)
  998.     # Add party Pokémon sprites
  999.     for i in 0...8
  1000.       if @party[i]
  1001.         @sprites["pokemon#{i}"] = PokemonPartyPanel.new(@party[i],i,@viewport)
  1002.       else
  1003.         @sprites["pokemon#{i}"] = PokemonPartyBlankPanel.new(@party[i],i,@viewport)
  1004.       end
  1005.       @sprites["pokemon#{i}"].text = annotations[i] if annotations
  1006.     end
  1007.     if @multiselect
  1008.       @sprites["pokemon8"] = PokemonPartyConfirmSprite.new(@viewport)
  1009.       @sprites["pokemon9"] = PokemonPartyCancelSprite2.new(@viewport)
  1010.     else
  1011.       @sprites["pokemon9"] = PokemonPartyCancelSprite.new(@viewport)
  1012.     end
  1013.     # Select first Pokémon
  1014.     @activecmd = 0
  1015.     @sprites["pokemon0"].selected = true
  1016.     pbFadeInAndShow(@sprites) { update }
  1017.    else
  1018.     @sprites = {}
  1019.     @party = party
  1020.     @viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  1021.     @viewport.z = 99999
  1022.     @multiselect = multiselect
  1023.     addBackgroundPlane(@sprites,"partybg","Party/bg",@viewport)
  1024.     @sprites["messagebox"] = Window_AdvancedTextPokemon.new("")
  1025.     @sprites["messagebox"].viewport       = @viewport
  1026.     @sprites["messagebox"].visible        = false
  1027.     @sprites["messagebox"].letterbyletter = true
  1028.     pbBottomLeftLines(@sprites["messagebox"],2)
  1029.     @sprites["helpwindow"] = Window_UnformattedTextPokemon.new(starthelptext)
  1030.     @sprites["helpwindow"].viewport = @viewport
  1031.     @sprites["helpwindow"].visible  = true
  1032.     pbBottomLeftLines(@sprites["helpwindow"],1)
  1033.     pbSetHelpText(starthelptext)
  1034.     # Add party Pokémon sprites
  1035.     for i in 0...6
  1036.       if @party[i]
  1037.         @sprites["pokemon#{i}"] = PokemonPartyPanel.new(@party[i],i,@viewport)
  1038.       else
  1039.         @sprites["pokemon#{i}"] = PokemonPartyBlankPanel.new(@party[i],i,@viewport)
  1040.       end
  1041.       @sprites["pokemon#{i}"].text = annotations[i] if annotations
  1042.     end
  1043.     if @multiselect
  1044.       @sprites["pokemon6"] = PokemonPartyConfirmSprite.new(@viewport)
  1045.       @sprites["pokemon7"] = PokemonPartyCancelSprite2.new(@viewport)
  1046.     else
  1047.       @sprites["pokemon6"] = PokemonPartyCancelSprite.new(@viewport)
  1048.     end
  1049.     # Select first Pokémon
  1050.     @activecmd = 0
  1051.     @sprites["pokemon0"].selected = true
  1052.     pbFadeInAndShow(@sprites) { update }
  1053.    end
  1054.   end
  1055.  
  1056.   def pbEndScene
  1057.     pbFadeOutAndHide(@sprites) { update }
  1058.     pbDisposeSpriteHash(@sprites)
  1059.     @viewport.dispose
  1060.   end
  1061.  
  1062.   def pbDisplay(text)
  1063.     @sprites["messagebox"].text    = text
  1064.     @sprites["messagebox"].visible = true
  1065.     @sprites["helpwindow"].visible = false
  1066.     pbPlayDecisionSE
  1067.     loop do
  1068.       Graphics.update
  1069.       Input.update
  1070.       self.update
  1071.       if @sprites["messagebox"].busy?
  1072.         if Input.trigger?(Input::C)
  1073.           pbPlayDecisionSE if @sprites["messagebox"].pausing?
  1074.           @sprites["messagebox"].resume
  1075.         end
  1076.       else
  1077.         if Input.trigger?(Input::B) || Input.trigger?(Input::C)
  1078.           break
  1079.         end
  1080.       end
  1081.     end
  1082.     @sprites["messagebox"].visible = false
  1083.     @sprites["helpwindow"].visible = true
  1084.   end
  1085.  
  1086.   def pbDisplayConfirm(text)
  1087.     ret = -1
  1088.     @sprites["messagebox"].text    = text
  1089.     @sprites["messagebox"].visible = true
  1090.     @sprites["helpwindow"].visible = false
  1091.     using(cmdwindow = Window_CommandPokemon.new([_INTL("Yes"),_INTL("No")])) {
  1092.       cmdwindow.visible = false
  1093.       pbBottomRight(cmdwindow)
  1094.       cmdwindow.y -= @sprites["messagebox"].height
  1095.       cmdwindow.z = @viewport.z+1
  1096.       loop do
  1097.         Graphics.update
  1098.         Input.update
  1099.         cmdwindow.visible = true if !@sprites["messagebox"].busy?
  1100.         cmdwindow.update
  1101.         self.update
  1102.         if !@sprites["messagebox"].busy?
  1103.           if Input.trigger?(Input::B)
  1104.             ret = false
  1105.             break
  1106.           elsif Input.trigger?(Input::C) && @sprites["messagebox"].resume
  1107.             ret = (cmdwindow.index==0)
  1108.             break
  1109.           end
  1110.         end
  1111.       end
  1112.     }
  1113.     @sprites["messagebox"].visible = false
  1114.     @sprites["helpwindow"].visible = true
  1115.     return ret
  1116.   end
  1117.  
  1118.   def pbShowCommands(helptext,commands,index=0)
  1119.     ret = -1
  1120.     helpwindow = @sprites["helpwindow"]
  1121.     helpwindow.visible = true
  1122.     using(cmdwindow = Window_CommandPokemonColor.new(commands)) {
  1123.       cmdwindow.z     = @viewport.z+1
  1124.       cmdwindow.index = index
  1125.       pbBottomRight(cmdwindow)
  1126.       helpwindow.resizeHeightToFit(helptext,Graphics.width-cmdwindow.width)
  1127.       helpwindow.text = helptext
  1128.       pbBottomLeft(helpwindow)
  1129.       loop do
  1130.         Graphics.update
  1131.         Input.update
  1132.         cmdwindow.update
  1133.         self.update
  1134.         if Input.trigger?(Input::B)
  1135.           pbPlayCancelSE
  1136.           ret = -1
  1137.           break
  1138.         elsif Input.trigger?(Input::C)
  1139.           pbPlayDecisionSE
  1140.           ret = cmdwindow.index
  1141.           break
  1142.         end
  1143.       end
  1144.     }
  1145.     return ret
  1146.   end
  1147.  
  1148.   def pbMessageFreeText(text,startMsg,maxlength)   # Unused
  1149.     return Kernel.pbMessageFreeText(
  1150.        _INTL("Please enter a message (max. {1} characters).",maxlength),
  1151.        startMsg,false,maxlength,Graphics.width) { update }
  1152.   end
  1153.  
  1154.   def pbSetHelpText(helptext)
  1155.     helpwindow = @sprites["helpwindow"]
  1156.     pbBottomLeftLines(helpwindow,1)
  1157.     helpwindow.text = helptext
  1158.     helpwindow.width = 398
  1159.     helpwindow.visible = true
  1160.   end
  1161.  
  1162.   def pbAnnotate(annot)
  1163.   if $Trainer.partyplus
  1164.     for i in 0...8
  1165.       @sprites["pokemon#{i}"].text = (annot) ? annot[i] : nil
  1166.     end
  1167.     else
  1168.     for i in 0...6
  1169.       @sprites["pokemon#{i}"].text = (annot) ? annot[i] : nil
  1170.     end
  1171.   end
  1172.  end
  1173.  
  1174.   def pbPreSelect(item)
  1175.     @activecmd = item
  1176.   end
  1177.  
  1178.   def pbSwitchBegin(oldid,newid)
  1179.     oldsprite = @sprites["pokemon#{oldid}"]
  1180.     newsprite = @sprites["pokemon#{newid}"]
  1181.     16.times do
  1182.       oldsprite.x += (oldid&1)==0 ? -16 : 16
  1183.       newsprite.x += (newid&1)==0 ? -16 : 16
  1184.       Graphics.update
  1185.       Input.update
  1186.       self.update
  1187.     end
  1188.   end
  1189.  
  1190.   def pbSwitchEnd(oldid,newid)
  1191.    if $Trainer.partyplus
  1192.     oldsprite = @sprites["pokemon#{oldid}"]
  1193.     newsprite = @sprites["pokemon#{newid}"]
  1194.     oldsprite.pokemon = @party[oldid]
  1195.     newsprite.pokemon = @party[newid]
  1196.     16.times do
  1197.       oldsprite.x -= (oldid&1)==0 ? -16 : 16
  1198.       newsprite.x -= (newid&1)==0 ? -16 : 16
  1199.       Graphics.update
  1200.       Input.update
  1201.       self.update
  1202.     end
  1203.     for i in 0...8
  1204.       @sprites["pokemon#{i}"].preselected = false
  1205.       @sprites["pokemon#{i}"].switching   = false
  1206.     end
  1207.     pbRefresh
  1208.   else
  1209.     oldsprite = @sprites["pokemon#{oldid}"]
  1210.     newsprite = @sprites["pokemon#{newid}"]
  1211.     oldsprite.pokemon = @party[oldid]
  1212.     newsprite.pokemon = @party[newid]
  1213.     16.times do
  1214.       oldsprite.x -= (oldid&1)==0 ? -16 : 16
  1215.       newsprite.x -= (newid&1)==0 ? -16 : 16
  1216.       Graphics.update
  1217.       Input.update
  1218.       self.update
  1219.     end
  1220.     for i in 0...6
  1221.       @sprites["pokemon#{i}"].preselected = false
  1222.       @sprites["pokemon#{i}"].switching   = false
  1223.     end
  1224.     pbRefresh
  1225.     end
  1226.   end
  1227.  
  1228.   def pbClearSwitching
  1229.    if $Trainer.partyplus
  1230.     for i in 0...8
  1231.       @sprites["pokemon#{i}"].preselected = false
  1232.       @sprites["pokemon#{i}"].switching   = false
  1233.     end
  1234.   else
  1235.     for i in 0...6
  1236.       @sprites["pokemon#{i}"].preselected = false
  1237.       @sprites["pokemon#{i}"].switching   = false
  1238.     end
  1239.     end
  1240.   end
  1241.  
  1242.   def pbSummary(pkmnid)
  1243.     oldsprites = pbFadeOutAndHide(@sprites)
  1244.     scene = PokemonSummary_Scene.new
  1245.     screen = PokemonSummaryScreen.new(scene)
  1246.     screen.pbStartScreen(@party,pkmnid)
  1247.     pbFadeInAndShow(@sprites,oldsprites)
  1248.   end
  1249.  
  1250.   def pbChooseItem(bag)
  1251.     ret = 0
  1252.     pbFadeOutIn(99999){
  1253.       scene = PokemonBag_Scene.new
  1254.       screen = PokemonBagScreen.new(scene,bag)
  1255.       ret = screen.pbChooseItemScreen(Proc.new{|item| pbCanHoldItem?(item) })
  1256.     }
  1257.     return ret
  1258.   end
  1259.  
  1260.   def pbUseItem(bag,pokemon)
  1261.     ret = 0
  1262.     pbFadeOutIn(99999){
  1263.       scene = PokemonBag_Scene.new
  1264.       screen = PokemonBagScreen.new(scene,bag)
  1265.       ret = screen.pbChooseItemScreen(Proc.new{|item|
  1266.         next false if !pbCanUseOnPokemon?(item)
  1267.         if pbIsMachine?(item)
  1268.           move = pbGetMachine(item)
  1269.           next false if pokemon.hasMove?(move) || !pokemon.isCompatibleWithMove?(move)
  1270.         end
  1271.         next true
  1272.       })
  1273.     }
  1274.     return ret
  1275.   end
  1276.  
  1277.   def pbChoosePokemon(switching=false,initialsel=-1,canswitch=0)
  1278.   if $Trainer.partyplus
  1279.     for i in 0...8
  1280.       @sprites["pokemon#{i}"].preselected = (switching && i==@activecmd)
  1281.       @sprites["pokemon#{i}"].switching   = switching
  1282.     end
  1283.     @activecmd = initialsel if initialsel>=0
  1284.     pbRefresh
  1285.     loop do
  1286.       Graphics.update
  1287.       Input.update
  1288.       self.update
  1289.       oldsel = @activecmd
  1290.       key = -1
  1291.       key = Input::DOWN if Input.repeat?(Input::DOWN)
  1292.       key = Input::RIGHT if Input.repeat?(Input::RIGHT)
  1293.       key = Input::LEFT if Input.repeat?(Input::LEFT)
  1294.       key = Input::UP if Input.repeat?(Input::UP)
  1295.       if key>=0
  1296.         @activecmd = pbChangeSelection(key,@activecmd)
  1297.       end
  1298.       if @activecmd!=oldsel # Changing selection
  1299.         pbPlayCursorSE
  1300.         numsprites = (@multiselect) ? 9 : 8
  1301.         for i in 0...numsprites
  1302.           @sprites["pokemon#{i}"].selected = (i==@activecmd)
  1303.         end
  1304.       end
  1305.       cancelsprite = (@multiselect) ? 9 : 8
  1306.       if Input.trigger?(Input::A) && canswitch==1 && @activecmd!=cancelsprite
  1307.         pbPlayDecisionSE
  1308.         return [1,@activecmd]
  1309.       elsif Input.trigger?(Input::A) && canswitch==2
  1310.         return -1
  1311.       elsif Input.trigger?(Input::B)
  1312.         return -1
  1313.       elsif Input.trigger?(Input::C)
  1314.         pbPlayDecisionSE
  1315.         return (@activecmd==cancelsprite) ? -1 : @activecmd
  1316.       end
  1317.     end
  1318.     else
  1319.     for i in 0...6
  1320.       @sprites["pokemon#{i}"].preselected = (switching && i==@activecmd)
  1321.       @sprites["pokemon#{i}"].switching   = switching
  1322.     end
  1323.     @activecmd = initialsel if initialsel>=0
  1324.     pbRefresh
  1325.     loop do
  1326.       Graphics.update
  1327.       Input.update
  1328.       self.update
  1329.       oldsel = @activecmd
  1330.       key = -1
  1331.       key = Input::DOWN if Input.repeat?(Input::DOWN)
  1332.       key = Input::RIGHT if Input.repeat?(Input::RIGHT)
  1333.       key = Input::LEFT if Input.repeat?(Input::LEFT)
  1334.       key = Input::UP if Input.repeat?(Input::UP)
  1335.       if key>=0
  1336.         @activecmd = pbChangeSelection(key,@activecmd)
  1337.       end
  1338.       if @activecmd!=oldsel # Changing selection
  1339.         pbPlayCursorSE
  1340.         numsprites = (@multiselect) ? 8 : 7
  1341.         for i in 0...numsprites
  1342.           @sprites["pokemon#{i}"].selected = (i==@activecmd)
  1343.         end
  1344.       end
  1345.       cancelsprite = (@multiselect) ? 7 : 6
  1346.       if Input.trigger?(Input::A) && canswitch==1 && @activecmd!=cancelsprite
  1347.         pbPlayDecisionSE
  1348.         return [1,@activecmd]
  1349.       elsif Input.trigger?(Input::A) && canswitch==2
  1350.         return -1
  1351.       elsif Input.trigger?(Input::B)
  1352.         return -1
  1353.       elsif Input.trigger?(Input::C)
  1354.         pbPlayDecisionSE
  1355.         return (@activecmd==cancelsprite) ? -1 : @activecmd
  1356.       end
  1357.     end
  1358.   end
  1359.  end
  1360.  
  1361.   def pbChangeSelection(key,currentsel)
  1362.   if $Trainer.partyplus
  1363.     numsprites = (@multiselect) ? 10 : 9
  1364.     case key
  1365.     when Input::LEFT
  1366.       begin
  1367.         currentsel -= 1
  1368.       end while currentsel>0 && currentsel<@party.length && !@party[currentsel]
  1369.       if currentsel>=@party.length && currentsel<8
  1370.         currentsel = @party.length-1
  1371.       end
  1372.       currentsel = numsprites-1 if currentsel<0
  1373.     when Input::RIGHT
  1374.       begin
  1375.         currentsel += 1
  1376.       end while currentsel<@party.length && !@party[currentsel]
  1377.       if currentsel==@party.length
  1378.         currentsel = 8
  1379.       elsif currentsel==numsprites
  1380.         currentsel = 0
  1381.       end
  1382.     when Input::UP
  1383.       if currentsel>=8
  1384.         begin
  1385.           currentsel -= 1
  1386.         end while currentsel>0 && !@party[currentsel]
  1387.       else
  1388.         begin
  1389.           currentsel -= 2
  1390.         end while currentsel>0 && !@party[currentsel]
  1391.       end
  1392.       if currentsel>=@party.length && currentsel<8
  1393.         currentsel = @party.length-1
  1394.       end
  1395.       currentsel = numsprites-1 if currentsel<0
  1396.     when Input::DOWN
  1397.       if currentsel>=7
  1398.         currentsel += 1
  1399.       else
  1400.         currentsel += 2
  1401.         currentsel = 8 if currentsel<8 && !@party[currentsel]
  1402.       end
  1403.       if currentsel>=@party.length && currentsel<8
  1404.         currentsel = 8
  1405.       elsif currentsel>=numsprites
  1406.         currentsel = 0
  1407.       end
  1408.     end
  1409.     return currentsel
  1410.     else
  1411.     numsprites=(@multiselect) ? 8 : 7
  1412.     case key
  1413.     when Input::LEFT
  1414.       begin
  1415.         currentsel-=1
  1416.       end while currentsel>0 && currentsel<@party.length && !@party[currentsel]
  1417.       if currentsel>=@party.length && currentsel<6
  1418.         currentsel=@party.length-1
  1419.       end
  1420.       currentsel=numsprites-1 if currentsel<0
  1421.     when Input::RIGHT
  1422.       begin
  1423.         currentsel+=1
  1424.       end while currentsel<@party.length && !@party[currentsel]
  1425.       if currentsel==@party.length
  1426.         currentsel=6
  1427.       elsif currentsel==numsprites
  1428.         currentsel=0
  1429.       end
  1430.     when Input::UP
  1431.       if currentsel>=6
  1432.         begin
  1433.           currentsel-=1
  1434.         end while currentsel>0 && !@party[currentsel]
  1435.       else
  1436.         begin
  1437.           currentsel-=2
  1438.         end while currentsel>0 && !@party[currentsel]
  1439.       end
  1440.       if currentsel>=@party.length && currentsel<6
  1441.         currentsel=@party.length-1
  1442.       end
  1443.       currentsel=numsprites-1 if currentsel<0
  1444.     when Input::DOWN
  1445.       if currentsel>=5
  1446.         currentsel+=1
  1447.       else
  1448.         currentsel+=2
  1449.         currentsel=6 if currentsel<6 && !@party[currentsel]
  1450.       end
  1451.       if currentsel>=@party.length && currentsel<6
  1452.         currentsel=6
  1453.       elsif currentsel>=numsprites
  1454.         currentsel=0
  1455.       end
  1456.     end
  1457.     return currentsel
  1458.    end
  1459.   end
  1460.  
  1461.   def pbHardRefresh
  1462.   if $Trainer.partyplus
  1463.     oldtext = []
  1464.     lastselected = -1
  1465.     for i in 0...8
  1466.       oldtext.push(@sprites["pokemon#{i}"].text)
  1467.       lastselected = i if @sprites["pokemon#{i}"].selected
  1468.       @sprites["pokemon#{i}"].dispose
  1469.     end
  1470.     lastselected = @party.length-1 if lastselected>=@party.length
  1471.     lastselected = 0 if lastselected<0
  1472.     for i in 0...8
  1473.       if @party[i]
  1474.         @sprites["pokemon#{i}"] = PokemonPartyPanel.new(@party[i],i,@viewport)
  1475.       else
  1476.         @sprites["pokemon#{i}"] = PokemonPartyBlankPanel.new(@party[i],i,@viewport)
  1477.       end
  1478.       @sprites["pokemon#{i}"].text = oldtext[i]
  1479.     end
  1480.     pbSelect(lastselected)
  1481.     else
  1482.     oldtext = []
  1483.     lastselected = -1
  1484.     for i in 0...6
  1485.       oldtext.push(@sprites["pokemon#{i}"].text)
  1486.       lastselected = i if @sprites["pokemon#{i}"].selected
  1487.       @sprites["pokemon#{i}"].dispose
  1488.     end
  1489.     lastselected = @party.length-1 if lastselected>=@party.length
  1490.     lastselected = 0 if lastselected<0
  1491.     for i in 0...6
  1492.       if @party[i]
  1493.         @sprites["pokemon#{i}"] = PokemonPartyPanel.new(@party[i],i,@viewport)
  1494.       else
  1495.         @sprites["pokemon#{i}"] = PokemonPartyBlankPanel.new(@party[i],i,@viewport)
  1496.       end
  1497.       @sprites["pokemon#{i}"].text = oldtext[i]
  1498.     end
  1499.     pbSelect(lastselected)
  1500.     end
  1501.   end
  1502.  
  1503.   def pbRefresh
  1504.   if $Trainer.partyplus
  1505.     for i in 0...8
  1506.       sprite = @sprites["pokemon#{i}"]
  1507.       if sprite
  1508.         if sprite.is_a?(PokemonPartyPanel)
  1509.           sprite.pokemon = sprite.pokemon
  1510.         else
  1511.           sprite.refresh
  1512.         end
  1513.       end
  1514.     end
  1515.     else
  1516.         for i in 0...6
  1517.       sprite = @sprites["pokemon#{i}"]
  1518.       if sprite
  1519.         if sprite.is_a?(PokemonPartyPanel)
  1520.           sprite.pokemon = sprite.pokemon
  1521.         else
  1522.           sprite.refresh
  1523.         end
  1524.       end
  1525.     end
  1526.   end
  1527. end
  1528.  
  1529.   def pbRefreshSingle(i)
  1530.     sprite = @sprites["pokemon#{i}"]
  1531.     if sprite
  1532.       if sprite.is_a?(PokemonPartyPanel)
  1533.         sprite.pokemon = sprite.pokemon
  1534.       else
  1535.         sprite.refresh
  1536.       end
  1537.     end
  1538.   end
  1539.  
  1540.   def update
  1541.     pbUpdateSpriteHash(@sprites)
  1542.   end
  1543. end
  1544.  
  1545. #===============================================================================
  1546. # Pokémon party mechanics
  1547. #===============================================================================
  1548. class PokemonPartyScreen
  1549.   attr_reader :scene
  1550.   attr_reader :party
  1551.  
  1552.   def initialize(scene,party)
  1553.     @scene = scene
  1554.     @party = party
  1555.   end
  1556.  
  1557.   def pbStartScene(helptext,doublebattle,annotations=nil)
  1558.     @scene.pbStartScene(@party,helptext,annotations)
  1559.   end
  1560.  
  1561.   def pbChoosePokemon(helptext=nil)
  1562.     @scene.pbSetHelpText(helptext) if helptext
  1563.     return @scene.pbChoosePokemon
  1564.   end
  1565.  
  1566.   def pbPokemonGiveScreen(item)
  1567.     @scene.pbStartScene(@party,_INTL("Give to which Pokémon?"))
  1568.     pkmnid = @scene.pbChoosePokemon
  1569.     ret = false
  1570.     if pkmnid>=0
  1571.       ret = pbGiveItemToPokemon(item,@party[pkmnid],self,pkmnid)
  1572.     end
  1573.     pbRefreshSingle(pkmnid)
  1574.     @scene.pbEndScene
  1575.     return ret
  1576.   end
  1577.  
  1578.   def pbPokemonGiveMailScreen(mailIndex)
  1579.     @scene.pbStartScene(@party,_INTL("Give to which Pokémon?"))
  1580.     pkmnid = @scene.pbChoosePokemon
  1581.     if pkmnid>=0
  1582.       pkmn = @party[pkmnid]
  1583.       if pkmn.hasItem? || pkmn.mail
  1584.         pbDisplay(_INTL("This Pokémon is holding an item. It can't hold mail."))
  1585.       elsif pkmn.egg?
  1586.         pbDisplay(_INTL("Eggs can't hold mail."))
  1587.       else
  1588.         pbDisplay(_INTL("Mail was transferred from the Mailbox."))
  1589.         pkmn.mail = $PokemonGlobal.mailbox[mailIndex]
  1590.         pkmn.setItem(pkmn.mail.item)
  1591.         $PokemonGlobal.mailbox.delete_at(mailIndex)
  1592.         pbRefreshSingle(pkmnid)
  1593.       end
  1594.     end
  1595.     @scene.pbEndScene
  1596.   end
  1597.  
  1598.   def pbEndScene
  1599.     @scene.pbEndScene
  1600.   end
  1601.  
  1602.   def pbUpdate
  1603.     @scene.update
  1604.   end
  1605.  
  1606.   def pbHardRefresh
  1607.     @scene.pbHardRefresh
  1608.   end
  1609.  
  1610.   def pbRefresh
  1611.     @scene.pbRefresh
  1612.   end
  1613.  
  1614.   def pbRefreshSingle(i)
  1615.     @scene.pbRefreshSingle(i)
  1616.   end
  1617.  
  1618.   def pbDisplay(text)
  1619.     @scene.pbDisplay(text)
  1620.   end
  1621.  
  1622.   def pbConfirm(text)
  1623.     return @scene.pbDisplayConfirm(text)
  1624.   end
  1625.  
  1626.   def pbShowCommands(helptext,commands,index=0)
  1627.     @scene.pbShowCommands(helptext,commands,index)
  1628.   end
  1629.  
  1630.   # Checks for identical species
  1631.   def pbCheckSpecies(array)   # Unused
  1632.     for i in 0...array.length
  1633.       for j in i+1...array.length
  1634.         return false if array[i].species==array[j].species
  1635.       end
  1636.     end
  1637.     return true
  1638.   end
  1639.  
  1640.   # Checks for identical held items
  1641.   def pbCheckItems(array)   # Unused
  1642.     for i in 0...array.length
  1643.       next if !array[i].hasItem?
  1644.       for j in i+1...array.length
  1645.         return false if array[i].item==array[j].item
  1646.       end
  1647.     end
  1648.     return true
  1649.   end
  1650.  
  1651.   def pbSwitch(oldid,newid)
  1652.     if oldid!=newid
  1653.       @scene.pbSwitchBegin(oldid,newid)
  1654.       tmp = @party[oldid]
  1655.       @party[oldid] = @party[newid]
  1656.       @party[newid] = tmp
  1657.       @scene.pbSwitchEnd(oldid,newid)
  1658.     end
  1659.   end
  1660.  
  1661.   def pbChooseMove(pokemon,helptext,index=0)
  1662.     movenames = []
  1663.     for i in pokemon.moves
  1664.       break if i.id==0
  1665.       if i.totalpp==0
  1666.         movenames.push(_INTL("{1} (PP: ---)",PBMoves.getName(i.id),i.pp,i.totalpp))
  1667.       else
  1668.         movenames.push(_INTL("{1} (PP: {2}/{3})",PBMoves.getName(i.id),i.pp,i.totalpp))
  1669.       end
  1670.     end
  1671.     return @scene.pbShowCommands(helptext,movenames,index)
  1672.   end
  1673.  
  1674.   def pbRefreshAnnotations(ableProc)   # For after using an evolution stone
  1675.     annot = []
  1676.     for pkmn in @party
  1677.       elig = ableProc.call(pkmn)
  1678.       annot.push((elig) ? _INTL("ABLE") : _INTL("NOT ABLE"))
  1679.     end
  1680.     @scene.pbAnnotate(annot)
  1681.   end
  1682.  
  1683.   def pbClearAnnotations
  1684.     @scene.pbAnnotate(nil)
  1685.   end
  1686.  
  1687.   def pbPokemonMultipleEntryScreenEx(ruleset)
  1688.     annot = []
  1689.     statuses = []
  1690.     ordinals = [
  1691.        _INTL("INELIGIBLE"),
  1692.        _INTL("NOT ENTERED"),
  1693.        _INTL("BANNED"),
  1694.        _INTL("FIRST"),
  1695.        _INTL("SECOND"),
  1696.        _INTL("THIRD"),
  1697.        _INTL("FOURTH"),
  1698.        _INTL("FIFTH"),
  1699.        _INTL("SIXTH")
  1700.     ]
  1701.     return nil if !ruleset.hasValidTeam?(@party)
  1702.     ret = nil
  1703.     addedEntry = false
  1704.     for i in 0...@party.length
  1705.       statuses[i] = (ruleset.isPokemonValid?(@party[i])) ? 1 : 2
  1706.     end
  1707.     for i in 0...@party.length
  1708.       annot[i] = ordinals[statuses[i]]
  1709.     end
  1710.     @scene.pbStartScene(@party,_INTL("Choose Pokémon and confirm."),annot,true)
  1711.     loop do
  1712.       realorder = []
  1713.       for i in 0...@party.length
  1714.         for j in 0...@party.length
  1715.           if statuses[j]==i+3
  1716.             realorder.push(j)
  1717.             break
  1718.           end
  1719.         end
  1720.       end
  1721.       for i in 0...realorder.length
  1722.         statuses[realorder[i]] = i+3
  1723.       end
  1724.       for i in 0...@party.length
  1725.         annot[i] = ordinals[statuses[i]]
  1726.       end
  1727.       @scene.pbAnnotate(annot)
  1728.       if realorder.length==ruleset.number && addedEntry
  1729.         @scene.pbSelect(6)
  1730.       end
  1731.       @scene.pbSetHelpText(_INTL("Choose Pokémon and confirm."))
  1732.       pkmnid = @scene.pbChoosePokemon
  1733.       addedEntry = false
  1734.       if $Trainer.partyplus
  1735.       if pkmnid==8 # Confirm was chosen
  1736.         ret = []
  1737.         for i in realorder; ret.push(@party[i]); end
  1738.         error = []
  1739.         break if ruleset.isValid?(ret,error)
  1740.         pbDisplay(error[0])
  1741.         ret = nil
  1742.       end
  1743.       else
  1744.       if pkmnid==6 # Confirm was chosen
  1745.         ret = []
  1746.         for i in realorder; ret.push(@party[i]); end
  1747.         error = []
  1748.         break if ruleset.isValid?(ret,error)
  1749.         pbDisplay(error[0])
  1750.         ret = nil
  1751.       end
  1752.       end
  1753.       break if pkmnid<0 # Canceled
  1754.       cmdEntry   = -1
  1755.       cmdNoEntry = -1
  1756.       cmdSummary = -1
  1757.       commands = []
  1758.       if (statuses[pkmnid] || 0) == 1
  1759.         commands[cmdEntry = commands.length]   = _INTL("Entry")
  1760.       elsif (statuses[pkmnid] || 0) > 2
  1761.         commands[cmdNoEntry = commands.length] = _INTL("No Entry")
  1762.       end
  1763.       pkmn = @party[pkmnid]
  1764.       commands[cmdSummary = commands.length]   = _INTL("Summary")
  1765.       commands[commands.length]                = _INTL("Cancel")
  1766.       command = @scene.pbShowCommands(_INTL("Do what with {1}?",pkmn.name),commands) if pkmn
  1767.       if cmdEntry>=0 && command==cmdEntry
  1768.         if realorder.length>=ruleset.number && ruleset.number>0
  1769.           pbDisplay(_INTL("No more than {1} Pokémon may enter.",ruleset.number))
  1770.         else
  1771.           statuses[pkmnid] = realorder.length+3
  1772.           addedEntry = true
  1773.           pbRefreshSingle(pkmnid)
  1774.         end
  1775.       elsif cmdNoEntry>=0 && command==cmdNoEntry
  1776.         statuses[pkmnid] = 1
  1777.         pbRefreshSingle(pkmnid)
  1778.       elsif cmdSummary>=0 && command==cmdSummary
  1779.         @scene.pbSummary(pkmnid)
  1780.       end
  1781.     end
  1782.     @scene.pbEndScene
  1783.     return ret
  1784.   end
  1785. end
  1786.  
  1787. #===============================================================================
  1788. # Pokémon party buttons and menu
  1789. #===============================================================================
  1790. class PokemonPartyConfirmCancelSprite < SpriteWrapper
  1791.   attr_reader :selected
  1792.  
  1793.   def initialize(text,x,y,narrowbox=false,viewport=nil)
  1794.     super(viewport)
  1795.     @refreshBitmap = true
  1796.     @bgsprite = ChangelingSprite.new(0,0,viewport)
  1797.     if narrowbox
  1798.       @bgsprite.addBitmap("desel","Graphics/Pictures/Party/Plusicon_cancel_narrow")
  1799.       @bgsprite.addBitmap("sel","Graphics/Pictures/Party/Plusicon_cancel_narrow_sel")
  1800.     else
  1801.       @bgsprite.addBitmap("desel","Graphics/Pictures/Party/icon_cancel")
  1802.       @bgsprite.addBitmap("sel","Graphics/Pictures/Party/icon_cancel_sel")
  1803.     end
  1804.     @bgsprite.changeBitmap("desel")
  1805.     @overlaysprite = BitmapSprite.new(@bgsprite.bitmap.width,@bgsprite.bitmap.height,viewport)
  1806.     @overlaysprite.z = self.z+1
  1807.     pbSetSystemFont(@overlaysprite.bitmap)
  1808.     @yoffset = 8
  1809.     textpos = [[text,56,(narrowbox) ? 2 : 8,2,Color.new(248,248,248),Color.new(40,40,40)]]
  1810.     pbDrawTextPositions(@overlaysprite.bitmap,textpos)
  1811.     self.x = x
  1812.     self.y = y
  1813.   end
  1814.  
  1815.   def dispose
  1816.     @bgsprite.dispose
  1817.     @overlaysprite.bitmap.dispose
  1818.     @overlaysprite.dispose
  1819.     super
  1820.   end
  1821.  
  1822.   def viewport=(value)
  1823.     super
  1824.     refresh
  1825.   end
  1826.  
  1827.   def x=(value)
  1828.     super
  1829.     refresh
  1830.   end
  1831.  
  1832.   def y=(value)
  1833.     super
  1834.     refresh
  1835.   end
  1836.  
  1837.   def color=(value)
  1838.     super
  1839.     refresh
  1840.   end
  1841.  
  1842.   def selected=(value)
  1843.     if @selected!=value
  1844.       @selected = value
  1845.       refresh
  1846.     end
  1847.   end
  1848.  
  1849.   def refresh
  1850.     if @bgsprite && !@bgsprite.disposed?
  1851.       @bgsprite.changeBitmap((@selected) ? "sel" : "desel")
  1852.       @bgsprite.x     = self.x
  1853.       @bgsprite.y     = self.y
  1854.       @bgsprite.color = self.color
  1855.     end
  1856.     if @overlaysprite && !@overlaysprite.disposed?
  1857.       @overlaysprite.x     = self.x
  1858.       @overlaysprite.y     = self.y
  1859.       @overlaysprite.color = self.color
  1860.     end
  1861.   end
  1862. end
  1863.  
  1864. class PokemonPartyCancelSprite < PokemonPartyConfirmCancelSprite
  1865.   def initialize(viewport=nil)
  1866.     super(_INTL("CANCEL"),398,328,false,viewport)
  1867.   end
  1868. end
  1869.  
  1870. class PokemonPartyConfirmSprite < PokemonPartyConfirmCancelSprite
  1871.   def initialize(viewport=nil)
  1872.     super(_INTL("CONFIRM"),398,308,true,viewport)
  1873.   end
  1874. end
  1875.  
  1876. class PokemonPartyCancelSprite2 < PokemonPartyConfirmCancelSprite
  1877.   def initialize(viewport=nil)
  1878.     super(_INTL("CANCEL"),398,346,true,viewport)
  1879.   end
  1880. end
  1881.  
  1882. ################################################################################
  1883. # Storage Scene                                                                #
  1884. ################################################################################
  1885. #===============================================================================
  1886. # Party pop-up panel
  1887. #===============================================================================
  1888. class PokemonBoxPartySprite < SpriteWrapper
  1889.   def initialize(party,viewport=nil)
  1890.   if $Trainer.partyplus
  1891.     super(viewport)
  1892.     @party = party
  1893.     @boxbitmap = AnimatedBitmap.new("Graphics/Pictures/Storage/overlay_partyplus")
  1894.     @pokemonsprites = []
  1895.     for i in 0...8
  1896.       @pokemonsprites[i] = nil
  1897.       pokemon = @party[i]
  1898.       if pokemon
  1899.         @pokemonsprites[i] = PokemonBoxIcon.new(pokemon,viewport)
  1900.       end
  1901.     end
  1902.     @contents = BitmapWrapper.new(172,352)
  1903.     self.bitmap = @contents
  1904.     self.x = 182
  1905.     self.y = Graphics.height-352
  1906.     pbSetSystemFont(self.bitmap)
  1907.     refresh
  1908.     else
  1909.     super(viewport)
  1910.     @party = party
  1911.     @boxbitmap = AnimatedBitmap.new("Graphics/Pictures/Storage/overlay_party")
  1912.     @pokemonsprites = []
  1913.     for i in 0...6
  1914.       @pokemonsprites[i] = nil
  1915.       pokemon = @party[i]
  1916.       if pokemon
  1917.         @pokemonsprites[i] = PokemonBoxIcon.new(pokemon,viewport)
  1918.       end
  1919.     end
  1920.     @contents = BitmapWrapper.new(172,352)
  1921.     self.bitmap = @contents
  1922.     self.x = 182
  1923.     self.y = Graphics.height-352
  1924.     pbSetSystemFont(self.bitmap)
  1925.     refresh
  1926.     end
  1927.   end
  1928.  
  1929.   def dispose
  1930.   if $Trainer.partyplus
  1931.     for i in 0...8
  1932.       @pokemonsprites[i].dispose if @pokemonsprites[i]
  1933.     end
  1934.     @boxbitmap.dispose
  1935.     @contents.dispose
  1936.     super
  1937.     else
  1938.     for i in 0...6
  1939.       @pokemonsprites[i].dispose if @pokemonsprites[i]
  1940.     end
  1941.     @boxbitmap.dispose
  1942.     @contents.dispose
  1943.     super
  1944.     end
  1945.   end
  1946.  
  1947.   def x=(value)
  1948.     super
  1949.     refresh
  1950.   end
  1951.  
  1952.   def y=(value)
  1953.     super
  1954.     refresh
  1955.   end
  1956.  
  1957.   def color=(value)
  1958.   if $Trainer.partyplus
  1959.     super
  1960.     for i in 0...8
  1961.       if @pokemonsprites[i] && !@pokemonsprites[i].disposed?
  1962.         @pokemonsprites[i].color = pbSrcOver(@pokemonsprites[i].color,value)
  1963.       end
  1964.     end
  1965.     else
  1966.     super
  1967.     for i in 0...6
  1968.       if @pokemonsprites[i] && !@pokemonsprites[i].disposed?
  1969.         @pokemonsprites[i].color = pbSrcOver(@pokemonsprites[i].color,value)
  1970.       end
  1971.     end
  1972.     end
  1973.   end
  1974.  
  1975.   def visible=(value)
  1976.   if $Trainer.partyplus
  1977.     super
  1978.     for i in 0...8
  1979.       if @pokemonsprites[i] && !@pokemonsprites[i].disposed?
  1980.         @pokemonsprites[i].visible = value
  1981.       end
  1982.     end
  1983.     else
  1984.         super
  1985.     for i in 0...6
  1986.       if @pokemonsprites[i] && !@pokemonsprites[i].disposed?
  1987.         @pokemonsprites[i].visible = value
  1988.       end
  1989.     end
  1990.    end
  1991.   end
  1992.  
  1993.   def getPokemon(index)
  1994.     return @pokemonsprites[index]
  1995.   end
  1996.  
  1997.   def setPokemon(index,sprite)
  1998.     @pokemonsprites[index] = sprite
  1999.     @pokemonsprites.compact!
  2000.     refresh
  2001.   end
  2002.  
  2003.   def grabPokemon(index,arrow)
  2004.     sprite = @pokemonsprites[index]
  2005.     if sprite
  2006.       arrow.grab(sprite)
  2007.       @pokemonsprites[index] = nil
  2008.       @pokemonsprites.compact!
  2009.       refresh
  2010.     end
  2011.   end
  2012.  
  2013.   def deletePokemon(index)
  2014.     @pokemonsprites[index].dispose
  2015.     @pokemonsprites[index] = nil
  2016.     @pokemonsprites.compact!
  2017.     refresh
  2018.   end
  2019.  
  2020.   def refresh
  2021.   if $Trainer.partyplus
  2022.     @contents.blt(0,0,@boxbitmap.bitmap,Rect.new(0,0,172,352))
  2023.     pbDrawTextPositions(self.bitmap,[
  2024.        [_INTL("Back"),86,306,2,Color.new(248,248,248),Color.new(80,80,80),1]
  2025.     ])
  2026.    
  2027.     xvalues = [18,90,18,90,18,90,18,90]
  2028.     yvalues = [2,18,66,82,130,146,194,210]
  2029.     for j in 0...8
  2030.       @pokemonsprites[j] = nil if @pokemonsprites[j] && @pokemonsprites[j].disposed?
  2031.     end
  2032.     @pokemonsprites.compact!
  2033.     for j in 0...8
  2034.       sprite = @pokemonsprites[j]
  2035.       if sprite && !sprite.disposed?
  2036.         sprite.viewport = self.viewport
  2037.         sprite.x = self.x+xvalues[j]
  2038.         sprite.y = self.y+yvalues[j]
  2039.         sprite.z = 0
  2040.       end
  2041.     end
  2042.     else
  2043.         @contents.blt(0,0,@boxbitmap.bitmap,Rect.new(0,0,172,352))
  2044.     pbDrawTextPositions(self.bitmap,[
  2045.        [_INTL("Back"),86,242,2,Color.new(248,248,248),Color.new(80,80,80),1]
  2046.     ])
  2047.    
  2048.     xvalues = [18,90,18,90,18,90]
  2049.     yvalues = [2,18,66,82,130,146]
  2050.     for j in 0...6
  2051.       @pokemonsprites[j] = nil if @pokemonsprites[j] && @pokemonsprites[j].disposed?
  2052.     end
  2053.     @pokemonsprites.compact!
  2054.     for j in 0...6
  2055.       sprite = @pokemonsprites[j]
  2056.       if sprite && !sprite.disposed?
  2057.         sprite.viewport = self.viewport
  2058.         sprite.x = self.x+xvalues[j]
  2059.         sprite.y = self.y+yvalues[j]
  2060.         sprite.z = 0
  2061.       end
  2062.     end
  2063.    end
  2064.   end
  2065.  
  2066.   def update
  2067.     super
  2068.   if $Trainer.partyplus
  2069.       for i in 0...8
  2070.       @pokemonsprites[i].update if @pokemonsprites[i] && !@pokemonsprites[i].disposed?
  2071.     end
  2072.    else
  2073.     for i in 0...6
  2074.       @pokemonsprites[i].update if @pokemonsprites[i] && !@pokemonsprites[i].disposed?
  2075.      end
  2076.    end
  2077.  end
  2078. end
  2079.  
  2080. #===============================================================================
  2081. # Pokémon storage visuals
  2082. #===============================================================================
  2083. class PokemonStorageScene
  2084.   attr_reader :quickswap
  2085.  
  2086.   def initialize
  2087.     @command = 1
  2088.   end
  2089.  
  2090.   def pbStartBox(screen,command)
  2091.     @screen = screen
  2092.     @storage = screen.storage
  2093.     @bgviewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  2094.     @bgviewport.z = 99999
  2095.     @boxviewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  2096.     @boxviewport.z = 99999
  2097.     @boxsidesviewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  2098.     @boxsidesviewport.z = 99999
  2099.     @arrowviewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  2100.     @arrowviewport.z = 99999
  2101.     @viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  2102.     @viewport.z = 99999
  2103.     @selection = 0
  2104.     @quickswap = false
  2105.     @sprites = {}
  2106.     @choseFromParty = false
  2107.     @command = command
  2108.     addBackgroundPlane(@sprites,"background","Storage/bg",@bgviewport)
  2109.     @sprites["box"] = PokemonBoxSprite.new(@storage,@storage.currentBox,@boxviewport)
  2110.     @sprites["boxsides"] = IconSprite.new(0,0,@boxsidesviewport)
  2111.     @sprites["boxsides"].setBitmap("Graphics/Pictures/Storage/overlay_main")
  2112.     @sprites["overlay"] = BitmapSprite.new(Graphics.width,Graphics.height,@boxsidesviewport)
  2113.     pbSetSystemFont(@sprites["overlay"].bitmap)
  2114.     @sprites["pokemon"] = AutoMosaicPokemonSprite.new(@boxsidesviewport)
  2115.     @sprites["pokemon"].setOffset(PictureOrigin::Center)
  2116.     @sprites["pokemon"].x = 90
  2117.     @sprites["pokemon"].y = 134
  2118.     @sprites["boxparty"] = PokemonBoxPartySprite.new(@storage.party,@boxsidesviewport)
  2119.     if command!=2 # Drop down tab only on Deposit
  2120.       @sprites["boxparty"].x = 182
  2121.       @sprites["boxparty"].y = Graphics.height
  2122.     end
  2123.     @markingbitmap = AnimatedBitmap.new("Graphics/Pictures/Storage/markings")
  2124.     @sprites["markingbg"] = IconSprite.new(292,68,@boxsidesviewport)
  2125.     @sprites["markingbg"].setBitmap("Graphics/Pictures/Storage/overlay_marking")
  2126.     @sprites["markingbg"].visible = false
  2127.     @sprites["markingoverlay"] = BitmapSprite.new(Graphics.width,Graphics.height,@boxsidesviewport)
  2128.     @sprites["markingoverlay"].visible = false
  2129.     pbSetSystemFont(@sprites["markingoverlay"].bitmap)
  2130.     @sprites["arrow"] = PokemonBoxArrow.new(@arrowviewport)
  2131.     @sprites["arrow"].z += 1
  2132.     if command!=2
  2133.       pbSetArrow(@sprites["arrow"],@selection)
  2134.       pbUpdateOverlay(@selection)
  2135.       pbSetMosaic(@selection)
  2136.     else
  2137.       pbPartySetArrow(@sprites["arrow"],@selection)
  2138.       pbUpdateOverlay(@selection,@storage.party)
  2139.       pbSetMosaic(@selection)
  2140.     end
  2141.     pbFadeInAndShow(@sprites)
  2142.   end
  2143.  
  2144.   def pbCloseBox
  2145.     pbFadeOutAndHide(@sprites)  
  2146.     pbDisposeSpriteHash(@sprites)
  2147.     @markingbitmap.dispose if @markingbitmap
  2148.     @boxviewport.dispose
  2149.     @boxsidesviewport.dispose
  2150.     @arrowviewport.dispose
  2151.   end
  2152.  
  2153.   def pbDisplay(message)
  2154.     msgwindow = Window_UnformattedTextPokemon.newWithSize("",180,0,Graphics.width-180,32)
  2155.     msgwindow.viewport       = @viewport
  2156.     msgwindow.visible        = true
  2157.     msgwindow.letterbyletter = false
  2158.     msgwindow.resizeHeightToFit(message,Graphics.width-180)
  2159.     msgwindow.text           = message
  2160.     pbBottomRight(msgwindow)
  2161.     loop do
  2162.       Graphics.update
  2163.       Input.update
  2164.       if Input.trigger?(Input::B) || Input.trigger?(Input::C)
  2165.         break
  2166.       end
  2167.       msgwindow.update
  2168.       self.update
  2169.     end
  2170.     msgwindow.dispose
  2171.     Input.update
  2172.   end
  2173.  
  2174.   def pbShowCommands(message,commands,index=0)
  2175.     ret = 0
  2176.     msgwindow = Window_UnformattedTextPokemon.newWithSize("",180,0,Graphics.width-180,32)
  2177.     msgwindow.viewport       = @viewport
  2178.     msgwindow.visible        = true
  2179.     msgwindow.letterbyletter = false
  2180.     msgwindow.text           = message
  2181.     msgwindow.resizeHeightToFit(message,Graphics.width-180)
  2182.     pbBottomRight(msgwindow)
  2183.     cmdwindow = Window_CommandPokemon.new(commands)
  2184.     cmdwindow.viewport = @viewport
  2185.     cmdwindow.visible  = true
  2186.     cmdwindow.resizeToFit(cmdwindow.commands)
  2187.     cmdwindow.height   = Graphics.height-msgwindow.height if cmdwindow.height>Graphics.height-msgwindow.height
  2188.     pbBottomRight(cmdwindow)
  2189.     cmdwindow.y        -= msgwindow.height
  2190.     cmdwindow.index    = index
  2191.     loop do
  2192.       Graphics.update
  2193.       Input.update
  2194.       msgwindow.update
  2195.       cmdwindow.update
  2196.       if Input.trigger?(Input::B)
  2197.         ret = -1
  2198.         break
  2199.       elsif Input.trigger?(Input::C)
  2200.         ret = cmdwindow.index
  2201.         break
  2202.       end
  2203.       self.update
  2204.     end
  2205.     msgwindow.dispose
  2206.     cmdwindow.dispose
  2207.     Input.update
  2208.     return ret
  2209.   end
  2210.  
  2211.   def pbSetArrow(arrow,selection)
  2212.     case selection
  2213.     when -1, -4, -5 # Box name, move left, move right
  2214.       arrow.x = 157*2
  2215.       arrow.y = -12*2
  2216.     when -2 # Party Pokémon
  2217.       arrow.x = 119*2
  2218.       arrow.y = 139*2
  2219.     when -3 # Close Box
  2220.       arrow.x = 207*2
  2221.       arrow.y = 139*2
  2222.     else
  2223.       arrow.x = (97+24*(selection%6))*2
  2224.       arrow.y = (8+24*(selection/6))*2
  2225.     end
  2226.   end
  2227.  
  2228.   def pbChangeSelection(key,selection)
  2229.     case key
  2230.     when Input::UP
  2231.       if selection==-1 # Box name
  2232.         selection = -2
  2233.       elsif selection==-2 # Party
  2234.         selection = 25
  2235.       elsif selection==-3 # Close Box
  2236.         selection = 28
  2237.       else
  2238.         selection -= 6
  2239.         selection = -1 if selection<0
  2240.       end
  2241.     when Input::DOWN
  2242.       if selection==-1 # Box name
  2243.         selection = 2
  2244.       elsif selection==-2 # Party
  2245.         selection = -1
  2246.       elsif selection==-3 # Close Box
  2247.         selection = -1
  2248.       else
  2249.         selection += 6
  2250.         selection = -2 if selection==30 || selection==31 || selection==32
  2251.         selection = -3 if selection==33 || selection==34 || selection==35
  2252.       end
  2253.     when Input::LEFT
  2254.       if selection==-1 # Box name
  2255.         selection = -4 # Move to previous box
  2256.       elsif selection==-2
  2257.         selection = -3
  2258.       elsif selection==-3
  2259.         selection = -2
  2260.       else
  2261.         selection -= 1
  2262.         selection += 6 if selection==-1 || selection%6==5
  2263.       end
  2264.     when Input::RIGHT
  2265.       if selection==-1 # Box name
  2266.         selection = -5 # Move to next box
  2267.       elsif selection==-2
  2268.         selection = -3
  2269.       elsif selection==-3
  2270.         selection = -2
  2271.       else
  2272.         selection += 1
  2273.         selection -= 6 if selection%6==0
  2274.       end
  2275.     end
  2276.     return selection
  2277.   end
  2278.  
  2279.   def pbPartySetArrow(arrow,selection)
  2280.   if $Trainer.partyplus
  2281.     if selection>=0
  2282.       xvalues = [100,136,100,136,100,136,100,136,118]
  2283.       yvalues = [1,9,33,41,65,73,97,105,142]
  2284.       arrow.angle = 0
  2285.       arrow.mirror = false
  2286.       arrow.ox = 0
  2287.       arrow.oy = 0
  2288.       arrow.x = xvalues[selection]*2
  2289.       arrow.y = yvalues[selection]*2
  2290.     end
  2291.     else
  2292.     if selection>=0
  2293.       xvalues = [100,136,100,136,100,136,118]
  2294.       yvalues = [1,9,33,41,65,73,110]
  2295.       arrow.angle = 0
  2296.       arrow.mirror = false
  2297.       arrow.ox = 0
  2298.       arrow.oy = 0
  2299.       arrow.x = xvalues[selection]*2
  2300.       arrow.y = yvalues[selection]*2
  2301.     end
  2302.    end
  2303.   end
  2304.  
  2305.   def pbPartyChangeSelection(key,selection)
  2306.   if $Trainer.partyplus
  2307.     case key
  2308.     when Input::LEFT
  2309.       selection -= 1
  2310.       selection = 8 if selection<0
  2311.     when Input::RIGHT
  2312.       selection += 1
  2313.       selection = 0 if selection>8
  2314.     when Input::UP
  2315.       if selection==8
  2316.         selection = 7
  2317.       else
  2318.         selection -= 2
  2319.         selection = 8 if selection<0
  2320.       end
  2321.     when Input::DOWN
  2322.       if selection==8
  2323.         selection = 0
  2324.       else
  2325.         selection += 2
  2326.         selection = 8 if selection>8
  2327.       end
  2328.     end
  2329.     return selection
  2330.  else
  2331.     case key
  2332.     when Input::LEFT
  2333.       selection -= 1
  2334.       selection = 6 if selection<0
  2335.     when Input::RIGHT
  2336.       selection += 1
  2337.       selection = 0 if selection>6
  2338.     when Input::UP
  2339.       if selection==6
  2340.         selection = 5
  2341.       else
  2342.         selection -= 2
  2343.         selection = 6 if selection<0
  2344.       end
  2345.     when Input::DOWN
  2346.       if selection==6
  2347.         selection = 0
  2348.       else
  2349.         selection += 2
  2350.         selection = 6 if selection>6
  2351.       end
  2352.     end
  2353.     return selection
  2354.   end
  2355.  end
  2356.  
  2357. def pbSelectBoxInternal(party)
  2358.     selection = @selection
  2359.     pbSetArrow(@sprites["arrow"],selection)
  2360.     pbUpdateOverlay(selection)
  2361.     pbSetMosaic(selection)
  2362.     loop do
  2363.       Graphics.update
  2364.       Input.update
  2365.       key = -1
  2366.       key = Input::DOWN if Input.repeat?(Input::DOWN)
  2367.       key = Input::RIGHT if Input.repeat?(Input::RIGHT)
  2368.       key = Input::LEFT if Input.repeat?(Input::LEFT)
  2369.       key = Input::UP if Input.repeat?(Input::UP)
  2370.       if key>=0
  2371.         pbPlayCursorSE
  2372.         selection = pbChangeSelection(key,selection)
  2373.         pbSetArrow(@sprites["arrow"],selection)
  2374.         if selection==-4
  2375.           nextbox = (@storage.currentBox+@storage.maxBoxes-1)%@storage.maxBoxes
  2376.           pbSwitchBoxToLeft(nextbox)
  2377.           @storage.currentBox = nextbox
  2378.         elsif selection==-5
  2379.           nextbox = (@storage.currentBox+1)%@storage.maxBoxes
  2380.           pbSwitchBoxToRight(nextbox)
  2381.           @storage.currentBox = nextbox
  2382.         end
  2383.         selection = -1 if selection==-4 || selection==-5
  2384.         pbUpdateOverlay(selection)
  2385.         pbSetMosaic(selection)
  2386.       end
  2387.       self.update
  2388.       if Input.trigger?(Input::L)
  2389.         pbPlayCursorSE
  2390.         nextbox = (@storage.currentBox+@storage.maxBoxes-1)%@storage.maxBoxes
  2391.         pbSwitchBoxToLeft(nextbox)
  2392.         @storage.currentBox = nextbox
  2393.         pbUpdateOverlay(selection)
  2394.         pbSetMosaic(selection)
  2395.       elsif Input.trigger?(Input::R)
  2396.         pbPlayCursorSE
  2397.         nextbox = (@storage.currentBox+1)%@storage.maxBoxes
  2398.         pbSwitchBoxToRight(nextbox)
  2399.         @storage.currentBox = nextbox
  2400.         pbUpdateOverlay(selection)
  2401.         pbSetMosaic(selection)
  2402.       elsif Input.trigger?(Input::F5)   # Jump to box name
  2403.         if selection!=-1
  2404.           pbPlayCursorSE
  2405.           selection = -1
  2406.           pbSetArrow(@sprites["arrow"],selection)
  2407.           pbUpdateOverlay(selection)
  2408.           pbSetMosaic(selection)
  2409.         end
  2410.       elsif Input.trigger?(Input::A) && @command==0   # Organize only
  2411.         pbPlayDecisionSE
  2412.         pbSetQuickSwap(!@quickswap)
  2413.       elsif Input.trigger?(Input::B)
  2414.         @selection = selection
  2415.         return nil
  2416.       elsif Input.trigger?(Input::C)
  2417.         @selection = selection
  2418.         if selection>=0
  2419.           return [@storage.currentBox,selection]
  2420.         elsif selection==-1 # Box name
  2421.           return [-4,-1]
  2422.         elsif selection==-2 # Party Pokémon
  2423.           return [-2,-1]
  2424.         elsif selection==-3 # Close Box
  2425.           return [-3,-1]
  2426.         end
  2427.       end
  2428.     end
  2429.   end
  2430.  
  2431.   def pbSelectBox(party)
  2432.     return pbSelectBoxInternal(party) if @command==1 # Withdraw
  2433.     ret = nil
  2434.     loop do
  2435.       if !@choseFromParty
  2436.         ret = pbSelectBoxInternal(party)
  2437.       end
  2438.       if @choseFromParty || (ret && ret[0]==-2) # Party Pokémon
  2439.         if !@choseFromParty
  2440.           pbShowPartyTab
  2441.           @selection = 0
  2442.         end
  2443.         ret = pbSelectPartyInternal(party,false)
  2444.         if ret<0
  2445.           pbHidePartyTab
  2446.           @selection = 0
  2447.           @choseFromParty = false
  2448.         else
  2449.           @choseFromParty = true
  2450.           return [-1,ret]
  2451.         end
  2452.       else
  2453.         @choseFromParty = false
  2454.         return ret
  2455.       end
  2456.     end
  2457.   end
  2458.  
  2459.   def pbSelectPartyInternal(party,depositing)
  2460.   if $Trainer.partyplus
  2461.     selection = @selection
  2462.     pbPartySetArrow(@sprites["arrow"],selection)
  2463.     pbUpdateOverlay(selection,party)
  2464.     pbSetMosaic(selection)
  2465.     lastsel = 1
  2466.     loop do
  2467.       Graphics.update
  2468.       Input.update
  2469.       key = -1
  2470.       key = Input::DOWN if Input.repeat?(Input::DOWN)
  2471.       key = Input::RIGHT if Input.repeat?(Input::RIGHT)
  2472.       key = Input::LEFT if Input.repeat?(Input::LEFT)
  2473.       key = Input::UP if Input.repeat?(Input::UP)
  2474.       if key>=0
  2475.         pbPlayCursorSE
  2476.         newselection = pbPartyChangeSelection(key,selection)
  2477.         if newselection==-1
  2478.           return -1 if !depositing
  2479.         elsif newselection==-2
  2480.           selection = lastsel
  2481.         else
  2482.           selection = newselection
  2483.         end
  2484.         pbPartySetArrow(@sprites["arrow"],selection)
  2485.         lastsel = selection if selection>0
  2486.         pbUpdateOverlay(selection,party)
  2487.         pbSetMosaic(selection)
  2488.       end
  2489.       self.update
  2490.       if Input.trigger?(Input::A) && @command==0   # Organize only
  2491.         pbPlayDecisionSE
  2492.         pbSetQuickSwap(!@quickswap)
  2493.       elsif Input.trigger?(Input::B)
  2494.         @selection = selection
  2495.         return -1
  2496.       elsif Input.trigger?(Input::C)
  2497.         if selection>=0 && selection<8
  2498.           @selection = selection
  2499.           return selection
  2500.         elsif selection==8   # Close Box
  2501.           @selection = selection
  2502.           return (depositing) ? -3 : -1
  2503.         end
  2504.       end
  2505.     end
  2506.     else
  2507.     selection = @selection
  2508.     pbPartySetArrow(@sprites["arrow"],selection)
  2509.     pbUpdateOverlay(selection,party)
  2510.     pbSetMosaic(selection)
  2511.     lastsel = 1
  2512.     loop do
  2513.       Graphics.update
  2514.       Input.update
  2515.       key = -1
  2516.       key = Input::DOWN if Input.repeat?(Input::DOWN)
  2517.       key = Input::RIGHT if Input.repeat?(Input::RIGHT)
  2518.       key = Input::LEFT if Input.repeat?(Input::LEFT)
  2519.       key = Input::UP if Input.repeat?(Input::UP)
  2520.       if key>=0
  2521.         pbPlayCursorSE
  2522.         newselection = pbPartyChangeSelection(key,selection)
  2523.         if newselection==-1
  2524.           return -1 if !depositing
  2525.         elsif newselection==-2
  2526.           selection = lastsel
  2527.         else
  2528.           selection = newselection
  2529.         end
  2530.         pbPartySetArrow(@sprites["arrow"],selection)
  2531.         lastsel = selection if selection>0
  2532.         pbUpdateOverlay(selection,party)
  2533.         pbSetMosaic(selection)
  2534.       end
  2535.       self.update
  2536.       if Input.trigger?(Input::A) && @command==0   # Organize only
  2537.         pbPlayDecisionSE
  2538.         pbSetQuickSwap(!@quickswap)
  2539.       elsif Input.trigger?(Input::B)
  2540.         @selection = selection
  2541.         return -1
  2542.       elsif Input.trigger?(Input::C)
  2543.         if selection>=0 && selection<6
  2544.           @selection = selection
  2545.           return selection
  2546.         elsif selection==6   # Close Box
  2547.           @selection = selection
  2548.           return (depositing) ? -3 : -1
  2549.         end
  2550.       end
  2551.      end
  2552.     end
  2553.   end
  2554. end
  2555.  
  2556. ################################################################################
  2557. # Pc                                                                           #
  2558. ################################################################################
  2559. class StorageSystemPC
  2560.   def shouldShow?
  2561.     return true
  2562.   end
  2563.  
  2564.   def name
  2565.     if $PokemonGlobal.seenStorageCreator
  2566.       return _INTL("{1}'s PC",Kernel.pbGetStorageCreator)
  2567.     else
  2568.       return _INTL("Someone's PC")
  2569.     end
  2570.   end
  2571.  
  2572.  def access
  2573.   if $Trainer.partyplus
  2574.         Kernel.pbMessage(_INTL("\\se[PC access]The Pokémon Storage System was opened."))
  2575.     loop do
  2576.       command=Kernel.pbShowCommandsWithHelp(nil,
  2577.          [_INTL("Organize Boxes"),
  2578.          _INTL("Withdraw Pokémon"),
  2579.          _INTL("Deposit Pokémon"),
  2580.          _INTL("See ya!")],
  2581.          [_INTL("Organize the Pokémon in Boxes and in your party."),
  2582.          _INTL("Move Pokémon stored in Boxes to your party."),
  2583.          _INTL("Store Pokémon in your party in Boxes."),
  2584.          _INTL("Return to the previous menu.")],-1
  2585.       )
  2586.       if command>=0 && command<3
  2587.         if command==1   # Withdraw
  2588.           if $PokemonStorage.party.length>=8
  2589.             Kernel.pbMessage(_INTL("Your party is full!"))
  2590.             next
  2591.           end
  2592.         elsif command==2   # Deposit
  2593.           count=0
  2594.           for p in $PokemonStorage.party
  2595.             count+=1 if p && !p.egg? && p.hp>0
  2596.           end
  2597.           if count<=1
  2598.             Kernel.pbMessage(_INTL("Can't deposit the last Pokémon!"))
  2599.             next
  2600.           end
  2601.         end
  2602.         pbFadeOutIn(99999){
  2603.           scene = PokemonStorageScene.new
  2604.           screen = PokemonStorageScreen.new(scene,$PokemonStorage)
  2605.           screen.pbStartScreen(command)
  2606.         }
  2607.       else
  2608.         break
  2609.       end
  2610.     end
  2611. else
  2612.       Kernel.pbMessage(_INTL("\\se[PC access]The Pokémon Storage System was opened."))
  2613.     loop do
  2614.       command=Kernel.pbShowCommandsWithHelp(nil,
  2615.          [_INTL("Organize Boxes"),
  2616.          _INTL("Withdraw Pokémon"),
  2617.          _INTL("Deposit Pokémon"),
  2618.          _INTL("See ya!")],
  2619.          [_INTL("Organize the Pokémon in Boxes and in your party."),
  2620.          _INTL("Move Pokémon stored in Boxes to your party."),
  2621.          _INTL("Store Pokémon in your party in Boxes."),
  2622.          _INTL("Return to the previous menu.")],-1
  2623.       )
  2624.       if command>=0 && command<3
  2625.         if command==1   # Withdraw
  2626.           if $PokemonStorage.party.length>=6
  2627.             Kernel.pbMessage(_INTL("Your party is full!"))
  2628.             next
  2629.           end
  2630.         elsif command==2   # Deposit
  2631.           count=0
  2632.           for p in $PokemonStorage.party
  2633.             count+=1 if p && !p.egg? && p.hp>0
  2634.           end
  2635.           if count<=1
  2636.             Kernel.pbMessage(_INTL("Can't deposit the last Pokémon!"))
  2637.             next
  2638.           end
  2639.         end
  2640.         pbFadeOutIn(99999){
  2641.           scene = PokemonStorageScene.new
  2642.           screen = PokemonStorageScreen.new(scene,$PokemonStorage)
  2643.           screen.pbStartScreen(command)
  2644.         }
  2645.       else
  2646.         break
  2647.       end
  2648.     end
  2649.   end
  2650. end
  2651.  
  2652.  
  2653.  
  2654.  
  2655. def pbTrainerPC
  2656.   Kernel.pbMessage(_INTL("\\se[PC open]{1} booted up the PC.",$Trainer.name))
  2657.   pbTrainerPCMenu
  2658.   pbSEPlay("PC close")
  2659. end
  2660.  
  2661. def pbPokeCenterPC
  2662.   Kernel.pbMessage(_INTL("\\se[PC open]{1} booted up the PC.",$Trainer.name))
  2663.   loop do
  2664.     commands=PokemonPCList.getCommandList
  2665.     command=Kernel.pbMessage(_INTL("Which PC should be accessed?"),commands,commands.length)
  2666.     break if !PokemonPCList.callCommand(command)
  2667.   end
  2668.   pbSEPlay("PC close")
  2669. end
  2670.  
  2671.  
  2672.  
  2673. module PokemonPCList
  2674.   @@pclist=[]
  2675.  
  2676.   def self.registerPC(pc)
  2677.     @@pclist.push(pc)
  2678.   end
  2679.  
  2680.   def self.getCommandList()
  2681.     commands=[]
  2682.     for pc in @@pclist
  2683.       if pc.shouldShow?
  2684.         commands.push(pc.name)
  2685.       end
  2686.     end
  2687.     commands.push(_INTL("Log Off"))
  2688.     return commands
  2689.   end
  2690.  
  2691.   def self.callCommand(cmd)
  2692.     if cmd<0 || cmd>=@@pclist.length
  2693.       return false
  2694.     end
  2695.     i=0
  2696.     for pc in @@pclist
  2697.       if pc.shouldShow?
  2698.         if i==cmd
  2699.            pc.access()
  2700.            return true
  2701.         end
  2702.         i+=1
  2703.       end
  2704.     end
  2705.     return false
  2706.   end
  2707.  end
  2708. end
  2709.  
  2710. ################################################################################
  2711. # OrgBattle                                                                    #
  2712. ################################################################################
  2713. def pbBattleFactoryPokemon(rule,numwins,numswaps,rentals)
  2714.  if $Trainer.partyplus
  2715.      table=nil
  2716.   btpokemon=pbGetBTPokemon(pbBattleChallenge.currentChallenge)
  2717.   ivtable=[
  2718.      0,6,3,6,
  2719.      7,13,6,9,
  2720.      14,20,9,12,
  2721.      21,27,12,15,
  2722.      28,34,15,21,
  2723.      35,41,21,31,
  2724.      42,-1,31,31
  2725.   ]
  2726.   groups=[
  2727.      1,14,6,0,
  2728.      15,21,5,1,
  2729.      22,28,4,2,
  2730.      29,35,3,3,
  2731.      36,42,2,4,
  2732.      43,-1,1,5
  2733.   ]
  2734.   if rule.ruleset.suggestedLevel!=100
  2735.     table=[
  2736.        0,6,110,199,
  2737.        7,13,162,266,
  2738.        14,20,267,371,
  2739.        21,27,372,467,
  2740.        28,34,468,563,
  2741.        35,41,564,659,
  2742.        42,48,660,755,
  2743.        49,-1,372,849
  2744.     ]
  2745.   else # Open Level (Level 100)
  2746.     table=[
  2747.        0,6,372,467,
  2748.        7,13,468,563,
  2749.        14,20,564,659,
  2750.        21,27,660,755,
  2751.        28,34,372,881,
  2752.        35,41,372,881,
  2753.        42,48,372,881,
  2754.        49,-1,372,881
  2755.     ]
  2756.   end
  2757.   pokemonNumbers=[0,0]
  2758.   ivs=[0,0]
  2759.   ivgroups=[6,0]
  2760.   for i in 0...table.length/4
  2761.     if table[i*4]<=numwins
  2762.       if (table[i*4+1]<0 || table[i*4+1]>=numwins)
  2763.         pokemonNumbers=[
  2764.            table[i*4+2]*btpokemon.length/882,
  2765.              table[i*4+3]*btpokemon.length/882
  2766.           ]
  2767.       end
  2768.     end
  2769.   end
  2770.   for i in 0...ivtable.length/4
  2771.     if ivtable[i*4]<=numwins
  2772.       if (ivtable[i*4+1]<0 || ivtable[i*4+1]>=numwins)
  2773.         ivs=[ivtable[i*4+2],ivtable[i*4+3]]
  2774.       end
  2775.     end
  2776.   end
  2777.   for i in 0...groups.length/4
  2778.     if groups[i*4]<=numswaps
  2779.       if (groups[i*4+1]<0 || groups[i*4+1]>=numswaps)
  2780.         ivgroups=[groups[i*4+2],groups[i*4+3]]
  2781.       end
  2782.     end
  2783.   end
  2784.   party=[]
  2785.   begin
  2786.     party.clear
  2787.     while party.length<6
  2788.       rnd=pokemonNumbers[0]+rand(pokemonNumbers[1]-pokemonNumbers[0]+1)
  2789.       rndpoke=btpokemon[rnd]
  2790.       indvalue=(party.length<ivgroups[0]) ? ivs[0] : ivs[1]
  2791.       party.push(rndpoke.createPokemon(rule.ruleset.suggestedLevel,indvalue,nil))
  2792.     end
  2793.   end until rule.ruleset.isValid?(party)
  2794.   return party
  2795. else
  2796.     table=nil
  2797.   btpokemon=pbGetBTPokemon(pbBattleChallenge.currentChallenge)
  2798.   ivtable=[
  2799.      0,6,3,6,
  2800.      7,13,6,9,
  2801.      14,20,9,12,
  2802.      21,27,12,15,
  2803.      28,34,15,21,
  2804.      35,41,21,31,
  2805.      42,-1,31,31
  2806.   ]
  2807.   groups=[
  2808.      1,14,6,0,
  2809.      15,21,5,1,
  2810.      22,28,4,2,
  2811.      29,35,3,3,
  2812.      36,42,2,4,
  2813.      43,-1,1,5
  2814.   ]
  2815.   if rule.ruleset.suggestedLevel!=100
  2816.     table=[
  2817.        0,6,110,199,
  2818.        7,13,162,266,
  2819.        14,20,267,371,
  2820.        21,27,372,467,
  2821.        28,34,468,563,
  2822.        35,41,564,659,
  2823.        42,48,660,755,
  2824.        49,-1,372,849
  2825.     ]
  2826.   else # Open Level (Level 100)
  2827.     table=[
  2828.        0,6,372,467,
  2829.        7,13,468,563,
  2830.        14,20,564,659,
  2831.        21,27,660,755,
  2832.        28,34,372,881,
  2833.        35,41,372,881,
  2834.        42,48,372,881,
  2835.        49,-1,372,881
  2836.     ]
  2837.   end
  2838.   pokemonNumbers=[0,0]
  2839.   ivs=[0,0]
  2840.   ivgroups=[6,0]
  2841.   for i in 0...table.length/4
  2842.     if table[i*4]<=numwins
  2843.       if (table[i*4+1]<0 || table[i*4+1]>=numwins)
  2844.         pokemonNumbers=[
  2845.            table[i*4+2]*btpokemon.length/882,
  2846.              table[i*4+3]*btpokemon.length/882
  2847.           ]
  2848.       end
  2849.     end
  2850.   end
  2851.   for i in 0...ivtable.length/4
  2852.     if ivtable[i*4]<=numwins
  2853.       if (ivtable[i*4+1]<0 || ivtable[i*4+1]>=numwins)
  2854.         ivs=[ivtable[i*4+2],ivtable[i*4+3]]
  2855.       end
  2856.     end
  2857.   end
  2858.   for i in 0...groups.length/4
  2859.     if groups[i*4]<=numswaps
  2860.       if (groups[i*4+1]<0 || groups[i*4+1]>=numswaps)
  2861.         ivgroups=[groups[i*4+2],groups[i*4+3]]
  2862.       end
  2863.     end
  2864.   end
  2865.   party=[]
  2866.   begin
  2867.     party.clear
  2868.     while party.length<6
  2869.       rnd=pokemonNumbers[0]+rand(pokemonNumbers[1]-pokemonNumbers[0]+1)
  2870.       rndpoke=btpokemon[rnd]
  2871.       indvalue=(party.length<ivgroups[0]) ? ivs[0] : ivs[1]
  2872.       party.push(rndpoke.createPokemon(rule.ruleset.suggestedLevel,indvalue,nil))
  2873.     end
  2874.   end until rule.ruleset.isValid?(party)
  2875.   return party
  2876.  end
  2877. end
  2878.  
  2879. ################################################################################
  2880. # PokemonUtilities                                                             #
  2881. ################################################################################
  2882. #===============================================================================
  2883. # Nicknaming and storing Pokémon
  2884. #===============================================================================
  2885. def pbBoxesFull?
  2886.  if $Trainer.partyplus
  2887.   return !$Trainer || ($Trainer.party.length==8 && $PokemonStorage.full?)
  2888.  else
  2889.   return !$Trainer || ($Trainer.party.length==6 && $PokemonStorage.full?)
  2890.  end
  2891. end
  2892.  
  2893. def pbNickname(pokemon)
  2894.   speciesname = PBSpecies.getName(pokemon.species)
  2895.   if Kernel.pbConfirmMessage(_INTL("Would you like to give a nickname to {1}?",speciesname))
  2896.     helptext = _INTL("{1}'s nickname?",speciesname)
  2897.     newname = pbEnterPokemonName(helptext,0,PokeBattle_Pokemon::NAMELIMIT,"",pokemon)
  2898.     pokemon.name = newname if newname!=""
  2899.   end
  2900. end
  2901.  
  2902. def pbStorePokemon(pokemon)
  2903.  if $Trainer.partyplus
  2904.   if pbBoxesFull?
  2905.     Kernel.pbMessage(_INTL("There's no more room for Pokémon!\1"))
  2906.     Kernel.pbMessage(_INTL("The Pokémon Boxes are full and can't accept any more!"))
  2907.     return
  2908.   end
  2909.   pokemon.pbRecordFirstMoves
  2910.   if $Trainer.party.length<8
  2911.     $Trainer.party[$Trainer.party.length]=pokemon
  2912.   else
  2913.     monsent=false
  2914.     while !monsent
  2915.       if Kernel.pbConfirmMessageSerious(_INTL("The party is full; do you want to send someone to the PC?"))
  2916.         iMon = -2
  2917.         eggcount = 0
  2918.         for i in $Trainer.party
  2919.           next if i.isEgg?
  2920.           eggcount += 1
  2921.         end
  2922.         pbFadeOutIn(99999){
  2923.           sscene  = PokemonParty_Scene.new
  2924.           sscreen = PokemonPartyScreen.new(sscene,$Trainer.party)
  2925.           sscreen.pbStartScene(_INTL("Choose a Pokémon."),false)
  2926.           loop do
  2927.             iMon=sscreen.pbChoosePokemon
  2928.             if eggcount<=1 && !($Trainer.party[iMon].isEgg?) && pokemon.isEgg?
  2929.               Kernel.pbMessage("That's your last Pokémon!")
  2930.             else
  2931.               sscreen.pbEndScene
  2932.               break
  2933.             end
  2934.           end
  2935.         }
  2936.         if !(iMon < 0)  
  2937.           iBox = $PokemonStorage.pbStoreCaught($Trainer.party[iMon])
  2938.           if iBox >= 0
  2939.             monsent=true
  2940.             $Trainer.party[iMon].heal
  2941.             Kernel.pbMessage(_INTL("{1} was sent to {2}.", $Trainer.party[iMon].name, $PokemonStorage[iBox].name))
  2942.             $Trainer.party[iMon] = nil
  2943.             $Trainer.party.compact!
  2944.             $Trainer.party[$Trainer.party.length]=pokemon
  2945.           else
  2946.             Kernel.pbMessage("No space left in the PC")
  2947.             return false
  2948.           end
  2949.         end    
  2950.       else
  2951.         monsent=true
  2952.         oldcurbox=$PokemonStorage.currentBox
  2953.         storedbox=$PokemonStorage.pbStoreCaught(pokemon)
  2954.         curboxname=$PokemonStorage[oldcurbox].name
  2955.         boxname=$PokemonStorage[storedbox].name
  2956.         creator=nil
  2957.         creator=Kernel.pbGetStorageCreator if $PokemonGlobal.seenStorageCreator
  2958.         if storedbox!=oldcurbox
  2959.           if creator
  2960.             Kernel.pbMessage(_INTL("Box \"{1}\" on {2}'s PC was full.\1",curboxname,creator))
  2961.           else
  2962.             Kernel.pbMessage(_INTL("Box \"{1}\" on someone's PC was full.\1",curboxname))
  2963.           end
  2964.           Kernel.pbMessage(_INTL("{1} was transferred to box \"{2}.\"",pokemon.name,boxname))
  2965.         else
  2966.           if creator
  2967.             Kernel.pbMessage(_INTL("{1} was transferred to {2}'s PC.\1",pokemon.name,creator))
  2968.           else
  2969.             Kernel.pbMessage(_INTL("{1} was transferred to someone's PC.\1",pokemon.name))
  2970.           end
  2971.           Kernel.pbMessage(_INTL("It was stored in box \"{1}\".",boxname))
  2972.         end
  2973.       end  
  2974.     end
  2975.   end
  2976.  else
  2977.   if pbBoxesFull?
  2978.     Kernel.pbMessage(_INTL("There's no more room for Pokémon!\1"))
  2979.     Kernel.pbMessage(_INTL("The Pokémon Boxes are full and can't accept any more!"))
  2980.     return
  2981.   end
  2982.   pokemon.pbRecordFirstMoves
  2983.   if $Trainer.party.length<6
  2984.     $Trainer.party[$Trainer.party.length]=pokemon
  2985.   else
  2986.     monsent=false
  2987.     while !monsent
  2988.       if Kernel.pbConfirmMessageSerious(_INTL("The party is full; do you want to send someone to the PC?"))
  2989.         iMon = -2
  2990.         eggcount = 0
  2991.         for i in $Trainer.party
  2992.           next if i.isEgg?
  2993.           eggcount += 1
  2994.         end
  2995.         pbFadeOutIn(99999){
  2996.           sscene  = PokemonParty_Scene.new
  2997.           sscreen = PokemonPartyScreen.new(sscene,$Trainer.party)
  2998.           sscreen.pbStartScene(_INTL("Choose a Pokémon."),false)
  2999.           loop do
  3000.             iMon=sscreen.pbChoosePokemon
  3001.             if eggcount<=1 && !($Trainer.party[iMon].isEgg?) && pokemon.isEgg?
  3002.               Kernel.pbMessage("That's your last Pokémon!")
  3003.             else
  3004.               sscreen.pbEndScene
  3005.               break
  3006.             end
  3007.           end
  3008.         }
  3009.         if !(iMon < 0)  
  3010.           iBox = $PokemonStorage.pbStoreCaught($Trainer.party[iMon])
  3011.           if iBox >= 0
  3012.             monsent=true
  3013.             $Trainer.party[iMon].heal
  3014.             Kernel.pbMessage(_INTL("{1} was sent to {2}.", $Trainer.party[iMon].name, $PokemonStorage[iBox].name))
  3015.             $Trainer.party[iMon] = nil
  3016.             $Trainer.party.compact!
  3017.             $Trainer.party[$Trainer.party.length]=pokemon
  3018.           else
  3019.             Kernel.pbMessage("No space left in the PC")
  3020.             return false
  3021.           end
  3022.         end    
  3023.       else
  3024.         monsent=true
  3025.         oldcurbox=$PokemonStorage.currentBox
  3026.         storedbox=$PokemonStorage.pbStoreCaught(pokemon)
  3027.         curboxname=$PokemonStorage[oldcurbox].name
  3028.         boxname=$PokemonStorage[storedbox].name
  3029.         creator=nil
  3030.         creator=Kernel.pbGetStorageCreator if $PokemonGlobal.seenStorageCreator
  3031.         if storedbox!=oldcurbox
  3032.           if creator
  3033.             Kernel.pbMessage(_INTL("Box \"{1}\" on {2}'s PC was full.\1",curboxname,creator))
  3034.           else
  3035.             Kernel.pbMessage(_INTL("Box \"{1}\" on someone's PC was full.\1",curboxname))
  3036.           end
  3037.           Kernel.pbMessage(_INTL("{1} was transferred to box \"{2}.\"",pokemon.name,boxname))
  3038.         else
  3039.           if creator
  3040.             Kernel.pbMessage(_INTL("{1} was transferred to {2}'s PC.\1",pokemon.name,creator))
  3041.           else
  3042.             Kernel.pbMessage(_INTL("{1} was transferred to someone's PC.\1",pokemon.name))
  3043.           end
  3044.           Kernel.pbMessage(_INTL("It was stored in box \"{1}\".",boxname))
  3045.         end
  3046.       end  
  3047.     end
  3048.   end
  3049.  end
  3050. end
  3051.  
  3052. def pbNicknameAndStore(pokemon)
  3053.   if pbBoxesFull?
  3054.     Kernel.pbMessage(_INTL("There's no more room for Pokémon!\1"))
  3055.     Kernel.pbMessage(_INTL("The Pokémon Boxes are full and can't accept any more!"))
  3056.     return
  3057.   end
  3058.   $Trainer.seen[pokemon.species]  = true
  3059.   $Trainer.owned[pokemon.species] = true
  3060.   pbNickname(pokemon)
  3061.   pbStorePokemon(pokemon)
  3062. end
  3063.  
  3064. #===============================================================================
  3065. # Giving Pokémon to the player (will send to storage if party is full)
  3066. #===============================================================================
  3067. def pbAddPokemon(pokemon,level=nil,seeform=true)
  3068.   return if !pokemon || !$Trainer
  3069.   if pbBoxesFull?
  3070.     Kernel.pbMessage(_INTL("There's no more room for Pokémon!\1"))
  3071.     Kernel.pbMessage(_INTL("The Pokémon Boxes are full and can't accept any more!"))
  3072.     return false
  3073.   end
  3074.   if pokemon.is_a?(String) || pokemon.is_a?(Symbol)
  3075.     pokemon = getID(PBSpecies,pokemon)
  3076.   end
  3077.   if pokemon.is_a?(Integer) && level.is_a?(Integer)
  3078.     pokemon = PokeBattle_Pokemon.new(pokemon,level,$Trainer)
  3079.   end
  3080.   speciesname = PBSpecies.getName(pokemon.species)
  3081.   Kernel.pbMessage(_INTL("\\me[Pkmn get]{1} obtained {2}!\1",$Trainer.name,speciesname))
  3082.   pbNicknameAndStore(pokemon)
  3083.   pbSeenForm(pokemon) if seeform
  3084.   return true
  3085. end
  3086.  
  3087. def pbAddPokemonSilent(pokemon,level=nil,seeform=true)
  3088.  if $Trainer.partyplus
  3089.   return false if !pokemon || pbBoxesFull? || !$Trainer
  3090.   if pokemon.is_a?(String) || pokemon.is_a?(Symbol)
  3091.     pokemon=getID(PBSpecies,pokemon)
  3092.   end
  3093.   if pokemon.is_a?(Integer) && level.is_a?(Integer)
  3094.     pokemon=PokeBattle_Pokemon.new(pokemon,level,$Trainer)
  3095.   end
  3096.   if pokemon.ot == ""
  3097.     pokemon.ot = $Trainer.name
  3098.     pokemon.trainerID = $Trainer.id
  3099.   end
  3100.   $Trainer.seen[pokemon.species]=true
  3101.   $Trainer.owned[pokemon.species]=true
  3102.   pbSeenForm(pokemon) if seeform
  3103.   pokemon.pbRecordFirstMoves
  3104.   if $Trainer.party.length<8
  3105.     $Trainer.party[$Trainer.party.length]=pokemon
  3106.   else
  3107.     monsent=false
  3108.     while !monsent
  3109.       if Kernel.pbConfirmMessageSerious(_INTL("The party is full; do you want to send someone to the PC?"))
  3110.         iMon = -2
  3111.         eggcount = 0
  3112.         for i in $Trainer.party
  3113.           next if i.isEgg?
  3114.           eggcount += 1
  3115.         end
  3116.         pbFadeOutIn(99999){
  3117.           sscene  = PokemonParty_Scene.new
  3118.           sscreen = PokemonPartyScreen.new(sscene,$Trainer.party)
  3119.           sscreen.pbStartScene(_INTL("Choose a Pokémon."),false)
  3120.           loop do
  3121.             iMon=sscreen.pbChoosePokemon
  3122.             if eggcount<=1 && !($Trainer.party[iMon].isEgg?) && pokemon.isEgg?
  3123.               Kernel.pbMessage("That's your last Pokémon!")
  3124.             else
  3125.               sscreen.pbEndScene
  3126.               break
  3127.             end
  3128.           end
  3129.         }
  3130.         if !(iMon < 0)
  3131.           iBox = $PokemonStorage.pbStoreCaught($Trainer.party[iMon])
  3132.           if iBox >= 0
  3133.             monsent=true
  3134.             Kernel.pbMessage(_INTL("{1} was sent to {2}.", $Trainer.party[iMon].name, $PokemonStorage[iBox].name))
  3135.             $Trainer.party[iMon] = nil
  3136.             $Trainer.party.compact!
  3137.             $Trainer.party[$Trainer.party.length]=pokemon
  3138.           else
  3139.             Kernel.pbMessage("No space left in the PC.")
  3140.             return false
  3141.           end
  3142.         end    
  3143.       else
  3144.         monsent=true
  3145.         storedbox = $PokemonStorage.pbStoreCaught(pokemon)
  3146.         if pokemon.isEgg?
  3147.          oldcurbox=$PokemonStorage.currentBox
  3148.          #storedbox=$PokemonStorage.pbStoreCaught(pokemon)
  3149.          curboxname=$PokemonStorage[oldcurbox].name
  3150.          boxname=$PokemonStorage[storedbox].name
  3151.          creator=nil
  3152.          creator=Kernel.pbGetStorageCreator if $PokemonGlobal.seenStorageCreator
  3153.           if storedbox!=oldcurbox
  3154.             if creator
  3155.               Kernel.pbMessage(_INTL("Box \"{1}\" on {2}'s PC was full.\1",curboxname,creator))
  3156.             else
  3157.               Kernel.pbMessage(_INTL("Box \"{1}\" on someone's PC was full.\1",curboxname))
  3158.             end
  3159.             Kernel.pbMessage(_INTL("{1} was transferred to box \"{2}.\"",pokemon.name,boxname))
  3160.           else
  3161.             if creator
  3162.               Kernel.pbMessage(_INTL("{1} was transferred to {2}'s PC.\1",pokemon.name,creator))
  3163.             else
  3164.               Kernel.pbMessage(_INTL("{1} was transferred to someone's PC.\1",pokemon.name))
  3165.             end
  3166.             Kernel.pbMessage(_INTL("It was stored in box \"{1}\".",boxname))
  3167.           end
  3168.         end
  3169.       end
  3170.     end  
  3171.   end
  3172.   return true
  3173.  else
  3174.   return false if !pokemon || pbBoxesFull? || !$Trainer
  3175.   if pokemon.is_a?(String) || pokemon.is_a?(Symbol)
  3176.     pokemon=getID(PBSpecies,pokemon)
  3177.   end
  3178.   if pokemon.is_a?(Integer) && level.is_a?(Integer)
  3179.     pokemon=PokeBattle_Pokemon.new(pokemon,level,$Trainer)
  3180.   end
  3181.   if pokemon.ot == ""
  3182.     pokemon.ot = $Trainer.name
  3183.     pokemon.trainerID = $Trainer.id
  3184.   end
  3185.   $Trainer.seen[pokemon.species]=true
  3186.   $Trainer.owned[pokemon.species]=true
  3187.   pbSeenForm(pokemon) if seeform
  3188.   pokemon.pbRecordFirstMoves
  3189.   if $Trainer.party.length<6
  3190.     $Trainer.party[$Trainer.party.length]=pokemon
  3191.   else
  3192.     monsent=false
  3193.     while !monsent
  3194.       if Kernel.pbConfirmMessageSerious(_INTL("The party is full; do you want to send someone to the PC?"))
  3195.         iMon = -2
  3196.         eggcount = 0
  3197.         for i in $Trainer.party
  3198.           next if i.isEgg?
  3199.           eggcount += 1
  3200.         end
  3201.         pbFadeOutIn(99999){
  3202.           sscene  = PokemonParty_Scene.new
  3203.           sscreen = PokemonPartyScreen.new(sscene,$Trainer.party)
  3204.           sscreen.pbStartScene(_INTL("Choose a Pokémon."),false)
  3205.           loop do
  3206.             iMon=sscreen.pbChoosePokemon
  3207.             if eggcount<=1 && !($Trainer.party[iMon].isEgg?) && pokemon.isEgg?
  3208.               Kernel.pbMessage("That's your last Pokémon!")
  3209.             else
  3210.               sscreen.pbEndScene
  3211.               break
  3212.             end
  3213.           end
  3214.         }
  3215.         if !(iMon < 0)
  3216.           iBox = $PokemonStorage.pbStoreCaught($Trainer.party[iMon])
  3217.           if iBox >= 0
  3218.             monsent=true
  3219.             Kernel.pbMessage(_INTL("{1} was sent to {2}.", $Trainer.party[iMon].name, $PokemonStorage[iBox].name))
  3220.             $Trainer.party[iMon] = nil
  3221.             $Trainer.party.compact!
  3222.             $Trainer.party[$Trainer.party.length]=pokemon
  3223.           else
  3224.             Kernel.pbMessage("No space left in the PC.")
  3225.             return false
  3226.           end
  3227.         end    
  3228.       else
  3229.         monsent=true
  3230.         storedbox = $PokemonStorage.pbStoreCaught(pokemon)
  3231.         if pokemon.isEgg?
  3232.          oldcurbox=$PokemonStorage.currentBox
  3233.          #storedbox=$PokemonStorage.pbStoreCaught(pokemon)
  3234.          curboxname=$PokemonStorage[oldcurbox].name
  3235.          boxname=$PokemonStorage[storedbox].name
  3236.          creator=nil
  3237.          creator=Kernel.pbGetStorageCreator if $PokemonGlobal.seenStorageCreator
  3238.           if storedbox!=oldcurbox
  3239.             if creator
  3240.               Kernel.pbMessage(_INTL("Box \"{1}\" on {2}'s PC was full.\1",curboxname,creator))
  3241.             else
  3242.               Kernel.pbMessage(_INTL("Box \"{1}\" on someone's PC was full.\1",curboxname))
  3243.             end
  3244.             Kernel.pbMessage(_INTL("{1} was transferred to box \"{2}.\"",pokemon.name,boxname))
  3245.           else
  3246.             if creator
  3247.               Kernel.pbMessage(_INTL("{1} was transferred to {2}'s PC.\1",pokemon.name,creator))
  3248.             else
  3249.               Kernel.pbMessage(_INTL("{1} was transferred to someone's PC.\1",pokemon.name))
  3250.             end
  3251.             Kernel.pbMessage(_INTL("It was stored in box \"{1}\".",boxname))
  3252.           end
  3253.         end
  3254.       end
  3255.     end  
  3256.   end
  3257.   return true
  3258.  end
  3259. end
  3260.  
  3261. #===============================================================================
  3262. # Giving Pokémon/eggs to the player (can only add to party)
  3263. #===============================================================================
  3264. def pbAddToParty(pokemon,level=nil,seeform=true)
  3265. if $Trainer.partyplus
  3266.   return false if !pokemon || !$Trainer || $Trainer.party.length>=8
  3267. else
  3268.   return false if !pokemon || !$Trainer || $Trainer.party.length>=6
  3269. end
  3270. if pokemon.is_a?(String) || pokemon.is_a?(Symbol)
  3271.     pokemon = getID(PBSpecies,pokemon)
  3272.   end
  3273.   if pokemon.is_a?(Integer) && level.is_a?(Integer)
  3274.     pokemon = PokeBattle_Pokemon.new(pokemon,level,$Trainer)
  3275.   end
  3276.   speciesname = PBSpecies.getName(pokemon.species)
  3277.   Kernel.pbMessage(_INTL("\\me[Pkmn get]{1} obtained {2}!\1",$Trainer.name,speciesname))
  3278.   pbNicknameAndStore(pokemon)
  3279.   pbSeenForm(pokemon) if seeform
  3280.   return true
  3281. end
  3282.  
  3283. def pbAddToPartySilent(pokemon,level=nil,seeform=true)
  3284. if $Trainer.partyplus
  3285.   return false if !pokemon || !$Trainer || $Trainer.party.length>=8
  3286. else
  3287.   return false if !pokemon || !$Trainer || $Trainer.party.length>=6
  3288. end
  3289.   if pokemon.is_a?(String) || pokemon.is_a?(Symbol)
  3290.     pokemon = getID(PBSpecies,pokemon)
  3291.   end
  3292.   if pokemon.is_a?(Integer) && level.is_a?(Integer)
  3293.     pokemon = PokeBattle_Pokemon.new(pokemon,level,$Trainer)
  3294.   end
  3295.   $Trainer.seen[pokemon.species]  = true
  3296.   $Trainer.owned[pokemon.species] = true
  3297.   pbSeenForm(pokemon) if seeform
  3298.   pokemon.pbRecordFirstMoves
  3299.   $Trainer.party[$Trainer.party.length] = pokemon
  3300.   return true
  3301. end
  3302.  
  3303. def pbAddForeignPokemon(pokemon,level=nil,ownerName=nil,nickname=nil,ownerGender=0,seeform=true)
  3304. if $Trainer.partyplus
  3305.   return false if !pokemon || !$Trainer || $Trainer.party.length>=8
  3306. else
  3307.   return false if !pokemon || !$Trainer || $Trainer.party.length>=6
  3308. end
  3309.   if pokemon.is_a?(String) || pokemon.is_a?(Symbol)
  3310.     pokemon = getID(PBSpecies,pokemon)
  3311.   end
  3312.   if pokemon.is_a?(Integer) && level.is_a?(Integer)
  3313.     pokemon = PokeBattle_Pokemon.new(pokemon,level,$Trainer)
  3314.   end
  3315.   # Set original trainer to a foreign one (if ID isn't already foreign)
  3316.   if pokemon.trainerID==$Trainer.id
  3317.     pokemon.trainerID = $Trainer.getForeignID
  3318.     pokemon.ot        = ownerName if ownerName && ownerName!=""
  3319.     pokemon.otgender  = ownerGender
  3320.   end
  3321.   # Set nickname
  3322.   pokemon.name = nickname[0,PokeBattle_Pokemon::NAMELIMIT] if nickname && nickname!=""
  3323.   # Recalculate stats
  3324.   pokemon.calcStats
  3325.   if ownerName
  3326.     Kernel.pbMessage(_INTL("\\me[Pkmn get]{1} received a Pokémon from {2}.\1",$Trainer.name,ownerName))
  3327.   else
  3328.     Kernel.pbMessage(_INTL("\\me[Pkmn get]{1} received a Pokémon.\1",$Trainer.name))
  3329.   end
  3330.   pbStorePokemon(pokemon)
  3331.   $Trainer.seen[pokemon.species]  = true
  3332.   $Trainer.owned[pokemon.species] = true
  3333.   pbSeenForm(pokemon) if seeform
  3334.   return true
  3335. end
  3336.  
  3337. def pbGenerateEgg(pokemon,text="")
  3338. if $Trainer.partyplus
  3339.   return false if !pokemon || !$Trainer || $Trainer.party.length>=8
  3340. else
  3341.   return false if !pokemon || !$Trainer || $Trainer.party.length>=6
  3342. end
  3343.   if pokemon.is_a?(String) || pokemon.is_a?(Symbol)
  3344.     pokemon = getID(PBSpecies,pokemon)
  3345.   end
  3346.   if pokemon.is_a?(Integer)
  3347.     pokemon = PokeBattle_Pokemon.new(pokemon,EGGINITIALLEVEL,$Trainer)
  3348.   end
  3349.   # Get egg steps
  3350.   dexdata = pbOpenDexData
  3351.   pbDexDataOffset(dexdata,pokemon.fSpecies,21)
  3352.   eggsteps = dexdata.fgetw
  3353.   dexdata.close
  3354.   # Set egg's details
  3355.   pokemon.name       = _INTL("Egg")
  3356.   pokemon.eggsteps   = eggsteps
  3357.   pokemon.obtainText = text
  3358.   pokemon.calcStats
  3359.   # Add egg to party
  3360.   $Trainer.party[$Trainer.party.length] = pokemon
  3361.   return true
  3362. end
  3363.  
  3364. def pbAddEgg(pokemon,text="")
  3365.   return pbGenerateEgg(pokemon,text)
  3366. end
  3367.  
  3368. ################################################################################
  3369. # Utilities                                                                    #
  3370. ################################################################################
  3371. #===============================================================================
  3372. # Other utilities
  3373. #===============================================================================
  3374. def pbTextEntry(helptext,minlength,maxlength,variableNumber)
  3375.   $game_variables[variableNumber] = pbEnterText(helptext,minlength,maxlength)
  3376.   $game_map.need_refresh = true if $game_map
  3377. end
  3378.  
  3379. def pbMoveTutorAnnotations(move,movelist=nil)
  3380. if $Trainer.partyplus
  3381.   ret = []
  3382.   for i in 0...8
  3383.     ret[i] = nil
  3384.     next if i>=$Trainer.party.length
  3385.     found = false
  3386.     for j in 0...4
  3387.       if !$Trainer.party[i].egg? && $Trainer.party[i].moves[j].id==move
  3388.         ret[i] = _INTL("LEARNED")
  3389.         found = true
  3390.       end
  3391.     end
  3392.     next if found
  3393.     species = $Trainer.party[i].species
  3394.     if !$Trainer.party[i].egg? && movelist && movelist.any?{|j| j==species }
  3395.       # Checked data from movelist
  3396.       ret[i] = _INTL("ABLE")
  3397.     elsif !$Trainer.party[i].egg? && $Trainer.party[i].isCompatibleWithMove?(move)
  3398.       # Checked data from PBS/tm.txt
  3399.       ret[i] = _INTL("ABLE")
  3400.     else
  3401.       ret[i] = _INTL("NOT ABLE")
  3402.     end
  3403.   end
  3404. else
  3405.   ret = []
  3406.   for i in 0...6
  3407.     ret[i] = nil
  3408.     next if i>=$Trainer.party.length
  3409.     found = false
  3410.     for j in 0...4
  3411.       if !$Trainer.party[i].egg? && $Trainer.party[i].moves[j].id==move
  3412.         ret[i] = _INTL("LEARNED")
  3413.         found = true
  3414.       end
  3415.     end
  3416.     next if found
  3417.     species = $Trainer.party[i].species
  3418.     if !$Trainer.party[i].egg? && movelist && movelist.any?{|j| j==species }
  3419.       # Checked data from movelist
  3420.       ret[i] = _INTL("ABLE")
  3421.     elsif !$Trainer.party[i].egg? && $Trainer.party[i].isCompatibleWithMove?(move)
  3422.       # Checked data from PBS/tm.txt
  3423.       ret[i] = _INTL("ABLE")
  3424.     else
  3425.       ret[i] = _INTL("NOT ABLE")
  3426.     end
  3427.    end
  3428.   end
  3429.   return ret
  3430. end
  3431.  
  3432. ################################################################################
  3433. # Debug                                                                        #
  3434. ################################################################################
  3435.   def pbDebugDayCare
  3436.   commands = [_INTL("Withdraw Pokémon 1"),
  3437.               _INTL("Withdraw Pokémon 2"),
  3438.               _INTL("Deposit Pokémon"),
  3439.               _INTL("Generate egg"),
  3440.               _INTL("Collect egg")]
  3441.   viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  3442.   viewport.z = 99999
  3443.   sprites = {}
  3444.   addBackgroundPlane(sprites,"background","hatchbg",viewport)
  3445.   sprites["overlay"] = BitmapSprite.new(Graphics.width,Graphics.height,viewport)
  3446.   pbSetSystemFont(sprites["overlay"].bitmap)
  3447.   sprites["cmdwindow"] = Window_CommandPokemonEx.new(commands)
  3448.   cmdwindow = sprites["cmdwindow"]
  3449.   cmdwindow.x        = 0
  3450.   cmdwindow.y        = Graphics.height-128
  3451.   cmdwindow.width    = Graphics.width
  3452.   cmdwindow.height   = 128
  3453.   cmdwindow.viewport = viewport
  3454.   cmdwindow.columns = 2
  3455.   base   = Color.new(248,248,248)
  3456.   shadow = Color.new(104,104,104)
  3457.   refresh = true
  3458.   loop do
  3459.     if refresh
  3460.       if pbEggGenerated?
  3461.         commands[3] = _INTL("Discard egg")
  3462.       else
  3463.         commands[3] = _INTL("Generate egg")
  3464.       end
  3465.       cmdwindow.commands = commands
  3466.       sprites["overlay"].bitmap.clear
  3467.       textpos = []
  3468.       for i in 0...2
  3469.         textpos.push([_INTL("Pokémon {1}",i+1),Graphics.width/4+i*Graphics.width/2,8,2,base,shadow])
  3470.       end
  3471.       for i in 0...pbDayCareDeposited
  3472.         next if !$PokemonGlobal.daycare[i][0]
  3473.         y = 40
  3474.         pkmn      = $PokemonGlobal.daycare[i][0]
  3475.         initlevel = $PokemonGlobal.daycare[i][1]
  3476.         leveldiff = pkmn.level-initlevel
  3477.         textpos.push([pkmn.name+" ("+PBSpecies.getName(pkmn.species)+")",8+i*Graphics.width/2,y,0,base,shadow])
  3478.         y += 32
  3479.         if pkmn.isMale?
  3480.           textpos.push([_INTL("Male ♂"),8+i*Graphics.width/2,y,0,Color.new(128,192,248),shadow])
  3481.         elsif pkmn.isFemale?
  3482.           textpos.push([_INTL("Female ♀"),8+i*Graphics.width/2,y,0,Color.new(248,96,96),shadow])
  3483.         else
  3484.           textpos.push([_INTL("Genderless"),8+i*Graphics.width/2,y,0,base,shadow])
  3485.         end
  3486.         y += 32
  3487.         if initlevel>=PBExperience::MAXLEVEL
  3488.           textpos.push(["Lv. #{initlevel} (max)",8+i*Graphics.width/2,y,0,base,shadow])
  3489.         elsif leveldiff>0
  3490.           textpos.push(["Lv. #{initlevel} -> #{pkmn.level} (+#{leveldiff})",
  3491.              8+i*Graphics.width/2,y,0,base,shadow])
  3492.         else
  3493.           textpos.push(["Lv. #{initlevel} (no change)",8+i*Graphics.width/2,y,0,base,shadow])
  3494.         end
  3495.         y += 32
  3496.         if pkmn.level<PBExperience::MAXLEVEL
  3497.           endexp   = PBExperience.pbGetStartExperience(pkmn.level+1,pkmn.growthrate)
  3498.           textpos.push(["To next Lv.: #{endexp-pkmn.exp}",8+i*Graphics.width/2,y,0,base,shadow])
  3499.           y += 32
  3500.         end
  3501.         textpos.push(["Cost: $#{pbDayCareCost(i)}",8+i*Graphics.width/2,y,0,base,shadow])
  3502.       end
  3503.       if pbEggGenerated?
  3504.         textpos.push(["Egg waiting for collection",Graphics.width/2,216,2,Color.new(248,248,0),shadow])
  3505.       elsif pbDayCareDeposited==2
  3506.         if pbDayCareGetCompat==0
  3507.           textpos.push(["Pokémon cannot breed",Graphics.width/2,216,2,Color.new(248,96,96),shadow])
  3508.         else
  3509.           textpos.push(["Pokémon can breed",Graphics.width/2,216,2,Color.new(64,248,64),shadow])
  3510.         end
  3511.       end
  3512.       pbDrawTextPositions(sprites["overlay"].bitmap,textpos)
  3513.       refresh = false
  3514.     end
  3515.     pbUpdateSpriteHash(sprites)
  3516.     Graphics.update
  3517.     Input.update
  3518.     if Input.trigger?(Input::B)
  3519.       break
  3520.     elsif Input.trigger?(Input::C)
  3521.       ret = cmdwindow.index
  3522.       case cmdwindow.index
  3523.       when 0 # Withdraw Pokémon 1
  3524.       if $Trainer.partyplus
  3525.         if !$PokemonGlobal.daycare[0][0]
  3526.           pbPlayBuzzerSE
  3527.         elsif $Trainer.party.length>=8
  3528.           pbPlayBuzzerSE
  3529.           Kernel.pbMessage(_INTL("Party is full, can't withdraw Pokémon."))
  3530.         else
  3531.           pbPlayDecisionSE
  3532.           pbDayCareGetDeposited(0,3,4)
  3533.           pbDayCareWithdraw(0)
  3534.           refresh = true
  3535.         end
  3536.       else
  3537.         if !$PokemonGlobal.daycare[0][0]
  3538.           pbPlayBuzzerSE
  3539.         elsif $Trainer.party.length>=6
  3540.           pbPlayBuzzerSE
  3541.           Kernel.pbMessage(_INTL("Party is full, can't withdraw Pokémon."))
  3542.         else
  3543.           pbPlayDecisionSE
  3544.           pbDayCareGetDeposited(0,3,4)
  3545.           pbDayCareWithdraw(0)
  3546.           refresh = true
  3547.         end
  3548.       end
  3549.       when 1 # Withdraw Pokémon 2
  3550.       if $Trainer.partyplus
  3551.         if !$PokemonGlobal.daycare[1][0]
  3552.           pbPlayBuzzerSE
  3553.         elsif $Trainer.party.length>=8
  3554.           pbPlayBuzzerSE
  3555.           Kernel.pbMessage(_INTL("Party is full, can't withdraw Pokémon."))
  3556.         else
  3557.           pbPlayDecisionSE
  3558.           pbDayCareGetDeposited(1,3,4)
  3559.           pbDayCareWithdraw(1)
  3560.           refresh = true
  3561.         end
  3562.       else
  3563.         if !$PokemonGlobal.daycare[1][0]
  3564.           pbPlayBuzzerSE
  3565.         elsif $Trainer.party.length>=6
  3566.           pbPlayBuzzerSE
  3567.           Kernel.pbMessage(_INTL("Party is full, can't withdraw Pokémon."))
  3568.         else
  3569.           pbPlayDecisionSE
  3570.           pbDayCareGetDeposited(1,3,4)
  3571.           pbDayCareWithdraw(1)
  3572.           refresh = true
  3573.         end
  3574.       end
  3575.       when 2 # Deposit Pokémon
  3576.         if pbDayCareDeposited==2
  3577.           pbPlayBuzzerSE
  3578.         elsif $Trainer.party.length==0
  3579.           pbPlayBuzzerSE
  3580.           Kernel.pbMessage(_INTL("Party is empty, can't deposit Pokémon."))
  3581.         else
  3582.           pbPlayDecisionSE
  3583.           pbChooseNonEggPokemon(1,3)
  3584.           if pbGet(1)>=0
  3585.             pbDayCareDeposit(pbGet(1))
  3586.             refresh = true
  3587.           end
  3588.         end
  3589.       when 3 # Generate/discard egg
  3590.         if pbEggGenerated?
  3591.           pbPlayDecisionSE
  3592.           $PokemonGlobal.daycareEgg      = 0
  3593.           $PokemonGlobal.daycareEggSteps = 0
  3594.           refresh = true
  3595.         else
  3596.           if pbDayCareDeposited!=2 || pbDayCareGetCompat==0
  3597.             pbPlayBuzzerSE
  3598.           else
  3599.             pbPlayDecisionSE
  3600.             $PokemonGlobal.daycareEgg = 1
  3601.             refresh = true
  3602.           end
  3603.         end
  3604.       when 4 # Collect egg
  3605.       if $Trainer.partyplus
  3606.         if $PokemonGlobal.daycareEgg!=1
  3607.           pbPlayBuzzerSE
  3608.         elsif $Trainer.party.length>=8
  3609.           pbPlayBuzzerSE
  3610.           Kernel.pbMessage(_INTL("Party is full, can't collect the egg."))
  3611.         else
  3612.           pbPlayDecisionSE
  3613.           pbDayCareGenerateEgg
  3614.           $PokemonGlobal.daycareEgg      = 0
  3615.           $PokemonGlobal.daycareEggSteps = 0
  3616.           Kernel.pbMessage(_INTL("Collected the {1} egg.",
  3617.              PBSpecies.getName($Trainer.lastParty.species)))
  3618.           refresh = true
  3619.         end
  3620.       else
  3621.         if $PokemonGlobal.daycareEgg!=1
  3622.           pbPlayBuzzerSE
  3623.         elsif $Trainer.party.length>=6
  3624.           pbPlayBuzzerSE
  3625.           Kernel.pbMessage(_INTL("Party is full, can't collect the egg."))
  3626.         else
  3627.           pbPlayDecisionSE
  3628.           pbDayCareGenerateEgg
  3629.           $PokemonGlobal.daycareEgg      = 0
  3630.           $PokemonGlobal.daycareEggSteps = 0
  3631.           Kernel.pbMessage(_INTL("Collected the {1} egg.",
  3632.              PBSpecies.getName($Trainer.lastParty.species)))
  3633.           refresh = true
  3634.         end
  3635.        end
  3636.       end
  3637.     end
  3638.   end
  3639.   pbDisposeSpriteHash(sprites)
  3640.   viewport.dispose
  3641. end
  3642.  
  3643. # For demonstration purposes only, not to be used in a real game.
  3644. def pbCreatePokemon
  3645.   pbRemovePokemonAt(7)
  3646.   pbRemovePokemonAt(6)
  3647. if $Trainer.partyplus
  3648.   party = []
  3649.   species = [:JOLTEON,:TOGETIC,:MONFERNO,:GYARADOS,:DIGLETT,:AMBIPOM,:PRINPLUP,:GROTLE]
  3650.   for id in species
  3651.     party.push(getConst(PBSpecies,id)) if hasConst?(PBSpecies,id)
  3652.   end
  3653.   # Species IDs of the Pokémon to be created
  3654.   for i in 0...party.length
  3655.     species = party[i]
  3656.     # Generate Pokémon with species and level 20
  3657.     $Trainer.party[i] = PokeBattle_Pokemon.new(species,20,$Trainer)
  3658.     $Trainer.seen[species]  = true # Set this species to seen and owned
  3659.     $Trainer.owned[species] = true
  3660.     pbSeenForm($Trainer.party[i])
  3661.   end
  3662.   $Trainer.party[1].pbLearnMove(:FLY)
  3663.   $Trainer.party[2].pbLearnMove(:FLASH)
  3664.   $Trainer.party[2].pbLearnMove(:TELEPORT)
  3665.   $Trainer.party[3].pbLearnMove(:SURF)
  3666.   $Trainer.party[3].pbLearnMove(:DIVE)
  3667.   $Trainer.party[3].pbLearnMove(:WATERFALL)
  3668.   $Trainer.party[4].pbLearnMove(:DIG)
  3669.   $Trainer.party[4].pbLearnMove(:CUT)
  3670.   $Trainer.party[4].pbLearnMove(:HEADBUTT)
  3671.   $Trainer.party[4].pbLearnMove(:ROCKSMASH)
  3672.   $Trainer.party[5].pbLearnMove(:SOFTBOILED)
  3673.   $Trainer.party[5].pbLearnMove(:STRENGTH)
  3674.   $Trainer.party[5].pbLearnMove(:SWEETSCENT)
  3675.   for i in 0...party.length
  3676.     $Trainer.party[i].pbRecordFirstMoves
  3677.   end
  3678.   else
  3679.   party = []
  3680.   species = [:JOLTEON,:TOGETIC,:MONFERNO,:GYARADOS,:DIGLETT,:AMBIPOM]
  3681.   for id in species
  3682.     party.push(getConst(PBSpecies,id)) if hasConst?(PBSpecies,id)
  3683.   end
  3684.   # Species IDs of the Pokémon to be created
  3685.   for i in 0...party.length
  3686.     species = party[i]
  3687.     # Generate Pokémon with species and level 20
  3688.     $Trainer.party[i] = PokeBattle_Pokemon.new(species,20,$Trainer)
  3689.     $Trainer.seen[species]  = true # Set this species to seen and owned
  3690.     $Trainer.owned[species] = true
  3691.     pbSeenForm($Trainer.party[i])
  3692.   end
  3693.   $Trainer.party[1].pbLearnMove(:FLY)
  3694.   $Trainer.party[2].pbLearnMove(:FLASH)
  3695.   $Trainer.party[2].pbLearnMove(:TELEPORT)
  3696.   $Trainer.party[3].pbLearnMove(:SURF)
  3697.   $Trainer.party[3].pbLearnMove(:DIVE)
  3698.   $Trainer.party[3].pbLearnMove(:WATERFALL)
  3699.   $Trainer.party[4].pbLearnMove(:DIG)
  3700.   $Trainer.party[4].pbLearnMove(:CUT)
  3701.   $Trainer.party[4].pbLearnMove(:HEADBUTT)
  3702.   $Trainer.party[4].pbLearnMove(:ROCKSMASH)
  3703.   $Trainer.party[5].pbLearnMove(:SOFTBOILED)
  3704.   $Trainer.party[5].pbLearnMove(:STRENGTH)
  3705.   $Trainer.party[5].pbLearnMove(:SWEETSCENT)
  3706.   for i in 0...party.length
  3707.     $Trainer.party[i].pbRecordFirstMoves
  3708.    end
  3709.   end
  3710. end
  3711.  
  3712. ################################################################################
  3713. # PBS Alterations                                                              #
  3714. ################################################################################
  3715. module TrainerBattleProperty
  3716.   def self.set(settingname,oldsetting)
  3717.     return oldsetting if !oldsetting
  3718.     properties = [
  3719.        [_INTL("Trainer Type"),TrainerTypeProperty,_INTL("Name of the trainer type for this Trainer.")],
  3720.        [_INTL("Trainer Name"),StringProperty,_INTL("Name of the Trainer.")],
  3721.        [_INTL("Battle ID"),LimitProperty.new(255),_INTL("ID used to distinguish Trainers with the same name and trainer type.")],
  3722.        [_INTL("Pokémon 1"),TrainerPokemonProperty,_INTL("First Pokémon.")],
  3723.        [_INTL("Pokémon 2"),TrainerPokemonProperty,_INTL("Second Pokémon.")],
  3724.        [_INTL("Pokémon 3"),TrainerPokemonProperty,_INTL("Third Pokémon.")],
  3725.        [_INTL("Pokémon 4"),TrainerPokemonProperty,_INTL("Fourth Pokémon.")],
  3726.        [_INTL("Pokémon 5"),TrainerPokemonProperty,_INTL("Fifth Pokémon.")],
  3727.        [_INTL("Pokémon 6"),TrainerPokemonProperty,_INTL("Sixth Pokémon.")],
  3728.        [_INTL("Pokémon 7"),TrainerPokemonProperty,_INTL("Seventh Pokémon.")],
  3729.        [_INTL("Pokémon 8"),TrainerPokemonProperty,_INTL("Eigth Pokémon.")],
  3730.        [_INTL("Item 1"),ItemProperty,_INTL("Item used by the trainer during battle.")],
  3731.        [_INTL("Item 2"),ItemProperty,_INTL("Item used by the trainer during battle.")],
  3732.        [_INTL("Item 3"),ItemProperty,_INTL("Item used by the trainer during battle.")],
  3733.        [_INTL("Item 4"),ItemProperty,_INTL("Item used by the trainer during battle.")],
  3734.        [_INTL("Item 5"),ItemProperty,_INTL("Item used by the trainer during battle.")],
  3735.        [_INTL("Item 6"),ItemProperty,_INTL("Item used by the trainer during battle.")],
  3736.        [_INTL("Item 7"),ItemProperty,_INTL("Item used by the trainer during battle.")],
  3737.        [_INTL("Item 8"),ItemProperty,_INTL("Item used by the trainer during battle.")]
  3738.     ]
  3739.     if !pbPropertyList(settingname,oldsetting,properties,true)
  3740.       oldsetting = nil
  3741.     else
  3742.       oldsetting = nil if !oldsetting[0] || oldsetting[0]==0
  3743.     end
  3744.     return oldsetting
  3745.   end
  3746.  
  3747.   def self.format(value)
  3748.     return value.inspect
  3749.   end
  3750. end
  3751.  
  3752. def pbTrainerBattleEditor
  3753.   selection = 0
  3754.   trainers     = load_data("Data/trainers.dat")
  3755.   trainertypes = load_data("Data/trainertypes.dat")
  3756.   modified = false
  3757.   for trainer in trainers
  3758.     trtype = trainer[0]
  3759.     if !trainertypes || !trainertypes[trtype]
  3760.       trainer[0] = 0
  3761.       modified = true
  3762.     end
  3763.   end
  3764.   if modified
  3765.     save_data(trainers,"Data/trainers.dat")
  3766.     pbConvertTrainerData
  3767.   end
  3768.   pbListScreenBlock(_INTL("Trainer Battles"),TrainerBattleLister.new(selection,true)){|button,trtype|
  3769.     if trtype
  3770.       index = trtype[0]
  3771.       trainerdata = trtype[1]
  3772.       if button==Input::A
  3773.         if index>=0
  3774.           if Kernel.pbConfirmMessageSerious("Delete this trainer battle?")
  3775.             data = load_data("Data/trainers.dat")
  3776.             data.delete_at(index)
  3777.             save_data(data,"Data/trainers.dat")
  3778.             pbConvertTrainerData
  3779.             Kernel.pbMessage(_INTL("The Trainer battle was deleted."))
  3780.           end
  3781.         end
  3782.       elsif button==Input::C
  3783.         selection = index
  3784.         if selection<0
  3785.           ret=Kernel.pbMessage(_INTL("First, define the type of trainer."),[
  3786.              _INTL("Use existing type"),
  3787.              _INTL("Use new type"),
  3788.              _INTL("Cancel")],3)
  3789.           trainertype = -1
  3790.           trainername = ""
  3791.           if ret==0
  3792.             trainertype = pbListScreen(_INTL("TRAINER TYPE"),TrainerTypeLister.new(0,false))
  3793.             next if !trainertype
  3794.             trainertype = trainertype[0]
  3795.             next if trainertype<0
  3796.           elsif ret==1
  3797.             trainertype = pbTrainerTypeEditorNew(nil)
  3798.             next if trainertype<0
  3799.           else
  3800.             next
  3801.           end
  3802.           trainername = Kernel.pbMessageFreeText(_INTL("Now enter the trainer's name."),"",false,32)
  3803.           next if trainername==""
  3804.           trainerparty = pbGetFreeTrainerParty(trainertype,trainername)
  3805.           if trainerparty<0
  3806.             Kernel.pbMessage(_INTL("There is no room to create a trainer of that type and name."))
  3807.             next
  3808.           end
  3809.           ###############
  3810.           pbNewTrainer(trainertype,trainername,trainerparty)
  3811.         else
  3812.           data = [
  3813.              trainerdata[0],      # Trainer type
  3814.              trainerdata[1],      # Trainer name
  3815.              trainerdata[4],      # ID
  3816.              trainerdata[3][0],   # Pokémon 1
  3817.              trainerdata[3][1],   # Pokémon 2
  3818.              trainerdata[3][2],   # Pokémon 3
  3819.              trainerdata[3][3],   # Pokémon 4
  3820.              trainerdata[3][4],   # Pokémon 5
  3821.              trainerdata[3][5],   # Pokémon 6
  3822.              trainerdata[3][6],   # Pokémon 7
  3823.              trainerdata[3][7],   # Pokémon 8
  3824.              trainerdata[2][0],   # Item 1
  3825.              trainerdata[2][1],   # Item 2
  3826.              trainerdata[2][2],   # Item 3
  3827.              trainerdata[2][3],   # Item 4
  3828.              trainerdata[2][4],   # Item 5
  3829.              trainerdata[2][5],   # Item 6
  3830.              trainerdata[2][6],   # Item 7
  3831.              trainerdata[2][7]    # Item 8
  3832.           ]
  3833.           save = false
  3834.           while true
  3835.             data = TrainerBattleProperty.set(trainerdata[1],data)
  3836.             if data
  3837.               trainerdata = [
  3838.                  data[0],
  3839.                  data[1],
  3840.                  [data[9],data[10],data[11],data[12],data[13],data[14],data[15],data[16]].find_all {|i| i && i!=0 },   # Item list
  3841.                  [data[3],data[4],data[5],data[6],data[7],data[8]].find_all {|i| i && i[TPSPECIES]!=0 },   # Pokémon list
  3842.                  data[2]
  3843.               ]
  3844.               if trainerdata[3].length==0
  3845.                 Kernel.pbMessage(_INTL("Can't save. The Pokémon list is empty."))
  3846.               elsif !trainerdata[1] || trainerdata[1].length==0
  3847.                 Kernel.pbMessage(_INTL("Can't save. No name was entered."))
  3848.               else
  3849.                 save = true
  3850.                 break
  3851.               end
  3852.             else
  3853.               break
  3854.             end
  3855.           end
  3856.           if save
  3857.             data = load_data("Data/trainers.dat")
  3858.             data[index] = trainerdata
  3859.             save_data(data,"Data/trainers.dat")
  3860.             pbConvertTrainerData
  3861.           end
  3862.         end
  3863.       end
  3864.     end
  3865.   }
  3866. end
  3867.  
  3868. ################################################################################
  3869. # Storaage Inprovements                                                        #
  3870. ################################################################################
  3871. class PokemonBox
  3872.   attr_reader :pokemon
  3873.   attr_accessor :name
  3874.   attr_accessor :background
  3875.  
  3876.   def initialize(name,maxPokemon=30)
  3877.     @pokemon = []
  3878.     @name = name
  3879.     @background = 0
  3880.     for i in 0...maxPokemon
  3881.       @pokemon[i] = nil
  3882.     end
  3883.   end
  3884.  
  3885.   def length
  3886.     return @pokemon.length
  3887.   end
  3888.  
  3889.   def nitems
  3890.     return @pokemon.nitems
  3891.   end
  3892.  
  3893.   def full?
  3894.     return (@pokemon.nitems==self.length)
  3895.   end
  3896.  
  3897.   def empty?
  3898.     return (@pokemon.nitems==0)
  3899.   end
  3900.  
  3901.   def [](i)
  3902.     return @pokemon[i]
  3903.   end
  3904.  
  3905.   def []=(i,value)
  3906.     @pokemon[i] = value
  3907.   end
  3908.  
  3909.   def each
  3910.     @pokemon.each{|item| yield item}
  3911.   end
  3912.  
  3913.   def clear
  3914.     @pokemon.clear
  3915.   end
  3916. end
  3917.  
  3918. class PokemonStorage
  3919.   attr_reader :boxes
  3920.   attr_accessor :currentBox
  3921.   attr_writer :unlockedWallpapers
  3922.   BASICWALLPAPERQTY = 16
  3923.  
  3924.   def initialize(maxBoxes=STORAGEBOXES,maxPokemon=30)
  3925.     @boxes = []
  3926.     for i in 0...maxBoxes
  3927.       @boxes[i] = PokemonBox.new(_INTL("Box {1}",i+1),maxPokemon)
  3928.       @boxes[i].background = i%BASICWALLPAPERQTY
  3929.     end
  3930.     @currentBox = 0
  3931.     @boxmode = -1
  3932.     @unlockedWallpapers = []
  3933.     for i in 0...allWallpapers.length
  3934.       @unlockedWallpapers[i] = false
  3935.     end
  3936.   end
  3937.  
  3938.   def allWallpapers
  3939.     return [
  3940.        # Basic wallpapers
  3941.        _INTL("Forest"),_INTL("City"),_INTL("Desert"),_INTL("Savanna"),
  3942.        _INTL("Crag"),_INTL("Volcano"),_INTL("Snow"),_INTL("Cave"),
  3943.        _INTL("Beach"),_INTL("Seafloor"),_INTL("River"),_INTL("Sky"),
  3944.        _INTL("Poké Center"),_INTL("Machine"),_INTL("Checks"),_INTL("Simple"),
  3945.        # Special wallpapers
  3946.        _INTL("Space"),_INTL("Backyard"),_INTL("Nostalgic 1"),_INTL("Torchic"),
  3947.        _INTL("Trio 1"),_INTL("PikaPika 1"),_INTL("Legend 1"),_INTL("Team Galactic 1"),
  3948.        _INTL("Distortion"),_INTL("Contest"),_INTL("Nostalgic 2"),_INTL("Croagunk"),
  3949.        _INTL("Trio 2"),_INTL("PikaPika 2"),_INTL("Legend 2"),_INTL("Team Galactic 2"),
  3950.        _INTL("Heart"),_INTL("Soul"),_INTL("Big Brother"),_INTL("Pokéathlon"),
  3951.        _INTL("Trio 3"),_INTL("Spiky Pika"),_INTL("Kimono Girl"),_INTL("Revival")
  3952.     ]
  3953.   end
  3954.  
  3955.   def unlockedWallpapers
  3956.     @unlockedWallpapers = [] if !@unlockedWallpapers
  3957.     return @unlockedWallpapers
  3958.   end
  3959.  
  3960.   def availableWallpapers
  3961.     ret = [[],[]]   # Names, IDs
  3962.     papers = allWallpapers
  3963.     @unlockedWallpapers = [] if !@unlockedWallpapers
  3964.     for i in 0...papers.length
  3965.       next if !isAvailableWallpaper(i)
  3966.       ret[0].push(papers[i]); ret[1].push(i)
  3967.     end
  3968.     return ret
  3969.   end
  3970.  
  3971.   def isAvailableWallpaper(i)
  3972.     @unlockedWallpapers = [] if !@unlockedWallpapers
  3973.     return true if i<BASICWALLPAPERQTY
  3974.     return true if @unlockedWallpapers[i]
  3975.     return false
  3976.   end
  3977.  
  3978.   def party
  3979.     $Trainer.party
  3980.   end
  3981.  
  3982.   def party=(value)
  3983.     raise ArgumentError.new("Not supported")
  3984.   end
  3985.  
  3986.   def maxBoxes
  3987.     return @boxes.length
  3988.   end
  3989.  
  3990.   def maxPokemon(box)
  3991.  if $Trainer.partyplus
  3992.     return 0 if box>=self.maxBoxes
  3993.     return (box<0) ? 8 : self[box].length
  3994.     else
  3995.     return 0 if box>=self.maxBoxes
  3996.     return (box<0) ? 6 : self[box].length
  3997.     end
  3998.  end
  3999.  
  4000.   def full?
  4001.     for i in 0...self.maxBoxes
  4002.       return false if !@boxes[i].full?
  4003.     end
  4004.     return true
  4005.   end
  4006.  
  4007.   def pbFirstFreePos(box)
  4008.   if $Trainer.partyplus
  4009.     if box==-1
  4010.       ret = self.party.nitems
  4011.       return (ret==8) ? -1 : ret
  4012.     else
  4013.       for i in 0...maxPokemon(box)
  4014.         return i if !self[box,i]
  4015.       end
  4016.       return -1
  4017.     end
  4018.   else
  4019.     if box==-1
  4020.       ret = self.party.nitems
  4021.       return (ret==6) ? -1 : ret
  4022.     else
  4023.       for i in 0...maxPokemon(box)
  4024.         return i if !self[box,i]
  4025.       end
  4026.       return -1
  4027.     end
  4028.  end
  4029. end
  4030.  
  4031.   def [](x,y=nil)
  4032.     if y==nil
  4033.       return (x==-1) ? self.party : @boxes[x]
  4034.     else
  4035.       for i in @boxes
  4036.         raise "Box is a Pokémon, not a box" if i.is_a?(PokeBattle_Pokemon)
  4037.       end
  4038.       return (x==-1) ? self.party[y] : @boxes[x][y]
  4039.     end
  4040.   end
  4041.  
  4042.   def []=(x,y,value)
  4043.     if x==-1
  4044.       self.party[y] = value
  4045.     else
  4046.       @boxes[x][y] = value
  4047.     end
  4048.   end
  4049.  
  4050.   def pbCopy(boxDst,indexDst,boxSrc,indexSrc)
  4051.    if $Trainer.partyplus
  4052.     if indexDst<0 && boxDst<self.maxBoxes
  4053.       found = false
  4054.       for i in 0...maxPokemon(boxDst)
  4055.         if !self[boxDst,i]
  4056.           found = true
  4057.           indexDst = i
  4058.           break
  4059.         end
  4060.       end
  4061.       return false if !found
  4062.     end
  4063.     if boxDst==-1
  4064.       return false if self.party.nitems>=8
  4065.       self.party[self.party.length] = self[boxSrc,indexSrc]
  4066.       self.party.compact!
  4067.     else
  4068.       pkmn = self[boxSrc,indexSrc]
  4069.       if !pkmn
  4070.         raise "Trying to copy nil to storage"
  4071.       end
  4072.       pkmn.heal
  4073.       pkmn.formTime = nil if pkmn.respond_to?("formTime") && pkmn.formTime
  4074.       self[boxDst,indexDst] = pkmn
  4075.     end
  4076.     return true
  4077.       else
  4078.     if indexDst<0 && boxDst<self.maxBoxes
  4079.       found = false
  4080.       for i in 0...maxPokemon(boxDst)
  4081.         if !self[boxDst,i]
  4082.           found = true
  4083.           indexDst = i
  4084.           break
  4085.         end
  4086.       end
  4087.       return false if !found
  4088.     end
  4089.     if boxDst==-1
  4090.       return false if self.party.nitems>=6
  4091.       self.party[self.party.length] = self[boxSrc,indexSrc]
  4092.       self.party.compact!
  4093.     else
  4094.       pkmn = self[boxSrc,indexSrc]
  4095.       if !pkmn
  4096.         raise "Trying to copy nil to storage"
  4097.       end
  4098.       pkmn.heal
  4099.       pkmn.formTime = nil if pkmn.respond_to?("formTime") && pkmn.formTime
  4100.       self[boxDst,indexDst] = pkmn
  4101.     end
  4102.     return true
  4103.    end
  4104.   end
  4105.  
  4106.   def pbMove(boxDst,indexDst,boxSrc,indexSrc)
  4107.     return false if !pbCopy(boxDst,indexDst,boxSrc,indexSrc)
  4108.     pbDelete(boxSrc,indexSrc)
  4109.     return true
  4110.   end
  4111.  
  4112.   def pbMoveCaughtToParty(pkmn)
  4113. if $Trainer.partyplus
  4114.     return false if self.party.nitems>=8
  4115.     self.party[self.party.length] = pkmn
  4116. else
  4117.     return false if self.party.nitems>=6
  4118.     self.party[self.party.length] = pkmn
  4119.    end
  4120.   end
  4121.  
  4122.   def pbMoveCaughtToBox(pkmn,box)
  4123.     for i in 0...maxPokemon(box)
  4124.       if self[box,i]==nil
  4125.         if box>=0
  4126.           pkmn.heal
  4127.           pkmn.formTime = nil if pkmn.respond_to?("formTime") && pkmn.formTime
  4128.         end
  4129.         self[box,i] = pkmn
  4130.         return true
  4131.       end
  4132.     end
  4133.     return false
  4134.   end
  4135.  
  4136.   def pbStoreCaught(pkmn)
  4137.     for i in 0...maxPokemon(@currentBox)
  4138.       if self[@currentBox,i]==nil
  4139.         self[@currentBox,i] = pkmn
  4140.         return @currentBox
  4141.       end
  4142.     end
  4143.     for j in 0...self.maxBoxes
  4144.       for i in 0...maxPokemon(j)
  4145.         if self[j,i]==nil
  4146.           self[j,i] = pkmn
  4147.           @currentBox = j
  4148.           return @currentBox
  4149.         end
  4150.       end
  4151.     end
  4152.     return -1
  4153.   end
  4154.  
  4155.   def pbDelete(box,index)
  4156.     if self[box,index]
  4157.       self[box,index] = nil
  4158.       self.party.compact! if box==-1
  4159.     end
  4160.   end
  4161.  
  4162.   def clear
  4163.     for i in 0...self.maxBoxes
  4164.       @boxes[i].clear
  4165.     end
  4166.   end
  4167. end
  4168.  
  4169. #===============================================================================
  4170. # Regional Storage scripts
  4171. #===============================================================================
  4172. class RegionalStorage
  4173.   def initialize
  4174.     @storages = []
  4175.     @lastmap = -1
  4176.     @rgnmap = -1
  4177.   end
  4178.  
  4179.   def getCurrentStorage
  4180.     if !$game_map
  4181.       raise _INTL("The player is not on a map, so the region could not be determined.")
  4182.     end
  4183.     if @lastmap!=$game_map.map_id
  4184.       @rgnmap = pbGetCurrentRegion # may access file IO, so caching result
  4185.       @lastmap = $game_map.map_id
  4186.     end
  4187.     if @rgnmap<0
  4188.       raise _INTL("The current map has no region set. Please set the MapPosition metadata setting for this map.")
  4189.     end
  4190.     if !@storages[@rgnmap]
  4191.       @storages[@rgnmap] = PokemonStorage.new
  4192.     end
  4193.     return @storages[@rgnmap]
  4194.   end
  4195.  
  4196.   def allWallpapers
  4197.     return getCurrentStorage.allWallpapers
  4198.   end
  4199.  
  4200.   def availableWallpapers
  4201.     return getCurrentStorage.availableWallpapers
  4202.   end
  4203.  
  4204.   def unlockWallpaper(index)
  4205.     getCurrentStorage.unlockWallpaper(index)
  4206.   end
  4207.  
  4208.   def boxes
  4209.     return getCurrentStorage.boxes
  4210.   end
  4211.  
  4212.   def party
  4213.     return getCurrentStorage.party
  4214.   end
  4215.  
  4216.   def maxBoxes
  4217.     return getCurrentStorage.maxBoxes
  4218.   end
  4219.  
  4220.   def maxPokemon(box)
  4221.     return getCurrentStorage.maxPokemon(box)
  4222.   end
  4223.  
  4224.   def full?
  4225.     getCurrentStorage.full?
  4226.   end
  4227.  
  4228.   def currentBox
  4229.     return getCurrentStorage.currentBox
  4230.   end
  4231.  
  4232.   def currentBox=(value)
  4233.     getCurrentStorage.currentBox = value
  4234.   end
  4235.  
  4236.   def [](x,y=nil)
  4237.     getCurrentStorage[x,y]
  4238.   end
  4239.  
  4240.   def []=(x,y,value)
  4241.     getCurrentStorage[x,y] = value
  4242.   end
  4243.  
  4244.   def pbFirstFreePos(box)
  4245.     getCurrentStorage.pbFirstFreePos(box)
  4246.   end
  4247.  
  4248.   def pbCopy(boxDst,indexDst,boxSrc,indexSrc)
  4249.     getCurrentStorage.pbCopy(boxDst,indexDst,boxSrc,indexSrc)
  4250.   end
  4251.  
  4252.   def pbMove(boxDst,indexDst,boxSrc,indexSrc)
  4253.     getCurrentStorage.pbCopy(boxDst,indexDst,boxSrc,indexSrc)
  4254.   end
  4255.  
  4256.   def pbMoveCaughtToParty(pkmn)
  4257.     getCurrentStorage.pbMoveCaughtToParty(pkmn)
  4258.   end
  4259.  
  4260.   def pbMoveCaughtToBox(pkmn,box)
  4261.     getCurrentStorage.pbMoveCaughtToBox(pkmn,box)
  4262.   end
  4263.  
  4264.   def pbStoreCaught(pkmn)
  4265.     getCurrentStorage.pbStoreCaught(pkmn)
  4266.   end
  4267.  
  4268.   def pbDelete(box,index)
  4269.     getCurrentStorage.pbDelete(pkmn)
  4270.   end
  4271. end
  4272.  
  4273. #===============================================================================
  4274. #
  4275. #===============================================================================
  4276. def pbUnlockWallpaper(index)
  4277.   $PokemonStorage.unlockedWallpapers[index] = true
  4278. end
  4279.  
  4280. def pbLockWallpaper(index)   # Don't know why you'd want to do this
  4281.   $PokemonStorage.unlockedWallpapers[index] = false
  4282. end
  4283.  
  4284. #===============================================================================
  4285. # Battle Party
  4286. #===============================================================================
  4287.  class PokeBattle_DebugScene
  4288.   def initialize
  4289.     @battle=nil
  4290.     @lastcmd=[0,0,0,0]
  4291.     @lastmove=[0,0,0,0]
  4292.     @pkmnwindows=[nil,nil,nil,nil]
  4293.   end
  4294.  
  4295.   def pbDisplayMessage(msg,brief=false)
  4296.     pbRefresh
  4297.     cw = Window_SimpleText.new(msg,4)
  4298.     cw.y=256
  4299.     i=0
  4300.     loop do
  4301.       Graphics.update
  4302.       Input.update
  4303.       cw.update
  4304.       if i==80
  4305.         cw.dispose
  4306.         return
  4307.       end
  4308.       if Input.trigger?(Input::C)
  4309.         cw.dispose
  4310.         return
  4311.       end
  4312.       i+=1
  4313.     end
  4314.   end
  4315.  
  4316.   def pbDisplayPausedMessage(msg)
  4317.     cw = Window_SimpleText.new(msg,4)
  4318.     cw.y=256
  4319.     cw.pause=true
  4320.     loop do
  4321.       Graphics.update
  4322.       Input.update
  4323.       cw.update
  4324.       if Input.trigger?(Input::C)
  4325.         cw.dispose
  4326.         return
  4327.       end
  4328.     end
  4329.   end
  4330.  
  4331.   def pbDisplayConfirmMessage(msg)
  4332.     dw = Window_SimpleText.new(msg,4)
  4333.     dw.y=256
  4334.     commands=["YES","NO"]
  4335.     cw = Window_Command.new(96, commands)
  4336.     cw.x=384
  4337.     cw.y=160
  4338.     cw.index=0
  4339.     pbRefresh
  4340.     loop do
  4341.       Graphics.update
  4342.       Input.update
  4343.       pbFrameUpdate(cw)
  4344.       if Input.trigger?(Input::B)
  4345.         cw.dispose
  4346.         dw.dispose
  4347.         return false
  4348.       end
  4349.       if Input.trigger?(Input::C)
  4350.         cw.dispose
  4351.         dw.dispose
  4352.         return (cw.index==0)?true:false
  4353.       end
  4354.     end
  4355.   end
  4356.  
  4357.   def pbFrameUpdate(cw)
  4358.     cw.update if cw
  4359.     for i in 0..3
  4360.       @pkmnwindows[i].update if @pkmnwindows[i]
  4361.     end
  4362. #   @exceptwindow.text="Exceptions: #{$PBDebugExceptions}"
  4363. #   @exceptwindow.update
  4364.   end
  4365.  
  4366.   def pbRefresh
  4367.     for i in 0..3
  4368.       @pkmnwindows[i].refresh if @pkmnwindows[i]
  4369.     end
  4370. #   @exceptwindow.refresh
  4371.   end
  4372.  
  4373. # Called whenever a new round begins.
  4374.   def pbBeginCommandPhase
  4375.   end
  4376.  
  4377. # Called whenever the battle begins
  4378.   def pbStartBattle(battle)
  4379.     @battle=battle
  4380.     @lastcmd=[0,0,0,0]
  4381.     @lastmove=[0,0,0,0]
  4382.     numwindows=battle.doublebattle ? 4 : 2
  4383.     for i in 0...numwindows
  4384.       @pkmnwindows[i]=Window_Pokemon.new(@battle.battlers[i])
  4385.       @pkmnwindows[i].y=i*64
  4386.     end
  4387. #   @exceptwindow=Window_SimpleText.new("Exceptions: 0",1)
  4388. #   @exceptwindow.x=0
  4389. #   @exceptwindow.y=416
  4390.   end
  4391.  
  4392.   def pbEndBattle(result)
  4393.     for i in 0..3
  4394.       @pkmnwindows[i].dispose if @pkmnwindows[i]
  4395.     end
  4396. #   @exceptwindow.dispose
  4397.   end
  4398.  
  4399.   def pbTrainerSendOut(battle,pkmn)
  4400.     pbRefresh
  4401.   end
  4402.  
  4403.   def pbSendOut(battle,pkmn)
  4404.     pbRefresh
  4405.   end
  4406.  
  4407.   def pbTrainerWithdraw(battle,pkmn)
  4408.     pbRefresh
  4409.   end
  4410.  
  4411.   def pbWithdraw(battle,pkmn)
  4412.     pbRefresh
  4413.   end
  4414.  
  4415. # Called whenever a Pokémon should forget a move.  It should return -1 if the
  4416. # selection is canceled, or 0 to 3 to indicate the move to forget.
  4417. # The function should not allow HM moves to be forgotten.
  4418.   def pbForgetMove(pkmn,move)
  4419.     return 0
  4420.   end
  4421.  
  4422.   def pbBeginAttackPhase
  4423.   end
  4424.  
  4425. # Use this method to display the list of commands.
  4426. #  Return values:
  4427. #  0 - Fight
  4428. #  1 - Pokémon
  4429. #  2 - Bag
  4430. #  3 - Run
  4431.   def pbCommandMenu(index)
  4432.     commands=["FIGHT","POKéMON","BAG","RUN"]
  4433.     cw = Window_Command.new(192, commands)
  4434.     cw.x=0
  4435.     cw.y=256
  4436.     cw.index=@lastcmd[index]
  4437.     pbRefresh
  4438.     loop do
  4439.       Graphics.update
  4440.       Input.update
  4441.       pbFrameUpdate(cw)
  4442.       if Input.trigger?(Input::C)
  4443.         ret=cw.index
  4444.         cw.dispose
  4445.         @lastcmd[index]=ret
  4446.         return ret
  4447.       end
  4448.     end
  4449.   end
  4450.  
  4451.   def pbPokemonString(pkmn)
  4452.     status=""
  4453.     if pkmn.hp<=0
  4454.       status=" [FNT]"
  4455.     else
  4456.       case pkmn.status
  4457.       when PBStatuses::SLEEP
  4458.         status=" [SLP]"
  4459.       when PBStatuses::FROZEN
  4460.         status=" [FRZ]"
  4461.       when PBStatuses::BURN
  4462.         status=" [BRN]"
  4463.       when PBStatuses::PARALYSIS
  4464.         status=" [PAR]"
  4465.       when PBStatuses::POISON
  4466.         status=" [PSN]"
  4467.       end
  4468.     end
  4469.     return "#{pkmn.name} (Lv. #{pkmn.level})#{status} HP: #{pkmn.hp}/#{pkmn.totalhp}"
  4470.   end
  4471.  
  4472.   def pbMoveString(move)
  4473.     ret="#{move.name}"
  4474.     typename=PBTypes.getName(move.type)
  4475.     if move.id>0
  4476.       ret+=" (#{typename}) PP: #{move.pp}/#{move.totalpp}"
  4477.     end
  4478.     return ret
  4479.   end
  4480.  
  4481. # Use this method to display the list of moves for a Pokémon
  4482.   def pbFightMenu(index)
  4483.     moves=@battle.battlers[index].moves
  4484.     commands=[
  4485.        pbMoveString(moves[0]),
  4486.        pbMoveString(moves[1]),
  4487.        pbMoveString(moves[2]),
  4488.        pbMoveString(moves[3])
  4489.     ]
  4490.     cw = Window_Command.new(480, commands)
  4491.     cw.x=0
  4492.     cw.y=256
  4493.     cw.index=@lastmove[index]
  4494.     pbRefresh
  4495.     loop do
  4496.       Graphics.update
  4497.       Input.update
  4498.       pbFrameUpdate(cw)
  4499.       if Input.trigger?(Input::B)
  4500.         @lastmove[index]=cw.index
  4501.         cw.dispose
  4502.         return -1
  4503.       end
  4504.       if Input.trigger?(Input::C)
  4505.         ret=cw.index
  4506.         @lastmove[index]=ret
  4507.         cw.dispose
  4508.         return ret
  4509.       end
  4510.     end
  4511.   end
  4512.  
  4513.   def pbResetMoveIndex(index)
  4514.   end
  4515.  
  4516. # Use this method to display the inventory
  4517. # The return value is the item chosen, or 0 if the choice was canceled.
  4518.   def pbItemMenu(index)
  4519.     pbDisplayMessage("Items can't be used here.")
  4520.     return -1
  4521.   end
  4522.  
  4523.   def pbFirstTarget(index,targettype)
  4524.     for i in 0...4
  4525.       if i!=index && !@battle.battlers[i].isFainted?
  4526.         return i
  4527.       end  
  4528.     end
  4529.     return -1
  4530.   end
  4531.  
  4532.   def pbNextTarget(cur,index)
  4533.     return -1 if cur>=3
  4534.     for i in cur+1..3
  4535.       if i!=index && !@battle.battlers[i].isFainted?
  4536.         return i
  4537.       end  
  4538.     end
  4539.     return -1
  4540.   end
  4541.  
  4542.   def pbPrevTarget(cur,index)
  4543.     return -1 if cur<=0
  4544.     ret=-1
  4545.     for i in 0..cur-1
  4546.       if i!=index && !@battle.battlers[i].isFainted?
  4547.         ret=i
  4548.       end  
  4549.     end
  4550.     return ret
  4551.   end
  4552.  
  4553. # Use this method to make the player choose a target
  4554. # for certain moves in double battles.
  4555.   def pbChooseTarget(index,targettype)
  4556.     curwindow=pbFirstTarget(index,targettype)
  4557.     if curwindow==-1
  4558.       raise RuntimeError.new("No targets somehow...")
  4559.     end
  4560.     numwindows=@battle.doublebattle ? 4 : 2
  4561.     for i in 0...numwindows
  4562.       @pkmnwindows[i].highlighted=(i==curwindow)
  4563.     end
  4564.     pbRefresh
  4565.     loop do
  4566.       Graphics.update
  4567.       Input.update
  4568.       pbFrameUpdate(nil)
  4569.       if Input.trigger?(Input::DOWN)
  4570.         newwindow=pbNextTarget(curwindow,index)
  4571.         if newwindow>=0
  4572.           curwindow=newwindow
  4573.           for i in 0...numwindows
  4574.             @pkmnwindows[i].highlighted=(i==curwindow)
  4575.           end
  4576.         end
  4577.       end
  4578.       if Input.trigger?(Input::UP)
  4579.         newwindow=pbPrevTarget(curwindow,index)
  4580.         if newwindow>=0
  4581.           curwindow=newwindow
  4582.           for i in 0...numwindows
  4583.             @pkmnwindows[i].highlighted=(i==curwindow)
  4584.           end
  4585.         end
  4586.       end
  4587.       if Input.trigger?(Input::B)
  4588.         for i in 0...numwindows
  4589.           @pkmnwindows[i].highlighted=false
  4590.           @pkmnwindows[i].update
  4591.         end
  4592.         return -1
  4593.       end
  4594.       if Input.trigger?(Input::C)
  4595.         for i in 0...numwindows
  4596.           @pkmnwindows[i].highlighted=false
  4597.           @pkmnwindows[i].update
  4598.         end
  4599.         return curwindow
  4600.       end
  4601.     end
  4602.   end
  4603.  
  4604.   def pbSwitch(index,lax,cancancel)
  4605.     party=@battle.pbParty(index)
  4606.     commands=[]
  4607.     inactives=[1,1,1,1,1,1,1,1]
  4608.     partypos=[]
  4609.     activecmd=0
  4610.     numactive=(@doublebattle)?2:1
  4611.     battler=@battle.battlers[0]
  4612.     commands[commands.length]=pbPokemonString(party[battler.pokemonIndex])
  4613.     activecmd=0 if battler.index==index
  4614.     inactives[battler.pokemonIndex]=0
  4615.     partypos[partypos.length]=battler.pokemonIndex
  4616.     if @battle.doublebattle
  4617.       battler=@battle.battlers[2]
  4618.       commands[commands.length]=pbPokemonString(party[battler.pokemonIndex])
  4619.       activecmd=1 if battler.index==index
  4620.       inactives[battler.pokemonIndex]=0
  4621.       partypos[partypos.length]=battler.pokemonIndex
  4622.     end
  4623.     for i in 0..party.length-1
  4624.       if inactives[i]==1
  4625.         commands[commands.length]=pbPokemonString(party[i])
  4626.         partypos[partypos.length]=i
  4627.       end
  4628.     end
  4629.     for i in 0..4
  4630.       @pkmnwindows[i].visible=false if @pkmnwindows[i]
  4631.     end
  4632.     cw = Window_Command.new(480, commands)
  4633.     cw.x=0
  4634.     cw.y=0
  4635.     cw.index=activecmd
  4636.     pbRefresh
  4637.     ret=0
  4638.     loop do
  4639.       Graphics.update
  4640.       Input.update
  4641.       pbFrameUpdate(cw)
  4642.       if cancancel && Input.trigger?(Input::B)
  4643.         ret=-1
  4644.         cw.dispose
  4645.         break
  4646.       end
  4647.       if Input.trigger?(Input::C)
  4648.         pkmnindex=partypos[cw.index]
  4649.         canswitch=lax ? @battle.pbCanSwitchLax?(index,pkmnindex,true) :
  4650.            @battle.pbCanSwitch?(index,pkmnindex,true)
  4651.         if canswitch
  4652.           ret=pkmnindex
  4653.           cw.dispose
  4654.           break
  4655.         end
  4656.       end
  4657.     end
  4658.     for i in 0..4
  4659.       @pkmnwindows[i].visible=true if @pkmnwindows[i]
  4660.     end
  4661.     return ret
  4662.   end
  4663.  
  4664. # This method is called whenever a Pokémon's HP changes.
  4665. # Used to animate the HP bar.
  4666.   def pbHPChanged(pkmn,oldhp,anim=false)
  4667.     hpchange=pkmn.hp-oldhp
  4668.     if hpchange<0
  4669.       hpchange=-hpchange
  4670.       PBDebug.log("[HP change] #{pkmn.pbThis} lost #{hpchange} HP (#{oldhp}=>#{pkmn.hp})")
  4671.     else
  4672.       PBDebug.log("[HP change] #{pkmn.pbThis} gained #{hpchange} HP (#{oldhp}=>#{pkmn.hp})")
  4673.     end
  4674.     pbRefresh
  4675.   end
  4676.  
  4677. # This method is called whenever a Pokémon faints
  4678.   def pbFainted(pkmn)
  4679.   end
  4680.  
  4681.   def pbChooseEnemyCommand(index)
  4682.     @battle.pbDefaultChooseEnemyCommand(index)
  4683.   end
  4684.  
  4685. # Use this method to choose a new Pokémon for the enemy
  4686. # The enemy's party is guaranteed to have at least one choosable member.
  4687.   def pbChooseNewEnemy(index,party)
  4688.     @battle.pbDefaultChooseNewEnemy(index,party)
  4689.   end
  4690.  
  4691. # This method is called when the player wins a wild Pokémon battle.
  4692. # This method can change the battle's music for example.
  4693.   def pbWildBattleSuccess
  4694.   end
  4695.  
  4696. # This method is called when the player wins a Trainer battle.
  4697. # This method can change the battle's music for example.
  4698.   def pbTrainerBattleSuccess
  4699.   end
  4700.  
  4701.   def pbEXPBar(battler,thispoke,startexp,endexp,tempexp1,tempexp2)
  4702.   end
  4703.  
  4704.   def pbLevelUp(battler,thispoke,oldtotalhp,oldattack,
  4705.                 olddefense,oldspeed,oldspatk,oldspdef)
  4706.   end
  4707.  
  4708.   def pbShowOpponent(opp)
  4709.   end
  4710.  
  4711.   def pbHideOpponent
  4712.   end
  4713.  
  4714.   def pbRecall(battlerindex)
  4715.   end
  4716.  
  4717.   def pbDamageAnimation(pkmn,effectiveness)
  4718.   end
  4719.  
  4720.   def pbAnimation(moveid,attacker,opponent,hitnum=0)
  4721.     if attacker
  4722.       if opponent
  4723.         PBDebug.log("[pbAnimation] #{attacker.pbThis}, #{opponent.pbThis}")
  4724.       else
  4725.         PBDebug.log("[pbAnimation] #{attacker.pbThis}")
  4726.       end
  4727.     else
  4728.       PBDebug.log("[pbAnimation]")
  4729.     end
  4730.   end
  4731. end
  4732.  
  4733. ################################################################################
  4734. # Battles ######################################################################
  4735. ################################################################################
  4736. #===============================================================================
  4737. # Start a double wild battle
  4738. #===============================================================================
  4739. def pbDoubleWildBattle(species1,level1,species2,level2,variable=nil,canescape=true,canlose=false)
  4740.   if (Input.press?(Input::CTRL) && $DEBUG) || $Trainer.pokemonCount==0
  4741.     if $Trainer.pokemonCount>0
  4742.       Kernel.pbMessage(_INTL("SKIPPING BATTLE..."))
  4743.     end
  4744.     pbSet(variable,1)
  4745.     $PokemonGlobal.nextBattleBGM  = nil
  4746.     $PokemonGlobal.nextBattleME   = nil
  4747.     $PokemonGlobal.nextBattleBack = nil
  4748.     return true
  4749.   end
  4750.   if species1.is_a?(String) || species1.is_a?(Symbol)
  4751.     species1 = getID(PBSpecies,species1)
  4752.   end
  4753.   if species2.is_a?(String) || species2.is_a?(Symbol)
  4754.     species2 = getID(PBSpecies,species2)
  4755.   end
  4756.   currentlevels = []
  4757.   for i in $Trainer.party
  4758.     currentlevels.push(i.level)
  4759.   end
  4760.   genwildpoke  = pbGenerateWildPokemon(species1,level1)
  4761.   genwildpoke2 = pbGenerateWildPokemon(species2,level2)
  4762.   Events.onStartBattle.trigger(nil,genwildpoke)
  4763.   scene = pbNewBattleScene
  4764.   if $PokemonGlobal.partner
  4765.     othertrainer = PokeBattle_Trainer.new($PokemonGlobal.partner[1],$PokemonGlobal.partner[0])
  4766.     othertrainer.id    = $PokemonGlobal.partner[2]
  4767.     othertrainer.party = $PokemonGlobal.partner[3]
  4768.     combinedParty = []
  4769.     for i in 0...$Trainer.party.length
  4770.       combinedParty[i] = $Trainer.party[i]
  4771.     end
  4772.      if $Trainer.partyplus
  4773.     for i in 0...othertrainer.party.length
  4774.       combinedParty[8+i] = othertrainer.party[i]
  4775.     end
  4776.      else
  4777.     for i in 0...othertrainer.party.length
  4778.       combinedParty[6+i] = othertrainer.party[i]
  4779.     end
  4780.      end
  4781.     battle = PokeBattle_Battle.new(scene,combinedParty,[genwildpoke,genwildpoke2],[$Trainer,othertrainer],nil)
  4782.     battle.fullparty1 = true
  4783.   else
  4784.     battle = PokeBattle_Battle.new(scene,$Trainer.party,[genwildpoke,genwildpoke2],$Trainer,nil)
  4785.     battle.fullparty1 = false
  4786.   end
  4787.   battle.internalbattle = true
  4788.   battle.doublebattle   = battle.pbDoubleBattleAllowed?()
  4789.   battle.cantescape     = !canescape
  4790.   pbPrepareBattle(battle)
  4791.   decision = 0
  4792.   pbBattleAnimation(pbGetWildBattleBGM(species1),2,[genwildpoke,genwildpoke2]) {
  4793.     pbSceneStandby {
  4794.       decision = battle.pbStartBattle(canlose)
  4795.     }
  4796.     pbAfterBattle(decision,canlose)
  4797.   }
  4798.   Input.update
  4799.   pbSet(variable,decision)
  4800.   return (decision!=2 && decision!=5)
  4801. end
  4802.  
  4803. #===============================================================================
  4804. # Start a trainer battle against one trainer
  4805. #===============================================================================
  4806. def pbTrainerBattle(trainerid,trainername,endspeech,
  4807.                     doublebattle=false,trainerparty=0,canlose=false,variable=nil)
  4808.   if $Trainer.pokemonCount==0
  4809.     Kernel.pbMessage(_INTL("SKIPPING BATTLE...")) if $DEBUG
  4810.     return false
  4811.   end
  4812. if $Trainer.partyplus
  4813.   if !$PokemonTemp.waitingTrainer && pbMapInterpreterRunning? &&
  4814.      ($Trainer.ablePokemonCount>1 || $Trainer.ablePokemonCount>0 && $PokemonGlobal.partner)
  4815.     thisEvent = pbMapInterpreter.get_character(0)
  4816.     triggeredEvents = $game_player.pbTriggeredTrainerEvents([2],false)
  4817.     otherEvent = []
  4818.     for i in triggeredEvents
  4819.       if i.id!=thisEvent.id && !$game_self_switches[[$game_map.map_id,i.id,"A"]]
  4820.         otherEvent.push(i)
  4821.       end
  4822.     end
  4823.     if otherEvent.length==1
  4824.       trainer = pbLoadTrainer(trainerid,trainername,trainerparty)
  4825.       Events.onTrainerPartyLoad.trigger(nil,trainer)
  4826.       if !trainer
  4827.         pbMissingTrainer(trainerid,trainername,trainerparty)
  4828.         return false
  4829.       end
  4830.       if trainer[2].length<=8
  4831.         $PokemonTemp.waitingTrainer=[trainer,thisEvent.id,endspeech]
  4832.         return false
  4833.       end
  4834.     end
  4835.   end
  4836.   else
  4837.   if !$PokemonTemp.waitingTrainer && pbMapInterpreterRunning? &&
  4838.      ($Trainer.ablePokemonCount>1 || $Trainer.ablePokemonCount>0 && $PokemonGlobal.partner)
  4839.     thisEvent = pbMapInterpreter.get_character(0)
  4840.     triggeredEvents = $game_player.pbTriggeredTrainerEvents([2],false)
  4841.     otherEvent = []
  4842.     for i in triggeredEvents
  4843.       if i.id!=thisEvent.id && !$game_self_switches[[$game_map.map_id,i.id,"A"]]
  4844.         otherEvent.push(i)
  4845.       end
  4846.     end
  4847.     if otherEvent.length==1
  4848.       trainer = pbLoadTrainer(trainerid,trainername,trainerparty)
  4849.       Events.onTrainerPartyLoad.trigger(nil,trainer)
  4850.       if !trainer
  4851.         pbMissingTrainer(trainerid,trainername,trainerparty)
  4852.         return false
  4853.       end
  4854.       if trainer[2].length<=6
  4855.         $PokemonTemp.waitingTrainer=[trainer,thisEvent.id,endspeech]
  4856.         return false
  4857.       end
  4858.     end
  4859.   end
  4860.   end
  4861.   trainer = pbLoadTrainer(trainerid,trainername,trainerparty)
  4862.   Events.onTrainerPartyLoad.trigger(nil,trainer)
  4863.   if !trainer
  4864.     pbMissingTrainer(trainerid,trainername,trainerparty)
  4865.     return false
  4866.   end
  4867.   if $PokemonGlobal.partner && ($PokemonTemp.waitingTrainer || doublebattle)
  4868.     othertrainer = PokeBattle_Trainer.new($PokemonGlobal.partner[1],$PokemonGlobal.partner[0])
  4869.     othertrainer.id    = $PokemonGlobal.partner[2]
  4870.     othertrainer.party = $PokemonGlobal.partner[3]
  4871.     playerparty = []
  4872.     for i in 0...$Trainer.party.length
  4873.       playerparty[i] = $Trainer.party[i]
  4874.     end
  4875. if $Trainer.partyplus
  4876.     for i in 0...othertrainer.party.length
  4877.       playerparty[8+i] = othertrainer.party[i]
  4878.     end
  4879. else
  4880.     for i in 0...othertrainer.party.length
  4881.       playerparty[6+i] = othertrainer.party[i]
  4882.     end
  4883. end
  4884.     playertrainer = [$Trainer,othertrainer]
  4885.     fullparty1    = true
  4886.     doublebattle  = true
  4887.   else
  4888.     playerparty   = $Trainer.party
  4889.     playertrainer = $Trainer
  4890.     fullparty1    = false
  4891.   end
  4892.   if $PokemonTemp.waitingTrainer
  4893.     combinedParty = []
  4894.     fullparty2 = false
  4895.     if $PokemonTemp.waitingTrainer[0][2].length>3 || trainer[2].length>3
  4896.       for i in 0...$PokemonTemp.waitingTrainer[0][2].length
  4897.         combinedParty[i] = $PokemonTemp.waitingTrainer[0][2][i]
  4898.       end
  4899. if $Trainer.partyplus
  4900.       for i in 0...trainer[2].length
  4901.         combinedParty[8+i] = trainer[2][i]
  4902.       end
  4903. else
  4904.       for i in 0...trainer[2].length
  4905.         combinedParty[6+i] = trainer[2][i]
  4906.       end
  4907. end
  4908.       fullparty2 = true
  4909.     else
  4910.       for i in 0...$PokemonTemp.waitingTrainer[0][2].length
  4911.         combinedParty[i] = $PokemonTemp.waitingTrainer[0][2][i]
  4912.       end
  4913. if $Trainer.partyplus
  4914.       for i in 0...trainer[2].length
  4915.         combinedParty[4+i] = trainer[2][i]
  4916.       end
  4917. else
  4918.       for i in 0...trainer[2].length
  4919.         combinedParty[3+i] = trainer[2][i]
  4920.       end
  4921. end
  4922.     end
  4923.     scene = pbNewBattleScene
  4924.     battle = PokeBattle_Battle.new(scene,playerparty,combinedParty,playertrainer,
  4925.                                    [$PokemonTemp.waitingTrainer[0][0],trainer[0]])
  4926.     battle.fullparty1   = fullparty1
  4927.     battle.fullparty2   = fullparty2
  4928.     battle.doublebattle = battle.pbDoubleBattleAllowed?
  4929.     battle.endspeech    = $PokemonTemp.waitingTrainer[2]
  4930.     battle.endspeech2   = endspeech
  4931.     battle.items        = [$PokemonTemp.waitingTrainer[0][1],trainer[1]]
  4932.     trainerbgm = pbGetTrainerBattleBGM([$PokemonTemp.waitingTrainer[0][0],trainer[0]])
  4933.   else
  4934.     scene = pbNewBattleScene
  4935.     battle = PokeBattle_Battle.new(scene,playerparty,trainer[2],playertrainer,trainer[0])
  4936.     battle.fullparty1   = fullparty1
  4937.     battle.doublebattle = (doublebattle) ? battle.pbDoubleBattleAllowed? : false
  4938.     battle.endspeech    = endspeech
  4939.     battle.items        = trainer[1]
  4940.     trainerbgm = pbGetTrainerBattleBGM(trainer[0])
  4941.   end
  4942.   if Input.press?(Input::CTRL) && $DEBUG
  4943.     Kernel.pbMessage(_INTL("SKIPPING BATTLE..."))
  4944.     Kernel.pbMessage(_INTL("AFTER LOSING..."))
  4945.     Kernel.pbMessage(battle.endspeech)
  4946.     Kernel.pbMessage(battle.endspeech2) if battle.endspeech2
  4947.     if $PokemonTemp.waitingTrainer
  4948.       pbMapInterpreter.pbSetSelfSwitch($PokemonTemp.waitingTrainer[1],"A",true)
  4949.       $PokemonTemp.waitingTrainer = nil
  4950.     end
  4951.     return true
  4952.   end
  4953.   Events.onStartBattle.trigger(nil,nil)
  4954.   battle.internalbattle = true
  4955.   pbPrepareBattle(battle)
  4956.   restorebgm = true
  4957.   decision = 0
  4958.   Audio.me_stop
  4959.   tr = [trainer]; tr.push($PokemonTemp.waitingTrainer[0]) if $PokemonTemp.waitingTrainer
  4960.   pbBattleAnimation(trainerbgm,(battle.doublebattle) ? 3 : 1,tr) {
  4961.     pbSceneStandby {
  4962.       decision = battle.pbStartBattle(canlose)
  4963.     }
  4964.     pbAfterBattle(decision,canlose)
  4965.     if decision==1
  4966.       if $PokemonTemp.waitingTrainer
  4967.         pbMapInterpreter.pbSetSelfSwitch($PokemonTemp.waitingTrainer[1],"A",true)
  4968.       end
  4969.     end
  4970.   }
  4971.   Input.update
  4972.   pbSet(variable,decision)
  4973.   $PokemonTemp.waitingTrainer = nil
  4974.   return (decision==1)
  4975. end
  4976.  
  4977. #===============================================================================
  4978. # Start a trainer battle against two trainers
  4979. #===============================================================================
  4980. def pbDoubleTrainerBattle(trainerid1, trainername1, trainerparty1, endspeech1,
  4981.                           trainerid2, trainername2, trainerparty2, endspeech2,
  4982.                           canlose=false,variable=nil)
  4983.   trainer1 = pbLoadTrainer(trainerid1,trainername1,trainerparty1)
  4984.   Events.onTrainerPartyLoad.trigger(nil,trainer1)
  4985.   if !trainer1
  4986.     pbMissingTrainer(trainerid1,trainername1,trainerparty1)
  4987.   end
  4988.   trainer2 = pbLoadTrainer(trainerid2,trainername2,trainerparty2)
  4989.   Events.onTrainerPartyLoad.trigger(nil,trainer2)
  4990.   if !trainer2
  4991.     pbMissingTrainer(trainerid2,trainername2,trainerparty2)
  4992.   end
  4993.   if !trainer1 || !trainer2
  4994.     return false
  4995.   end
  4996.   if $PokemonGlobal.partner
  4997.     othertrainer = PokeBattle_Trainer.new($PokemonGlobal.partner[1],$PokemonGlobal.partner[0])
  4998.     othertrainer.id    = $PokemonGlobal.partner[2]
  4999.     othertrainer.party = $PokemonGlobal.partner[3]
  5000.     playerparty = []
  5001.     for i in 0...$Trainer.party.length
  5002.       playerparty[i] = $Trainer.party[i]
  5003.     end
  5004. if $Trainer.partyplus
  5005.     for i in 0...othertrainer.party.length
  5006.       playerparty[8+i] = othertrainer.party[i]
  5007.     end
  5008. else
  5009.     for i in 0...othertrainer.party.length
  5010.       playerparty[6+i] = othertrainer.party[i]
  5011.     end
  5012. end
  5013.     playertrainer = [$Trainer,othertrainer]
  5014.     fullparty1    = true
  5015.   else
  5016.     playerparty   = $Trainer.party
  5017.     playertrainer = $Trainer
  5018.     fullparty1    = false
  5019.   end
  5020.   combinedParty = []
  5021.   for i in 0...trainer1[2].length
  5022.     combinedParty[i] = trainer1[2][i]
  5023.   end
  5024. if $Trainer.partyplus
  5025.   for i in 0...trainer2[2].length
  5026.     combinedParty[8+i] = trainer2[2][i]
  5027.   end
  5028. else
  5029.   for i in 0...trainer2[2].length
  5030.     combinedParty[6+i] = trainer2[2][i]
  5031.   end
  5032. end
  5033.   scene = pbNewBattleScene
  5034.   battle = PokeBattle_Battle.new(scene,playerparty,combinedParty,playertrainer,
  5035.                                  [trainer1[0],trainer2[0]])
  5036.   battle.fullparty1   = fullparty1
  5037.   battle.fullparty2   = true
  5038.   battle.doublebattle = battle.pbDoubleBattleAllowed?()
  5039.   battle.endspeech    = endspeech1
  5040.   battle.endspeech2   = endspeech2
  5041.   battle.items        = [trainer1[1],trainer2[1]]
  5042.   trainerbgm = pbGetTrainerBattleBGM([trainer1[0],trainer2[0]])
  5043.   if Input.press?(Input::CTRL) && $DEBUG
  5044.     Kernel.pbMessage(_INTL("SKIPPING BATTLE..."))
  5045.     Kernel.pbMessage(_INTL("AFTER LOSING..."))
  5046.     Kernel.pbMessage(battle.endspeech)
  5047.     Kernel.pbMessage(battle.endspeech2) if battle.endspeech2 && battle.endspeech2!=""
  5048.     return true
  5049.   end
  5050.   Events.onStartBattle.trigger(nil,nil)
  5051.   battle.internalbattle = true
  5052.   pbPrepareBattle(battle)
  5053.   restorebgm = true
  5054.   decision = 0
  5055.   pbBattleAnimation(trainerbgm,(battle.doublebattle) ? 3 : 1,[trainer1,trainer2]) {
  5056.     pbSceneStandby {
  5057.        decision = battle.pbStartBattle(canlose)
  5058.     }
  5059.     pbAfterBattle(decision,canlose)
  5060.   }
  5061.   Input.update
  5062.   pbSet(variable,decision)
  5063.   return (decision==1)
  5064. end
  5065.  
  5066. #===============================================================================
  5067. # After battles
  5068. #===============================================================================
  5069. def pbAfterBattle(decision,canlose)
  5070.   for i in $Trainer.party
  5071.     (i.makeUnmega rescue nil); (i.makeUnprimal rescue nil)
  5072.   end
  5073.   if $PokemonGlobal.partner
  5074.     pbHealAll
  5075.     for i in $PokemonGlobal.partner[3]
  5076.       i.heal
  5077.       (i.makeUnmega rescue nil); (i.makeUnprimal rescue nil)
  5078.     end
  5079.   end
  5080.   if decision==2 || decision==5 # if loss or draw
  5081.     if canlose
  5082.       for i in $Trainer.party; i.heal; end
  5083.       for i in 0...10
  5084.         Graphics.update
  5085.       end
  5086.     end
  5087.   end
  5088.   Events.onEndBattle.trigger(nil,decision,canlose)
  5089. end
  5090.  
  5091. Events.onEndBattle+=proc {|sender,e|
  5092.   decision = e[0]
  5093.   canlose  = e[1]
  5094.   if USENEWBATTLEMECHANICS || (decision!=2 && decision!=5) # not a loss or a draw
  5095.     if $PokemonTemp.evolutionLevels
  5096.       pbEvolutionCheck($PokemonTemp.evolutionLevels)
  5097.       $PokemonTemp.evolutionLevels = nil
  5098.     end
  5099.   end
  5100.   if decision==1
  5101.     for pkmn in $Trainer.pokemonParty
  5102.       Kernel.pbPickup(pkmn)
  5103.       if isConst?(pkmn.ability,PBAbilities,:HONEYGATHER) && !pkmn.hasItem?
  5104.         if hasConst?(PBItems,:HONEY)
  5105.           chance = 5+((pkmn.level-1)/10).floor*5
  5106.           pkmn.setItem(:HONEY) if rand(100)<chance
  5107.         end
  5108.       end
  5109.     end
  5110.   end
  5111.   if (decision==2 || decision==5) && !canlose
  5112.     $game_system.bgm_unpause
  5113.     $game_system.bgs_unpause
  5114.     Kernel.pbStartOver
  5115.   end
  5116. }
  5117.  
  5118. def pbEvolutionCheck(currentlevels)
  5119.   for i in 0...currentlevels.length
  5120.     pokemon = $Trainer.party[i]
  5121.     next if pokemon.hp==0 && !USENEWBATTLEMECHANICS
  5122.     if pokemon && (!currentlevels[i] || pokemon.level!=currentlevels[i])
  5123.       newspecies = Kernel.pbCheckEvolution(pokemon)
  5124.       if newspecies>0
  5125.         evo = PokemonEvolutionScene.new
  5126.         evo.pbStartScreen(pokemon,newspecies)
  5127.         evo.pbEvolution
  5128.         evo.pbEndScreen
  5129.       end
  5130.     end
  5131.   end
  5132. end
  5133.  
  5134. def pbDynamicItemList(*args)
  5135.   ret = []
  5136.   for i in 0...args.length
  5137.     if hasConst?(PBItems,args[i])
  5138.       ret.push(getConst(PBItems,args[i].to_sym))
  5139.     end
  5140.   end
  5141.   return ret
  5142. end
  5143.  
  5144. # Runs the Pickup event after a battle if a Pokemon has the ability Pickup.
  5145. def Kernel.pbPickup(pokemon)
  5146.   return if !isConst?(pokemon.ability,PBAbilities,:PICKUP) || pokemon.egg?
  5147.   return if pokemon.item!=0
  5148.   return if rand(10)!=0
  5149.   pickupList = pbDynamicItemList(
  5150.      :POTION,
  5151.      :ANTIDOTE,
  5152.      :SUPERPOTION,
  5153.      :GREATBALL,
  5154.      :REPEL,
  5155.      :ESCAPEROPE,
  5156.      :FULLHEAL,
  5157.      :HYPERPOTION,
  5158.      :ULTRABALL,
  5159.      :REVIVE,
  5160.      :RARECANDY,
  5161.      :SUNSTONE,
  5162.      :MOONSTONE,
  5163.      :HEARTSCALE,
  5164.      :FULLRESTORE,
  5165.      :MAXREVIVE,
  5166.      :PPUP,
  5167.      :MAXELIXIR
  5168.   )
  5169.   pickupListRare = pbDynamicItemList(
  5170.      :HYPERPOTION,
  5171.      :NUGGET,
  5172.      :KINGSROCK,
  5173.      :FULLRESTORE,
  5174.      :ETHER,
  5175.      :IRONBALL,
  5176.      :DESTINYKNOT,
  5177.      :ELIXIR,
  5178.      :DESTINYKNOT,
  5179.      :LEFTOVERS,
  5180.      :DESTINYKNOT,
  5181.      :ICESTONE
  5182.   )
  5183.   return if pickupList.length<18
  5184.   return if pickupListRare.length<12
  5185.   randlist = [30,10,10,10,10,10,10,4,4,1,1]
  5186.   items = []
  5187.   plevel = [100,pokemon.level].min
  5188.   itemstart = (plevel-1)/10
  5189.   itemstart = 0 if itemstart<0
  5190.   for i in 0...9
  5191.     items.push(pickupList[itemstart+i])
  5192.   end
  5193.   for i in 0...2
  5194.     items.push(pickupListRare[itemstart+i])
  5195.   end
  5196.   rnd = rand(100)
  5197.   cumnumber = 0
  5198.   for i in 0...randlist.length
  5199.     cumnumber += randlist[i]
  5200.     if rnd<cumnumber
  5201.       pokemon.setItem(items[i])
  5202.       break
  5203.     end
  5204.   end
  5205. end
  5206.  
  5207. class PokeBattle_Scene
  5208.   def pbSwitch(index,lax,cancancel)
  5209.     party=@battle.pbParty(index)
  5210.     partypos=@battle.party1order
  5211.     ret=-1
  5212.     # Fade out and hide all sprites
  5213.     visiblesprites=pbFadeOutAndHide(@sprites)
  5214.     pbShowWindow(BLANK)
  5215.     pbSetMessageMode(true)
  5216.     modparty=[]
  5217. if $Trainer.partyplus
  5218.     for i in 0...8
  5219.       modparty.push(party[partypos[i]])
  5220.     end
  5221. else
  5222.     for i in 0...6
  5223.       modparty.push(party[partypos[i]])
  5224.     end
  5225. end
  5226.     scene=PokemonParty_Scene.new
  5227.     @switchscreen=PokemonPartyScreen.new(scene,modparty)
  5228.     @switchscreen.pbStartScene(_INTL("Choose a Pokémon."),
  5229.        @battle.doublebattle && !@battle.fullparty1)
  5230.     loop do
  5231.       scene.pbSetHelpText(_INTL("Choose a Pokémon."))
  5232.       activecmd=@switchscreen.pbChoosePokemon
  5233.       if cancancel && activecmd==-1
  5234.         ret=-1
  5235.         break
  5236.       end
  5237.       if activecmd>=0
  5238.         commands=[]
  5239.         cmdShift=-1
  5240.         cmdSummary=-1
  5241.         pkmnindex=partypos[activecmd]
  5242.         commands[cmdShift=commands.length]=_INTL("Switch In") if !party[pkmnindex].egg?
  5243.         commands[cmdSummary=commands.length]=_INTL("Summary")
  5244.         commands[commands.length]=_INTL("Cancel")
  5245.         command=scene.pbShowCommands(_INTL("Do what with {1}?",party[pkmnindex].name),commands)
  5246.         if cmdShift>=0 && command==cmdShift
  5247.           canswitch=lax ? @battle.pbCanSwitchLax?(index,pkmnindex,true) :
  5248.              @battle.pbCanSwitch?(index,pkmnindex,true)
  5249.           if canswitch
  5250.             ret=pkmnindex
  5251.             break
  5252.           end
  5253.         elsif cmdSummary>=0 && command==cmdSummary
  5254.           scene.pbSummary(activecmd)
  5255.         end
  5256.       end
  5257.     end
  5258.     @switchscreen.pbEndScene
  5259.     @switchscreen=nil
  5260.     pbShowWindow(BLANK)
  5261.     pbSetMessageMode(false)
  5262.     # back to main battle screen
  5263.     pbFadeInAndShow(@sprites,visiblesprites)
  5264.     return ret
  5265.   end
  5266. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement