Advertisement
Guest User

Terrain Tag Detection ~

a guest
Aug 28th, 2015
533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.05 KB | None | 0 0
  1. MAX_RANDOM_STEPS = 20 # Leave this alone, it's set at 20 for a reason :3
  2.  
  3. GRASS = 3 # Terrain Tag 3
  4. WATER = 4 # Terrain Tag 4
  5. LEDGE = 5 # Terrain Tag 5
  6.  
  7. #-------------------------------------------------------------------------------
  8. # * TerrainTag class.
  9. # * This checks the Player's current terrain tag, and if it's an encounter tag,
  10. # * Runs encounter processes.
  11. #-------------------------------------------------------------------------------
  12. class TerrainTag
  13.   attr_accessor :max_steps
  14.   attr_accessor :play_sound
  15.   #-----------------------------------------------------------------------------
  16.   # * Initialize the TerrainTag class and create initial values
  17.   #-----------------------------------------------------------------------------
  18.   def initialize
  19.     @terraintag = $game_player.terrain_tag
  20.     @max_steps = (18.75 * 10 / 8.5)
  21.     @play_sound = true
  22.     @sound_frames = 0
  23.     @goframes = true
  24.   end # initialize
  25.   #-----------------------------------------------------------------------------
  26.   # * Update the Terrain Tag detection and run encounter processes.
  27.   #-----------------------------------------------------------------------------
  28.   def update
  29.     if @terraintag != $game_player.terrain_tag
  30.       @terraintag = $game_player.terrain_tag
  31.       @max_steps = (18.75 * 10 / 8.5) - rand(MAX_RANDOM_STEPS)
  32.     end
  33.     case @terraintag
  34.     when GRASS
  35.       if @max_steps <= 0
  36.         @max_steps = (18.75 * 10 / 8.5) - rand(MAX_RANDOM_STEPS)
  37.         if $party.members.size == 0
  38.           $game_temp.battle_calling = false
  39.           p "You have no Pokemon in your party to battle with"
  40.           p "Bypassing Battle System to prevent errors."
  41.         else
  42.           select_random_pokemon
  43.           $game_temp.map_bgm = $game_system.playing_bgm
  44.           $game_system.bgm_stop
  45.           $game_system.se_play($data_system.battle_start_se)
  46.           $game_system.bgm_play($game_system.battle_bgm)
  47.           $game_player.straighten
  48.           $scene = Scene_WildBattle.new(@enemy, @level)
  49.         end
  50.       end
  51.     when LEDGE
  52.       @move_route = RPG::MoveRoute.new
  53.       @route = RPG::MoveCommand.new
  54.       case $game_player.direction
  55.       when 2  # Down
  56.         @route.parameters = [0, 1]
  57.         @x = 0
  58.         @y = 1
  59.       when 4  # Left
  60.         @route.parameters = [-1, 0]
  61.         @x = -1
  62.         @y = 0
  63.       when 6  # Right
  64.         @route.parameters = [1, 0]
  65.         @x = 1
  66.         @y = 0
  67.       when 8  # Up
  68.         @route.parameters = [0, -1]
  69.         @x = 0
  70.         @y = -1
  71.       end
  72.       @route.code = 14
  73.       @dummy = RPG::MoveCommand.new
  74.       @dummy.parameters = []
  75.       @dummy.code = 0
  76.       @move_route.list = [@route, @dummy]
  77.       @move_route.skippable = false
  78.       @move_route.repeat = false
  79.       if $game_player.passable?($game_player.x + @x, $game_player.y + @y, $game_player.direction)
  80.         if @play_sound == true
  81.           Audio.se_play("Audio/SE/Jump", 100, 100)
  82.           @goframes = true
  83.           @play_sound = false
  84.         end
  85.         $game_player.refresh
  86.         $game_player.force_move_route(@move_route)
  87.       end
  88.     end
  89.     if @goframes
  90.       if Config::FPSBOOST
  91.         if @sound_frames < 20
  92.           @sound_frames += 1
  93.         elsif @sound_frames == 20
  94.           @play_sound = true
  95.           @goframes = false
  96.           @sound_frames = 0
  97.         end
  98.       else
  99.         if @sound_frames < 10
  100.           @sound_frames += 1
  101.         elsif @sound_frames == 10
  102.           @play_sound = true
  103.           @goframes = false
  104.           @sound_frames = 0
  105.         end
  106.       end
  107.     end
  108.   end # update
  109.   #-----------------------------------------------------------------------------
  110.   # * Make sure that the wild Pokemon's ID and Level are not 0.
  111.   # * If so, choose again and again until both values are not 0.
  112.   #-----------------------------------------------------------------------------
  113.   def select_random_pokemon
  114.     @map = WildPokemon.fetch($game_map.map_id)
  115.     @enemy = @map[0][rand(@map[0].size)]
  116.     @level = @map[1][rand(@map[1].size)]
  117.   end # select_random_pokemon
  118. end # TerrainTag
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement