Heartbreak61

[SIMPLE STUPID] Parameter Growth v1.0

Jan 25th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 14.24 KB | None | 0 0
  1. $imported = {} if $imported.nil?
  2. $imported["HBK-SSPG"] = 1.0
  3. #==============================================================================
  4. # ■ SIMPLE STUPID PARAM GROWTH ver1.0
  5. # by HBK61
  6. # Requires: N/A
  7. # Rewrites method: N/A  
  8. # Aliases method:
  9. #   Data_Manager.load_database
  10. #   Game_Actor.setup
  11. #   Game_Battler.item_apply
  12. #==============================================================================
  13. # This simple-stupid script is intended to change default parameters (usually
  14. # called stats) by performing skils on battle.
  15. #
  16. # The basic idea is to make a character gain progress point for each action
  17. # and when he reach specified point, he will gain parameters.
  18. #
  19. # However, I give more options like growth chance, growth multiplier by actor,
  20. # growth multiplier by class, etc. in case you like to use more detailed
  21. # calculation.
  22. #
  23. #==============================================================================
  24. # ver1.0  2013.01.21  add notetags for various items
  25. #                     compacting syntax
  26. #                     make target calculation more simple
  27. #
  28. # ver0.9a 2012.08.16  fix class coefficient doesn't being calculated
  29. #                     fix bug that make game crash when GBAII is active
  30. #
  31. # ver0.9  2012.08.??  initial release
  32. #==============================================================================
  33. # TERMS OF USE
  34. #==============================================================================
  35. # Just don't claim this script as yours. No need to credit me in game :>
  36. #
  37. #==============================================================================
  38. # INSTRUCTIONS
  39. #==============================================================================
  40. ## TARGET = value
  41. # Is a target for the actor progress to gain parameters. After an actor's
  42. # progress point reach TARGET, he/she will gain parameters as declared in
  43. # PARAM_ADD then his/her progress point will be reset. You can set this TARGET
  44. # value to be dynamic or static. If TARGET_ADD is set more than 0.0, then the
  45. # TARGET will be increased by TARGET_ADD each time an actor's progress reaches
  46. # it.
  47. #-----------------------------------------------------------------------------
  48. ## PARAM_ADD = [mhp, mmp, atk, def, mat, mdf, agi, luk]
  49. # How much parameters you get after you progress passed TARGET.
  50. # For example you want your actor to get 5 MHP and 3 MMP and the other
  51. # parameters to 1 after he/she passed the TARGET, just set
  52. # PARAM_ADD = [5, 3, 1, 1, 1, 1, 1, 1]
  53. #-----------------------------------------------------------------------------
  54. ## GROW_CHANCE[param_id] = value
  55. # is random factor for the growth progress. Default value is 1.0 means 100%
  56. # chance your will get progress point on each parameters.
  57. #-----------------------------------------------------------------------------
  58. ## Actor Multiplier ##
  59. # <param_multiplier stat: 1.0>
  60. # replace stat with mhp, mmp, atk, def, mat, mdf, agi, luk
  61. #
  62. # Will decide how much progress point you will gain depend on each actor.
  63. # Total growth point per action comes from multiplying Class Multiplier &
  64. # Actor Multiplier.
  65. #
  66. ## Class Multiplier ##
  67. # <param_multiplier stat: 1.0>
  68. # replace stat with mhp, mmp, atk, def, mat, mdf, agi, luk
  69. #
  70. # Will decide how much progress point you will gain for each class.
  71. # This features is useful in case you want specific class to gain its
  72. # parameter progress more rapidly than another class.
  73. # Lets say you want Warrior to have higher ATK progress than Priest.
  74. # Total growth point per action comes from multiplying Actor Multiplier &
  75. # Class Multiplier.
  76. #-----------------------------------------------------------------------------
  77. ## GBAST, GBEST, GBAA, GBAE, GBAA_Include_Item
  78. #
  79. # You can see that I'm not creative in giving name, that's why I use
  80. # abbreviations in my module:P
  81. #-----------------------------------------------------------------------------
  82. # GBAST = Grow By Actor's Skill Hit Type (Certain Hit, Physical, Magical)
  83. # GBEST = Grow By Enemy's Skill Hit Type (Certain Hit, Physical, Magical)
  84. # GBAA = Grow By All - Actor
  85. # GBAE = Grow By All - Enemy
  86. # GBAA_Include_Item = Using item will grow parameter defined in GBAA
  87. #
  88. # Please look at examples below for instruction how to use this feature.
  89. #-----------------------------------------------------------------------------
  90. ## DISPLAY_GAIN
  91. # Will display a message whenever an actor gain a parameter. In case you're
  92. # In the middle of a battle, the parameter will be actually added once the
  93. # battle end.
  94. #
  95. #==============================================================================
  96. # NOTE
  97. #==============================================================================
  98. #* Each calculation is performed independently.
  99. #    For example you set GBAS[3] = [0] and GBAST[1] = [0] where skill 3 is
  100. #    categorized as skill type 1, MHP progress calculation will be performed
  101. #    twice.
  102. #    Another example: you set GBAS[3] = [0,0]
  103. #    This will result MHP progress calculation performed twice as well.
  104. #
  105. #* The actor will actually gain parameters after battle ends.
  106. #
  107. #* MHP doesn't change your current HP. For example you get 90/100 HP and gain
  108. #  10 MHP on a battle. After battle ends, your HP will be 90/110.
  109. #
  110. # PS: Sorry for my poor English and confusing instructions XD
  111. #==============================================================================
  112. # CREDITS FROM ME
  113. #==============================================================================
  114. # Yanfly for his Ace Debug Engine... Helps me a lot for testing :D
  115. # Rei_Fan49 for compacting the scripts
  116. #==============================================================================
  117.  
  118. module HBK
  119.   module SSPG
  120.   # Declaration of Constants. Leave it as it is!
  121.     GBAST = []
  122.     GBEST = []
  123.     GBAA = []
  124.     GBAE = []
  125.   #----------------------------------------------------------------------------  
  126.   # CONFIGURATIONS
  127.     TARGET = 20
  128.     TARGET_ADD = [
  129.     2.0, # <= MHP
  130.     1.0, # <= MMP
  131.     0.5, # <= ATK
  132.     0.5, # <= DEF
  133.     0.5, # <= MAT
  134.     0.5, # <= MDF
  135.     0.5, # <= AGI
  136.     0.5, # <= LUK
  137.     ] # <= Don't delete this!
  138.    
  139.     PARAM_ADD = [
  140.     10, # <= MHP
  141.     5,  # <= MMP
  142.     1,  # <= ATK
  143.     1,  # <= DEF
  144.     1,  # <= MAT
  145.     1,  # <= MDF
  146.     1,  # <= AGI
  147.     1,  # <= LUK
  148.     ]
  149.    
  150.     GROW_CHANCE = [
  151.     1.0, # <= MHP
  152.     1.0, # <= MMP
  153.     1.0, # <= ATK
  154.     1.0, # <= DEF
  155.     1.0, # <= MAT
  156.     1.0, # <= MDF
  157.     1.0, # <= AGI
  158.     1.0, # <= LUK
  159.     ] # <= Don't delete this!
  160.      
  161.     # GBAST/GBEST[skill_id/skill_hit_type] = [param1, param2, etc]
  162.     GBAST[2] = [1,4] # will grow MMP and MAT when actor use any skill with hit type 2 (Magical)
  163.     GBEST[2] = [5,6] # will grow MDF and AGI when enemy use any skill with hit type 2 (Magical)
  164.     # GBAE/GBAA = [param_id 1, param_id 2]
  165.     GBAA = [6,7] # will grow AGI and LUK when any skill is performed by actor.
  166.     GBAE = [6]   # will grow AGI when any skill is performed by enemy.
  167.     # using items will be considered GBAA (default: false).
  168.     GBAA_Include_Item = false
  169.     # will display message window parameter gain (default: true).
  170.     DISPLAY_GAIN = true
  171.     # just a simple stupid way to track actor's progress on Ace console window.
  172.     DISPLAY_CONSOLE = true
  173.     #----------------------------------------------------------------------------  
  174.     # END OF CONFIGURATION
  175.  
  176.    
  177. #==============================================================================
  178. # WARNING!
  179. # Don't edit anything below this point unless you know what you're doing :>
  180. #==============================================================================
  181.   end #module SSPG
  182. #-----------------------------------------------------------------------------
  183.   module REGEX
  184.     PARAM_MULTIPLIER = /<param_multiplier\s+(mhp|mmp|atk|def|mat|mdf|agi|luk)\s*:\s*(\d+.\d+)>/i
  185.     ENEMY_GROW_PARAM = /<enemy_skill_grow\s*:\s*(mhp|mmp|atk|def|mat|mdf|agi|luk)>/i
  186.     ACTOR_GROW_PARAM = /<actor_skill_grow\s*:\s*(mhp|mmp|atk|def|mat|mdf|agi|luk)>/i
  187.   end
  188. end #module REGEX
  189.  
  190. module DataManager
  191.   class <<self
  192.     alias hbk_sspg_load_database load_database
  193.   end
  194.  
  195.   def self.load_database
  196.     hbk_sspg_load_database
  197.     hbk_sspg_scan_notes
  198.   end
  199.  
  200.   def self.hbk_sspg_scan_notes
  201.     groups = [$data_actors,$data_classes,$data_skills]
  202.     for group in groups
  203.       for obj in group
  204.         next if obj.nil?
  205.         obj.hbk_sspg_scan_notes
  206.       end
  207.     end
  208.   end
  209.  
  210. end # DataManager
  211.  
  212. class RPG::Actor < RPG::BaseItem
  213.   def hbk_sspg_scan_notes
  214.     @param_multiplier = []
  215.     self.note.split(/[\r\n]+/).each {|line|
  216.     case line
  217.     when HBK::REGEX::PARAM_MULTIPLIER
  218.       case $1
  219.       when 'mhp'
  220.         @param_multiplier[0] = $2.to_f
  221.       when 'mmp'
  222.         @param_multiplier[1] = $2.to_f
  223.       when 'atk'
  224.         @param_multiplier[2] = $2.to_f
  225.       when 'def'
  226.         @param_multiplier[3] = $2.to_f
  227.       when 'mat'
  228.         @param_multiplier[4] = $2.to_f
  229.       when 'mdf'
  230.         @param_multiplier[5] = $2.to_f
  231.       when 'agi'
  232.         @param_multiplier[6] = $2.to_f
  233.       when 'luk'
  234.         @param_multiplier[7] = $2.to_f
  235.       end
  236.     end
  237.     }
  238.   end
  239.   attr_accessor :param_multiplier
  240. end #RPG::Actor
  241.  
  242. class RPG::Class < RPG::BaseItem
  243.   def hbk_sspg_scan_notes
  244.     @param_multiplier = []
  245.     self.note.split(/[\r\n]+/).each {|line|
  246.     case line
  247.     when HBK::REGEX::PARAM_MULTIPLIER
  248.       case $1
  249.       when 'mhp'
  250.         @param_multiplier[0] = $2.to_f
  251.       when 'mmp'
  252.         @param_multiplier[1] = $2.to_f
  253.       when 'atk'
  254.         @param_multiplier[2] = $2.to_f
  255.       when 'def'
  256.         @param_multiplier[3] = $2.to_f
  257.       when 'mat'
  258.         @param_multiplier[4] = $2.to_f
  259.       when 'mdf'
  260.         @param_multiplier[5] = $2.to_f
  261.       when 'agi'
  262.         @param_multiplier[6] = $2.to_f
  263.       when 'luk'
  264.         @param_multiplier[7] = $2.to_f
  265.       end
  266.     end
  267.     }
  268.   end
  269.   attr_accessor :param_multiplier
  270. end #RPG::Class
  271.  
  272. class RPG::Skill < RPG::UsableItem
  273.   def hbk_sspg_scan_notes
  274.     @actor_grow_param = []
  275.     @enemy_grow_param = []
  276.     self.note.split(/[\r\n]+/).each {|line|
  277.     case line
  278.     when HBK::REGEX::ACTOR_GROW_PARAM
  279.       case $1
  280.       when 'mhp'
  281.         @actor_grow_param.push(0)
  282.       when 'mmp'
  283.         @actor_grow_param.push(1)
  284.       when 'atk'
  285.         @actor_grow_param.push(2)
  286.       when 'def'
  287.         @actor_grow_param.push(3)
  288.       when 'mat'
  289.         @actor_grow_param.push(4)
  290.       when 'mdf'
  291.         @actor_grow_param.push(5)
  292.       when 'agi'
  293.         @actor_grow_param.push(6)
  294.       when 'luk'
  295.         @actor_grow_param.push(7)
  296.       end
  297.     end
  298.     }
  299.     self.note.split(/[\r\n]+/).each {|line|
  300.     case line
  301.     when HBK::REGEX::ENEMY_GROW_PARAM
  302.       case $1
  303.       when 'mhp'
  304.         @enemy_grow_param.push(0)
  305.       when 'mmp'
  306.         @enemy_grow_param.push(1)
  307.       when 'atk'
  308.         @enemy_grow_param.push(2)
  309.       when 'def'
  310.         @enemy_grow_param.push(3)
  311.       when 'mat'
  312.         @enemy_grow_param.push(4)
  313.       when 'mdf'
  314.         @enemy_grow_param.push(5)
  315.       when 'agi'
  316.         @enemy_grow_param.push(6)
  317.       when 'luk'
  318.         @enemy_grow_param.push(7)
  319.       end
  320.     end
  321.     }
  322.   end
  323.   attr_accessor :actor_grow_param, :enemy_grow_param
  324. end #RPG::Skill
  325.  
  326. class Game_Battler;include HBK;end
  327.  
  328. class Game_Actor < Game_Battler
  329.   alias hbk_sspg_setup setup
  330.   attr_accessor :actor_multiplier, :class_multiplier, :cur_progress, :tgt_progress
  331.   def setup(actor_id)
  332.     hbk_sspg_setup(actor_id)
  333.     @cur_progress = []
  334.     @tgt_progress = []
  335.     @actor_multiplier = [1.0] * 8
  336.     setup_param_grow
  337.     setup_actor_multiplier(actor_id)
  338.   end
  339.  
  340.   def setup_param_grow
  341.     n = HBK::SSPG::TARGET
  342.     @cur_progress = [0] * 8
  343.     @tgt_progress = [n] * 8
  344.   end
  345.  
  346.   def setup_actor_multiplier(actor_id)
  347.     (0..7).each {|i|
  348.       @actor_multiplier[i] = actor.param_multiplier[i] if actor.param_multiplier[i]
  349.     }
  350.   end
  351.  
  352.   def param_grow(param_id)
  353.       cm = self.class.param_multiplier
  354.       (0..7).each {|i|
  355.         cm[i] = 1.0 if cm[i].nil?
  356.       }
  357.       grow = @actor_multiplier[param_id] * cm[param_id]
  358.       if rand < HBK::SSPG::GROW_CHANCE[param_id]
  359.       if @cur_progress[param_id] < (@tgt_progress[param_id] - grow)
  360.         @cur_progress[param_id] += grow
  361.         if HBK::SSPG::DISPLAY_CONSOLE
  362.           puts (actor.name + "'s " + Vocab::param(param_id) + "AM is " +    @actor_multiplier[param_id].to_s)
  363.           puts (actor.name + "'s " + Vocab::param(param_id) + "CM is " + cm[param_id].to_s)
  364.           puts (actor.name + "'s " + Vocab::param(param_id) + "grow is " + grow.to_s)
  365.           puts (actor.name + "'s " + Vocab::param(param_id) + " current progress is " + @cur_progress[param_id].to_s)
  366.           puts (actor.name + "'s " + Vocab::param(param_id) + " target progress is " + @tgt_progress[param_id].to_s + "\n\n")
  367.         end
  368.       else
  369.         n = HBK::SSPG::TARGET_ADD[param_id]
  370.         @cur_progress[param_id] -= @tgt_progress[param_id]
  371.         @tgt_progress[param_id] += n
  372.         if HBK::SSPG::PARAM_ADD[param_id] >= 1
  373.           add_param(param_id, HBK::SSPG::PARAM_ADD[param_id])
  374.           if HBK::SSPG::DISPLAY_GAIN
  375.             $game_message.add(actor.name + " " + Vocab::param(param_id) + " is increased by " + HBK::SSPG::PARAM_ADD[param_id].to_s + "!")
  376.           end
  377.         end
  378.       end
  379.     end
  380.   end #param_grow
  381.    
  382. end #Game_Actor
  383.  
  384. class Game_Battler < Game_BattlerBase
  385.   alias hbk_item_apply item_apply
  386.   def item_apply(user, item)
  387.     hbk_item_apply(user, item)
  388.       if item.is_a?(RPG::Skill)
  389.          a = item.actor_grow_param
  390.          b = HBK::SSPG::GBAST[item.hit_type]
  391.          c = item.enemy_grow_param
  392.          d = HBK::SSPG::GBEST[item.hit_type]
  393.          e = HBK::SSPG::GBAA
  394.          f = HBK::SSPG::GBAE
  395.          bool = HBK::SSPG::GBAA_Include_Item
  396.          _growparam = []
  397.          _user = nil
  398.          if user.is_a?(Game_Actor)
  399.            _growparam = [a,b,e]
  400.            _user = user
  401.          elsif user.is_a?(Game_Enemy)
  402.            _growparam = [c,d,f]
  403.             _user = self
  404.          end
  405.          _growparam.each { |param_plus|
  406.             unless param_plus.nil?
  407.                param_plus.each { |n|
  408.                   _user.param_grow(n) if !n.nil? && n < 8
  409.                }
  410.             end
  411.          }
  412.       elsif user.is_a?(Game_Actor)
  413.          user.param_grow(n) if bool && n < 8
  414.       end
  415.   end #item_apply
  416. end #Game_Battler
Advertisement
Add Comment
Please, Sign In to add comment