Advertisement
Guest User

Multi Hit Skills v1.1 (for RMVX)

a guest
Nov 2nd, 2011
678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 14.03 KB | None | 0 0
  1. #--------------------------------------------------------------------------
  2. # Multi Hit Skills (RMVX)
  3. #
  4. #   Author : Logan Forrests
  5. #   With   : Mr G W
  6. #   Date Created   : 20 August 2011
  7. #   Date Finished  : 20 August 2011
  8. #   Last Updated   : 03 November 2011
  9. #   Latest Version : 1.1
  10. #
  11. #--------------------------------------------------------------------------
  12. # Version History
  13. #--------------------------------------------------------------------------
  14. #
  15. #   v1.1 - 11.03.2011
  16. #       Introduces new paramters:
  17. #         - allowing a missed or evaded hit to stop further damage calculation
  18. #         - Critical hit factored into individual hits
  19. #       Code updated to fit coding standards
  20. #   v1.0  - 08.20.2011
  21. #       Original release of the script
  22. #
  23. #--------------------------------------------------------------------------
  24. # Description
  25. #--------------------------------------------------------------------------
  26. # Allows skills to be assigned a specific number of hits.
  27. #
  28. # For example, Quad Slash is intended to be a 4-hit physical skill. By
  29. # specifying this in the Database, the skill would be calculated as if it
  30. # was dealing 4 individual hits. Each individual hit of a multiple hit skill
  31. # is calculated seperately with the damage dealt by each hit being cumulitive
  32. # to provide the total damage dealt. This also means that the accuracy of
  33. # the skill and the evasion of the target is considered on each hit and not the
  34. # skill as a whole. Thus, of the 4 hits of Quad Slash, only 2 may hit and
  35. # contribute towards damage.
  36. #
  37. # The messages associated with attacks missing and being evaded will only be
  38. # shown when all hits of an attack miss or are evaded.
  39. #
  40. # Because the properties are kept within an items BaseItem class, it can also
  41. # be used for Items as well as Skills.
  42. #
  43. #--------------------------------------------------------------------------
  44. # Directions On How To Implement
  45. #--------------------------------------------------------------------------
  46. # Assigning the Number of Hits
  47. # ----------------------------
  48. # To specify the number of hits a skill has simply use the following the tag
  49. # within the Note field in the Database of the appropriate skills:
  50. #
  51. #   <mhs_hits: #>  - where # is the number of hits
  52. #
  53. # It is advised that skills that are made multiple hit are given a lower than
  54. # 100 hit ratio. Setting a skill to have a hit ratio of 100 will mean all hits
  55. # will land unless evaded which may result in a largely unbalanced skill.
  56. # This is, however, not required and skills may be set a 100 hit ratio if desired.
  57. #
  58. # Implementing Critical Hits
  59. # --------------------------
  60. # It is possible to assign a critical hit ratio, allowing a skill to sometimes
  61. # deal a critical blow on any one (or more) or its hits:
  62. #
  63. #   <mhs_crit: c% d%>
  64. #       - where c is the critical hit chance as a percentage
  65. #       - where d is the critical damage bonus
  66. #
  67. # The '%' signs are optional and not required to function properly. It is allowed
  68. # simply for aesthetic and readability.
  69. # The value of c should be an integer value between 0 and 100;
  70. #     0 being no critical hit chance, 100 being always critical.
  71. # The value of d should be an integer value above 100.
  72. #   Note: A d value of 150 means 150% or 1.5x damage dealt. This is to follow the same
  73. #      calculation style as the default scripts. Thus, setting a value less than
  74. #      100 will reduce the damage dealt.
  75. #
  76. # Ending Damage Calculation Upon a Missed or Evaded Attack
  77. # --------------------------------------------------------
  78. # To make a skill stop damage calculation processing when the attack misses
  79. # or is evaded, the following tag can be used:
  80. #  
  81. #   <mhs_end_on_miss>
  82. #
  83. # No additional value is required.
  84. # This particular additional allows one to create skills that are 'interrupted'
  85. # should an attack miss somewhere during execution. Using this produces
  86. # a more realistic* effect but can lead to a much smaller average in damage.
  87. #
  88. # *Realistic in the sense that the attacker is caught off-guard when an attack
  89. # does not connect or is evaded by the target and can no longer continue the
  90. # barrage of attacks he is delivering. Mostly used for close combat type skills.
  91. #--------------------------------------------------------------------------
  92. # Script Installation & Compatibility
  93. #--------------------------------------------------------------------------
  94. #
  95. # Simply place the script in the Materials section of the Script Editor,
  96. # somewhere above Main.
  97. # If using this to extend GW Extra Skill Features, this script must be placed
  98. # below that script.
  99. #
  100. # This script is based from GW Extra Skill Features and thus is compatible
  101. # with it. It is also suggested that the GW Extra Skill Features is used
  102. # with this script, also it is not necessary.
  103. #
  104. # This script overwrites the following the methods:
  105. #   skill_effect
  106. #       - Removes the accuracy and evasion checks from this method.
  107. #   make_obj_damage_value
  108. #       - Includes critical hit damage calculation
  109. #          - The default value can be set within this script in the LF::MHS
  110. #            module; custom values can be assigned on a per skill basis.
  111. #
  112. # This script aliases the following methods:
  113. #   make_obj_damage_value
  114. #       - Implements a while loop to allow calculating of cumulative damage
  115. #         for multiple hit skills
  116. #       - Includes accuracy and evasion checks for each hit
  117. #         but only sets the @missed and @evaded flags if all hits of a skill
  118. #         miss or are evaded.
  119. #--------------------------------------------------------------------------
  120. # Support & Credit
  121. #--------------------------------------------------------------------------
  122. # The script has been written and tested with no other scripts in place. As
  123. # such, if you encounted any issues with regards to other scripts,
  124. # first try to resolve the problem by moving this script around. If you are
  125. # still unable to resolve the problem, feel free to contact me on rmrk.net
  126. # under the name LoganForrests (no spaces involved) with the name of the
  127. # script(s) you find no longer work when this script is included and the
  128. # nature of the problem(s) so that I can begin to work on the problem(s)
  129. # being caused.
  130. #
  131. # Credit must be given if used.
  132. #
  133. # Credit must also be given to Mr G W as this script is based and designed from
  134. # their Extra Skill Features script. When used as an extension to the Extra
  135. # Skill Features script, this script follows the same copyright restrictions.
  136. #--------------------------------------------------------------------------
  137. #==========================================================================    
  138. #=============         CUSTOMISE THE SCRIPT HERE            ===============    
  139. #==========================================================================
  140. module LF
  141.   module MHS
  142.     #Allows critical hit bonuses from weapon/actor trait to be included
  143.     # in the critical hit rate check. Will currently only apply to skills
  144.     # which have their Physical Attack flag checked true.
  145.     INCLUDE_USER_BONUSES = true
  146.    
  147.     #Set the damage multiplier for a critical hit
  148.     # This is the default multiplier; it will be overwritten if a crit hit
  149.     # damage multiplier is also assigned in the Note field of the Skill.
  150.     # A crit multiplier of 3 means that a critical hit will deal 300% damage
  151.     # This value should not be set less than 1 (100% damage) as this will
  152.     # reduce the final damage.
  153.     CRIT_MULTIPLIER = 3
  154.   end
  155. end
  156. #==========================================================================    
  157. #=============       NO MORE CUSTOMISING THE SCRIPT         ===============    
  158. #==========================================================================    
  159. #=============       DO NOT EDIT THE CONTENTS BELOW         ===============    
  160. #==========================================================================
  161.  
  162. class RPG::BaseItem
  163.  
  164.   #assume 1 hit if not specified
  165.   def skillhits
  166.     self.note[/<mhs_hits: ([-0-9]+)>/]
  167.     return 1 if $1 == nil
  168.     return $1.to_i
  169.   end
  170.  
  171.   #determine if calculation of damage should end on a miss/evade
  172.   def miss_means_end
  173.     return true if self.note[/<mhs_end_on_miss>/]
  174.     return false
  175.   end
  176.  
  177.   #chance of critical hit - value is based on percentage
  178.   # First Value  : critical hit chance/ratio
  179.   # Second Value : critical hit damage bonus (if provided)
  180.   def mhs_cri
  181.     self.note[/<mhs_crit: ([-0-9]+)(?:[%]*)[ ]*([-0-9]*)(?:[%]*)>/]
  182.     return [$1.to_i, $2.to_i]
  183.   end
  184.  
  185. end
  186.  
  187.  
  188. class Game_Battler
  189.  
  190.   #---------------------------------------------------------------
  191.   # overwrite: skill_effect
  192.   #     Removed some checks - see Note at line 123
  193.   #---------------------------------------------------------------
  194.   def skill_effect(user, skill)
  195.     clear_action_results
  196.     unless skill_effective?(user, skill)
  197.       @skipped = true
  198.       return
  199.     end
  200.     #NOTE:
  201.     #removed hit and evasion check from here to make_obj_damage_value
  202.     #in order to perform this check for each hit in a multi hit skill
  203.     #Effect stays the same even if single hit.
  204.     make_obj_damage_value(user, skill)            # calculate damage
  205.     make_obj_absorb_effect(user, skill)           # calculate absorption effect
  206.     execute_damage(user)                          # damage reflection
  207.     if skill.physical_attack && @hp_damage == 0   # physical and no damage?
  208.       return                                    
  209.     end
  210.     apply_state_changes(skill)                    # state change
  211.   end
  212.  
  213.   #--------------------------------------------------------------------------
  214.   # overwrite: make_obj_damage_value
  215.   #    Adds critical hit to obj damage calculation
  216.   #
  217.   #* Calculation of Damage Caused by Skills or Items
  218.   #     user : User of skill or item
  219.   #     obj  : Skill or item (for normal attacks, this is nil)
  220.   #    The results are substituted for @hp_damage or @mp_damage.
  221.   #--------------------------------------------------------------------------
  222.   def make_obj_damage_value(user, obj)
  223.     damage = obj.base_damage                        # get base damage
  224.     if damage > 0                                   # a positive number?
  225.       damage += user.atk * 4 * obj.atk_f / 100      # Attack F of the user
  226.       damage += user.spi * 2 * obj.spi_f / 100      # Spirit F of the user
  227.       unless obj.ignore_defense                     # Except for ignore defense
  228.         damage -= self.def * 2 * obj.atk_f / 100    # Attack F of the target
  229.         damage -= self.spi * 1 * obj.spi_f / 100    # Spirit F of the target
  230.       end
  231.       damage = 0 if damage < 0                      # If negative, make 0
  232.     elsif damage < 0                                # a negative number?
  233.       damage -= user.atk * 4 * obj.atk_f / 100      # Attack F of the user
  234.       damage -= user.spi * 2 * obj.spi_f / 100      # Spirit F of the user
  235.     end
  236.     damage *= elements_max_rate(obj.element_set)    # elemental adjustment
  237.     damage /= 100
  238.     #added by LoganForrests
  239.       #to_i used due to possible floating point calculations
  240.     damage = (damage * critical_damage(user, obj)).to_i
  241.     #end added code
  242.     damage = apply_variance(damage, obj.variance)   # variance
  243.     damage = apply_guard(damage)                    # guard adjustment
  244.     if obj.damage_to_mp  
  245.       @mp_damage = damage                           # damage MP
  246.     else
  247.       @hp_damage = damage                           # damage HP
  248.     end
  249.   end
  250.  
  251.   def critical_damage(user, obj)
  252.     crit_chance = obj.mhs_cri[0]
  253.     if LF::MHS::INCLUDE_USER_BONUSES && obj.physical_attack
  254.       crit_chance += user.cri
  255.     end
  256.     crit_multi = obj.mhs_cri[1]
  257.     @critical = (rand(100) < crit_chance)           # critical hit?
  258.     @critical = false if prevent_critical           # criticals prevented?
  259.     if @critical #is a critical hit
  260.       if crit_multi >= 100 #safety net for silly values like 50% damage
  261.         return (crit_multi/100.0).to_i if @critical
  262.       else #otherwise, use 'default' multiplier
  263.         return LF::MHS::CRIT_MULTIPLIER if @critical
  264.       end
  265.     end
  266.     return 1 #1 will ensure normal damage calculation if not critical
  267.   end
  268.   #---------------------------------------------------------------
  269.   # alias method: make_obj_damage_value
  270.   #     calculates damage on a per hit basis
  271.   #---------------------------------------------------------------
  272.   alias :lfmhs_modv_gb_cd3e :make_obj_damage_value
  273.   def make_obj_damage_value(user, obj, *args)
  274.     #get number of hits of skill
  275.     hits = obj.skillhits
  276.     #repeat original method for 'hits' number of times,
  277.     #storing the total damage to HP and MP
  278.     #Set default variables
  279.     count = 0 #hit cycle count
  280.     totalhpdamage = 0 #total damage to HP
  281.     totalmpdamage = 0 #total damage to MP (where required)
  282.     miss_count = 0  #for correct message displaying - only if all hits miss
  283.     evade_count = 0 #for correct message displaying - only if all hits evaded
  284.     while (count < hits)  #count starts at 0; cycle is: count until hits - 1
  285.       #Check accuracy and evasion
  286.       if rand(100) >= calc_hit(user, obj)
  287.         if obj.miss_means_end
  288.           #stop damage processing by ending while loop
  289.           break
  290.         end
  291.         miss_count += 1 #missed a hit
  292.         count += 1 #next hit
  293.         next
  294.       end
  295.       if rand(100) < calc_eva(user, obj)
  296.         if obj.miss_means_end
  297.           #stop damage processing by ending while loop
  298.           break
  299.         end
  300.         evade_count += 1 #evaded a hit
  301.         count += 1 #next hit
  302.         next
  303.       end
  304.       #check if all hits have been missed or evaded
  305.       if miss_count == hits
  306.         @missed = true
  307.         return #don't process damage; show miss message
  308.       end
  309.       if evade_count == hits
  310.         @evaded = true
  311.         return #don't process damage; show evade message
  312.       end
  313.       #run original to get damage for this current hit
  314.       lfmhs_modv_gb_cd3e(user, obj, *args)
  315.       totalhpdamage += @hp_damage
  316.       totalmpdamage += @mp_damage
  317.       #increase counter
  318.       count += 1
  319.     end
  320.     @hp_damage = totalhpdamage
  321.     @mp_damage = totalmpdamage
  322.   end
  323.    
  324. end
  325.  
  326.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement