Advertisement
TechSkylander1518

Semi Safari

Apr 8th, 2022
1,264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.94 KB | None | 0 0
  1. def pbTotalPokeBalls
  2.   total = 0
  3.   GameData::Item.each do |i|
  4.     total += $PokemonBag.pbQuantity(i)if i.is_poke_ball?
  5.   end
  6.   return total
  7. end
  8.  
  9. def pbBattleOnStepTaken(repel_active)
  10.   #return if $Trainer.able_pokemon_count == 0
  11.   return if !$PokemonEncounters.encounter_possible_here?
  12.   encounter_type = $PokemonEncounters.encounter_type
  13.   return if !encounter_type
  14.   return if !$PokemonEncounters.encounter_triggered?(encounter_type, repel_active)
  15.   $PokemonTemp.encounterType = encounter_type
  16.   encounter = $PokemonEncounters.choose_wild_pokemon(encounter_type)
  17.   encounter = EncounterModifier.trigger(encounter)
  18.   if $PokemonEncounters.allow_encounter?(encounter, repel_active)
  19.     if $Trainer.able_pokemon_count == 0
  20.       pbTrainerWildBattle(encounter[0], encounter[1])
  21.     elsif $PokemonEncounters.have_double_wild_battle?
  22.       encounter2 = $PokemonEncounters.choose_wild_pokemon(encounter_type)
  23.       encounter2 = EncounterModifier.trigger(encounter2)
  24.       pbDoubleWildBattle(encounter[0], encounter[1], encounter2[0], encounter2[1])
  25.     else
  26.       pbWildBattle(encounter[0], encounter[1])
  27.     end
  28.     $PokemonTemp.encounterType = nil
  29.     $PokemonTemp.encounterTriggered = true
  30.   end
  31.   $PokemonTemp.forceSingleBattle = false
  32.   EncounterModifier.triggerEncounterEnd
  33. end
  34.  
  35.  
  36. def pbTrainerWildBattle(species,level)
  37.   # Generate a wild Pokémon based on the species and level
  38.   pkmn = pbGenerateWildPokemon(species,level)
  39.   foeParty = [pkmn]
  40.   # Calculate who the trainer is
  41.   playerTrainer = $Trainer
  42.   # Create the battle scene (the visual side of it)
  43.   scene = pbNewBattleScene
  44.   # Create the battle class (the mechanics side of it)
  45.   battle = PokeBattle_WildTrainer.new(scene,playerTrainer,foeParty)
  46.   #battle.ballCount = pbSafariState.ballcount
  47.   pbPrepareBattle(battle)
  48.   # Perform the battle itself
  49.   decision = 0
  50.   pbBattleAnimation(pbGetWildBattleBGM(foeParty),0,foeParty) {
  51.     pbSceneStandby {
  52.       decision = battle.pbStartBattle
  53.     }
  54.   }
  55.   Input.update
  56.   # Update Safari game data based on result of battle
  57.   #pbSafariState.ballcount = battle.ballCount
  58.   #if pbSafariState.ballcount<=0
  59.     #if decision!=2   # Last Safari Ball was used to catch the wild Pokémon
  60.     #  pbMessage(_INTL("Announcer: You're out of Safari Balls! Game over!"))
  61.     #end
  62.     #pbSafariState.decision = 1
  63.    # pbSafariState.pbGoToStart
  64.   #end
  65.   # Save the result of the battle in Game Variable 1
  66.   #    0 - Undecided or aborted
  67.   #    2 - Player ran out of Safari Balls
  68.   #    3 - Player or wild Pokémon ran from battle, or player forfeited the match
  69.   #    4 - Wild Pokémon was caught
  70.   #pbSet(1,decision)
  71.   # Used by the Poké Radar to update/break the chain
  72.   Events.onWildBattleEnd.trigger(nil,species,level,decision)
  73.   # Return the outcome of the battle
  74.   return decision
  75. end
  76.  
  77.  
  78.  
  79. #===============================================================================
  80. # Data box for safari battles
  81. #===============================================================================
  82. class WildTrainerDataBox < SpriteWrapper
  83.   attr_accessor :selected
  84.  
  85.   def initialize(battle,viewport=nil)
  86.     super(viewport)
  87.     @selected    = 0
  88.     @battle      = battle
  89.     @databox     = AnimatedBitmap.new("Graphics/Pictures/Battle/databox_trainerwild")
  90.     self.x       = Graphics.width - 232
  91.     self.y       = Graphics.height - 184
  92.     @contents    = BitmapWrapper.new(@databox.width,@databox.height)
  93.     self.bitmap  = @contents
  94.     self.visible = false
  95.     self.z       = 50
  96.     pbSetSystemFont(self.bitmap)
  97.     refresh
  98.   end
  99.  
  100.   def refresh
  101.     self.bitmap.clear
  102.     self.bitmap.blt(0,0,@databox.bitmap,Rect.new(0,0,@databox.width,@databox.height))
  103.     base   = Color.new(72,72,72)
  104.     shadow = Color.new(184,184,184)
  105.     textpos = []
  106.     textpos.push([_INTL("Poké Balls"),30,2,false,base,shadow])
  107.     textpos.push([_INTL("Left: {1}",@battle.ballCount),30,32,false,base,shadow])
  108.     pbDrawTextPositions(self.bitmap,textpos)
  109.   end
  110.  
  111.   def update(frameCounter=0)
  112.     super()
  113.   end
  114. end
  115.  
  116.  
  117.  
  118.  
  119.  
  120. #===============================================================================
  121. # Safari Zone battle scene (the visuals of the battle)
  122. #===============================================================================
  123. class PokeBattle_Scene
  124.   def pbWildTrainerStart
  125.     @briefMessage = false
  126.     @sprites["dataBox_0"] = WildTrainerDataBox.new(@battle,@viewport)
  127.     dataBoxAnim = DataBoxAppearAnimation.new(@sprites,@viewport,0)
  128.     loop do
  129.       dataBoxAnim.update
  130.       pbUpdate
  131.       break if dataBoxAnim.animDone?
  132.     end
  133.     dataBoxAnim.dispose
  134.     pbRefresh
  135.   end
  136.  
  137.   #def pbSafariCommandMenu(index)
  138.   #  pbCommandMenuEx(index,[
  139.   #     _INTL("What will\n{1} throw?",@battle.pbPlayer.name),
  140.   #     _INTL("Ball"),
  141.   #     _INTL("Bait"),
  142.   #     _INTL("Rock"),
  143.   #     _INTL("Run")
  144.   #  ],3)
  145.   #end
  146.  
  147.   #def pbThrowBait
  148.   #  @briefMessage = false
  149.   #  baitAnim = ThrowBaitAnimation.new(@sprites,@viewport,@battle.battlers[1])
  150.   #  loop do
  151.   #    baitAnim.update
  152.   #    pbUpdate
  153.   #    break if baitAnim.animDone?
  154.   #  end
  155.   #  baitAnim.dispose
  156.   #end
  157.  
  158.   #def pbThrowRock
  159.   #  @briefMessage = false
  160.   #  rockAnim = ThrowRockAnimation.new(@sprites,@viewport,@battle.battlers[1])
  161.   #  loop do
  162.   #    rockAnim.update
  163.   #    pbUpdate
  164.   #    break if rockAnim.animDone?
  165.   #  end
  166.   #  rockAnim.dispose
  167.   #end
  168.  
  169.   #alias __safari__pbThrowSuccess pbThrowSuccess
  170.   #def pbThrowSuccess
  171.   #  __safari__pbThrowSuccess
  172.   #  pbWildBattleSuccess if @battle.is_a?(PokeBattle_SafariZone)
  173.   #end
  174. end
  175.  
  176.  
  177.  
  178. #===============================================================================
  179. # Safari Zone battle class
  180. #===============================================================================
  181. class PokeBattle_WildTrainer
  182.   attr_reader   :battlers         # Array of fake battler objects
  183.   attr_accessor :sideSizes        # Array of number of battlers per side
  184.   attr_accessor :backdrop         # Filename fragment used for background graphics
  185.   attr_accessor :backdropBase     # Filename fragment used for base graphics
  186.   attr_accessor :time             # Time of day (0=day, 1=eve, 2=night)
  187.   attr_accessor :environment      # Battle surroundings (for mechanics purposes)
  188.   attr_reader   :weather
  189.   attr_reader   :player
  190.   attr_accessor :party2
  191.   attr_accessor :canRun           # True if player can run from battle
  192.   attr_accessor :canLose          # True if player won't black out if they lose
  193.   attr_accessor :switchStyle      # Switch/Set "battle style" option
  194.   attr_accessor :showAnims        # "Battle scene" option (show anims)
  195.   attr_accessor :expGain          # Whether Pokémon can gain Exp/EVs
  196.   attr_accessor :moneyGain        # Whether the player can gain/lose money
  197.   attr_accessor :rules
  198.   attr_accessor :ballCount
  199.  
  200.   include PokeBattle_BattleCommon
  201.  
  202.   def pbRandom(x); return rand(x); end
  203.  
  204.   #=============================================================================
  205.   # Initialize the battle class
  206.   #=============================================================================
  207.   def initialize(scene,player,party2)
  208.     @scene         = scene
  209.     @peer          = PokeBattle_BattlePeer.create()
  210.     @backdrop      = ""
  211.     @backdropBase  = nil
  212.     @time          = 0
  213.     @environment   = :None   # e.g. Tall grass, cave, still water
  214.     @weather       = :None
  215.     @decision      = 0
  216.     @caughtPokemon = []
  217.     @player        = [player]
  218.     @party2        = party2
  219.     @sideSizes     = [1,1]
  220.     @battlers      = [
  221.        PokeBattle_FakeBattler.new(self,0),
  222.        PokeBattle_FakeBattler.new(self,1)
  223.     ]
  224.     @rules         = {}
  225.     @ballCount     = pbTotalPokeBalls
  226.   end
  227.  
  228.   def defaultWeather=(value); @weather = value; end
  229.   def defaultTerrain=(value); end
  230.  
  231.   #=============================================================================
  232.   # Information about the type and size of the battle
  233.   #=============================================================================
  234.   def wildBattle?;    return true;  end
  235.   def trainerBattle?; return false; end
  236.  
  237.   def setBattleMode(mode); end
  238.  
  239.   def pbSideSize(index)
  240.     return @sideSizes[index%2]
  241.   end
  242.  
  243.   #=============================================================================
  244.   # Trainers and owner-related
  245.   #=============================================================================
  246.   def pbPlayer; return @player[0]; end
  247.   def opponent; return nil;        end
  248.  
  249.   def pbGetOwnerFromBattlerIndex(idxBattler); return pbPlayer; end
  250.  
  251.   #=============================================================================
  252.   # Get party info (counts all teams on the same side)
  253.   #=============================================================================
  254.   def pbParty(idxBattler)
  255.     return (opposes?(idxBattler)) ? @party2 : nil
  256.   end
  257.  
  258.   def pbAllFainted?(idxBattler=0); return false; end
  259.  
  260.   #=============================================================================
  261.   # Battler-related
  262.   #=============================================================================
  263.   def opposes?(idxBattler1,idxBattler2=0)
  264.     idxBattler1 = idxBattler1.index if idxBattler1.respond_to?("index")
  265.     idxBattler2 = idxBattler2.index if idxBattler2.respond_to?("index")
  266.     return (idxBattler1&1)!=(idxBattler2&1)
  267.   end
  268.  
  269.   def pbRemoveFromParty(idxBattler,idxParty); end
  270.   def pbGainExp; end
  271.  
  272.   #=============================================================================
  273.   # Messages and animations
  274.   #=============================================================================
  275.   def pbDisplay(msg,&block)
  276.     @scene.pbDisplayMessage(msg,&block)
  277.   end
  278.  
  279.   def pbDisplayPaused(msg,&block)
  280.     @scene.pbDisplayPausedMessage(msg,&block)
  281.   end
  282.  
  283.   def pbDisplayBrief(msg)
  284.     @scene.pbDisplayMessage(msg,true)
  285.   end
  286.  
  287.   def pbDisplayConfirm(msg)
  288.     return @scene.pbDisplayConfirmMessage(msg)
  289.   end
  290.  
  291.  
  292.  
  293.   class BattleAbortedException < Exception; end
  294.  
  295.   def pbAbort
  296.     raise BattleAbortedException.new("Battle aborted")
  297.   end
  298.  
  299.   #=============================================================================
  300.   # Safari battle-specific methods
  301.   #=============================================================================
  302.   def pbEscapeRate(catch_rate)
  303.     return 125 if catch_rate <= 45   # Escape factor 9 (45%)
  304.     return 100 if catch_rate <= 60   # Escape factor 7 (35%)
  305.     return 75 if catch_rate <= 120   # Escape factor 5 (25%)
  306.     return 50 if catch_rate <= 250   # Escape factor 3 (15%)
  307.     return 25                        # Escape factor 2 (10%)
  308.   end
  309.  
  310.   def pbStartBattle
  311.     begin
  312.       pkmn = @party2[0]
  313.       self.pbPlayer.pokedex.register(pkmn)
  314.       @scene.pbStartBattle(self)
  315.       pbDisplayPaused(_INTL("Wild {1} appeared!",pkmn.name))
  316.       @scene.pbWildTrainerStart
  317.       weather_data = GameData::BattleWeather.try_get(@weather)
  318.       @scene.pbCommonAnimation(weather_data.animation) if weather_data
  319.       catch_rate = pkmn.species_data.catch_rate
  320.       catchFactor  = (catch_rate*100)/1275
  321.       catchFactor  = [[catchFactor,3].max,20].min
  322.       escapeFactor = (pbEscapeRate(catch_rate)*100)/1275
  323.       escapeFactor = [[escapeFactor,2].max,20].min
  324.       loop do
  325.         cmd = @scene.pbSafariCommandMenu(0)
  326.         case cmd
  327.         when 0   # Ball
  328.           if pbBoxesFull?
  329.             pbDisplay(_INTL("The boxes are full! You can't catch any more Pokémon!"))
  330.             next
  331.           end
  332.           if @ballCount<=0
  333.             pbDisplay(_INTL("You're all out of Poké Balls!"))
  334.             next
  335.           end
  336.           pbFadeOutIn {
  337.             scene = PokemonBag_Scene.new
  338.             screen = PokemonBagScreen.new(scene,$PokemonBag)
  339.             @ret = screen.pbChooseItemScreen(Proc.new { |item| GameData::Item.get(item).is_poke_ball? })
  340.             yield if block_given?
  341.           }
  342.           @scene.pbRefresh
  343.           rare = (catchFactor*1275)/100
  344.           if @ret
  345.             $PokemonBag.pbDeleteItem(@ret)
  346.             pbThrowPokeBall(1,@ret,rare,true)
  347.             @ballCount = pbTotalPokeBalls
  348.             if @caughtPokemon.length>0
  349.               pbRecordAndStoreCaughtPokemon
  350.               @decision = 4
  351.             end
  352.             @ballCount = pbTotalPokeBalls
  353.           end
  354.         when 1   # Bait
  355.           pbDisplayBrief(_INTL("{1} threw some bait at the {2}!",self.pbPlayer.name,pkmn.name))
  356.           @scene.pbThrowBait
  357.           catchFactor  /= 2 if pbRandom(100)<90   # Harder to catch
  358.           escapeFactor /= 2                       # Less likely to escape
  359.         when 2   # Rock
  360.           pbDisplayBrief(_INTL("{1} threw a rock at the {2}!",self.pbPlayer.name,pkmn.name))
  361.           @scene.pbThrowRock
  362.           catchFactor  *= 2                       # Easier to catch
  363.           escapeFactor *= 2 if pbRandom(100)<90   # More likely to escape
  364.         when 3   # Run
  365.           pbSEPlay("Battle flee")
  366.           pbDisplayPaused(_INTL("You got away safely!"))
  367.           @decision = 3
  368.         end
  369.         catchFactor  = [[catchFactor,3].max,20].min
  370.         escapeFactor = [[escapeFactor,2].max,20].min
  371.         # End of round
  372.         if @decision==0
  373.           if @ballCount<=0
  374.             #pbDisplay(_INTL("PA: You have no Safari Balls left! Game over!"))
  375.             #@decision = 2
  376.           elsif pbRandom(100)<5*escapeFactor
  377.             pbSEPlay("Battle flee")
  378.             pbDisplay(_INTL("{1} fled!",pkmn.name))
  379.             @decision = 3
  380.           elsif cmd==1   # Bait
  381.             pbDisplay(_INTL("{1} is eating!",pkmn.name))
  382.           elsif cmd==2   # Rock
  383.             pbDisplay(_INTL("{1} is angry!",pkmn.name))
  384.           else
  385.             pbDisplay(_INTL("{1} is watching carefully!",pkmn.name))
  386.           end
  387.           # Weather continues
  388.           weather_data = GameData::BattleWeather.try_get(@weather)
  389.           @scene.pbCommonAnimation(weather_data.animation) if weather_data
  390.         end
  391.         break if @decision > 0
  392.       end
  393.       @scene.pbEndBattle(@decision)
  394.     rescue BattleAbortedException
  395.       @decision = 0
  396.       @scene.pbEndBattle(@decision)
  397.     end
  398.     return @decision
  399.   end
  400. end
  401.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement