Double_X

DoubleX RMMV Action Cost v102a

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