Double_X

DoubleX RMVXA Basic ATB Delay v1.00a

Aug 8th, 2015 (edited)
784
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 18.12 KB | None | 0 0
  1. #==============================================================================|
  2. #  ** Script Info                                                              |
  3. #------------------------------------------------------------------------------|
  4. #  * Script Name                                                               |
  5. #    DoubleX RMVXA Basic ATB Delay                                             |
  6. #------------------------------------------------------------------------------|
  7. #  * Functions                                                                 |
  8. #    Aids other scripters to learn how a basic atb system addon can be written |
  9. #------------------------------------------------------------------------------|
  10. #  * Terms Of Use                                                              |
  11. #    You shall keep this script's Script Info part's contents intact           |
  12. #    You shalln't claim that this script is written by anyone other than       |
  13. #    DoubleX or his aliases                                                    |
  14. #    None of the above applies to DoubleX or his aliases                       |
  15. #------------------------------------------------------------------------------|
  16. #  * Prerequisites                                                             |
  17. #    Scripts:                                                                  |
  18. #    1. DoubleX RMVXA Basic ATB                                                |
  19. #    Abilities:                                                                |
  20. #    1. Nothing special                                                        |
  21. #------------------------------------------------------------------------------|
  22. #  * Instructions                                                              |
  23. #    1. Open the script editor and put this script into an open slot between   |
  24. #       DoubleX RMVXA Basic ATB and Main, save to take effect.                 |
  25. #------------------------------------------------------------------------------|
  26. #  * Links                                                                     |
  27. #    Script Usage 101:                                                         |
  28. #    1. forums.rpgmakerweb.com/index.php?/topic/32752-rmvxa-script-usage-101/  |
  29. #    2. rpgmakervxace.net/topic/27475-rmvxa-script-usage-101/                  |
  30. #    How to write an atb system script:                                        |
  31. #    1. http://rpgmaker.net/articles/1127/                                     |
  32. #    This script:                                                              |
  33. #    1. http://pastebin.com/BnZZ0npB                                           |
  34. #    Video:                                                                    |
  35. #    1. https://www.youtube.com/watch?v=EASgWfV_Nxs                            |
  36. #    Mentioned Patreon Supporters:                                             |
  37. #    https://www.patreon.com/posts/71738797                                    |
  38. #------------------------------------------------------------------------------|
  39. #  * Authors                                                                   |
  40. #    DoubleX                                                                   |
  41. #------------------------------------------------------------------------------|
  42. #  * Changelog                                                                 |
  43. #    v1.00a(GMT 0400 9-8-2015):                                                |
  44. #    1. 1st version of this script finished                                    |
  45. #==============================================================================|
  46.  
  47. ($doublex_rmvxa ||= {})[:BATB_Delay] = "v1.00a"
  48.  
  49. #==============================================================================|
  50. #  ** Script Configurations                                                    |
  51. #     You only need to edit this part as it's about what this script does      |
  52. #------------------------------------------------------------------------------|
  53.  
  54. module DoubleX_RMVXA
  55.  
  56.   module BATB_Delay
  57.  
  58.     # Sets the scale applied to the skill/item's invocation speed
  59.     # The sum of all inputted skills/items' invocation speeds, multiplied by
  60.     # this scale, will be subtracted from the battler's atb value right after
  61.     # that battler finished inputting all that battler's action slots
  62.     # If INVOCATION_SPEED_SCALE_VAR_ID is a natural number, the value of
  63.     # variable with id INVOCATION_SPEED_SCALE_VAR_ID will be used instead of
  64.     # using INVOCATION_SPEED_SCALE
  65.     # The value of variable with id INVOCATION_SPEED_SCALE_VAR_ID should remain
  66.     # the same during the same battle to ensure proper invocation speed scaling
  67.     INVOCATION_SPEED_SCALE = 10
  68.     INVOCATION_SPEED_SCALE_VAR_ID = 0
  69.  
  70.     # Sets the maximum atb value displayed on the atb bars
  71.     # If the actual atb value's greater than this, the atb bar's overlaid
  72.     # If MAX_ATB_VAL_VAR_ID is a natural number, the value of variable with id
  73.     # MAX_ATB_VAL_VAR_ID will be used instead of using MAX_ATB_VAL
  74.     # The value of variable with id MAX_ATB_VAL_VAR_ID should remain the same
  75.     # during the same battle to ensure proper atb bar display
  76.     MAX_ATB_VAL = 60000
  77.     MAX_ATB_VAL_VAR_ID = 0
  78.  
  79.     # Sets the atb value added when the battler's atb's reset
  80.     # If RESET_ATB_VAL_VAR_ID is a natural number, the value of variable with id
  81.     # RESET_ATB_VAL_VAR_ID will be used instead of using RESET_ATB_VAL
  82.     RESET_ATB_VAL = 60000
  83.     RESET_ATB_VAL_VAR_ID = 0
  84.  
  85.     # Sets the maximum atb value at the start of a battle
  86.     # If START_ATB_VAL_VAR_ID is a natural number, the value of variable with id
  87.     # START_ATB_VAL_VAR_ID will be used instead of using START_ATB_VAL
  88.     START_ATB_VAL = 60000
  89.     START_ATB_VAL_VAR_ID = 0
  90.  
  91.     # Sets the 1st atb bar overlay color as text color ATB_OVERLAY_COLOR1
  92.     # It'll be used when the atb bar's overlaid
  93.     # If ATB_OVERLAY_COLOR1_VAR_ID is a natural number, the value of variable
  94.     # with id ATB_OVERLAY_COLOR1_VAR_ID will be used instead of using
  95.     # ATB_OVERLAY_COLOR1
  96.     # The value of variable with id ATB_OVERLAY_COLOR1_VAR_ID should remain the
  97.     # same during the same battle to ensure proper atb bar color displays
  98.     ATB_OVERLAY_COLOR1 = 19
  99.     ATB_OVERLAY_COLOR1_VAR_ID = 0
  100.  
  101.     # Sets the 2nd atb bar overlay color as text color ATB_OVERLAY_COLOR2
  102.     # It'll be used when the atb bar's overlaid
  103.     # If ATB_OVERLAY_COLOR2_VAR_ID is a natural number, the value of variable
  104.     # with id ATB_OVERLAY_COLOR2_VAR_ID will be used instead of using
  105.     # ATB_OVERLAY_COLOR2
  106.     # The value of variable with id ATB_OVERLAY_COLOR2_VAR_ID should remain the
  107.     # same during the same battle to ensure proper atb bar color displays
  108.     ATB_OVERLAY_COLOR2 = 26
  109.     ATB_OVERLAY_COLOR2_VAR_ID = 0
  110.  
  111. #==============================================================================|
  112. #  ** Script Implementations                                                   |
  113. #     You need not edit this part as it's about how this script works          |
  114. #------------------------------------------------------------------------------|
  115. #  * Script Support Info:                                                      |
  116. #    1. Prerequisites                                                          |
  117. #       - Basic atb concept and default RMVXA battle system knowledge          |
  118. #       - Some RGSS3 scripting proficiency to fully comprehend this script     |
  119. #    2. Method documentation                                                   |
  120. #       - The 1st part describes why this method's rewritten/aliased for       |
  121. #         rewritten/aliased methods or what the method does for new methods    |
  122. #       - The 2nd part describes what the arguments of the method are          |
  123. #       - The 3rd part informs which version rewritten, aliased or created this|
  124. #         method                                                               |
  125. #       - The 4th part informs whether the method's rewritten or new           |
  126. #       - The 5th part describes how this method works for new methods only,   |
  127. #         and describes the parts added, removed or rewritten for rewritten or |
  128. #         aliased methods only                                                 |
  129. #       Example:                                                               |
  130. # #--------------------------------------------------------------------------| |
  131. # #  Why rewrite/alias/What this method does                                 | |
  132. # #--------------------------------------------------------------------------| |
  133. # # *argv: What these variables are                                            |
  134. # # &argb: What this block is                                                  |
  135. # def def_name(*argv, &argb) # Version X+; Rewrite/New                         |
  136. #   # Added/Removed/Rewritten to do something/How this method works            |
  137. #   def_name_code                                                              |
  138. #   #                                                                          |
  139. # end # def_name                                                               |
  140. #------------------------------------------------------------------------------|
  141.  
  142.     #--------------------------------------------------------------------------|
  143.     #  Helper methods simplifying the uses of the configuration values         |
  144.     #--------------------------------------------------------------------------|
  145.  
  146.     def self.invocation_speed_scale
  147.       return INVOCATION_SPEED_SCALE if INVOCATION_SPEED_SCALE_VAR_ID <= 0
  148.       $game_variables[INVOCATION_SPEED_SCALE_VAR_ID]
  149.     end # invocation_speed_scale
  150.  
  151.     def self.max_atb_val
  152.       MAX_ATB_VAL_VAR_ID > 0 ? $game_variables[MAX_ATB_VAL_VAR_ID] : MAX_ATB_VAL
  153.     end # max_atb_val
  154.  
  155.     def self.reset_atb_val
  156.       return RESET_ATB_VAL if RESET_ATB_VAL_VAR_ID <= 0
  157.       $game_variables[RESET_ATB_VAL_VAR_ID]
  158.     end # reset_atb_val
  159.  
  160.     def self.start_atb_val
  161.       return START_ATB_VAL if START_ATB_VAL_VAR_ID <= 0
  162.       $game_variables[START_ATB_VAL_VAR_ID]
  163.     end # start_atb_val
  164.  
  165.     def self.atb_overlay_color1
  166.       return ATB_OVERLAY_COLOR1 if ATB_OVERLAY_COLOR1_VAR_ID <= 0
  167.       $game_variables[ATB_OVERLAY_COLOR1_VAR_ID]
  168.     end # atb_overlay_color1
  169.  
  170.     def self.atb_overlay_color2
  171.       return ATB_OVERLAY_COLOR2 if ATB_OVERLAY_COLOR2_VAR_ID <= 0
  172.       $game_variables[ATB_OVERLAY_COLOR2_VAR_ID]
  173.     end # atb_overlay_color2
  174.  
  175.   end # BATB_Delay
  176.  
  177. end # DoubleX_RMVXA
  178.  
  179. if $doublex_rmvxa[:BATB]
  180.  
  181. class << BattleManager # Edit
  182.  
  183.   #----------------------------------------------------------------------------|
  184.   #  Gets rid of the conflicting batb features                                 |
  185.   #----------------------------------------------------------------------------|
  186.   def process_escape # Rewrite
  187.     @batb_can_esc && process_escape_batb # Rewritten
  188.   end # process_escape
  189.  
  190. end # BattleManager
  191.  
  192. class Game_BattlerBase # Edit
  193.  
  194.   #----------------------------------------------------------------------------|
  195.   #  Uses the atb decrement mechanics and open atb value scale instead         |
  196.   #----------------------------------------------------------------------------|
  197.   def batb_start(start) # Rewrite
  198.     # Rewritten
  199.     @batb_val += DoubleX_RMVXA::BATB_Delay.start_atb_val
  200.     return if DoubleX_RMVXA::BATB.atb_start_mode == 0
  201.     return if start == :surprise && actor? || start == :preempt && enemy?
  202.     @batb_val = (@batb_val * ((param_max(6) - agi) * 1.0 / param_max(6))).to_i
  203.     make_actions if @batb_val <= 0
  204.     #
  205.   end # batb_start
  206.  
  207. end # Game_BattlerBase
  208.  
  209. #------------------------------------------------------------------------------|
  210. #  * Gets rid of the conflicting batb features and uses the batb delay ones    |
  211. #------------------------------------------------------------------------------|
  212. class Game_Battler < Game_BattlerBase # Edit
  213.  
  214.   #----------------------------------------------------------------------------|
  215.   #  New public instance variable                                              |
  216.   #----------------------------------------------------------------------------|
  217.   attr_reader :last_batb_inputable # The action inputability flag
  218.  
  219.   #----------------------------------------------------------------------------|
  220.   #  Gets rid of the atb fill mode and uses the atb decrement mechanics instead|
  221.   #----------------------------------------------------------------------------|
  222.   def batb_start(start) # Rewrite
  223.     @batb_val_change = true
  224.     # Rewritten
  225.     @last_batb_inputable = false
  226.     return @batb_val = DoubleX_RMVXA::BATB_Delay.start_atb_val unless movable?
  227.     if start == :preempt && actor? || start == :surprise && enemy?
  228.       @batb_val = 0
  229.       return make_actions
  230.     end
  231.     #
  232.     super(start)
  233.   end # batb_start
  234.  
  235.   #----------------------------------------------------------------------------|
  236.   #  Gets rid of the atb fill mode and uses the atb decrement mechanics instead|
  237.   #----------------------------------------------------------------------------|
  238.   def batb_update # Rewrite
  239.     # Rewritten
  240.     return if restriction > 3
  241.     if @batb_val > 0
  242.       @batb_val_change = @batb_val != @batb_val -= batb_rate
  243.     elsif @last_batb_inputable && @actions.all? { |act| act.batb_confirm }
  244.       @batb_val_change = @batb_val != @batb_val -= batb_speed
  245.       @last_batb_inputable = false
  246.     end
  247.     return unless @batb_val <= 0
  248.     @batb_val = 0
  249.     make_actions if @actions.empty?
  250.     #
  251.   end # batb_update
  252.  
  253.   #----------------------------------------------------------------------------|
  254.   #  Gets rid of the atb fill mode and uses integer instead of floating points |
  255.   #----------------------------------------------------------------------------|
  256.   def batb_rate # Rewrite
  257.     # Rewritten
  258.     return agi if DoubleX_RMVXA::BATB.atb_rate_code == 0
  259.     (agi * (agi * 1.0 / BattleManager.batb_avg_agi)).to_i
  260.     #
  261.   end # batb_rate
  262.  
  263.   #----------------------------------------------------------------------------|
  264.   #  Uses the atb decrement mechanics and open atb value scale instead         |
  265.   #----------------------------------------------------------------------------|
  266.   def reset_batb_val(reset = true) # Rewrite
  267.     # Rewritten
  268.     if reset
  269.       @batb_val += DoubleX_RMVXA::BATB_Delay.reset_atb_val
  270.       @batb_val_change = true
  271.     end
  272.     @last_batb_inputable = false
  273.     #
  274.     clear_actions
  275.     BattleManager.action_battlers.delete(self)
  276.     BattleManager.clear_actor if actor? && BattleManager.actor == self
  277.   end # reset_batb_val
  278.  
  279.   #----------------------------------------------------------------------------|
  280.   #  Marks that this battler becomes able to input actions as well             |
  281.   #----------------------------------------------------------------------------|
  282.   alias make_actions_batb_delay make_actions
  283.   def make_actions
  284.     make_actions_batb_delay
  285.     @last_batb_inputable = true # Added
  286.   end # make_actions
  287.  
  288.   #----------------------------------------------------------------------------|
  289.   #  Ensures battlers added after the battle will have correct inputable flag  |
  290.   #----------------------------------------------------------------------------|
  291.   alias on_battle_end_batb_delay on_battle_end
  292.   def on_battle_end
  293.     on_battle_end_batb_delay
  294.     @last_batb_inputable = false # Added
  295.   end # on_battle_end
  296.  
  297.   #----------------------------------------------------------------------------|
  298.   #  Gets rid of the party escape speed and uses the invocation speed scale    |
  299.   #----------------------------------------------------------------------------|
  300.   alias batb_speed_delay batb_speed
  301.   def batb_speed
  302.     # Rewritten
  303.     batb_speed_delay * DoubleX_RMVXA::BATB_Delay.invocation_speed_scale
  304.     #
  305.   end # batb_speed
  306.  
  307. end # Game_Battler
  308.  
  309. #------------------------------------------------------------------------------|
  310. #  * Displays the atb bars with overlay colors if they're overlaid as well     |
  311. #------------------------------------------------------------------------------|
  312. class Window_BattleStatus < Window_Selectable # Edit
  313.  
  314.   # rect: The atb bar's rect
  315.   # actor: The atb bar's owner
  316.   # display_tp: The tp bar display flag
  317.   def draw_batb_bar(rect, actor, display_tp) # Rewrite
  318.     display_tp ? (x, w = rect.x + 184, 36) : (x, w = rect.x + 160, 60)
  319.     # Rewritten
  320.     colors = set_batb_bar_colors(actor.batb_val)
  321.     max = DoubleX_RMVXA::BATB_Delay.max_atb_val
  322.     batb_val = actor.batb_val > max ? max : actor.batb_val
  323.     draw_gauge(x, rect.y, w, batb_val * 1.0 / max, colors[0], colors[1])
  324.     #
  325.     change_color(system_color)
  326.     draw_text(x, rect.y, 30, line_height, DoubleX_RMVXA::BATB.atb_bar_text)
  327.     actor.batb_val_change = false
  328.   end # draw_batb_bar
  329.  
  330.   # batb_val: The atb value
  331.   def set_batb_bar_colors(batb_val) # New
  332.     if batb_val <= DoubleX_RMVXA::BATB_Delay.max_atb_val
  333.       batb = DoubleX_RMVXA::BATB
  334.       return [text_color(batb.atb_bar_color1), text_color(batb.atb_bar_color2)]
  335.     end
  336.     delay = DoubleX_RMVXA::BATB_Delay
  337.     [text_color(delay.atb_overlay_color1), text_color(delay.atb_overlay_color2)]
  338.   end # set_batb_bar_colors
  339.  
  340. end # Window_BattleStatus
  341.  
  342. class Scene_Battle < Scene_Base # Edit
  343.  
  344.   #----------------------------------------------------------------------------|
  345.   #  Uses the atb decrement mechanics and battler action inputable flag instead|
  346.   #----------------------------------------------------------------------------|
  347.   def process_action # Rewrite
  348.     return if scene_changing?
  349.     return process_batb_act(true) if @subject
  350.     esc = BattleManager.batb_esc
  351.     BattleManager.action_battlers.each { |battler|
  352.       next if esc && battler.actor?
  353.       next if battler.batb_val > 0 || battler.last_batb_inputable # Rewritten
  354.       @subject = battler
  355.       process_batb_act
  356.       @subject = nil
  357.     }
  358.   end # process_action
  359.  
  360. end # Scene_Battle
  361.  
  362. #------------------------------------------------------------------------------|
  363.  
  364. else
  365.  
  366.   # Informs users that they didn't place BATB above this script
  367.   msgbox("To use DoubleX RMVXA Basic ATB Delay, put it below:\n" +
  368.          "DoubleX RMVXA Basic ATB\nbut above Main")
  369.  
  370. end
  371.  
  372. #==============================================================================|
Add Comment
Please, Sign In to add comment