Advertisement
Double_X

DoubleX RMVXA Min ATB v1.00a

Oct 13th, 2015 (edited)
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 20.17 KB | None | 0 0
  1. #==============================================================================|
  2. #  ** Script Info                                                              |
  3. #------------------------------------------------------------------------------|
  4. #  * Script Name                                                               |
  5. #    DoubleX RMVXA Min ATB                                                     |
  6. #------------------------------------------------------------------------------|
  7. #  * Functions                                                                 |
  8. #    To be the smallest ATB system script with the fewest features ever        |
  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. #    Abilities:                                                                |
  18. #    1. Little RGSS3 scripting proficiency to fully utilize this script        |
  19. #------------------------------------------------------------------------------|
  20. #  * Instructions                                                              |
  21. #    1. Open the script editor and put this script into an open slot between   |
  22. #       Materials and Main, save to take effect.                               |
  23. #------------------------------------------------------------------------------|
  24. #  * Links                                                                     |
  25. #    Script Usage 101:                                                         |
  26. #    1. forums.rpgmakerweb.com/index.php?/topic/32752-rmvxa-script-usage-101/  |
  27. #    2. rpgmakervxace.net/topic/27475-rmvxa-script-usage-101/                  |
  28. #    This script:                                                              |
  29. #    1. http://pastebin.com/PJtqgJ1y                                           |
  30. #    Mentioned Patreon Supporters:                                             |
  31. #    https://www.patreon.com/posts/71738797                                    |
  32. #------------------------------------------------------------------------------|
  33. #  * Authors                                                                   |
  34. #    DoubleX                                                                   |
  35. #------------------------------------------------------------------------------|
  36. #  * Changelog                                                                 |
  37. #    v1.00a(GMT 0800 14-10-2015):                                              |
  38. #    1. 1st version of this script finished                                    |
  39. #==============================================================================|
  40.  
  41. #==============================================================================|
  42. #  ** Script Call Info                                                         |
  43. #------------------------------------------------------------------------------|
  44. #  * Battler manipulations                                                     |
  45. #    1. matb_val                                                               |
  46. #       - Returns the battler's atb fill percentage                            |
  47. #    2. reset_matb_val                                                         |
  48. #       - Clears all battler's actions and empties the battler's atb bar also  |
  49. #==============================================================================|
  50.  
  51. ($doublex_rmvxa ||= {})[:MATB] = "v1.00a"
  52.  
  53. #==============================================================================|
  54. #  ** Script Configurations                                                    |
  55. #     You only need to edit this part as it's about what this script does      |
  56. #------------------------------------------------------------------------------|
  57.  
  58. module DoubleX_RMVXA
  59.  
  60.   module MATB
  61.  
  62.     # Sets the base atb fill time from empty to full as BASE_FILL_T seconds
  63.     # If BASE_FILL_T_VAR_ID is a natural number, the value of variable with id
  64.     # BASE_FILL_T_VAR_ID will be used instead of using BASE_FILL_T
  65.     BASE_FILL_T = 5
  66.     BASE_FILL_T_VAR_ID = 0
  67.  
  68.     # Sets the maximum turn clock unit as MAX_TURN_UNIT
  69.     # If MAX_TURN_UNIT_VAR_ID is a natural number, the value of variable with id
  70.     # MAX_TURN_UNIT_VAR_ID will be used instead of using MAX_TURN_UNIT
  71.     MAX_TURN_UNIT = 5
  72.     MAX_TURN_UNIT_VAR_ID = 0
  73.  
  74.     # Sets the 1st atb bar color as text color ATB_BAR_COLOR1
  75.     # If ATB_BAR_COLOR1_VAR_ID is a natural number, the value of variable with
  76.     # id ATB_BAR_COLOR1_VAR_ID will be used instead of using ATB_BAR_COLOR1
  77.     # The value of variable with id ATB_BAR_COLOR1_VAR_ID should remain the same
  78.     # during battles to ensure proper atb bar color displays
  79.     ATB_BAR_COLOR1 = 7
  80.     ATB_BAR_COLOR1_VAR_ID = 0
  81.  
  82.     # Sets the 2nd atb bar color as text color ATB_BAR_COLOR2
  83.     # If ATB_BAR_COLOR2_VAR_ID is a natural number, the value of variable with
  84.     # id ATB_BAR_COLOR2_VAR_ID will be used instead of using ATB_BAR_COLOR2
  85.     # The value of variable with id ATB_BAR_COLOR2_VAR_ID should remain the same
  86.     # during battles to ensure proper atb bar color displays
  87.     ATB_BAR_COLOR2 = 8
  88.     ATB_BAR_COLOR2_VAR_ID = 0
  89.  
  90. #==============================================================================|
  91. #  ** Script Implementations                                                   |
  92. #     You need not edit this part as it's about how this script works          |
  93. #------------------------------------------------------------------------------|
  94. #  * Script Support Info:                                                      |
  95. #    1. Prerequisites                                                          |
  96. #       - Basic atb concept and default RMVXA battle system knowledge          |
  97. #       - Some RGSS3 scripting proficiency to fully comprehend this script     |
  98. #    2. Method documentation                                                   |
  99. #       - The 1st part describes why this method's rewritten/aliased for       |
  100. #         rewritten/aliased methods or what the method does for new methods    |
  101. #       - The 2nd part describes what the arguments of the method are          |
  102. #       - The 3rd part informs which version rewritten, aliased or created this|
  103. #         method                                                               |
  104. #       - The 4th part informs whether the method's rewritten or new           |
  105. #       - The 5th part describes how this method works for new methods only,   |
  106. #         and describes the parts added, removed or rewritten for rewritten or |
  107. #         aliased methods only                                                 |
  108. #       Example:                                                               |
  109. # #--------------------------------------------------------------------------| |
  110. # #  Why rewrite/alias/What this method does                                 | |
  111. # #--------------------------------------------------------------------------| |
  112. # # *argv: What these variables are                                            |
  113. # # &argb: What this block is                                                  |
  114. # def def_name(*argv, &argb) # Version X+; Rewrite/New                         |
  115. #   # Added/Removed/Rewritten to do something/How this method works            |
  116. #   def_name_code                                                              |
  117. #   #                                                                          |
  118. # end # def_name                                                               |
  119. #------------------------------------------------------------------------------|
  120.  
  121.     def self.base_fill_t
  122.       return BASE_FILL_T if BASE_FILL_T_VAR_ID <= 0
  123.       $game_variables[BASE_FILL_T_VAR_ID]
  124.     end # base_fill_t
  125.  
  126.     def self.max_turn_unit
  127.       return MAX_TURN_UNIT * Graphics.frame_rate if MAX_TURN_UNIT_VAR_ID <= 0
  128.       $game_variables[MAX_TURN_UNIT_VAR_ID] * Graphics.frame_rate
  129.     end # max_turn_unit
  130.  
  131.     def self.atb_bar_color1
  132.       return ATB_BAR_COLOR1 if ATB_BAR_COLOR1_VAR_ID <= 0
  133.       $game_variables[ATB_BAR_COLOR1_VAR_ID]
  134.     end # atb_bar_color1
  135.  
  136.     def self.atb_bar_color2
  137.       return ATB_BAR_COLOR2 if ATB_BAR_COLOR2_VAR_ID <= 0
  138.       $game_variables[ATB_BAR_COLOR2_VAR_ID]
  139.     end # atb_bar_color2
  140.  
  141.   end # MATB
  142.  
  143. end # DoubleX_RMVXA
  144.  
  145. #------------------------------------------------------------------------------|
  146. #  * Reimplements the the whole battle flow to run the atb system              |
  147. #------------------------------------------------------------------------------|
  148. class << BattleManager # Edit
  149.  
  150.   #----------------------------------------------------------------------------|
  151.   #  New public instance variables                                             |
  152.   #----------------------------------------------------------------------------|
  153.   attr_reader :action_battlers # Read by Scene_Battle to execute actions
  154.   attr_writer :actor_index # Accessed by Scene_Battle to setup actors
  155.  
  156.   #----------------------------------------------------------------------------|
  157.   #  Always lets actions to be executed whenever the atb frame update runs     |
  158.   #----------------------------------------------------------------------------|
  159.   def in_turn? # Rewrite
  160.     SceneManager.scene.matb_update? # Rewritten
  161.   end # in_turn?
  162.  
  163.   #----------------------------------------------------------------------------|
  164.   #  Stops making battlers' actions when opening the party command window      |
  165.   #----------------------------------------------------------------------------|
  166.   alias input_start_matb input_start
  167.   def input_start
  168.     @phase = :input # Added
  169.     input_start_matb
  170.   end # input_start
  171.  
  172.   alias battle_start_matb battle_start
  173.   def battle_start
  174.     battle_start_matb
  175.     matb_battle_start # Added
  176.   end # battle_start
  177.  
  178.   def matb_battle_start # New
  179.     start = @preemptive ? :preempt : @surprise ? :surprise : :norm
  180.     ($game_party.battle_members + $game_troop.members).each { |mem|
  181.       mem.matb_start(start)
  182.     }
  183.   end # matb_battle_start
  184.  
  185.   def matb_update? # New
  186.     return false if $game_party.all_dead? || $game_troop.all_dead? ||
  187.     $game_message.visible
  188.     @phase && @phase != :init
  189.   end # matb_update?
  190.  
  191.   def matb_update # New
  192.     ($game_party.alive_members + $game_troop.alive_members).each { |mem|
  193.       mem.matb_update
  194.     }
  195.   end # matb_update
  196.  
  197. end # BattleManager
  198.  
  199. #------------------------------------------------------------------------------|
  200. #  * Reimplements the actor inputability check and fixes bugs and edge cases   |
  201. #------------------------------------------------------------------------------|
  202. class Game_BattlerBase # Edit
  203.  
  204.   alias hide_matb hide
  205.   def hide
  206.     hide_matb
  207.     reset_matb_val # Added
  208.   end # hide
  209.  
  210.   alias inputable_matb? inputable?
  211.   def inputable?
  212.     return false if @actions.all? { |act| act.item }
  213.     inputable_matb? && @actions.size > 0 && actor? # Rewritten
  214.   end # inputable?
  215.  
  216. end # Game_BattlerBase
  217.  
  218. #------------------------------------------------------------------------------|
  219. #  * Implements the battler's atb actions, control flows and logics            |
  220. #------------------------------------------------------------------------------|
  221. class Game_Battler < Game_BattlerBase # Edit
  222.  
  223.   #----------------------------------------------------------------------------|
  224.   #  New public instance variables                                             |
  225.   #----------------------------------------------------------------------------|
  226.   attr_accessor :matb_val_change # The atb value change flag
  227.   attr_reader :matb_val # The battler's atb value
  228.  
  229.   def update_state_turns # Rewrite
  230.     matb_update_state_turns(2) # Rewritten
  231.   end # update_state_turns
  232.  
  233.   alias initialize_matb initialize
  234.   def initialize
  235.     initialize_matb
  236.     # Added to fix nil action input index bugs and edge cases as well
  237.     clear_actions
  238.     @matb_val = 0.0
  239.     #
  240.   end # initialize
  241.  
  242.   alias on_restrict_matb on_restrict
  243.   def on_restrict
  244.     on_restrict_matb
  245.     # Added to fix nil action battlers bugs and edge cases as well
  246.     reset_matb_val if BattleManager.action_battlers
  247.     #
  248.   end # on_restrict
  249.  
  250.   alias make_actions_matb make_actions
  251.   def make_actions
  252.     make_actions_matb
  253.     # Added
  254.     return if BattleManager.action_battlers.include?(self)
  255.     BattleManager.action_battlers << self
  256.     #
  257.   end # make_actions
  258.  
  259.   alias on_action_end_matb on_action_end
  260.   def on_action_end
  261.     on_action_end_matb
  262.     # Added
  263.     matb_update_state_turns(1)
  264.     reset_matb_val
  265.     #
  266.   end # on_action_end
  267.  
  268.   alias on_turn_end_matb on_turn_end
  269.   def on_turn_end
  270.     on_turn_end_matb
  271.     remove_buffs_auto # Added
  272.   end # on_turn_end
  273.  
  274.   #----------------------------------------------------------------------------|
  275.   #  Ensures battlers added after the battle starts will start with 0 atb value|
  276.   #----------------------------------------------------------------------------|
  277.   alias on_battle_end_matb on_battle_end
  278.   def on_battle_end
  279.     on_battle_end_matb
  280.     @matb_val = 0.0 # Added
  281.   end # on_battle_end
  282.  
  283.   # start: The battle start type
  284.   def matb_start(start) # New
  285.     @matb_val = movable? && (start == :preempt && actor? ||
  286.     start == :surprise && enemy?) ? 100.0 : 0.0
  287.     @matb_val_change = true
  288.   end # matb_start
  289.  
  290.   # timing: The state's auto removal timing
  291.   def matb_update_state_turns(timing) # New
  292.     states.each { |state|
  293.       next if state.auto_removal_timing != timing
  294.       @state_turns[state.id] -= 1 if @state_turns[state.id] > 0
  295.     }
  296.   end # matb_update_state_turns
  297.  
  298.   def matb_update # New
  299.     return if @matb_val >= 100.0 || inputable? || restriction > 3
  300.     @matb_val_change = @matb_val != @matb_val += agi / 100.0
  301.     return unless @matb_val >= 100.0
  302.     @matb_val = 100.0
  303.     make_actions
  304.   end # matb_update
  305.  
  306.   def reset_matb_val # New
  307.     @matb_val = 0.0
  308.     @matb_val_change = true
  309.     clear_actions
  310.     BattleManager.action_battlers.delete(self)
  311.     BattleManager.clear_actor if actor? && BattleManager.actor == self
  312.   end # reset_matb_val
  313.  
  314. end # Game_Battler
  315.  
  316. #------------------------------------------------------------------------------|
  317. #  * Resets all party members' atb values upon failed party escape attempts    |
  318. #------------------------------------------------------------------------------|
  319. class Game_Party < Game_Unit # Edit
  320.  
  321.   alias clear_actions_matb clear_actions
  322.   def clear_actions
  323.     clear_actions_matb
  324.     members.each { |mem| mem.reset_matb_val } # Added
  325.   end # clear_actions
  326.  
  327. end # Game_Party
  328.  
  329. class Window_BattleStatus < Window_Selectable # Edit
  330.  
  331.   def draw_gauge_area_with_tp(rect, actor) # Rewrite
  332.     # Rewritten
  333.     draw_actor_hp(actor, rect.x + 0, rect.y, 60)
  334.     draw_actor_mp(actor, rect.x + 64, rect.y, 60)
  335.     draw_actor_tp(actor, rect.x + 128, rect.y, 52)
  336.     draw_matb_bar(rect, actor, true) if actor
  337.     #
  338.   end # draw_gauge_area_with_tp
  339.  
  340.   def draw_gauge_area_without_tp(rect, actor) # Rewrite
  341.     # Rewritten
  342.     draw_actor_hp(actor, rect.x + 0, rect.y, 72)
  343.     draw_actor_mp(actor, rect.x + 80, rect.y, 72)
  344.     draw_matb_bar(rect, actor, false) if actor
  345.     #
  346.   end # draw_gauge_area_without_tp
  347.  
  348.   def refresh_matb_bars # New
  349.     display_tp = $data_system.opt_display_tp
  350.     item_max.times { |index|
  351.       next unless (actor = $game_party.battle_members[index]) &&
  352.       actor.matb_val_change
  353.       draw_matb_bar(gauge_area_rect(index), actor, display_tp)
  354.       actor.matb_val_change = false
  355.     }
  356.   end # refresh_matb_bars
  357.  
  358.   # rect: The atb bar's rect
  359.   # actor: The atb bar's owner
  360.   # display_tp: The tp bar display flag
  361.   def draw_matb_bar(rect, actor, display_tp) # New
  362.     display_tp ? (x, w = rect.x + 184, 36) : (x, w = rect.x + 160, 60)
  363.     draw_gauge(x, rect.y, w, actor.matb_val / 100.0,
  364.     text_color(DoubleX_RMVXA::MATB.atb_bar_color1),
  365.     text_color(DoubleX_RMVXA::MATB.atb_bar_color2))
  366.     change_color(system_color)
  367.     draw_text(x, rect.y, 30, line_height, "AP")
  368.   end # draw_matb_bar
  369.  
  370. end # Window_BattleStatus
  371.  
  372. #------------------------------------------------------------------------------|
  373. #  * Reconstructs the the whole battle flow to control the atb system          |
  374. #------------------------------------------------------------------------------|
  375. class Scene_Battle < Scene_Base # Edit
  376.  
  377.   #----------------------------------------------------------------------------|
  378.   #  New private instance variable                                             |
  379.   #----------------------------------------------------------------------------|
  380.   # @matb_turn_clock: The turn atb clock with seconds as the unit
  381.  
  382.   def update_info_viewport # Rewrite
  383.     # Rewritten
  384.     move_info_viewport(@party_command_window.active ? 0 : matb_update? ? 64 : 128)
  385.     #
  386.   end # update_info_viewport
  387.  
  388.   def turn_start # Rewrite
  389.     @party_command_window.close
  390.     @actor_command_window.close
  391.     @status_window.unselect
  392.     # Removed to stop shifting battle phase nor clearing subject
  393.     @log_window.wait
  394.     # Removed to stop clearing the log window
  395.   end # turn_start
  396.  
  397.   def turn_end # Rewrite
  398.     ($game_party.battle_members + $game_troop.members).each { |mem|
  399.       mem.on_turn_end
  400.       refresh_status
  401.       @log_window.display_auto_affected_status(mem)
  402.       @log_window.wait_and_clear
  403.     }
  404.     # Added
  405.     @matb_turn_clock = 0
  406.     $game_troop.increase_turn
  407.     #
  408.     BattleManager.turn_end
  409.     process_event
  410.     # Removed to stop opening the party window
  411.   end # turn_end
  412.  
  413.   def process_action # Rewrite
  414.     # Rewritten
  415.     return process_matb_act(true) if @subject
  416.     BattleManager.action_battlers.reject { |b| b.inputable? }.each { |b|
  417.       @subject = b
  418.       process_matb_act
  419.       @subject = nil
  420.     }
  421.     #
  422.   end # process_action
  423.  
  424.   alias start_matb start
  425.   def start
  426.     start_matb
  427.     @matb_turn_clock = 0 # Added
  428.   end # start
  429.  
  430.   alias update_matb update
  431.   def update
  432.     update_matb
  433.     matb_update if matb_update? # Added
  434.   end # update
  435.  
  436.   alias update_message_open_matb update_message_open
  437.   def update_message_open
  438.     update_message_open_matb
  439.     # Added
  440.     return if $game_message.busy? || $game_troop.all_dead? ||
  441.     $game_party.all_dead?
  442.     @status_window.open if @status_window.close?
  443.     #
  444.   end # update_message_open
  445.  
  446.   def matb_update? # New
  447.     return false if scene_changing? || @spriteset.animation? ||
  448.     @actor_window.active || @enemy_window.active || @skill_window.active ||
  449.     @item_window.active || @actor_command_window.active ||
  450.     @party_command_window.active
  451.     BattleManager.matb_update?
  452.   end # matb_update?
  453.  
  454.   def matb_update # New
  455.     turn_end if (@matb_turn_clock += 1) >= DoubleX_RMVXA::MATB.max_turn_unit
  456.     BattleManager.matb_update
  457.     list = BattleManager.action_battlers.select { |b| b.inputable? }.collect! {
  458.     |b| b.index }
  459.     matb_update_windows(list) unless list.include?(@status_window.index)
  460.     @status_window.refresh_matb_bars
  461.   end # matb_update
  462.  
  463.   # list: The list of indices of all the currently inputable actors
  464.   def matb_update_windows(list) # New
  465.     @status_window.unselect if @status_window.index >= 0
  466.     return if list.empty?
  467.     BattleManager.actor_index = list[0]
  468.     start_actor_command_selection
  469.   end # matb_update_windows
  470.  
  471.   # forced: Whether the action's forced
  472.   def process_matb_act(forced = false) # New
  473.     while @subject.current_action
  474.       @subject.current_action.prepare
  475.       if @subject.current_action.valid?
  476.         @status_window.open
  477.         execute_action
  478.       end
  479.       @subject.remove_current_action
  480.       break if forced
  481.     end
  482.     process_action_end unless @subject.current_action
  483.   end # process_matb_act
  484.  
  485. end # Scene_Battle
  486.  
  487. #------------------------------------------------------------------------------|
  488.  
  489. #==============================================================================|
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement