neonblack

Chain Skills v1.2

Jan 31st, 2013
152
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ##----------------------------------------------------------------------------##
  2. ## Chain Skills v1.2
  3. ## Created by Neon Black
  4. ##
  5. ## Only for non-commercial use.  See full terms of use and contact info at:
  6. ## http://cphouseset.wordpress.com/liscense-and-terms-of-use/
  7. ##----------------------------------------------------------------------------##
  8.                                                                               ##
  9. ##----------------------------------------------------------------------------##
  10. ##    Revision Info:
  11. ## v1.2 - 3.19.2013
  12. ##  Added combo skills
  13. ## v1.1 - 2.25.2013
  14. ##  Added finisher skills
  15. ##  Added customizable finisher options
  16. ##  Bugfixes and changes
  17. ## v1.0 - 1.31.2013
  18. ##  Wrote and debugged main script
  19. ##----------------------------------------------------------------------------##
  20.                                                                               ##
  21. $imported ||= {}                                                              ##
  22. $imported["CP_CHAIN_SKILLS"] = 1.2                                            ##
  23.                                                                               ##
  24. ##----------------------------------------------------------------------------##
  25. ##    Instructions:
  26. ## Place this script in the script editor below "Materials" and above "Main".
  27. ## This script allows skill sets to be defined as a chain skills command.
  28. ## Skills in this skill subset can be selected one after another to form a
  29. ## skill chain that will then be executed all at once.
  30. ##
  31. ##------
  32. ##    Notebox Tags:
  33. ##
  34. ## chain blocks[5]
  35. ##  - This tag can be used on actors, classes, and skills.  When used on an
  36. ##    actor or class, this tag is the default number of "blocks" the actor has
  37. ##    for a skill chain (with class taking priority.  When used on a skill,
  38. ##    this tag is the number of skill blocks required to use the skill.  The
  39. ##    value (5 in this case) can be set to any number.
  40. ## chain blocks[+2]  -or-  chain blocks[-2]
  41. ##  - This tag can be used on classes, weapons, armors, and states.  When used
  42. ##    on any of these, the tag increases or decreases the number of blocks the
  43. ##    actor has to use on skills.  There are cumulative, for example, +3, +2,
  44. ##    and -1 would result in +4 blocks.
  45. ## chain follow[2]  -or-  chain follow[2, 3, 4]  -etc.-
  46. ##  - This tag can be used on skills.  If this tag is present, the skill can
  47. ##    only be used after a skill with an ID present in the tag.  For example,
  48. ##    a skill tagged with "chain follow[22]" can only be used after skill ID 22
  49. ##    while a skill tagged with "chain follow[54, 55]" can be used after skills
  50. ##    ID 54 or 55.  You can have as many skill IDs in this tag as you wish.  A
  51. ##    skill can be told it can follow itself as well as any other skill.
  52. ## chain usage[1]
  53. ##  - This tag can be used on skills.  If this tag is present, the skill can
  54. ##    only be used the number of times defined in the tag per chain.  For
  55. ##    example, if the number "2" is used, the skill can only be in the chain
  56. ##    twice.
  57. ## <chain finisher>
  58. ##  - This tag can be used on skills.  If a skill is tagged with this, the skill
  59. ##    will end a chain, even if there are other skills that could be used.
  60. ##----------------------------------------------------------------------------##
  61.                                                                               ##
  62. module CP    # Do not touch                                                   ##
  63. module CHAIN #  these lines.                                                  ##
  64.                                                                               ##
  65. ##----------------------------------------------------------------------------##
  66. ##    Config:
  67. ## The config options are below.  You can set these depending on the flavour of
  68. ## your game.  Each option is explained in a bit more detail above it.
  69. ##
  70. ##------
  71. # These are the default values if no tags are used in skills or actors.  CHAIN
  72. # is the default number of blocks an actor has, COST is the default number of
  73. # blocks required per skill, and USAGE is the default number of times a skill
  74. # may be used in a single chain, set high by default to make it "limitless".
  75. DEFAULT_CHAIN = 3
  76. DEFAULT_COST  = 1
  77. DEFAULT_USAGE = 100
  78.  
  79. # If this value is set to true, only a single target may be used for "one
  80. # enemy", "one ally", or "one ally (dead)" scopes.  If the target is lost in
  81. # the middle of the chain for some reason, skills with these scopes will be
  82. # skipped.  If this value is set to false, a new target is found instead.
  83. SINGLE_TARGET = true
  84.  
  85. # This array contains the ID of the skill subsets that will be used as chain
  86. # skill sets.  All other skill subsets function normally.
  87. CHAIN_COMMS = [1]
  88.  
  89. # These are the minimum and maximum number of blocks an actor may have.
  90. MIN_BLOCKS = 1
  91. MAX_BLOCKS = 12
  92.  
  93. # These settings are used for the chain gauge.  If the first setting is set to
  94. # false, the rest of the settings are ignored.  IMAGE determines the file name
  95. # of the chain image which must be placed in "Graphics/System".  Gauge block is
  96. # the horizontal offset of each block in the image, which can be different if
  97. # you want each block to overlap.  Finally, OFFSET_XY is the x and y offsets of
  98. # the chain from it's default location.
  99. USE_GAUGE = true
  100. GAUGE_IMAGE = "ChainGauge"
  101. GAUGE_BLOCK = 26
  102. OFFSET_XY = [10, 0]
  103.  
  104. # These settings are for finishing a chain.  The BUTTON option is the symbol for
  105. # the button that can be pressed in order to end a chain instantly.  TEXT is the
  106. # name of the finish option to add to the skill list.  Either of these can be
  107. # set to nil if you do not want to use them.  ICON and HELP are used to make the
  108. # finish option look prettier in the menu.
  109. FINISH_BUTTON = :A
  110. FINISH_TEXT = "Finish"
  111. FINISH_ICON = 0
  112. FINISH_HELP = "Confirm selection and use skills"
  113.  
  114. ## Do not touch this line##
  115. ACTOR_COMBOS = {}##########
  116.  
  117. ## This hash contains the basic combo attacks for chain skills.  When the skills
  118. ## in the first array are used in that order, they become the skills in the
  119. ## second array.  This hash is used by all actors.
  120. COMBOS ={
  121.   [129, 129, 129] => [135],
  122. }
  123.  
  124. ## Similar to above, these hashes contain skill combos for an individual actor.
  125. ## To add combos for another actor, copy from "ACTOR_COMBOS" down to the
  126. ## reverse bracket "}" and paste a copy of it underneath the reverse bracket.
  127. ## Then change the number in "ACTOR_COMBOS[1]" to the actor's ID.  Note that
  128. ## these take priority over the combos above.
  129. ACTOR_COMBOS[1] ={
  130.   [129, 129, 129] => [134],
  131. }
  132.  
  133.  
  134. ##----------------------------------------------------------------------------##
  135.                                                                               ##
  136.                                                                               ##
  137. ##----------------------------------------------------------------------------##
  138. ## The following lines are the actual core code of the script.  While you are
  139. ## certainly invited to look, modifying it may result in undesirable results.
  140. ## Modify at your own risk!
  141. ###----------------------------------------------------------------------------
  142.  
  143.  
  144. end
  145. end
  146.  
  147. module BattleManager  ## Easier method for getting the chain array.
  148.   def self.chain_array
  149.     return SceneManager.scene.chain_array || []
  150.   end
  151. end
  152.  
  153. class Game_Battler < Game_BattlerBase
  154.   attr_accessor :temp_chain_action  ## Allows a temp action to be set in chains.
  155.  
  156.   alias :cp_c_act :current_action
  157.   def current_action
  158.     return @temp_chain_action || cp_c_act
  159.   end
  160. end
  161.  
  162. class Game_Actor < Game_Battler   ## Creates a new skill with the cost of all
  163.   def temp_array_cost(skill)      ## skills in the chain.
  164.     tpc, mpc, hpc, gpc, blk = 0, 0, 0, 0, 0
  165.     ipc, spc, swc, vwc, apc, wec, aec = [], [], [], [], [], [], []
  166.     (BattleManager.chain_array + [skill.id]).each do |id|
  167.       skill = $data_skills[id]
  168.       next unless skill
  169.       tpc += skill_tp_cost(skill)  ## Does extra costs if a cost manager has
  170.       mpc += skill_mp_cost(skill)  ## been imported.
  171.       if $imported["YEA-SkillCostManager"] || $imported["CP_SKILLCOSTS"]
  172.         hpc = skill_hp_cost(skill)
  173.         gpc = skill_gold_cost(skill)
  174.       end
  175.       if $imported["CP_SKILLCOSTS"]
  176.         ipc += skill.item_cost
  177.         spc += skill.req_state + skill.state_cost
  178.         swc += skill.req_switch
  179.         vwc += skill.req_variable
  180.         apc += skill.req_actor
  181.         wec += skill.req_w
  182.         aec += skill.req_a
  183.       end
  184.       blk += skill.chain_blocks
  185.     end
  186.     return false if blk > chain_blocks
  187.     temp_skill = RPG::Skill.new  ## Temp skill created for the test.
  188.     temp_skill.tp_cost = tpc
  189.     temp_skill.mp_cost = mpc
  190.     temp_skill.hp_cost = hpc
  191.     temp_skill.gold_cost = gpc
  192.     temp_skill.item_cost = ipc
  193.     temp_skill.req_state = spc.uniq
  194.     temp_skill.req_switch = swc.uniq
  195.     temp_skill.req_variable = vwc.uniq
  196.     temp_skill.req_actor = apc.uniq
  197.     temp_skill.req_w = wec.uniq
  198.     temp_skill.req_a = aec.uniq
  199.     return usable?(temp_skill)
  200.   end
  201.  
  202.   def usage_unused(skill)  ## Checks if the skill has been used max times.
  203.     BattleManager.chain_array.count(skill.id) < skill.chain_usage
  204.   end
  205.  
  206.   def same_targets(skill)  ## Ensures the skill uses the same kind of target.
  207.     return true if BattleManager.chain_array.empty?
  208.     return true if skill.for_user?
  209.     BattleManager.chain_array.each do |id|
  210.       next if $data_skills[id].for_user?
  211.       return skill.for_friend? == $data_skills[id].for_friend?
  212.     end
  213.     return true
  214.   end
  215.  
  216.   def chain_follow(item)  ## Checks if the skill properly follows another skill.
  217.     return true if item.chain_follow.empty?
  218.     i = BattleManager.chain_array[-1] || 0
  219.     return item.chain_follow.include?(i)
  220.   end
  221.  
  222.   def chain_blocks  ## Calculates the number of blocks an actor has.
  223.     r = self.class.chain_blocks || actor.chain_blocks
  224.     r += self.class.chain_modifier || 0
  225.     r = states.inject(r) {|o, n| o += n.chain_modifier}
  226.     r = equips.compact.inject(r) {|o, n| o += n.chain_modifier}
  227.     return [[r, 1, CP::CHAIN::MIN_BLOCKS].max, CP::CHAIN::MAX_BLOCKS].min
  228.   end
  229. end
  230.  
  231. class Window_BattleSkill < Window_SkillList
  232.   attr_writer :temp_skill  ## Temp skill for the chain.
  233.  
  234.   def enable?(item)  ## Longer check for each item with new params.
  235.     return false if item.id == 0 && BattleManager.chain_array.empty?
  236.     return false if finisher_enabled?(item.id)
  237.     super && @actor.usage_unused(item) && @actor.same_targets(item) &&
  238.     @actor.chain_follow(item) && @actor.temp_array_cost(item)
  239.   end
  240.  
  241.   def finisher_enabled?(id)
  242.     return false if id == 0
  243.     return false if BattleManager.chain_array.empty?
  244.     return false unless $data_skills[BattleManager.chain_array[-1]]
  245.     return $data_skills[BattleManager.chain_array[-1]].chain_finisher
  246.   end
  247.  
  248.   def no_selectable_skills?  ## Determines if any item is selectable.
  249.     return !@data.any? {|skill| skill.id != 0 && enable?(skill)}
  250.   end
  251.  
  252.   def item  ## Gets the item if a temp is used.
  253.     return @temp_skill || super
  254.   end
  255.  
  256.   def chain_skill_display=(window)  ## Gets the chain window.
  257.     @chain_skill_display = window
  258.   end
  259.  
  260.   def make_item_list
  261.     super
  262.     return unless CP::CHAIN::FINISH_TEXT &&
  263.                   CP::CHAIN::CHAIN_COMMS.include?(@stype_id)
  264.     finisher = RPG::Skill.new
  265.     finisher.name = CP::CHAIN::FINISH_TEXT
  266.     finisher.icon_index = CP::CHAIN::FINISH_ICON
  267.     finisher.description = CP::CHAIN::FINISH_HELP
  268.     finisher.chain_finisher = true
  269.     finisher.chain_blocks = 0
  270.     @data.push(finisher)
  271.   end
  272.  
  273.   alias :cp_cskill_ref :refresh
  274.   def refresh  ## Refresh the chain window.
  275.     cp_cskill_ref
  276.     @chain_skill_display.refresh if @chain_skill_display
  277.   end
  278.  
  279.   def process_handling  ## Adds a key to end selection entirely.
  280.     return unless open? && active
  281.     return process_finish if finish_trigger && !BattleManager.chain_array.empty?
  282.     super
  283.   end
  284.  
  285.   def finish_trigger
  286.     CP::CHAIN::FINISH_BUTTON && Input.trigger?(CP::CHAIN::FINISH_BUTTON)
  287.   end
  288.  
  289.   def process_finish  ## Finish process.
  290.     call_handler(:finish)
  291.   end
  292.  
  293.   def update_help
  294.     super  ## Update the gauge.
  295.     @chain_skill_display.refresh_gauge if @chain_skill_display
  296.   end
  297.  
  298.   alias :cp_cskill_show :show
  299.   def show  ## Recalculate height.
  300.     @norm_height = self.height
  301.     cp_cskill_show
  302.     return self unless @chain_skill_display &&
  303.                        CP::CHAIN::CHAIN_COMMS.include?(@stype_id)
  304.     @chain_skill_display.show
  305.     return self if self.y > @chain_skill_display.y
  306.     return self unless self.y + self.height >= @chain_skill_display.y
  307.     self.height = @chain_skill_display.y - self.y
  308.     refresh
  309.     return self
  310.   end
  311.  
  312.   alias :cp_cskill_hide :hide
  313.   def hide  ## Recalculate height.
  314.     cp_cskill_hide
  315.     self.height = @norm_height if @norm_height
  316.     @chain_skill_display.hide if @chain_skill_display
  317.     return self
  318.   end
  319.  
  320.   def actor  ## Gets the window actor.
  321.     return @actor
  322.   end
  323.  
  324.   def select_ending
  325.     select(item_max - 1)
  326.   end
  327. end
  328.  
  329. class Window_ChainDisplay < Window_Base
  330.   def initialize(skill_wind)  ## New window for chain display.
  331.     super(0 - standard_padding, 0, window_width, window_height)
  332.     @skill_window = skill_wind
  333.     @gauge = Sprite.new
  334.     self.opacity = 0
  335.     hide
  336.     set_positions
  337.     refresh
  338.   end
  339.  
  340.   def window_width
  341.     Graphics.width + standard_padding * 2
  342.   end
  343.  
  344.   def window_height
  345.     fitting_height(2)
  346.   end
  347.  
  348.   def set_positions  ## Sets the window and gauge positions.
  349.     self.y = Graphics.height - (120 + self.height)
  350.     oxy = CP::CHAIN::OFFSET_XY
  351.     @gauge.y = self.y + standard_padding + line_height / 2 + oxy[1]
  352.     @gauge.x = 0 + oxy[0]
  353.   end
  354.  
  355.   def dispose  ## Dispose the gauge.
  356.     @gauge.dispose
  357.     super
  358.   end
  359.  
  360.   def refresh_gauge  ## Creates the gauge from basic parts.
  361.     return unless CP::CHAIN::USE_GAUGE && @skill_window.actor
  362.     bitmap = Cache.system(CP::CHAIN::GAUGE_IMAGE)
  363.     ofs = bitmap.width / 5
  364.     wd = (@skill_window.actor.chain_blocks + 1) * CP::CHAIN::GAUGE_BLOCK + ofs
  365.     @gauge.bitmap = Bitmap.new(wd, bitmap.height)
  366.     @gauge.oy = @gauge.height / 2
  367.     rect = Rect.new(0, 0, ofs, bitmap.height)
  368.     xpl = 0
  369.     @gauge.bitmap.blt(xpl, 0, bitmap, rect)
  370.     blocks = 0
  371.     vals = @skill_window.item ? @skill_window.item.chain_blocks : 0
  372.     BattleManager.chain_array.each {|id| blocks += $data_skills[id].chain_blocks}
  373.     @skill_window.actor.chain_blocks.times do |i|
  374.       xpl += CP::CHAIN::GAUGE_BLOCK
  375.       if i < blocks
  376.         rect.x = ofs * 2
  377.       elsif i < blocks + vals && @skill_window.active
  378.         rect.x = ofs * 3
  379.       else
  380.         rect.x = ofs * 1
  381.       end
  382.       @gauge.bitmap.blt(xpl, 0, bitmap, rect)
  383.     end
  384.     xpl += CP::CHAIN::GAUGE_BLOCK
  385.     rect.x = ofs * 4
  386.     @gauge.bitmap.blt(xpl, 0, bitmap, rect)
  387.   end
  388.  
  389.   def back_color  ## Color and opacity of the back.
  390.     Color.new(0, 0, 0, back_opacity)
  391.   end
  392.  
  393.   def back_opacity
  394.     return 128
  395.   end
  396.  
  397.   def refresh
  398.     contents.clear
  399.     refresh_gauge
  400.     draw_back
  401.     draw_skills
  402.   end
  403.  
  404.   def draw_back  ## Draws the skill names in the chain.
  405.     contents.fill_rect(0, line_height, contents.width, line_height, back_color)
  406.   end
  407.  
  408.   def draw_skills
  409.     rect = Rect.new(contents.width - standard_padding, line_height,
  410.                     contents.width, line_height)
  411.     return unless BattleManager.chain_array
  412.     i = 0
  413.     BattleManager.chain_array.reverse_each do |id|
  414.       i += 1
  415.       skill = $data_skills[id]
  416.       rect.x -= contents.text_size(skill.name).width + 24
  417.       draw_item_name(skill, rect.x, rect.y, true, rect.width)
  418.       next if i == BattleManager.chain_array.size
  419.       rect.x -= contents.text_size(" > ").width
  420.       contents.draw_text(rect, " > ")
  421.       break if rect.x <= 0
  422.     end
  423.   end
  424.  
  425.   def show  ## Shows and hides the gauge.
  426.     @gauge.visible = true
  427.     super
  428.   end
  429.  
  430.   def hide
  431.     @gauge.visible = false
  432.     super
  433.   end
  434. end
  435.  
  436. class Scene_Battle  ## Holds onto the chain array.
  437.   attr_reader :chain_array
  438.  
  439.   alias :cp_cskill_create_swind :create_skill_window
  440.   def create_skill_window  ## Adds the new window and window handler.
  441.     cp_cskill_create_swind
  442.     @skill_window.set_handler(:finish, method(:shift_press_finish))
  443.     @chain_display_window = Window_ChainDisplay.new(@skill_window)
  444.     @skill_window.chain_skill_display = @chain_display_window
  445.   end
  446.  
  447.   alias :cp_chain_command_skill :command_skill
  448.   def command_skill  ## Alias the command skill to reset the chain.
  449.     @chain_array = []
  450.     @skill_window.temp_skill = nil
  451.     cp_chain_command_skill
  452.   end
  453.  
  454.   alias :cp_chain_skill_ok :on_skill_ok
  455.   def on_skill_ok  ## Checks if the skill set is a chain and processes.
  456.     @chain_array.push(@skill_window.item.id) unless @skill_window.item.id == 0
  457.     if !CP::CHAIN::CHAIN_COMMS.include?(@actor_command_window.current_ext)
  458.       cp_chain_skill_ok
  459.     elsif @skill_window.no_selectable_skills? ||
  460.           @skill_window.item.chain_finisher
  461.       @skill_window.refresh
  462.       @chain_shift_press = true if @skill_window.item.id == 0
  463.       finish_skill_chain_select
  464.     else
  465.       @skill_window.refresh
  466.       @skill_window.activate
  467.     end
  468.   end
  469.  
  470.   def shift_press_finish  ## The handler for if shift is pressed.
  471.     @chain_shift_press = true
  472.     Sound.play_ok
  473.     finish_skill_chain_select
  474.   end
  475.  
  476.   def finish_skill_chain_select  ## The end method for either chain finish.
  477.     @skill_window.select_ending if CP::CHAIN::FINISH_TEXT
  478.     @skill_window.deactivate
  479.     @skill_window.temp_skill = create_skill_chain_skill
  480.     @chain_display_window.refresh
  481.     cp_chain_skill_ok
  482.   end
  483.  
  484.   alias :cp_chain_skill_cancel :on_skill_cancel
  485.   def on_skill_cancel  ## Determines cancel type based on chain.
  486.     if @chain_array.empty?
  487.       cp_chain_skill_cancel
  488.     else
  489.       @chain_array.pop
  490.       @skill_window.refresh
  491.       @skill_window.activate
  492.     end
  493.   end
  494.  
  495.   alias :cp_cskill_e_cancel :on_enemy_cancel
  496.   def on_enemy_cancel  ## Pops the chain if a chain is being used.
  497.     cancel_cskill_pop
  498.     cp_cskill_e_cancel
  499.   end
  500.  
  501.   alias :cp_cskill_a_cancel :on_actor_cancel
  502.   def on_actor_cancel
  503.     cancel_cskill_pop
  504.     cp_cskill_a_cancel
  505.   end
  506.  
  507.   def cancel_cskill_pop  ## Perform a chain pop.
  508.     return if @chain_array.nil? || @chain_array.empty?
  509.     @chain_array.pop unless @chain_shift_press
  510.     @chain_shift_press = false
  511.     @skill_window.temp_skill = nil
  512.     @skill_window.refresh
  513.   end
  514.  
  515.   def create_skill_chain_skill         ## Creates the chain skill and a temp
  516.     @remove_chain_skills_array ||= []  ## array for later removal.
  517.     skill = RPG::Skill.new
  518.     skill.id = $data_skills.size
  519.     skill.chain_skill = true
  520.     skill.chain_array = @chain_array
  521.     skill.scope = get_chain_scope || $data_skills[@chain_array[0]].scope
  522.     $data_skills.push(skill)
  523.     @remove_chain_skills_array.push(skill)
  524.     return skill
  525.   end
  526.  
  527.   def get_chain_scope  ## Determines the scope of the entire chain.
  528.     @chain_array.each do |id|
  529.       skill = $data_skills[id]
  530.       return 1 if [1].include?(skill.scope)
  531.       return 7 if [7, 9].include?(skill.scope)
  532.     end
  533.     return nil
  534.   end
  535.  
  536.   alias :cp_chain_use_item :use_item
  537.   def use_item  ## Changes use_item for a chain method.
  538.     item = @subject.current_action.item
  539.     if item.chain_skill
  540.       mtarg = @subject.current_action.target_index
  541.       btarg = @subject.current_action.make_targets.compact
  542.       skip_num = 0
  543.       action_array = @subject.current_action.item.chain_array
  544.       action_array.each_with_index do |id,n|
  545.         if skip_num > 0
  546.           skip_num -= 1
  547.           next
  548.         end
  549.         st = [id]
  550.         skills_hash = CP::CHAIN::COMBOS.dup
  551.         if CP::CHAIN::ACTOR_COMBOS.include?(@subject.id)
  552.           CP::CHAIN::ACTOR_COMBOS[@subject.id].each { |k,r| skills_hash[k] = r }
  553.         end
  554.         skills_hash.each do |k,r|
  555.           next if k.empty?
  556.           setup = action_array[n,k.size]
  557.           if setup == k
  558.             skip_num = k.size - 1
  559.             st = r
  560.             break
  561.           end
  562.         end
  563.         st.each do |id2|
  564.           @subject.temp_chain_action = Game_Action.new(@subject)
  565.           @subject.current_action.set_skill(id2)
  566.           @subject.current_action.target_index = mtarg
  567.           next if CP::CHAIN::SINGLE_TARGET &&
  568.                   @subject.current_action.item.need_selection? &&
  569.                   @subject.current_action.make_targets.compact != btarg
  570.           next unless @subject.current_action.valid?
  571.           cp_chain_use_item
  572.           @log_window.wait_and_clear
  573.           break if $game_troop.alive_members.empty?  ## Break if battle won.
  574.         end
  575.         break if $game_troop.alive_members.empty?  ## Break if battle won.
  576.       end
  577.       @subject.temp_chain_action = nil
  578.     else
  579.       cp_chain_use_item
  580.     end
  581.   end
  582.  
  583.   alias :cp_cskills_turn_end :turn_end
  584.   def turn_end  ## Removes chains from the skills data.
  585.     $data_skills -= @remove_chain_skills_array || []
  586.     @remove_chain_skills_array = []
  587.     cp_cskills_turn_end
  588.   end
  589. end
  590.  
  591. module CP  ## Common methods for all later classes.
  592. module REGEXP
  593. module CHAIN
  594.   BLOCKS_1 = /chain blocks\[(\+|-)?(\d+)\]/i
  595.   USAGE_1  = /chain usage\[(\d+)\]/i
  596.   FOLLOW_1 = /chain follow\[([\d, ]+)\]/i
  597.   FINISH_1 = /<chain finisher>/i
  598.  
  599.   def default_chain_blocks
  600.     return 0
  601.   end
  602.  
  603.   def chain_modifier
  604.     get_chain_blocks if @chain_modifier.nil?
  605.     return @chain_modifier
  606.   end
  607.  
  608.   def chain_blocks
  609.     get_chain_blocks if @chain_blocks.nil?
  610.     return @chain_blocks
  611.   end
  612.  
  613.   def get_chain_blocks
  614.     @chain_modifier = default_chain_blocks
  615.     @chain_blocks = default_chain_blocks
  616.     self.note.split(/[\r\n]+/).each do |line|
  617.       case line
  618.       when BLOCKS_1
  619.         case $1.to_s
  620.         when '-'
  621.           @chain_modifier = -$2.to_i
  622.         when '+'
  623.           @chain_modifier = $2.to_i
  624.         else
  625.           @chain_blocks = $2.to_i
  626.         end
  627.       end
  628.     end
  629.   end
  630. end
  631. end
  632. end
  633.  
  634. class RPG::Skill < RPG::UsableItem  ## Creates neccessary skill data.
  635.   attr_accessor :chain_skill, :chain_array, :chain_finisher
  636.   attr_writer   :chain_blocks
  637.  
  638.   attr_accessor :hp_cost, :gold_cost, :item_cost, :req_state, :req_switch,
  639.                 :req_variable, :req_actor, :req_w, :req_a
  640.  
  641.   attr_accessor :hp_cost_percent, :mp_cost_percent, :tp_cost_percent,
  642.                 :gold_cost_percent, :cast_ani
  643.  
  644.   include CP::REGEXP::CHAIN
  645.  
  646.   alias :cp_chain_init :initialize
  647.   def initialize(*args)
  648.     cp_chain_init(*args)
  649.     yanfly_skill_additions
  650.   end
  651.  
  652.   def yanfly_skill_additions
  653.     @hp_cost_percent ||= 0
  654.     @mp_cost_percent ||= 0
  655.     @tp_cost_percent ||= 0
  656.     @gold_cost_percent ||= 0
  657.     @hp_cost ||= 0
  658.     @gold_cost ||= 0
  659.     @cast_ani ||= 0
  660.   end
  661.  
  662.   def chain_usage
  663.     get_chain_blocks if @chain_usage.nil?
  664.     return @chain_usage
  665.   end
  666.  
  667.   def chain_follow
  668.     get_chain_blocks if @chain_follow.nil?
  669.     return @chain_follow
  670.   end
  671.  
  672.   def chain_finisher
  673.     get_chain_blocks if @chain_finisher.nil?
  674.     return @chain_finisher
  675.   end
  676.  
  677.   def get_chain_blocks
  678.     @chain_modifier = default_chain_blocks
  679.     @chain_usage = CP::CHAIN::DEFAULT_USAGE
  680.     @chain_blocks = CP::CHAIN::DEFAULT_COST if @chain_blocks.nil?
  681.     @chain_follow = []
  682.     @chain_finisher = false if @chain_finisher.nil?
  683.     self.note.split(/[\r\n]+/).each do |line|
  684.       case line
  685.       when BLOCKS_1
  686.         @chain_blocks = $2.to_i unless ['-', '+'].include?($1.to_s)
  687.       when USAGE_1
  688.         @chain_usage = $1.to_i
  689.       when FOLLOW_1
  690.         @chain_follow = $1.to_s.delete(' ').split(/,/).collect {|i| i.to_i}
  691.       when FINISH_1
  692.         @chain_finisher = true
  693.       end
  694.     end
  695.   end
  696. end
  697.  
  698. class RPG::Actor < RPG::BaseItem
  699.   include CP::REGEXP::CHAIN  ## Extra chain info to other classes.
  700.  
  701.   def default_chain_blocks
  702.     return CP::CHAIN::DEFAULT_CHAIN
  703.   end
  704. end
  705.  
  706. class RPG::Class < RPG::BaseItem
  707.   include CP::REGEXP::CHAIN
  708.  
  709.   def default_chain_blocks
  710.     return false
  711.   end
  712. end
  713.  
  714. class RPG::EquipItem < RPG::BaseItem
  715.   include CP::REGEXP::CHAIN
  716. end
  717.  
  718. class RPG::State < RPG::BaseItem
  719.   include CP::REGEXP::CHAIN
  720. end
  721.  
  722.  
  723. ###--------------------------------------------------------------------------###
  724. #  End of script.                                                              #
  725. ###--------------------------------------------------------------------------###
RAW Paste Data