Advertisement
neonblack

Scale Encounters V1.0b

Jul 18th, 2012
794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 12.80 KB | None | 0 0
  1. ###--------------------------------------------------------------------------###
  2. #  Scale Encounters script                                                     #
  3. #  Version 1.0                                                                 #
  4. #                                                                              #
  5. #      Credits:                                                                #
  6. #  Original code by: Neonblack                                                 #
  7. #  Modified by:                                                                #
  8. #                                                                              #
  9. #  This work is licensed under the Creative Commons Attribution-NonCommercial  #
  10. #  3.0 Unported License. To view a copy of this license, visit                 #
  11. #  http://creativecommons.org/licenses/by-nc/3.0/.                             #
  12. #  Permissions beyond the scope of this license are available at               #
  13. #  http://cphouseset.wordpress.com/liscense-and-terms-of-use/.                 #
  14. #                                                                              #
  15. #      Contact:                                                                #
  16. #  NeonBlack - neonblack23@live.com (e-mail) or "neonblack23" on skype         #
  17. ###--------------------------------------------------------------------------###
  18.  
  19. ###--------------------------------------------------------------------------###
  20. #      Revision information:                                                   #
  21. #  V1.0 - 7.17.2012                                                            #
  22. #   Wrote and debugged main script                                             #
  23. ###--------------------------------------------------------------------------###
  24.  
  25. ###--------------------------------------------------------------------------###
  26. #      Compatibility:                                                          #
  27. #  Alias       - Game_Player: encounter, update_encounter                      #
  28. #                Scene_Map: create_all_windows                                 #
  29. #  Overwrites  - Game_Player: make_encounter_count                             #
  30. #                Scene_Map: update_encounter                                   #
  31. #  New Objects - Game_Interpreter: encounters                                  #
  32. #                Game_Player: set_encounters_total, encounter_rate_refresh,    #
  33. #                             lower_scale_val, lower_enc_scale                 #
  34. #                Scene_Map: create_encounter_window                            #
  35. #                Window_ScaleEncounter: initialize, update, refresh            #
  36. ###--------------------------------------------------------------------------###
  37.  
  38. ###--------------------------------------------------------------------------###
  39. #      Instructions:                                                           #
  40. #  Place this script in the "Materials" section of the scripts above main.     #
  41. #  This script modifies how random encounters are generated by creating a      #
  42. #  random value each step rather than using a static value at the start of     #
  43. #  each map and battle.  The random value will also scale from a top ratio to  #
  44. #  a bottom ratio based on the map encounter rate.  There are a few settings   #
  45. #  that need to be set and depending on the settings you may need to use the   #
  46. #  command below.                                                              #
  47. #                                                                              #
  48. #    encounter(x) - When using the "encounter gauge", you need to manually     #
  49. #                   set the number of battles that appear in an area.  To do   #
  50. #                   this, set up a script call somewhere in the transfer       #
  51. #                   event at the start of the area with this script call in    #
  52. #                   it.  You set the total number of battles you can find in   #
  53. #                   the area by changing "x" to the number of battles you      #
  54. #                   want to be able to find.                                   #
  55. ###--------------------------------------------------------------------------###
  56.  
  57. ###--------------------------------------------------------------------------###
  58. #      Config:                                                                 #
  59. #  These are the default values used by several of the functions in the        #
  60. #  script.  You may change these values as you find your game requires in      #
  61. #  order to give the player a better playing experience based on your game.    #
  62. #                                                                              #
  63. module CP              # Do not                                                #
  64. module SCALE_ENCOUNTER #  change these.                                        #
  65. #                                                                              #
  66. ###-----                                                                -----###
  67. # This is the top ratio value to use for random encounters.  After entering a  #
  68. # map or fighting in a battle, the encounter ratio resets to this value and    #
  69. # on each step will scale down to at least the map average steps.  This means  #
  70. # you have a higher chance of getting into a battle on later steps.            #
  71. TOP_VALUE = 100 # Default = 100                                                #
  72. #                                                                              #
  73. # The rate at which the guage scales down to the average steps.  The higher    #
  74. # this number, the faster the encounters scale down.                           #
  75. SCALE_AMOUNT = 1.0 # Default = 1.0                                             #
  76. #                                                                              #
  77. ###-----                                                                -----###
  78. # Choose wether or not to use the encounters gauge.  If this is set to true    #
  79. # you will need to set the number of encounters in an area using the command   #
  80. # above (see the instructions section).  If set to false, you do not need to   #
  81. # set any of the following options and are done with the config.               #
  82. ENCOUNTERS_GAUGE = true # Default = true                                       #
  83. #                                                                              #
  84. # Choose if you want to show the encounter gauge on the map.  This changes     #
  85. # color depending on the scale and also decreases as the number of battles     #
  86. # remaining drops.  The gauge does not show up on maps with no encounters or   #
  87. # with 0 average steps.                                                        #
  88. SHOW_GAUGE = true # Default = true                                             #
  89. #                                                                              #
  90. # Set the colors for the gauge.  "LO" colors are for when scaling has a high   #
  91. # ratio, "HI" colors are for when the ratio has a low scaling.                 #
  92. GAUGE_COLOR_LO_1 = Color.new( 50, 200,  50)                                    #
  93. GAUGE_COLOR_LO_2 = Color.new(125, 255, 125)                                    #
  94. #                                                                              #
  95. GAUGE_COLOR_HI_1 = Color.new(200,  50,  50)                                    #
  96. GAUGE_COLOR_HI_2 = Color.new(255, 125, 125)                                    #
  97. #                                                                              #
  98. ###--------------------------------------------------------------------------###
  99.  
  100.  
  101. ###--------------------------------------------------------------------------###
  102. #  The following lines are the actual core code of the script.  While you are  #
  103. #  certainly invited to look, modifying it may result in undesirable results.  #
  104. #  Modify at your own risk!                                                    #
  105. ###--------------------------------------------------------------------------###
  106.  
  107. end
  108. end
  109.  
  110. $imported = {} if $imported.nil?
  111. $imported["CP_SCALE_ENCOUNTER"] = 1.0
  112.  
  113. class Game_Interpreter
  114.   def encounters(i = 1)  ## So an encounters script call works.
  115.     $game_player.set_encounters_total(i)
  116.   end
  117. end
  118.  
  119. class Game_Player < Game_Character
  120.   attr_reader :scale_enc_max  ## Sets all the new readers.
  121.   attr_reader :scale_enc_min
  122.   attr_reader :scale_enc_cur
  123.   attr_reader :scale_enc_total
  124.   attr_reader :scale_enc_left
  125.  
  126.   def set_encounters_total(i = 1)  ## Makes new total and current encounters.
  127.     @scale_enc_total = i
  128.     @scale_enc_left = i
  129.   end
  130.  
  131.   def make_encounter_count  ## Overwriten.  Resets the scale.
  132.     @scale_enc_max = CP::SCALE_ENCOUNTER::TOP_VALUE
  133.     @scale_enc_min = $game_map.encounter_step
  134.     @scale_enc_cur = @scale_enc_max
  135.     @scale_enc_total = 1 if @scale_enc_total.nil?
  136.     @scale_enc_left = 1 if @scale_enc_left.nil?
  137.     @encounter_count = @scale_enc_cur
  138.   end
  139.  
  140.   alias cp_se_encounter encounter unless $@
  141.   def encounter  ## Ignores encounters if there are none left.
  142.     return false if @scale_enc_left <= 0
  143.     cp_se_encounter
  144.   end
  145.  
  146.   alias cp_se_update_encounter update_encounter unless $@
  147.   def update_encounter
  148.     cp_se_update_encounter  ## Gets the encounter chance via the ratio.
  149.     @encounter_count = encounter_rate_refresh
  150.   end
  151.  
  152.   def encounter_rate_refresh  ## Reduces the scale and gets an encounter value.
  153.     @scale_enc_cur -= lower_scale_val if @scale_enc_cur > @scale_enc_min
  154.     @scale_enc_cur = @scale_enc_min if @scale_enc_cur < @scale_enc_min
  155.     return rand(@scale_enc_cur)  ## Returns the random number.
  156.   end
  157.  
  158.   def lower_scale_val  ## Used to find the scale speed.
  159.     res = 1 * encounter_progress_value * CP::SCALE_ENCOUNTER::SCALE_AMOUNT
  160.     return res
  161.   end
  162.  
  163.   def lower_enc_scale  ## Reduces the number of encounters by 1.
  164.     return unless CP::SCALE_ENCOUNTER::ENCOUNTERS_GAUGE
  165.     @scale_enc_left -= 1
  166.   end
  167. end
  168.  
  169. class Window_ScaleEncounter < Window_Base
  170.   def initialize  ## Sets the encounter window's size.
  171.     super(Graphics.width - 146, Graphics.height - 40, 138, 32)
  172.     self.back_opacity = 0  ## Makes the back clear.
  173.     self.openness = 0  ## Closes the window.
  174.     @gcur = 0  ## Gives nul values to the variables.
  175.     @gtot = 0  ## gcur is for scaling, gtot is for encounter numbers.
  176.   end
  177.  
  178.   def update
  179.     super  ## Ignores a refresh if nothing has changed.
  180.     refresh if (@gcur != $game_player.scale_enc_cur) ||
  181.                (@gtot != $game_player.scale_enc_left)
  182.   end
  183.  
  184.   def refresh
  185.     if $game_map.encounter_step == 0 || $game_map.encounter_list.empty?
  186.       self.openness = 0  ## Keep closed if there are no battles.
  187.     else
  188.       open  ## Open up the gauge if needed.
  189.       if $game_player.scale_enc_total == 0
  190.         width = 0  ## Prevents "divided by zero" errors.
  191.       else
  192.         width = $game_player.scale_enc_left.to_f / $game_player.scale_enc_total
  193.         width *= 112  ## Gets gauge width.
  194.       end
  195.       cb1 = CP::SCALE_ENCOUNTER::GAUGE_COLOR_LO_1  ## Gets all colors.
  196.       cb2 = CP::SCALE_ENCOUNTER::GAUGE_COLOR_LO_2
  197.       ct1 = CP::SCALE_ENCOUNTER::GAUGE_COLOR_HI_1
  198.       ct2 = CP::SCALE_ENCOUNTER::GAUGE_COLOR_HI_2  ## Find scale rate.
  199.       rate1 = $game_player.scale_enc_max - $game_player.scale_enc_min
  200.       if rate1 <= 0  ## Ignores the "High" gauge in non-scaling cases.
  201.         alp = 0
  202.       else
  203.         rate2 = $game_player.scale_enc_max - $game_player.scale_enc_cur
  204.         alp = rate2.to_f / rate1
  205.         alp *= 255  ## Makes the alpha rate for the "high" gauge.
  206.       end
  207.       contents.fill_rect(1, 1, 112, 6, gauge_back_color)  ## Gauge back.
  208.       contents.gradient_fill_rect(1, 1, width, 6, cb1, cb2)  ## "Low" gauge.
  209.       bitmap = Bitmap.new(contents.width, contents.height)
  210.       bitmap.gradient_fill_rect(1, 1, width, 6, ct1, ct2)  ## "High" gauge.
  211.       contents.blt(0, 0, bitmap, bitmap.rect, alp)  ## BLT in the "high" gauge.
  212.     end
  213.     @gcur = $game_player.scale_enc_cur  ## Sets the variable values.
  214.     @gtot = $game_player.scale_enc_left  ## This prevents constant refreshes.
  215.   end
  216. end
  217.  
  218. class Scene_Map < Scene_Base
  219.   def update_encounter  ## Overwrite this to decrease encounters total.
  220.     if $game_player.encounter
  221.       $game_player.lower_enc_scale
  222.       SceneManager.call(Scene_Battle)
  223.     end
  224.   end
  225.  
  226.   alias cp_se_create_all_windows create_all_windows unless $@
  227.   def create_all_windows
  228.     create_encounter_window if CP::SCALE_ENCOUNTER::SHOW_GAUGE
  229.     cp_se_create_all_windows  ## Adds a new window.
  230.   end
  231.  
  232.   def create_encounter_window  ## Creates that new window.
  233.     @map_encounter_window = Window_ScaleEncounter.new
  234.   end
  235. end
  236.  
  237.  
  238. ###--------------------------------------------------------------------------###
  239. #  End of script.                                                              #
  240. ###--------------------------------------------------------------------------###
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement