adiktuzmiko

Critical EX v1.01

May 23rd, 2013
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.14 KB | None | 0 0
  1. #==============================================================================
  2. #
  3. # Critical EX v1.01
  4. # by AdiktuzMiko
  5. # --- Date Created: 05/23/2013
  6. # --- Last Date Updated: 06/21/2013
  7. # --- Level: Easy
  8. #
  9. # Basically it allows you to tag objects to enable critical hits in all
  10. # hits (attack/skill must have allow criticals turned on)
  11. # And also allows you to tag objects to protect from critical hits
  12. #
  13. # Also allows you to define what will happen if an incoming damage is affected
  14. # by perfect critical, while the target is protected from criticals
  15. #
  16. # Why not just add 100% critical rate to the object? Well because the formula
  17. # for critical selection is critical*(1-critical evasion), so if you have 100%
  18. # critical, but the target has a higher than 0 cev, then you can still miss that
  19. # critical. And also because it will still be subjected to traits that can lower
  20. # critical rate if you do it that way.
  21. #
  22. # Now that means that critical immunity is doable by default, but I added it too
  23. # to this system just so its easier to set up the scenario where the damage
  24. # has perfect crit and target has immunity. And also so that immunity won't
  25. # be affected by traits that could lower cev value.
  26. #
  27. # You can now also alter the critical formula to be used. You can even
  28. # set actors, classes or enemies to have different formulas.
  29. # Requires: Elements EX
  30. #
  31. #==============================================================================
  32. #   ++ Notetags ++
  33. #==============================================================================
  34. #
  35. # These tags goes into Actors, Classes, Items, Skills, Weapons, Armors, Enemies
  36. # and States
  37. #
  38. # <CRITEX> = Flags that object to have perfect critical
  39. # <ANTICRITEX> = Flags that object to have critical immunity
  40. #
  41. # For actors, classes and enemies only
  42. #
  43. # Note: class critical formula will override the actor formula
  44. #       REQUIRES my ElementsEX script
  45. #
  46. # <CRITICAL_START> = Flags the start of a custom critical formula
  47. #   Place your custom ruby formula here!
  48. # <CRITICAL_END> = Flags the end of a custom critical formula
  49. #
  50. # self => the target of the damage
  51. # user => the source of the damage
  52. # item => item or skill used to deal the damage
  53. # damage => current damage amount
  54. #
  55. # ex:
  56. # <CRITICAL_START>
  57. # user.mhp*10
  58. # <CRITICAL_END>
  59. #
  60. # Everytime an actor/class/enemy tagged with this attacks and scores a critical
  61. # he will deal critical damage equal to his max hp times 10.
  62. #
  63. # <CRITICAL_START>
  64. # damage + user.mhp*10
  65. # <CRITICAL_END>
  66. #
  67. # Everytime an actor/class/enemy tagged with this attacks and scores a critical
  68. # he will deal critical damage equal to the damage amount + 10 times his maximum hp.
  69. #
  70. # Note: critical damage is the last calculation in the damage part
  71. #
  72. #==============================================================================
  73. #   ++ Installation ++
  74. #==============================================================================
  75. # Install this script in the Materials section in your project's
  76. # script editor.
  77. #
  78. # Edit the WHAT_TO_DO constant to fit your needs then start tagging objects!
  79. #
  80. #==============================================================================
  81. #   ++ Compatibility ++
  82. #==============================================================================
  83. # This script aliases the following default VXA methods:
  84. #
  85. #     Game_Battler#make_damage_value
  86. #    
  87. # There are no default method overwrites.
  88. #
  89. # Place this under ElementsEX if you have that script.
  90. #
  91. #==============================================================================
  92. #   ++ Terms and Conditions ++
  93. #==============================================================================
  94. #
  95. # This script is free to use
  96. #
  97. #==============================================================================
  98.  
  99. $imported = {} if $imported.nil?
  100. $imported["CriticalEX"] = true
  101.  
  102. #==========================================================================
  103. # ++ Adiktuz::Crit
  104. #==========================================================================
  105. module Adiktuz
  106.   module Crit
  107.     #==========================================================================
  108.     # Determines what to do if the damage has a perfect critical flag
  109.     # while the target has a critical immunity flag
  110.     #
  111.     # Values:
  112.     #
  113.     # 1 -> Perfect critical takes into effect
  114.     # 2 -> Critical Immunity takes into effect
  115.     # Any other number -> Lets the default system handle the critical chance
  116.     #==========================================================================
  117.     WHAT_TO_DO = 3
  118.    
  119.     #==========================================================================
  120.     # Determines the critical formula to be used
  121.     #
  122.     # REQUIRES my Elements EX script
  123.     #
  124.     # self => the target of the damage
  125.     # user => the source of the damage
  126.     # item => item or skill used to deal the damage
  127.     # damage => current damage amount
  128.     #
  129.     #==========================================================================
  130.     CRITICAL_FORMULA = "damage * 2"
  131.   end #module Crit
  132. end #module Adiktuz
  133.  
  134. #==========================================================================
  135. # ++ DataManager
  136. #==========================================================================
  137. module DataManager
  138.   #--------------------------------------------------------------------------
  139.   # alias : load_database
  140.   #--------------------------------------------------------------------------
  141.   class << self; alias load_database_critex load_database; end
  142.   def self.load_database
  143.     load_database_critex # alias
  144.     load_notetags_critex
  145.   end
  146.  
  147.   #--------------------------------------------------------------------------
  148.   # new method : load_notetags_critex
  149.   #--------------------------------------------------------------------------
  150.   def self.load_notetags_critex
  151.     groups = [$data_skills, $data_weapons, $data_armors, $data_actors,
  152.               $data_states, $data_classes, $data_items, $data_enemies]
  153.     for group in groups
  154.       for obj in group
  155.         next if obj.nil?
  156.         obj.load_notetags_critex
  157.       end # for obj
  158.     end # for group
  159.   end # def
  160.  
  161. end # module DataManager
  162.  
  163.  
  164. #==========================================================================
  165. # ++ Adiktuz::Regexp
  166. #==========================================================================
  167. module Adiktuz
  168.   module Regexp
  169.     CRIT_TAG = /<CRITEX>/i
  170.     ANTI_CRIT_TAG = /<ANTICRITEX>/i
  171.     CRITICAL_START = /<CRITICAL_START>/i
  172.     CRITICAL_END = /<CRITICAL_END>/i
  173.   end # module Regexp
  174. end # module Adiktuz
  175.  
  176.  
  177. #==========================================================================
  178. # ++ RPG::BaseItem
  179. #==========================================================================
  180. class RPG::BaseItem
  181.   #--------------------------------------------------------------------------
  182.   # public instance variables
  183.   #--------------------------------------------------------------------------
  184.   attr_accessor :crit_ex
  185.   attr_accessor :anti_crit_ex
  186.   attr_accessor :critical_formula
  187.   #--------------------------------------------------------------------------
  188.   # common cache : load_notetags_critex
  189.   #--------------------------------------------------------------------------
  190.   def load_notetags_critex
  191.     @crit_ex = false
  192.     @anti_crit_ex = false
  193.     @critical_formula = nil
  194.     crit_start = false
  195.    
  196.     self.note.split(/[\r\n]+/).each { |line|
  197.       case line
  198.       when Adiktuz::Regexp::CRIT_TAG
  199.         @crit_ex = true
  200.       when Adiktuz::Regexp::ANTI_CRIT_TAG
  201.         @anti_crit_ex = true
  202.       when Adiktuz::Regexp::CRITICAL_START
  203.         crit_start = true
  204.       when Adiktuz::Regexp::CRITICAL_END
  205.         crit_start = false
  206.       else
  207.         @critical_formula = "" if @critical_formula.nil? && crit_start
  208.         @critical_formula += line.to_s if crit_start
  209.       end # case
  210.     } # self.note.split
  211.   end # def load_notetags_critex
  212. end # class RPG::BaseItem
  213.  
  214.  
  215. #==========================================================================
  216. # ++ Game_Battler
  217. #==========================================================================
  218. class Game_Battler < Game_BattlerBase
  219.  
  220.   #--------------------------------------------------------------------------
  221.   # new method : has_anti_critex?
  222.   #--------------------------------------------------------------------------
  223.   def has_anti_critex?
  224.     if actor? then
  225.       return true if self.actor.anti_crit_ex
  226.       return true if self.class.anti_crit_ex
  227.       for equip in equips
  228.         next if equip.nil?
  229.         return true if equip.anti_crit_ex
  230.       end
  231.       for state in states
  232.         next if state.nil?
  233.         return true if state.anti_crit_ex
  234.       end
  235.     end
  236.     if enemy? then
  237.       return true if self.enemy.anti_crit_ex
  238.       for state in states
  239.         next if state.nil?
  240.         return true if state.anti_crit_ex
  241.       end
  242.     end
  243.     return false
  244.   end
  245.  
  246.   #--------------------------------------------------------------------------
  247.   # new method : has_critex?
  248.   #--------------------------------------------------------------------------
  249.   def has_critex?(user,item)
  250.     return true if item.crit_ex
  251.     if user.actor? then
  252.       return true if user.actor.crit_ex
  253.       return true if user.class.crit_ex
  254.       for equip in user.equips
  255.         next if equip.nil?
  256.         return true if equip.crit_ex
  257.       end
  258.       for state in user.states
  259.         next if state.nil?
  260.         return true if state.crit_ex
  261.       end
  262.     end
  263.     if user.enemy? then
  264.       return true if user.enemy.crit_ex
  265.       for state in user.states
  266.         next if state.nil?
  267.         return true if state.crit_ex
  268.       end
  269.     end
  270.     return false
  271.   end
  272.  
  273.  
  274.   #--------------------------------------------------------------------------
  275.   # aliased method : make_damage_value(user,item)
  276.   #--------------------------------------------------------------------------
  277.   alias CritEX make_damage_value
  278.   def make_damage_value(user,item)
  279.     positive = has_critex?(user,item)
  280.     negative = has_anti_critex?
  281.     if positive then
  282.       if negative then
  283.         case Adiktuz::Crit::WHAT_TO_DO
  284.         when 1
  285.           @result.critical = true
  286.         when 2
  287.           @result.critical = false
  288.         end
  289.       else
  290.         @result.critical = true
  291.       end
  292.     elsif negative
  293.       @result.critical = false
  294.     end
  295.     CritEX(user,item)
  296.   end
  297.  
  298.   #--------------------------------------------------------------------------
  299.   # aliased method : apply_critical(damage)
  300.   #--------------------------------------------------------------------------
  301.   if $imported["ElementEX"]
  302.     alias apply_critical_exe apply_critical
  303.     def apply_critical(damage)
  304.       #Just so it doesn't do anything
  305.     end
  306.   end
  307.  
  308.   def apply_critical_ex(damage,user,item)
  309.     if user.actor?
  310.       if not user.class.critical_formula.nil?
  311.         return eval(user.class.critical_formula)
  312.       elsif not user.actor.critical_formula.nil?
  313.         return eval(user.actor.critical_formula)
  314.       end
  315.     elsif user.enemy?
  316.       if not user.enemy.critical_formula.nil?
  317.         return eval(user.enemy.critical_formula)
  318.       end
  319.     end
  320.     eval(Adiktuz::Crit::CRITICAL_FORMULA)
  321.   end
  322.  
  323. end
Advertisement
Add Comment
Please, Sign In to add comment