Double_X

DoubleX RMMV Unison Item Default v100g

Dec 25th, 2015 (edited)
876
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 Unison Item Default                                      
  6.  *----------------------------------------------------------------------------
  7.  *    # Terms Of Use                                                          
  8.  *      You shall keep this plugin's Plugin Info part's contents intact      
  9.  *      You shalln't claim that this plugin's written by anyone other than    
  10.  *      DoubleX or his aliases                                                
  11.  *      None of the above applies to DoubleX or his aliases                  
  12.  *----------------------------------------------------------------------------
  13.  *    # Prerequisites                                                        
  14.  *      Plugins:                                                              
  15.  *      1. DoubleX RMMV Unison Item Config                                    
  16.  *----------------------------------------------------------------------------
  17.  *    # Links                                                                
  18.  *      This plugin:                                                          
  19.  *      1. http://pastebin.com/kV33uWeU                                      
  20.  *      Video:                                                                
  21.  *      1. https://www.youtube.com/watch?v=iBeSIPQnRb0                        
  22.  *      Mentioned Patreon Supporters:
  23.  *      https://www.patreon.com/posts/71738797
  24.  *----------------------------------------------------------------------------
  25.  *    # Instructions                                                          
  26.  *      1. Place this plugin below DoubleX RMMV Unison Item Config            
  27.  *----------------------------------------------------------------------------
  28.  *    # Author                                                                
  29.  *      DoubleX                                                              
  30.  *----------------------------------------------------------------------------
  31.  *    # Changelog                                                            
  32.  *      v1.00g(GMT 0300 5-6-2016):                                            
  33.  *      1. Fixed a bug where game crashes when accessing equips in item menu  
  34.  *      v1.00f(GMT 1300 14-5-2016):                                          
  35.  *      1. Fixed a bug where unison items can have unison invokees with no    
  36.  *         empty action slots                                                
  37.  *      2. In sync with the latest version of DoubleX RMMV Unison Item Config
  38.  *      v1.00e(GMT 1500 30-1-2016):                                          
  39.  *      1. Fixed not passing this to canUseUnisonSkill and canUseUnisonItem  
  40.  *      2. Fixed not checking if item exist first in canUse bug              
  41.  *      3. Fixed unison invoker might not have the smallest party member index
  42.  *      v1.00d(GMT 1100 4-1-2016):                                            
  43.  *      1. Fixed all unison item being unusable due to typo bug              
  44.  *      2. Added plugin description and author name in the plugin manager    
  45.  *      v1.00c(GMT 0100 1-1-2016):                                            
  46.  *      1. Fixed undefined SceneManager.scene by using $gameParty.inBattle()  
  47.  *      v1.00b(GMT 0300 26-12-2015):                                          
  48.  *      1. Fixed unison skills/items not usable outside battles bug          
  49.  *      2. Simplified the unison skill usability checks                      
  50.  *      v1.00a(GMT 1400 25-12-2015):                                          
  51.  *      1. 1st version of this plugin finished                                
  52.  *============================================================================*/
  53. /*:
  54.  * @plugindesc Lets you use unison skills/items with the default battle system
  55.  * @author DoubleX
  56.  *============================================================================
  57.  */
  58.  
  59. var DoubleX_RMMV = DoubleX_RMMV || {};
  60. DoubleX_RMMV["Unison Item Default"] = 'v1.00g';
  61.  
  62. /*============================================================================
  63.  *    ## Plugin Implementations                                              
  64.  *       You need not edit this part as it's about how this plugin works      
  65.  *----------------------------------------------------------------------------
  66.  *    # Plugin Support Info:                                                  
  67.  *      1. Prerequisites                                                      
  68.  *         - Solid understanding to the default RMMV actor action input flows
  69.  *         - Decent battled related RMMV plugin developement proficiency to  
  70.  *           fully comprehend this plugin                                    
  71.  *      2. Function documentation                                            
  72.  *         - The 1st part describes why this function's rewritten/extended for
  73.  *           rewritten/extended functions or what the function does for new  
  74.  *           functions                                                        
  75.  *         - The 2nd part describes what the arguments of the function are    
  76.  *         - The 3rd part informs which version rewritten, extended or created
  77.  *           this function                                                    
  78.  *         - The 4th part informs whether the function's rewritten or new    
  79.  *         - The 5th part informs whether the function's a real or potential  
  80.  *           hotspot                                                          
  81.  *         - The 6th part describes how this function works for new functions
  82.  *           only, and describes the parts added, removed or rewritten for    
  83.  *           rewritten or extended functions only                            
  84.  *         Example:                                                          
  85.  * /*----------------------------------------------------------------------
  86.  *  *    Why rewrite/extended/What this function does                      
  87.  *  *----------------------------------------------------------------------*/
  88. /* // arguments: What these arguments are                                    
  89.  * functionName = function(arguments) { // Version X+; Hotspot                
  90.  *     // Added/Removed/Rewritten to do something/How this function works    
  91.  *     functionContents                                                      
  92.  *     //                                                                    
  93.  * } // functionName                                                          
  94.  *----------------------------------------------------------------------------*/
  95.  
  96. if (DoubleX_RMMV["Unison Item Config"]) {
  97.  
  98. (function(UI) {
  99.  
  100.     'use strict';
  101.  
  102.     UI.BattleManager = UI.BattleManager || {};
  103.     var BM = UI.BattleManager;
  104.  
  105.     /*------------------------------------------------------------------------
  106.      *    New public instance variable                                        
  107.      *------------------------------------------------------------------------*/
  108.     // BM.unisonActors: The mapping between unison actions and unison invokees
  109.  
  110.     BM.initMembers = BattleManager.initMembers;
  111.     BattleManager.initMembers = function() {
  112.         BM.unisonActors = {}; // Added
  113.         BM.initMembers.apply(this, arguments);
  114.     }; // BattleManager.initMembers
  115.  
  116.     BM.selectNextCommand = BattleManager.selectNextCommand;
  117.     BattleManager.selectNextCommand = function() {
  118.         BM.addUnisonActors.call(this); // Added to set the action-invokee pair
  119.         BM.selectNextCommand.apply(this, arguments);
  120.     }; // BattleManager.selectNextCommand
  121.  
  122.     BM.selectPreviousCommand = BattleManager.selectPreviousCommand;
  123.     BattleManager.selectPreviousCommand = function() {
  124.         // Added to ensure this cancelled action can be reserved for unison ones
  125.         var act = this.actor().inputtingAction();
  126.         if (act) { act.clear(); }
  127.         //
  128.         BM.selectPreviousCommand.apply(this, arguments);
  129.         // Added to clear the action-invokee pair
  130.         if (this.actor()) { BM.eraseUnisonActors(this.actor()); }
  131.         //
  132.     }; // BattleManager.selectPreviousCommand
  133.  
  134.     BM.startTurn = BattleManager.startTurn;
  135.     BattleManager.startTurn = function() {
  136.         // Added to clears all action-invokee mappings and reserved action slots
  137.         BM.clearUnisonActors.call(this);
  138.         //
  139.         BM.startTurn.apply(this, arguments);
  140.     }; // BattleManager.startTurn
  141.  
  142.     BM.addUnisonActors = function() {
  143.         var actor = this.actor(), act, item;
  144.         if (actor) { act = actor.inputtingAction(); }
  145.         if (act) { item = act.item(); }
  146.         if (!item || item.meta.unisonItemActors.length <= 1) { return; }
  147.         var actorIds = item.meta.unisonItemActors.filter(function(actorId) {
  148.             return actorId !== actor.actorId();
  149.         });
  150.         // Stores the action-invokee pair and reserves 1 action for each of them
  151.         BM.unisonActors[[actor.index(), actor.actionInputIndex]] = actorIds;
  152.         actorIds.forEach(function(actorId) {
  153.             $gameActors.actor(actorId).unisonItemNumInputs += 1;
  154.         });
  155.         //
  156.     }; // BM.addUnisonActors
  157.  
  158.     // actor: The currently selected actor
  159.     BM.eraseUnisonActors = function(actor) {
  160.         var actorIds = BM.unisonActors[[actor.index(), actor.actionInputIndex]];
  161.         if (!actorIds) { return; }
  162.         // Voids the action-invokee pair and frees 1 action for each of them
  163.         BM.unisonActors[[actor.index(), actor.actionInputIndex]] = null;
  164.         actorIds.forEach(function(actorId) {
  165.             $gameActors.actor(actorId).unisonItemNumInputs -= 1;
  166.         });
  167.         //
  168.     }; // BM.eraseUnisonActors
  169.  
  170.     BM.clearUnisonActors = function() {
  171.         BM.unisonActors = {};
  172.         // Ensures the unison action usability check will pass upon using it
  173.         $gameParty.movableMembers().forEach(function(mem) {
  174.             mem.unisonItemNumInputs = -1;
  175.         });
  176.         //
  177.     }; // BM.clearUnisonActors
  178.  
  179.     UI.Game_BattlerBase = UI.Game_BattlerBase || {};
  180.     var GBB = UI.Game_BattlerBase;
  181.  
  182.     GBB.canInput = Game_BattlerBase.prototype.canInput;
  183.     Game_BattlerBase.prototype.canInput = function() {
  184.         // Rewritten to check if at least 1 action slot isn't reserved
  185.         if (!GBB.canInput.apply(this, arguments)) { return false; }
  186.         if (!this.isActor() || !$gameParty.inBattle()) { return true; }
  187.         return this._unisonItemNumInputs < this._actions.length;
  188.         //
  189.     }; // Game_BattlerBase.prototype.canInput
  190.  
  191.     GBB.canUse = Game_BattlerBase.prototype.canUse;
  192.     Game_BattlerBase.prototype.canUse = function(item) {
  193.         // Rewritten to check if all unison actors can use the unison skill/item
  194.         if (!this.isActor() || !item) {
  195.             return GBB.canUse.apply(this, arguments);
  196.         }
  197.         var actorIds = item.meta.unisonItemActors;
  198.         if (!actorIds || actorIds.length <= 0) {
  199.             return GBB.canUse.apply(this, arguments);
  200.         }
  201.         if (actorIds.indexOf(this.actorId()) < 0) { return false; }
  202.         if (!GBB.canUse.apply(this, arguments)) { return false; }
  203.         if (DataManager.isSkill(item)) {
  204.             return GBB.canUseUnisonSkill.call(this, item);
  205.         }
  206.         return DataManager.isItem(item) && GBB.canUseUnisonItem.call(this, item);
  207.         //
  208.     }; // Game_BattlerBase.prototype.canUse
  209.  
  210.     GBB.canUseUnisonSkill = function(skill) {
  211.         var actor, actorIds = skill.meta.unisonItemActors;
  212.         var inBattle = $gameParty.inBattle(), mems = $gameParty.aliveMembers();
  213.         var learnFlags = skill.meta.unisonItemActorLearn;
  214.         // Checks if all needed actors can use the skill and have empty actions
  215.         for (var i = 0, length = actorIds.length; i < length; i++) {
  216.             if (this.actorId() === actorIds[i]) { continue; }
  217.             actor = mems.filter(function(m) {
  218.                 return m.index() > this.index() && m.actorId() === actorIds[i];
  219.             }, this)[0];
  220.             if (!actor || inBattle && !actor.canInput()) { return false; }
  221.             if (!actor.meetsSkillConditions(skill)) { return false; }
  222.             if (learnFlags[i] && actor.skills().every(function(s) {
  223.                 return s !== skill;
  224.             })) { return false; }
  225.         }
  226.         //
  227.         return true;
  228.     }; // GBB.canUseUnisonSkill
  229.  
  230.     GBB.canUseUnisonItem = function(item) {
  231.         if (!this.meetsItemConditions(item)) { return false; }
  232.         var actor, actorIds = item.meta.unisonItemActors;
  233.         var inBattle = $gameParty.inBattle(), mems = $gameParty.aliveMembers();
  234.         // The unison invoker's index's smaller than those of all unison invokees
  235.         for (var i = 0, length = actorIds.length; i < length; i++) {
  236.             if (this.actorId() === actorIds[i]) { continue; }
  237.             actor = mems.filter(function(m) {
  238.                 return m.index() > this.index() && m.actorId() === actorIds[i];
  239.             }, this)[0];
  240.             if (!actor || inBattle && !actor.canInput()) { return false; }
  241.         }
  242.         //
  243.         return true;
  244.     }; // GBB.canUseUnisonItem
  245.  
  246.     UI.Game_Actor = UI.Game_Actor || {};
  247.     var GA = UI.Game_Actor;
  248.  
  249.     /*------------------------------------------------------------------------
  250.      *    New public instance variables                                      
  251.      *------------------------------------------------------------------------*/
  252.     Object.defineProperties(Game_Actor.prototype, {
  253.         // Read by BattleManager to store the unison action-invokees pairs
  254.         'actionInputIndex': {
  255.             get: function() { return this._actionInputIndex; },
  256.             configurable: true
  257.         },
  258.         // The number of empty actions reserved for using unison skills/items
  259.         'unisonItemNumInputs': {
  260.             get: function() { return this._unisonItemNumInputs; },
  261.             set: function(num) { this._unisonItemNumInputs = num; },
  262.             configurable: true
  263.         }
  264.     });
  265.  
  266.     GA.initMembers = Game_Actor.prototype.initMembers;
  267.     Game_Actor.prototype.initMembers = function() {
  268.         GA.initMembers.apply(this, arguments);
  269.         this._unisonItemNumInputs = 0; // Added
  270.     }; // Game_Actor.prototype.initMembers
  271.  
  272.     GA.clearActions = Game_Actor.prototype.clearActions;
  273.     Game_Actor.prototype.clearActions = function() {
  274.         GA.clearActions.apply(this, arguments);
  275.         this._unisonItemNumInputs = 0; // Added
  276.     }; // Game_Actor.prototype.clearActions
  277.  
  278.     GA.selectNextCommand = Game_Actor.prototype.selectNextCommand;
  279.     Game_Actor.prototype.selectNextCommand = function() {
  280.         // Added to return false if the next slot's reserved for unison act also
  281.         var maxIndex = this._actions.length - 1;
  282.         if (this._actionInputIndex + this._unisonItemNumInputs >= maxIndex) {
  283.             return false;
  284.         }
  285.         //
  286.         return GA.selectNextCommand.apply(this, arguments);
  287.     }; // Game_Actor.prototype.selectNextCommand
  288.  
  289. })(DoubleX_RMMV.Unison_Item);
  290.  
  291. } else {
  292.     alert('To use Unison Item Default, place it below Unison Item Config.');
  293. }
  294.  
  295. /*============================================================================*/
Add Comment
Please, Sign In to add comment