Advertisement
roninator2

TG22 - Better Critical Chance - mod

Dec 4th, 2024
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.07 KB | None | 0 0
  1. #===============================================================================#
  2. #
  3. #  Better Critical Chance
  4. #   Custom Script File by TG22
  5. #   Mod by Roninator2
  6. #   This script creates skill notetags to give the developper a better control
  7. #  of skills' critical chance
  8. #-------------------------------------------------------------------------------#
  9. # Status : v0 : Just implemented, needs alpha testing.
  10. #-------------------------------------------------------------------------------#
  11. #
  12. #  Usage : In the skill notes you can add :
  13. #
  14. #  <critical chance: = 10>
  15. #  This notetag will override the battler crit chance (but not the "can-crit?"
  16. #   flag of the skill). In this example, if the skill can crit, the chance is
  17. #   10%, whoever uses it. Only the target CEV can modify it.
  18. #  Set the value to zero and the skill will not be able to crit.
  19. #  The entered value must be an integer!
  20. #
  21. #  <critical chance: + 5>
  22. #  <critical chance: - 5>
  23. #  Unless overriden by an "=" notetag, this skill will have an additional chance
  24. #   to have a critical effect. In this example, if the user has 4% cri, the
  25. #   resulting crit chance will be 4+5 = 9% or 9-5 = 4%
  26. #  Note: the target's cev is applied to the final value (9%)
  27. #  The entered value must be an integer!
  28. #
  29. #  <critical chance: x 110>
  30. #  Unless overriden by an "=" notetag, this skill will have a multiplied chance
  31. #   to have a critical effect. In this example, if the user has 4% cri, the
  32. #   resulting critical chance will be 4 * 1.10 = 4.4%
  33. #  Note: the target's cev is applied to the final value (4.4%)
  34. #  Note: Can be used to increase or decrease (<100%) crit chance.
  35. #  The entered value must be an integer!
  36. #
  37. #  Stacking :
  38. #  <critical chance: x 110>
  39. #  <critical chance: + 5>
  40. #  If these two tags are used, and unless they are overriden by the "=" notetag,
  41. #  if the battler has a base 4% cri, the resulting crit chance will be :
  42. #  (4 + 5) * 1.10 = 9.9% chance. The multiply tag is applied after the
  43. #  additive one.
  44. #  Note: the target's cev is applied to the final value (9.9%)
  45. #
  46. #-------------------------------------------------------------------------------#
  47. # Compatibility :
  48. #  Warning : the method
  49. #  -Game_Battler > item_cri
  50. #  is erased.
  51. #-------------------------------------------------------------------------------#
  52. # Configuration
  53. #===============================================================================#
  54.  
  55. module TGTT
  56.   module BETTERCRITCHANCE
  57.     REGEXP_CRITCHANCE = /<critical[ -_]chance:[ -_](.)[ -_](\d+)>/i
  58.   end
  59. end
  60.  
  61. #===============================================================================#
  62. # End of Configuration
  63. #-------------------------------------------------------------------------------#
  64. # Erasing the crit chance computation
  65. #===============================================================================#
  66.  
  67. class Game_Battler < Game_BattlerBase
  68.   def item_cri(user, item)
  69.     #Zero crit chance if the critical flag is not set.
  70.     return 0 unless item.damage.critical
  71.     #Base user crit chance
  72.     base_cri = user.cri
  73.     #Apply additional notetag
  74.     if item.critchance_additional != 0.0
  75.       base_cri += item.critchance_additional
  76.     end
  77.     #Apply subtractive notetag
  78.     if item.critchance_subtractive != 0.0
  79.       base_cri -= item.critchance_subtractive
  80.       base_cri = 0 if base_cri < 0
  81.     end
  82.     #Apply multiplicative notetag
  83.     if item.critchance_multiplier != 1.0
  84.       base_cri *= item.critchance_multiplier
  85.     end
  86.     #Apply overriding notetag, if present
  87.     if !item.critchance_override.nil?
  88.       base_cri = item.critchance_override
  89.     end
  90.     #Applying CEV to the final value.
  91.     return base_cri * (1.0 - cev)
  92.   end
  93. end
  94.  
  95. #===============================================================================#
  96. # Notetag management
  97. #===============================================================================#
  98.  
  99. module DataManager
  100.   #Aliasing the module "static" method
  101.   class << self
  102.     alias hrpg_betcc_load_database load_database
  103.   end
  104.  
  105.   def self.load_database
  106.     hrpg_betcc_load_database
  107.     hrpg_betcc_load_notetags
  108.   end
  109.  
  110.   def self.hrpg_betcc_load_notetags
  111.     for sk in $data_skills
  112.       next if sk.nil?
  113.       sk.hrpg_betcc_load_notetags
  114.     end
  115.   end
  116.  
  117. end
  118.  
  119. class RPG::BaseItem
  120.   attr_accessor :critchance_additional
  121.   attr_accessor :critchance_subtractive
  122.   attr_accessor :critchance_multiplier
  123.   attr_accessor :critchance_override
  124.  
  125.   def hrpg_betcc_load_notetags
  126.     #Default values.
  127.     @critchance_additional  = 0.0
  128.     @critchance_subtractive = 0.0
  129.     @critchance_multiplier  = 1.0
  130.     @critchance_override    = nil #nil means not present. Do not change that.
  131.  
  132.     self.note.split(/[\r\n]+/).each do |line|
  133.       case line
  134.       when TGTT::BETTERCRITCHANCE::REGEXP_CRITCHANCE
  135.         case $1
  136.         when '+'
  137.           @critchance_additional = $2.to_i * 0.01
  138.         when '-'
  139.           @critchance_subtractive = $2.to_i * 0.01
  140.         when 'x'
  141.           @critchance_multiplier = $2.to_i * 0.01
  142.         when '='
  143.           @critchance_override = $2.to_i * 0.01
  144.         end
  145.       end
  146.     end
  147.   end
  148.  
  149. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement