Double_X

DoubleX RMMV Popularized ATB Core v104b

Nov 22nd, 2015
1,438
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*============================================================================
  2.  *    ## Plugin Info
  3.  *----------------------------------------------------------------------------
  4.  *    # Plugin Name
  5.  *      DoubleX RMMV Popularized ATB Core
  6.  *----------------------------------------------------------------------------
  7.  *    # Terms Of Use
  8.  *      You shall keep this plugin's Plugin Info part's contents intact
  9.  *      You shalln't claim that this plugin's written by anyone other than
  10.  *      DoubleX or his aliases
  11.  *      None of the above applies to DoubleX or his aliases
  12.  *----------------------------------------------------------------------------
  13.  *    # Prerequisites
  14.  *      Abilities:
  15.  *      1. Nothing special for most ordinary use cases
  16.  *      2. Little Javascript coding proficiency to fully utilize this plugin
  17.  *----------------------------------------------------------------------------
  18.  *    # Author Notes
  19.  *      1. DoubleX RMMV Popularized ATB uses the core addon approach with this
  20.  *         plugin as its core and all addons needing this plugin to work
  21.  *      2. DoubleX RMMV Popularized ATB also serves as a learning tool for
  22.  *         plugin developers to learn how an atb system plugin can be written
  23.  *      3. State's Auto-removal Timing as Action End becomes right after the
  24.  *         state owner executed all the actions to conform with the defaults
  25.  *----------------------------------------------------------------------------
  26.  *    # Links
  27.  *      This plugin:
  28.  *      1. http://pastebin.com/9nEDBapc
  29.  *      Video:
  30.  *      1. https://www.youtube.com/watch?v=6KTV1k6ohfE
  31.  *      Basic knowledge on writing ATB(Active Time Battle) system plugins:
  32.  *      1. Link included in http://rpgmaker.net/submit/script/631/
  33.  *----------------------------------------------------------------------------
  34.  *    # Author
  35.  *      DoubleX
  36.  *----------------------------------------------------------------------------
  37.  *    # Changelog
  38.  *      v1.04a(GMT 1200 20-5-2020):
  39.  *      1. Added wait_party_cmd
  40.  *      v1.03d(GMT 0500 20-5-2020):
  41.  *      1. Fixed the party escape command being selectable even when it won't
  42.  *         be effective
  43.  *      v1.03c(GMT 0400 13-5-2020):
  44.  *      1. Fixed the skill/item window being locked after another actor dies
  45.  *      2. Fixed the actor command window being deselected after another actor
  46.  *         dies
  47.  *      v1.03b(GMT 0400 28-4-2020):
  48.  *      1. Fixed the target window being locked after another actor dies
  49.  *      2. Fixed stale target sprite still displayed as being selected
  50.  *      v1.03a(GMT 1200 26-8-2017):
  51.  *      1. Added no_prior_actor
  52.  *      v1.02d(GMT 1500 13-8-2017):
  53.  *      1. Increased this plugin's extensibility, modularity and robustness
  54.  *      v1.02c(GMT 0500 11-8-2017):
  55.  *      1. Fixed the 1st actor becoming inputable not performing the waiting
  56.  *         pose bug
  57.  *      v1.02b(GMT 0500 17-9-2016):
  58.  *      1. Fixed max_linked_input_actors not working when there are 3+
  59.  *         inputable actors at the same time with no one having Action Times +
  60.  *      2. Lets you set max_linked_input_actors as negative to disable it
  61.  *      v1.02a(GMT 0600 20-8-2016):
  62.  *      1. Added max_linked_input_actors
  63.  *      v1.01f(GMT 1400 12-8-2016):
  64.  *      1. Fixed empty atb_bar_text being converted to 0 bug
  65.  *      2. PATB notetags won't be loaded more than once per game execution
  66.  *      3. Increased this plugin's effectiveness, efficiency and simplicity
  67.  *      v1.01e(GMT 0500 15-7-2016):
  68.  *      1. Upgraded to support the latest version of PATB Order
  69.  *      2. Increased this plugin's effectiveness, efficiency and readibility
  70.  *      v1.01d(GMT 0800 19-6-2016):
  71.  *      1. Fixed maximum atb value being possible to be nonpositive bug
  72.  *      v1.01c(GMT 1000 5-6-2016):
  73.  *      1. Fixed not updating unmovable battlers' max atb and countdown states
  74.  *      2. Improved this plugin's effectiveness, efficiency and readibility
  75.  *      v1.01b(GMT 1400 31-5-2016):
  76.  *      1. Fixed the unmovable battlers having nonempty atb bug in start addon
  77.  *      2. Improved this plugin's effectiveness, efficiency and readibility
  78.  *      v1.01a(GMT 0300 20-2-2016):
  79.  *      1. Lets users set whether actor atb bar will be shown on status window
  80.  *      2. Fixed inactive actor command window not being closed immediately
  81.  *      3. Fixed not refreshing the inputable actor upon confirming input bug
  82.  *      v1.00d(GMT 0400 7-2-2016):
  83.  *      1. Fixed not updating the status window when executing actions bug
  84.  *      2. Fixed actor input windows not deactivating upon being uninputable
  85.  *      3. Fixed forbidden party escape freezing the party command window bug
  86.  *      4. Loosens the coupling between core, charge, cooldown and speed addon
  87.  *      5. Removed some excessive couplings and added some code documentations
  88.  *      v1.00c(GMT 1000 31-1-2016):
  89.  *      1. Fixed not updating the battler atb rate due to changing the battler
  90.  *         agi without changing the base atb rate bug
  91.  *      2. Fixed not refreshing actor atb bar upon reset with delay fill mode
  92.  *      3. Fixed not updating the status window when executing actions bug
  93.  *      v1.00b(GMT 0900 27-1-2016):
  94.  *      1. Fixed active hidden actor command window after closing all windows
  95.  *      2. Fixed not updating status windos and incorrect actor window x
  96.  *         position in unavailable battle system codes
  97.  *      3. Fixed actor not able to execute autobattle/confusion actions with
  98.  *         max atb value notetag used
  99.  *      4. Fixed actor not able to do anything if becoming autobattle or
  100.  *         restricted when inputable bug
  101.  *      5. max_atb_val must be at least 10000 times larger than 2 ^ -52
  102.  *      6. atb gain rate must be at least 2 ^ -52 * max atb value * 100 per
  103.  *         frame
  104.  *      7. Confused battlers can execute confused actions ahortly after
  105.  *         removing confusion
  106.  *      8. Next/prior command can cause actor selections to appear chaotic
  107.  *      9. The battle turn clock can be disabled as using an unavailable unit
  108.  *      10. Increased this plugin's compatibility, modularity and readability
  109.  *      v1.00a(GMT 0400 23-1-2016):
  110.  *      1. Outsourced the ctb feature to the CTB addon
  111.  *      2. Fixed same name patb_rate for both a property setter and function
  112.  *      3. Fixed actors added during battles having unitiailized atb statuses
  113.  *      4. Fxied undefined textWidth in draw_actor_patb bug
  114.  *      5. Fixed trying to read meta from null equip bug
  115.  *      6. Fixed undefined this_ and patb_color due to typo bug
  116.  *      7. Fixed unitialized max atb value upon battle start bug
  117.  *      8. Fixed executing next action before finishing the current one bug
  118.  *      9. Fixed actor window not completely covering status window bug
  119.  *      10. Actor poses can be chaotic when actor input actions or battle ends
  120.  *      11. Added some missing documentations
  121.  *      12. Incrased this plugin's compactness, modularity and simplicity
  122.  *      13. 1st completed version of this plugin finished
  123.  *      v0.00g(GMT 0700 1-1-2016):
  124.  *      1. Fixed undefined data in Game_Battler.prototype.patb_note_data bug
  125.  *      2. Fixed used the undefined any instead of some function for Array bug
  126.  *      3. Fixed missed return in Array filter function bug
  127.  *      4. Fixed undefined SceneManager.scene by adding a this._scene getter
  128.  *      5. Increased this plugin's compactness, modularity and readability
  129.  *      v0.00f(GMT 1200 9-12-2015):
  130.  *      1. Fixed concat the active flag of the actor command window instead of
  131.  *         the window itself
  132.  *      2. Fixed not refreshing the actor atb bars upon resetting atb values
  133.  *      3. Updated some outdated documentations
  134.  *      4. Increased this plugin's extensibility, modularity and readability
  135.  *      v0.00e(GMT 1300 29-11-2015):
  136.  *      1. Fixed not refreshing all input windows upon turn end
  137.  *      2. Fixed not returning the reevaluated sum of all battlers' agi
  138.  *      3. Fixed not clearing the sum of all battlers' agi upon battle start
  139.  *      4. Fixed not raising refresh and update flags upon battler atb reset
  140.  *      5. Fixed undefined updateEvent due to typo
  141.  *      6. Fixed duplicate battle event updates upon turn end
  142.  *      7. Fixed resetting atb always clearing the atb values on restrict
  143.  *      8. Added atb_rate_code abs_agi
  144.  *      9. Updated some outdated documentations
  145.  *      10. Increased this plugin's extensibility, modularity and robustness
  146.  *      v0.00d(GMT 0100 27-11-2015):
  147.  *      1. Exposed more easy, simple and user-friendly plugin calls
  148.  *      2. Increased this plugin's efficiency and user-friendliness
  149.  *      v0.00c(GMT 1400 24-11-2015):
  150.  *      1. Fixed database falsely returning database not loaded on game start
  151.  *      2. Fixed BattleManager properties falsely belonging to Game_Battler
  152.  *      3. Fixed undefined this when raising the battler's refresh flags
  153.  *      4. Fixed are_patb_battler_changed not referenced by this due to typo
  154.  *      5. Fixed atb bars not drawing properly due to note passing fill rate
  155.  *      6. Invalid configuration and/or notetag values will log error messages
  156.  *      7. The param descriptions and plugin help become more helpful to users
  157.  *      8. Increased this plugin's extensibility, readability and robustness
  158.  *      v0.00b(GMT 0000 24-11-2015):
  159.  *      1. Fixed changing max atb value not rechecking battler actability
  160.  *      2. Fixed null this when reading <operator max patb val: val> notetag
  161.  *      3. Fixed update state turns not working in the default battle system
  162.  *      4. Fixed description, params and help not loading due to typo
  163.  *      5. Fixed battler atb clock update not triggering due to typo
  164.  *      6. Fixed action set item passing the null argument due to typo
  165.  *      7. Fixed undefined function error when updating atb frame due to typo
  166.  *      8. Fixed failed party escape not resetting actors' atb values in delay
  167.  *      9. Fixed passing wrong color argument type when drawing actor atb bars
  168.  *      10. Simplified operator in <operator max patb val: val>
  169.  *      11. Increased this plugin's efficiency, extensibility and modularity
  170.  *      v0.00a(GMT 1600 22-11-2015):
  171.  *      1. 1st testing version of this plugin finished
  172.  *============================================================================*/
  173. /*:
  174.  * @plugindesc To be an easy, simple and user-friendly, yet powerful atb system
  175.  *             Serves as the core plugin implementing all atb system essentials
  176.  * @author DoubleX
  177.  *
  178.  * @param battle_system_code
  179.  * @desc Sets the code indicating if ATB or the default battle system will be
  180.  *       used as battle_system_code
  181.  *       Available codes for battle_system_code:
  182.  *       atb - ATB will be used
  183.  *       The default battle system will be used if battle_system_code doesn't
  184.  *       return any available code
  185.  *       battle_system_code must not be changed from the available codes to the
  186.  *       unavailable ones during the same battle(the same for the vice versa) or
  187.  *       this plugin will fail extremely badly
  188.  * @default atb
  189.  *
  190.  * @param base_fill_time
  191.  * @desc Sets the base atb fill time from empty to full as base_fill_time
  192.  *       seconds
  193.  *       base_fill_time must return a Number and should return a positive one
  194.  * @default 5
  195.  *
  196.  * @param turn_unit_code
  197.  * @desc Sets the code of the unit of the battle turn clock as turn_unit_code
  198.  *       Available code for the unit of the battle turn clock:
  199.  *       act - Number of executed actions
  200.  *       sec - Seconds
  201.  *       The battle turn clock won't run if turn_unit_code doesn't return an
  202.  *       available code
  203.  * @default sec
  204.  *
  205.  * @param max_turn_unit
  206.  * @desc Sets the maximum battle turn clock unit as max_turn_unit
  207.  *       max_turn_unit must return a Number and should return a positive one
  208.  * @default 5
  209.  *
  210.  * @param wait_cond_code
  211.  * @desc Sets the atb wait condition code as wait_cond_code
  212.  *       Available atb wait condition codes:
  213.  *       full - Wait only when a message's showing or an event's running
  214.  *       act - Wait when an action's executing as well
  215.  *       target - Wait when the target selection window's shown as well
  216.  *       item - Wait when the skill/item selection window's shown as well
  217.  *       "Wait when players can input actions as well" will be used if
  218.  *       wait_cond_code doesn't return any available code
  219.  *       Only 1 battler can execute actions at a time
  220.  *       Only 1 action can be executed at a time
  221.  * @default full
  222.  *
  223.  * @param wait_party_cmd
  224.  * @desc (v1.04a+)Forces the atb to wait when the party command window's shown
  225.  *       wait_cond_code will be applied otherwise
  226.  * @default false
  227.  *
  228.  * @param atb_fill_code
  229.  * @desc Sets the atb fill code as atb_fill_code
  230.  *       Available atb fill code:
  231.  *       delay - Lets battlers input actions when that battler's atb's empty
  232.  *               Refills that battler's atb right after executing actions
  233.  *       If atb_fill_code doesn't return an available atb fill code, "Lets
  234.  *       battlers input and execute actions when the battler's atb's full and
  235.  *       empties the battler's atb right after executing actions" will be used
  236.  *       atb_fill_code should return the same code during the same battle to
  237.  *       ensure proper atb fillings and action executions
  238.  * @default fill
  239.  *
  240.  * @param max_atb_val
  241.  * @desc Sets the minimum atb value regarded as overlay(also the maximum atb
  242.  *       value displayed on the atb bars) with atb fill code delay, and the
  243.  *       maximum atb value with other codes, as max_atb_val
  244.  *       max_atb_val must return a nonzero Number and should return a positive
  245.  *       one
  246.  *       max_atb_val should return the same value during the same battle to
  247.  *       ensure proper atb fillings and action executions
  248.  *       max_atb_val must be at least 10000 times larger than 2 ^ -52
  249.  * @default 100
  250.  *
  251.  * @param atb_rate_code
  252.  * @desc Sets the atb refill rate code as atb_rate_code
  253.  *       Available atb refill rate codes:
  254.  *       abs_agi - agi
  255.  *       agi - agi * max_atb_val / base_fill_time / 60
  256.  *       avg_agi - (formula in agi) / average of all alive battlers' agi
  257.  *       The fps is assumed to be always 60
  258.  *       If atb_rate_code returns an unavailable atb refill rate code, it'll be
  259.  *       the same as avg_agi, except BattleManager.patb_avg_agi will always be
  260.  *       reevalauted when it can change instead of just upon battle start
  261.  *       atb gain rate must be at least 2 ^ -52 * max atb value * 100 per frame
  262.  * @default update_avg_agi
  263.  *
  264.  * @param atb_start_code
  265.  * @desc Sets the starting atb value code as atb_start_code
  266.  *       The starting atb value is always 0 for:
  267.  *       - unmovable battlers with non-delay atb fill code
  268.  *       - actors with non-delay atb fill code and start type as surprise
  269.  *       - enemies with non-delay atb fill code and start type as preemptive
  270.  *       - actors with atb fill code delay and start type as preemptive
  271.  *       - enemies with atb fill code delay and start type as surprise
  272.  *       The starting atb value is always max_atb_val for:
  273.  *       - unmovable battlers with atb fill code delay
  274.  *       - actors with non-delay atb fill code and start type as preemptive
  275.  *       - enemies with non-delay atb fill code and start type as surprise
  276.  *       - actors with atb fill code delay and start type as surprise
  277.  *       - enemies with atb fill code delay and start type as preemptive
  278.  *       Available starting atb value code for normal start:
  279.  *       agi - max_atb_val * agi / max agi in non-delay atb fill code
  280.  *             max_atb_val * (1 - agi / this.paramMax(6)) in atb fill code
  281.  *             delay
  282.  *       The starting atb value will be 0 and max_atb_val in non-delay and
  283.  *       delay atb fill code respectively if atb_start_code doesn't return an
  284.  *       available starting atb value code for normal starts
  285.  * @default agi
  286.  *
  287.  * @param atb_reset_code
  288.  * @desc Sets the code of the reset atb mechanism as atb_reset_code for
  289.  *       additional effects
  290.  *       It'll only be used with non-delay atb_reset_code
  291.  *       The atb refill will always be freezed while not movable
  292.  *       Available code for the atb reset mechanism for additional effects:
  293.  *       clear - The atb will be emptied when becoming unmovable as well
  294.  *       No additional effects will trigger if atb_reset_code doesn't return
  295.  *       an available code
  296.  * @default clear
  297.  *
  298.  * @param max_linked_input_actors
  299.  * @desc (v1.02a+)Sets the maximum number of inputable actors that can proceed
  300.  *       inputting actions without any of them actually starting to charge
  301.  *       or execute any inputted ones as max_linked_input_actors
  302.  *       max_linked_input_actors should return the same value during the
  303.  *       same battle
  304.  *       Setting max_linked_input_actors as negative will disable this feature
  305.  *       This feature doesn't work well with any inputable actor having Action
  306.  *       Times +
  307.  *       Disabling this feature for available wait_cond_code is recommended
  308.  * @default -1
  309.  *
  310.  * @param no_prior_actor
  311.  * @desc (v1.03a+)Sets the previous command that would go to the previous(in
  312.  *       terms of party member index) inputable actor to go to the party command
  313.  *       window instead
  314.  *       Enabling this feature's recommended only with the hotkey addon
  315.  * @default false
  316.  *
  317.  * @param show_atb_bars
  318.  * @desc Sets the actor atb bars to be shown on the status window if
  319.  *       show_atb_bars is true
  320.  *       show_atb_bars should return the same value during the same battle to
  321.  *       ensure proper status window display
  322.  * @default true
  323.  *
  324.  * @param actor_name_w
  325.  * @desc Sets the maximum width allocated for actor name display on the status
  326.  *       window as actor_name_w
  327.  *       actor_name_w must return a positive Number
  328.  * @default 123
  329.  *
  330.  * @param actor_icon_ox
  331.  * @desc Sets the actor icon display area x offset relative to the actor name
  332.  *       display area on the status window as actor_icon_ox
  333.  *       actor_icon_ox must return a positive Number
  334.  * @default 6
  335.  *
  336.  * @param hp_bar_ox
  337.  * @desc Sets the actor hp bar display area x offset relative to the actor icon
  338.  *       display area on the status window as hp_bar_ox
  339.  *       hp_bar_ox must return a positive Number
  340.  * @default 6
  341.  *
  342.  * @param hp_bar_w
  343.  * @desc Sets the maximum width allocated for actor hp bar display on the status
  344.  *       window as hp_bar_w
  345.  *       hp_bar_w must return a positive Number
  346.  * @default 87
  347.  *
  348.  * @param mp_bar_ox
  349.  * @desc Sets the actor mp bar display area x offset relative to the actor hp
  350.  *       bar display area on the status window as mp_bar_ox
  351.  *       mp_bar_ox must return a positive Number
  352.  * @default 6
  353.  *
  354.  * @param mp_bar_w
  355.  * @desc Sets the maximum width allocated for actor mp bar display on the status
  356.  *       window as mp_bar_w
  357.  *       mp_bar_w must return a positive Number
  358.  * @default 87
  359.  *
  360.  * @param tp_bar_ox
  361.  * @desc Sets the actor tp bar display area x offset relative to the actor mp
  362.  *       bar display area on the status window as tp_bar_ox
  363.  *       tp_bar_ox must return a positive Number
  364.  * @default 6
  365.  *
  366.  * @param tp_bar_w
  367.  * @desc Sets the maximum width allocated for actor tp bar display on the status
  368.  *       window as tp_bar_w
  369.  *       tp_bar_w must return a positive Number
  370.  * @default 87
  371.  *
  372.  * @param atb_bar_ox
  373.  * @desc Sets the actor atb bar display area x offset relative to the actor
  374.  *       mp/tp bar display area on the status window as atb_bar_ox
  375.  *       atb_bar_ox must return a positive Number
  376.  * @default 6
  377.  *
  378.  * @param atb_bar_w
  379.  * @desc Sets the maximum width allocated for actor atb bar display on the
  380.  *       status window as atb_bar_w
  381.  *       atb_bar_w must return a positive Number
  382.  * @default 87
  383.  *
  384.  * @param atb_c1
  385.  * @desc Sets the 1st atb bar color as text color atb_c1
  386.  *       atb_c1 must return a valid text color code
  387.  *       atb_c1 should return the same value during the same battle to ensure
  388.  *       proper atb bar color displays
  389.  * @default 7
  390.  *
  391.  * @param atb_c2
  392.  * @desc Sets the 2nd atb bar color as text color atb_c2
  393.  *       atb_c2 must return a valid text color code
  394.  *       atb_c2 should return the same value during the same battle to ensure
  395.  *       proper atb bar color displays
  396.  * @default 8
  397.  *
  398.  * @param atb_overlay_c1
  399.  * @desc Sets the 1st atb bar overlay color as text color atb_overlay_c1
  400.  *       It'll only be used with atb value above max_atb_val
  401.  *       atb_overlay_c1 must return a valid text color code
  402.  *       atb_overlay_c1 should return the same value during the same battle to
  403.  *       ensure proper atb bar color displays
  404.  * @default 19
  405.  *
  406.  * @param atb_overlay_c2
  407.  * @desc Sets the 2nd atb bar overlay color as text color atb_overlay_c2
  408.  *       It'll only be used with atb value above max_atb_val
  409.  *       atb_overlay_c2 must return a valid text color code
  410.  *       atb_overlay_c2 should return the same value during the same battle to
  411.  *       ensure proper atb bar color displays
  412.  * @default 26
  413.  *
  414.  * @param atb_bar_text
  415.  * @desc Sets the atb bar description text as atb_bar_text
  416.  *       atb_bar_text should return the same value during the same battle to
  417.  *       ensure proper atb bar text displays
  418.  * @default AP
  419.  *
  420.  * @help
  421.  * The default plugin file name is DoubleX RMMV Popularized ATB Core v104a
  422.  * If you want to change that, you must edit the value of
  423.  * DoubleX_RMMV.PATB_Core_File, which must be done via opening this plugin js
  424.  * file directly
  425.  *============================================================================
  426.  *    ## Notetag Info
  427.  *----------------------------------------------------------------------------
  428.  *    # Actor/Class/Weapon/Armor/Enemy/State Notetags:
  429.  *      State notetags take the highest priority, followed by enemy, weapon,
  430.  *      armor, class and actor
  431.  *      1. <operator max patb val: val>
  432.  *         - Assigns val to the battler's maximum atb value via operator
  433.  *         - operator can be either =, +, -, *, / or %, meaning set to, add
  434.  *           by, subtract by, multiply by, divide by or modulo by respectively
  435.  *         - All instances of this notetag will be used sequentially
  436.  *         - The final max atb_value must be at least 10000 times larger than
  437.  *           2 ^ -52
  438.  *      2. <patb colors: text color 1, text color 2>
  439.  *         - Changes the atb bar color 1 and 2 to text color 1 and 2
  440.  *           respectively when this notetag's used
  441.  *         - The 1st notetag that's being read by the battler will be used
  442.  *      3. <patb overlay colors: text color 1, text color 2>
  443.  *         - Changes the atb overlay color 1 and 2 to text color 1 and 2
  444.  *           respectively when this notetag's used
  445.  *         - The 1st notetag that's being read by the battler will be used
  446.  *============================================================================
  447.  *    ## Plugin Call Info
  448.  *----------------------------------------------------------------------------
  449.  *    # Configuration manipulations
  450.  *      1. $gameSystem.patb.param
  451.  *         - Returns the value of param listed in the plugin manager
  452.  *      2. $gameSystem.patb.param = val
  453.  *         - Sets the value of param listed in the plugin manager as val
  454.  *         - All $gameSystem.patb.param changes will be saved
  455.  *      3. $gameSystem.is_patb()
  456.  *         - Returns if battle_system_code returns an available code
  457.  *      4. $gameSystem.max_patb_turn_unit(unit)
  458.  *         - Returns the maximum global battle turn counter with unit as unit
  459.  *    # Data actor/class/weapon/armor/enemy/state manipulations
  460.  *      1. meta.max_patb_val
  461.  *         - Returns the maximum atb value with the operator stored in
  462.  *           <operator max patb val: val> in the form of [opeartor, val]
  463.  *      2. meta.max_patb_val = [opeartor, val]
  464.  *         - Sets the maximum atb value with the operator stored in
  465.  *           <operator max patb val: val> as string operator and Number val
  466.  *         - The final max atb value must be at least 10000 times larger than
  467.  *           2 ^ -52
  468.  *         - All meta.max_patb_val changes can be saved if
  469.  *           DoubleX RMMV Dynamic Data is used
  470.  *      3. meta.patb_colors
  471.  *         - Returns the text colors stored in
  472.  *           <patb colors: text color 1, text color 2> in the form of
  473.  *           [text color 1, text color 2]
  474.  *      4. meta.patb_colors = [text color 1, text color 2]
  475.  *         - Sets the text colors stored in
  476.  *           <patb colors: text color 1, text color 2> as text color 1 and 2
  477.  *         - All meta.patb_colors changes can be saved if
  478.  *           DoubleX RMMV Dynamic Data is used
  479.  *      5. meta.patb_overlay_colors
  480.  *         - Returns the text colors stored in
  481.  *           <patb overlay colors: text color 1, text color 2> in the form of
  482.  *           [text color 1, text color 2]
  483.  *      6. meta.patb_overlay_colors = [text color 1, text color 2]
  484.  *         - Sets the text colors stored in
  485.  *           <patb overlay colors: text color 1, text color 2> as text color 1
  486.  *           and 2
  487.  *         - All meta.patb_overlay_colors changes can be saved if
  488.  *           DoubleX RMMV Dynamic Data is used
  489.  *    # Battler manipulations
  490.  *      1. max_patb_val
  491.  *         - Returns the battler's maximum atb value for all atb types
  492.  *      2. max_patb_val = val
  493.  *         - Sets the battler's maximum atb value for all atb types as val
  494.  *         - It'll be reevaluated if it can be changed without plugin calls
  495.  *      3. patb_val.atb
  496.  *         - Returns the battler's atb value
  497.  *      4. patb_val.atb = val
  498.  *         - Set the battler's atb value as val
  499.  *      5. patb_rate.atb
  500.  *         - Returns the battler's atb rate
  501.  *      6. patb_rate.atb = rate
  502.  *         - Set the battler's atb rate as rate
  503.  *         - It'll be reevaluated if it can be changed without plugin calls
  504.  *      7. patb_val_change.atb = true
  505.  *         - Notifies that the atb value's changed
  506.  *         - It must be used right after the atb bar length changed
  507.  *      8. patb_note_change.note = true
  508.  *         - Notifies that the values of at least 1 notetag instance of
  509.  *           notetag note or the corresponding configuration value has changed
  510.  *         - Note can be max_atb_val, atb_color or atb_overlay_color,
  511.  *           referring to <operator max patb val: val>,
  512.  *           <patb colors: text color 1, text color 2>, and
  513.  *           <patb overlay colors: text color 1, text color 2> respectively
  514.  *      9. clear_patb()
  515.  *          - Same as calling reset_patb_val() and reset_patb()
  516.  *      10. reset_patb_val()
  517.  *          - Resets the battler's atb value to the maximum atb value in delay
  518.  *            fill mode and 0 if otherwise
  519.  *      11. reset_patb()
  520.  *          - Clears all battler's actions
  521.  *      12. patb_type()
  522.  *          - Returns the current atb type, which can be either atb, charge or
  523.  *            cooldown
  524.  *          - charge and cooldown will be available when corresponding addons
  525.  *            are used as well
  526.  *      13. patb_colors(type)
  527.  *          - Returns the text colors of the atb bars of type type, which can
  528.  *            be either atb, charge or cooldown
  529.  *          - The overlay colors will be returned instead if the atb value of
  530.  *            type type is greater than max_atb_val
  531.  *          - charge and cooldown will be available when corresponding addons
  532.  *            are used as well
  533.  *    # Battle manipulations
  534.  *      1. BattleManager.patb_turn_clock
  535.  *         - Returns the current global battle turn clock with both second and
  536.  *           action units in the form of { act: act, sec: sec }
  537.  *         - sec is stored with the number of frames as the unit
  538.  *         - The fps is assumed to be always 60
  539.  *      2. BattleManager.patb_turn_clock.act = act
  540.  *         - Sets the current global battle turn clock with action unit as act
  541.  *      3. BattleManager.patb_turn_clock.sec = sec
  542.  *         - Sets the current global battle turn clock with second unit as sec
  543.  *         - sec is stored with the number of frames as the unit
  544.  *         - The fps is assumed to be always 60
  545.  *      4. BattleManager.patb_base
  546.  *         - Returns the global base atb rate
  547.  *      5. BattleManager.need_patb_refresh = true
  548.  *         - Indicates that at least 1 battler has refreshed
  549.  *         - All windows will be refreshed and the sum of all battler's agi
  550.  *           will be reevaluated
  551.  *============================================================================
  552.  */
  553.  
  554. "use strict";
  555. var DoubleX_RMMV = DoubleX_RMMV || {};
  556. DoubleX_RMMV["PATB Core"] = "v1.04a";
  557.  
  558. // The plugin file name must be the same as DoubleX_RMMV.PATB_Core_File
  559. DoubleX_RMMV.PATB_Core_File = "DoubleX RMMV Popularized ATB Core v104a";
  560.  
  561. /*============================================================================
  562.  *    ## Plugin Implementations
  563.  *       You need not edit this part as it's about how this plugin works
  564.  *----------------------------------------------------------------------------
  565.  *    # Plugin Support Info:
  566.  *      1. Prerequisites
  567.  *         - Basic knowledge of this plugin on the user level, the default
  568.  *           battle system implementations and the atb system concepts
  569.  *         - Some Javascript coding proficiency to fully comprehend this
  570.  *           plugin
  571.  *      2. Function documentation
  572.  *         - The 1st part describes why this function's rewritten/extended for
  573.  *           rewritten/extended functions or what the function does for new
  574.  *           functions
  575.  *         - The 2nd part describes what the arguments of the function are
  576.  *         - The 3rd part informs which version rewritten, extended or created
  577.  *           this function
  578.  *         - The 4th part informs whether the function's rewritten or new
  579.  *         - The 5th part informs whether the function's a real or potential
  580.  *           hotspot
  581.  *         - The 6th part describes how this function works for new functions
  582.  *           only, and describes the parts added, removed or rewritten for
  583.  *           rewritten or extended functions only
  584.  *         Example:
  585.  * /*----------------------------------------------------------------------
  586.  *  *    Why rewrite/extended/What this function does
  587.  *  *----------------------------------------------------------------------*/
  588. /* // arguments: What these arguments are
  589.  * function_name = function(arguments) { // Version X+; Rewrite/New; Hotspot
  590.  *     // Added/Removed/Rewritten to do something/How this function works
  591.  *     function_name_code;
  592.  *     //
  593.  * } // function_name
  594.  *----------------------------------------------------------------------------*/
  595.  
  596. DoubleX_RMMV.Is_PATB_Notes_Loaded = false; // v1.01f+
  597.  
  598. /*----------------------------------------------------------------------------
  599.  *    # Edit class: DataManager
  600.  *----------------------------------------------------------------------------*/
  601.  
  602. DataManager.isDatabaseLoadedPatb = DataManager.isDatabaseLoaded;
  603. DataManager.isDatabaseLoaded = function() {
  604.     // Rewritten
  605.     return this.isDatabaseLoadedPatb() && this.load_all_patb_notes();
  606.     //
  607. }; // DataManager.isDatabaseLoaded
  608.  
  609. DataManager.load_all_patb_notes = function() { // v0.00b+; New
  610.     // Prevents loading PATB notetags more than once per game execution
  611.     if (DoubleX_RMMV.Is_PATB_Notes_Loaded) { return true; }
  612.     var types = [$dataActors, $dataClasses, $dataWeapons, $dataArmors];
  613.     types.concat([$dataEnemies, $dataStates]).forEach(function(type) {
  614.         type.forEach(function(data) {
  615.             if (data) { this.load_patb_data_notes(data); }
  616.         }, this);
  617.     }, this);
  618.     DoubleX_RMMV.Is_PATB_Notes_Loaded = true;
  619.     return true;
  620.     //
  621. }; // DataManager.load_all_patb_notes
  622.  
  623. // data: The data to have its notetags read
  624. DataManager.load_patb_data_notes = function(data) { // v0.00b+; New
  625.     var color = /< *patb +colors *: *(\d+) *, *(\d+) *>/i;
  626.     var overlay = /< *patb +overlay +colors *: *(\d+) *, *(\d+) *>/i;
  627.     var max = /< *(.+) +max +patb +val *: *(\d+) *>/i, meta = data.meta;
  628.     meta.max_patb_val = [];
  629.     data.note.split(/[\r\n]+/).forEach(function(line) {
  630.         if (!meta.patb_colors && line.match(color)) {
  631.             meta.patb_colors = [+RegExp.$1, +RegExp.$2];
  632.         } else if (!meta.patb_overlay_colors && line.match(overlay)) {
  633.             meta.patb_overlay_colors = [+RegExp.$1, +RegExp.$2];
  634.         } else if (line.match(max)) {
  635.             meta.max_patb_val.push([RegExp.$1, +RegExp.$2]);
  636.         }
  637.     });
  638. }; // DataManager.load_patb_data_notes
  639.  
  640. /*----------------------------------------------------------------------------
  641.  *    # Edit class: SceneManager
  642.  *----------------------------------------------------------------------------*/
  643.  
  644. /*----------------------------------------------------------------------------
  645.  *    New public instance variable
  646.  *----------------------------------------------------------------------------*/
  647. // Read by BattleManager to close all windows on battle scene upon battle end
  648. Object.defineProperty(SceneManager, "scene", {
  649.     get: function() { return this._scene; },
  650.     configurable: true
  651. });
  652.  
  653. /*----------------------------------------------------------------------------
  654.  *    # Edit class: BattleManager
  655.  *      - Reimplements the the whole battle flow to run the atb system
  656.  *----------------------------------------------------------------------------*/
  657.  
  658. /*----------------------------------------------------------------------------
  659.  *    New public instance variables
  660.  *----------------------------------------------------------------------------*/
  661. Object.defineProperties(BattleManager, {
  662.     // The global base atb rate
  663.     "patb_base": { get: function() { // Hotspot
  664.         return this._patb_base;
  665.     }, configurable: true },
  666.     // The global base atb rate change flag for battler atb rate
  667.     "patb_base_change": { get: function() { // Hotspot
  668.         return this._patb_base_change;
  669.     }, configurable: true },
  670.     // Read by Scene_Battle to check for update action executions
  671.     "phase": { get: function() { // Hotspot
  672.         return this._phase;
  673.     }, configurable: true },
  674.     // Read by Game_Battler and Scene_Battle to mark all actable battlers
  675.     "action_battlers": { get: function() { // Hotspot
  676.         return this._actionBattlers;
  677.     }, configurable: true },
  678.     // (v0.00b+)The battler refresh flag for refreshing agi sum and windows
  679.     "need_patb_refresh": { get: function() { // Hotspot
  680.         return this._need_patb_refresh;
  681.     }, set: function(refresh) { // Hotspot
  682.         this._need_patb_refresh = refresh;
  683.     }, configurable: true },
  684.     // (v0.00d+)The battle turn atb clock with all units
  685.     "patb_turn_clock": { get: function() { // Potential Hotspot
  686.         return this._patb_turn_clock;
  687.     }, configurable: true }
  688. });
  689.  
  690. /*----------------------------------------------------------------------------
  691.  *    New private instance variables
  692.  *----------------------------------------------------------------------------*/
  693. /* _is_halt_patb_input: Whether inputable actors can't input actions by players
  694.  * _patb_agi_sum: The sum of agi of all alive battlers
  695.  * _patb_input_actors_count: The number of actors inputting consecutively
  696.  */
  697.  
  698. BattleManager.initMembersPatb = BattleManager.initMembers;
  699. BattleManager.initMembers = function() {
  700.     this.initMembersPatb();
  701.     if ($gameSystem.is_patb()) { this.init_patb(); } // Added
  702. }; // BattleManager.initMembers
  703.  
  704. /*----------------------------------------------------------------------------
  705.  *    Keeps the appropriate input window opened if there are inputable actors
  706.  *----------------------------------------------------------------------------*/
  707. BattleManager.isInputtingPatb = BattleManager.isInputting;
  708. BattleManager.isInputting = function() { // Hotspot
  709.     if ($gameSystem.is_patb()) { return $gameParty.canInput(); } // Added
  710.     return this.isInputtingPatb();
  711. }; // BattleManager.isInputting
  712.  
  713. /*----------------------------------------------------------------------------
  714.  *    Disables party escape command when the global atb frame can update
  715.  *----------------------------------------------------------------------------*/
  716. BattleManager.canEscapePatb = BattleManager.canEscape;
  717. BattleManager.canEscape = function() { // v1.03d+
  718.     if (!this.canEscapePatb()) { return false; }
  719.     // Added
  720.     return !$gameSystem.is_patb() || this.can_patb_esc();
  721.     //
  722. }; // BattleManager.canEscapePatb
  723.  
  724. /*----------------------------------------------------------------------------
  725.  *    Sets the starting atb value for all battlers as well
  726.  *----------------------------------------------------------------------------*/
  727. BattleManager.startBattlePatb = BattleManager.startBattle;
  728. BattleManager.startBattle = function() {
  729.     this.startBattlePatb();
  730.     if ($gameSystem.is_patb()) { this.start_patb_battle(); } // Added
  731. }; // BattleManager.startBattle
  732.  
  733. BattleManager.selectNextCommandPatb = BattleManager.selectNextCommand;
  734. BattleManager.selectNextCommand = function() { // v1.01f+
  735.     if ($gameSystem.is_patb()) { this.select_next_patb_command(); } // Added
  736.     this.selectNextCommandPatb();
  737. }; // BattleManager.selectNextCommand
  738.  
  739. BattleManager.selectPreviousCommandPatb = BattleManager.selectPreviousCommand;
  740. BattleManager.selectPreviousCommand = function() { // v1.03a+
  741.     // Added
  742.     if ($gameSystem.is_patb() && $gameSystem.patb.no_prior_actor) {
  743.         return this.select_previous_patb_command();
  744.     }
  745.     //
  746.     this.selectPreviousCommandPatb();
  747. }; // BattleManager.selectPreviousCommand
  748.  
  749. BattleManager.refreshStatusPatb = BattleManager.refreshStatus;
  750. BattleManager.refreshStatus = function() { // v0.00e+
  751.     // Added to refresh all visible input windows as well
  752.     this.process_patb_scene("refresh_patb_windows");
  753.     //
  754.     this.refreshStatusPatb();
  755. }; // BattleManager.refreshStatus
  756.  
  757. /*----------------------------------------------------------------------------
  758.  *    Abandons the default battle system phase transitions
  759.  *----------------------------------------------------------------------------*/
  760. BattleManager.startTurnPatb = BattleManager.startTurn;
  761. BattleManager.startTurn = function() {
  762.     if (!$gameSystem.is_patb()) { this.startTurnPatb(); } // Rewritten
  763. }; // BattleManager.startTurn
  764.  
  765. BattleManager.processVictoryPatb = BattleManager.processVictory;
  766. BattleManager.processVictory = function() {
  767.     // Added to close all active input windows as well
  768.     this.process_patb_scene("close_patb_windows");
  769.     //
  770.     this.processVictoryPatb();
  771. }; // BattleManager.processVictory
  772.  
  773. BattleManager.processDefeatPatb = BattleManager.processDefeat;
  774. BattleManager.processDefeat = function() {
  775.     // Added to close all active input windows as well
  776.     this.process_patb_scene("close_patb_windows");
  777.     //
  778.     this.processDefeatPatb();
  779. }; // BattleManager.processDefeat
  780.  
  781. BattleManager.endActionPatb = BattleManager.endAction;
  782. BattleManager.endAction = function() {
  783.     this.endActionPatb();
  784.     // Added
  785.     if ($gameSystem.is_patb() && $gameSystem.patb.turn_unit_code === "act") {
  786.         this.update_patb_turn("act");
  787.     }
  788.     //
  789. }; // BattleManager.endAction
  790.  
  791. /*----------------------------------------------------------------------------
  792.  *    Abandons the default battle system action execution subject FIFO queue
  793.  *----------------------------------------------------------------------------*/
  794. BattleManager.getNextSubjectPatb = BattleManager.getNextSubject;
  795. BattleManager.getNextSubject = function() {
  796.     // Rewritten
  797.     return $gameSystem.is_patb() ? null : this.getNextSubjectPatb();
  798.     //
  799. }; // BattleManager.getNextSubject
  800.  
  801. BattleManager.init_patb = function() { // v1.00b+; New
  802.     this._patb_turn_clock = { act: 0, sec: 0 }, this._patb_agi_sum = null;
  803.     this._patb_input_actors_count = 0;
  804. }; // BattleManager.init_patb
  805.  
  806. BattleManager.start_patb_battle = function() { // New
  807.     this._phase = 'turn';
  808.     var s = this._preemptive ? "preempt" : this._surprise ? "surprise" : "norm";
  809.     $gameParty.set_start_patb_val(s);
  810.     $gameTroop.set_start_patb_val(s);
  811. }; // BattleManager.start_patb_battle
  812.  
  813. /*----------------------------------------------------------------------------
  814.  *    Checks if the atb frame update or the action execution can be processed
  815.  *----------------------------------------------------------------------------*/
  816. BattleManager.can_update_patb_process = function() { // v1.00a+; New; Hotspot
  817.     if (this.isAborting() || this.isBattleEnd()) {
  818.         this.update();
  819.         return false;
  820.     }
  821.     return !$gameMessage.isBusy() && !this.updateEvent();
  822. }; // BattleManager.can_update_patb_process
  823.  
  824. /*----------------------------------------------------------------------------
  825.  *    Updates the current action when finished execution on the current target
  826.  *----------------------------------------------------------------------------*/
  827. BattleManager.update_patb_process = function() { // v1.00a+; New; Hotspot
  828.     if (this._phase === 'action' && !this.isBusy()) { this.updateAction(); }
  829. }; // BattleManager.update_patb_process
  830.  
  831. /*----------------------------------------------------------------------------
  832.  *    Checks if cases always stopping the global atb frame update aren't met
  833.  *----------------------------------------------------------------------------*/
  834. BattleManager.can_update_patb = function() { // New; Hotspot
  835.     return this._phase && this._phase !== 'init';
  836. }; // BattleManager.can_update_patb
  837.  
  838. /*----------------------------------------------------------------------------
  839.  *    Runs the global and battler atb clocks and sets action execution subject
  840.  *----------------------------------------------------------------------------*/
  841. BattleManager.update_patb = function() { // New; Hotspot
  842.     this.set_patb_base();
  843.     $gameParty.update_patb();
  844.     $gameTroop.update_patb();
  845.     this.update_patb_auto_battle();
  846.     if (this._phase !== 'action') { this.process_patb_turn(); }
  847.     if ($gameSystem.patb.turn_unit_code !== "sec") { return; }
  848.     this.update_patb_turn("sec");
  849. }; // BattleManager.update_patb
  850.  
  851. /*----------------------------------------------------------------------------
  852.  *    Sets the global base atb rate
  853.  *----------------------------------------------------------------------------*/
  854. BattleManager.set_patb_base = function() { // New; Hotspot
  855.     var last_base = this._patb_base;
  856.     // Fps's assumed to be always 60
  857.     this._patb_base = $gameSystem.patb.base_fill_time * 60;
  858.     //
  859.     if ($gameSystem.patb.atb_rate_code !== "agi") {
  860.         this._patb_base *= this.patb_avg_agi();
  861.     }
  862.     this._patb_base_change = last_base !== this._patb_base;
  863. }; // BattleManager.set_patb_base
  864.  
  865. BattleManager.patb_avg_agi = function() { // New; Hotspot
  866.     if (this._patb_agi_sum) {
  867.         if ($gameSystem.patb.atb_rate_code === "avg_agi") {
  868.             return this._patb_agi_sum;
  869.         }
  870.         // Returns the cached average agi unless it can be changed
  871.         if (!this._need_patb_refresh) { return this._patb_agi_sum; }
  872.         //
  873.     }
  874.     this.set_patb_avg_agi();
  875.     return this._patb_agi_sum;
  876. }; // BattleManager.patb_avg_agi
  877.  
  878. BattleManager.set_patb_avg_agi = function() { // v0.00e+; New; Potential Hotspot
  879.     var mems = $gameParty.aliveMembers().concat($gameTroop.aliveMembers());
  880.     this._patb_agi_sum = mems.reduce(function(sum, mem) {
  881.         return sum + mem.agi;
  882.     }, 0) / mems.length;
  883. }; // BattleManager.set_patb_avg_agi
  884.  
  885. /*----------------------------------------------------------------------------
  886.  *    Ensures inputable battler becoming autobattle will make autobattle acts
  887.  *----------------------------------------------------------------------------*/
  888. BattleManager.update_patb_auto_battle = function() { // v1.00b+; New; Hotspot
  889.     var reset = $gameSystem.patb.atb_reset_code !== "clear";
  890.     this._actionBattlers.forEach(function(battler) {
  891.         if (!battler.isAutoBattle() || !battler.can_input_patb()) { return; }
  892.         if (reset) { battler.reset_patb_val(); }
  893.         battler.reset_patb();
  894.     });
  895. }; // BattleManager.update_patb_auto_battle
  896.  
  897. /*----------------------------------------------------------------------------
  898.  *    Finds the 1st battler in the actable battler list that can cast actions
  899.  *----------------------------------------------------------------------------*/
  900. BattleManager.process_patb_turn = function() { // New; Hotspot
  901.     this._subject = this._subject || this._actionBattlers.filter(function(b) {
  902.         return b.can_patb_act();
  903.     })[0];
  904.     if (this._subject) { this.processTurn(); }
  905. }; // BattleManager.process_patb_turn
  906.  
  907. /*----------------------------------------------------------------------------
  908.  *    Runs the global battle turn clock
  909.  *----------------------------------------------------------------------------*/
  910. // unit: The battle turn counter unit
  911. BattleManager.update_patb_turn = function(unit) { // New; Hotspot
  912.     this._patb_turn_clock[unit] += 1;
  913.     // Loosens the coupling among the core and turn plugins
  914.     if (this._patb_turn_clock[unit] >= $gameSystem.max_patb_turn_unit(unit)) {
  915.         this._patb_turn_clock[unit] = 0;
  916.         this.end_patb_turn();
  917.     }
  918.     //
  919. }; // BattleManager.update_patb_turn
  920.  
  921. BattleManager.end_patb_turn = function() { // New
  922.     var mems = $gameParty.battleMembers().concat($gameTroop.members());
  923.     mems.forEach(function(mem) {
  924.         mem.onTurnEnd();
  925.         this.refreshStatus();
  926.         this._logWindow.displayAutoAffectedStatus(mem);
  927.         this._logWindow.displayRegeneration(mem);
  928.     }, this);
  929.     $gameTroop.increaseTurn();
  930. }; // BattleManager.end_patb_turn
  931.  
  932. BattleManager.can_patb_esc = function() { // v1.00a+; New
  933.     // Ensures party escape attempt won't trigger when the battle's busy
  934.     if (!this._spriteset || !this._logWindow || this.isBusy()) { return false; }
  935.     return this._phase && this._phase !== 'init' && this._phase !== 'action';
  936.     //
  937. }; // BattleManager.can_patb_esc
  938.  
  939. /*----------------------------------------------------------------------------
  940.  *    Helper function for calling Scene_Battle functions
  941.  *----------------------------------------------------------------------------*/
  942. // func: The function in Scene_Battle to be called
  943. BattleManager.process_patb_scene = function(func) { // v1.01c+; New
  944.     if (!$gameSystem.is_patb() || !$gameParty.inBattle()) { return; }
  945.     SceneManager.scene[func]();
  946. }; // BattleManager.process_patb_windows
  947.  
  948. // battler: The battler to be makred as actable
  949. BattleManager.add_patb_action_battler = function(battler) { // v1.01e+; New
  950.     if (this._actionBattlers.indexOf(battler) >= 0) { return; }
  951.     this._actionBattlers.push(battler);
  952.     battler.makeActionsPatb();
  953. }; // BattleManager.add_patb_action_battler
  954.  
  955. // battler: The battler to be makred as unactable
  956. BattleManager.remove_patb_action_battler = function(battler) { // v1.01e+; New
  957.     var index = this._actionBattlers.indexOf(battler);
  958.     if (index >= 0) { this._actionBattlers.splice(index, 1); }
  959.     if (this.actor() === battler) { this.clearActor(); }
  960. }; // BattleManager.remove_patb_action_battler
  961.  
  962. BattleManager.inputable_patb_actor_indices = function() {
  963. // v1.01e+; New; Hotspot
  964.     // Ensures subject won't stop inputted actor from executing acts immediately
  965.     if (this._is_halt_patb_input) {
  966.         if (!this.can_patb_esc()) { return []; }
  967.         this._is_halt_patb_input = false;
  968.     }
  969.     //
  970.     return this._actionBattlers.filter(function(battler) {
  971.         return battler.canInput();
  972.     }).map(function(battler) { return battler.index(); });
  973. }; // BattleManager.inputable_patb_actor_indices
  974.  
  975. BattleManager.select_next_patb_command = function() { // v1.02a+; New
  976.     var actor = this.actor();
  977.     if (!actor) { return; }
  978.     actor.confirm_patb_act();
  979.     if (actor.can_input_patb()) { return; }
  980.     this._patb_input_actors_count += 1;
  981.     var max_linked_input_actors = $gameSystem.patb.max_linked_input_actors;
  982.     if (max_linked_input_actors < 0) { return; }
  983.     if (this._patb_input_actors_count <= max_linked_input_actors) { return; }
  984.     this._patb_input_actors_count = 0;
  985.     this._is_halt_patb_input = true;
  986.     this.changeActor($gameParty.size(), 'waiting');
  987. }; // BattleManager.select_next_patb_command
  988.  
  989. BattleManager.select_previous_patb_command = function() { // v1.03a+; New
  990.     if (this.actor() && this.actor().selectPreviousCommand()) { return; }
  991.     this.clearActor();
  992. }; // BattleManager.select_previous_patb_command
  993.  
  994. /*----------------------------------------------------------------------------
  995.  *    # Edit class: Game_System
  996.  *      - Stores the values of all configurations listed in the plugin manager
  997.  *----------------------------------------------------------------------------*/
  998.  
  999. /*----------------------------------------------------------------------------
  1000.  *    New public instance variable
  1001.  *----------------------------------------------------------------------------*/
  1002. // The storage of all configuration values
  1003. Object.defineProperty(Game_System.prototype, "patb", {
  1004.     get: function() { /* Hotspot */ return this._patb; },
  1005.     configurable: true
  1006. });
  1007.  
  1008. Game_System.prototype.initializePatb = Game_System.prototype.initialize;
  1009. Game_System.prototype.initialize = function() {
  1010.     this.initializePatb();
  1011.     this.init_patb_params(); // Added
  1012. }; // Game_System.prototype.initialize
  1013.  
  1014. Game_System.prototype.init_patb_params = function() { // New
  1015.     var val, params = PluginManager.parameters(DoubleX_RMMV.PATB_Core_File);
  1016.     this._patb = {};
  1017.     Object.keys(params).forEach(function(param) {
  1018.         val = params[param].length > 0 ? +params[param] : params[param];
  1019.         this._patb[param] = isNaN(val) ? params[param] : val;
  1020.     }, this);
  1021.     this._patb.no_prior_actor = params.no_prior_actor === "true";
  1022.     this._patb.show_atb_bars = params.show_atb_bars === "true";
  1023.     this._patb.wait_party_cmd = params.wait_party_cmd === "true";
  1024. }; // Game_System.prototype.init_patb_params
  1025.  
  1026. Game_System.prototype.is_patb = function() { // New; Hotspot
  1027.     // Loosens the coupling among the core and ctb plugins
  1028.     return this._patb.battle_system_code === "atb";
  1029.     //
  1030. }; // Game_System.prototype.is_patb
  1031.  
  1032. /*----------------------------------------------------------------------------
  1033.  *    Loosen the coupling among the core and turn plugins
  1034.  *----------------------------------------------------------------------------*/
  1035. // unit: The battle turn counter unit
  1036. Game_System.prototype.max_patb_turn_unit = function(unit) {
  1037. // v0.00c+; New; Hotspot
  1038.     // Fps's assumed to be always 60
  1039.     if (unit === "sec") { return this._patb.max_turn_unit * 60; }
  1040.     //
  1041.     return this._patb.max_turn_unit;
  1042. }; // Game_System.prototype.max_patb_turn_unit
  1043.  
  1044. /*----------------------------------------------------------------------------
  1045.  *    # Edit class: Game_Action
  1046.  *----------------------------------------------------------------------------*/
  1047.  
  1048. /*----------------------------------------------------------------------------
  1049.  *    New public instance variable
  1050.  *----------------------------------------------------------------------------*/
  1051. // The action's confirmation flag for actor action inputability check
  1052. Object.defineProperty(Game_Action.prototype, "patb_confirm", {
  1053.     get: function() { /* Hotspot */ return this._patb_confirm; },
  1054.     set: function(confirm) { this._patb_confirm = confirm; },
  1055.     configurable: true
  1056. });
  1057.  
  1058. /*----------------------------------------------------------------------------
  1059.  *    # Edit class: Game_BattlerBase
  1060.  *----------------------------------------------------------------------------*/
  1061.  
  1062. /*----------------------------------------------------------------------------
  1063.  *    Updates state turns with different removal timings at different timings
  1064.  *----------------------------------------------------------------------------*/
  1065. Game_BattlerBase.prototype.updateStateTurnsPatb =
  1066. Game_BattlerBase.prototype.updateStateTurns;
  1067. Game_BattlerBase.prototype.updateStateTurns = function() {
  1068.     // Added
  1069.     if ($gameSystem.is_patb()) { return this.update_patb_state_turns(2); }
  1070.     //
  1071.     this.updateStateTurnsPatb();
  1072. }; // Game_BattlerBase.prototype.updateStateTurns
  1073.  
  1074. Game_BattlerBase.prototype.hidePatb = Game_BattlerBase.prototype.hide;
  1075. Game_BattlerBase.prototype.hide = function() {
  1076.     this.hidePatb();
  1077.     // Added to ensure hidden battlers won't be able to execute or input actions
  1078.     if ($gameSystem.is_patb()) { this.clear_patb(); }
  1079.     //
  1080. }; // Game_BattlerBase.prototype.hide
  1081.  
  1082. Game_BattlerBase.prototype.canInputPatb = Game_BattlerBase.prototype.canInput;
  1083. Game_BattlerBase.prototype.canInput = function() { // Hotspot
  1084.     // Rewritten
  1085.     if (!this.canInputPatb()) { return false; }
  1086.     return !$gameSystem.is_patb() || this.can_input_patb();
  1087.     //
  1088. }; // Game_BattlerBase.prototype.canInput
  1089.  
  1090. // start: The battle start type
  1091. Game_BattlerBase.prototype.set_start_patb_val = function(start) { // New
  1092.     // Loosens the coupling among the core and start plugins
  1093.     this["set_start_patb_val_" + start]();
  1094.     //
  1095. }; // Game_BattlerBase.prototype.set_start_patb_val
  1096.  
  1097. /*----------------------------------------------------------------------------
  1098.  *    Ensures this plugin still works for battlers not being actor nor enemy
  1099.  *----------------------------------------------------------------------------*/
  1100. Game_BattlerBase.prototype.set_start_patb_val_preempt = function() {
  1101. // v1.01b+; New
  1102.     // Ensures this plugin still works for battler not being actor nor enemy
  1103.     this.set_start_patb_val_norm();
  1104.     //
  1105. }; // Game_BattlerBase.prototype.set_start_patb_val_preempt
  1106.  
  1107. /*----------------------------------------------------------------------------
  1108.  *    Ensures this plugin still works for battlers not being actor nor enemy
  1109.  *----------------------------------------------------------------------------*/
  1110. Game_BattlerBase.prototype.set_start_patb_val_surprise = function() {
  1111. // v1.01b+; New
  1112.     this.set_start_patb_val_norm();
  1113. }; // Game_BattlerBase.prototype.set_start_patb_val_surprise
  1114.  
  1115. Game_BattlerBase.prototype.set_start_patb_val_norm = function() {
  1116. // v1.01b+; New
  1117.     if ($gameSystem.patb.atb_start_code === "agi") {
  1118.         this._patb_val.atb = this._max_patb_val * this.agi / this.paramMax(6);
  1119.     } else {
  1120.         this._patb_val.atb = 0;
  1121.     }
  1122. }; // Game_BattlerBase.prototype.set_start_patb_val_norm
  1123.  
  1124. /*----------------------------------------------------------------------------
  1125.  *    # Edit class: Game_Battler
  1126.  *      - Implements the battler's atb actions, clock, control flow and logics
  1127.  *----------------------------------------------------------------------------*/
  1128.  
  1129. /*----------------------------------------------------------------------------
  1130.  *    New public instance variables
  1131.  *----------------------------------------------------------------------------*/
  1132. Object.defineProperties(Game_Battler.prototype, {
  1133.     // The maximum atb value
  1134.     "max_patb_val": { get: function() { // Hotspot
  1135.         return this._max_patb_val;
  1136.     }, set: function(val) { // Potential Hotspot
  1137.         this._max_patb_val = val;
  1138.     }, configurable: true },
  1139.     // The atb rate of all atb types
  1140.     "patb_rate": { get: function() { // Hotspot
  1141.         return this._patb_rate;
  1142.     }, configurable: true },
  1143.     // The atb values of all atb types
  1144.     "patb_val": { get: function() { // Hotspot
  1145.         return this._patb_val;
  1146.     }, configurable: true },
  1147.     // The atb value change flag of all atb types for their atb bars
  1148.     "patb_val_change": { // Hotspot
  1149.         get: function() { return this._patb_val_change; },
  1150.         set: function(change) { this._patb_val_change = change; },
  1151.         configurable: true
  1152.     },
  1153.     // The effective notetag list change flag for all notetags
  1154.     "patb_note_change": { get: function() { // Hotspot
  1155.         return this._patb_note_change;
  1156.     }, configurable: true }
  1157. });
  1158.  
  1159. /*----------------------------------------------------------------------------
  1160.  *    New private instance variables
  1161.  *----------------------------------------------------------------------------*/
  1162. /* _patb_battler_change: The effective notetag list change flag for all notetags
  1163.  * _max_patb_val_change: The maximum atb value change flag for atb rate
  1164.  * _patb_colors: The atb bar colors for all atb types
  1165.  */
  1166.  
  1167. Game_Battler.prototype.initMembersPatb = Game_Battler.prototype.initMembers;
  1168. Game_Battler.prototype.initMembers = function() {
  1169.     this.initMembersPatb();
  1170.     this.init_patb(); // Added
  1171. }; // Game_Battler.prototype.initMembers
  1172.  
  1173. Game_Battler.prototype.refreshPatb = Game_Battler.prototype.refresh;
  1174. Game_Battler.prototype.refresh = function() {
  1175.     this.refreshPatb();
  1176.     if ($gameSystem.is_patb()) { this.set_patb_refresh(); } // Added
  1177. }; // Game_Battler.prototype.refresh
  1178.  
  1179. Game_Battler.prototype.onRestrictPatb = Game_Battler.prototype.onRestrict;
  1180. Game_Battler.prototype.onRestrict = function() {
  1181.     this.onRestrictPatb();
  1182.     // Added to fix nil action battlers bugs and edge cases as well
  1183.     if (!$gameSystem.is_patb() || !BattleManager.action_battlers) { return; }
  1184.     if ($gameSystem.patb.atb_reset_code !== "clear") { this.reset_patb_val(); }
  1185.     this.reset_patb();
  1186.     //
  1187. }; // Game_Battler.prototype.onRestrict
  1188.  
  1189. /*----------------------------------------------------------------------------
  1190.  *    Marks that this battler becomes able to act as well
  1191.  *----------------------------------------------------------------------------*/
  1192. Game_Battler.prototype.makeActionsPatb = Game_Battler.prototype.makeActions;
  1193. Game_Battler.prototype.makeActions = function() {
  1194.     // Rewritten
  1195.     if (!$gameSystem.is_patb()) { return this.makeActionsPatb(); }
  1196.     BattleManager.add_patb_action_battler(this);
  1197.     //
  1198. }; // Game_Battler.prototype.makeActions
  1199.  
  1200. Game_Battler.prototype.onAllActionsEndPatb =
  1201. Game_Battler.prototype.onAllActionsEnd;
  1202. Game_Battler.prototype.onAllActionsEnd = function() {
  1203.     this.onAllActionsEndPatb();
  1204.     if ($gameSystem.is_patb()) { this.on_all_patb_acts_end(); } // Added
  1205. }; // Game_Battler.prototype.onAllActionsEnd
  1206.  
  1207. Game_Battler.prototype.onTurnEndPatb = Game_Battler.prototype.onTurnEnd;
  1208. Game_Battler.prototype.onTurnEnd = function() {
  1209.     this.onTurnEndPatb();
  1210.     if ($gameSystem.is_patb()) { this.removeBuffsAuto(); } // Added
  1211. }; // Game_Battler.prototype.onTurnEnd
  1212.  
  1213. /*----------------------------------------------------------------------------
  1214.  *    Ensures battlers added after the battle starts won't carry statuses over
  1215.  *----------------------------------------------------------------------------*/
  1216. Game_Battler.prototype.onBattleEndPatb = Game_Battler.prototype.onBattleEnd;
  1217. Game_Battler.prototype.onBattleEnd = function() {
  1218.     this.onBattleEndPatb();
  1219.     if ($gameSystem.is_patb()) { this.clear_patb(); } // Added
  1220. }; // Game_Battler.prototype.onBattleEnd
  1221.  
  1222. // start: The battle start type
  1223. Game_Battler.prototype.set_start_patb_val = function(start) { // New
  1224.     this.init_patb();
  1225.     this.update_max_patb_val();
  1226.     if (this.canMove()) {
  1227.         Game_BattlerBase.prototype.set_start_patb_val.call(this, start);
  1228.         if (this._patb_val.atb >= this._max_patb_val) { this.makeActions(); }
  1229.     } else {
  1230.         this._patb_val.atb = 0;
  1231.     }
  1232.     if ($gameSystem.patb.atb_fill_code === "delay") {
  1233.         this._patb_val.atb = this._max_patb_val - this._patb_val.atb;
  1234.     }
  1235.     this._patb_val_change.atb = true;
  1236. }; // Game_Battler.prototype.set_start_patb_val
  1237.  
  1238. Game_Battler.prototype.init_patb = function() { // New
  1239.     // Loosen the coupling among the core, charge and cooldown plugins
  1240.     this._max_patb_val = $gameSystem.patb.max_atb_val;
  1241.     this._patb_colors = { atb: [], atb_overlay: [] };
  1242.     this._patb_rate = { atb: 0 }, this._patb_val = { atb: 0 };
  1243.     this._patb_val_change = { atb: true };
  1244.     this._patb_battler_change = {
  1245.         max_patb_val: true,
  1246.         atb_color: true,
  1247.         atb_overlay_color: true
  1248.     };
  1249.     this._patb_note_change = {
  1250.         max_patb_val: true,
  1251.         atb_color: true,
  1252.         atb_overlay_color: true
  1253.     };
  1254.     //
  1255. }; // Game_Battler.prototype.init_patb
  1256.  
  1257. /*----------------------------------------------------------------------------
  1258.  *    Runs the battler atb clock
  1259.  *----------------------------------------------------------------------------*/
  1260. Game_Battler.prototype.update_patb = function() { // New; Hotspot
  1261.     this.update_max_patb_val();
  1262.     if (this.canInput()) { return; }
  1263.     // Loosens the coupling among the core, charge, cooldown and speed plugins
  1264.     if ($gameSystem.patb.atb_fill_code === "delay") {
  1265.         return this.update_patb_val(0, -1);
  1266.     }
  1267.     this.update_patb_val(this._max_patb_val, 1);
  1268.     //
  1269. }; // Game_Battler.prototype.update_patb
  1270.  
  1271. /* cap: The atb value cap stopping further atb value updates
  1272.  * sign: The atb value update direction sign
  1273.  */
  1274. Game_Battler.prototype.update_patb_val = function(cap, sign) { // New; Hotspot
  1275.     if (this._patb_val.atb * sign >= cap * sign) { return; }
  1276.     var rate = this.get_patb_rate() * sign;
  1277.     this._patb_val.atb += rate, this._patb_val_change.atb = rate !== 0;
  1278.     if (this._patb_val.atb * sign < cap * sign) { return; }
  1279.     this._patb_val.atb = cap;
  1280.     this.makeActions();
  1281. }; // Game_Battler.prototype.update_patb_val
  1282.  
  1283. /*----------------------------------------------------------------------------
  1284.  *    Reevaluates the atb rate only if any of its determinators can change
  1285.  *----------------------------------------------------------------------------*/
  1286. Game_Battler.prototype.get_patb_rate = function() { // New; Hotspot
  1287.     if ($gameSystem.patb.atb_rate_code === "abs_agi") { return this.agi; }
  1288.     if (this.can_patb_rate_change()) {
  1289.         this._patb_rate.atb = this.agi * this._max_patb_val;
  1290.         this._patb_rate.atb /= BattleManager.patb_base;
  1291.         this._max_patb_val_change = false;
  1292.         // Multiplies the difference by 100% to work with small max atb value
  1293.         if (this._patb_rate.atb < Number.EPSILON * this._max_patb_val * 100) {
  1294.             console.log("ATB rate of " + this.name() + " is too small");
  1295.         }
  1296.         //
  1297.     }
  1298.     return this._patb_rate.atb;
  1299. }; // Game_Battler.prototype.get_patb_rate
  1300.  
  1301. /*----------------------------------------------------------------------------
  1302.  *    Fixes bugs from changing battler agi without changing the base atb rate
  1303.  *----------------------------------------------------------------------------*/
  1304. Game_Battler.prototype.can_patb_rate_change = function() {
  1305. // v1.00c+; New; Hotspot
  1306.     if (this._max_patb_val_change) { return true; }
  1307.     return BattleManager.patb_base_change || BattleManager.need_patb_refresh;
  1308. }; // Game_Battler.prototype.can_patb_rate_change
  1309.  
  1310. /*----------------------------------------------------------------------------
  1311.  *    Rereads the effective max atb val notetag only if its values can change
  1312.  *----------------------------------------------------------------------------*/
  1313. Game_Battler.prototype.update_max_patb_val = function() { // New; Hotspot
  1314.     if (!this.are_patb_battler_changed("max_patb_val")) { return; }
  1315.     var f = this._patb_val.atb >= this._max_patb_val;
  1316.     var max = $gameSystem.patb.max_atb_val;
  1317.     this._max_patb_val = this.set_multi_patb_notes(max, "max_patb_val");
  1318.     // Multiplies the difference by 10000 to work with very small max atb value
  1319.     if (this._max_patb_val < Number.EPSILON * 10000) {
  1320.         console.log("Max atb value of " + this.name() + " is too small");
  1321.         this._max_patb_val = Number.EPSILON * 10000;
  1322.     }
  1323.     //
  1324.     this._max_patb_val_change = true;
  1325.     if ($gameSystem.patb.atb_fill_code !== "delay") { this.corr_patb(f); }
  1326.     this.mark_patb_val_change();
  1327. }; // Game_Battler.prototype.update_max_patb_val
  1328.  
  1329. /*----------------------------------------------------------------------------
  1330.  *    Corrects the actability and all atb values after changing max atb value
  1331.  *----------------------------------------------------------------------------*/
  1332. // full: The full atb before changing the max atb value flag
  1333. Game_Battler.prototype.corr_patb = function(full) { // New; Potential Hotspot
  1334.     if (!full && this._patb_val.atb >= this._max_patb_val) {
  1335.         this.makeActions();
  1336.     } else if (full && this._patb_val.atb < this._max_patb_val) {
  1337.         this.clear_patb();
  1338.     }
  1339.     this.cap_patb_val();
  1340. }; // Game_Battler.prototype.corr_patb
  1341.  
  1342. /*----------------------------------------------------------------------------
  1343.  *    Ensures no atb value will exceed its max
  1344.  *----------------------------------------------------------------------------*/
  1345. Game_Battler.prototype.cap_patb_val = function() {
  1346. // v1.01b+; New; Potential Hotspot
  1347.     Object.keys(this._patb_val).forEach(function(type) {
  1348.         if (this._patb_val[type] <= this._max_patb_val) { return; }
  1349.         this._patb_val[type] = this._max_patb_val;
  1350.     }, this);
  1351. }; // Game_Battler.prototype.cap_patb_val
  1352.  
  1353. /*----------------------------------------------------------------------------
  1354.  *    Notifies the atb bars to be redrawn
  1355.  *----------------------------------------------------------------------------*/
  1356. Game_Battler.prototype.mark_patb_val_change = function() {
  1357. // v1.00b+; New; Potential Hotspot
  1358.     Object.keys(this._patb_val_change).forEach(function(type) {
  1359.         this._patb_val_change[type] = true;
  1360.     }, this);
  1361. }; // Game_Battler.prototype.mark_patb_val_change
  1362.  
  1363. /* val: The configuration value as the initial notetag value
  1364.  * note: The notetag type with its values to be set
  1365.  */
  1366. Game_Battler.prototype.set_multi_patb_notes = function(val, note) {
  1367. // New; Potential Hotspot
  1368.     // Loosens the coupling among the core, delay, rate and start plugins
  1369.     this.patb_note_data().forEach(function(type) {
  1370.         type.forEach(function(data) {
  1371.             data.meta[note].forEach(function(vals) {
  1372.                 val = this.operate_patb_notes(val, vals[0], vals[1]);
  1373.             }, this);
  1374.         }, this);
  1375.     }, this);
  1376.     return val;
  1377.     //
  1378. }; // Game_Battler.prototype.set_multi_patb_notes
  1379.  
  1380. /* current: The current value to be operated
  1381.  * operator: The notetag operator
  1382.  * val: The notetag value to be operated with the current one
  1383.  */
  1384. Game_Battler.prototype.operate_patb_notes = function(current, operator, val) {
  1385. // New; Potential Hotspot
  1386.     switch (operator) {
  1387.         case "=": return val;
  1388.         case "+": return current + val;
  1389.         case "-": return current - val;
  1390.         case "*": return current * val;
  1391.         case "/": return current / val;
  1392.         case "%": return current % val;
  1393.         default:
  1394.             console.log('Invalid notetag operator: ' + operator);
  1395.             console.log('All notetags having this operator are ignored');
  1396.             return current;
  1397.     }
  1398. }; // Game_Battler.prototype.operate_patb_notes
  1399.  
  1400. /*----------------------------------------------------------------------------
  1401.  *    Rereads the effective atb color notetag only if its values can change
  1402.  *----------------------------------------------------------------------------*/
  1403. // type: The current atb type
  1404. Game_Battler.prototype.patb_colors = function(type) { // New; Hotspot
  1405.     if (this._patb_val[type] > this._max_patb_val) { type += "_overlay"; }
  1406.     if (this.are_patb_battler_changed(type + "_color")) {
  1407.         this.set_patb_colors(type);
  1408.     }
  1409.     return this._patb_colors[type];
  1410. }; // Game_Battler.prototype.patb_colors
  1411.  
  1412. // type: The current atb type
  1413. Game_Battler.prototype.set_patb_colors = function(type) {
  1414. // New; Potential Hotspot
  1415.     this._patb_colors[type] = this.set_patb_notes("p" + type + "_colors");
  1416.     if (this._patb_colors[type]) { return; }
  1417.     var patb = $gameSystem.patb;
  1418.     this._patb_colors[type] = [patb[type + "_c1"], patb[type + "_c2"]];
  1419. }; // Game_Battler.prototype.set_patb_colors
  1420.  
  1421. // note: The notetag type with its values to be set
  1422. Game_Battler.prototype.set_patb_notes = function(note) {
  1423. // New; Potential Hotspot
  1424.     // Loosens the coupling among the core, order and se plugins
  1425.     var data = this.patb_note_data(), notetag;
  1426.     for (var index = 0, length = data.length; index < length; index++) {
  1427.         for (var d = data[index], i = 0, l = d.length; i < l; i++) {
  1428.             notetag = d[i].meta[note];
  1429.             if (notetag !== null && notetag !== undefined) { return notetag; }
  1430.         }
  1431.     }
  1432.     return null;
  1433.     //
  1434. }; // Game_Battler.prototype.set_patb_notes
  1435.  
  1436. Game_Battler.prototype.patb_note_data = function() {
  1437. // v0.00e+; New; Potential Hotspot
  1438.     return [this.states()];
  1439. }; // Game_Battler.prototype.patb_note_data
  1440.  
  1441. /*----------------------------------------------------------------------------
  1442.  *    Checks if the effective notetag list or any of their values changed
  1443.  *----------------------------------------------------------------------------*/
  1444. // note: The notetags to be checked for changes
  1445. Game_Battler.prototype.are_patb_battler_changed = function(note) {
  1446. // New; Hotspot
  1447.     var ch = this._patb_battler_change[note] || this._patb_note_change[note];
  1448.     this._patb_battler_change[note] = this._patb_note_change[note] = false;
  1449.     return ch;
  1450. }; // Game_Battler.prototype.are_patb_battler_changed
  1451.  
  1452. Game_Battler.prototype.on_all_patb_acts_end = function() { // v1.00b+; New
  1453.     this.update_patb_state_turns(1);
  1454.     this.clear_patb();
  1455. }; // Game_Battler.prototype.on_all_patb_acts_end
  1456.  
  1457. Game_Battler.prototype.clear_patb = function() { // v1.01c+; New
  1458.     this.reset_patb_val();
  1459.     this.reset_patb();
  1460. }; // Game_Battler.prototype.clear_patb
  1461.  
  1462. Game_Battler.prototype.reset_patb_val = function() { // v0.00e+; New
  1463.     if ($gameSystem.patb.atb_fill_code === "delay") {
  1464.         this._patb_val.atb += this._max_patb_val;
  1465.     } else {
  1466.         this._patb_val.atb = 0;
  1467.     }
  1468.     this._patb_val_change.atb = true;
  1469. }; // Game_Battler.prototype.reset_patb_val
  1470.  
  1471. Game_Battler.prototype.reset_patb = function() { // New
  1472.     this.corr_patb_val();
  1473.     this.clearActions();
  1474.     BattleManager.remove_patb_action_battler(this);
  1475.     this.set_patb_refresh();
  1476. }; // Game_Battler.prototype.reset_patb
  1477.  
  1478. /*----------------------------------------------------------------------------
  1479.  *    Prevents the atb value of an unactable battler from reaching its cap
  1480.  *----------------------------------------------------------------------------*/
  1481. Game_Battler.prototype.corr_patb_val = function() { // v1.00b+; New
  1482.     if ($gameSystem.patb.atb_fill_code === "delay") {
  1483.         var cap = 0, sign = -1;
  1484.     } else {
  1485.         var cap = this._max_patb_val, sign = 1;
  1486.     }
  1487.     if (this._patb_val.atb * sign < cap * sign) { return; }
  1488.     // Multiplies the difference by 100% to work with very small max atb value
  1489.     var max = Math.min(this._max_patb_val, 1);
  1490.     this._patb_val.atb -= Number.EPSILON * max * 100 * sign;
  1491.     //
  1492.     this._patb_val_change.atb = true;
  1493. }; // Game_Battler.prototype.corr_patb_val
  1494.  
  1495. Game_Battler.prototype.set_patb_refresh = function() { // New
  1496.     Object.keys(this._patb_battler_change).forEach(function(note) {
  1497.         this._patb_battler_change[note] = true;
  1498.     }, this);
  1499.     BattleManager.need_patb_refresh = true;
  1500. }; // Game_Battler.prototype.set_patb_refresh
  1501.  
  1502. // timing: The state auto removal timing
  1503. Game_Battler.prototype.update_patb_state_turns = function(timing) { // New
  1504.     this.states().forEach(function(s) {
  1505.         if (s.autoRemovalTiming === timing && this._stateTurns[s.id] > 0) {
  1506.             this._stateTurns[s.id] -= 1;
  1507.         }
  1508.     }, this);
  1509. }; // Game_Battler.prototype.update_patb_state_turns
  1510.  
  1511. Game_BattlerBase.prototype.can_input_patb = function() { // New; Hotspot
  1512.     return false;
  1513. }; // Game_BattlerBase.prototype.can_input_patb
  1514.  
  1515. /*----------------------------------------------------------------------------
  1516.  *    Checks if the battler in the actable battler list can execute actions
  1517.  *----------------------------------------------------------------------------*/
  1518. Game_Battler.prototype.can_patb_act = function() { // New; Hotspot
  1519.     // Loosens the coupling among the core, charge, delay and cooldown plugins
  1520.     return !this.can_input_patb();
  1521.     //
  1522. }; // Game_Battler.prototype.can_patb_act
  1523.  
  1524. /*----------------------------------------------------------------------------
  1525.  *    Loosens the coupling among the core, charge and cooldown plugins
  1526.  *----------------------------------------------------------------------------*/
  1527. Game_Battler.prototype.patb_type = function() { // New; Hotspot
  1528.     return "atb";
  1529. }; // Game_Battler.prototype.patb_type
  1530.  
  1531. /*----------------------------------------------------------------------------
  1532.  *    Loosens the coupling among the core, bar, charge and cooldown plugins
  1533.  *----------------------------------------------------------------------------*/
  1534. Game_Battler.prototype.patb_bar_text = function() { // v1.01a+; New; Hotspot
  1535.     return $gameSystem.patb.atb_bar_text;
  1536. }; // Game_Battler.prototype.patb_bar_text
  1537.  
  1538. //type: he atb type
  1539. Game_Battler.prototype.patb_fill_rate = function(type) {
  1540. // v1.01b+; New; Hotspot
  1541.     var max = this._max_patb_val;
  1542.     return Math.min(this._patb_val[type], max) / max;
  1543. }; // Game_Battler.prototype.patb_fill_rate
  1544.  
  1545. /*----------------------------------------------------------------------------
  1546.  *    # Edit class: Game_Actor
  1547.  *----------------------------------------------------------------------------*/
  1548.  
  1549. /*----------------------------------------------------------------------------
  1550.  *    New private instance variable
  1551.  *----------------------------------------------------------------------------*/
  1552. // _patb_reserve: The actor added during battles flag
  1553.  
  1554. /*----------------------------------------------------------------------------
  1555.  *    Ensures actors added during battles are properly initialized as well
  1556.  *----------------------------------------------------------------------------*/
  1557. Game_Actor.prototype.initMembersActorPatb = Game_Actor.prototype.initMembers;
  1558. Game_Actor.prototype.initMembers = function() { // v1.00a+
  1559.     this.initMembersActorPatb();
  1560.     this._patb_reserve = true; // Added
  1561. }; // Game_Actor.prototype.initMembers
  1562.  
  1563. Game_Actor.prototype.makeAutoBattleActionsPatb =
  1564. Game_Actor.prototype.makeAutoBattleActions;
  1565. Game_Actor.prototype.makeAutoBattleActions = function() {
  1566.     this.makeAutoBattleActionsPatb();
  1567.     if ($gameSystem.is_patb()) { this.confirm_patb_acts(); } // Added
  1568. }; // Game_Actor.prototype.makeAutoBattleActions
  1569.  
  1570. Game_Actor.prototype.makeConfusionActionsPatb =
  1571. Game_Actor.prototype.makeConfusionActions ;
  1572. Game_Actor.prototype.makeConfusionActions = function() {
  1573.     this.makeConfusionActionsPatb();
  1574.     if ($gameSystem.is_patb()) { this.confirm_patb_acts(); } // Added
  1575. }; // Game_Actor.prototype.makeConfusionActions
  1576.  
  1577. /*----------------------------------------------------------------------------
  1578.  *    Ensures actors added during battles are properly initialized as well
  1579.  *----------------------------------------------------------------------------*/
  1580. Game_Actor.prototype.onBattleEnd = function() { // v1.00a+; New
  1581.     Game_Battler.prototype.onBattleEnd.call(this);
  1582.     this._patb_reserve = true; // Added
  1583. }; // Game_Actor.prototype.onBattleEnd
  1584.  
  1585. Game_Actor.prototype.set_start_patb_val_preempt = function() { // v1.01b+; New
  1586.     this._patb_val.atb = this._max_patb_val;
  1587. }; // Game_Actor.prototype.set_start_patb_val_preempt
  1588.  
  1589. Game_Actor.prototype.set_start_patb_val_surprise = function() { // v1.01b+; New
  1590.     this._patb_val.atb = 0;
  1591. }; // Game_Actor.prototype.set_start_patb_val_surprise
  1592.  
  1593. /*----------------------------------------------------------------------------
  1594.  *    Ensures actors added during battles are properly initialized as well
  1595.  *----------------------------------------------------------------------------*/
  1596. // start: The battle start type
  1597. Game_Actor.prototype.set_start_patb_val = function(start) { // v1.00a+; New
  1598.     Game_Battler.prototype.set_start_patb_val.call(this, start);
  1599.     this._patb_reserve = false; // Added
  1600. }; // Game_Actor.prototype.set_start_patb_val
  1601.  
  1602. /*----------------------------------------------------------------------------
  1603.  *    Ensures actors added during battles are properly initialized as well
  1604.  *----------------------------------------------------------------------------*/
  1605. Game_Actor.prototype.update_patb = function() { // v1.00a+; New; Hotspot
  1606.     // Added
  1607.     if (this._patb_reserve) {
  1608.         this.init_patb();
  1609.         this._patb_reserve = false;
  1610.     }
  1611.     //
  1612.     Game_Battler.prototype.update_patb.call(this);
  1613. }; // Game_Actor.prototype.update_patb
  1614.  
  1615. Game_Actor.prototype.patb_note_data = function() {
  1616. // v1.01b+; New; Potential Hotspot
  1617.     var types = Game_Battler.prototype.patb_note_data.call(this);
  1618.     // Ensures no null data will be queried for its notetags
  1619.     types.push(this.equips().filter(function(equip) { return equip; }));
  1620.     //
  1621.     return types.concat([[this.currentClass()], [this.actor()]]);
  1622. }; // Game_Actor.prototype.patb_note_data
  1623.  
  1624. Game_Actor.prototype.confirm_patb_act = function() { // v1.01f+; New
  1625.     // Loosens the coupling among the core, cooldown, event and unison plugins
  1626.     var act = this.inputtingAction();
  1627.     if (!act) { return; }
  1628.     act.patb_confirm = true;
  1629.     this.set_patb_refresh();
  1630.     //
  1631. }; // Game_Actor.prototype.confirm_patb_act
  1632.  
  1633. /*----------------------------------------------------------------------------
  1634.  *    Loosen the coupling among the core, charge and cooldown plugins
  1635.  *----------------------------------------------------------------------------*/
  1636. Game_Actor.prototype.confirm_patb_acts = function() { // v0.00g+; New
  1637.     this._actions.forEach(function(act) { act.patb_confirm = true; });
  1638.     this.set_patb_refresh();
  1639. }; // Game_Actor.prototype.confirm_patb_acts
  1640.  
  1641. Game_Actor.prototype.can_input_patb = function() { // v1.01c+; New; Hotspot
  1642.     if (this._actions.length <= 0) { return false; }
  1643.     return !this._actions.every(function(act) { return act.patb_confirm; });
  1644. }; // Game_Actor.prototype.can_input_patb
  1645.  
  1646. /*----------------------------------------------------------------------------
  1647.  *    # (v1.01b+)Edit class: Game_Enemy
  1648.  *----------------------------------------------------------------------------*/
  1649.  
  1650. Game_Enemy.prototype.set_start_patb_val_preempt = function() { // v1.01b+; New
  1651.     this._patb_val.atb = 0;
  1652. }; // Game_Enemy.prototype.set_start_patb_val_preempt
  1653.  
  1654. Game_Enemy.prototype.set_start_patb_val_surprise = function() { // v1.01b+; New
  1655.     this._patb_val.atb = this._max_patb_val;
  1656. }; // Game_Enemy.prototype.set_start_patb_val_surprise
  1657.  
  1658. Game_Enemy.prototype.patb_note_data = function() {
  1659. // v1.01b+; New; Potential Hotspot
  1660.     var types = Game_Battler.prototype.patb_note_data.call(this);
  1661.     return types.concat([[this.enemy()]]);
  1662. }; // Game_Enemy.prototype.patb_note_data
  1663.  
  1664. /*----------------------------------------------------------------------------
  1665.  *    # (v1.01b+)Edit class: Game_Unit
  1666.  *----------------------------------------------------------------------------*/
  1667.  
  1668. // start: The battle start type
  1669. Game_Unit.prototype.set_start_patb_val = function(start) { // New
  1670.     this.members().forEach(function(mem) { mem.set_start_patb_val(start); });
  1671. }; // Game_Unit.prototype.set_start_patb_val
  1672.  
  1673. Game_Unit.prototype.update_patb = function() { // New; Hotspot
  1674.     this.movableMembers().forEach(function(mem) { mem.update_patb(); });
  1675. }; // Game_Unit.prototype.update_patb
  1676.  
  1677. /*----------------------------------------------------------------------------
  1678.  *    # Edit class: Game_Party
  1679.  *----------------------------------------------------------------------------*/
  1680.  
  1681. Game_Party.prototype.clearActions = function() { // New
  1682.     Game_Unit.prototype.clearActions.call(this);
  1683.     // Added to reset all party members' atb values upon failed party escapes
  1684.     if (!$gameSystem.is_patb()) { return; }
  1685.     this.aliveMembers().forEach(function(mem) { mem.clear_patb(); });
  1686.     //
  1687. }; // Game_Party.prototype.clearActions
  1688.  
  1689. /*----------------------------------------------------------------------------
  1690.  *    # Edit class: Window_BattleStatus
  1691.  *      - Draws all actors atb bars by reallocating spaces for drawing stuffs
  1692.  *----------------------------------------------------------------------------*/
  1693.  
  1694. Window_BattleStatus.prototype.basicAreaRectPatb =
  1695. Window_BattleStatus.prototype.basicAreaRect;
  1696. Window_BattleStatus.prototype.basicAreaRect = function(index) {
  1697.     // Added to reallocate spaces to draw the atb bars
  1698.     if ($gameSystem.is_patb() && $gameSystem.patb.show_atb_bars) {
  1699.         return this.patb_basic_area_rect(index);
  1700.     }
  1701.     //
  1702.     return this.basicAreaRectPatb(index);
  1703. }; // Window_BattleStatus.prototype.basicAreaRect
  1704.  
  1705. Window_BattleStatus.prototype.gaugeAreaWidthPatb =
  1706. Window_BattleStatus.prototype.gaugeAreaWidth;
  1707. Window_BattleStatus.prototype.gaugeAreaWidth = function() { // Hotspot
  1708.     // Added to reallocate spaces to draw the atb bars
  1709.     if ($gameSystem.is_patb() && $gameSystem.patb.show_atb_bars) {
  1710.         return this.patb_gauge_area_width();
  1711.     }
  1712.     //
  1713.     return this.gaugeAreaWidthPatb();
  1714. }; // Window_BattleStatus.prototype.gaugeAreaWidth
  1715.  
  1716. Window_BattleStatus.prototype.drawBasicAreaPatb =
  1717. Window_BattleStatus.prototype.drawBasicArea;
  1718. Window_BattleStatus.prototype.drawBasicArea = function(rect, actor) {
  1719.     // Added to reallocate spaces to draw the atb bars
  1720.     if ($gameSystem.is_patb() && $gameSystem.patb.show_atb_bars) {
  1721.         return this.draw_patb_basic_area(rect, actor);
  1722.     }
  1723.     //
  1724.     this.drawBasicAreaPatb(rect, actor);
  1725. }; // Window_BattleStatus.prototype.drawBasicArea
  1726.  
  1727. Window_BattleStatus.prototype.drawGaugeAreaWithTpPatb =
  1728. Window_BattleStatus.prototype.drawGaugeAreaWithTp;
  1729. Window_BattleStatus.prototype.drawGaugeAreaWithTp = function(rect, actor) {
  1730.     // Added to reallocate spaces to draw the atb bars
  1731.     if ($gameSystem.is_patb() && $gameSystem.patb.show_atb_bars) {
  1732.         return this.draw_patb_bar_with_tp(rect, actor);
  1733.     }
  1734.     //
  1735.     this.drawGaugeAreaWithTpPatb(rect, actor);
  1736. }; // Window_BattleStatus.prototype.drawGaugeAreaWithTp
  1737.  
  1738. Window_BattleStatus.prototype.drawGaugeAreaWithoutTpPatb =
  1739. Window_BattleStatus.prototype.drawGaugeAreaWithoutTp;
  1740. Window_BattleStatus.prototype.drawGaugeAreaWithoutTp = function(rect, actor) {
  1741.     // Added to reallocate spaces to draw the atb bars
  1742.     if ($gameSystem.is_patb() && $gameSystem.patb.show_atb_bars) {
  1743.         return this.draw_patb_bar_without_tp(rect, actor);
  1744.     }
  1745.     //
  1746.     this.drawGaugeAreaWithoutTpPatb(rect, actor);
  1747. }; // Window_BattleStatus.prototype.drawGaugeAreaWithoutTp
  1748.  
  1749. Window_BattleStatus.prototype.patb_basic_area_rect = function(index) { // New
  1750.     var rect = this.itemRectForText(index);
  1751.     rect.width -= this.gaugeAreaWidth() + $gameSystem.patb.hp_bar_ox;
  1752.     return rect;
  1753. }; // Window_BattleStatus.prototype.patb_basic_area_rect
  1754.  
  1755. Window_BattleStatus.prototype.patb_gauge_area_width = function() {
  1756. // New; Hotspot
  1757.     var p = $gameSystem.patb, w = p.hp_bar_w + p.mp_bar_ox + p.mp_bar_w;
  1758.     if ($dataSystem.optDisplayTp) { w += p.tp_bar_ox + p.tp_bar_w; }
  1759.     return w + p.atb_bar_ox + p.atb_bar_w;
  1760. }; // Window_BattleStatus.prototype.patb_gauge_area_width
  1761.  
  1762. Window_BattleStatus.prototype.draw_patb_basic_area = function(rect, actor) {
  1763. // New
  1764.     var w = $gameSystem.patb.actor_name_w;
  1765.     this.drawActorName(actor, rect.x, rect.y, w);
  1766.     var ox = w + $gameSystem.patb.actor_icon_ox;
  1767.     this.drawActorIcons(actor, rect.x + ox, rect.y, rect.width - w);
  1768. }; // Window_BattleStatus.prototype.draw_patb_basic_area
  1769.  
  1770. Window_BattleStatus.prototype.draw_patb_bar_with_tp = function(rect, actor) {
  1771. // New
  1772.     var patb = $gameSystem.patb;
  1773.     this.drawActorHp(actor, rect.x, rect.y, patb.hp_bar_w);
  1774.     var ox = patb.hp_bar_w + patb.mp_bar_ox;
  1775.     this.drawActorMp(actor, rect.x + ox, rect.y, patb.mp_bar_w);
  1776.     ox += patb.mp_bar_w + patb.tp_bar_ox;
  1777.     this.drawActorTp(actor, rect.x + ox, rect.y, patb.tp_bar_w);
  1778.     ox += patb.tp_bar_w + patb.atb_bar_ox;
  1779.     this.draw_actor_patb(actor, rect.x + ox, rect.y, actor.patb_type());
  1780. }; // Window_BattleStatus.prototype.draw_patb_bar_with_tp
  1781.  
  1782. Window_BattleStatus.prototype.draw_patb_bar_without_tp = function(rect, actor) {
  1783. // New
  1784.     var patb = $gameSystem.patb;
  1785.     this.drawActorHp(actor, rect.x, rect.y, patb.hp_bar_w);
  1786.     var ox = patb.hp_bar_w + patb.mp_bar_ox;
  1787.     this.drawActorMp(actor, rect.x + ox, rect.y, patb.mp_bar_w);
  1788.     ox += patb.mp_bar_w + patb.atb_bar_ox;
  1789.     this.draw_actor_patb(actor, rect.x + ox, rect.y, actor.patb_type());
  1790. }; // Window_BattleStatus.prototype.draw_patb_bar_without_tp
  1791.  
  1792. /*----------------------------------------------------------------------------
  1793.  *    Refreshes the atb bars only instead of the whole status window per frame
  1794.  *----------------------------------------------------------------------------*/
  1795. Window_BattleStatus.prototype.refresh_patb_bars = function() { // New; Hotspot
  1796.     var patb = $gameSystem.patb, actor, rect, type;
  1797.     var ox = patb.hp_bar_w + patb.mp_bar_ox + patb.mp_bar_w + patb.atb_bar_ox;
  1798.     if ($dataSystem.optDisplayTp) { ox += patb.tp_bar_ox + patb.tp_bar_w; }
  1799.     for (var index = 0, max = this.maxItems(); index < max; index++) {
  1800.         actor = $gameParty.battleMembers()[index];
  1801.         if (!actor) { continue; }
  1802.         type = actor.patb_type();
  1803.         // Refreshes the atb bar only if the atb value changed
  1804.         if (!actor.patb_val_change[type]) { continue; }
  1805.         rect = this.gaugeAreaRect(index);
  1806.         this.draw_actor_patb(actor, rect.x + ox, rect.y, type);
  1807.         actor.patb_val_change[type] = false;
  1808.         //
  1809.     }
  1810. }; // Window_BattleStatus.prototype.refresh_patb_bars
  1811.  
  1812. /* actor: The actor using the atb bar
  1813.  * x: The atb bar x position
  1814.  * y: The atb bar y position
  1815.  * type: The current atb type
  1816.  */
  1817. Window_BattleStatus.prototype.draw_actor_patb = function(actor, x, y, type) {
  1818. // New; Hotspot
  1819.     var w = $gameSystem.patb.atb_bar_w, colors = actor.patb_colors(type);
  1820.     var c0 = this.textColor(colors[0]), c1 = this.textColor(colors[1]);
  1821.     this.drawGauge(x, y, w, actor.patb_fill_rate(type), c0, c1);
  1822.     this.changeTextColor(this.systemColor());
  1823.     var text = actor.patb_bar_text();
  1824.     this.drawText(text, x, y, this.textWidth(text));
  1825. }; // Window_BattleStatus.prototype.draw_actor_patb
  1826.  
  1827. /*----------------------------------------------------------------------------
  1828.  *    # Edit class: Scene_Battle
  1829.  *----------------------------------------------------------------------------*/
  1830.  
  1831.  /*----------------------------------------------------------------------------
  1832.   *    New private instance variable
  1833.   *----------------------------------------------------------------------------*/
  1834.  // _can_patb_esc: Whether the party escape command can be active
  1835.  
  1836. /*----------------------------------------------------------------------------
  1837.  *    Abandons the default battle system action input and execution flows
  1838.  *----------------------------------------------------------------------------*/
  1839. Scene_Battle.prototype.updateBattleProcessPatb =
  1840. Scene_Battle.prototype.updateBattleProcess;
  1841. Scene_Battle.prototype.updateBattleProcess = function() { // Hotspot
  1842.     if ($gameSystem.is_patb()) { return this.update_patb_process(); } // Added
  1843.     this.updateBattleProcessPatb();
  1844. }; // Scene_Battle.prototype.updateBattleProcess
  1845.  
  1846. Scene_Battle.prototype.updateStatusWindowPatb =
  1847. Scene_Battle.prototype.updateStatusWindow;
  1848. Scene_Battle.prototype.updateStatusWindow = function() { // Hotspot
  1849.     // Added
  1850.     if ($gameSystem.is_patb() && this.isActive()) {
  1851.         this.update_patb_status_window();
  1852.     }
  1853.     //
  1854.     this.updateStatusWindowPatb();
  1855. }; // Scene_Battle.prototype.updateStatusWindow
  1856.  
  1857. Scene_Battle.prototype.updateWindowPositionsPatb =
  1858. Scene_Battle.prototype.updateWindowPositions;
  1859. Scene_Battle.prototype.updateWindowPositions = function() { // v1.00a+; Hotspot
  1860.     this.updateWindowPositionsPatb();
  1861.     if ($gameSystem.is_patb()) { this.update_patb_window_positions();  }// Added
  1862. }; // Scene_Battle.prototype.updateWindowPositions
  1863.  
  1864. Scene_Battle.prototype.refreshStatusPatb = Scene_Battle.prototype.refreshStatus;
  1865. Scene_Battle.prototype.refreshStatus = function() {
  1866.     if ($gameSystem.is_patb()) { this.refresh_patb_windows(); } // Added
  1867.     this.refreshStatusPatb();
  1868. }; // Scene_Battle.prototype.refreshStatus
  1869.  
  1870. Scene_Battle.prototype.commandEscapePatb = Scene_Battle.prototype.commandEscape;
  1871. Scene_Battle.prototype.commandEscape = function() { // v1.00a+
  1872.     // Added to ensure party escape attempt won't trigger when the battle's busy
  1873.     if ($gameSystem.is_patb() && !BattleManager.can_patb_esc()) {
  1874.         return this.startPartyCommandSelection();
  1875.     }
  1876.     //
  1877.     this.commandEscapePatb();
  1878. }; // Scene_Battle.prototype.commandEscape
  1879.  
  1880. Scene_Battle.prototype.startActorCommandSelectionPatb =
  1881. Scene_Battle.prototype.startActorCommandSelection;
  1882. Scene_Battle.prototype.startActorCommandSelection = function() { // v1.00b+
  1883.     this.startActorCommandSelectionPatb();
  1884.     if ($gameSystem.is_patb()) { this._actorCommandWindow.show(); } // Added
  1885. }; // Scene_Battle.prototype.startActorCommandSelection
  1886.  
  1887. Scene_Battle.prototype.selectNextCommandPatb =
  1888. Scene_Battle.prototype.selectNextCommand;
  1889. Scene_Battle.prototype.selectNextCommand = function() { // v1.00a+
  1890.     // Added to avoid setting up the party command window upon next command
  1891.     if ($gameSystem.is_patb()) { return this.select_next_patb_command(); }
  1892.     //
  1893.     this.selectNextCommandPatb();
  1894. }; // Scene_Battle.prototype.selectNextCommand
  1895.  
  1896. Scene_Battle.prototype.commandSkillPatb = Scene_Battle.prototype.commandSkill;
  1897. Scene_Battle.prototype.commandSkill = function() { // v1.03c+
  1898.     this.commandSkillPatb();
  1899.     // Added to ensure that the skill window will be shown and active
  1900.     this._skillWindow.open();
  1901.     //
  1902. }; // Scene_Battle.prototype.commandSkill
  1903.  
  1904. Scene_Battle.prototype.commandItemPatb = Scene_Battle.prototype.commandItem;
  1905. Scene_Battle.prototype.commandItem = function() { // v1.03c+
  1906.     this.commandItemPatb();
  1907.     // Added to ensure that the item window will be shown and active
  1908.     this._itemWindow.open();
  1909. }; // Scene_Battle.prototype.commandItem
  1910.  
  1911. Scene_Battle.prototype.selectActorSelectionPatb =
  1912. Scene_Battle.prototype.selectActorSelection;
  1913. Scene_Battle.prototype.selectActorSelection = function() { // v1.03b+
  1914.     this.selectActorSelectionPatb();
  1915.     // Added to ensure that the actor window will be shown and active
  1916.     this._actorWindow.open();
  1917.     //
  1918. }; // Scene_Battle.prototype.selectActorSelection
  1919.  
  1920. Scene_Battle.prototype.selectEnemySelectionPatb =
  1921. Scene_Battle.prototype.selectEnemySelection;
  1922. Scene_Battle.prototype.selectEnemySelection = function() { // v1.03b+
  1923.     this.selectEnemySelectionPatb();
  1924.     // Added to ensure that the actor window will be shown and active
  1925.     this._enemyWindow.open();
  1926.     //
  1927. }; // Scene_Battle.prototype.selectEnemySelection
  1928.  
  1929. /*----------------------------------------------------------------------------
  1930.  *    Reconstructs the battle system action input and execution flows for atb
  1931.  *----------------------------------------------------------------------------*/
  1932. Scene_Battle.prototype.update_patb_process = function() { // New; Hotspot
  1933.     this.update_can_patb_esc();
  1934.     // Loosens the coupling among the core and force plugins
  1935.     if (!BattleManager.can_update_patb_process()) {
  1936.         return this.update_patb_actor_selection();
  1937.     } else if (BattleManager.can_update_patb() && this.can_update_patb()) {
  1938.         this.update_patb();
  1939.     }
  1940.     //
  1941.     this.update_patb_actor_selection();
  1942.     BattleManager.update_patb_process();
  1943. }; // Scene_Battle.prototype.update_patb_process
  1944.  
  1945. /*----------------------------------------------------------------------------
  1946.  *    Updates the party escape command availability if the window's active
  1947.  *----------------------------------------------------------------------------*/
  1948. Scene_Battle.prototype.update_can_patb_esc = function() {
  1949. // v1.03d+; New; Hotspot
  1950.     if (!this._partyCommandWindow.active) { return; }
  1951.     var can_patb_esc = BattleManager.can_patb_esc();
  1952.     if (this._can_patb_esc !== can_patb_esc) {
  1953.         this._partyCommandWindow.setup();
  1954.     }
  1955.     this._can_patb_esc = can_patb_esc;
  1956. }; // Scene_Battle.prototype.update_can_patb_esc
  1957.  
  1958. /*----------------------------------------------------------------------------
  1959.  *    Runs the global atb wait conditions
  1960.  *----------------------------------------------------------------------------*/
  1961. Scene_Battle.prototype.can_update_patb = function() { // New; Hotspot
  1962.     var patb = $gameSystem.patb, code = patb.wait_cond_code;
  1963.     var party_cmd_active = this._partyCommandWindow.active;
  1964.     if (patb.wait_party_cmd && party_cmd_active) { return false; }
  1965.     if (code === "full") { return true; }
  1966.     if (BattleManager.phase === 'action') { return false; }
  1967.     if (code === "act") { return true; }
  1968.     if (this._actorWindow.active || this._enemyWindow.active) { return false; }
  1969.     if (code === "target") { return true; }
  1970.     if (this._skillWindow.active || this._itemWindow.active) { return false; }
  1971.     if (code === "item") { return true; }
  1972.     return !this._actorCommandWindow.active && !party_cmd_active;
  1973. }; // Scene_Battle.prototype.can_update_patb
  1974.  
  1975. /*----------------------------------------------------------------------------
  1976.  *    Runs the global atb frame update
  1977.  *----------------------------------------------------------------------------*/
  1978. Scene_Battle.prototype.update_patb = function() { // New; Hotspot
  1979.     // Loosens the coupling among the core and event plugins
  1980.     BattleManager.update_patb();
  1981.     if (BattleManager.need_patb_refresh) {
  1982.         BattleManager.need_patb_refresh = false;
  1983.         return this.refreshStatus();
  1984.     }
  1985.     if (!$gameSystem.patb.show_atb_bars) { return; }
  1986.     this._statusWindow.refresh_patb_bars();
  1987.     //
  1988. }; // Scene_Battle.prototype.update_patb
  1989.  
  1990. /*----------------------------------------------------------------------------
  1991.  *    Setups new inputable actors and deselects selected uninputable ones
  1992.  *----------------------------------------------------------------------------*/
  1993. // actor_indices: The indices of all currently inputable actors
  1994. Scene_Battle.prototype.update_patb_actor_selection = function() {
  1995. // New; Hotspot
  1996.     var actor_indices = BattleManager.inputable_patb_actor_indices();
  1997.     var index = this._statusWindow.index();
  1998.     if (actor_indices.indexOf(index) >= 0) { return; }
  1999.     // Deactivates the active input windows that should be no longer active
  2000.     if (index >= 0) { return this.close_patb_selection_windows(); }
  2001.     if (this._partyCommandWindow.active) {
  2002.         if (actor_indices.length <= 0) {
  2003.             this.close_patb_window(this._partyCommandWindow);
  2004.         }
  2005.         return;
  2006.     }
  2007.     //
  2008.     if (actor_indices.length <= 0) { return; }
  2009.     BattleManager.changeActor(actor_indices[0], 'waiting');
  2010.     this.startActorCommandSelection();
  2011. }; // Scene_Battle.prototype.update_patb_actor_selection
  2012.  
  2013. /*----------------------------------------------------------------------------
  2014.  *    Closes all selection windows for the selected uninputable actor
  2015.  *----------------------------------------------------------------------------*/
  2016. Scene_Battle.prototype.close_patb_selection_windows = function() { // New
  2017.     var windows = this.patb_selection_windows();
  2018.     if (windows.some(function(window) { return window.visible; })) {
  2019.         this._statusWindow.open();
  2020.         this._statusWindow.show();
  2021.     }
  2022.     windows.forEach(function(window) {
  2023.         if (window.active) { this.close_patb_window(window); }
  2024.     }, this);
  2025.     this._statusWindow.deselect();
  2026. }; // Scene_Battle.prototype.close_patb_selection_windows
  2027.  
  2028. /*----------------------------------------------------------------------------
  2029.  *    Loosens the coupling among core and charge plugins
  2030.  *----------------------------------------------------------------------------*/
  2031. Scene_Battle.prototype.update_patb_window_positions = function() {
  2032. // v1.02a+; New
  2033.     // Ensure the actor window will completely cover the status window
  2034.     if (!this._actorWindow.active) { return; }
  2035.     this._actorWindow.x = this._statusWindow.x;
  2036.     //
  2037. }; // Scene_Battle.prototype.update_patb_window_positions
  2038.  
  2039. Scene_Battle.prototype.refresh_patb_windows = function() { // New
  2040.     this.patb_selection_windows().forEach(function(window) {
  2041.         window.visible ? window.refresh() : window.deselect();
  2042.     });
  2043.     if (this._actorCommandWindow.visible) { return; }
  2044.     this._actorCommandWindow.selectLast();
  2045. }; // Scene_Battle.prototype.refresh_patb_windows
  2046.  
  2047. Scene_Battle.prototype.update_patb_status_window = function() {
  2048. // v1.00b+; New; Hotspot
  2049.     if ($gameMessage.isBusy() || this._messageWindow.isClosing()) { return; }
  2050.     if ($gameParty.isAllDead() || $gameTroop.isAllDead()) { return; }
  2051.     this.open_patb_selection_windows();
  2052. }; // Scene_Battle.prototype.update_patb_status_window
  2053.  
  2054. Scene_Battle.prototype.open_patb_selection_windows = function() {
  2055. // New; Hotspot
  2056.     if (this.patb_selection_windows().some(function(window) {
  2057.         return window.active;
  2058.     }) && BattleManager.actor()) { return this._actorCommandWindow.open(); }
  2059.     if (this._partyCommandWindow.active) { this._partyCommandWindow.open(); }
  2060. }; // Scene_Battle.prototype.open_patb_selection_windows
  2061.  
  2062. Scene_Battle.prototype.select_next_patb_command = function() { // v1.00b+; New
  2063.     BattleManager.selectNextCommand();
  2064.     if (BattleManager.isInputting() && BattleManager.actor()) {
  2065.         return this.startActorCommandSelection();
  2066.     }
  2067.     this.endCommandSelection();
  2068. }; // Scene_Battle.prototype.select_next_patb_command
  2069.  
  2070. Scene_Battle.prototype.close_patb_windows = function() { // New
  2071.     this.patb_windows().forEach(this.close_patb_window);
  2072. }; // Scene_Battle.prototype.close_patb_windows
  2073.  
  2074. Scene_Battle.prototype.patb_windows = function() { // v1.02d+; New
  2075.     return this.patb_selection_windows().concat([this._partyCommandWindow]);
  2076. }; // Scene_Battle.prototype.patb_windows
  2077.  
  2078. Scene_Battle.prototype.patb_selection_windows = function() { // v1.02d+; New
  2079.     var windows = [this._actorWindow, this._enemyWindow, this._skillWindow];
  2080.     return windows.concat([this._itemWindow, this._actorCommandWindow]);
  2081. }; // Scene_Battle.prototype.patb_selection_windows
  2082.  
  2083. Scene_Battle.prototype.close_patb_window = function(window) { // v1.02d+; New
  2084.     window.hide();
  2085.     window.deactivate();
  2086.     window.close();
  2087. }; // Scene_Battle.prototype.close_patb_window
  2088.  
  2089. /*============================================================================*/
RAW Paste Data