Advertisement
Vendily

Pokemon Exploration

Jan 2nd, 2019
1,192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.82 KB | None | 0 0
  1. #===============================================================================
  2. # Pokemon Exploration - By Vendily [v17]
  3. #===============================================================================
  4. # This script adds in Pokemon Exploration, where you send off your pokemon to
  5. #  find items. It's loosely based off one of the Poke Pelago Islands.
  6. # Each pokemon in an exploration team has a TREASURERATE% chance of finding an
  7. #  item. The Treasure pool is defined before the expedition begins.
  8. #===============================================================================
  9. # To use it, you must create an event that takes the pokemon, using
  10. #  pbChooseNonEggPokemon to select the pokemon and pbExplorationDeposit to
  11. #  to deposit them, taking the party index as an argument. The script has no
  12. #  restriction on the length of the exploration team, but only 8 pokemon fit on
  13. #  the included display screen. 9 pokemon causes them to get cut in half.
  14. # Next, you must call pbExplorationItemPool with an array of item ids or symbols
  15. #  to define the possible treasure that a pokemon can find. The script picks one
  16. #  at random, so just include duplicate entries to weigh items more or less
  17. #  commonly.
  18. # To start an exploration, call pbExplorationState.pbStart(steps), where steps
  19. #  is the number of steps required to complete the expedition.
  20. # To check if an expedition is complete after starting it, call
  21. #  pbExplorationState.inProgress?, which returns true if there are still more
  22. #  steps remaining.
  23. # After an expedition, call pbRecieveExplorationItems to receive any items found.
  24. #  If the player does not have room, the excess items are lost. To return the
  25. #  pokemon, call pbExplorationChoose, which takes the text to say and the variable
  26. #  to save the selected index, and give the resulting index to
  27. #  pbExplorationWithdraw, which actually returns the pokemon. Neither method
  28. #  checks if there is space in the party, and the latter will raise an error if
  29. #  you give an index that does not exist.
  30. # Included is a display that shows the current party, the remaining steps and the
  31. #  the last item found. call it with
  32. #   pbFadeOutIn(99999){
  33. #     scene =PokemonExploration_Scene.new
  34. #     screen=PokemonExplorationScreen.new(scene)
  35. #     screen.pbStartScreen
  36. #   }
  37. #===============================================================================
  38. # * The percent chance a pokemon will find an item each step. This is per
  39. #    pokemon, not per team, so lower values are recommended. (Default 1)
  40. #===============================================================================
  41.  
  42. TREASURERATE  = 1
  43.  
  44. class ExplorationState
  45.   attr_accessor :party
  46.   attr_accessor :steps
  47.   attr_accessor :startingSteps
  48.   attr_accessor :treasure
  49.   attr_accessor :treasurePool
  50.  
  51.   def initialize
  52.     @party=[]
  53.     @steps=0
  54.     @startingSteps=0
  55.     @inProgress=false
  56.     @treasure=[]
  57.     @treasurePool=[]
  58.   end
  59.  
  60.   def partyCount
  61.     return @party.length
  62.   end
  63.  
  64.   def inProgress?
  65.     return @inProgress
  66.   end
  67.  
  68.   def pbStart(steps)
  69.     @steps=steps
  70.     @startingSteps=steps
  71.     @treasure=[]
  72.     @inProgress=true
  73.   end
  74.  
  75.   def pbEnd
  76.     @steps=0
  77.     @inProgress=false
  78.     @treasurePool=[]
  79.   end
  80.  
  81.   def findTreasure
  82.     if rand(100)<TREASURERATE
  83.       index=rand(@treasurePool.length)
  84.       @treasure.push(@treasurePool[index])
  85.     end
  86.   end
  87.  
  88. end
  89.  
  90. class PokemonGlobalMetadata
  91.   attr_accessor :explorationState
  92. end
  93.  
  94. def pbExplorationState
  95.   if !$PokemonGlobal.explorationState
  96.     $PokemonGlobal.explorationState=ExplorationState.new
  97.   end
  98.   return $PokemonGlobal.explorationState
  99. end
  100.  
  101. def pbExplorationDeposit(index)
  102.   pbExplorationState.party.push($Trainer.party[index])
  103.   pbExplorationState.party[-1].heal
  104.   $Trainer.party[index]=nil
  105.   $Trainer.party.compact!
  106. end
  107.  
  108. def pbExplorationWithdraw(index)
  109.   if !pbExplorationState.party[index]
  110.     raise _INTL("There's no Pokémon here...")
  111.   elsif $Trainer.party.length>=6
  112.     raise _INTL("Can't store the Pokémon...")
  113.   else
  114.     $Trainer.party[$Trainer.party.length]=pbExplorationState.party[index]
  115.     pbExplorationState.party[index]=nil
  116.     pbExplorationState.party.compact!
  117.   end
  118. end
  119.  
  120. def pbExplorationChoose(text,indexvariable,namevariable)
  121.   count=pbExplorationState.partyCount
  122.   if count==0
  123.     raise _INTL("There's no Pokémon here...")
  124.   else
  125.     choices=[]
  126.     for i in 0...count
  127.       pokemon=pbExplorationState.party[i]
  128.       if pokemon.isMale?
  129.         choices.push(_ISPRINTF("{1:s} (♂, Lv{2:d})",pokemon.name,pokemon.level))
  130.       elsif pokemon.isFemale?
  131.         choices.push(_ISPRINTF("{1:s} (♀, Lv{2:d})",pokemon.name,pokemon.level))
  132.       else
  133.         choices.push(_ISPRINTF("{1:s} (Lv{2:d})",pokemon.name,pokemon.level))
  134.       end
  135.     end
  136.     choices.push(_INTL("CANCEL"))
  137.     command=Kernel.pbMessage(text,choices,choices.length)
  138.     $game_variables[indexvariable]=(command==(choices.length-1)) ? -1 : command
  139.     $game_variables[namevariable]=(command==(choices.length-1)) ? -1 :
  140.                       pbExplorationState.party[command].name
  141.   end
  142. end
  143.  
  144. def pbRecieveExplorationItems
  145.   treasure = []
  146.   ret=false
  147.   if pbExplorationState.treasure.length>0
  148.     ret=true
  149.     items=pbExplorationState.treasure
  150.     items.each do |item|
  151.       unless treasure.include?(item)
  152.         treasure.push(item)
  153.         treasure.push(1)  
  154.       else
  155.         temp = treasure.index(item)
  156.         treasure[temp+1] +=1
  157.       end
  158.     end
  159.     while treasure[0]
  160.       item = treasure.shift
  161.       qty = treasure.shift      
  162.       Kernel.pbReceiveItem(item,qty)
  163.     end
  164.   end
  165.   pbExplorationState.treasure=[]
  166.   return ret
  167. end
  168.  
  169. def pbExplorationItemPool(items)
  170.   return if pbExplorationState.inProgress?
  171.   for i in 0...items.length
  172.      items[i]=getID(PBItems,items[i])
  173.   end
  174.   pbExplorationState.treasurePool=items
  175. end
  176.  
  177. class PokemonExploration_Scene
  178.   BACKCOLOUR=Color.new(255,255,162)
  179.   FILLCOLOUR=Color.new(50,170,40)
  180.   def pbUpdate
  181.     pbUpdateSpriteHash(@sprites)
  182.   end
  183.  
  184.   def pbStartScene
  185.     @viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  186.     @viewport.z = 99999
  187.     @sprites = {}
  188.     @sprites["background"] = IconSprite.new(0,0,@viewport)
  189.     @sprites["background"].setBitmap("Graphics/Pictures/Pokegear/bg")
  190.     @sprites["overlay"] = BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
  191.     pbSetSystemFont(@sprites["overlay"].bitmap)
  192.     @sprites["duration"] = BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
  193.     @sprites["elapsed"] = BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
  194.     @sprites["elapsed"].z=100
  195.     @sprites["lastitem"] = ItemIconSprite.new(160,300,-1,@viewport)
  196.     pbDrawExplorers
  197.     pbFadeInAndShow(@sprites) { pbUpdate }
  198.   end
  199.  
  200.   def pbDrawExplorers
  201.     overlay = @sprites["overlay"].bitmap
  202.     overlay.clear
  203.     for i in 0...pbExplorationState.partyCount
  204.       x = 256 - (pbExplorationState.partyCount*32) + (i*64)
  205.       @sprites["pokemon#{i}"]=PokemonIconSprite.new(pbExplorationState.party[i],@viewport)
  206.       @sprites["pokemon#{i}"].x=x
  207.       @sprites["pokemon#{i}"].y=(Graphics.height-96)/2
  208.       @sprites["pokemon#{i}"].mirror=true
  209.     end
  210.     totalsteps=pbExplorationState.startingSteps
  211.     stepstaken=pbExplorationState.steps
  212.     timegauge = (totalsteps==0) ? 448 : stepstaken*448/totalsteps
  213.     @sprites["duration"].bitmap.clear
  214.     @sprites["duration"].bitmap.fill_rect(32,222,448,8,BACKCOLOUR)
  215.     @sprites["elapsed"].bitmap.clear
  216.     @sprites["elapsed"].bitmap.fill_rect(32,222,timegauge,8,FILLCOLOUR)
  217.     lastitem=pbExplorationState.treasure[-1]
  218.     @sprites["lastitem"].item=lastitem ? lastitem : -1
  219.     textpos=[]
  220.     if pbExplorationState.inProgress?
  221.       textpos.push([_INTL("{1} steps remaining",stepstaken),256,236,2,Color.new(232,232,232),Color.new(136,136,136)])
  222.     else
  223.       textpos.push([_INTL("No Exploration"),256,236,2,Color.new(232,232,232),Color.new(136,136,136)])
  224.     end
  225.     if lastitem
  226.       textpos.push([_INTL("Last Item: {1}",PBItems.getName(lastitem)),192,284,0,Color.new(232,232,232),Color.new(136,136,136)])
  227.     end
  228.     pbDrawTextPositions(overlay,textpos)
  229.   end
  230.  
  231.   def pbMiddleScene
  232.     loop do
  233.       Graphics.update
  234.       Input.update
  235.       pbUpdate
  236.       if Input.trigger?(Input::B)
  237.         break
  238.       end
  239.     end
  240.   end
  241.  
  242.   def pbEndScene
  243.     pbFadeOutAndHide(@sprites) { pbUpdate }
  244.     pbDisposeSpriteHash(@sprites)
  245.     @viewport.dispose
  246.   end
  247. end
  248.  
  249.  
  250.  
  251. class PokemonExplorationScreen
  252.   def initialize(scene)
  253.     @scene = scene
  254.   end
  255.  
  256.   def pbStartScreen
  257.     @scene.pbStartScene
  258.     @scene.pbMiddleScene
  259.     @scene.pbEndScene
  260.   end
  261. end
  262.  
  263. Events.onStepTaken+=proc {|sender,e|
  264.   next if !pbExplorationState.inProgress?
  265.   for i in 0...pbExplorationState.partyCount
  266.     pbExplorationState.findTreasure
  267.   end
  268.   pbExplorationState.steps-=1
  269.   if pbExplorationState.steps<=0
  270.     pbExplorationState.pbEnd
  271.   end
  272. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement