daily pastebin goal
58%
SHARE
TWEET

DoubleX RMMV Popularized ATB Core v103a

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