pokeminer20

Pokemon Essentials V18.1 PartyPlus V3.1

Jan 31st, 2021 (edited)
1,831
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 147.95 KB | None | 0 0
  1. #------------------------------------------------------------------------------#
  2. #Currently supports any party limit between 1-10. higher values may be asked   #
  3. #on the thread for a mini update. to set the max number of pokemon a trainer   #
  4. #may carry change '$Trainer.partyplus' to a number between 1 & 10 like so:     #
  5. # '$Trainer.partyplus=8' this will allow a player to have 8 pokemon on them.   #
  6. #If you want a player to have more than 6 pokemon but be unable to use them in #
  7. #battle, alter the partybenched value to forbid those pokemon from fighting.   #
  8. #This also affects enemy trainers. they may have up to 40 pokemon if the dev   #
  9. #wanted to.                                                              ~PDM20#
  10. #------------------------------------------------------------------------------#
  11.     ALLOW_BENCHING = true
  12. class PokeBattle_Trainer
  13.     attr_accessor(:partyplus)
  14.     attr_accessor(:partybenched)
  15.  
  16.   alias partyplus_initialize initialize
  17.   def initialize(name,trainertype)
  18.     partyplus_initialize(name,trainertype)
  19.     @partyplus    = 0
  20.     @partybenched = 0
  21.   end
  22. end
  23. class PokeBattle_Pokemon
  24.   def able?
  25.     return !egg? && @hp>0 && !benched?
  26.   end
  27.   attr_accessor(:benchedflag)
  28.  
  29.   def benched?
  30.     return @benchedflag if @benchedflag!=nil
  31.   end
  32.   alias isBenched? benched?
  33.  
  34.   # Makes this Pokémon benched.
  35.   def makeBenched
  36.     @benchedflag = true
  37.   end
  38.  
  39.   # Makes this Pokémon not benched.
  40.   def makeNotBenched
  41.     @benchedflag = false
  42.   end
  43.  
  44.   alias partyplus_initialize initialize  
  45.   def initialize(*args)
  46.     partyplus_initialize(*args)
  47.     @benchedflag = false
  48.   end
  49. end
  50. def setBenchedParty
  51.   size  = $Trainer.partyplus
  52.   limit = $Trainer.partybenched
  53.   max   = $Trainer.party.length
  54.   if ALLOW_BENCHING && size>=limit
  55.    for j in 0...max
  56.       $Trainer.party[j].makeNotBenched
  57.    end
  58.    for i in limit...max
  59.     $Trainer.party[i].makeBenched
  60.    end
  61.   end
  62. end
  63. #------------------------------------------------------------------------------#
  64. # PokeBattle_BattlePeer
  65. #------------------------------------------------------------------------------#
  66. class PokeBattle_RealBattlePeer
  67.   def pbStorePokemon(player,pkmn)
  68.   if $Trainer.partyplus>=1
  69.   plus = $Trainer.partyplus
  70.   else
  71.   plus = 6
  72.   end
  73.     if player.party.length<plus
  74.       player.party[player.party.length] = pkmn
  75.       return -1
  76.     end
  77.     pkmn.heal
  78.     oldCurBox = pbCurrentBox
  79.     storedBox = $PokemonStorage.pbStoreCaught(pkmn)
  80.     if storedBox<0
  81.       # NOTE: Poké Balls can't be used if storage is full, so you shouldn't ever
  82.       #       see this message.
  83.       pbDisplayPaused(_INTL("Can't catch any more..."))
  84.       return oldCurBox
  85.     end
  86.     return storedBox
  87.   end
  88. end
  89. #------------------------------------------------------------------------------#
  90. # PField_DayCare
  91. #------------------------------------------------------------------------------#
  92. def pbDayCareWithdraw(index)
  93.   if !$PokemonGlobal.daycare[index][0]
  94.     raise _INTL("There's no Pokémon here...")
  95.   elsif $Trainer.party.length>=$Trainer.partyplus && $Trainer.partyplus>=1
  96.     raise _INTL("Can't store the Pokémon...")
  97.   elsif $Trainer.party.length>=6
  98.     raise _INTL("Can't store the Pokémon...")
  99.   else
  100.     $Trainer.party[$Trainer.party.length] = $PokemonGlobal.daycare[index][0]
  101.     $PokemonGlobal.daycare[index][0] = nil
  102.     $PokemonGlobal.daycare[index][1] = 0
  103.     $PokemonGlobal.daycareEgg = 0
  104.   end
  105. end
  106. #===============================================================================
  107. # Generate an Egg based on Pokémon in the Day Care.
  108. #===============================================================================
  109. def pbDayCareGenerateEgg
  110.   return if pbDayCareDeposited!=2
  111.   raise _INTL("Can't store the egg") if $Trainer.party.length>=6 || $Trainer.party.length>=$Trainer.partyplus && $Trainer.partyplus>=1
  112.   pokemon0 = $PokemonGlobal.daycare[0][0]
  113.   pokemon1 = $PokemonGlobal.daycare[1][0]
  114.   mother = nil
  115.   father = nil
  116.   babyspecies = 0
  117.   ditto0 = pbIsDitto?(pokemon0)
  118.   ditto1 = pbIsDitto?(pokemon1)
  119.   if pokemon0.female? || ditto0
  120.     babyspecies = (ditto0) ? pokemon1.species : pokemon0.species
  121.     mother = pokemon0
  122.     father = pokemon1
  123.   else
  124.     babyspecies = (ditto1) ? pokemon0.species : pokemon1.species
  125.     mother = pokemon1
  126.     father = pokemon0
  127.   end
  128.   # Determine the egg's species
  129.   babyspecies = pbGetBabySpecies(babyspecies,mother.item,father.item)
  130.   if isConst?(babyspecies,PBSpecies,:MANAPHY) && hasConst?(PBSpecies,:PHIONE)
  131.     babyspecies = getConst(PBSpecies,:PHIONE)
  132.   elsif (isConst?(babyspecies,PBSpecies,:NIDORANfE) && hasConst?(PBSpecies,:NIDORANmA)) ||
  133.         (isConst?(babyspecies,PBSpecies,:NIDORANmA) && hasConst?(PBSpecies,:NIDORANfE))
  134.     babyspecies = [getConst(PBSpecies,:NIDORANmA),
  135.                    getConst(PBSpecies,:NIDORANfE)][rand(2)]
  136.   elsif (isConst?(babyspecies,PBSpecies,:VOLBEAT) && hasConst?(PBSpecies,:ILLUMISE)) ||
  137.         (isConst?(babyspecies,PBSpecies,:ILLUMISE) && hasConst?(PBSpecies,:VOLBEAT))
  138.     babyspecies = [getConst(PBSpecies,:VOLBEAT),
  139.                    getConst(PBSpecies,:ILLUMISE)][rand(2)]
  140.   end
  141.   # Generate egg
  142.   egg = pbNewPkmn(babyspecies,EGG_LEVEL)
  143.   # Randomise personal ID
  144.   pid = rand(65536)
  145.   pid |= (rand(65536)<<16)
  146.   egg.personalID = pid
  147.   # Inheriting form
  148.   if isConst?(babyspecies,PBSpecies,:BURMY) ||
  149.      isConst?(babyspecies,PBSpecies,:SHELLOS) ||
  150.      isConst?(babyspecies,PBSpecies,:BASCULIN) ||
  151.      isConst?(babyspecies,PBSpecies,:FLABEBE) ||
  152.      isConst?(babyspecies,PBSpecies,:PUMPKABOO) ||
  153.      isConst?(babyspecies,PBSpecies,:ORICORIO) ||
  154.      isConst?(babyspecies,PBSpecies,:ROCKRUFF) ||
  155.      isConst?(babyspecies,PBSpecies,:MINIOR)
  156.     newForm = mother.form
  157.     newForm = 0 if mother.isSpecies?(:MOTHIM)
  158.     egg.form = newForm
  159.   end
  160.   # Inheriting Alolan form
  161.   if isConst?(babyspecies,PBSpecies,:RATTATA) ||
  162.      isConst?(babyspecies,PBSpecies,:SANDSHREW) ||
  163.      isConst?(babyspecies,PBSpecies,:VULPIX) ||
  164.      isConst?(babyspecies,PBSpecies,:DIGLETT) ||
  165.      isConst?(babyspecies,PBSpecies,:MEOWTH) ||
  166.      isConst?(babyspecies,PBSpecies,:GEODUDE) ||
  167.      isConst?(babyspecies,PBSpecies,:GRIMER)
  168.     if mother.form==1
  169.       egg.form = 1 if mother.hasItem?(:EVERSTONE)
  170.     elsif pbGetBabySpecies(father.species,mother.item,father.item)==babyspecies
  171.       egg.form = 1 if father.form==1 && father.hasItem?(:EVERSTONE)
  172.     end
  173.   end
  174.   # Inheriting Moves
  175.   moves = []
  176.   othermoves = []
  177.   movefather = father; movemother = mother
  178.   if pbIsDitto?(movefather) && !mother.female?
  179.     movefather = mother; movemother = father
  180.   end
  181.   # Initial Moves
  182.   initialmoves = egg.getMoveList
  183.   for k in initialmoves
  184.     if k[0]<=EGG_LEVEL
  185.       moves.push(k[1])
  186.     else
  187.       next if !mother.hasMove?(k[1]) || !father.hasMove?(k[1])
  188.       othermoves.push(k[1])
  189.     end
  190.   end
  191.   # Inheriting Natural Moves
  192.   for move in othermoves
  193.     moves.push(move)
  194.   end
  195.   # Inheriting Machine Moves
  196.   if !NEWEST_BATTLE_MECHANICS
  197.     itemsData = pbLoadItemsData
  198.     for i in 0...itemsData.length
  199.       next if !itemsData[i]
  200.       atk = itemsData[i][ITEM_MACHINE]
  201.       next if !atk || atk==0
  202.       next if !egg.compatibleWithMove?(atk)
  203.       next if !movefather.hasMove?(atk)
  204.       moves.push(atk)
  205.     end
  206.   end
  207.   # Inheriting Egg Moves
  208.   babyEggMoves = pbGetSpeciesEggMoves(egg.species,egg.form)
  209.   if movefather.male?
  210.     babyEggMoves.each { |m| moves.push(m) if movefather.hasMove?(m) }
  211.   end
  212.   if NEWEST_BATTLE_MECHANICS
  213.     babyEggMoves.each { |m| moves.push(m) if movemother.hasMove?(m) }
  214.   end
  215.   # Volt Tackle
  216.   lightball = false
  217.   if (father.isSpecies?(:PIKACHU) || father.isSpecies?(:RAICHU)) &&
  218.       father.hasItem?(:LIGHTBALL)
  219.     lightball = true
  220.   end
  221.   if (mother.isSpecies?(:PIKACHU) || mother.isSpecies?(:RAICHU)) &&
  222.       mother.hasItem?(:LIGHTBALL)
  223.     lightball = true
  224.   end
  225.   if lightball && isConst?(babyspecies,PBSpecies,:PICHU) &&
  226.      hasConst?(PBMoves,:VOLTTACKLE)
  227.     moves.push(getConst(PBMoves,:VOLTTACKLE))
  228.   end
  229.   moves = moves.reverse
  230.   moves |= []   # remove duplicates
  231.   moves = moves.reverse
  232.   # Assembling move list
  233.   finalmoves = []
  234.   listend = moves.length-4
  235.   listend = 0 if listend<0
  236.   for i in listend...listend+4
  237.     moveid = (i>=moves.length) ? 0 : moves[i]
  238.     finalmoves[finalmoves.length] = PBMove.new(moveid)
  239.   end
  240.   # Inheriting Individual Values
  241.   ivs = []
  242.   for i in 0...6
  243.     ivs[i] = rand(32)
  244.   end
  245.   ivinherit = []
  246.   for i in 0...2
  247.     parent = [mother,father][i]
  248.     ivinherit[i] = PBStats::HP if parent.hasItem?(:POWERWEIGHT)
  249.     ivinherit[i] = PBStats::ATTACK if parent.hasItem?(:POWERBRACER)
  250.     ivinherit[i] = PBStats::DEFENSE if parent.hasItem?(:POWERBELT)
  251.     ivinherit[i] = PBStats::SPATK if parent.hasItem?(:POWERLENS)
  252.     ivinherit[i] = PBStats::SPDEF if parent.hasItem?(:POWERBAND)
  253.     ivinherit[i] = PBStats::SPEED if parent.hasItem?(:POWERANKLET)
  254.   end
  255.   num = 0; r = rand(2)
  256.   2.times do
  257.     if ivinherit[r]!=nil
  258.       parent = [mother,father][r]
  259.       ivs[ivinherit[r]] = parent.iv[ivinherit[r]]
  260.       num += 1
  261.       break
  262.     end
  263.     r = (r+1)%2
  264.   end
  265.   limit = (NEWEST_BATTLE_MECHANICS && (mother.hasItem?(:DESTINYKNOT) ||
  266.            father.hasItem?(:DESTINYKNOT))) ? 5 : 3
  267.   loop do
  268.     freestats = []
  269.     PBStats.eachStat { |s| freestats.push(s) if !ivinherit.include?(s) }
  270.     break if freestats.length==0
  271.     r = freestats[rand(freestats.length)]
  272.     parent = [mother,father][rand(2)]
  273.     ivs[r] = parent.iv[r]
  274.     ivinherit.push(r)
  275.     num += 1
  276.     break if num>=limit
  277.   end
  278.   # Inheriting nature
  279.   newnatures = []
  280.   newnatures.push(mother.nature) if mother.hasItem?(:EVERSTONE)
  281.   newnatures.push(father.nature) if father.hasItem?(:EVERSTONE)
  282.   if newnatures.length>0
  283.     egg.setNature(newnatures[rand(newnatures.length)])
  284.   end
  285.   # Masuda method and Shiny Charm
  286.   shinyretries = 0
  287.   shinyretries += 5 if father.language!=mother.language
  288.   shinyretries += 2 if hasConst?(PBItems,:SHINYCHARM) && $PokemonBag.pbHasItem?(:SHINYCHARM)
  289.   if shinyretries>0
  290.     shinyretries.times do
  291.       break if egg.shiny?
  292.       egg.personalID = rand(65536)|(rand(65536)<<16)
  293.     end
  294.   end
  295.   # Inheriting ability from the mother
  296.   if !ditto0 && !ditto1
  297.     if mother.hasHiddenAbility?
  298.       egg.setAbility(mother.abilityIndex) if rand(10)<6
  299.     else
  300.       if rand(10)<8
  301.         egg.setAbility(mother.abilityIndex)
  302.       else
  303.         egg.setAbility((mother.abilityIndex+1)%2)
  304.       end
  305.     end
  306.   elsif !(ditto0 && ditto1) && NEWEST_BATTLE_MECHANICS
  307.     parent = (!ditto0) ? mother : father
  308.     if parent.hasHiddenAbility?
  309.       egg.setAbility(parent.abilityIndex) if rand(10)<6
  310.     end
  311.   end
  312.   # Inheriting Poké Ball from the mother
  313.   if mother.female? &&
  314.      !isConst?(pbBallTypeToItem(mother.ballused),PBItems,:MASTERBALL) &&
  315.      !isConst?(pbBallTypeToItem(mother.ballused),PBItems,:CHERISHBALL)
  316.     egg.ballused = mother.ballused
  317.   end
  318.   # Set all stats
  319.   egg.happiness = 120
  320.   egg.iv[0] = ivs[0]
  321.   egg.iv[1] = ivs[1]
  322.   egg.iv[2] = ivs[2]
  323.   egg.iv[3] = ivs[3]
  324.   egg.iv[4] = ivs[4]
  325.   egg.iv[5] = ivs[5]
  326.   egg.moves[0] = finalmoves[0]
  327.   egg.moves[1] = finalmoves[1]
  328.   egg.moves[2] = finalmoves[2]
  329.   egg.moves[3] = finalmoves[3]
  330.   egg.calcStats
  331.   egg.obtainText = _INTL("Day-Care Couple")
  332.   egg.name = _INTL("Egg")
  333.   eggSteps = pbGetSpeciesData(babyspecies,egg.form,SpeciesStepsToHatch)
  334.   egg.eggsteps = eggSteps
  335.   egg.givePokerus if rand(65536)<POKERUS_CHANCE
  336.   # Add egg to party
  337.   $Trainer.party[$Trainer.party.length] = egg
  338. end
  339. #------------------------------------------------------------------------------#
  340. # PItem_ItemEffects
  341. #------------------------------------------------------------------------------#
  342. ItemHandlers::UseOnPokemon.add(:DNASPLICERS,proc { |item,pkmn,scene|
  343.   if !pkmn.isSpecies?(:KYUREM)
  344.     scene.pbDisplay(_INTL("It had no effect."))
  345.     next false
  346.   end
  347.   if pkmn.fainted?
  348.     scene.pbDisplay(_INTL("This can't be used on the fainted Pokémon."))
  349.     next false
  350.   end
  351.   # Fusing
  352.   if pkmn.fused==nil
  353.     chosen = scene.pbChoosePokemon(_INTL("Fuse with which Pokémon?"))
  354.     next false if chosen<0
  355.     poke2 = $Trainer.party[chosen]
  356.     if pkmn==poke2
  357.       scene.pbDisplay(_INTL("It cannot be fused with itself."))
  358.       next false
  359.     elsif poke2.egg?
  360.       scene.pbDisplay(_INTL("It cannot be fused with an Egg."))
  361.       next false
  362.     elsif poke2.fainted?
  363.       scene.pbDisplay(_INTL("It cannot be fused with that fainted Pokémon."))
  364.       next false
  365.     elsif !poke2.isSpecies?(:RESHIRAM) &&
  366.           !poke2.isSpecies?(:ZEKROM)
  367.       scene.pbDisplay(_INTL("It cannot be fused with that Pokémon."))
  368.       next false
  369.     end
  370.     newForm = 0
  371.     newForm = 1 if poke2.isSpecies?(:RESHIRAM)
  372.     newForm = 2 if poke2.isSpecies?(:ZEKROM)
  373.     pkmn.setForm(newForm) {
  374.       pkmn.fused = poke2
  375.       pbRemovePokemonAt(chosen)
  376.       scene.pbHardRefresh
  377.       scene.pbDisplay(_INTL("{1} changed Forme!",pkmn.name))
  378.     }
  379.     next true
  380.   end
  381.   # Unfusing
  382.   if $Trainer.party.length>=6 || $Trainer.party.length>=$Trainer.partyplus && $Trainer.partyplus>=1
  383.     scene.pbDisplay(_INTL("You have no room to separate the Pokémon."))
  384.     next false
  385.   end
  386.   pkmn.setForm(0) {
  387.     $Trainer.party[$Trainer.party.length] = pkmn.fused
  388.     pkmn.fused = nil
  389.     scene.pbHardRefresh
  390.     scene.pbDisplay(_INTL("{1} changed Forme!",pkmn.name))
  391.   }
  392.   next true
  393. })
  394. ItemHandlers::UseOnPokemon.add(:NSOLARIZER,proc { |item,pkmn,scene|
  395.   if !pkmn.isSpecies?(:NECROZMA) || pkmn.form == 2
  396.     scene.pbDisplay(_INTL("It had no effect."))
  397.     next false
  398.   end
  399.   if pkmn.fainted?
  400.     scene.pbDisplay(_INTL("This can't be used on the fainted Pokémon."))
  401.     next false
  402.   end
  403.   # Fusing
  404.   if pkmn.fused==nil
  405.     chosen = scene.pbChoosePokemon(_INTL("Fuse with which Pokémon?"))
  406.     next false if chosen<0
  407.     poke2 = $Trainer.party[chosen]
  408.     if pkmn==poke2
  409.       scene.pbDisplay(_INTL("It cannot be fused with itself."))
  410.       next false
  411.     elsif poke2.egg?
  412.       scene.pbDisplay(_INTL("It cannot be fused with an Egg."))
  413.       next false
  414.     elsif poke2.fainted?
  415.       scene.pbDisplay(_INTL("It cannot be fused with that fainted Pokémon."))
  416.       next false
  417.     elsif !poke2.isSpecies?(:SOLGALEO)
  418.       scene.pbDisplay(_INTL("It cannot be fused with that Pokémon."))
  419.       next false
  420.     end
  421.     pkmn.setForm(1) {
  422.       pkmn.fused = poke2
  423.       pbRemovePokemonAt(chosen)
  424.       scene.pbHardRefresh
  425.       scene.pbDisplay(_INTL("{1} changed Forme!",pkmn.name))
  426.     }
  427.     next true
  428.   end
  429.   # Unfusing
  430.   if $Trainer.party.length>=6 || $Trainer.party.length>=$Trainer.partyplus && $Trainer.partyplus>=1
  431.     scene.pbDisplay(_INTL("You have no room to separate the Pokémon."))
  432.     next false
  433.   end
  434.   pkmn.setForm(0) {
  435.     $Trainer.party[$Trainer.party.length] = pkmn.fused
  436.     pkmn.fused = nil
  437.     scene.pbHardRefresh
  438.     scene.pbDisplay(_INTL("{1} changed Forme!",pkmn.name))
  439.   }
  440.   next true
  441. })
  442. ItemHandlers::UseOnPokemon.add(:NLUNARIZER,proc { |item,pkmn,scene|
  443.   if !pkmn.isSpecies?(:NECROZMA) || pkmn.form == 1
  444.     scene.pbDisplay(_INTL("It had no effect."))
  445.     next false
  446.   end
  447.   if pkmn.fainted?
  448.     scene.pbDisplay(_INTL("This can't be used on the fainted Pokémon."))
  449.     next false
  450.   end
  451.   # Fusing
  452.   if pkmn.fused==nil
  453.     chosen = scene.pbChoosePokemon(_INTL("Fuse with which Pokémon?"))
  454.     next false if chosen<0
  455.     poke2 = $Trainer.party[chosen]
  456.     if pkmn==poke2
  457.       scene.pbDisplay(_INTL("It cannot be fused with itself."))
  458.       next false
  459.     elsif poke2.egg?
  460.       scene.pbDisplay(_INTL("It cannot be fused with an Egg."))
  461.       next false
  462.     elsif poke2.fainted?
  463.       scene.pbDisplay(_INTL("It cannot be fused with that fainted Pokémon."))
  464.       next false
  465.     elsif !poke2.isSpecies?(:LUNALA)
  466.       scene.pbDisplay(_INTL("It cannot be fused with that Pokémon."))
  467.       next false
  468.     end
  469.     pkmn.setForm(2) {
  470.       pkmn.fused = poke2
  471.       pbRemovePokemonAt(chosen)
  472.       scene.pbHardRefresh
  473.       scene.pbDisplay(_INTL("{1} changed Forme!",pkmn.name))
  474.     }
  475.     next true
  476.   end
  477.   # Unfusing
  478.   if $Trainer.party.length>=6 || $Trainer.party.length>=$Trainer.partyplus && $Trainer.partyplus>=1
  479.     scene.pbDisplay(_INTL("You have no room to separate the Pokémon."))
  480.     next false
  481.   end
  482.   pkmn.setForm(0) {
  483.     $Trainer.party[$Trainer.party.length] = pkmn.fused
  484.     pkmn.fused = nil
  485.     scene.pbHardRefresh
  486.     scene.pbDisplay(_INTL("{1} changed Forme!",pkmn.name))
  487.   }
  488.   next true
  489. })
  490. #------------------------------------------------------------------------------#
  491. # PItem_BattleItemEffects
  492. #------------------------------------------------------------------------------#
  493. ItemHandlers::CanUseInBattle.addIf(proc { |item| pbIsPokeBall?(item) },   # Poké Balls
  494.   proc { |item,pokemon,battler,move,firstAction,battle,scene,showMessages|
  495.     if ((battle.pbPlayer.party.length>=6 || $Trainer.party.length>=$Trainer.partyplus) && $Trainer.partyplus>=1) && $PokemonStorage.full?
  496.       scene.pbDisplay(_INTL("There is no room left in the PC!")) if showMessages
  497.       next false
  498.     end
  499.     # NOTE: Using a Poké Ball consumes all your actions for the round. The code
  500.     #       below is one half of making this happen; the other half is in def
  501.     #       pbItemUsesAllActions?.
  502.     if !firstAction
  503.       scene.pbDisplay(_INTL("It's impossible to aim without being focused!")) if showMessages
  504.       next false
  505.     end
  506.     if battler.semiInvulnerable?
  507.       scene.pbDisplay(_INTL("It's no good! It's impossible to aim at a Pokémon that's not in sight!")) if showMessages
  508.       next false
  509.     end
  510.     # NOTE: The code below stops you from throwing a Poké Ball if there is more
  511.     #       than one unfainted opposing Pokémon. (Snag Balls can be thrown in
  512.     #       this case, but only in trainer battles, and the trainer will deflect
  513.     #       them if they are trying to catch a non-Shadow Pokémon.)
  514.     if battle.pbOpposingBattlerCount>1 && !(pbIsSnagBall?(item) && battle.trainerBattle?)
  515.       if battle.pbOpposingBattlerCount==2
  516.         scene.pbDisplay(_INTL("It's no good! It's impossible to aim when there are two Pokémon!")) if showMessages
  517.       else
  518.         scene.pbDisplay(_INTL("It's no good! It's impossible to aim when there are more than one Pokémon!")) if showMessages
  519.       end
  520.       next false
  521.     end
  522.     next true
  523.   }
  524. )
  525. #------------------------------------------------------------------------------#
  526. # Pokemon_Storage
  527. #------------------------------------------------------------------------------#
  528. class PokemonStorage
  529.   attr_reader   :boxes
  530.   attr_accessor :currentBox
  531.   attr_writer   :unlockedWallpapers
  532.   BASICWALLPAPERQTY = 16
  533.   def initialize(maxBoxes=NUM_STORAGE_BOXES,maxPokemon=30)
  534.     @boxes = []
  535.     for i in 0...maxBoxes
  536.       @boxes[i] = PokemonBox.new(_INTL("Box {1}",i+1),maxPokemon)
  537.       @boxes[i].background = i%BASICWALLPAPERQTY
  538.     end
  539.     @currentBox = 0
  540.     @boxmode = -1
  541.     @unlockedWallpapers = []
  542.     for i in 0...allWallpapers.length
  543.       @unlockedWallpapers[i] = false
  544.     end
  545.   end
  546.   def allWallpapers
  547.     return [
  548.        # Basic wallpapers
  549.        _INTL("Forest"),_INTL("City"),_INTL("Desert"),_INTL("Savanna"),
  550.        _INTL("Crag"),_INTL("Volcano"),_INTL("Snow"),_INTL("Cave"),
  551.        _INTL("Beach"),_INTL("Seafloor"),_INTL("River"),_INTL("Sky"),
  552.        _INTL("Poké Center"),_INTL("Machine"),_INTL("Checks"),_INTL("Simple"),
  553.        # Special wallpapers
  554.        _INTL("Space"),_INTL("Backyard"),_INTL("Nostalgic 1"),_INTL("Torchic"),
  555.        _INTL("Trio 1"),_INTL("PikaPika 1"),_INTL("Legend 1"),_INTL("Team Galactic 1"),
  556.        _INTL("Distortion"),_INTL("Contest"),_INTL("Nostalgic 2"),_INTL("Croagunk"),
  557.        _INTL("Trio 2"),_INTL("PikaPika 2"),_INTL("Legend 2"),_INTL("Team Galactic 2"),
  558.        _INTL("Heart"),_INTL("Soul"),_INTL("Big Brother"),_INTL("Pokéathlon"),
  559.        _INTL("Trio 3"),_INTL("Spiky Pika"),_INTL("Kimono Girl"),_INTL("Revival")
  560.     ]
  561.   end
  562.   def unlockedWallpapers
  563.     @unlockedWallpapers = [] if !@unlockedWallpapers
  564.     return @unlockedWallpapers
  565.   end
  566.   def isAvailableWallpaper?(i)
  567.     @unlockedWallpapers = [] if !@unlockedWallpapers
  568.     return true if i<BASICWALLPAPERQTY
  569.     return true if @unlockedWallpapers[i]
  570.     return false
  571.   end
  572.   def availableWallpapers
  573.     ret = [[],[]]   # Names, IDs
  574.     papers = allWallpapers
  575.     @unlockedWallpapers = [] if !@unlockedWallpapers
  576.     for i in 0...papers.length
  577.       next if !isAvailableWallpaper?(i)
  578.       ret[0].push(papers[i]); ret[1].push(i)
  579.     end
  580.     return ret
  581.   end
  582.   def party
  583.     $Trainer.party
  584.   end
  585.   def party=(value)
  586.     raise ArgumentError.new("Not supported")
  587.   end
  588.   def maxBoxes
  589.     return @boxes.length
  590.   end
  591.   def maxPokemon(box)
  592.     return 0 if box>=self.maxBoxes
  593.     return (box<0) ? 6 : self[box].length
  594.   end
  595.   def full?
  596.     for i in 0...self.maxBoxes
  597.       return false if !@boxes[i].full?
  598.     end
  599.     return true
  600.   end
  601.   def pbFirstFreePos(box)
  602.     if box==-1
  603.       ret = self.party.nitems
  604.       return (ret==6) ? -1 : ret
  605.     else
  606.       for i in 0...maxPokemon(box)
  607.         return i if !self[box,i]
  608.       end
  609.       return -1
  610.     end
  611.   end
  612.   def [](x,y=nil)
  613.     if y==nil
  614.       return (x==-1) ? self.party : @boxes[x]
  615.     else
  616.       for i in @boxes
  617.         raise "Box is a Pokémon, not a box" if i.is_a?(PokeBattle_Pokemon)
  618.       end
  619.       return (x==-1) ? self.party[y] : @boxes[x][y]
  620.     end
  621.   end
  622.   def []=(x,y,value)
  623.     if x==-1
  624.       self.party[y] = value
  625.     else
  626.       @boxes[x][y] = value
  627.     end
  628.   end
  629.   def pbCopy(boxDst,indexDst,boxSrc,indexSrc)
  630.     if indexDst<0 && boxDst<self.maxBoxes
  631.       found = false
  632.       for i in 0...maxPokemon(boxDst)
  633.         next if self[boxDst,i]
  634.         found = true
  635.         indexDst = i
  636.         break
  637.       end
  638.       return false if !found
  639.     end
  640.     if boxDst==-1   # Copying into party
  641.      if $Trainer.partyplus>=1
  642.       return false if self.party.nitems>=$Trainer.partyplus
  643.      else
  644.       return false if self.party.nitems>=6
  645.      end
  646.       self.party[self.party.length] = self[boxSrc,indexSrc]
  647.       self.party.compact!
  648.     else   # Copying into box
  649.       pkmn = self[boxSrc,indexSrc]
  650.       raise "Trying to copy nil to storage" if !pkmn
  651.       pkmn.formTime = nil if pkmn.respond_to?("formTime")
  652.       pkmn.form     = 0 if isConst?(pkmn.species,PBSpecies,:SHAYMIN)
  653.       pkmn.heal
  654.       self[boxDst,indexDst] = pkmn
  655.     end
  656.     return true
  657.   end
  658.   def pbMove(boxDst,indexDst,boxSrc,indexSrc)
  659.     return false if !pbCopy(boxDst,indexDst,boxSrc,indexSrc)
  660.     pbDelete(boxSrc,indexSrc)
  661.     return true
  662.   end
  663.   def pbMoveCaughtToParty(pkmn)
  664.     if $Trainer.partyplus>=1
  665.     return false if self.party.nitems>=$Trainer.partyplus
  666.     else
  667.     return false if self.party.nitems>=6
  668.     end
  669.     self.party[self.party.length] = pkmn
  670.   end
  671.   def pbMoveCaughtToBox(pkmn,box)
  672.     for i in 0...maxPokemon(box)
  673.       if self[box,i]==nil
  674.         if box>=0
  675.           pkmn.formTime = nil if pkmn.respond_to?("formTime") && pkmn.formTime
  676.           pkmn.form     = 0 if isConst?(pkmn.species,PBSpecies,:SHAYMIN)
  677.           pkmn.heal
  678.         end
  679.         self[box,i] = pkmn
  680.         return true
  681.       end
  682.     end
  683.     return false
  684.   end
  685.   def pbStoreCaught(pkmn)
  686.     if @currentBox>=0
  687.       pkmn.formTime = nil if pkmn.respond_to?("formTime")
  688.       pkmn.form     = 0 if isConst?(pkmn.species,PBSpecies,:SHAYMIN)
  689.       pkmn.heal
  690.     end
  691.     for i in 0...maxPokemon(@currentBox)
  692.       if self[@currentBox,i]==nil
  693.         self[@currentBox,i] = pkmn
  694.         return @currentBox
  695.       end
  696.     end
  697.     for j in 0...self.maxBoxes
  698.       for i in 0...maxPokemon(j)
  699.         if self[j,i]==nil
  700.           self[j,i] = pkmn
  701.           @currentBox = j
  702.           return @currentBox
  703.         end
  704.       end
  705.     end
  706.     return -1
  707.   end
  708.   def pbDelete(box,index)
  709.     if self[box,index]
  710.       self[box,index] = nil
  711.       self.party.compact! if box==-1
  712.     end
  713.   end
  714.   def clear
  715.     for i in 0...self.maxBoxes
  716.       @boxes[i].clear
  717.     end
  718.   end
  719. end
  720. #------------------------------------------------------------------------------#
  721. # PScreen_Party
  722. #------------------------------------------------------------------------------#
  723. #===============================================================================
  724. # Pokémon party panels
  725. #===============================================================================
  726. class PokemonPartyBlankPanel < SpriteWrapper
  727.   attr_accessor :text
  728.   def initialize(_pokemon,index,viewport=nil)
  729.     super(viewport)
  730.     #==============================================================================#
  731.     #Since I assume no one will go above a Max party Limit of 10, I leave it to you#
  732.     #To code them in. if you want a specific numeric, here is a list Of those that #
  733.     #will be mathematically easy to fit into base essentials.                      #
  734.     #160,150,144,140,135,130,128,126,120,117,112,110,108,105,104,100,99,98,96,91,  #
  735.     #90,88,84,81,80,78,77,75,72,70,66,65,64,63,60,56,55,54,52,50,49,48,45,44,42,   #
  736.     #40,39,36,35,33,32,30,28,27,26,25,24,22,21,20,18,16,15,14,13,12,11             #
  737.     #============================================================================= #
  738.     if $Trainer.partyplus==10
  739.      self.x = [0,256,  0,256,  0,265,  0,265,  0,265][index]
  740.      self.y = [0,  0, 64, 64,128,128,192,192,256,256][index]
  741.     elsif $Trainer.partyplus==9
  742.      self.x = [0,171,341,  0,171,342,  0,171,342][index]
  743.      self.y = [0,  0,  0,107,107,107,214,214,214][index]
  744.     elsif $Trainer.partyplus==8
  745.      self.x = [0,256,  0,256,  0,265,  0,265][index]
  746.      self.y = [0,  0, 80, 80,160,160,240,240][index]
  747.     elsif $Trainer.partyplus==7
  748.      self.x = [0, 74,146,220,294,336,440][index]
  749.      self.y = [0,  0,  0,  0,  0,  0,  0][index]
  750.     elsif $Trainer.partyplus==6
  751.      self.x = [0,256,  0,256,  0,265][index]
  752.      self.y = [0,  0,106,106,214,214][index]
  753.     elsif $Trainer.partyplus==5
  754.      self.x = [0,  0,  0,  0,  0][index]
  755.      self.y = [0, 64,128,192,256][index]
  756.     elsif $Trainer.partyplus==4
  757.      self.x = [0,256,  0,256][index]
  758.      self.y = [0,  0,160,160][index]
  759.     elsif $Trainer.partyplus==3
  760.      self.x = [0,171,342][index]
  761.      self.y = [0,  0,  0][index]
  762.     elsif $Trainer.partyplus==2
  763.      self.x = [0,256][index]
  764.      self.y = [0,  0][index]
  765.     elsif $Trainer.partyplus==1
  766.      self.x = [0][index]
  767.      self.y = [0][index]
  768.     else
  769.      self.x = [0, Graphics.width/2][index%2]
  770.      self.y = [0, 16, 96,112,192,208][index]
  771.     end
  772.     folder = $Trainer.partyplus
  773.     if $Trainer.partyplus>=1
  774.     @panelbgsprite = AnimatedBitmap.new("Graphics/Pictures/Party/PartyPlus/"+"#{folder}"+" - Party/panel_blank")
  775.     else
  776.     @panelbgsprite = AnimatedBitmap.new("Graphics/Pictures/Party/panel_blank")
  777.     end
  778.     self.bitmap = @panelbgsprite.bitmap
  779.     @text = nil
  780.   end
  781.   def dispose
  782.     @panelbgsprite.dispose
  783.     super
  784.   end
  785.   def selected; return false; end
  786.   def selected=(value); end
  787.   def preselected; return false; end
  788.   def preselected=(value); end
  789.   def switching; return false; end
  790.   def switching=(value); end
  791.   def refresh; end
  792. end
  793. class PokemonPartyPanel < SpriteWrapper
  794.   attr_reader :pokemon
  795.   attr_reader :active
  796.   attr_reader :selected
  797.   attr_reader :preselected
  798.   attr_reader :switching
  799.   attr_reader :text
  800.   def initialize(pokemon,index,viewport=nil)
  801.     super(viewport)
  802.     @pokemon = pokemon
  803.     @active = (index==0)   # true = rounded panel, false = rectangular panel
  804.     @refreshing = true
  805.     #==============================================================================#
  806.     #Since I assume no one will go above a Max party Limit of 10, I leave it to you#
  807.     #To code them in. if you want a specific numeric, here is a list Of those that #
  808.     #will be mathematically easy to fit into base essentials.                      #
  809.     #160,150,144,140,135,130,128,126,120,117,112,110,108,105,104,100,99,98,96,91,  #
  810.     #90,88,84,81,80,78,77,75,72,70,66,65,64,63,60,56,55,54,52,50,49,48,45,44,42,   #
  811.     #40,39,36,35,33,32,30,28,27,26,25,24,22,21,20,18,16,15,14,13,12,11             #
  812.     #============================================================================= #
  813.     if $Trainer.partyplus==10
  814.      self.x = [0,256,  0,256,  0,265,  0,265,  0,265][index]
  815.      self.y = [0,  0, 64, 64,128,128,192,192,256,256][index]
  816.     elsif $Trainer.partyplus==9
  817.      self.x = [0,171,341,  0,171,342,  0,171,342][index]
  818.      self.y = [0,  0,  0,107,107,107,214,214,214][index]
  819.     elsif $Trainer.partyplus==8
  820.      self.x = [0,256,  0,256,  0,265,  0,265][index]
  821.      self.y = [0,  0, 80, 80,160,160,240,240][index]
  822.     elsif $Trainer.partyplus==7
  823.      self.x = [0, 74,146,220,294,336,440][index]
  824.      self.y = [0,  0,  0,  0,  0,  0,  0][index]
  825.     elsif $Trainer.partyplus==6
  826.      self.x = [0,256,  0,256,  0,265][index]
  827.      self.y = [0,  0,106,106,214,214][index]
  828.     elsif $Trainer.partyplus==5
  829.      self.x = [0,  0,  0,  0,  0][index]
  830.      self.y = [0, 64,128,192,256][index]
  831.     elsif $Trainer.partyplus==4
  832.      self.x = [0,256,  0,256][index]
  833.      self.y = [0,  0,160,160][index]
  834.     elsif $Trainer.partyplus==3
  835.      self.x = [0,171,342][index]
  836.      self.y = [0,  0,  0][index]
  837.     elsif $Trainer.partyplus==2
  838.      self.x = [0,256][index]
  839.      self.y = [0,  0][index]
  840.     elsif $Trainer.partyplus==1
  841.      self.x = [0][index]
  842.      self.y = [0][index]
  843.     else
  844.      self.x = [0, Graphics.width/2][index%2]
  845.      self.y = [0, 16, 96,112,192,208][index]
  846.     end
  847.     @panelbgsprite = ChangelingSprite.new(0,0,viewport)
  848.     @panelbgsprite.z = self.z
  849.     if $Trainer.partyplus>=1
  850.       folder = $Trainer.partyplus
  851.       @panelbgsprite.addBitmap("able","Graphics/Pictures/Party/PartyPlus/"+"#{folder}"+" - Party/panel_rect")
  852.       @panelbgsprite.addBitmap("ablesel","Graphics/Pictures/Party/PartyPlus/"+"#{folder}"+" - Party/panel_rect_sel")
  853.       @panelbgsprite.addBitmap("fainted","Graphics/Pictures/Party/PartyPlus/"+"#{folder}"+" - Party/panel_rect_faint")
  854.       @panelbgsprite.addBitmap("faintedsel","Graphics/Pictures/Party/PartyPlus/"+"#{folder}"+" - Party/panel_rect_faint_sel")
  855.       @panelbgsprite.addBitmap("swap","Graphics/Pictures/Party/PartyPlus/"+"#{folder}"+" - Party/panel_rect_swap")
  856.       @panelbgsprite.addBitmap("swapsel","Graphics/Pictures/Party/PartyPlus/"+"#{folder}"+" - Party/panel_rect_swap_sel")
  857.       @panelbgsprite.addBitmap("swapsel2","Graphics/Pictures/Party/PartyPlus/"+"#{folder}"+" - Party/panel_rect_swap_sel2")
  858.       @panelbgsprite.addBitmap("benched","Graphics/Pictures/Party/PartyPlus/"+"#{folder}"+" - Party/panel_rect_bench")
  859.       @panelbgsprite.addBitmap("benchedsel","Graphics/Pictures/Party/PartyPlus/"+"#{folder}"+" - Party/panel_rect_bench_sel")
  860.     elsif @active   # Rounded panel
  861.       @panelbgsprite.addBitmap("able","Graphics/Pictures/Party/panel_round")
  862.       @panelbgsprite.addBitmap("ablesel","Graphics/Pictures/Party/panel_round_sel")
  863.       @panelbgsprite.addBitmap("fainted","Graphics/Pictures/Party/panel_round_faint")
  864.       @panelbgsprite.addBitmap("faintedsel","Graphics/Pictures/Party/panel_round_faint_sel")
  865.       @panelbgsprite.addBitmap("swap","Graphics/Pictures/Party/panel_round_swap")
  866.       @panelbgsprite.addBitmap("swapsel","Graphics/Pictures/Party/panel_round_swap_sel")
  867.       @panelbgsprite.addBitmap("swapsel2","Graphics/Pictures/Party/panel_round_swap_sel2")
  868.     else   # Rectangular panel
  869.       @panelbgsprite.addBitmap("able","Graphics/Pictures/Party/panel_rect")
  870.       @panelbgsprite.addBitmap("ablesel","Graphics/Pictures/Party/panel_rect_sel")
  871.       @panelbgsprite.addBitmap("fainted","Graphics/Pictures/Party/panel_rect_faint")
  872.       @panelbgsprite.addBitmap("faintedsel","Graphics/Pictures/Party/panel_rect_faint_sel")
  873.       @panelbgsprite.addBitmap("swap","Graphics/Pictures/Party/panel_rect_swap")
  874.       @panelbgsprite.addBitmap("swapsel","Graphics/Pictures/Party/panel_rect_swap_sel")
  875.       @panelbgsprite.addBitmap("swapsel2","Graphics/Pictures/Party/panel_rect_swap_sel2")
  876.     end
  877.     @hpbgsprite = ChangelingSprite.new(0,0,viewport)
  878.     @hpbgsprite.z = self.z+1
  879.     @hpbgsprite.addBitmap("able","Graphics/Pictures/Party/overlay_hp_back")
  880.     @hpbgsprite.addBitmap("fainted","Graphics/Pictures/Party/overlay_hp_back_faint")
  881.     @hpbgsprite.addBitmap("swap","Graphics/Pictures/Party/overlay_hp_back_swap")
  882.     @ballsprite = ChangelingSprite.new(0,0,viewport)
  883.     @ballsprite.z = self.z+1
  884.     @ballsprite.addBitmap("desel","Graphics/Pictures/Party/icon_ball")
  885.     @ballsprite.addBitmap("sel","Graphics/Pictures/Party/icon_ball_sel")
  886.     @pkmnsprite = PokemonIconSprite.new(pokemon,viewport)
  887.     @pkmnsprite.setOffset(PictureOrigin::Center)
  888.     @pkmnsprite.active = @active
  889.     @pkmnsprite.z      = self.z+2
  890.     @helditemsprite = HeldItemIconSprite.new(0,0,@pokemon,viewport)
  891.     @helditemsprite.z = self.z+3
  892.     @overlaysprite = BitmapSprite.new(Graphics.width,Graphics.height,viewport)
  893.     @overlaysprite.z = self.z+4
  894.     @hpbar    = AnimatedBitmap.new("Graphics/Pictures/Party/overlay_hp")
  895.     @statuses = AnimatedBitmap.new(_INTL("Graphics/Pictures/statuses"))
  896.     if $Trainer.partyplus>=1
  897.     @pkmnsprite.zoom_x = 1
  898.     @pkmnsprite.zoom_y = 1
  899.     @ballsprite.zoom_x = 1
  900.     @ballsprite.zoom_y = 1
  901.     end
  902.     @selected      = false
  903.     @preselected   = false
  904.     @switching     = false
  905.     @text          = nil
  906.     @refreshBitmap = true
  907.     @refreshing    = false
  908.     refresh
  909.   end
  910.   def dispose
  911.     @panelbgsprite.dispose
  912.     @hpbgsprite.dispose
  913.     @ballsprite.dispose
  914.     @pkmnsprite.dispose
  915.     @helditemsprite.dispose
  916.     @overlaysprite.bitmap.dispose
  917.     @overlaysprite.dispose
  918.     @hpbar.dispose
  919.     @statuses.dispose
  920.     super
  921.   end
  922.   def x=(value)
  923.     super
  924.     refresh
  925.   end
  926.   def y=(value)
  927.     super
  928.     refresh
  929.   end
  930.   def color=(value)
  931.     super
  932.     refresh
  933.   end
  934.   def text=(value)
  935.     if @text!=value
  936.       @text = value
  937.       @refreshBitmap = true
  938.       refresh
  939.     end
  940.   end
  941.   def pokemon=(value)
  942.     @pokemon = value
  943.     @pkmnsprite.pokemon = value if @pkmnsprite && !@pkmnsprite.disposed?
  944.     @helditemsprite.pokemon = value if @helditemsprite && !@helditemsprite.disposed?
  945.     @refreshBitmap = true
  946.     refresh
  947.   end
  948.   def selected=(value)
  949.     if @selected!=value
  950.       @selected = value
  951.       refresh
  952.     end
  953.   end
  954.   def preselected=(value)
  955.     if @preselected!=value
  956.       @preselected = value
  957.       refresh
  958.     end
  959.   end
  960.   def switching=(value)
  961.     if @switching!=value
  962.       @switching = value
  963.       refresh
  964.     end
  965.   end
  966.   def hp; return @pokemon.hp; end
  967.   def refresh
  968.     return if disposed?
  969.     return if @refreshing
  970.     @refreshing = true
  971.     if @panelbgsprite && !@panelbgsprite.disposed?
  972.       if self.selected
  973.         if self.preselected;     @panelbgsprite.changeBitmap("swapsel2")
  974.         elsif @switching;        @panelbgsprite.changeBitmap("swapsel")
  975.         elsif @pokemon.fainted?; @panelbgsprite.changeBitmap("faintedsel")
  976.         elsif @pokemon.benched?; @panelbgsprite.changeBitmap("benchedsel")
  977.         else;                    @panelbgsprite.changeBitmap("ablesel")
  978.         end
  979.       else
  980.         if self.preselected;     @panelbgsprite.changeBitmap("swap")
  981.         elsif @pokemon.fainted?; @panelbgsprite.changeBitmap("fainted")
  982.         elsif @pokemon.benched?; @panelbgsprite.changeBitmap("benched")
  983.         else;                    @panelbgsprite.changeBitmap("able")
  984.         end
  985.       end
  986.       @panelbgsprite.x     = self.x
  987.       @panelbgsprite.y     = self.y
  988.       @panelbgsprite.color = self.color
  989.     end
  990.     if @hpbgsprite && !@hpbgsprite.disposed?
  991.       @hpbgsprite.visible = (!@pokemon.egg? && !(@text && @text.length>0))
  992.       if @hpbgsprite.visible
  993.         if self.preselected || (self.selected && @switching); @hpbgsprite.changeBitmap("swap")
  994.         elsif @pokemon.fainted?;                              @hpbgsprite.changeBitmap("fainted")
  995.         else;                                                 @hpbgsprite.changeBitmap("able")
  996.         end
  997.         @hpbgsprite.x     = self.x+96
  998.         @hpbgsprite.y     = self.y+50
  999.         @hpbgsprite.color = self.color
  1000.       end
  1001.     end
  1002.     if @ballsprite && !@ballsprite.disposed?
  1003.       @ballsprite.changeBitmap((self.selected) ? "sel" : "desel")
  1004.       @ballsprite.x     = self.x+10
  1005.       @ballsprite.y     = self.y
  1006.       @ballsprite.color = self.color
  1007.     end
  1008.     if @pkmnsprite && !@pkmnsprite.disposed?
  1009.       @pkmnsprite.x        = self.x+60
  1010.       @pkmnsprite.y        = self.y+40
  1011.       @pkmnsprite.color    = self.color
  1012.       @pkmnsprite.selected = self.selected
  1013.     end
  1014.     if @helditemsprite && !@helditemsprite.disposed?
  1015.       if @helditemsprite.visible
  1016.         @helditemsprite.x     = self.x+62
  1017.         @helditemsprite.y     = self.y+48
  1018.         @helditemsprite.color = self.color
  1019.       end
  1020.     end
  1021.     if @overlaysprite && !@overlaysprite.disposed?
  1022.       @overlaysprite.x     = self.x
  1023.       @overlaysprite.y     = self.y
  1024.       @overlaysprite.color = self.color
  1025.     end
  1026.     if @refreshBitmap
  1027.       @refreshBitmap = false
  1028.       @overlaysprite.bitmap.clear if @overlaysprite.bitmap
  1029.       basecolor   = Color.new(248,248,248)
  1030.       shadowcolor = Color.new(40,40,40)
  1031.       pbSetSystemFont(@overlaysprite.bitmap)
  1032.       textpos = []
  1033.       # Draw Pokémon name
  1034.       textpos.push([@pokemon.name,96,16,0,basecolor,shadowcolor])
  1035.       if !@pokemon.egg?
  1036.         if !@text || @text.length==0
  1037.           # Draw HP numbers
  1038.           textpos.push([sprintf("% 3d /% 3d",@pokemon.hp,@pokemon.totalhp),224,60,1,basecolor,shadowcolor])
  1039.           # Draw HP bar
  1040.           if @pokemon.hp>0
  1041.             w = @pokemon.hp*96*1.0/@pokemon.totalhp
  1042.             w = 1 if w<1
  1043.             w = ((w/2).round)*2
  1044.             hpzone = 0
  1045.             hpzone = 1 if @pokemon.hp<=(@pokemon.totalhp/2).floor
  1046.             hpzone = 2 if @pokemon.hp<=(@pokemon.totalhp/4).floor
  1047.             hprect = Rect.new(0,hpzone*8,w,8)
  1048.             @overlaysprite.bitmap.blt(128,52,@hpbar.bitmap,hprect)
  1049.           end
  1050.           # Draw status
  1051.           status = -1
  1052.           status = 6 if @pokemon.pokerusStage==1
  1053.           status = @pokemon.status-1 if @pokemon.status>0
  1054.           status = 5 if @pokemon.hp<=0
  1055.           if status>=0
  1056.             statusrect = Rect.new(0,16*status,44,16)
  1057.             @overlaysprite.bitmap.blt(78,68,@statuses.bitmap,statusrect)
  1058.           end
  1059.         end
  1060.         # Draw gender symbol
  1061.         if @pokemon.male?
  1062.           textpos.push([_INTL("♂"),224,16,0,Color.new(0,112,248),Color.new(120,184,232)])
  1063.         elsif @pokemon.female?
  1064.           textpos.push([_INTL("♀"),224,16,0,Color.new(232,32,16),Color.new(248,168,184)])
  1065.         end
  1066.         # Draw shiny icon
  1067.         if @pokemon.shiny?
  1068.           pbDrawImagePositions(@overlaysprite.bitmap,[[
  1069.              "Graphics/Pictures/shiny",80,48,0,0,16,16]])
  1070.         end
  1071.       end
  1072.       pbDrawTextPositions(@overlaysprite.bitmap,textpos)
  1073.       # Draw level text
  1074.       if !@pokemon.egg?
  1075.         pbDrawImagePositions(@overlaysprite.bitmap,[[
  1076.            "Graphics/Pictures/Party/overlay_lv",20,70,0,0,22,14]])
  1077.         pbSetSmallFont(@overlaysprite.bitmap)
  1078.         pbDrawTextPositions(@overlaysprite.bitmap,[
  1079.            [@pokemon.level.to_s,42,62,0,basecolor,shadowcolor]
  1080.         ])
  1081.       end
  1082.       # Draw annotation text
  1083.       if @text && @text.length>0
  1084.         pbSetSystemFont(@overlaysprite.bitmap)
  1085.         pbDrawTextPositions(@overlaysprite.bitmap,[
  1086.            [@text,96,58,0,basecolor,shadowcolor]
  1087.         ])
  1088.       end
  1089.     end
  1090.     @refreshing = false
  1091.   end
  1092.   def update
  1093.     super
  1094.     @panelbgsprite.update if @panelbgsprite && !@panelbgsprite.disposed?
  1095.     @hpbgsprite.update if @hpbgsprite && !@hpbgsprite.disposed?
  1096.     @ballsprite.update if @ballsprite && !@ballsprite.disposed?
  1097.     @pkmnsprite.update if @pkmnsprite && !@pkmnsprite.disposed?
  1098.     @helditemsprite.update if @helditemsprite && !@helditemsprite.disposed?
  1099.   end
  1100. end
  1101. #===============================================================================
  1102. # Pokémon party visuals
  1103. #===============================================================================
  1104. class PokemonParty_Scene
  1105.   def pbStartScene(party,starthelptext,annotations=nil,multiselect=false)
  1106.     if ALLOW_BENCHING && $Trainer.partyplus>=1
  1107.      setBenchedParty
  1108.     end
  1109.     @sprites = {}
  1110.     @party = party
  1111.     @viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  1112.     @viewport.z = 99999
  1113.     @multiselect = multiselect
  1114.     if $Trainer.partyplus>=1
  1115.     addBackgroundPlane(@sprites,"partybg","Party/PartyPlus/bg",@viewport)
  1116.     else
  1117.     addBackgroundPlane(@sprites,"partybg","Party/bg",@viewport)
  1118.     end
  1119.     @sprites["messagebox"] = Window_AdvancedTextPokemon.new("")
  1120.     @sprites["messagebox"].viewport       = @viewport
  1121.     @sprites["messagebox"].visible        = false
  1122.     @sprites["messagebox"].letterbyletter = true
  1123.     pbBottomLeftLines(@sprites["messagebox"],2)
  1124.     @sprites["helpwindow"] = Window_UnformattedTextPokemon.new(starthelptext)
  1125.     @sprites["helpwindow"].viewport = @viewport
  1126.     @sprites["helpwindow"].visible  = true
  1127.     pbBottomLeftLines(@sprites["helpwindow"],1)
  1128.     pbSetHelpText(starthelptext)
  1129.     # Add party Pokémon sprites
  1130.     if $Trainer.partyplus>=1
  1131.      for i in 0...$Trainer.partyplus
  1132.        if @party[i]
  1133.          @sprites["pokemon#{i}"] = PokemonPartyPanel.new(@party[i],i,@viewport)
  1134.        else
  1135.          @sprites["pokemon#{i}"] = PokemonPartyBlankPanel.new(@party[i],i,@viewport)
  1136.        end
  1137.        @sprites["pokemon#{i}"].text = annotations[i] if annotations
  1138.      end
  1139.     else
  1140.      for i in 0...6
  1141.        if @party[i]
  1142.          @sprites["pokemon#{i}"] = PokemonPartyPanel.new(@party[i],i,@viewport)
  1143.        else
  1144.          @sprites["pokemon#{i}"] = PokemonPartyBlankPanel.new(@party[i],i,@viewport)
  1145.        end
  1146.        @sprites["pokemon#{i}"].text = annotations[i] if annotations
  1147.      end
  1148.    end
  1149.    if $Trainer.partyplus>=1
  1150.     p = $Trainer.partyplus
  1151.     u = p+1
  1152.    else
  1153.     p = 6
  1154.    end
  1155.      if @multiselect
  1156.        @sprites["pokemon#{p}"] = PokemonPartyConfirmSprite.new(@viewport)
  1157.        @sprites["pokemon#{u}"] = PokemonPartyCancelSprite2.new(@viewport)
  1158.      else
  1159.        @sprites["pokemon#{p}"] = PokemonPartyCancelSprite.new(@viewport)
  1160.      end
  1161.     # Select first Pokémon
  1162.     @activecmd = 0
  1163.     @sprites["pokemon0"].selected = true
  1164.     pbFadeInAndShow(@sprites) { update }
  1165.   end
  1166.   def pbEndScene
  1167.     pbFadeOutAndHide(@sprites) { update }
  1168.     pbDisposeSpriteHash(@sprites)
  1169.     @viewport.dispose
  1170.   end
  1171.   def pbDisplay(text)
  1172.     @sprites["messagebox"].text    = text
  1173.     @sprites["messagebox"].visible = true
  1174.     @sprites["helpwindow"].visible = false
  1175.     pbPlayDecisionSE
  1176.     loop do
  1177.       Graphics.update
  1178.       Input.update
  1179.       self.update
  1180.       if @sprites["messagebox"].busy?
  1181.         if Input.trigger?(Input::C)
  1182.           pbPlayDecisionSE if @sprites["messagebox"].pausing?
  1183.           @sprites["messagebox"].resume
  1184.         end
  1185.       else
  1186.         if Input.trigger?(Input::B) || Input.trigger?(Input::C)
  1187.           break
  1188.         end
  1189.       end
  1190.     end
  1191.     @sprites["messagebox"].visible = false
  1192.     @sprites["helpwindow"].visible = true
  1193.   end
  1194.   def pbDisplayConfirm(text)
  1195.     ret = -1
  1196.     @sprites["messagebox"].text    = text
  1197.     @sprites["messagebox"].visible = true
  1198.     @sprites["helpwindow"].visible = false
  1199.     using(cmdwindow = Window_CommandPokemon.new([_INTL("Yes"),_INTL("No")])) {
  1200.       cmdwindow.visible = false
  1201.       pbBottomRight(cmdwindow)
  1202.       cmdwindow.y -= @sprites["messagebox"].height
  1203.       cmdwindow.z = @viewport.z+1
  1204.       loop do
  1205.         Graphics.update
  1206.         Input.update
  1207.         cmdwindow.visible = true if !@sprites["messagebox"].busy?
  1208.         cmdwindow.update
  1209.         self.update
  1210.         if !@sprites["messagebox"].busy?
  1211.           if Input.trigger?(Input::B)
  1212.             ret = false
  1213.             break
  1214.           elsif Input.trigger?(Input::C) && @sprites["messagebox"].resume
  1215.             ret = (cmdwindow.index==0)
  1216.             break
  1217.           end
  1218.         end
  1219.       end
  1220.     }
  1221.     @sprites["messagebox"].visible = false
  1222.     @sprites["helpwindow"].visible = true
  1223.     return ret
  1224.   end
  1225.   def pbShowCommands(helptext,commands,index=0)
  1226.     ret = -1
  1227.     helpwindow = @sprites["helpwindow"]
  1228.     helpwindow.visible = true
  1229.     using(cmdwindow = Window_CommandPokemonColor.new(commands)) {
  1230.       cmdwindow.z     = @viewport.z+1
  1231.       cmdwindow.index = index
  1232.       pbBottomRight(cmdwindow)
  1233.       helpwindow.resizeHeightToFit(helptext,Graphics.width-cmdwindow.width)
  1234.       helpwindow.text = helptext
  1235.       pbBottomLeft(helpwindow)
  1236.       loop do
  1237.         Graphics.update
  1238.         Input.update
  1239.         cmdwindow.update
  1240.         self.update
  1241.         if Input.trigger?(Input::B)
  1242.           pbPlayCancelSE
  1243.           ret = -1
  1244.           break
  1245.         elsif Input.trigger?(Input::C)
  1246.           pbPlayDecisionSE
  1247.           ret = cmdwindow.index
  1248.           break
  1249.         end
  1250.       end
  1251.     }
  1252.     return ret
  1253.   end
  1254.   def pbSetHelpText(helptext)
  1255.     helpwindow = @sprites["helpwindow"]
  1256.     pbBottomLeftLines(helpwindow,1)
  1257.     helpwindow.text = helptext
  1258.     helpwindow.width = 398
  1259.     helpwindow.visible = true
  1260.   end
  1261.   def pbHasAnnotations?
  1262.     return @sprites["pokemon0"].text!=nil
  1263.   end
  1264.   def pbAnnotate(annot)
  1265.   if $Trainer.partyplus>=1
  1266.     for i in 0...$Trainer.partyplus6
  1267.       @sprites["pokemon#{i}"].text = (annot) ? annot[i] : nil
  1268.     end
  1269.    else
  1270.     for i in 0...6
  1271.       @sprites["pokemon#{i}"].text = (annot) ? annot[i] : nil
  1272.     end
  1273.    end
  1274.   end
  1275.   def pbSelect(item)
  1276.     @activecmd = item
  1277.     if $Trainer.partyplus>=1
  1278.     numsprites = (@multiselect) ? $Trainer.partyplus+2 : $Trainer.partyplus+1
  1279.     else
  1280.     numsprites = (@multiselect) ? 8 : 7
  1281.     end
  1282.     for i in 0...numsprites
  1283.       @sprites["pokemon#{i}"].selected = (i==@activecmd)
  1284.     end
  1285.   end
  1286.   def pbPreSelect(item)
  1287.     @activecmd = item
  1288.   end
  1289.   def pbSwitchBegin(oldid,newid)
  1290.     pbSEPlay("GUI party switch")
  1291.     oldsprite = @sprites["pokemon#{oldid}"]
  1292.     newsprite = @sprites["pokemon#{newid}"]
  1293.     timeTaken = Graphics.frame_rate*4/10
  1294.     distancePerFrame = (Graphics.width/(2.0*timeTaken)).ceil
  1295.     timeTaken.times do
  1296.       oldsprite.x += (oldid&1)==0 ? -distancePerFrame : distancePerFrame
  1297.       newsprite.x += (newid&1)==0 ? -distancePerFrame : distancePerFrame
  1298.       Graphics.update
  1299.       Input.update
  1300.       self.update
  1301.     end
  1302.   end
  1303.   def pbSwitchEnd(oldid,newid)
  1304.     pbSEPlay("GUI party switch")
  1305.     oldsprite = @sprites["pokemon#{oldid}"]
  1306.     newsprite = @sprites["pokemon#{newid}"]
  1307.     oldsprite.pokemon = @party[oldid]
  1308.     newsprite.pokemon = @party[newid]
  1309.     timeTaken = Graphics.frame_rate*4/10
  1310.     distancePerFrame = (Graphics.width/(2.0*timeTaken)).ceil
  1311.     timeTaken.times do
  1312.       oldsprite.x -= (oldid&1)==0 ? -distancePerFrame : distancePerFrame
  1313.       newsprite.x -= (newid&1)==0 ? -distancePerFrame : distancePerFrame
  1314.       Graphics.update
  1315.       Input.update
  1316.       self.update
  1317.     end
  1318.     if $Trainer.partyplus>=1
  1319.      for i in 0...$Trainer.partyplus
  1320.        @sprites["pokemon#{i}"].preselected = false
  1321.        @sprites["pokemon#{i}"].switching   = false
  1322.      end
  1323.     else
  1324.      for i in 0...6
  1325.        @sprites["pokemon#{i}"].preselected = false
  1326.        @sprites["pokemon#{i}"].switching   = false
  1327.      end
  1328.     end
  1329.     pbRefresh
  1330.   end
  1331.   def pbClearSwitching
  1332.    if$Trainer.partyplus>=1
  1333.     for i in 0...$Trainer.partyplus
  1334.       @sprites["pokemon#{i}"].preselected = false
  1335.       @sprites["pokemon#{i}"].switching   = false
  1336.     end
  1337.    else
  1338.     for i in 0...6
  1339.       @sprites["pokemon#{i}"].preselected = false
  1340.       @sprites["pokemon#{i}"].switching   = false
  1341.     end
  1342.    end
  1343.   end
  1344.   def pbSummary(pkmnid,inbattle=false)
  1345.     oldsprites = pbFadeOutAndHide(@sprites)
  1346.     scene = PokemonSummary_Scene.new
  1347.     screen = PokemonSummaryScreen.new(scene,inbattle)
  1348.     screen.pbStartScreen(@party,pkmnid)
  1349.     yield if block_given?
  1350.     pbFadeInAndShow(@sprites,oldsprites)
  1351.   end
  1352.   def pbChooseItem(bag)
  1353.     ret = 0
  1354.     pbFadeOutIn {
  1355.       scene = PokemonBag_Scene.new
  1356.       screen = PokemonBagScreen.new(scene,bag)
  1357.       ret = screen.pbChooseItemScreen(Proc.new { |item| pbCanHoldItem?(item) })
  1358.       yield if block_given?
  1359.     }
  1360.     return ret
  1361.   end
  1362.   def pbUseItem(bag,pokemon)
  1363.     ret = 0
  1364.     pbFadeOutIn {
  1365.       scene = PokemonBag_Scene.new
  1366.       screen = PokemonBagScreen.new(scene,bag)
  1367.       ret = screen.pbChooseItemScreen(Proc.new { |item|
  1368.         next false if !pbCanUseOnPokemon?(item)
  1369.         if pbIsMachine?(item)
  1370.           move = pbGetMachine(item)
  1371.           next false if pokemon.hasMove?(move) || !pokemon.compatibleWithMove?(move)
  1372.         end
  1373.         next true
  1374.       })
  1375.       yield if block_given?
  1376.     }
  1377.     return ret
  1378.   end
  1379.   def pbChoosePokemon(switching=false,initialsel=-1,canswitch=0)
  1380.   if $Trainer.partyplus>=1
  1381.   plus = $Trainer.partyplus
  1382.   else
  1383.   plus = 6
  1384.   end
  1385.     for i in 0...plus
  1386.       @sprites["pokemon#{i}"].preselected = (switching && i==@activecmd)
  1387.       @sprites["pokemon#{i}"].switching   = switching
  1388.     end
  1389.     @activecmd = initialsel if initialsel>=0
  1390.     pbRefresh
  1391.     loop do
  1392.       Graphics.update
  1393.       Input.update
  1394.       self.update
  1395.       oldsel = @activecmd
  1396.       key = -1
  1397.       key = Input::DOWN if Input.repeat?(Input::DOWN)
  1398.       key = Input::RIGHT if Input.repeat?(Input::RIGHT)
  1399.       key = Input::LEFT if Input.repeat?(Input::LEFT)
  1400.       key = Input::UP if Input.repeat?(Input::UP)
  1401.       if key>=0
  1402.         @activecmd = pbChangeSelection(key,@activecmd)
  1403.       end
  1404.       if @activecmd!=oldsel   # Changing selection
  1405.         pbPlayCursorSE
  1406.         numsprites = (@multiselect) ? plaus+2 : plus+1
  1407.         for i in 0...numsprites
  1408.           @sprites["pokemon#{i}"].selected = (i==@activecmd)
  1409.         end
  1410.       end
  1411.       cancelsprite = (@multiselect) ? plus+1 : plus
  1412.       if Input.trigger?(Input::A) && canswitch==1 && @activecmd!=cancelsprite
  1413.         pbPlayDecisionSE
  1414.         return [1,@activecmd]
  1415.       elsif Input.trigger?(Input::A) && canswitch==2
  1416.         return -1
  1417.       elsif Input.trigger?(Input::B)
  1418.         pbPlayCloseMenuSE if !switching
  1419.         return -1
  1420.       elsif Input.trigger?(Input::C)
  1421.         if @activecmd==cancelsprite
  1422.           (switching) ? pbPlayDecisionSE : pbPlayCloseMenuSE
  1423.           return -1
  1424.         else
  1425.           pbPlayDecisionSE
  1426.           return @activecmd
  1427.         end
  1428.       end
  1429.     end
  1430.   end
  1431.   def pbChangeSelection(key,currentsel)
  1432.     numsprites = (@multiselect) ? 8 : 7
  1433.     numsprites = (@multiselect) ? $Trainer.partyplus+2 : $Trainer.partyplus+1 if $Trainer.partyplus>=1
  1434.     if $Trainer.partyplus==10
  1435.     case key
  1436.     when Input::LEFT
  1437.       begin
  1438.         currentsel -= 1
  1439.       end while currentsel>0 && currentsel<@party.length && !@party[currentsel]
  1440.       if currentsel>=@party.length && currentsel<10
  1441.         currentsel = @party.length-1
  1442.       end
  1443.       currentsel = numsprites-1 if currentsel<0
  1444.     when Input::RIGHT
  1445.       begin
  1446.         currentsel += 1
  1447.       end while currentsel<@party.length && !@party[currentsel]
  1448.       if currentsel==@party.length
  1449.         currentsel = 10
  1450.       elsif currentsel==numsprites
  1451.         currentsel = 0
  1452.       end
  1453.     when Input::UP
  1454.       if currentsel>=10
  1455.         begin
  1456.           currentsel -= 1
  1457.         end while currentsel>0 && !@party[currentsel]
  1458.       else
  1459.         begin
  1460.           currentsel -= 2
  1461.         end while currentsel>0 && !@party[currentsel]
  1462.       end
  1463.       if currentsel>=@party.length && currentsel<10
  1464.         currentsel = @party.length-1
  1465.       end
  1466.       currentsel = numsprites-1 if currentsel<0
  1467.     when Input::DOWN
  1468.       if currentsel>=9
  1469.         currentsel += 1
  1470.       else
  1471.         currentsel += 2
  1472.         currentsel = 10 if currentsel<10 && !@party[currentsel]
  1473.       end
  1474.       if currentsel>=@party.length && currentsel<10
  1475.         currentsel = 10
  1476.       elsif currentsel>=numsprites
  1477.         currentsel = 0
  1478.       end
  1479.     end
  1480.     elsif $Trainer.partyplus==9
  1481.     case key
  1482.     when Input::LEFT
  1483.       begin
  1484.         currentsel -= 1
  1485.       end while currentsel>0 && currentsel<@party.length && !@party[currentsel]
  1486.       if currentsel>=@party.length && currentsel<9
  1487.         currentsel = @party.length-1
  1488.       end
  1489.       currentsel = numsprites-1 if currentsel<0
  1490.     when Input::RIGHT
  1491.       begin
  1492.         currentsel += 1
  1493.       end while currentsel<@party.length && !@party[currentsel]
  1494.       if currentsel==@party.length
  1495.         currentsel = 9
  1496.       elsif currentsel==numsprites
  1497.         currentsel = 0
  1498.       end
  1499.     when Input::UP
  1500.       if currentsel>=9
  1501.         begin
  1502.           currentsel -= 1
  1503.         end while currentsel>0 && !@party[currentsel]
  1504.       else
  1505.         begin
  1506.           currentsel -= 3
  1507.         end while currentsel>0 && !@party[currentsel]
  1508.       end
  1509.       if currentsel>=@party.length && currentsel<9
  1510.         currentsel = @party.length-1
  1511.       end
  1512.       currentsel = numsprites-1 if currentsel<0
  1513.     when Input::DOWN
  1514.       if currentsel>=7
  1515.         currentsel += 1
  1516.       else
  1517.         currentsel += 3
  1518.         currentsel = 9 if currentsel<9 && !@party[currentsel]
  1519.       end
  1520.       if currentsel>=@party.length && currentsel<9
  1521.         currentsel = 9
  1522.       elsif currentsel>=numsprites
  1523.         currentsel = 0
  1524.       end
  1525.     end
  1526.     elsif $Trainer.partyplus==8
  1527.     case key
  1528.     when Input::LEFT
  1529.       begin
  1530.         currentsel -= 1
  1531.       end while currentsel>0 && currentsel<@party.length && !@party[currentsel]
  1532.       if currentsel>=@party.length && currentsel<8
  1533.         currentsel = @party.length-1
  1534.       end
  1535.       currentsel = numsprites-1 if currentsel<0
  1536.     when Input::RIGHT
  1537.       begin
  1538.         currentsel += 1
  1539.       end while currentsel<@party.length && !@party[currentsel]
  1540.       if currentsel==@party.length
  1541.         currentsel = 8
  1542.       elsif currentsel==numsprites
  1543.         currentsel = 0
  1544.       end
  1545.     when Input::UP
  1546.       if currentsel>=8
  1547.         begin
  1548.           currentsel -= 1
  1549.         end while currentsel>0 && !@party[currentsel]
  1550.       else
  1551.         begin
  1552.           currentsel -= 2
  1553.         end while currentsel>0 && !@party[currentsel]
  1554.       end
  1555.       if currentsel>=@party.length && currentsel<8
  1556.         currentsel = @party.length-1
  1557.       end
  1558.       currentsel = numsprites-1 if currentsel<0
  1559.     when Input::DOWN
  1560.       if currentsel>=7
  1561.         currentsel += 1
  1562.       else
  1563.         currentsel += 2
  1564.         currentsel = 8 if currentsel<8 && !@party[currentsel]
  1565.       end
  1566.       if currentsel>=@party.length && currentsel<8
  1567.         currentsel = 8
  1568.       elsif currentsel>=numsprites
  1569.         currentsel = 0
  1570.       end
  1571.     end
  1572.     elsif $Trainer.partyplus==7
  1573.     case key
  1574.     when Input::LEFT
  1575.       begin
  1576.         currentsel -= 1
  1577.       end while currentsel>0 && currentsel<@party.length && !@party[currentsel]
  1578.       if currentsel>=@party.length && currentsel<7
  1579.         currentsel = @party.length-1
  1580.       end
  1581.       currentsel = numsprites-1 if currentsel<0
  1582.     when Input::RIGHT
  1583.       begin
  1584.         currentsel += 1
  1585.       end while currentsel<@party.length && !@party[currentsel]
  1586.       if currentsel==@party.length
  1587.         currentsel = 7
  1588.       elsif currentsel==numsprites
  1589.         currentsel = 0
  1590.       end
  1591.     when Input::UP
  1592.       if currentsel>=7
  1593.         begin
  1594.           currentsel -= 1
  1595.         end while currentsel>0 && !@party[currentsel]
  1596.       else
  1597.         begin
  1598.           currentsel -= 1
  1599.         end while currentsel>0 && !@party[currentsel]
  1600.       end
  1601.       if currentsel>=@party.length && currentsel<7
  1602.         currentsel = @party.length-1
  1603.       end
  1604.       currentsel = numsprites-1 if currentsel<0
  1605.     when Input::DOWN
  1606.       if currentsel>=6
  1607.         currentsel += 1
  1608.       else
  1609.         currentsel += 1
  1610.         currentsel = 7 if currentsel<7 && !@party[currentsel]
  1611.       end
  1612.       if currentsel>=@party.length && currentsel<7
  1613.         currentsel = 7
  1614.       elsif currentsel>=numsprites
  1615.         currentsel = 0
  1616.       end
  1617.     end
  1618.     elsif $Trainer.partyplus==5
  1619.     case key
  1620.     when Input::LEFT
  1621.       begin
  1622.         currentsel -= 1
  1623.       end while currentsel>0 && currentsel<@party.length && !@party[currentsel]
  1624.       if currentsel>=@party.length && currentsel<5
  1625.         currentsel = @party.length-1
  1626.       end
  1627.       currentsel = numsprites-1 if currentsel<0
  1628.     when Input::RIGHT
  1629.       begin
  1630.         currentsel += 1
  1631.       end while currentsel<@party.length && !@party[currentsel]
  1632.       if currentsel==@party.length
  1633.         currentsel = 5
  1634.       elsif currentsel==numsprites
  1635.         currentsel = 0
  1636.       end
  1637.     when Input::UP
  1638.       if currentsel>=5
  1639.         begin
  1640.           currentsel -= 1
  1641.         end while currentsel>0 && !@party[currentsel]
  1642.       else
  1643.         begin
  1644.           currentsel -= 1
  1645.         end while currentsel>0 && !@party[currentsel]
  1646.       end
  1647.       if currentsel>=@party.length && currentsel<5
  1648.         currentsel = @party.length-1
  1649.       end
  1650.       currentsel = numsprites-1 if currentsel<0
  1651.     when Input::DOWN
  1652.       if currentsel>=4
  1653.         currentsel += 1
  1654.       else
  1655.         currentsel += 1
  1656.         currentsel = 5 if currentsel<5 && !@party[currentsel]
  1657.       end
  1658.       if currentsel>=@party.length && currentsel<5
  1659.         currentsel = 5
  1660.       elsif currentsel>=numsprites
  1661.         currentsel = 0
  1662.       end
  1663.     end
  1664.     elsif $Trainer.partyplus==4
  1665.     case key
  1666.     when Input::LEFT
  1667.       begin
  1668.         currentsel -= 1
  1669.       end while currentsel>0 && currentsel<@party.length && !@party[currentsel]
  1670.       if currentsel>=@party.length && currentsel<4
  1671.         currentsel = @party.length-1
  1672.       end
  1673.       currentsel = numsprites-1 if currentsel<0
  1674.     when Input::RIGHT
  1675.       begin
  1676.         currentsel += 1
  1677.       end while currentsel<@party.length && !@party[currentsel]
  1678.       if currentsel==@party.length
  1679.         currentsel = 4
  1680.       elsif currentsel==numsprites
  1681.         currentsel = 0
  1682.       end
  1683.     when Input::UP
  1684.       if currentsel>=4
  1685.         begin
  1686.           currentsel -= 1
  1687.         end while currentsel>0 && !@party[currentsel]
  1688.       else
  1689.         begin
  1690.           currentsel -= 2
  1691.         end while currentsel>0 && !@party[currentsel]
  1692.       end
  1693.       if currentsel>=@party.length && currentsel<4
  1694.         currentsel = @party.length-1
  1695.       end
  1696.       currentsel = numsprites-1 if currentsel<0
  1697.     when Input::DOWN
  1698.       if currentsel>=3
  1699.         currentsel += 1
  1700.       else
  1701.         currentsel += 2
  1702.         currentsel = 4 if currentsel<4 && !@party[currentsel]
  1703.       end
  1704.       if currentsel>=@party.length && currentsel<4
  1705.         currentsel = 4
  1706.       elsif currentsel>=numsprites
  1707.         currentsel = 0
  1708.       end
  1709.     end
  1710.     elsif $Trainer.partyplus==3
  1711.     case key
  1712.     when Input::LEFT
  1713.       begin
  1714.         currentsel -= 1
  1715.       end while currentsel>0 && currentsel<@party.length && !@party[currentsel]
  1716.       if currentsel>=@party.length && currentsel<3
  1717.         currentsel = @party.length-1
  1718.       end
  1719.       currentsel = numsprites-1 if currentsel<0
  1720.     when Input::RIGHT
  1721.       begin
  1722.         currentsel += 1
  1723.       end while currentsel<@party.length && !@party[currentsel]
  1724.       if currentsel==@party.length
  1725.         currentsel = 3
  1726.       elsif currentsel==numsprites
  1727.         currentsel = 0
  1728.       end
  1729.     when Input::UP
  1730.       if currentsel>=3
  1731.         begin
  1732.           currentsel -= 1
  1733.         end while currentsel>0 && !@party[currentsel]
  1734.       else
  1735.         begin
  1736.           currentsel -= 1
  1737.         end while currentsel>0 && !@party[currentsel]
  1738.       end
  1739.       if currentsel>=@party.length && currentsel<3
  1740.         currentsel = @party.length-1
  1741.       end
  1742.       currentsel = numsprites-1 if currentsel<0
  1743.     when Input::DOWN
  1744.       if currentsel>=3
  1745.         currentsel += 1
  1746.       else
  1747.         currentsel += 1
  1748.         currentsel = 3 if currentsel<3 && !@party[currentsel]
  1749.       end
  1750.       if currentsel>=@party.length && currentsel<3
  1751.         currentsel = 3
  1752.       elsif currentsel>=numsprites
  1753.         currentsel = 0
  1754.       end
  1755.     end
  1756.     elsif $Trainer.partyplus==2
  1757.     case key
  1758.     when Input::LEFT
  1759.       begin
  1760.         currentsel -= 1
  1761.       end while currentsel>0 && currentsel<@party.length && !@party[currentsel]
  1762.       if currentsel>=@party.length && currentsel<2
  1763.         currentsel = @party.length-1
  1764.       end
  1765.       currentsel = numsprites-1 if currentsel<0
  1766.     when Input::RIGHT
  1767.       begin
  1768.         currentsel += 1
  1769.       end while currentsel<@party.length && !@party[currentsel]
  1770.       if currentsel==@party.length
  1771.         currentsel = 2
  1772.       elsif currentsel==numsprites
  1773.         currentsel = 0
  1774.       end
  1775.     when Input::UP
  1776.       if currentsel>=2
  1777.         begin
  1778.           currentsel -= 1
  1779.         end while currentsel>0 && !@party[currentsel]
  1780.       else
  1781.         begin
  1782.           currentsel -= 2
  1783.         end while currentsel>0 && !@party[currentsel]
  1784.       end
  1785.       if currentsel>=@party.length && currentsel<2
  1786.         currentsel = @party.length-1
  1787.       end
  1788.       currentsel = numsprites-1 if currentsel<0
  1789.     when Input::DOWN
  1790.       if currentsel>=2
  1791.         currentsel += 1
  1792.       else
  1793.         currentsel += 2
  1794.         currentsel = 2 if currentsel<2 && !@party[currentsel]
  1795.       end
  1796.       if currentsel>=@party.length && currentsel<2
  1797.         currentsel = 2
  1798.       elsif currentsel>=numsprites
  1799.         currentsel = 0
  1800.       end
  1801.     end
  1802.     elsif $Trainer.partyplus==1
  1803.     case key
  1804.     when Input::LEFT
  1805.       begin
  1806.         currentsel -= 1
  1807.       end while currentsel>0 && currentsel<@party.length && !@party[currentsel]
  1808.       if currentsel>=@party.length && currentsel<1
  1809.         currentsel = @party.length-1
  1810.       end
  1811.       currentsel = numsprites-1 if currentsel<0
  1812.     when Input::RIGHT
  1813.       begin
  1814.         currentsel += 1
  1815.       end while currentsel<@party.length && !@party[currentsel]
  1816.       if currentsel==@party.length
  1817.         currentsel = 1
  1818.       elsif currentsel==numsprites
  1819.         currentsel = 0
  1820.       end
  1821.     when Input::UP
  1822.       if currentsel>=1
  1823.         begin
  1824.           currentsel -= 1
  1825.         end while currentsel>0 && !@party[currentsel]
  1826.       else
  1827.         begin
  1828.           currentsel -= 1
  1829.         end while currentsel>0 && !@party[currentsel]
  1830.       end
  1831.       if currentsel>=@party.length && currentsel<1
  1832.         currentsel = @party.length-1
  1833.       end
  1834.       currentsel = numsprites-1 if currentsel<0
  1835.     when Input::DOWN
  1836.       if currentsel>=1
  1837.         currentsel += 1
  1838.       else
  1839.         currentsel += 1
  1840.         currentsel = 1 if currentsel<1 && !@party[currentsel]
  1841.       end
  1842.       if currentsel>=@party.length && currentsel<1
  1843.         currentsel = 1
  1844.       elsif currentsel>=numsprites
  1845.         currentsel = 0
  1846.       end
  1847.     end
  1848.     else
  1849.     case key
  1850.     when Input::LEFT
  1851.       begin
  1852.         currentsel -= 1
  1853.       end while currentsel>0 && currentsel<@party.length && !@party[currentsel]
  1854.       if currentsel>=@party.length && currentsel<6
  1855.         currentsel = @party.length-1
  1856.       end
  1857.       currentsel = numsprites-1 if currentsel<0
  1858.     when Input::RIGHT
  1859.       begin
  1860.         currentsel += 1
  1861.       end while currentsel<@party.length && !@party[currentsel]
  1862.       if currentsel==@party.length
  1863.         currentsel = 6
  1864.       elsif currentsel==numsprites
  1865.         currentsel = 0
  1866.       end
  1867.     when Input::UP
  1868.       if currentsel>=6
  1869.         begin
  1870.           currentsel -= 1
  1871.         end while currentsel>0 && !@party[currentsel]
  1872.       else
  1873.         begin
  1874.           currentsel -= 2
  1875.         end while currentsel>0 && !@party[currentsel]
  1876.       end
  1877.       if currentsel>=@party.length && currentsel<6
  1878.         currentsel = @party.length-1
  1879.       end
  1880.       currentsel = numsprites-1 if currentsel<0
  1881.     when Input::DOWN
  1882.       if currentsel>=5
  1883.         currentsel += 1
  1884.       else
  1885.         currentsel += 2
  1886.         currentsel = 6 if currentsel<6 && !@party[currentsel]
  1887.       end
  1888.       if currentsel>=@party.length && currentsel<6
  1889.         currentsel = 6
  1890.       elsif currentsel>=numsprites
  1891.         currentsel = 0
  1892.       end
  1893.     end
  1894.     end
  1895.     return currentsel
  1896.   end
  1897.   def pbHardRefresh
  1898.     oldtext = []
  1899.     lastselected = -1
  1900.     if $Trainer.partyplus>=1
  1901.     for i in 0...$Trainer.partyplus
  1902.       oldtext.push(@sprites["pokemon#{i}"].text)
  1903.       lastselected = i if @sprites["pokemon#{i}"].selected
  1904.       @sprites["pokemon#{i}"].dispose
  1905.     end
  1906.     else
  1907.     for i in 0...6
  1908.       oldtext.push(@sprites["pokemon#{i}"].text)
  1909.       lastselected = i if @sprites["pokemon#{i}"].selected
  1910.       @sprites["pokemon#{i}"].dispose
  1911.     end
  1912.     end
  1913.     lastselected = @party.length-1 if lastselected>=@party.length
  1914.     lastselected = 0 if lastselected<0
  1915.     if $Trainer.partyplus>=1
  1916.     for i in 0...$Trainer.partyplus
  1917.       if @party[i]
  1918.         @sprites["pokemon#{i}"] = PokemonPartyPanel.new(@party[i],i,@viewport)
  1919.       else
  1920.         @sprites["pokemon#{i}"] = PokemonPartyBlankPanel.new(@party[i],i,@viewport)
  1921.       end
  1922.       @sprites["pokemon#{i}"].text = oldtext[i]
  1923.     end
  1924.     else
  1925.     for i in 0...6
  1926.       if @party[i]
  1927.         @sprites["pokemon#{i}"] = PokemonPartyPanel.new(@party[i],i,@viewport)
  1928.       else
  1929.         @sprites["pokemon#{i}"] = PokemonPartyBlankPanel.new(@party[i],i,@viewport)
  1930.       end
  1931.       @sprites["pokemon#{i}"].text = oldtext[i]
  1932.     end
  1933.     end
  1934.     pbSelect(lastselected)
  1935.   end
  1936.   def pbRefresh
  1937.   if $Trainer.partyplus>=1
  1938.     for i in 0...$Trainer.partyplus
  1939.       sprite = @sprites["pokemon#{i}"]
  1940.       if sprite
  1941.         if sprite.is_a?(PokemonPartyPanel)
  1942.           sprite.pokemon = sprite.pokemon
  1943.         else
  1944.           sprite.refresh
  1945.         end
  1946.       end
  1947.     end
  1948.   else
  1949.     for i in 0...6
  1950.       sprite = @sprites["pokemon#{i}"]
  1951.       if sprite
  1952.         if sprite.is_a?(PokemonPartyPanel)
  1953.           sprite.pokemon = sprite.pokemon
  1954.         else
  1955.           sprite.refresh
  1956.         end
  1957.       end
  1958.     end
  1959.   end
  1960.   end
  1961.   def pbRefreshSingle(i)
  1962.     sprite = @sprites["pokemon#{i}"]
  1963.     if sprite
  1964.       if sprite.is_a?(PokemonPartyPanel)
  1965.         sprite.pokemon = sprite.pokemon
  1966.       else
  1967.         sprite.refresh
  1968.       end
  1969.     end
  1970.   end
  1971.   def update
  1972.     pbUpdateSpriteHash(@sprites)
  1973.   end
  1974. end
  1975. #===============================================================================
  1976. # PC menus
  1977. #===============================================================================
  1978. def pbGetStorageCreator
  1979.   creator = pbStorageCreator
  1980.   if $Trainer.partyplus>=1
  1981.   creator = _INTL("Nate") if !creator || creator==""
  1982.   else
  1983.   creator = _INTL("Bill") if !creator || creator==""
  1984.   end
  1985.   return creator
  1986. end
  1987. class StorageSystemPC
  1988.   def shouldShow?
  1989.     return true
  1990.   end
  1991.  
  1992.   def name
  1993.     if $PokemonGlobal.seenStorageCreator
  1994.       return _INTL("{1}'s PC",pbGetStorageCreator)
  1995.     else
  1996.       return _INTL("Someone's PC")
  1997.     end
  1998.   end
  1999.  
  2000.   def access
  2001.     pbMessage(_INTL("\\se[PC access]The Pokémon Storage System was opened."))
  2002.     command = 0
  2003.     if $Trainer.partyplus>=1
  2004.     plus = $Trainer.partyplus
  2005.     else
  2006.     plus = 6
  2007.     end
  2008.     loop do
  2009.       command = pbShowCommandsWithHelp(nil,
  2010.          [_INTL("Organize Boxes"),
  2011.          _INTL("Withdraw Pokémon"),
  2012.          _INTL("Deposit Pokémon"),
  2013.          _INTL("See ya!")],
  2014.          [_INTL("Organize the Pokémon in Boxes and in your party."),
  2015.          _INTL("Move Pokémon stored in Boxes to your party."),
  2016.          _INTL("Store Pokémon in your party in Boxes."),
  2017.          _INTL("Return to the previous menu.")],-1,command
  2018.       )
  2019.       if command>=0 && command<3
  2020.         if command==1   # Withdraw
  2021.           if $PokemonStorage.party.length>=plus
  2022.             pbMessage(_INTL("Your party is full!"))
  2023.             next
  2024.           end
  2025.         elsif command==2   # Deposit
  2026.           count=0
  2027.           for p in $PokemonStorage.party
  2028.             count += 1 if p && !p.egg? && p.hp>0
  2029.           end
  2030.           if count<=1
  2031.             pbMessage(_INTL("Can't deposit the last Pokémon!"))
  2032.             next
  2033.           end
  2034.         end
  2035.         pbFadeOutIn {
  2036.           scene = PokemonStorageScene.new
  2037.           screen = PokemonStorageScreen.new(scene,$PokemonStorage)
  2038.           screen.pbStartScreen(command)
  2039.         }
  2040.       else
  2041.         break
  2042.       end
  2043.     end
  2044.   end
  2045. end
  2046. #===============================================================================
  2047. # Party pop-up panel
  2048. #===============================================================================
  2049. class PokemonBoxPartySprite < SpriteWrapper
  2050.   def initialize(party,viewport=nil)
  2051.     if $Trainer.partyplus>=1
  2052.     plus = $Trainer.partyplus
  2053.     else
  2054.     plus = 6
  2055.     end
  2056.     super(viewport)
  2057.     @party = party
  2058.     if $Trainer.partyplus>=1
  2059.     @boxbitmap = AnimatedBitmap.new("Graphics/Pictures/Storage/Partyplus/overlay_party_"+"#{plus}")
  2060.     else
  2061.     @boxbitmap = AnimatedBitmap.new("Graphics/Pictures/Storage/overlay_party")
  2062.     end
  2063.     @pokemonsprites = []
  2064.     for i in 0...plus
  2065.       @pokemonsprites[i] = nil
  2066.       pokemon = @party[i]
  2067.       if pokemon
  2068.         @pokemonsprites[i] = PokemonBoxIcon.new(pokemon,viewport)
  2069.       end
  2070.     end
  2071.     if $Trainer.partyplus==10
  2072.     @contents = BitmapWrapper.new(172,370)
  2073.     elsif $Trainer.partyplus==9
  2074.     @contents = BitmapWrapper.new(244,352)
  2075.     elsif $Trainer.partyplus==7
  2076.     @contents = BitmapWrapper.new(504,352)
  2077.     elsif $Trainer.partyplus==5
  2078.     @contents = BitmapWrapper.new(172,370)
  2079.     else # 1,2,3,4,6,8
  2080.     @contents = BitmapWrapper.new(172,352)
  2081.     end
  2082.     self.bitmap = @contents
  2083.     if $Trainer.partyplus==9
  2084.     self.x = 254
  2085.     elsif $Trainer.partyplus==7
  2086.     self.x = 514
  2087.     else #1,2,3,4,5,6,8,10
  2088.     self.x = 182
  2089.     end
  2090.     if $Trainer.partyplus==10 || $Trainer.partyplus==5  
  2091.     self.y = Graphics.height-370
  2092.     self.y = Graphics.height-370
  2093.     else # 1,2,3,4,6,7,8,9
  2094.     self.y = Graphics.height-352
  2095.     end
  2096.     pbSetSystemFont(self.bitmap)
  2097.     refresh
  2098.   end
  2099.  
  2100.   def dispose
  2101.     if $Trainer.partyplus>=1
  2102.     plus = $Trainer.partyplus
  2103.     else
  2104.     plus = 6
  2105.     end
  2106.     for i in 0...plus
  2107.       @pokemonsprites[i].dispose if @pokemonsprites[i]
  2108.     end
  2109.     @boxbitmap.dispose
  2110.     @contents.dispose
  2111.     super
  2112.   end
  2113.  
  2114.   def x=(value)
  2115.     super
  2116.     refresh
  2117.   end
  2118.  
  2119.   def y=(value)
  2120.     super
  2121.     refresh
  2122.   end
  2123.  
  2124.   def color=(value)
  2125.     if $Trainer.partyplus>=1
  2126.     plus = $Trainer.partyplus
  2127.     else
  2128.     plus = 6
  2129.     end
  2130.     super
  2131.     for i in 0...plus
  2132.       if @pokemonsprites[i] && !@pokemonsprites[i].disposed?
  2133.         @pokemonsprites[i].color = pbSrcOver(@pokemonsprites[i].color,value)
  2134.       end
  2135.     end
  2136.   end
  2137.  
  2138.   def visible=(value)
  2139.     if $Trainer.partyplus>=1
  2140.     plus = $Trainer.partyplus
  2141.     else
  2142.     plus = 6
  2143.     end
  2144.     super
  2145.     for i in 0...plus
  2146.       if @pokemonsprites[i] && !@pokemonsprites[i].disposed?
  2147.         @pokemonsprites[i].visible = value
  2148.       end
  2149.     end
  2150.   end
  2151.  
  2152.   def getPokemon(index)
  2153.     return @pokemonsprites[index]
  2154.   end
  2155.  
  2156.   def setPokemon(index,sprite)
  2157.     @pokemonsprites[index] = sprite
  2158.     @pokemonsprites.compact!
  2159.     refresh
  2160.   end
  2161.  
  2162.   def grabPokemon(index,arrow)
  2163.     sprite = @pokemonsprites[index]
  2164.     if sprite
  2165.       arrow.grab(sprite)
  2166.       @pokemonsprites[index] = nil
  2167.       @pokemonsprites.compact!
  2168.       refresh
  2169.     end
  2170.   end
  2171.  
  2172.   def deletePokemon(index)
  2173.     @pokemonsprites[index].dispose
  2174.     @pokemonsprites[index] = nil
  2175.     @pokemonsprites.compact!
  2176.     refresh
  2177.   end
  2178.  
  2179.   def refresh
  2180.     if $Trainer.partyplus>=1
  2181.     plus = $Trainer.partyplus
  2182.     else
  2183.     plus = 6
  2184.     end  
  2185.     if $Trainer.partyplus==10 || $Trainer.partyplus==5
  2186.     @contents.blt(0,0,@boxbitmap.bitmap,Rect.new(0,0,172,370))
  2187.     elsif $Trainer.partyplus==9
  2188.     @contents.blt(0,0,@boxbitmap.bitmap,Rect.new(0,0,244,352))
  2189.     elsif $Trainer.partyplus==7
  2190.     @contents.blt(0,0,@boxbitmap.bitmap,Rect.new(0,0,504,352))
  2191.     else # 1,2,3,4,6,8
  2192.     @contents.blt(0,0,@boxbitmap.bitmap,Rect.new(0,0,172,352))
  2193.     end
  2194.     if $Trainer.partyplus==10 || $Trainer.partyplus==5
  2195.     pbDrawTextPositions(self.bitmap,[
  2196.        [_INTL("Back"),86,324,2,Color.new(248,248,248),Color.new(80,80,80),1]
  2197.     ])
  2198.     elsif $Trainer.partyplus==9
  2199.     pbDrawTextPositions(self.bitmap,[
  2200.        [_INTL("Back"),122,242,2,Color.new(248,248,248),Color.new(80,80,80),1]
  2201.     ])
  2202.     elsif $Trainer.partyplus==8
  2203.     pbDrawTextPositions(self.bitmap,[
  2204.        [_INTL("Back"),86,306,2,Color.new(248,248,248),Color.new(80,80,80),1]
  2205.     ])
  2206.     elsif $Trainer.partyplus==7
  2207.     pbDrawTextPositions(self.bitmap,[
  2208.        [_INTL("Back"),252,306,2,Color.new(248,248,248),Color.new(80,80,80),1]
  2209.     ])
  2210.     else
  2211.     pbDrawTextPositions(self.bitmap,[
  2212.        [_INTL("Back"),86,242,2,Color.new(248,248,248),Color.new(80,80,80),1]
  2213.     ])
  2214.     end
  2215.  
  2216.     if $Trainer.partyplus==10
  2217.     xvalues = [ 18, 90, 18, 90, 18, 90, 18, 90, 18, 90]
  2218.     yvalues = [  6, 22, 60, 76,114,130,168,184,222,238]
  2219.     elsif $Trainer.partyplus==9
  2220.     xvalues = [ 18, 90,162, 18, 90,162, 18, 90,162]
  2221.     yvalues = [  2, 18,  2, 66, 82, 66,130,146,130]
  2222.     elsif $Trainer.partyplus==8
  2223.     xvalues = [18, 90, 18, 90, 18, 90, 18, 90]
  2224.     yvalues = [ 2, 18, 66, 82,130,146,194,210]
  2225.     elsif $Trainer.partyplus==7
  2226.     xvalues = [ 16, 84,152,220,288,356,424]
  2227.     yvalues = [194,210,194,210,194,210,194]
  2228.     elsif $Trainer.partyplus==5
  2229.     xvalues = [ 54, 54, 54, 54, 54]
  2230.     yvalues = [  6, 60,114,168,222]
  2231.     elsif $Trainer.partyplus==4
  2232.     xvalues = [ 18, 90, 18, 90]
  2233.     yvalues = [ 66, 82,130,146]
  2234.     elsif $Trainer.partyplus==3
  2235.     xvalues = [ 54, 54, 54]
  2236.     yvalues = [  2, 66,130]
  2237.     elsif $Trainer.partyplus==2
  2238.     xvalues = [ 18, 90]
  2239.     yvalues = [130,146]
  2240.     elsif $Trainer.partyplus==1
  2241.     xvalues = [ 54]
  2242.     yvalues = [130]
  2243.     else
  2244.     xvalues = [18,90,18,90,18,90]
  2245.     yvalues = [2,18,66,82,130,146]
  2246.     end
  2247.     for j in 0...plus
  2248.       @pokemonsprites[j] = nil if @pokemonsprites[j] && @pokemonsprites[j].disposed?
  2249.     end
  2250.     @pokemonsprites.compact!
  2251.     for j in 0...plus
  2252.       sprite = @pokemonsprites[j]
  2253.       if sprite && !sprite.disposed?
  2254.         sprite.viewport = self.viewport
  2255.         sprite.x = self.x+xvalues[j]
  2256.         sprite.y = self.y+yvalues[j]
  2257.         sprite.z = 0
  2258.       end
  2259.     end
  2260.   end
  2261.  
  2262.   def update
  2263.     if $Trainer.partyplus>=1
  2264.     plus = $Trainer.partyplus
  2265.     else
  2266.     plus = 6
  2267.     end  
  2268.     super
  2269.     for i in 0...plus
  2270.       @pokemonsprites[i].update if @pokemonsprites[i] && !@pokemonsprites[i].disposed?
  2271.     end
  2272.   end
  2273. end
  2274. #===============================================================================
  2275. # Pokémon storage visuals
  2276. #===============================================================================
  2277. class PokemonStorageScene
  2278.   attr_reader :quickswap
  2279.  
  2280.   def initialize
  2281.     @command = 1
  2282.   end
  2283.  
  2284.   def pbStartBox(screen,command)
  2285.     @screen = screen
  2286.     @storage = screen.storage
  2287.     @bgviewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  2288.     @bgviewport.z = 99999
  2289.     @boxviewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  2290.     @boxviewport.z = 99999
  2291.     @boxsidesviewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  2292.     @boxsidesviewport.z = 99999
  2293.     @arrowviewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  2294.     @arrowviewport.z = 99999
  2295.     @viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  2296.     @viewport.z = 99999
  2297.     @selection = 0
  2298.     @quickswap = false
  2299.     @sprites = {}
  2300.     @choseFromParty = false
  2301.     @command = command
  2302.     addBackgroundPlane(@sprites,"background","Storage/bg",@bgviewport)
  2303.     @sprites["box"] = PokemonBoxSprite.new(@storage,@storage.currentBox,@boxviewport)
  2304.     @sprites["boxsides"] = IconSprite.new(0,0,@boxsidesviewport)
  2305.     @sprites["boxsides"].setBitmap("Graphics/Pictures/Storage/overlay_main")
  2306.     @sprites["overlay"] = BitmapSprite.new(Graphics.width,Graphics.height,@boxsidesviewport)
  2307.     pbSetSystemFont(@sprites["overlay"].bitmap)
  2308.     @sprites["pokemon"] = AutoMosaicPokemonSprite.new(@boxsidesviewport)
  2309.     @sprites["pokemon"].setOffset(PictureOrigin::Center)
  2310.     @sprites["pokemon"].x = 90
  2311.     @sprites["pokemon"].y = 134
  2312.     @sprites["boxparty"] = PokemonBoxPartySprite.new(@storage.party,@boxsidesviewport)
  2313.     if command!=2   # Drop down tab only on Deposit
  2314.      if $Trainer.partyplus==7
  2315.       @sprites["boxparty"].x = 4
  2316.      else
  2317.       @sprites["boxparty"].x = 182
  2318.      end
  2319.       @sprites["boxparty"].y = Graphics.height
  2320.     end
  2321.     @markingbitmap = AnimatedBitmap.new("Graphics/Pictures/Storage/markings")
  2322.     @sprites["markingbg"] = IconSprite.new(292,68,@boxsidesviewport)
  2323.     @sprites["markingbg"].setBitmap("Graphics/Pictures/Storage/overlay_marking")
  2324.     @sprites["markingbg"].visible = false
  2325.     @sprites["markingoverlay"] = BitmapSprite.new(Graphics.width,Graphics.height,@boxsidesviewport)
  2326.     @sprites["markingoverlay"].visible = false
  2327.     pbSetSystemFont(@sprites["markingoverlay"].bitmap)
  2328.     @sprites["arrow"] = PokemonBoxArrow.new(@arrowviewport)
  2329.     @sprites["arrow"].z += 1
  2330.     if command!=2
  2331.       pbSetArrow(@sprites["arrow"],@selection)
  2332.       pbUpdateOverlay(@selection)
  2333.       pbSetMosaic(@selection)
  2334.     else
  2335.       pbPartySetArrow(@sprites["arrow"],@selection)
  2336.       pbUpdateOverlay(@selection,@storage.party)
  2337.       pbSetMosaic(@selection)
  2338.     end
  2339.     pbSEPlay("PC access")
  2340.     pbFadeInAndShow(@sprites)
  2341.   end
  2342.  
  2343.   def pbCloseBox
  2344.     pbFadeOutAndHide(@sprites)
  2345.     pbDisposeSpriteHash(@sprites)
  2346.     @markingbitmap.dispose if @markingbitmap
  2347.     @boxviewport.dispose
  2348.     @boxsidesviewport.dispose
  2349.     @arrowviewport.dispose
  2350.   end
  2351.  
  2352.   def pbDisplay(message)
  2353.     msgwindow = Window_UnformattedTextPokemon.newWithSize("",180,0,Graphics.width-180,32)
  2354.     msgwindow.viewport       = @viewport
  2355.     msgwindow.visible        = true
  2356.     msgwindow.letterbyletter = false
  2357.     msgwindow.resizeHeightToFit(message,Graphics.width-180)
  2358.     msgwindow.text           = message
  2359.     pbBottomRight(msgwindow)
  2360.     loop do
  2361.       Graphics.update
  2362.       Input.update
  2363.       if Input.trigger?(Input::B) || Input.trigger?(Input::C)
  2364.         break
  2365.       end
  2366.       msgwindow.update
  2367.       self.update
  2368.     end
  2369.     msgwindow.dispose
  2370.     Input.update
  2371.   end
  2372.  
  2373.   def pbShowCommands(message,commands,index=0)
  2374.     ret = -1
  2375.     msgwindow = Window_UnformattedTextPokemon.newWithSize("",180,0,Graphics.width-180,32)
  2376.     msgwindow.viewport       = @viewport
  2377.     msgwindow.visible        = true
  2378.     msgwindow.letterbyletter = false
  2379.     msgwindow.text           = message
  2380.     msgwindow.resizeHeightToFit(message,Graphics.width-180)
  2381.     pbBottomRight(msgwindow)
  2382.     cmdwindow = Window_CommandPokemon.new(commands)
  2383.     cmdwindow.viewport = @viewport
  2384.     cmdwindow.visible  = true
  2385.     cmdwindow.resizeToFit(cmdwindow.commands)
  2386.     cmdwindow.height   = Graphics.height-msgwindow.height if cmdwindow.height>Graphics.height-msgwindow.height
  2387.     pbBottomRight(cmdwindow)
  2388.     cmdwindow.y        -= msgwindow.height
  2389.     cmdwindow.index    = index
  2390.     loop do
  2391.       Graphics.update
  2392.       Input.update
  2393.       msgwindow.update
  2394.       cmdwindow.update
  2395.       if Input.trigger?(Input::B)
  2396.         ret = -1
  2397.         break
  2398.       elsif Input.trigger?(Input::C)
  2399.         ret = cmdwindow.index
  2400.         break
  2401.       end
  2402.       self.update
  2403.     end
  2404.     msgwindow.dispose
  2405.     cmdwindow.dispose
  2406.     Input.update
  2407.     return ret
  2408.   end
  2409.  
  2410.   def pbSetArrow(arrow,selection)
  2411.     case selection
  2412.     when -1, -4, -5 # Box name, move left, move right
  2413.       arrow.x = 157*2
  2414.       arrow.y = -12*2
  2415.     when -2 # Party Pokémon
  2416.       arrow.x = 119*2
  2417.       arrow.y = 139*2
  2418.     when -3 # Close Box
  2419.       arrow.x = 207*2
  2420.       arrow.y = 139*2
  2421.     else
  2422.       arrow.x = (97+24*(selection%6))*2
  2423.       arrow.y = (8+24*(selection/6))*2
  2424.     end
  2425.   end
  2426.  
  2427.   def pbChangeSelection(key,selection)
  2428.     case key
  2429.     when Input::UP
  2430.       if selection==-1   # Box name
  2431.         selection = -2
  2432.       elsif selection==-2   # Party
  2433.         selection = 25
  2434.       elsif selection==-3   # Close Box
  2435.         selection = 28
  2436.       else
  2437.         selection -= 6
  2438.         selection = -1 if selection<0
  2439.       end
  2440.     when Input::DOWN
  2441.       if selection==-1   # Box name
  2442.         selection = 2
  2443.       elsif selection==-2   # Party
  2444.         selection = -1
  2445.       elsif selection==-3   # Close Box
  2446.         selection = -1
  2447.       else
  2448.         selection += 6
  2449.         selection = -2 if selection==30 || selection==31 || selection==32
  2450.         selection = -3 if selection==33 || selection==34 || selection==35
  2451.       end
  2452.     when Input::LEFT
  2453.       if selection==-1   # Box name
  2454.         selection = -4   # Move to previous box
  2455.       elsif selection==-2
  2456.         selection = -3
  2457.       elsif selection==-3
  2458.         selection = -2
  2459.       else
  2460.         selection -= 1
  2461.         selection += 6 if selection==-1 || selection%6==5
  2462.       end
  2463.     when Input::RIGHT
  2464.       if selection==-1   # Box name
  2465.         selection = -5   # Move to next box
  2466.       elsif selection==-2
  2467.         selection = -3
  2468.       elsif selection==-3
  2469.         selection = -2
  2470.       else
  2471.         selection += 1
  2472.         selection -= 6 if selection%6==0
  2473.       end
  2474.     end
  2475.     return selection
  2476.   end
  2477.  
  2478.   def pbPartySetArrow(arrow,selection)
  2479.     if selection>=0
  2480.     if $Trainer.partyplus==10
  2481.       xvalues = [200,272,200,272,200,272,200,272,200,272,236]
  2482.       yvalues = [-12,  4, 42, 58, 96,112,150,166,204,220,284]
  2483.     elsif $Trainer.partyplus==9
  2484.       xvalues = [200,272,344,200,272,344,200,272,344,272]
  2485.       yvalues = [  2, 18,  2, 66, 82, 66,130,146,130,220]
  2486.     elsif $Trainer.partyplus==8
  2487.       xvalues = [200,272,200,272,200,272,200,272,236]
  2488.       yvalues = [  2, 18, 66, 82,130,146,194,210,284]
  2489.     elsif $Trainer.partyplus==7
  2490.       xvalues = [ 20, 88,156,224,292,360,428,224]
  2491.       yvalues = [194,210,194,210,194,210,194,284]
  2492.     elsif $Trainer.partyplus==5
  2493.       xvalues = [236,236,236,236,236,236]
  2494.       yvalues = [-12, 42, 96,150,204,284]
  2495.     elsif $Trainer.partyplus==4
  2496.       xvalues = [200,272,200,272,236]
  2497.       yvalues = [ 66, 82,130,146,220]
  2498.     elsif $Trainer.partyplus==3
  2499.       xvalues = [236,236,236,236]
  2500.       yvalues = [  2, 66,130,220]
  2501.     elsif $Trainer.partyplus==2
  2502.       xvalues = [200,272,236]
  2503.       yvalues = [130,146,220]
  2504.     elsif $Trainer.partyplus==1
  2505.       xvalues = [236,236]
  2506.       yvalues = [130,220]
  2507.     else
  2508.       xvalues = [200,272,200,272,200,272,236]
  2509.       yvalues = [2,18,66,82,130,146,220]
  2510.     end
  2511.       arrow.angle = 0
  2512.       arrow.mirror = false
  2513.       arrow.ox = 0
  2514.       arrow.oy = 0
  2515.       arrow.x = xvalues[selection]
  2516.       arrow.y = yvalues[selection]
  2517.     end
  2518.   end
  2519.  
  2520.  
  2521.   def pbPartyChangeSelection(key,selection)
  2522.     if $Trainer.partyplus>=1
  2523.     plus = $Trainer.partyplus
  2524.     else
  2525.     plus = 6
  2526.     end
  2527.     if $Trainer.partyplus>=1
  2528.     case key
  2529.     when Input::LEFT
  2530.       selection -= 1
  2531.       selection = plus if selection<0
  2532.     when Input::RIGHT
  2533.       selection += 1
  2534.       selection = 0 if selection>plus
  2535.     when Input::UP
  2536.       if selection==plus
  2537.         selection = plus-1
  2538.       else
  2539.        if $Trainer.partyplus==7
  2540.         selection -= 7
  2541.        elsif $Trainer.partyplus==9
  2542.         selection -= 3
  2543.        elsif $Trainer.partyplus==1 || $Trainer.partyplus==3 || $Trainer.partyplus==5
  2544.         selection -= 1
  2545.        else #10,2,4,6,8
  2546.         selection -= 2
  2547.        end
  2548.         selection = plus if selection<0
  2549.       end
  2550.     when Input::DOWN
  2551.       if selection==plus
  2552.         selection = 0
  2553.        elsif $Trainer.partyplus==7
  2554.         selection += 7
  2555.        elsif $Trainer.partyplus==9
  2556.         selection += 3
  2557.        elsif $Trainer.partyplus==1 || $Trainer.partyplus==3 || $Trainer.partyplus==5
  2558.         selection += 1
  2559.        else
  2560.         selection += 2
  2561.        end
  2562.         selection = plus if selection>plus
  2563.       end
  2564.     else
  2565.     case key
  2566.     when Input::LEFT
  2567.       selection -= 1
  2568.       selection = 6 if selection<0
  2569.     when Input::RIGHT
  2570.       selection += 1
  2571.       selection = 0 if selection>6
  2572.     when Input::UP
  2573.       if selection==6
  2574.         selection = 5
  2575.       else
  2576.         selection -= 2
  2577.         selection = 6 if selection<0
  2578.       end
  2579.     when Input::DOWN
  2580.       if selection==6
  2581.         selection = 0
  2582.       else
  2583.         selection += 2
  2584.         selection = 6 if selection>6
  2585.       end
  2586.     end
  2587.   end
  2588.     return selection
  2589.   end
  2590.  
  2591.   def pbSelectBoxInternal(_party)
  2592.     selection = @selection
  2593.     pbSetArrow(@sprites["arrow"],selection)
  2594.     pbUpdateOverlay(selection)
  2595.     pbSetMosaic(selection)
  2596.     loop do
  2597.       Graphics.update
  2598.       Input.update
  2599.       key = -1
  2600.       key = Input::DOWN if Input.repeat?(Input::DOWN)
  2601.       key = Input::RIGHT if Input.repeat?(Input::RIGHT)
  2602.       key = Input::LEFT if Input.repeat?(Input::LEFT)
  2603.       key = Input::UP if Input.repeat?(Input::UP)
  2604.       if key>=0
  2605.         pbPlayCursorSE
  2606.         selection = pbChangeSelection(key,selection)
  2607.         pbSetArrow(@sprites["arrow"],selection)
  2608.         if selection==-4
  2609.           nextbox = (@storage.currentBox+@storage.maxBoxes-1)%@storage.maxBoxes
  2610.           pbSwitchBoxToLeft(nextbox)
  2611.           @storage.currentBox = nextbox
  2612.         elsif selection==-5
  2613.           nextbox = (@storage.currentBox+1)%@storage.maxBoxes
  2614.           pbSwitchBoxToRight(nextbox)
  2615.           @storage.currentBox = nextbox
  2616.         end
  2617.         selection = -1 if selection==-4 || selection==-5
  2618.         pbUpdateOverlay(selection)
  2619.         pbSetMosaic(selection)
  2620.       end
  2621.       self.update
  2622.       if Input.trigger?(Input::L)
  2623.         pbPlayCursorSE
  2624.         nextbox = (@storage.currentBox+@storage.maxBoxes-1)%@storage.maxBoxes
  2625.         pbSwitchBoxToLeft(nextbox)
  2626.         @storage.currentBox = nextbox
  2627.         pbUpdateOverlay(selection)
  2628.         pbSetMosaic(selection)
  2629.       elsif Input.trigger?(Input::R)
  2630.         pbPlayCursorSE
  2631.         nextbox = (@storage.currentBox+1)%@storage.maxBoxes
  2632.         pbSwitchBoxToRight(nextbox)
  2633.         @storage.currentBox = nextbox
  2634.         pbUpdateOverlay(selection)
  2635.         pbSetMosaic(selection)
  2636.       elsif Input.trigger?(Input::F5)   # Jump to box name
  2637.         if selection!=-1
  2638.           pbPlayCursorSE
  2639.           selection = -1
  2640.           pbSetArrow(@sprites["arrow"],selection)
  2641.           pbUpdateOverlay(selection)
  2642.           pbSetMosaic(selection)
  2643.         end
  2644.       elsif Input.trigger?(Input::A) && @command==0   # Organize only
  2645.         pbPlayDecisionSE
  2646.         pbSetQuickSwap(!@quickswap)
  2647.       elsif Input.trigger?(Input::B)
  2648.         @selection = selection
  2649.         return nil
  2650.       elsif Input.trigger?(Input::C)
  2651.         @selection = selection
  2652.         if selection>=0
  2653.           return [@storage.currentBox,selection]
  2654.         elsif selection==-1   # Box name
  2655.           return [-4,-1]
  2656.         elsif selection==-2   # Party Pokémon
  2657.           return [-2,-1]
  2658.         elsif selection==-3   # Close Box
  2659.           return [-3,-1]
  2660.         end
  2661.       end
  2662.     end
  2663.   end
  2664.  
  2665.   def pbSelectBox(party)
  2666.     return pbSelectBoxInternal(party) if @command==1   # Withdraw
  2667.     ret = nil
  2668.     loop do
  2669.       if !@choseFromParty
  2670.         ret = pbSelectBoxInternal(party)
  2671.       end
  2672.       if @choseFromParty || (ret && ret[0]==-2)   # Party Pokémon
  2673.         if !@choseFromParty
  2674.           pbShowPartyTab
  2675.           @selection = 0
  2676.         end
  2677.         ret = pbSelectPartyInternal(party,false)
  2678.         if ret<0
  2679.           pbHidePartyTab
  2680.           @selection = 0
  2681.           @choseFromParty = false
  2682.         else
  2683.           @choseFromParty = true
  2684.           return [-1,ret]
  2685.         end
  2686.       else
  2687.         @choseFromParty = false
  2688.         return ret
  2689.       end
  2690.     end
  2691.   end
  2692.  
  2693.   def pbSelectPartyInternal(party,depositing)
  2694.     if $Trainer.partyplus>=1
  2695.     plus = $Trainer.partyplus
  2696.     else
  2697.     plus = 6
  2698.     end
  2699.     selection = @selection
  2700.     pbPartySetArrow(@sprites["arrow"],selection)
  2701.     pbUpdateOverlay(selection,party)
  2702.     pbSetMosaic(selection)
  2703.     lastsel = 1
  2704.     loop do
  2705.       Graphics.update
  2706.       Input.update
  2707.       key = -1
  2708.       key = Input::DOWN if Input.repeat?(Input::DOWN)
  2709.       key = Input::RIGHT if Input.repeat?(Input::RIGHT)
  2710.       key = Input::LEFT if Input.repeat?(Input::LEFT)
  2711.       key = Input::UP if Input.repeat?(Input::UP)
  2712.       if key>=0
  2713.         pbPlayCursorSE
  2714.         newselection = pbPartyChangeSelection(key,selection)
  2715.         if newselection==-1
  2716.           return -1 if !depositing
  2717.         elsif newselection==-2
  2718.           selection = lastsel
  2719.         else
  2720.           selection = newselection
  2721.         end
  2722.         pbPartySetArrow(@sprites["arrow"],selection)
  2723.         lastsel = selection if selection>0
  2724.         pbUpdateOverlay(selection,party)
  2725.         pbSetMosaic(selection)
  2726.       end
  2727.       self.update
  2728.       if Input.trigger?(Input::A) && @command==0   # Organize only
  2729.         pbPlayDecisionSE
  2730.         pbSetQuickSwap(!@quickswap)
  2731.       elsif Input.trigger?(Input::B)
  2732.         @selection = selection
  2733.         return -1
  2734.       elsif Input.trigger?(Input::C)
  2735.         if selection>=0 && selection<plus
  2736.           @selection = selection
  2737.           return selection
  2738.         elsif selection==plus   # Close Box
  2739.           @selection = selection
  2740.           return (depositing) ? -3 : -1
  2741.         end
  2742.       end
  2743.     end
  2744.   end
  2745.  
  2746.   def pbSelectParty(party)
  2747.     return pbSelectPartyInternal(party,true)
  2748.   end
  2749.  
  2750.   def pbChangeBackground(wp)
  2751.     @sprites["box"].refreshSprites = false
  2752.     alpha = 0
  2753.     Graphics.update
  2754.     self.update
  2755.     timeTaken = Graphics.frame_rate*4/10
  2756.     alphaDiff = (255.0/timeTaken).ceil
  2757.     timeTaken.times do
  2758.       alpha += alphaDiff
  2759.       Graphics.update
  2760.       Input.update
  2761.       @sprites["box"].color = Color.new(248,248,248,alpha)
  2762.       self.update
  2763.     end
  2764.     @sprites["box"].refreshBox = true
  2765.     @storage[@storage.currentBox].background = wp
  2766.     (Graphics.frame_rate/10).times do
  2767.       Graphics.update
  2768.       Input.update
  2769.       self.update
  2770.     end
  2771.     timeTaken.times do
  2772.       alpha -= alphaDiff
  2773.       Graphics.update
  2774.       Input.update
  2775.       @sprites["box"].color = Color.new(248,248,248,alpha)
  2776.       self.update
  2777.     end
  2778.     @sprites["box"].refreshSprites = true
  2779.   end
  2780.  
  2781.   def pbSwitchBoxToRight(newbox)
  2782.     newbox = PokemonBoxSprite.new(@storage,newbox,@boxviewport)
  2783.     newbox.x = 520
  2784.     Graphics.frame_reset
  2785.     distancePerFrame = 64*20/Graphics.frame_rate
  2786.     loop do
  2787.       Graphics.update
  2788.       Input.update
  2789.       @sprites["box"].x -= distancePerFrame
  2790.       newbox.x -= distancePerFrame
  2791.       self.update
  2792.       break if newbox.x<=184
  2793.     end
  2794.     diff = newbox.x-184
  2795.     newbox.x = 184
  2796.     @sprites["box"].x -= diff
  2797.     @sprites["box"].dispose
  2798.     @sprites["box"] = newbox
  2799.   end
  2800.  
  2801.   def pbSwitchBoxToLeft(newbox)
  2802.     newbox = PokemonBoxSprite.new(@storage,newbox,@boxviewport)
  2803.     newbox.x = -152
  2804.     Graphics.frame_reset
  2805.     distancePerFrame = 64*20/Graphics.frame_rate
  2806.     loop do
  2807.       Graphics.update
  2808.       Input.update
  2809.       @sprites["box"].x += distancePerFrame
  2810.       newbox.x += distancePerFrame
  2811.       self.update
  2812.       break if newbox.x>=184
  2813.     end
  2814.     diff = newbox.x-184
  2815.     newbox.x = 184
  2816.     @sprites["box"].x -= diff
  2817.     @sprites["box"].dispose
  2818.     @sprites["box"] = newbox
  2819.   end
  2820.  
  2821.   def pbJumpToBox(newbox)
  2822.     if @storage.currentBox!=newbox
  2823.       if newbox>@storage.currentBox
  2824.         pbSwitchBoxToRight(newbox)
  2825.       else
  2826.         pbSwitchBoxToLeft(newbox)
  2827.       end
  2828.       @storage.currentBox = newbox
  2829.     end
  2830.   end
  2831.  
  2832.   def pbSetMosaic(selection)
  2833.     if !@screen.pbHeldPokemon
  2834.       if @boxForMosaic!=@storage.currentBox || @selectionForMosaic!=selection
  2835.         @sprites["pokemon"].mosaic = Graphics.frame_rate/4
  2836.         @boxForMosaic = @storage.currentBox
  2837.         @selectionForMosaic = selection
  2838.       end
  2839.     end
  2840.   end
  2841.  
  2842.   def pbSetQuickSwap(value)
  2843.     @quickswap = value
  2844.     @sprites["arrow"].quickswap = value
  2845.   end
  2846.  
  2847.   def pbShowPartyTab
  2848.   if $Trainer.partyplus==10 || $Trainer.partyplus==5
  2849.   plus = 370
  2850.   else
  2851.   plus = 352
  2852.   end
  2853.     pbSEPlay("GUI storage show party panel")
  2854.     distancePerFrame = 48*20/Graphics.frame_rate
  2855.     loop do
  2856.       Graphics.update
  2857.       Input.update
  2858.       @sprites["boxparty"].y -= distancePerFrame
  2859.       self.update
  2860.       break if @sprites["boxparty"].y<=Graphics.height-plus
  2861.     end
  2862.     @sprites["boxparty"].y = Graphics.height-plus
  2863.   end
  2864.  
  2865.   def pbHidePartyTab
  2866.     pbSEPlay("GUI storage hide party panel")
  2867.     distancePerFrame = 48*20/Graphics.frame_rate
  2868.     loop do
  2869.       Graphics.update
  2870.       Input.update
  2871.       @sprites["boxparty"].y += distancePerFrame
  2872.       self.update
  2873.       break if @sprites["boxparty"].y>=Graphics.height
  2874.     end
  2875.     @sprites["boxparty"].y = Graphics.height
  2876.   end
  2877.  
  2878.   def pbHold(selected)
  2879.     pbSEPlay("GUI storage pick up")
  2880.     if selected[0]==-1
  2881.       @sprites["boxparty"].grabPokemon(selected[1],@sprites["arrow"])
  2882.     else
  2883.       @sprites["box"].grabPokemon(selected[1],@sprites["arrow"])
  2884.     end
  2885.     while @sprites["arrow"].grabbing?
  2886.       Graphics.update
  2887.       Input.update
  2888.       self.update
  2889.     end
  2890.   end
  2891.  
  2892.   def pbSwap(selected,_heldpoke)
  2893.     pbSEPlay("GUI storage pick up")
  2894.     heldpokesprite = @sprites["arrow"].heldPokemon
  2895.     boxpokesprite = nil
  2896.     if selected[0]==-1
  2897.       boxpokesprite = @sprites["boxparty"].getPokemon(selected[1])
  2898.     else
  2899.       boxpokesprite = @sprites["box"].getPokemon(selected[1])
  2900.     end
  2901.     if selected[0]==-1
  2902.       @sprites["boxparty"].setPokemon(selected[1],heldpokesprite)
  2903.     else
  2904.       @sprites["box"].setPokemon(selected[1],heldpokesprite)
  2905.     end
  2906.     @sprites["arrow"].setSprite(boxpokesprite)
  2907.     @sprites["pokemon"].mosaic = 10
  2908.     @boxForMosaic = @storage.currentBox
  2909.     @selectionForMosaic = selected[1]
  2910.   end
  2911.  
  2912.   def pbPlace(selected,_heldpoke)
  2913.     pbSEPlay("GUI storage put down")
  2914.     heldpokesprite = @sprites["arrow"].heldPokemon
  2915.     @sprites["arrow"].place
  2916.     while @sprites["arrow"].placing?
  2917.       Graphics.update
  2918.       Input.update
  2919.       self.update
  2920.     end
  2921.     if selected[0]==-1
  2922.       @sprites["boxparty"].setPokemon(selected[1],heldpokesprite)
  2923.     else
  2924.       @sprites["box"].setPokemon(selected[1],heldpokesprite)
  2925.     end
  2926.     @boxForMosaic = @storage.currentBox
  2927.     @selectionForMosaic = selected[1]
  2928.   end
  2929.  
  2930.   def pbWithdraw(selected,heldpoke,partyindex)
  2931.     pbHold(selected) if !heldpoke
  2932.     pbShowPartyTab
  2933.     pbPartySetArrow(@sprites["arrow"],partyindex)
  2934.     pbPlace([-1,partyindex],heldpoke)
  2935.     pbHidePartyTab
  2936.   end
  2937.  
  2938.   def pbStore(selected,heldpoke,destbox,firstfree)
  2939.     if heldpoke
  2940.       if destbox==@storage.currentBox
  2941.         heldpokesprite = @sprites["arrow"].heldPokemon
  2942.         @sprites["box"].setPokemon(firstfree,heldpokesprite)
  2943.         @sprites["arrow"].setSprite(nil)
  2944.       else
  2945.         @sprites["arrow"].deleteSprite
  2946.       end
  2947.     else
  2948.       sprite = @sprites["boxparty"].getPokemon(selected[1])
  2949.       if destbox==@storage.currentBox
  2950.         @sprites["box"].setPokemon(firstfree,sprite)
  2951.         @sprites["boxparty"].setPokemon(selected[1],nil)
  2952.       else
  2953.         @sprites["boxparty"].deletePokemon(selected[1])
  2954.       end
  2955.     end
  2956.   end
  2957.  
  2958.   def pbRelease(selected,heldpoke)
  2959.     box = selected[0]
  2960.     index = selected[1]
  2961.     if heldpoke
  2962.       sprite = @sprites["arrow"].heldPokemon
  2963.     elsif box==-1
  2964.       sprite = @sprites["boxparty"].getPokemon(index)
  2965.     else
  2966.       sprite = @sprites["box"].getPokemon(index)
  2967.     end
  2968.     if sprite
  2969.       sprite.release
  2970.       while sprite.releasing?
  2971.         Graphics.update
  2972.         sprite.update
  2973.         self.update
  2974.       end
  2975.     end
  2976.   end
  2977.  
  2978.   def pbChooseBox(msg)
  2979.     commands = []
  2980.     for i in 0...@storage.maxBoxes
  2981.       box = @storage[i]
  2982.       if box
  2983.         commands.push(_INTL("{1} ({2}/{3})",box.name,box.nitems,box.length))
  2984.       end
  2985.     end
  2986.     return pbShowCommands(msg,commands,@storage.currentBox)
  2987.   end
  2988.  
  2989.   def pbBoxName(helptext,minchars,maxchars)
  2990.     oldsprites = pbFadeOutAndHide(@sprites)
  2991.     ret = pbEnterBoxName(helptext,minchars,maxchars)
  2992.     if ret.length>0
  2993.       @storage[@storage.currentBox].name = ret
  2994.     end
  2995.     @sprites["box"].refreshBox = true
  2996.     pbRefresh
  2997.     pbFadeInAndShow(@sprites,oldsprites)
  2998.   end
  2999.  
  3000.   def pbChooseItem(bag)
  3001.     ret = 0
  3002.     pbFadeOutIn {
  3003.       scene = PokemonBag_Scene.new
  3004.       screen = PokemonBagScreen.new(scene,bag)
  3005.       ret = screen.pbChooseItemScreen(Proc.new { |item| pbCanHoldItem?(item) })
  3006.     }
  3007.     return ret
  3008.   end
  3009.  
  3010.   def pbSummary(selected,heldpoke)
  3011.     oldsprites = pbFadeOutAndHide(@sprites)
  3012.     scene = PokemonSummary_Scene.new
  3013.     screen = PokemonSummaryScreen.new(scene)
  3014.     if heldpoke
  3015.       screen.pbStartScreen([heldpoke],0)
  3016.     elsif selected[0]==-1
  3017.       @selection = screen.pbStartScreen(@storage.party,selected[1])
  3018.       pbPartySetArrow(@sprites["arrow"],@selection)
  3019.       pbUpdateOverlay(@selection,@storage.party)
  3020.     else
  3021.       @selection = screen.pbStartScreen(@storage.boxes[selected[0]],selected[1])
  3022.       pbSetArrow(@sprites["arrow"],@selection)
  3023.       pbUpdateOverlay(@selection)
  3024.     end
  3025.     pbFadeInAndShow(@sprites,oldsprites)
  3026.   end
  3027.  
  3028.   def pbMarkingSetArrow(arrow,selection)
  3029.     if selection>=0
  3030.       xvalues = [162,191,220,162,191,220,184,184]
  3031.       yvalues = [24,24,24,49,49,49,77,109]
  3032.       arrow.angle = 0
  3033.       arrow.mirror = false
  3034.       arrow.ox = 0
  3035.       arrow.oy = 0
  3036.       arrow.x = xvalues[selection]*2
  3037.       arrow.y = yvalues[selection]*2
  3038.     end
  3039.   end
  3040.  
  3041.   def pbMarkingChangeSelection(key,selection)
  3042.     case key
  3043.     when Input::LEFT
  3044.       if selection<6
  3045.         selection -= 1
  3046.         selection += 3 if selection%3==2
  3047.       end
  3048.     when Input::RIGHT
  3049.       if selection<6
  3050.         selection += 1
  3051.         selection -= 3 if selection%3==0
  3052.       end
  3053.     when Input::UP
  3054.       if selection==7; selection = 6
  3055.       elsif selection==6; selection = 4
  3056.       elsif selection<3; selection = 7
  3057.       else; selection -= 3
  3058.       end
  3059.     when Input::DOWN
  3060.       if selection==7; selection = 1
  3061.       elsif selection==6; selection = 7
  3062.       elsif selection>=3; selection = 6
  3063.       else; selection += 3
  3064.       end
  3065.     end
  3066.     return selection
  3067.   end
  3068.  
  3069.   def pbMark(selected,heldpoke)
  3070.     @sprites["markingbg"].visible      = true
  3071.     @sprites["markingoverlay"].visible = true
  3072.     msg = _INTL("Mark your Pokémon.")
  3073.     msgwindow = Window_UnformattedTextPokemon.newWithSize("",180,0,Graphics.width-180,32)
  3074.     msgwindow.viewport       = @viewport
  3075.     msgwindow.visible        = true
  3076.     msgwindow.letterbyletter = false
  3077.     msgwindow.text           = msg
  3078.     msgwindow.resizeHeightToFit(msg,Graphics.width-180)
  3079.     pbBottomRight(msgwindow)
  3080.     base   = Color.new(248,248,248)
  3081.     shadow = Color.new(80,80,80)
  3082.     pokemon = heldpoke
  3083.     if heldpoke
  3084.       pokemon = heldpoke
  3085.     elsif selected[0]==-1
  3086.       pokemon = @storage.party[selected[1]]
  3087.     else
  3088.       pokemon = @storage.boxes[selected[0]][selected[1]]
  3089.     end
  3090.     markings = pokemon.markings
  3091.     index = 0
  3092.     redraw = true
  3093.     markrect = Rect.new(0,0,16,16)
  3094.     loop do
  3095.       # Redraw the markings and text
  3096.       if redraw
  3097.         @sprites["markingoverlay"].bitmap.clear
  3098.         for i in 0...6
  3099.           markrect.x = i*16
  3100.           markrect.y = (markings&(1<<i)!=0) ? 16 : 0
  3101.           @sprites["markingoverlay"].bitmap.blt(336+58*(i%3),106+50*(i/3),@markingbitmap.bitmap,markrect)
  3102.         end
  3103.         textpos = [
  3104.            [_INTL("OK"),402,210,2,base,shadow,1],
  3105.            [_INTL("Cancel"),402,274,2,base,shadow,1]
  3106.         ]
  3107.         pbDrawTextPositions(@sprites["markingoverlay"].bitmap,textpos)
  3108.         pbMarkingSetArrow(@sprites["arrow"],index)
  3109.         redraw = false
  3110.       end
  3111.       Graphics.update
  3112.       Input.update
  3113.       key = -1
  3114.       key = Input::DOWN if Input.repeat?(Input::DOWN)
  3115.       key = Input::RIGHT if Input.repeat?(Input::RIGHT)
  3116.       key = Input::LEFT if Input.repeat?(Input::LEFT)
  3117.       key = Input::UP if Input.repeat?(Input::UP)
  3118.       if key>=0
  3119.         oldindex = index
  3120.         index = pbMarkingChangeSelection(key,index)
  3121.         pbPlayCursorSE if index!=oldindex
  3122.         pbMarkingSetArrow(@sprites["arrow"],index)
  3123.       end
  3124.       self.update
  3125.       if Input.trigger?(Input::B)
  3126.         pbPlayCancelSE
  3127.         break
  3128.       elsif Input.trigger?(Input::C)
  3129.         pbPlayDecisionSE
  3130.         if index==6   # OK
  3131.           pokemon.markings = markings
  3132.           break
  3133.         elsif index==7   # Cancel
  3134.           break
  3135.         else
  3136.           mask = (1<<index)
  3137.           if (markings&mask)==0
  3138.             markings |= mask
  3139.           else
  3140.             markings &= ~mask
  3141.           end
  3142.           redraw = true
  3143.         end
  3144.       end
  3145.     end
  3146.     @sprites["markingbg"].visible      = false
  3147.     @sprites["markingoverlay"].visible = false
  3148.     msgwindow.dispose
  3149.   end
  3150.  
  3151.   def pbRefresh
  3152.     @sprites["box"].refresh
  3153.     @sprites["boxparty"].refresh
  3154.   end
  3155.  
  3156.   def pbHardRefresh
  3157.     oldPartyY = @sprites["boxparty"].y
  3158.     @sprites["box"].dispose
  3159.     @sprites["box"] = PokemonBoxSprite.new(@storage,@storage.currentBox,@boxviewport)
  3160.     @sprites["boxparty"].dispose
  3161.     @sprites["boxparty"] = PokemonBoxPartySprite.new(@storage.party,@boxsidesviewport)
  3162.     @sprites["boxparty"].y = oldPartyY
  3163.   end
  3164.  
  3165.   def drawMarkings(bitmap,x,y,_width,_height,markings)
  3166.     markrect = Rect.new(0,0,16,16)
  3167.     for i in 0...8
  3168.       markrect.x = i*16
  3169.       markrect.y = (markings&(1<<i)!=0) ? 16 : 0
  3170.       bitmap.blt(x+i*16,y,@markingbitmap.bitmap,markrect)
  3171.     end
  3172.   end
  3173.  
  3174.   def pbUpdateOverlay(selection,party=nil)
  3175.     overlay = @sprites["overlay"].bitmap
  3176.     overlay.clear
  3177.     buttonbase = Color.new(248,248,248)
  3178.     buttonshadow = Color.new(80,80,80)
  3179.     pbDrawTextPositions(overlay,[
  3180.        [_INTL("Party: {1}",(@storage.party.length rescue 0)),270,328,2,buttonbase,buttonshadow,1],
  3181.        [_INTL("Exit"),446,328,2,buttonbase,buttonshadow,1],
  3182.     ])
  3183.     pokemon = nil
  3184.     if @screen.pbHeldPokemon
  3185.       pokemon = @screen.pbHeldPokemon
  3186.     elsif selection>=0
  3187.       pokemon = (party) ? party[selection] : @storage[@storage.currentBox,selection]
  3188.     end
  3189.     if !pokemon
  3190.       @sprites["pokemon"].visible = false
  3191.       return
  3192.     end
  3193.     @sprites["pokemon"].visible = true
  3194.     base   = Color.new(88,88,80)
  3195.     shadow = Color.new(168,184,184)
  3196.     nonbase   = Color.new(208,208,208)
  3197.     nonshadow = Color.new(224,224,224)
  3198.     pokename = pokemon.name
  3199.     textstrings = [
  3200.        [pokename,10,8,false,base,shadow]
  3201.     ]
  3202.     if !pokemon.egg?
  3203.       imagepos = []
  3204.       if pokemon.male?
  3205.         textstrings.push([_INTL("♂"),148,8,false,Color.new(24,112,216),Color.new(136,168,208)])
  3206.       elsif pokemon.female?
  3207.         textstrings.push([_INTL("♀"),148,8,false,Color.new(248,56,32),Color.new(224,152,144)])
  3208.       end
  3209.       imagepos.push(["Graphics/Pictures/Storage/overlay_lv",6,246])
  3210.       textstrings.push([pokemon.level.to_s,28,234,false,base,shadow])
  3211.       if pokemon.ability>0
  3212.         textstrings.push([PBAbilities.getName(pokemon.ability),86,306,2,base,shadow])
  3213.       else
  3214.         textstrings.push([_INTL("No ability"),86,306,2,nonbase,nonshadow])
  3215.       end
  3216.       if pokemon.item>0
  3217.         textstrings.push([PBItems.getName(pokemon.item),86,342,2,base,shadow])
  3218.       else
  3219.         textstrings.push([_INTL("No item"),86,342,2,nonbase,nonshadow])
  3220.       end
  3221.       if pokemon.shiny?
  3222.         imagepos.push(["Graphics/Pictures/shiny",156,198])
  3223.       end
  3224.       typebitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/types"))
  3225.       type1rect = Rect.new(0,pokemon.type1*28,64,28)
  3226.       type2rect = Rect.new(0,pokemon.type2*28,64,28)
  3227.       if pokemon.type1==pokemon.type2
  3228.         overlay.blt(52,272,typebitmap.bitmap,type1rect)
  3229.       else
  3230.         overlay.blt(18,272,typebitmap.bitmap,type1rect)
  3231.         overlay.blt(88,272,typebitmap.bitmap,type2rect)
  3232.       end
  3233.       drawMarkings(overlay,70,240,128,20,pokemon.markings)
  3234.       pbDrawImagePositions(overlay,imagepos)
  3235.     end
  3236.     pbDrawTextPositions(overlay,textstrings)
  3237.     @sprites["pokemon"].setPokemonBitmap(pokemon)
  3238.   end
  3239.  
  3240.   def update
  3241.     pbUpdateSpriteHash(@sprites)
  3242.   end
  3243. end
  3244. #===============================================================================
  3245. # Pokémon storage mechanics
  3246. #===============================================================================
  3247. class PokemonStorageScreen
  3248.   def pbWithdraw(selected,heldpoke)
  3249.     if $Trainer.partyplus>=1
  3250.     plus = $Trainer.partyplus
  3251.     else
  3252.     plus = 6
  3253.     end
  3254.     box = selected[0]
  3255.     index = selected[1]
  3256.     if box==-1
  3257.       raise _INTL("Can't withdraw from party...");
  3258.     end
  3259.     if @storage.party.nitems>=plus
  3260.       pbDisplay(_INTL("Your party's full!"))
  3261.       return false
  3262.     end
  3263.     @scene.pbWithdraw(selected,heldpoke,@storage.party.length)
  3264.     if heldpoke
  3265.       @storage.pbMoveCaughtToParty(heldpoke)
  3266.       @heldpkmn = nil
  3267.     else
  3268.       @storage.pbMove(-1,-1,box,index)
  3269.     end
  3270.     @scene.pbRefresh
  3271.     return true
  3272.   end
  3273. end
  3274. #------------------------------------------------------------------------------#
  3275. # PScreen_Evolution
  3276. #------------------------------------------------------------------------------#
  3277. #===============================================================================
  3278. # Evolution screen
  3279. #===============================================================================
  3280. class PokemonEvolutionScene
  3281.   private
  3282.   def pbGenerateMetafiles(s1x,s1y,s2x,s2y)
  3283.     sprite  = SpriteMetafile.new
  3284.     sprite.ox      = s1x
  3285.     sprite.oy      = s1y
  3286.     sprite.opacity = 255
  3287.     sprite2 = SpriteMetafile.new
  3288.     sprite2.ox      = s2x
  3289.     sprite2.oy      = s2y
  3290.     sprite2.zoom    = 0.0
  3291.     sprite2.opacity = 255
  3292.     alpha = 0
  3293.     alphaDiff = 10*20/Graphics.frame_rate
  3294.     loop do
  3295.       sprite.color.red   = 255
  3296.       sprite.color.green = 255
  3297.       sprite.color.blue  = 255
  3298.       sprite.color.alpha = alpha
  3299.       sprite.color  = sprite.color
  3300.       sprite2.color = sprite.color
  3301.       sprite2.color.alpha = 255
  3302.       sprite.update
  3303.       sprite2.update
  3304.       break if alpha>=255
  3305.       alpha += alphaDiff
  3306.     end
  3307.     totaltempo   = 0
  3308.     currenttempo = 25
  3309.     maxtempo = 7*Graphics.frame_rate
  3310.     while totaltempo<maxtempo
  3311.       for j in 0...currenttempo
  3312.         if alpha<255
  3313.           sprite.color.red   = 255
  3314.           sprite.color.green = 255
  3315.           sprite.color.blue  = 255
  3316.           sprite.color.alpha = alpha
  3317.           sprite.color = sprite.color
  3318.           alpha += 10
  3319.         end
  3320.         sprite.zoom  = [1.1*(currenttempo-j-1)/currenttempo,1.0].min
  3321.         sprite2.zoom = [1.1*(j+1)/currenttempo,1.0].min
  3322.         sprite.update
  3323.         sprite2.update
  3324.       end
  3325.       totaltempo += currenttempo
  3326.       if totaltempo+currenttempo<maxtempo
  3327.         for j in 0...currenttempo
  3328.           sprite.zoom  = [1.1*(j+1)/currenttempo,1.0].min
  3329.           sprite2.zoom = [1.1*(currenttempo-j-1)/currenttempo,1.0].min
  3330.           sprite.update
  3331.           sprite2.update
  3332.         end
  3333.       end
  3334.       totaltempo += currenttempo
  3335.       currenttempo = [(currenttempo/1.5).floor,5].max
  3336.     end
  3337.     @metafile1 = sprite
  3338.     @metafile2 = sprite2
  3339.   end
  3340.   public
  3341.   def pbUpdate(animating=false)
  3342.     if animating      # Pokémon shouldn't animate during the evolution animation
  3343.       @sprites["background"].update
  3344.     else
  3345.       pbUpdateSpriteHash(@sprites)
  3346.     end
  3347.   end
  3348.   def pbUpdateNarrowScreen
  3349.     halfResizeDiff = 8*20/Graphics.frame_rate
  3350.     if @bgviewport.rect.y<80
  3351.       @bgviewport.rect.height -= halfResizeDiff*2
  3352.       if @bgviewport.rect.height<Graphics.height-64
  3353.         @bgviewport.rect.y += halfResizeDiff
  3354.         @sprites["background"].oy = @bgviewport.rect.y
  3355.       end
  3356.     end
  3357.   end
  3358.   def pbUpdateExpandScreen
  3359.     halfResizeDiff = 8*20/Graphics.frame_rate
  3360.     if @bgviewport.rect.y>0
  3361.       @bgviewport.rect.y -= halfResizeDiff
  3362.       @sprites["background"].oy = @bgviewport.rect.y
  3363.     end
  3364.     if @bgviewport.rect.height<Graphics.height
  3365.       @bgviewport.rect.height += halfResizeDiff*2
  3366.     end
  3367.   end
  3368.   def pbFlashInOut(canceled,oldstate,oldstate2)
  3369.     tone = 0
  3370.     toneDiff = 20*20/Graphics.frame_rate
  3371.     loop do
  3372.       Graphics.update
  3373.       pbUpdate(true)
  3374.       pbUpdateExpandScreen
  3375.       tone += toneDiff
  3376.       @viewport.tone.set(tone,tone,tone,0)
  3377.       break if tone>=255
  3378.     end
  3379.     @bgviewport.rect.y      = 0
  3380.     @bgviewport.rect.height = Graphics.height
  3381.     @sprites["background"].oy = 0
  3382.     if canceled
  3383.       pbRestoreSpriteState(@sprites["rsprite1"],oldstate)
  3384.       pbRestoreSpriteState(@sprites["rsprite2"],oldstate2)
  3385.       @sprites["rsprite1"].zoom_x      = 1.0
  3386.       @sprites["rsprite1"].zoom_y      = 1.0
  3387.       @sprites["rsprite1"].color.alpha = 0
  3388.       @sprites["rsprite1"].visible     = true
  3389.       @sprites["rsprite2"].visible     = false
  3390.     else
  3391.       @sprites["rsprite1"].visible     = false
  3392.       @sprites["rsprite2"].visible     = true
  3393.       @sprites["rsprite2"].zoom_x      = 1.0
  3394.       @sprites["rsprite2"].zoom_y      = 1.0
  3395.       @sprites["rsprite2"].color.alpha = 0
  3396.     end
  3397.     (Graphics.frame_rate/4).times do
  3398.       Graphics.update
  3399.       pbUpdate(true)
  3400.     end
  3401.     tone = 255
  3402.     toneDiff = 40*20/Graphics.frame_rate
  3403.     loop do
  3404.       Graphics.update
  3405.       pbUpdate
  3406.       tone -= toneDiff
  3407.       @viewport.tone.set(tone,tone,tone,0)
  3408.       break if tone<=0
  3409.     end
  3410.   end
  3411.   def pbStartScreen(pokemon,newspecies)
  3412.     @pokemon = pokemon
  3413.     @newspecies = newspecies
  3414.     @sprites = {}
  3415.     @bgviewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  3416.     @bgviewport.z = 99999
  3417.     @viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  3418.     @viewport.z = 99999
  3419.     @msgviewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  3420.     @msgviewport.z = 99999
  3421.     addBackgroundOrColoredPlane(@sprites,"background","evolutionbg",
  3422.        Color.new(248,248,248),@bgviewport)
  3423.     rsprite1 = PokemonSprite.new(@viewport)
  3424.     rsprite1.setOffset(PictureOrigin::Center)
  3425.     rsprite1.setPokemonBitmap(@pokemon,false)
  3426.     rsprite1.x = Graphics.width/2
  3427.     rsprite1.y = (Graphics.height-64)/2
  3428.     rsprite2 = PokemonSprite.new(@viewport)
  3429.     rsprite2.setOffset(PictureOrigin::Center)
  3430.     rsprite2.setPokemonBitmapSpecies(@pokemon,@newspecies,false)
  3431.     rsprite2.x       = rsprite1.x
  3432.     rsprite2.y       = rsprite1.y
  3433.     rsprite2.opacity = 0
  3434.     @sprites["rsprite1"] = rsprite1
  3435.     @sprites["rsprite2"] = rsprite2
  3436.     pbGenerateMetafiles(rsprite1.ox,rsprite1.oy,rsprite2.ox,rsprite2.oy)
  3437.     @sprites["msgwindow"] = pbCreateMessageWindow(@msgviewport)
  3438.     pbFadeInAndShow(@sprites) { pbUpdate }
  3439.   end
  3440.   # Closes the evolution screen.
  3441.   def pbEndScreen
  3442.     pbDisposeMessageWindow(@sprites["msgwindow"])
  3443.     pbFadeOutAndHide(@sprites) { pbUpdate }
  3444.     pbDisposeSpriteHash(@sprites)
  3445.     @viewport.dispose
  3446.     @bgviewport.dispose
  3447.     @msgviewport.dispose
  3448.   end
  3449.   # Opens the evolution screen
  3450.   def pbEvolution(cancancel=true)
  3451.     metaplayer1 = SpriteMetafilePlayer.new(@metafile1,@sprites["rsprite1"])
  3452.     metaplayer2 = SpriteMetafilePlayer.new(@metafile2,@sprites["rsprite2"])
  3453.     metaplayer1.play
  3454.     metaplayer2.play
  3455.     pbBGMStop
  3456.     pbPlayCry(@pokemon)
  3457.     pbMessageDisplay(@sprites["msgwindow"],
  3458.        _INTL("\\se[]What? {1} is evolving!\\^",@pokemon.name)) { pbUpdate }
  3459.     pbMessageWaitForInput(@sprites["msgwindow"],50,true) { pbUpdate }
  3460.     pbPlayDecisionSE
  3461.     oldstate  = pbSaveSpriteState(@sprites["rsprite1"])
  3462.     oldstate2 = pbSaveSpriteState(@sprites["rsprite2"])
  3463.     pbMEPlay("Evolution start")
  3464.     pbBGMPlay("Evolution")
  3465.     canceled = false
  3466.     begin
  3467.       pbUpdateNarrowScreen
  3468.       metaplayer1.update
  3469.       metaplayer2.update
  3470.       Graphics.update
  3471.       Input.update
  3472.       pbUpdate(true)
  3473.       if Input.trigger?(Input::B) && cancancel
  3474.         pbBGMStop
  3475.         pbPlayCancelSE
  3476.         canceled = true
  3477.         break
  3478.       end
  3479.     end while metaplayer1.playing? && metaplayer2.playing?
  3480.     pbFlashInOut(canceled,oldstate,oldstate2)
  3481.     if canceled
  3482.       pbMessageDisplay(@sprites["msgwindow"],
  3483.          _INTL("Huh? {1} stopped evolving!",@pokemon.name)) { pbUpdate }
  3484.     else
  3485.       pbEvolutionSuccess
  3486.     end
  3487.   end
  3488.   def pbEvolutionSuccess
  3489.     # Play cry of evolved species
  3490.     frames = pbCryFrameLength(@newspecies,@pokemon.form)
  3491.     pbBGMStop
  3492.     pbPlayCrySpecies(@newspecies,@pokemon.form)
  3493.     frames.times do
  3494.       Graphics.update
  3495.       pbUpdate
  3496.     end
  3497.     # Success jingle/message
  3498.     pbMEPlay("Evolution success")
  3499.     newspeciesname = PBSpecies.getName(@newspecies)
  3500.     oldspeciesname = PBSpecies.getName(@pokemon.species)
  3501.     pbMessageDisplay(@sprites["msgwindow"],
  3502.        _INTL("\\se[]Congratulations! Your {1} evolved into {2}!\\wt[80]",
  3503.        @pokemon.name,newspeciesname)) { pbUpdate }
  3504.     @sprites["msgwindow"].text = ""
  3505.     # Check for consumed item and check if Pokémon should be duplicated
  3506.     createSpecies = pbRemoveItemAfterEvolution
  3507.     # Modify Pokémon to make it evolved
  3508.     @pokemon.species = @newspecies
  3509.     @pokemon.name    = newspeciesname if @pokemon.name==oldspeciesname
  3510.     @pokemon.form    = 0 if isConst?(@pokemon.species,PBSpecies,:MOTHIM)
  3511.     @pokemon.calcStats
  3512.     # See and own evolved species
  3513.     $Trainer.seen[@newspecies]  = true
  3514.     $Trainer.owned[@newspecies] = true
  3515.     pbSeenForm(@pokemon)
  3516.     # Learn moves upon evolution for evolved species
  3517.     movelist = @pokemon.getMoveList
  3518.     for i in movelist
  3519.       next if i[0]!=0 && i[0]!=@pokemon.level   # 0 is "learn upon evolution"
  3520.       pbLearnMove(@pokemon,i[1],true) { pbUpdate }
  3521.     end
  3522.     # Duplicate Pokémon (i.e. Shedinja)
  3523. if $Trainer.partyplus>=1
  3524.     if createSpecies>0 && $Trainer.party.length<$Trainer.partyplus
  3525.       pbDuplicatePokemon(createSpecies)
  3526.       # Consume Poké Ball
  3527.       $PokemonBag.pbDeleteItem(getConst(PBItems,:POKEBALL))
  3528.     end
  3529. else
  3530.     if createSpecies>0 && $Trainer.party.length<6
  3531.       pbDuplicatePokemon(createSpecies)
  3532.       # Consume Poké Ball
  3533.       $PokemonBag.pbDeleteItem(getConst(PBItems,:POKEBALL))
  3534.     end
  3535. end
  3536.   end
  3537.   def pbRemoveItemAfterEvolution
  3538.     removeItem = false
  3539.     createSpecies = pbCheckEvolutionEx(@pokemon) { |pokemon,evonib,level,pkmn|
  3540.       case evonib
  3541.       when PBEvolution::Shedinja
  3542.         next pkmn if $PokemonBag.pbHasItem?(getConst(PBItems,:POKEBALL))
  3543.       when PBEvolution::TradeItem,PBEvolution::DayHoldItem,PBEvolution::NightHoldItem
  3544.         removeItem = true if pkmn==@newspecies   # Item is now consumed
  3545.       end
  3546.       next -1
  3547.     }
  3548.     @pokemon.setItem(0) if removeItem
  3549.     return createSpecies
  3550.   end
  3551.   def pbDuplicatePokemon(createSpecies)
  3552.     newpokemon = @pokemon.clone
  3553.     newpokemon.species = createSpecies
  3554.     newpokemon.name    = PBSpecies.getName(createSpecies)
  3555.     newpokemon.iv      = @pokemon.iv.clone
  3556.     newpokemon.ev      = @pokemon.ev.clone
  3557.     newpokemon.markings = 0
  3558.     newpokemon.ballused = 0
  3559.     newpokemon.setItem(0)
  3560.     newpokemon.clearAllRibbons
  3561.     newpokemon.calcStats
  3562.     newpokemon.heal
  3563.     # Add duplicate Pokémon to party
  3564.     $Trainer.party.push(newpokemon)
  3565.     # See and own duplicate Pokémon
  3566.     $Trainer.seen[createSpecies]  = true
  3567.     $Trainer.owned[createSpecies] = true
  3568.     pbSeenForm(newpokemon)
  3569.   end
  3570. end
  3571. #------------------------------------------------------------------------------#
  3572. # PBattle_OrgBattle
  3573. #------------------------------------------------------------------------------#
  3574. def pbBattleFactoryPokemon(rule,numwins,numswaps,rentals)
  3575.   table=nil
  3576.   btpokemon=pbGetBTPokemon(pbBattleChallenge.currentChallenge)
  3577.   ivtable=[
  3578.      0,6,3,6,
  3579.      7,13,6,9,
  3580.      14,20,9,12,
  3581.      21,27,12,15,
  3582.      28,34,15,21,
  3583.      35,41,21,31,
  3584.      42,-1,31,31
  3585.   ]
  3586.   groups=[
  3587.      1,14,6,0,
  3588.      15,21,5,1,
  3589.      22,28,4,2,
  3590.      29,35,3,3,
  3591.      36,42,2,4,
  3592.      43,-1,1,5
  3593.   ]
  3594.   if rule.ruleset.suggestedLevel!=100
  3595.     table=[
  3596.        0,6,110,199,
  3597.        7,13,162,266,
  3598.        14,20,267,371,
  3599.        21,27,372,467,
  3600.        28,34,468,563,
  3601.        35,41,564,659,
  3602.        42,48,660,755,
  3603.        49,-1,372,849
  3604.     ]
  3605.   else # Open Level (Level 100)
  3606.     table=[
  3607.        0,6,372,467,
  3608.        7,13,468,563,
  3609.        14,20,564,659,
  3610.        21,27,660,755,
  3611.        28,34,372,881,
  3612.        35,41,372,881,
  3613.        42,48,372,881,
  3614.        49,-1,372,881
  3615.     ]
  3616.   end
  3617.   pokemonNumbers=[0,0]
  3618.   ivs=[0,0]
  3619.   ivgroups=[6,0]
  3620.   for i in 0...table.length/4
  3621.     if table[i*4]<=numwins
  3622.       if (table[i*4+1]<0 || table[i*4+1]>=numwins)
  3623.         pokemonNumbers=[
  3624.            table[i*4+2]*btpokemon.length/882,
  3625.              table[i*4+3]*btpokemon.length/882
  3626.           ]
  3627.       end
  3628.     end
  3629.   end
  3630.   for i in 0...ivtable.length/4
  3631.     if ivtable[i*4]<=numwins
  3632.       if (ivtable[i*4+1]<0 || ivtable[i*4+1]>=numwins)
  3633.         ivs=[ivtable[i*4+2],ivtable[i*4+3]]
  3634.       end
  3635.     end
  3636.   end
  3637.   for i in 0...groups.length/4
  3638.     if groups[i*4]<=numswaps
  3639.       if (groups[i*4+1]<0 || groups[i*4+1]>=numswaps)
  3640.         ivgroups=[groups[i*4+2],groups[i*4+3]]
  3641.       end
  3642.     end
  3643.   end
  3644.   party=[]
  3645. if $Trainer.partyplus>=1
  3646.   begin
  3647.     party.clear
  3648.     while party.length<$Trainer.partyplus
  3649.       rnd=pokemonNumbers[0]+rand(pokemonNumbers[1]-pokemonNumbers[0]+1)
  3650.       rndpoke=btpokemon[rnd]
  3651.       indvalue=(party.length<ivgroups[0]) ? ivs[0] : ivs[1]
  3652.       party.push(rndpoke.createPokemon(rule.ruleset.suggestedLevel,indvalue,nil))
  3653.     end
  3654.   end until rule.ruleset.isValid?(party)
  3655. else
  3656.   begin
  3657.     party.clear
  3658.     while party.length<6
  3659.       rnd=pokemonNumbers[0]+rand(pokemonNumbers[1]-pokemonNumbers[0]+1)
  3660.       rndpoke=btpokemon[rnd]
  3661.       indvalue=(party.length<ivgroups[0]) ? ivs[0] : ivs[1]
  3662.       party.push(rndpoke.createPokemon(rule.ruleset.suggestedLevel,indvalue,nil))
  3663.     end
  3664.   end until rule.ruleset.isValid?(party)
  3665. end
  3666.   return party
  3667. end
  3668. #------------------------------------------------------------------------------#
  3669. # PSystem_PokemonUtilities
  3670. #------------------------------------------------------------------------------#
  3671. #===============================================================================
  3672. # Nicknaming and storing Pokémon
  3673. #===============================================================================
  3674. def pbBoxesFull?
  3675.  if $Trainer.partyplus>=1
  3676.   return ($Trainer.party.length==$Trainer.partyplus && $PokemonStorage.full?)
  3677.  else
  3678.   return ($Trainer.party.length==6 && $PokemonStorage.full?)
  3679.  end
  3680. end
  3681. def pbStorePokemon(pokemon)
  3682.   if pbBoxesFull?
  3683.     pbMessage(_INTL("There's no more room for Pokémon!\1"))
  3684.     pbMessage(_INTL("The Pokémon Boxes are full and can't accept any more!"))
  3685.     return
  3686.   end
  3687.   pokemon.pbRecordFirstMoves
  3688. if $Trainer.partyplus>=1
  3689.   if $Trainer.party.length<$Trainer.partyplus
  3690.     $Trainer.party[$Trainer.party.length] = pokemon
  3691.   else
  3692.     oldcurbox = $PokemonStorage.currentBox
  3693.     storedbox = $PokemonStorage.pbStoreCaught(pokemon)
  3694.     curboxname = $PokemonStorage[oldcurbox].name
  3695.     boxname = $PokemonStorage[storedbox].name
  3696.     creator = nil
  3697.     creator = pbGetStorageCreator if $PokemonGlobal.seenStorageCreator
  3698.     if storedbox!=oldcurbox
  3699.       if creator
  3700.         pbMessage(_INTL("Box \"{1}\" on {2}'s PC was full.\1",curboxname,creator))
  3701.       else
  3702.         pbMessage(_INTL("Box \"{1}\" on someone's PC was full.\1",curboxname))
  3703.       end
  3704.       pbMessage(_INTL("{1} was transferred to box \"{2}.\"",pokemon.name,boxname))
  3705.     else
  3706.       if creator
  3707.         pbMessage(_INTL("{1} was transferred to {2}'s PC.\1",pokemon.name,creator))
  3708.       else
  3709.         pbMessage(_INTL("{1} was transferred to someone's PC.\1",pokemon.name))
  3710.       end
  3711.       pbMessage(_INTL("It was stored in box \"{1}.\"",boxname))
  3712.     end
  3713.   end
  3714. else
  3715.   if $Trainer.party.length<6
  3716.     $Trainer.party[$Trainer.party.length] = pokemon
  3717.   else
  3718.     oldcurbox = $PokemonStorage.currentBox
  3719.     storedbox = $PokemonStorage.pbStoreCaught(pokemon)
  3720.     curboxname = $PokemonStorage[oldcurbox].name
  3721.     boxname = $PokemonStorage[storedbox].name
  3722.     creator = nil
  3723.     creator = pbGetStorageCreator if $PokemonGlobal.seenStorageCreator
  3724.     if storedbox!=oldcurbox
  3725.       if creator
  3726.         pbMessage(_INTL("Box \"{1}\" on {2}'s PC was full.\1",curboxname,creator))
  3727.       else
  3728.         pbMessage(_INTL("Box \"{1}\" on someone's PC was full.\1",curboxname))
  3729.       end
  3730.       pbMessage(_INTL("{1} was transferred to box \"{2}.\"",pokemon.name,boxname))
  3731.     else
  3732.       if creator
  3733.         pbMessage(_INTL("{1} was transferred to {2}'s PC.\1",pokemon.name,creator))
  3734.       else
  3735.         pbMessage(_INTL("{1} was transferred to someone's PC.\1",pokemon.name))
  3736.       end
  3737.       pbMessage(_INTL("It was stored in box \"{1}.\"",boxname))
  3738.     end
  3739.   end
  3740. end
  3741. end
  3742. #===============================================================================
  3743. # Giving Pokémon to the player (will send to storage if party is full)
  3744. #===============================================================================
  3745. def pbAddPokemonSilent(pokemon,level=nil,seeform=true)
  3746.   return false if !pokemon || pbBoxesFull?
  3747.   pokemon = getID(PBSpecies,pokemon)
  3748.   if pokemon.is_a?(Integer) && level.is_a?(Integer)
  3749.     pokemon = pbNewPkmn(pokemon,level)
  3750.   end
  3751.   $Trainer.seen[pokemon.species]  = true
  3752.   $Trainer.owned[pokemon.species] = true
  3753.   pbSeenForm(pokemon) if seeform
  3754.   pokemon.pbRecordFirstMoves
  3755. if $Trainer.partyplus>=1
  3756.   if $Trainer.party.length<$Trainer.partyplus
  3757.     $Trainer.party[$Trainer.party.length] = pokemon
  3758.   else
  3759.     $PokemonStorage.pbStoreCaught(pokemon)
  3760.   end
  3761. else
  3762.   if $Trainer.party.length<6
  3763.     $Trainer.party[$Trainer.party.length] = pokemon
  3764.   else
  3765.     $PokemonStorage.pbStoreCaught(pokemon)
  3766.   end
  3767. end
  3768.   return true
  3769. end
  3770. #===============================================================================
  3771. # Giving Pokémon/eggs to the player (can only add to party)
  3772. #===============================================================================
  3773. def pbAddToParty(pokemon,level=nil,seeform=true)
  3774.   if $Trainer.partyplus>=1
  3775.   return false if !pokemon || $Trainer.party.length>=$Trainer.partyplus
  3776.   else
  3777.   return false if !pokemon || $Trainer.party.length>=6
  3778.   end
  3779.   pokemon = getID(PBSpecies,pokemon)
  3780.   if pokemon.is_a?(Integer) && level.is_a?(Integer)
  3781.     pokemon = pbNewPkmn(pokemon,level)
  3782.   end
  3783.   speciesname = PBSpecies.getName(pokemon.species)
  3784.   pbMessage(_INTL("\\me[Pkmn get]{1} obtained {2}!\1",$Trainer.name,speciesname))
  3785.   pbNicknameAndStore(pokemon)
  3786.   pbSeenForm(pokemon) if seeform
  3787.   return true
  3788. end
  3789. def pbAddToPartySilent(pokemon,level=nil,seeform=true)
  3790.   if $Trainer.partyplus>=1
  3791.   return false if !pokemon || $Trainer.party.length>=$Trainer.partyplus
  3792.   else
  3793.   return false if !pokemon || $Trainer.party.length>=6
  3794.   end
  3795.   pokemon = getID(PBSpecies,pokemon)
  3796.   if pokemon.is_a?(Integer) && level.is_a?(Integer)
  3797.     pokemon = pbNewPkmn(pokemon,level)
  3798.   end
  3799.   $Trainer.seen[pokemon.species]  = true
  3800.   $Trainer.owned[pokemon.species] = true
  3801.   pbSeenForm(pokemon) if seeform
  3802.   pokemon.pbRecordFirstMoves
  3803.   $Trainer.party[$Trainer.party.length] = pokemon
  3804.   return true
  3805. end
  3806. def pbAddForeignPokemon(pokemon,level=nil,ownerName=nil,nickname=nil,ownerGender=0,seeform=true)
  3807.   if $Trainer.partyplus>=1
  3808.   return false if !pokemon || $Trainer.party.length>=$Trainer.partyplus
  3809.   else
  3810.   return false if !pokemon || $Trainer.party.length>=6
  3811.   end
  3812.   pokemon = getID(PBSpecies,pokemon)
  3813.   if pokemon.is_a?(Integer) && level.is_a?(Integer)
  3814.     pokemon = pbNewPkmn(pokemon,level)
  3815.   end
  3816.   # Set original trainer to a foreign one (if ID isn't already foreign)
  3817.   if pokemon.trainerID==$Trainer.id
  3818.     pokemon.trainerID = $Trainer.getForeignID
  3819.     pokemon.ot        = ownerName if ownerName && ownerName!=""
  3820.     pokemon.otgender  = ownerGender
  3821.   end
  3822.   # Set nickname
  3823.   pokemon.name = nickname[0,PokeBattle_Pokemon::MAX_POKEMON_NAME_SIZE] if nickname && nickname!=""
  3824.   # Recalculate stats
  3825.   pokemon.calcStats
  3826.   if ownerName
  3827.     pbMessage(_INTL("\\me[Pkmn get]{1} received a Pokémon from {2}.\1",$Trainer.name,ownerName))
  3828.   else
  3829.     pbMessage(_INTL("\\me[Pkmn get]{1} received a Pokémon.\1",$Trainer.name))
  3830.   end
  3831.   pbStorePokemon(pokemon)
  3832.   $Trainer.seen[pokemon.species]  = true
  3833.   $Trainer.owned[pokemon.species] = true
  3834.   pbSeenForm(pokemon) if seeform
  3835.   return true
  3836. end
  3837. def pbGenerateEgg(pokemon,text="")
  3838.   if $Trainer.partyplus>=1
  3839.   return false if !pokemon || $Trainer.party.length>=$Trainer.partyplus
  3840.   else
  3841.   return false if !pokemon || $Trainer.party.length>=6
  3842.   end
  3843.   pokemon = getID(PBSpecies,pokemon)
  3844.   if pokemon.is_a?(Integer)
  3845.     pokemon = pbNewPkmn(pokemon,EGG_LEVEL)
  3846.   end
  3847.   # Get egg steps
  3848.   eggSteps = pbGetSpeciesData(pokemon.species,pokemon.form,SpeciesStepsToHatch)
  3849.   # Set egg's details
  3850.   pokemon.name       = _INTL("Egg")
  3851.   pokemon.eggsteps   = eggSteps
  3852.   pokemon.obtainText = text
  3853.   pokemon.calcStats
  3854.   # Add egg to party
  3855.   $Trainer.party[$Trainer.party.length] = pokemon
  3856.   return true
  3857. end
  3858. #------------------------------------------------------------------------------#
  3859. # PSystem_Utilities
  3860. #------------------------------------------------------------------------------#
  3861. def pbMoveTutorAnnotations(move,movelist=nil)
  3862.   ret = []
  3863.   if $Trainer.partyplus>=1
  3864.   for i in 0...$Trainer.partyplus
  3865.     ret[i] = nil
  3866.     next if i>=$Trainer.party.length
  3867.     found = false
  3868.     for j in 0...4
  3869.       if !$Trainer.party[i].egg? && $Trainer.party[i].moves[j].id==move
  3870.         ret[i] = _INTL("LEARNED")
  3871.         found = true
  3872.       end
  3873.     end
  3874.     next if found
  3875.     species = $Trainer.party[i].species
  3876.     if !$Trainer.party[i].egg? && movelist && movelist.any? { |j| j==species }
  3877.       # Checked data from movelist
  3878.       ret[i] = _INTL("ABLE")
  3879.     elsif !$Trainer.party[i].egg? && $Trainer.party[i].compatibleWithMove?(move)
  3880.       # Checked data from PBS/tm.txt
  3881.       ret[i] = _INTL("ABLE")
  3882.     else
  3883.       ret[i] = _INTL("NOT ABLE")
  3884.     end
  3885.   end
  3886.   else
  3887.   for i in 0...6
  3888.     ret[i] = nil
  3889.     next if i>=$Trainer.party.length
  3890.     found = false
  3891.     for j in 0...4
  3892.       if !$Trainer.party[i].egg? && $Trainer.party[i].moves[j].id==move
  3893.         ret[i] = _INTL("LEARNED")
  3894.         found = true
  3895.       end
  3896.     end
  3897.     next if found
  3898.     species = $Trainer.party[i].species
  3899.     if !$Trainer.party[i].egg? && movelist && movelist.any? { |j| j==species }
  3900.       # Checked data from movelist
  3901.       ret[i] = _INTL("ABLE")
  3902.     elsif !$Trainer.party[i].egg? && $Trainer.party[i].compatibleWithMove?(move)
  3903.       # Checked data from PBS/tm.txt
  3904.       ret[i] = _INTL("ABLE")
  3905.     else
  3906.       ret[i] = _INTL("NOT ABLE")
  3907.     end
  3908.   end
  3909.   end
  3910.   return ret
  3911. end
  3912. #------------------------------------------------------------------------------#
  3913. # Debug_Actions
  3914. #------------------------------------------------------------------------------#
  3915. def pbDebugDayCare
  3916.   commands = [_INTL("Withdraw Pokémon 1"),
  3917.               _INTL("Withdraw Pokémon 2"),
  3918.               _INTL("Deposit Pokémon"),
  3919.               _INTL("Generate egg"),
  3920.               _INTL("Collect egg")]
  3921.   viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  3922.   viewport.z = 99999
  3923.   sprites = {}
  3924.   addBackgroundPlane(sprites,"background","hatchbg",viewport)
  3925.   sprites["overlay"] = BitmapSprite.new(Graphics.width,Graphics.height,viewport)
  3926.   pbSetSystemFont(sprites["overlay"].bitmap)
  3927.   sprites["cmdwindow"] = Window_CommandPokemonEx.new(commands)
  3928.   cmdwindow = sprites["cmdwindow"]
  3929.   cmdwindow.x        = 0
  3930.   cmdwindow.y        = Graphics.height-128
  3931.   cmdwindow.width    = Graphics.width
  3932.   cmdwindow.height   = 128
  3933.   cmdwindow.viewport = viewport
  3934.   cmdwindow.columns = 2
  3935.   base   = Color.new(248,248,248)
  3936.   shadow = Color.new(104,104,104)
  3937.   refresh = true
  3938.   loop do
  3939.     if refresh
  3940.       if pbEggGenerated?
  3941.         commands[3] = _INTL("Discard egg")
  3942.       else
  3943.         commands[3] = _INTL("Generate egg")
  3944.       end
  3945.       cmdwindow.commands = commands
  3946.       sprites["overlay"].bitmap.clear
  3947.       textpos = []
  3948.       for i in 0...2
  3949.         textpos.push([_INTL("Pokémon {1}",i+1),Graphics.width/4+i*Graphics.width/2,8,2,base,shadow])
  3950.       end
  3951.       for i in 0...pbDayCareDeposited
  3952.         next if !$PokemonGlobal.daycare[i][0]
  3953.         y = 40
  3954.         pkmn      = $PokemonGlobal.daycare[i][0]
  3955.         initlevel = $PokemonGlobal.daycare[i][1]
  3956.         leveldiff = pkmn.level-initlevel
  3957.         textpos.push([pkmn.name+" ("+PBSpecies.getName(pkmn.species)+")",8+i*Graphics.width/2,y,0,base,shadow])
  3958.         y += 32
  3959.         if pkmn.male?
  3960.           textpos.push([_INTL("Male ♂"),8+i*Graphics.width/2,y,0,Color.new(128,192,248),shadow])
  3961.         elsif pkmn.female?
  3962.           textpos.push([_INTL("Female ♀"),8+i*Graphics.width/2,y,0,Color.new(248,96,96),shadow])
  3963.         else
  3964.           textpos.push([_INTL("Genderless"),8+i*Graphics.width/2,y,0,base,shadow])
  3965.         end
  3966.         y += 32
  3967.         if initlevel>=PBExperience.maxLevel
  3968.           textpos.push(["Lv. #{initlevel} (max)",8+i*Graphics.width/2,y,0,base,shadow])
  3969.         elsif leveldiff>0
  3970.           textpos.push(["Lv. #{initlevel} -> #{pkmn.level} (+#{leveldiff})",
  3971.              8+i*Graphics.width/2,y,0,base,shadow])
  3972.         else
  3973.           textpos.push(["Lv. #{initlevel} (no change)",8+i*Graphics.width/2,y,0,base,shadow])
  3974.         end
  3975.         y += 32
  3976.         if pkmn.level<PBExperience.maxLevel
  3977.           endexp   = PBExperience.pbGetStartExperience(pkmn.level+1,pkmn.growthrate)
  3978.           textpos.push(["To next Lv.: #{endexp-pkmn.exp}",8+i*Graphics.width/2,y,0,base,shadow])
  3979.           y += 32
  3980.         end
  3981.         cost = pbDayCareGetCost(i)
  3982.         textpos.push(["Cost: $#{cost}",8+i*Graphics.width/2,y,0,base,shadow])
  3983.       end
  3984.       if pbEggGenerated?
  3985.         textpos.push(["Egg waiting for collection",Graphics.width/2,216,2,Color.new(248,248,0),shadow])
  3986.       elsif pbDayCareDeposited==2
  3987.         if pbDayCareGetCompat==0
  3988.           textpos.push(["Pokémon cannot breed",Graphics.width/2,216,2,Color.new(248,96,96),shadow])
  3989.         else
  3990.           textpos.push(["Pokémon can breed",Graphics.width/2,216,2,Color.new(64,248,64),shadow])
  3991.         end
  3992.       end
  3993.       pbDrawTextPositions(sprites["overlay"].bitmap,textpos)
  3994.       refresh = false
  3995.     end
  3996.     pbUpdateSpriteHash(sprites)
  3997.     Graphics.update
  3998.     Input.update
  3999.     if Input.trigger?(Input::B)
  4000.       break
  4001.     elsif Input.trigger?(Input::C)
  4002.       ret = cmdwindow.index
  4003.      if $Trainer.partyplus>=1
  4004.       case cmdwindow.index
  4005.       when 0   # Withdraw Pokémon 1
  4006.         if !$PokemonGlobal.daycare[0][0]
  4007.           pbPlayBuzzerSE
  4008.         elsif $Trainer.party.length>=$Trainer.partyplus
  4009.           pbPlayBuzzerSE
  4010.           pbMessage(_INTL("Party is full, can't withdraw Pokémon."))
  4011.         else
  4012.           pbPlayDecisionSE
  4013.           pbDayCareGetDeposited(0,3,4)
  4014.           pbDayCareWithdraw(0)
  4015.           refresh = true
  4016.         end
  4017.       when 1  # Withdraw Pokémon 2
  4018.         if !$PokemonGlobal.daycare[1][0]
  4019.           pbPlayBuzzerSE
  4020.         elsif $Trainer.party.length>=$Trainer.partyplus
  4021.           pbPlayBuzzerSE
  4022.           pbMessage(_INTL("Party is full, can't withdraw Pokémon."))
  4023.         else
  4024.           pbPlayDecisionSE
  4025.           pbDayCareGetDeposited(1,3,4)
  4026.           pbDayCareWithdraw(1)
  4027.           refresh = true
  4028.         end
  4029.       when 2   # Deposit Pokémon
  4030.         if pbDayCareDeposited==2
  4031.           pbPlayBuzzerSE
  4032.         elsif $Trainer.party.length==0
  4033.           pbPlayBuzzerSE
  4034.           pbMessage(_INTL("Party is empty, can't deposit Pokémon."))
  4035.         else
  4036.           pbPlayDecisionSE
  4037.           pbChooseNonEggPokemon(1,3)
  4038.           if pbGet(1)>=0
  4039.             pbDayCareDeposit(pbGet(1))
  4040.             refresh = true
  4041.           end
  4042.         end
  4043.       when 3   # Generate/discard egg
  4044.         if pbEggGenerated?
  4045.           pbPlayDecisionSE
  4046.           $PokemonGlobal.daycareEgg      = 0
  4047.           $PokemonGlobal.daycareEggSteps = 0
  4048.           refresh = true
  4049.         else
  4050.           if pbDayCareDeposited!=2 || pbDayCareGetCompat==0
  4051.             pbPlayBuzzerSE
  4052.           else
  4053.             pbPlayDecisionSE
  4054.             $PokemonGlobal.daycareEgg = 1
  4055.             refresh = true
  4056.           end
  4057.         end
  4058.       when 4   # Collect egg
  4059.         if $PokemonGlobal.daycareEgg!=1
  4060.           pbPlayBuzzerSE
  4061.         elsif $Trainer.party.length>=$Trainer.partyplus
  4062.           pbPlayBuzzerSE
  4063.           pbMessage(_INTL("Party is full, can't collect the egg."))
  4064.         else
  4065.           pbPlayDecisionSE
  4066.           pbDayCareGenerateEgg
  4067.           $PokemonGlobal.daycareEgg      = 0
  4068.           $PokemonGlobal.daycareEggSteps = 0
  4069.           pbMessage(_INTL("Collected the {1} egg.",
  4070.              PBSpecies.getName($Trainer.lastParty.species)))
  4071.           refresh = true
  4072.         end
  4073.       end
  4074.     else
  4075.       case cmdwindow.index
  4076.       when 0   # Withdraw Pokémon 1
  4077.         if !$PokemonGlobal.daycare[0][0]
  4078.           pbPlayBuzzerSE
  4079.         elsif $Trainer.party.length>=6
  4080.           pbPlayBuzzerSE
  4081.           pbMessage(_INTL("Party is full, can't withdraw Pokémon."))
  4082.         else
  4083.           pbPlayDecisionSE
  4084.           pbDayCareGetDeposited(0,3,4)
  4085.           pbDayCareWithdraw(0)
  4086.           refresh = true
  4087.         end
  4088.       when 1  # Withdraw Pokémon 2
  4089.         if !$PokemonGlobal.daycare[1][0]
  4090.           pbPlayBuzzerSE
  4091.         elsif $Trainer.party.length>=6
  4092.           pbPlayBuzzerSE
  4093.           pbMessage(_INTL("Party is full, can't withdraw Pokémon."))
  4094.         else
  4095.           pbPlayDecisionSE
  4096.           pbDayCareGetDeposited(1,3,4)
  4097.           pbDayCareWithdraw(1)
  4098.           refresh = true
  4099.         end
  4100.       when 2   # Deposit Pokémon
  4101.         if pbDayCareDeposited==2
  4102.           pbPlayBuzzerSE
  4103.         elsif $Trainer.party.length==0
  4104.           pbPlayBuzzerSE
  4105.           pbMessage(_INTL("Party is empty, can't deposit Pokémon."))
  4106.         else
  4107.           pbPlayDecisionSE
  4108.           pbChooseNonEggPokemon(1,3)
  4109.           if pbGet(1)>=0
  4110.             pbDayCareDeposit(pbGet(1))
  4111.             refresh = true
  4112.           end
  4113.         end
  4114.       when 3   # Generate/discard egg
  4115.         if pbEggGenerated?
  4116.           pbPlayDecisionSE
  4117.           $PokemonGlobal.daycareEgg      = 0
  4118.           $PokemonGlobal.daycareEggSteps = 0
  4119.           refresh = true
  4120.         else
  4121.           if pbDayCareDeposited!=2 || pbDayCareGetCompat==0
  4122.             pbPlayBuzzerSE
  4123.           else
  4124.             pbPlayDecisionSE
  4125.             $PokemonGlobal.daycareEgg = 1
  4126.             refresh = true
  4127.           end
  4128.         end
  4129.       when 4   # Collect egg
  4130.         if $PokemonGlobal.daycareEgg!=1
  4131.           pbPlayBuzzerSE
  4132.         elsif $Trainer.party.length>=6
  4133.           pbPlayBuzzerSE
  4134.           pbMessage(_INTL("Party is full, can't collect the egg."))
  4135.         else
  4136.           pbPlayDecisionSE
  4137.           pbDayCareGenerateEgg
  4138.           $PokemonGlobal.daycareEgg      = 0
  4139.           $PokemonGlobal.daycareEggSteps = 0
  4140.           pbMessage(_INTL("Collected the {1} egg.",
  4141.              PBSpecies.getName($Trainer.lastParty.species)))
  4142.           refresh = true
  4143.         end
  4144.       end
  4145.      end
  4146.     end
  4147.   end
  4148.   pbDisposeSpriteHash(sprites)
  4149.   viewport.dispose
  4150. end
  4151. class PokeBattle_Battler
  4152.   attr_reader   :fainted    # Boolean to mark whether self has fainted properly
  4153.   attr_reader   :benched    # Boolean to mark whether self has fainted properly
  4154.   def hp=(value)
  4155.     @hp = value.to_i
  4156.     @pokemon.hp = value.to_i if @pokemon
  4157.   end
  4158.   def benchedflag
  4159.     return @pokemon.benchedflag
  4160.   end
  4161.   def fainted?; return @hp<=0; end
  4162.   alias isFainted? fainted?
  4163.   def benched?; return @benchedflag; end
  4164.   alias isBenched? benched?
  4165.   # Yields each unfainted ally Pokémon.
  4166.   def eachAlly
  4167.     @battle.battlers.each do |b|
  4168.       yield b if b && !b.fainted? && !b.benched? && !b.opposes?(@index) && b.index!=@index
  4169.     end
  4170.   end
  4171.   # Yields each unfainted opposing Pokémon.
  4172.   def eachOpposing
  4173.     @battle.battlers.each { |b| yield b if b && !b.fainted? && !b.benched? && b.opposes?(@index) }
  4174.   end
  4175. end
  4176. class PokeBattle_Battle
  4177.   #=============================================================================
  4178.   # Iterate through battlers
  4179.   #=============================================================================
  4180. #  def eachBattler
  4181. #    @battlers.each { |b| yield b if b && !b.fainted? || !b.benched?}
  4182. #  end
  4183. #  def eachSameSideBattler(idxBattler=0)
  4184. #    idxBattler = idxBattler.index if idxBattler.respond_to?("index")
  4185. #    @battlers.each { |b| yield b if b && !b.fainted? || !b.benched? && !b.opposes?(idxBattler) }
  4186. #  end
  4187. #  def eachOtherSideBattler(idxBattler=0)
  4188. #    idxBattler = idxBattler.index if idxBattler.respond_to?("index")
  4189. #    @battlers.each { |b| yield b if b && !b.fainted? || !b.benched? && b.opposes?(idxBattler) }
  4190. #  end
  4191.   #=============================================================================
  4192.   # Choosing Pokémon to switch
  4193.   #=============================================================================
  4194.   # Checks whether the replacement Pokémon (at party index idxParty) can enter
  4195.   # battle.
  4196.   # NOTE: Messages are only shown while in the party screen when choosing a
  4197.   #       command for the next round.
  4198.   def pbCanSwitchLax?(idxBattler,idxParty,partyScene=nil)
  4199.     return true if idxParty<0
  4200.     party = pbParty(idxBattler)
  4201.     return false if idxParty>=party.length
  4202.     return false if !party[idxParty]
  4203.     if party[idxParty].egg?
  4204.       partyScene.pbDisplay(_INTL("An Egg can't battle!")) if partyScene
  4205.       return false
  4206.     end
  4207.     if !pbIsOwner?(idxBattler,idxParty)
  4208.       owner = pbGetOwnerFromPartyIndex(idxBattler,idxParty)
  4209.       partyScene.pbDisplay(_INTL("You can't switch {1}'s Pokémon with one of yours!",
  4210.         owner.name)) if partyScene
  4211.       return false
  4212.     end
  4213.     if party[idxParty].fainted?
  4214.       partyScene.pbDisplay(_INTL("{1} has no energy left to battle!",
  4215.          party[idxParty].name)) if partyScene
  4216.       return false
  4217.     end
  4218.     if party[idxParty].benched?
  4219.       partyScene.pbDisplay(_INTL("{1} can only watch, not participate!",
  4220.          party[idxParty].name)) if partyScene
  4221.       return false
  4222.     end
  4223.     if pbFindBattler(idxParty,idxBattler)
  4224.       partyScene.pbDisplay(_INTL("{1} is already in battle!",
  4225.          party[idxParty].name)) if partyScene
  4226.       return false
  4227.     end
  4228.     return true
  4229.   end
  4230.   #=============================================================================
  4231.   # Switching Pokémon
  4232.   #=============================================================================
  4233.   # General switching method that checks if any Pokémon need to be sent out and,
  4234.   # if so, does. Called at the end of each round.
  4235.   def pbEORSwitch(favorDraws=false)
  4236.     return if @decision>0 && !favorDraws
  4237.     return if @decision==5 && favorDraws
  4238.     pbJudge
  4239.     return if @decision>0
  4240.     # Check through each fainted battler to see if that spot can be filled.
  4241.     switched = []
  4242.     loop do
  4243.       switched.clear
  4244.       @battlers.each do |b|
  4245.         next if !b || !b.fainted? || !b.benched?
  4246.         idxBattler = b.index
  4247.         next if !pbCanChooseNonActive?(idxBattler)
  4248.         if !pbOwnedByPlayer?(idxBattler)   # Opponent/ally is switching in
  4249.           next if wildBattle? && opposes?(idxBattler)   # Wild Pokémon can't switch
  4250.           idxPartyNew = pbSwitchInBetween(idxBattler)
  4251.           opponent = pbGetOwnerFromBattlerIndex(idxBattler)
  4252.           # NOTE: The player is only offered the chance to switch their own
  4253.           #       Pokémon when an opponent replaces a fainted Pokémon in single
  4254.           #       battles. In double battles, etc. there is no such offer.
  4255.           if @internalBattle && @switchStyle && trainerBattle? && pbSideSize(0)==1 &&
  4256.              opposes?(idxBattler) && !@battlers[0].fainted? && pbCanChooseNonActive?(0) &&
  4257.              @battlers[0].effects[PBEffects::Outrage]==0
  4258.             idxPartyForName = idxPartyNew
  4259.             enemyParty = pbParty(idxBattler)
  4260.             if isConst?(enemyParty[idxPartyNew].ability,PBAbilities,:ILLUSION)
  4261.               idxPartyForName = pbLastInTeam(idxBattler)
  4262.             end
  4263.             if pbDisplayConfirm(_INTL("{1} is about to send in {2}. Will you switch your Pokémon?",
  4264.                opponent.fullname,enemyParty[idxPartyForName].name))
  4265.               idxPlayerPartyNew = pbSwitchInBetween(0,false,true)
  4266.               if idxPlayerPartyNew>=0
  4267.                 pbMessageOnRecall(@battlers[0])
  4268.                 pbRecallAndReplace(0,idxPlayerPartyNew)
  4269.                 switched.push(0)
  4270.               end
  4271.             end
  4272.           end
  4273.           pbRecallAndReplace(idxBattler,idxPartyNew)
  4274.           switched.push(idxBattler)
  4275.         elsif trainerBattle?   # Player switches in in a trainer battle
  4276.           idxPlayerPartyNew = pbGetReplacementPokemonIndex(idxBattler)   # Owner chooses
  4277.           pbRecallAndReplace(idxBattler,idxPlayerPartyNew)
  4278.           switched.push(idxBattler)
  4279.         else   # Player's Pokémon has fainted in a wild battle
  4280.           switch = false
  4281.           if !pbDisplayConfirm(_INTL("Use next Pokémon?"))
  4282.             switch = (pbRun(idxBattler,true)<=0)
  4283.           else
  4284.             switch = true
  4285.           end
  4286.           if switch
  4287.             idxPlayerPartyNew = pbGetReplacementPokemonIndex(idxBattler)   # Owner chooses
  4288.             pbRecallAndReplace(idxBattler,idxPlayerPartyNew)
  4289.             switched.push(idxBattler)
  4290.           end
  4291.         end
  4292.       end
  4293.       break if switched.length==0
  4294.       pbPriority(true).each do |b|
  4295.         b.pbEffectsOnSwitchIn(true) if switched.include?(b.index)
  4296.       end
  4297.     end
  4298.   end
  4299.   # Actually performs the recalling and sending out in all situations.
  4300.   def pbRecallAndReplace(idxBattler,idxParty,randomReplacement=false,batonPass=false)
  4301.     @scene.pbRecall(idxBattler) if !@battlers[idxBattler].fainted? || !@battlers[idxBattler].benched?
  4302.     @battlers[idxBattler].pbAbilitiesOnSwitchOut   # Inc. primordial weather check
  4303.     @scene.pbShowPartyLineup(idxBattler&1) if pbSideSize(idxBattler)==1
  4304.     pbMessagesOnReplace(idxBattler,idxParty) if !randomReplacement
  4305.     pbReplace(idxBattler,idxParty,batonPass)
  4306.   end
  4307.   #=============================================================================
  4308.   # Check whether actions can be taken
  4309.   #=============================================================================
  4310.   def pbCanShowCommands?(idxBattler)
  4311.     battler = @battlers[idxBattler]
  4312.     return false if !battler || battler.fainted?
  4313.     return false if !battler || battler.benched?
  4314.     return false if battler.usingMultiTurnAttack?
  4315.     return true
  4316.   end
  4317. end
  4318. #===============================================================================
  4319. # Individual trainer editor
  4320. #===============================================================================
  4321. module TrainerBattleProperty
  4322.   def self.set(settingname,oldsetting)
  4323.     return nil if !oldsetting
  4324.     properties = [
  4325.        [_INTL("Trainer Type"),TrainerTypeProperty,_INTL("Name of the trainer type for this Trainer.")],
  4326.        [_INTL("Trainer Name"),StringProperty,_INTL("Name of the Trainer.")],
  4327.        [_INTL("Battle ID"),LimitProperty.new(9999),_INTL("ID used to distinguish Trainers with the same name and trainer type.")],
  4328.        [_INTL("Lose Text"),StringProperty,_INTL("Message shown in battle when the Trainer is defeated.")],
  4329.        [_INTL("Pokémon 1"),TrainerPokemonProperty,_INTL("1st Pokémon.")],
  4330.        [_INTL("Pokémon 2"),TrainerPokemonProperty,_INTL("2nd Pokémon.")],
  4331.        [_INTL("Pokémon 3"),TrainerPokemonProperty,_INTL("3rd Pokémon.")],
  4332.        [_INTL("Pokémon 4"),TrainerPokemonProperty,_INTL("4th Pokémon.")],
  4333.        [_INTL("Pokémon 5"),TrainerPokemonProperty,_INTL("5th Pokémon.")],
  4334.        [_INTL("Pokémon 6"),TrainerPokemonProperty,_INTL("6th Pokémon.")],
  4335.        [_INTL("Pokémon 7"),TrainerPokemonProperty,_INTL("7th Pokémon.")],
  4336.        [_INTL("Pokémon 8"),TrainerPokemonProperty,_INTL("8th Pokémon.")],
  4337.        [_INTL("Pokémon 9"),TrainerPokemonProperty,_INTL("9th Pokémon.")],
  4338.        [_INTL("Pokémon 10"),TrainerPokemonProperty,_INTL("10th Pokémon.")],
  4339.        [_INTL("Pokémon 11"),TrainerPokemonProperty,_INTL("11th Pokémon.")],
  4340.        [_INTL("Pokémon 12"),TrainerPokemonProperty,_INTL("12th Pokémon.")],
  4341.        [_INTL("Pokémon 13"),TrainerPokemonProperty,_INTL("13th Pokémon.")],
  4342.        [_INTL("Pokémon 14"),TrainerPokemonProperty,_INTL("14th Pokémon.")],
  4343.        [_INTL("Pokémon 15"),TrainerPokemonProperty,_INTL("15th Pokémon.")],
  4344.        [_INTL("Pokémon 16"),TrainerPokemonProperty,_INTL("16th Pokémon.")],
  4345.        [_INTL("Pokémon 17"),TrainerPokemonProperty,_INTL("17th Pokémon.")],
  4346.        [_INTL("Pokémon 18"),TrainerPokemonProperty,_INTL("18th Pokémon.")],
  4347.        [_INTL("Pokémon 19"),TrainerPokemonProperty,_INTL("19th Pokémon.")],
  4348.        [_INTL("Pokémon 20"),TrainerPokemonProperty,_INTL("20th Pokémon.")],
  4349.        [_INTL("Pokémon 21"),TrainerPokemonProperty,_INTL("21th Pokémon.")],
  4350.        [_INTL("Pokémon 22"),TrainerPokemonProperty,_INTL("22th Pokémon.")],
  4351.        [_INTL("Pokémon 23"),TrainerPokemonProperty,_INTL("23th Pokémon.")],
  4352.        [_INTL("Pokémon 24"),TrainerPokemonProperty,_INTL("24th Pokémon.")],
  4353.        [_INTL("Pokémon 25"),TrainerPokemonProperty,_INTL("25th Pokémon.")],
  4354.        [_INTL("Pokémon 26"),TrainerPokemonProperty,_INTL("26th Pokémon.")],
  4355.        [_INTL("Pokémon 27"),TrainerPokemonProperty,_INTL("27th Pokémon.")],
  4356.        [_INTL("Pokémon 28"),TrainerPokemonProperty,_INTL("28th Pokémon.")],
  4357.        [_INTL("Pokémon 29"),TrainerPokemonProperty,_INTL("29th Pokémon.")],
  4358.        [_INTL("Pokémon 30"),TrainerPokemonProperty,_INTL("30th Pokémon.")],
  4359.        [_INTL("Pokémon 31"),TrainerPokemonProperty,_INTL("31th Pokémon.")],
  4360.        [_INTL("Pokémon 32"),TrainerPokemonProperty,_INTL("32th Pokémon.")],
  4361.        [_INTL("Pokémon 33"),TrainerPokemonProperty,_INTL("33th Pokémon.")],
  4362.        [_INTL("Pokémon 34"),TrainerPokemonProperty,_INTL("34th Pokémon.")],
  4363.        [_INTL("Pokémon 35"),TrainerPokemonProperty,_INTL("35th Pokémon.")],
  4364.        [_INTL("Pokémon 36"),TrainerPokemonProperty,_INTL("36th Pokémon.")],
  4365.        [_INTL("Pokémon 37"),TrainerPokemonProperty,_INTL("37th Pokémon.")],
  4366.        [_INTL("Pokémon 38"),TrainerPokemonProperty,_INTL("38th Pokémon.")],
  4367.        [_INTL("Pokémon 39"),TrainerPokemonProperty,_INTL("39th Pokémon.")],
  4368.        [_INTL("Pokémon 40"),TrainerPokemonProperty,_INTL("40th Pokémon.")],
  4369.        [_INTL("Item 1"),ItemProperty,_INTL("Item used by the Trainer during battle.")],
  4370.        [_INTL("Item 2"),ItemProperty,_INTL("Item used by the Trainer during battle.")],
  4371.        [_INTL("Item 3"),ItemProperty,_INTL("Item used by the Trainer during battle.")],
  4372.        [_INTL("Item 4"),ItemProperty,_INTL("Item used by the Trainer during battle.")],
  4373.        [_INTL("Item 5"),ItemProperty,_INTL("Item used by the Trainer during battle.")],
  4374.        [_INTL("Item 6"),ItemProperty,_INTL("Item used by the Trainer during battle.")],
  4375.        [_INTL("Item 7"),ItemProperty,_INTL("Item used by the Trainer during battle.")],
  4376.        [_INTL("Item 8"),ItemProperty,_INTL("Item used by the Trainer during battle.")]
  4377.     ]
  4378.     if !pbPropertyList(settingname,oldsetting,properties,true)
  4379.       return nil
  4380.     end
  4381.     oldsetting = nil if !oldsetting[0] || oldsetting[0]==0
  4382.     return oldsetting
  4383.   end
  4384.  
  4385.   def self.format(value)
  4386.     return value.inspect
  4387.   end
  4388. end
  4389. class PokeBattle_NullBattlePeer
  4390.   def pbStorePokemon(player,pkmn)
  4391.     if $Trainer.partyplus>=1
  4392.      plus = $Trainer.partyplus
  4393.     else
  4394.      plus = 6
  4395.     end
  4396.     player.party[player.party.length] = pkmn if player.party.length<plus
  4397.     return -1
  4398.   end
  4399. end
  4400. def pbTrainerBattleEditor
  4401.   selection = 0
  4402.   trainertypes = pbLoadTrainerTypesData
  4403.   trainers     = pbLoadTrainersData
  4404.   modified = false
  4405.   for trainer in trainers
  4406.     trtype = trainer[0]
  4407.     next if trainertypes && trainertypes[trtype]
  4408.     trainer[0] = 0
  4409.     modified = true
  4410.   end
  4411.   pbListScreenBlock(_INTL("Trainer Battles"),TrainerBattleLister.new(selection,true)) { |button,trtype|
  4412.     next if !trtype
  4413.     index       = trtype[0]
  4414.     trainerdata = trtype[1]
  4415.     if button==Input::A
  4416.       # Delete trainer
  4417.       if index>=0
  4418.         if pbConfirmMessageSerious("Delete this trainer battle?")
  4419.           trainers.delete_at(index)
  4420.           modified = true
  4421.           pbMessage(_INTL("The Trainer battle was deleted."))
  4422.         end
  4423.       end
  4424.     elsif button==Input::C
  4425.       # New trainer/edit existing trainer
  4426.       selection = index
  4427.       if selection<0
  4428.         # New trainer
  4429.         trainertype = -1
  4430.         ret = pbMessage(_INTL("First, define the type of trainer."),[
  4431.            _INTL("Use existing type"),
  4432.            _INTL("Use new type"),
  4433.            _INTL("Cancel")],3)
  4434.         if ret==0
  4435.           trainertype = pbListScreen(_INTL("TRAINER TYPE"),TrainerTypeLister.new(0,false))
  4436.           next if !trainertype
  4437.           trainertype = trainertype[0]
  4438.           next if trainertype<0
  4439.         elsif ret==1
  4440.           trainertype = pbTrainerTypeEditorNew(nil)
  4441.           next if trainertype<0
  4442.         else
  4443.           next
  4444.         end
  4445.         trainername = pbMessageFreeText(_INTL("Now enter the trainer's name."),"",false,30)
  4446.         next if trainername==""
  4447.         trainerparty = pbGetFreeTrainerParty(trainertype,trainername)
  4448.         if trainerparty<0
  4449.           pbMessage(_INTL("There is no room to create a trainer of that type and name."))
  4450.           next
  4451.         end
  4452.         t = pbNewTrainer(trainertype,trainername,trainerparty,false)
  4453.         trainers.push(t) if t
  4454.         pbMessage(_INTL("The Trainer battle was added."))
  4455.       else
  4456.         # Edit existing trainer
  4457.         data = [trainerdata[0],trainerdata[1],trainerdata[4],trainerdata[5]]   # Type, name, ID, lose text
  4458.         for i in 0...40
  4459.           data.push(trainerdata[3][i])   # Pokémon
  4460.         end
  4461.         for i in 0...8
  4462.           data.push(trainerdata[2][i])   # Items
  4463.         end
  4464.         loop do
  4465.           data = TrainerBattleProperty.set(trainerdata[1],data)
  4466.           break if !data
  4467.           trainerdata = [
  4468.              data[0],
  4469.              data[1],
  4470.              [data[44],data[45],data[46],data[47],data[48],data[49],data[50],data[51]].find_all { |i| i && i!=0 },   # Item list
  4471.              [data[4],data[5],data[6],data[7],data[8],data[9],data[10],data[11],data[12],data[13],data[14],data[15],data[16],data[17],data[18],data[19],data[20],data[21],data[22],data[23],data[24],data[25],data[26],data[27],data[28],data[29],data[30],data[31],data[32],data[33],data[34],data[35],data[36],data[37],data[38],data[39],data[40],data[41],data[42],data[43]].find_all { |i| i && i[TPSPECIES]!=0 },   # Pokémon list
  4472.              data[2],
  4473.              data[3]
  4474.           ]
  4475.           if !trainerdata[1] || trainerdata[1].length==0
  4476.             pbMessage(_INTL("Can't save. No name was entered."))
  4477.           elsif trainerdata[3].length==0
  4478.             pbMessage(_INTL("Can't save. The Pokémon list is empty."))
  4479.           else
  4480.             trainers[index] = trainerdata
  4481.             modified = true
  4482.             break
  4483.           end
  4484.         end
  4485.       end
  4486.     end
  4487.   }
  4488.   if modified && pbConfirmMessage(_INTL("Save changes?"))
  4489.     save_data(trainers,"Data/trainers.dat")
  4490.     $PokemonTemp.trainersData = nil
  4491.     pbConvertTrainerData
  4492.   end
  4493. end
  4494.  
Add Comment
Please, Sign In to add comment