Double_X

DoubleX RMMV Item Charge v100a

Aug 28th, 2016
316
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 Item Charge                                              
  6.  *----------------------------------------------------------------------------
  7.  *    # Introduction                                                          
  8.  *      Suppose a battler has n action slots(that battler can input n actions
  9.  *      in a single turn), and suppose that battler has inputted n actions,  
  10.  *      each needing xi turns to be charged, where 1 <= i <= n, then that    
  11.  *      battler will behave as follows:                                      
  12.  *      1. At turn y, that battler has inputted the aforementioned n actions  
  13.  *      2. At turn y + x1, that battler will execute the 1st inputted action  
  14.  *      3. At turn y + x1 + x2, that battler will execute the 2nd inputted    
  15.  *         action                                                            
  16.  *      4. At turn y + x1 + x2 + x3, that battler will execute the 3rd        
  17.  *         inputted action                                                    
  18.  *      5. At turn y + x1 + x2 + x3 + ... + xi, where 1 <= i <= n, that      
  19.  *         battler will execute the ith action                                
  20.  *      6. At turn y + x1 + x2 + x3 + ... + xn, that battler will execute the
  21.  *         nth action                                                        
  22.  *      7. At turn y + x1 + x2 + x3 + ... + xn + 1, that battler will become  
  23.  *         able to input actions again                                        
  24.  *      If the ith action that's not executed yet is the 1st one needing      
  25.  *      charging, the battler speed will only take the first (i - 1)th        
  26.  *      actions' speeds into account                                          
  27.  *      Item charging's ignored by forced actions                            
  28.  *----------------------------------------------------------------------------
  29.  *    # Terms Of Use                                                          
  30.  *      1. Commercial use's always allowed and crediting me's always optional.
  31.  *      2. You shall keep this plugin's Plugin Info part's contents intact.  
  32.  *      3. You shalln't claim that this plugin's written by anyone other than
  33.  *         DoubleX or my aliases. I always reserve the right to deny you from
  34.  *         using any of my plugins anymore if you've violated this.          
  35.  *      4. CC BY 4.0, except those conflicting with any of the above, applies
  36.  *         to this plugin, unless you've my permissions not needing follow so.
  37.  *      5. I always reserve the right to deny you from using this plugin      
  38.  *         anymore if you've violated any of the above.                      
  39.  *----------------------------------------------------------------------------
  40.  *    # Prerequisites                                                        
  41.  *      Abilities:                                                            
  42.  *      1. Nothing special for most ordinary use cases                        
  43.  *      2. Little RMMV plugin development proficiency to fully utilize this  
  44.  *----------------------------------------------------------------------------
  45.  *    # Links                                                                
  46.  *      This plugin:                                                          
  47.  *      1. http://pastebin.com/1BBbTbZs                                      
  48.  *      Video:                                                                
  49.  *      1. https://www.youtube.com/watch?v=uYnDbV0qgBM                        
  50.  *----------------------------------------------------------------------------
  51.  *    # Author                                                                
  52.  *      DoubleX                                                              
  53.  *----------------------------------------------------------------------------
  54.  *    # Changelog                                                            
  55.  *      v1.00a(GMT 0800 28-8-2016):                                          
  56.  *      1. 1st version of this plugin finished                                
  57.  *============================================================================*/
  58. /*:
  59.  * @plugindesc Lets you set skills/items to need turns to charge before using
  60.  * @author DoubleX
  61.  *
  62.  * @param isEnabled
  63.  * @desc Sets whether this plugin will be enabled
  64.  *       It'll be stored as a boolean, and will be regarded as true if and only
  65.  *       if it's true
  66.  *       Don't change this during the same battle unless you really know what
  67.  *       you're truly foing
  68.  *       E.g.: Setting isEnabled as false will disable this plugin
  69.  * @default true
  70.  *
  71.  * @param textColor
  72.  * @desc Sets the text color of the text showing the number of turns needed to
  73.  *       charge the skill/item on the skill/item window
  74.  *       It'll be stored as a Number
  75.  *       Don't change this when it's shown to ensure proper text displays
  76.  *       E.g.: Setting textColor as 31 will set the text color of the text
  77.  *             showing the number of turns needed to charge the skill/item on
  78.  *             the skill/item window as 31
  79.  * @default 30
  80.  *
  81.  * @help
  82.  * The skill/item window charging turn display can be problematic if the
  83.  * number of turn's 1000 or above
  84.  * The default plugin file name is DoubleX RMMV Item Charge v100a
  85.  * If you want to change that, you must edit the value of
  86.  * DoubleX_RMMV.Item_Charge_File, which must be done via opening this plugin
  87.  * js file directly
  88.  *============================================================================
  89.  *    ## Notetag Info                                                        
  90.  *----------------------------------------------------------------------------
  91.  *    # Skill/Item Notetags:                                                  
  92.  *      1. <item charge: turns>                                              
  93.  *         - Sets the number of turns needed to charge the skill/item before  
  94.  *           using it as turns                                                
  95.  *         - E.g.:                                                            
  96.  *           <item charge: 1> will set the number of turns needed to charge  
  97.  *           the skill/item before using it as 1                              
  98.  *         - Only the 1st notetag will be used                                
  99.  *============================================================================
  100.  *    ## Plugin Call Info                                                    
  101.  *----------------------------------------------------------------------------
  102.  *    # Configuration manipulations                                          
  103.  *      1. $gameSystem.itemCharge.param                                      
  104.  *         - Returns the stored value of param listed in the plugin manager  
  105.  *         - E.g.:                                                            
  106.  *           $gameSystem.itemCharge.textColor will return the stored value of
  107.  *           parameter textColor shown on the plugin manager                  
  108.  *      2. $gameSystem.itemCharge.param = val                                
  109.  *         - Sets the stored value of param listed in plugin manager as val  
  110.  *         - E.g.:                                                            
  111.  *           $gameSystem.itemCharge.isEnabled = false will set the stored    
  112.  *           value of parameter isEnabled shown on the plugin manager as false
  113.  *         - All $gameSystem.itemCharge.param changes will be saved          
  114.  *    # Skill/Item notetag manipulations                                      
  115.  *      1. meta.itemCharge                                                    
  116.  *         - Returns the <item charge: turns> notetag value turns as a Number
  117.  *         - E.g.:                                                            
  118.  *           $dataSkills[1].meta.itemCharge will return the                  
  119.  *           <item charge: turns> notetag value of skill with id 1            
  120.  *      2. meta.itemCharge = turns                                            
  121.  *         - Sets the <item charge: turns> notetag value turns as a Number    
  122.  *         - E.g.:                                                            
  123.  *           $dataItems[2].meta.itemCharge = 0 will set the                  
  124.  *           <item charge: turns> notetag value of item with id 2 as 0        
  125.  *         - All meta.itemCharge changes can be saved if                      
  126.  *           DoubleX RMMV Dynamic Data is used                                
  127.  *============================================================================
  128.  */
  129.  
  130. var DoubleX_RMMV = DoubleX_RMMV || {};
  131. DoubleX_RMMV['Item Charge'] = 'v1.00a';
  132.  
  133. // The plugin file name must be the same as DoubleX_RMMV.Item_Charge_File
  134. DoubleX_RMMV.Item_Charge_File = 'DoubleX RMMV Item Charge v100a';
  135.  
  136. /*============================================================================
  137.  *    ## Plugin Implementations                                              
  138.  *       You need not edit this part as it's about how this plugin works      
  139.  *----------------------------------------------------------------------------
  140.  *    # Plugin Support Info:                                                  
  141.  *      1. Prerequisites                                                      
  142.  *         - Basic knowledge on the default RMMV battle flow implementations  
  143.  *         - Some RMMV plugin development proficiency to fully comprehend this
  144.  *----------------------------------------------------------------------------*/
  145.  
  146. DoubleX_RMMV.Is_Item_Charge_Notes_Loaded = false; // v1.00a - v1.00a
  147.  
  148. DoubleX_RMMV.Item_Charge_Params = { // v1.00a - v1.00a
  149.  
  150.     isEnabled: 'Boolean', // Marks that isEnabled is a Boolean
  151.  
  152.     textColor: 'Number', // Marks that textColor is a Number
  153.  
  154.     Boolean: function(param) { return param === 'true'; }, // Boolean
  155.  
  156.     Number: function(param) { return +param; } // Number
  157.  
  158. }; // DoubleX_RMMV.Item_Charge_Params
  159.  
  160. (function(IC) {
  161.  
  162.     'use strict';
  163.  
  164.     IC.DataManager = {};
  165.     var DM = IC.DataManager;
  166.  
  167.     DM.isDatabaseLoaded = DataManager.isDatabaseLoaded;
  168.     DataManager.isDatabaseLoaded = function() { // Extended; v1.00a - v1.00a
  169.         // Rewritten to read all notetags of this plugin as well
  170.         return DM.isDatabaseLoaded.apply(this, arguments) && DM.loadAllNotes();
  171.         //
  172.     }; // DataManager.isDatabaseLoaded
  173.  
  174.     /* Reads all notetags of this plugin from the database
  175.      * Return: True
  176.      * Functional cohesion/Message coupling/Idempotent
  177.      */
  178.     DM.loadAllNotes = function() { // New; v1.00a - v1.00a
  179.         // Ensures the notetags will only be read exactly once upon game start
  180.         if (DoubleX_RMMV.Is_Item_Charge_Notes_Loaded) return true;
  181.         [$dataSkills, $dataItems].forEach(function(type) {
  182.             type.forEach(function(data) { if (data) DM.loadNotes(data); });
  183.         });
  184.         DoubleX_RMMV.Is_Item_Charge_Notes_Loaded = true;
  185.         //
  186.         return true;
  187.     }; // DM.loadAllNotes
  188.  
  189.     /* Reads all notetags of this plugin from a dataum of the database
  190.      * (Object)datum: The datum to have its notetags of this plugin read
  191.      * Functional cohesion/Data coupling/Idempotent
  192.      */
  193.     DM.loadNotes = function(datum) { // New; v1.00a - v1.00a
  194.         var regExp = /< *item +charge *: *(\d+) *>/i;
  195.         var lines = datum.note.split(/[\r\n]+/);
  196.         for (var index = 0, length = lines.length; index < length; index++) {
  197.             if (!lines[index].match(regExp)) continue;
  198.             return datum.meta.itemCharge = +RegExp.$1;
  199.         }
  200.         datum.meta.itemCharge = 0; // The default's not needing charging
  201.     }; // DM.loadNotes
  202.  
  203.     IC.BattleManager = {};
  204.     var BM = IC.BattleManager;
  205.  
  206.     BM.processTurn = BattleManager.processTurn;
  207.     BattleManager.processTurn = function() { // Rewritten; v1.00a - v1.00a
  208.         var subject = this._subject;
  209.         var action = subject.currentAction();
  210.         // Rewritten to stop executing actions upon reaching a charging one
  211.         var isEnabled = $gameSystem.itemCharge.isEnabled;
  212.         if (action && (!isEnabled || action.itemCharge <= 0)) {
  213.             action.prepare();
  214.             if (action.isValid()) {
  215.                 this.startAction();
  216.             }
  217.             subject.removeCurrentAction();
  218.         } else {
  219.             subject.onAllActionsEnd();
  220.             this.refreshStatus();
  221.             this._logWindow.displayAutoAffectedStatus(subject);
  222.             this._logWindow.displayCurrentState(subject);
  223.             this._logWindow.displayRegeneration(subject);
  224.             this._subject = this.getNextSubject();
  225.         }
  226.         //
  227.     }; // BattleManager.processTurn
  228.  
  229.     IC.Game_System = {};
  230.     var GS = IC.Game_System;
  231.  
  232.     /*------------------------------------------------------------------------
  233.      *    New public instance variable                                        
  234.      *------------------------------------------------------------------------*/
  235.     // itemCharge: The container of all parameters shown on the plugin manger
  236.  
  237.     GS.initialize = Game_System.prototype.initialize;
  238.     Game_System.prototype.initialize = function() { // Extended; v1.00a - v1.00a
  239.         GS.initialize.apply(this, arguments);
  240.         GS.initializeItemCharge.call(this); // Added
  241.     }; // Game_System.prototype.initialize
  242.  
  243.     /* Initializes all parameters of this plugin shown on the plugin manager
  244.      * Functional cohesion/Message coupling/Idempotent
  245.      */
  246.     GS.initializeItemCharge = function() { // New; v1.00a - v1.00a
  247.         this.itemCharge = {};
  248.         var params = PluginManager.parameters(DoubleX_RMMV.Item_Charge_File);
  249.         var ICP = DoubleX_RMMV.Item_Charge_Params;
  250.         Object.keys(params).forEach(function(param) {
  251.             this.itemCharge[param] = ICP[ICP[param]](params[param]);
  252.         }, this);
  253.     }; // GS.initializeItemCharge
  254.  
  255.     IC.Game_Action = {};
  256.     var GA = IC.Game_Action;
  257.  
  258.     /*------------------------------------------------------------------------
  259.      *    New public instance variable                                        
  260.      *------------------------------------------------------------------------*/
  261.     // itemCharge: The number of remaining turns for the action to be charged
  262.  
  263.     GA.initialize = Game_Action.prototype.initialize;
  264.     Game_Action.prototype.initialize = function(subject, forcing) {
  265.     // Extended; v1.00a - v1.00a
  266.         GA.initialize.apply(this, arguments);
  267.         this.itemCharge = 0; // Added
  268.     }; // Game_Action.prototype.initialize
  269.  
  270.     GA.clear = Game_Action.prototype.clear;
  271.     Game_Action.prototype.clear = function() { // Extended; v1.00a - v1.00a
  272.         GA.clear.apply(this, arguments);
  273.         this.itemCharge = 0; // Added
  274.     }; // Game_Action.prototype.clear
  275.  
  276.     GA.setSkill = Game_Action.prototype.setSkill;
  277.     Game_Action.prototype.setSkill = function(skillId) {
  278.     // Extended; v1.00a - v1.00a
  279.         GA.setSkill.apply(this, arguments);
  280.         // Added to mark the number of turns needed to charge this action
  281.         if (!this._forcing) this.itemCharge = this.item().meta.itemCharge;
  282.         //
  283.     }; // Game_Action.prototype.setSkill
  284.  
  285.     GA.setItem = Game_Action.prototype.setItem;
  286.     Game_Action.prototype.setItem = function(itemId) {
  287.     // Extended; v1.00a - v1.00a
  288.         GA.setItem.apply(this, arguments);
  289.         // Added to mark the number of turns needed to charge this action
  290.         if (!this._forcing)this.itemCharge = this.item().meta.itemCharge;
  291.         //
  292.     }; // Game_Action.prototype.setItem
  293.  
  294.     IC.Game_Battler = {};
  295.     var GB = IC.Game_Battler;
  296.  
  297.     GB.makeSpeed = Game_Battler.prototype.makeSpeed;
  298.     Game_Battler.prototype.makeSpeed = function() {
  299.     // Extended; v1.00a - v1.00a
  300.         // Rewritten
  301.         if (!$gameSystem.itemCharge.isEnabled) {
  302.             return GB.makeSpeed.apply(this, arguments);
  303.         }
  304.         this._speed = Math.min.apply(null, GB.makeItemChargeSpeed.call(this));
  305.         this._speed = this._speed || 0;
  306.         //
  307.     };
  308.     // Game_Battler.prototype.makeSpeed
  309.  
  310.     /* Collects speed from 1st act to the one right before the one having charge
  311.      * Return: An array of Numbers each being the speed of a collected action
  312.      * Functional cohesion/Message coupling
  313.      */
  314.     GB.makeItemChargeSpeed = function() { // New; v1.00a - v1.00a
  315.         var act, length = this._actions.length, speeds = [];
  316.         for (var index = 0; index < length; index++) {
  317.             act = this._actions[index];
  318.             if (!act) continue;
  319.             if (act.itemCharge > 0) return speeds;
  320.             speeds.push(act.speed());
  321.         }
  322.         return speeds;
  323.     }; // GB.makeItemChargeSpeed
  324.  
  325.     /* Removes all actions before the 1st charging one and updates its turn
  326.      * Functional cohesion/Message coupling
  327.      */
  328.     GB.updateItemCharge = function() { // New; v1.00a - v1.00a
  329.         var act;
  330.         for (var i = 0, length = this._actions.length; i < length; i++) {
  331.             act = this._actions[i];
  332.             if (act && act.itemCharge > 0) return act.itemCharge -= 1;
  333.             this._actions.shift();
  334.         }
  335.     }; // GB.updateItemCharge
  336.  
  337.     IC.Game_Actor = {};
  338.     var GActor = IC.Game_Actor;
  339.  
  340.     /*------------------------------------------------------------------------
  341.      *    New private instance variable                                      
  342.      *------------------------------------------------------------------------*/
  343.     // _hasItemCharge: Whether the actor's charging skills/items
  344.  
  345.     GActor.initMembers = Game_Actor.prototype.initMembers;
  346.     Game_Actor.prototype.initMembers = function() {
  347.     // Extended; v1.00a - v1.00a
  348.         GActor.initMembers.apply(this, arguments);
  349.         this._hasItemCharge = false; // Added
  350.     };
  351.     // Game_Actor.prototype.initMembers
  352.  
  353.     GActor.makeActions = Game_Actor.prototype.makeActions;
  354.     Game_Actor.prototype.makeActions = function() { // Extended; v1.00a - 1.00a
  355.         // Added to stop making new actions when there are still charging ones
  356.         if (!$gameSystem.itemCharge.isEnabled) {
  357.             return GActor.makeActions.apply(this, arguments);
  358.         }
  359.         if (BattleManager._surprise) return;
  360.         GB.updateItemCharge.call(this);
  361.         this._hasItemCharge = this._actions.length > 0;
  362.         if (this._hasItemCharge) return ;
  363.         //
  364.         GActor.makeActions.apply(this, arguments);
  365.     }; // Game_Actor.prototype.makeActions
  366.  
  367.     /* Checks whether this actor isn't also charging skills/items
  368.      * Functional cohesion/Message coupling/Referentially transparent
  369.      */
  370.     Game_Actor.prototype.canInput = function() { // New; v1.00a - v1.00a
  371.         // Ensures this plugin works with those having state changes in canInput
  372.         if (!Game_BattlerBase.prototype.canInput.call(this)) return false;
  373.         return !$gameSystem.itemCharge.isEnabled || !this._hasItemCharge;
  374.         //
  375.     }; // Game_Actor.prototype.canInput
  376.  
  377.     IC.Game_Enemy = {};
  378.     var GE = IC.Game_Enemy;
  379.  
  380.     GE.makeActions = Game_Enemy.prototype.makeActions;
  381.     Game_Enemy.prototype.makeActions = function() { // Extended; v1.00a - 1.00a
  382.         // Added to stop making new actions when there are still charging ones
  383.         if (!$gameSystem.itemCharge.isEnabled) {
  384.             return GE.makeActions.apply(this, arguments);
  385.         }
  386.         if (BattleManager._preemptive) return;
  387.         GB.updateItemCharge.call(this);
  388.         if (this._actions.length > 0) return ;
  389.         //
  390.         GE.makeActions.apply(this, arguments);
  391.     }; // Game_Enemy.prototype.makeActions
  392.  
  393.     IC.Window_ItemList = {};
  394.     var WIL = IC.Window_ItemList;
  395.  
  396.     WIL.drawItem = Window_ItemList.prototype.drawItem;
  397.     Window_ItemList.prototype.drawItem = function(index) {
  398.     // Extended; v1.00a - v1.00a
  399.         WIL.drawItem.apply(this, arguments);
  400.         // Added to draw the number of turns need to charge the item as well
  401.         if (!$gameSystem.itemCharge.isEnabled) return;
  402.         var item = this._data[index];
  403.         if (!item || item.meta.itemCharge <= 0) return;
  404.         var r = this.itemRect(index);
  405.         r.x -= WSL.costWidth.apply(this, arguments);
  406.         r.width -= this.textPadding();
  407.         WIL.drawItemCharge.call(this, item.meta.itemCharge, r.x, r.y, r.width);
  408.         //
  409.     }; // Window_ItemList.prototype.drawItem
  410.  
  411.     WIL.numberWidth = Window_ItemList.prototype.numberWidth;
  412.     Window_ItemList.prototype.numberWidth = function() {
  413.     // Rewritten; v1.00a - v1.00a
  414.         // Added
  415.         if ($gameSystem.itemCharge.isEnabled) {
  416.             return WIL.numberWidth.apply(this, arguments) * 2;
  417.         }
  418.         //
  419.         return WIL.numberWidth.apply(this, arguments);
  420.     }; // Window_ItemList.prototype.numberWidth
  421.  
  422.     /* Draws the number of turns needed to charge the item on the item window
  423.      * (Number)turns: The number of turns needed to charge the item
  424.      * (Number)x; The x position of the text drawn
  425.      * (Number)y; The y position of the text drawn
  426.      * (Number)width: The max width of the text drawn
  427.      * Functional cohesion/Data coupling/Idempotent
  428.      */
  429.     WIL.drawItemCharge = function(turns, x, y, width) { // New; v1.00a - v1.00a
  430.         this.changeTextColor(this.textColor($gameSystem.itemCharge.textColor));
  431.         this.drawText(turns, x, y, width, 'right');
  432.         this.resetTextColor();
  433.     }; // WIL.drawItemCharge
  434.  
  435.     IC.Window_SkillList = {};
  436.     var WSL = IC.Window_SkillList;
  437.  
  438.     WSL.drawItem = Window_SkillList.prototype.drawItem;
  439.     Window_SkillList.prototype.drawItem = function(index) {
  440.     // Extended; v1.00a - v1.00a
  441.         WSL.drawItem.apply(this, arguments);
  442.         // Added to draw the number of turns needed to charge the skill as well
  443.         if (!$gameSystem.itemCharge.isEnabled) return;
  444.         var skill = this._data[index];
  445.         if (!skill || skill.meta.itemCharge <= 0) return;
  446.         var r = this.itemRect(index);
  447.         r.x -= WSL.costWidth.apply(this, arguments);
  448.         r.width -= this.textPadding();
  449.         WSL.drawItemCharge.call(this, skill.meta.itemCharge, r.x, r.y, r.width);
  450.         //
  451.     }; // Window_SkillList.prototype.drawItem
  452.  
  453.     WSL.costWidth = Window_SkillList.prototype.costWidth;
  454.     Window_SkillList.prototype.costWidth = function() {
  455.     // Rewritten; v1.00a - v1.00a
  456.         // Added
  457.         if ($gameSystem.itemCharge.isEnabled) {
  458.             return WSL.costWidth.apply(this, arguments) + this.textWidth('000');
  459.         }
  460.         //
  461.         return WSL.costWidth.apply(this, arguments);
  462.     }; // Window_SkillList.prototype.costWidth
  463.  
  464.     /* Draws the number of turns needed to charge the skill on the skill window
  465.      * (Number)turns: The number of turns needed to charge the item
  466.      * (Number)x; The x position of the text drawn
  467.      * (Number)y; The y position of the text drawn
  468.      * (Number)width: The max width of the text drawn
  469.      * Functional cohesion/Data coupling/Idempotent
  470.      */
  471.     WSL.drawItemCharge = function(turns, x, y, width) { // New; v1.00a - v1.00a
  472.         this.changeTextColor(this.textColor($gameSystem.itemCharge.textColor));
  473.         this.drawText(turns, x, y, width, 'right');
  474.     }; // WSL.drawItemCharge
  475.  
  476. })(DoubleX_RMMV.Item_Charge = {});
  477.  
  478. /*============================================================================*/
RAW Paste Data