Advertisement
Guest User

GTS?

a guest
Feb 26th, 2013
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.05 KB | None | 0 0
  1. begin
  2.  
  3. class GTS_Scene
  4.  
  5. def pbStartScene
  6.  @sprites={}
  7.  @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
  8.  @viewport.z=99999
  9.  @sprites["overlay"]=Sprite.new(@viewport)
  10.  @sprites["overlay"].bitmap=Bitmap.new(Graphics.width,Graphics.height)
  11.  @sprites["overlay"].z=9999999
  12.  pbSetSystemFont(@sprites["overlay"].bitmap)
  13.  @overlay = @sprites["overlay"].bitmap
  14.  @baseColor=Color.new(0,0,0)
  15.  @shadowColor=Color.new(208-40,208-40,200-40)
  16. end
  17.  
  18. def pbEndScene
  19.   @viewport.dispose
  20. end        
  21.  
  22. def pbUpdate
  23.  
  24.   $mouse.update
  25.   Graphics.update
  26.   Input.update
  27.  
  28. end
  29.  
  30. def pbChooseCommand(commands,cancel=false)
  31.     @commands=commands
  32.     @cancel=cancel
  33.      
  34.     @command_window = Window_CommandPokemon.new(@commands,160)
  35.     @command_window.index = 0
  36.     height=(@commands.length*64)-(28*(@commands.length-1))
  37.     if height<384-124
  38.     @command_window.height=height
  39.     else
  40.     @command_window.height=384-124
  41.     end
  42.     @command_window.width=400
  43.     @command_window.x = Graphics.width
  44.     @command_window.y = (Graphics.height/2)-(@command_window.height/2)
  45.    
  46.     10.times do
  47.       @command_window.x-=@command_window.width/10
  48.       pbWait(1)
  49.     end
  50.      
  51.    
  52.     loop do
  53.       if Input.trigger?(Input::UP) && @command_window.index>0
  54.         @command_window.index-=1
  55.         pbWait(6)
  56.       end
  57.  
  58.       if Input.trigger?(Input::DOWN) && @command_window.index<(@command_window.commands.length-1)
  59.         @command_window.index+=1
  60.         pbWait(6)
  61.       end
  62.            
  63.       if Input.trigger?(Input::C)
  64.         10.times do
  65.          @command_window.x+=@command_window.width/10
  66.          pbWait(1)
  67.         end
  68.         return @command_window.index
  69.       end
  70.      
  71.       if Input.trigger?(Input::B) && @cancel==true
  72.         10.times do
  73.          @command_window.x+=@command_window.width/10
  74.          pbWait(1)
  75.         end
  76.         @command_window.dispose
  77.         return -1
  78.       end
  79.       pbUpdate
  80.     end
  81. end
  82.  
  83. def pbGTS(temp)
  84.  
  85.   gtsfile="./Data/GTS.rxdata"
  86.   target="http://yourhost.com/FTP location/GTS.rxdata"
  87.  
  88.   File.delete(gtsfile) if FileTest.exist?(gtsfile)
  89.  
  90.   pbDownloadToFile(target,gtsfile)
  91.   @file=gtsfile
  92.   Kernel.pbMessage(_INTL("Welcome to the GTS!"))
  93.  
  94.   if FileTest.exist?(@file)
  95.     global=$PokemonGlobal
  96.     File.open(@file){|f|
  97.         $PokemonGlobal.GTS = Marshal.load(f)
  98.     }
  99.     @gtsdata=$PokemonGlobal.GTS
  100.     $PokemonGlobal=global
  101.     trade=false
  102.     index=0
  103.     i=0
  104.     (@gtsdata.length).times do
  105.       trade=true if @gtsdata[i][0][1]==$Trainer.id && @gtsdata[i][3]==true
  106.       index=i if @gtsdata[i][0][1]==$Trainer.id && @gtsdata[i][3]==true
  107.       i+=1
  108.     end
  109.     if trade==true
  110.       Kernel.pbMessage(_INTL("You have a trade pending."))
  111.       if $Trainer.party.length<6
  112.         $Trainer.party.push(@gtsdata[index][1])
  113.         Kernel.pbMessage(_INTL("You recieved {1}'s {2}.",@gtsdata[index][0][0],@gtsdata[index][1].name))
  114.         @gtsdata.delete_at(index)
  115.         $PokemonGlobal.GTS=@gtsdata
  116.         File.open(@file,"wb"){|f|
  117.            Marshal.dump($PokemonGlobal.GTS,f)
  118.         }
  119.         Net::FTP.upload(@file,"GTS.rxdata")
  120.         $PokemonGlobal.GTS=[]    
  121.       else
  122.         Kernel.pbMessage(_INTL("Please free up a Pokemon Slot in your party to proceed."))
  123.       end
  124.     end
  125.   end
  126.  
  127.   Kernel.pbMessage(_INTL("What would you like to do?"))
  128.   @choice=pbChooseCommand(["Put a Pokemon up for Trade","Trade a Pokemon already listed"],true)
  129.   case @choice
  130.     when 0
  131.       Kernel.pbMessage(_INTL("Please select a Pokemon to put up for trade."))
  132.       commands=[]
  133.       i=0
  134.       ($Trainer.party.length).times do
  135.         commands.push($Trainer.party[i].name)
  136.         i+=1
  137.       end
  138.       i=pbChooseCommand(commands)
  139.       @trainer=[$Trainer.name,$Trainer.id,$Trainer.outfit]
  140.       @pokemon=$Trainer.party[i]
  141.       $Trainer.party.delete_at(i)
  142.       Kernel.pbMessage(_INTL("Please type the number of the Species you'd like in return."))
  143.       species=(pbEnterText("Pokemon Number:",1,3,"")).to_i
  144.       Kernel.pbMessage(_INTL("Please type its level."))
  145.       level=(pbEnterText("Pokemon Level:",1,3,"")).to_i
  146.       if Kernel.pbConfirmMessage(_INTL("Would you like a shiny version of that Pokemon?"))
  147.         shiny=true
  148.       else
  149.         shiny=false
  150.       end
  151.       @gtsentry=[@trainer,@pokemon,[species,level],false]
  152.       if FileTest.exist?(@file)
  153.         global=$PokemonGlobal
  154.         File.open(@file){|f|
  155.               $PokemonGlobal.GTS = Marshal.load(f)
  156.         }
  157.         @gtsdata=$PokemonGlobal.GTS
  158.         $PokemonGlobal=global
  159.         @gtsdata.push(@gtsentry)
  160.         $PokemonGlobal.GTS=@gtsdata
  161.         File.open(@file,"wb"){|f|
  162.            Marshal.dump($PokemonGlobal.GTS,f)
  163.         }
  164.         Net::FTP.upload(@file,"GTS.rxdata")
  165.         Kernel.pbMessage(_INTL("Your Trade request has been sent!"))
  166.         $PokemonGlobal.GTS=[]
  167.       else
  168.         @gtsdata=[]
  169.         @gtsdata.push(@gtsentry)
  170.         $PokemonGlobal.GTS=@gtsdata
  171.         File.open(@file,"wb"){|f|
  172.            Marshal.dump($PokemonGlobal.GTS,f)
  173.         }
  174.         Net::FTP.upload(@file,"GTS.rxdata")
  175.         Kernel.pbMessage(_INTL("Your Trade request has been sent!"))
  176.         $PokemonGlobal.GTS=[]        
  177.       end
  178.  
  179.     when 1
  180.       ret=nil
  181.       if FileTest.exist?(@file)
  182.         global=$PokemonGlobal
  183.         File.open(@file){|f|
  184.               $PokemonGlobal.GTS = Marshal.load(f)
  185.         }
  186.         @gtsdata=$PokemonGlobal.GTS
  187.         $PokemonGlobal=global
  188.       end
  189.       if FileTest.exist?(@file) && @gtsdata.length>0
  190.         Kernel.pbMessage(_INTL("Which Pokemon would you like to trade with?"))
  191.         global=$PokemonGlobal
  192.         File.open(@file){|f|
  193.               $PokemonGlobal.GTS = Marshal.load(f)
  194.         }
  195.         @gtsdata=$PokemonGlobal.GTS
  196.         $PokemonGlobal=global
  197.         commands=[]
  198.         i=0
  199.         (@gtsdata.length).times do
  200.           commands.push(@gtsdata[i][1].name)
  201.           i+=1
  202.         end
  203.         i=pbChooseCommand(commands)
  204.         @i2=i
  205.         @tradepoke=@gtsdata[i][1]
  206.         @requestpoke=@gtsdata[i][2]
  207.         if @gtsdata[i][3]==true
  208.           Kernel.pbMessage(_INTL("That trade has already been completed"))
  209.         else
  210.           loop do
  211.             Kernel.pbMessage(_INTL("Please offer up a Pokemon for trade."))
  212.             commands=[]
  213.             i=0
  214.             ($Trainer.party.length).times do
  215.               commands.push($Trainer.party[i].name)
  216.               i+=1
  217.             end
  218.             @i=pbChooseCommand(commands,true)
  219.             @yourpoke=$Trainer.party[@i] if @i>-1
  220.             if @yourpoke && @yourpoke.species==@requestpoke[0] && @yourpoke.level>=@requestpoke[1]
  221.               Kernel.pbMessage(_INTL("The Trade will now begin."))
  222.               $Trainer.party[@i]=@tradepoke
  223.               @gtsdata[@i2][1]=@yourpoke
  224.               @gtsdata[@i2][3]=true
  225.               $PokemonGlobal.GTS=@gtsdata
  226.               File.open(@file,"wb"){|f|
  227.                 Marshal.dump($PokemonGlobal.GTS,f)
  228.               }
  229.               Net::FTP.upload(@file,"GTS.rxdata")
  230.               Kernel.pbMessage(_INTL("The Trade was successful"))
  231.               $PokemonGlobal.GTS=[]
  232.               break
  233.             else
  234.               Kernel.pbMessage(_INTL("Your Pokemon does not match the requirements.")) if @i>-1
  235.             end
  236.             break if @i==-1
  237.           end
  238.         end
  239.       else
  240.         Kernel.pbMessage(_INTL("There currently isn't any GTS data online."))
  241.       end
  242.   when -1
  243.     Kernel.pbMessage(_INTL("We hope to see you again."))
  244.   end
  245.  
  246.  
  247. end
  248.  
  249. end
  250.  
  251. class GTS
  252.  
  253. def initialize(scene)
  254.  @scene=scene
  255. end
  256.  
  257. def pbStartScreen(temp=nil)
  258.  @scene.pbStartScene
  259.  @scene.pbGTS(temp)
  260.  @scene.pbEndScene
  261. end
  262.  
  263. end
  264.  
  265.  
  266. rescue Exception
  267.  
  268. if $!.is_a?(SystemExit) || "#{$!.class}"=="Reset"
  269.  
  270. raise $!
  271.  
  272. else
  273.  
  274. end
  275.  
  276. end
  277.  
  278. # Net module done by Berka
  279.  
  280. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  281. #                   Download & Upload Files with RGSS
  282. #  par berka                      v 2.1                  rgss 1
  283. #                         [url="http://www.rpgmakervx-fr.com&nbsp;&nbsp;"]http://www.rpgmakervx-fr.com&nbsp;&nbsp;[/url]                                    
  284. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  285. # thanks to: [url="http://www.66rpg.com"]http://www.66rpg.com[/url] for documentation on wininet
  286. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  287. # ! do not use ftp which contains privates data
  288. # ! this scripts need ftp account information !
  289. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  290. # Ftp :
  291. #    �–� receive :
  292. #          Net::Ftp.download("dir_on_ftp/file.zip","./Graphics")
  293. #    �–� send :
  294. #          Net::Ftp.upload("./Graphics/file.zip","§dir_on_ftp/file.zip")
  295. #    �–� make directory :
  296. #          Net::Ftp.mkdir("/dir_on_ftp")
  297. #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  298. module Berka
  299.   module NetError
  300.     ErrConIn="Unable to connect to Internet"
  301.     ErrConFtp="Unable to connect to Ftp"
  302.     ErrConHttp="Unable to connect to the Server"
  303.     ErrNoFFtpIn="The file to be download doesn't exist"
  304.     ErrNoFFtpEx="The file to be upload doesn't exist"
  305.     ErrTranHttp="Http Download is failed"
  306.     ErrDownFtp="Ftp Download is failed"
  307.     ErrUpFtp="Ftp Upload is failed"
  308.     ErrNoFile="No file to be download"
  309.     ErrMkdir="Unable to create a new directory"
  310.   end
  311. end
  312. module Net
  313.   W='wininet'
  314.   SPC=Win32API.new('kernel32','SetPriorityClass','pi','i').call(-1,128)
  315.   IOA=Win32API.new(W,'InternetOpenA','plppl','l').call('',0,'','',0)
  316.   IC=Win32API.new(W,'InternetConnectA','lplpplll','l')
  317.   print(Berka::NetErrorErr::ConIn)if IOA==0
  318.   module FTP
  319.     FSCD=Win32API.new(W,'FtpSetCurrentDirectoryA','lp','l')
  320.     FGF=Win32API.new(W,'FtpGetFileA','lppllll','l')
  321.     FPF=Win32API.new(W,'FtpPutFile','lppll','l')
  322.     FCD=Win32API.new(W,'FtpCreateDirectoryA','lp','l')
  323.     module_function    
  324.     def init
  325.       #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
  326.       ftp="ftp.yourhost.com"          #
  327.       port=21                       #  A modifier !
  328.       identifiant="username"            #
  329.       motdepasse="password"         #
  330.       #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-#
  331.       @fb=IC.call(IOA,ftp,port,identifiant,motdepasse,1,0,0)
  332.       ftp,port,identifiant,motdepasse=[nil]*4 # efface les ids par s�curit�
  333.       (print(Berka::NetError::ErrConFtp))if @fb==0
  334.     end
  335.     def download(ext,int='./')
  336.       init if @fb.nil?    
  337.       c=ext.split('/').pop
  338.       if FSCD.call(@fb,ext.gsub(c,''))!=0
  339.         print(Berka::NetErrorErr::ErrDownFtp)if FGF.call(@fb,c,"#{int}/#{c}",0,32,2,0)==0
  340.       else
  341.         print(Berka::NetErrorErr::ErrNoFFtpIn)
  342.       end
  343.     end
  344.     def mkdir(rep)
  345.       init if @fb.nil?
  346.       print(Berka::NetErrorErr::ErrMkdir)if FCD.call(@fb,rep)==0
  347.     end
  348.     def upload(int,ext)
  349.       init if @fb.nil?
  350.       if FSCD.call(@fb,ext)&&File.exist?(int)
  351.         print(Berka::NetErrorErr::ErrUpFtp)if FPF.call(@fb,int,ext,2,0)==0
  352.       else
  353.         print(Berka::NetErrorErr::ErrNoFFtpEx)
  354.       end
  355.     end
  356.   end
  357. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement