Advertisement
Scinaya

ERE by Kread-EX

Apr 28th, 2011
759
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.14 KB | None | 0 0
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  2. # Extended Random Encounters (ERE)
  3. # Author: Kread-EX
  4. # Version 1.0
  5. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  6.  
  7. #-------------------------------------------------------------------------------------------------
  8. #  TERMS OF USAGE
  9. #-------------------------------------------------------------------------------------------------
  10. # #  You are free to adapt this work to suit your needs.
  11. # #  You can use this work for commercial purposes if you like it.
  12. # #  Credit is appreciated.
  13. #-------------------------------------------------------------------------------------------------
  14.  
  15.  
  16. #===========================================================
  17. # INTRODUCTION
  18. #
  19. # For the random encounters lovers out there (bleh), here is a simple script to make them slightly
  20. # more interesting.
  21. # First, a colorful circle to know when the fight will start. More red the circle is, closer the battle is.
  22. # Secondly, a Gust-ish system to allow a maximum number of battles for each area.
  23. #
  24. # INSTRUCTIONS
  25. #
  26. # By default, the maximum number of battles are 10. For all the game. Of course, you want to change
  27. # this. There are two ways:
  28. # 1. In the map name, put this: #EC[number]. The number represent the maximum allowed random
  29. # encounters for an area. It is set until you change it, without another map for instance.
  30. # 2. With a Call Script command: $game_system.set_encounter_ratio(number).
  31. # The most efficient way is to set a number for an entire area via map name.
  32. #
  33. # You can hide the circle with this command: $game_system.display_encounter_dot = false.
  34. #===========================================================
  35.  
  36.  
  37. #===========================================================
  38. # ** Game_System
  39. #------------------------------------------------------------------------------
  40. #  This class handles data surrounding the system. Backround music, etc.
  41. #  is managed here as well. Refer to "$game_system" for the instance of
  42. #  this class.
  43. #===========================================================
  44.  
  45. class Game_System
  46.   #--------------------------------------------------------------------------
  47.   # * Public Instance Variables
  48.   #--------------------------------------------------------------------------
  49.   attr_accessor :display_encounter_dot
  50.   attr_accessor :max_encounter
  51.   attr_accessor :current_encounter
  52.   #--------------------------------------------------------------------------
  53.   # * Object Initialization
  54.   #--------------------------------------------------------------------------
  55.   unless method_defined?(:kread_ERE_game_system_initialize)
  56.     alias_method :kread_ERE_game_system_initialize, :initialize
  57.   end
  58.   def initialize
  59.     kread_ERE_game_system_initialize
  60.     @display_encounter_dot = true
  61.     @max_encounter = 10
  62.     @current_encounter = 0
  63.   end
  64.   #--------------------------------------------------------------------------
  65.   # * Reinitialize encounter ratio
  66.   #--------------------------------------------------------------------------
  67.   def set_encounter_ratio(max = 10)
  68.     @max_encounter = max
  69.     @current_encounter = 0
  70.   end
  71.   #--------------------------------------------------------------------------
  72. end
  73.  
  74. #===========================================================
  75. # ** Spriteset_Map
  76. #------------------------------------------------------------------------------
  77. #  This class brings together map screen sprites, tilemaps, etc.
  78. #  It's used within the Scene_Map class.
  79. #===========================================================
  80.  
  81. class Spriteset_Map
  82.   #--------------------------------------------------------------------------
  83.   # * Dispose
  84.   #--------------------------------------------------------------------------
  85.   unless method_defined?(:kread_ERE_spriteset_map_dispose)
  86.     alias_method :kread_ERE_spriteset_map_dispose, :dispose
  87.   end
  88.   def dispose
  89.     unless @encounter_dot == nil
  90.      @encounter_dot.dispose
  91.      @encounter_tex.dispose
  92.     end
  93.     kread_ERE_spriteset_map_dispose
  94.   end
  95.   #--------------------------------------------------------------------------
  96.   # * Frame Update
  97.   #--------------------------------------------------------------------------
  98.   unless method_defined?(:kread_ERE_spriteset_map_update)
  99.     alias_method :kread_ERE_spriteset_map_update, :update
  100.   end
  101.   def update
  102.     update_encounter_dot unless $game_map.encounter_list.empty?
  103.     kread_ERE_spriteset_map_update
  104.   end
  105.   #--------------------------------------------------------------------------
  106.   # * Update the encounter dot
  107.   #--------------------------------------------------------------------------
  108.   def update_encounter_dot
  109.     if @encounter_dot == nil && $game_system.max_encounter != @last_max
  110.       @encounter_dot.bitmap.dispose if @encounter_dot != nil
  111.       @encounter_dot = Sprite.new(@viewport3)
  112.       @encounter_dot.bitmap = Bitmap.new('Graphics/Pictures/Dot_Fill')
  113.       @encounter_dot.x = 491
  114.       @encounter_dot.y = 348
  115.       @blink_dot = 0
  116.     end
  117.     if @encounter_tex == nil
  118.       @encounter_tex = Sprite.new(@viewport3)
  119.       @encounter_tex.bitmap = RPG::Cache.picture('Dot_Texture')
  120.       @encounter_tex.x, @encounter_tex.y = @encounter_dot.x, @encounter_dot.y
  121.       @encounter_tex.z = @encounter_dot.z + 1
  122.     end
  123.     @encounter_dot.visible = @encounter_tex.visible = ($game_system.display_encounter_dot &&
  124.     !$game_system.encounter_disabled)
  125.     w, h = @encounter_dot.bitmap.width, @encounter_dot.bitmap.height
  126.     if $game_player.encounter_count != @last_count
  127.       rate = [(($game_map.encounter_step.to_f - $game_player.encounter_count.to_f) /
  128.       $game_map.encounter_step.to_f), 0].max
  129.       case rate
  130.       when 0...0.4
  131.         @encounter_dot.src_rect.set(0, 0, 133, 116)
  132.       when 0.4...0.5
  133.         @encounter_dot.src_rect.set(133, 0, 133, 116)
  134.       when 0.5...0.6
  135.         @encounter_dot.src_rect.set(266, 0, 133, 116)
  136.       when 0.6...0.7
  137.         @encounter_dot.src_rect.set(399, 0, 133, 116)
  138.       when 0.7...0.8
  139.         @encounter_dot.src_rect.set(0, 116, 133, 116)
  140.       when 0.8...0.9
  141.         @encounter_dot.src_rect.set(133, 116, 133, 116)
  142.       when 0.9...1
  143.         @encounter_dot.src_rect.set(266, 116, 133, 116)
  144.       end
  145.     end
  146.     unless $game_system.current_encounter == $game_system.max_encounter
  147.       @encounter_dot.tone = Tone.new(@blink_dot * 4, @blink_dot * 4, @blink_dot * 4)
  148.       if @blink_dot == 25
  149.         @sign = 'sub'
  150.       elsif @blink_dot == -25
  151.         @sign = 'add'
  152.       end
  153.       @blink_dot += @sign == 'sub' ? -1 : 1
  154.     end
  155.     crop_dot
  156.   end
  157.   #--------------------------------------------------------------------------
  158.   # * Crop the encounter dot
  159.   #--------------------------------------------------------------------------
  160.   def crop_dot
  161.     if $game_system.current_encounter > 0
  162.       rect = @encounter_dot.src_rect
  163.       ratio = (116 * $game_system.current_encounter.to_f / $game_system.max_encounter.to_f).round
  164.       @encounter_dot.bitmap.fill_rect(rect.x, (rect.y + 116) - ratio, 133, ratio, Color.new(0, 0, 0, 0))
  165.     end
  166.   end
  167.   #--------------------------------------------------------------------------
  168. end
  169.  
  170. #===========================================================
  171. # ** Game_Map
  172. #------------------------------------------------------------------------------
  173. #  This class handles the map. It includes scrolling and passable determining
  174. #  functions. Refer to "$game_map" for the instance of this class.
  175. #===========================================================
  176.  
  177. class Game_Map
  178.   #--------------------------------------------------------------------------
  179.   # * Setup
  180.   #--------------------------------------------------------------------------
  181.   unless method_defined?(:kread_ERE_game_map_setup)
  182.     alias_method :kread_ERE_game_map_setup, :setup
  183.   end
  184.   def setup(map_id)
  185.     kread_ERE_game_map_setup(map_id)
  186.     name = load_data('Data/MapInfos.rxdata')[map_id].name
  187.     name.split.each {|line|
  188.       if line =~ /#EC\[([0-9]+)\]/i && $1 != $game_system.max_encounter
  189.         $game_system.set_encounter_ratio($1.to_i)
  190.       end
  191.     }
  192.   end
  193.   #--------------------------------------------------------------------------
  194. end
  195.  
  196. #===========================================================
  197. # ** Scene_Map
  198. #------------------------------------------------------------------------------
  199. #  This class performs map screen processing.
  200. #===========================================================
  201.  
  202. class Scene_Map
  203.   #--------------------------------------------------------------------------
  204.   # * Battle Call
  205.   #--------------------------------------------------------------------------
  206.   unless method_defined?(:kread_ERE_scene_map_call_battle)
  207.     alias_method :kread_ERE_scene_map_call_battle, :call_battle
  208.   end
  209.   def call_battle
  210.     if $game_system.current_encounter == $game_system.max_encounter &&
  211.     !$game_system.map_interpreter.running?
  212.       $game_temp.battle_calling = false
  213.       return
  214.     end
  215.     $game_system.current_encounter += 1 if $game_player.encounter_count == 0
  216.     kread_ERE_scene_map_call_battle
  217.   end
  218.   #--------------------------------------------------------------------------
  219. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement