TechSkylander1518

Release Not Delete

Jan 20th, 2022 (edited)
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.37 KB | None | 0 0
  1. #To do:
  2. #Make sure the Pokemon is removed from the array when caught (even defeated?)
  3. #Consider how this affects save data compatibility, esp with save call script
  4. #Add to the Trainer memo that they were reunited
  5. #Have a unique message for released encounter
  6.  
  7. class PokemonGlobalMetadata
  8.   attr_accessor :releasedPokemon
  9. end
  10.  
  11. class PokemonStorageScreen
  12.  
  13.   def pbRelease(selected,heldpoke)
  14.     box = selected[0]
  15.     index = selected[1]
  16.     pokemon = (heldpoke) ? heldpoke : @storage[box,index]
  17.     return if !pokemon
  18.     if pokemon.egg?
  19.       pbDisplay(_INTL("You can't release an Egg."))
  20.       return false
  21.     elsif pokemon.mail
  22.       pbDisplay(_INTL("Please remove the mail."))
  23.       return false
  24.     end
  25.     if box==-1 && pbAbleCount<=1 && pbAble?(pokemon) && !heldpoke
  26.       pbPlayBuzzerSE
  27.       pbDisplay(_INTL("That's your last Pokémon!"))
  28.       return
  29.     end
  30.     command = pbShowCommands(_INTL("Release this Pokémon?"),[_INTL("No"),_INTL("Yes")])
  31.     if command==1
  32.       $PokemonGlobal.releasedPokemon = [] if $PokemonGlobal.releasedPokemon == nil
  33.       $PokemonGlobal.releasedPokemon.push(pokemon)
  34.       pkmnname = pokemon.name
  35.       @scene.pbRelease(selected,heldpoke)
  36.       if heldpoke
  37.         @heldpkmn = nil
  38.       else
  39.         @storage.pbDelete(box,index)
  40.       end
  41.       @scene.pbRefresh
  42.       pbDisplay(_INTL("{1} was released.",pkmnname))
  43.       pbDisplay(_INTL("Bye-bye, {1}!",pkmnname))
  44.       @scene.pbRefresh
  45.     end
  46.     return
  47.   end
  48.  
  49. end
  50.  
  51. Events.onWildBattleOverride += proc { |_sender,e|
  52.   handled = e[2]
  53.   next if handled[0]!=nil
  54.   next if $PokemonGlobal.releasedPokemon == nil
  55.   handled[0] = pbReleasedBattle
  56. }
  57.  
  58.  
  59. def pbReleasedBattle
  60.   pokemon = $PokemonGlobal.releasedPokemon.sample
  61.   index = $PokemonGlobal.releasedPokemon.find_index(pokemon)
  62.   species = pokemon.species
  63.   level = pokemon.level
  64.   # Set some battle rules
  65.   setBattleRule("single")
  66.   # Perform the battle
  67.   decision = pbWildBattleCore(pokemon)
  68.   # Update Released Pokémon data based on result of battle
  69.   if decision==1 || decision==4   # Defeated or caught
  70.     $PokemonGlobal.releasedPokemon.delete_at(index)
  71.   end
  72.   # Used by the Poké Radar to update/break the chain
  73.   Events.onWildBattleEnd.trigger(nil,species,level,decision)
  74.   # Return false if the player lost or drew the battle, and true if any other result
  75.   return (decision!=2 && decision!=5)
  76. end
Add Comment
Please, Sign In to add comment