Advertisement
Double_X

DoubleX RMMV Popularized ATB Reset v100b

Feb 20th, 2016 (edited)
652
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*============================================================================
  2.  *    ## Plugin Info                                                          
  3.  *----------------------------------------------------------------------------
  4.  *    # Plugin Name                                                          
  5.  *      DoubleX RMMV Popularized ATB Reset                                    
  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.  *      Plugins:                                                              
  15.  *      1. DoubleX RMMV Popularized ATB Core                                  
  16.  *      Abilities:                                                            
  17.  *      1. Little Javascript coding proficiency to fully utilize this plugin  
  18.  *----------------------------------------------------------------------------
  19.  *    # Links                                                                
  20.  *      This plugin:                                                          
  21.  *      1. http://pastebin.com/b1w0zqYw                                      
  22.  *      Video:                                                                
  23.  *      1. https://www.youtube.com/watch?v=Iqy7c1Wm7TQ                        
  24.  *      Mentioned Patreon Supporters:
  25.  *      https://www.patreon.com/posts/71738797
  26.  *----------------------------------------------------------------------------
  27.  *    # Author                                                                
  28.  *      DoubleX                                                              
  29.  *----------------------------------------------------------------------------
  30.  *    # Changelog                                                            
  31.  *      v1.00b(GMT 1400 31-5-2016):                                          
  32.  *      1. Fixed a bug where the reset value is always 0 in the delay mode    
  33.  *      v1.00a(GMT 0800 20-2-2016):                                          
  34.  *      1. 1st testing version of this plugin finished                        
  35.  *============================================================================*/
  36. /*:
  37.  * @plugindesc Lets users set skills/items to have different ATB reset values
  38.  * @author DoubleX
  39.  *
  40.  * @help
  41.  *============================================================================
  42.  *    ## Notetag Info                                                        
  43.  *----------------------------------------------------------------------------
  44.  *    # Skill/Item Notetags:                                                  
  45.  *      1. <operator patb reset: val>                                        
  46.  *         - Assigns val to the battler's atb reset value via operator        
  47.  *         - operator can be either =, +, -, *, / or %, meaning set to, add  
  48.  *           by, subtract by, multiply by, divide by or modulo by respectively
  49.  *         - All instances of this notetag will be used sequentially          
  50.  *============================================================================
  51.  *    ## Plugin Call Info                                                    
  52.  *----------------------------------------------------------------------------
  53.  *    # Data Skill/Item manipulations                                        
  54.  *      1. meta.patb_reset                                                    
  55.  *         - Returns the atb reset value with the operator stored in          
  56.  *           <operator patb reset: val> in the form of [opeartor, val]        
  57.  *      2. meta.patb_reset = [opeartor, val]                                  
  58.  *         - Sets the atb reset value with the operator stored in            
  59.  *           <operator patb reset: val> as string operator and Number val    
  60.  *         - All meta.patb_reset changes can be saved if                      
  61.  *           DoubleX RMMV Dynamic Data is used                                
  62.  *    # Battler manipulations                                                
  63.  *      1. patb_reset_val                                                    
  64.  *         - Returns the battler ATB reset value                              
  65.  *      2. patb_reset_val = val                                              
  66.  *         - Sets the battler ATB reset value as val                          
  67.  *============================================================================
  68.  */
  69.  
  70. "use strict";
  71. var DoubleX_RMMV = DoubleX_RMMV || {};
  72. DoubleX_RMMV["PATB Reset"] = "v1.00b";
  73.  
  74. /*============================================================================
  75.  *    ## Plugin Implementations                                              
  76.  *       You need not edit this part as it's about how this plugin works      
  77.  *----------------------------------------------------------------------------
  78.  *    # Plugin Support Info:                                                  
  79.  *      1. Prerequisites                                                      
  80.  *         - Basic knowledge of this plugin on the user level, the default    
  81.  *           battle system implementations and the atb system concepts        
  82.  *         - Some Javascript coding proficiency to fully comprehend this      
  83.  *           plugin                                                          
  84.  *      2. Function documentation                                            
  85.  *         - The 1st part describes why this function's rewritten/extended for
  86.  *           rewritten/extended functions or what the function does for new  
  87.  *           functions                                                        
  88.  *         - The 2nd part describes what the arguments of the function are    
  89.  *         - The 3rd part informs which version rewritten, extended or created
  90.  *           this function                                                    
  91.  *         - The 4th part informs whether the function's rewritten or new    
  92.  *         - The 5th part informs whether the function's a real or potential  
  93.  *           hotspot                                                          
  94.  *         - The 6th part describes how this function works for new functions
  95.  *           only, and describes the parts added, removed or rewritten for    
  96.  *           rewritten or extended functions only                            
  97.  *         Example:                                                          
  98.  * /*----------------------------------------------------------------------
  99.  *  *    Why rewrite/extended/What this function does                      
  100.  *  *----------------------------------------------------------------------*/
  101. /* // arguments: What these arguments are                                    
  102.  * function_name = function(arguments) { // Version X+; Rewrite/New; Hotspot  
  103.  *     // Added/Removed/Rewritten to do something/How this function works    
  104.  *     function_name_code;                                                    
  105.  *     //                                                                    
  106.  * } // function_name                                                        
  107.  *----------------------------------------------------------------------------*/
  108.  
  109. if (DoubleX_RMMV["PATB Core"]) {
  110.  
  111. /*----------------------------------------------------------------------------*/
  112.  
  113. /*----------------------------------------------------------------------------
  114.  *    # Edit class: DataManager                                              
  115.  *----------------------------------------------------------------------------*/
  116.  
  117. // data: The data to have its notetags read
  118. DataManager.load_all_patb_reset_notes = DataManager.load_all_patb_notes;
  119. DataManager.load_all_patb_notes = function() {
  120.     // Added
  121.     [$dataSkills, $dataItems].forEach(function(type) {
  122.         type.forEach(function(data) {
  123.             if (data) { this.load_patb_reset_notes(data); }
  124.         }, this);
  125.     }, this);
  126.     //
  127.     return this.load_all_patb_reset_notes();
  128. }; // DataManager.load_all_patb_notes
  129.  
  130. // data: The data to have its notetags read
  131. DataManager.load_patb_reset_notes = function(data) { // New
  132.     var reset = /< *(.+) +patb +reset *: *(\d+) *>/i, m = data.meta;
  133.     m.patb_reset = [];
  134.     data.note.split(/[\r\n]+/).forEach(function(line) {
  135.         if (line.match(reset)) { m.patb_reset.push([RegExp.$1, +RegExp.$2]); }
  136.     });
  137. }; // DataManager.load_patb_reset_notes
  138.  
  139. /*----------------------------------------------------------------------------
  140.  *    # Edit class: BattleManager                                            
  141.  *----------------------------------------------------------------------------*/
  142.  
  143. BattleManager.endActionPatbReset = BattleManager.endAction;
  144. BattleManager.endAction = function() {
  145.     // Added to cache the ATB reset value
  146.     if ($gameSystem.is_patb() && this._action && this._action.item()) {
  147.         this._subject.set_patb_reset_val(this._action.item());
  148.     }
  149.     //
  150.     this.endActionPatbReset();
  151. }; // BattleManager.endAction
  152.  
  153. /*----------------------------------------------------------------------------
  154.  *    # Edit class: Game_Battler                                              
  155.  *----------------------------------------------------------------------------*/
  156.  
  157. /*----------------------------------------------------------------------------
  158.  *    New public instance variable                                            
  159.  *----------------------------------------------------------------------------*/
  160.  
  161. Object.defineProperty(Game_Battler.prototype, 'patb_reset_val', {
  162.     get: function() { return this._patb_reset_val; },
  163.     set: function(val) { this._patb_reset_val = val; },
  164.     configurable: true
  165. });
  166.  
  167. Game_Battler.prototype.init_patb_reset = Game_Battler.prototype.init_patb;
  168. Game_Battler.prototype.init_patb = function() {
  169.     this.init_patb_reset();
  170.     this._patb_reset_val = 0; // Added
  171. }; // Game_Battler.prototype.init_patb
  172.  
  173. Game_Battler.prototype.reset_patb_val_reset =
  174. Game_Battler.prototype.reset_patb_val;
  175. Game_Battler.prototype.reset_patb_val = function() {
  176.     this.reset_patb_val_reset();
  177.     if ($gameSystem.patb.atb_fill_code === "delay") {
  178.         this._patb_val.atb -= this._patb_reset_val;
  179.         this._patb_val.atb = Math.max(this._patb_val.atb, 0);
  180.     } else {
  181.         this._patb_val.atb += this._patb_reset_val;
  182.         this._patb_val.atb = this._patb_val.atb.clamp(0, this._max_patb_val);
  183.     }
  184.     this._patb_reset_val = 0;
  185. }; // Game_Battler.prototype.reset_patb_val
  186.  
  187. Game_Battler.prototype.set_patb_reset_val = function(item) {
  188.     var val = this._patb_reset_val;
  189.     item.meta.patb_reset.forEach(function(reset) {
  190.         val = this.operate_patb_notes(val, reset[0], reset[1]);
  191.     }, this);
  192.     this._patb_reset_val = val;
  193. }; // Game_Battler.prototype.set_patb_reset_val
  194.  
  195. /*----------------------------------------------------------------------------*/
  196.  
  197. } else {
  198.     alert("To use PATB Reset, place it below PATB Core.");
  199. }
  200.  
  201. /*============================================================================*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement