Advertisement
TechSkylander1518

Foreign Pokémon v20

Dec 18th, 2022
1,310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 15.19 KB | None | 0 0
  1. module ForeignPokemon
  2.   NPurrloin = {
  3.     :species    => :PURRLOIN,
  4.     :level      => 7,
  5.     :shiny      => false,
  6.     :gender     => 0,
  7.     :ot         => :N,
  8.     :happiness  => 255,
  9.     :nature     => :TIMID,
  10.     :moves      => [:SCRATCH,:GROWL,:ASSIST],
  11.     :iv         => {:HP => 30,
  12.                     :ATTACK => 30,
  13.                     :DEFENSE => 30,
  14.                     :SPECIAL_ATTACK => 30,
  15.                     :SPECIAL_DEFENSE => 30,
  16.                     :SPEED => 30}
  17.   }
  18.  
  19.     NPidove = {
  20.     :species    => :PIDOVE,
  21.     :level      => 13,
  22.     :shiny      => false,
  23.     :gender     => 0,
  24.     :ot         => :N,
  25.     :happiness  => 255,
  26.     :nature     => :SASSY,
  27.     :moves      => [:GUST,:QUICKATTACK,:LEER,:GROWL],
  28.     :iv        => { :HP => 30,
  29.                     :ATTACK => 30,
  30.                     :DEFENSE => 30,
  31.                     :SPECIAL_ATTACK => 30,
  32.                     :SPECIAL_DEFENSE => 30,
  33.                     :SPEED => 30}
  34.   }
  35.  
  36.     NTimburr = {
  37.     :species    => :TIMBURR,
  38.     :level      => 13,
  39.     :shiny      => false,
  40.     :gender     => 0,
  41.     :ot         => :N,
  42.     :happiness  => 255,
  43.     :nature     => :RASH,
  44.     :moves      => [:LEER,:FOCUSENERGY,:BIDE,:LOWKICK],
  45.     :iv        => { :HP => 30,
  46.                     :ATTACK => 30,
  47.                     :DEFENSE => 30,
  48.                     :SPECIAL_ATTACK => 30,
  49.                     :SPECIAL_DEFENSE => 30,
  50.                     :SPEED => 30}
  51.   }
  52.  
  53.     NTympole = {
  54.     :species    => :TYMPOLE,
  55.     :level      => 13,
  56.     :shiny      => false,
  57.     :gender     => 0,
  58.     :ot         => :N,
  59.     :happiness  => 255,
  60.     :nature     => :MODEST,
  61.     :moves      => [:GROWL,:SUPERSONIC,:ROUND,:BUBBLEBEAM],
  62.     :iv        => { :HP => 30,
  63.                     :ATTACK => 30,
  64.                     :DEFENSE => 30,
  65.                     :SPECIAL_ATTACK => 30,
  66.                     :SPECIAL_DEFENSE => 30,
  67.                     :SPEED => 30}
  68.   }
  69.  
  70.     NWoobat = {
  71.     :species    => :WOOBAT,
  72.     :level      => 55,
  73.     :shiny      => false,
  74.     :gender     => 0,
  75.     :ot         => :N,
  76.     :happiness  => 255,
  77.     :nature     => :TIMID,
  78.     :moves      => [:AIRSLASH,:FUTURESIGHT,:PSYCHIC,:ENDEAVOR],
  79.     :iv        => { :HP => 30,
  80.                     :ATTACK => 30,
  81.                     :DEFENSE => 30,
  82.                     :SPECIAL_ATTACK => 30,
  83.                     :SPECIAL_DEFENSE => 30,
  84.                     :SPEED => 30}
  85.   }
  86.  
  87.     NSandile = {
  88.     :species    => :SANDILE,
  89.     :level      => 22,
  90.     :shiny      => false,
  91.     :gender     => 0,
  92.     :ot         => :N,
  93.     :happiness  => 255,
  94.     :nature     => :DOCILE,
  95.     :moves      => [:SANDTOMB,:ASSURANCE,:MUDSLAP,:EMBARGO],
  96.     :iv        => { :HP => 30,
  97.                     :ATTACK => 30,
  98.                     :DEFENSE => 30,
  99.                     :SPECIAL_ATTACK => 30,
  100.                     :SPECIAL_DEFENSE => 30,
  101.                     :SPEED => 30}
  102.   }
  103.  
  104.     NDarumaka = {
  105.     :species    => :DARUMAKA,
  106.     :level      => 22,
  107.     :shiny      => false,
  108.     :gender     => 0,
  109.     :ot         => :N,
  110.     :happiness  => 255,
  111.     :nature     => :NAIVE,
  112.     :moves      => [:HEADBUTT,:UPROAR,:FACADE,:FIREPUNCH],
  113.     :iv        => { :HP => 30,
  114.                     :ATTACK => 30,
  115.                     :DEFENSE => 30,
  116.                     :SPECIAL_ATTACK => 30,
  117.                     :SPECIAL_DEFENSE => 30,
  118.                     :SPEED => 30}
  119.   }
  120.  
  121.     NDarmanitan = {
  122.     :species       => :DARMANITAN,
  123.     :level         => 35,
  124.     :ability_index => 2,
  125.     :shiny         => false,
  126.     :gender        => 0,
  127.     :ot            => :N,
  128.     :happiness     => 255,
  129.     :nature        => :CALM,
  130.     :moves         => [:THRASH,:BELLYDRUM,:FLAREBLITZ,:HAMMERARM],
  131.     :iv            => { :HP => 30,
  132.                     :ATTACK => 30,
  133.                     :DEFENSE => 30,
  134.                     :SPECIAL_ATTACK => 30,
  135.                     :SPECIAL_DEFENSE => 30,
  136.                     :SPEED => 30}
  137.   }
  138.  
  139.     NScraggy = {
  140.     :species    => :SCRAGGY,
  141.     :level      => 22,
  142.     :shiny      => false,
  143.     :gender     => 0,
  144.     :ot         => :N,
  145.     :happiness  => 255,
  146.     :nature     => :LAX,
  147.     :moves      => [:FAINTATTACK,:HEADBUTT,:SWAGGER,:BRICKBREAK],
  148.     :iv        => { :HP => 30,
  149.                     :ATTACK => 30,
  150.                     :DEFENSE => 30,
  151.                     :SPECIAL_ATTACK => 30,
  152.                     :SPECIAL_DEFENSE => 30,
  153.                     :SPEED => 30}
  154.   }
  155.  
  156.     NSigilyph = {
  157.     :species    => :SIGILYPH,
  158.     :level      => 22,
  159.     :shiny      => false,
  160.     :gender     => 0,
  161.     :ot         => :N,
  162.     :happiness  => 255,
  163.     :nature     => :GENTLE,
  164.     :moves      => [:TAILWIND,:WHIRLWIND,:PSYBEAM,:AIRCUTTER],
  165.     :iv        => { :HP => 30,
  166.                     :ATTACK => 30,
  167.                     :DEFENSE => 30,
  168.                     :SPECIAL_ATTACK => 30,
  169.                     :SPECIAL_DEFENSE => 30,
  170.                     :SPEED => 30}
  171.   }
  172.  
  173.     NBoldore = {
  174.     :species    => :BOLDORE,
  175.     :level      => 28,
  176.     :shiny      => false,
  177.     :gender     => 0,
  178.     :ot         => :N,
  179.     :happiness  => 255,
  180.     :nature     => :NAIVE,
  181.     :moves      => [:MUDSLAP,:IRONDEFENSE,:SMACKDOWN,:POWERGEM],
  182.     :iv        => { :HP => 30,
  183.                     :ATTACK => 30,
  184.                     :DEFENSE => 30,
  185.                     :SPECIAL_ATTACK => 30,
  186.                     :SPECIAL_DEFENSE => 30,
  187.                     :SPEED => 30}
  188.   }
  189.  
  190.     NJoltik = {
  191.     :species    => :JOLTIK,
  192.     :level      => 28,
  193.     :shiny      => false,
  194.     :gender     => 0,
  195.     :ot         => :N,
  196.     :happiness  => 255,
  197.     :nature     => :DOCILE,
  198.     :moves      => [:ELECTROWEB,:BUGBITE,:GASTROACID,:SLASH],
  199.     :iv        => { :HP => 30,
  200.                     :ATTACK => 30,
  201.                     :DEFENSE => 30,
  202.                     :SPECIAL_ATTACK => 30,
  203.                     :SPECIAL_DEFENSE => 30,
  204.                     :SPEED => 30}
  205.   }
  206.  
  207.     NFerroseed = {
  208.     :species    => :FERROSEED,
  209.     :level      => 28,
  210.     :shiny      => false,
  211.     :gender     => 0,
  212.     :ot         => :N,
  213.     :happiness  => 255,
  214.     :nature     => :BASHFUL,
  215.     :moves      => [:METALCLAW,:PINMISSILE,:GYROBALL,:IRONDEFENSE],
  216.     :iv        => { :HP => 30,
  217.                     :ATTACK => 30,
  218.                     :DEFENSE => 30,
  219.                     :SPECIAL_ATTACK => 30,
  220.                     :SPECIAL_DEFENSE => 30,
  221.                     :SPEED => 30}
  222.   }
  223.  
  224.     NKlink = {
  225.     :species    => :KLINK,
  226.     :level      => 28,
  227.     :shiny      => false,
  228.     :ot         => :N,
  229.     :happiness  => 255,
  230.     :nature     => :RASH,
  231.     :moves      => [:THUNDERSHOCK,:GEARGRIND,:BIND,:CHARGEBEAM],
  232.     :iv        => { :HP => 30,
  233.                     :ATTACK => 30,
  234.                     :DEFENSE => 30,
  235.                     :SPECIAL_ATTACK => 30,
  236.                     :SPECIAL_DEFENSE => 30,
  237.                     :SPEED => 30}
  238.   }
  239.  
  240. end
  241.  
  242.  
  243. module ForeignOTs
  244.  
  245.  
  246.   N = {
  247.     :name       => "N",
  248.     :gender     => 0,
  249.     :id_number  => 2
  250.   }
  251.  
  252. end
  253.  
  254. module Settings
  255.   # A set of arrays, each containing the details of a foreign Pokémon. The
  256.   # information within each array is as follows:
  257.   #   * Module with Pokémon's data
  258.   #   * Game Switch; the Pokémon can be encountered while this is ON.
  259.   #   * Map(s) the Pokémon can be encountered on.
  260.   #   * Encounter type (0=any, 1=grass/walking in cave, 2=surfing, 3=fishing,
  261.   #     4=surfing/fishing). See the bottom of PField_RoamingPokemon for lists.
  262.   #   * Name of BGM to play for that encounter (optional).
  263.   #   * Chance of being encountered. (out of 100)
  264.   FOREIGN_SPECIES = [
  265.     #[:NPurrloin,2,[66],1,"Battle Elite",100]
  266.   ]
  267.  
  268. end
  269.  
  270.  
  271.  
  272. class PokemonGlobalMetadata
  273.   attr_accessor :foreignEncounter
  274.   attr_accessor :foreignPokemon
  275.   attr_writer   :foreignPokemonCaught
  276.  
  277.   def foreignPokemonCaught
  278.     return @foreignPokemonCaught || []
  279.   end
  280. end
  281.  
  282. #===============================================================================
  283. # Encountering a foreign Pokémon in a wild battle.
  284. #===============================================================================
  285. class Game_Temp
  286.   attr_accessor :foreign_index_for_encounter   # Index of foreign Pokémon to encounter next
  287. end
  288.  
  289. EventHandlers.add(:on_wild_species_chosen, :foreign_pokemon,
  290.   proc { |encounter|
  291.     $game_temp.foreign_index_for_encounter = nil
  292.     $PokemonGlobal.foreignPokemon = [] if !$PokemonGlobal.foreignPokemon
  293.     next if !encounter
  294.     # Give the regular encounter if encountering a foreign Pokémon isn't possible
  295.     next if $PokemonGlobal.partner
  296.     next if $game_temp.poke_radar_data
  297.     # Look at each foreign Pokémon in turn and decide whether it's possible to encounter it
  298.     currentRegion = pbGetCurrentRegion
  299.     currentMapName = $game_map.name
  300.     possible_foreign = []
  301.     Settings::FOREIGN_SPECIES.each_with_index do |data, i|
  302.       # data = [module, Game Switch, maps, encounter method, battle BGM, encounter chance]
  303.       pokedata = ForeignPokemon.const_get(data[0])
  304.       next if !GameData::Species.exists?(pokedata[:species])
  305.       next if data[1] > 0 && !$game_switches[data[1]]   # Isn't active
  306.       next if $PokemonGlobal.foreignPokemon[i] == true   # Foreign Pokémon has been caught
  307.       # Get possible maps
  308.       foreignMaps = data[2]
  309.       if foreignMaps.include?($game_map.map_id)
  310.         match = true
  311.       else
  312.       # If foreign mon isn't on the current map, check if it's on a map with the same
  313.       # name and in the same region
  314.           for i in 0...foreignMaps.length
  315.           testMap = foreignMaps[i]
  316.           map_metadata = GameData::MapMetadata.try_get(testMap)
  317.             if map_metadata && map_metadata.town_map_position &&
  318.                 map_metadata.town_map_position[0] == currentRegion &&
  319.                 pbGetMapNameFromId(testMap) == currentMapName
  320.                   match = true
  321.             end
  322.           end
  323.       end
  324.       next if !match
  325.       # Check whether the encounter method is currently possible
  326.       next if !pbRoamingMethodAllowed(data[3])
  327.       next if !(rand(100) < data[5])
  328.       # Add this foreign Pokémon to the list of possible foreign Pokémon to encounter
  329.       possible_foreign.push([i, data[4]])   # [i, BGM]
  330.     end
  331.     # No encounterable foreign Pokémon were found, just have the regular encounter
  332.     next if possible_foreign.length == 0
  333.     # Pick a foreign Pokémon to encounter out of those available
  334.     foreign = possible_foreign.sample
  335.     $PokemonGlobal.foreignEncounter = foreign
  336.     $game_temp.foreign_index_for_encounter = foreign[0]
  337.     $PokemonGlobal.nextBattleBGM = foreign[1] if foreign[1] && !foreign[1].empty?
  338.     $game_temp.force_single_battle = true
  339.   }
  340. )
  341.  
  342. EventHandlers.add(:on_calling_wild_battle, :foreign_pokemon,
  343.   proc { |species, level, handled|
  344.     # handled is an array: [nil]. If [true] or [false], the battle has already
  345.     # been overridden (the boolean is its outcome), so don't do anything that
  346.     # would override it again
  347.     next if !handled[0].nil?
  348.     next if !$PokemonGlobal.foreignEncounter || $game_temp.foreign_index_for_encounter.nil?
  349.     handled[0] = pbForeignPokemonBattle
  350.   }
  351. )
  352.  
  353. def pbForeignPokemonBattle
  354.   # Get the foreign Pokémon to encounter; generate it based on the species and
  355.   # level if it doesn't already exist
  356.   idxForeign = $game_temp.foreign_index_for_encounter
  357.   if !$PokemonGlobal.foreignPokemon[idxForeign] ||
  358.      !$PokemonGlobal.foreignPokemon[idxForeign].is_a?(Pokemon)
  359.       pokedata = Settings::FOREIGN_SPECIES[idxForeign][0]
  360.       pokedata = ForeignPokemon.const_get(pokedata)
  361.       newpoke = pbGenerateWildPokemon(pokedata[:species],pokedata[:level])
  362.       newpoke.shiny = pokedata[:shiny] if pokedata[:shiny]
  363.       newpoke.name = pokedata[:name] if pokedata[:name]
  364.       newpoke.gender = pokedata[:gender] if pokedata[:gender]
  365.       newpoke.item = pokedata[:item] if pokedata[:item]
  366.       newpoke.nature = pokedata[:nature] if pokedata[:nature]
  367.       newpoke.form = pokedata[:form] if pokedata[:form]
  368.       newpoke.happiness = pokedata[:happiness] if pokedata[:happiness]
  369.       newpoke.sheen = pokedata[:sheen] if pokedata[:sheen]
  370.       newpoke.cool = pokedata[:cool] if pokedata[:cool]
  371.       newpoke.beauty = pokedata[:beauty] if pokedata[:beauty]
  372.       newpoke.cute = pokedata[:cute] if pokedata[:cute]
  373.       newpoke.smart = pokedata[:smart] if pokedata[:smart]
  374.       newpoke.tough = pokedata[:tough] if pokedata[:tough]
  375.       if pokedata[:ribbons]
  376.         for i in 0...pokedata[:ribbons].length
  377.           newpoke.giveRibbon(pokedata[:ribbons][i])
  378.         end
  379.       end
  380.       if pokedata[:pokerus]
  381.         if pokedata[:pokerus].is_a?(Integer)
  382.           newpoke.givePokerus(pokedata[:pokerus])
  383.         else
  384.           newpoke.givePokerus
  385.         end
  386.       end
  387.       newpoke.ability = pokedata[:ability] if pokedata[:ability]
  388.       newpoke.ability_index = pokedata[:ability_index] if pokedata[:ability_index]
  389.       if pokedata[:moves]
  390.         moves = []
  391.         for i in 0...pokedata[:moves].length
  392.             moves.push(Pokemon::Move.new(pokedata[:moves][i]))
  393.         end
  394.         newpoke.moves = moves
  395.       end
  396.       if pokedata[:newmoves]
  397.         for i in 0...pokedata[:newmoves].length
  398.             newpoke.learn_move(pokedata[:newmoves][i])
  399.         end
  400.       end
  401.       newpoke.ev = pokedata[:ev] if pokedata[:ev]
  402.       newpoke.iv = pokedata[:iv] if pokedata[:iv]
  403.       if pokedata[:perf_ivs]
  404.         stats = []
  405.         GameData::Stat.each_main { |s| stats.push(s.id)}
  406.         stats = stats.sample(pokedata[:perf_ivs])
  407.         stats.each do |s|
  408.           newpoke.iv[s] = Pokemon::IV_STAT_LIMIT
  409.         end
  410.       end
  411.       newpoke.memory = pokedata[:memory] if pokedata[:memory]
  412.       if pokedata[:ot]
  413.         trainerdata = ForeignOTs.const_get(pokedata[:ot])
  414.         newpoke.owner.name = trainerdata[:name] if trainerdata[:name]
  415.         newpoke.owner.gender = trainerdata[:gender] if trainerdata[:gender]
  416.         if trainerdata[:id_number]
  417.           id = trainerdata[:id_number]
  418.           newpoke.owner.id = id | (id << 16)
  419.         else
  420.           newpoke.owner.id = $player.make_foreign_ID
  421.         end
  422.         newpoke.owner.language = trainerdata[:language] if trainerdata[:language]
  423.       end
  424.       $PokemonGlobal.foreignPokemon[idxForeign] = newpoke
  425.   end
  426.   if $PokemonGlobal.foreignPokemon[idxForeign].is_a?(Pokemon)
  427.     $PokemonGlobal.foreignPokemon[idxForeign].heal if $PokemonGlobal.foreignPokemon[idxForeign].fainted?
  428.   end
  429.   # Set some battle rules
  430.   setBattleRule("single")
  431.   # Perform the battle
  432.   decision = WildBattle.start_core($PokemonGlobal.foreignPokemon[idxForeign])
  433.   species = $PokemonGlobal.foreignPokemon[idxForeign].species
  434.   level = $PokemonGlobal.foreignPokemon[idxForeign].level
  435.   # Update Foreign Pokémon data based on result of battle
  436.   if decision == 4   # Caught
  437.     $PokemonGlobal.foreignPokemon[idxForeign]       = true
  438.     $PokemonGlobal.foreignPokemonCaught[idxForeign] = (decision == 4)
  439.   end
  440.   $PokemonGlobal.foreignEncounter = nil
  441.   $game_temp.foreign_index_for_encounter = nil
  442.   # Used by the Poké Radar to update/break the chain
  443.   EventHandlers.trigger(:on_wild_battle_end, species, level, decision)
  444.   # Return false if the player lost or drew the battle, and true if any other result
  445.   return (decision != 2 && decision != 5)
  446. end
  447.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement