Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 DoubleX RMMV Item Cooldown
#1
DoubleX RMMV Item Cooldown

Version: v1.00a

Introduction

* Lets you set skills/items causing users to cooldown after using

Prerequisites

* Nothing special for most ordinary use cases
* Little RMMV plugin development proficiency to fully utilize this

Script

Code:
/*============================================================================

 *    ## Plugin Info                                                          
 *----------------------------------------------------------------------------
 *    # Plugin Name                                                           
 *      DoubleX RMMV Item Cooldown                                            
 *----------------------------------------------------------------------------
 *    # 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 cooled down, 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, that battler will execute the 1st inputted action       
 *      3. At turn y + x1, that battler will execute the 2nd inputted action  
 *      4. At turn y + x1 + x2, that battler will execute the 3rd inputted    
 *         action                                                             
 *      5. At turn y + x1 + x2 + x3, that battler will execute the 4th        
 *         inputted action                                                    
 *      6. At turn y + x1 + x2 + x3 + ... + xi, where 1 <= i <= n, that       
 *         battler will execute the (i + 1)th inputted action                 
 *      7. At turn y + x1 + x2 + x3 + ... + x(n - 1), that battler will       
 *         execute the nth inputted action                                    
 *      8. At turn y + x1 + x2 + x3 + ... + xn, that battler will become able
 *         to input actions again                                             
 *      If the ith action that's not executed yet is the 1st one needing      
 *      cooling down, the battler speed will only take the first ith actions'
 *      speeds into account                                                   
 *      Forced actions themselves don't cause their users to cooldown         
 *----------------------------------------------------------------------------
 *    # 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. http://pastebin.com/Pvn5Vpfe                                       
 *      Video:                                                                
 *      1. https://www.youtube.com/watch?v=t7LSw2qfkcs                        
*      Mentioned Patreon Supporters:
*      https://www.patreon.com/posts/71738797
 *----------------------------------------------------------------------------
 *    # Author                                                                
 *      DoubleX                                                               
 *----------------------------------------------------------------------------
 *    # Changelog                                                             
 *      v1.00a(GMT 1400 28-8-2016):                                           
 *      1. 1st version of this plugin finished                                
 *============================================================================*/
/*:
 * @plugindesc Lets you set skills/items causing users to cooldown after 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
 *       cooldown the skill/item user 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 26 will set the text color of the text
 *             showing the number of turns needed to cooldown the skill/item
 *             user on the skill/item window as 26
 * @default 19
 *
 * @help
 * The skill/item window cooldown turn display can be problematic if the
 * number of turn's 1000 or above
 * The default plugin file name is DoubleX RMMV Item Cooldown v100a
 * If you want to change that, you must edit the value of
 * DoubleX_RMMV.Item_Cooldown_File, which must be done via opening this plugin
 * js file directly
 *============================================================================
 *    ## Notetag Info                                                         
 *----------------------------------------------------------------------------
 *    # Skill/Item Notetags:                                                  
 *      1. <item cooldown: turns>                                             
 *         - Sets the number of turns needed to cooldown the skill/item user  
 *           after using it as turns                                          
 *         - E.g.:                                                            
 *           <item cooldown: 1> will set the number of turns needed to        
 *           cooldown the skill/item user after using it as 1                 
 *         - Only the 1st notetag will be used                                
 *============================================================================
 *    ## Plugin Call Info                                                     
 *----------------------------------------------------------------------------
 *    # Configuration manipulations                                           
 *      1. $gameSystem.itemCooldown.param                                     
 *         - Returns the stored value of param listed in the plugin manager   
 *         - E.g.:                                                            
 *           $gameSystem.itemCooldown.textColor will return the stored value  
 *           of parameter textColor shown on the plugin manager               
 *      2. $gameSystem.itemCooldown.param = val                               
 *         - Sets the stored value of param listed in plugin manager as val   
 *         - E.g.:                                                            
 *           $gameSystem.itemCooldown.isEnabled = false will set the stored   
 *           value of parameter isEnabled shown on the plugin manager as false
 *         - All $gameSystem.itemCooldown.param changes will be saved         
 *    # Skill/Item notetag manipulations                                      
 *      1. meta.itemCooldown                                                  
 *         - Returns the <item cooldown: turns> notetag value turns as a      
 *           Number                                                           
 *         - E.g.:                                                            
 *           $dataSkills[1].meta.itemCooldown will return the                 
 *           <item cooldown: turns> notetag value of skill with id 1          
 *      2. meta.itemCooldown = turns                                          
 *         - Sets the <item cooldown: turns> notetag value turns as a Number  
 *         - E.g.:                                                            
 *           $dataItems[2].meta.itemCooldown = 0 will set the                 
 *           <item cooldown: turns> notetag value of item with id 2 as 0      
 *         - All meta.itemCooldown changes can be saved if                    
 *           DoubleX RMMV Dynamic Data is used                                
 *============================================================================
 */

