G2A Many GEOs
SHARE
TWEET

DoubleX RMMV Action Cost v102a

Double_X Apr 17th, 2016 (edited) 269 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 Action Cost
  6.  *----------------------------------------------------------------------------
  7.  *    # Terms Of Use
  8.  *      1. Commercial use's always allowed and crediting me's always optional.
  9.  *      2. You shall keep this plugin's Plugin Info part's contents intact.
  10.  *      3. You shalln't claim that this plugin's written by anyone other than
  11.  *         DoubleX or my aliases. I always reserve the right to deny you from
  12.  *         using any of my plugins anymore if you've violated this.
  13.  *      4. CC BY 4.0, except those conflicting with any of the above, applies
  14.  *         to this plugin, unless you've my permissions not needing follow so.
  15.  *      5. I always reserve the right to deny you from using this plugin
  16.  *         anymore if you've violated any of the above.
  17.  *----------------------------------------------------------------------------
  18.  *    # Prerequisites
  19.  *      Abilities:
  20.  *      1. Little plugin development proficiency to fully utilize this plugin
  21.  *----------------------------------------------------------------------------
  22.  *    # Links
  23.  *      This plugin:
  24.  *      1. http://pastebin.com/pkyCifBZ
  25.  *      Video:
  26.  *      1. https://www.youtube.com/watch?v=epa5v4wZuOs
  27.  *----------------------------------------------------------------------------
  28.  *    # Author
  29.  *      DoubleX
  30.  *----------------------------------------------------------------------------
  31.  *    # Changelog
  32.  *      v1.02a(GMT 0300 20-5-2020):
  33.  *      1. Added <max act cost> notetag
  34.  *      v1.01c(GMT 0300 2-9-2017):
  35.  *      1. Fixed all skills/items being not usable outside battle bug
  36.  *      v1.01b(GMT 0800 11-8-2016):
  37.  *      1. Improved compatibility with DoubleX RMMV Popularized ATB Core
  38.  *      v1.01a(GMT 0500 16-9-2016):
  39.  *      1. Compatible with DoubleX RMMV Item Charge and
  40.  *         DoubleX RMMV Item Cooldown
  41.  *      2. Lets you set the action cots text color via textColor
  42.  *      v1.00c(GMT 0400 5-6-2016):
  43.  *      1. Fixed a bug where action cost's checked for non skills/items
  44.  *      v1.00b(GMT 1400 22-5-2016):
  45.  *      1. Fixed making some skills/items becoming not usable after cancelling
  46.  *         attack
  47.  *      v1.00a(GMT 1500 17-4-2016):
  48.  *      1. 1st version of this plugin finished
  49.  *============================================================================*/
  50. /*:
  51.  * @plugindesc Lets you set some skills/items to need more than 1 action slots
  52.  * @author DoubleX
  53.  *
  54.  * @param textColor
  55.  * @desc Sets the text color of the text showing the number of action slots
  56.  *       needed to use the skill/item on the skill/item window
  57.  *       It'll be stored as a Number
  58.  *       Don't change this when it's shown to ensure proper text displays
  59.  *       E.g.: Setting textColor as 15 will set the text color of the text
  60.  *             showing the number of action slots needed to use the skill/item
  61.  *             onthe skill/item window as 15
  62.  * @default 0
  63.  *
  64.  * @help
  65.  * The skill/item window action cost display can be problematic if the action
  66.  * cost's 1000 or above
  67.  * This plugin won't work well if the total number of action slot of a battler
  68.  * is 1000 or above
  69.  * This plugin won't work well if the action cost of attack or guard is
  70.  * greater than 1
  71.  * This plugin won't work well if the action cost isn't positive
  72.  * The default plugin file name is DoubleX RMMV Act Cost v102a
  73.  * If you want to change that, you must edit the value of
  74.  * DoubleX_RMMV.Act_Cost_File, which must be done via opening this plugin js
  75.  * file directly
  76.  *============================================================================
  77.  *    ## Notetag Info
  78.  *----------------------------------------------------------------------------
  79.  *    # Skill/Item Notetags:
  80.  *      1. <act cost: num>
  81.  *         - Sets the number of action slots needed by this skill/item as num
  82.  *      (v1.02a+)2. <max act cost>
  83.  *         - Sets the skill/item to always need all action slots
  84.  *============================================================================
  85.  *    ## Plugin Call Info
  86.  *----------------------------------------------------------------------------
  87.  *    # Skill/Item notetag manipulations
  88.  *      1. meta.actCost
  89.  *         - Returns the <act cost: num> notetag value num as a Number
  90.  *      2. meta.actCost = num
  91.  *         - Sets the <act cost: num> notetag value num as a Number
  92.  *          - All meta.actCost changes can be saved if
  93.  *            DoubleX RMMV Dynamic Data is used
  94.  *    # Skill/Item notetag manipulations
  95.  *      1. meta.isMaxActCost
  96.  *         - Returns whether <max act cost> notetag is effective
  97.  *      2. meta.isMaxActCost = boolean
  98.  *         - Sets the <max act cost> notetag to be effective if boolean is
  99.  *           true and ineffective otherwise
  100.  *          - All meta.isMaxActCost changes can be saved if
  101.  *            DoubleX RMMV Dynamic Data is used
  102.  *============================================================================
  103.  */
  104.  
  105. var DoubleX_RMMV = DoubleX_RMMV || {};
  106. DoubleX_RMMV['Act Cost'] = 'v1.02a';
  107.  
  108. // The plugin file name must be the same as DoubleX_RMMV.Act_Cost_File
  109. DoubleX_RMMV.Act_Cost_File = 'DoubleX RMMV Act Cost v102a';
  110.  
  111. /*============================================================================
  112.  *    ## Plugin Implementations
  113.  *       You need not edit this part as it's about how this plugin works
  114.  *----------------------------------------------------------------------------
  115.  *    # Plugin Support Info:
  116.  *      1. Prerequisites
  117.  *         - Some plugin development proficiency to fully comprehend this
  118.  *           plugin
  119.  *      2. Function documentation
  120.  *         - The 1st part describes why this function's rewritten/extended for
  121.  *           rewritten/extended functions or what the function does for new
  122.  *           functions
  123.  *         - The 2nd part describes what the arguments of the function are
  124.  *         - The 3rd part informs which version rewritten, extended or created
  125.  *           this function
  126.  *         - The 4th part informs whether the function's rewritten or new
  127.  *         - The 5th part informs whether the function's a real or potential
  128.  *           hotspot
  129.  *         - The 6th part describes how this function works for new functions
  130.  *           only, and describes the parts added, removed or rewritten for
  131.  *           rewritten or extended functions only
  132.  *         Example:
  133.  * /*----------------------------------------------------------------------
  134.  *  *    Why rewrite/extended/What this function does
  135.  *  *----------------------------------------------------------------------*/
  136. /* // arguments: What these arguments are
  137.  * functionName = function(arguments) { // Version X+; Hotspot
  138.  *     // Added/Removed/Rewritten to do something/How this function works
  139.  *     functionContents
  140.  *     //
  141.  * } // functionName
  142.  *----------------------------------------------------------------------------*/
  143.  
  144. (function(AC) {
  145.  
  146.     'use strict';
  147.  
  148.     AC.DataManager = {};
  149.     var DM = AC.DataManager;
  150.  
  151.     DM.isDatabaseLoaded = DataManager.isDatabaseLoaded;
  152.     DataManager.isDatabaseLoaded = function() {
  153.         // Rewritten
  154.         return DM.isDatabaseLoaded.apply(this, arguments) && DM.loadAllNotes();
  155.         //
  156.     }; // DataManager.isDatabaseLoaded
  157.  
  158.     DM.loadAllNotes = function() {
  159.         [$dataSkills, $dataItems].forEach(function(type) {
  160.             type.forEach(function(data) { if (data) DM.loadNotes(data); });
  161.         });
  162.         return true;
  163.     }; // DM.loadAllNotes
  164.  
  165.     // (Object)data: The data to have its notetags read
  166.     DM.loadNotes = function(data) {
  167.         var actCost = /< *act +cost *: *(\d+) *>/i;
  168.         var isMaxActCost = /< *max +act +cost *>/i;
  169.         data.meta.actCost = 1; // The default action cost for all skills/items
  170.         data.note.split(/[\r\n]+/).forEach(function(line) {
  171.             if (line.match(actCost)) return data.meta.actCost = +RegExp.$1;
  172.             if (line.match(isMaxActCost)) return data.meta.isMaxActCost = true;
  173.         });
  174.     }; // DM.loadNotes
  175.  
  176.     AC.BattleManager = {};
  177.     var BM = AC.BattleManager;
  178.  
  179.     BM.selectNextCommand = BattleManager.selectNextCommand;
  180.     BattleManager.selectNextCommand = function() {
  181.         // Added to reserve action slots for the currently inputted action
  182.         BM.reserveActs.call(this);
  183.         //
  184.         BM.selectNextCommand.apply(this, arguments);
  185.     }; // BattleManager.selectNextCommand
  186.  
  187.     BM.selectPreviousCommand = BattleManager.selectPreviousCommand;
  188.     BattleManager.selectPreviousCommand = function() {
  189.         // Added to ensure all reserved action slots are empty
  190.         var act = this.actor().inputtingAction();
  191.         if (act) { act.clear(); }
  192.         //
  193.         BM.selectPreviousCommand.apply(this, arguments);
  194.         // Added to release action slots from the currently inputted action
  195.         BM.releaseReservedActs.call(this);
  196.         //
  197.     }; // BattleManager.selectPreviousCommand
  198.  
  199.     BM.startTurn = BattleManager.startTurn;
  200.     BattleManager.startTurn = function() {
  201.         // Added to ensures battlers can use valid actions upon executing them
  202.         BM.clearReservedActs.call(this);
  203.         //
  204.         BM.startTurn.apply(this, arguments);
  205.     }; // BattleManager.startTurn
  206.  
  207.     BM.reserveActs = function() {
  208.         var actor = this.actor();
  209.         if (!actor) { return; }
  210.         var item = actor.inputtingAction().item();
  211.         actor.actCostInputs += GB.actCost.call(actor, item) - 1;
  212.     }; // BM.reserveActs
  213.  
  214.     BM.releaseReservedActs = function() {
  215.         var actor = this.actor();
  216.         if (!actor) { return; }
  217.         var act = actor.inputtingAction();
  218.         var item = act.item();
  219.         if (!item) return;
  220.         actor.actCostInputs -= GB.actCost.call(actor, item) - 1;
  221.         if (act) { act.clear(); }
  222.     }; // BM.releaseReservedActs
  223.  
  224.     BM.clearReservedActs = function() {
  225.         // This plugin's not supposed to work with action cost greater than 999
  226.         $gameParty.movableMembers().forEach(function(mem) {
  227.             mem.actCostInputs = -999;
  228.         });
  229.         $gameTroop.movableMembers().forEach(function(mem) {
  230.             mem.actCostInputs = -999;
  231.         });
  232.         //
  233.     }; // BM.clearReservedActs
  234.  
  235.     // v1.01a+
  236.     AC.Game_System = {};
  237.     var GS = AC.Game_System;
  238.  
  239.     /*------------------------------------------------------------------------
  240.      *    New public instance variable
  241.      *------------------------------------------------------------------------*/
  242.     // actCost: The container of all parameters shown on the plugin manger
  243.  
  244.     GS.initialize = Game_System.prototype.initialize;
  245.     Game_System.prototype.initialize = function() {
  246.         GS.initialize.apply(this, arguments);
  247.         GS.initializeActCost.call(this); // Added
  248.     }; // Game_System.prototype.initialize
  249.  
  250.     GS.initializeActCost = function() { // New; v1.00a - v1.00a
  251.         this.actCost = {};
  252.         var params = PluginManager.parameters(DoubleX_RMMV.Act_Cost_File);
  253.         Object.keys(params).forEach(function(param) {
  254.             this.actCost[param] = params[param];
  255.         }, this);
  256.     }; // GS.initializeActCost
  257.  
  258.     AC.Game_BattlerBase = {};
  259.     var GBB = AC.Game_BattlerBase;
  260.  
  261.     GBB.initMembers = Game_BattlerBase.prototype.initMembers;
  262.     Game_BattlerBase.prototype.initMembers = function() {
  263.         GBB.initMembers.apply(this, arguments);
  264.         this._actCostInputs = 0; // Added to reset the number of reserved slots
  265.     }; // Game_Actor.prototype.initMembers
  266.  
  267.     GBB.canUse = Game_BattlerBase.prototype.canUse;
  268.     Game_BattlerBase.prototype.canUse = function(item) {
  269.         // Added to check if there are enough empty action slots to be reserved
  270.         if (DataManager.isSkill(item) || DataManager.isItem(item)) {
  271.             if (!GBB.canReserveActs.call(this, item)) { return false; }
  272.         }
  273.         //
  274.         return GBB.canUse.apply(this, arguments);
  275.     }; // Game_BattlerBase.prototype.canUse
  276.  
  277.     GBB.canReserveActs = function(item) {
  278.         if (!$gameParty.inBattle()) return true;
  279.         if (!item) { return false; }
  280.         var emptyActs = this._actions.filter(function(act) {
  281.             return !act.item();
  282.         }).length;
  283.         return GB.actCost.call(this, item) <= emptyActs - this._actCostInputs;
  284.     }; // GBB.canReserveActs
  285.  
  286.     AC.Game_Battler = {};
  287.     var GB = AC.Game_Battler;
  288.  
  289.     /*------------------------------------------------------------------------
  290.      *    New public instance variable
  291.      *------------------------------------------------------------------------*/
  292.     Object.defineProperty(Game_Battler.prototype, 'actCostInputs', {
  293.         get: function() { return this._actCostInputs; },
  294.         set: function(num) { this._actCostInputs = num; },
  295.         configurable: true
  296.     });
  297.  
  298.     GB.clearActions = Game_Battler.prototype.clearActions;
  299.     Game_Battler.prototype.clearActions = function() {
  300.         GB.clearActions.apply(this, arguments);
  301.         this._actCostInputs = 0; // Added to reset the number of reserved slots
  302.     }; // Game_Battler.prototype.clearActions
  303.  
  304.     GB.actCost = function(item) { // v1.02a+
  305.         if (item.meta.isMaxActCost) return this._actions.length;
  306.         return item.meta.actCost;
  307.     }; // GB.actCost
  308.  
  309.     AC.Game_Actor = {};
  310.     var GA = AC.Game_Actor;
  311.  
  312.     GA.selectNextCommand = Game_Actor.prototype.selectNextCommand;
  313.     Game_Actor.prototype.selectNextCommand = function() {
  314.         // Added to return false if the next slot's reserved by actions too
  315.         var maxIndex = this._actions.length - 1;
  316.         if (this._actionInputIndex + this._actCostInputs >= maxIndex) {
  317.             return false;
  318.         }
  319.         //
  320.         return GA.selectNextCommand.apply(this, arguments);
  321.     }; // Game_Actor.prototype.selectNextCommand
  322.  
  323.     AC.Game_Enemy = {};
  324.     var GE = AC.Game_Enemy;
  325.  
  326.     GE.selectAction = Game_Enemy.prototype.selectAction;
  327.     Game_Enemy.prototype.selectAction = function(actionList, ratingZero) {
  328.         // Rewritten to only select those that can reserve action slots
  329.         arguments[0] = actionList.filter(function(act) {
  330.             var skill = $dataSkills[act.skillId];
  331.             return GBB.canReserveActs.call(this, skill);
  332.         }, this);
  333.         var act = GE.selectAction.apply(this, arguments);
  334.         if (act) {
  335.             var skill = $dataSkills[act.skillId];
  336.             this._actCostInputs += GB.actCost.call(this, skill) - 1;
  337.         };
  338.         return act;
  339.         //
  340.     }; // Game_Enemy.prototype.selectAction
  341.  
  342.     AC.Window_ItemList = {};
  343.     var WIL = AC.Window_ItemList;
  344.  
  345.     WIL.isEnabled = Window_ItemList.prototype.isEnabled;
  346.     Window_ItemList.prototype.isEnabled = function(item) {
  347.         // Rewritten to disable item when its user doesn't have enough actions
  348.         if (!DataManager.isItem(item) || !$gameParty.inBattle()) {
  349.             return WIL.isEnabled.apply(this, arguments);
  350.         }
  351.         var actor = BattleManager.actor();
  352.         return actor && actor.canUse(item);
  353.         //
  354.     }; // Window_ItemList.prototype.isEnabled
  355.  
  356.     WIL.drawItem = Window_ItemList.prototype.drawItem;
  357.     Window_ItemList.prototype.drawItem = function(index) {
  358.         WIL.drawItem.apply(this, arguments);
  359.         // Added to draw the action cost as well
  360.         var item = this._data[index];
  361.         if (!item) { return; }
  362.         var rect = this.itemRect(index);
  363.         rect.x -= WSL.costWidth.apply(this, arguments);
  364.         rect.width -= this.textPadding();
  365.         WIL.drawActCost.call(this, item, rect.x, rect.y, rect.width);
  366.         //
  367.     }; // Window_ItemList.prototype.drawItem
  368.  
  369.     WIL.numberWidth = Window_ItemList.prototype.numberWidth;
  370.     Window_ItemList.prototype.numberWidth = function() {
  371.         return WIL.numberWidth.apply(this, arguments) * 2; // Rewritten
  372.     }; // Window_ItemList.prototype.numberWidth
  373.  
  374.     WIL.drawActCost = function(item, x, y, width) {
  375.         var actor = BattleManager.actor();
  376.         var cost = actor ? GB.actCost.call(actor, item) : item.meta.actCost;
  377.         this.drawText(cost, x, y, width, 'right');
  378.     }; // WIL.drawActCost
  379.  
  380.     AC.Window_SkillList = {};
  381.     var WSL = AC.Window_SkillList;
  382.  
  383.     WSL.drawItem = Window_SkillList.prototype.drawItem;
  384.     Window_SkillList.prototype.drawItem = function(index) {
  385.         WSL.drawItem.apply(this, arguments);
  386.         // Added to draw the action cost as well
  387.         var skill = this._data[index];
  388.         if (!skill) { return; }
  389.         var rect = this.itemRect(index);
  390.         rect.x -= WSL.costWidth.apply(this, arguments);
  391.         rect.width -= this.textPadding();
  392.         WSL.drawActCost.call(this, skill, rect.x, rect.y, rect.width);
  393.         //
  394.     }; // Window_SkillList.prototype.drawItem
  395.  
  396.     WSL.costWidth = Window_SkillList.prototype.costWidth;
  397.     Window_SkillList.prototype.costWidth = function() {
  398.         // Rewritten
  399.         return WSL.costWidth.apply(this, arguments) + this.textWidth('000');
  400.         //
  401.     }; // Window_SkillList.prototype.costWidth
  402.  
  403.     WSL.drawActCost = function(skill, x, y, width) {
  404.         this.changeTextColor(this.textColor($gameSystem.actCost.textColor));
  405.         var actor = BattleManager.actor();
  406.         var cost = actor ? GB.actCost.call(actor, skill) : skill.meta.actCost;
  407.         this.drawText(cost, x, y, width, 'right');
  408.         this.changeTextColor(this.normalColor());
  409.     }; // WSL.drawActCost
  410.  
  411.     AC.Scene_Battle = {}; // v1.00b+
  412.     var SB = AC.Scene_Battle;
  413.  
  414.     SB.onActorCancel = Scene_Battle.prototype.onActorCancel;
  415.     Scene_Battle.prototype.onActorCancel = function() {
  416.         SB.onActorCancel.apply(this, arguments);
  417.         BattleManager.inputtingAction().clear(); // Added
  418.     }; // Scene_Battle.prototype.onActorCancel
  419.  
  420.     SB.onEnemyCancel = Scene_Battle.prototype.onEnemyCancel;
  421.     Scene_Battle.prototype.onEnemyCancel = function() {
  422.         SB.onEnemyCancel.apply(this, arguments);
  423.         BattleManager.inputtingAction().clear(); // Added
  424.     }; // Scene_Battle.prototype.onEnemyCancel
  425.  
  426. })(DoubleX_RMMV.Act_Cost = {});
  427.  
  428. /*============================================================================*/
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top