mrbubble

Learned Skills Stat Bonus

Jul 30th, 2012
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.32 KB | None | 0 0
  1. #==============================================================================
  2. # ++ Learned Skills Stat Bonus ++                               v1.0 (7/30/12)
  3. #==============================================================================
  4. # Script by:
  5. #     Mr. Bubble ( http://mrbubblewand.wordpress.com/ )
  6. # Thanks:
  7. #     YF, mass alias code reference
  8. #--------------------------------------------------------------------------
  9. # This script allows the ability to provide stat bonuses for any skills
  10. # learned by an actor. That's it.
  11. #
  12. # It doesn't matter if the skill is usable or not usable. As long as the
  13. # actor has a skill learned, the actor will gain any stat bonuses it may
  14. # provide. I guess this is akin to "passive skills", but I did not
  15. # want to name it as that since this will work even with active skills.
  16. #
  17. # This script has no effect on enemy stats.
  18. #
  19. # I made this script to study and practice mass method aliasing. I don't
  20. # think a lot of people will find this that useful.
  21. #--------------------------------------------------------------------------
  22. #   ++ Changelog ++
  23. #--------------------------------------------------------------------------
  24. # v1.0 : Initial release. (7/30/2012)
  25. #--------------------------------------------------------------------------
  26. #   ++ Installation ++
  27. #--------------------------------------------------------------------------
  28. # Install this script in the Materials section in your project's
  29. # script editor.
  30. #==============================================================================
  31. #   ++ TO Crafting Notetags ++
  32. #==============================================================================
  33. # Note: Some tags are given shorter tags for typing convenience. You only
  34. #       need to use one <tag> from a given group for a notebox.
  35. #       Use common sense.
  36. #
  37. # The following Notetags are for Skills only:
  38. #  
  39. # <learn bonus>
  40. # stat
  41. # stat
  42. # </learn bonus>
  43. #
  44. #   This tag allows you define the stat bonuses for learning the skill.
  45. #   You can add as many stats between the <learn bonus> tags as you like.
  46. #   Stat names are not case-sensitive. The following stats are available:
  47. #
  48. #     mhp n
  49. #     mmp n
  50. #     atk n
  51. #     def n
  52. #     mat n
  53. #     mdf n
  54. #     agi n
  55. #     luk n
  56. #
  57. #       There are the regular stats. The names should be self-explanatory.
  58. #       n can be any positive or negative number.
  59. #
  60. #     hit n%
  61. #     eva n%
  62. #     cri n%
  63. #     cev n%
  64. #     mev n%
  65. #     mrf n%
  66. #     cnt n%
  67. #     hrg n%
  68. #     mrg n%
  69. #     trg n%
  70. #     tgr n%
  71. #     grd n%
  72. #     rec n%
  73. #     pha n%
  74. #     mcr n%
  75. #     tcr n%
  76. #     pdr n%
  77. #     mdr n%
  78. #     fdr n%
  79. #     exr n%
  80. #
  81. #       These are the xparams, the stats that you can't normally see.
  82. #       It's important to note that all these stats deal with rates. That
  83. #       means n% should be between 0.0% ~ 100.0% whether it's positive
  84. #       or negative.
  85. #
  86. # Here is an example of a <learn bonus> tag:
  87. #
  88. #     <learn bonus>
  89. #     atk +10
  90. #     cri +0.5%
  91. #     </learn bonus>
  92. #
  93. # Learning this skill increases the actor's ATK by +10 and CRI by 0.5%
  94. #
  95. #--------------------------------------------------------------------------
  96. #   Parameter Abbreviations
  97. #--------------------------------------------------------------------------
  98. #     MHP  Maximum Hit Points
  99. #     MMP  Maximum Magic Points
  100. #     ATK  ATtacK power
  101. #     DEF  DEFense power
  102. #     MAT  Magic ATtack power
  103. #     MDF  Magic DeFense power
  104. #     AGI  AGIlity
  105. #     LUK  LUcK
  106. #     HIT  HIT rate
  107. #     EVA  EVAsion rate
  108. #     CRI  CRItical rate
  109. #     CEV  Critical EVasion rate
  110. #     MEV  Magic EVasion rate
  111. #     MRF  Magic ReFlection rate
  112. #     CNT  CouNTer attack rate
  113. #     HRG  Hp ReGeneration rate
  114. #     MRG  Mp ReGeneration rate
  115. #     TRG  Tp ReGeneration rate
  116. #     TGR  TarGet Rate
  117. #     GRD  GuaRD effect rate
  118. #     REC  RECovery effect rate
  119. #     PHA  PHArmacology
  120. #     MCR  Mp Cost Rate
  121. #     TCR  Tp Charge Rate
  122. #     PDR  Physical Damage Rate
  123. #     MDR  Magical Damage Rate
  124. #     FDR  Floor Damage Rate
  125. #     EXR  EXperience Rate
  126. #
  127. #--------------------------------------------------------------------------
  128. #   ++ Compatibility ++
  129. #--------------------------------------------------------------------------
  130. # This script aliases the following default VXA methods:
  131. #
  132. #     DataManager#load_database
  133. #     Game_BattlerBase#params
  134. #     All the xparams in Game_BattlerBase
  135. #    
  136. # There are no default method overwrites.
  137. #
  138. # Requests for compatibility with other scripts are welcome.
  139. #--------------------------------------------------------------------------
  140. #   ++ Terms and Conditions ++
  141. #--------------------------------------------------------------------------
  142. # Please do not repost this script elsewhere without permission.
  143. # Free for non-commercial use. For commercial use, contact me first.
  144. #
  145. # Newest versions of this script can be found at
  146. #                                           http://mrbubblewand.wordpress.com/
  147. #==============================================================================
  148.  
  149. $imported ||= {}
  150. $imported["BubsLearnedSkillsStatBonus"] = true
  151.  
  152. #==========================================================================
  153. # ++ START OF USER CUSTOMIZATION MODULE ++
  154. #==========================================================================
  155. module Bubs
  156.   #==========================================================================
  157.   # ++ Learn Bonus Settings
  158.   #==========================================================================
  159.   module LearnBonus
  160.   #--------------------------------------------------------------------------
  161.   #   Param Strings
  162.   #--------------------------------------------------------------------------
  163.   # Do not alter any of the default parameter names here. You can,
  164.   # however, add any custom stats provided by other scripts into the
  165.   # arrays if your project has them.
  166.   #
  167.   # PARAMS contain parameters that are flat values.
  168.   # XPARAMS contain parameters that are rates (i.e. percentages, chance)
  169.   PARAMS  = [:mhp, :mmp, :atk, :def, :mat, :mdf, :agi, :luk]
  170.  
  171.   XPARAMS = [:hit, :eva, :cri, :cev, :mev, :mrf, :cnt, :hrg,
  172.              :mrg, :trg, :tgr, :grd, :rec, :pha, :mcr, :tcr,
  173.              :pdr, :mdr, :fdr, :exr]
  174.   end # module LearnBonus
  175. end # module Bubs
  176.  
  177. #==========================================================================
  178. # ++ END OF USER CUSTOMIZATION MODULE ++
  179. #==========================================================================
  180.  
  181.  
  182.  
  183. #==========================================================================
  184. # ++ DataManager
  185. #==========================================================================
  186. module DataManager
  187.   #--------------------------------------------------------------------------
  188.   # alias : load_database
  189.   #--------------------------------------------------------------------------
  190.   class << self; alias load_database_bubs_learn_bonus load_database; end
  191.   def self.load_database
  192.     load_database_bubs_learn_bonus # alias
  193.     load_notetags_bubs_learn_bonus
  194.   end
  195.  
  196.   #--------------------------------------------------------------------------
  197.   # new method : load_notetags_bubs_learn_bonus
  198.   #--------------------------------------------------------------------------
  199.   def self.load_notetags_bubs_learn_bonus
  200.     for obj in $data_skills
  201.       next if obj.nil?
  202.       obj.load_notetags_bubs_learn_bonus
  203.     end # for obj
  204.   end # def
  205.  
  206. end # module DataManager
  207.  
  208.  
  209. #==========================================================================
  210. # ++ Bubs::Regexp
  211. #==========================================================================
  212. module Bubs
  213.   module Regexp
  214.     LEARN_BONUS_START_TAG = /<learn[_\s]?bonus>/i
  215.     LEARN_BONUS_END_TAG = /<\/learn[_\s]?bonus>/i
  216.     LEARN_BONUS_PARAM_TAG = /(\w+)\s*([-+]?\d+\.?\d*)[%]?/i
  217.   end # module Regexp
  218. end # module Bubs
  219.  
  220.  
  221. #==========================================================================
  222. # ++ RPG::BaseItem
  223. #==========================================================================
  224. class RPG::BaseItem
  225.   #--------------------------------------------------------------------------
  226.   # public instance variables
  227.   #--------------------------------------------------------------------------
  228.   attr_accessor :learn_bonus
  229.   #--------------------------------------------------------------------------
  230.   # common cache : load_notetags_bubs_learn_bonus
  231.   #--------------------------------------------------------------------------
  232.   def load_notetags_bubs_learn_bonus
  233.     initialize_learn_bonus
  234.    
  235.     learn_bonus_tag = false
  236.    
  237.     self.note.split(/[\r\n]+/).each { |line|
  238.       case line
  239.       when Bubs::Regexp::LEARN_BONUS_START_TAG
  240.         learn_bonus_tag = true
  241.       when Bubs::Regexp::LEARN_BONUS_END_TAG
  242.         learn_bonus_tag = false
  243.  
  244.       else
  245.         next unless learn_bonus_tag
  246.         next unless line =~ Bubs::Regexp::LEARN_BONUS_PARAM_TAG ? true : false
  247.         if Bubs::LearnBonus::PARAMS.include?($1.to_sym)
  248.           @learn_bonus[$1.to_sym] = $2.to_i
  249.         elsif Bubs::LearnBonus::XPARAMS.include?($1.to_sym)
  250.           @learn_bonus[$1.to_sym] = $2.to_f
  251.         end
  252.        
  253.       end # case
  254.     } # self.note.split
  255.   end
  256.  
  257.   #--------------------------------------------------------------------------
  258.   # common cache : initialize_learn_bonus
  259.   #--------------------------------------------------------------------------
  260.   def initialize_learn_bonus
  261.     @learn_bonus = {}
  262.     symbols = Bubs::LearnBonus::PARAMS + Bubs::LearnBonus::XPARAMS
  263.     symbols.each { |param|
  264.       @learn_bonus[param] = 0
  265.     }
  266.   end
  267.  
  268. end # RPG::BaseItem
  269.  
  270.  
  271. #==============================================================================
  272. # ++ Game_BattlerBase
  273. #==============================================================================
  274. class Game_BattlerBase
  275.   #--------------------------------------------------------------------------
  276.   # mass alias methods        # referenced from YF
  277.   #--------------------------------------------------------------------------
  278.   Bubs::LearnBonus::XPARAMS.each { |param|
  279.     aString = %Q<
  280.     alias #{param}_bubs_learned_skill_bonus #{param}
  281.     def #{param}
  282.       base = #{param}_bubs_learned_skill_bonus
  283.       bonus = learned_skill_stat_bonus(:#{param})
  284.       return base + bonus
  285.     end
  286.     >
  287.     module_eval(aString)
  288.  
  289.   } # !!
  290.  
  291.   #--------------------------------------------------------------------------
  292.   # alias : param
  293.   #--------------------------------------------------------------------------
  294.   alias param_bubs_learned_skill_bonus param
  295.   def param(param_id)
  296.     param_sym = {0 => :mhp, 1 => :mmp, 2 => :atk, 3 => :def, 4 => :mat,
  297.     5 => :mdf, 6 => :agi, 7 => :luk}
  298.     base = param_bubs_learned_skill_bonus(param_id)
  299.     bonus = learned_skill_stat_bonus(param_sym[param_id])
  300.     value = base + bonus
  301.     return [[value, param_max(param_id)].min, param_min(param_id)].max.to_i
  302.   end
  303.  
  304.   #--------------------------------------------------------------------------
  305.   # new method : learned_skill_stat_bonus
  306.   #--------------------------------------------------------------------------
  307.   def learned_skill_stat_bonus(symbol)
  308.     n = 0
  309.     return n unless actor?
  310.     skills.each { |skill| n += skill.learn_bonus[symbol] }
  311.     n *= 0.01 if Bubs::LearnBonus::XPARAMS.include?(symbol)
  312.     return n
  313.   end
  314.  
  315. end # class Game_BattlerBase
Add Comment
Please, Sign In to add comment