var DoubleX_RMMV = DoubleX_RMMV || {};
DoubleX_RMMV['Item Cooldown'] = 'v1.00a';

// The plugin file name must be the same as DoubleX_RMMV.Item_Cooldown_File
DoubleX_RMMV.Item_Cooldown_File = 'DoubleX RMMV Item Cooldown 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_Cooldown_Notes_Loaded = false; // v1.00a - v1.00a

DoubleX_RMMV.Item_Cooldown_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_Cooldown_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_Cooldown_Notes_Loaded) return true;
        [$dataSkills, $dataItems].forEach(function(type) {
            type.forEach(function(data) { if (data) DM.loadNotes(data); });
        });
        DoubleX_RMMV.Is_Item_Cooldown_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 +cooldown *: *(\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.itemCooldown = +RegExp.$1;
        }
        datum.meta.itemCooldown = 0; // The default's not needing charging
    }; // DM.loadNotes

    IC.BattleManager = {};
    var BM = IC.BattleManager;

    BM.makeActionOrders = BattleManager.makeActionOrders;
    BattleManager.makeActionOrders = function() { // Rewritten; v1.00a - v1.00a
        var battlers = [];
        // Rewritten to exclude battlers still cooling down
        if (!this._surprise) {
            battlers = battlers.concat(GU.nonItemCooldownMems.call($gameParty));
        }
        if (!this._preemptive) {
            battlers = battlers.concat(GU.nonItemCooldownMems.call($gameTroop));
        }
        //
        battlers.forEach(function(battler) {
            battler.makeSpeed();
        });
        battlers.sort(function(a, b) {
            return b.speed() - a.speed();
        });
        this._actionBattlers = battlers;
    }; // BattleManager.makeActionOrders

    BM.startTurn = BattleManager.startTurn;
    BattleManager.startTurn = function() { // Extended; v1.00a - v1.00a
        BM.updateItemCooldown(); // Added
        BM.startTurn.apply(this, arguments);
    }; // BattleManager.startTurn

    BM.endAction = BattleManager.endAction;
    BattleManager.endAction = function() { // Extended; v1.00a - v1.00a
        BM.endAction.apply(this, arguments);
        // Added to mark the number of turns for the battler to cooldown
        if (!$gameSystem.itemCooldown.isEnabled) return;
        this._subject.itemCooldown = this._action.item().meta.itemCooldown;
        //
    }; // BattleManager.endAction

    /* Updates the remaining cooldown turns of all battlers
     * Functional cohesion/Message coupling
     */
    BM.updateItemCooldown = function() { // New; v1.00a - v1.00a
        GU.updateItemCooldown.call($gameParty);
        GU.updateItemCooldown.call($gameTroop);
    }; // BM.updateItemCooldown

    IC.Game_System = {};
    var GS = IC.Game_System;

    /*------------------------------------------------------------------------
     *    New public instance variable                                        
     *------------------------------------------------------------------------*/
    // itemCooldown: 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.initializeItemCooldown.call(this); // Added
    }; // Game_System.prototype.initialize

    /* Initializes all parameters of this plugin shown on the plugin manager
     * Functional cohesion/Message coupling/Idempotent
     */
    GS.initializeItemCooldown = function() { // New; v1.00a - v1.00a
        this.itemCooldown = {};
        var params = PluginManager.parameters(DoubleX_RMMV.Item_Cooldown_File);
        var ICP = DoubleX_RMMV.Item_Cooldown_Params;
        Object.keys(params).forEach(function(param) {
            this.itemCooldown[param] = ICP[ICP[param]](params[param]);
        }, this);
    }; // GS.initializeItemCooldown

    IC.Game_Battler = {};
    var GB = IC.Game_Battler;

    /*------------------------------------------------------------------------
     *    New public instance variable                                        
     *------------------------------------------------------------------------*/
    // itemCooldown: The number of turns for this battler to be cooled down

    GB.initMembers = Game_Battler.prototype.initMembers;
    Game_Battler.prototype.initMembers = function() {
    // Extended; v1.00a - v1.00a
        GB.initMembers.apply(this, arguments);
        this.itemCooldown = 0; // Added
    };
    // Game_Battler.prototype.initMembers

    GB.makeSpeed = Game_Battler.prototype.makeSpeed;
    Game_Battler.prototype.makeSpeed = function() {
    // Extended; v1.00a - v1.00a
        // Rewritten
        if (!$gameSystem.itemCooldown.isEnabled) {
            return GB.makeSpeed.apply(this, arguments);
        }
        this._speed = Math.min.apply(null, GB.makeItemCooldownSpeed.call(this));
        this._speed = this._speed || 0;
        //
    };
    // Game_Battler.prototype.makeSpeed

    /* Collects speed from 1st act to the 1st one needing cooldown
     * Return: An array of Numbers each being the speed of a collected action
     * Functional cohesion/Message coupling
     */
    GB.makeItemCooldownSpeed = function() { // New; v1.00a - v1.00a
        var act, item, length = this._actions.length, speeds = [];
        for (var index = 0; index < length; index++) {
            act = this._actions[index];
            if (!act) continue;
            speeds.push(act.speed());
            item = act.item();
            if (item && item.meta.itemCooldown > 0) return speeds;
        }
        return speeds;
    }; // GB.makeItemCooldownSpeed

    IC.Game_Actor = {};
    var GActor = IC.Game_Actor;

    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.itemCooldown.isEnabled && this.itemCooldown > 0) 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.itemCooldown.isEnabled || this.itemCooldown <= 0;
        //
    }; // 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.itemCooldown.isEnabled && this.itemCooldown > 0) return;
        //
        GE.makeActions.apply(this, arguments);
    }; // Game_Enemy.prototype.makeActions

    IC.Game_Unit = {};
    var GU = IC.Game_Unit;

    /* Gets all alive members not cooling down
     * Return: An array of alive members not cooling down
     * Functional cohesion/Message coupling/Referentially Transparent
     */
    GU.nonItemCooldownMems = function() { // New; v1.00a - v1.00a
        return this.aliveMembers().filter(function(mem) {
            return mem.itemCooldown <= 0;
        });
    }; // GU.nonItemCooldownMems

    /* Updates the remaining cooldown turn of all alive members
     * Functional cohesion/Message coupling
     */
    GU.updateItemCooldown = function() { // New; v1.00a - v1.00a
        this.aliveMembers().forEach(function(mem) {
            if (mem.itemCooldown > 0) mem.itemCooldown -= 1;
        });
    }; // GU.updateItemCooldown

    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 turns need to cooldown the item as well
        if (!$gameSystem.itemCooldown.isEnabled) return;
        var item = this._data[index];
        if (!item || item.meta.itemCooldown <= 0) return;
        var rect = this.itemRect(index);
        rect.x -= WSL.costWidth.apply(this, arguments);
        rect.width -= this.textPadding();
        var turns = item.meta.itemCooldown;
        WIL.drawItemCooldown.call(this, turns, rect.x, rect.y, rect.width);
        //
    }; // Window_ItemList.prototype.drawItem

    WIL.numberWidth = Window_ItemList.prototype.numberWidth;
    Window_ItemList.prototype.numberWidth = function() {
    // Rewritten; v1.00a - v1.00a
        // Added
        if ($gameSystem.itemCooldown.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 cooldown the item on the item window
     * (Number)turns: The number of turns needed to cooldown 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.drawItemCooldown = function(turns, x, y, width) {
    // New; v1.00a - v1.00a
        var textColor = $gameSystem.itemCooldown.textColor;
        this.changeTextColor(this.textColor(textColor));
        this.drawText(turns, x, y, width, 'right');
        this.resetTextColor();
    }; // WIL.drawItemCooldown

    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 to cooldown the skill user as well
        if (!$gameSystem.itemCooldown.isEnabled) return;
        var skill = this._data[index];
        if (!skill || skill.meta.itemCooldown <= 0) return;
        var rect = this.itemRect(index);
        rect.x -= WSL.costWidth.apply(this, arguments);
        rect.width -= this.textPadding();
        var turns = skill.meta.itemCooldown;
        WSL.drawItemCooldown.call(this, turns, rect.x, rect.y, rect.width);
        //
    }; // Window_SkillList.prototype.drawItem

    WSL.costWidth = Window_SkillList.prototype.costWidth;
    Window_SkillList.prototype.costWidth = function() {
    // Rewritten; v1.00a - v1.00a
        // Added
        if ($gameSystem.itemCooldown.isEnabled) {
            return WSL.costWidth.apply(this, arguments) + this.textWidth('000');
        }
        //
        return WSL.costWidth.apply(this, arguments);
    }; // Window_SkillList.prototype.costWidth

    /* Draws number of turns needed to cooldown skill user on skill window
     * (Number)turns: The number of turns needed to cooldown 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.drawItemCooldown = function(turns, x, y, width) {
    // New; v1.00a - v1.00a
        var textColor = $gameSystem.itemCooldown.textColor;
        this.changeTextColor(this.textColor(textColor));
        this.drawText(turns, x, y, width, 'right');
    }; // WSL.drawItemCooldown

})(DoubleX_RMMV.Item_Cooldown = {});

/*============================================================================*/

Video



FAQ

* None so far

Credits and Thanks

* None

Author's Notes

* None so far

Terms and Conditions

* Commercial use's always allowed and crediting me's always optional.
* You shall keep this plugin's Plugin Info part's contents intact.
*
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.
* 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.
* I always reserve the right to deny you from using this plugin anymore if you've violated any of the above.

Changelog

v1.00a(GMT 1400 28-8-2016):
1. 1st version of this script finished
My RMVXA/RMMV/RMMZ scripts/plugins:
http://rpgmaker.net/users/DoubleX/scripts/
Reply }


