Double_X

DoubleX RMMV Item Charge v100a

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