Vendily

Party balls

Jul 13th, 2018
246
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class PokeSelectionPlaceholderSprite < SpriteWrapper
  2.   attr_accessor :text
  3.  
  4.   def initialize(pokemon,index,viewport=nil)
  5.     super(viewport)
  6.     xvalues=[0,256,0,256,0,256]
  7.     yvalues=[0,16,96,112,192,208]
  8.     @pbitmap=AnimatedBitmap.new("Graphics/Pictures/partyPanelBlank")
  9.     self.bitmap=@pbitmap.bitmap
  10.     self.x=xvalues[index]
  11.     self.y=yvalues[index]
  12.     @text=nil
  13.   end
  14.  
  15.   def update
  16.     super
  17.     @pbitmap.update
  18.     self.bitmap=@pbitmap.bitmap
  19.   end
  20.  
  21.   def selected
  22.     return false
  23.   end
  24.  
  25.   def selected=(value)
  26.   end
  27.  
  28.   def preselected
  29.     return false
  30.   end
  31.  
  32.   def preselected=(value)
  33.   end
  34.  
  35.   def switching
  36.     return false
  37.   end
  38.  
  39.   def switching=(value)
  40.   end
  41.  
  42.   def refresh
  43.   end
  44.  
  45.   def dispose
  46.     @pbitmap.dispose
  47.     super
  48.   end
  49. end
  50.  
  51.  
  52.  
  53. class PokeSelectionConfirmCancelSprite < SpriteWrapper
  54.   attr_reader :selected
  55.  
  56.   def initialize(text,x,y,narrowbox=false,viewport=nil)
  57.     super(viewport)
  58.     @refreshBitmap=true
  59.     @bgsprite=ChangelingSprite.new(0,0,viewport)
  60.     if narrowbox
  61.       @bgsprite.addBitmap("deselbitmap","Graphics/Pictures/partyCancelNarrow")
  62.       @bgsprite.addBitmap("selbitmap","Graphics/Pictures/partyCancelSelNarrow")
  63.     else
  64.       @bgsprite.addBitmap("deselbitmap","Graphics/Pictures/partyCancel")
  65.       @bgsprite.addBitmap("selbitmap","Graphics/Pictures/partyCancelSel")
  66.     end
  67.     @bgsprite.changeBitmap("deselbitmap")
  68.     @overlaysprite=BitmapSprite.new(@bgsprite.bitmap.width,@bgsprite.bitmap.height,viewport)
  69.     @yoffset=8
  70.     ynarrow=narrowbox ? -6 : 0
  71.     pbSetSystemFont(@overlaysprite.bitmap)
  72.     textpos=[[text,56,8+ynarrow,2,Color.new(248,248,248),Color.new(40,40,40)]]
  73.     pbDrawTextPositions(@overlaysprite.bitmap,textpos)
  74.     @overlaysprite.z=self.z+1 # For compatibility with RGSS2
  75.     self.x=x
  76.     self.y=y
  77.   end
  78.  
  79.   def dispose
  80.     @overlaysprite.bitmap.dispose
  81.     @overlaysprite.dispose
  82.     @bgsprite.dispose
  83.     super
  84.   end
  85.  
  86.   def viewport=(value)
  87.     super
  88.     refresh
  89.   end
  90.  
  91.   def color=(value)
  92.     super
  93.     refresh
  94.   end
  95.  
  96.   def x=(value)
  97.     super
  98.     refresh
  99.   end
  100.  
  101.   def y=(value)
  102.     super
  103.     refresh
  104.   end
  105.  
  106.   def selected=(value)
  107.     @selected=value
  108.     refresh
  109.   end
  110.  
  111.   def refresh
  112.     @bgsprite.changeBitmap((@selected) ? "selbitmap" : "deselbitmap")
  113.     if @bgsprite && !@bgsprite.disposed?
  114.       @bgsprite.x=self.x
  115.       @bgsprite.y=self.y
  116.       @overlaysprite.x=self.x
  117.       @overlaysprite.y=self.y
  118.       @bgsprite.color=self.color
  119.       @overlaysprite.color=self.color
  120.     end
  121.   end
  122. end
  123.  
  124.  
  125.  
  126. class PokeSelectionCancelSprite < PokeSelectionConfirmCancelSprite
  127.   def initialize(viewport=nil)
  128.     super(_INTL("CANCEL"),398,328,false,viewport)
  129.   end
  130. end
  131.  
  132.  
  133.  
  134. class PokeSelectionConfirmSprite < PokeSelectionConfirmCancelSprite
  135.   def initialize(viewport=nil)
  136.     super(_INTL("CONFIRM"),398,308,true,viewport)
  137.   end
  138. end
  139.  
  140.  
  141.  
  142. class PokeSelectionCancelSprite2 < PokeSelectionConfirmCancelSprite
  143.   def initialize(viewport=nil)
  144.     super(_INTL("CANCEL"),398,346,true,viewport)
  145.   end
  146. end
  147.  
  148.  
  149.  
  150. class ChangelingSprite < SpriteWrapper
  151.   def initialize(x=0,y=0,viewport=nil)
  152.     super(viewport)
  153.     self.x=x
  154.     self.y=y
  155.     @bitmaps={}
  156.     @currentBitmap=nil
  157.   end
  158.  
  159.   def addBitmap(key,path)
  160.     if @bitmaps[key]
  161.       @bitmaps[key].dispose
  162.     end
  163.     @bitmaps[key]=AnimatedBitmap.new(path)
  164.   end
  165.  
  166.   def changeBitmap(key)
  167.     @currentBitmap=@bitmaps[key]
  168.     self.bitmap=@currentBitmap ? @currentBitmap.bitmap : nil
  169.   end
  170.  
  171.   def dispose
  172.     return if disposed?
  173.     for bm in @bitmaps.values; bm.dispose; end
  174.     @bitmaps.clear
  175.     super
  176.   end
  177.  
  178.   def update
  179.     return if disposed?
  180.     for bm in @bitmaps.values; bm.update; end
  181.     self.bitmap=@currentBitmap ? @currentBitmap.bitmap : nil
  182.   end
  183. end
  184.  
  185.  
  186.  
  187. class PokeSelectionSprite < SpriteWrapper
  188.   attr_reader :selected
  189.   attr_reader :preselected
  190.   attr_reader :switching
  191.   attr_reader :pokemon
  192.   attr_reader :active
  193.   attr_accessor :text
  194.  
  195.   def initialize(pokemon,index,viewport=nil)
  196.     super(viewport)
  197.     @pokemon=pokemon
  198.     active=(index==0)
  199.     @active=active
  200.     if active # Rounded panel
  201.       @deselbitmap=AnimatedBitmap.new("Graphics/Pictures/partyPanelRound")
  202.       @selbitmap=AnimatedBitmap.new("Graphics/Pictures/partyPanelRoundSel")
  203.       @deselfntbitmap=AnimatedBitmap.new("Graphics/Pictures/partyPanelRoundFnt")
  204.       @selfntbitmap=AnimatedBitmap.new("Graphics/Pictures/partyPanelRoundSelFnt")
  205.       @deselswapbitmap=AnimatedBitmap.new("Graphics/Pictures/partyPanelRoundSwap")
  206.       @selswapbitmap=AnimatedBitmap.new("Graphics/Pictures/partyPanelRoundSelSwap")
  207.     else # Rectangular panel
  208.       @deselbitmap=AnimatedBitmap.new("Graphics/Pictures/partyPanelRect")
  209.       @selbitmap=AnimatedBitmap.new("Graphics/Pictures/partyPanelRectSel")
  210.       @deselfntbitmap=AnimatedBitmap.new("Graphics/Pictures/partyPanelRectFnt")
  211.       @selfntbitmap=AnimatedBitmap.new("Graphics/Pictures/partyPanelRectSelFnt")
  212.       @deselswapbitmap=AnimatedBitmap.new("Graphics/Pictures/partyPanelRectSwap")
  213.       @selswapbitmap=AnimatedBitmap.new("Graphics/Pictures/partyPanelRectSelSwap")
  214.     end
  215.     @spriteXOffset=28
  216.     @spriteYOffset=0
  217.     @pokeballXOffset=10
  218.     @pokeballYOffset=0
  219.     @pokenameX=96
  220.     @pokenameY=16
  221.     @levelX=20
  222.     @levelY=62
  223.     @statusX=80
  224.     @statusY=68
  225.     @genderX=224
  226.     @genderY=16
  227.     @hpX=224
  228.     @hpY=60
  229.     @hpbarX=96
  230.     @hpbarY=50
  231.     @gaugeX=128
  232.     @gaugeY=52
  233.     @itemXOffset=62
  234.     @itemYOffset=48
  235.     @annotX=96
  236.     @annotY=58
  237.     xvalues=[0,256,0,256,0,256]
  238.     yvalues=[0,16,96,112,192,208]
  239.     @text=nil
  240.     @statuses=AnimatedBitmap.new(_INTL("Graphics/Pictures/statuses"))
  241.     @hpbar=AnimatedBitmap.new("Graphics/Pictures/partyHP")
  242.     @hpbarfnt=AnimatedBitmap.new("Graphics/Pictures/partyHPfnt")
  243.     @hpbarswap=AnimatedBitmap.new("Graphics/Pictures/partyHPswap")
  244.     @pokeballsprite=ChangelingSprite.new(0,0,viewport)
  245.     @pokeballsprite.addBitmap("pokeballdesel","Graphics/Pictures/PartyBall/partyBallBasic")
  246.     @pokeballsprite.addBitmap("pokeballsel","Graphics/Pictures/PartyBall/partyBallSelBasic")
  247.     @pokeballsprite.addBitmap("greatballdesel","Graphics/Pictures/PartyBall/partyBallGreat")
  248.     @pokeballsprite.addBitmap("greatballsel","Graphics/Pictures/PartyBall/partyBallSelGreat")
  249.     @pokeballsprite.addBitmap("safariballdesel","Graphics/Pictures/PartyBall/partyBallSafari")
  250.     @pokeballsprite.addBitmap("safariballsel","Graphics/Pictures/PartyBall/partyBallSelSafari")
  251.     @pokeballsprite.addBitmap("ultraballdesel","Graphics/Pictures/PartyBall/partyBallUltra")
  252.     @pokeballsprite.addBitmap("ultraballsel","Graphics/Pictures/PartyBall/partyBallSelUltra")
  253.     @pokeballsprite.addBitmap("masterballdesel","Graphics/Pictures/PartyBall/partyBallMaster")
  254.     @pokeballsprite.addBitmap("masterballsel","Graphics/Pictures/PartyBall/partyBallSelMaster")
  255.     @pokeballsprite.addBitmap("netballdesel","Graphics/Pictures/PartyBall/partyBallNet")
  256.     @pokeballsprite.addBitmap("netballsel","Graphics/Pictures/PartyBall/partyBallSelNet")
  257.     @pokeballsprite.addBitmap("diveballdesel","Graphics/Pictures/PartyBall/partyBallDive")
  258.     @pokeballsprite.addBitmap("diveballsel","Graphics/Pictures/PartyBall/partyBallSelDive")
  259.     @pokeballsprite.addBitmap("nestballdesel","Graphics/Pictures/PartyBall/partyBallNest")
  260.     @pokeballsprite.addBitmap("nestballsel","Graphics/Pictures/PartyBall/partyBallSelNest")
  261.     @pokeballsprite.addBitmap("repeatballdesel","Graphics/Pictures/PartyBall/partyBallRepeat")
  262.     @pokeballsprite.addBitmap("repeatballsel","Graphics/Pictures/PartyBall/partyBallSelRepeat")
  263.     @pokeballsprite.addBitmap("timerballdesel","Graphics/Pictures/PartyBall/partyBallTimer")
  264.     @pokeballsprite.addBitmap("timerballsel","Graphics/Pictures/PartyBall/partyBallSelTimer")
  265.     @pokeballsprite.addBitmap("luxuryballdesel","Graphics/Pictures/PartyBall/partyBallLuxury")
  266.     @pokeballsprite.addBitmap("luxuryballsel","Graphics/Pictures/PartyBall/partyBallSelLuxury")
  267.     @pokeballsprite.addBitmap("premierballdesel","Graphics/Pictures/PartyBall/partyBallPremier")
  268.     @pokeballsprite.addBitmap("premierballsel","Graphics/Pictures/PartyBall/partyBallSelPremier")
  269.     @pokeballsprite.addBitmap("duskballdesel","Graphics/Pictures/PartyBall/partyBallDusk")
  270.     @pokeballsprite.addBitmap("duskballsel","Graphics/Pictures/PartyBall/partyBallSelDusk")
  271.     @pokeballsprite.addBitmap("healballdesel","Graphics/Pictures/PartyBall/partyBallHeal")
  272.     @pokeballsprite.addBitmap("healballsel","Graphics/Pictures/PartyBall/partyBallSelHeal")
  273.     @pokeballsprite.addBitmap("quickballdesel","Graphics/Pictures/PartyBall/partyBallQuick")
  274.     @pokeballsprite.addBitmap("quickballsel","Graphics/Pictures/PartyBall/partyBallSelQuick")
  275.     @pokeballsprite.addBitmap("cherishballdesel","Graphics/Pictures/PartyBall/partyBallCherish")
  276.     @pokeballsprite.addBitmap("cherishballsel","Graphics/Pictures/PartyBall/partyBallSelCherish")
  277.     @pokeballsprite.addBitmap("fastballdesel","Graphics/Pictures/PartyBall/partyBallFast")
  278.     @pokeballsprite.addBitmap("fastballsel","Graphics/Pictures/PartyBall/partyBallSelFast")
  279.     @pokeballsprite.addBitmap("levelballdesel","Graphics/Pictures/PartyBall/partyBallLevel")
  280.     @pokeballsprite.addBitmap("levelballsel","Graphics/Pictures/PartyBall/partyBallSelLevel")
  281.     @pokeballsprite.addBitmap("lureballdesel","Graphics/Pictures/PartyBall/partyBallLure")
  282.     @pokeballsprite.addBitmap("lureballsel","Graphics/Pictures/PartyBall/partyBallSelLure")
  283.     @pokeballsprite.addBitmap("heavyballdesel","Graphics/Pictures/PartyBall/partyBallHeavy")
  284.     @pokeballsprite.addBitmap("heavyballsel","Graphics/Pictures/PartyBall/partyBallSelHeavy")
  285.     @pokeballsprite.addBitmap("loveballdesel","Graphics/Pictures/PartyBall/partyBallLove")
  286.     @pokeballsprite.addBitmap("loveballsel","Graphics/Pictures/PartyBall/partyBallSelLove")
  287.     @pokeballsprite.addBitmap("friendballdesel","Graphics/Pictures/PartyBall/partyBallFriend")
  288.     @pokeballsprite.addBitmap("friendballsel","Graphics/Pictures/PartyBall/partyBallSelFriend")
  289.     @pokeballsprite.addBitmap("moonballdesel","Graphics/Pictures/PartyBall/partyBallMoon")
  290.     @pokeballsprite.addBitmap("moonballsel","Graphics/Pictures/PartyBall/partyBallSelMoon")
  291.     @pokeballsprite.addBitmap("sportballdesel","Graphics/Pictures/PartyBall/partyBallSport")
  292.     @pokeballsprite.addBitmap("sportballsel","Graphics/Pictures/PartyBall/partyBallSelSport")
  293.     @pkmnsprite=PokemonIconSprite.new(pokemon,viewport)
  294.     @pkmnsprite.active=active
  295.     @itemsprite=ChangelingSprite.new(0,0,viewport)
  296.     @itemsprite.addBitmap("itembitmap","Graphics/Pictures/item")
  297.     @itemsprite.addBitmap("mailbitmap","Graphics/Pictures/mail")
  298.     @spriteX=xvalues[index]
  299.     @spriteY=yvalues[index]
  300.     @refreshBitmap=true
  301.     @refreshing=false
  302.     @preselected=false
  303.     @switching=false
  304.     @pkmnsprite.z=self.z+2 # For compatibility with RGSS2
  305.     @itemsprite.z=self.z+3 # For compatibility with RGSS2
  306.     @pokeballsprite.z=self.z+1 # For compatibility with RGSS2
  307.     self.selected=false
  308.     self.x=@spriteX
  309.     self.y=@spriteY
  310.     refresh
  311.   end
  312.  
  313.   def dispose
  314.     @selbitmap.dispose
  315.     @statuses.dispose
  316.     @hpbar.dispose
  317.     @deselbitmap.dispose
  318.     @itemsprite.dispose
  319.     @pkmnsprite.dispose
  320.     @pokeballsprite.dispose
  321.     self.bitmap.dispose
  322.     super
  323.   end
  324.  
  325.   def selected=(value)
  326.     @selected=value
  327.     @refreshBitmap=true
  328.     refresh
  329.   end
  330.  
  331.   def text=(value)
  332.     @text=value
  333.     @refreshBitmap=true
  334.     refresh
  335.   end
  336.  
  337.   def pokemon=(value)
  338.     @pokemon=value
  339.     if @pkmnsprite && !@pkmnsprite.disposed?
  340.       @pkmnsprite.pokemon=value
  341.     end
  342.     @refreshBitmap=true
  343.     refresh
  344.   end
  345.  
  346.   def preselected=(value)
  347.     if value!=@preselected
  348.       @preselected=value
  349.       refresh
  350.     end
  351.   end
  352.  
  353.   def switching=(value)
  354.     if value!=@switching
  355.       @switching=value
  356.       refresh
  357.     end
  358.   end
  359.  
  360.   def color=(value)
  361.     super
  362.     refresh
  363.   end
  364.  
  365.   def x=(value)
  366.     super
  367.     refresh
  368.   end
  369.  
  370.   def y=(value)
  371.     super
  372.     refresh
  373.   end
  374.  
  375.   def hp
  376.     return @pokemon.hp
  377.   end
  378.  
  379.   def refresh
  380.     return if @refreshing
  381.     return if disposed?
  382.     @refreshing=true
  383.     if !self.bitmap || self.bitmap.disposed?
  384.       self.bitmap=BitmapWrapper.new(@selbitmap.width,@selbitmap.height)
  385.     end
  386.     if @pkmnsprite && !@pkmnsprite.disposed?
  387.       @pkmnsprite.x=self.x+@spriteXOffset
  388.       @pkmnsprite.y=self.y+@spriteYOffset
  389.       @pkmnsprite.color=pbSrcOver(@pkmnsprite.color,self.color)
  390.       @pkmnsprite.selected=self.selected
  391.     end
  392.     if @pokeballsprite && !@pokeballsprite.disposed?
  393.       @pokeballsprite.x=self.x+@pokeballXOffset
  394.       @pokeballsprite.y=self.y+@pokeballYOffset
  395.       @pokeballsprite.color=self.color
  396.       if @pokemon.ballused==1
  397.         @pokeballsprite.changeBitmap((self.selected) ? "greatballsel" : "greatballdesel")
  398.       elsif @pokemon.ballused==2
  399.         @pokeballsprite.changeBitmap((self.selected) ? "safariballsel" : "safariballdesel")
  400.       elsif @pokemon.ballused==3
  401.         @pokeballsprite.changeBitmap((self.selected) ? "ultraballsel" : "ultraballdesel")
  402.       elsif @pokemon.ballused==4
  403.         @pokeballsprite.changeBitmap((self.selected) ? "masterballsel" : "masterballdesel")
  404.       elsif @pokemon.ballused==5
  405.         @pokeballsprite.changeBitmap((self.selected) ? "netballsel" : "netballdesel")
  406.       elsif @pokemon.ballused==6
  407.         @pokeballsprite.changeBitmap((self.selected) ? "diveballsel" : "diveballdesel")
  408.       elsif @pokemon.ballused==7
  409.         @pokeballsprite.changeBitmap((self.selected) ? "nestballsel" : "nestballdesel")
  410.       elsif @pokemon.ballused==8
  411.         @pokeballsprite.changeBitmap((self.selected) ? "repeatballsel" : "repeatballdesel")
  412.       elsif @pokemon.ballused==9
  413.         @pokeballsprite.changeBitmap((self.selected) ? "timerballsel" : "timerballdesel")
  414.       elsif @pokemon.ballused==10
  415.         @pokeballsprite.changeBitmap((self.selected) ? "luxuryballsel" : "luxuryballdesel")
  416.       elsif @pokemon.ballused==11
  417.         @pokeballsprite.changeBitmap((self.selected) ? "premierballsel" : "premierballdesel")
  418.       elsif @pokemon.ballused==12
  419.         @pokeballsprite.changeBitmap((self.selected) ? "duskballsel" : "duskballdesel")
  420.       elsif @pokemon.ballused==13
  421.         @pokeballsprite.changeBitmap((self.selected) ? "healballsel" : "healballdesel")
  422.       elsif @pokemon.ballused==14
  423.         @pokeballsprite.changeBitmap((self.selected) ? "quickballsel" : "quickballdesel")
  424.       elsif @pokemon.ballused==15
  425.         @pokeballsprite.changeBitmap((self.selected) ? "cherishballsel" : "cherishballdesel")
  426.       elsif @pokemon.ballused==16
  427.         @pokeballsprite.changeBitmap((self.selected) ? "fastballsel" : "fastballdesel")
  428.       elsif @pokemon.ballused==17
  429.         @pokeballsprite.changeBitmap((self.selected) ? "levelballsel" : "levelballdesel")
  430.       elsif @pokemon.ballused==18
  431.         @pokeballsprite.changeBitmap((self.selected) ? "lureballsel" : "lureballdesel")
  432.       elsif @pokemon.ballused==19
  433.         @pokeballsprite.changeBitmap((self.selected) ? "heavyballsel" : "heavyballdesel")
  434.       elsif @pokemon.ballused==20
  435.         @pokeballsprite.changeBitmap((self.selected) ? "loveballsel" : "loveballdesel")
  436.       elsif @pokemon.ballused==21
  437.         @pokeballsprite.changeBitmap((self.selected) ? "friendballsel" : "friendballdesel")
  438.       elsif @pokemon.ballused==22
  439.         @pokeballsprite.changeBitmap((self.selected) ? "moonballsel" : "moonballdesel")
  440.       elsif @pokemon.ballused==23
  441.         @pokeballsprite.changeBitmap((self.selected) ? "sportballsel" : "sportballdesel")
  442.       else
  443.          @pokeballsprite.changeBitmap((self.selected) ? "pokeballsel" : "pokeballdesel")
  444.       end
  445.     end
  446.     if @itemsprite && !@itemsprite.disposed?
  447.       @itemsprite.visible=(@pokemon.item>0)
  448.       if @itemsprite.visible
  449.         @itemsprite.changeBitmap(@pokemon.mail ? "mailbitmap" : "itembitmap")
  450.         @itemsprite.x=self.x+@itemXOffset
  451.         @itemsprite.y=self.y+@itemYOffset
  452.         @itemsprite.color=self.color
  453.       end
  454.     end
  455.     if @refreshBitmap
  456.       @refreshBitmap=false
  457.       self.bitmap.clear if self.bitmap
  458.       if self.selected
  459.         if self.preselected
  460.           self.bitmap.blt(0,0,@selswapbitmap.bitmap,Rect.new(0,0,@selswapbitmap.width,@selswapbitmap.height))
  461.           self.bitmap.blt(0,0,@deselswapbitmap.bitmap,Rect.new(0,0,@deselswapbitmap.width,@deselswapbitmap.height))
  462.         elsif @switching
  463.           self.bitmap.blt(0,0,@selswapbitmap.bitmap,Rect.new(0,0,@selswapbitmap.width,@selswapbitmap.height))
  464.         elsif @pokemon.hp<=0 && !@pokemon.isEgg?
  465.           self.bitmap.blt(0,0,@selfntbitmap.bitmap,Rect.new(0,0,@selfntbitmap.width,@selfntbitmap.height))
  466.         else
  467.           self.bitmap.blt(0,0,@selbitmap.bitmap,Rect.new(0,0,@selbitmap.width,@selbitmap.height))
  468.         end
  469.       else
  470.         if self.preselected
  471.           self.bitmap.blt(0,0,@deselswapbitmap.bitmap,Rect.new(0,0,@deselswapbitmap.width,@deselswapbitmap.height))
  472.         elsif @pokemon.hp<=0 && !@pokemon.isEgg?
  473.           self.bitmap.blt(0,0,@deselfntbitmap.bitmap,Rect.new(0,0,@deselfntbitmap.width,@deselfntbitmap.height))
  474.         else
  475.           self.bitmap.blt(0,0,@deselbitmap.bitmap,Rect.new(0,0,@deselbitmap.width,@deselbitmap.height))
  476.         end
  477.       end
  478.       base=Color.new(248,248,248)
  479.       shadow=Color.new(40,40,40)
  480.       pbSetSystemFont(self.bitmap)
  481.       pokename=@pokemon.name
  482.       textpos=[[pokename,@pokenameX,@pokenameY,0,base,shadow]]
  483.       if !@pokemon.isEgg?
  484.         if !@text || @text.length==0
  485.           tothp=@pokemon.totalhp
  486.           textpos.push([_ISPRINTF("{1: 3d}/{2: 3d}",@pokemon.hp,tothp),
  487.              @hpX,@hpY,1,base,shadow])
  488.           barbg=(@pokemon.hp<=0) ? @hpbarfnt : @hpbar
  489.           barbg=(self.preselected || (self.selected && @switching)) ? @hpbarswap : barbg
  490.           self.bitmap.blt(@hpbarX,@hpbarY,barbg.bitmap,Rect.new(0,0,@hpbar.width,@hpbar.height))
  491.           hpgauge=@pokemon.totalhp==0 ? 0 : (self.hp*96/@pokemon.totalhp)
  492.           hpgauge=1 if hpgauge==0 && self.hp>0
  493.           hpzone=0
  494.           hpzone=1 if self.hp<=(@pokemon.totalhp/2).floor
  495.           hpzone=2 if self.hp<=(@pokemon.totalhp/4).floor
  496.           hpcolors=[
  497.              Color.new(24,192,32),Color.new(96,248,96),   # Green
  498.              Color.new(232,168,0),Color.new(248,216,0),   # Orange
  499.              Color.new(248,72,56),Color.new(248,152,152)  # Red
  500.           ]
  501.           # fill with HP color
  502.           self.bitmap.fill_rect(@gaugeX,@gaugeY,hpgauge,2,hpcolors[hpzone*2])
  503.           self.bitmap.fill_rect(@gaugeX,@gaugeY+2,hpgauge,4,hpcolors[hpzone*2+1])
  504.           self.bitmap.fill_rect(@gaugeX,@gaugeY+6,hpgauge,2,hpcolors[hpzone*2])
  505.           if @pokemon.hp==0 || @pokemon.status>0
  506.             status=(@pokemon.hp==0) ? 5 : @pokemon.status-1
  507.             statusrect=Rect.new(0,16*status,44,16)
  508.             self.bitmap.blt(@statusX,@statusY,@statuses.bitmap,statusrect)
  509.           end
  510.         end
  511.         if @pokemon.isMale?
  512.           textpos.push([_INTL("♂"),@genderX,@genderY,0,Color.new(0,112,248),Color.new(120,184,232)])
  513.         elsif @pokemon.isFemale?
  514.           textpos.push([_INTL("♀"),@genderX,@genderY,0,Color.new(232,32,16),Color.new(248,168,184)])
  515.         end
  516.       end
  517.       pbDrawTextPositions(self.bitmap,textpos)
  518.       if !@pokemon.isEgg?
  519.         pbSetSmallFont(self.bitmap)
  520.         leveltext=[([_INTL("Lv.{1}",@pokemon.level),@levelX,@levelY,0,base,shadow])]
  521.         pbDrawTextPositions(self.bitmap,leveltext)
  522.       end
  523.       if @text && @text.length>0
  524.         pbSetSystemFont(self.bitmap)
  525.         annotation=[[@text,@annotX,@annotY,0,base,shadow]]
  526.         pbDrawTextPositions(self.bitmap,annotation)
  527.       end
  528.     end
  529.     @refreshing=false
  530.   end
  531.  
  532.   def update
  533.     super
  534.     @pokeballsprite.update if @pokeballsprite && !@pokeballsprite.disposed?
  535.     @itemsprite.update if @itemsprite && !@itemsprite.disposed?
  536.     if @pkmnsprite && !@pkmnsprite.disposed?
  537.       @pkmnsprite.update
  538.     end
  539.   end
  540. end
  541.  
  542.  
  543. ##############################
  544.  
  545.  
  546. class PokemonScreen_Scene
  547.   def pbShowCommands(helptext,commands,index=0)
  548.     ret=-1
  549.     helpwindow=@sprites["helpwindow"]
  550.     helpwindow.visible=true
  551.     using(cmdwindow=Window_CommandPokemon.new(commands)) {
  552.        cmdwindow.z=@viewport.z+1
  553.        cmdwindow.index=index
  554.        pbBottomRight(cmdwindow)
  555.        helpwindow.text=""
  556.        helpwindow.resizeHeightToFit(helptext,Graphics.width-cmdwindow.width)
  557.        helpwindow.text=helptext
  558.        pbBottomLeft(helpwindow)
  559.        loop do
  560.          Graphics.update
  561.          Input.update
  562.          cmdwindow.update
  563.          self.update
  564.          if Input.trigger?(Input::B)
  565.            pbPlayCancelSE()
  566.            ret=-1
  567.            break
  568.          end
  569.          if Input.trigger?(Input::C)
  570.            pbPlayDecisionSE()
  571.            ret=cmdwindow.index
  572.            break
  573.          end
  574.        end
  575.     }
  576.     return ret
  577.   end
  578.  
  579.   def update
  580.     pbUpdateSpriteHash(@sprites)
  581.   end
  582.  
  583.   def pbSetHelpText(helptext)
  584.     helpwindow=@sprites["helpwindow"]
  585.     pbBottomLeftLines(helpwindow,1)
  586.     helpwindow.text=helptext
  587.     helpwindow.width=398
  588.     helpwindow.visible=true
  589.   end
  590.  
  591.   def pbStartScene(party,starthelptext,annotations=nil,multiselect=false)
  592.     @sprites={}
  593.     @party=party
  594.     @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
  595.     @viewport.z=99999
  596.     @multiselect=multiselect
  597.     addBackgroundPlane(@sprites,"partybg","partybg",@viewport)
  598.     @sprites["messagebox"]=Window_AdvancedTextPokemon.new("")
  599.     @sprites["helpwindow"]=Window_UnformattedTextPokemon.new(starthelptext)
  600.     @sprites["messagebox"].viewport=@viewport
  601.     @sprites["messagebox"].visible=false
  602.     @sprites["messagebox"].letterbyletter=true
  603.     @sprites["helpwindow"].viewport=@viewport
  604.     @sprites["helpwindow"].visible=true
  605.     pbBottomLeftLines(@sprites["messagebox"],2)
  606.     pbBottomLeftLines(@sprites["helpwindow"],1)
  607.     pbSetHelpText(starthelptext)
  608.     # Add party Pokémon sprites
  609.     for i in 0...6
  610.       if @party[i]
  611.         @sprites["pokemon#{i}"]=PokeSelectionSprite.new(
  612.            @party[i],i,@viewport)
  613.       else
  614.         @sprites["pokemon#{i}"]=PokeSelectionPlaceholderSprite.new(
  615.            @party[i],i,@viewport)
  616.       end
  617.       if annotations
  618.         @sprites["pokemon#{i}"].text=annotations[i]
  619.       end
  620.     end
  621.     if @multiselect
  622.       @sprites["pokemon6"]=PokeSelectionConfirmSprite.new(@viewport)
  623.       @sprites["pokemon7"]=PokeSelectionCancelSprite2.new(@viewport)
  624.     else
  625.       @sprites["pokemon6"]=PokeSelectionCancelSprite.new(@viewport)
  626.     end
  627.     # Select first Pokémon
  628.     @activecmd=0
  629.     @sprites["pokemon0"].selected=true
  630.     pbFadeInAndShow(@sprites) { update }
  631.   end
  632.  
  633.   def pbEndScene
  634.     pbFadeOutAndHide(@sprites) { update }
  635.     pbDisposeSpriteHash(@sprites)
  636.     @viewport.dispose
  637.   end
  638.  
  639.   def pbChangeSelection(key,currentsel)
  640.     numsprites=(@multiselect) ? 8 : 7
  641.     case key
  642.     when Input::LEFT
  643.       begin
  644.         currentsel-=1
  645.       end while currentsel>0 && currentsel<@party.length && !@party[currentsel]
  646.       if currentsel>=@party.length && currentsel<6
  647.         currentsel=@party.length-1
  648.       end
  649.       currentsel=numsprites-1 if currentsel<0
  650.     when Input::RIGHT
  651.       begin
  652.         currentsel+=1
  653.       end while currentsel<@party.length && !@party[currentsel]
  654.       if currentsel==@party.length
  655.         currentsel=6
  656.       elsif currentsel==numsprites
  657.         currentsel=0
  658.       end
  659.     when Input::UP
  660.       if currentsel>=6
  661.         begin
  662.           currentsel-=1
  663.         end while currentsel>0 && !@party[currentsel]
  664.       else
  665.         begin
  666.           currentsel-=2
  667.         end while currentsel>0 && !@party[currentsel]
  668.       end
  669.       if currentsel>=@party.length && currentsel<6
  670.         currentsel=@party.length-1
  671.       end
  672.       currentsel=numsprites-1 if currentsel<0
  673.     when Input::DOWN
  674.       if currentsel>=5
  675.         currentsel+=1
  676.       else
  677.         currentsel+=2
  678.         currentsel=6 if currentsel<6 && !@party[currentsel]
  679.       end
  680.       if currentsel>=@party.length && currentsel<6
  681.         currentsel=6
  682.       elsif currentsel>=numsprites
  683.         currentsel=0
  684.       end
  685.     end
  686.     return currentsel
  687.   end
  688.  
  689.   def pbRefresh
  690.     for i in 0...6
  691.       sprite=@sprites["pokemon#{i}"]
  692.       if sprite
  693.         if sprite.is_a?(PokeSelectionSprite)
  694.           sprite.pokemon=sprite.pokemon
  695.         else
  696.           sprite.refresh
  697.         end
  698.       end
  699.     end
  700.   end
  701.  
  702.   def pbRefreshSingle(i)
  703.     sprite=@sprites["pokemon#{i}"]
  704.     if sprite
  705.       if sprite.is_a?(PokeSelectionSprite)
  706.         sprite.pokemon=sprite.pokemon
  707.       else
  708.         sprite.refresh
  709.       end
  710.     end
  711.   end
  712.  
  713.   def pbHardRefresh
  714.     oldtext=[]
  715.     lastselected=-1
  716.     for i in 0...6
  717.       oldtext.push(@sprites["pokemon#{i}"].text)
  718.       lastselected=i if @sprites["pokemon#{i}"].selected
  719.       @sprites["pokemon#{i}"].dispose
  720.     end
  721.     lastselected=@party.length-1 if lastselected>=@party.length
  722.     lastselected=0 if lastselected<0
  723.     for i in 0...6
  724.       if @party[i]
  725.         @sprites["pokemon#{i}"]=PokeSelectionSprite.new(
  726.         @party[i],i,@viewport)
  727.       else
  728.         @sprites["pokemon#{i}"]=PokeSelectionPlaceholderSprite.new(
  729.         @party[i],i,@viewport)
  730.       end
  731.       @sprites["pokemon#{i}"].text=oldtext[i]
  732.     end
  733.     pbSelect(lastselected)
  734.   end
  735.  
  736.   def pbPreSelect(pkmn)
  737.     @activecmd=pkmn
  738.   end
  739.  
  740.   def pbChoosePokemon(switching=false,initialsel=-1)
  741.     for i in 0...6
  742.       @sprites["pokemon#{i}"].preselected=(switching && i==@activecmd)
  743.       @sprites["pokemon#{i}"].switching=switching
  744.     end
  745.     @activecmd=initialsel if initialsel>=0
  746.     pbRefresh
  747.     loop do
  748.       Graphics.update
  749.       Input.update
  750.       self.update
  751.       oldsel=@activecmd
  752.       key=-1
  753.       key=Input::DOWN if Input.repeat?(Input::DOWN)
  754.       key=Input::RIGHT if Input.repeat?(Input::RIGHT)
  755.       key=Input::LEFT if Input.repeat?(Input::LEFT)
  756.       key=Input::UP if Input.repeat?(Input::UP)
  757.       if key>=0
  758.         @activecmd=pbChangeSelection(key,@activecmd)
  759.       end
  760.       if @activecmd!=oldsel # Changing selection
  761.         pbPlayCursorSE()
  762.         numsprites=(@multiselect) ? 8 : 7
  763.         for i in 0...numsprites
  764.           @sprites["pokemon#{i}"].selected=(i==@activecmd)
  765.         end
  766.       end
  767.       if Input.trigger?(Input::B)
  768.         return -1
  769.       end
  770.       if Input.trigger?(Input::C)
  771.         pbPlayDecisionSE()
  772.         cancelsprite=(@multiselect) ? 7 : 6
  773.         return (@activecmd==cancelsprite) ? -1 : @activecmd
  774.       end
  775.     end
  776.   end
  777.  
  778.   def pbSelect(item)
  779.     @activecmd=item
  780.     numsprites=(@multiselect) ? 8 : 7
  781.     for i in 0...numsprites
  782.       @sprites["pokemon#{i}"].selected=(i==@activecmd)
  783.     end
  784.   end
  785.  
  786.   def pbDisplay(text)
  787.     @sprites["messagebox"].text=text
  788.     @sprites["messagebox"].visible=true
  789.     @sprites["helpwindow"].visible=false
  790.     pbPlayDecisionSE()
  791.     loop do
  792.       Graphics.update
  793.       Input.update
  794.       self.update
  795.       if @sprites["messagebox"].busy? && Input.trigger?(Input::C)
  796.         pbPlayDecisionSE() if @sprites["messagebox"].pausing?
  797.         @sprites["messagebox"].resume
  798.       end
  799.       if !@sprites["messagebox"].busy? &&
  800.          (Input.trigger?(Input::C) || Input.trigger?(Input::B))
  801.         break
  802.       end
  803.     end
  804.     @sprites["messagebox"].visible=false
  805.     @sprites["helpwindow"].visible=true
  806.   end
  807.  
  808.   def pbSwitchBegin(oldid,newid)
  809.     oldsprite=@sprites["pokemon#{oldid}"]
  810.     newsprite=@sprites["pokemon#{newid}"]
  811.     22.times do
  812.       oldsprite.x+=(oldid&1)==0 ? -12 : 12
  813.       newsprite.x+=(newid&1)==0 ? -12 : 12
  814.       Graphics.update
  815.       Input.update
  816.       self.update
  817.     end
  818.   end
  819.  
  820.   def pbSwitchEnd(oldid,newid)
  821.     oldsprite=@sprites["pokemon#{oldid}"]
  822.     newsprite=@sprites["pokemon#{newid}"]
  823.     oldsprite.pokemon=@party[oldid]
  824.     newsprite.pokemon=@party[newid]
  825.     22.times do
  826.       oldsprite.x-=(oldid&1)==0 ? -12 : 12
  827.       newsprite.x-=(newid&1)==0 ? -12 : 12
  828.       Graphics.update
  829.       Input.update
  830.       self.update
  831.     end
  832.     for i in 0...6
  833.       @sprites["pokemon#{i}"].preselected=false
  834.       @sprites["pokemon#{i}"].switching=false
  835.     end
  836.     pbRefresh
  837.   end
  838.  
  839.   def pbDisplayConfirm(text)
  840.     ret=-1
  841.     @sprites["messagebox"].text=text
  842.     @sprites["messagebox"].visible=true
  843.     @sprites["helpwindow"].visible=false
  844.     using(cmdwindow=Window_CommandPokemon.new([_INTL("Yes"),_INTL("No")])){
  845.        cmdwindow.z=@viewport.z+1
  846.        cmdwindow.visible=false
  847.        pbBottomRight(cmdwindow)
  848.        cmdwindow.y-=@sprites["messagebox"].height
  849.        loop do
  850.          Graphics.update
  851.          Input.update
  852.          cmdwindow.visible=true if !@sprites["messagebox"].busy?
  853.          cmdwindow.update
  854.          self.update
  855.          if Input.trigger?(Input::B) && !@sprites["messagebox"].busy?
  856.            ret=false
  857.            break
  858.          end
  859.          if Input.trigger?(Input::C) && @sprites["messagebox"].resume && !@sprites["messagebox"].busy?
  860.            ret=(cmdwindow.index==0)
  861.            break
  862.          end
  863.        end
  864.     }
  865.     @sprites["messagebox"].visible=false
  866.     @sprites["helpwindow"].visible=true
  867.     return ret
  868.   end
  869.  
  870.   def pbAnnotate(annot)
  871.     for i in 0...6
  872.       if annot
  873.         @sprites["pokemon#{i}"].text=annot[i]
  874.       else
  875.         @sprites["pokemon#{i}"].text=nil
  876.       end
  877.     end
  878.   end
  879.  
  880.   def pbSummary(pkmnid)
  881.     oldsprites=pbFadeOutAndHide(@sprites)
  882.     scene=PokemonSummaryScene.new
  883.     screen=PokemonSummary.new(scene)
  884.     screen.pbStartScreen(@party,pkmnid)
  885.     pbFadeInAndShow(@sprites,oldsprites)
  886.   end
  887.  
  888.   def pbChooseItem(bag)
  889.     oldsprites=pbFadeOutAndHide(@sprites)
  890.     @sprites["helpwindow"].visible=false
  891.     @sprites["messagebox"].visible=false
  892.     scene=PokemonBag_Scene.new
  893.     screen=PokemonBagScreen.new(scene,bag)
  894.     ret=screen.pbGiveItemScreen
  895.     pbFadeInAndShow(@sprites,oldsprites)
  896.     return ret
  897.   end
  898.  
  899.   def pbUseItem(bag,pokemon)
  900.     oldsprites=pbFadeOutAndHide(@sprites)
  901.     @sprites["helpwindow"].visible=false
  902.     @sprites["messagebox"].visible=false
  903.     scene=PokemonBag_Scene.new
  904.     screen=PokemonBagScreen.new(scene,bag)
  905.     ret=screen.pbUseItemScreen(pokemon)
  906.     pbFadeInAndShow(@sprites,oldsprites)
  907.     return ret
  908.   end
  909.  
  910.   def pbMessageFreeText(text,startMsg,maxlength)
  911.     return Kernel.pbMessageFreeText(
  912.        _INTL("Please enter a message (max. {1} characters).",maxlength),
  913.        _INTL("{1}",startMsg),false,maxlength,Graphics.width) { update }
  914.   end
  915. end
  916.  
  917.  
  918. ######################################
  919.  
  920.  
  921. class PokemonScreen
  922.   def initialize(scene,party)
  923.     @party=party
  924.     @scene=scene
  925.   end
  926.  
  927.   def pbHardRefresh
  928.     @scene.pbHardRefresh
  929.   end
  930.  
  931.   def pbRefresh
  932.     @scene.pbRefresh
  933.   end
  934.  
  935.   def pbRefreshSingle(i)
  936.     @scene.pbRefreshSingle(i)
  937.   end
  938.  
  939.   def pbDisplay(text)
  940.     @scene.pbDisplay(text)
  941.   end
  942.  
  943.   def pbConfirm(text)
  944.     return @scene.pbDisplayConfirm(text)
  945.   end
  946.  
  947.   def pbSwitch(oldid,newid)
  948.     if oldid!=newid
  949.       @scene.pbSwitchBegin(oldid,newid)
  950.       tmp=@party[oldid]
  951.       @party[oldid]=@party[newid]
  952.       @party[newid]=tmp
  953.       @scene.pbSwitchEnd(oldid,newid)
  954.     end
  955.   end
  956.  
  957.   def pbMailScreen(item,pkmn,pkmnid)
  958.     message=""
  959.     loop do
  960.       message=@scene.pbMessageFreeText(
  961.          _INTL("Please enter a message (max. 256 characters)."),"",256)
  962.       if message!=""
  963.         # Store mail if a message was written
  964.         poke1=poke2=poke3=nil
  965.         if $Trainer.party[pkmnid+2]
  966.           p=$Trainer.party[pkmnid+2]
  967.           poke1=[p.species,p.gender,p.isShiny?,(p.form rescue 0),(p.isShadow? rescue false)]
  968.           poke1.push(true) if p.isEgg?
  969.         end
  970.         if $Trainer.party[pkmnid+1]
  971.           p=$Trainer.party[pkmnid+1]
  972.           poke2=[p.species,p.gender,p.isShiny?,(p.form rescue 0),(p.isShadow? rescue false)]
  973.           poke2.push(true) if p.isEgg?
  974.         end
  975.         poke3=[pkmn.species,pkmn.gender,pkmn.isShiny?,(pkmn.form rescue 0),(pkmn.isShadow? rescue false)]
  976.         poke3.push(true) if pkmn.isEgg?
  977.         pbStoreMail(pkmn,item,message,poke1,poke2,poke3)
  978.         return true
  979.       else
  980.         return false if pbConfirm(_INTL("Stop giving the Pokémon Mail?"))
  981.       end
  982.     end
  983.   end
  984.  
  985.   def pbTakeMail(pkmn)
  986.     if !pkmn.hasItem?
  987.       pbDisplay(_INTL("{1} isn't holding anything.",pkmn.name))
  988.     elsif !$PokemonBag.pbCanStore?(pkmn.item)
  989.       pbDisplay(_INTL("The Bag is full. The Pokémon's item could not be removed."))
  990.     elsif pkmn.mail
  991.       if pbConfirm(_INTL("Send the removed mail to your PC?"))
  992.         if !pbMoveToMailbox(pkmn)
  993.           pbDisplay(_INTL("Your PC's Mailbox is full."))
  994.         else
  995.           pbDisplay(_INTL("The mail was sent to your PC."))
  996.           pkmn.setItem(0)
  997.         end
  998.       elsif pbConfirm(_INTL("If the mail is removed, the message will be lost. OK?"))
  999.         pbDisplay(_INTL("Mail was taken from the Pokémon."))
  1000.         $PokemonBag.pbStoreItem(pkmn.item)
  1001.         pkmn.setItem(0)
  1002.         pkmn.mail=nil
  1003.       end
  1004.     else
  1005.       $PokemonBag.pbStoreItem(pkmn.item)
  1006.       itemname=PBItems.getName(pkmn.item)
  1007.       pbDisplay(_INTL("Received the {1} from {2}.",itemname,pkmn.name))
  1008.       pkmn.setItem(0)
  1009.     end
  1010.   end
  1011.  
  1012.   def pbGiveMail(item,pkmn,pkmnid=0)
  1013.     thisitemname=PBItems.getName(item)
  1014.     if pkmn.isEgg?
  1015.       pbDisplay(_INTL("Eggs can't hold items."))
  1016.       return false
  1017.     elsif pkmn.mail
  1018.       pbDisplay(_INTL("{1}'s mail must be removed before giving it an item.",pkmn.name))
  1019.       return false
  1020.     end
  1021.     if pkmn.item!=0
  1022.       itemname=PBItems.getName(pkmn.item)
  1023.       pbDisplay(_INTL("{1} is already holding {2}.\1",pkmn.name,itemname))
  1024.       if pbConfirm(_INTL("Would you like to switch the two items?"))
  1025.         $PokemonBag.pbDeleteItem(item)
  1026.         if !$PokemonBag.pbStoreItem(pkmn.item)
  1027.           if !$PokemonBag.pbStoreItem(item) # Compensate
  1028.             raise _INTL("Can't re-store deleted item in bag")
  1029.           end
  1030.           pbDisplay(_INTL("The Bag is full. The Pokémon's item could not be removed."))
  1031.         else
  1032.           if pbIsMail?(item)
  1033.             if pbMailScreen(item,pkmn,pkmnid)
  1034.               pkmn.setItem(item)
  1035.               pbDisplay(_INTL("The {1} was taken and replaced with the {2}.",itemname,thisitemname))
  1036.               return true
  1037.             else
  1038.               if !$PokemonBag.pbStoreItem(item) # Compensate
  1039.                 raise _INTL("Can't re-store deleted item in bag")
  1040.               end
  1041.             end
  1042.           else
  1043.             pkmn.setItem(item)
  1044.             pbDisplay(_INTL("Took the Pokémon's {1} and gave it the {2}.",itemname,thisitemname))
  1045.             return true
  1046.           end
  1047.         end
  1048.       end
  1049.     else
  1050.       if !pbIsMail?(item) || pbMailScreen(item,pkmn,pkmnid) # Open the mail screen if necessary
  1051.         $PokemonBag.pbDeleteItem(item)
  1052.         pkmn.setItem(item)
  1053.         pbDisplay(_INTL("The Pokémon is now holding the {1}.",thisitemname))
  1054.         return true
  1055.       end
  1056.     end
  1057.     return false
  1058.   end
  1059.  
  1060.   def pbPokemonGiveScreen(item)
  1061.     @scene.pbStartScene(@party,_INTL("Give to which Pokémon?"))
  1062.     pkmnid=@scene.pbChoosePokemon
  1063.     ret=false
  1064.     if pkmnid>=0
  1065.       ret=pbGiveMail(item,@party[pkmnid],pkmnid)
  1066.     end
  1067.     pbRefreshSingle(pkmnid)
  1068.     @scene.pbEndScene
  1069.     return ret
  1070.   end
  1071.  
  1072.   def pbPokemonGiveMailScreen(mailIndex)
  1073.     @scene.pbStartScene(@party,_INTL("Give to which Pokémon?"))
  1074.     pkmnid=@scene.pbChoosePokemon
  1075.     if pkmnid>=0
  1076.       pkmn=@party[pkmnid]
  1077.       if pkmn.item!=0 || pkmn.mail
  1078.         pbDisplay(_INTL("This Pokémon is holding an item. It can't hold mail."))
  1079.       elsif pkmn.isEgg?
  1080.         pbDisplay(_INTL("Eggs can't hold mail."))
  1081.       else
  1082.         pbDisplay(_INTL("Mail was transferred from the Mailbox."))
  1083.         pkmn.mail=$PokemonGlobal.mailbox[mailIndex]
  1084.         pkmn.setItem(pkmn.mail.item)
  1085.         $PokemonGlobal.mailbox.delete_at(mailIndex)
  1086.         pbRefreshSingle(pkmnid)
  1087.       end
  1088.     end
  1089.     @scene.pbEndScene
  1090.   end
  1091.  
  1092.   def pbStartScene(helptext,doublebattle,annotations=nil)
  1093.     @scene.pbStartScene(@party,helptext,annotations)
  1094.   end
  1095.  
  1096.   def pbChoosePokemon(helptext=nil)
  1097.     @scene.pbSetHelpText(helptext) if helptext
  1098.     return @scene.pbChoosePokemon
  1099.   end
  1100.  
  1101.   def pbChooseMove(pokemon,helptext)
  1102.     movenames=[]
  1103.     for i in pokemon.moves
  1104.       break if i.id==0
  1105.       if i.totalpp==0
  1106.         movenames.push(_INTL("{1} (PP: ---)",PBMoves.getName(i.id),i.pp,i.totalpp))
  1107.       else
  1108.         movenames.push(_INTL("{1} (PP: {2}/{3})",PBMoves.getName(i.id),i.pp,i.totalpp))
  1109.       end
  1110.     end
  1111.     return @scene.pbShowCommands(helptext,movenames)
  1112.   end
  1113.  
  1114.   def pbEndScene
  1115.     @scene.pbEndScene
  1116.   end
  1117.  
  1118.   # Checks for identical species
  1119.   def pbCheckSpecies(array)
  1120.     for i in 0...array.length
  1121.       for j in i+1...array.length
  1122.         return false if array[i].species==array[j].species
  1123.       end
  1124.     end
  1125.     return true
  1126.   end
  1127.  
  1128. # Checks for identical held items
  1129.   def pbCheckItems(array)
  1130.     for i in 0...array.length
  1131.       next if !array[i].hasItem?
  1132.       for j in i+1...array.length
  1133.         return false if array[i].item==array[j].item
  1134.       end
  1135.     end
  1136.     return true
  1137.   end
  1138.  
  1139.   def pbPokemonMultipleEntryScreenEx(ruleset)
  1140.     annot=[]
  1141.     statuses=[]
  1142.     ordinals=[
  1143.        _INTL("INELIGIBLE"),
  1144.        _INTL("NOT ENTERED"),
  1145.        _INTL("BANNED"),
  1146.        _INTL("FIRST"),
  1147.        _INTL("SECOND"),
  1148.        _INTL("THIRD"),
  1149.        _INTL("FOURTH"),
  1150.        _INTL("FIFTH"),
  1151.        _INTL("SIXTH")
  1152.     ]
  1153.     if !ruleset.hasValidTeam?(@party)
  1154.       return nil
  1155.     end
  1156.     ret=nil
  1157.     addedEntry=false
  1158.     for i in 0...@party.length
  1159.       if ruleset.isPokemonValid?(@party[i])
  1160.         statuses[i]=1
  1161.       else
  1162.         statuses[i]=2
  1163.       end  
  1164.     end
  1165.     for i in 0...@party.length
  1166.       annot[i]=ordinals[statuses[i]]
  1167.     end
  1168.     @scene.pbStartScene(@party,_INTL("Choose Pokémon and confirm."),annot,true)
  1169.     loop do
  1170.       realorder=[]
  1171.       for i in 0...@party.length
  1172.         for j in 0...@party.length
  1173.           if statuses[j]==i+3
  1174.             realorder.push(j)
  1175.             break
  1176.           end
  1177.         end
  1178.       end
  1179.       for i in 0...realorder.length
  1180.         statuses[realorder[i]]=i+3
  1181.       end
  1182.       for i in 0...@party.length
  1183.         annot[i]=ordinals[statuses[i]]
  1184.       end
  1185.       @scene.pbAnnotate(annot)
  1186.       if realorder.length==ruleset.number && addedEntry
  1187.         @scene.pbSelect(6)
  1188.       end
  1189.       @scene.pbSetHelpText(_INTL("Choose Pokémon and confirm."))
  1190.       pkmnid=@scene.pbChoosePokemon
  1191.       addedEntry=false
  1192.       if pkmnid==6 # Confirm was chosen
  1193.         ret=[]
  1194.         for i in realorder
  1195.           ret.push(@party[i])
  1196.         end
  1197.         error=[]
  1198.         if !ruleset.isValid?(ret,error)
  1199.           pbDisplay(error[0])
  1200.           ret=nil
  1201.         else
  1202.           break
  1203.         end
  1204.       end
  1205.       if pkmnid<0 # Canceled
  1206.         break
  1207.       end
  1208.       cmdEntry=-1
  1209.       cmdNoEntry=-1
  1210.       cmdSummary=-1
  1211.       commands=[]
  1212.       if (statuses[pkmnid] || 0) == 1
  1213.         commands[cmdEntry=commands.length]=_INTL("Entry")
  1214.       elsif (statuses[pkmnid] || 0) > 2
  1215.         commands[cmdNoEntry=commands.length]=_INTL("No Entry")
  1216.       end
  1217.       pkmn=@party[pkmnid]
  1218.       commands[cmdSummary=commands.length]=_INTL("Summary")
  1219.       commands[commands.length]=_INTL("Cancel")
  1220.       command=@scene.pbShowCommands(_INTL("Do what with {1}?",pkmn.name),commands) if pkmn
  1221.       if cmdEntry>=0 && command==cmdEntry
  1222.         if realorder.length>=ruleset.number && ruleset.number>0
  1223.           pbDisplay(_INTL("No more than {1} Pokémon may enter.",ruleset.number))
  1224.         else
  1225.           statuses[pkmnid]=realorder.length+3
  1226.           addedEntry=true
  1227.           pbRefreshSingle(pkmnid)
  1228.         end
  1229.       elsif cmdNoEntry>=0 && command==cmdNoEntry
  1230.         statuses[pkmnid]=1
  1231.         pbRefreshSingle(pkmnid)
  1232.       elsif cmdSummary>=0 && command==cmdSummary
  1233.         @scene.pbSummary(pkmnid)
  1234.       end
  1235.     end
  1236.     @scene.pbEndScene
  1237.     return ret
  1238.   end
  1239.  
  1240.   def pbChooseAblePokemon(ableProc,allowIneligible=false)
  1241.     annot=[]
  1242.     eligibility=[]
  1243.     for pkmn in @party
  1244.       elig=ableProc.call(pkmn)
  1245.       eligibility.push(elig)
  1246.       annot.push(elig ? _INTL("ABLE") : _INTL("NOT ABLE"))
  1247.     end
  1248.     ret=-1
  1249.     @scene.pbStartScene(@party,
  1250.        @party.length>1 ? _INTL("Choose a Pokémon.") : _INTL("Choose Pokémon or cancel."),annot)
  1251.     loop do
  1252.       @scene.pbSetHelpText(
  1253.          @party.length>1 ? _INTL("Choose a Pokémon.") : _INTL("Choose Pokémon or cancel."))
  1254.       pkmnid=@scene.pbChoosePokemon
  1255.       if pkmnid<0
  1256.         break
  1257.       elsif !eligibility[pkmnid] && !allowIneligible
  1258.         pbDisplay(_INTL("This Pokémon can't be chosen."))
  1259.       else
  1260.         ret=pkmnid
  1261.         break
  1262.       end
  1263.     end
  1264.     @scene.pbEndScene
  1265.     return ret
  1266.   end
  1267.  
  1268.   def pbRefreshAnnotations(ableProc)   # For after using an evolution stone
  1269.     annot=[]
  1270.     for pkmn in @party
  1271.       elig=ableProc.call(pkmn)
  1272.       annot.push(elig ? _INTL("ABLE") : _INTL("NOT ABLE"))
  1273.     end
  1274.     @scene.pbAnnotate(annot)
  1275.   end
  1276.  
  1277.   def pbClearAnnotations
  1278.     @scene.pbAnnotate(nil)
  1279.   end
  1280.  
  1281.   def pbPokemonDebug(pkmn,pkmnid)
  1282.     command=0
  1283.     loop do
  1284.       command=@scene.pbShowCommands(_INTL("Do what with {1}?",pkmn.name),[
  1285.          _INTL("HP/Status"),
  1286.          _INTL("Level"),
  1287.          _INTL("Species"),
  1288.          _INTL("Moves"),
  1289.          _INTL("Gender"),
  1290.          _INTL("Ability"),
  1291.          _INTL("Nature"),
  1292.          _INTL("Shininess"),
  1293.          _INTL("Form"),
  1294.          _INTL("Happiness"),
  1295.          _INTL("EV/IV/pID"),
  1296.          _INTL("Pokérus"),
  1297.          _INTL("Ownership"),
  1298.          _INTL("Nickname"),
  1299.          _INTL("Poké Ball"),
  1300.          _INTL("Ribbons"),
  1301.          _INTL("Egg"),
  1302.          _INTL("Shadow Pokémon"),
  1303.          _INTL("Make Mystery Gift"),
  1304.          _INTL("Duplicate"),
  1305.          _INTL("Delete"),
  1306.          _INTL("Cancel")
  1307.       ],command)
  1308.       case command
  1309.       ### Cancel ###
  1310.       when -1, 21
  1311.         break
  1312.       ### HP/Status ###
  1313.       when 0
  1314.         cmd=0
  1315.         loop do
  1316.           cmd=@scene.pbShowCommands(_INTL("Do what with {1}?",pkmn.name),[
  1317.              _INTL("Set HP"),
  1318.              _INTL("Status: Sleep"),
  1319.              _INTL("Status: Poison"),
  1320.              _INTL("Status: Burn"),
  1321.              _INTL("Status: Paralysis"),
  1322.              _INTL("Status: Frozen"),
  1323.              _INTL("Fainted"),
  1324.              _INTL("Heal")
  1325.           ],cmd)
  1326.           # Break
  1327.           if cmd==-1
  1328.             break
  1329.           # Set HP
  1330.           elsif cmd==0
  1331.             params=ChooseNumberParams.new
  1332.             params.setRange(0,pkmn.totalhp)
  1333.             params.setDefaultValue(pkmn.hp)
  1334.             newhp=Kernel.pbMessageChooseNumber(
  1335.                _INTL("Set the Pokémon's HP (max. {1}).",pkmn.totalhp),params) { @scene.update }
  1336.             if newhp!=pkmn.hp
  1337.               pkmn.hp=newhp
  1338.               pbDisplay(_INTL("{1}'s HP was set to {2}.",pkmn.name,pkmn.hp))
  1339.               pbRefreshSingle(pkmnid)
  1340.             end
  1341.           # Set status
  1342.           elsif cmd>=1 && cmd<=5
  1343.             if pkmn.hp>0
  1344.               pkmn.status=cmd
  1345.               pkmn.statusCount=0
  1346.               if pkmn.status==PBStatuses::SLEEP
  1347.                 params=ChooseNumberParams.new
  1348.                 params.setRange(0,9)
  1349.                 params.setDefaultValue(0)
  1350.                 sleep=Kernel.pbMessageChooseNumber(
  1351.                    _INTL("Set the Pokémon's sleep count."),params) { @scene.update }
  1352.                 pkmn.statusCount=sleep
  1353.               end
  1354.               pbDisplay(_INTL("{1}'s status was changed.",pkmn.name))
  1355.               pbRefreshSingle(pkmnid)
  1356.             else
  1357.               pbDisplay(_INTL("{1}'s status could not be changed.",pkmn.name))
  1358.             end
  1359.           # Faint
  1360.           elsif cmd==6
  1361.             pkmn.hp=0
  1362.             pbDisplay(_INTL("{1}'s HP was set to 0.",pkmn.name))
  1363.             pbRefreshSingle(pkmnid)
  1364.           # Heal
  1365.           elsif cmd==7
  1366.             pkmn.heal
  1367.             pbDisplay(_INTL("{1} was fully healed.",pkmn.name))
  1368.             pbRefreshSingle(pkmnid)
  1369.           end
  1370.         end
  1371.       ### Level ###
  1372.       when 1
  1373.         params=ChooseNumberParams.new
  1374.         params.setRange(1,PBExperience::MAXLEVEL)
  1375.         params.setDefaultValue(pkmn.level)
  1376.         level=Kernel.pbMessageChooseNumber(
  1377.            _INTL("Set the Pokémon's level (max. {1}).",PBExperience::MAXLEVEL),params) { @scene.update }
  1378.         if level!=pkmn.level
  1379.           pkmn.level=level
  1380.           pkmn.calcStats
  1381.           pbDisplay(_INTL("{1}'s level was set to {2}.",pkmn.name,pkmn.level))
  1382.           pbRefreshSingle(pkmnid)
  1383.         end
  1384.       ### Species ###
  1385.       when 2
  1386.         species=pbChooseSpecies(pkmn.species)
  1387.         if species!=0
  1388.           oldspeciesname=PBSpecies.getName(pkmn.species)
  1389.           pkmn.species=species
  1390.           pkmn.calcStats
  1391.           oldname=pkmn.name
  1392.           pkmn.name=PBSpecies.getName(pkmn.species) if pkmn.name==oldspeciesname
  1393.           pbDisplay(_INTL("{1}'s species was changed to {2}.",oldname,PBSpecies.getName(pkmn.species)))
  1394.           pbSeenForm(pkmn)
  1395.           pbRefreshSingle(pkmnid)
  1396.         end
  1397.       ### Moves ###
  1398.       when 3
  1399.         cmd=0
  1400.         loop do
  1401.           cmd=@scene.pbShowCommands(_INTL("Do what with {1}?",pkmn.name),[
  1402.              _INTL("Teach move"),
  1403.              _INTL("Forget move"),
  1404.              _INTL("Reset movelist"),
  1405.              _INTL("Reset initial moves")],cmd)
  1406.           # Break
  1407.           if cmd==-1
  1408.             break
  1409.           # Teach move
  1410.           elsif cmd==0
  1411.             move=pbChooseMoveList
  1412.             if move!=0
  1413.               pbLearnMove(pkmn,move)
  1414.               pbRefreshSingle(pkmnid)
  1415.             end
  1416.           # Forget move
  1417.           elsif cmd==1
  1418.             move=pbChooseMove(pkmn,_INTL("Choose move to forget."))
  1419.             if move>=0
  1420.               movename=PBMoves.getName(pkmn.moves[move].id)
  1421.               pkmn.pbDeleteMoveAtIndex(move)
  1422.               pbDisplay(_INTL("{1} forgot {2}.",pkmn.name,movename))
  1423.               pbRefreshSingle(pkmnid)
  1424.             end
  1425.           # Reset movelist
  1426.           elsif cmd==2
  1427.             pkmn.resetMoves
  1428.             pbDisplay(_INTL("{1}'s moves were reset.",pkmn.name))
  1429.             pbRefreshSingle(pkmnid)
  1430.           # Reset initial moves
  1431.           elsif cmd==3
  1432.             pkmn.pbRecordFirstMoves
  1433.             pbDisplay(_INTL("{1}'s moves were set as its first-known moves.",pkmn.name))
  1434.             pbRefreshSingle(pkmnid)
  1435.           end
  1436.         end
  1437.       ### Gender ###
  1438.       when 4
  1439.         if pkmn.gender==2
  1440.           pbDisplay(_INTL("{1} is genderless.",pkmn.name))
  1441.         else
  1442.           cmd=0
  1443.           loop do
  1444.             oldgender=(pkmn.isMale?) ? _INTL("male") : _INTL("female")
  1445.             msg=[_INTL("Gender {1} is natural.",oldgender),
  1446.                  _INTL("Gender {1} is being forced.",oldgender)][pkmn.genderflag ? 1 : 0]
  1447.             cmd=@scene.pbShowCommands(msg,[
  1448.                _INTL("Make male"),
  1449.                _INTL("Make female"),
  1450.                _INTL("Remove override")],cmd)
  1451.             # Break
  1452.             if cmd==-1
  1453.               break
  1454.             # Make male
  1455.             elsif cmd==0
  1456.               pkmn.setGender(0)
  1457.               if pkmn.isMale?
  1458.                 pbDisplay(_INTL("{1} is now male.",pkmn.name))
  1459.               else
  1460.                 pbDisplay(_INTL("{1}'s gender couldn't be changed.",pkmn.name))
  1461.               end
  1462.             # Make female
  1463.             elsif cmd==1
  1464.               pkmn.setGender(1)
  1465.               if pkmn.isFemale?
  1466.                 pbDisplay(_INTL("{1} is now female.",pkmn.name))
  1467.               else
  1468.                 pbDisplay(_INTL("{1}'s gender couldn't be changed.",pkmn.name))
  1469.               end
  1470.             # Remove override
  1471.             elsif cmd==2
  1472.               pkmn.genderflag=nil
  1473.               pbDisplay(_INTL("Gender override removed."))
  1474.             end
  1475.             pbSeenForm(pkmn)
  1476.             pbRefreshSingle(pkmnid)
  1477.           end
  1478.         end
  1479.       ### Ability ###
  1480.       when 5
  1481.         cmd=0
  1482.         loop do
  1483.           abils=pkmn.getAbilityList
  1484.           oldabil=PBAbilities.getName(pkmn.ability)
  1485.           commands=[]
  1486.           for i in abils
  1487.             commands.push((i[1]<2 ? "" : "(H) ")+PBAbilities.getName(i[0]))
  1488.           end
  1489.           commands.push(_INTL("Remove override"))
  1490.           msg=[_INTL("Ability {1} is natural.",oldabil),
  1491.                _INTL("Ability {1} is being forced.",oldabil)][pkmn.abilityflag!=nil ? 1 : 0]
  1492.           cmd=@scene.pbShowCommands(msg,commands,cmd)
  1493.           # Break
  1494.           if cmd==-1
  1495.             break
  1496.           # Set ability override
  1497.           elsif cmd>=0 && cmd<abils.length
  1498.             pkmn.setAbility(abils[cmd][1])
  1499.           # Remove override
  1500.           elsif cmd==abils.length
  1501.             pkmn.abilityflag=nil
  1502.           end
  1503.           pbRefreshSingle(pkmnid)
  1504.         end
  1505.       ### Nature ###
  1506.       when 6
  1507.         cmd=0
  1508.         loop do
  1509.           oldnature=PBNatures.getName(pkmn.nature)
  1510.           commands=[]
  1511.           (PBNatures.getCount).times do |i|
  1512.             commands.push(PBNatures.getName(i))
  1513.           end
  1514.           commands.push(_INTL("Remove override"))
  1515.           msg=[_INTL("Nature {1} is natural.",oldnature),
  1516.                _INTL("Nature {1} is being forced.",oldnature)][pkmn.natureflag ? 1 : 0]
  1517.           cmd=@scene.pbShowCommands(msg,commands,cmd)
  1518.           # Break
  1519.           if cmd==-1
  1520.             break
  1521.           # Set nature override
  1522.           elsif cmd>=0 && cmd<PBNatures.getCount
  1523.             pkmn.setNature(cmd)
  1524.             pkmn.calcStats
  1525.           # Remove override
  1526.           elsif cmd==PBNatures.getCount
  1527.             pkmn.natureflag=nil
  1528.           end
  1529.           pbRefreshSingle(pkmnid)
  1530.         end
  1531.       ### Shininess ###
  1532.       when 7
  1533.         cmd=0
  1534.         loop do
  1535.           oldshiny=(pkmn.isShiny?) ? _INTL("shiny") : _INTL("normal")
  1536.           msg=[_INTL("Shininess ({1}) is natural.",oldshiny),
  1537.                _INTL("Shininess ({1}) is being forced.",oldshiny)][pkmn.shinyflag!=nil ? 1 : 0]
  1538.           cmd=@scene.pbShowCommands(msg,[
  1539.                _INTL("Make shiny"),
  1540.                _INTL("Make normal"),
  1541.                _INTL("Remove override")],cmd)
  1542.           # Break
  1543.           if cmd==-1
  1544.             break
  1545.           # Make shiny
  1546.           elsif cmd==0
  1547.             pkmn.makeShiny
  1548.           # Make normal
  1549.           elsif cmd==1
  1550.             pkmn.makeNotShiny
  1551.           # Remove override
  1552.           elsif cmd==2
  1553.             pkmn.shinyflag=nil
  1554.           end
  1555.           pbRefreshSingle(pkmnid)
  1556.         end
  1557.       ### Form ###
  1558.       when 8
  1559.         params=ChooseNumberParams.new
  1560.         params.setRange(0,100)
  1561.         params.setDefaultValue(pkmn.form)
  1562.         f=Kernel.pbMessageChooseNumber(
  1563.            _INTL("Set the Pokémon's form."),params) { @scene.update }
  1564.         if f!=pkmn.form
  1565.           pkmn.form=f
  1566.           pbDisplay(_INTL("{1}'s form was set to {2}.",pkmn.name,pkmn.form))
  1567.           pbSeenForm(pkmn)
  1568.           pbRefreshSingle(pkmnid)
  1569.         end
  1570.       ### Happiness ###
  1571.       when 9
  1572.         params=ChooseNumberParams.new
  1573.         params.setRange(0,255)
  1574.         params.setDefaultValue(pkmn.happiness)
  1575.         h=Kernel.pbMessageChooseNumber(
  1576.            _INTL("Set the Pokémon's happiness (max. 255)."),params) { @scene.update }
  1577.         if h!=pkmn.happiness
  1578.           pkmn.happiness=h
  1579.           pbDisplay(_INTL("{1}'s happiness was set to {2}.",pkmn.name,pkmn.happiness))
  1580.           pbRefreshSingle(pkmnid)
  1581.         end
  1582.       ### EV/IV/pID ###
  1583.       when 10
  1584.         stats=[_INTL("HP"),_INTL("Attack"),_INTL("Defense"),
  1585.                _INTL("Speed"),_INTL("Sp. Attack"),_INTL("Sp. Defense")]
  1586.         cmd=0
  1587.         loop do
  1588.           persid=sprintf("0x%08X",pkmn.personalID)
  1589.           cmd=@scene.pbShowCommands(_INTL("Personal ID is {1}.",persid),[
  1590.              _INTL("Set EVs"),
  1591.              _INTL("Set IVs"),
  1592.              _INTL("Randomise pID")],cmd)
  1593.           case cmd
  1594.           # Break
  1595.           when -1
  1596.             break
  1597.           # Set EVs
  1598.           when 0
  1599.             cmd2=0
  1600.             loop do
  1601.               evcommands=[]
  1602.               for i in 0...stats.length
  1603.                 evcommands.push(stats[i]+" (#{pkmn.ev[i]})")
  1604.               end
  1605.               cmd2=@scene.pbShowCommands(_INTL("Change which EV?"),evcommands,cmd2)
  1606.               if cmd2==-1
  1607.                 break
  1608.               elsif cmd2>=0 && cmd2<stats.length
  1609.                 params=ChooseNumberParams.new
  1610.                 params.setRange(0,PokeBattle_Pokemon::EVSTATLIMIT)
  1611.                 params.setDefaultValue(pkmn.ev[cmd2])
  1612.                 params.setCancelValue(pkmn.ev[cmd2])
  1613.                 f=Kernel.pbMessageChooseNumber(
  1614.                    _INTL("Set the EV for {1} (max. {2}).",
  1615.                       stats[cmd2],PokeBattle_Pokemon::EVSTATLIMIT),params) { @scene.update }
  1616.                 pkmn.ev[cmd2]=f
  1617.                 pkmn.totalhp
  1618.                 pkmn.calcStats
  1619.                 pbRefreshSingle(pkmnid)
  1620.               end
  1621.             end
  1622.           # Set IVs
  1623.           when 1
  1624.             cmd2=0
  1625.             loop do
  1626.               hiddenpower=pbHiddenPower(pkmn.iv)
  1627.               msg=_INTL("Hidden Power:\n{1}, power {2}.",PBTypes.getName(hiddenpower[0]),hiddenpower[1])
  1628.               ivcommands=[]
  1629.               for i in 0...stats.length
  1630.                 ivcommands.push(stats[i]+" (#{pkmn.iv[i]})")
  1631.               end
  1632.               ivcommands.push(_INTL("Randomise all"))
  1633.               cmd2=@scene.pbShowCommands(msg,ivcommands,cmd2)
  1634.               if cmd2==-1
  1635.                 break
  1636.               elsif cmd2>=0 && cmd2<stats.length
  1637.                 params=ChooseNumberParams.new
  1638.                 params.setRange(0,31)
  1639.                 params.setDefaultValue(pkmn.iv[cmd2])
  1640.                 params.setCancelValue(pkmn.iv[cmd2])
  1641.                 f=Kernel.pbMessageChooseNumber(
  1642.                    _INTL("Set the IV for {1} (max. 31).",stats[cmd2]),params) { @scene.update }
  1643.                 pkmn.iv[cmd2]=f
  1644.                 pkmn.calcStats
  1645.                 pbRefreshSingle(pkmnid)
  1646.               elsif cmd2==ivcommands.length-1
  1647.                 pkmn.iv[0]=rand(32)
  1648.                 pkmn.iv[1]=rand(32)
  1649.                 pkmn.iv[2]=rand(32)
  1650.                 pkmn.iv[3]=rand(32)
  1651.                 pkmn.iv[4]=rand(32)
  1652.                 pkmn.iv[5]=rand(32)
  1653.                 pkmn.calcStats
  1654.                 pbRefreshSingle(pkmnid)
  1655.               end
  1656.             end
  1657.           # Randomise pID
  1658.           when 2
  1659.             pkmn.personalID=rand(256)
  1660.             pkmn.personalID|=rand(256)<<8
  1661.             pkmn.personalID|=rand(256)<<16
  1662.             pkmn.personalID|=rand(256)<<24
  1663.             pkmn.calcStats
  1664.             pbRefreshSingle(pkmnid)
  1665.           end
  1666.         end
  1667.       ### Pokérus ###
  1668.       when 11
  1669.         cmd=0
  1670.         loop do
  1671.           pokerus=(pkmn.pokerus) ? pkmn.pokerus : 0
  1672.           msg=[_INTL("{1} doesn't have Pokérus.",pkmn.name),
  1673.                _INTL("Has strain {1}, infectious for {2} more days.",pokerus/16,pokerus%16),
  1674.                _INTL("Has strain {1}, not infectious.",pokerus/16)][pkmn.pokerusStage]
  1675.           cmd=@scene.pbShowCommands(msg,[
  1676.                _INTL("Give random strain"),
  1677.                _INTL("Make not infectious"),
  1678.                _INTL("Clear Pokérus")],cmd)
  1679.           # Break
  1680.           if cmd==-1
  1681.             break
  1682.           # Give random strain
  1683.           elsif cmd==0
  1684.             pkmn.givePokerus
  1685.           # Make not infectious
  1686.           elsif cmd==1
  1687.             strain=pokerus/16
  1688.             p=strain<<4
  1689.             pkmn.pokerus=p
  1690.           # Clear Pokérus
  1691.           elsif cmd==2
  1692.             pkmn.pokerus=0
  1693.           end
  1694.         end
  1695.       ### Ownership ###
  1696.       when 12
  1697.         cmd=0
  1698.         loop do
  1699.           gender=[_INTL("Male"),_INTL("Female"),_INTL("Unknown")][pkmn.otgender]
  1700.           msg=[_INTL("Player's Pokémon\n{1}\n{2}\n{3} ({4})",pkmn.ot,gender,pkmn.publicID,pkmn.trainerID),
  1701.                _INTL("Foreign Pokémon\n{1}\n{2}\n{3} ({4})",pkmn.ot,gender,pkmn.publicID,pkmn.trainerID)
  1702.               ][pkmn.isForeign?($Trainer) ? 1 : 0]
  1703.           cmd=@scene.pbShowCommands(msg,[
  1704.                _INTL("Make player's"),
  1705.                _INTL("Set OT's name"),
  1706.                _INTL("Set OT's gender"),
  1707.                _INTL("Random foreign ID"),
  1708.                _INTL("Set foreign ID")],cmd)
  1709.           # Break
  1710.           if cmd==-1
  1711.             break
  1712.           # Make player's
  1713.           elsif cmd==0
  1714.             pkmn.trainerID=$Trainer.id
  1715.             pkmn.ot=$Trainer.name
  1716.             pkmn.otgender=$Trainer.gender
  1717.           # Set OT's name
  1718.           elsif cmd==1
  1719.             newot=pbEnterPlayerName(_INTL("{1}'s OT's name?",pkmn.name),1,7)
  1720.             pkmn.ot=newot
  1721.           # Set OT's gender
  1722.           elsif cmd==2
  1723.             cmd2=@scene.pbShowCommands(_INTL("Set OT's gender."),
  1724.                [_INTL("Male"),_INTL("Female"),_INTL("Unknown")])
  1725.             pkmn.otgender=cmd2 if cmd2>=0
  1726.           # Random foreign ID
  1727.           elsif cmd==3
  1728.             pkmn.trainerID=$Trainer.getForeignID
  1729.           # Set foreign ID
  1730.           elsif cmd==4
  1731.             params=ChooseNumberParams.new
  1732.             params.setRange(0,65535)
  1733.             params.setDefaultValue(pkmn.publicID)
  1734.             val=Kernel.pbMessageChooseNumber(
  1735.                _INTL("Set the new ID (max. 65535)."),params) { @scene.update }
  1736.             pkmn.trainerID=val
  1737.             pkmn.trainerID|=val<<16
  1738.           end
  1739.         end
  1740.       ### Nickname ###
  1741.       when 13
  1742.         cmd=0
  1743.         loop do
  1744.           speciesname=PBSpecies.getName(pkmn.species)
  1745.           msg=[_INTL("{1} has the nickname {2}.",speciesname,pkmn.name),
  1746.                _INTL("{1} has no nickname.",speciesname)][pkmn.name==speciesname ? 1 : 0]
  1747.           cmd=@scene.pbShowCommands(msg,[
  1748.                _INTL("Rename"),
  1749.                _INTL("Erase name")],cmd)
  1750.           # Break
  1751.           if cmd==-1
  1752.             break
  1753.           # Rename
  1754.           elsif cmd==0
  1755.             newname=pbEnterPokemonName(_INTL("{1}'s nickname?",speciesname),0,10,"",pkmn)
  1756.             pkmn.name=(newname=="") ? speciesname : newname
  1757.             pbRefreshSingle(pkmnid)
  1758.           # Erase name
  1759.           elsif cmd==1
  1760.             pkmn.name=speciesname
  1761.           end
  1762.         end
  1763.       ### Poké Ball ###
  1764.       when 14
  1765.         cmd=0
  1766.         loop do
  1767.           oldball=PBItems.getName(pbBallTypeToBall(pkmn.ballused))
  1768.           commands=[]; balls=[]
  1769.           for key in $BallTypes.keys
  1770.             item=getID(PBItems,$BallTypes[key])
  1771.             balls.push([key,PBItems.getName(item)]) if item && item>0
  1772.           end
  1773.           balls.sort! {|a,b| a[1]<=>b[1]}
  1774.           for i in 0...commands.length
  1775.             cmd=i if pkmn.ballused==balls[i][0]
  1776.           end
  1777.           for i in balls
  1778.             commands.push(i[1])
  1779.           end
  1780.           cmd=@scene.pbShowCommands(_INTL("{1} used.",oldball),commands,cmd)
  1781.           if cmd==-1
  1782.             break
  1783.           else
  1784.             pkmn.ballused=balls[cmd][0]
  1785.           end
  1786.         end
  1787.       ### Ribbons ###
  1788.       when 15
  1789.         cmd=0
  1790.         loop do
  1791.           commands=[]
  1792.           for i in 1..PBRibbons.maxValue
  1793.             commands.push(_INTL("{1} {2}",
  1794.                pkmn.hasRibbon?(i) ? "[X]" : "[  ]",PBRibbons.getName(i)))
  1795.           end
  1796.           cmd=@scene.pbShowCommands(_INTL("{1} ribbons.",pkmn.ribbonCount),commands,cmd)
  1797.           if cmd==-1
  1798.             break
  1799.           elsif cmd>=0 && cmd<commands.length
  1800.             if pkmn.hasRibbon?(cmd+1)
  1801.               pkmn.takeRibbon(cmd+1)
  1802.             else
  1803.               pkmn.giveRibbon(cmd+1)
  1804.             end
  1805.           end
  1806.         end
  1807.       ### Egg ###
  1808.       when 16
  1809.         cmd=0
  1810.         loop do
  1811.           msg=[_INTL("Not an egg"),
  1812.                _INTL("Egg with eggsteps: {1}.",pkmn.eggsteps)][pkmn.isEgg? ? 1 : 0]
  1813.           cmd=@scene.pbShowCommands(msg,[
  1814.                _INTL("Make egg"),
  1815.                _INTL("Make Pokémon"),
  1816.                _INTL("Set eggsteps to 1")],cmd)
  1817.           # Break
  1818.           if cmd==-1
  1819.             break
  1820.           # Make egg
  1821.           elsif cmd==0
  1822.             if pbHasEgg?(pkmn.species) ||
  1823.                pbConfirm(_INTL("{1} cannot be an egg. Make egg anyway?",PBSpecies.getName(pkmn.species)))
  1824.               pkmn.level=EGGINITIALLEVEL
  1825.               pkmn.calcStats
  1826.               pkmn.name=_INTL("Egg")
  1827.               dexdata=pbOpenDexData
  1828.               pbDexDataOffset(dexdata,pkmn.species,21)
  1829.               pkmn.eggsteps=dexdata.fgetw
  1830.               dexdata.close
  1831.               pkmn.hatchedMap=0
  1832.               pkmn.obtainMode=1
  1833.               pbRefreshSingle(pkmnid)
  1834.             end
  1835.           # Make Pokémon
  1836.           elsif cmd==1
  1837.             pkmn.name=PBSpecies.getName(pkmn.species)
  1838.             pkmn.eggsteps=0
  1839.             pkmn.hatchedMap=0
  1840.             pkmn.obtainMode=0
  1841.             pbRefreshSingle(pkmnid)
  1842.           # Set eggsteps to 1
  1843.           elsif cmd==2
  1844.             pkmn.eggsteps=1 if pkmn.eggsteps>0
  1845.           end
  1846.         end
  1847.       ### Shadow Pokémon ###
  1848.       when 17
  1849.         cmd=0
  1850.         loop do
  1851.           msg=[_INTL("Not a Shadow Pokémon."),
  1852.                _INTL("Heart gauge is {1}.",pkmn.heartgauge)][(pkmn.isShadow? rescue false) ? 1 : 0]
  1853.           cmd=@scene.pbShowCommands(msg,[
  1854.              _INTL("Make Shadow"),
  1855.              _INTL("Lower heart gauge")],cmd)
  1856.           # Break
  1857.           if cmd==-1
  1858.             break
  1859.           # Make Shadow
  1860.           elsif cmd==0
  1861.             if !(pkmn.isShadow? rescue false) && pkmn.respond_to?("makeShadow")
  1862.               pkmn.makeShadow
  1863.               pbDisplay(_INTL("{1} is now a Shadow Pokémon.",pkmn.name))
  1864.               pbRefreshSingle(pkmnid)
  1865.             else
  1866.               pbDisplay(_INTL("{1} is already a Shadow Pokémon.",pkmn.name))
  1867.             end
  1868.           # Lower heart gauge
  1869.           elsif cmd==1
  1870.             if (pkmn.isShadow? rescue false)
  1871.               prev=pkmn.heartgauge
  1872.               pkmn.adjustHeart(-700)
  1873.               Kernel.pbMessage(_INTL("{1}'s heart gauge was lowered from {2} to {3} (now stage {4}).",
  1874.                  pkmn.name,prev,pkmn.heartgauge,pkmn.heartStage))
  1875.               pbReadyToPurify(pkmn)
  1876.             else
  1877.               Kernel.pbMessage(_INTL("{1} is not a Shadow Pokémon.",pkmn.name))
  1878.             end
  1879.           end
  1880.         end
  1881.       ### Make Mystery Gift ###
  1882.       when 18
  1883.         pbCreateMysteryGift(0,pkmn)
  1884.       ### Duplicate ###
  1885.       when 19
  1886.         if pbConfirm(_INTL("Are you sure you want to copy this Pokémon?"))
  1887.           clonedpkmn=pkmn.clone
  1888.           clonedpkmn.iv=pkmn.iv.clone
  1889.           clonedpkmn.ev=pkmn.ev.clone
  1890.           pbStorePokemon(clonedpkmn)
  1891.           pbHardRefresh
  1892.           pbDisplay(_INTL("The Pokémon was duplicated."))
  1893.           break
  1894.         end
  1895.       ### Delete ###
  1896.       when 20
  1897.         if pbConfirm(_INTL("Are you sure you want to delete this Pokémon?"))
  1898.           @party[pkmnid]=nil
  1899.           @party.compact!
  1900.           pbHardRefresh
  1901.           pbDisplay(_INTL("The Pokémon was deleted."))
  1902.           break
  1903.         end
  1904.       end
  1905.     end
  1906.   end
  1907.  
  1908.   def pbPokemonScreen
  1909.     @scene.pbStartScene(@party,@party.length>1 ? _INTL("Choose a Pokémon.") : _INTL("Choose Pokémon or cancel."),nil)
  1910.     loop do
  1911.       @scene.pbSetHelpText(@party.length>1 ? _INTL("Choose a Pokémon.") : _INTL("Choose Pokémon or cancel."))
  1912.       pkmnid=@scene.pbChoosePokemon
  1913.       break if pkmnid<0
  1914.       pkmn=@party[pkmnid]
  1915.       commands   = []
  1916.       cmdSummary = -1
  1917.       cmdDebug   = -1
  1918.       cmdMoves   = [-1,-1,-1,-1]
  1919.       cmdSwitch  = -1
  1920.       cmdMail    = -1
  1921.       cmdItem    = -1
  1922.       # Build the commands
  1923.       commands[cmdSummary=commands.length]      = _INTL("Summary")
  1924.       commands[cmdDebug=commands.length]        = _INTL("Debug") if $DEBUG
  1925.       for i in 0...pkmn.moves.length
  1926.         move=pkmn.moves[i]
  1927.         # Check for hidden moves and add any that were found
  1928.         if !pkmn.isEgg? && (isConst?(move.id,PBMoves,:MILKDRINK) ||
  1929.                             isConst?(move.id,PBMoves,:SOFTBOILED) ||
  1930.                             HiddenMoveHandlers.hasHandler(move.id))
  1931.           commands[cmdMoves[i]=commands.length] = PBMoves.getName(move.id)
  1932.         end
  1933.       end
  1934.       commands[cmdSwitch=commands.length]       = _INTL("Switch") if @party.length>1
  1935.       if !pkmn.isEgg?
  1936.         if pkmn.mail
  1937.           commands[cmdMail=commands.length]     = _INTL("Mail")
  1938.         else
  1939.           commands[cmdItem=commands.length]     = _INTL("Item")
  1940.         end
  1941.       end
  1942.       commands[commands.length]                 = _INTL("Cancel")
  1943.       command=@scene.pbShowCommands(_INTL("Do what with {1}?",pkmn.name),commands)
  1944.       havecommand=false
  1945.       for i in 0...4
  1946.         if cmdMoves[i]>=0 && command==cmdMoves[i]
  1947.           havecommand=true
  1948.           if isConst?(pkmn.moves[i].id,PBMoves,:SOFTBOILED) ||
  1949.              isConst?(pkmn.moves[i].id,PBMoves,:MILKDRINK)
  1950.             amt=[(pkmn.totalhp/5).floor,1].max
  1951.             if pkmn.hp<=amt
  1952.               pbDisplay(_INTL("Not enough HP..."))
  1953.               break
  1954.             end
  1955.             @scene.pbSetHelpText(_INTL("Use on which Pokémon?"))
  1956.             oldpkmnid=pkmnid
  1957.             loop do
  1958.               @scene.pbPreSelect(oldpkmnid)
  1959.               pkmnid=@scene.pbChoosePokemon(true,pkmnid)
  1960.               break if pkmnid<0
  1961.               newpkmn=@party[pkmnid]
  1962.               if pkmnid==oldpkmnid
  1963.                 pbDisplay(_INTL("{1} can't use {2} on itself!",pkmn.name,PBMoves.getName(pkmn.moves[i].id)))
  1964.               elsif newpkmn.isEgg?
  1965.                 pbDisplay(_INTL("{1} can't be used on an Egg!",PBMoves.getName(pkmn.moves[i].id)))
  1966.               elsif newpkmn.hp==0 || newpkmn.hp==newpkmn.totalhp
  1967.                 pbDisplay(_INTL("{1} can't be used on that Pokémon.",PBMoves.getName(pkmn.moves[i].id)))
  1968.               else
  1969.                 pkmn.hp-=amt
  1970.                 hpgain=pbItemRestoreHP(newpkmn,amt)
  1971.                 @scene.pbDisplay(_INTL("{1}'s HP was restored by {2} points.",newpkmn.name,hpgain))
  1972.                 pbRefresh
  1973.               end
  1974.               break if pkmn.hp<=amt
  1975.             end
  1976.             break
  1977.           elsif Kernel.pbCanUseHiddenMove?(pkmn,pkmn.moves[i].id)
  1978.             @scene.pbEndScene
  1979.             if isConst?(pkmn.moves[i].id,PBMoves,:FLY)
  1980.               scene=PokemonRegionMapScene.new(-1,false)
  1981.               screen=PokemonRegionMap.new(scene)
  1982.               ret=screen.pbStartFlyScreen
  1983.               if ret
  1984.                 $PokemonTemp.flydata=ret
  1985.                 return [pkmn,pkmn.moves[i].id]
  1986.               end
  1987.               @scene.pbStartScene(@party,
  1988.                  @party.length>1 ? _INTL("Choose a Pokémon.") : _INTL("Choose Pokémon or cancel."))
  1989.               break
  1990.             end
  1991.             return [pkmn,pkmn.moves[i].id]
  1992.           else
  1993.             break
  1994.           end
  1995.         end
  1996.       end
  1997.       next if havecommand
  1998.       if cmdSummary>=0 && command==cmdSummary
  1999.         @scene.pbSummary(pkmnid)
  2000.       elsif cmdDebug>=0 && command==cmdDebug
  2001.         pbPokemonDebug(pkmn,pkmnid)
  2002.       elsif cmdSwitch>=0 && command==cmdSwitch
  2003.         @scene.pbSetHelpText(_INTL("Move to where?"))
  2004.         oldpkmnid=pkmnid
  2005.         pkmnid=@scene.pbChoosePokemon(true)
  2006.         if pkmnid>=0 && pkmnid!=oldpkmnid
  2007.           pbSwitch(oldpkmnid,pkmnid)
  2008.         end
  2009.       elsif cmdMail>=0 && command==cmdMail
  2010.         command=@scene.pbShowCommands(_INTL("Do what with the mail?"),
  2011.            [_INTL("Read"),_INTL("Take"),_INTL("Cancel")])
  2012.         case command
  2013.         when 0 # Read
  2014.           pbFadeOutIn(99999){
  2015.              pbDisplayMail(pkmn.mail,pkmn)
  2016.           }
  2017.         when 1 # Take
  2018.           pbTakeMail(pkmn)
  2019.           pbRefreshSingle(pkmnid)
  2020.         end
  2021.       elsif cmdItem>=0 && command==cmdItem
  2022.         itemcommands = []
  2023.         cmdUseItem   = -1
  2024.         cmdGiveItem  = -1
  2025.         cmdTakeItem  = -1
  2026.         cmdMoveItem  = -1
  2027.         # Build the commands
  2028.         itemcommands[cmdUseItem=itemcommands.length]  = _INTL("Use")
  2029.         itemcommands[cmdGiveItem=itemcommands.length] = _INTL("Give")
  2030.         itemcommands[cmdTakeItem=itemcommands.length] = _INTL("Take") if pkmn.hasItem?
  2031.         itemcommands[cmdMoveItem=itemcommands.length] = _INTL("Move") if pkmn.hasItem? && !pbIsMail?(pkmn.item)
  2032.         itemcommands[itemcommands.length]             = _INTL("Cancel")
  2033.         command=@scene.pbShowCommands(_INTL("Do what with an item?"),itemcommands)
  2034.         if cmdUseItem>=0 && command==cmdUseItem   # Use
  2035.           item=@scene.pbUseItem($PokemonBag,pkmn)
  2036.           if item>0
  2037.             pbUseItemOnPokemon(item,pkmn,self)
  2038.             pbRefreshSingle(pkmnid)
  2039.           end
  2040.         elsif cmdGiveItem>=0 && command==cmdGiveItem   # Give
  2041.           item=@scene.pbChooseItem($PokemonBag)
  2042.           if item>0
  2043.             pbGiveMail(item,pkmn,pkmnid)
  2044.             pbRefreshSingle(pkmnid)
  2045.           end
  2046.         elsif cmdTakeItem>=0 && command==cmdTakeItem   # Take
  2047.           pbTakeMail(pkmn)
  2048.           pbRefreshSingle(pkmnid)
  2049.         elsif cmdMoveItem>=0 && command==cmdMoveItem   # Move
  2050.           item=pkmn.item
  2051.           itemname=PBItems.getName(item)
  2052.           @scene.pbSetHelpText(_INTL("Give {1} to which Pokémon?",itemname))
  2053.           oldpkmnid=pkmnid
  2054.           loop do
  2055.             @scene.pbPreSelect(oldpkmnid)
  2056.             pkmnid=@scene.pbChoosePokemon(true,pkmnid)
  2057.             break if pkmnid<0
  2058.             newpkmn=@party[pkmnid]
  2059.             if pkmnid==oldpkmnid
  2060.               break
  2061.             elsif newpkmn.isEgg?
  2062.               pbDisplay(_INTL("Eggs can't hold items."))
  2063.             elsif !newpkmn.hasItem?
  2064.               newpkmn.setItem(item)
  2065.               pkmn.setItem(0)
  2066.               pbRefresh
  2067.               pbDisplay(_INTL("{1} was given the {2} to hold.",newpkmn.name,itemname))
  2068.               break
  2069.             elsif pbIsMail?(newpkmn.item)
  2070.               pbDisplay(_INTL("{1}'s mail must be removed before giving it an item.",newpkmn.name))
  2071.             else
  2072.               newitem=newpkmn.item
  2073.               newitemname=PBItems.getName(newitem)
  2074.               pbDisplay(_INTL("{1} is already holding one {2}.\1",newpkmn.name,newitemname))
  2075.               if pbConfirm(_INTL("Would you like to switch the two items?"))
  2076.                 newpkmn.setItem(item)
  2077.                 pkmn.setItem(newitem)
  2078.                 pbRefresh
  2079.                 pbDisplay(_INTL("{1} was given the {2} to hold.",newpkmn.name,itemname))
  2080.                 pbDisplay(_INTL("{1} was given the {2} to hold.",pkmn.name,newitemname))
  2081.                 break
  2082.               end
  2083.             end
  2084.           end
  2085.         end
  2086.       end
  2087.     end
  2088.     @scene.pbEndScene
  2089.     return nil
  2090.   end  
  2091. end
RAW Paste Data