/*============================================================================ * ## Plugin Info *---------------------------------------------------------------------------- * # Plugin Name * DoubleX RMMV Item Charge *---------------------------------------------------------------------------- * # Introduction * Suppose a battler has n action slots(that battler can input n actions * in a single turn), and suppose that battler has inputted n actions, * each needing xi turns to be charged, where 1 <= i <= n, then that * battler will behave as follows: * 1. At turn y, that battler has inputted the aforementioned n actions * 2. At turn y + x1, that battler will execute the 1st inputted action * 3. At turn y + x1 + x2, that battler will execute the 2nd inputted * action * 4. At turn y + x1 + x2 + x3, that battler will execute the 3rd * inputted action * 5. At turn y + x1 + x2 + x3 + ... + xi, where 1 <= i <= n, that * battler will execute the ith action * 6. At turn y + x1 + x2 + x3 + ... + xn, that battler will execute the * nth action * 7. At turn y + x1 + x2 + x3 + ... + xn + 1, that battler will become * able to input actions again * If the ith action that's not executed yet is the 1st one needing * charging, the battler speed will only take the first (i - 1)th * actions' speeds into account * Item charging's ignored by forced actions *---------------------------------------------------------------------------- * # Terms Of Use * 1. Commercial use's always allowed and crediting me's always optional. * 2. You shall keep this plugin's Plugin Info part's contents intact. * 3. You shalln't claim that this plugin's written by anyone other than * DoubleX or my aliases. I always reserve the right to deny you from * using any of my plugins anymore if you've violated this. * 4. CC BY 4.0, except those conflicting with any of the above, applies * to this plugin, unless you've my permissions not needing follow so. * 5. I always reserve the right to deny you from using this plugin * anymore if you've violated any of the above. *---------------------------------------------------------------------------- * # Prerequisites * Abilities: * 1. Nothing special for most ordinary use cases * 2. Little RMMV plugin development proficiency to fully utilize this *---------------------------------------------------------------------------- * # Links * This plugin: * 1. [url]http://pastebin.com/1BBbTbZs[/url] * Video: * 1. [url]https://www.youtube.com/watch?v=uYnDbV0qgBM[/url] * Mentioned Patreon Supporters: * [url]https://www.patreon.com/posts/71738797[/url] *---------------------------------------------------------------------------- * # Author * DoubleX *---------------------------------------------------------------------------- * # Changelog * v1.00a(GMT 0800 28-8-2016): * 1. 1st version of this plugin finished *============================================================================*/ /*: * @plugindesc Lets you set skills/items to need turns to charge before using * @author DoubleX * * @param isEnabled * @desc Sets whether this plugin will be enabled * It'll be stored as a boolean, and will be regarded as true if and only * if it's true * Don't change this during the same battle unless you really know what * you're truly foing * E.g.: Setting isEnabled as false will disable this plugin * @default true * * @param textColor * @desc Sets the text color of the text showing the number of turns needed to * charge the skill/item on the skill/item window * It'll be stored as a Number * Don't change this when it's shown to ensure proper text displays * E.g.: Setting textColor as 31 will set the text color of the text * showing the number of turns needed to charge the skill/item on * the skill/item window as 31 * @default 30 * * @help * The skill/item window charging turn display can be problematic if the * number of turn's 1000 or above * The default plugin file name is DoubleX RMMV Item Charge v100a * If you want to change that, you must edit the value of * DoubleX_RMMV.Item_Charge_File, which must be done via opening this plugin * js file directly *============================================================================ * ## Notetag Info *---------------------------------------------------------------------------- * # Skill/Item Notetags: * 1. <item charge: turns> * - Sets the number of turns needed to charge the skill/item before * using it as turns * - E.g.: * <item charge: 1> will set the number of turns needed to charge * the skill/item before using it as 1 * - Only the 1st notetag will be used *============================================================================ * ## Plugin Call Info *---------------------------------------------------------------------------- * # Configuration manipulations * 1. $gameSystem.itemCharge.param * - Returns the stored value of param listed in the plugin manager * - E.g.: * $gameSystem.itemCharge.textColor will return the stored value of * parameter textColor shown on the plugin manager * 2. $gameSystem.itemCharge.param = val * - Sets the stored value of param listed in plugin manager as val * - E.g.: * $gameSystem.itemCharge.isEnabled = false will set the stored * value of parameter isEnabled shown on the plugin manager as false * - All $gameSystem.itemCharge.param changes will be saved * # Skill/Item notetag manipulations * 1. meta.itemCharge * - Returns the <item charge: turns> notetag value turns as a Number * - E.g.: * $dataSkills[1].meta.itemCharge will return the * <item charge: turns> notetag value of skill with id 1 * 2. meta.itemCharge = turns * - Sets the <item charge: turns> notetag value turns as a Number * - E.g.: * $dataItems[2].meta.itemCharge = 0 will set the * <item charge: turns> notetag value of item with id 2 as 0 * - All meta.itemCharge changes can be saved if * DoubleX RMMV Dynamic Data is used *============================================================================ */ var DoubleX_RMMV = DoubleX_RMMV || {}; DoubleX_RMMV['Item Charge'] = 'v1.00a'; // The plugin file name must be the same as DoubleX_RMMV.Item_Charge_File DoubleX_RMMV.Item_Charge_File = 'DoubleX RMMV Item Charge v100a'; /*============================================================================ * ## Plugin Implementations * You need not edit this part as it's about how this plugin works *---------------------------------------------------------------------------- * # Plugin Support Info: * 1. Prerequisites * - Basic knowledge on the default RMMV battle flow implementations * - Some RMMV plugin development proficiency to fully comprehend this *----------------------------------------------------------------------------*/ DoubleX_RMMV.Is_Item_Charge_Notes_Loaded = false; // v1.00a - v1.00a DoubleX_RMMV.Item_Charge_Params = { // v1.00a - v1.00a isEnabled: 'Boolean', // Marks that isEnabled is a Boolean textColor: 'Number', // Marks that textColor is a Number Boolean: function(param) { return param === 'true'; }, // Boolean Number: function(param) { return +param; } // Number }; // DoubleX_RMMV.Item_Charge_Params (function(IC) { 'use strict'; IC.DataManager = {}; var DM = IC.DataManager; DM.isDatabaseLoaded = DataManager.isDatabaseLoaded; DataManager.isDatabaseLoaded = function() { // Extended; v1.00a - v1.00a // Rewritten to read all notetags of this plugin as well return DM.isDatabaseLoaded.apply(this, arguments) && DM.loadAllNotes(); // }; // DataManager.isDatabaseLoaded /* Reads all notetags of this plugin from the database * Return: True * Functional cohesion/Message coupling/Idempotent */ DM.loadAllNotes = function() { // New; v1.00a - v1.00a // Ensures the notetags will only be read exactly once upon game start if (DoubleX_RMMV.Is_Item_Charge_Notes_Loaded) return true; [$dataSkills, $dataItems].forEach(function(type) { type.forEach(function(data) { if (data) DM.loadNotes(data); }); }); DoubleX_RMMV.Is_Item_Charge_Notes_Loaded = true; // return true; }; // DM.loadAllNotes /* Reads all notetags of this plugin from a dataum of the database * (Object)datum: The datum to have its notetags of this plugin read * Functional cohesion/Data coupling/Idempotent */ DM.loadNotes = function(datum) { // New; v1.00a - v1.00a var regExp = /< *item +charge *: *(\d+) *>/i; var lines = datum.note.split(/[\r\n]+/); for (var index = 0, length = lines.length; index < length; index++) { if (!lines[index].match(regExp)) continue; return datum.meta.itemCharge = +RegExp.$1; } datum.meta.itemCharge = 0; // The default's not needing charging }; // DM.loadNotes IC.BattleManager = {}; var BM = IC.BattleManager; BM.processTurn = BattleManager.processTurn; BattleManager.processTurn = function() { // Rewritten; v1.00a - v1.00a var subject = this._subject; var action = subject.currentAction(); // Rewritten to stop executing actions upon reaching a charging one var isEnabled = $gameSystem.itemCharge.isEnabled; if (action && (!isEnabled || action.itemCharge <= 0)) { action.prepare(); if (action.isValid()) { this.startAction(); } subject.removeCurrentAction(); } else { subject.onAllActionsEnd(); this.refreshStatus(); this._logWindow.displayAutoAffectedStatus(subject); this._logWindow.displayCurrentState(subject); this._logWindow.displayRegeneration(subject); this._subject = this.getNextSubject(); } // }; // BattleManager.processTurn IC.Game_System = {}; var GS = IC.Game_System; /*------------------------------------------------------------------------ * New public instance variable *------------------------------------------------------------------------*/ // itemCharge: The container of all parameters shown on the plugin manger GS.initialize = Game_System.prototype.initialize; Game_System.prototype.initialize = function() { // Extended; v1.00a - v1.00a GS.initialize.apply(this, arguments); GS.initializeItemCharge.call(this); // Added }; // Game_System.prototype.initialize /* Initializes all parameters of this plugin shown on the plugin manager * Functional cohesion/Message coupling/Idempotent */ GS.initializeItemCharge = function() { // New; v1.00a - v1.00a this.itemCharge = {}; var params = PluginManager.parameters(DoubleX_RMMV.Item_Charge_File); var ICP = DoubleX_RMMV.Item_Charge_Params; Object.keys(params).forEach(function(param) { this.itemCharge[param] = ICP[ICP[param]](params[param]); }, this); }; // GS.initializeItemCharge IC.Game_Action = {}; var GA = IC.Game_Action; /*------------------------------------------------------------------------ * New public instance variable *------------------------------------------------------------------------*/ // itemCharge: The number of remaining turns for the action to be charged GA.initialize = Game_Action.prototype.initialize; Game_Action.prototype.initialize = function(subject, forcing) { // Extended; v1.00a - v1.00a GA.initialize.apply(this, arguments); this.itemCharge = 0; // Added }; // Game_Action.prototype.initialize GA.clear = Game_Action.prototype.clear; Game_Action.prototype.clear = function() { // Extended; v1.00a - v1.00a GA.clear.apply(this, arguments); this.itemCharge = 0; // Added }; // Game_Action.prototype.clear GA.setSkill = Game_Action.prototype.setSkill; Game_Action.prototype.setSkill = function(skillId) { // Extended; v1.00a - v1.00a GA.setSkill.apply(this, arguments); // Added to mark the number of turns needed to charge this action if (!this._forcing) this.itemCharge = this.item().meta.itemCharge; // }; // Game_Action.prototype.setSkill GA.setItem = Game_Action.prototype.setItem; Game_Action.prototype.setItem = function(itemId) { // Extended; v1.00a - v1.00a GA.setItem.apply(this, arguments); // Added to mark the number of turns needed to charge this action if (!this._forcing)this.itemCharge = this.item().meta.itemCharge; // }; // Game_Action.prototype.setItem IC.Game_Battler = {}; var GB = IC.Game_Battler; GB.makeSpeed = Game_Battler.prototype.makeSpeed; Game_Battler.prototype.makeSpeed = function() { // Extended; v1.00a - v1.00a // Rewritten if (!$gameSystem.itemCharge.isEnabled) { return GB.makeSpeed.apply(this, arguments); } this._speed = Math.min.apply(null, GB.makeItemChargeSpeed.call(this)); this._speed = this._speed || 0; // }; // Game_Battler.prototype.makeSpeed /* Collects speed from 1st act to the one right before the one having charge * Return: An array of Numbers each being the speed of a collected action * Functional cohesion/Message coupling */ GB.makeItemChargeSpeed = function() { // New; v1.00a - v1.00a var act, length = this._actions.length, speeds = []; for (var index = 0; index < length; index++) { act = this._actions[index]; if (!act) continue; if (act.itemCharge > 0) return speeds; speeds.push(act.speed()); } return speeds; }; // GB.makeItemChargeSpeed /* Removes all actions before the 1st charging one and updates its turn * Functional cohesion/Message coupling */ GB.updateItemCharge = function() { // New; v1.00a - v1.00a var act; for (var i = 0, length = this._actions.length; i < length; i++) { act = this._actions[i]; if (act && act.itemCharge > 0) return act.itemCharge -= 1; this._actions.shift(); } }; // GB.updateItemCharge IC.Game_Actor = {}; var GActor = IC.Game_Actor; /*------------------------------------------------------------------------ * New private instance variable *------------------------------------------------------------------------*/ // _hasItemCharge: Whether the actor's charging skills/items GActor.initMembers = Game_Actor.prototype.initMembers; Game_Actor.prototype.initMembers = function() { // Extended; v1.00a - v1.00a GActor.initMembers.apply(this, arguments); this._hasItemCharge = false; // Added }; // Game_Actor.prototype.initMembers GActor.makeActions = Game_Actor.prototype.makeActions; Game_Actor.prototype.makeActions = function() { // Extended; v1.00a - 1.00a // Added to stop making new actions when there are still charging ones if (!$gameSystem.itemCharge.isEnabled) { return GActor.makeActions.apply(this, arguments); } if (BattleManager._surprise) return; GB.updateItemCharge.call(this); this._hasItemCharge = this._actions.length > 0; if (this._hasItemCharge) return ; // GActor.makeActions.apply(this, arguments); }; // Game_Actor.prototype.makeActions /* Checks whether this actor isn't also charging skills/items * Functional cohesion/Message coupling/Referentially transparent */ Game_Actor.prototype.canInput = function() { // New; v1.00a - v1.00a // Ensures this plugin works with those having state changes in canInput if (!Game_BattlerBase.prototype.canInput.call(this)) return false; return !$gameSystem.itemCharge.isEnabled || !this._hasItemCharge; // }; // Game_Actor.prototype.canInput IC.Game_Enemy = {}; var GE = IC.Game_Enemy; GE.makeActions = Game_Enemy.prototype.makeActions; Game_Enemy.prototype.makeActions = function() { // Extended; v1.00a - 1.00a // Added to stop making new actions when there are still charging ones if (!$gameSystem.itemCharge.isEnabled) { return GE.makeActions.apply(this, arguments); } if (BattleManager._preemptive) return; GB.updateItemCharge.call(this); if (this._actions.length > 0) return ; // GE.makeActions.apply(this, arguments); }; // Game_Enemy.prototype.makeActions IC.Window_ItemList = {}; var WIL = IC.Window_ItemList; WIL.drawItem = Window_ItemList.prototype.drawItem; Window_ItemList.prototype.drawItem = function(index) { // Extended; v1.00a - v1.00a WIL.drawItem.apply(this, arguments); // Added to draw the number of turns need to charge the item as well if (!$gameSystem.itemCharge.isEnabled) return; var item = this._data[index]; if (!item || item.meta.itemCharge <= 0) return; var r = this.itemRect(index); r.x -= WSL.costWidth.apply(this, arguments); r.width -= this.textPadding(); WIL.drawItemCharge.call(this, item.meta.itemCharge, r.x, r.y, r.width); // }; // Window_ItemList.prototype.drawItem WIL.numberWidth = Window_ItemList.prototype.numberWidth; Window_ItemList.prototype.numberWidth = function() { // Rewritten; v1.00a - v1.00a // Added if ($gameSystem.itemCharge.isEnabled) { return WIL.numberWidth.apply(this, arguments) * 2; } // return WIL.numberWidth.apply(this, arguments); }; // Window_ItemList.prototype.numberWidth /* Draws the number of turns needed to charge the item on the item window * (Number)turns: The number of turns needed to charge the item * (Number)x; The x position of the text drawn * (Number)y; The y position of the text drawn * (Number)width: The max width of the text drawn * Functional cohesion/Data coupling/Idempotent */ WIL.drawItemCharge = function(turns, x, y, width) { // New; v1.00a - v1.00a this.changeTextColor(this.textColor($gameSystem.itemCharge.textColor)); this.drawText(turns, x, y, width, 'right'); this.resetTextColor(); }; // WIL.drawItemCharge IC.Window_SkillList = {}; var WSL = IC.Window_SkillList; WSL.drawItem = Window_SkillList.prototype.drawItem; Window_SkillList.prototype.drawItem = function(index) { // Extended; v1.00a - v1.00a WSL.drawItem.apply(this, arguments); // Added to draw the number of turns needed to charge the skill as well if (!$gameSystem.itemCharge.isEnabled) return; var skill = this._data[index]; if (!skill || skill.meta.itemCharge <= 0) return; var r = this.itemRect(index); r.x -= WSL.costWidth.apply(this, arguments); r.width -= this.textPadding(); WSL.drawItemCharge.call(this, skill.meta.itemCharge, r.x, r.y, r.width); // }; // Window_SkillList.prototype.drawItem WSL.costWidth = Window_SkillList.prototype.costWidth; Window_SkillList.prototype.costWidth = function() { // Rewritten; v1.00a - v1.00a // Added if ($gameSystem.itemCharge.isEnabled) { return WSL.costWidth.apply(this, arguments) + this.textWidth('000'); } // return WSL.costWidth.apply(this, arguments); }; // Window_SkillList.prototype.costWidth /* Draws the number of turns needed to charge the skill on the skill window * (Number)turns: The number of turns needed to charge the item * (Number)x; The x position of the text drawn * (Number)y; The y position of the text drawn * (Number)width: The max width of the text drawn * Functional cohesion/Data coupling/Idempotent */ WSL.drawItemCharge = function(turns, x, y, width) { // New; v1.00a - v1.00a this.changeTextColor(this.textColor($gameSystem.itemCharge.textColor)); this.drawText(turns, x, y, width, 'right'); }; // WSL.drawItemCharge })(DoubleX_RMMV.Item_Charge = {}); /*============================================================================*/