Advertisement
Double_X

DoubleX RMMV Popularized ATB Core v104b

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