Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #------------------------------------------------------------------------------#
- #Currently supports any party limit between 1-10. higher values may be asked #
- #on the thread for a mini update. to set the max number of pokemon a trainer #
- #may carry change '$Trainer.partyplus' to a number between 1 & 10 like so: #
- # '$Trainer.partyplus=8' this will allow a player to have 8 pokemon on them. #
- #If you want a player to have more than 6 pokemon but be unable to use them in #
- #battle, alter the partybenched value to forbid those pokemon from fighting. #
- #This also affects enemy trainers. they may have up to 40 pokemon if the dev #
- #wanted to. ~PDM20#
- #------------------------------------------------------------------------------#
- ALLOW_BENCHING = true
- class PokeBattle_Trainer
- attr_accessor(:partyplus)
- attr_accessor(:partybenched)
- alias partyplus_initialize initialize
- def initialize(name,trainertype)
- partyplus_initialize(name,trainertype)
- @partyplus = 0
- @partybenched = 0
- end
- end
- class PokeBattle_Pokemon
- def able?
- return !egg? && @hp>0 && !benched?
- end
- attr_accessor(:benchedflag)
- def benched?
- return @benchedflag if @benchedflag!=nil
- end
- alias isBenched? benched?
- # Makes this Pokémon benched.
- def makeBenched
- @benchedflag = true
- end
- # Makes this Pokémon not benched.
- def makeNotBenched
- @benchedflag = false
- end
- alias partyplus_initialize initialize
- def initialize(*args)
- partyplus_initialize(*args)
- @benchedflag = false
- end
- end
- def setBenchedParty
- size = $Trainer.partyplus
- limit = $Trainer.partybenched
- max = $Trainer.party.length
- if ALLOW_BENCHING && size>=limit
- for j in 0...max
- $Trainer.party[j].makeNotBenched
- end
- for i in limit...max
- $Trainer.party[i].makeBenched
- end
- end
- end
- #------------------------------------------------------------------------------#
- # PokeBattle_BattlePeer
- #------------------------------------------------------------------------------#
- class PokeBattle_RealBattlePeer
- def pbStorePokemon(player,pkmn)
- if $Trainer.partyplus>=1
- plus = $Trainer.partyplus
- else
- plus = 6
- end
- if player.party.length<plus
- player.party[player.party.length] = pkmn
- return -1
- end
- pkmn.heal
- oldCurBox = pbCurrentBox
- storedBox = $PokemonStorage.pbStoreCaught(pkmn)
- if storedBox<0
- # NOTE: Poké Balls can't be used if storage is full, so you shouldn't ever
- # see this message.
- pbDisplayPaused(_INTL("Can't catch any more..."))
- return oldCurBox
- end
- return storedBox
- end
- end
- #------------------------------------------------------------------------------#
- # PField_DayCare
- #------------------------------------------------------------------------------#
- def pbDayCareWithdraw(index)
- if !$PokemonGlobal.daycare[index][0]
- raise _INTL("There's no Pokémon here...")
- elsif $Trainer.party.length>=$Trainer.partyplus && $Trainer.partyplus>=1
- raise _INTL("Can't store the Pokémon...")
- elsif $Trainer.party.length>=6
- raise _INTL("Can't store the Pokémon...")
- else
- $Trainer.party[$Trainer.party.length] = $PokemonGlobal.daycare[index][0]
- $PokemonGlobal.daycare[index][0] = nil
- $PokemonGlobal.daycare[index][1] = 0
- $PokemonGlobal.daycareEgg = 0
- end
- end
- #===============================================================================
- # Generate an Egg based on Pokémon in the Day Care.
- #===============================================================================
- def pbDayCareGenerateEgg
- return if pbDayCareDeposited!=2
- raise _INTL("Can't store the egg") if $Trainer.party.length>=6 || $Trainer.party.length>=$Trainer.partyplus && $Trainer.partyplus>=1
- pokemon0 = $PokemonGlobal.daycare[0][0]
- pokemon1 = $PokemonGlobal.daycare[1][0]
- mother = nil
- father = nil
- babyspecies = 0
- ditto0 = pbIsDitto?(pokemon0)
- ditto1 = pbIsDitto?(pokemon1)
- if pokemon0.female? || ditto0
- babyspecies = (ditto0) ? pokemon1.species : pokemon0.species
- mother = pokemon0
- father = pokemon1
- else
- babyspecies = (ditto1) ? pokemon0.species : pokemon1.species
- mother = pokemon1
- father = pokemon0
- end
- # Determine the egg's species
- babyspecies = pbGetBabySpecies(babyspecies,mother.item,father.item)
- if isConst?(babyspecies,PBSpecies,:MANAPHY) && hasConst?(PBSpecies,:PHIONE)
- babyspecies = getConst(PBSpecies,:PHIONE)
- elsif (isConst?(babyspecies,PBSpecies,:NIDORANfE) && hasConst?(PBSpecies,:NIDORANmA)) ||
- (isConst?(babyspecies,PBSpecies,:NIDORANmA) && hasConst?(PBSpecies,:NIDORANfE))
- babyspecies = [getConst(PBSpecies,:NIDORANmA),
- getConst(PBSpecies,:NIDORANfE)][rand(2)]
- elsif (isConst?(babyspecies,PBSpecies,:VOLBEAT) && hasConst?(PBSpecies,:ILLUMISE)) ||
- (isConst?(babyspecies,PBSpecies,:ILLUMISE) && hasConst?(PBSpecies,:VOLBEAT))
- babyspecies = [getConst(PBSpecies,:VOLBEAT),
- getConst(PBSpecies,:ILLUMISE)][rand(2)]
- end
- # Generate egg
- egg = pbNewPkmn(babyspecies,EGG_LEVEL)
- # Randomise personal ID
- pid = rand(65536)
- pid |= (rand(65536)<<16)
- egg.personalID = pid
- # Inheriting form
- if isConst?(babyspecies,PBSpecies,:BURMY) ||
- isConst?(babyspecies,PBSpecies,:SHELLOS) ||
- isConst?(babyspecies,PBSpecies,:BASCULIN) ||
- isConst?(babyspecies,PBSpecies,:FLABEBE) ||
- isConst?(babyspecies,PBSpecies,:PUMPKABOO) ||
- isConst?(babyspecies,PBSpecies,:ORICORIO) ||
- isConst?(babyspecies,PBSpecies,:ROCKRUFF) ||
- isConst?(babyspecies,PBSpecies,:MINIOR)
- newForm = mother.form
- newForm = 0 if mother.isSpecies?(:MOTHIM)
- egg.form = newForm
- end
- # Inheriting Alolan form
- if isConst?(babyspecies,PBSpecies,:RATTATA) ||
- isConst?(babyspecies,PBSpecies,:SANDSHREW) ||
- isConst?(babyspecies,PBSpecies,:VULPIX) ||
- isConst?(babyspecies,PBSpecies,:DIGLETT) ||
- isConst?(babyspecies,PBSpecies,:MEOWTH) ||
- isConst?(babyspecies,PBSpecies,:GEODUDE) ||
- isConst?(babyspecies,PBSpecies,:GRIMER)
- if mother.form==1
- egg.form = 1 if mother.hasItem?(:EVERSTONE)
- elsif pbGetBabySpecies(father.species,mother.item,father.item)==babyspecies
- egg.form = 1 if father.form==1 && father.hasItem?(:EVERSTONE)
- end
- end
- # Inheriting Moves
- moves = []
- othermoves = []
- movefather = father; movemother = mother
- if pbIsDitto?(movefather) && !mother.female?
- movefather = mother; movemother = father
- end
- # Initial Moves
- initialmoves = egg.getMoveList
- for k in initialmoves
- if k[0]<=EGG_LEVEL
- moves.push(k[1])
- else
- next if !mother.hasMove?(k[1]) || !father.hasMove?(k[1])
- othermoves.push(k[1])
- end
- end
- # Inheriting Natural Moves
- for move in othermoves
- moves.push(move)
- end
- # Inheriting Machine Moves
- if !NEWEST_BATTLE_MECHANICS
- itemsData = pbLoadItemsData
- for i in 0...itemsData.length
- next if !itemsData[i]
- atk = itemsData[i][ITEM_MACHINE]
- next if !atk || atk==0
- next if !egg.compatibleWithMove?(atk)
- next if !movefather.hasMove?(atk)
- moves.push(atk)
- end
- end
- # Inheriting Egg Moves
- babyEggMoves = pbGetSpeciesEggMoves(egg.species,egg.form)
- if movefather.male?
- babyEggMoves.each { |m| moves.push(m) if movefather.hasMove?(m) }
- end
- if NEWEST_BATTLE_MECHANICS
- babyEggMoves.each { |m| moves.push(m) if movemother.hasMove?(m) }
- end
- # Volt Tackle
- lightball = false
- if (father.isSpecies?(:PIKACHU) || father.isSpecies?(:RAICHU)) &&
- father.hasItem?(:LIGHTBALL)
- lightball = true
- end
- if (mother.isSpecies?(:PIKACHU) || mother.isSpecies?(:RAICHU)) &&
- mother.hasItem?(:LIGHTBALL)
- lightball = true
- end
- if lightball && isConst?(babyspecies,PBSpecies,:PICHU) &&
- hasConst?(PBMoves,:VOLTTACKLE)
- moves.push(getConst(PBMoves,:VOLTTACKLE))
- end
- moves = moves.reverse
- moves |= [] # remove duplicates
- moves = moves.reverse
- # Assembling move list
- finalmoves = []
- listend = moves.length-4
- listend = 0 if listend<0
- for i in listend...listend+4
- moveid = (i>=moves.length) ? 0 : moves[i]
- finalmoves[finalmoves.length] = PBMove.new(moveid)
- end
- # Inheriting Individual Values
- ivs = []
- for i in 0...6
- ivs[i] = rand(32)
- end
- ivinherit = []
- for i in 0...2
- parent = [mother,father][i]
- ivinherit[i] = PBStats::HP if parent.hasItem?(:POWERWEIGHT)
- ivinherit[i] = PBStats::ATTACK if parent.hasItem?(:POWERBRACER)
- ivinherit[i] = PBStats::DEFENSE if parent.hasItem?(:POWERBELT)
- ivinherit[i] = PBStats::SPATK if parent.hasItem?(:POWERLENS)
- ivinherit[i] = PBStats::SPDEF if parent.hasItem?(:POWERBAND)
- ivinherit[i] = PBStats::SPEED if parent.hasItem?(:POWERANKLET)
- end
- num = 0; r = rand(2)
- 2.times do
- if ivinherit[r]!=nil
- parent = [mother,father][r]
- ivs[ivinherit[r]] = parent.iv[ivinherit[r]]
- num += 1
- break
- end
- r = (r+1)%2
- end
- limit = (NEWEST_BATTLE_MECHANICS && (mother.hasItem?(:DESTINYKNOT) ||
- father.hasItem?(:DESTINYKNOT))) ? 5 : 3
- loop do
- freestats = []
- PBStats.eachStat { |s| freestats.push(s) if !ivinherit.include?(s) }
- break if freestats.length==0
- r = freestats[rand(freestats.length)]
- parent = [mother,father][rand(2)]
- ivs[r] = parent.iv[r]
- ivinherit.push(r)
- num += 1
- break if num>=limit
- end
- # Inheriting nature
- newnatures = []
- newnatures.push(mother.nature) if mother.hasItem?(:EVERSTONE)
- newnatures.push(father.nature) if father.hasItem?(:EVERSTONE)
- if newnatures.length>0
- egg.setNature(newnatures[rand(newnatures.length)])
- end
- # Masuda method and Shiny Charm
- shinyretries = 0
- shinyretries += 5 if father.language!=mother.language
- shinyretries += 2 if hasConst?(PBItems,:SHINYCHARM) && $PokemonBag.pbHasItem?(:SHINYCHARM)
- if shinyretries>0
- shinyretries.times do
- break if egg.shiny?
- egg.personalID = rand(65536)|(rand(65536)<<16)
- end
- end
- # Inheriting ability from the mother
- if !ditto0 && !ditto1
- if mother.hasHiddenAbility?
- egg.setAbility(mother.abilityIndex) if rand(10)<6
- else
- if rand(10)<8
- egg.setAbility(mother.abilityIndex)
- else
- egg.setAbility((mother.abilityIndex+1)%2)
- end
- end
- elsif !(ditto0 && ditto1) && NEWEST_BATTLE_MECHANICS
- parent = (!ditto0) ? mother : father
- if parent.hasHiddenAbility?
- egg.setAbility(parent.abilityIndex) if rand(10)<6
- end
- end
- # Inheriting Poké Ball from the mother
- if mother.female? &&
- !isConst?(pbBallTypeToItem(mother.ballused),PBItems,:MASTERBALL) &&
- !isConst?(pbBallTypeToItem(mother.ballused),PBItems,:CHERISHBALL)
- egg.ballused = mother.ballused
- end
- # Set all stats
- egg.happiness = 120
- egg.iv[0] = ivs[0]
- egg.iv[1] = ivs[1]
- egg.iv[2] = ivs[2]
- egg.iv[3] = ivs[3]
- egg.iv[4] = ivs[4]
- egg.iv[5] = ivs[5]
- egg.moves[0] = finalmoves[0]
- egg.moves[1] = finalmoves[1]
- egg.moves[2] = finalmoves[2]
- egg.moves[3] = finalmoves[3]
- egg.calcStats
- egg.obtainText = _INTL("Day-Care Couple")
- egg.name = _INTL("Egg")
- eggSteps = pbGetSpeciesData(babyspecies,egg.form,SpeciesStepsToHatch)
- egg.eggsteps = eggSteps
- egg.givePokerus if rand(65536)<POKERUS_CHANCE
- # Add egg to party
- $Trainer.party[$Trainer.party.length] = egg
- end
- #------------------------------------------------------------------------------#
- # PItem_ItemEffects
- #------------------------------------------------------------------------------#
- ItemHandlers::UseOnPokemon.add(:DNASPLICERS,proc { |item,pkmn,scene|
- if !pkmn.isSpecies?(:KYUREM)
- scene.pbDisplay(_INTL("It had no effect."))
- next false
- end
- if pkmn.fainted?
- scene.pbDisplay(_INTL("This can't be used on the fainted Pokémon."))
- next false
- end
- # Fusing
- if pkmn.fused==nil
- chosen = scene.pbChoosePokemon(_INTL("Fuse with which Pokémon?"))
- next false if chosen<0
- poke2 = $Trainer.party[chosen]
- if pkmn==poke2
- scene.pbDisplay(_INTL("It cannot be fused with itself."))
- next false
- elsif poke2.egg?
- scene.pbDisplay(_INTL("It cannot be fused with an Egg."))
- next false
- elsif poke2.fainted?
- scene.pbDisplay(_INTL("It cannot be fused with that fainted Pokémon."))
- next false
- elsif !poke2.isSpecies?(:RESHIRAM) &&
- !poke2.isSpecies?(:ZEKROM)
- scene.pbDisplay(_INTL("It cannot be fused with that Pokémon."))
- next false
- end
- newForm = 0
- newForm = 1 if poke2.isSpecies?(:RESHIRAM)
- newForm = 2 if poke2.isSpecies?(:ZEKROM)
- pkmn.setForm(newForm) {
- pkmn.fused = poke2
- pbRemovePokemonAt(chosen)
- scene.pbHardRefresh
- scene.pbDisplay(_INTL("{1} changed Forme!",pkmn.name))
- }
- next true
- end
- # Unfusing
- if $Trainer.party.length>=6 || $Trainer.party.length>=$Trainer.partyplus && $Trainer.partyplus>=1
- scene.pbDisplay(_INTL("You have no room to separate the Pokémon."))
- next false
- end
- pkmn.setForm(0) {
- $Trainer.party[$Trainer.party.length] = pkmn.fused
- pkmn.fused = nil
- scene.pbHardRefresh
- scene.pbDisplay(_INTL("{1} changed Forme!",pkmn.name))
- }
- next true
- })
- ItemHandlers::UseOnPokemon.add(:NSOLARIZER,proc { |item,pkmn,scene|
- if !pkmn.isSpecies?(:NECROZMA) || pkmn.form == 2
- scene.pbDisplay(_INTL("It had no effect."))
- next false
- end
- if pkmn.fainted?
- scene.pbDisplay(_INTL("This can't be used on the fainted Pokémon."))
- next false
- end
- # Fusing
- if pkmn.fused==nil
- chosen = scene.pbChoosePokemon(_INTL("Fuse with which Pokémon?"))
- next false if chosen<0
- poke2 = $Trainer.party[chosen]
- if pkmn==poke2
- scene.pbDisplay(_INTL("It cannot be fused with itself."))
- next false
- elsif poke2.egg?
- scene.pbDisplay(_INTL("It cannot be fused with an Egg."))
- next false
- elsif poke2.fainted?
- scene.pbDisplay(_INTL("It cannot be fused with that fainted Pokémon."))
- next false
- elsif !poke2.isSpecies?(:SOLGALEO)
- scene.pbDisplay(_INTL("It cannot be fused with that Pokémon."))
- next false
- end
- pkmn.setForm(1) {
- pkmn.fused = poke2
- pbRemovePokemonAt(chosen)
- scene.pbHardRefresh
- scene.pbDisplay(_INTL("{1} changed Forme!",pkmn.name))
- }
- next true
- end
- # Unfusing
- if $Trainer.party.length>=6 || $Trainer.party.length>=$Trainer.partyplus && $Trainer.partyplus>=1
- scene.pbDisplay(_INTL("You have no room to separate the Pokémon."))
- next false
- end
- pkmn.setForm(0) {
- $Trainer.party[$Trainer.party.length] = pkmn.fused
- pkmn.fused = nil
- scene.pbHardRefresh
- scene.pbDisplay(_INTL("{1} changed Forme!",pkmn.name))
- }
- next true
- })
- ItemHandlers::UseOnPokemon.add(:NLUNARIZER,proc { |item,pkmn,scene|
- if !pkmn.isSpecies?(:NECROZMA) || pkmn.form == 1
- scene.pbDisplay(_INTL("It had no effect."))
- next false
- end
- if pkmn.fainted?
- scene.pbDisplay(_INTL("This can't be used on the fainted Pokémon."))
- next false
- end
- # Fusing
- if pkmn.fused==nil
- chosen = scene.pbChoosePokemon(_INTL("Fuse with which Pokémon?"))
- next false if chosen<0
- poke2 = $Trainer.party[chosen]
- if pkmn==poke2
- scene.pbDisplay(_INTL("It cannot be fused with itself."))
- next false
- elsif poke2.egg?
- scene.pbDisplay(_INTL("It cannot be fused with an Egg."))
- next false
- elsif poke2.fainted?
- scene.pbDisplay(_INTL("It cannot be fused with that fainted Pokémon."))
- next false
- elsif !poke2.isSpecies?(:LUNALA)
- scene.pbDisplay(_INTL("It cannot be fused with that Pokémon."))
- next false
- end
- pkmn.setForm(2) {
- pkmn.fused = poke2
- pbRemovePokemonAt(chosen)
- scene.pbHardRefresh
- scene.pbDisplay(_INTL("{1} changed Forme!",pkmn.name))
- }
- next true
- end
- # Unfusing
- if $Trainer.party.length>=6 || $Trainer.party.length>=$Trainer.partyplus && $Trainer.partyplus>=1
- scene.pbDisplay(_INTL("You have no room to separate the Pokémon."))
- next false
- end
- pkmn.setForm(0) {
- $Trainer.party[$Trainer.party.length] = pkmn.fused
- pkmn.fused = nil
- scene.pbHardRefresh
- scene.pbDisplay(_INTL("{1} changed Forme!",pkmn.name))
- }
- next true
- })
- #------------------------------------------------------------------------------#
- # PItem_BattleItemEffects
- #------------------------------------------------------------------------------#
- ItemHandlers::CanUseInBattle.addIf(proc { |item| pbIsPokeBall?(item) }, # Poké Balls
- proc { |item,pokemon,battler,move,firstAction,battle,scene,showMessages|
- if ((battle.pbPlayer.party.length>=6 || $Trainer.party.length>=$Trainer.partyplus) && $Trainer.partyplus>=1) && $PokemonStorage.full?
- scene.pbDisplay(_INTL("There is no room left in the PC!")) if showMessages
- next false
- end
- # NOTE: Using a Poké Ball consumes all your actions for the round. The code
- # below is one half of making this happen; the other half is in def
- # pbItemUsesAllActions?.
- if !firstAction
- scene.pbDisplay(_INTL("It's impossible to aim without being focused!")) if showMessages
- next false
- end
- if battler.semiInvulnerable?
- scene.pbDisplay(_INTL("It's no good! It's impossible to aim at a Pokémon that's not in sight!")) if showMessages
- next false
- end
- # NOTE: The code below stops you from throwing a Poké Ball if there is more
- # than one unfainted opposing Pokémon. (Snag Balls can be thrown in
- # this case, but only in trainer battles, and the trainer will deflect
- # them if they are trying to catch a non-Shadow Pokémon.)
- if battle.pbOpposingBattlerCount>1 && !(pbIsSnagBall?(item) && battle.trainerBattle?)
- if battle.pbOpposingBattlerCount==2
- scene.pbDisplay(_INTL("It's no good! It's impossible to aim when there are two Pokémon!")) if showMessages
- else
- scene.pbDisplay(_INTL("It's no good! It's impossible to aim when there are more than one Pokémon!")) if showMessages
- end
- next false
- end
- next true
- }
- )
- #------------------------------------------------------------------------------#
- # Pokemon_Storage
- #------------------------------------------------------------------------------#
- class PokemonStorage
- attr_reader :boxes
- attr_accessor :currentBox
- attr_writer :unlockedWallpapers
- BASICWALLPAPERQTY = 16
- def initialize(maxBoxes=NUM_STORAGE_BOXES,maxPokemon=30)
- @boxes = []
- for i in 0...maxBoxes
- @boxes[i] = PokemonBox.new(_INTL("Box {1}",i+1),maxPokemon)
- @boxes[i].background = i%BASICWALLPAPERQTY
- end
- @currentBox = 0
- @boxmode = -1
- @unlockedWallpapers = []
- for i in 0...allWallpapers.length
- @unlockedWallpapers[i] = false
- end
- end
- def allWallpapers
- return [
- # Basic wallpapers
- _INTL("Forest"),_INTL("City"),_INTL("Desert"),_INTL("Savanna"),
- _INTL("Crag"),_INTL("Volcano"),_INTL("Snow"),_INTL("Cave"),
- _INTL("Beach"),_INTL("Seafloor"),_INTL("River"),_INTL("Sky"),
- _INTL("Poké Center"),_INTL("Machine"),_INTL("Checks"),_INTL("Simple"),
- # Special wallpapers
- _INTL("Space"),_INTL("Backyard"),_INTL("Nostalgic 1"),_INTL("Torchic"),
- _INTL("Trio 1"),_INTL("PikaPika 1"),_INTL("Legend 1"),_INTL("Team Galactic 1"),
- _INTL("Distortion"),_INTL("Contest"),_INTL("Nostalgic 2"),_INTL("Croagunk"),
- _INTL("Trio 2"),_INTL("PikaPika 2"),_INTL("Legend 2"),_INTL("Team Galactic 2"),
- _INTL("Heart"),_INTL("Soul"),_INTL("Big Brother"),_INTL("Pokéathlon"),
- _INTL("Trio 3"),_INTL("Spiky Pika"),_INTL("Kimono Girl"),_INTL("Revival")
- ]
- end
- def unlockedWallpapers
- @unlockedWallpapers = [] if !@unlockedWallpapers
- return @unlockedWallpapers
- end
- def isAvailableWallpaper?(i)
- @unlockedWallpapers = [] if !@unlockedWallpapers
- return true if i<BASICWALLPAPERQTY
- return true if @unlockedWallpapers[i]
- return false
- end
- def availableWallpapers
- ret = [[],[]] # Names, IDs
- papers = allWallpapers
- @unlockedWallpapers = [] if !@unlockedWallpapers
- for i in 0...papers.length
- next if !isAvailableWallpaper?(i)
- ret[0].push(papers[i]); ret[1].push(i)
- end
- return ret
- end
- def party
- $Trainer.party
- end
- def party=(value)
- raise ArgumentError.new("Not supported")
- end
- def maxBoxes
- return @boxes.length
- end
- def maxPokemon(box)
- return 0 if box>=self.maxBoxes
- return (box<0) ? 6 : self[box].length
- end
- def full?
- for i in 0...self.maxBoxes
- return false if !@boxes[i].full?
- end
- return true
- end
- def pbFirstFreePos(box)
- if box==-1
- ret = self.party.nitems
- return (ret==6) ? -1 : ret
- else
- for i in 0...maxPokemon(box)
- return i if !self[box,i]
- end
- return -1
- end
- end
- def [](x,y=nil)
- if y==nil
- return (x==-1) ? self.party : @boxes[x]
- else
- for i in @boxes
- raise "Box is a Pokémon, not a box" if i.is_a?(PokeBattle_Pokemon)
- end
- return (x==-1) ? self.party[y] : @boxes[x][y]
- end
- end
- def []=(x,y,value)
- if x==-1
- self.party[y] = value
- else
- @boxes[x][y] = value
- end
- end
- def pbCopy(boxDst,indexDst,boxSrc,indexSrc)
- if indexDst<0 && boxDst<self.maxBoxes
- found = false
- for i in 0...maxPokemon(boxDst)
- next if self[boxDst,i]
- found = true
- indexDst = i
- break
- end
- return false if !found
- end
- if boxDst==-1 # Copying into party
- if $Trainer.partyplus>=1
- return false if self.party.nitems>=$Trainer.partyplus
- else
- return false if self.party.nitems>=6
- end
- self.party[self.party.length] = self[boxSrc,indexSrc]
- self.party.compact!
- else # Copying into box
- pkmn = self[boxSrc,indexSrc]
- raise "Trying to copy nil to storage" if !pkmn
- pkmn.formTime = nil if pkmn.respond_to?("formTime")
- pkmn.form = 0 if isConst?(pkmn.species,PBSpecies,:SHAYMIN)
- pkmn.heal
- self[boxDst,indexDst] = pkmn
- end
- return true
- end
- def pbMove(boxDst,indexDst,boxSrc,indexSrc)
- return false if !pbCopy(boxDst,indexDst,boxSrc,indexSrc)
- pbDelete(boxSrc,indexSrc)
- return true
- end
- def pbMoveCaughtToParty(pkmn)
- if $Trainer.partyplus>=1
- return false if self.party.nitems>=$Trainer.partyplus
- else
- return false if self.party.nitems>=6
- end
- self.party[self.party.length] = pkmn
- end
- def pbMoveCaughtToBox(pkmn,box)
- for i in 0...maxPokemon(box)
- if self[box,i]==nil
- if box>=0
- pkmn.formTime = nil if pkmn.respond_to?("formTime") && pkmn.formTime
- pkmn.form = 0 if isConst?(pkmn.species,PBSpecies,:SHAYMIN)
- pkmn.heal
- end
- self[box,i] = pkmn
- return true
- end
- end
- return false
- end
- def pbStoreCaught(pkmn)
- if @currentBox>=0
- pkmn.formTime = nil if pkmn.respond_to?("formTime")
- pkmn.form = 0 if isConst?(pkmn.species,PBSpecies,:SHAYMIN)
- pkmn.heal
- end
- for i in 0...maxPokemon(@currentBox)
- if self[@currentBox,i]==nil
- self[@currentBox,i] = pkmn
- return @currentBox
- end
- end
- for j in 0...self.maxBoxes
- for i in 0...maxPokemon(j)
- if self[j,i]==nil
- self[j,i] = pkmn
- @currentBox = j
- return @currentBox
- end
- end
- end
- return -1
- end
- def pbDelete(box,index)
- if self[box,index]
- self[box,index] = nil
- self.party.compact! if box==-1
- end
- end
- def clear
- for i in 0...self.maxBoxes
- @boxes[i].clear
- end
- end
- end
- #------------------------------------------------------------------------------#
- # PScreen_Party
- #------------------------------------------------------------------------------#
- #===============================================================================
- # Pokémon party panels
- #===============================================================================
- class PokemonPartyBlankPanel < SpriteWrapper
- attr_accessor :text
- def initialize(_pokemon,index,viewport=nil)
- super(viewport)
- #==============================================================================#
- #Since I assume no one will go above a Max party Limit of 10, I leave it to you#
- #To code them in. if you want a specific numeric, here is a list Of those that #
- #will be mathematically easy to fit into base essentials. #
- #160,150,144,140,135,130,128,126,120,117,112,110,108,105,104,100,99,98,96,91, #
- #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, #
- #40,39,36,35,33,32,30,28,27,26,25,24,22,21,20,18,16,15,14,13,12,11 #
- #============================================================================= #
- if $Trainer.partyplus==10
- self.x = [0,256, 0,256, 0,265, 0,265, 0,265][index]
- self.y = [0, 0, 64, 64,128,128,192,192,256,256][index]
- elsif $Trainer.partyplus==9
- self.x = [0,171,341, 0,171,342, 0,171,342][index]
- self.y = [0, 0, 0,107,107,107,214,214,214][index]
- elsif $Trainer.partyplus==8
- self.x = [0,256, 0,256, 0,265, 0,265][index]
- self.y = [0, 0, 80, 80,160,160,240,240][index]
- elsif $Trainer.partyplus==7
- self.x = [0, 74,146,220,294,336,440][index]
- self.y = [0, 0, 0, 0, 0, 0, 0][index]
- elsif $Trainer.partyplus==6
- self.x = [0,256, 0,256, 0,265][index]
- self.y = [0, 0,106,106,214,214][index]
- elsif $Trainer.partyplus==5
- self.x = [0, 0, 0, 0, 0][index]
- self.y = [0, 64,128,192,256][index]
- elsif $Trainer.partyplus==4
- self.x = [0,256, 0,256][index]
- self.y = [0, 0,160,160][index]
- elsif $Trainer.partyplus==3
- self.x = [0,171,342][index]
- self.y = [0, 0, 0][index]
- elsif $Trainer.partyplus==2
- self.x = [0,256][index]
- self.y = [0, 0][index]
- elsif $Trainer.partyplus==1
- self.x = [0][index]
- self.y = [0][index]
- else
- self.x = [0, Graphics.width/2][index%2]
- self.y = [0, 16, 96,112,192,208][index]
- end
- folder = $Trainer.partyplus
- if $Trainer.partyplus>=1
- @panelbgsprite = AnimatedBitmap.new("Graphics/Pictures/Party/PartyPlus/"+"#{folder}"+" - Party/panel_blank")
- else
- @panelbgsprite = AnimatedBitmap.new("Graphics/Pictures/Party/panel_blank")
- end
- self.bitmap = @panelbgsprite.bitmap
- @text = nil
- end
- def dispose
- @panelbgsprite.dispose
- super
- end
- def selected; return false; end
- def selected=(value); end
- def preselected; return false; end
- def preselected=(value); end
- def switching; return false; end
- def switching=(value); end
- def refresh; end
- end
- class PokemonPartyPanel < SpriteWrapper
- attr_reader :pokemon
- attr_reader :active
- attr_reader :selected
- attr_reader :preselected
- attr_reader :switching
- attr_reader :text
- def initialize(pokemon,index,viewport=nil)
- super(viewport)
- @pokemon = pokemon
- @active = (index==0) # true = rounded panel, false = rectangular panel
- @refreshing = true
- #==============================================================================#
- #Since I assume no one will go above a Max party Limit of 10, I leave it to you#
- #To code them in. if you want a specific numeric, here is a list Of those that #
- #will be mathematically easy to fit into base essentials. #
- #160,150,144,140,135,130,128,126,120,117,112,110,108,105,104,100,99,98,96,91, #
- #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, #
- #40,39,36,35,33,32,30,28,27,26,25,24,22,21,20,18,16,15,14,13,12,11 #
- #============================================================================= #
- if $Trainer.partyplus==10
- self.x = [0,256, 0,256, 0,265, 0,265, 0,265][index]
- self.y = [0, 0, 64, 64,128,128,192,192,256,256][index]
- elsif $Trainer.partyplus==9
- self.x = [0,171,341, 0,171,342, 0,171,342][index]
- self.y = [0, 0, 0,107,107,107,214,214,214][index]
- elsif $Trainer.partyplus==8
- self.x = [0,256, 0,256, 0,265, 0,265][index]
- self.y = [0, 0, 80, 80,160,160,240,240][index]
- elsif $Trainer.partyplus==7
- self.x = [0, 74,146,220,294,336,440][index]
- self.y = [0, 0, 0, 0, 0, 0, 0][index]
- elsif $Trainer.partyplus==6
- self.x = [0,256, 0,256, 0,265][index]
- self.y = [0, 0,106,106,214,214][index]
- elsif $Trainer.partyplus==5
- self.x = [0, 0, 0, 0, 0][index]
- self.y = [0, 64,128,192,256][index]
- elsif $Trainer.partyplus==4
- self.x = [0,256, 0,256][index]
- self.y = [0, 0,160,160][index]
- elsif $Trainer.partyplus==3
- self.x = [0,171,342][index]
- self.y = [0, 0, 0][index]
- elsif $Trainer.partyplus==2
- self.x = [0,256][index]
- self.y = [0, 0][index]
- elsif $Trainer.partyplus==1
- self.x = [0][index]
- self.y = [0][index]
- else
- self.x = [0, Graphics.width/2][index%2]
- self.y = [0, 16, 96,112,192,208][index]
- end
- @panelbgsprite = ChangelingSprite.new(0,0,viewport)
- @panelbgsprite.z = self.z
- if $Trainer.partyplus>=1
- folder = $Trainer.partyplus
- @panelbgsprite.addBitmap("able","Graphics/Pictures/Party/PartyPlus/"+"#{folder}"+" - Party/panel_rect")
- @panelbgsprite.addBitmap("ablesel","Graphics/Pictures/Party/PartyPlus/"+"#{folder}"+" - Party/panel_rect_sel")
- @panelbgsprite.addBitmap("fainted","Graphics/Pictures/Party/PartyPlus/"+"#{folder}"+" - Party/panel_rect_faint")
- @panelbgsprite.addBitmap("faintedsel","Graphics/Pictures/Party/PartyPlus/"+"#{folder}"+" - Party/panel_rect_faint_sel")
- @panelbgsprite.addBitmap("swap","Graphics/Pictures/Party/PartyPlus/"+"#{folder}"+" - Party/panel_rect_swap")
- @panelbgsprite.addBitmap("swapsel","Graphics/Pictures/Party/PartyPlus/"+"#{folder}"+" - Party/panel_rect_swap_sel")
- @panelbgsprite.addBitmap("swapsel2","Graphics/Pictures/Party/PartyPlus/"+"#{folder}"+" - Party/panel_rect_swap_sel2")
- @panelbgsprite.addBitmap("benched","Graphics/Pictures/Party/PartyPlus/"+"#{folder}"+" - Party/panel_rect_bench")
- @panelbgsprite.addBitmap("benchedsel","Graphics/Pictures/Party/PartyPlus/"+"#{folder}"+" - Party/panel_rect_bench_sel")
- elsif @active # Rounded panel
- @panelbgsprite.addBitmap("able","Graphics/Pictures/Party/panel_round")
- @panelbgsprite.addBitmap("ablesel","Graphics/Pictures/Party/panel_round_sel")
- @panelbgsprite.addBitmap("fainted","Graphics/Pictures/Party/panel_round_faint")
- @panelbgsprite.addBitmap("faintedsel","Graphics/Pictures/Party/panel_round_faint_sel")
- @panelbgsprite.addBitmap("swap","Graphics/Pictures/Party/panel_round_swap")
- @panelbgsprite.addBitmap("swapsel","Graphics/Pictures/Party/panel_round_swap_sel")
- @panelbgsprite.addBitmap("swapsel2","Graphics/Pictures/Party/panel_round_swap_sel2")
- else # Rectangular panel
- @panelbgsprite.addBitmap("able","Graphics/Pictures/Party/panel_rect")
- @panelbgsprite.addBitmap("ablesel","Graphics/Pictures/Party/panel_rect_sel")
- @panelbgsprite.addBitmap("fainted","Graphics/Pictures/Party/panel_rect_faint")
- @panelbgsprite.addBitmap("faintedsel","Graphics/Pictures/Party/panel_rect_faint_sel")
- @panelbgsprite.addBitmap("swap","Graphics/Pictures/Party/panel_rect_swap")
- @panelbgsprite.addBitmap("swapsel","Graphics/Pictures/Party/panel_rect_swap_sel")
- @panelbgsprite.addBitmap("swapsel2","Graphics/Pictures/Party/panel_rect_swap_sel2")
- end
- @hpbgsprite = ChangelingSprite.new(0,0,viewport)
- @hpbgsprite.z = self.z+1
- @hpbgsprite.addBitmap("able","Graphics/Pictures/Party/overlay_hp_back")
- @hpbgsprite.addBitmap("fainted","Graphics/Pictures/Party/overlay_hp_back_faint")
- @hpbgsprite.addBitmap("swap","Graphics/Pictures/Party/overlay_hp_back_swap")
- @ballsprite = ChangelingSprite.new(0,0,viewport)
- @ballsprite.z = self.z+1
- @ballsprite.addBitmap("desel","Graphics/Pictures/Party/icon_ball")
- @ballsprite.addBitmap("sel","Graphics/Pictures/Party/icon_ball_sel")
- @pkmnsprite = PokemonIconSprite.new(pokemon,viewport)
- @pkmnsprite.setOffset(PictureOrigin::Center)
- @pkmnsprite.active = @active
- @pkmnsprite.z = self.z+2
- @helditemsprite = HeldItemIconSprite.new(0,0,@pokemon,viewport)
- @helditemsprite.z = self.z+3
- @overlaysprite = BitmapSprite.new(Graphics.width,Graphics.height,viewport)
- @overlaysprite.z = self.z+4
- @hpbar = AnimatedBitmap.new("Graphics/Pictures/Party/overlay_hp")
- @statuses = AnimatedBitmap.new(_INTL("Graphics/Pictures/statuses"))
- if $Trainer.partyplus>=1
- @pkmnsprite.zoom_x = 1
- @pkmnsprite.zoom_y = 1
- @ballsprite.zoom_x = 1
- @ballsprite.zoom_y = 1
- end
- @selected = false
- @preselected = false
- @switching = false
- @text = nil
- @refreshBitmap = true
- @refreshing = false
- refresh
- end
- def dispose
- @panelbgsprite.dispose
- @hpbgsprite.dispose
- @ballsprite.dispose
- @pkmnsprite.dispose
- @helditemsprite.dispose
- @overlaysprite.bitmap.dispose
- @overlaysprite.dispose
- @hpbar.dispose
- @statuses.dispose
- super
- end
- def x=(value)
- super
- refresh
- end
- def y=(value)
- super
- refresh
- end
- def color=(value)
- super
- refresh
- end
- def text=(value)
- if @text!=value
- @text = value
- @refreshBitmap = true
- refresh
- end
- end
- def pokemon=(value)
- @pokemon = value
- @pkmnsprite.pokemon = value if @pkmnsprite && !@pkmnsprite.disposed?
- @helditemsprite.pokemon = value if @helditemsprite && !@helditemsprite.disposed?
- @refreshBitmap = true
- refresh
- end
- def selected=(value)
- if @selected!=value
- @selected = value
- refresh
- end
- end
- def preselected=(value)
- if @preselected!=value
- @preselected = value
- refresh
- end
- end
- def switching=(value)
- if @switching!=value
- @switching = value
- refresh
- end
- end
- def hp; return @pokemon.hp; end
- def refresh
- return if disposed?
- return if @refreshing
- @refreshing = true
- if @panelbgsprite && !@panelbgsprite.disposed?
- if self.selected
- if self.preselected; @panelbgsprite.changeBitmap("swapsel2")
- elsif @switching; @panelbgsprite.changeBitmap("swapsel")
- elsif @pokemon.fainted?; @panelbgsprite.changeBitmap("faintedsel")
- elsif @pokemon.benched?; @panelbgsprite.changeBitmap("benchedsel")
- else; @panelbgsprite.changeBitmap("ablesel")
- end
- else
- if self.preselected; @panelbgsprite.changeBitmap("swap")
- elsif @pokemon.fainted?; @panelbgsprite.changeBitmap("fainted")
- elsif @pokemon.benched?; @panelbgsprite.changeBitmap("benched")
- else; @panelbgsprite.changeBitmap("able")
- end
- end
- @panelbgsprite.x = self.x
- @panelbgsprite.y = self.y
- @panelbgsprite.color = self.color
- end
- if @hpbgsprite && !@hpbgsprite.disposed?
- @hpbgsprite.visible = (!@pokemon.egg? && !(@text && @text.length>0))
- if @hpbgsprite.visible
- if self.preselected || (self.selected && @switching); @hpbgsprite.changeBitmap("swap")
- elsif @pokemon.fainted?; @hpbgsprite.changeBitmap("fainted")
- else; @hpbgsprite.changeBitmap("able")
- end
- @hpbgsprite.x = self.x+96
- @hpbgsprite.y = self.y+50
- @hpbgsprite.color = self.color
- end
- end
- if @ballsprite && !@ballsprite.disposed?
- @ballsprite.changeBitmap((self.selected) ? "sel" : "desel")
- @ballsprite.x = self.x+10
- @ballsprite.y = self.y
- @ballsprite.color = self.color
- end
- if @pkmnsprite && !@pkmnsprite.disposed?
- @pkmnsprite.x = self.x+60
- @pkmnsprite.y = self.y+40
- @pkmnsprite.color = self.color
- @pkmnsprite.selected = self.selected
- end
- if @helditemsprite && !@helditemsprite.disposed?
- if @helditemsprite.visible
- @helditemsprite.x = self.x+62
- @helditemsprite.y = self.y+48
- @helditemsprite.color = self.color
- end
- end
- if @overlaysprite && !@overlaysprite.disposed?
- @overlaysprite.x = self.x
- @overlaysprite.y = self.y
- @overlaysprite.color = self.color
- end
- if @refreshBitmap
- @refreshBitmap = false
- @overlaysprite.bitmap.clear if @overlaysprite.bitmap
- basecolor = Color.new(248,248,248)
- shadowcolor = Color.new(40,40,40)
- pbSetSystemFont(@overlaysprite.bitmap)
- textpos = []
- # Draw Pokémon name
- textpos.push([@pokemon.name,96,16,0,basecolor,shadowcolor])
- if !@pokemon.egg?
- if !@text || @text.length==0
- # Draw HP numbers
- textpos.push([sprintf("% 3d /% 3d",@pokemon.hp,@pokemon.totalhp),224,60,1,basecolor,shadowcolor])
- # Draw HP bar
- if @pokemon.hp>0
- w = @pokemon.hp*96*1.0/@pokemon.totalhp
- w = 1 if w<1
- w = ((w/2).round)*2
- hpzone = 0
- hpzone = 1 if @pokemon.hp<=(@pokemon.totalhp/2).floor
- hpzone = 2 if @pokemon.hp<=(@pokemon.totalhp/4).floor
- hprect = Rect.new(0,hpzone*8,w,8)
- @overlaysprite.bitmap.blt(128,52,@hpbar.bitmap,hprect)
- end
- # Draw status
- status = -1
- status = 6 if @pokemon.pokerusStage==1
- status = @pokemon.status-1 if @pokemon.status>0
- status = 5 if @pokemon.hp<=0
- if status>=0
- statusrect = Rect.new(0,16*status,44,16)
- @overlaysprite.bitmap.blt(78,68,@statuses.bitmap,statusrect)
- end
- end
- # Draw gender symbol
- if @pokemon.male?
- textpos.push([_INTL("♂"),224,16,0,Color.new(0,112,248),Color.new(120,184,232)])
- elsif @pokemon.female?
- textpos.push([_INTL("♀"),224,16,0,Color.new(232,32,16),Color.new(248,168,184)])
- end
- # Draw shiny icon
- if @pokemon.shiny?
- pbDrawImagePositions(@overlaysprite.bitmap,[[
- "Graphics/Pictures/shiny",80,48,0,0,16,16]])
- end
- end
- pbDrawTextPositions(@overlaysprite.bitmap,textpos)
- # Draw level text
- if !@pokemon.egg?
- pbDrawImagePositions(@overlaysprite.bitmap,[[
- "Graphics/Pictures/Party/overlay_lv",20,70,0,0,22,14]])
- pbSetSmallFont(@overlaysprite.bitmap)
- pbDrawTextPositions(@overlaysprite.bitmap,[
- [@pokemon.level.to_s,42,62,0,basecolor,shadowcolor]
- ])
- end
- # Draw annotation text
- if @text && @text.length>0
- pbSetSystemFont(@overlaysprite.bitmap)
- pbDrawTextPositions(@overlaysprite.bitmap,[
- [@text,96,58,0,basecolor,shadowcolor]
- ])
- end
- end
- @refreshing = false
- end
- def update
- super
- @panelbgsprite.update if @panelbgsprite && !@panelbgsprite.disposed?
- @hpbgsprite.update if @hpbgsprite && !@hpbgsprite.disposed?
- @ballsprite.update if @ballsprite && !@ballsprite.disposed?
- @pkmnsprite.update if @pkmnsprite && !@pkmnsprite.disposed?
- @helditemsprite.update if @helditemsprite && !@helditemsprite.disposed?
- end
- end
- #===============================================================================
- # Pokémon party visuals
- #===============================================================================
- class PokemonParty_Scene
- def pbStartScene(party,starthelptext,annotations=nil,multiselect=false)
- if ALLOW_BENCHING && $Trainer.partyplus>=1
- setBenchedParty
- end
- @sprites = {}
- @party = party
- @viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
- @viewport.z = 99999
- @multiselect = multiselect
- if $Trainer.partyplus>=1
- addBackgroundPlane(@sprites,"partybg","Party/PartyPlus/bg",@viewport)
- else
- addBackgroundPlane(@sprites,"partybg","Party/bg",@viewport)
- end
- @sprites["messagebox"] = Window_AdvancedTextPokemon.new("")
- @sprites["messagebox"].viewport = @viewport
- @sprites["messagebox"].visible = false
- @sprites["messagebox"].letterbyletter = true
- pbBottomLeftLines(@sprites["messagebox"],2)
- @sprites["helpwindow"] = Window_UnformattedTextPokemon.new(starthelptext)
- @sprites["helpwindow"].viewport = @viewport
- @sprites["helpwindow"].visible = true
- pbBottomLeftLines(@sprites["helpwindow"],1)
- pbSetHelpText(starthelptext)
- # Add party Pokémon sprites
- if $Trainer.partyplus>=1
- for i in 0...$Trainer.partyplus
- if @party[i]
- @sprites["pokemon#{i}"] = PokemonPartyPanel.new(@party[i],i,@viewport)
- else
- @sprites["pokemon#{i}"] = PokemonPartyBlankPanel.new(@party[i],i,@viewport)
- end
- @sprites["pokemon#{i}"].text = annotations[i] if annotations
- end
- else
- for i in 0...6
- if @party[i]
- @sprites["pokemon#{i}"] = PokemonPartyPanel.new(@party[i],i,@viewport)
- else
- @sprites["pokemon#{i}"] = PokemonPartyBlankPanel.new(@party[i],i,@viewport)
- end
- @sprites["pokemon#{i}"].text = annotations[i] if annotations
- end
- end
- if $Trainer.partyplus>=1
- p = $Trainer.partyplus
- u = p+1
- else
- p = 6
- end
- if @multiselect
- @sprites["pokemon#{p}"] = PokemonPartyConfirmSprite.new(@viewport)
- @sprites["pokemon#{u}"] = PokemonPartyCancelSprite2.new(@viewport)
- else
- @sprites["pokemon#{p}"] = PokemonPartyCancelSprite.new(@viewport)
- end
- # Select first Pokémon
- @activecmd = 0
- @sprites["pokemon0"].selected = true
- pbFadeInAndShow(@sprites) { update }
- end
- def pbEndScene
- pbFadeOutAndHide(@sprites) { update }
- pbDisposeSpriteHash(@sprites)
- @viewport.dispose
- end
- def pbDisplay(text)
- @sprites["messagebox"].text = text
- @sprites["messagebox"].visible = true
- @sprites["helpwindow"].visible = false
- pbPlayDecisionSE
- loop do
- Graphics.update
- Input.update
- self.update
- if @sprites["messagebox"].busy?
- if Input.trigger?(Input::C)
- pbPlayDecisionSE if @sprites["messagebox"].pausing?
- @sprites["messagebox"].resume
- end
- else
- if Input.trigger?(Input::B) || Input.trigger?(Input::C)
- break
- end
- end
- end
- @sprites["messagebox"].visible = false
- @sprites["helpwindow"].visible = true
- end
- def pbDisplayConfirm(text)
- ret = -1
- @sprites["messagebox"].text = text
- @sprites["messagebox"].visible = true
- @sprites["helpwindow"].visible = false
- using(cmdwindow = Window_CommandPokemon.new([_INTL("Yes"),_INTL("No")])) {
- cmdwindow.visible = false
- pbBottomRight(cmdwindow)
- cmdwindow.y -= @sprites["messagebox"].height
- cmdwindow.z = @viewport.z+1
- loop do
- Graphics.update
- Input.update
- cmdwindow.visible = true if !@sprites["messagebox"].busy?
- cmdwindow.update
- self.update
- if !@sprites["messagebox"].busy?
- if Input.trigger?(Input::B)
- ret = false
- break
- elsif Input.trigger?(Input::C) && @sprites["messagebox"].resume
- ret = (cmdwindow.index==0)
- break
- end
- end
- end
- }
- @sprites["messagebox"].visible = false
- @sprites["helpwindow"].visible = true
- return ret
- end
- def pbShowCommands(helptext,commands,index=0)
- ret = -1
- helpwindow = @sprites["helpwindow"]
- helpwindow.visible = true
- using(cmdwindow = Window_CommandPokemonColor.new(commands)) {
- cmdwindow.z = @viewport.z+1
- cmdwindow.index = index
- pbBottomRight(cmdwindow)
- helpwindow.resizeHeightToFit(helptext,Graphics.width-cmdwindow.width)
- helpwindow.text = helptext
- pbBottomLeft(helpwindow)
- loop do
- Graphics.update
- Input.update
- cmdwindow.update
- self.update
- if Input.trigger?(Input::B)
- pbPlayCancelSE
- ret = -1
- break
- elsif Input.trigger?(Input::C)
- pbPlayDecisionSE
- ret = cmdwindow.index
- break
- end
- end
- }
- return ret
- end
- def pbSetHelpText(helptext)
- helpwindow = @sprites["helpwindow"]
- pbBottomLeftLines(helpwindow,1)
- helpwindow.text = helptext
- helpwindow.width = 398
- helpwindow.visible = true
- end
- def pbHasAnnotations?
- return @sprites["pokemon0"].text!=nil
- end
- def pbAnnotate(annot)
- if $Trainer.partyplus>=1
- for i in 0...$Trainer.partyplus6
- @sprites["pokemon#{i}"].text = (annot) ? annot[i] : nil
- end
- else
- for i in 0...6
- @sprites["pokemon#{i}"].text = (annot) ? annot[i] : nil
- end
- end
- end
- def pbSelect(item)
- @activecmd = item
- if $Trainer.partyplus>=1
- numsprites = (@multiselect) ? $Trainer.partyplus+2 : $Trainer.partyplus+1
- else
- numsprites = (@multiselect) ? 8 : 7
- end
- for i in 0...numsprites
- @sprites["pokemon#{i}"].selected = (i==@activecmd)
- end
- end
- def pbPreSelect(item)
- @activecmd = item
- end
- def pbSwitchBegin(oldid,newid)
- pbSEPlay("GUI party switch")
- oldsprite = @sprites["pokemon#{oldid}"]
- newsprite = @sprites["pokemon#{newid}"]
- timeTaken = Graphics.frame_rate*4/10
- distancePerFrame = (Graphics.width/(2.0*timeTaken)).ceil
- timeTaken.times do
- oldsprite.x += (oldid&1)==0 ? -distancePerFrame : distancePerFrame
- newsprite.x += (newid&1)==0 ? -distancePerFrame : distancePerFrame
- Graphics.update
- Input.update
- self.update
- end
- end
- def pbSwitchEnd(oldid,newid)
- pbSEPlay("GUI party switch")
- oldsprite = @sprites["pokemon#{oldid}"]
- newsprite = @sprites["pokemon#{newid}"]
- oldsprite.pokemon = @party[oldid]
- newsprite.pokemon = @party[newid]
- timeTaken = Graphics.frame_rate*4/10
- distancePerFrame = (Graphics.width/(2.0*timeTaken)).ceil
- timeTaken.times do
- oldsprite.x -= (oldid&1)==0 ? -distancePerFrame : distancePerFrame
- newsprite.x -= (newid&1)==0 ? -distancePerFrame : distancePerFrame
- Graphics.update
- Input.update
- self.update
- end
- if $Trainer.partyplus>=1
- for i in 0...$Trainer.partyplus
- @sprites["pokemon#{i}"].preselected = false
- @sprites["pokemon#{i}"].switching = false
- end
- else
- for i in 0...6
- @sprites["pokemon#{i}"].preselected = false
- @sprites["pokemon#{i}"].switching = false
- end
- end
- pbRefresh
- end
- def pbClearSwitching
- if$Trainer.partyplus>=1
- for i in 0...$Trainer.partyplus
- @sprites["pokemon#{i}"].preselected = false
- @sprites["pokemon#{i}"].switching = false
- end
- else
- for i in 0...6
- @sprites["pokemon#{i}"].preselected = false
- @sprites["pokemon#{i}"].switching = false
- end
- end
- end
- def pbSummary(pkmnid,inbattle=false)
- oldsprites = pbFadeOutAndHide(@sprites)
- scene = PokemonSummary_Scene.new
- screen = PokemonSummaryScreen.new(scene,inbattle)
- screen.pbStartScreen(@party,pkmnid)
- yield if block_given?
- pbFadeInAndShow(@sprites,oldsprites)
- end
- def pbChooseItem(bag)
- ret = 0
- pbFadeOutIn {
- scene = PokemonBag_Scene.new
- screen = PokemonBagScreen.new(scene,bag)
- ret = screen.pbChooseItemScreen(Proc.new { |item| pbCanHoldItem?(item) })
- yield if block_given?
- }
- return ret
- end
- def pbUseItem(bag,pokemon)
- ret = 0
- pbFadeOutIn {
- scene = PokemonBag_Scene.new
- screen = PokemonBagScreen.new(scene,bag)
- ret = screen.pbChooseItemScreen(Proc.new { |item|
- next false if !pbCanUseOnPokemon?(item)
- if pbIsMachine?(item)
- move = pbGetMachine(item)
- next false if pokemon.hasMove?(move) || !pokemon.compatibleWithMove?(move)
- end
- next true
- })
- yield if block_given?
- }
- return ret
- end
- def pbChoosePokemon(switching=false,initialsel=-1,canswitch=0)
- if $Trainer.partyplus>=1
- plus = $Trainer.partyplus
- else
- plus = 6
- end
- for i in 0...plus
- @sprites["pokemon#{i}"].preselected = (switching && i==@activecmd)
- @sprites["pokemon#{i}"].switching = switching
- end
- @activecmd = initialsel if initialsel>=0
- pbRefresh
- loop do
- Graphics.update
- Input.update
- self.update
- oldsel = @activecmd
- key = -1
- key = Input::DOWN if Input.repeat?(Input::DOWN)
- key = Input::RIGHT if Input.repeat?(Input::RIGHT)
- key = Input::LEFT if Input.repeat?(Input::LEFT)
- key = Input::UP if Input.repeat?(Input::UP)
- if key>=0
- @activecmd = pbChangeSelection(key,@activecmd)
- end
- if @activecmd!=oldsel # Changing selection
- pbPlayCursorSE
- numsprites = (@multiselect) ? plaus+2 : plus+1
- for i in 0...numsprites
- @sprites["pokemon#{i}"].selected = (i==@activecmd)
- end
- end
- cancelsprite = (@multiselect) ? plus+1 : plus
- if Input.trigger?(Input::A) && canswitch==1 && @activecmd!=cancelsprite
- pbPlayDecisionSE
- return [1,@activecmd]
- elsif Input.trigger?(Input::A) && canswitch==2
- return -1
- elsif Input.trigger?(Input::B)
- pbPlayCloseMenuSE if !switching
- return -1
- elsif Input.trigger?(Input::C)
- if @activecmd==cancelsprite
- (switching) ? pbPlayDecisionSE : pbPlayCloseMenuSE
- return -1
- else
- pbPlayDecisionSE
- return @activecmd
- end
- end
- end
- end
- def pbChangeSelection(key,currentsel)
- numsprites = (@multiselect) ? 8 : 7
- numsprites = (@multiselect) ? $Trainer.partyplus+2 : $Trainer.partyplus+1 if $Trainer.partyplus>=1
- if $Trainer.partyplus==10
- case key
- when Input::LEFT
- begin
- currentsel -= 1
- end while currentsel>0 && currentsel<@party.length && !@party[currentsel]
- if currentsel>=@party.length && currentsel<10
- currentsel = @party.length-1
- end
- currentsel = numsprites-1 if currentsel<0
- when Input::RIGHT
- begin
- currentsel += 1
- end while currentsel<@party.length && !@party[currentsel]
- if currentsel==@party.length
- currentsel = 10
- elsif currentsel==numsprites
- currentsel = 0
- end
- when Input::UP
- if currentsel>=10
- begin
- currentsel -= 1
- end while currentsel>0 && !@party[currentsel]
- else
- begin
- currentsel -= 2
- end while currentsel>0 && !@party[currentsel]
- end
- if currentsel>=@party.length && currentsel<10
- currentsel = @party.length-1
- end
- currentsel = numsprites-1 if currentsel<0
- when Input::DOWN
- if currentsel>=9
- currentsel += 1
- else
- currentsel += 2
- currentsel = 10 if currentsel<10 && !@party[currentsel]
- end
- if currentsel>=@party.length && currentsel<10
- currentsel = 10
- elsif currentsel>=numsprites
- currentsel = 0
- end
- end
- elsif $Trainer.partyplus==9
- case key
- when Input::LEFT
- begin
- currentsel -= 1
- end while currentsel>0 && currentsel<@party.length && !@party[currentsel]
- if currentsel>=@party.length && currentsel<9
- currentsel = @party.length-1
- end
- currentsel = numsprites-1 if currentsel<0
- when Input::RIGHT
- begin
- currentsel += 1
- end while currentsel<@party.length && !@party[currentsel]
- if currentsel==@party.length
- currentsel = 9
- elsif currentsel==numsprites
- currentsel = 0
- end
- when Input::UP
- if currentsel>=9
- begin
- currentsel -= 1
- end while currentsel>0 && !@party[currentsel]
- else
- begin
- currentsel -= 3
- end while currentsel>0 && !@party[currentsel]
- end
- if currentsel>=@party.length && currentsel<9
- currentsel = @party.length-1
- end
- currentsel = numsprites-1 if currentsel<0
- when Input::DOWN
- if currentsel>=7
- currentsel += 1
- else
- currentsel += 3
- currentsel = 9 if currentsel<9 && !@party[currentsel]
- end
- if currentsel>=@party.length && currentsel<9
- currentsel = 9
- elsif currentsel>=numsprites
- currentsel = 0
- end
- end
- elsif $Trainer.partyplus==8
- case key
- when Input::LEFT
- begin
- currentsel -= 1
- end while currentsel>0 && currentsel<@party.length && !@party[currentsel]
- if currentsel>=@party.length && currentsel<8
- currentsel = @party.length-1
- end
- currentsel = numsprites-1 if currentsel<0
- when Input::RIGHT
- begin
- currentsel += 1
- end while currentsel<@party.length && !@party[currentsel]
- if currentsel==@party.length
- currentsel = 8
- elsif currentsel==numsprites
- currentsel = 0
- end
- when Input::UP
- if currentsel>=8
- begin
- currentsel -= 1
- end while currentsel>0 && !@party[currentsel]
- else
- begin
- currentsel -= 2
- end while currentsel>0 && !@party[currentsel]
- end
- if currentsel>=@party.length && currentsel<8
- currentsel = @party.length-1
- end
- currentsel = numsprites-1 if currentsel<0
- when Input::DOWN
- if currentsel>=7
- currentsel += 1
- else
- currentsel += 2
- currentsel = 8 if currentsel<8 && !@party[currentsel]
- end
- if currentsel>=@party.length && currentsel<8
- currentsel = 8
- elsif currentsel>=numsprites
- currentsel = 0
- end
- end
- elsif $Trainer.partyplus==7
- case key
- when Input::LEFT
- begin
- currentsel -= 1
- end while currentsel>0 && currentsel<@party.length && !@party[currentsel]
- if currentsel>=@party.length && currentsel<7
- currentsel = @party.length-1
- end
- currentsel = numsprites-1 if currentsel<0
- when Input::RIGHT
- begin
- currentsel += 1
- end while currentsel<@party.length && !@party[currentsel]
- if currentsel==@party.length
- currentsel = 7
- elsif currentsel==numsprites
- currentsel = 0
- end
- when Input::UP
- if currentsel>=7
- begin
- currentsel -= 1
- end while currentsel>0 && !@party[currentsel]
- else
- begin
- currentsel -= 1
- end while currentsel>0 && !@party[currentsel]
- end
- if currentsel>=@party.length && currentsel<7
- currentsel = @party.length-1
- end
- currentsel = numsprites-1 if currentsel<0
- when Input::DOWN
- if currentsel>=6
- currentsel += 1
- else
- currentsel += 1
- currentsel = 7 if currentsel<7 && !@party[currentsel]
- end
- if currentsel>=@party.length && currentsel<7
- currentsel = 7
- elsif currentsel>=numsprites
- currentsel = 0
- end
- end
- elsif $Trainer.partyplus==5
- case key
- when Input::LEFT
- begin
- currentsel -= 1
- end while currentsel>0 && currentsel<@party.length && !@party[currentsel]
- if currentsel>=@party.length && currentsel<5
- currentsel = @party.length-1
- end
- currentsel = numsprites-1 if currentsel<0
- when Input::RIGHT
- begin
- currentsel += 1
- end while currentsel<@party.length && !@party[currentsel]
- if currentsel==@party.length
- currentsel = 5
- elsif currentsel==numsprites
- currentsel = 0
- end
- when Input::UP
- if currentsel>=5
- begin
- currentsel -= 1
- end while currentsel>0 && !@party[currentsel]
- else
- begin
- currentsel -= 1
- end while currentsel>0 && !@party[currentsel]
- end
- if currentsel>=@party.length && currentsel<5
- currentsel = @party.length-1
- end
- currentsel = numsprites-1 if currentsel<0
- when Input::DOWN
- if currentsel>=4
- currentsel += 1
- else
- currentsel += 1
- currentsel = 5 if currentsel<5 && !@party[currentsel]
- end
- if currentsel>=@party.length && currentsel<5
- currentsel = 5
- elsif currentsel>=numsprites
- currentsel = 0
- end
- end
- elsif $Trainer.partyplus==4
- case key
- when Input::LEFT
- begin
- currentsel -= 1
- end while currentsel>0 && currentsel<@party.length && !@party[currentsel]
- if currentsel>=@party.length && currentsel<4
- currentsel = @party.length-1
- end
- currentsel = numsprites-1 if currentsel<0
- when Input::RIGHT
- begin
- currentsel += 1
- end while currentsel<@party.length && !@party[currentsel]
- if currentsel==@party.length
- currentsel = 4
- elsif currentsel==numsprites
- currentsel = 0
- end
- when Input::UP
- if currentsel>=4
- begin
- currentsel -= 1
- end while currentsel>0 && !@party[currentsel]
- else
- begin
- currentsel -= 2
- end while currentsel>0 && !@party[currentsel]
- end
- if currentsel>=@party.length && currentsel<4
- currentsel = @party.length-1
- end
- currentsel = numsprites-1 if currentsel<0
- when Input::DOWN
- if currentsel>=3
- currentsel += 1
- else
- currentsel += 2
- currentsel = 4 if currentsel<4 && !@party[currentsel]
- end
- if currentsel>=@party.length && currentsel<4
- currentsel = 4
- elsif currentsel>=numsprites
- currentsel = 0
- end
- end
- elsif $Trainer.partyplus==3
- case key
- when Input::LEFT
- begin
- currentsel -= 1
- end while currentsel>0 && currentsel<@party.length && !@party[currentsel]
- if currentsel>=@party.length && currentsel<3
- currentsel = @party.length-1
- end
- currentsel = numsprites-1 if currentsel<0
- when Input::RIGHT
- begin
- currentsel += 1
- end while currentsel<@party.length && !@party[currentsel]
- if currentsel==@party.length
- currentsel = 3
- elsif currentsel==numsprites
- currentsel = 0
- end
- when Input::UP
- if currentsel>=3
- begin
- currentsel -= 1
- end while currentsel>0 && !@party[currentsel]
- else
- begin
- currentsel -= 1
- end while currentsel>0 && !@party[currentsel]
- end
- if currentsel>=@party.length && currentsel<3
- currentsel = @party.length-1
- end
- currentsel = numsprites-1 if currentsel<0
- when Input::DOWN
- if currentsel>=3
- currentsel += 1
- else
- currentsel += 1
- currentsel = 3 if currentsel<3 && !@party[currentsel]
- end
- if currentsel>=@party.length && currentsel<3
- currentsel = 3
- elsif currentsel>=numsprites
- currentsel = 0
- end
- end
- elsif $Trainer.partyplus==2
- case key
- when Input::LEFT
- begin
- currentsel -= 1
- end while currentsel>0 && currentsel<@party.length && !@party[currentsel]
- if currentsel>=@party.length && currentsel<2
- currentsel = @party.length-1
- end
- currentsel = numsprites-1 if currentsel<0
- when Input::RIGHT
- begin
- currentsel += 1
- end while currentsel<@party.length && !@party[currentsel]
- if currentsel==@party.length
- currentsel = 2
- elsif currentsel==numsprites
- currentsel = 0
- end
- when Input::UP
- if currentsel>=2
- begin
- currentsel -= 1
- end while currentsel>0 && !@party[currentsel]
- else
- begin
- currentsel -= 2
- end while currentsel>0 && !@party[currentsel]
- end
- if currentsel>=@party.length && currentsel<2
- currentsel = @party.length-1
- end
- currentsel = numsprites-1 if currentsel<0
- when Input::DOWN
- if currentsel>=2
- currentsel += 1
- else
- currentsel += 2
- currentsel = 2 if currentsel<2 && !@party[currentsel]
- end
- if currentsel>=@party.length && currentsel<2
- currentsel = 2
- elsif currentsel>=numsprites
- currentsel = 0
- end
- end
- elsif $Trainer.partyplus==1
- case key
- when Input::LEFT
- begin
- currentsel -= 1
- end while currentsel>0 && currentsel<@party.length && !@party[currentsel]
- if currentsel>=@party.length && currentsel<1
- currentsel = @party.length-1
- end
- currentsel = numsprites-1 if currentsel<0
- when Input::RIGHT
- begin
- currentsel += 1
- end while currentsel<@party.length && !@party[currentsel]
- if currentsel==@party.length
- currentsel = 1
- elsif currentsel==numsprites
- currentsel = 0
- end
- when Input::UP
- if currentsel>=1
- begin
- currentsel -= 1
- end while currentsel>0 && !@party[currentsel]
- else
- begin
- currentsel -= 1
- end while currentsel>0 && !@party[currentsel]
- end
- if currentsel>=@party.length && currentsel<1
- currentsel = @party.length-1
- end
- currentsel = numsprites-1 if currentsel<0
- when Input::DOWN
- if currentsel>=1
- currentsel += 1
- else
- currentsel += 1
- currentsel = 1 if currentsel<1 && !@party[currentsel]
- end
- if currentsel>=@party.length && currentsel<1
- currentsel = 1
- elsif currentsel>=numsprites
- currentsel = 0
- end
- end
- else
- case key
- when Input::LEFT
- begin
- currentsel -= 1
- end while currentsel>0 && currentsel<@party.length && !@party[currentsel]
- if currentsel>=@party.length && currentsel<6
- currentsel = @party.length-1
- end
- currentsel = numsprites-1 if currentsel<0
- when Input::RIGHT
- begin
- currentsel += 1
- end while currentsel<@party.length && !@party[currentsel]
- if currentsel==@party.length
- currentsel = 6
- elsif currentsel==numsprites
- currentsel = 0
- end
- when Input::UP
- if currentsel>=6
- begin
- currentsel -= 1
- end while currentsel>0 && !@party[currentsel]
- else
- begin
- currentsel -= 2
- end while currentsel>0 && !@party[currentsel]
- end
- if currentsel>=@party.length && currentsel<6
- currentsel = @party.length-1
- end
- currentsel = numsprites-1 if currentsel<0
- when Input::DOWN
- if currentsel>=5
- currentsel += 1
- else
- currentsel += 2
- currentsel = 6 if currentsel<6 && !@party[currentsel]
- end
- if currentsel>=@party.length && currentsel<6
- currentsel = 6
- elsif currentsel>=numsprites
- currentsel = 0
- end
- end
- end
- return currentsel
- end
- def pbHardRefresh
- oldtext = []
- lastselected = -1
- if $Trainer.partyplus>=1
- for i in 0...$Trainer.partyplus
- oldtext.push(@sprites["pokemon#{i}"].text)
- lastselected = i if @sprites["pokemon#{i}"].selected
- @sprites["pokemon#{i}"].dispose
- end
- else
- for i in 0...6
- oldtext.push(@sprites["pokemon#{i}"].text)
- lastselected = i if @sprites["pokemon#{i}"].selected
- @sprites["pokemon#{i}"].dispose
- end
- end
- lastselected = @party.length-1 if lastselected>=@party.length
- lastselected = 0 if lastselected<0
- if $Trainer.partyplus>=1
- for i in 0...$Trainer.partyplus
- if @party[i]
- @sprites["pokemon#{i}"] = PokemonPartyPanel.new(@party[i],i,@viewport)
- else
- @sprites["pokemon#{i}"] = PokemonPartyBlankPanel.new(@party[i],i,@viewport)
- end
- @sprites["pokemon#{i}"].text = oldtext[i]
- end
- else
- for i in 0...6
- if @party[i]
- @sprites["pokemon#{i}"] = PokemonPartyPanel.new(@party[i],i,@viewport)
- else
- @sprites["pokemon#{i}"] = PokemonPartyBlankPanel.new(@party[i],i,@viewport)
- end
- @sprites["pokemon#{i}"].text = oldtext[i]
- end
- end
- pbSelect(lastselected)
- end
- def pbRefresh
- if $Trainer.partyplus>=1
- for i in 0...$Trainer.partyplus
- sprite = @sprites["pokemon#{i}"]
- if sprite
- if sprite.is_a?(PokemonPartyPanel)
- sprite.pokemon = sprite.pokemon
- else
- sprite.refresh
- end
- end
- end
- else
- for i in 0...6
- sprite = @sprites["pokemon#{i}"]
- if sprite
- if sprite.is_a?(PokemonPartyPanel)
- sprite.pokemon = sprite.pokemon
- else
- sprite.refresh
- end
- end
- end
- end
- end
- def pbRefreshSingle(i)
- sprite = @sprites["pokemon#{i}"]
- if sprite
- if sprite.is_a?(PokemonPartyPanel)
- sprite.pokemon = sprite.pokemon
- else
- sprite.refresh
- end
- end
- end
- def update
- pbUpdateSpriteHash(@sprites)
- end
- end
- #===============================================================================
- # PC menus
- #===============================================================================
- def pbGetStorageCreator
- creator = pbStorageCreator
- if $Trainer.partyplus>=1
- creator = _INTL("Nate") if !creator || creator==""
- else
- creator = _INTL("Bill") if !creator || creator==""
- end
- return creator
- end
- class StorageSystemPC
- def shouldShow?
- return true
- end
- def name
- if $PokemonGlobal.seenStorageCreator
- return _INTL("{1}'s PC",pbGetStorageCreator)
- else
- return _INTL("Someone's PC")
- end
- end
- def access
- pbMessage(_INTL("\\se[PC access]The Pokémon Storage System was opened."))
- command = 0
- if $Trainer.partyplus>=1
- plus = $Trainer.partyplus
- else
- plus = 6
- end
- loop do
- command = pbShowCommandsWithHelp(nil,
- [_INTL("Organize Boxes"),
- _INTL("Withdraw Pokémon"),
- _INTL("Deposit Pokémon"),
- _INTL("See ya!")],
- [_INTL("Organize the Pokémon in Boxes and in your party."),
- _INTL("Move Pokémon stored in Boxes to your party."),
- _INTL("Store Pokémon in your party in Boxes."),
- _INTL("Return to the previous menu.")],-1,command
- )
- if command>=0 && command<3
- if command==1 # Withdraw
- if $PokemonStorage.party.length>=plus
- pbMessage(_INTL("Your party is full!"))
- next
- end
- elsif command==2 # Deposit
- count=0
- for p in $PokemonStorage.party
- count += 1 if p && !p.egg? && p.hp>0
- end
- if count<=1
- pbMessage(_INTL("Can't deposit the last Pokémon!"))
- next
- end
- end
- pbFadeOutIn {
- scene = PokemonStorageScene.new
- screen = PokemonStorageScreen.new(scene,$PokemonStorage)
- screen.pbStartScreen(command)
- }
- else
- break
- end
- end
- end
- end
- #===============================================================================
- # Party pop-up panel
- #===============================================================================
- class PokemonBoxPartySprite < SpriteWrapper
- def initialize(party,viewport=nil)
- if $Trainer.partyplus>=1
- plus = $Trainer.partyplus
- else
- plus = 6
- end
- super(viewport)
- @party = party
- if $Trainer.partyplus>=1
- @boxbitmap = AnimatedBitmap.new("Graphics/Pictures/Storage/Partyplus/overlay_party_"+"#{plus}")
- else
- @boxbitmap = AnimatedBitmap.new("Graphics/Pictures/Storage/overlay_party")
- end
- @pokemonsprites = []
- for i in 0...plus
- @pokemonsprites[i] = nil
- pokemon = @party[i]
- if pokemon
- @pokemonsprites[i] = PokemonBoxIcon.new(pokemon,viewport)
- end
- end
- if $Trainer.partyplus==10
- @contents = BitmapWrapper.new(172,370)
- elsif $Trainer.partyplus==9
- @contents = BitmapWrapper.new(244,352)
- elsif $Trainer.partyplus==7
- @contents = BitmapWrapper.new(504,352)
- elsif $Trainer.partyplus==5
- @contents = BitmapWrapper.new(172,370)
- else # 1,2,3,4,6,8
- @contents = BitmapWrapper.new(172,352)
- end
- self.bitmap = @contents
- if $Trainer.partyplus==9
- self.x = 254
- elsif $Trainer.partyplus==7
- self.x = 514
- else #1,2,3,4,5,6,8,10
- self.x = 182
- end
- if $Trainer.partyplus==10 || $Trainer.partyplus==5
- self.y = Graphics.height-370
- self.y = Graphics.height-370
- else # 1,2,3,4,6,7,8,9
- self.y = Graphics.height-352
- end
- pbSetSystemFont(self.bitmap)
- refresh
- end
- def dispose
- if $Trainer.partyplus>=1
- plus = $Trainer.partyplus
- else
- plus = 6
- end
- for i in 0...plus
- @pokemonsprites[i].dispose if @pokemonsprites[i]
- end
- @boxbitmap.dispose
- @contents.dispose
- super
- end
- def x=(value)
- super
- refresh
- end
- def y=(value)
- super
- refresh
- end
- def color=(value)
- if $Trainer.partyplus>=1
- plus = $Trainer.partyplus
- else
- plus = 6
- end
- super
- for i in 0...plus
- if @pokemonsprites[i] && !@pokemonsprites[i].disposed?
- @pokemonsprites[i].color = pbSrcOver(@pokemonsprites[i].color,value)
- end
- end
- end
- def visible=(value)
- if $Trainer.partyplus>=1
- plus = $Trainer.partyplus
- else
- plus = 6
- end
- super
- for i in 0...plus
- if @pokemonsprites[i] && !@pokemonsprites[i].disposed?
- @pokemonsprites[i].visible = value
- end
- end
- end
- def getPokemon(index)
- return @pokemonsprites[index]
- end
- def setPokemon(index,sprite)
- @pokemonsprites[index] = sprite
- @pokemonsprites.compact!
- refresh
- end
- def grabPokemon(index,arrow)
- sprite = @pokemonsprites[index]
- if sprite
- arrow.grab(sprite)
- @pokemonsprites[index] = nil
- @pokemonsprites.compact!
- refresh
- end
- end
- def deletePokemon(index)
- @pokemonsprites[index].dispose
- @pokemonsprites[index] = nil
- @pokemonsprites.compact!
- refresh
- end
- def refresh
- if $Trainer.partyplus>=1
- plus = $Trainer.partyplus
- else
- plus = 6
- end
- if $Trainer.partyplus==10 || $Trainer.partyplus==5
- @contents.blt(0,0,@boxbitmap.bitmap,Rect.new(0,0,172,370))
- elsif $Trainer.partyplus==9
- @contents.blt(0,0,@boxbitmap.bitmap,Rect.new(0,0,244,352))
- elsif $Trainer.partyplus==7
- @contents.blt(0,0,@boxbitmap.bitmap,Rect.new(0,0,504,352))
- else # 1,2,3,4,6,8
- @contents.blt(0,0,@boxbitmap.bitmap,Rect.new(0,0,172,352))
- end
- if $Trainer.partyplus==10 || $Trainer.partyplus==5
- pbDrawTextPositions(self.bitmap,[
- [_INTL("Back"),86,324,2,Color.new(248,248,248),Color.new(80,80,80),1]
- ])
- elsif $Trainer.partyplus==9
- pbDrawTextPositions(self.bitmap,[
- [_INTL("Back"),122,242,2,Color.new(248,248,248),Color.new(80,80,80),1]
- ])
- elsif $Trainer.partyplus==8
- pbDrawTextPositions(self.bitmap,[
- [_INTL("Back"),86,306,2,Color.new(248,248,248),Color.new(80,80,80),1]
- ])
- elsif $Trainer.partyplus==7
- pbDrawTextPositions(self.bitmap,[
- [_INTL("Back"),252,306,2,Color.new(248,248,248),Color.new(80,80,80),1]
- ])
- else
- pbDrawTextPositions(self.bitmap,[
- [_INTL("Back"),86,242,2,Color.new(248,248,248),Color.new(80,80,80),1]
- ])
- end
- if $Trainer.partyplus==10
- xvalues = [ 18, 90, 18, 90, 18, 90, 18, 90, 18, 90]
- yvalues = [ 6, 22, 60, 76,114,130,168,184,222,238]
- elsif $Trainer.partyplus==9
- xvalues = [ 18, 90,162, 18, 90,162, 18, 90,162]
- yvalues = [ 2, 18, 2, 66, 82, 66,130,146,130]
- elsif $Trainer.partyplus==8
- xvalues = [18, 90, 18, 90, 18, 90, 18, 90]
- yvalues = [ 2, 18, 66, 82,130,146,194,210]
- elsif $Trainer.partyplus==7
- xvalues = [ 16, 84,152,220,288,356,424]
- yvalues = [194,210,194,210,194,210,194]
- elsif $Trainer.partyplus==5
- xvalues = [ 54, 54, 54, 54, 54]
- yvalues = [ 6, 60,114,168,222]
- elsif $Trainer.partyplus==4
- xvalues = [ 18, 90, 18, 90]
- yvalues = [ 66, 82,130,146]
- elsif $Trainer.partyplus==3
- xvalues = [ 54, 54, 54]
- yvalues = [ 2, 66,130]
- elsif $Trainer.partyplus==2
- xvalues = [ 18, 90]
- yvalues = [130,146]
- elsif $Trainer.partyplus==1
- xvalues = [ 54]
- yvalues = [130]
- else
- xvalues = [18,90,18,90,18,90]
- yvalues = [2,18,66,82,130,146]
- end
- for j in 0...plus
- @pokemonsprites[j] = nil if @pokemonsprites[j] && @pokemonsprites[j].disposed?
- end
- @pokemonsprites.compact!
- for j in 0...plus
- sprite = @pokemonsprites[j]
- if sprite && !sprite.disposed?
- sprite.viewport = self.viewport
- sprite.x = self.x+xvalues[j]
- sprite.y = self.y+yvalues[j]
- sprite.z = 0
- end
- end
- end
- def update
- if $Trainer.partyplus>=1
- plus = $Trainer.partyplus
- else
- plus = 6
- end
- super
- for i in 0...plus
- @pokemonsprites[i].update if @pokemonsprites[i] && !@pokemonsprites[i].disposed?
- end
- end
- end
- #===============================================================================
- # Pokémon storage visuals
- #===============================================================================
- class PokemonStorageScene
- attr_reader :quickswap
- def initialize
- @command = 1
- end
- def pbStartBox(screen,command)
- @screen = screen
- @storage = screen.storage
- @bgviewport = Viewport.new(0,0,Graphics.width,Graphics.height)
- @bgviewport.z = 99999
- @boxviewport = Viewport.new(0,0,Graphics.width,Graphics.height)
- @boxviewport.z = 99999
- @boxsidesviewport = Viewport.new(0,0,Graphics.width,Graphics.height)
- @boxsidesviewport.z = 99999
- @arrowviewport = Viewport.new(0,0,Graphics.width,Graphics.height)
- @arrowviewport.z = 99999
- @viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
- @viewport.z = 99999
- @selection = 0
- @quickswap = false
- @sprites = {}
- @choseFromParty = false
- @command = command
- addBackgroundPlane(@sprites,"background","Storage/bg",@bgviewport)
- @sprites["box"] = PokemonBoxSprite.new(@storage,@storage.currentBox,@boxviewport)
- @sprites["boxsides"] = IconSprite.new(0,0,@boxsidesviewport)
- @sprites["boxsides"].setBitmap("Graphics/Pictures/Storage/overlay_main")
- @sprites["overlay"] = BitmapSprite.new(Graphics.width,Graphics.height,@boxsidesviewport)
- pbSetSystemFont(@sprites["overlay"].bitmap)
- @sprites["pokemon"] = AutoMosaicPokemonSprite.new(@boxsidesviewport)
- @sprites["pokemon"].setOffset(PictureOrigin::Center)
- @sprites["pokemon"].x = 90
- @sprites["pokemon"].y = 134
- @sprites["boxparty"] = PokemonBoxPartySprite.new(@storage.party,@boxsidesviewport)
- if command!=2 # Drop down tab only on Deposit
- if $Trainer.partyplus==7
- @sprites["boxparty"].x = 4
- else
- @sprites["boxparty"].x = 182
- end
- @sprites["boxparty"].y = Graphics.height
- end
- @markingbitmap = AnimatedBitmap.new("Graphics/Pictures/Storage/markings")
- @sprites["markingbg"] = IconSprite.new(292,68,@boxsidesviewport)
- @sprites["markingbg"].setBitmap("Graphics/Pictures/Storage/overlay_marking")
- @sprites["markingbg"].visible = false
- @sprites["markingoverlay"] = BitmapSprite.new(Graphics.width,Graphics.height,@boxsidesviewport)
- @sprites["markingoverlay"].visible = false
- pbSetSystemFont(@sprites["markingoverlay"].bitmap)
- @sprites["arrow"] = PokemonBoxArrow.new(@arrowviewport)
- @sprites["arrow"].z += 1
- if command!=2
- pbSetArrow(@sprites["arrow"],@selection)
- pbUpdateOverlay(@selection)
- pbSetMosaic(@selection)
- else
- pbPartySetArrow(@sprites["arrow"],@selection)
- pbUpdateOverlay(@selection,@storage.party)
- pbSetMosaic(@selection)
- end
- pbSEPlay("PC access")
- pbFadeInAndShow(@sprites)
- end
- def pbCloseBox
- pbFadeOutAndHide(@sprites)
- pbDisposeSpriteHash(@sprites)
- @markingbitmap.dispose if @markingbitmap
- @boxviewport.dispose
- @boxsidesviewport.dispose
- @arrowviewport.dispose
- end
- def pbDisplay(message)
- msgwindow = Window_UnformattedTextPokemon.newWithSize("",180,0,Graphics.width-180,32)
- msgwindow.viewport = @viewport
- msgwindow.visible = true
- msgwindow.letterbyletter = false
- msgwindow.resizeHeightToFit(message,Graphics.width-180)
- msgwindow.text = message
- pbBottomRight(msgwindow)
- loop do
- Graphics.update
- Input.update
- if Input.trigger?(Input::B) || Input.trigger?(Input::C)
- break
- end
- msgwindow.update
- self.update
- end
- msgwindow.dispose
- Input.update
- end
- def pbShowCommands(message,commands,index=0)
- ret = -1
- msgwindow = Window_UnformattedTextPokemon.newWithSize("",180,0,Graphics.width-180,32)
- msgwindow.viewport = @viewport
- msgwindow.visible = true
- msgwindow.letterbyletter = false
- msgwindow.text = message
- msgwindow.resizeHeightToFit(message,Graphics.width-180)
- pbBottomRight(msgwindow)
- cmdwindow = Window_CommandPokemon.new(commands)
- cmdwindow.viewport = @viewport
- cmdwindow.visible = true
- cmdwindow.resizeToFit(cmdwindow.commands)
- cmdwindow.height = Graphics.height-msgwindow.height if cmdwindow.height>Graphics.height-msgwindow.height
- pbBottomRight(cmdwindow)
- cmdwindow.y -= msgwindow.height
- cmdwindow.index = index
- loop do
- Graphics.update
- Input.update
- msgwindow.update
- cmdwindow.update
- if Input.trigger?(Input::B)
- ret = -1
- break
- elsif Input.trigger?(Input::C)
- ret = cmdwindow.index
- break
- end
- self.update
- end
- msgwindow.dispose
- cmdwindow.dispose
- Input.update
- return ret
- end
- def pbSetArrow(arrow,selection)
- case selection
- when -1, -4, -5 # Box name, move left, move right
- arrow.x = 157*2
- arrow.y = -12*2
- when -2 # Party Pokémon
- arrow.x = 119*2
- arrow.y = 139*2
- when -3 # Close Box
- arrow.x = 207*2
- arrow.y = 139*2
- else
- arrow.x = (97+24*(selection%6))*2
- arrow.y = (8+24*(selection/6))*2
- end
- end
- def pbChangeSelection(key,selection)
- case key
- when Input::UP
- if selection==-1 # Box name
- selection = -2
- elsif selection==-2 # Party
- selection = 25
- elsif selection==-3 # Close Box
- selection = 28
- else
- selection -= 6
- selection = -1 if selection<0
- end
- when Input::DOWN
- if selection==-1 # Box name
- selection = 2
- elsif selection==-2 # Party
- selection = -1
- elsif selection==-3 # Close Box
- selection = -1
- else
- selection += 6
- selection = -2 if selection==30 || selection==31 || selection==32
- selection = -3 if selection==33 || selection==34 || selection==35
- end
- when Input::LEFT
- if selection==-1 # Box name
- selection = -4 # Move to previous box
- elsif selection==-2
- selection = -3
- elsif selection==-3
- selection = -2
- else
- selection -= 1
- selection += 6 if selection==-1 || selection%6==5
- end
- when Input::RIGHT
- if selection==-1 # Box name
- selection = -5 # Move to next box
- elsif selection==-2
- selection = -3
- elsif selection==-3
- selection = -2
- else
- selection += 1
- selection -= 6 if selection%6==0
- end
- end
- return selection
- end
- def pbPartySetArrow(arrow,selection)
- if selection>=0
- if $Trainer.partyplus==10
- xvalues = [200,272,200,272,200,272,200,272,200,272,236]
- yvalues = [-12, 4, 42, 58, 96,112,150,166,204,220,284]
- elsif $Trainer.partyplus==9
- xvalues = [200,272,344,200,272,344,200,272,344,272]
- yvalues = [ 2, 18, 2, 66, 82, 66,130,146,130,220]
- elsif $Trainer.partyplus==8
- xvalues = [200,272,200,272,200,272,200,272,236]
- yvalues = [ 2, 18, 66, 82,130,146,194,210,284]
- elsif $Trainer.partyplus==7
- xvalues = [ 20, 88,156,224,292,360,428,224]
- yvalues = [194,210,194,210,194,210,194,284]
- elsif $Trainer.partyplus==5
- xvalues = [236,236,236,236,236,236]
- yvalues = [-12, 42, 96,150,204,284]
- elsif $Trainer.partyplus==4
- xvalues = [200,272,200,272,236]
- yvalues = [ 66, 82,130,146,220]
- elsif $Trainer.partyplus==3
- xvalues = [236,236,236,236]
- yvalues = [ 2, 66,130,220]
- elsif $Trainer.partyplus==2
- xvalues = [200,272,236]
- yvalues = [130,146,220]
- elsif $Trainer.partyplus==1
- xvalues = [236,236]
- yvalues = [130,220]
- else
- xvalues = [200,272,200,272,200,272,236]
- yvalues = [2,18,66,82,130,146,220]
- end
- arrow.angle = 0
- arrow.mirror = false
- arrow.ox = 0
- arrow.oy = 0
- arrow.x = xvalues[selection]
- arrow.y = yvalues[selection]
- end
- end
- def pbPartyChangeSelection(key,selection)
- if $Trainer.partyplus>=1
- plus = $Trainer.partyplus
- else
- plus = 6
- end
- if $Trainer.partyplus>=1
- case key
- when Input::LEFT
- selection -= 1
- selection = plus if selection<0
- when Input::RIGHT
- selection += 1
- selection = 0 if selection>plus
- when Input::UP
- if selection==plus
- selection = plus-1
- else
- if $Trainer.partyplus==7
- selection -= 7
- elsif $Trainer.partyplus==9
- selection -= 3
- elsif $Trainer.partyplus==1 || $Trainer.partyplus==3 || $Trainer.partyplus==5
- selection -= 1
- else #10,2,4,6,8
- selection -= 2
- end
- selection = plus if selection<0
- end
- when Input::DOWN
- if selection==plus
- selection = 0
- elsif $Trainer.partyplus==7
- selection += 7
- elsif $Trainer.partyplus==9
- selection += 3
- elsif $Trainer.partyplus==1 || $Trainer.partyplus==3 || $Trainer.partyplus==5
- selection += 1
- else
- selection += 2
- end
- selection = plus if selection>plus
- end
- else
- case key
- when Input::LEFT
- selection -= 1
- selection = 6 if selection<0
- when Input::RIGHT
- selection += 1
- selection = 0 if selection>6
- when Input::UP
- if selection==6
- selection = 5
- else
- selection -= 2
- selection = 6 if selection<0
- end
- when Input::DOWN
- if selection==6
- selection = 0
- else
- selection += 2
- selection = 6 if selection>6
- end
- end
- end
- return selection
- end
- def pbSelectBoxInternal(_party)
- selection = @selection
- pbSetArrow(@sprites["arrow"],selection)
- pbUpdateOverlay(selection)
- pbSetMosaic(selection)
- loop do
- Graphics.update
- Input.update
- key = -1
- key = Input::DOWN if Input.repeat?(Input::DOWN)
- key = Input::RIGHT if Input.repeat?(Input::RIGHT)
- key = Input::LEFT if Input.repeat?(Input::LEFT)
- key = Input::UP if Input.repeat?(Input::UP)
- if key>=0
- pbPlayCursorSE
- selection = pbChangeSelection(key,selection)
- pbSetArrow(@sprites["arrow"],selection)
- if selection==-4
- nextbox = (@storage.currentBox+@storage.maxBoxes-1)%@storage.maxBoxes
- pbSwitchBoxToLeft(nextbox)
- @storage.currentBox = nextbox
- elsif selection==-5
- nextbox = (@storage.currentBox+1)%@storage.maxBoxes
- pbSwitchBoxToRight(nextbox)
- @storage.currentBox = nextbox
- end
- selection = -1 if selection==-4 || selection==-5
- pbUpdateOverlay(selection)
- pbSetMosaic(selection)
- end
- self.update
- if Input.trigger?(Input::L)
- pbPlayCursorSE
- nextbox = (@storage.currentBox+@storage.maxBoxes-1)%@storage.maxBoxes
- pbSwitchBoxToLeft(nextbox)
- @storage.currentBox = nextbox
- pbUpdateOverlay(selection)
- pbSetMosaic(selection)
- elsif Input.trigger?(Input::R)
- pbPlayCursorSE
- nextbox = (@storage.currentBox+1)%@storage.maxBoxes
- pbSwitchBoxToRight(nextbox)
- @storage.currentBox = nextbox
- pbUpdateOverlay(selection)
- pbSetMosaic(selection)
- elsif Input.trigger?(Input::F5) # Jump to box name
- if selection!=-1
- pbPlayCursorSE
- selection = -1
- pbSetArrow(@sprites["arrow"],selection)
- pbUpdateOverlay(selection)
- pbSetMosaic(selection)
- end
- elsif Input.trigger?(Input::A) && @command==0 # Organize only
- pbPlayDecisionSE
- pbSetQuickSwap(!@quickswap)
- elsif Input.trigger?(Input::B)
- @selection = selection
- return nil
- elsif Input.trigger?(Input::C)
- @selection = selection
- if selection>=0
- return [@storage.currentBox,selection]
- elsif selection==-1 # Box name
- return [-4,-1]
- elsif selection==-2 # Party Pokémon
- return [-2,-1]
- elsif selection==-3 # Close Box
- return [-3,-1]
- end
- end
- end
- end
- def pbSelectBox(party)
- return pbSelectBoxInternal(party) if @command==1 # Withdraw
- ret = nil
- loop do
- if !@choseFromParty
- ret = pbSelectBoxInternal(party)
- end
- if @choseFromParty || (ret && ret[0]==-2) # Party Pokémon
- if !@choseFromParty
- pbShowPartyTab
- @selection = 0
- end
- ret = pbSelectPartyInternal(party,false)
- if ret<0
- pbHidePartyTab
- @selection = 0
- @choseFromParty = false
- else
- @choseFromParty = true
- return [-1,ret]
- end
- else
- @choseFromParty = false
- return ret
- end
- end
- end
- def pbSelectPartyInternal(party,depositing)
- if $Trainer.partyplus>=1
- plus = $Trainer.partyplus
- else
- plus = 6
- end
- selection = @selection
- pbPartySetArrow(@sprites["arrow"],selection)
- pbUpdateOverlay(selection,party)
- pbSetMosaic(selection)
- lastsel = 1
- loop do
- Graphics.update
- Input.update
- key = -1
- key = Input::DOWN if Input.repeat?(Input::DOWN)
- key = Input::RIGHT if Input.repeat?(Input::RIGHT)
- key = Input::LEFT if Input.repeat?(Input::LEFT)
- key = Input::UP if Input.repeat?(Input::UP)
- if key>=0
- pbPlayCursorSE
- newselection = pbPartyChangeSelection(key,selection)
- if newselection==-1
- return -1 if !depositing
- elsif newselection==-2
- selection = lastsel
- else
- selection = newselection
- end
- pbPartySetArrow(@sprites["arrow"],selection)
- lastsel = selection if selection>0
- pbUpdateOverlay(selection,party)
- pbSetMosaic(selection)
- end
- self.update
- if Input.trigger?(Input::A) && @command==0 # Organize only
- pbPlayDecisionSE
- pbSetQuickSwap(!@quickswap)
- elsif Input.trigger?(Input::B)
- @selection = selection
- return -1
- elsif Input.trigger?(Input::C)
- if selection>=0 && selection<plus
- @selection = selection
- return selection
- elsif selection==plus # Close Box
- @selection = selection
- return (depositing) ? -3 : -1
- end
- end
- end
- end
- def pbSelectParty(party)
- return pbSelectPartyInternal(party,true)
- end
- def pbChangeBackground(wp)
- @sprites["box"].refreshSprites = false
- alpha = 0
- Graphics.update
- self.update
- timeTaken = Graphics.frame_rate*4/10
- alphaDiff = (255.0/timeTaken).ceil
- timeTaken.times do
- alpha += alphaDiff
- Graphics.update
- Input.update
- @sprites["box"].color = Color.new(248,248,248,alpha)
- self.update
- end
- @sprites["box"].refreshBox = true
- @storage[@storage.currentBox].background = wp
- (Graphics.frame_rate/10).times do
- Graphics.update
- Input.update
- self.update
- end
- timeTaken.times do
- alpha -= alphaDiff
- Graphics.update
- Input.update
- @sprites["box"].color = Color.new(248,248,248,alpha)
- self.update
- end
- @sprites["box"].refreshSprites = true
- end
- def pbSwitchBoxToRight(newbox)
- newbox = PokemonBoxSprite.new(@storage,newbox,@boxviewport)
- newbox.x = 520
- Graphics.frame_reset
- distancePerFrame = 64*20/Graphics.frame_rate
- loop do
- Graphics.update
- Input.update
- @sprites["box"].x -= distancePerFrame
- newbox.x -= distancePerFrame
- self.update
- break if newbox.x<=184
- end
- diff = newbox.x-184
- newbox.x = 184
- @sprites["box"].x -= diff
- @sprites["box"].dispose
- @sprites["box"] = newbox
- end
- def pbSwitchBoxToLeft(newbox)
- newbox = PokemonBoxSprite.new(@storage,newbox,@boxviewport)
- newbox.x = -152
- Graphics.frame_reset
- distancePerFrame = 64*20/Graphics.frame_rate
- loop do
- Graphics.update
- Input.update
- @sprites["box"].x += distancePerFrame
- newbox.x += distancePerFrame
- self.update
- break if newbox.x>=184
- end
- diff = newbox.x-184
- newbox.x = 184
- @sprites["box"].x -= diff
- @sprites["box"].dispose
- @sprites["box"] = newbox
- end
- def pbJumpToBox(newbox)
- if @storage.currentBox!=newbox
- if newbox>@storage.currentBox
- pbSwitchBoxToRight(newbox)
- else
- pbSwitchBoxToLeft(newbox)
- end
- @storage.currentBox = newbox
- end
- end
- def pbSetMosaic(selection)
- if !@screen.pbHeldPokemon
- if @boxForMosaic!=@storage.currentBox || @selectionForMosaic!=selection
- @sprites["pokemon"].mosaic = Graphics.frame_rate/4
- @boxForMosaic = @storage.currentBox
- @selectionForMosaic = selection
- end
- end
- end
- def pbSetQuickSwap(value)
- @quickswap = value
- @sprites["arrow"].quickswap = value
- end
- def pbShowPartyTab
- if $Trainer.partyplus==10 || $Trainer.partyplus==5
- plus = 370
- else
- plus = 352
- end
- pbSEPlay("GUI storage show party panel")
- distancePerFrame = 48*20/Graphics.frame_rate
- loop do
- Graphics.update
- Input.update
- @sprites["boxparty"].y -= distancePerFrame
- self.update
- break if @sprites["boxparty"].y<=Graphics.height-plus
- end
- @sprites["boxparty"].y = Graphics.height-plus
- end
- def pbHidePartyTab
- pbSEPlay("GUI storage hide party panel")
- distancePerFrame = 48*20/Graphics.frame_rate
- loop do
- Graphics.update
- Input.update
- @sprites["boxparty"].y += distancePerFrame
- self.update
- break if @sprites["boxparty"].y>=Graphics.height
- end
- @sprites["boxparty"].y = Graphics.height
- end
- def pbHold(selected)
- pbSEPlay("GUI storage pick up")
- if selected[0]==-1
- @sprites["boxparty"].grabPokemon(selected[1],@sprites["arrow"])
- else
- @sprites["box"].grabPokemon(selected[1],@sprites["arrow"])
- end
- while @sprites["arrow"].grabbing?
- Graphics.update
- Input.update
- self.update
- end
- end
- def pbSwap(selected,_heldpoke)
- pbSEPlay("GUI storage pick up")
- heldpokesprite = @sprites["arrow"].heldPokemon
- boxpokesprite = nil
- if selected[0]==-1
- boxpokesprite = @sprites["boxparty"].getPokemon(selected[1])
- else
- boxpokesprite = @sprites["box"].getPokemon(selected[1])
- end
- if selected[0]==-1
- @sprites["boxparty"].setPokemon(selected[1],heldpokesprite)
- else
- @sprites["box"].setPokemon(selected[1],heldpokesprite)
- end
- @sprites["arrow"].setSprite(boxpokesprite)
- @sprites["pokemon"].mosaic = 10
- @boxForMosaic = @storage.currentBox
- @selectionForMosaic = selected[1]
- end
- def pbPlace(selected,_heldpoke)
- pbSEPlay("GUI storage put down")
- heldpokesprite = @sprites["arrow"].heldPokemon
- @sprites["arrow"].place
- while @sprites["arrow"].placing?
- Graphics.update
- Input.update
- self.update
- end
- if selected[0]==-1
- @sprites["boxparty"].setPokemon(selected[1],heldpokesprite)
- else
- @sprites["box"].setPokemon(selected[1],heldpokesprite)
- end
- @boxForMosaic = @storage.currentBox
- @selectionForMosaic = selected[1]
- end
- def pbWithdraw(selected,heldpoke,partyindex)
- pbHold(selected) if !heldpoke
- pbShowPartyTab
- pbPartySetArrow(@sprites["arrow"],partyindex)
- pbPlace([-1,partyindex],heldpoke)
- pbHidePartyTab
- end
- def pbStore(selected,heldpoke,destbox,firstfree)
- if heldpoke
- if destbox==@storage.currentBox
- heldpokesprite = @sprites["arrow"].heldPokemon
- @sprites["box"].setPokemon(firstfree,heldpokesprite)
- @sprites["arrow"].setSprite(nil)
- else
- @sprites["arrow"].deleteSprite
- end
- else
- sprite = @sprites["boxparty"].getPokemon(selected[1])
- if destbox==@storage.currentBox
- @sprites["box"].setPokemon(firstfree,sprite)
- @sprites["boxparty"].setPokemon(selected[1],nil)
- else
- @sprites["boxparty"].deletePokemon(selected[1])
- end
- end
- end
- def pbRelease(selected,heldpoke)
- box = selected[0]
- index = selected[1]
- if heldpoke
- sprite = @sprites["arrow"].heldPokemon
- elsif box==-1
- sprite = @sprites["boxparty"].getPokemon(index)
- else
- sprite = @sprites["box"].getPokemon(index)
- end
- if sprite
- sprite.release
- while sprite.releasing?
- Graphics.update
- sprite.update
- self.update
- end
- end
- end
- def pbChooseBox(msg)
- commands = []
- for i in 0...@storage.maxBoxes
- box = @storage[i]
- if box
- commands.push(_INTL("{1} ({2}/{3})",box.name,box.nitems,box.length))
- end
- end
- return pbShowCommands(msg,commands,@storage.currentBox)
- end
- def pbBoxName(helptext,minchars,maxchars)
- oldsprites = pbFadeOutAndHide(@sprites)
- ret = pbEnterBoxName(helptext,minchars,maxchars)
- if ret.length>0
- @storage[@storage.currentBox].name = ret
- end
- @sprites["box"].refreshBox = true
- pbRefresh
- pbFadeInAndShow(@sprites,oldsprites)
- end
- def pbChooseItem(bag)
- ret = 0
- pbFadeOutIn {
- scene = PokemonBag_Scene.new
- screen = PokemonBagScreen.new(scene,bag)
- ret = screen.pbChooseItemScreen(Proc.new { |item| pbCanHoldItem?(item) })
- }
- return ret
- end
- def pbSummary(selected,heldpoke)
- oldsprites = pbFadeOutAndHide(@sprites)
- scene = PokemonSummary_Scene.new
- screen = PokemonSummaryScreen.new(scene)
- if heldpoke
- screen.pbStartScreen([heldpoke],0)
- elsif selected[0]==-1
- @selection = screen.pbStartScreen(@storage.party,selected[1])
- pbPartySetArrow(@sprites["arrow"],@selection)
- pbUpdateOverlay(@selection,@storage.party)
- else
- @selection = screen.pbStartScreen(@storage.boxes[selected[0]],selected[1])
- pbSetArrow(@sprites["arrow"],@selection)
- pbUpdateOverlay(@selection)
- end
- pbFadeInAndShow(@sprites,oldsprites)
- end
- def pbMarkingSetArrow(arrow,selection)
- if selection>=0
- xvalues = [162,191,220,162,191,220,184,184]
- yvalues = [24,24,24,49,49,49,77,109]
- arrow.angle = 0
- arrow.mirror = false
- arrow.ox = 0
- arrow.oy = 0
- arrow.x = xvalues[selection]*2
- arrow.y = yvalues[selection]*2
- end
- end
- def pbMarkingChangeSelection(key,selection)
- case key
- when Input::LEFT
- if selection<6
- selection -= 1
- selection += 3 if selection%3==2
- end
- when Input::RIGHT
- if selection<6
- selection += 1
- selection -= 3 if selection%3==0
- end
- when Input::UP
- if selection==7; selection = 6
- elsif selection==6; selection = 4
- elsif selection<3; selection = 7
- else; selection -= 3
- end
- when Input::DOWN
- if selection==7; selection = 1
- elsif selection==6; selection = 7
- elsif selection>=3; selection = 6
- else; selection += 3
- end
- end
- return selection
- end
- def pbMark(selected,heldpoke)
- @sprites["markingbg"].visible = true
- @sprites["markingoverlay"].visible = true
- msg = _INTL("Mark your Pokémon.")
- msgwindow = Window_UnformattedTextPokemon.newWithSize("",180,0,Graphics.width-180,32)
- msgwindow.viewport = @viewport
- msgwindow.visible = true
- msgwindow.letterbyletter = false
- msgwindow.text = msg
- msgwindow.resizeHeightToFit(msg,Graphics.width-180)
- pbBottomRight(msgwindow)
- base = Color.new(248,248,248)
- shadow = Color.new(80,80,80)
- pokemon = heldpoke
- if heldpoke
- pokemon = heldpoke
- elsif selected[0]==-1
- pokemon = @storage.party[selected[1]]
- else
- pokemon = @storage.boxes[selected[0]][selected[1]]
- end
- markings = pokemon.markings
- index = 0
- redraw = true
- markrect = Rect.new(0,0,16,16)
- loop do
- # Redraw the markings and text
- if redraw
- @sprites["markingoverlay"].bitmap.clear
- for i in 0...6
- markrect.x = i*16
- markrect.y = (markings&(1<<i)!=0) ? 16 : 0
- @sprites["markingoverlay"].bitmap.blt(336+58*(i%3),106+50*(i/3),@markingbitmap.bitmap,markrect)
- end
- textpos = [
- [_INTL("OK"),402,210,2,base,shadow,1],
- [_INTL("Cancel"),402,274,2,base,shadow,1]
- ]
- pbDrawTextPositions(@sprites["markingoverlay"].bitmap,textpos)
- pbMarkingSetArrow(@sprites["arrow"],index)
- redraw = false
- end
- Graphics.update
- Input.update
- key = -1
- key = Input::DOWN if Input.repeat?(Input::DOWN)
- key = Input::RIGHT if Input.repeat?(Input::RIGHT)
- key = Input::LEFT if Input.repeat?(Input::LEFT)
- key = Input::UP if Input.repeat?(Input::UP)
- if key>=0
- oldindex = index
- index = pbMarkingChangeSelection(key,index)
- pbPlayCursorSE if index!=oldindex
- pbMarkingSetArrow(@sprites["arrow"],index)
- end
- self.update
- if Input.trigger?(Input::B)
- pbPlayCancelSE
- break
- elsif Input.trigger?(Input::C)
- pbPlayDecisionSE
- if index==6 # OK
- pokemon.markings = markings
- break
- elsif index==7 # Cancel
- break
- else
- mask = (1<<index)
- if (markings&mask)==0
- markings |= mask
- else
- markings &= ~mask
- end
- redraw = true
- end
- end
- end
- @sprites["markingbg"].visible = false
- @sprites["markingoverlay"].visible = false
- msgwindow.dispose
- end
- def pbRefresh
- @sprites["box"].refresh
- @sprites["boxparty"].refresh
- end
- def pbHardRefresh
- oldPartyY = @sprites["boxparty"].y
- @sprites["box"].dispose
- @sprites["box"] = PokemonBoxSprite.new(@storage,@storage.currentBox,@boxviewport)
- @sprites["boxparty"].dispose
- @sprites["boxparty"] = PokemonBoxPartySprite.new(@storage.party,@boxsidesviewport)
- @sprites["boxparty"].y = oldPartyY
- end
- def drawMarkings(bitmap,x,y,_width,_height,markings)
- markrect = Rect.new(0,0,16,16)
- for i in 0...8
- markrect.x = i*16
- markrect.y = (markings&(1<<i)!=0) ? 16 : 0
- bitmap.blt(x+i*16,y,@markingbitmap.bitmap,markrect)
- end
- end
- def pbUpdateOverlay(selection,party=nil)
- overlay = @sprites["overlay"].bitmap
- overlay.clear
- buttonbase = Color.new(248,248,248)
- buttonshadow = Color.new(80,80,80)
- pbDrawTextPositions(overlay,[
- [_INTL("Party: {1}",(@storage.party.length rescue 0)),270,328,2,buttonbase,buttonshadow,1],
- [_INTL("Exit"),446,328,2,buttonbase,buttonshadow,1],
- ])
- pokemon = nil
- if @screen.pbHeldPokemon
- pokemon = @screen.pbHeldPokemon
- elsif selection>=0
- pokemon = (party) ? party[selection] : @storage[@storage.currentBox,selection]
- end
- if !pokemon
- @sprites["pokemon"].visible = false
- return
- end
- @sprites["pokemon"].visible = true
- base = Color.new(88,88,80)
- shadow = Color.new(168,184,184)
- nonbase = Color.new(208,208,208)
- nonshadow = Color.new(224,224,224)
- pokename = pokemon.name
- textstrings = [
- [pokename,10,8,false,base,shadow]
- ]
- if !pokemon.egg?
- imagepos = []
- if pokemon.male?
- textstrings.push([_INTL("♂"),148,8,false,Color.new(24,112,216),Color.new(136,168,208)])
- elsif pokemon.female?
- textstrings.push([_INTL("♀"),148,8,false,Color.new(248,56,32),Color.new(224,152,144)])
- end
- imagepos.push(["Graphics/Pictures/Storage/overlay_lv",6,246])
- textstrings.push([pokemon.level.to_s,28,234,false,base,shadow])
- if pokemon.ability>0
- textstrings.push([PBAbilities.getName(pokemon.ability),86,306,2,base,shadow])
- else
- textstrings.push([_INTL("No ability"),86,306,2,nonbase,nonshadow])
- end
- if pokemon.item>0
- textstrings.push([PBItems.getName(pokemon.item),86,342,2,base,shadow])
- else
- textstrings.push([_INTL("No item"),86,342,2,nonbase,nonshadow])
- end
- if pokemon.shiny?
- imagepos.push(["Graphics/Pictures/shiny",156,198])
- end
- typebitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/types"))
- type1rect = Rect.new(0,pokemon.type1*28,64,28)
- type2rect = Rect.new(0,pokemon.type2*28,64,28)
- if pokemon.type1==pokemon.type2
- overlay.blt(52,272,typebitmap.bitmap,type1rect)
- else
- overlay.blt(18,272,typebitmap.bitmap,type1rect)
- overlay.blt(88,272,typebitmap.bitmap,type2rect)
- end
- drawMarkings(overlay,70,240,128,20,pokemon.markings)
- pbDrawImagePositions(overlay,imagepos)
- end
- pbDrawTextPositions(overlay,textstrings)
- @sprites["pokemon"].setPokemonBitmap(pokemon)
- end
- def update
- pbUpdateSpriteHash(@sprites)
- end
- end
- #===============================================================================
- # Pokémon storage mechanics
- #===============================================================================
- class PokemonStorageScreen
- def pbWithdraw(selected,heldpoke)
- if $Trainer.partyplus>=1
- plus = $Trainer.partyplus
- else
- plus = 6
- end
- box = selected[0]
- index = selected[1]
- if box==-1
- raise _INTL("Can't withdraw from party...");
- end
- if @storage.party.nitems>=plus
- pbDisplay(_INTL("Your party's full!"))
- return false
- end
- @scene.pbWithdraw(selected,heldpoke,@storage.party.length)
- if heldpoke
- @storage.pbMoveCaughtToParty(heldpoke)
- @heldpkmn = nil
- else
- @storage.pbMove(-1,-1,box,index)
- end
- @scene.pbRefresh
- return true
- end
- end
- #------------------------------------------------------------------------------#
- # PScreen_Evolution
- #------------------------------------------------------------------------------#
- #===============================================================================
- # Evolution screen
- #===============================================================================
- class PokemonEvolutionScene
- private
- def pbGenerateMetafiles(s1x,s1y,s2x,s2y)
- sprite = SpriteMetafile.new
- sprite.ox = s1x
- sprite.oy = s1y
- sprite.opacity = 255
- sprite2 = SpriteMetafile.new
- sprite2.ox = s2x
- sprite2.oy = s2y
- sprite2.zoom = 0.0
- sprite2.opacity = 255
- alpha = 0
- alphaDiff = 10*20/Graphics.frame_rate
- loop do
- sprite.color.red = 255
- sprite.color.green = 255
- sprite.color.blue = 255
- sprite.color.alpha = alpha
- sprite.color = sprite.color
- sprite2.color = sprite.color
- sprite2.color.alpha = 255
- sprite.update
- sprite2.update
- break if alpha>=255
- alpha += alphaDiff
- end
- totaltempo = 0
- currenttempo = 25
- maxtempo = 7*Graphics.frame_rate
- while totaltempo<maxtempo
- for j in 0...currenttempo
- if alpha<255
- sprite.color.red = 255
- sprite.color.green = 255
- sprite.color.blue = 255
- sprite.color.alpha = alpha
- sprite.color = sprite.color
- alpha += 10
- end
- sprite.zoom = [1.1*(currenttempo-j-1)/currenttempo,1.0].min
- sprite2.zoom = [1.1*(j+1)/currenttempo,1.0].min
- sprite.update
- sprite2.update
- end
- totaltempo += currenttempo
- if totaltempo+currenttempo<maxtempo
- for j in 0...currenttempo
- sprite.zoom = [1.1*(j+1)/currenttempo,1.0].min
- sprite2.zoom = [1.1*(currenttempo-j-1)/currenttempo,1.0].min
- sprite.update
- sprite2.update
- end
- end
- totaltempo += currenttempo
- currenttempo = [(currenttempo/1.5).floor,5].max
- end
- @metafile1 = sprite
- @metafile2 = sprite2
- end
- public
- def pbUpdate(animating=false)
- if animating # Pokémon shouldn't animate during the evolution animation
- @sprites["background"].update
- else
- pbUpdateSpriteHash(@sprites)
- end
- end
- def pbUpdateNarrowScreen
- halfResizeDiff = 8*20/Graphics.frame_rate
- if @bgviewport.rect.y<80
- @bgviewport.rect.height -= halfResizeDiff*2
- if @bgviewport.rect.height<Graphics.height-64
- @bgviewport.rect.y += halfResizeDiff
- @sprites["background"].oy = @bgviewport.rect.y
- end
- end
- end
- def pbUpdateExpandScreen
- halfResizeDiff = 8*20/Graphics.frame_rate
- if @bgviewport.rect.y>0
- @bgviewport.rect.y -= halfResizeDiff
- @sprites["background"].oy = @bgviewport.rect.y
- end
- if @bgviewport.rect.height<Graphics.height
- @bgviewport.rect.height += halfResizeDiff*2
- end
- end
- def pbFlashInOut(canceled,oldstate,oldstate2)
- tone = 0
- toneDiff = 20*20/Graphics.frame_rate
- loop do
- Graphics.update
- pbUpdate(true)
- pbUpdateExpandScreen
- tone += toneDiff
- @viewport.tone.set(tone,tone,tone,0)
- break if tone>=255
- end
- @bgviewport.rect.y = 0
- @bgviewport.rect.height = Graphics.height
- @sprites["background"].oy = 0
- if canceled
- pbRestoreSpriteState(@sprites["rsprite1"],oldstate)
- pbRestoreSpriteState(@sprites["rsprite2"],oldstate2)
- @sprites["rsprite1"].zoom_x = 1.0
- @sprites["rsprite1"].zoom_y = 1.0
- @sprites["rsprite1"].color.alpha = 0
- @sprites["rsprite1"].visible = true
- @sprites["rsprite2"].visible = false
- else
- @sprites["rsprite1"].visible = false
- @sprites["rsprite2"].visible = true
- @sprites["rsprite2"].zoom_x = 1.0
- @sprites["rsprite2"].zoom_y = 1.0
- @sprites["rsprite2"].color.alpha = 0
- end
- (Graphics.frame_rate/4).times do
- Graphics.update
- pbUpdate(true)
- end
- tone = 255
- toneDiff = 40*20/Graphics.frame_rate
- loop do
- Graphics.update
- pbUpdate
- tone -= toneDiff
- @viewport.tone.set(tone,tone,tone,0)
- break if tone<=0
- end
- end
- def pbStartScreen(pokemon,newspecies)
- @pokemon = pokemon
- @newspecies = newspecies
- @sprites = {}
- @bgviewport = Viewport.new(0,0,Graphics.width,Graphics.height)
- @bgviewport.z = 99999
- @viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
- @viewport.z = 99999
- @msgviewport = Viewport.new(0,0,Graphics.width,Graphics.height)
- @msgviewport.z = 99999
- addBackgroundOrColoredPlane(@sprites,"background","evolutionbg",
- Color.new(248,248,248),@bgviewport)
- rsprite1 = PokemonSprite.new(@viewport)
- rsprite1.setOffset(PictureOrigin::Center)
- rsprite1.setPokemonBitmap(@pokemon,false)
- rsprite1.x = Graphics.width/2
- rsprite1.y = (Graphics.height-64)/2
- rsprite2 = PokemonSprite.new(@viewport)
- rsprite2.setOffset(PictureOrigin::Center)
- rsprite2.setPokemonBitmapSpecies(@pokemon,@newspecies,false)
- rsprite2.x = rsprite1.x
- rsprite2.y = rsprite1.y
- rsprite2.opacity = 0
- @sprites["rsprite1"] = rsprite1
- @sprites["rsprite2"] = rsprite2
- pbGenerateMetafiles(rsprite1.ox,rsprite1.oy,rsprite2.ox,rsprite2.oy)
- @sprites["msgwindow"] = pbCreateMessageWindow(@msgviewport)
- pbFadeInAndShow(@sprites) { pbUpdate }
- end
- # Closes the evolution screen.
- def pbEndScreen
- pbDisposeMessageWindow(@sprites["msgwindow"])
- pbFadeOutAndHide(@sprites) { pbUpdate }
- pbDisposeSpriteHash(@sprites)
- @viewport.dispose
- @bgviewport.dispose
- @msgviewport.dispose
- end
- # Opens the evolution screen
- def pbEvolution(cancancel=true)
- metaplayer1 = SpriteMetafilePlayer.new(@metafile1,@sprites["rsprite1"])
- metaplayer2 = SpriteMetafilePlayer.new(@metafile2,@sprites["rsprite2"])
- metaplayer1.play
- metaplayer2.play
- pbBGMStop
- pbPlayCry(@pokemon)
- pbMessageDisplay(@sprites["msgwindow"],
- _INTL("\\se[]What? {1} is evolving!\\^",@pokemon.name)) { pbUpdate }
- pbMessageWaitForInput(@sprites["msgwindow"],50,true) { pbUpdate }
- pbPlayDecisionSE
- oldstate = pbSaveSpriteState(@sprites["rsprite1"])
- oldstate2 = pbSaveSpriteState(@sprites["rsprite2"])
- pbMEPlay("Evolution start")
- pbBGMPlay("Evolution")
- canceled = false
- begin
- pbUpdateNarrowScreen
- metaplayer1.update
- metaplayer2.update
- Graphics.update
- Input.update
- pbUpdate(true)
- if Input.trigger?(Input::B) && cancancel
- pbBGMStop
- pbPlayCancelSE
- canceled = true
- break
- end
- end while metaplayer1.playing? && metaplayer2.playing?
- pbFlashInOut(canceled,oldstate,oldstate2)
- if canceled
- pbMessageDisplay(@sprites["msgwindow"],
- _INTL("Huh? {1} stopped evolving!",@pokemon.name)) { pbUpdate }
- else
- pbEvolutionSuccess
- end
- end
- def pbEvolutionSuccess
- # Play cry of evolved species
- frames = pbCryFrameLength(@newspecies,@pokemon.form)
- pbBGMStop
- pbPlayCrySpecies(@newspecies,@pokemon.form)
- frames.times do
- Graphics.update
- pbUpdate
- end
- # Success jingle/message
- pbMEPlay("Evolution success")
- newspeciesname = PBSpecies.getName(@newspecies)
- oldspeciesname = PBSpecies.getName(@pokemon.species)
- pbMessageDisplay(@sprites["msgwindow"],
- _INTL("\\se[]Congratulations! Your {1} evolved into {2}!\\wt[80]",
- @pokemon.name,newspeciesname)) { pbUpdate }
- @sprites["msgwindow"].text = ""
- # Check for consumed item and check if Pokémon should be duplicated
- createSpecies = pbRemoveItemAfterEvolution
- # Modify Pokémon to make it evolved
- @pokemon.species = @newspecies
- @pokemon.name = newspeciesname if @pokemon.name==oldspeciesname
- @pokemon.form = 0 if isConst?(@pokemon.species,PBSpecies,:MOTHIM)
- @pokemon.calcStats
- # See and own evolved species
- $Trainer.seen[@newspecies] = true
- $Trainer.owned[@newspecies] = true
- pbSeenForm(@pokemon)
- # Learn moves upon evolution for evolved species
- movelist = @pokemon.getMoveList
- for i in movelist
- next if i[0]!=0 && i[0]!=@pokemon.level # 0 is "learn upon evolution"
- pbLearnMove(@pokemon,i[1],true) { pbUpdate }
- end
- # Duplicate Pokémon (i.e. Shedinja)
- if $Trainer.partyplus>=1
- if createSpecies>0 && $Trainer.party.length<$Trainer.partyplus
- pbDuplicatePokemon(createSpecies)
- # Consume Poké Ball
- $PokemonBag.pbDeleteItem(getConst(PBItems,:POKEBALL))
- end
- else
- if createSpecies>0 && $Trainer.party.length<6
- pbDuplicatePokemon(createSpecies)
- # Consume Poké Ball
- $PokemonBag.pbDeleteItem(getConst(PBItems,:POKEBALL))
- end
- end
- end
- def pbRemoveItemAfterEvolution
- removeItem = false
- createSpecies = pbCheckEvolutionEx(@pokemon) { |pokemon,evonib,level,pkmn|
- case evonib
- when PBEvolution::Shedinja
- next pkmn if $PokemonBag.pbHasItem?(getConst(PBItems,:POKEBALL))
- when PBEvolution::TradeItem,PBEvolution::DayHoldItem,PBEvolution::NightHoldItem
- removeItem = true if pkmn==@newspecies # Item is now consumed
- end
- next -1
- }
- @pokemon.setItem(0) if removeItem
- return createSpecies
- end
- def pbDuplicatePokemon(createSpecies)
- newpokemon = @pokemon.clone
- newpokemon.species = createSpecies
- newpokemon.name = PBSpecies.getName(createSpecies)
- newpokemon.iv = @pokemon.iv.clone
- newpokemon.ev = @pokemon.ev.clone
- newpokemon.markings = 0
- newpokemon.ballused = 0
- newpokemon.setItem(0)
- newpokemon.clearAllRibbons
- newpokemon.calcStats
- newpokemon.heal
- # Add duplicate Pokémon to party
- $Trainer.party.push(newpokemon)
- # See and own duplicate Pokémon
- $Trainer.seen[createSpecies] = true
- $Trainer.owned[createSpecies] = true
- pbSeenForm(newpokemon)
- end
- end
- #------------------------------------------------------------------------------#
- # PBattle_OrgBattle
- #------------------------------------------------------------------------------#
- def pbBattleFactoryPokemon(rule,numwins,numswaps,rentals)
- table=nil
- btpokemon=pbGetBTPokemon(pbBattleChallenge.currentChallenge)
- ivtable=[
- 0,6,3,6,
- 7,13,6,9,
- 14,20,9,12,
- 21,27,12,15,
- 28,34,15,21,
- 35,41,21,31,
- 42,-1,31,31
- ]
- groups=[
- 1,14,6,0,
- 15,21,5,1,
- 22,28,4,2,
- 29,35,3,3,
- 36,42,2,4,
- 43,-1,1,5
- ]
- if rule.ruleset.suggestedLevel!=100
- table=[
- 0,6,110,199,
- 7,13,162,266,
- 14,20,267,371,
- 21,27,372,467,
- 28,34,468,563,
- 35,41,564,659,
- 42,48,660,755,
- 49,-1,372,849
- ]
- else # Open Level (Level 100)
- table=[
- 0,6,372,467,
- 7,13,468,563,
- 14,20,564,659,
- 21,27,660,755,
- 28,34,372,881,
- 35,41,372,881,
- 42,48,372,881,
- 49,-1,372,881
- ]
- end
- pokemonNumbers=[0,0]
- ivs=[0,0]
- ivgroups=[6,0]
- for i in 0...table.length/4
- if table[i*4]<=numwins
- if (table[i*4+1]<0 || table[i*4+1]>=numwins)
- pokemonNumbers=[
- table[i*4+2]*btpokemon.length/882,
- table[i*4+3]*btpokemon.length/882
- ]
- end
- end
- end
- for i in 0...ivtable.length/4
- if ivtable[i*4]<=numwins
- if (ivtable[i*4+1]<0 || ivtable[i*4+1]>=numwins)
- ivs=[ivtable[i*4+2],ivtable[i*4+3]]
- end
- end
- end
- for i in 0...groups.length/4
- if groups[i*4]<=numswaps
- if (groups[i*4+1]<0 || groups[i*4+1]>=numswaps)
- ivgroups=[groups[i*4+2],groups[i*4+3]]
- end
- end
- end
- party=[]
- if $Trainer.partyplus>=1
- begin
- party.clear
- while party.length<$Trainer.partyplus
- rnd=pokemonNumbers[0]+rand(pokemonNumbers[1]-pokemonNumbers[0]+1)
- rndpoke=btpokemon[rnd]
- indvalue=(party.length<ivgroups[0]) ? ivs[0] : ivs[1]
- party.push(rndpoke.createPokemon(rule.ruleset.suggestedLevel,indvalue,nil))
- end
- end until rule.ruleset.isValid?(party)
- else
- begin
- party.clear
- while party.length<6
- rnd=pokemonNumbers[0]+rand(pokemonNumbers[1]-pokemonNumbers[0]+1)
- rndpoke=btpokemon[rnd]
- indvalue=(party.length<ivgroups[0]) ? ivs[0] : ivs[1]
- party.push(rndpoke.createPokemon(rule.ruleset.suggestedLevel,indvalue,nil))
- end
- end until rule.ruleset.isValid?(party)
- end
- return party
- end
- #------------------------------------------------------------------------------#
- # PSystem_PokemonUtilities
- #------------------------------------------------------------------------------#
- #===============================================================================
- # Nicknaming and storing Pokémon
- #===============================================================================
- def pbBoxesFull?
- if $Trainer.partyplus>=1
- return ($Trainer.party.length==$Trainer.partyplus && $PokemonStorage.full?)
- else
- return ($Trainer.party.length==6 && $PokemonStorage.full?)
- end
- end
- def pbStorePokemon(pokemon)
- if pbBoxesFull?
- pbMessage(_INTL("There's no more room for Pokémon!\1"))
- pbMessage(_INTL("The Pokémon Boxes are full and can't accept any more!"))
- return
- end
- pokemon.pbRecordFirstMoves
- if $Trainer.partyplus>=1
- if $Trainer.party.length<$Trainer.partyplus
- $Trainer.party[$Trainer.party.length] = pokemon
- else
- oldcurbox = $PokemonStorage.currentBox
- storedbox = $PokemonStorage.pbStoreCaught(pokemon)
- curboxname = $PokemonStorage[oldcurbox].name
- boxname = $PokemonStorage[storedbox].name
- creator = nil
- creator = pbGetStorageCreator if $PokemonGlobal.seenStorageCreator
- if storedbox!=oldcurbox
- if creator
- pbMessage(_INTL("Box \"{1}\" on {2}'s PC was full.\1",curboxname,creator))
- else
- pbMessage(_INTL("Box \"{1}\" on someone's PC was full.\1",curboxname))
- end
- pbMessage(_INTL("{1} was transferred to box \"{2}.\"",pokemon.name,boxname))
- else
- if creator
- pbMessage(_INTL("{1} was transferred to {2}'s PC.\1",pokemon.name,creator))
- else
- pbMessage(_INTL("{1} was transferred to someone's PC.\1",pokemon.name))
- end
- pbMessage(_INTL("It was stored in box \"{1}.\"",boxname))
- end
- end
- else
- if $Trainer.party.length<6
- $Trainer.party[$Trainer.party.length] = pokemon
- else
- oldcurbox = $PokemonStorage.currentBox
- storedbox = $PokemonStorage.pbStoreCaught(pokemon)
- curboxname = $PokemonStorage[oldcurbox].name
- boxname = $PokemonStorage[storedbox].name
- creator = nil
- creator = pbGetStorageCreator if $PokemonGlobal.seenStorageCreator
- if storedbox!=oldcurbox
- if creator
- pbMessage(_INTL("Box \"{1}\" on {2}'s PC was full.\1",curboxname,creator))
- else
- pbMessage(_INTL("Box \"{1}\" on someone's PC was full.\1",curboxname))
- end
- pbMessage(_INTL("{1} was transferred to box \"{2}.\"",pokemon.name,boxname))
- else
- if creator
- pbMessage(_INTL("{1} was transferred to {2}'s PC.\1",pokemon.name,creator))
- else
- pbMessage(_INTL("{1} was transferred to someone's PC.\1",pokemon.name))
- end
- pbMessage(_INTL("It was stored in box \"{1}.\"",boxname))
- end
- end
- end
- end
- #===============================================================================
- # Giving Pokémon to the player (will send to storage if party is full)
- #===============================================================================
- def pbAddPokemonSilent(pokemon,level=nil,seeform=true)
- return false if !pokemon || pbBoxesFull?
- pokemon = getID(PBSpecies,pokemon)
- if pokemon.is_a?(Integer) && level.is_a?(Integer)
- pokemon = pbNewPkmn(pokemon,level)
- end
- $Trainer.seen[pokemon.species] = true
- $Trainer.owned[pokemon.species] = true
- pbSeenForm(pokemon) if seeform
- pokemon.pbRecordFirstMoves
- if $Trainer.partyplus>=1
- if $Trainer.party.length<$Trainer.partyplus
- $Trainer.party[$Trainer.party.length] = pokemon
- else
- $PokemonStorage.pbStoreCaught(pokemon)
- end
- else
- if $Trainer.party.length<6
- $Trainer.party[$Trainer.party.length] = pokemon
- else
- $PokemonStorage.pbStoreCaught(pokemon)
- end
- end
- return true
- end
- #===============================================================================
- # Giving Pokémon/eggs to the player (can only add to party)
- #===============================================================================
- def pbAddToParty(pokemon,level=nil,seeform=true)
- if $Trainer.partyplus>=1
- return false if !pokemon || $Trainer.party.length>=$Trainer.partyplus
- else
- return false if !pokemon || $Trainer.party.length>=6
- end
- pokemon = getID(PBSpecies,pokemon)
- if pokemon.is_a?(Integer) && level.is_a?(Integer)
- pokemon = pbNewPkmn(pokemon,level)
- end
- speciesname = PBSpecies.getName(pokemon.species)
- pbMessage(_INTL("\\me[Pkmn get]{1} obtained {2}!\1",$Trainer.name,speciesname))
- pbNicknameAndStore(pokemon)
- pbSeenForm(pokemon) if seeform
- return true
- end
- def pbAddToPartySilent(pokemon,level=nil,seeform=true)
- if $Trainer.partyplus>=1
- return false if !pokemon || $Trainer.party.length>=$Trainer.partyplus
- else
- return false if !pokemon || $Trainer.party.length>=6
- end
- pokemon = getID(PBSpecies,pokemon)
- if pokemon.is_a?(Integer) && level.is_a?(Integer)
- pokemon = pbNewPkmn(pokemon,level)
- end
- $Trainer.seen[pokemon.species] = true
- $Trainer.owned[pokemon.species] = true
- pbSeenForm(pokemon) if seeform
- pokemon.pbRecordFirstMoves
- $Trainer.party[$Trainer.party.length] = pokemon
- return true
- end
- def pbAddForeignPokemon(pokemon,level=nil,ownerName=nil,nickname=nil,ownerGender=0,seeform=true)
- if $Trainer.partyplus>=1
- return false if !pokemon || $Trainer.party.length>=$Trainer.partyplus
- else
- return false if !pokemon || $Trainer.party.length>=6
- end
- pokemon = getID(PBSpecies,pokemon)
- if pokemon.is_a?(Integer) && level.is_a?(Integer)
- pokemon = pbNewPkmn(pokemon,level)
- end
- # Set original trainer to a foreign one (if ID isn't already foreign)
- if pokemon.trainerID==$Trainer.id
- pokemon.trainerID = $Trainer.getForeignID
- pokemon.ot = ownerName if ownerName && ownerName!=""
- pokemon.otgender = ownerGender
- end
- # Set nickname
- pokemon.name = nickname[0,PokeBattle_Pokemon::MAX_POKEMON_NAME_SIZE] if nickname && nickname!=""
- # Recalculate stats
- pokemon.calcStats
- if ownerName
- pbMessage(_INTL("\\me[Pkmn get]{1} received a Pokémon from {2}.\1",$Trainer.name,ownerName))
- else
- pbMessage(_INTL("\\me[Pkmn get]{1} received a Pokémon.\1",$Trainer.name))
- end
- pbStorePokemon(pokemon)
- $Trainer.seen[pokemon.species] = true
- $Trainer.owned[pokemon.species] = true
- pbSeenForm(pokemon) if seeform
- return true
- end
- def pbGenerateEgg(pokemon,text="")
- if $Trainer.partyplus>=1
- return false if !pokemon || $Trainer.party.length>=$Trainer.partyplus
- else
- return false if !pokemon || $Trainer.party.length>=6
- end
- pokemon = getID(PBSpecies,pokemon)
- if pokemon.is_a?(Integer)
- pokemon = pbNewPkmn(pokemon,EGG_LEVEL)
- end
- # Get egg steps
- eggSteps = pbGetSpeciesData(pokemon.species,pokemon.form,SpeciesStepsToHatch)
- # Set egg's details
- pokemon.name = _INTL("Egg")
- pokemon.eggsteps = eggSteps
- pokemon.obtainText = text
- pokemon.calcStats
- # Add egg to party
- $Trainer.party[$Trainer.party.length] = pokemon
- return true
- end
- #------------------------------------------------------------------------------#
- # PSystem_Utilities
- #------------------------------------------------------------------------------#
- def pbMoveTutorAnnotations(move,movelist=nil)
- ret = []
- if $Trainer.partyplus>=1
- for i in 0...$Trainer.partyplus
- ret[i] = nil
- next if i>=$Trainer.party.length
- found = false
- for j in 0...4
- if !$Trainer.party[i].egg? && $Trainer.party[i].moves[j].id==move
- ret[i] = _INTL("LEARNED")
- found = true
- end
- end
- next if found
- species = $Trainer.party[i].species
- if !$Trainer.party[i].egg? && movelist && movelist.any? { |j| j==species }
- # Checked data from movelist
- ret[i] = _INTL("ABLE")
- elsif !$Trainer.party[i].egg? && $Trainer.party[i].compatibleWithMove?(move)
- # Checked data from PBS/tm.txt
- ret[i] = _INTL("ABLE")
- else
- ret[i] = _INTL("NOT ABLE")
- end
- end
- else
- for i in 0...6
- ret[i] = nil
- next if i>=$Trainer.party.length
- found = false
- for j in 0...4
- if !$Trainer.party[i].egg? && $Trainer.party[i].moves[j].id==move
- ret[i] = _INTL("LEARNED")
- found = true
- end
- end
- next if found
- species = $Trainer.party[i].species
- if !$Trainer.party[i].egg? && movelist && movelist.any? { |j| j==species }
- # Checked data from movelist
- ret[i] = _INTL("ABLE")
- elsif !$Trainer.party[i].egg? && $Trainer.party[i].compatibleWithMove?(move)
- # Checked data from PBS/tm.txt
- ret[i] = _INTL("ABLE")
- else
- ret[i] = _INTL("NOT ABLE")
- end
- end
- end
- return ret
- end
- #------------------------------------------------------------------------------#
- # Debug_Actions
- #------------------------------------------------------------------------------#
- def pbDebugDayCare
- commands = [_INTL("Withdraw Pokémon 1"),
- _INTL("Withdraw Pokémon 2"),
- _INTL("Deposit Pokémon"),
- _INTL("Generate egg"),
- _INTL("Collect egg")]
- viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
- viewport.z = 99999
- sprites = {}
- addBackgroundPlane(sprites,"background","hatchbg",viewport)
- sprites["overlay"] = BitmapSprite.new(Graphics.width,Graphics.height,viewport)
- pbSetSystemFont(sprites["overlay"].bitmap)
- sprites["cmdwindow"] = Window_CommandPokemonEx.new(commands)
- cmdwindow = sprites["cmdwindow"]
- cmdwindow.x = 0
- cmdwindow.y = Graphics.height-128
- cmdwindow.width = Graphics.width
- cmdwindow.height = 128
- cmdwindow.viewport = viewport
- cmdwindow.columns = 2
- base = Color.new(248,248,248)
- shadow = Color.new(104,104,104)
- refresh = true
- loop do
- if refresh
- if pbEggGenerated?
- commands[3] = _INTL("Discard egg")
- else
- commands[3] = _INTL("Generate egg")
- end
- cmdwindow.commands = commands
- sprites["overlay"].bitmap.clear
- textpos = []
- for i in 0...2
- textpos.push([_INTL("Pokémon {1}",i+1),Graphics.width/4+i*Graphics.width/2,8,2,base,shadow])
- end
- for i in 0...pbDayCareDeposited
- next if !$PokemonGlobal.daycare[i][0]
- y = 40
- pkmn = $PokemonGlobal.daycare[i][0]
- initlevel = $PokemonGlobal.daycare[i][1]
- leveldiff = pkmn.level-initlevel
- textpos.push([pkmn.name+" ("+PBSpecies.getName(pkmn.species)+")",8+i*Graphics.width/2,y,0,base,shadow])
- y += 32
- if pkmn.male?
- textpos.push([_INTL("Male ♂"),8+i*Graphics.width/2,y,0,Color.new(128,192,248),shadow])
- elsif pkmn.female?
- textpos.push([_INTL("Female ♀"),8+i*Graphics.width/2,y,0,Color.new(248,96,96),shadow])
- else
- textpos.push([_INTL("Genderless"),8+i*Graphics.width/2,y,0,base,shadow])
- end
- y += 32
- if initlevel>=PBExperience.maxLevel
- textpos.push(["Lv. #{initlevel} (max)",8+i*Graphics.width/2,y,0,base,shadow])
- elsif leveldiff>0
- textpos.push(["Lv. #{initlevel} -> #{pkmn.level} (+#{leveldiff})",
- 8+i*Graphics.width/2,y,0,base,shadow])
- else
- textpos.push(["Lv. #{initlevel} (no change)",8+i*Graphics.width/2,y,0,base,shadow])
- end
- y += 32
- if pkmn.level<PBExperience.maxLevel
- endexp = PBExperience.pbGetStartExperience(pkmn.level+1,pkmn.growthrate)
- textpos.push(["To next Lv.: #{endexp-pkmn.exp}",8+i*Graphics.width/2,y,0,base,shadow])
- y += 32
- end
- cost = pbDayCareGetCost(i)
- textpos.push(["Cost: $#{cost}",8+i*Graphics.width/2,y,0,base,shadow])
- end
- if pbEggGenerated?
- textpos.push(["Egg waiting for collection",Graphics.width/2,216,2,Color.new(248,248,0),shadow])
- elsif pbDayCareDeposited==2
- if pbDayCareGetCompat==0
- textpos.push(["Pokémon cannot breed",Graphics.width/2,216,2,Color.new(248,96,96),shadow])
- else
- textpos.push(["Pokémon can breed",Graphics.width/2,216,2,Color.new(64,248,64),shadow])
- end
- end
- pbDrawTextPositions(sprites["overlay"].bitmap,textpos)
- refresh = false
- end
- pbUpdateSpriteHash(sprites)
- Graphics.update
- Input.update
- if Input.trigger?(Input::B)
- break
- elsif Input.trigger?(Input::C)
- ret = cmdwindow.index
- if $Trainer.partyplus>=1
- case cmdwindow.index
- when 0 # Withdraw Pokémon 1
- if !$PokemonGlobal.daycare[0][0]
- pbPlayBuzzerSE
- elsif $Trainer.party.length>=$Trainer.partyplus
- pbPlayBuzzerSE
- pbMessage(_INTL("Party is full, can't withdraw Pokémon."))
- else
- pbPlayDecisionSE
- pbDayCareGetDeposited(0,3,4)
- pbDayCareWithdraw(0)
- refresh = true
- end
- when 1 # Withdraw Pokémon 2
- if !$PokemonGlobal.daycare[1][0]
- pbPlayBuzzerSE
- elsif $Trainer.party.length>=$Trainer.partyplus
- pbPlayBuzzerSE
- pbMessage(_INTL("Party is full, can't withdraw Pokémon."))
- else
- pbPlayDecisionSE
- pbDayCareGetDeposited(1,3,4)
- pbDayCareWithdraw(1)
- refresh = true
- end
- when 2 # Deposit Pokémon
- if pbDayCareDeposited==2
- pbPlayBuzzerSE
- elsif $Trainer.party.length==0
- pbPlayBuzzerSE
- pbMessage(_INTL("Party is empty, can't deposit Pokémon."))
- else
- pbPlayDecisionSE
- pbChooseNonEggPokemon(1,3)
- if pbGet(1)>=0
- pbDayCareDeposit(pbGet(1))
- refresh = true
- end
- end
- when 3 # Generate/discard egg
- if pbEggGenerated?
- pbPlayDecisionSE
- $PokemonGlobal.daycareEgg = 0
- $PokemonGlobal.daycareEggSteps = 0
- refresh = true
- else
- if pbDayCareDeposited!=2 || pbDayCareGetCompat==0
- pbPlayBuzzerSE
- else
- pbPlayDecisionSE
- $PokemonGlobal.daycareEgg = 1
- refresh = true
- end
- end
- when 4 # Collect egg
- if $PokemonGlobal.daycareEgg!=1
- pbPlayBuzzerSE
- elsif $Trainer.party.length>=$Trainer.partyplus
- pbPlayBuzzerSE
- pbMessage(_INTL("Party is full, can't collect the egg."))
- else
- pbPlayDecisionSE
- pbDayCareGenerateEgg
- $PokemonGlobal.daycareEgg = 0
- $PokemonGlobal.daycareEggSteps = 0
- pbMessage(_INTL("Collected the {1} egg.",
- PBSpecies.getName($Trainer.lastParty.species)))
- refresh = true
- end
- end
- else
- case cmdwindow.index
- when 0 # Withdraw Pokémon 1
- if !$PokemonGlobal.daycare[0][0]
- pbPlayBuzzerSE
- elsif $Trainer.party.length>=6
- pbPlayBuzzerSE
- pbMessage(_INTL("Party is full, can't withdraw Pokémon."))
- else
- pbPlayDecisionSE
- pbDayCareGetDeposited(0,3,4)
- pbDayCareWithdraw(0)
- refresh = true
- end
- when 1 # Withdraw Pokémon 2
- if !$PokemonGlobal.daycare[1][0]
- pbPlayBuzzerSE
- elsif $Trainer.party.length>=6
- pbPlayBuzzerSE
- pbMessage(_INTL("Party is full, can't withdraw Pokémon."))
- else
- pbPlayDecisionSE
- pbDayCareGetDeposited(1,3,4)
- pbDayCareWithdraw(1)
- refresh = true
- end
- when 2 # Deposit Pokémon
- if pbDayCareDeposited==2
- pbPlayBuzzerSE
- elsif $Trainer.party.length==0
- pbPlayBuzzerSE
- pbMessage(_INTL("Party is empty, can't deposit Pokémon."))
- else
- pbPlayDecisionSE
- pbChooseNonEggPokemon(1,3)
- if pbGet(1)>=0
- pbDayCareDeposit(pbGet(1))
- refresh = true
- end
- end
- when 3 # Generate/discard egg
- if pbEggGenerated?
- pbPlayDecisionSE
- $PokemonGlobal.daycareEgg = 0
- $PokemonGlobal.daycareEggSteps = 0
- refresh = true
- else
- if pbDayCareDeposited!=2 || pbDayCareGetCompat==0
- pbPlayBuzzerSE
- else
- pbPlayDecisionSE
- $PokemonGlobal.daycareEgg = 1
- refresh = true
- end
- end
- when 4 # Collect egg
- if $PokemonGlobal.daycareEgg!=1
- pbPlayBuzzerSE
- elsif $Trainer.party.length>=6
- pbPlayBuzzerSE
- pbMessage(_INTL("Party is full, can't collect the egg."))
- else
- pbPlayDecisionSE
- pbDayCareGenerateEgg
- $PokemonGlobal.daycareEgg = 0
- $PokemonGlobal.daycareEggSteps = 0
- pbMessage(_INTL("Collected the {1} egg.",
- PBSpecies.getName($Trainer.lastParty.species)))
- refresh = true
- end
- end
- end
- end
- end
- pbDisposeSpriteHash(sprites)
- viewport.dispose
- end
- class PokeBattle_Battler
- attr_reader :fainted # Boolean to mark whether self has fainted properly
- attr_reader :benched # Boolean to mark whether self has fainted properly
- def hp=(value)
- @hp = value.to_i
- @pokemon.hp = value.to_i if @pokemon
- end
- def benchedflag
- return @pokemon.benchedflag
- end
- def fainted?; return @hp<=0; end
- alias isFainted? fainted?
- def benched?; return @benchedflag; end
- alias isBenched? benched?
- # Yields each unfainted ally Pokémon.
- def eachAlly
- @battle.battlers.each do |b|
- yield b if b && !b.fainted? && !b.benched? && !b.opposes?(@index) && b.index!=@index
- end
- end
- # Yields each unfainted opposing Pokémon.
- def eachOpposing
- @battle.battlers.each { |b| yield b if b && !b.fainted? && !b.benched? && b.opposes?(@index) }
- end
- end
- class PokeBattle_Battle
- #=============================================================================
- # Iterate through battlers
- #=============================================================================
- # def eachBattler
- # @battlers.each { |b| yield b if b && !b.fainted? || !b.benched?}
- # end
- # def eachSameSideBattler(idxBattler=0)
- # idxBattler = idxBattler.index if idxBattler.respond_to?("index")
- # @battlers.each { |b| yield b if b && !b.fainted? || !b.benched? && !b.opposes?(idxBattler) }
- # end
- # def eachOtherSideBattler(idxBattler=0)
- # idxBattler = idxBattler.index if idxBattler.respond_to?("index")
- # @battlers.each { |b| yield b if b && !b.fainted? || !b.benched? && b.opposes?(idxBattler) }
- # end
- #=============================================================================
- # Choosing Pokémon to switch
- #=============================================================================
- # Checks whether the replacement Pokémon (at party index idxParty) can enter
- # battle.
- # NOTE: Messages are only shown while in the party screen when choosing a
- # command for the next round.
- def pbCanSwitchLax?(idxBattler,idxParty,partyScene=nil)
- return true if idxParty<0
- party = pbParty(idxBattler)
- return false if idxParty>=party.length
- return false if !party[idxParty]
- if party[idxParty].egg?
- partyScene.pbDisplay(_INTL("An Egg can't battle!")) if partyScene
- return false
- end
- if !pbIsOwner?(idxBattler,idxParty)
- owner = pbGetOwnerFromPartyIndex(idxBattler,idxParty)
- partyScene.pbDisplay(_INTL("You can't switch {1}'s Pokémon with one of yours!",
- owner.name)) if partyScene
- return false
- end
- if party[idxParty].fainted?
- partyScene.pbDisplay(_INTL("{1} has no energy left to battle!",
- party[idxParty].name)) if partyScene
- return false
- end
- if party[idxParty].benched?
- partyScene.pbDisplay(_INTL("{1} can only watch, not participate!",
- party[idxParty].name)) if partyScene
- return false
- end
- if pbFindBattler(idxParty,idxBattler)
- partyScene.pbDisplay(_INTL("{1} is already in battle!",
- party[idxParty].name)) if partyScene
- return false
- end
- return true
- end
- #=============================================================================
- # Switching Pokémon
- #=============================================================================
- # General switching method that checks if any Pokémon need to be sent out and,
- # if so, does. Called at the end of each round.
- def pbEORSwitch(favorDraws=false)
- return if @decision>0 && !favorDraws
- return if @decision==5 && favorDraws
- pbJudge
- return if @decision>0
- # Check through each fainted battler to see if that spot can be filled.
- switched = []
- loop do
- switched.clear
- @battlers.each do |b|
- next if !b || !b.fainted? || !b.benched?
- idxBattler = b.index
- next if !pbCanChooseNonActive?(idxBattler)
- if !pbOwnedByPlayer?(idxBattler) # Opponent/ally is switching in
- next if wildBattle? && opposes?(idxBattler) # Wild Pokémon can't switch
- idxPartyNew = pbSwitchInBetween(idxBattler)
- opponent = pbGetOwnerFromBattlerIndex(idxBattler)
- # NOTE: The player is only offered the chance to switch their own
- # Pokémon when an opponent replaces a fainted Pokémon in single
- # battles. In double battles, etc. there is no such offer.
- if @internalBattle && @switchStyle && trainerBattle? && pbSideSize(0)==1 &&
- opposes?(idxBattler) && !@battlers[0].fainted? && pbCanChooseNonActive?(0) &&
- @battlers[0].effects[PBEffects::Outrage]==0
- idxPartyForName = idxPartyNew
- enemyParty = pbParty(idxBattler)
- if isConst?(enemyParty[idxPartyNew].ability,PBAbilities,:ILLUSION)
- idxPartyForName = pbLastInTeam(idxBattler)
- end
- if pbDisplayConfirm(_INTL("{1} is about to send in {2}. Will you switch your Pokémon?",
- opponent.fullname,enemyParty[idxPartyForName].name))
- idxPlayerPartyNew = pbSwitchInBetween(0,false,true)
- if idxPlayerPartyNew>=0
- pbMessageOnRecall(@battlers[0])
- pbRecallAndReplace(0,idxPlayerPartyNew)
- switched.push(0)
- end
- end
- end
- pbRecallAndReplace(idxBattler,idxPartyNew)
- switched.push(idxBattler)
- elsif trainerBattle? # Player switches in in a trainer battle
- idxPlayerPartyNew = pbGetReplacementPokemonIndex(idxBattler) # Owner chooses
- pbRecallAndReplace(idxBattler,idxPlayerPartyNew)
- switched.push(idxBattler)
- else # Player's Pokémon has fainted in a wild battle
- switch = false
- if !pbDisplayConfirm(_INTL("Use next Pokémon?"))
- switch = (pbRun(idxBattler,true)<=0)
- else
- switch = true
- end
- if switch
- idxPlayerPartyNew = pbGetReplacementPokemonIndex(idxBattler) # Owner chooses
- pbRecallAndReplace(idxBattler,idxPlayerPartyNew)
- switched.push(idxBattler)
- end
- end
- end
- break if switched.length==0
- pbPriority(true).each do |b|
- b.pbEffectsOnSwitchIn(true) if switched.include?(b.index)
- end
- end
- end
- # Actually performs the recalling and sending out in all situations.
- def pbRecallAndReplace(idxBattler,idxParty,randomReplacement=false,batonPass=false)
- @scene.pbRecall(idxBattler) if !@battlers[idxBattler].fainted? || !@battlers[idxBattler].benched?
- @battlers[idxBattler].pbAbilitiesOnSwitchOut # Inc. primordial weather check
- @scene.pbShowPartyLineup(idxBattler&1) if pbSideSize(idxBattler)==1
- pbMessagesOnReplace(idxBattler,idxParty) if !randomReplacement
- pbReplace(idxBattler,idxParty,batonPass)
- end
- #=============================================================================
- # Check whether actions can be taken
- #=============================================================================
- def pbCanShowCommands?(idxBattler)
- battler = @battlers[idxBattler]
- return false if !battler || battler.fainted?
- return false if !battler || battler.benched?
- return false if battler.usingMultiTurnAttack?
- return true
- end
- end
- #===============================================================================
- # Individual trainer editor
- #===============================================================================
- module TrainerBattleProperty
- def self.set(settingname,oldsetting)
- return nil if !oldsetting
- properties = [
- [_INTL("Trainer Type"),TrainerTypeProperty,_INTL("Name of the trainer type for this Trainer.")],
- [_INTL("Trainer Name"),StringProperty,_INTL("Name of the Trainer.")],
- [_INTL("Battle ID"),LimitProperty.new(9999),_INTL("ID used to distinguish Trainers with the same name and trainer type.")],
- [_INTL("Lose Text"),StringProperty,_INTL("Message shown in battle when the Trainer is defeated.")],
- [_INTL("Pokémon 1"),TrainerPokemonProperty,_INTL("1st Pokémon.")],
- [_INTL("Pokémon 2"),TrainerPokemonProperty,_INTL("2nd Pokémon.")],
- [_INTL("Pokémon 3"),TrainerPokemonProperty,_INTL("3rd Pokémon.")],
- [_INTL("Pokémon 4"),TrainerPokemonProperty,_INTL("4th Pokémon.")],
- [_INTL("Pokémon 5"),TrainerPokemonProperty,_INTL("5th Pokémon.")],
- [_INTL("Pokémon 6"),TrainerPokemonProperty,_INTL("6th Pokémon.")],
- [_INTL("Pokémon 7"),TrainerPokemonProperty,_INTL("7th Pokémon.")],
- [_INTL("Pokémon 8"),TrainerPokemonProperty,_INTL("8th Pokémon.")],
- [_INTL("Pokémon 9"),TrainerPokemonProperty,_INTL("9th Pokémon.")],
- [_INTL("Pokémon 10"),TrainerPokemonProperty,_INTL("10th Pokémon.")],
- [_INTL("Pokémon 11"),TrainerPokemonProperty,_INTL("11th Pokémon.")],
- [_INTL("Pokémon 12"),TrainerPokemonProperty,_INTL("12th Pokémon.")],
- [_INTL("Pokémon 13"),TrainerPokemonProperty,_INTL("13th Pokémon.")],
- [_INTL("Pokémon 14"),TrainerPokemonProperty,_INTL("14th Pokémon.")],
- [_INTL("Pokémon 15"),TrainerPokemonProperty,_INTL("15th Pokémon.")],
- [_INTL("Pokémon 16"),TrainerPokemonProperty,_INTL("16th Pokémon.")],
- [_INTL("Pokémon 17"),TrainerPokemonProperty,_INTL("17th Pokémon.")],
- [_INTL("Pokémon 18"),TrainerPokemonProperty,_INTL("18th Pokémon.")],
- [_INTL("Pokémon 19"),TrainerPokemonProperty,_INTL("19th Pokémon.")],
- [_INTL("Pokémon 20"),TrainerPokemonProperty,_INTL("20th Pokémon.")],
- [_INTL("Pokémon 21"),TrainerPokemonProperty,_INTL("21th Pokémon.")],
- [_INTL("Pokémon 22"),TrainerPokemonProperty,_INTL("22th Pokémon.")],
- [_INTL("Pokémon 23"),TrainerPokemonProperty,_INTL("23th Pokémon.")],
- [_INTL("Pokémon 24"),TrainerPokemonProperty,_INTL("24th Pokémon.")],
- [_INTL("Pokémon 25"),TrainerPokemonProperty,_INTL("25th Pokémon.")],
- [_INTL("Pokémon 26"),TrainerPokemonProperty,_INTL("26th Pokémon.")],
- [_INTL("Pokémon 27"),TrainerPokemonProperty,_INTL("27th Pokémon.")],
- [_INTL("Pokémon 28"),TrainerPokemonProperty,_INTL("28th Pokémon.")],
- [_INTL("Pokémon 29"),TrainerPokemonProperty,_INTL("29th Pokémon.")],
- [_INTL("Pokémon 30"),TrainerPokemonProperty,_INTL("30th Pokémon.")],
- [_INTL("Pokémon 31"),TrainerPokemonProperty,_INTL("31th Pokémon.")],
- [_INTL("Pokémon 32"),TrainerPokemonProperty,_INTL("32th Pokémon.")],
- [_INTL("Pokémon 33"),TrainerPokemonProperty,_INTL("33th Pokémon.")],
- [_INTL("Pokémon 34"),TrainerPokemonProperty,_INTL("34th Pokémon.")],
- [_INTL("Pokémon 35"),TrainerPokemonProperty,_INTL("35th Pokémon.")],
- [_INTL("Pokémon 36"),TrainerPokemonProperty,_INTL("36th Pokémon.")],
- [_INTL("Pokémon 37"),TrainerPokemonProperty,_INTL("37th Pokémon.")],
- [_INTL("Pokémon 38"),TrainerPokemonProperty,_INTL("38th Pokémon.")],
- [_INTL("Pokémon 39"),TrainerPokemonProperty,_INTL("39th Pokémon.")],
- [_INTL("Pokémon 40"),TrainerPokemonProperty,_INTL("40th Pokémon.")],
- [_INTL("Item 1"),ItemProperty,_INTL("Item used by the Trainer during battle.")],
- [_INTL("Item 2"),ItemProperty,_INTL("Item used by the Trainer during battle.")],
- [_INTL("Item 3"),ItemProperty,_INTL("Item used by the Trainer during battle.")],
- [_INTL("Item 4"),ItemProperty,_INTL("Item used by the Trainer during battle.")],
- [_INTL("Item 5"),ItemProperty,_INTL("Item used by the Trainer during battle.")],
- [_INTL("Item 6"),ItemProperty,_INTL("Item used by the Trainer during battle.")],
- [_INTL("Item 7"),ItemProperty,_INTL("Item used by the Trainer during battle.")],
- [_INTL("Item 8"),ItemProperty,_INTL("Item used by the Trainer during battle.")]
- ]
- if !pbPropertyList(settingname,oldsetting,properties,true)
- return nil
- end
- oldsetting = nil if !oldsetting[0] || oldsetting[0]==0
- return oldsetting
- end
- def self.format(value)
- return value.inspect
- end
- end
- class PokeBattle_NullBattlePeer
- def pbStorePokemon(player,pkmn)
- if $Trainer.partyplus>=1
- plus = $Trainer.partyplus
- else
- plus = 6
- end
- player.party[player.party.length] = pkmn if player.party.length<plus
- return -1
- end
- end
- def pbTrainerBattleEditor
- selection = 0
- trainertypes = pbLoadTrainerTypesData
- trainers = pbLoadTrainersData
- modified = false
- for trainer in trainers
- trtype = trainer[0]
- next if trainertypes && trainertypes[trtype]
- trainer[0] = 0
- modified = true
- end
- pbListScreenBlock(_INTL("Trainer Battles"),TrainerBattleLister.new(selection,true)) { |button,trtype|
- next if !trtype
- index = trtype[0]
- trainerdata = trtype[1]
- if button==Input::A
- # Delete trainer
- if index>=0
- if pbConfirmMessageSerious("Delete this trainer battle?")
- trainers.delete_at(index)
- modified = true
- pbMessage(_INTL("The Trainer battle was deleted."))
- end
- end
- elsif button==Input::C
- # New trainer/edit existing trainer
- selection = index
- if selection<0
- # New trainer
- trainertype = -1
- ret = pbMessage(_INTL("First, define the type of trainer."),[
- _INTL("Use existing type"),
- _INTL("Use new type"),
- _INTL("Cancel")],3)
- if ret==0
- trainertype = pbListScreen(_INTL("TRAINER TYPE"),TrainerTypeLister.new(0,false))
- next if !trainertype
- trainertype = trainertype[0]
- next if trainertype<0
- elsif ret==1
- trainertype = pbTrainerTypeEditorNew(nil)
- next if trainertype<0
- else
- next
- end
- trainername = pbMessageFreeText(_INTL("Now enter the trainer's name."),"",false,30)
- next if trainername==""
- trainerparty = pbGetFreeTrainerParty(trainertype,trainername)
- if trainerparty<0
- pbMessage(_INTL("There is no room to create a trainer of that type and name."))
- next
- end
- t = pbNewTrainer(trainertype,trainername,trainerparty,false)
- trainers.push(t) if t
- pbMessage(_INTL("The Trainer battle was added."))
- else
- # Edit existing trainer
- data = [trainerdata[0],trainerdata[1],trainerdata[4],trainerdata[5]] # Type, name, ID, lose text
- for i in 0...40
- data.push(trainerdata[3][i]) # Pokémon
- end
- for i in 0...8
- data.push(trainerdata[2][i]) # Items
- end
- loop do
- data = TrainerBattleProperty.set(trainerdata[1],data)
- break if !data
- trainerdata = [
- data[0],
- data[1],
- [data[44],data[45],data[46],data[47],data[48],data[49],data[50],data[51]].find_all { |i| i && i!=0 }, # Item list
- [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
- data[2],
- data[3]
- ]
- if !trainerdata[1] || trainerdata[1].length==0
- pbMessage(_INTL("Can't save. No name was entered."))
- elsif trainerdata[3].length==0
- pbMessage(_INTL("Can't save. The Pokémon list is empty."))
- else
- trainers[index] = trainerdata
- modified = true
- break
- end
- end
- end
- end
- }
- if modified && pbConfirmMessage(_INTL("Save changes?"))
- save_data(trainers,"Data/trainers.dat")
- $PokemonTemp.trainersData = nil
- pbConvertTrainerData
- end
- end
Add Comment
Please, Sign In to add comment