Advertisement
Double_X

DoubleX RMMV Popularized ATB Countdown v100c

Feb 6th, 2016 (edited)
685
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 Countdown                                
  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. Decent Javascript coding proficiency to fully utilize this plugin  
  18.  *----------------------------------------------------------------------------
  19.  *    # Links                                                                
  20.  *      This plugin:                                                          
  21.  *      1. http://pastebin.com/3a2pgKVr                                      
  22.  *      Video:                                                                
  23.  *      1. https://www.youtube.com/watch?v=YeyHaybDZt4                        
  24.  *      Mentioned Patreon Supporters:
  25.  *      https://www.patreon.com/posts/71738797
  26.  *----------------------------------------------------------------------------
  27.  *    # Author                                                                
  28.  *      DoubleX                                                              
  29.  *----------------------------------------------------------------------------
  30.  *    # Changelog                                                            
  31.  *      v1.00c(GMT 0700 20-8-2016):                                          
  32.  *      1. In sync with the latest DoubleX RMMV Popularized ATB Core version  
  33.  *      v1.00b(GMT 0400 16-7-2016):                                          
  34.  *      1. Changed auto removing timing of countdown state to "patb_countdown"
  35.  *      2. Increased this plugin's compatibility and robustness              
  36.  *      v1.00a(GMT 0600 6-2-2016):                                            
  37.  *      1. 1st testing version of this plugin finished                        
  38.  *============================================================================*/
  39. /*:
  40.  * @plugindesc Lets users set some states updating turns per specified seconds
  41.  * @author DoubleX
  42.  *
  43.  * @help
  44.  * You're supposed to edit this js file directly
  45.  *============================================================================
  46.  *    ## Notetag Info                                                        
  47.  *----------------------------------------------------------------------------
  48.  *    # State Notetags:                                                      
  49.  *      1. <patb countdown: sec>                                              
  50.  *         - Sets the state to have its turn updated every sec seconds        
  51.  *         - Every second in sec only consists of frames with atb updates    
  52.  *============================================================================
  53.  *    ## Plugin Call Info                                                    
  54.  *----------------------------------------------------------------------------
  55.  *    # Data State manipulations                                              
  56.  *      1. meta.patb_countdown                                                
  57.  *         - Returns the number of seconds per state turn update              
  58.  *         - Those seconds only consist of frames with atb updates            
  59.  *      2. meta.patb_countdown = sec                                          
  60.  *         - Sets the number of seconds per state turn update as sec          
  61.  *         - Every second in sec only consists of frames with atb updates    
  62.  *         - All meta.patb_countdown changes can be saved if                  
  63.  *           DoubleX RMMV Dynamic Data is used                                
  64.  *    # Battler manipulations                                                
  65.  *      1. patb_countdown_clock[stateId]                                      
  66.  *         - Returns the countdown clock, measured in frames, of state with id
  67.  *           stateId                                                          
  68.  *         - The number of frames per second is hardcoded as 60 by default    
  69.  *      2. patb_countdown_clock[stateId] = frames                            
  70.  *         - Sets the countdown clock, measured in frames, of state with id  
  71.  *           stateId, as frames frame                                        
  72.  *         - The number of frames per second is hardcoded as 60 by default    
  73.  *      3. patb_countdown_freeze[stateId]                                    
  74.  *         - Returns whether the countdown of a state with id stateId's frozen
  75.  *      4. patb_countdown_freeze[stateId] = boolean                          
  76.  *         - Sets the countdown of state with id stateId to be frozen if      
  77.  *           boolean is true                                                  
  78.  *============================================================================
  79.  */
  80.  
  81. "use strict";
  82. var DoubleX_RMMV = DoubleX_RMMV || {};
  83. DoubleX_RMMV["PATB Countdown"] = "v1.00c";
  84.  
  85. /*============================================================================
  86.  *    ## Plugin Configurations                                                
  87.  *       You only need to edit this part as it's about what this plugin does  
  88.  *----------------------------------------------------------------------------*/
  89.  
  90. DoubleX_RMMV.PATB_Countdown = {
  91.  
  92.     /* Sets something to happen when the turn of the countdown state state
  93.      * owned by the battler calling on_countdown_update decreases
  94.      * on_countdown_update will be bound to the battler upon use
  95.      */
  96.     on_countdown_update: function(state) {
  97.         // Uses DoubleX RMMV State Triggers to trigger countdown update effects
  98.         //var GBB = DoubleX_RMMV.State_Triggers.Game_BattlerBase;
  99.         //GBB.execStateTriggers.call(this, state.id, "turn");
  100.         //
  101.        
  102.         // Applies 10 hp damage to the state owner per countdown update
  103.         this._result.clear();
  104.         this._result.success = true;
  105.         this.gainHp(-10);
  106.         this.onDamage(10);
  107.         this.startDamagePopup();
  108.         if (this._hp <= 0) { this.performCollapse(); }
  109.     } // on_countdown_update
  110.  
  111. }; // DoubleX_RMMV.PATB_Countdown
  112.  
  113. /*============================================================================
  114.  *    ## Plugin Implementations                                              
  115.  *       You need not edit this part as it's about how this plugin works      
  116.  *----------------------------------------------------------------------------
  117.  *    # Plugin Support Info:                                                  
  118.  *      1. Prerequisites                                                      
  119.  *         - Basic knowledge of this plugin on the user level, the default    
  120.  *           battle system implementations and the atb system concepts        
  121.  *         - Some Javascript coding proficiency to fully comprehend this      
  122.  *           plugin                                                          
  123.  *      2. Function documentation                                            
  124.  *         - The 1st part describes why this function's rewritten/extended for
  125.  *           rewritten/extended functions or what the function does for new  
  126.  *           functions                                                        
  127.  *         - The 2nd part describes what the arguments of the function are    
  128.  *         - The 3rd part informs which version rewritten, extended or created
  129.  *           this function                                                    
  130.  *         - The 4th part informs whether the function's rewritten or new    
  131.  *         - The 5th part informs whether the function's a real or potential  
  132.  *           hotspot                                                          
  133.  *         - The 6th part describes how this function works for new functions
  134.  *           only, and describes the parts added, removed or rewritten for    
  135.  *           rewritten or extended functions only                            
  136.  *         Example:                                                          
  137.  * /*----------------------------------------------------------------------
  138.  *  *    Why rewrite/extended/What this function does                      
  139.  *  *----------------------------------------------------------------------*/
  140. /* // arguments: What these arguments are                                    
  141.  * function_name = function(arguments) { // Version X+; Rewrite/New; Hotspot  
  142.  *     // Added/Removed/Rewritten to do something/How this function works    
  143.  *     function_name_code;                                                    
  144.  *     //                                                                    
  145.  * } // function_name                                                        
  146.  *----------------------------------------------------------------------------*/
  147.  
  148. if (DoubleX_RMMV["PATB Core"]) {
  149.  
  150. /*----------------------------------------------------------------------------*/
  151.  
  152. /*----------------------------------------------------------------------------
  153.  *    # Edit class: DataManager                                              
  154.  *----------------------------------------------------------------------------*/
  155.  
  156. // data: The data to have its notetags read
  157. DataManager.load_all_patb_countdown_notes = DataManager.load_all_patb_notes;
  158. DataManager.load_all_patb_notes = function() {
  159.     // Added
  160.     $dataStates.forEach(function(data) {
  161.         if (data) { this.load_patb_countdown_notes(data); }
  162.     }, this);
  163.     //
  164.     return this.load_all_patb_countdown_notes();
  165. }; // DataManager.load_all_patb_notes
  166.  
  167. // data: The data to have its notetags read
  168. DataManager.load_patb_countdown_notes = function(data) { // New
  169.     var countdown = /< *patb +countdown *: *(\d+) *>/i;
  170.     var lines = data.note.split(/[\r\n]+/);
  171.     for (var index = 0, length = lines.length; index < length; index++) {
  172.         if (!lines[index].match(countdown)) { continue; }
  173.         // Ensures no other plugin will share the same timing
  174.         data.autoRemovalTiming = "patb_countdown";
  175.         //
  176.         return data.meta.patb_countdown = +RegExp.$1;
  177.     }
  178. }; // DataManager.load_patb_countdown_notes
  179.  
  180. /*----------------------------------------------------------------------------
  181.  *    # Edit class: Game_BattlerBase                                          
  182.  *----------------------------------------------------------------------------*/
  183.  
  184. Game_BattlerBase.prototype.clearStatesPatbCountdown =
  185. Game_BattlerBase.prototype.clearStates;
  186. Game_BattlerBase.prototype.clearStates = function() {
  187.     this.clearStatesPatbCountdown();
  188.     // Added
  189.     this._patb_countdown_clock = {};
  190.     this._patb_countdown_freeze = {};
  191.     //
  192. }; // Game_BattlerBase.prototype.clearStates
  193.  
  194. Game_BattlerBase.prototype.eraseStatePatbCountdown =
  195. Game_BattlerBase.prototype.eraseState;
  196. Game_BattlerBase.prototype.eraseState = function(stateId) {
  197.     this.eraseStatePatbCountdown(stateId);
  198.     // Added
  199.     this._patb_countdown_clock[stateId] = undefined;
  200.     this._patb_countdown_freeze[stateId] = undefined;
  201.     //
  202. }; // Game_BattlerBase.prototype.eraseState
  203.  
  204. Game_BattlerBase.prototype.resetStateCountsPatbCountdown =
  205. Game_BattlerBase.prototype.resetStateCounts;
  206. Game_BattlerBase.prototype.resetStateCounts = function(stateId) {
  207.     this.resetStateCountsPatbCountdown(stateId);
  208.     // Added
  209.     if (!$dataStates[stateId].meta.patb_countdown) { return; }
  210.     this._patb_countdown_clock[stateId] = 0;
  211.     //
  212. }; // Game_BattlerBase.prototype.resetStateCounts
  213.  
  214. /*----------------------------------------------------------------------------
  215.  *    # Edit class: Game_Battler                                              
  216.  *----------------------------------------------------------------------------*/
  217.  
  218. /*----------------------------------------------------------------------------
  219.  *    New public instance variables                                          
  220.  *----------------------------------------------------------------------------*/
  221. Object.defineProperties(Game_Battler.prototype, {
  222.     // The countdown clock of all countdown states
  223.     "patb_countdown_clock": { get: function() { // Potential Hotspot
  224.         return this._patb_countdown_clock;
  225.     },  configurable: true },
  226.     // The countdown clock freeze flag for all countdown states
  227.     "patb_countdown_freeze": { get: function() { // Potential Hotspot
  228.         return this._patb_countdown_freeze;
  229.     }, configurable: true }
  230. });
  231.  
  232. Game_Battler.prototype.init_patb_countdown = Game_Battler.prototype.init_patb;
  233. Game_Battler.prototype.init_patb = function() {
  234.     this.init_patb_countdown();
  235.     // Added to prevent rewriting state countdown status upon battle start
  236.     this._patb_countdown_clock = this._patb_countdown_clock || {};
  237.     this._patb_countdown_freeze = this._patb_countdown_freeze || {};
  238.     //
  239. }; // Game_Battler.prototype.init_patb
  240.  
  241. Game_Battler.prototype.update_patb_state_countdown = function() {
  242. // New; Hotspot
  243.     this.states().forEach(function(state) {
  244.         if (this._patb_countdown_clock[state.id] === undefined) { return; }
  245.         if (this._patb_countdown_freeze[state.id]) { return; }
  246.         this._patb_countdown_clock[state.id] += 1;
  247.         // Fps's assumed to be always 60
  248.         var sec = state.meta.patb_countdown * 60;
  249.         //
  250.         if (this._patb_countdown_clock[state.id] % sec != 0) { return; }
  251.         if (this._stateTurns[state.id] >= 0) {
  252.             this._stateTurns[state.id] -= 1;
  253.             this.set_patb_refresh();
  254.         }
  255.         DoubleX_RMMV.PATB_Countdown.on_countdown_update.call(this, state);
  256.     }, this);
  257.     this.removeStatesAuto("patb_countdown");
  258. }; // Game_Battler.prototype.update_patb_state_countdown
  259.  
  260. /*----------------------------------------------------------------------------
  261.  *    # (v1.00c+)Edit class: Game_Unit                                        
  262.  *----------------------------------------------------------------------------*/
  263.  
  264. Game_Unit.prototype.update_patb_countdown = Game_Unit.prototype.update_patb;
  265. Game_Unit.prototype.update_patb = function() { // v1.00c+; Hotspot
  266.     this.update_patb_countdown();
  267.     // Added
  268.     this.aliveMembers().forEach(function(mem) {
  269.         mem.update_patb_state_countdown();
  270.     });
  271.     //
  272. }; // Game_Unit.prototype.update_patb
  273.  
  274. /*----------------------------------------------------------------------------*/
  275.  
  276. } else {
  277.     alert("To use PATB Countdown, place it below PATB Core.");
  278. }
  279.  
  280. /*============================================================================*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement