Advertisement
TheSixth

Hit Modifiers

Nov 17th, 2020
1,208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.17 KB | None | 0 0
  1. =begin
  2. #-------------------------------------------------------------------------------
  3.  - Hit Modifiers v1.0
  4.  - Made by: Sixth
  5.  
  6. #-------------------------------------------------------------------------------
  7. - Description:
  8. #-------------------------------------------------------------------------------
  9. This script will let you setup hit modifiers for all of your database objects.
  10. Basically, you can have different hit rates on different targets based on what
  11. "hit type" that target has.
  12.  
  13. #-------------------------------------------------------------------------------
  14. - Note-Tags:
  15. #-------------------------------------------------------------------------------
  16. To setup a hit type for your actors and enemies, use this note-tag:
  17.  
  18.   <hit_type: type>
  19.  
  20. Just replace the type after the : sign to whatever you want. That will be the
  21. hit type of the actor/enemy.
  22.  
  23. Examples:
  24.  
  25.   <hit_type: short_range>
  26.   <hit_type: flying>
  27.   <hit_type: melee>
  28.  
  29. #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  30. To setup hit modifiers for your actors, classes, enemies, equipment, states,
  31. skills and items, use this note-tag:
  32.  
  33.   <hit_mod: type, value>
  34.  
  35. The type can be any type you used with the <hit_type: type> note-tag.
  36. Well, you can basically use anything for it, but the effect will only trigger
  37. if the user targets someone with the same type, so it would be useless if you
  38. have no actor/enemy tagged with the same type.
  39.  
  40. The value must be a float number from 0.0 to infinity.
  41. 0.1 means 10%, 0.25 means 25%, 1.0 means 100%, and so on.
  42.  
  43. These note-tags are additive, and can be gained from all the sources I listed
  44. above (actros, classes, equipment, etc).
  45.  
  46. The skill and item note-tags will only be added if the used skill/item has
  47. the note-tag, while the rest of them will always be active, regardless of which
  48. skill/item is used.
  49.  
  50. You can use multiple of these note-tags on the same object to setup values for
  51. multiple hit mods.
  52.  
  53. Examples:
  54.  
  55.   <hit_mod: melee, 0.33>
  56.   <hit_mod: long_range, -0.85>
  57.   <hit_mod: mid_range, 0.55>
  58.  
  59. #-------------------------------------------------------------------------------
  60. - Installation:
  61. #-------------------------------------------------------------------------------
  62. Place this script between Materials and Main.
  63.  
  64. #-------------------------------------------------------------------------------
  65. =end
  66. # Settings:
  67. module HE_Mods
  68.   # Default hit value for actors and enemies.
  69.   # This values will only be used when attacking a target with the note-tag
  70.   # <hit_type: x>. If the target is not tagged with that note-tag, the default
  71.   # database values will be used (default hit rate calculation).
  72.   # Also, the script will only redirect the hit calculation for physical
  73.   # attacks, magical attacks will use the default database values only!
  74.   DefHIT = 0.25 # 25% hit rate
  75.  
  76. end
  77. # End of settings!
  78. #-------------------------------------------------------------------------------
  79.  
  80. class RPG::BaseItem
  81.  
  82.   attr_accessor :hit_type, :hit_mod
  83.  
  84.   def hit_type
  85.     init_hit_type if @hit_type.nil?
  86.     return @hit_type
  87.   end
  88.  
  89.   def init_hit_type
  90.     @hit_type = @note =~ /<hit_type:\s*(.*)>/i ? $1 : ""
  91.   end
  92.  
  93.   def hit_mod
  94.     init_hit_mod if @hit_mod.nil?
  95.     return @hit_mod
  96.   end
  97.  
  98.   def init_hit_mod
  99.     @hit_mod = {}
  100.     cnote = @note.clone
  101.     while cnote =~ /<hit_mod:(?:\s*)(.*)(?:\s*),(?:\s*)(.*)>/i
  102.       @hit_mod[$1] = $2.to_f
  103.       cnote.sub!(/<hit_mod:(?:\s*)(.*)(?:\s*),(?:\s*)(.*)>/i,"")
  104.     end
  105.   end
  106.    
  107. end
  108.  
  109. class Game_Battler < Game_BattlerBase
  110.  
  111.   def hit_mod(type)
  112.     val = HE_Mods::DefHIT
  113.     feature_objects.each do |ft|
  114.       val += ft.hit_mod[type] || 0
  115.     end
  116.     return val
  117.   end
  118.    
  119.   def item_hit(user, item)
  120.     rate = item.success_rate * 0.01     # Get success rate
  121.     if item.physical? # Physical attack: Multiply hit rate
  122.       htp = self.is_a?(Game_Actor) ? actor.hit_type : enemy.hit_type
  123.       if htp == ""
  124.         mul = user.hit
  125.       else
  126.         mul = user.hit_mod(htp)
  127.         mul += item.hit_mod[htp] || 0.0
  128.       end
  129.       rate *= mul  
  130.     end
  131.     return rate    # Return calculated hit rate
  132.   end
  133.  
  134. end
  135. # End of script!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement