Advertisement
Double_X

DoubleX RMVXA Basic ATB v1.02c

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