Double_X

DoubleX RMMV Popularized ATB Core v104b

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