SHARE
TWEET

DoubleX RMVXA Basic ATB v1.02c

Double_X Jun 10th, 2015 (edited) 631 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================|
  2. #  ** Script Info                                                              |
  3. #------------------------------------------------------------------------------|
  4. #  * Script Name                                                               |
  5. #    DoubleX RMVXA Basic ATB                                                   |
  6. #------------------------------------------------------------------------------|
  7. #  * Functions                                                                 |
  8. #    Aids other scripters to learn how a basic atb system script 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. #    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. #  * Author's Notes                                                            |
  25. #    1. This script's meant to be easy and simple to comprehend and utilize,   |
  26. #       meaning high level control nor freedom won't be given to users, and    |
  27. #       advanced scripting proficiencies won't be applied to this script.      |
  28. #    2. Readability's prioritized over almost everything else in this script to|
  29. #       aid scripters to learn how a basic atb system can be written.          |
  30. #    3. State's Auto-removal Timing as Action End becomes right after the state|
  31. #       owner executed all his/her/its actions to conform with the defaults    |
  32. #------------------------------------------------------------------------------|
  33. #  * FAQ                                                                       |
  34. #    Q1. Will this script be compatible with Victor Engine - Basic Module or   |
  35. #        Yanfly Engine Ace - Ace Battle Engine?                                |
  36. #    A1. Probably no, as there's Victor Engine - Active Time Battle, and I've  |
  37. #        been already supporting both CATB and ECATB scripts.                  |
  38. #    Q2. Why this script only has global settings and has no notetag at all?   |
  39. #    A2. To help scripters learn from this script, it's better to focus on the |
  40. #        core concepts and structures when implementing this script, while     |
  41. #        adding notetags as well might impede them from grapsing those basics. |
  42. #    Q3. May you please teach me scripting so I can fully utilize this script? |
  43. #    A3. You can ask me how to set specific settings to meet your specific     |
  44. #        needs, but it seems to me that there are many good scripting teachers |
  45. #        so you may want to ask them instead of me for learning scripting.     |
  46. #------------------------------------------------------------------------------|
  47. #  * Links                                                                     |
  48. #    Script Usage 101:                                                         |
  49. #    1. forums.rpgmakerweb.com/index.php?/topic/32752-rmvxa-script-usage-101/  |
  50. #    2. rpgmakervxace.net/topic/27475-rmvxa-script-usage-101/                  |
  51. #    How to write an atb system script:                                        |
  52. #    1. http://rpgmaker.net/articles/1127/                                     |
  53. #    This script:                                                              |
  54. #    1. http://pastebin.com/5xUZfbbB                                           |
  55. #    Video:                                                                    |
  56. #    1. https://www.youtube.com/watch?v=yBNftauefPQ                            |
  57. #------------------------------------------------------------------------------|
  58. #  * Authors                                                                   |
  59. #    DoubleX                                                                   |
  60. #------------------------------------------------------------------------------|
  61. #  * Changelog                                                                 |
  62. #    v1.02c(GMT 1100 5-8-2015):                                                |
  63. #    1. Fixed nil enemy selection and not executing all confirmed actions bug  |
  64. #    2. Further improved this script's compactness, efficiency and readability |
  65. #    v1.02b(GMT 1300 5-7-2015):                                                |
  66. #    1. Fixed hidden battlers and updating atb while game messages' showing bug|
  67. #    2. Improved this script's efficiency                                      |
  68. #    v1.02a(GMT 1200 1-7-2015):                                                |
  69. #    1. Lets users set the party escape speed in atb fill mode 1               |
  70. #    2. On action end now triggers when a battler processed all the actions    |
  71. #    v1.01a(GMT 1100 13-6-2015):                                               |
  72. #    1. Lets users select the starting atb value formulae                      |
  73. #    2. Fixed clearing empty log window upon turn start bug                    |
  74. #    3. Fixed failed party escape not costing anything bug                     |
  75. #       - This bug's still present in atb fill mode 1                          |
  76. #    4. Fixed enemies not executing actions under some conditions bug          |
  77. #    5. Simplified the actor input selection implementations                   |
  78. #    v1.00a(GMT 1400 10-6-2015):                                               |
  79. #    1. 1st version of this script finished                                    |
  80. #==============================================================================|
  81.  
  82. #==============================================================================|
  83. #  ** Script Call Info                                                         |
  84. #------------------------------------------------------------------------------|
  85. #  * Battler manipulations                                                     |
  86. #    1. batb_val                                                               |
  87. #       - Returns the battler's atb fill percentage                            |
  88. #    2. reset_batb_val(reset)                                                  |
  89. #       - Clears all battler's actions                                         |
  90. #       - Empties the battler's atb bar as well if reset returns true          |
  91. #==============================================================================|
  92.  
  93. ($doublex_rmvxa ||= {})[:BATB] = "v1.02c"
  94.  
  95. #==============================================================================|
  96. #  ** Script Configurations                                                    |
  97. #     You only need to edit this part as it's about what this script does      |
  98. #------------------------------------------------------------------------------|
  99.  
  100. module DoubleX_RMVXA
  101.  
  102.   module BATB
  103.  
  104.     # Sets the base atb fill time from empty to full as BASE_FILL_T seconds
  105.     # If BASE_FILL_T_VAR_ID is a natural number, the value of variable with id
  106.     # BASE_FILL_T_VAR_ID will be used instead of using BASE_FILL_T
  107.     BASE_FILL_T = 5
  108.     BASE_FILL_T_VAR_ID = 0
  109.  
  110.     # Sets the atb wait condition code as WAIT_COND_CODE
  111.     # If WAIT_COND_CODE_VAR_ID is a natural number, the value of variable with
  112.     # id WAIT_COND_CODE_VAR_ID will be used instead of using WAIT_COND_CODE
  113.     # Available atb wait condition codes:
  114.     # 0 - Wait only when an action's executing or a message's showing
  115.     # 1 - Wait when an animation's playing as well
  116.     # 2 - Wait when the target selection window's shown as well
  117.     # 3 - Wait when the skill/item selection window's shown as well
  118.     # 4 - Wait when players can input actions as well
  119.     WAIT_COND_CODE = 0
  120.     WAIT_COND_CODE_VAR_ID = 0
  121.  
  122.     # Sets the code of the unit of the turn clock as TURN_UNIT_CODE
  123.     # If TURN_UNIT_CODE_VAR_ID is a natural number, the value of variable with
  124.     # id TURN_UNIT_CODE_VAR_ID will be used instead of using TURN_UNIT_CODE
  125.     # Available codes of the unit of the turn clock:
  126.     # 0 - Seconds
  127.     # 1 - Number of executed actions in the same turn
  128.     TURN_UNIT_CODE = 0
  129.     TURN_UNIT_CODE_VAR_ID = 0
  130.  
  131.     # Sets the maximum turn clock unit as MAX_TURN_UNIT
  132.     # If MAX_TURN_UNIT_VAR_ID is a natural number, the value of variable with id
  133.     # MAX_TURN_UNIT_VAR_ID will be used instead of using MAX_TURN_UNIT
  134.     MAX_TURN_UNIT = 5
  135.     MAX_TURN_UNIT_VAR_ID = 0
  136.  
  137.     # Sets the atb fill mode as ATB_FILL_MODE
  138.     # If ATB_FILL_MODE_VAR_ID is a natural number, the value of variable with id
  139.     # ATB_FILL_MODE_VAR_ID will be used instead of using ATB_FILL_MODE
  140.     # Available atb fill modes:
  141.     # 0 - Lets battlers input and execute actions when that battler's atb's full
  142.     #     Empties and refills that battler's atb right after executing actions
  143.     # 1 - Lets battlers input actions when that battler's atb's empty
  144.     #     Refills that battler's atb right after inputting actions
  145.     #     Let battlers execute actions when that battler's atb's full
  146.     #     Empties that battler's atb right after executing actions
  147.     # The value of variable with id ATB_FILL_MODE_VAR_ID should remain the same
  148.     # during battles to ensure proper atb fillings and action executions
  149.     ATB_FILL_MODE = 0
  150.     ATB_FILL_MODE_VAR_ID = 0
  151.  
  152.     # (v1.01a+)Sets the starting atb value mode as ATB_START_MODE
  153.     # If ATB_START_MODE_VAR_ID is a natural number, the value of variable with
  154.     # id ATB_START_MODE_VAR_ID will be used instead of using ATB_START_MODE
  155.     # The starting atb value is always 0.0 for:
  156.     # - unmovable battlers
  157.     # - atb fill mode as 1
  158.     # - actors with start type surprise
  159.     # - enemies with start type preemptive
  160.     # The starting atb value is always 100.0 for:
  161.     # - movable actors with atb fill mode as 0 and start type preemptive
  162.     # - movable enemies with atb fill mode as 0 and start type surprise
  163.     # Available starting atb value mode for normal start:
  164.     # - agi is the battler's agi
  165.     # - param_max(6) is the maximum value of any battler's agi
  166.     # 0 - 0.0
  167.     # 1 - 100.0 * agi / param_max(6)
  168.     ATB_START_MODE = 0
  169.     ATB_START_MODE_VAR_ID = 0
  170.  
  171.     # (v1.02a+)Sets the party escape invocation speed as PARTY_ESC_SPEED
  172.     # It'll only be used with ATB_FILL_MODE being 1
  173.     # With ATB_FILL_MODE being 1, if no actor would be able to act without the
  174.     # party escape attempt, that attempt will fail immediately
  175.     # If PARTY_ESC_SPEED_VAR_ID is a natural number, the value of variable with
  176.     # id PARTY_ESC_SPEED_VAR_ID will be used instead of using PARTY_ESC_SPEED
  177.     PARTY_ESC_SPEED = 0
  178.     PARTY_ESC_SPEED_VAR_ID = 0
  179.  
  180.     # Sets the atb refill rate code as ATB_RATE_CODE
  181.     # If ATB_RATE_CODE_VAR_ID is a natural number, the value of variable with id
  182.     # ATB_RATE_CODE_VAR_ID will be used instead of using ATB_RATE_CODE
  183.     # Available atb refill rate code:
  184.     # - speed is
  185.     #   Battler's agi for atb fill mode 0
  186.     #   Battler's agi + batb_item_speed_sum for atb fill mode 1
  187.     # - batb_item_speed_sum is the sum of invocation speeds(+ attack speed for
  188.     #   the attack skill) of all inputted skills/items
  189.     # - DoubleX_RMVXA::BATB.base_batb_fill_t is the base atb fill time
  190.     # - Graphics.frame_rate is the number of frames per second
  191.     # - BattleManager.batb_avg_agi is the average of all battler's agi
  192.     # 0 - speed * 100.0 / DoubleX_RMVXA::BATB.base_batb_fill_t /
  193.     #     Graphics.frame_rate
  194.     # 1 - (formula in code 0) / BattleManager.batb_avg_agi
  195.     # 2 - Same as 1, except BattleManager.batb_avg_agi will always be
  196.     #     reevalauted per frame instead of just at the start of a battle
  197.     ATB_RATE_CODE = 1
  198.     ATB_RATE_CODE_VAR_ID = 0
  199.  
  200.     # Sets the code of the reset atb mechanism as ATB_RESET_CODE
  201.     # If ATB_RESET_CODE_VAR_ID is a natural number, the value of variable with
  202.     # id ATB_RESET_CODE_VAR_ID will be used instead of using ATB_RESET_CODE
  203.     # Available codes of the atb reset mechanism:
  204.     # 0 - Freezes the atb refill while not movable
  205.     # 1 - Same as 0, except the atb will be emptied when becoming unmovable
  206.     ATB_RESET_CODE = 1
  207.     ATB_RESET_CODE_VAR_ID = 0
  208.  
  209.     # Sets the 1st atb bar color as text color ATB_BAR_COLOR1
  210.     # If ATB_BAR_COLOR1_VAR_ID is a natural number, the value of variable with
  211.     # id ATB_BAR_COLOR1_VAR_ID will be used instead of using ATB_BAR_COLOR1
  212.     # The value of variable with id ATB_BAR_COLOR1_VAR_ID should remain the same
  213.     # during battles to ensure proper atb bar color displays
  214.     ATB_BAR_COLOR1 = 7
  215.     ATB_BAR_COLOR1_VAR_ID = 0
  216.  
  217.     # Sets the 2nd atb bar color as text color ATB_BAR_COLOR2
  218.     # If ATB_BAR_COLOR2_VAR_ID is a natural number, the value of variable with
  219.     # id ATB_BAR_COLOR2_VAR_ID will be used instead of using ATB_BAR_COLOR2
  220.     # The value of variable with id ATB_BAR_COLOR2_VAR_ID should remain the same
  221.     # during battles to ensure proper atb bar color displays
  222.     ATB_BAR_COLOR2 = 8
  223.     ATB_BAR_COLOR2_VAR_ID = 0
  224.  
  225.     # Sets the atb bar description text as ATB_BAR_TEXT
  226.     # If ATB_BAR_TEXT_VAR_ID is a natural number, the value of variable with id
  227.     # ATB_BAR_TEXT_VAR_ID will be used instead of using ATB_BAR_TEXT
  228.     # The value of variable with id ATB_BAR_TEXT_VAR_ID should remain the same
  229.     # during battles to ensure proper atb bar text displays
  230.     ATB_BAR_TEXT = "AP"
  231.     ATB_BAR_TEXT_VAR_ID = 0
  232.  
  233. #==============================================================================|
  234. #  ** Script Implementations                                                   |
  235. #     You need not edit this part as it's about how this script works          |
  236. #------------------------------------------------------------------------------|
  237. #  * Script Support Info:                                                      |
  238. #    1. Prerequisites                                                          |
  239. #       - Basic atb concept and default RMVXA battle system knowledge          |
  240. #       - Some RGSS3 scripting proficiency to fully comprehend this script     |
  241. #    2. Method documentation                                                   |
  242. #       - The 1st part describes why this method's rewritten/aliased for       |
  243. #         rewritten/aliased methods or what the method does for new methods    |
  244. #       - The 2nd part describes what the arguments of the method are          |
  245. #       - The 3rd part informs which version rewritten, aliased or created this|
  246. #         method                                                               |
  247. #       - The 4th part informs whether the method's rewritten or new           |
  248. #       - The 5th part describes how this method works for new methods only,   |
  249. #         and describes the parts added, removed or rewritten for rewritten or |
  250. #         aliased methods only                                                 |
  251. #       Example:                                                               |
  252. # #--------------------------------------------------------------------------| |
  253. # #  Why rewrite/alias/What this method does                                 | |
  254. # #--------------------------------------------------------------------------| |
  255. # # *argv: What these variables are                                            |
  256. # # &argb: What this block is                                                  |
  257. # def def_name(*argv, &argb) # Version X+; Rewrite/New                         |
  258. #   # Added/Removed/Rewritten to do something/How this method works            |
  259. #   def_name_code                                                              |
  260. #   #                                                                          |
  261. # end # def_name                                                               |
  262. #------------------------------------------------------------------------------|
  263.  
  264.     #--------------------------------------------------------------------------|
  265.     #  Helper methods simplifying the uses of the configuration values         |
  266.     #--------------------------------------------------------------------------|
  267.  
  268.     def self.wait_cond_code
  269.       return WAIT_COND_CODE if WAIT_COND_CODE_VAR_ID <= 0
  270.       $game_variables[WAIT_COND_CODE_VAR_ID]
  271.     end # wait_cond_code
  272.  
  273.     def self.turn_unit_code
  274.       return TURN_UNIT_CODE if TURN_UNIT_CODE_VAR_ID <= 0
  275.       $game_variables[TURN_UNIT_CODE_VAR_ID]
  276.     end # turn_unit_code
  277.  
  278.     def self.max_turn_unit
  279.       return MAX_TURN_UNIT if MAX_TURN_UNIT_VAR_ID <= 0
  280.       $game_variables[MAX_TURN_UNIT_VAR_ID]
  281.     end # max_turn_unit
  282.  
  283.     def self.atb_fill_mode
  284.       return ATB_FILL_MODE if ATB_FILL_MODE_VAR_ID <= 0
  285.       $game_variables[ATB_FILL_MODE_VAR_ID]
  286.     end # atb_fill_mode
  287.  
  288.     def self.atb_start_mode # v1.01a+
  289.       return ATB_START_MODE if ATB_START_MODE_VAR_ID <= 0
  290.       $game_variables[ATB_START_MODE_VAR_ID]
  291.     end # atb_start_mode
  292.  
  293.     def self.party_esc_speed # v1.02a+
  294.       return PARTY_ESC_SPEED if PARTY_ESC_SPEED_VAR_ID <= 0
  295.       $game_variables[PARTY_ESC_SPEED_VAR_ID]
  296.     end # party_esc_speed
  297.  
  298.     def self.atb_rate_code
  299.       return ATB_RATE_CODE if ATB_RATE_CODE_VAR_ID <= 0
  300.       $game_variables[ATB_RATE_CODE_VAR_ID]
  301.     end # atb_rate_code
  302.  
  303.     def self.base_fill_t
  304.       return BASE_FILL_T if BASE_FILL_T_VAR_ID <= 0
  305.       $game_variables[BASE_FILL_T_VAR_ID]
  306.     end # base_fill_t
  307.  
  308.     def self.atb_reset_code
  309.       return ATB_RESET_CODE if ATB_RESET_CODE_VAR_ID <= 0
  310.       $game_variables[ATB_RESET_CODE_VAR_ID]
  311.     end # atb_reset_code
  312.  
  313.     def self.atb_bar_color1
  314.       return ATB_BAR_COLOR1 if ATB_BAR_COLOR1_VAR_ID <= 0
  315.       $game_variables[ATB_BAR_COLOR1_VAR_ID]
  316.     end # atb_bar_color1
  317.  
  318.     def self.atb_bar_color2
  319.       return ATB_BAR_COLOR2 if ATB_BAR_COLOR2_VAR_ID <= 0
  320.       $game_variables[ATB_BAR_COLOR2_VAR_ID]
  321.     end # atb_bar_color2
  322.  
  323.     def self.atb_bar_text
  324.       return ATB_BAR_TEXT if ATB_BAR_TEXT_VAR_ID <= 0
  325.       $game_variables[ATB_BAR_TEXT_VAR_ID]
  326.     end # atb_bar_text
  327.  
  328.   end # BATB
  329.  
  330. end # DoubleX_RMVXA
  331.  
  332. #------------------------------------------------------------------------------|
  333. #  * Reimplements the the whole battle flow to run the atb system              |
  334. #------------------------------------------------------------------------------|
  335. class << BattleManager # Edit
  336.  
  337.   #----------------------------------------------------------------------------|
  338.   #  New public instance variables                                             |
  339.   #----------------------------------------------------------------------------|
  340.   attr_accessor :actor_index # Accessed by Scene_Battle to setup actors
  341.   attr_reader :action_battlers # Read by Scene_Battle to execute actions
  342.   attr_reader :batb_base # (v1.02c+)The base and global atb rate denominator
  343.   attr_reader :batb_esc # (v1.02a+)The party escape attempt flag
  344.   attr_writer :batb_can_esc # The party escape allowance flag
  345.  
  346.   #----------------------------------------------------------------------------|
  347.   #  New private instance variable                                             |
  348.   #----------------------------------------------------------------------------|
  349.   # @batb_sum: The cached sum of all battlers' agi
  350.  
  351.   #----------------------------------------------------------------------------|
  352.   #  Always lets actions to be executed at any frame                           |
  353.   #----------------------------------------------------------------------------|
  354.   def in_turn? # Rewrite
  355.     true # Rewritten
  356.   end # in_turn?
  357.  
  358.   #----------------------------------------------------------------------------|
  359.   #  Stops making battlers' actions when opening the party command window      |
  360.   #----------------------------------------------------------------------------|
  361.   alias input_start_batb input_start
  362.   def input_start
  363.     @phase = :input # Added
  364.     input_start_batb
  365.   end # input_start
  366.  
  367.   alias battle_start_batb battle_start
  368.   def battle_start
  369.     battle_start_batb
  370.     batb_battle_start # Added
  371.   end # battle_start
  372.  
  373.   alias process_victory_batb process_victory
  374.   def process_victory
  375.     # Added
  376.     SceneManager.scene.close_batb_windows if SceneManager.scene_is?(Scene_Battle)
  377.     #
  378.     process_victory_batb
  379.   end # process_victory
  380.  
  381.   #----------------------------------------------------------------------------|
  382.   #  Starts/Executes a party escape attempt only if it's allowed/ready         |
  383.   #----------------------------------------------------------------------------|
  384.   alias process_escape_batb process_escape
  385.   def process_escape
  386.     # Rewritten
  387.     return false unless @batb_can_esc
  388.     DoubleX_RMVXA::BATB.atb_fill_mode == 0 ? process_escape_batb : batb_esc_start
  389.     #
  390.   end # process_escape
  391.  
  392.   alias process_defeat_batb process_defeat
  393.   def process_defeat
  394.     # Added
  395.     SceneManager.scene.close_batb_windows if SceneManager.scene_is?(Scene_Battle)
  396.     #
  397.     process_defeat_batb
  398.   end # process_defeat
  399.  
  400.   #----------------------------------------------------------------------------|
  401.   #  Set all battlers' starting atb values using start types upon battle start |
  402.   #----------------------------------------------------------------------------|
  403.   def batb_battle_start # New
  404.     @batb_can_esc = true
  405.     @batb_esc = false
  406.     start = @preemptive ? :preempt : @surprise ? :surprise : :norm
  407.     ($game_party.battle_members + $game_troop.members).each { |mem|
  408.       mem.batb_start(start)
  409.     }
  410.   end # batb_battle_start
  411.  
  412.   #----------------------------------------------------------------------------|
  413.   #  Checks if cases always disabling atb frame updates aren't met             |
  414.   #----------------------------------------------------------------------------|
  415.   def batb_update? # New
  416.     return false if $game_party.all_dead? || $game_troop.all_dead?
  417.     @phase && @phase != :init && !$game_message.visible
  418.   end # batb_update?
  419.  
  420.   #----------------------------------------------------------------------------|
  421.   #  Updates all alive battlers' atb values and the party escape's statuses    |
  422.   #----------------------------------------------------------------------------|
  423.   def batb_update # New
  424.     set_batb_base
  425.     alive_mems = $game_party.alive_members
  426.     (alive_mems + $game_troop.alive_members).each { |b| b.batb_update }
  427.     # Checks if the party escape attempt can continue to charge/execute now
  428.     return unless @batb_can_esc && @batb_esc
  429.     return batb_esc_fail if DoubleX_RMVXA::BATB.atb_fill_mode == 0
  430.     return batb_esc_fail if @action_battlers.none? { |battler| battler.actor? }
  431.     batb_esc_end if alive_mems.any? { |battler| battler.batb_val >= 100.0 }
  432.     #
  433.   end # batb_update
  434.  
  435.   #----------------------------------------------------------------------------|
  436.   #  Returns the base and global atb rate denominator applied to all battlers  |
  437.   #----------------------------------------------------------------------------|
  438.   def set_batb_base # v1.02c+; New
  439.     @batb_base = DoubleX_RMVXA::BATB.base_fill_t * Graphics.frame_rate
  440.     @batb_base *= batb_avg_agi if DoubleX_RMVXA::BATB.atb_rate_code != 0
  441.   end # batb_base_rate
  442.  
  443.   #----------------------------------------------------------------------------|
  444.   #  Returns the cached or reevaluates the average of all alive battler's agi  |
  445.   #----------------------------------------------------------------------------|
  446.   def batb_avg_agi # New
  447.     return @batb_sum if @batb_sum && DoubleX_RMVXA::BATB.atb_rate_code != 2
  448.     mems = $game_party.alive_members + $game_troop.alive_members
  449.     @batb_sum = mems.inject(0) { |sum, battler| sum + battler.agi } / mems.size
  450.   end # batb_avg_agi
  451.  
  452.   #----------------------------------------------------------------------------|
  453.   #  Starts the party escape attempt preparation for atb fill mode 1           |
  454.   #----------------------------------------------------------------------------|
  455.   def batb_esc_start # v1.02a+; New
  456.     $game_message.add(sprintf(Vocab::EscapeStart, $game_party.name))
  457.     Sound.play_escape
  458.     wait_for_message
  459.     @batb_esc = true
  460.     false
  461.   end # batb_esc_start
  462.  
  463.   #----------------------------------------------------------------------------|
  464.   #  Executes the party escape attempt for atb fill mode 1                     |
  465.   #----------------------------------------------------------------------------|
  466.   def batb_esc_end # v1.02a+; New
  467.     @preemptive || rand < @escape_ratio ? process_abort : batb_esc_fail
  468.     wait_for_message
  469.   end # batb_esc_end
  470.  
  471.   #----------------------------------------------------------------------------|
  472.   #  Processes the failed party escape attempt for atb fill mode 1             |
  473.   #----------------------------------------------------------------------------|
  474.   def batb_esc_fail # v1.02a+; New
  475.     @escape_ratio += 0.1
  476.     $game_message.add('\.' + Vocab::EscapeFailure)
  477.     $game_party.clear_actions
  478.     @batb_esc = false
  479.   end # batb_esc_fail
  480.  
  481. end # BattleManager
  482.  
  483. class Game_Action # Edit
  484.  
  485.   #----------------------------------------------------------------------------|
  486.   #  New public instance variable                                              |
  487.   #----------------------------------------------------------------------------|
  488.   attr_accessor :batb_confirm # The action's confirmation flag
  489.  
  490.   alias set_skill_batb set_skill
  491.   def set_skill(skill_id)
  492.     set_skill_batb(skill_id)
  493.     # Added
  494.     @batb_confirm ||= !@item.object.need_selection?
  495.     self
  496.     #
  497.   end # set_skill
  498.  
  499.   alias set_item_batb set_item
  500.   def set_item(item_id)
  501.     set_item_batb(item_id)
  502.     # Added
  503.     @batb_confirm ||= !@item.object.need_selection?
  504.     self
  505.     #
  506.   end # set_item
  507.  
  508. end # Game_Action
  509.  
  510. #------------------------------------------------------------------------------|
  511. #  * Reimplements the actor inputability check and fixes bugs and edge cases   |
  512. #------------------------------------------------------------------------------|
  513. class Game_BattlerBase # Edit
  514.  
  515.   alias hide_batb hide # v1.02b+
  516.   def hide
  517.     hide_batb
  518.     reset_batb_val # Added
  519.   end # hide
  520.  
  521.   alias inputable_batb? inputable?
  522.   def inputable?
  523.     # Rewritten
  524.     return false unless inputable_batb? && @actions.size > 0 && actor?
  525.     !BattleManager.batb_esc && !@actions.all? { |act| act.batb_confirm }
  526.     #
  527.   end # inputable?
  528.  
  529.   #----------------------------------------------------------------------------|
  530.   #  Sets the battler's starting atb value according to the battle start type  |
  531.   #----------------------------------------------------------------------------|
  532.   # start: The battle start type
  533.   def batb_start(start) # v1.02c+; New
  534.     return @batb_val = 0.0 if DoubleX_RMVXA::BATB.atb_start_mode == 0
  535.     return @batb_val = 0.0 if start == :surprise && actor?
  536.     return @batb_val = 0.0 if start == :preempt && enemy?
  537.     @batb_val = 100.0 * agi / param_max(6)
  538.     make_actions if @batb_val >= 100.0
  539.   end # batb_start
  540.  
  541. end # Game_BattlerBase
  542.  
  543. #------------------------------------------------------------------------------|
  544. #  * Implements the battler's atb actions, control flows and logics            |
  545. #------------------------------------------------------------------------------|
  546. class Game_Battler < Game_BattlerBase # Edit
  547.  
  548.   #----------------------------------------------------------------------------|
  549.   #  New public instance variables                                             |
  550.   #----------------------------------------------------------------------------|
  551.   attr_accessor :batb_val_change # The atb value change flag
  552.   attr_reader :batb_val # The battler's atb value
  553.  
  554.   #----------------------------------------------------------------------------|
  555.   #  (v1.02c+)New private instance variable                                    |
  556.   #----------------------------------------------------------------------------|
  557.   # @batb_speed: The cached speed sum of all skills/items to be executed
  558.  
  559.   def update_state_turns # v1.02a+; Rewrite
  560.     batb_update_state_turns(2) # Rewritten
  561.   end # update_state_turns
  562.  
  563.   alias initialize_batb initialize
  564.   def initialize
  565.     initialize_batb
  566.     # Added to fix nil action input index bugs and edge cases as well
  567.     clear_actions
  568.     @batb_val = 0.0
  569.     #
  570.   end # initialize
  571.  
  572.   alias on_restrict_batb on_restrict
  573.   def on_restrict
  574.     on_restrict_batb
  575.     # Added to fix nil action battlers bugs and edge cases as well
  576.     return unless BattleManager.action_battlers
  577.     reset_batb_val(DoubleX_RMVXA::BATB.atb_reset_code == 0)
  578.     #
  579.   end # on_restrict
  580.  
  581.   #----------------------------------------------------------------------------|
  582.   #  Marks that this battler becomes able to act as well                       |
  583.   #----------------------------------------------------------------------------|
  584.   alias make_actions_batb make_actions
  585.   def make_actions
  586.     make_actions_batb
  587.     # Added
  588.     return if BattleManager.action_battlers.include?(self)
  589.     BattleManager.action_battlers << self
  590.     #
  591.   end # make_actions
  592.  
  593.   alias on_action_end_batb on_action_end
  594.   def on_action_end
  595.     on_action_end_batb
  596.     # Added
  597.     batb_update_state_turns(1)
  598.     reset_batb_val
  599.     #
  600.   end # on_action_end
  601.  
  602.   alias on_turn_end_batb on_turn_end
  603.   def on_turn_end
  604.     on_turn_end_batb
  605.     remove_buffs_auto # Added
  606.   end # on_turn_end
  607.  
  608.   #----------------------------------------------------------------------------|
  609.   #  Ensures battlers added after the battle starts will start with 0 atb value|
  610.   #----------------------------------------------------------------------------|
  611.   alias on_battle_end_batb on_battle_end
  612.   def on_battle_end
  613.     on_battle_end_batb
  614.     @batb_val = 0.0 # Added
  615.   end # on_battle_end
  616.  
  617.   #----------------------------------------------------------------------------|
  618.   #  Sets the battler's starting atb value according to the battle start type  |
  619.   #----------------------------------------------------------------------------|
  620.   # start: The battle start type
  621.   def batb_start(start) # New
  622.     @batb_val_change = true
  623.     return @batb_val = 0.0 unless movable?
  624.     if DoubleX_RMVXA::BATB.atb_fill_mode == 1
  625.       @batb_val = 0.0
  626.       return make_actions
  627.     elsif start == :preempt && actor? || start == :surprise && enemy?
  628.       @batb_val = 100.0
  629.       return make_actions
  630.     end
  631.     super(start)
  632.   end # batb_start
  633.  
  634.   #----------------------------------------------------------------------------|
  635.   #  Lets states with different auto removal timings to update turns separately|
  636.   #----------------------------------------------------------------------------|
  637.   # timing: The state's auto removal timing
  638.   def batb_update_state_turns(timing) # v1.02c+; New
  639.     states.each { |state|
  640.       next if state.auto_removal_timing != timing
  641.       @state_turns[state.id] -= 1 if @state_turns[state.id] > 0
  642.     }
  643.   end # update_state_turns
  644.  
  645.   #----------------------------------------------------------------------------|
  646.   #  Increases the battler's atb value and makes actions in mode 0 if it's full|
  647.   #----------------------------------------------------------------------------|
  648.   def batb_update # New
  649.     return if @batb_val >= 100.0 || inputable? || restriction > 3
  650.     mode = DoubleX_RMVXA::BATB.atb_fill_mode
  651.     return make_actions if mode == 1 && @batb_val == 0.0 && @actions.empty?
  652.     @batb_val_change = @batb_val != @batb_val += batb_rate
  653.     return unless @batb_val >= 100.0
  654.     @batb_val = 100.0
  655.     make_actions if mode == 0
  656.   end # batb_update
  657.  
  658.   #----------------------------------------------------------------------------|
  659.   #  Returns the atb rate using the current rate formula and cached speed sum  |
  660.   #----------------------------------------------------------------------------|
  661.   def batb_rate # New
  662.     rate = agi
  663.     @batb_speed ||= batb_speed # Caches the sum until the actions are cleared
  664.     rate += @batb_speed if DoubleX_RMVXA::BATB.atb_fill_mode == 1
  665.     rate < 0 ? 0 : rate * 100.0 / BattleManager.batb_base
  666.   end # batb_rate
  667.  
  668.   #----------------------------------------------------------------------------|
  669.   #  Returns the invocation speed sum of all skills/items to be executed       |
  670.   #----------------------------------------------------------------------------|
  671.   def batb_speed # v1.02a+; New
  672.     return DoubleX_RMVXA::BATB.party_esc_speed if BattleManager.batb_esc
  673.     @actions.inject(0) { |sum, act|
  674.       act.item ? sum + act.item.speed + (act.attack? ? atk_speed : 0) : 0
  675.     }
  676.   end # batb_speed
  677.  
  678.   #----------------------------------------------------------------------------|
  679.   #  Resets the battler's atb value to its min and clears all battler's actions|
  680.   #----------------------------------------------------------------------------|
  681.   # reset: The battler action reset flag
  682.   def reset_batb_val(reset = true) # New
  683.     if reset
  684.       @batb_val = 0.0
  685.       @batb_val_change = true
  686.     end
  687.     clear_actions
  688.     @batb_speed = nil # Clears the cached sum to be ready to cache new ones
  689.     BattleManager.action_battlers.delete(self)
  690.     BattleManager.clear_actor if actor? && BattleManager.actor == self
  691.   end # reset_batb_val
  692.  
  693. end # Game_Battler
  694.  
  695. #------------------------------------------------------------------------------|
  696. #  * Resets all party members' atb values upon failed party escape attempts    |
  697. #------------------------------------------------------------------------------|
  698. class Game_Party < Game_Unit # v1.01a+; Edit
  699.  
  700.   #----------------------------------------------------------------------------|
  701.   #  Resets all party members' atb values as well                              |
  702.   #----------------------------------------------------------------------------|
  703.   alias clear_actions_batb clear_actions
  704.   def clear_actions
  705.     clear_actions_batb
  706.     members.each { |mem| mem.reset_batb_val } # Added
  707.   end # clear_actions
  708.  
  709. end # Game_Party
  710.  
  711. class Window_BattleStatus < Window_Selectable # Edit
  712.  
  713.   #----------------------------------------------------------------------------|
  714.   #  Reserves enough space for the atb bars to be drawn as well                |
  715.   #----------------------------------------------------------------------------|
  716.   def draw_gauge_area_with_tp(rect, actor) # Rewrite
  717.     # Rewritten
  718.     draw_actor_hp(actor, rect.x + 0, rect.y, 60)
  719.     draw_actor_mp(actor, rect.x + 64, rect.y, 60)
  720.     draw_actor_tp(actor, rect.x + 128, rect.y, 52)
  721.     draw_batb_bar(rect, actor, true) if actor
  722.     #
  723.   end # draw_gauge_area_with_tp
  724.  
  725.   #----------------------------------------------------------------------------|
  726.   #  Reserves enough space for the atb bars to be drawn as well                |
  727.   #----------------------------------------------------------------------------|
  728.   def draw_gauge_area_without_tp(rect, actor) # Rewrite
  729.     # Rewritten
  730.     draw_actor_hp(actor, rect.x + 0, rect.y, 72)
  731.     draw_actor_mp(actor, rect.x + 80,  rect.y, 72)
  732.     draw_batb_bar(rect, actor, false) if actor
  733.     #
  734.   end # draw_gauge_area_without_tp
  735.  
  736.   #----------------------------------------------------------------------------|
  737.   #  Draws each actor's atb bar only if that actor's atb value's changed       |
  738.   #----------------------------------------------------------------------------|
  739.   def refresh_batb_bars # New
  740.     display_tp = $data_system.opt_display_tp
  741.     item_max.times { |index|
  742.       actor = $game_party.battle_members[index]
  743.       next unless actor && actor.batb_val_change
  744.       draw_batb_bar(gauge_area_rect(index), actor, display_tp)
  745.     }
  746.   end # refresh_batb_bars
  747.  
  748.   # rect: The atb bar's rect
  749.   # actor: The atb bar's owner
  750.   # display_tp: The tp bar display flag
  751.   def draw_batb_bar(rect, actor, display_tp) # New
  752.     display_tp ? (x, w = rect.x + 184, 36) : (x, w = rect.x + 160, 60)
  753.     color1 = text_color(DoubleX_RMVXA::BATB.atb_bar_color1)
  754.     color2 = text_color(DoubleX_RMVXA::BATB.atb_bar_color2)
  755.     draw_gauge(x, rect.y, w, actor.batb_val / 100.0, color1, color2)
  756.     change_color(system_color)
  757.     draw_text(x, rect.y, 30, line_height, DoubleX_RMVXA::BATB.atb_bar_text)
  758.     actor.batb_val_change = false
  759.   end # draw_batb_bar
  760.  
  761. end # Window_BattleStatus
  762.  
  763. #------------------------------------------------------------------------------|
  764. #  * Reconstructs the the whole battle flow to control the atb system          |
  765. #------------------------------------------------------------------------------|
  766. class Scene_Battle < Scene_Base # Edit
  767.  
  768.   #----------------------------------------------------------------------------|
  769.   #  New private instance variable                                             |
  770.   #----------------------------------------------------------------------------|
  771.   # @batb_turn_clock: The turn atb clock with both units
  772.  
  773.   #----------------------------------------------------------------------------|
  774.   #  Moves the info viewport according to which windows are active             |
  775.   #----------------------------------------------------------------------------|
  776.   def update_info_viewport # Rewrite
  777.     # Rewritten
  778.     return move_info_viewport(0) if @party_command_window.active
  779.     windows = [@actor_window, @enemy_window, @skill_window, @item_window]
  780.     return move_info_viewport(128) if windows.any? { |window| window.visible }
  781.     return move_info_viewport(128) if @actor_command_window.active
  782.     move_info_viewport(64)
  783.     #
  784.   end # update_info_viewport
  785.  
  786.   def turn_start # Rewrite
  787.     @party_command_window.close
  788.     @actor_command_window.close
  789.     @status_window.unselect
  790.     # Removed to stop shifting battle phase nor clearing subject
  791.     @log_window.wait
  792.     # (v1.01a+)Removed to stop clearing the log window
  793.   end # turn_start
  794.  
  795.   def turn_end # Rewrite
  796.     ($game_party.battle_members + $game_troop.members).each { |battler|
  797.       battler.on_turn_end
  798.       refresh_status
  799.       @log_window.display_auto_affected_status(battler)
  800.       @log_window.wait_and_clear
  801.     }
  802.     $game_troop.increase_turn # Added
  803.     BattleManager.turn_end
  804.     process_event
  805.     # Removed to stop opening the party window
  806.   end # turn_end
  807.  
  808.   #----------------------------------------------------------------------------|
  809.   #  Executes non forced actions of all actable battlers not trying to escape  |
  810.   #----------------------------------------------------------------------------|
  811.   def process_action # Rewrite
  812.     return if scene_changing?
  813.     # Rewritten
  814.     return process_batb_act(true) if @subject
  815.     esc = BattleManager.batb_esc
  816.     BattleManager.action_battlers.each { |battler|
  817.       next if esc && battler.actor?
  818.       next if battler.batb_val < 100.0 || battler.inputable?
  819.       @subject = battler
  820.       process_batb_act
  821.       @subject = nil
  822.     }
  823.     #
  824.   end # process_action
  825.  
  826.   alias start_batb start
  827.   def start
  828.     start_batb
  829.     @batb_turn_clock = [0, 0] # Added
  830.   end # start
  831.  
  832.   alias update_batb update
  833.   def update
  834.     update_batb
  835.     batb_update if !@spriteset.animation? && batb_update? # Added
  836.   end # update
  837.  
  838.   alias update_for_wait_batb update_for_wait
  839.   def update_for_wait
  840.     update_for_wait_batb
  841.     batb_update if @spriteset.animation? && batb_update? # Added
  842.   end # update_for_wait
  843.  
  844.   alias update_message_open_batb update_message_open
  845.   def update_message_open
  846.     update_message_open_batb
  847.     # Added
  848.     return if $game_message.busy?
  849.     return if $game_troop.all_dead? || $game_party.all_dead?
  850.     batb_update_message_open if @status_window.close?
  851.     #
  852.   end # update_message_open
  853.  
  854.   alias refresh_status_batb refresh_status
  855.   def refresh_status
  856.     refresh_status_batb
  857.     # Added
  858.     windows = [@actor_window, @enemy_window, @skill_window, @item_window]
  859.     (windows + [@actor_command_window]).each { |w| w.refresh if w.visible }
  860.     #
  861.   end # refresh_status
  862.  
  863.   alias command_guard_batb command_guard
  864.   def command_guard
  865.     # Added to fix nil actor and/or input bugs and edge cases as well
  866.     actor = BattleManager.actor
  867.     return unless actor && actor.input
  868.     actor.input.batb_confirm = true
  869.     #
  870.     command_guard_batb
  871.   end # command_guard
  872.  
  873.   alias on_actor_ok_batb on_actor_ok
  874.   def on_actor_ok
  875.     # Added to fix nil actor and/or input bugs and edge cases as well
  876.     actor = BattleManager.actor
  877.     return unless actor && actor.input
  878.     actor.input.batb_confirm = true
  879.     #
  880.     on_actor_ok_batb
  881.   end # on_actor_ok
  882.  
  883.   alias on_enemy_ok_batb on_enemy_ok
  884.   def on_enemy_ok
  885.     # Added to fix nil enemy, actor and/or input bugs and edge cases as well
  886.     return if $game_troop.all_dead?
  887.     actor = BattleManager.actor
  888.     return unless actor && actor.input
  889.     actor.input.batb_confirm = true
  890.     #
  891.     on_enemy_ok_batb
  892.   end # on_enemy_ok
  893.  
  894.   #----------------------------------------------------------------------------|
  895.   #  Runs the atb frame update                                                 |
  896.   #----------------------------------------------------------------------------|
  897.   def batb_update # New
  898.     batb_update_turn(0)
  899.     BattleManager.batb_update
  900.     list = BattleManager.action_battlers.select { |b| b.actor? && b.inputable? }
  901.     list.collect! { |battler| battler.index }
  902.     batb_update_windows(list) unless list.include?(@status_window.index)
  903.     @status_window.refresh_batb_bars
  904.   end # batb_update
  905.  
  906.   # list: The list of indices of all the currently inputable actors
  907.   def batb_update_windows(list) # New
  908.     if @status_window.index >= 0
  909.       batb_close_selection_windows
  910.     elsif list.empty?
  911.       @party_command_window.deactivate.close if @party_command_window.active
  912.       return
  913.     end
  914.     return if @party_command_window.active || list.empty?
  915.     BattleManager.actor_index = list[0]
  916.     start_actor_command_selection
  917.   end # batb_update_windows
  918.  
  919.   def batb_close_selection_windows # v1.02c+; New
  920.     windows = [@actor_window, @enemy_window, @skill_window, @item_window]
  921.     @status_window.open.show if windows.any? { |window| window.visible }
  922.     (windows + [@actor_command_window]).each { |window|
  923.       window.hide.deactivate.close if window.active
  924.     }
  925.     @status_window.unselect
  926.   end # batb_close_selection_windows
  927.  
  928.   def batb_update? # New
  929.     # Checks if atb frame update can be run and the wait conditions aren't met
  930.     return false if scene_changing? || !BattleManager.batb_update?
  931.     code = DoubleX_RMVXA::BATB.wait_cond_code
  932.     return true if code == 0
  933.     return false if @spriteset.animation?
  934.     return true if code == 1
  935.     return false if @actor_window.active || @enemy_window.active
  936.     return true if code == 2
  937.     return false if @skill_window.active || @item_window.active
  938.     code == 3 || !@actor_command_window.active && !@party_command_window.active
  939.     #
  940.   end # batb_update?
  941.  
  942.   # forced: Whether the action's forced
  943.   def process_batb_act(forced = false) # New
  944.     while @subject.current_action
  945.       @subject.current_action.prepare
  946.       exec_batb_act if @subject.current_action.valid?
  947.       @subject.remove_current_action
  948.       break if forced
  949.     end
  950.     process_action_end unless @subject.current_action
  951.   end # process_batb_act
  952.  
  953.   def exec_batb_act # New
  954.     @status_window.open
  955.     BattleManager.batb_can_esc = false
  956.     execute_action
  957.     BattleManager.batb_can_esc = true
  958.     batb_update_turn(1)
  959.   end # exec_batb_act
  960.  
  961.   # code: The current turn atb clock unit code
  962.   def batb_update_turn(code) # New
  963.     # Increases the turn number and resets its atb clock when its max's reached
  964.     return unless code == DoubleX_RMVXA::BATB.turn_unit_code
  965.     @batb_turn_clock[code] += 1
  966.     max_clock = DoubleX_RMVXA::BATB.max_turn_unit
  967.     max_clock *= Graphics.frame_rate if code == 0
  968.     return unless @batb_turn_clock[code] >= max_clock
  969.     @batb_turn_clock[code] = 0
  970.     turn_end
  971.     #
  972.   end # batb_update_turn
  973.  
  974.   #----------------------------------------------------------------------------|
  975.   #  Opens the actor or party command window according to the window statuses  |
  976.   #----------------------------------------------------------------------------|
  977.   def batb_update_message_open # New
  978.     @status_window.open
  979.     windows = [@actor_window, @enemy_window, @skill_window, @item_window]
  980.     return @actor_command_window.open if windows.any? { |window| window.active }
  981.     return @actor_command_window.open if @actor_command_window.active
  982.     @party_command_window.open if @party_command_window.active
  983.   end # batb_update_message_open
  984.  
  985.   #----------------------------------------------------------------------------|
  986.   #  Closes all windows upon battle end                                        |
  987.   #----------------------------------------------------------------------------|
  988.   def close_batb_windows # New
  989.     windows = [@actor_window, @enemy_window, @skill_window, @item_window]
  990.     ([@actor_command_window, @party_command_window] + windows).each { |window|
  991.       window.hide.deactivate.close
  992.     }
  993.   end # close_batb_windows
  994.  
  995. end # Scene_Battle
  996.  
  997. #------------------------------------------------------------------------------|
  998.  
  999. #==============================================================================|
RAW Paste Data
Top