gerkrt

Improved impact rate

Sep 14th, 2011
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 12.38 KB | None | 0 0
  1. #==============================================================================
  2. # Improved impact rate
  3. # By gerkrt/gerrtunk
  4. # Version: 1.0
  5. # License: MIT, credits
  6. # Date: 18/01/2010
  7. # IMPORTANT NOTE: to acces the more actualitzed or corrected version of this
  8. # script check here: http://usuarios.multimania.es/kisap/english_list.html
  9. #==============================================================================
  10.  
  11. =begin
  12.  
  13. --------Introduction-----------
  14.  
  15. This script completely revamps the classic impact rate calculations. Now you have
  16. a full control of the random targets of the enemies.
  17.  
  18. You can set it now by:
  19.  
  20. -Positions in actor group
  21. -Actor
  22. -Classes
  23. -Armors
  24. -Weapons
  25.  
  26. You can also set a Max and a Base impact rate values, and add a inernal correction
  27. to any actor that can be temporal or not and is setted via script call.
  28.  
  29. Finally it adds the option to use the default clasic values for actors postions, but
  30. now you can set the rate value of rear, front and mid guard.
  31.  
  32.  
  33. ----IMPACT RATE FOR POSITIONS-------
  34.  
  35. Impact_rate['positions'][2] = 3
  36. Impact_rate['positions'][1] = 2
  37.  
  38. Impact_rate['positions'][actor position] = rate
  39.  
  40. ----IMPACT RATE FOR ACTORS-------
  41.  
  42. Impact_rate['actors'][1] = 5
  43.  
  44. Impact_rate['actors'][actor id] = rate
  45.  
  46. ----IMPACT RATE FOR CLASSES-------
  47.  
  48. Impact_rate['classes'][1] = 1
  49.  
  50. Impact_rate['classes'][class id] = rate
  51.  
  52. ----IMPACT RATE FOR WEAPONS-------
  53.  
  54. Impact_rate['weapons'][1] = 1
  55.  
  56. Impact_rate['weapons'][weapon id] = rate
  57.  
  58. ----IMPACT RATE FOR ARMORS-------
  59.  
  60. Impact_rate['armors'][1] = -1
  61.  
  62. Impact_rate['armors'][armor id] = rate
  63.  
  64. ----FIXED AND TEMPORAL CHANGUES(script calls)-----
  65.  
  66. modify_impact_rate(actor, value): This will add to a internal variable that have each
  67. actor. That atribute is added when calculating its posibilities.
  68. Ex:
  69.   modify_impact_rate(2, 4)
  70.   This is adding 4 to the impact rate of the actor that have the id 2 in the database.
  71.  
  72. The difference of this and the actors value is that the actors value cant be modified.
  73.  
  74.  
  75. modify_tmp_impact_rate(actor, value): This is like the other, but at the end of each
  76. combat, its reseted to 0. It can be used for special effects.
  77.   Ex:
  78.   modify_tmp_impact_rate(3, -4)
  79.   This is adding -4 to the temporal impact rate of the actor that have the id 3 in the
  80.   database. Note that in the two cases is valid to put negative numbers to compensate
  81.   this.
  82.  
  83. ----OTHER CONFIGURATIONS---------
  84.  
  85. Impact_rate_max : This is used to create a max for the times the actors are put
  86. in the roulette. It can be interesting for someone thats lookig for tweaking the
  87. formula.
  88.  
  89. Impact_rate_base : This is used to create a base value that will be added to all actors
  90. It can be interesting for someone thats lookig for tweaking theformula.
  91.    
  92. Use_database_position : If not actived, it wont add the default impact rate of
  93. the database. If you set it to the word false, it will be desactived.
  94.  
  95. You can set new values for the clasic options here:
  96. Front_guard_rate = 4
  97. Mid_guard_rate = 3
  98. Rear_guard_rate = 2
  99.  
  100. ----HOW THE FORMULA WORKS-------
  101.  
  102. Its an expansion of the classic one:
  103.  
  104. Each active and valid actor is added to the list n times, where n is the sum of:
  105.  
  106. Base rate
  107. Clasic database position(if active)
  108. All equipment rates
  109. Class rate
  110. Actor rate
  111. Actor base rate
  112. Actor temporal rate
  113.  
  114. Then is checked if that is more than the Max n, if so, it sets n to that Max.
  115.  
  116. So if all of them sum 15, and 15 is valid, it will add the actor 15 times to
  117. the roulette.
  118.  
  119. The script does that for all the actors, and then try for a random slot of the
  120. roulette list.
  121.  
  122. Note that any value of the script may have a negative value. Thats valid to
  123. for whatever you want, but, the minium of n is always 0.
  124.  
  125. Finally, only the defined values will be added, so, if a position or class
  126. dont have any value for that, it will be ignored, like a default +0.
  127.  
  128. =end
  129.  
  130. module Wep
  131.     # Dont touch this
  132.     Impact_rate =  {'positions' => [], 'actors' => [], 'classes' => [],'weapons' => [],'armors' => []}
  133.  
  134.    
  135.     Impact_rate['positions'][0] = 0
  136.     Impact_rate['positions'][2] = 3
  137.     Impact_rate['positions'][1] = 2
  138.     Impact_rate['positions'][3] = 1
  139.    
  140.     Impact_rate['weapons'][3] = 4
  141.     Impact_rate['armors'][4] = -3
  142.     Impact_rate['classes'][1] = 1
  143.     Impact_rate['actors'][1] = 5
  144.    
  145.    
  146.     Impact_rate_max = 20
  147.     Impact_rate_base = 4
  148.    
  149.     Use_database_position = true
  150.  
  151.     Front_guard_rate = 4
  152.     Mid_guard_rate = 3
  153.     Rear_guard_rate = 2
  154.  
  155. end
  156.  
  157.  
  158.  
  159. #==============================================================================
  160. # ** Interpreter
  161. #------------------------------------------------------------------------------
  162. # added two impact rate  methods to modify internal actor variables
  163. #==============================================================================
  164.  
  165. class Interpreter
  166.   #--------------------------------------------------------------------------
  167.   # * Modifiy impact rate
  168.   #--------------------------------------------------------------------------
  169.   def modify_impact_rate(actor, val)
  170.     $game_actors[actor].impact_rate_base += val
  171.   end
  172.  
  173.   #--------------------------------------------------------------------------
  174.   # * Modifiy temporal impact rate
  175.   #--------------------------------------------------------------------------
  176.   def modify_tmp_impact_rate(actor, val)
  177.     $game_actors[actor].impact_rate_temp += val
  178.   end
  179.  
  180. end
  181.  
  182. #==============================================================================
  183. # ** Game_Party
  184. #------------------------------------------------------------------------------
  185. # moded the random target method
  186. #==============================================================================
  187.  
  188. class Game_Party
  189.   #--------------------------------------------------------------------------
  190.   # * Defined Random Selection of Target Actor
  191.   #   It allows you to define enemy random target based on combat positions,
  192.   #   actor, class, weapon, armor, and internal actor variables
  193.   #--------------------------------------------------------------------------
  194.   def random_target_actor(hp0 = false)
  195.    
  196.     # Initialize roulette
  197.     roulette = []
  198.    
  199.     # Loop
  200.     count = 0
  201.     # Iterate in active actors
  202.     for actor in @actors
  203.      
  204.       # If it fits the conditions
  205.       if (not hp0 and actor.exist?) or (hp0 and actor.hp0?)
  206.      
  207.       # Create the total number
  208.       n = Wep::Impact_rate_base + Wep::Impact_rate['positions'][count] + actor.impact_rate  
  209.  
  210.         # Check if the use database position is active and apply it
  211.         if Wep::Use_database_position
  212.           # Get actor class [position]
  213.           position = $data_classes[actor.class_id].position
  214.          
  215.           # Exchangue with defined values
  216.           if position == 4
  217.             position = Wep::Front_guard_rate
  218.           elsif position == 3
  219.             position = Wep::Mid_guard_rate
  220.           else
  221.             position = Wep::Rear_guard_rate
  222.           end
  223.          
  224.           # Rest position values: Front guard: n = 4; Mid guard: n = 3; Rear guard: n = 2
  225.           n -= position
  226.           n = n.abs
  227.         end
  228.        
  229.         # Check for n max size
  230.         if n > Wep::Impact_rate_max
  231.           n = Wep::Impact_rate_max
  232.         end
  233.        
  234.         #p 'rand', n
  235.         # Add actor to roulette n times
  236.         n.times do
  237.           roulette.push(actor)
  238.         end
  239.        
  240.       end
  241.       count+=1
  242.      
  243.     end
  244.    
  245.     # If roulette size is 0
  246.     if roulette.size == 0
  247.       return nil
  248.     end
  249.    
  250.     # Spin the roulette, choose an actor
  251.     return roulette[rand(roulette.size)]
  252.    
  253.   end
  254. end
  255.  
  256. #==============================================================================
  257. # ** Scene_Battle
  258. #------------------------------------------------------------------------------
  259. #  modified battle end method
  260. #==============================================================================
  261.  
  262. class Scene_Battle
  263.  
  264.   #--------------------------------------------------------------------------
  265.   # * Battle Ends
  266.   # moded to reset impact rate temp variables
  267.   #--------------------------------------------------------------------------
  268.   alias wep_ib_battle_end battle_end
  269.   def battle_end(result)
  270.    
  271.     # Reset all game party actors temporal impact rate
  272.     $game_party.actors.each {|i|i.impact_rate_temp = 0 }
  273.    
  274.     wep_sb_battle_end(result)
  275.   end
  276.  
  277. end
  278.  
  279.  
  280. #==============================================================================
  281. # ** Game_Actor
  282. #------------------------------------------------------------------------------
  283. # added two variables in setup and general impact rate method
  284. #==============================================================================
  285.  
  286. class Game_Actor
  287.   attr_accessor   :impact_rate_base
  288.   attr_accessor   :impact_rate_temp
  289.   attr_accessor   :impact_rate
  290.      
  291.   #--------------------------------------------------------------------------
  292.   # * Setup
  293.   # moded set internal variables
  294.   #--------------------------------------------------------------------------
  295.   alias ga_wep_ib_setup setup
  296.   def setup(actor_id)
  297.     ga_wep_ib_setup(actor_id)
  298.     @impact_rate_base = 0
  299.     @impact_rate_temp = 0
  300.   end
  301.  
  302.   #--------------------------------------------------------------------------
  303.   # * Impact Rate
  304.   # sum all impact rates values
  305.   #--------------------------------------------------------------------------
  306.   def impact_rate
  307.     n = 0
  308.    
  309.     n += $data_weapons[@weapon_id].impact_rate if @weapon_id != 0
  310.     n += $data_armors[@armor1_id].impact_rate if @armor1_id != 0
  311.     n += $data_armors[@armor2_id].impact_rate if @armor2_id != 0
  312.     n += $data_armors[@armor3_id].impact_rate if @armor3_id != 0
  313.     n += $data_armors[@armor4_id].impact_rate if @armor4_id != 0
  314.    
  315.     n += $data_classes[@class_id].impact_rate
  316.     n += $data_actors[@actor_id].impact_rate
  317.     n += @impact_rate_base
  318.     n += @impact_rate_temp
  319.    
  320.     return n.to_i != 0 ? n.to_i: 1
  321.   end
  322.  
  323. end
  324.  
  325. #==============================================================================
  326. # ¦ RPG::Actor
  327. # added impact rate support
  328. #==============================================================================
  329. class RPG::Actor
  330.  
  331.   attr_accessor :impact_rate
  332.    
  333.   #--------------------------------------------------------------------------
  334.   # * Impact rate
  335.   # moded to return the array values throught a internal method
  336.   #--------------------------------------------------------------------------
  337.   def impact_rate
  338.      data = Wep::Impact_rate['actors']
  339.      return data[@id] != nil ? data[@id] : 0
  340.   end
  341. end
  342.  
  343. #==============================================================================
  344. # ¦ RPG::Armor
  345. # added impact rate support
  346. #==============================================================================
  347. class RPG::Armor
  348.   attr_accessor :impact_rate
  349.  
  350.   #--------------------------------------------------------------------------
  351.   # * Impact rate
  352.   # moded to return the array values throught a internal method
  353.   #--------------------------------------------------------------------------
  354.   def impact_rate
  355.      data = Wep::Impact_rate['armors']
  356.      return data[@id] != nil ? data[@id] : 0
  357.   end
  358.    
  359. end
  360.  
  361. #==============================================================================
  362. # ¦ RPG::Class
  363. # added impact rate support
  364. #==============================================================================
  365. class RPG::Class
  366.   attr_accessor :impact_rate
  367.  
  368.   #--------------------------------------------------------------------------
  369.   # * Impact rate
  370.   # moded to return the array values throught a internal method
  371.   #--------------------------------------------------------------------------
  372.   def impact_rate
  373.      data = Wep::Impact_rate['classes']
  374.      return data[@id] != nil ? data[@id] : 0
  375.    end
  376. end
  377.  
  378.  
  379. #==============================================================================
  380. # ¦ RPG::Weapon
  381. # added impact rate support
  382. #==============================================================================
  383. class RPG::Weapon
  384.  
  385.   attr_accessor :impact_rate
  386.  
  387.   #--------------------------------------------------------------------------
  388.   # * Impact rate
  389.   # moded to return the array values throught a internal method
  390.   #--------------------------------------------------------------------------
  391.   def impact_rate
  392.      data = Wep::Impact_rate['weapons']
  393.      return data[@id] != nil ? data[@id] : 0
  394.   end
  395. end
Add Comment
Please, Sign In to add comment