Advertisement
QuasiXi

Quasi Fixed Passive

Mar 26th, 2014
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.67 KB | None | 0 0
  1. #==============================================================================
  2. #** Quasi Fixed Passive Skills v 1.00
  3. #==============================================================================
  4. # Allows Passive Skills to give a fixed value to params.
  5. # SParams and XParams, are not included.
  6. #==============================================================================
  7. # Instructions:
  8. #  Use the Skill Note Tag.  Tag is not case sensative, but it is space sensative!
  9. #
  10. #------------------------------------------------------------------------------
  11. # * Skill Note Tag
  12. #------------------------------------------------------------------------------
  13. # <fixed_passive>
  14. # param value
  15. # </fixed_passive>
  16. # param can be: MHP, MMP, ATK, DEF, MAT, MDF, AGI, LUK
  17. # values can be set to a fixed number or a percent with a % sign
  18. #
  19. # * Example
  20. # <fixed_passive>
  21. # MHP 50%
  22. # ATK 1000
  23. # </fixed_passive>
  24. #
  25. # This skill will add 50 percent hp and it will add 1000 atk.
  26. #
  27. #==============================================================================#
  28. # By Quasi (http://quasixi.wordpress.com/)
  29. #  - 3/26/14
  30. #==============================================================================#
  31. #   ** Stop! Do not edit anything below, unless you know what you      **
  32. #   ** are doing!                                                      **
  33. #==============================================================================#
  34.  
  35. $imported = {} if $imported.nil?
  36. $imported["Quasi_Fixed_Passive"] = 1.00
  37. module Quasi
  38.   def self.param_id(string)
  39.     case string.downcase
  40.     when "mhp"
  41.       0
  42.     when "mmp"
  43.       1
  44.     when "atk"
  45.       2
  46.     when "def"
  47.       3
  48.     when "mat"
  49.       4
  50.     when "mdf"
  51.       5
  52.     when "agi"
  53.       6
  54.     when "luk"
  55.       7
  56.     end
  57.   end
  58. end
  59.  
  60. #==============================================================================
  61. # ** Game_BattlerBase
  62. #------------------------------------------------------------------------------
  63. #  This base class handles battlers. It mainly contains methods for calculating
  64. # parameters. It is used as a super class of the Game_Battler class.
  65. #==============================================================================
  66.  
  67. class Game_BattlerBase
  68.   alias quasi_passive_init initialize
  69.   #--------------------------------------------------------------------------
  70.   # * ALIAS Object Initialization
  71.   #--------------------------------------------------------------------------
  72.   def initialize
  73.     quasi_passive_init
  74.     clear_passive_plus
  75.   end
  76.   #--------------------------------------------------------------------------
  77.   # * OVERWRITE Get Parameter
  78.   #--------------------------------------------------------------------------
  79.   def param(param_id)
  80.     value = param_base(param_id) + param_plus(param_id)
  81.     value += @passive_param[param_id]
  82.     value *= @passive_per[param_id]
  83.     value *= param_rate(param_id) * param_buff_rate(param_id)
  84.     [[value, param_max(param_id)].min, param_min(param_id)].max.to_i
  85.   end
  86.   #--------------------------------------------------------------------------
  87.   # * NEW Clear Values Added to Parameter
  88.   #--------------------------------------------------------------------------
  89.   def clear_passive_plus
  90.     @passive_param = [0] * 8
  91.     @passive_per = [1] * 8
  92.   end
  93.   #--------------------------------------------------------------------------
  94.   # * NEW Runs passive
  95.   #--------------------------------------------------------------------------
  96.   def fixed_passive(type, param_id, value, percent)
  97.     case type
  98.     when :param
  99.       @passive_param[param_id] += value if !percent
  100.       @passive_per[param_id] += value/100.0 if percent
  101.     end
  102.     refresh
  103.   end
  104. end
  105. #==============================================================================
  106. # ** Game_Actor
  107. #------------------------------------------------------------------------------
  108. #  This class handles actors. It is used within the Game_Actors class
  109. # ($game_actors) and is also referenced from the Game_Party class ($game_party).
  110. #==============================================================================
  111.  
  112. class Game_Actor < Game_Battler
  113.   alias quasi_passive_learn learn_skill
  114.   alias quasi_passive_forget forget_skill
  115.   #--------------------------------------------------------------------------
  116.   # * Learn Skill
  117.   #--------------------------------------------------------------------------
  118.   def learn_skill(skill_id)
  119.     add_fixed_passive(skill_id)
  120.     quasi_passive_learn(skill_id)
  121.   end
  122.   #--------------------------------------------------------------------------
  123.   # * Forget Skill
  124.   # remove passive needs to be above the alias!
  125.   #--------------------------------------------------------------------------
  126.   def forget_skill(skill_id)
  127.     remove_fixed_passive(skill_id)
  128.     quasi_passive_forget(skill_id)
  129.   end
  130.   #--------------------------------------------------------------------------
  131.   # * Add Passive values
  132.   #--------------------------------------------------------------------------
  133.   def add_fixed_passive(skill_id)
  134.     unless skill_learn?($data_skills[skill_id])
  135.       passive = $data_skills[skill_id].quasi_passive
  136.       passive.each {|p| passive_list(p, 1)} if passive
  137.     end
  138.   end
  139.   #--------------------------------------------------------------------------
  140.   # * Removes Passive values
  141.   # Only if skill is known to prevent param to be lowered when skill/passive
  142.   # is not learned.
  143.   #--------------------------------------------------------------------------
  144.   def remove_fixed_passive(skill_id)
  145.     if skill_learn?($data_skills[skill_id])
  146.       passive = $data_skills[skill_id].quasi_passive
  147.       passive.each {|p| passive_list(p, -1)} if passive
  148.     end
  149.   end
  150.   #--------------------------------------------------------------------------
  151.   # * Converts note tag to array [param, value]
  152.   # Checks if it includes % if so, sets percent value to true
  153.   #--------------------------------------------------------------------------
  154.   def passive_list(passive, add)
  155.     param = passive.scan(/\S+/)
  156.     id = Quasi::param_id(param[0].downcase)
  157.     percent = param[1].include?("%")
  158.     value = param[1].delete("%")
  159.     fixed_passive(:param, id, value.to_i*add, percent)
  160.   end
  161. end
  162.  
  163. #==============================================================================
  164. # ** RPG::Skill
  165. # * Note Tags
  166. #==============================================================================
  167. class RPG::Skill
  168.   def quasi_passive
  169.     if @qpassive.nil?
  170.       if @note =~ /<(?:fixed_passive)>(.*)<\/(?:fixed_passive)>/im
  171.         @qpassive = []
  172.         for p in $1.split("\r\n")
  173.           @qpassive.push(p) if p != ""
  174.         end
  175.       else
  176.         @qpassive = false
  177.       end
  178.     end
  179.     @qpassive
  180.   end
  181. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement