pokeminer20

Pokemon Essentials V19.1 PartyPlus V4.0.2

Aug 17th, 2021 (edited)
1,810
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 64.61 KB | None | 0 0
  1. #==============================================================================#
  2. # PartyPlus 4.0.1 for Pokemon Essentials 19.1                                  #
  3. #==============================================================================#
  4. # Important usage Instructions: START A NEW SAVE FILE BEFORE USING THIS SCRIPT!#
  5. # To use as a plugin, drag and drop the folder containing this file into the   #
  6. # /Plugins folder. to use as a script, create a new script section within RMXP #
  7. # and paste all text here into the new section (To add new sections, press     #
  8. # 'Insert' on your keyboard. If you overwrite something, that's on you         #
  9. #==============================================================================#
  10. # This script allows a developer to modify how many pokemon the player may play#
  11. # with. the current allowed sizes are between 1-20, with 3,5,7,11,13,17, and 19#
  12. # being invalid. This script also features "Benching", A mechanic that allowes #
  13. # Pokemon to travel with the player but are unable to participate in battle.   #
  14. # to easily set the Party Limit and Bench limits, use the command `ppSetLimit` #
  15. # followed by two valid limits between 0-20. Ex: ppSetLimit(14,7) will let you #
  16. # travel with 14 pokemon, but only allow you to battle with 7 of them. setting #
  17. # the first argument to 0 will disable the limit modifyer, as well as the bench#
  18. # limit entierly. know that the continue screen, healing animation, and hall of#
  19. # fame are unedited, and updates for them are up to the user of the script to  #
  20. # properly implement.                                                          #
  21. #==============================================================================#
  22. # Party Plus Settings                                                          #
  23. #==============================================================================#
  24. module Settings
  25.  HARD_TEAM_LIMIT  = 20 #The highest number of pokemon a trainer may have
  26. end
  27. #==============================================================================#
  28. # Custom commands for modifying the party. Modify me if you want to use party
  29. # limits over 20
  30. #==============================================================================#
  31. def ppSetLimit(total,limit=total)
  32. ########[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20]
  33.  size = [ 1, 1, 1 ,0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1]
  34.  legal = true if size[total]==1
  35.  legal = false if size[total]==0
  36.  limit = total if limit == 0
  37.  if legal && total <= 20
  38.   #total is greater than 1
  39.   $Trainer.pluscount    = total if total>=1
  40.   $Trainer.partybenched = limit if total>=1
  41.   $Trainer.partyplus    = true  if total>=1
  42.   pbMessage(_INTL("Total Party Size and Battler limit Set.")) if total>=1
  43.   # total equals 0
  44.   $Trainer.partyplus    = false if total==0
  45.   $Trainer.pluscount    = 0 if total==0
  46.   $Trainer.partybenched = 0 if total==0
  47.   pbMessage(_INTL("Party Size returned to Default value.")) if total==0
  48.  elsif total >= 21
  49.   pbMessage(_INTL("Current limit for trainer party cannot exceed 20."))
  50.  else
  51.   pbMessage(_INTL("The party value is invalid. Please enter a valid total."))
  52.  end
  53. end
  54. def ppSetBenched
  55.  plus  = $Trainer.pluscount if $Trainer.partyplus==true
  56.  plus  = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  57.  limit = $Trainer.partybenched
  58.  limit = plus if plus==1
  59.  if $Trainer.partyplus==true
  60.   for j in 0...limit
  61.    $Trainer.party[j].benched=false if $Trainer.party[j]!=nil
  62.   end
  63.   for i in limit...plus
  64.    $Trainer.party[i].benched=true if limit<plus && $Trainer.party[i]!=nil
  65.   end
  66.  else
  67.   for i in 0...$Trainer.party.length
  68.    $Trainer.party[i].benched=false if $Trainer.party[i]!=nil
  69.   end
  70.  end
  71. end
  72. def ppUpdate
  73.   partydep = $Trainer.partyplus
  74.   plusded  = false if $Trainer.partyif $Trainer.partyplus==false
  75.   plusded  = true  if $Trainer.partyif $Trainer.partyplus==true
  76.   $Trainer.partyplus    = plusdep
  77.   $Trainer.pluscount    = partydep
  78. end
  79. #===============================================================================
  80. # Open the party screen
  81. #===============================================================================
  82. class PokemonPartyBlankPanel < SpriteWrapper
  83.   def initialize(_pokemon,index,viewport=nil)
  84.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  85.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  86.     super(viewport)
  87. ##########[ 0, 1, 2, 3,  4, 5,  6, 7, 8,  9,10,11,12,13, 14, 15,16,17, 18,19,20]
  88.     csn = [ 2, 2, 2, 0,  2, 0,  2, 0, 2,  3, 2, 0, 3, 0,  7,  5, 4, 0,  6, 0, 5]
  89.     rsn = [ 2, 2, 2, 0,  2, 0,  2, 0, 2,  3, 2, 0, 3, 0,  7,  5, 4, 0,  6, 0, 5]
  90.     psy = [96, 0,96, 0,160, 0,106, 0,80,106,64, 0,80, 0,160,106,80, 0,108, 0,80]
  91.     if $Trainer.partyplus==true && $Trainer.pluscount>=1
  92.      self.x = (index % csn[plus]) * Graphics.width / csn[plus]
  93.      self.y = 0 * (index % rsn[plus]) + psy[plus] * (index / rsn[plus])
  94.     else
  95.      self.x = (index % 2) * Graphics.width / 2
  96.      self.y = 16 * (index % 2) + 96 * (index / 2)
  97.     end
  98.     @panelbgsprite = AnimatedBitmap.new("Graphics/Pictures/Party/PartyPlus/"+"#{plus}"+" - Party/panel_blank") if $Trainer.partyplus==true
  99.     @panelbgsprite = AnimatedBitmap.new("Graphics/Pictures/Party/panel_blank") if $Trainer.partyplus==false
  100.     self.bitmap = @panelbgsprite.bitmap
  101.     @text = nil
  102.   end
  103. end
  104. #===============================================================================
  105. # Pokémon party panel
  106. #===============================================================================
  107. class PokemonPartyPanel < SpriteWrapper
  108.   attr_reader :pokemon
  109.   attr_reader :active
  110.   attr_reader :selected
  111.   attr_reader :preselected
  112.   attr_reader :switching
  113.   attr_reader :text
  114.  
  115.   def initialize(pokemon,index,viewport=nil)
  116.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  117.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  118.     super(viewport)
  119.     @pokemon = pokemon
  120.     @active = (index==0)   # true = rounded panel, false = rectangular panel
  121.     @refreshing = true
  122. ##########[ 0, 1, 2, 3,  4, 5,  6, 7, 8,  9,10,11,12,13, 14, 15,16,17, 18,19,20]
  123.     csn = [ 2, 2, 2, 0,  2, 0,  2, 0, 2,  3, 2, 0, 3, 0,  7,  5, 4, 0,  6, 0, 5]
  124.     rsn = [ 2, 2, 2, 0,  2, 0,  2, 0, 2,  3, 2, 0, 3, 0,  7,  5, 4, 0,  6, 0, 5]
  125.     psy = [96, 0,96, 0,160, 0,106, 0,80,106,64, 0,80, 0,160,106,80, 0,108, 0,80]
  126.     if $Trainer.partyplus==true && $Trainer.pluscount>=1
  127.      self.x = (index % csn[plus]) * Graphics.width / csn[plus]
  128.      self.y = 0 * (index % rsn[plus]) + psy[plus] * (index / rsn[plus])
  129.     else
  130.      self.x = (index % 2) * Graphics.width / 2
  131.      self.y = 16 * (index % 2) + 96 * (index / 2)
  132.     end
  133.     @panelbgsprite = ChangelingSprite.new(0,0,viewport)
  134.     @panelbgsprite.z = self.z
  135.     if @active   # Rounded panel
  136.       #Normal Panel
  137.       @panelbgsprite.addBitmap("able","Graphics/Pictures/Party/panel_round") if $Trainer.partyplus==false
  138.       @panelbgsprite.addBitmap("ablesel","Graphics/Pictures/Party/panel_round_sel") if $Trainer.partyplus==false
  139.       @panelbgsprite.addBitmap("fainted","Graphics/Pictures/Party/panel_round_faint") if $Trainer.partyplus==false
  140.       @panelbgsprite.addBitmap("faintedsel","Graphics/Pictures/Party/panel_round_faint_sel") if $Trainer.partyplus==false
  141.       @panelbgsprite.addBitmap("swap","Graphics/Pictures/Party/panel_round_swap") if $Trainer.partyplus==false
  142.       @panelbgsprite.addBitmap("swapsel","Graphics/Pictures/Party/panel_round_swap_sel") if $Trainer.partyplus==false
  143.       @panelbgsprite.addBitmap("swapsel2","Graphics/Pictures/Party/panel_round_swap_sel2") if $Trainer.partyplus==false
  144.       #Plus Pannels
  145.       @panelbgsprite.addBitmap("able","Graphics/Pictures/Party/PartyPlus/"+"#{plus}"+" - Party/panel_rect") if $Trainer.partyplus==true
  146.       @panelbgsprite.addBitmap("ablesel","Graphics/Pictures/Party/PartyPlus/"+"#{plus}"+" - Party/panel_rect_sel") if $Trainer.partyplus==true
  147.       @panelbgsprite.addBitmap("fainted","Graphics/Pictures/Party/PartyPlus/"+"#{plus}"+" - Party/panel_rect_faint") if $Trainer.partyplus==true
  148.       @panelbgsprite.addBitmap("faintedsel","Graphics/Pictures/Party/PartyPlus/"+"#{plus}"+" - Party/panel_rect_faint_sel") if $Trainer.partyplus==true
  149.       @panelbgsprite.addBitmap("swap","Graphics/Pictures/Party/PartyPlus/"+"#{plus}"+" - Party/panel_rect_swap") if $Trainer.partyplus==true
  150.       @panelbgsprite.addBitmap("swapsel","Graphics/Pictures/Party/PartyPlus/"+"#{plus}"+" - Party/panel_rect_swap_sel") if $Trainer.partyplus==true
  151.       @panelbgsprite.addBitmap("swapsel2","Graphics/Pictures/Party/PartyPlus/"+"#{plus}"+" - Party/panel_rect_swap_sel2") if $Trainer.partyplus==true
  152.       @panelbgsprite.addBitmap("benched","Graphics/Pictures/Party/PartyPlus/"+"#{plus}"+" - Party/panel_rect_bench") if $Trainer.partyplus==true
  153.       @panelbgsprite.addBitmap("benchsel","Graphics/Pictures/Party/PartyPlus/"+"#{plus}"+" - Party/panel_rect_bench_sel") if $Trainer.partyplus==true
  154.     else   # Rectangular panel
  155.       #Normal Panel
  156.       @panelbgsprite.addBitmap("able","Graphics/Pictures/Party/panel_rect") if $Trainer.partyplus==false
  157.       @panelbgsprite.addBitmap("ablesel","Graphics/Pictures/Party/panel_rect_sel") if $Trainer.partyplus==false
  158.       @panelbgsprite.addBitmap("fainted","Graphics/Pictures/Party/panel_rect_faint") if $Trainer.partyplus==false
  159.       @panelbgsprite.addBitmap("faintedsel","Graphics/Pictures/Party/panel_rect_faint_sel") if $Trainer.partyplus==false
  160.       @panelbgsprite.addBitmap("swap","Graphics/Pictures/Party/panel_rect_swap") if $Trainer.partyplus==false
  161.       @panelbgsprite.addBitmap("swapsel","Graphics/Pictures/Party/panel_rect_swap_sel") if $Trainer.partyplus==false
  162.       @panelbgsprite.addBitmap("swapsel2","Graphics/Pictures/Party/panel_rect_swap_sel2") if $Trainer.partyplus==false
  163.       #Plus Pannels
  164.       @panelbgsprite.addBitmap("able","Graphics/Pictures/Party/PartyPlus/"+"#{plus}"+" - Party/panel_rect") if $Trainer.partyplus==true
  165.       @panelbgsprite.addBitmap("ablesel","Graphics/Pictures/Party/PartyPlus/"+"#{plus}"+" - Party/panel_rect_sel") if $Trainer.partyplus==true
  166.       @panelbgsprite.addBitmap("fainted","Graphics/Pictures/Party/PartyPlus/"+"#{plus}"+" - Party/panel_rect_faint") if $Trainer.partyplus==true
  167.       @panelbgsprite.addBitmap("faintedsel","Graphics/Pictures/Party/PartyPlus/"+"#{plus}"+" - Party/panel_rect_faint_sel") if $Trainer.partyplus==true
  168.       @panelbgsprite.addBitmap("swap","Graphics/Pictures/Party/PartyPlus/"+"#{plus}"+" - Party/panel_rect_swap") if $Trainer.partyplus==true
  169.       @panelbgsprite.addBitmap("swapsel","Graphics/Pictures/Party/PartyPlus/"+"#{plus}"+" - Party/panel_rect_swap_sel") if $Trainer.partyplus==true
  170.       @panelbgsprite.addBitmap("swapsel2","Graphics/Pictures/Party/PartyPlus/"+"#{plus}"+" - Party/panel_rect_swap_sel2") if $Trainer.partyplus==true
  171.       @panelbgsprite.addBitmap("benched","Graphics/Pictures/Party/PartyPlus/"+"#{plus}"+" - Party/panel_rect_bench") if $Trainer.partyplus==true
  172.       @panelbgsprite.addBitmap("benchsel","Graphics/Pictures/Party/PartyPlus/"+"#{plus}"+" - Party/panel_rect_bench_sel") if $Trainer.partyplus==true
  173.     end
  174.     count = [1,1,1,0,1,0,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0]
  175.     show = true if count[$Trainer.pluscount]==1
  176.     show = false if count[$Trainer.pluscount]==0
  177.     if show
  178.     @hpbgsprite = ChangelingSprite.new(0,0,viewport)
  179.     @hpbgsprite.z = self.z+1
  180.     @hpbgsprite.addBitmap("able","Graphics/Pictures/Party/overlay_hp_back")
  181.     @hpbgsprite.addBitmap("fainted","Graphics/Pictures/Party/overlay_hp_back_faint")
  182.     @hpbgsprite.addBitmap("swap","Graphics/Pictures/Party/overlay_hp_back_swap")
  183.     end
  184.     @ballsprite = ChangelingSprite.new(0,0,viewport)
  185.     @ballsprite.z = self.z+1
  186.     @ballsprite.addBitmap("desel","Graphics/Pictures/Party/icon_ball")
  187.     @ballsprite.addBitmap("sel","Graphics/Pictures/Party/icon_ball_sel")
  188.     @pkmnsprite = PokemonIconSprite.new(pokemon,viewport)
  189.     @pkmnsprite.setOffset(PictureOrigin::Center) if $Trainer.partyplus==false
  190.     @pkmnsprite.setOffset(PictureOrigin::TopLeft) if $Trainer.partyplus==true
  191.     @pkmnsprite.active = @active
  192.     @pkmnsprite.z      = self.z+2
  193.     #---------------------------------------------------------------------------
  194.     # ZUD - Dynamax Icons
  195.     #---------------------------------------------------------------------------
  196.     _ZUD_DynamaxSize if defined?(Settings::ZUD_COMPAT)
  197.     #---------------------------------------------------------------------------
  198.     @helditemsprite = HeldItemIconSprite.new(0,0,@pokemon,viewport)
  199.     @helditemsprite.z = self.z+3
  200.     @overlaysprite = BitmapSprite.new(Graphics.width,Graphics.height,viewport)
  201.     @overlaysprite.z = self.z+4
  202.     @hpbar    = AnimatedBitmap.new("Graphics/Pictures/Party/overlay_hp")
  203.     @statuses = AnimatedBitmap.new(_INTL("Graphics/Pictures/statuses"))
  204.     @selected      = false
  205.     @preselected   = false
  206.     @switching     = false
  207.     @text          = nil
  208.     @refreshBitmap = true
  209.     @refreshing    = false
  210.     refresh
  211.   end
  212.  
  213.   def dispose
  214.     count = [1,1,1,0,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0]
  215.     show = true if count[$Trainer.pluscount]==1
  216.     show = false if count[$Trainer.pluscount]==0
  217.     @panelbgsprite.dispose
  218.     @hpbgsprite.dispose if show
  219.     @ballsprite.dispose
  220.     @pkmnsprite.dispose
  221.     @helditemsprite.dispose
  222.     @overlaysprite.bitmap.dispose
  223.     @overlaysprite.dispose
  224.     @hpbar.dispose if show
  225.     @statuses.dispose
  226.     super
  227.   end
  228.  
  229.   def refresh
  230.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  231.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  232. ##############[  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
  233.     name   = [1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
  234.     hp_bar = [1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
  235.     hp_txt = [1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0]
  236.     show_name = true if name[$Trainer.pluscount]==1
  237.     show_name = false if name[$Trainer.pluscount]==0
  238.     show_bar  = true if hp_bar[$Trainer.pluscount]==1
  239.     show_bar  = false if hp_bar[$Trainer.pluscount]==0
  240.     show_hp   = true if hp_txt[$Trainer.pluscount]==1
  241.     show_hp   = false if hp_txt[$Trainer.pluscount]==0
  242.     return if disposed?
  243.     return if @refreshing
  244.     @refreshing = true
  245.     if @panelbgsprite && !@panelbgsprite.disposed?
  246.       if self.selected
  247.         if self.preselected;     @panelbgsprite.changeBitmap("swapsel2")
  248.         elsif @switching;        @panelbgsprite.changeBitmap("swapsel")
  249.         elsif @pokemon.fainted?; @panelbgsprite.changeBitmap("faintedsel")
  250.         elsif @pokemon.benched?; @panelbgsprite.changeBitmap("benchsel")
  251.         else;                    @panelbgsprite.changeBitmap("ablesel")
  252.         end
  253.       else
  254.         if self.preselected;     @panelbgsprite.changeBitmap("swap")
  255.         elsif @pokemon.fainted?; @panelbgsprite.changeBitmap("fainted")
  256.         elsif @pokemon.benched?; @panelbgsprite.changeBitmap("benched")
  257.         else;                    @panelbgsprite.changeBitmap("able")
  258.         end
  259.       end
  260.       @panelbgsprite.x     = self.x
  261.       @panelbgsprite.y     = self.y
  262.       @panelbgsprite.color = self.color
  263.     end
  264.     if @hpbgsprite && !@hpbgsprite.disposed?
  265.       @hpbgsprite.visible = (!@pokemon.egg? && !(@text && @text.length>0))
  266.       if @hpbgsprite.visible
  267.         if self.preselected || (self.selected && @switching); @hpbgsprite.changeBitmap("swap")
  268.         elsif @pokemon.fainted?;                              @hpbgsprite.changeBitmap("fainted")
  269.         else;                                                 @hpbgsprite.changeBitmap("able")
  270.         end
  271. ##############[  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
  272.         hsx = [108,364,108,  0,108,  0,108,  0,108, 22,108,  0, 96,  0, 96, 96, 96,  0, 96,  0, 96]
  273.         hsy = [ 47,153,153,  0, 73,  0, 47,  0, 33, 46, 25,  0, 32,  0, 32, 32, 32,  0, 32,  0, 32]
  274.         @hpbgsprite.x     = self.x+hsx[$Trainer.pluscount]
  275.         @hpbgsprite.y     = self.y+hsy[$Trainer.pluscount]
  276.         @hpbgsprite.color = self.color
  277.       end
  278.     end
  279.     if @ballsprite && !@ballsprite.disposed?
  280.       @ballsprite.changeBitmap((self.selected) ? "sel" : "desel")
  281.       @ballsprite.x     = self.x+2
  282.       @ballsprite.y     = self.y-4
  283.       @ballsprite.color = self.color
  284.     end
  285.     if @pkmnsprite && !@pkmnsprite.disposed?
  286.       @pkmnsprite.x        = self.x+60 if $Trainer.partyplus==false
  287.       @pkmnsprite.x        = self.x if $Trainer.partyplus==true
  288.       @pkmnsprite.y        = self.y+40 if $Trainer.partyplus==false
  289.       @pkmnsprite.y        = self.y if $Trainer.partyplus==true
  290.       @pkmnsprite.color    = self.color
  291.       #-------------------------------------------------------------------------
  292.       # ZUD - Dynamax Icons
  293.       #-------------------------------------------------------------------------
  294.       _ZUD_DynamaxColor if defined?(Settings::ZUD_COMPAT)
  295.       #-------------------------------------------------------------------------
  296.       @pkmnsprite.selected = self.selected
  297.     end
  298.     if @helditemsprite && !@helditemsprite.disposed?
  299.       if @helditemsprite.visible
  300.         @helditemsprite.x     = self.x+62
  301.         @helditemsprite.y     = self.y+48
  302.         @helditemsprite.color = self.color
  303.       end
  304.     end
  305.     if @overlaysprite && !@overlaysprite.disposed?
  306.       @overlaysprite.x     = self.x
  307.       @overlaysprite.y     = self.y
  308.       @overlaysprite.color = self.color
  309.     end
  310.     if @refreshBitmap
  311.       @refreshBitmap = false
  312.       @overlaysprite.bitmap.clear if @overlaysprite.bitmap
  313.       basecolor   = Color.new(248,248,248)
  314.       shadowcolor = Color.new(40,40,40)
  315.       pbSetSystemFont(@overlaysprite.bitmap)
  316.       textpos = []
  317.       # Draw Pokémon name
  318. ############[  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
  319.       pnx = [244,502,244,  0,244,  0,244,  0,244,158,244,  0, 96,  0, 96, 96, 96,  0, 96,  0, 96]
  320.       pny = [ 22, 10, 10,  0, 10,  0, 10,  0, 10, 10, 10,  0, 10,  0, 10, 10, 10,  0, 10,  0, 10]
  321.       if @pokemon.male? || @pokemon.female?
  322.        textpos.push([@pokemon.name,pnx[$Trainer.pluscount]-16,pny[$Trainer.pluscount]-12,1,basecolor,shadowcolor]) if show_name
  323.       else
  324.        textpos.push([@pokemon.name,pnx[$Trainer.pluscount],pny[$Trainer.pluscount]-12,1,basecolor,shadowcolor]) if show_name
  325.       end
  326.       if !@pokemon.egg?
  327.         if !@text || @text.length==0
  328.           # Draw HP numbers
  329. ################[  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
  330.           hpx = [244,502,244,  0,244,  0,244,  0,244,158,244,  0, 96,  0, 96, 96, 96,  0, 96,  0, 96]
  331.           hpy = [ 68,290,290,  0,130,  0, 78,  0, 50, 76, 34,  0, 32,  0, 32, 32, 32,  0, 32,  0, 32]
  332.           textpos.push([sprintf("% 3d /% 3d",@pokemon.hp,@pokemon.totalhp),hpx[$Trainer.pluscount],hpy[$Trainer.pluscount]-12,1,basecolor,shadowcolor]) if show_hp
  333.           # Draw HP bar
  334.           if @pokemon.hp>0
  335.             w = @pokemon.hp*96*1.0/@pokemon.totalhp
  336.             w = 1 if w<1
  337.             w = ((w/2).round)*2
  338.             hpzone = 0
  339.             hpzone = 1 if @pokemon.hp<=(@pokemon.totalhp/2).floor
  340.             hpzone = 2 if @pokemon.hp<=(@pokemon.totalhp/4).floor
  341.             hprect = Rect.new(0,hpzone*8,w,8)
  342. ##################[  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
  343.             hbx = [108,364,108,  0,108,  0,108,  0,108, 22,108,  0, 96,  0, 96, 96, 96,  0, 96,  0, 96]
  344.             hby = [ 47,153,153,  0, 73,  0, 47,  0, 33, 46, 25,  0, 32,  0, 32, 32, 32,  0, 32,  0, 32]
  345.             @overlaysprite.bitmap.blt(hbx[$Trainer.pluscount]+32,hby[$Trainer.pluscount]+2,@hpbar.bitmap,hprect) if show_bar
  346.           end
  347.           # Draw status
  348.           status = 0
  349.           if @pokemon.fainted?
  350.             status = GameData::Status::DATA.keys.length / 2
  351.           elsif @pokemon.status != :NONE
  352.             status = GameData::Status.get(@pokemon.status).id_number
  353.           elsif @pokemon.pokerusStage == 1
  354.             status = GameData::Status::DATA.keys.length / 2 + 1
  355.           end
  356.           status -= 1
  357.           if status >= 0
  358.             statusrect = Rect.new(0,16*status,44,16)
  359.             @overlaysprite.bitmap.blt(78,68,@statuses.bitmap,statusrect)
  360.           end
  361.         end
  362.         # draw gender symbol
  363. ##############[  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
  364.         gxp = [244,502,244,  0,244,  0,244,  0,244,158,244,  0, 96,  0, 96, 96, 96,  0, 96,  0, 96]
  365.         gyp = [ 22, 10, 10,  0, 10,  0, 10,  0, 10, 10, 10,  0, 10,  0, 10, 10, 10,  0, 10,  0, 10]
  366.         if @pokemon.male? && show_name
  367.           textpos.push([_INTL("♂"),gxp[$Trainer.pluscount],gyp[$Trainer.pluscount]-12,1,Color.new(0,112,248),Color.new(120,184,232)])
  368.         elsif @pokemon.female? && show_name
  369.           textpos.push([_INTL("♀"),gxp[$Trainer.pluscount],gyp[$Trainer.pluscount]-12,1,Color.new(232,32,16),Color.new(248,168,184)])
  370.         end
  371.         # Draw shiny icon
  372.         if @pokemon.shiny?
  373.           pbDrawImagePositions(@overlaysprite.bitmap,[[
  374.              "Graphics/Pictures/shiny",80,48,0,0,16,16]])
  375.         end
  376.       end
  377.       pbDrawTextPositions(@overlaysprite.bitmap,textpos)
  378.       # Draw level text
  379.       if !@pokemon.egg?
  380.         pbDrawImagePositions(@overlaysprite.bitmap,[["Graphics/Pictures/Party/overlay_lv",20,70,0,0,22,14]]) if $Trainer.partyplus==false
  381.         pbDrawImagePositions(@overlaysprite.bitmap,[["Graphics/Pictures/Party/overlay_lv",20,60,0,0,22,14]]) if $Trainer.partyplus==true
  382.         pbSetSmallFont(@overlaysprite.bitmap)
  383.         pbDrawTextPositions(@overlaysprite.bitmap,[[@pokemon.level.to_s,42,57,0,basecolor,shadowcolor]]) if $Trainer.partyplus==false
  384.         pbDrawTextPositions(@overlaysprite.bitmap,[[@pokemon.level.to_s,42,47,0,basecolor,shadowcolor]]) if $Trainer.partyplus==true
  385.        
  386.       end
  387.       # Draw annotation text
  388.       if @text && @text.length>0
  389.         pbSetSystemFont(@overlaysprite.bitmap)
  390.         pbDrawTextPositions(@overlaysprite.bitmap,[
  391.            [@text,96,52,0,basecolor,shadowcolor]
  392.         ])
  393.       end
  394.     end
  395.     @refreshing = false
  396.   end
  397.  
  398.   def update
  399.     count = [1,1,1,0,1,0,1,0,1,1,1,0,1,0,1,1,1,0,1,0,0]
  400.     show = true if count[$Trainer.pluscount]==1
  401.     show = false if count[$Trainer.pluscount]==0
  402.     super
  403.     @panelbgsprite.update if @panelbgsprite && !@panelbgsprite.disposed?
  404.     @hpbgsprite.update if @hpbgsprite && !@hpbgsprite.disposed? && show
  405.     @ballsprite.update if @ballsprite && !@ballsprite.disposed?
  406.     @pkmnsprite.update if @pkmnsprite && !@pkmnsprite.disposed?
  407.     @helditemsprite.update if @helditemsprite && !@helditemsprite.disposed?
  408.   end
  409. end
  410. #===============================================================================
  411. # Basic trainer class (use a child class rather than this one)
  412. #===============================================================================
  413. class Player < Trainer
  414.   attr_accessor :partyplus
  415.   attr_accessor :partybenched
  416.   attr_accessor :pluscount
  417.  
  418.   alias _partyplus_initialize initialize
  419.   def initialize(name, trainer_type)
  420.     _partyplus_initialize(name, trainer_type)
  421.     @partyplus    = false
  422.     @partybenched = 0
  423.     @pluscount    = 0
  424.   end
  425.  
  426.   def able_party
  427.     return @party.find_all { |p| p && !p.egg? && !p.fainted? && !p.benched? }
  428.   end
  429. end
  430. #===============================================================================
  431. # Standard methods that start a trainer battle of various sizes
  432. #===============================================================================
  433. # Used by most trainer events, which can be positioned in such a way that
  434. # multiple trainer events spot the player at once. The extra code in this method
  435. # deals with that case and can cause a double trainer battle instead.
  436. def pbTrainerBattle(trainerID, trainerName, endSpeech=nil,
  437.                     doubleBattle=false, trainerPartyID=0, canLose=false, outcomeVar=1)
  438.   # If there is another NPC trainer who spotted the player at the same time, and
  439.   # it is possible to have a double battle (the player has 2+ able Pokémon or
  440.   # has a partner trainer), then record this first NPC trainer into
  441.   # $PokemonTemp.waitingTrainer and end this method. That second NPC event will
  442.   # then trigger and cause the battle to happen against this first trainer and
  443.   # themselves.
  444.   if !$PokemonTemp.waitingTrainer && pbMapInterpreterRunning? && ($Trainer.able_pokemon_count > 1 || ($Trainer.able_pokemon_count > 0 && $PokemonGlobal.partner))
  445.     thisEvent = pbMapInterpreter.get_character(0)
  446.     # Find all other triggered trainer events
  447.     triggeredEvents = $game_player.pbTriggeredTrainerEvents([2],false)
  448.     otherEvent = []
  449.     for i in triggeredEvents
  450.       next if i.id==thisEvent.id
  451.       next if $game_self_switches[[$game_map.map_id,i.id,"A"]]
  452.       otherEvent.push(i)
  453.     end
  454.     # Load the trainer's data, and call an event which might modify it
  455.     trainer = pbLoadTrainer(trainerID,trainerName,trainerPartyID)
  456.     pbMissingTrainer(trainerID,trainerName,trainerPartyID) if !trainer
  457.     return false if !trainer
  458.     Events.onTrainerPartyLoad.trigger(nil,trainer)
  459.     # If there is exactly 1 other triggered trainer event, and this trainer has
  460.     # 6 or fewer Pokémon, record this trainer for a double battle caused by the
  461.     # other triggered trainer event
  462.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  463.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  464.     if otherEvent.length == 1 && trainer.party.length <= plus
  465.       trainer.lose_text = endSpeech if endSpeech && !endSpeech.empty?
  466.       $PokemonTemp.waitingTrainer = [trainer, thisEvent.id]
  467.       return false
  468.     end
  469.   end
  470.   # Set some battle rules
  471.   setBattleRule("outcomeVar",outcomeVar) if outcomeVar!=1
  472.   setBattleRule("canLose") if canLose
  473.   setBattleRule("double") if doubleBattle || $PokemonTemp.waitingTrainer
  474.   # Perform the battle
  475.   if $PokemonTemp.waitingTrainer
  476.     decision = pbTrainerBattleCore($PokemonTemp.waitingTrainer[0],
  477.        [trainerID,trainerName,trainerPartyID,endSpeech]
  478.     )
  479.   else
  480.     decision = pbTrainerBattleCore([trainerID,trainerName,trainerPartyID,endSpeech])
  481.   end
  482.   # Finish off the recorded waiting trainer, because they have now been battled
  483.   if decision==1 && $PokemonTemp.waitingTrainer   # Win
  484.     pbMapInterpreter.pbSetSelfSwitch($PokemonTemp.waitingTrainer[1], "A", true)
  485.   end
  486.   $PokemonTemp.waitingTrainer = nil
  487.   # Return true if the player won the battle, and false if any other result
  488.   return (decision==1)
  489. end
  490. #===============================================================================
  491. # Basic trainer class (use a child class rather than this one)
  492. #===============================================================================
  493. class Trainer
  494.   def party_full?
  495.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  496.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  497.     return party_count >= plus
  498.   end
  499. end
  500. #===============================================================================
  501. #
  502. #===============================================================================
  503. def pbNewTrainer(tr_type, tr_name, tr_version, save_changes = true)
  504.   party = []
  505.   for i in 0...Settings::HARD_TEAM_LIMIT
  506.     if i == 0
  507.       pbMessage(_INTL("Please enter the first Pokémon.",i))
  508.     else
  509.       break if !pbConfirmMessage(_INTL("Add another Pokémon?"))
  510.     end
  511.     loop do
  512.       species = pbChooseSpeciesList
  513.       if species
  514.         params = ChooseNumberParams.new
  515.         params.setRange(1, GameData::GrowthRate.max_level)
  516.         params.setDefaultValue(10)
  517.         level = pbMessageChooseNumber(_INTL("Set the level for {1} (max. #{params.maxNumber}).",
  518.            GameData::Species.get(species).name), params)
  519.         party.push([species, level])
  520.         break
  521.       else
  522.         break if i > 0
  523.         pbMessage(_INTL("This trainer must have at least 1 Pokémon!"))
  524.       end
  525.     end
  526.   end
  527.   trainer = [tr_type, tr_name, [], party, tr_version]
  528.   if save_changes
  529.     trainer_hash = {
  530.       :id_number    => GameData::Trainer::DATA.keys.length / 2,
  531.       :trainer_type => tr_type,
  532.       :name         => tr_name,
  533.       :version      => tr_version,
  534.       :pokemon      => []
  535.     }
  536.     party.each do |pkmn|
  537.       trainer_hash[:pokemon].push({
  538.         :species => pkmn[0],
  539.         :level   => pkmn[1]
  540.       })
  541.     end
  542.     # Add trainer's data to records
  543.     trainer_hash[:id] = [trainer_hash[:trainer_type], trainer_hash[:name], trainer_hash[:version]]
  544.     GameData::Trainer.register(trainer_hash)
  545.     GameData::Trainer.save
  546.     pbConvertTrainerData
  547.     pbMessage(_INTL("The Trainer's data was added to the list of battles and in PBS/trainers.txt."))
  548.   end
  549.   return trainer
  550. end
  551. #===============================================================================
  552. # Pokémon party visuals
  553. #===============================================================================
  554. class PokemonParty_Scene
  555.   def pbStartScene(party,starthelptext,annotations=nil,multiselect=false)
  556.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  557.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  558.     ppSetBenched
  559.     @sprites = {}
  560.     @party = party
  561.     @viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  562.     @viewport.z = 99999
  563.     @multiselect = multiselect
  564.     addBackgroundPlane(@sprites,"partybg","Party/PartyPlus/bg",@viewport) if $Trainer.partyplus==true
  565.     addBackgroundPlane(@sprites,"partybg","Party/bg",@viewport) if $Trainer.partyplus==false
  566.     @sprites["messagebox"] = Window_AdvancedTextPokemon.new("")
  567.     @sprites["messagebox"].viewport       = @viewport
  568.     @sprites["messagebox"].visible        = false
  569.     @sprites["messagebox"].letterbyletter = true
  570.     pbBottomLeftLines(@sprites["messagebox"],2)
  571.     @sprites["helpwindow"] = Window_UnformattedTextPokemon.new(starthelptext)
  572.     @sprites["helpwindow"].viewport = @viewport
  573.     @sprites["helpwindow"].visible  = true
  574.     pbBottomLeftLines(@sprites["helpwindow"],1)
  575.     pbSetHelpText(starthelptext)
  576.     # Add party Pokémon sprites
  577.     for i in 0...plus
  578.       if @party[i]
  579.         @sprites["pokemon#{i}"] = PokemonPartyPanel.new(@party[i],i,@viewport)
  580.       else
  581.         @sprites["pokemon#{i}"] = PokemonPartyBlankPanel.new(@party[i],i,@viewport)
  582.       end
  583.       @sprites["pokemon#{i}"].text = annotations[i] if annotations
  584.     end
  585.     if @multiselect
  586.       @sprites["pokemon#{plus}"] = PokemonPartyConfirmSprite.new(@viewport)
  587.       @sprites["pokemon#{plus + 1}"] = PokemonPartyCancelSprite2.new(@viewport)
  588.     else
  589.       @sprites["pokemon#{plus}"] = PokemonPartyCancelSprite.new(@viewport)
  590.     end
  591.     # Select first Pokémon
  592.     @activecmd = 0
  593.     @sprites["pokemon0"].selected = true
  594.     pbFadeInAndShow(@sprites) { update }
  595.   end
  596.  
  597.   def pbAnnotate(annot)
  598.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  599.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  600.     for i in 0...plus
  601.       @sprites["pokemon#{i}"].text = (annot) ? annot[i] : nil
  602.     end
  603.   end
  604.  
  605.   def pbSelect(item)
  606.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  607.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  608.     @activecmd = item
  609.     numsprites = plus + ((@multiselect) ? 2 : 1)
  610.     for i in 0...numsprites
  611.       @sprites["pokemon#{i}"].selected = (i==@activecmd)
  612.     end
  613.   end
  614.  
  615.   def pbSwitchEnd(oldid,newid)
  616.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  617.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  618.     pbSEPlay("GUI party switch")
  619.     oldsprite = @sprites["pokemon#{oldid}"]
  620.     newsprite = @sprites["pokemon#{newid}"]
  621.     oldsprite.pokemon = @party[oldid]
  622.     newsprite.pokemon = @party[newid]
  623.     timeTaken = Graphics.frame_rate*4/10
  624.     distancePerFrame = (Graphics.width/(2.0*timeTaken)).ceil
  625.     timeTaken.times do
  626.       oldsprite.x -= (oldid&1)==0 ? -distancePerFrame : distancePerFrame
  627.       newsprite.x -= (newid&1)==0 ? -distancePerFrame : distancePerFrame
  628.       Graphics.update
  629.       Input.update
  630.       self.update
  631.     end
  632.     #Inject Benching Code Here
  633.     for i in 0...plus
  634.       @sprites["pokemon#{i}"].preselected = false
  635.       @sprites["pokemon#{i}"].switching   = false
  636.     end
  637.     ppSetBenched
  638.     pbRefresh
  639.   end
  640.  
  641.   def pbClearSwitching
  642.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  643.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  644.     for i in 0...plus
  645.       @sprites["pokemon#{i}"].preselected = false
  646.       @sprites["pokemon#{i}"].switching   = false
  647.     end
  648.   end
  649.  
  650.   def pbChoosePokemon(switching=false,initialsel=-1,canswitch=0)
  651.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  652.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  653.     for i in 0...plus
  654.       @sprites["pokemon#{i}"].preselected = (switching && i==@activecmd)
  655.       @sprites["pokemon#{i}"].switching   = switching
  656.     end
  657.     @activecmd = initialsel if initialsel>=0
  658.     pbRefresh
  659.     loop do
  660.       Graphics.update
  661.       Input.update
  662.       self.update
  663.       oldsel = @activecmd
  664.       key = -1
  665.       key = Input::DOWN if Input.repeat?(Input::DOWN)
  666.       key = Input::RIGHT if Input.repeat?(Input::RIGHT)
  667.       key = Input::LEFT if Input.repeat?(Input::LEFT)
  668.       key = Input::UP if Input.repeat?(Input::UP)
  669.       if key>=0
  670.         @activecmd = pbChangeSelection(key,@activecmd)
  671.       end
  672.       if @activecmd!=oldsel   # Changing selection
  673.         pbPlayCursorSE
  674.         numsprites = plus + ((@multiselect) ? 2 : 1)
  675.         for i in 0...numsprites
  676.           @sprites["pokemon#{i}"].selected = (i==@activecmd)
  677.         end
  678.       end
  679.       cancelsprite = plus + ((@multiselect) ? 1 : 0)
  680.       if Input.trigger?(Input::ACTION) && canswitch==1 && @activecmd!=cancelsprite
  681.         pbPlayDecisionSE
  682.         return [1,@activecmd]
  683.       elsif Input.trigger?(Input::ACTION) && canswitch==2
  684.         return -1
  685.       elsif Input.trigger?(Input::BACK)
  686.         pbPlayCloseMenuSE if !switching
  687.         return -1
  688.       elsif Input.trigger?(Input::USE)
  689.         if @activecmd==cancelsprite
  690.           (switching) ? pbPlayDecisionSE : pbPlayCloseMenuSE
  691.           return -1
  692.         else
  693.           pbPlayDecisionSE
  694.           return @activecmd
  695.         end
  696.       end
  697.     end
  698.   end
  699.  
  700.   def pbChangeSelection(key,currentsel) #Further Mods Needed
  701.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  702.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  703.     div = [ 2, 1, 2, 2, 2, 2, 2, 2, 2, 3, 2, 2, 3, 2, 7, 5, 4, 2, 6, 2, 5]
  704.     numsprites = plus + ((@multiselect) ? 2 : 1)
  705.     case key
  706.     when Input::LEFT
  707.       begin
  708.         currentsel -= 1
  709.       end while currentsel > 0 && currentsel < @party.length && !@party[currentsel]
  710.       if currentsel >= @party.length && currentsel < plus
  711.         currentsel = @party.length - 1
  712.       end
  713.       currentsel = numsprites - 1 if currentsel < 0
  714.     when Input::RIGHT
  715.       begin
  716.         currentsel += 1
  717.       end while currentsel < @party.length && !@party[currentsel]
  718.       if currentsel == @party.length
  719.         currentsel = plus
  720.       elsif currentsel == numsprites
  721.         currentsel = 0
  722.       end
  723.     when Input::UP
  724.       if currentsel >= plus
  725.         currentsel -= 1
  726.         while currentsel > 0 && currentsel < plus && !@party[currentsel]
  727.           currentsel -= 1
  728.         end
  729.       else
  730.         begin
  731.           currentsel -= div[plus]
  732.         end while currentsel > 0 && !@party[currentsel]
  733.       end
  734.       if currentsel >= @party.length && currentsel < plus
  735.         currentsel = @party.length-1
  736.       end
  737.       currentsel = numsprites - 1 if currentsel < 0
  738.     when Input::DOWN
  739.       if currentsel >= plus - 1
  740.         currentsel += 1
  741.       else
  742.         currentsel += div[plus]
  743.         currentsel = plus if currentsel < plus && !@party[currentsel]
  744.       end
  745.       if currentsel >= @party.length && currentsel < plus
  746.         currentsel = plus
  747.       elsif currentsel >= numsprites
  748.         currentsel = 0
  749.       end
  750.     end
  751.     return currentsel
  752.   end
  753.  
  754.   def pbHardRefresh
  755.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  756.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  757.     oldtext = []
  758.     lastselected = -1
  759.     for i in 0...plus
  760.       oldtext.push(@sprites["pokemon#{i}"].text)
  761.       lastselected = i if @sprites["pokemon#{i}"].selected
  762.       @sprites["pokemon#{i}"].dispose
  763.     end
  764.     lastselected = @party.length-1 if lastselected>=@party.length
  765.     lastselected = 0 if lastselected<0
  766.     for i in 0...plus
  767.       if @party[i]
  768.         @sprites["pokemon#{i}"] = PokemonPartyPanel.new(@party[i],i,@viewport)
  769.       else
  770.         @sprites["pokemon#{i}"] = PokemonPartyBlankPanel.new(@party[i],i,@viewport)
  771.       end
  772.       @sprites["pokemon#{i}"].text = oldtext[i]
  773.     end
  774.     pbSelect(lastselected)
  775.   end
  776.  
  777.   def pbRefresh
  778.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  779.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  780.     for i in 0...plus
  781.       sprite = @sprites["pokemon#{i}"]
  782.       if sprite
  783.         if sprite.is_a?(PokemonPartyPanel)
  784.           sprite.pokemon = sprite.pokemon
  785.         else
  786.           sprite.refresh
  787.         end
  788.       end
  789.     end
  790.   end
  791. end
  792. #===============================================================================
  793. # Pokémon party mechanics
  794. #===============================================================================
  795. class PokemonPartyScreen
  796.   def pbPokemonMultipleEntryScreenEx(ruleset)
  797.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  798.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  799.     annot = []
  800.     statuses = []
  801.     ordinals = [_INTL("INELIGIBLE"), _INTL("NOT ENTERED"), _INTL("BANNED")]
  802.     positions = [_INTL("1st"), _INTL("2nd"), _INTL("3rd"), _INTL("4th"),
  803.                  _INTL("5th"), _INTL("6th"), _INTL("7th"), _INTL("8th"),
  804.                  _INTL("9th"),_INTL("10th"), _INTL("11th"), _INTL("12"),
  805.                  _INTL("13th"), _INTL("14th"), _INTL("15th"), _INTL("16th"),
  806.                  _INTL("17th"), _INTL("18th"), _INTL("19th"), _INTL("20th"),
  807.                  _INTL("21st"), _INTL("22nd"), _INTL("23rd"), _INTL("24th"),
  808.                  _INTL("25th"), _INTL("26th"), _INTL("27th"), _INTL("28th"),
  809.                  _INTL("29th"), _INTL("30th"), _INTL("31st"), _INTL("32nd"),
  810.                  _INTL("33rd"), _INTL("34th"), _INTL("35th"), _INTL("36th"),
  811.                  _INTL("37th"), _INTL("38th"), _INTL("39th"), _INTL("40th"),]
  812.     for i in 0...plus
  813.       if i < positions.length
  814.         ordinals.push(positions[i])
  815.       else
  816.         ordinals.push("#{i + 1}th")
  817.       end
  818.     end
  819.     return nil if !ruleset.hasValidTeam?(@party)
  820.     ret = nil
  821.     addedEntry = false
  822.     for i in 0...@party.length
  823.       statuses[i] = (ruleset.isPokemonValid?(@party[i])) ? 1 : 2
  824.     end
  825.     for i in 0...@party.length
  826.       annot[i] = ordinals[statuses[i]]
  827.     end
  828.     @scene.pbStartScene(@party,_INTL("Choose Pokémon and confirm."),annot,true)
  829.     loop do
  830.       realorder = []
  831.       for i in 0...@party.length
  832.         for j in 0...@party.length
  833.           if statuses[j]==i+3
  834.             realorder.push(j)
  835.             break
  836.           end
  837.         end
  838.       end
  839.       for i in 0...realorder.length
  840.         statuses[realorder[i]] = i+3
  841.       end
  842.       for i in 0...@party.length
  843.         annot[i] = ordinals[statuses[i]]
  844.       end
  845.       @scene.pbAnnotate(annot)
  846.       if realorder.length==ruleset.number && addedEntry
  847.         @scene.pbSelect(plus)
  848.       end
  849.       @scene.pbSetHelpText(_INTL("Choose Pokémon and confirm."))
  850.       pkmnid = @scene.pbChoosePokemon
  851.       addedEntry = false
  852.       if pkmnid == plus   # Confirm was chosen
  853.         ret = []
  854.         for i in realorder; ret.push(@party[i]); end
  855.         error = []
  856.         break if ruleset.isValid?(ret,error)
  857.         pbDisplay(error[0])
  858.         ret = nil
  859.       end
  860.       break if pkmnid<0   # Cancelled
  861.       cmdEntry   = -1
  862.       cmdNoEntry = -1
  863.       cmdSummary = -1
  864.       commands = []
  865.       if (statuses[pkmnid] || 0) == 1
  866.         commands[cmdEntry = commands.length]   = _INTL("Entry")
  867.       elsif (statuses[pkmnid] || 0) > 2
  868.         commands[cmdNoEntry = commands.length] = _INTL("No Entry")
  869.       end
  870.       pkmn = @party[pkmnid]
  871.       commands[cmdSummary = commands.length]   = _INTL("Summary")
  872.       commands[commands.length]                = _INTL("Cancel")
  873.       command = @scene.pbShowCommands(_INTL("Do what with {1}?",pkmn.name),commands) if pkmn
  874.       if cmdEntry>=0 && command==cmdEntry
  875.         if realorder.length>=ruleset.number && ruleset.number>0
  876.           pbDisplay(_INTL("No more than {1} Pokémon may enter.",ruleset.number))
  877.         else
  878.           statuses[pkmnid] = realorder.length+3
  879.           addedEntry = true
  880.           pbRefreshSingle(pkmnid)
  881.         end
  882.       elsif cmdNoEntry>=0 && command==cmdNoEntry
  883.         statuses[pkmnid] = 1
  884.         pbRefreshSingle(pkmnid)
  885.       elsif cmdSummary>=0 && command==cmdSummary
  886.         @scene.pbSummary(pkmnid) {
  887.           @scene.pbSetHelpText((@party.length>1) ? _INTL("Choose a Pokémon.") : _INTL("Choose Pokémon or cancel."))
  888.         }
  889.       end
  890.     end
  891.     @scene.pbEndScene
  892.     return ret
  893.   end
  894. end
  895. #===============================================================================
  896. # Instances of this class are individual Pokémon.
  897. # The player's party Pokémon are stored in the array $Trainer.party.
  898. #===============================================================================
  899. class Pokemon
  900.   attr_writer   :benched
  901.   def benched?
  902.     return @benched
  903.   end
  904.  
  905.   # @return [Boolean] whether the Pokémon is not fainted and not an egg
  906.   def able?
  907.     return !egg? && !benched? && @hp > 0
  908.   end
  909.  
  910.   alias _PPB_initialize initialize
  911.   def initialize(species, level, owner = $Trainer, withMoves = true, recheck_form = true)
  912.     _PPB_initialize(species, level, owner = $Trainer, withMoves = true, recheck_form = true)
  913.     @benched = nil
  914.   end
  915. end
  916. #===============================================================================
  917. #
  918. #===============================================================================
  919. class StorageSystemPC
  920.   def access
  921.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  922.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  923.     pbMessage(_INTL("\\se[PC access]The Pokémon Storage System was opened."))
  924.     command = 0
  925.     loop do
  926.     if plus==1
  927.       command = pbShowCommandsWithHelp(nil,
  928.          [_INTL("Organize Boxes"),
  929.          _INTL("See ya!")],
  930.          [_INTL("Organize the Pokémon in Boxes and in your party."),
  931.          _INTL("Return to the previous menu.")],-1,command
  932.       )
  933.       if command>=0 && command<1
  934.         pbFadeOutIn {
  935.           scene = PokemonStorageScene.new
  936.           screen = PokemonStorageScreen.new(scene,$PokemonStorage)
  937.           screen.pbStartScreen(command)
  938.         }
  939.       else
  940.         break
  941.       end
  942.     else
  943.       command = pbShowCommandsWithHelp(nil,
  944.          [_INTL("Organize Boxes"),
  945.          _INTL("Withdraw Pokémon"),
  946.          _INTL("Deposit Pokémon"),
  947.          _INTL("See ya!")],
  948.          [_INTL("Organize the Pokémon in Boxes and in your party."),
  949.          _INTL("Move Pokémon stored in Boxes to your party."),
  950.          _INTL("Store Pokémon in your party in Boxes."),
  951.          _INTL("Return to the previous menu.")],-1,command
  952.       )
  953.       if command>=0 && command<3
  954.         if command==1   # Withdraw
  955.           if $PokemonStorage.party_full?
  956.             pbMessage(_INTL("Your party is full!"))
  957.             next
  958.           end
  959.         elsif command==2   # Deposit
  960.           count=0
  961.           for p in $PokemonStorage.party
  962.             count += 1 if p && !p.egg? && p.hp>0
  963.           end
  964.           if count<=1
  965.             pbMessage(_INTL("Can't deposit the last Pokémon!"))
  966.             next
  967.           end
  968.         end
  969.         pbFadeOutIn {
  970.           scene = PokemonStorageScene.new
  971.           screen = PokemonStorageScreen.new(scene,$PokemonStorage)
  972.           screen.pbStartScreen(command)
  973.         }
  974.       else
  975.         break
  976.       end
  977.    end
  978.   end
  979.  end
  980. end
  981. #===============================================================================
  982. # Party pop-up panel
  983. #===============================================================================
  984. class PokemonBoxPartySprite < SpriteWrapper
  985.   def initialize(party,viewport=nil)
  986.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  987.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  988.     super(viewport)
  989.     @party = party
  990.     @boxbitmap = AnimatedBitmap.new("Graphics/Pictures/Storage/PartyPlus/"+"#{plus}"+" - overlay_party") if $Trainer.partyplus==true
  991.     @boxbitmap = AnimatedBitmap.new("Graphics/Pictures/Storage/overlay_party") if $Trainer.partyplus==false
  992.     @pokemonsprites = []
  993.     for i in 0...plus
  994.       @pokemonsprites[i] = nil
  995.       pokemon = @party[i]
  996.       if pokemon
  997.         @pokemonsprites[i] = PokemonBoxIcon.new(pokemon,viewport)
  998.       end
  999.     end
  1000. ##########[  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
  1001.     gxd = [182,164,164,182,164,182,164,182,164,224,164,182,224,182,488,356,296,182,432,182,356]
  1002.     gyd = [352,130,130,352,180,352,230,352,280,230,330,352,280,352,180,230,280,352,230,352,280]
  1003.     @contents = BitmapWrapper.new(gxd[plus],gyd[plus]) if $Trainer.partyplus==true
  1004.     @contents = BitmapWrapper.new(172,352) if $Trainer.partyplus==false
  1005.     self.bitmap = @contents
  1006.     self.x = Graphics.width-gxd[plus]-8 if $Trainer.partyplus==true
  1007.     self.y = Graphics.height-gyd[plus] if $Trainer.partyplus==true
  1008.     self.x = 182 if $Trainer.partyplus==false
  1009.     self.y = Graphics.height-352 if $Trainer.partyplus==false
  1010.     pbSetSystemFont(self.bitmap)
  1011.     refresh
  1012.   end
  1013.  
  1014.   def dispose
  1015.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  1016.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  1017.     for i in 0...plus
  1018.       @pokemonsprites[i].dispose if @pokemonsprites[i]
  1019.     end
  1020.     @boxbitmap.dispose
  1021.     @contents.dispose
  1022.     super
  1023.   end
  1024.  
  1025.   def color=(value)
  1026.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  1027.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  1028.     super
  1029.     for i in 0...plus
  1030.       if @pokemonsprites[i] && !@pokemonsprites[i].disposed?
  1031.         @pokemonsprites[i].color = pbSrcOver(@pokemonsprites[i].color,value)
  1032.       end
  1033.     end
  1034.   end
  1035.  
  1036.   def visible=(value)
  1037.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  1038.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  1039.     super
  1040.     for i in 0...plus
  1041.       if @pokemonsprites[i] && !@pokemonsprites[i].disposed?
  1042.         @pokemonsprites[i].visible = value
  1043.       end
  1044.     end
  1045.   end
  1046.  
  1047.   def refresh
  1048.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  1049.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  1050. ##########[  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
  1051.     gxd = [182,164,164,182,164,182,164,182,162,224,164,182,224,182,488,356,296,182,432,182,356]
  1052.     gyd = [352,130,130,352,180,352,230,352,280,230,330,352,280,352,180,230,280,352,230,352,280]
  1053.     if $Trainer.partyplus==true
  1054.      @contents.blt(0, 0, @boxbitmap.bitmap, Rect.new(0, 0, gxd[plus], gyd[plus]))
  1055.     else
  1056.      @contents.blt(0, 0, @boxbitmap.bitmap, Rect.new(0, 0, 172, 352))
  1057.     end
  1058.     pbDrawTextPositions(self.bitmap,[[_INTL("Back"), 86, 240, 2, Color.new(248, 248, 248), Color.new(80, 80, 80), 1]]) if $Trainer.partyplus==false
  1059.     pbDrawTextPositions(self.bitmap,[[_INTL("     "), 86, 240, 2, Color.new(248, 248, 248), Color.new(80, 80, 80), 1]]) if $Trainer.partyplus==true
  1060. ##########[  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
  1061.     pxp = [ 18, 50, 16,  2, 16,  2, 16,  2, 16, 14, 16,  2, 14,  2, 14, 14, 14,  2, 14,  2, 14]
  1062.     pcp = [  2,  2,  2,  2,  2,  2,  2,  2,  2,  3,  2,  2,  3,  2,  7,  5,  4,  2,  6,  2,  5]
  1063.     pig = [  0,  2,  4,  2,  4,  2,  4,  2,  4,  2,  4,  2,  2,  2,  2,  2,  4,  2,  4,  2,  2]
  1064.     xvalues = []   # [18, 90, 18, 90, 18, 90]
  1065.     yvalues = []   # [2, 18, 66, 82, 130, 146]
  1066.     for i in 0...plus
  1067.       #Party Plus Formula
  1068.       xvalues.push(pxp[plus] + (64+pig[plus]) * (i % pcp[plus])) if $Trainer.partyplus==true
  1069.       yvalues.push(2 + 0 * (i % pcp[plus]) + 50 * (i / pcp[plus])) if $Trainer.partyplus==true
  1070.       #Vanilla Formula
  1071.       xvalues.push(18 + 72 * (i % 2)) if $Trainer.partyplus==false
  1072.       yvalues.push(2 + 16 * (i % 2) + 64 * (i / 2)) if $Trainer.partyplus==false
  1073.     end
  1074.     for j in 0...plus
  1075.       @pokemonsprites[j] = nil if @pokemonsprites[j] && @pokemonsprites[j].disposed?
  1076.     end
  1077.     @pokemonsprites.compact!
  1078.     for j in 0...plus
  1079.       sprite = @pokemonsprites[j]
  1080.       if sprite && !sprite.disposed?
  1081.         sprite.viewport = self.viewport
  1082.         sprite.x = self.x + xvalues[j]
  1083.         sprite.y = self.y + yvalues[j]
  1084.         sprite.z = 0
  1085.       end
  1086.     end
  1087.   end
  1088.  
  1089.   def update
  1090.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  1091.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  1092.     super
  1093.     for i in 0...plus
  1094.       @pokemonsprites[i].update if @pokemonsprites[i] && !@pokemonsprites[i].disposed?
  1095.     end
  1096.   end
  1097. end
  1098. #===============================================================================
  1099. # Pokémon storage visuals
  1100. #===============================================================================
  1101. class PokemonStorageScene
  1102.   def pbStartBox(screen,command)
  1103.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  1104.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  1105.     @screen = screen
  1106.     @storage = screen.storage
  1107.     @bgviewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  1108.     @bgviewport.z = 99999
  1109.     @boxviewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  1110.     @boxviewport.z = 99999
  1111.     @boxsidesviewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  1112.     @boxsidesviewport.z = 99999
  1113.     @arrowviewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  1114.     @arrowviewport.z = 99999
  1115.     @viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  1116.     @viewport.z = 99999
  1117.     @selection = 0
  1118.     @quickswap = false
  1119.     @sprites = {}
  1120.     @choseFromParty = false
  1121.     @command = command
  1122.     addBackgroundPlane(@sprites,"background","Storage/bg",@bgviewport)
  1123.     @sprites["box"] = PokemonBoxSprite.new(@storage,@storage.currentBox,@boxviewport)
  1124.     @sprites["boxsides"] = IconSprite.new(0,0,@boxsidesviewport)
  1125.     @sprites["boxsides"].setBitmap("Graphics/Pictures/Storage/overlay_main")
  1126.     @sprites["overlay"] = BitmapSprite.new(Graphics.width,Graphics.height,@boxsidesviewport)
  1127.     pbSetSystemFont(@sprites["overlay"].bitmap)
  1128.     @sprites["pokemon"] = AutoMosaicPokemonSprite.new(@boxsidesviewport)
  1129.     @sprites["pokemon"].setOffset(PictureOrigin::Center)
  1130.     @sprites["pokemon"].x = 90
  1131.     @sprites["pokemon"].y = 134
  1132.     @sprites["boxparty"] = PokemonBoxPartySprite.new(@storage.party,@boxsidesviewport)
  1133.     if command!=2   # Drop down tab only on Deposit
  1134. ############[  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
  1135.       gxd = [182,164,164,182,164,182,164,182,164,224,164,182,224,182,488,356,296,182,432,182,356]
  1136.       @sprites["boxparty"].x = Graphics.width-gxd[plus]-8 if $Trainer.partyplus==true
  1137.       @sprites["boxparty"].x = 182 if $Trainer.partyplus==false
  1138.       @sprites["boxparty"].y = Graphics.height
  1139.     end
  1140.     @markingbitmap = AnimatedBitmap.new("Graphics/Pictures/Storage/markings")
  1141.     @sprites["markingbg"] = IconSprite.new(292,68,@boxsidesviewport)
  1142.     @sprites["markingbg"].setBitmap("Graphics/Pictures/Storage/overlay_marking")
  1143.     @sprites["markingbg"].visible = false
  1144.     @sprites["markingoverlay"] = BitmapSprite.new(Graphics.width,Graphics.height,@boxsidesviewport)
  1145.     @sprites["markingoverlay"].visible = false
  1146.     pbSetSystemFont(@sprites["markingoverlay"].bitmap)
  1147.     @sprites["arrow"] = PokemonBoxArrow.new(@arrowviewport)
  1148.     @sprites["arrow"].z += 1
  1149.     if command!=2
  1150.       pbSetArrow(@sprites["arrow"],@selection)
  1151.       pbUpdateOverlay(@selection)
  1152.       pbSetMosaic(@selection)
  1153.     else
  1154.       pbPartySetArrow(@sprites["arrow"],@selection)
  1155.       pbUpdateOverlay(@selection,@storage.party)
  1156.       pbSetMosaic(@selection)
  1157.     end
  1158.     pbSEPlay("PC access")
  1159.     pbFadeInAndShow(@sprites)
  1160.   end
  1161.  
  1162.   def pbPartySetArrow(arrow,selection)
  1163.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  1164.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  1165.     return if selection < 0
  1166. ##########[  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
  1167.     pbs = [  2,  1,  2,  2,  2,  2,  2,  2,  2,  3,  2,  2,  3,  2,  7,  5,  4,  2,  6,  2,  5]
  1168.     prs = [  3,  1,  1,  2,  2,  2,  3,  2,  4,  3,  5,  2,  4,  2,  2,  3,  4,  2,  6,  2,  5]
  1169.     axp = [200,390,356,  0,356,  0,356,  0,356,294,356,  0,294,  0, 30,162,222,  0, 86,  0,162]
  1170.     ayp = [ 16,224,224,  0,174,  0,124,  0, 74,124, 24,  0, 74,  0,174,124, 74,  0,124,  0, 72]
  1171.     igx = [  0,  2,  4,  0,  4,  0,  4,  0,  4,  2,  4,  0,  2,  0,  2,  2,  4,  0,  4,  0,  2]
  1172.     xvalues = []   # [200, 272, 200, 272, 200, 272, 236]
  1173.     yvalues = []   # [2, 18, 66, 82, 130, 146, 220]
  1174.     for i in 0...plus
  1175.       #Plus Cords
  1176.       xvalues.push(axp[plus] + (igx[plus]+64) * (i % pbs[plus])) if $Trainer.partyplus==true
  1177.       yvalues.push(ayp[plus] + 0 * (i % pbs[plus]) + 50 * (i / pbs[plus])) if $Trainer.partyplus==true
  1178.       #Vanilla Cords
  1179.       xvalues.push(200 + 72 * (i % 2)) if $Trainer.partyplus==false
  1180.       yvalues.push(2 + 16 * (i % 2) + 64 * (i / 2)) if $Trainer.partyplus==false
  1181.     end
  1182.     #Plus Back
  1183. ##########[  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
  1184.     bxp = [236,390,390,  0,390,  0,390,  0,390,360,390,  0,360,  0,228,294,324,  0,256,  0,294]
  1185.     xvalues.push(bxp[plus]) if $Trainer.partyplus==true
  1186.     yvalues.push(280) if $Trainer.partyplus==true
  1187.     #Vanilla Back
  1188.     xvalues.push(236) if $Trainer.partyplus==false
  1189.     yvalues.push(220) if $Trainer.partyplus==false
  1190.     arrow.angle = 0
  1191.     arrow.mirror = false
  1192.     arrow.ox = 0
  1193.     arrow.oy = 0
  1194.     arrow.x = xvalues[selection]
  1195.     arrow.y = yvalues[selection]
  1196.   end
  1197.  
  1198.   def pbPartyChangeSelection(key,selection)
  1199.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  1200.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  1201.     div = [ 2, 1, 2, 2, 2, 2, 2, 2, 2, 3, 2, 2, 3, 2, 7, 5, 4, 2, 6, 2, 5]
  1202.     case key
  1203.     when Input::LEFT
  1204.       selection -= 1
  1205.       selection = plus if selection < 0
  1206.     when Input::RIGHT
  1207.       selection += 1
  1208.       selection = 0 if selection > plus
  1209.     when Input::UP
  1210.       if selection == plus
  1211.         selection = plus - 1
  1212.       else
  1213.         selection -= div[plus]
  1214.         selection = plus if selection < 0
  1215.       end
  1216.     when Input::DOWN
  1217.       if selection == plus
  1218.         selection = 0
  1219.       else
  1220.         selection += div[plus]
  1221.         selection = plus if selection > plus
  1222.       end
  1223.     end
  1224.     return selection
  1225.   end
  1226.  
  1227.   def pbSelectPartyInternal(party,depositing)
  1228.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  1229.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  1230.     selection = @selection
  1231.     pbPartySetArrow(@sprites["arrow"],selection)
  1232.     pbUpdateOverlay(selection,party)
  1233.     pbSetMosaic(selection)
  1234.     lastsel = 1
  1235.     loop do
  1236.       Graphics.update
  1237.       Input.update
  1238.       key = -1
  1239.       key = Input::DOWN if Input.repeat?(Input::DOWN)
  1240.       key = Input::RIGHT if Input.repeat?(Input::RIGHT)
  1241.       key = Input::LEFT if Input.repeat?(Input::LEFT)
  1242.       key = Input::UP if Input.repeat?(Input::UP)
  1243.       if key>=0
  1244.         pbPlayCursorSE
  1245.         newselection = pbPartyChangeSelection(key,selection)
  1246.         if newselection==-1
  1247.           return -1 if !depositing
  1248.         elsif newselection==-2
  1249.           selection = lastsel
  1250.         else
  1251.           selection = newselection
  1252.         end
  1253.         pbPartySetArrow(@sprites["arrow"],selection)
  1254.         lastsel = selection if selection>0
  1255.         pbUpdateOverlay(selection,party)
  1256.         pbSetMosaic(selection)
  1257.       end
  1258.       self.update
  1259.       if Input.trigger?(Input::ACTION) && @command == 0   # Organize only
  1260.         pbPlayDecisionSE
  1261.         pbSetQuickSwap(!@quickswap)
  1262.       elsif Input.trigger?(Input::BACK)
  1263.         @selection = selection
  1264.         return -1
  1265.       elsif Input.trigger?(Input::USE)
  1266.         if selection >= 0 && selection < plus
  1267.           @selection = selection
  1268.           return selection
  1269.         elsif selection == plus   # Close Box
  1270.           @selection = selection
  1271.           return (depositing) ? -3 : -1
  1272.         end
  1273.       end
  1274.     end
  1275.   end
  1276.  
  1277.   def pbShowPartyTab
  1278.     plus = $Trainer.pluscount
  1279. ##########[  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
  1280.     gyd = [352,130,130,  0,180,  0,230,  0,280,230,330,  0,280,  0,180,230,280,  0,230,  0,280]
  1281.     pbSEPlay("GUI storage show party panel")
  1282.     distancePerFrame = 48*20/Graphics.frame_rate
  1283.     loop do
  1284.       Graphics.update
  1285.       Input.update
  1286.       @sprites["boxparty"].y -= distancePerFrame
  1287.       self.update
  1288.       break if @sprites["boxparty"].y<=Graphics.height-gyd[plus]
  1289.     end
  1290.     @sprites["boxparty"].y = Graphics.height-gyd[plus]
  1291.   end
  1292.  
  1293.   def pbHidePartyTab
  1294.     plus = $Trainer.pluscount
  1295. ##########[  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
  1296.     gyd = [352,130,130,  0,180,  0,230,  0,280,230,330,  0,280,  0,180,230,280,  0,230,  0,280]
  1297.     pbSEPlay("GUI storage hide party panel")
  1298.     distancePerFrame = 48*20/Graphics.frame_rate
  1299.     loop do
  1300.       Graphics.update
  1301.       Input.update
  1302.       @sprites["boxparty"].y += distancePerFrame
  1303.       self.update
  1304.       break if @sprites["boxparty"].y>=Graphics.height
  1305.     end
  1306.     @sprites["boxparty"].y = Graphics.height
  1307.   end
  1308.  
  1309.   def maxPokemon(box)
  1310.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  1311.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  1312.     return 0 if box >= self.maxBoxes
  1313.     return (box < 0) ? plus : self[box].length
  1314.   end
  1315.  
  1316.   def pbFirstFreePos(box)
  1317.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  1318.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  1319.     if box==-1
  1320.       ret = self.party.length
  1321.       return (ret >= plus) ? -1 : ret
  1322.     end
  1323.     for i in 0...maxPokemon(box)
  1324.       return i if !self[box,i]
  1325.     end
  1326.     return -1
  1327.   end
  1328. end
  1329. #==============================================================================#
  1330. # Pokemon Storage Calls
  1331. #==============================================================================#
  1332. class PokemonStorage
  1333.   def maxPokemon(box)
  1334.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  1335.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  1336.     return 0 if box >= self.maxBoxes
  1337.     return (box < 0) ? plus : self[box].length
  1338.   end
  1339.  
  1340.   def pbFirstFreePos(box)
  1341.     plus = $Trainer.pluscount if $Trainer.partyplus==true
  1342.     plus = Settings::MAX_PARTY_SIZE if $Trainer.partyplus==false
  1343.     if box==-1
  1344.       ret = self.party.length
  1345.       return (ret >= plus) ? -1 : ret
  1346.     end
  1347.     for i in 0...maxPokemon(box)
  1348.       return i if !self[box,i]
  1349.     end
  1350.     return -1
  1351.   end
  1352. end
  1353. #===============================================================================
  1354. # Individual trainer editor
  1355. #===============================================================================
  1356. module TrainerBattleProperty
  1357.   def self.set(settingname, oldsetting)
  1358.     return nil if !oldsetting
  1359.     properties = [
  1360.        [_INTL("Trainer Type"), TrainerTypeProperty,     _INTL("Name of the trainer type for this Trainer.")],
  1361.        [_INTL("Trainer Name"), StringProperty,          _INTL("Name of the Trainer.")],
  1362.        [_INTL("Version"),      LimitProperty.new(9999), _INTL("Number used to distinguish Trainers with the same name and trainer type.")],
  1363.        [_INTL("Lose Text"),    StringProperty,          _INTL("Message shown in battle when the Trainer is defeated.")]
  1364.     ]
  1365.     Settings::HARD_TEAM_LIMIT.times do |i|
  1366.       properties.push([_INTL("Pokémon {1}", i + 1), TrainerPokemonProperty, _INTL("A Pokémon owned by the Trainer.")])
  1367.     end
  1368.     NUM_ITEMS.times do |i|
  1369.       properties.push([_INTL("Item {1}", i + 1), ItemProperty, _INTL("An item used by the Trainer during battle.")])
  1370.     end
  1371.     return nil if !pbPropertyList(settingname, oldsetting, properties, true)
  1372.     oldsetting = nil if !oldsetting[0]
  1373.     return oldsetting
  1374.   end
  1375. end
  1376. def pbTrainerBattleEditor
  1377.   modified = false
  1378.   pbListScreenBlock(_INTL("Trainer Battles"), TrainerBattleLister.new(0, true)) { |button, trainer_id|
  1379.     if trainer_id
  1380.       if button == Input::ACTION
  1381.         if trainer_id.is_a?(Array)
  1382.           if pbConfirmMessageSerious("Delete this trainer battle?")
  1383.             tr_data = GameData::Trainer::DATA[trainer_id]
  1384.             GameData::Trainer::DATA.delete(trainer_id)
  1385.             GameData::Trainer::DATA.delete(tr_data.id_number)
  1386.             modified = true
  1387.             pbMessage(_INTL("The Trainer battle was deleted."))
  1388.           end
  1389.         end
  1390.       elsif button == Input::USE
  1391.         if trainer_id.is_a?(Array)   # Edit existing trainer
  1392.           tr_data = GameData::Trainer::DATA[trainer_id]
  1393.           old_type = tr_data.trainer_type
  1394.           old_name = tr_data.real_name
  1395.           old_version = tr_data.version
  1396.           data = [
  1397.             tr_data.trainer_type,
  1398.             tr_data.real_name,
  1399.             tr_data.version,
  1400.             tr_data.real_lose_text
  1401.           ]
  1402.           for i in 0...Settings::HARD_TEAM_LIMIT
  1403.             data.push(tr_data.pokemon[i])
  1404.           end
  1405.           for i in 0...TrainerBattleProperty::NUM_ITEMS
  1406.             data.push(tr_data.items[i])
  1407.           end
  1408.           loop do
  1409.             data = TrainerBattleProperty.set(tr_data.real_name, data)
  1410.             break if !data
  1411.             party = []
  1412.             items = []
  1413.             for i in 0...Settings::HARD_TEAM_LIMIT
  1414.               party.push(data[4 + i]) if data[4 + i] && data[4 + i][:species]
  1415.             end
  1416.             for i in 0...TrainerBattleProperty::NUM_ITEMS
  1417.               items.push(data[4 + Settings::HARD_TEAM_LIMIT + i]) if data[4 + Settings::HARD_TEAM_LIMIT + i]
  1418.             end
  1419.             if !data[0]
  1420.               pbMessage(_INTL("Can't save. No trainer type was chosen."))
  1421.             elsif !data[1] || data[1].empty?
  1422.               pbMessage(_INTL("Can't save. No name was entered."))
  1423.             elsif party.length == 0
  1424.               pbMessage(_INTL("Can't save. The Pokémon list is empty."))
  1425.             else
  1426.               trainer_hash = {
  1427.                 :id_number    => tr_data.id_number,
  1428.                 :trainer_type => data[0],
  1429.                 :name         => data[1],
  1430.                 :version      => data[2],
  1431.                 :lose_text    => data[3],
  1432.                 :pokemon      => party,
  1433.                 :items        => items
  1434.               }
  1435.               # Add trainer type's data to records
  1436.               trainer_hash[:id] = [trainer_hash[:trainer_type], trainer_hash[:name], trainer_hash[:version]]
  1437.               GameData::Trainer.register(trainer_hash)
  1438.               if data[0] != old_type || data[1] != old_name || data[2] != old_version
  1439.                 GameData::Trainer::DATA.delete([old_type, old_name, old_version])
  1440.               end
  1441.               modified = true
  1442.               break
  1443.             end
  1444.           end
  1445.         else   # New trainer
  1446.           tr_type = nil
  1447.           ret = pbMessage(_INTL("First, define the new trainer's type."), [
  1448.              _INTL("Use existing type"),
  1449.              _INTL("Create new type"),
  1450.              _INTL("Cancel")], 3)
  1451.           case ret
  1452.           when 0
  1453.             tr_type = pbListScreen(_INTL("TRAINER TYPE"), TrainerTypeLister.new(0, false))
  1454.           when 1
  1455.             tr_type = pbTrainerTypeEditorNew(nil)
  1456.           else
  1457.             next
  1458.           end
  1459.           next if !tr_type
  1460.           tr_name = pbMessageFreeText(_INTL("Now enter the trainer's name."), "", false, 30)
  1461.           next if nil_or_empty?(tr_name)
  1462.           tr_version = pbGetFreeTrainerParty(tr_type, tr_name)
  1463.           if tr_version < 0
  1464.             pbMessage(_INTL("There is no room to create a trainer of that type and name."))
  1465.             next
  1466.           end
  1467.           t = pbNewTrainer(tr_type, tr_name, tr_version, false)
  1468.           if t
  1469.             trainer_hash = {
  1470.               :id_number    => GameData::Trainer::DATA.keys.length / 2,
  1471.               :trainer_type => tr_type,
  1472.               :name         => tr_name,
  1473.               :version      => tr_version,
  1474.               :pokemon      => []
  1475.             }
  1476.             t[3].each do |pkmn|
  1477.               trainer_hash[:pokemon].push({
  1478.                 :species => pkmn[0],
  1479.                 :level   => pkmn[1]
  1480.               })
  1481.             end
  1482.             # Add trainer's data to records
  1483.             trainer_hash[:id] = [trainer_hash[:trainer_type], trainer_hash[:name], trainer_hash[:version]]
  1484.             GameData::Trainer.register(trainer_hash)
  1485.             pbMessage(_INTL("The Trainer battle was added."))
  1486.             modified = true
  1487.           end
  1488.         end
  1489.       end
  1490.     end
  1491.   }
  1492.   if modified && pbConfirmMessage(_INTL("Save changes?"))
  1493.     GameData::Trainer.save
  1494.     pbConvertTrainerData
  1495.   else
  1496.     GameData::Trainer.load
  1497.   end
  1498. end
  1499.  
Add Comment
Please, Sign In to add comment