Advertisement
TechSkylander1518

Set Builder NPC backup

May 17th, 2023 (edited)
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 15.04 KB | None | 0 0
  1. #If a Pokemon's base Attack and Special Atk are within this range,
  2. #the Pokemon is considered a mixed attacker. Otherwise, the Pokemon
  3. #will be considered a physical/special attacker, depending on which is higher.
  4. MIXED_ATTACKER_LIMIT = 10
  5.  
  6.  
  7. def pbSetBuilder
  8.  
  9.   if pbConfirmMessage(_INTL("Would you like me to suggest a set for one of your Pokémon?"))
  10.     pbChoosePokemon(1, 3)
  11.     if pbGet(1) < 0 #cancelled
  12.       pbMessage(_INTL("Let me know if you'd like me to suggest a set for your Pokémon."))
  13.       return
  14.     elsif pbGetPokemon(1).egg?
  15.       pbMessage(_INTL("I can't suggest a set for an Egg... Come back to me after you've hatched it."))
  16.       return
  17.     elsif pbGetPokemon(1).shadowPokemon?
  18.       pbMessage(_INTL("Maybe you should focus on purifying your Pokémon first..."))
  19.       return
  20.     end
  21.     poke = pbGetPokemon(1)
  22.     name = poke.name
  23.     species_data = poke.species_data
  24.     species_name = species_data.real_name
  25.     ana = (species_name.starts_with_vowel?) ? "an" : "a"
  26.     type1 = species_data.types[0]
  27.     type2 = (species_data.types.length > 1) ? species_data.types[1] : species_data.types[0]
  28.     #Check base stats to see if physical, special, or mixed attacker
  29.     base_stats = species_data.base_stats
  30.     atk = base_stats[:ATTACK]
  31.     spatk = base_stats[:SPECIAL_ATTACK]
  32.     if (atk - spatk).abs > MIXED_ATTACKER_LIMIT
  33.       if atk > spatk
  34.         attacker = :PHYSICAL
  35.       else
  36.         attacker = :SPECIAL
  37.       end
  38.     else
  39.       attacker = :MIXED
  40.     end
  41.     #Create array of known moves
  42.     knownmoves = []
  43.     poke.moves.each { |m| knownmoves.push(m.id) }
  44.     pbMessage(_INTL("{1} {2}, huh? Hm...",ana.capitalize,species_name))
  45.     #Create arrays of weaknesses, resistances, immunities, and double weaknesses
  46.     weakness = []
  47.     resist = []
  48.     immune = []
  49.     dweakness = []
  50.     GameData::Type.each do |t|
  51.       eff = Effectiveness.calculate(t.id, type1, type2)
  52.       weakness.push(t.id) if Effectiveness.super_effective?(eff)
  53.       resist.push(t.id) if Effectiveness.not_very_effective?(eff)
  54.       immune.push(t.id) if Effectiveness.ineffective?(eff)
  55.       dweakness.push(t.id) if eff > Effectiveness::SUPER_EFFECTIVE_MULTIPLIER
  56.     end
  57.     cover = {}
  58.     GameData::Type.each do |t|
  59.       cover[t.id] = 0
  60.       for i in 0...weakness.length
  61.         weak = weakness[i]
  62.         eff = Effectiveness.calculate(t.id, weak)
  63.         cover[t.id] += 1 if Effectiveness.super_effective?(eff)
  64.       end
  65.     end
  66.     coverbest = []
  67.     cover.each { |k, v|  coverbest.push(k) if v == cover.values.max }
  68.     coverstring = ""
  69.     for i in 0...coverbest.length
  70.       coverbest[i] = GameData::Type.get(coverbest[i]).real_name + "-"
  71.     end
  72.     coverstring = pbArrayToString(coverbest,"or")
  73.     weaktext = (weakness.length > 1) ? "weaknesses" : "weakness"
  74.     pbMessage(_INTL("You'll want a #{coverstring}type move to take care of its #{weaktext}."))
  75.     tutor = species_data.tutor_moves
  76.     level = []
  77.     for i in 0...species_data.moves.length
  78.       level.push(species_data.moves[i][1])
  79.     end
  80.     movepool = tutor + level
  81.     covermove = :HIDDENPOWER
  82.     covermovedata = GameData::Move.get(covermove)
  83.     for i in 0...movepool.length
  84.       movedata = GameData::Move.get(movepool[i])
  85.       next unless coverbest.include?(movedata.type)
  86.       next unless movedata.power > covermovedata.power
  87.       covermove = movepool[i]
  88.       covermovedata = movedata
  89.     end
  90.     pbMessage(_INTL("Your best bet would be #{covermovedata.real_name}."))
  91.     #Forget any useless moves
  92.     useless = [:SPLASH,:HOLDHANDS,:CELEBRATE]
  93.     if useless.intersect?(knownmoves)
  94.       useless = useless & knownmoves
  95.       if useless.length > 1
  96.         pbSymbolArrayNames(useless,:Move)
  97.         uselessstring = pbArrayToString(useless)
  98.         pbMessage(_INTL("You'll definitely want to forget #{uselessstring}."))
  99.         pbMessage(_INTL("They... don't do anything..."))
  100.       else
  101.         movename = GameData::Move.get(useless[0]).real_name
  102.         pbMessage(_INTL("You'll definitely want to forget #{movename}."))
  103.         pbMessage(_INTL("That... doesn't do anything..."))
  104.       end
  105.     end
  106.     #Check if has Spit Up and/or Swallow but not Stockpile
  107.     reqstockpile = [:SPITUP,:SWALLOW]
  108.     if reqstockpile.intersect?(knownmoves) && !poke.hasMove?(:STOCKPILE)
  109.       nostock = reqstockpile & knownmoves
  110.       nostock = pbSymbolArrayNames(nostock,:Move)
  111.       nostock = pbArrayToString(nostock, "or")
  112.       pbMessage(_INTL("#{name} can't make use of #{nostock} without Stockpile."))
  113.     end
  114.     #If Pokemon has Iron Fist, recommend punching moves.
  115.     if poke.hasAbility?(:IRONFIST)
  116.       possiblepunch = []
  117.       GameData::Move.each { |move|
  118.         possiblepunch.push(move.id) if move.flags.any? { |f| f[/^Punching$/i] } && movepool.include?(move.id)
  119.       }
  120.       pbMessage(_INTL("#{name} has Iron Fist, which powers up punching moves..."))
  121.       if possiblepunch.length > 0
  122.         possiblepunch = pbSymbolArrayNames(possiblepunch,:Move)
  123.         possiblepunch = pbArrayToString(possiblepunch, "or")
  124.         pbMessage(_INTL("You might teach it #{possiblepunch}."))
  125.         if GameData::Item.exists?(:PUNCHINGGLOVE)
  126.           pbMessage(_INTL("You might also give it a Punching Glove. That will power up those moves even further, and you'll avoid contact with your targets."))
  127.         end
  128.       else
  129.         pbMessage(_INTL("But it can't actually learn any punching move. Kind of a waste..."))
  130.       end
  131.     end
  132.     pbMessage(_INTL("For a held item..."))
  133.     #Check if species has a Mega Stone
  134.     megastones = []
  135.     GameData::Species.each do |data|
  136.       next if data.species != poke.species || data.unmega_form != poke.form_simple || !data.mega_stone
  137.       megastones.push(data.mega_stone)
  138.     end
  139.     if megastones.length > 0
  140.       megastring = ""
  141.       for i in 0...megastones.length
  142.         name = GameData::Item.get(megastones[i]).real_name
  143.         megastring += (name.starts_with_vowel?) ? "an " : "a "
  144.         megastring += name
  145.         megastring += ", " if coverbest.length > 2 && i < coverbest.length - 1
  146.         megastring += " or " if coverbest.length > 1 && i == coverbest.length - 2
  147.       end
  148.       pbMessage(_INTL("Well, you can never go wrong with #{megastring}."))
  149.     end
  150.     #Recommend berry for double weakness
  151.     if dweakness.length > 0
  152.       conversion_hash = {
  153.           :FIGHTING  => :CHOPLEBERRY,
  154.           :FLYING    => :COBABERRY,
  155.           :POISON    => :KEBIABERRY,
  156.           :GROUND    => :SHUCABERRY,
  157.           :ROCK      => :CHARTIBERRY,
  158.           :BUG       => :TANGABERRY,
  159.           :GHOST     => :KASIBBERRY,
  160.           :STEEL     => :BABIRIBERRY,
  161.           :DARK      => :COLBURBERRY,
  162.           :FIRE      => :OCCABERRY,
  163.           :WATER     => :PASSHOBERRY,
  164.           :GRASS     => :RINDOBERRY,
  165.           :ELECTRIC  => :WACANBERRY,
  166.           :PSYCHIC   => :PAYAPABERRY,
  167.           :ICE       => :YACHEBERRY,
  168.           :DRAGON    => :HABANBERRY,
  169.           :FAIRY     => :ROSELIBERRY
  170.         }
  171.       if dweakness.length > 1
  172.         for i in 0...dweakness.length
  173.           dweak = dweakness[i]
  174.           berry = conversion_hash[dweak]
  175.         end
  176.       else
  177.         berry = conversion_hash[dweakness[0]]
  178.         berry = GameData::Item.get(berry).real_name
  179.         dweak = GameData::Type.get(dweakness[0]).real_name
  180.         pbMessage(_INTL("A #{berry} could be useful, to help #{name}'s double weakness against #{dweak}."))
  181.       end
  182.     end
  183. #      conversion_hash = {
  184. #          :NORMAL    => :SILKSCARF,
  185. #          :FIGHTING  => :BLACKBELT,
  186. #          :FLYING    => :SHARPBEAK,
  187. #          :POISON    => :POISONBARB,
  188. #          :GROUND    => :SOFTSAND,
  189. #          :ROCK      => :HARDSTONE,
  190. #          :BUG       => :SILVERPOWDER,
  191. #          :GHOST     => :SPELLTAG,
  192. #          :STEEL     => :METALCOAT,
  193. #          :DARK      => :BLACKGLASSES,
  194. #          :FIRE      => :CHARCOAL,
  195. #          :WATER     => :MYSTICWATER,
  196. #          :GRASS     => :MIRACLESEED,
  197. #          :ELECTRIC  => :MAGNET,
  198. #          :PSYCHIC   => :TWISTEDSPOON,
  199. #          :ICE       => :NEVERMELTICE,
  200. #          :DRAGON    => :DRAGONFANG,
  201. #          :FAIRY     => :FAIRYFEATHER
  202. #        }
  203. #      conversion_hash = {
  204. #          :DROUGHT      => :Sun,
  205. #          :DRIZZLE      => :Rain,
  206. #          :SNOWWARNING  => :Hail,
  207. #          :SANDSTREAM   => :Sandstorm
  208. #        }
  209. #      conversion_hash = {
  210. #          :SUNNYDAY   => :Sun,
  211. #          :RAINDANCE  => :Rain,
  212. #          :HAIL       => :Hail,
  213. #          :SANDSTORM  => :Sandstorm
  214. #        }
  215. #      conversion_hash = {
  216. #          :Sun        => :HEATROCK,
  217. #          :Rain       => :DAMPROCK,
  218. #          :Hail       => :ICYROCK,
  219. #          :SANDSTORM  => :SMOOTHROCK
  220. #        }
  221.     #Weather rocks
  222.     if poke.hasAbility?(:DROUGHT)
  223.       pbMessage(_INTL("Since #{name} has #{wset}, you might want a #{wrock} to make the #{weather} last longer."))
  224.     end
  225.     #If Pokemon can evolve, suggest Eviolite.
  226.     if species_data.get_evolutions(true).length > 0 && GameData::Item.exists?(:EVIOLITE)
  227.       pbMessage(_INTL("Since #{name} can evolve further, it could hold an Eviolite to raise its Defense and Special Defense by 50%."))
  228.     end
  229.     #If Pokemon has Poison Heal, suggest Toxic Orb
  230.     if poke.hasAbility?(:POISONHEAL) && GameData::Item.exists?(:TOXICORB)
  231.       pbMessage(_INTL("Since #{name} has the Ability Poison Heal, you might consider a Toxic Orb, to inflict bad poisoning on the first turn."))
  232.       pbMessage(_INTL("You've probably guessed from the name, but Poison Heal makes a Pokémon recover HP from poisoning instead of losing it!"))
  233.       pbMessage(_INTL("And you could use Fling to poison your foe, too!")) if poke.hasMove?(:FLING)
  234.       pbMessage(_INTL("And you could pass it onto a foe to poison them, too!")) if [:BESTOW,:TRICK,:SWITCHEROO].intersect?(knownmoves)
  235.       pbMessage(_INTL("Be careful not to lose the Ability in battle, though, or #{name} will start taking damage again."))
  236.     end
  237.     #If Pokemon has Guts and is not Fire-type, suggest Flame Orb
  238.     if poke.hasAbility?(:GUTS) && !poke.hasType?(:FIRE) && GameData::Item.exists?(:FLAMEORB)
  239.       pbMessage(_INTL("Since #{name} has the Ability Guts, you might consider a Flame Orb, to inflict a burn on the first turn."))
  240.       pbMessage(_INTL("It'll still take damage every turn, but it won't suffer the Attack loss - in fact, it'll be boosted by 50%!"))
  241.       pbMessage(_INTL("Being burned means you can't suffer any other major status condition, either - can't be paralyzed, frozen, badly poisoned..."))
  242.       pbMessage(_INTL("And you could use Fling to burn your foe, too!")) if poke.hasMove?(:FLING)
  243.       pbMessage(_INTL("And you could pass it onto a foe to burn them, too!")) if [:BESTOW,:TRICK,:SWITCHEROO].intersect?(knownmoves)
  244.     end
  245.     #Mention Light Clay if knows a move that sets up screens
  246.     if [:REFLECT,:LIGHTCLAY,:AURORAVEIL].intersect?(knownmoves) &&  GameData::Item.exists?(:LIGHTCLAY)
  247.      
  248.     end
  249.     #If weak to Ground, mention Air Balloon
  250.     if weakness.include?(:GROUND) && GameData::Item.exists?(:AIRBALLOON)
  251.       pbMessage(_INTL("An Air Balloon could help take care of that Ground weakness - until it pops, of course."))
  252.       if dweakness.include?(:GROUND)
  253.         pbMessage(_INTL("#{name} is doubly weak to Ground, so I'd definitely consider it."))
  254.       end
  255.     end
  256.     #If doubly weak to Rock, mention
  257.     if dweakness.include?(:ROCK) && GameData::Item.exists?(:HEAVYDUTYBOOTS) && GameData::Move.exists?(:STEALTHROCKS)
  258.       pbMessage(_INTL("If you're facing a foe who uses Stealth Rocks, you might want to look into Heavy-Duty Boots for #{name}. Its double Rock weakness means Stealth Rock will take quite a chunk of its HP."))
  259.     end
  260.     #If weak to Water, mention Luminous Moss
  261.     if weakness.include?(:WATER)
  262.       pbMessage(_INTL("Since #{name} is weak to Water, foes will probably use that against it. You could work that to your advantage with a Luminous Moss."))
  263.       pbMessage(_INTL("It won't stop the damage, but it'll boost your Special Defense by one stage the first time you're hit by a Water-type move."))
  264.       #If also special/mixed attacker, mention Absorb Bulb
  265.       if [:SPECIAL,:MIXED].include?(attacker)
  266.         pbMessage(_INTL("You could also try an Absorb Bulb. Same idea, but it boosts Special Attack rather than Special Defense."))
  267.       end
  268.     end
  269.     #If weak to Electric and physical/mixed attacker, mention Cell Battery
  270.     if weakness.include?(:ELECTRIC) && [:PHYSICAL,:MIXED].include?(attacker) && GameData::Item.exists?(:CELLBATTERY)
  271.       pbMessage(_INTL("Since #{name} is weak to Electric, foes will probably use that against it. You could work that to your advantage with a Cell Battery."))
  272.       pbMessage(_INTL("It won't stop the damage, but it'll boost your Attack by one stage the first time you're hit by an Electric-type move."))
  273.     end
  274.     #Species-specific held items
  275.     case species_data.id
  276.       when :FARFETCHD, :SIRFETCHD
  277.         pbMessage(_INTL("Since #{name} is #{ana} #{species_name}, it could use a Leek to boost its critical hit ratio.")) if GameData::Item.exists?(:LEEK)
  278.       when :PIKACHU
  279.         pbMessage(_INTL("Since #{name} is #{ana} #{species_name}, it could use a Light Ball to boost its Attack and Special Attack."))
  280.       when :DITTO
  281.         pbMessage(_INTL("Since #{name} is #{ana} #{species_name}, it could use a Metal Powder to boost its Defense, or a Quick Powder to boost its Speed."))
  282.         pbMessage(_INTL("These don't work after using Transform, though - it's mostly just to make sure you get a chance to use it."))
  283.       when :CHANSEY
  284.         pbMessage(_INTL("Since #{name} is #{ana} #{species_name}, it could use a Lucky Punch to boost its critical hit ratio."))
  285.       when :CUBONE, :MAROWAK
  286.         pbMessage(_INTL("Since #{name} is #{ana} #{species_name}, it could use a Thick Club to boost its Attack."))
  287.       when :SILVALLY
  288.         pbMessage(_INTL("Well, the neat thing about Silvally is that its RKS System lets it change to any type, as long as it's holding the right Memory."))
  289.     end
  290.     #If Poison-type, mention Black Sludge
  291.     if species_data.types.include?(:POISON)
  292.       pbMessage(_INTL("Since #{name} is Poison-type, it could hold a Black Sludge. It restores HP each turn, just like Leftovers, but if another Pokémon steals it and they're not Poison-type themselves, they'll take damage!"))
  293.     end
  294.     #If Pokemon knows any sound moves and is a special/mixed attacker, mention Throat Spray
  295.     if GameData::Item.exists?(:THROATSPRAY) && [:SPECIAL,:MIXED].include?(attacker)
  296.       knownsoundmoves = []
  297.       poke.moves.each { |m| knownsoundmoves.push(m.id) if m.flags.any? { |f| f[/^Sound$/i]} }
  298.       if knownsoundmoves.length > 0
  299.         knownsoundmoves = pbSymbolArrayNames(knownsoundmoves,:Move)
  300.         knownsoundmoves = pbArrayToString(knownsoundmoves, "or")
  301.         pbMessage(_INTL("Throat Spray raises a Pokémon's Special Attack after using a sound-based move, although it's consumed after use. #{name} could use it after using #{knownsoundmoves}."))
  302.       end
  303.     end
  304.   #Player said "No" to initial question
  305.   else
  306.     pbMessage(_INTL("Let me know if you'd like me to suggest a set for your Pokémon."))
  307.   end  
  308. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement