Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. PluginManager.register({
  2.    :name => "FRLG Party Screen",
  3.    :version => "1.0",
  4.    :credits => "Seyuna, Golisopod User",
  5.    :link => "https://reliccastle.com/resources/411/"
  6. })
  7.  
  8. #===============================================================================
  9. # Pokémon party buttons and menu
  10. #===============================================================================
  11. class PokemonPartyConfirmCancelSprite < SpriteWrapper
  12.   attr_reader :selected
  13.  
  14.   def initialize(text,x,y,narrowbox=false,viewport=nil)
  15.     super(viewport)
  16.     @refreshBitmap = true
  17.     @bgsprite = ChangelingSprite.new(0,0,viewport)
  18.     if narrowbox
  19.       @bgsprite.addBitmap("desel","Graphics/Pictures/Party/icon_cancel_narrow")
  20.       @bgsprite.addBitmap("sel","Graphics/Pictures/Party/icon_cancel_narrow_sel")
  21.     else
  22.       @bgsprite.addBitmap("desel","Graphics/Pictures/Party/icon_cancel")
  23.       @bgsprite.addBitmap("sel","Graphics/Pictures/Party/icon_cancel_sel")
  24.     end
  25.     @bgsprite.changeBitmap("desel")
  26.     @overlaysprite = BitmapSprite.new(@bgsprite.bitmap.width,@bgsprite.bitmap.height,viewport)
  27.     @overlaysprite.z = self.z+1
  28.     pbSetSystemFont(@overlaysprite.bitmap)
  29.     @yoffset = 8
  30.     textpos = [[text,56,(narrowbox) ? 2 : 8,2,Color.new(248,248,248),Color.new(40,40,40)]]
  31.     pbDrawTextPositions(@overlaysprite.bitmap,textpos)
  32.     self.x = x
  33.     self.y = y
  34.   end
  35.  
  36.   def dispose
  37.     @bgsprite.dispose
  38.     @overlaysprite.bitmap.dispose
  39.     @overlaysprite.dispose
  40.     super
  41.   end
  42.  
  43.   def viewport=(value)
  44.     super
  45.     refresh
  46.   end
  47.  
  48.   def x=(value)
  49.     super
  50.     refresh
  51.   end
  52.  
  53.   def y=(value)
  54.     super
  55.     refresh
  56.   end
  57.  
  58.   def color=(value)
  59.     super
  60.     refresh
  61.   end
  62.  
  63.   def selected=(value)
  64.     if @selected!=value
  65.       @selected = value
  66.       refresh
  67.     end
  68.   end
  69.  
  70.   def refresh
  71.     if @bgsprite && !@bgsprite.disposed?
  72.       @bgsprite.changeBitmap((@selected) ? "sel" : "desel")
  73.       @bgsprite.x     = self.x
  74.       @bgsprite.y     = self.y
  75.       @bgsprite.color = self.color
  76.     end
  77.     if @overlaysprite && !@overlaysprite.disposed?
  78.       @overlaysprite.x     = self.x
  79.       @overlaysprite.y     = self.y
  80.       @overlaysprite.color = self.color
  81.     end
  82.   end
  83. end
  84.  
  85.  
  86.  
  87. class PokemonPartyCancelSprite < PokemonPartyConfirmCancelSprite
  88.   def initialize(viewport=nil)
  89.     super(_INTL(""),383,318,false,viewport)
  90.   end
  91. end
  92.  
  93.  
  94.  
  95. class PokemonPartyConfirmSprite < PokemonPartyConfirmCancelSprite
  96.   def initialize(viewport=nil)
  97.     super(_INTL(""),383,318,true,viewport)
  98.   end
  99. end
  100.  
  101.  
  102.  
  103. class PokemonPartyCancelSprite2 < PokemonPartyConfirmCancelSprite
  104.   def initialize(viewport=nil)
  105.     super(_INTL(""),383,318,true,viewport)
  106.   end
  107. end
  108.  
  109.  
  110.  
  111. class Window_CommandPokemonColor < Window_CommandPokemon
  112.   def initialize(commands,width=nil)
  113.     @colorKey = []
  114.     for i in 0...commands.length
  115.       if commands[i].is_a?(Array)
  116.         @colorKey[i] = commands[i][1]
  117.         commands[i] = commands[i][0]
  118.       end
  119.     end
  120.     super(commands,width)
  121.   end
  122.  
  123.   def drawItem(index,_count,rect)
  124.     pbSetSystemFont(self.contents) if @starting
  125.     rect = drawCursor(index,rect)
  126.     base   = self.baseColor
  127.     shadow = self.shadowColor
  128.     if @colorKey[index] && @colorKey[index]==1
  129.       base   = Color.new(0,80,160)
  130.       shadow = Color.new(128,192,240)
  131.     end
  132.     pbDrawShadowText(self.contents,rect.x,rect.y,rect.width,rect.height,@commands[index],base,shadow)
  133.   end
  134. end
  135.  
  136.  
  137.  
  138. #===============================================================================
  139. # Pokémon party panels
  140. #===============================================================================
  141. class PokemonPartyBlankPanel < SpriteWrapper
  142.   attr_accessor :text
  143.  
  144.   def initialize(_pokemon,index,viewport=nil)
  145.     super(viewport)
  146.     self.x = [0, Graphics.width/2][index%2]
  147.     self.y = [4,20,104,120,204,221][index]
  148.     @panelbgsprite = AnimatedBitmap.new("Graphics/Pictures/Party/panel_blank")
  149.     self.bitmap = @panelbgsprite.bitmap
  150.     @text = nil
  151.   end
  152.  
  153.   def dispose
  154.     @panelbgsprite.dispose
  155.     super
  156.   end
  157.  
  158.   def selected; return false; end
  159.   def selected=(value); end
  160.   def preselected; return false; end
  161.   def preselected=(value); end
  162.   def switching; return false; end
  163.   def switching=(value); end
  164.   def refresh; end
  165. end
  166.  
  167.  
  168.  
  169. class PokemonPartyPanel < SpriteWrapper
  170.   attr_reader :pokemon
  171.   attr_reader :active
  172.   attr_reader :selected
  173.   attr_reader :preselected
  174.   attr_reader :switching
  175.   attr_reader :text
  176.  
  177.   def initialize(pokemon,index,viewport=nil)
  178.     super(viewport)
  179.     @pokemon = pokemon
  180.     @active = (index==0)   # true = rounded panel, false = rectangular panel
  181.     @refreshing = true
  182.     self.x = [0, Graphics.width/2][index%2]
  183.     self.y = [4,20,104,120,204,221][index]
  184.     # self.y = [0,16,96,112,192,208][index]
  185.     @panelbgsprite = ChangelingSprite.new(0,0,viewport)
  186.     @panelbgsprite.z = self.z
  187.     if @active   # Rounded panel
  188.       @panelbgsprite.addBitmap("able","Graphics/Pictures/Party/panel_round")
  189.       @panelbgsprite.addBitmap("ablesel","Graphics/Pictures/Party/panel_round_sel")
  190.       @panelbgsprite.addBitmap("fainted","Graphics/Pictures/Party/panel_round_faint")
  191.       @panelbgsprite.addBitmap("faintedsel","Graphics/Pictures/Party/panel_round_faint_sel")
  192.       @panelbgsprite.addBitmap("swap","Graphics/Pictures/Party/panel_round_swap")
  193.       @panelbgsprite.addBitmap("swapsel","Graphics/Pictures/Party/panel_round_swap_sel")
  194.       @panelbgsprite.addBitmap("swapsel2","Graphics/Pictures/Party/panel_round_swap_sel2")
  195.     else   # Rectangular panel
  196.       @panelbgsprite.addBitmap("able","Graphics/Pictures/Party/panel_rect")
  197.       @panelbgsprite.addBitmap("ablesel","Graphics/Pictures/Party/panel_rect_sel")
  198.       @panelbgsprite.addBitmap("fainted","Graphics/Pictures/Party/panel_rect_faint")
  199.       @panelbgsprite.addBitmap("faintedsel","Graphics/Pictures/Party/panel_rect_faint_sel")
  200.       @panelbgsprite.addBitmap("swap","Graphics/Pictures/Party/panel_rect_swap")
  201.       @panelbgsprite.addBitmap("swapsel","Graphics/Pictures/Party/panel_rect_swap_sel")
  202.       @panelbgsprite.addBitmap("swapsel2","Graphics/Pictures/Party/panel_rect_swap_sel2")
  203.     end
  204.     @hpbgsprite = ChangelingSprite.new(0,0,viewport)
  205.     @hpbgsprite.z = self.z+1
  206.     @hpbgsprite.addBitmap("able","Graphics/Pictures/Party/overlay_hp_back")
  207.     @hpbgsprite.addBitmap("fainted","Graphics/Pictures/Party/overlay_hp_back_faint")
  208.     @hpbgsprite.addBitmap("swap","Graphics/Pictures/Party/overlay_hp_back_swap")
  209.     @ballsprite = ChangelingSprite.new(0,0,viewport)
  210.     @ballsprite.z = self.z+1
  211.     @ballsprite.addBitmap("desel","Graphics/Pictures/Party/icon_ball")
  212.     @ballsprite.addBitmap("sel","Graphics/Pictures/Party/icon_ball_sel")
  213.     @pkmnsprite = PokemonIconSprite.new(pokemon,viewport)
  214.     @pkmnsprite.setOffset(PictureOrigin::Center)
  215.     @pkmnsprite.active = @active
  216.     @pkmnsprite.z      = self.z+2
  217.     @helditemsprite = HeldItemIconSprite.new(0,0,@pokemon,viewport)
  218.     @helditemsprite.z = self.z+3
  219.     @overlaysprite = BitmapSprite.new(Graphics.width,Graphics.height,viewport)
  220.     @overlaysprite.z = self.z+4
  221.     @hpbar    = AnimatedBitmap.new("Graphics/Pictures/Party/overlay_hp")
  222.     @statuses = AnimatedBitmap.new(_INTL("Graphics/Pictures/statuses"))
  223.     @selected      = false
  224.     @preselected   = false
  225.     @switching     = false
  226.     @text          = nil
  227.     @refreshBitmap = true
  228.     @refreshing    = false
  229.     refresh
  230.   end
  231.  
  232.   def dispose
  233.     @panelbgsprite.dispose
  234.     @hpbgsprite.dispose
  235.     @ballsprite.dispose
  236.     @pkmnsprite.dispose
  237.     @helditemsprite.dispose
  238.     @overlaysprite.bitmap.dispose
  239.     @overlaysprite.dispose
  240.     @hpbar.dispose
  241.     @statuses.dispose
  242.     super
  243.   end
  244.  
  245.   def x=(value)
  246.     super
  247.     refresh
  248.   end
  249.  
  250.   def y=(value)
  251.     super
  252.     refresh
  253.   end
  254.  
  255.   def color=(value)
  256.     super
  257.     refresh
  258.   end
  259.  
  260.   def text=(value)
  261.     if @text!=value
  262.       @text = value
  263.       @refreshBitmap = true
  264.       refresh
  265.     end
  266.   end
  267.  
  268.   def pokemon=(value)
  269.     @pokemon = value
  270.     @pkmnsprite.pokemon = value if @pkmnsprite && !@pkmnsprite.disposed?
  271.     @helditemsprite.pokemon = value if @helditemsprite && !@helditemsprite.disposed?
  272.     @refreshBitmap = true
  273.     refresh
  274.   end
  275.  
  276.   def selected=(value)
  277.     if @selected!=value
  278.       @selected = value
  279.       refresh
  280.     end
  281.   end
  282.  
  283.   def preselected=(value)
  284.     if @preselected!=value
  285.       @preselected = value
  286.       refresh
  287.     end
  288.   end
  289.  
  290.   def switching=(value)
  291.     if @switching!=value
  292.       @switching = value
  293.       refresh
  294.     end
  295.   end
  296.  
  297.   def hp; return @pokemon.hp; end
  298.  
  299.   def refresh
  300.     return if disposed?
  301.     return if @refreshing
  302.     @refreshing = true
  303.     if @panelbgsprite && !@panelbgsprite.disposed?
  304.       if self.selected
  305.         if self.preselected;     @panelbgsprite.changeBitmap("swapsel2")
  306.         elsif @switching;        @panelbgsprite.changeBitmap("swapsel")
  307.         elsif @pokemon.fainted?; @panelbgsprite.changeBitmap("faintedsel")
  308.         else;                    @panelbgsprite.changeBitmap("ablesel")
  309.         end
  310.       else
  311.         if self.preselected;     @panelbgsprite.changeBitmap("swap")
  312.         elsif @pokemon.fainted?; @panelbgsprite.changeBitmap("fainted")
  313.         else;                    @panelbgsprite.changeBitmap("able")
  314.         end
  315.       end
  316.       @panelbgsprite.x     = self.x
  317.       @panelbgsprite.y     = self.y
  318.       @panelbgsprite.color = self.color
  319.     end
  320.     if @hpbgsprite && !@hpbgsprite.disposed?
  321.       @hpbgsprite.visible = (!@pokemon.egg? && !(@text && @text.length>0))
  322.       if @hpbgsprite.visible
  323.         if self.preselected || (self.selected && @switching); @hpbgsprite.changeBitmap("swap")
  324.         elsif @pokemon.fainted?;                              @hpbgsprite.changeBitmap("fainted")
  325.         else;                                                 @hpbgsprite.changeBitmap("able")
  326.         end
  327.         @hpbgsprite.x     = self.x+96
  328.         @hpbgsprite.y     = self.y+50
  329.         @hpbgsprite.color = self.color
  330.       end
  331.     end
  332.     if @ballsprite && !@ballsprite.disposed?
  333.       @ballsprite.changeBitmap((self.selected) ? "sel" : "desel")
  334.       @ballsprite.x     = self.x+13
  335.       @ballsprite.y     = self.y+3
  336.       @ballsprite.color = self.color
  337.     end
  338.     if @pkmnsprite && !@pkmnsprite.disposed?
  339.       @pkmnsprite.x        = self.x+57
  340.       @pkmnsprite.y        = self.y+37
  341.       @pkmnsprite.color    = self.color
  342.       @pkmnsprite.selected = self.selected
  343.     end
  344.     if @helditemsprite && !@helditemsprite.disposed?
  345.       if @helditemsprite.visible
  346.         @helditemsprite.x     = self.x+62
  347.         @helditemsprite.y     = self.y+48
  348.         @helditemsprite.color = self.color
  349.       end
  350.     end
  351.     if @overlaysprite && !@overlaysprite.disposed?
  352.       @overlaysprite.x     = self.x
  353.       @overlaysprite.y     = self.y
  354.       @overlaysprite.color = self.color
  355.     end
  356.     if @refreshBitmap
  357.       @refreshBitmap = false
  358.       @overlaysprite.bitmap.clear if @overlaysprite.bitmap
  359.       basecolor   = Color.new(248,248,248)
  360.       shadowcolor = Color.new(106,106,106)
  361.       pbSetSystemFont(@overlaysprite.bitmap)
  362.       textpos = []
  363.       # Draw Pokémon name
  364.       textpos.push([@pokemon.name,96,16,0,basecolor,shadowcolor])
  365.       if !@pokemon.egg?
  366.         if !@text || @text.length==0
  367.           # Draw HP numbers
  368.           textpos.push([sprintf("% 3d /% 3d",@pokemon.hp,@pokemon.totalhp),224,61,1,basecolor,shadowcolor])
  369.           # Draw HP bar
  370.           if @pokemon.hp>0
  371.             w = @pokemon.hp*96*1.0/@pokemon.totalhp
  372.             w = 1 if w<1
  373.             w = ((w/2).round)*2
  374.             hpzone = 0
  375.             hpzone = 1 if @pokemon.hp<=(@pokemon.totalhp/2).floor
  376.             hpzone = 2 if @pokemon.hp<=(@pokemon.totalhp/4).floor
  377.             hprect = Rect.new(0,hpzone*8,w,8)
  378.             @overlaysprite.bitmap.blt(126,53,@hpbar.bitmap,hprect)
  379.           end
  380.           # Draw status
  381.           status = -1
  382.           status = 6 if @pokemon.pokerusStage==1
  383.           status = @pokemon.status-1 if @pokemon.status>0
  384.           status = 5 if @pokemon.hp<=0
  385.           if status>=0
  386.             statusrect = Rect.new(0,16*status,44,16)
  387.             @overlaysprite.bitmap.blt(78,68,@statuses.bitmap,statusrect)
  388.           end
  389.         end
  390.         # Draw gender symbol
  391.         if @pokemon.male?
  392.           textpos.push([_INTL("♂"),224,16,0,Color.new(176,208,144),Color.new(96,176,72)])
  393.         elsif @pokemon.female?
  394.           textpos.push([_INTL("♀"),224,16,0,Color.new(248,168,184),Color.new(232,32,16)])
  395.         end
  396.         # Draw shiny icon
  397.         if @pokemon.shiny?
  398.           pbDrawImagePositions(@overlaysprite.bitmap,[[
  399.              "Graphics/Pictures/shiny",80,48,0,0,16,16]])
  400.         end
  401.       end
  402.       pbDrawTextPositions(@overlaysprite.bitmap,textpos)
  403.       # Draw level text
  404.       if !@pokemon.egg?
  405.         pbDrawImagePositions(@overlaysprite.bitmap,[[
  406.            "Graphics/Pictures/Party/overlay_lv",20,70,0,0,22,14]])
  407.         pbSetSmallFont(@overlaysprite.bitmap)
  408.         pbDrawTextPositions(@overlaysprite.bitmap,[
  409.            [@pokemon.level.to_s,45,63,0,basecolor,shadowcolor]
  410.         ])
  411.       end
  412.       # Draw annotation text
  413.       if @text && @text.length>0
  414.         pbSetSystemFont(@overlaysprite.bitmap)
  415.         pbDrawTextPositions(@overlaysprite.bitmap,[
  416.            [@text,96,58,0,basecolor,shadowcolor]
  417.         ])
  418.       end
  419.     end
  420.     @refreshing = false
  421.   end
  422.  
  423.   def update
  424.     super
  425.     @panelbgsprite.update if @panelbgsprite && !@panelbgsprite.disposed?
  426.     @hpbgsprite.update if @hpbgsprite && !@hpbgsprite.disposed?
  427.     @ballsprite.update if @ballsprite && !@ballsprite.disposed?
  428.     @pkmnsprite.update if @pkmnsprite && !@pkmnsprite.disposed?
  429.     @helditemsprite.update if @helditemsprite && !@helditemsprite.disposed?
  430.   end
  431. end
  432.  
  433.  
  434.  
  435. #===============================================================================
  436. # Pokémon party visuals
  437. #===============================================================================
  438. class PokemonParty_Scene
  439.   def pbStartScene(party,starthelptext,annotations=nil,multiselect=false)
  440.     @sprites = {}
  441.     @party = party
  442.     @viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  443.     @viewport.z = 99999
  444.     @multiselect = multiselect
  445.     addBackgroundPlane(@sprites,"partybg","Party/bg",@viewport)
  446.     @sprites["messagebox"] = Window_AdvancedTextPokemon.new("")
  447.     @sprites["messagebox"].viewport       = @viewport
  448.     @sprites["messagebox"].visible        = false
  449.     @sprites["messagebox"].letterbyletter = true
  450.     pbBottomLeftLines(@sprites["messagebox"],2)
  451.     @sprites["helpwindow"] = Window_UnformattedTextPokemon.new(starthelptext)
  452.     @sprites["helpwindow"].viewport = @viewport
  453.     @sprites["helpwindow"].visible  = true
  454.     pbBottomLeftLines(@sprites["helpwindow"],1)
  455.     pbSetHelpText(starthelptext)
  456.     # Add party Pokémon sprites
  457.     for i in 0...6
  458.       if @party[i]
  459.         @sprites["pokemon#{i}"] = PokemonPartyPanel.new(@party[i],i,@viewport)
  460.       else
  461.         @sprites["pokemon#{i}"] = PokemonPartyBlankPanel.new(@party[i],i,@viewport)
  462.       end
  463.       @sprites["pokemon#{i}"].text = annotations[i] if annotations
  464.     end
  465.     if @multiselect
  466.       @sprites["pokemon6"] = PokemonPartyConfirmSprite.new(@viewport)
  467.       @sprites["pokemon7"] = PokemonPartyCancelSprite2.new(@viewport)
  468.     else
  469.       @sprites["pokemon6"] = PokemonPartyCancelSprite.new(@viewport)
  470.     end
  471.     # Select first Pokémon
  472.     @activecmd = 0
  473.     @sprites["pokemon0"].selected = true
  474.     pbFadeInAndShow(@sprites) { update }
  475.   end
  476.  
  477.   def pbEndScene
  478.     pbFadeOutAndHide(@sprites) { update }
  479.     pbDisposeSpriteHash(@sprites)
  480.     @viewport.dispose
  481.   end
  482.  
  483.   def pbDisplay(text)
  484.     @sprites["messagebox"].text    = text
  485.     @sprites["messagebox"].visible = true
  486.     @sprites["helpwindow"].visible = false
  487.     pbPlayDecisionSE
  488.     loop do
  489.       Graphics.update
  490.       Input.update
  491.       self.update
  492.       if @sprites["messagebox"].busy?
  493.         if Input.trigger?(Input::C)
  494.           pbPlayDecisionSE if @sprites["messagebox"].pausing?
  495.           @sprites["messagebox"].resume
  496.         end
  497.       else
  498.         if Input.trigger?(Input::B) || Input.trigger?(Input::C)
  499.           break
  500.         end
  501.       end
  502.     end
  503.     @sprites["messagebox"].visible = false
  504.     @sprites["helpwindow"].visible = true
  505.   end
  506.  
  507.   def pbDisplayConfirm(text)
  508.     ret = -1
  509.     @sprites["messagebox"].text    = text
  510.     @sprites["messagebox"].visible = true
  511.     @sprites["helpwindow"].visible = false
  512.     using(cmdwindow = Window_CommandPokemon.new([_INTL("Yes"),_INTL("No")])) {
  513.       cmdwindow.visible = false
  514.       pbBottomRight(cmdwindow)
  515.       cmdwindow.y -= @sprites["messagebox"].height
  516.       cmdwindow.z = @viewport.z+1
  517.       loop do
  518.         Graphics.update
  519.         Input.update
  520.         cmdwindow.visible = true if !@sprites["messagebox"].busy?
  521.         cmdwindow.update
  522.         self.update
  523.         if !@sprites["messagebox"].busy?
  524.           if Input.trigger?(Input::B)
  525.             ret = false
  526.             break
  527.           elsif Input.trigger?(Input::C) && @sprites["messagebox"].resume
  528.             ret = (cmdwindow.index==0)
  529.             break
  530.           end
  531.         end
  532.       end
  533.     }
  534.     @sprites["messagebox"].visible = false
  535.     @sprites["helpwindow"].visible = true
  536.     return ret
  537.   end
  538.  
  539.   def pbShowCommands(helptext,commands,index=0)
  540.     ret = -1
  541.     helpwindow = @sprites["helpwindow"]
  542.     helpwindow.visible = true
  543.     using(cmdwindow = Window_CommandPokemonColor.new(commands)) {
  544.       cmdwindow.z     = @viewport.z+1
  545.       cmdwindow.index = index
  546.       pbBottomRight(cmdwindow)
  547.       helpwindow.resizeHeightToFit(helptext,Graphics.width-cmdwindow.width)
  548.       helpwindow.text = helptext
  549.       pbBottomLeft(helpwindow)
  550.       loop do
  551.         Graphics.update
  552.         Input.update
  553.         cmdwindow.update
  554.         self.update
  555.         if Input.trigger?(Input::B)
  556.           pbPlayCancelSE
  557.           ret = -1
  558.           break
  559.         elsif Input.trigger?(Input::C)
  560.           pbPlayDecisionSE
  561.           ret = cmdwindow.index
  562.           break
  563.         end
  564.       end
  565.     }
  566.     return ret
  567.   end
  568.  
  569.   def pbSetHelpText(helptext)
  570.     helpwindow = @sprites["helpwindow"]
  571.     pbBottomLeftLines(helpwindow,1)
  572.     helpwindow.text = helptext
  573.     helpwindow.width = 398
  574.     helpwindow.visible = true
  575.   end
  576.  
  577.   def pbHasAnnotations?
  578.     return @sprites["pokemon0"].text!=nil
  579.   end
  580.  
  581.   def pbAnnotate(annot)
  582.     for i in 0...6
  583.       @sprites["pokemon#{i}"].text = (annot) ? annot[i] : nil
  584.     end
  585.   end
  586.  
  587.   def pbSelect(item)
  588.     @activecmd = item
  589.     numsprites = (@multiselect) ? 8 : 7
  590.     for i in 0...numsprites
  591.       @sprites["pokemon#{i}"].selected = (i==@activecmd)
  592.     end
  593.   end
  594.  
  595.   def pbPreSelect(item)
  596.     @activecmd = item
  597.   end
  598.  
  599.   def pbSwitchBegin(oldid,newid)
  600.     pbSEPlay("GUI party switch")
  601.     oldsprite = @sprites["pokemon#{oldid}"]
  602.     newsprite = @sprites["pokemon#{newid}"]
  603.     timeTaken = Graphics.frame_rate*4/10
  604.     distancePerFrame = (Graphics.width/(2.0*timeTaken)).ceil
  605.     timeTaken.times do
  606.       oldsprite.x += (oldid&1)==0 ? -distancePerFrame : distancePerFrame
  607.       newsprite.x += (newid&1)==0 ? -distancePerFrame : distancePerFrame
  608.       Graphics.update
  609.       Input.update
  610.       self.update
  611.     end
  612.   end
  613.  
  614.   def pbSwitchEnd(oldid,newid)
  615.     pbSEPlay("GUI party switch")
  616.     oldsprite = @sprites["pokemon#{oldid}"]
  617.     newsprite = @sprites["pokemon#{newid}"]
  618.     oldsprite.pokemon = @party[oldid]
  619.     newsprite.pokemon = @party[newid]
  620.     timeTaken = Graphics.frame_rate*4/10
  621.     distancePerFrame = (Graphics.width/(2.0*timeTaken)).ceil
  622.     timeTaken.times do
  623.       oldsprite.x -= (oldid&1)==0 ? -distancePerFrame : distancePerFrame
  624.       newsprite.x -= (newid&1)==0 ? -distancePerFrame : distancePerFrame
  625.       Graphics.update
  626.       Input.update
  627.       self.update
  628.     end
  629.     for i in 0...6
  630.       @sprites["pokemon#{i}"].preselected = false
  631.       @sprites["pokemon#{i}"].switching   = false
  632.     end
  633.     pbRefresh
  634.   end
  635.  
  636.   def pbClearSwitching
  637.     for i in 0...6
  638.       @sprites["pokemon#{i}"].preselected = false
  639.       @sprites["pokemon#{i}"].switching   = false
  640.     end
  641.   end
  642.  
  643.   def pbSummary(pkmnid,inbattle=false)
  644.     oldsprites = pbFadeOutAndHide(@sprites)
  645.     scene = PokemonSummary_Scene.new
  646.     screen = PokemonSummaryScreen.new(scene,inbattle)
  647.     screen.pbStartScreen(@party,pkmnid)
  648.     yield if block_given?
  649.     pbFadeInAndShow(@sprites,oldsprites)
  650.   end
  651.  
  652.   def pbChooseItem(bag)
  653.     ret = 0
  654.     pbFadeOutIn {
  655.       scene = PokemonBag_Scene.new
  656.       screen = PokemonBagScreen.new(scene,bag)
  657.       ret = screen.pbChooseItemScreen(Proc.new { |item| pbCanHoldItem?(item) })
  658.       yield if block_given?
  659.     }
  660.     return ret
  661.   end
  662.  
  663.   def pbUseItem(bag,pokemon)
  664.     ret = 0
  665.     pbFadeOutIn {
  666.       scene = PokemonBag_Scene.new
  667.       screen = PokemonBagScreen.new(scene,bag)
  668.       ret = screen.pbChooseItemScreen(Proc.new { |item|
  669.         next false if !pbCanUseOnPokemon?(item)
  670.         if pbIsMachine?(item)
  671.           move = pbGetMachine(item)
  672.           next false if pokemon.hasMove?(move) || !pokemon.compatibleWithMove?(move)
  673.         end
  674.         next true
  675.       })
  676.       yield if block_given?
  677.     }
  678.     return ret
  679.   end
  680.  
  681.   def pbChoosePokemon(switching=false,initialsel=-1,canswitch=0)
  682.     for i in 0...6
  683.       @sprites["pokemon#{i}"].preselected = (switching && i==@activecmd)
  684.       @sprites["pokemon#{i}"].switching   = switching
  685.     end
  686.     @activecmd = initialsel if initialsel>=0
  687.     pbRefresh
  688.     loop do
  689.       Graphics.update
  690.       Input.update
  691.       self.update
  692.       oldsel = @activecmd
  693.       key = -1
  694.       key = Input::DOWN if Input.repeat?(Input::DOWN)
  695.       key = Input::RIGHT if Input.repeat?(Input::RIGHT)
  696.       key = Input::LEFT if Input.repeat?(Input::LEFT)
  697.       key = Input::UP if Input.repeat?(Input::UP)
  698.       if key>=0
  699.         @activecmd = pbChangeSelection(key,@activecmd)
  700.       end
  701.       if @activecmd!=oldsel   # Changing selection
  702.         pbPlayCursorSE
  703.         numsprites = (@multiselect) ? 8 : 7
  704.         for i in 0...numsprites
  705.           @sprites["pokemon#{i}"].selected = (i==@activecmd)
  706.         end
  707.       end
  708.       cancelsprite = (@multiselect) ? 7 : 6
  709.       if Input.trigger?(Input::A) && canswitch==1 && @activecmd!=cancelsprite
  710.         pbPlayDecisionSE
  711.         return [1,@activecmd]
  712.       elsif Input.trigger?(Input::A) && canswitch==2
  713.         return -1
  714.       elsif Input.trigger?(Input::B)
  715.         pbPlayCloseMenuSE if !switching
  716.         return -1
  717.       elsif Input.trigger?(Input::C)
  718.         if @activecmd==cancelsprite
  719.           (switching) ? pbPlayDecisionSE : pbPlayCloseMenuSE
  720.           return -1
  721.         else
  722.           pbPlayDecisionSE
  723.           return @activecmd
  724.         end
  725.       end
  726.     end
  727.   end
  728.  
  729.   def pbChangeSelection(key,currentsel)
  730.     numsprites = (@multiselect) ? 8 : 7
  731.     case key
  732.     when Input::LEFT
  733.       begin
  734.         currentsel -= 1
  735.       end while currentsel>0 && currentsel<@party.length && !@party[currentsel]
  736.       if currentsel>=@party.length && currentsel<6
  737.         currentsel = @party.length-1
  738.       end
  739.       currentsel = numsprites-1 if currentsel<0
  740.     when Input::RIGHT
  741.       begin
  742.         currentsel += 1
  743.       end while currentsel<@party.length && !@party[currentsel]
  744.       if currentsel==@party.length
  745.         currentsel = 6
  746.       elsif currentsel==numsprites
  747.         currentsel = 0
  748.       end
  749.     when Input::UP
  750.       if currentsel>=6
  751.         begin
  752.           currentsel -= 1
  753.         end while currentsel>0 && !@party[currentsel]
  754.       else
  755.         begin
  756.           currentsel -= 2
  757.         end while currentsel>0 && !@party[currentsel]
  758.       end
  759.       if currentsel>=@party.length && currentsel<6
  760.         currentsel = @party.length-1
  761.       end
  762.       currentsel = numsprites-1 if currentsel<0
  763.     when Input::DOWN
  764.       if currentsel>=5
  765.         currentsel += 1
  766.       else
  767.         currentsel += 2
  768.         currentsel = 6 if currentsel<6 && !@party[currentsel]
  769.       end
  770.       if currentsel>=@party.length && currentsel<6
  771.         currentsel = 6
  772.       elsif currentsel>=numsprites
  773.         currentsel = 0
  774.       end
  775.     end
  776.     return currentsel
  777.   end
  778.  
  779.   def pbHardRefresh
  780.     oldtext = []
  781.     lastselected = -1
  782.     for i in 0...6
  783.       oldtext.push(@sprites["pokemon#{i}"].text)
  784.       lastselected = i if @sprites["pokemon#{i}"].selected
  785.       @sprites["pokemon#{i}"].dispose
  786.     end
  787.     lastselected = @party.length-1 if lastselected>=@party.length
  788.     lastselected = 0 if lastselected<0
  789.     for i in 0...6
  790.       if @party[i]
  791.         @sprites["pokemon#{i}"] = PokemonPartyPanel.new(@party[i],i,@viewport)
  792.       else
  793.         @sprites["pokemon#{i}"] = PokemonPartyBlankPanel.new(@party[i],i,@viewport)
  794.       end
  795.       @sprites["pokemon#{i}"].text = oldtext[i]
  796.     end
  797.     pbSelect(lastselected)
  798.   end
  799.  
  800.   def pbRefresh
  801.     for i in 0...6
  802.       sprite = @sprites["pokemon#{i}"]
  803.       if sprite
  804.         if sprite.is_a?(PokemonPartyPanel)
  805.           sprite.pokemon = sprite.pokemon
  806.         else
  807.           sprite.refresh
  808.         end
  809.       end
  810.     end
  811.   end
  812.  
  813.   def pbRefreshSingle(i)
  814.     sprite = @sprites["pokemon#{i}"]
  815.     if sprite
  816.       if sprite.is_a?(PokemonPartyPanel)
  817.         sprite.pokemon = sprite.pokemon
  818.       else
  819.         sprite.refresh
  820.       end
  821.     end
  822.   end
  823.  
  824.   def update
  825.     pbUpdateSpriteHash(@sprites)
  826.   end
  827. end
  828.  
  829.  
  830.  
  831. #===============================================================================
  832. # Pokémon party mechanics
  833. #===============================================================================
  834. class PokemonPartyScreen
  835.   attr_reader :scene
  836.   attr_reader :party
  837.  
  838.   def initialize(scene,party)
  839.     @scene = scene
  840.     @party = party
  841.   end
  842.  
  843.   def pbStartScene(helptext,_numBattlersOut,annotations=nil)
  844.     @scene.pbStartScene(@party,helptext,annotations)
  845.   end
  846.  
  847.   def pbChoosePokemon(helptext=nil)
  848.     @scene.pbSetHelpText(helptext) if helptext
  849.     return @scene.pbChoosePokemon
  850.   end
  851.  
  852.   def pbPokemonGiveScreen(item)
  853.     @scene.pbStartScene(@party,_INTL("Give to which Pokémon?"))
  854.     pkmnid = @scene.pbChoosePokemon
  855.     ret = false
  856.     if pkmnid>=0
  857.       ret = pbGiveItemToPokemon(item,@party[pkmnid],self,pkmnid)
  858.     end
  859.     pbRefreshSingle(pkmnid)
  860.     @scene.pbEndScene
  861.     return ret
  862.   end
  863.  
  864.   def pbPokemonGiveMailScreen(mailIndex)
  865.     @scene.pbStartScene(@party,_INTL("Give to which Pokémon?"))
  866.     pkmnid = @scene.pbChoosePokemon
  867.     if pkmnid>=0
  868.       pkmn = @party[pkmnid]
  869.       if pkmn.hasItem? || pkmn.mail
  870.         pbDisplay(_INTL("This Pokémon is holding an item. It can't hold mail."))
  871.       elsif pkmn.egg?
  872.         pbDisplay(_INTL("Eggs can't hold mail."))
  873.       else
  874.         pbDisplay(_INTL("Mail was transferred from the Mailbox."))
  875.         pkmn.mail = $PokemonGlobal.mailbox[mailIndex]
  876.         pkmn.setItem(pkmn.mail.item)
  877.         $PokemonGlobal.mailbox.delete_at(mailIndex)
  878.         pbRefreshSingle(pkmnid)
  879.       end
  880.     end
  881.     @scene.pbEndScene
  882.   end
  883.  
  884.   def pbEndScene
  885.     @scene.pbEndScene
  886.   end
  887.  
  888.   def pbUpdate
  889.     @scene.update
  890.   end
  891.  
  892.   def pbHardRefresh
  893.     @scene.pbHardRefresh
  894.   end
  895.  
  896.   def pbRefresh
  897.     @scene.pbRefresh
  898.   end
  899.  
  900.   def pbRefreshSingle(i)
  901.     @scene.pbRefreshSingle(i)
  902.   end
  903.  
  904.   def pbDisplay(text)
  905.     @scene.pbDisplay(text)
  906.   end
  907.  
  908.   def pbConfirm(text)
  909.     return @scene.pbDisplayConfirm(text)
  910.   end
  911.  
  912.   def pbShowCommands(helptext,commands,index=0)
  913.     return @scene.pbShowCommands(helptext,commands,index)
  914.   end
  915.  
  916.   # Checks for identical species
  917.   def pbCheckSpecies(array)   # Unused
  918.     for i in 0...array.length
  919.       for j in i+1...array.length
  920.         return false if array[i].species==array[j].species
  921.       end
  922.     end
  923.     return true
  924.   end
  925.  
  926.   # Checks for identical held items
  927.   def pbCheckItems(array)   # Unused
  928.     for i in 0...array.length
  929.       next if !array[i].hasItem?
  930.       for j in i+1...array.length
  931.         return false if array[i].item==array[j].item
  932.       end
  933.     end
  934.     return true
  935.   end
  936.  
  937.   def pbSwitch(oldid,newid)
  938.     if oldid!=newid
  939.       @scene.pbSwitchBegin(oldid,newid)
  940.       tmp = @party[oldid]
  941.       @party[oldid] = @party[newid]
  942.       @party[newid] = tmp
  943.       @scene.pbSwitchEnd(oldid,newid)
  944.     end
  945.   end
  946.  
  947.   def pbChooseMove(pokemon,helptext,index=0)
  948.     movenames = []
  949.     for i in pokemon.moves
  950.       break if i.id==0
  951.       if i.totalpp<=0
  952.         movenames.push(_INTL("{1} (PP: ---)",PBMoves.getName(i.id)))
  953.       else
  954.         movenames.push(_INTL("{1} (PP: {2}/{3})",PBMoves.getName(i.id),i.pp,i.totalpp))
  955.       end
  956.     end
  957.     return @scene.pbShowCommands(helptext,movenames,index)
  958.   end
  959.  
  960.   def pbRefreshAnnotations(ableProc)   # For after using an evolution stone
  961.     return if !@scene.pbHasAnnotations?
  962.     annot = []
  963.     for pkmn in @party
  964.       elig = ableProc.call(pkmn)
  965.       annot.push((elig) ? _INTL("ABLE") : _INTL("NOT ABLE"))
  966.     end
  967.     @scene.pbAnnotate(annot)
  968.   end
  969.  
  970.   def pbClearAnnotations
  971.     @scene.pbAnnotate(nil)
  972.   end
  973.  
  974.   def pbPokemonMultipleEntryScreenEx(ruleset)
  975.     annot = []
  976.     statuses = []
  977.     ordinals = [
  978.        _INTL("INELIGIBLE"),
  979.        _INTL("NOT ENTERED"),
  980.        _INTL("BANNED"),
  981.        _INTL("FIRST"),
  982.        _INTL("SECOND"),
  983.        _INTL("THIRD"),
  984.        _INTL("FOURTH"),
  985.        _INTL("FIFTH"),
  986.        _INTL("SIXTH")
  987.     ]
  988.     return nil if !ruleset.hasValidTeam?(@party)
  989.     ret = nil
  990.     addedEntry = false
  991.     for i in 0...@party.length
  992.       statuses[i] = (ruleset.isPokemonValid?(@party[i])) ? 1 : 2
  993.     end
  994.     for i in 0...@party.length
  995.       annot[i] = ordinals[statuses[i]]
  996.     end
  997.     @scene.pbStartScene(@party,_INTL("Choose Pokémon and confirm."),annot,true)
  998.     loop do
  999.       realorder = []
  1000.       for i in 0...@party.length
  1001.         for j in 0...@party.length
  1002.           if statuses[j]==i+3
  1003.             realorder.push(j)
  1004.             break
  1005.           end
  1006.         end
  1007.       end
  1008.       for i in 0...realorder.length
  1009.         statuses[realorder[i]] = i+3
  1010.       end
  1011.       for i in 0...@party.length
  1012.         annot[i] = ordinals[statuses[i]]
  1013.       end
  1014.       @scene.pbAnnotate(annot)
  1015.       if realorder.length==ruleset.number && addedEntry
  1016.         @scene.pbSelect(6)
  1017.       end
  1018.       @scene.pbSetHelpText(_INTL("Choose Pokémon and confirm."))
  1019.       pkmnid = @scene.pbChoosePokemon
  1020.       addedEntry = false
  1021.       if pkmnid==6   # Confirm was chosen
  1022.         ret = []
  1023.         for i in realorder; ret.push(@party[i]); end
  1024.         error = []
  1025.         break if ruleset.isValid?(ret,error)
  1026.         pbDisplay(error[0])
  1027.         ret = nil
  1028.       end
  1029.       break if pkmnid<0   # Cancelled
  1030.       cmdEntry   = -1
  1031.       cmdNoEntry = -1
  1032.       cmdSummary = -1
  1033.       commands = []
  1034.       if (statuses[pkmnid] || 0) == 1
  1035.         commands[cmdEntry = commands.length]   = _INTL("Entry")
  1036.       elsif (statuses[pkmnid] || 0) > 2
  1037.         commands[cmdNoEntry = commands.length] = _INTL("No Entry")
  1038.       end
  1039.       pkmn = @party[pkmnid]
  1040.       commands[cmdSummary = commands.length]   = _INTL("Summary")
  1041.       commands[commands.length]                = _INTL("Cancel")
  1042.       command = @scene.pbShowCommands(_INTL("Do what with {1}?",pkmn.name),commands) if pkmn
  1043.       if cmdEntry>=0 && command==cmdEntry
  1044.         if realorder.length>=ruleset.number && ruleset.number>0
  1045.           pbDisplay(_INTL("No more than {1} Pokémon may enter.",ruleset.number))
  1046.         else
  1047.           statuses[pkmnid] = realorder.length+3
  1048.           addedEntry = true
  1049.           pbRefreshSingle(pkmnid)
  1050.         end
  1051.       elsif cmdNoEntry>=0 && command==cmdNoEntry
  1052.         statuses[pkmnid] = 1
  1053.         pbRefreshSingle(pkmnid)
  1054.       elsif cmdSummary>=0 && command==cmdSummary
  1055.         @scene.pbSummary(pkmnid) {
  1056.           @scene.pbSetHelpText((@party.length>1) ? _INTL("Choose a Pokémon.") : _INTL("Choose Pokémon or cancel."))
  1057.         }
  1058.       end
  1059.     end
  1060.     @scene.pbEndScene
  1061.     return ret
  1062.   end
  1063.  
  1064.   def pbChooseAblePokemon(ableProc,allowIneligible=false)
  1065.     annot = []
  1066.     eligibility = []
  1067.     for pkmn in @party
  1068.       elig = ableProc.call(pkmn)
  1069.       eligibility.push(elig)
  1070.       annot.push((elig) ? _INTL("ABLE") : _INTL("NOT ABLE"))
  1071.     end
  1072.     ret = -1
  1073.     @scene.pbStartScene(@party,
  1074.        (@party.length>1) ? _INTL("Choose a Pokémon.") : _INTL("Choose Pokémon or cancel."),annot)
  1075.     loop do
  1076.       @scene.pbSetHelpText(
  1077.          (@party.length>1) ? _INTL("Choose a Pokémon.") : _INTL("Choose Pokémon or cancel."))
  1078.       pkmnid = @scene.pbChoosePokemon
  1079.       break if pkmnid<0
  1080.       if !eligibility[pkmnid] && !allowIneligible
  1081.         pbDisplay(_INTL("This Pokémon can't be chosen."))
  1082.       else
  1083.         ret = pkmnid
  1084.         break
  1085.       end
  1086.     end
  1087.     @scene.pbEndScene
  1088.     return ret
  1089.   end
  1090.  
  1091.   def pbChooseTradablePokemon(ableProc,allowIneligible=false)
  1092.     annot = []
  1093.     eligibility = []
  1094.     for pkmn in @party
  1095.       elig = ableProc.call(pkmn)
  1096.       elig = false if pkmn.egg? || pkmn.shadowPokemon?
  1097.       eligibility.push(elig)
  1098.       annot.push((elig) ? _INTL("ABLE") : _INTL("NOT ABLE"))
  1099.     end
  1100.     ret = -1
  1101.     @scene.pbStartScene(@party,
  1102.        (@party.length>1) ? _INTL("Choose a Pokémon.") : _INTL("Choose Pokémon or cancel."),annot)
  1103.     loop do
  1104.       @scene.pbSetHelpText(
  1105.          (@party.length>1) ? _INTL("Choose a Pokémon.") : _INTL("Choose Pokémon or cancel."))
  1106.       pkmnid = @scene.pbChoosePokemon
  1107.       break if pkmnid<0
  1108.       if !eligibility[pkmnid] && !allowIneligible
  1109.         pbDisplay(_INTL("This Pokémon can't be chosen."))
  1110.       else
  1111.         ret = pkmnid
  1112.         break
  1113.       end
  1114.     end
  1115.     @scene.pbEndScene
  1116.     return ret
  1117.   end
  1118.  
  1119.   def pbPokemonScreen
  1120.     @scene.pbStartScene(@party,
  1121.        (@party.length>1) ? _INTL("Choose a Pokémon.") : _INTL("Choose Pokémon or cancel."),nil)
  1122.     loop do
  1123.       @scene.pbSetHelpText((@party.length>1) ? _INTL("Choose a Pokémon.") : _INTL("Choose Pokémon or cancel."))
  1124.       pkmnid = @scene.pbChoosePokemon(false,-1,1)
  1125.       break if (pkmnid.is_a?(Numeric) && pkmnid<0) || (pkmnid.is_a?(Array) && pkmnid[1]<0)
  1126.       if pkmnid.is_a?(Array) && pkmnid[0]==1   # Switch
  1127.         @scene.pbSetHelpText(_INTL("Move to where?"))
  1128.         oldpkmnid = pkmnid[1]
  1129.         pkmnid = @scene.pbChoosePokemon(true,-1,2)
  1130.         if pkmnid>=0 && pkmnid!=oldpkmnid
  1131.           pbSwitch(oldpkmnid,pkmnid)
  1132.         end
  1133.         next
  1134.       end
  1135.       pkmn = @party[pkmnid]
  1136.       commands   = []
  1137.       cmdSummary = -1
  1138.       cmdDebug   = -1
  1139.       cmdMoves   = [-1,-1,-1,-1]
  1140.       cmdSwitch  = -1
  1141.       cmdMail    = -1
  1142.       cmdItem    = -1
  1143.       # Build the commands
  1144.       commands[cmdSummary = commands.length]      = _INTL("Summary")
  1145.       commands[cmdDebug = commands.length]        = _INTL("Debug") if $DEBUG
  1146.       for i in 0...pkmn.moves.length
  1147.         move = pkmn.moves[i]
  1148.         # Check for hidden moves and add any that were found
  1149.         if !pkmn.egg? && (isConst?(move.id,PBMoves,:MILKDRINK) ||
  1150.                           isConst?(move.id,PBMoves,:SOFTBOILED))# ||
  1151. #                          HiddenMoveHandlers.hasHandler(move.id))
  1152.           commands[cmdMoves[i] = commands.length] = [PBMoves.getName(move.id),1]
  1153.         end
  1154.       end
  1155.       commands[cmdSwitch = commands.length]       = _INTL("Switch") if @party.length>1
  1156.       if !pkmn.egg?
  1157.         if pkmn.mail
  1158.           commands[cmdMail = commands.length]     = _INTL("Mail")
  1159.         else
  1160.           commands[cmdItem = commands.length]     = _INTL("Item")
  1161.         end
  1162.       end
  1163.       commands[commands.length]                   = _INTL("Cancel")
  1164.       command = @scene.pbShowCommands(_INTL("Do what with {1}?",pkmn.name),commands)
  1165.       havecommand = false
  1166.       for i in 0...4
  1167.         if cmdMoves[i]>=0 && command==cmdMoves[i]
  1168.           havecommand = true
  1169.           if isConst?(pkmn.moves[i].id,PBMoves,:SOFTBOILED) ||
  1170.              isConst?(pkmn.moves[i].id,PBMoves,:MILKDRINK)
  1171.             amt = [(pkmn.totalhp/5).floor,1].max
  1172.             if pkmn.hp<=amt
  1173.               pbDisplay(_INTL("Not enough HP..."))
  1174.               break
  1175.             end
  1176.             @scene.pbSetHelpText(_INTL("Use on which Pokémon?"))
  1177.             oldpkmnid = pkmnid
  1178.             loop do
  1179.               @scene.pbPreSelect(oldpkmnid)
  1180.               pkmnid = @scene.pbChoosePokemon(true,pkmnid)
  1181.               break if pkmnid<0
  1182.               newpkmn = @party[pkmnid]
  1183.               movename = PBMoves.getName(pkmn.moves[i].id)
  1184.               if pkmnid==oldpkmnid
  1185.                 pbDisplay(_INTL("{1} can't use {2} on itself!",pkmn.name,movename))
  1186.               elsif newpkmn.egg?
  1187.                 pbDisplay(_INTL("{1} can't be used on an Egg!",movename))
  1188.               elsif newpkmn.hp==0 || newpkmn.hp==newpkmn.totalhp
  1189.                 pbDisplay(_INTL("{1} can't be used on that Pokémon.",movename))
  1190.               else
  1191.                 pkmn.hp -= amt
  1192.                 hpgain = pbItemRestoreHP(newpkmn,amt)
  1193.                 @scene.pbDisplay(_INTL("{1}'s HP was restored by {2} points.",newpkmn.name,hpgain))
  1194.                 pbRefresh
  1195.               end
  1196.               break if pkmn.hp<=amt
  1197.             end
  1198.             @scene.pbSelect(oldpkmnid)
  1199.             pbRefresh
  1200.             break
  1201. =begin
  1202.           elsif pbCanUseHiddenMove?(pkmn,pkmn.moves[i].id)
  1203.             if pbConfirmUseHiddenMove(pkmn,pkmn.moves[i].id)
  1204.               @scene.pbEndScene
  1205.               if isConst?(pkmn.moves[i].id,PBMoves,:FLY)
  1206.                 scene = PokemonRegionMap_Scene.new(-1,false)
  1207.                 screen = PokemonRegionMapScreen.new(scene)
  1208.                 ret = screen.pbStartFlyScreen
  1209.                 if ret
  1210.                   $PokemonTemp.flydata=ret
  1211.                   return [pkmn,pkmn.moves[i].id]
  1212.                 end
  1213.                 @scene.pbStartScene(@party,
  1214.                    (@party.length>1) ? _INTL("Choose a Pokémon.") : _INTL("Choose Pokémon or cancel."))
  1215.                 break
  1216.               end
  1217.               return [pkmn,pkmn.moves[i].id]
  1218.             end
  1219. =end
  1220.           else
  1221.             break
  1222.           end
  1223.         end
  1224.       end
  1225.       next if havecommand
  1226.       if cmdSummary>=0 && command==cmdSummary
  1227.         @scene.pbSummary(pkmnid) {
  1228.           @scene.pbSetHelpText((@party.length>1) ? _INTL("Choose a Pokémon.") : _INTL("Choose Pokémon or cancel."))
  1229.         }
  1230.       elsif cmdDebug>=0 && command==cmdDebug
  1231.         pbPokemonDebug(pkmn,pkmnid)
  1232.       elsif cmdSwitch>=0 && command==cmdSwitch
  1233.         @scene.pbSetHelpText(_INTL("Move to where?"))
  1234.         oldpkmnid = pkmnid
  1235.         pkmnid = @scene.pbChoosePokemon(true)
  1236.         if pkmnid>=0 && pkmnid!=oldpkmnid
  1237.           pbSwitch(oldpkmnid,pkmnid)
  1238.         end
  1239.       elsif cmdMail>=0 && command==cmdMail
  1240.         command = @scene.pbShowCommands(_INTL("Do what with the mail?"),
  1241.            [_INTL("Read"),_INTL("Take"),_INTL("Cancel")])
  1242.         case command
  1243.         when 0   # Read
  1244.           pbFadeOutIn {
  1245.             pbDisplayMail(pkmn.mail,pkmn)
  1246.             @scene.pbSetHelpText((@party.length>1) ? _INTL("Choose a Pokémon.") : _INTL("Choose Pokémon or cancel."))
  1247.           }
  1248.         when 1   # Take
  1249.           if pbTakeItemFromPokemon(pkmn,self)
  1250.             pbRefreshSingle(pkmnid)
  1251.           end
  1252.         end
  1253.       elsif cmdItem>=0 && command==cmdItem
  1254.         itemcommands = []
  1255.         cmdUseItem   = -1
  1256.         cmdGiveItem  = -1
  1257.         cmdTakeItem  = -1
  1258.         cmdMoveItem  = -1
  1259.         # Build the commands
  1260.         itemcommands[cmdUseItem=itemcommands.length]  = _INTL("Use")
  1261.         itemcommands[cmdGiveItem=itemcommands.length] = _INTL("Give")
  1262.         itemcommands[cmdTakeItem=itemcommands.length] = _INTL("Take") if pkmn.hasItem?
  1263.         itemcommands[cmdMoveItem=itemcommands.length] = _INTL("Move") if pkmn.hasItem? && !pbIsMail?(pkmn.item)
  1264.         itemcommands[itemcommands.length]             = _INTL("Cancel")
  1265.         command = @scene.pbShowCommands(_INTL("Do what with an item?"),itemcommands)
  1266.         if cmdUseItem>=0 && command==cmdUseItem   # Use
  1267.           item = @scene.pbUseItem($PokemonBag,pkmn) {
  1268.             @scene.pbSetHelpText((@party.length>1) ? _INTL("Choose a Pokémon.") : _INTL("Choose Pokémon or cancel."))
  1269.           }
  1270.           if item>0
  1271.             pbUseItemOnPokemon(item,pkmn,self)
  1272.             pbRefreshSingle(pkmnid)
  1273.           end
  1274.         elsif cmdGiveItem>=0 && command==cmdGiveItem   # Give
  1275.           item = @scene.pbChooseItem($PokemonBag) {
  1276.             @scene.pbSetHelpText((@party.length>1) ? _INTL("Choose a Pokémon.") : _INTL("Choose Pokémon or cancel."))
  1277.           }
  1278.           if item>0
  1279.             if pbGiveItemToPokemon(item,pkmn,self,pkmnid)
  1280.               pbRefreshSingle(pkmnid)
  1281.             end
  1282.           end
  1283.         elsif cmdTakeItem>=0 && command==cmdTakeItem   # Take
  1284.           if pbTakeItemFromPokemon(pkmn,self)
  1285.             pbRefreshSingle(pkmnid)
  1286.           end
  1287.         elsif cmdMoveItem>=0 && command==cmdMoveItem   # Move
  1288.           item = pkmn.item
  1289.           itemname = PBItems.getName(item)
  1290.           @scene.pbSetHelpText(_INTL("Move {1} to where?",itemname))
  1291.           oldpkmnid = pkmnid
  1292.           loop do
  1293.             @scene.pbPreSelect(oldpkmnid)
  1294.             pkmnid = @scene.pbChoosePokemon(true,pkmnid)
  1295.             break if pkmnid<0
  1296.             newpkmn = @party[pkmnid]
  1297.             if pkmnid==oldpkmnid
  1298.               break
  1299.             elsif newpkmn.egg?
  1300.               pbDisplay(_INTL("Eggs can't hold items."))
  1301.             elsif !newpkmn.hasItem?
  1302.               newpkmn.setItem(item)
  1303.               pkmn.setItem(0)
  1304.               @scene.pbClearSwitching
  1305.               pbRefresh
  1306.               pbDisplay(_INTL("{1} was given the {2} to hold.",newpkmn.name,itemname))
  1307.               break
  1308.             elsif pbIsMail?(newpkmn.item)
  1309.               pbDisplay(_INTL("{1}'s mail must be removed before giving it an item.",newpkmn.name))
  1310.             else
  1311.               newitem = newpkmn.item
  1312.               newitemname = PBItems.getName(newitem)
  1313.               if isConst?(newitem,PBItems,:LEFTOVERS)
  1314.                 pbDisplay(_INTL("{1} is already holding some {2}.\1",newpkmn.name,newitemname))
  1315.               elsif newitemname.starts_with_vowel?
  1316.                 pbDisplay(_INTL("{1} is already holding an {2}.\1",newpkmn.name,newitemname))
  1317.               else
  1318.                 pbDisplay(_INTL("{1} is already holding a {2}.\1",newpkmn.name,newitemname))
  1319.               end
  1320.               if pbConfirm(_INTL("Would you like to switch the two items?"))
  1321.                 newpkmn.setItem(item)
  1322.                 pkmn.setItem(newitem)
  1323.                 @scene.pbClearSwitching
  1324.                 pbRefresh
  1325.                 pbDisplay(_INTL("{1} was given the {2} to hold.",newpkmn.name,itemname))
  1326.                 pbDisplay(_INTL("{1} was given the {2} to hold.",pkmn.name,newitemname))
  1327.                 break
  1328.               end
  1329.             end
  1330.           end
  1331.         end
  1332.       end
  1333.     end
  1334.     @scene.pbEndScene
  1335.     return nil
  1336.   end
  1337. end
  1338.  
  1339.  
  1340.  
  1341. def pbPokemonScreen
  1342.   pbFadeOutIn {
  1343.     sscene = PokemonParty_Scene.new
  1344.     sscreen = PokemonPartyScreen.new(sscene,$Trainer.party)
  1345.     sscreen.pbPokemonScreen
  1346.   }
  1347. end
  1348.