Messages In This Thread
DoubleX RMMV Item Cooldown - by DoubleX - 08-28-2016, 02:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
   Select Key Item ACE kyonides 0 66 03-22-2024, 05:49 PM
Last Post: kyonides
   Battle Item Count kyonides 4 638 02-04-2024, 05:49 AM
Last Post: kyonides
   Skill Item Kost ACE kyonides 0 260 01-03-2024, 12:07 AM
Last Post: kyonides
   Fast Item Grouping DerVVulfman 1 2,343 06-12-2023, 05:28 PM
Last Post: DerVVulfman
   DoubleX RMMV Popularized ATB Compatibility DoubleX 16 19,933 12-26-2022, 06:17 AM
Last Post: DoubleX
   DoubleX RMMV Confusion Edit DoubleX 3 6,600 09-09-2022, 11:12 AM
Last Post: DoubleX
   DoubleX RMMV Popularized ATB Clock DoubleX 2 5,527 03-25-2022, 01:04 PM
Last Post: DoubleX
   DoubleX RMMV Status Bars Compatibility DoubleX 0 1,463 02-06-2022, 07:56 AM
Last Post: DoubleX
   DoubleX RMMV Popularized ATB Bar DoubleX 3 7,565 05-19-2021, 06:10 AM
Last Post: DoubleX
   DoubleX RMMV Skill Hotkeys DoubleX 2 5,039 02-13-2021, 04:59 AM
Last Post: DoubleX



Users browsing this thread: