Advertisement
Guest User

Trade

a guest
Dec 11th, 2015
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 27.98 KB | None | 0 0
  1. ################################################################################
  2. #-------------------------------------------------------------------------------
  3. #Author: Alexandre
  4. #Simple trade system.
  5. #-------------------------------------------------------------------------------
  6. ################################################################################
  7. class Scene_Trade
  8. ################################################################################
  9. #-------------------------------------------------------------------------------
  10. #Author: Alexandre
  11. #Lets initialise the scene:
  12. #@list is the main trade background
  13. #@info is the background that appears when confirming the trade
  14. #-------------------------------------------------------------------------------
  15. ################################################################################
  16.   def initialize(user)
  17.     #--------
  18.     #necessary to make sure both users have started the trade scene before
  19.     #proceeding with the trade
  20. #    $network.send("<TRA start>")
  21. #    loop do
  22. #      Graphics.update
  23. #      Input.update
  24. #      message = $network.listen
  25. #      case message
  26. #      when /<TRA start>/ then break
  27. #      when /<TRA dead>/ then $scene = Scene_Map.new; break
  28. #      end
  29. #    end
  30.     #--------
  31.     @username = user
  32.     @partysent = false
  33.     @pokemonselected = false
  34.     @theirparty = nil
  35.     @theirpartylength = 0
  36.     @theirchosen = nil
  37.     @index = 1
  38.     @viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  39.     @overlay=SpriteWrapper.new(@viewport)
  40.     @overlay.bitmap = Bitmap.new(Graphics.width,Graphics.height)
  41.     @overlay.z = 1000005
  42.     @overlay2=SpriteWrapper.new(@viewport)
  43.     @overlay2.bitmap = Bitmap.new(Graphics.width,Graphics.height)
  44.     @overlay2.z = 1000009
  45.     @overlay3=SpriteWrapper.new(@viewport)
  46.     @overlay3.bitmap = Bitmap.new(Graphics.width,Graphics.height)
  47.     @overlay3.z = 1000009
  48.     @list=SpriteWrapper.new(@viewport)
  49.     @list.visible = true
  50.     @list.bitmap=BitmapCache.load_bitmap("Graphics/Pictures/tradebackground.png")
  51.     @list.z = 1000004
  52.     @selector=SpriteWrapper.new(@viewport)
  53.     @selector.visible = true
  54.     @selector.bitmap=BitmapCache.load_bitmap("Graphics/Pictures/boxpoint1.png")
  55.     @selector.z = 1000006
  56.     @waiting = Window_AdvancedTextPokemon.new("Waiting...")
  57.     @waiting.visible = false
  58.     @waiting.width = 120
  59.     @waiting.x = Graphics.width/2 - 50
  60.     @waiting.y = 160
  61.     @sprite = []
  62.     @spritex = []
  63.     @sprites = {}
  64.     @info=SpriteWrapper.new(@viewport)
  65.     @info.visible = true
  66.     @info.bitmap=BitmapCache.load_bitmap("Graphics/Pictures/tradebottom.png")
  67.     @info.z = 1000008
  68.     @info.visible = false
  69.     @accepted = false
  70.     @received = false
  71.     @listreceived = false
  72.   end
  73. ################################################################################
  74. #-------------------------------------------------------------------------------
  75. #Main procedure of the Scene, contains the loop that keeps it alive. When B is
  76. #pressed, the Trade dead message is sent to the server and the scene is disposed
  77. #-------------------------------------------------------------------------------
  78. ################################################################################
  79.   def main
  80.     mylist
  81.     Graphics.transition
  82.     loop do
  83.       Graphics.update
  84.       Input.update
  85.       update
  86.       if $scene != self
  87.         break
  88.       end
  89.       if Input.trigger?(Input::B)
  90.         $scene = Connect.new
  91.         $network.send("<TRA dead>")
  92.       end
  93.     end
  94.     Graphics.freeze
  95.     @waiting.dispose
  96.     @viewport.dispose
  97.     @list.dispose
  98.     @overlay.dispose
  99.     @overlay2.dispose
  100.     @overlay3.dispose
  101.     @sprite[0].dispose if @sprite[0] != nil
  102.     @sprite[1].dispose if @sprite[1] != nil
  103.     @sprite[2].dispose if @sprite[2] != nil
  104.     @sprite[3].dispose if @sprite[3] != nil
  105.     @sprite[4].dispose if @sprite[4] != nil
  106.     @sprite[5].dispose if @sprite[5] != nil
  107.     @spritex[0].dispose if @spritex[0] != nil
  108.     @spritex[1].dispose if @spritex[1] != nil
  109.     @spritex[2].dispose if @spritex[2] != nil
  110.     @spritex[3].dispose if @spritex[3] != nil
  111.     @spritex[4].dispose if @spritex[4] != nil
  112.     @spritex[5].dispose if @spritex[5] != nil
  113.     @sprites["mypokemon"].dispose if @sprites["mypokemon"] != nil
  114.     @sprites["theirpokemon"].dispose if @sprites["theirpokemon"] != nil
  115.   end
  116. ################################################################################
  117. #-------------------------------------------------------------------------------
  118. #Just a procedure to update the scene and check for any incoming messages
  119. #-------------------------------------------------------------------------------
  120. ################################################################################
  121.   def update
  122.     their_info if @received == true and @pokemonselected == true
  123.     their_list if @listreceived == true
  124.     message = $network.listen
  125.     handle(message)
  126.     @sprite[0].update if @sprite[0] != nil
  127.     @sprite[1].update if @sprite[1] != nil
  128.     @sprite[2].update if @sprite[2] != nil
  129.     @sprite[3].update if @sprite[3] != nil
  130.     @sprite[4].update if @sprite[4] != nil
  131.     @sprite[5].update if @sprite[5] != nil
  132.     @spritex[0].update if @spritex[0] != nil
  133.     @spritex[1].update if @spritex[1] != nil
  134.     @spritex[2].update if @spritex[2] != nil
  135.     @spritex[3].update if @spritex[3] != nil
  136.     @spritex[4].update if @spritex[4] != nil
  137.     @spritex[5].update if @spritex[5] != nil
  138.     @viewport.update
  139.     @overlay.update
  140.     @overlay2.update
  141.     @overlay3.update
  142.     @selector.update
  143.     check_input
  144.     if @pokemonselected == false and @theirparty != nil
  145.       update_selector_input
  146.       update_selector
  147.     end
  148.     @waiting.update
  149.     end
  150. ################################################################################
  151. #-------------------------------------------------------------------------------
  152. #Listens to incoming messages and determines what to do when trade messages are
  153. #received.
  154. #-------------------------------------------------------------------------------
  155. ################################################################################  
  156.   def handle(message)
  157.     case message
  158.       when /<TRA party=(.*)>/ #$Trainer.party dump
  159.         theirparty($1) if @theirparty == nil
  160.       when /<TRA offer=(.*)>/ #Trainer.party[@index - 1] dump
  161.         receiveoffer($1) if @theirchosen == nil
  162.       when /<TRA accepted>/
  163.         execute_trade if @accepted == true
  164.       when /<TRA declined>/ then trade_declined
  165.       when /<TRA dead>/
  166.         Kernel.pbMessage("The user exited the trade.")
  167.         $scene=Connect.new
  168.       end
  169.   end
  170. ################################################################################
  171. #-------------------------------------------------------------------------------
  172. #Checks for input from C to select a pokemon or show the summary.
  173. #-------------------------------------------------------------------------------
  174. ################################################################################  
  175.   def check_input
  176.     #Player's pokemon
  177.     if Input.trigger?(Input::C) and @pokemonselected == false
  178.       if @index >= 1 and @index <= $Trainer.party.length
  179.       commands=[_INTL("Offer"),_INTL("Summary"),_INTL("Cancel")]
  180.       choice=Kernel.pbMessage(_INTL("What do you want to do?"),commands)
  181.       if choice==0
  182.         serialized = [Marshal.dump($Trainer.party[@index - 1])].pack("m").delete("\n")
  183.         $network.send("<TRA offer=" + serialized + ">")
  184.         show_information
  185.         @waiting.visible = true
  186.         @pokemonselected=true
  187.       elsif choice==1
  188.         scene=PokemonSummaryScene.new
  189.         screen=PokemonSummary.new(scene)
  190.         screen.pbStartScreen($Trainer.party,@index - 1)
  191.       elsif choice==2
  192.         #do nothing
  193.       end
  194.     else
  195.       #Other user's pokemon
  196.     commands=[_INTL("Summary"),_INTL("Cancel")]
  197.       choice=Kernel.pbMessage(_INTL("What do you want to do?"),commands)
  198.       if choice==0
  199.         scene=PokemonSummaryScene.new
  200.         screen=PokemonSummary.new(scene)
  201.         screen.pbStartScreen(@theirparty,@index - 1 - $Trainer.party.length)
  202.       elsif choice==1
  203.         #donothing
  204.       end
  205.       end
  206.     end
  207.   end
  208. ################################################################################
  209. #-------------------------------------------------------------------------------
  210. #Checks for left and right input to move selector.
  211. #-------------------------------------------------------------------------------
  212. ################################################################################        
  213.   def update_selector_input
  214.     @index += 1 if Input.trigger?(Input::RIGHT)
  215.     @index += 1 if Input.trigger?(Input::DOWN)
  216.     @index -= 1 if Input.trigger?(Input::LEFT)
  217.     @index -= 1 if Input.trigger?(Input::UP)
  218.     @index = 1 if @index > $Trainer.party.length + @theirparty.length
  219.     @index = $Trainer.party.length + @theirparty.length if @index <= 0
  220.   end
  221. ################################################################################
  222. #-------------------------------------------------------------------------------
  223. #Updates the position of the selector.
  224. #-------------------------------------------------------------------------------
  225. ################################################################################  
  226.   def update_selector
  227.     case @index
  228.     when 1 then @selector.x = 46; @selector.y = 40
  229.     when 2 then @selector.x = 135; @selector.y = 40
  230.     when 3 then @selector.x = 46; @selector.y = 120
  231.     when 4 then @selector.x = 135; @selector.y = 120
  232.     when 5 then @selector.x = 46; @selector.y = 220
  233.     when 6 then @selector.x = 135; @selector.y = 220
  234.     when 7 then @selector.x = 299; @selector.y = 40
  235.     when 8 then @selector.x = 388; @selector.y = 40
  236.     when 9 then @selector.x = 299; @selector.y = 120
  237.     when 10 then @selector.x = 388; @selector.y = 120
  238.     when 11 then @selector.x = 299; @selector.y = 220
  239.     when 12 then @selector.x = 388; @selector.y = 220
  240.     end
  241.   end
  242. ################################################################################
  243. #-------------------------------------------------------------------------------
  244. #Receives the other user's party.
  245. #-------------------------------------------------------------------------------
  246. ################################################################################  
  247.   def theirparty(data)
  248.     @theirparty = Marshal.load(data.unpack("m")[0]) #load serialised party data
  249.     @listreceived = true
  250.   end
  251. ################################################################################
  252. #-------------------------------------------------------------------------------
  253. #Display the other uer's party.
  254. #-------------------------------------------------------------------------------
  255. ################################################################################
  256.   def their_list
  257.     @listreceived = false
  258.    
  259.     @theirpartylength = 1 if @theirparty[0] !=nil
  260.     @theirpartylength = 2 if @theirparty[1] !=nil
  261.     @theirpartylength = 3 if @theirparty[2] !=nil
  262.     @theirpartylength = 4 if @theirparty[3] !=nil
  263.     @theirpartylength = 5 if @theirparty[4] !=nil
  264.     @theirpartylength = 6 if @theirparty[5] !=nil
  265.     for i in 0..@theirpartylength-1
  266.       @spritex[i]= PokemonTradeIcon.new(@theirparty[i].species,@theirparty[i].eggsteps,@theirparty[i].personalID,false,@viewport)
  267.     end
  268.     @spritex[0].x = 284 if @spritex[0] != nil
  269.     @spritex[0].y = 55 if @spritex[0] != nil
  270.     @spritex[1].x = 373 if @spritex[1] != nil
  271.     @spritex[1].y = 55 if @spritex[1] != nil
  272.     @spritex[2].x = 284 if @spritex[2] != nil
  273.     @spritex[2].y = 135 if @spritex[2] != nil
  274.     @spritex[3].x = 373 if @spritex[3] != nil
  275.     @spritex[3].y = 135 if @spritex[3] != nil
  276.     @spritex[4].x = 284 if @spritex[4] != nil
  277.     @spritex[4].y = 235 if @spritex[4] != nil
  278.     @spritex[5].x = 373 if @spritex[5]!= nil
  279.     @spritex[5].y = 235 if @spritex[5] != nil
  280.     @spritex[0].z = 1000005 if @spritex[0] != nil
  281.     @spritex[1].z = 1000005 if @spritex[1] != nil
  282.     @spritex[2].z = 1000005 if @spritex[2] != nil
  283.     @spritex[3].z = 1000005 if @spritex[3] != nil
  284.     @spritex[4].z = 1000005 if @spritex[4] != nil
  285.     @spritex[5].z = 1000005 if @spritex[5] != nil
  286.   end
  287. ################################################################################
  288. #-------------------------------------------------------------------------------
  289. #Show's information about your chosen pokemon.
  290. #-------------------------------------------------------------------------------
  291. ################################################################################  
  292.   def show_information
  293.     @waiting.visible = false
  294.     @info.visible = true
  295.     pkmn = $Trainer.party[@index - 1]
  296.     itemname=pkmn.item==0 ? _INTL("NONE") : PBItems.getName(pkmn.item)
  297.     imagepos = []
  298.     @overlay2.bitmap.clear
  299.     @typebitmap=BitmapCache.load_bitmap(_INTL("Graphics/Pictures/types.png"))
  300.     @sprites["mypokemon"]=SpriteWrapper.new(@viewport)
  301.     @sprites["mypokemon"].bitmap=pbLoadTradeBitmap(pkmn.species,pkmn.eggsteps,pkmn.personalID,pkmn.trainerID)
  302.     @sprites["mypokemon"].mirror = true
  303.     pbPositionPokemonSprite(@sprites["mypokemon"],-10,24)
  304.     @sprites["mypokemon"].z = 1000009
  305.     @sprites["mypokemon"].visible = true
  306.     @chosenpokemon = false
  307.     move0 = pkmn.moves[0].id == 0 ? "--" : PBMoves.getName(pkmn.moves[0].id)
  308.     move1 = pkmn.moves[1].id == 0 ? "--" : PBMoves.getName(pkmn.moves[1].id)
  309.     move2 = pkmn.moves[2].id == 0 ? "--" : PBMoves.getName(pkmn.moves[2].id)
  310.     move3 = pkmn.moves[3].id == 0 ? "--" : PBMoves.getName(pkmn.moves[3].id)
  311.      textpositions = [
  312.  [_INTL("#{pkmn.name}"),40,12,2,Color.new(255,255,255),Color.new(0,0,0)],
  313.  [_INTL("Lv: #{pkmn.level}"),105,0,0,Color.new(255,255,255),Color.new(0,0,0)],
  314.  [_INTL("HP: #{pkmn.hp}/#{pkmn.totalhp}"),105,11,0,Color.new(255,255,255),Color.new(0,0,0)],
  315.  [_INTL("Attack: #{pkmn.attack}"),105,22,0,Color.new(255,255,255),Color.new(0,0,0)],
  316.  [_INTL("Defense: #{pkmn.defense}"),105,33,0,Color.new(255,255,255),Color.new(0,0,0)],
  317.  [_INTL("Speed: #{pkmn.speed}"),105,44,0,Color.new(255,255,255),Color.new(0,0,0)],
  318.  [_INTL("Sp. Att: #{pkmn.spatk}"),105,55,0,Color.new(255,255,255),Color.new(0,0,0)],
  319.  [_INTL("Sp. Def: #{pkmn.spdef}"),105,66,0,Color.new(255,255,255),Color.new(0,0,0)],
  320.  [_INTL("Nature: #{PBNatures.getName(pkmn.nature)}"),105,77,0,Color.new(255,255,255),Color.new(0,0,0)],  
  321.  [_INTL("Ability: #{PBAbilities.getName(pkmn.ability)}"),105,88,0,Color.new(255,255,255),Color.new(0,0,0)],  
  322.  [_INTL("Move 1: #{move0}"),105,99,0,Color.new(255,255,255),Color.new(0,0,0)],  
  323.  [_INTL("Move 2: #{move1}"),105,110,0,Color.new(255,255,255),Color.new(0,0,0)],  
  324.  [_INTL("Move 3: #{move2}"),105,121,0,Color.new(255,255,255),Color.new(0,0,0)],  
  325.  [_INTL("Move 4: #{move3}"),105,132,0,Color.new(255,255,255),Color.new(0,0,0)],  
  326.  [_INTL("Item: #{itemname}"),2,27,0,Color.new(255,255,255),Color.new(0,0,0)],
  327.  ]
  328.   if pkmn.gender==0
  329.     textpositions.push([_INTL("♂"),90,12,false,Color.new(120,184,248),Color.new(0,120,248)])
  330.  elsif pkmn.gender==1
  331.     textpositions.push([_INTL("♀"),90,12,false,Color.new(248,128,128),Color.new(168,24,24)])
  332.  end
  333.   pbSetExtraSmallFont(@overlay2.bitmap)
  334.   pbDrawTextPositions(@overlay2.bitmap,textpositions)
  335.  type1rect=Rect.new(0,pkmn.type1*28,64,28)
  336.  type2rect=Rect.new(0,pkmn.type2*28,64,28)
  337.  @overlay2.bitmap.blt(170,4,@typebitmap,type1rect)
  338.  @overlay2.bitmap.blt(170,4 + 28,@typebitmap,type2rect) if pkmn.type1!=pkmn.type2
  339.  ballimage=sprintf("Graphics/Pictures/ball%02d_0.png",pkmn.ballused)
  340.  imagepos.push([ballimage,-4,124,0,0,-1,-1])
  341.  pbDrawImagePositions(@overlay2.bitmap,imagepos)
  342.  end
  343. ################################################################################
  344. #-------------------------------------------------------------------------------
  345. #Display's the user's party.
  346. #-------------------------------------------------------------------------------
  347. ################################################################################  
  348. def mylist
  349.  textpos = [
  350.  [_INTL("#{$network.username}'s list"),91,14,2,Color.new(255,255,255),Color.new(0,0,0)],
  351.  [_INTL("#{@username}'s list"),390,14,2,Color.new(255,255,255),Color.new(0,0,0)],
  352.  ]
  353.   @overlay.bitmap.font.name=["Pokemon Emerald Small","Arial Narrow","Arial"]
  354.   pbDrawTextPositions(@overlay.bitmap,textpos)
  355.   if @partysent == false
  356.     #we must serialie the data in order to send the whole class then encode
  357.     #in base 64 (and delete the newline that the packing causes) in order for
  358.     #server not to go beserk (serialised data is binary, server does not understand
  359.     #how to receive this data as it is, encoding in base 64 avoids this)
  360.     party = [Marshal.dump($Trainer.party)].pack("m").delete("\n")
  361.     $network.send("<TRA party="+ party +">")
  362.     @partysent = true
  363.   end
  364.   for i in 0..$Trainer.party.length-1
  365.     @sprite[i] = PokemonTradeIcon.new($Trainer.party[i].species,$Trainer.party[i].eggsteps,$Trainer.party[i].personalID,false,@viewport)
  366.   end
  367.     @sprite[0].x = 31 if @sprite[0] != nil
  368.     @sprite[0].y = 55 if @sprite[0] != nil
  369.     @sprite[1].x = 120 if @sprite[1] != nil
  370.     @sprite[1].y = 55 if @sprite[1] != nil
  371.     @sprite[2].x = 31 if @sprite[2] != nil
  372.     @sprite[2].y = 135 if @sprite[2] != nil
  373.     @sprite[3].x = 120 if @sprite[3] != nil
  374.     @sprite[3].y = 135 if @sprite[3] != nil
  375.     @sprite[4].x = 31 if @sprite[4] != nil
  376.     @sprite[4].y = 235 if @sprite[4] != nil
  377.     @sprite[5].x = 120 if @sprite[5] != nil
  378.     @sprite[5].y = 235 if @sprite[5] != nil
  379.     @sprite[0].z = 1000005 if @sprite[0] != nil
  380.     @sprite[1].z = 1000005 if @sprite[1] != nil
  381.     @sprite[2].z = 1000005 if @sprite[2] != nil
  382.     @sprite[3].z = 1000005 if @sprite[3] != nil
  383.     @sprite[4].z = 1000005 if @sprite[4] != nil
  384.     @sprite[5].z = 1000005 if @sprite[5] != nil
  385.   end
  386.  
  387. ################################################################################
  388. #-------------------------------------------------------------------------------
  389. #Receives the data for the other user's chosen pokemon.
  390. #-------------------------------------------------------------------------------
  391. ################################################################################  
  392.   def receiveoffer(data)
  393.     @theirchosen = Marshal.load(data.unpack("m")[0]) #decode base 64 and load serialised data
  394.     @received = true
  395.   end
  396. ################################################################################
  397. #-------------------------------------------------------------------------------
  398. #Displays the information about the other user's chosen pokemon.
  399. #-------------------------------------------------------------------------------
  400. ################################################################################
  401.   def their_info
  402.     @received = false
  403.     @waiting.visible = false
  404.     itemname=@theirchosen.item==0 ? _INTL("NONE") : PBItems.getName(@theirchosen.item)
  405.     @sprites["theirpokemon"].dispose if @sprites["theirpokemon"] != nil
  406.     @sprites["theirpokemon"]=SpriteWrapper.new(@viewport)
  407.     @sprites["theirpokemon"].bitmap=pbLoadTradeBitmap(@theirchosen.species,@theirchosen.eggsteps,@theirchosen.personalID,@theirchosen.trainerID)
  408.     pbPositionPokemonSprite(@sprites["theirpokemon"],368,24)
  409.     @sprites["theirpokemon"].z = 1000009
  410.     @sprites["theirpokemon"].visible = true
  411.     @overlay3.bitmap.clear
  412.     imagepos2 = []
  413.     @typebitmap2=BitmapCache.load_bitmap(_INTL("Graphics/Pictures/types.png"))
  414.     move0x = @theirchosen.moves[0] == 0 ? "--" : PBMoves.getName(@theirchosen.moves[0].id)
  415.     move1x = @theirchosen.moves[1] == 0 ? "--" : PBMoves.getName(@theirchosen.moves[1].id)
  416.     move2x = @theirchosen.moves[2] == 0 ? "--" : PBMoves.getName(@theirchosen.moves[2].id)
  417.     move3x = @theirchosen.moves[3] == 0 ? "--" : PBMoves.getName(@theirchosen.moves[3].id)
  418.     textpositions2 = [
  419.  [_INTL("{1}",@theirchosen.name),440,12,2,Color.new(255,255,255),Color.new(0,0,0)],
  420.  [_INTL("Lv: {1}",@theirchosen.level),257,0,0,Color.new(255,255,255),Color.new(0,0,0)],
  421.  [_INTL("HP: {1}/{2}",@theirchosen.hp,@theirchosen.totalhp),257,11,0,Color.new(255,255,255),Color.new(0,0,0)],
  422.  [_INTL("Attack: {1}",@theirchosen.attack),257,22,0,Color.new(255,255,255),Color.new(0,0,0)],
  423.  [_INTL("Defense: {1}",@theirchosen.defense),257,33,0,Color.new(255,255,255),Color.new(0,0,0)],
  424.  [_INTL("Speed: {1}",@theirchosen.speed),257,44,0,Color.new(255,255,255),Color.new(0,0,0)],
  425.  [_INTL("Sp. Att: {1}",@theirchosen.spatk),257,55,0,Color.new(255,255,255),Color.new(0,0,0)],
  426.  [_INTL("Sp. Def: {1}",@theirchosen.spdef),257,66,0,Color.new(255,255,255),Color.new(0,0,0)],
  427.  [_INTL("Nature: {1}",PBNatures.getName(@theirchosen.nature)),257,77,0,Color.new(255,255,255),Color.new(0,0,0)],  
  428.  [_INTL("Ability: {1}",PBAbilities.getName(@theirchosen.ability)),257,88,0,Color.new(255,255,255),Color.new(0,0,0)],  
  429.  [_INTL("Move 1: {1}",move0x),257,99,0,Color.new(255,255,255),Color.new(0,0,0)],  
  430.  [_INTL("Move 2: {1}",move1x),257,110,0,Color.new(255,255,255),Color.new(0,0,0)],  
  431.  [_INTL("Move 3: {1}",move2x),257,121,0,Color.new(255,255,255),Color.new(0,0,0)],  
  432.  [_INTL("Move 4: {1}",move3x),257,132,0,Color.new(255,255,255),Color.new(0,0,0)],  
  433.  [_INTL("Item: {1}",itemname),383,27,0,Color.new(255,255,255),Color.new(0,0,0)],
  434.  ]
  435.   if @theirchosen.gender == 0
  436.     textpositions2.push([_INTL("♂"),390,12,false,Color.new(120,184,248),Color.new(0,120,248)])
  437.   elsif @theirchosen.gender == 1
  438.     textpositions2.push([_INTL("♀"),390,12,false,Color.new(248,128,128),Color.new(168,24,24)])
  439.  end
  440.   pbSetExtraSmallFont(@overlay3.bitmap)
  441.   pbDrawTextPositions(@overlay3.bitmap,textpositions2)
  442.  type1rect2=Rect.new(0,(@theirchosen.type1)*28,64,28)
  443.  type2rect2=Rect.new(0,(@theirchosen.type2)*28,64,28)
  444.  @overlay3.bitmap.blt(320,4,@typebitmap2,type1rect2)
  445.  @overlay3.bitmap.blt(320,4 + 28,@typebitmap2,type2rect2) if @theirchosen.type1 != @theirchosen.type2
  446.  ballimage=sprintf("Graphics/Pictures/ball%02d_0.png",@theirchosen.ballused)
  447.  imagepos2.push([ballimage,452,124,0,0,-1,-1])
  448.  pbDrawImagePositions(@overlay2.bitmap,imagepos2)
  449.  if Kernel.pbConfirmMessage(_INTL("Trade your #{$Trainer.party[@index - 1].name} for their #{@theirchosen.name}?"))
  450.    @waiting.visible = true
  451.    $network.send("<TRA accepted>")
  452.    @accepted = true
  453.  else
  454.   trade_declined
  455.    $network.send("<TRA declined>")
  456.   end
  457. end
  458. ################################################################################
  459. #-------------------------------------------------------------------------------
  460. #Procedure that is called when the other player declines the trade.
  461. #-------------------------------------------------------------------------------
  462. ################################################################################
  463. def trade_declined
  464.   @waiting.visible = false
  465.   @info.visible=false
  466.   @sprites["mypokemon"].dispose
  467.   @sprites["theirpokemon"].dispose
  468.   @overlay2.bitmap.clear
  469.   @overlay3.bitmap.clear
  470.   @pokemonselected = false
  471.   @theirchosen = nil
  472.   @accepted = false
  473.   @received = false
  474.   @listreceived = false
  475. end
  476. ################################################################################
  477. #-------------------------------------------------------------------------------
  478. #Excutes the trade, this is where the pokemon chosen is modified to the new one.
  479. #-------------------------------------------------------------------------------
  480. ################################################################################
  481. def execute_trade
  482.   @waiting.visible = false
  483.   old = $Trainer.party[@index - 1]
  484.   $Trainer.party[@index - 1] = @theirchosen
  485.   evo=PokemonTradeScene.new
  486.   evo.pbStartScreen(old,@theirchosen,$network.username,@username)
  487.   evo.pbTrade
  488.   evo.pbEndScreen
  489.     $Trainer.seen[@theirchosen.species]=true
  490.   $Trainer.owned[@theirchosen.species]=true
  491.  
  492.   $network.send("<TRA dead>")
  493.   pbSave
  494.   Kernel.pbMessage("Saved the game!")
  495.   $scene = Connect.new
  496.  
  497. end
  498.  
  499. end
  500. ################################################################################
  501. #-------------------------------------------------------------------------------
  502. #Other Essentials based classes and methods needed for the scene to function
  503. #-------------------------------------------------------------------------------
  504. ################################################################################
  505. class PokemonTradeIcon < SpriteWrapper
  506.  attr_accessor :selected
  507.  attr_accessor :active
  508.  attr_reader :pokemon
  509.  def initialize(pokemon,eggsteps,personalID,active,viewport=nil)
  510.   super(viewport)
  511.   @eggsteps = eggsteps
  512.   @personalID = personalID
  513.   @animbitmap=nil
  514.   @frames=[
  515.    Rect.new(0,0,64,64),
  516.    Rect.new(64,0,64,64)
  517.   ]
  518.   @active=active
  519.   @selected=false
  520.   @animframe=0
  521.   self.pokemon=pokemon
  522.   @frame=0
  523.   @pokemon=pokemon
  524.   @spriteX=self.x
  525.   @spriteY=self.y
  526.   @updating=false
  527. end
  528. def width
  529.   return 300
  530. end
  531. def height
  532.   return 300
  533.   end
  534.  def pokemon=(value)
  535.   @animbitmap.dispose if @animbitmap
  536.   @animbitmap=pbLoadTradeIcon(value,@eggsteps,@personalID)
  537.   self.bitmap=@animbitmap
  538.   self.src_rect=@frames[@animframe]
  539.  end
  540.  def dispose
  541.   @animbitmap.dispose
  542.   super
  543. end
  544.  def update
  545.   @updating=true
  546.   super
  547.   frameskip=5
  548.   if frameskip==-1
  549.     @animframe=0
  550.     self.src_rect=@frames[@animframe]
  551.   else
  552.    @frame+=1
  553.    @frame=0 if @frame>100
  554.    if @frame>=frameskip
  555.     @animframe=(@animframe==1) ? 0 : 1
  556.     self.src_rect=@frames[@animframe]
  557.     @frame=0
  558.    end
  559.  end
  560.    if self.selected
  561.    if !self.active
  562.     self.x=@spriteX+8
  563.     self.y=(@animframe==0) ? @spriteY-6 : @spriteY+2
  564.    else
  565.     self.x=@spriteX
  566.     self.y=(@animframe==0) ? @spriteY+2 : @spriteY+10
  567.    end
  568.  end
  569.  end
  570.  def x=(value)
  571.   super
  572.   @spriteX=value if !@updating
  573.  end
  574.  def y=(value)
  575.   super
  576.   @spriteY=value if !@updating
  577.  end
  578. end
  579.  
  580.  def pbLoadTradeIcon(pokemon,eggsteps,personalID)
  581.   return BitmapCache.load_bitmap(pbPokemonTradeFile(pokemon,eggsteps,personalID))
  582.  end
  583.  def pbPokemonTradeFile(pokemon,eggsteps,personalID)
  584.   # return sprintf("Graphics/Pictures/ball00.png")
  585.  
  586.    @pokemon = pokemon.to_i
  587.    @eggsteps = eggsteps.to_i
  588.    @personalID = personalID.to_i
  589.  # if @eggsteps > 1
  590.    # Special case for eggs
  591.  #  return sprintf("Graphics/Pictures/iconEgg.png")
  592.  # end
  593.   if isConst?(@pokemon,PBSpecies,:UNOWN)
  594.    # Special case for Unown
  595.    d=@personalID&3
  596.    d|=((@personalID>>8)&3)<<2
  597.    d|=((@personalID>>16)&3)<<4
  598.    d|=((@personalID>>24)&3)<<6
  599.    d%=28  # index of letter : ABCDEFGHIJKLMNOPQRSTUVWXYZ!?
  600.    filename=sprintf("Graphics/Icons/icon%03d_%02d.png",@pokemon,d)
  601.    begin
  602.     load_data(filename)
  603.     return filename
  604.    rescue Errno::ENOENT, Errno::EACCES, RGSSError
  605.     # File not found, just fall back
  606.    end
  607.   end
  608.   return sprintf("Graphics/Icons/icon%03d.png",pokemon)
  609. end
  610.  
  611. def pbLoadTradeBitmap(species,eggsteps,personalID,trainerID)
  612.   return pbLoadTradeBitmapSpecies(species,eggsteps,personalID,trainerID)
  613. end
  614.  
  615.  def pbLoadTradeBitmapSpecies(species,eggsteps,personalID,trainerID)
  616.       return BitmapCache.load_bitmap(
  617.      sprintf("Graphics/Pictures/ball00.png"))
  618. =begin
  619.   if eggsteps.to_i > 0
  620.    return BitmapCache.load_bitmap(
  621.      sprintf("Graphics/Pictures/egg.png"))
  622.   end
  623.   bitmapFileName=sprintf("Graphics/Battlers/%03d%s.png",species,pbcheckShiny(personalID,trainerID) ? "s" : "")
  624.   if isConst?(species,PBSpecies,:SPINDA)
  625.    bitmap=Bitmap.new(bitmapFileName)
  626.    pbTradeSpindaSpots(pokemon,bitmap)
  627.    return bitmap
  628.   elsif isConst?(species,PBSpecies,:UNOWN)
  629.    d=personalID&3
  630.    d|=((personalID>>8)&3)<<2
  631.    d|=((personalID>>16)&3)<<4
  632.    d|=((personalID>>24)&3)<<6
  633.    d%=28 # index of letter : ABCDEFGHIJKLMNOPQRSTUVWXYZ!?
  634.    begin
  635.     # Load special bitmap if found
  636.     # Example: 201b_02 for the letter C
  637.     return BitmapCache.load_bitmap(
  638.       sprintf("Graphics/Battlers/%03d%s_%02d.png",species,
  639.        pbcheckShiny(personalID,trainerID) ? "s" : "",d)
  640.     )
  641.    rescue
  642.     # Load plain bitmap as usual (see below)
  643.    end
  644.  end
  645.   return BitmapCache.load_bitmap(bitmapFileName)
  646. =end
  647. end
  648.  
  649. def pbSetExtraSmallFont(bitmap)
  650.   bitmap.font.name=["Pokemon Emerald Small","Arial Narrow","Arial"]
  651.   bitmap.font.size=16
  652. end
  653.  
  654. def pbcheckShiny(personalID,trainerID)
  655.  a=personalID.to_i^trainerID.to_i
  656.  b=a&0xFFFF
  657.  c=(a>>16)&0xFFFF
  658.  d=b^c
  659.  return (d<8)
  660. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement