Advertisement
Double_X

DoubleX RMMV Unison Item YEP_X_BattleSysATB v100a

May 21st, 2016 (edited)
684
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 YEP_X_BattleSysATB                          
  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. Yanfly Engine Plugins - Battle System - Active Turn Battle        
  16.  *      2. DoubleX RMMV Unison Item Config                                    
  17.  *      3. DoubleX RMMV Unison Item Default                                  
  18.  *----------------------------------------------------------------------------
  19.  *    # Links                                                                
  20.  *      This plugin:                                                          
  21.  *      1. http://pastebin.com/y2SMpu9V                                      
  22.  *      Video:                                                                
  23.  *      1. https://www.youtube.com/watch?v=9JsrGSjbb2s                        
  24.  *      Mentioned Patreon Supporters:
  25.  *      https://www.patreon.com/posts/71738797
  26.  *----------------------------------------------------------------------------
  27.  *    # Instructions                                                          
  28.  *      1. Place DoubleX RMMV Unison Item Config below YEP_BattleEngineCore  
  29.  *      2. Place this plugin below DoubleX RMMV Unison Item Default          
  30.  *----------------------------------------------------------------------------
  31.  *    # Author                                                                
  32.  *      DoubleX                                                              
  33.  *----------------------------------------------------------------------------
  34.  *    # Changelog                                                            
  35.  *      v1.00a(GMT 0600 21-5-2016):                                          
  36.  *      1. 1st version of this plugin finished                                
  37.  *============================================================================*/
  38. /*:
  39.  * @plugindesc Lets you use unison skills/items with YEP_X_BattleSysATB
  40.  * @author DoubleX
  41.  * @help
  42.  * Charge Rate -
  43.  * All actors needed for an unison skill/item will always have the same charge
  44.  * value when charging that skill/item
  45.  * unisonFunctionRule is used to set the unison charge rate for those actors
  46.  *
  47.  * Asynchronous unison skills/items:
  48.  * All <async unison item> notetags will be ignored by this plugin and all
  49.  * unison skills/items will be regarded as asynchronous unison skills/items
  50.  * Right now asynchoronous unison skills/items won't work without charging    
  51.  * An asynchoronous unison skill/item is inputable by any battler needed by
  52.  * that skill/item as long as all the needed battlers are alive and pass the
  53.  * skill learn requirements for skills if any, and that battler passes the
  54.  * ordinary skill/item usability checks
  55.  * Battlers having inputted asynchronous unison skills/items will wait for all
  56.  * needed battlers to input those unison skills/items to execute them together
  57.  * They'll stop waiting if any needed battler's not alive
  58.  *============================================================================
  59.  */
  60.  
  61. var DoubleX_RMMV = DoubleX_RMMV || {};
  62. DoubleX_RMMV["Unison Item YEP_X_BattleSysATB"] = 'v1.00a';
  63.  
  64. /*============================================================================
  65.  *    ## Plugin Implementations                                              
  66.  *       You need not edit this part as it's about how this plugin works      
  67.  *----------------------------------------------------------------------------
  68.  *    # Plugin Support Info:                                                  
  69.  *      1. Prerequisites                                                      
  70.  *         - Solid understanding on the implementations of                    
  71.  *           Yanfly Engine Plugins - Battle System - Active Turn Battle      
  72.  *         - Decent Javascript coding proficiency to fully comprehend this    
  73.  *           plugin                                                          
  74.  *      2. Function documentation                                            
  75.  *         - The 1st part describes why this function's rewritten/extended for
  76.  *           rewritten/extended functions or what the function does for new  
  77.  *           functions                                                        
  78.  *         - The 2nd part describes what the arguments of the function are    
  79.  *         - The 3rd part informs which version rewritten, extended or created
  80.  *           this function                                                    
  81.  *         - The 4th part informs whether the function's rewritten or new    
  82.  *         - The 5th part informs whether the function's a real or potential  
  83.  *           hotspot                                                          
  84.  *         - The 6th part describes how this function works for new functions
  85.  *           only, and describes the parts added, removed or rewritten for    
  86.  *           rewritten or extended functions only                            
  87.  *         Example:                                                          
  88.  * /*----------------------------------------------------------------------
  89.  *  *    Why rewrite/extended/What this function does                      
  90.  *  *----------------------------------------------------------------------*/
  91. /* // arguments: What these arguments are                                    
  92.  * functionName = function(arguments) { // Version X+; Hotspot                
  93.  *     // Added/Removed/Rewritten to do something/How this function works    
  94.  *     functionContents                                                      
  95.  *     //                                                                    
  96.  * } // functionName                                                          
  97.  *----------------------------------------------------------------------------*/
  98.  
  99. if (DoubleX_RMMV["Unison Item Config"]) {
  100.  
  101. if (DoubleX_RMMV["Unison Item Default"]) {
  102.  
  103. if (Imported.YEP_X_BattleSysATB) {
  104.  
  105. (function(UI, ATB) {
  106.  
  107.     'use strict';
  108.  
  109.     ATB.BattleManager = {};
  110.     var BMATB = ATB.BattleManager;
  111.  
  112.     /*------------------------------------------------------------------------
  113.      *    New public instance variable                                        
  114.      *------------------------------------------------------------------------*/
  115.     // The cached mapping from async unison skills/items to all inputted actors
  116.     Object.defineProperty(BattleManager, 'asyncUnisonItems', {
  117.         get: function() { return this._asyncUnisonItems; },
  118.         configurable: true
  119.     });
  120.  
  121.     BattleManager.actionCastAnimation = function() {
  122.       if (!$gameSystem.isSideView() && this._subject.isActor()) return true;
  123.       if (!this._action.isAttack() && !this._action.isGuard() &&
  124.       this._action.isSkill()) {
  125.         // Rewritten
  126.         var ani = this._action.item().castAnimation;
  127.         if (ani > 0) {
  128.           var actorIds = this._action.item().meta.unisonItemActors;
  129.           if (actorIds.length > 1) {
  130.               var actors = actorIds.map(function(actorId) {
  131.                   return $gameActors.actor(actorId);
  132.               });
  133.               this._logWindow.showAnimation(this._subject, actors, ani);
  134.           } else {
  135.               this._logWindow.showAnimation(this._subject, [this._subject], ani);
  136.           }
  137.         }
  138.         //
  139.       }
  140.       return true;
  141.     }; //BattleManager.actionCastAnimation
  142.  
  143.     BattleManager.endATBAction = function() {
  144.         if (Imported.YEP_BattleEngineCore) {
  145.           if (this._processingForcedAction) this._phase = this._preForcePhase;
  146.           this._processingForcedAction = false;
  147.         }
  148.         if (this._subject) this._subject.onAllActionsEnd();
  149.         if (this.updateEventMain()) return;
  150.         BMATB.endATBAct.call(this); // Rewritten
  151.         if (this.loadPreForceActionSettings()) return;
  152.         this.updateBattlerATB(true);
  153.         var chargedBattler = this.getChargedATBBattler();
  154.         if (chargedBattler) {
  155.           this.startATBAction(chargedBattler);
  156.         } else {
  157.           this.setATBPhase();
  158.         }
  159.     }; // BattleManager.endATBAction
  160.  
  161.     BMATB.setup = BattleManager.setup;
  162.     BattleManager.setup = function(troopId, canEscape, canLose) {
  163.         BMATB.setup.apply(this, arguments);
  164.         this._asyncUnisonItems = {}; // Added
  165.     }; // BattleManager.setup
  166.  
  167.     BMATB.selectNextCommand = BattleManager.selectNextCommand;
  168.     BattleManager.selectNextCommand = function() {
  169.         if (this.isATB()) {
  170.           if (!this.actor()) return this.setATBPhase();
  171.           this.resetNonPartyActorATB();
  172.           GBBATB.markUnisonActors.call(this.actor()); // Added
  173.           this.actor().setupATBCharge();
  174.           this.actor().spriteStepBack();
  175.           this.actor().requestMotionRefresh();
  176.           this._actorIndex = undefined;
  177.           var chargedBattler = this.getChargedATBBattler();
  178.           if (chargedBattler) {
  179.             this.startATBAction(chargedBattler);
  180.           } else {
  181.             this.setATBPhase();
  182.           }
  183.         } else {
  184.           BMATB.selectNextCommand.apply(this, arguments);
  185.         }
  186.     }; // BattleManager.selectNextCommand
  187.  
  188.     /*------------------------------------------------------------------------
  189.      *    Removes battlers that are no longer waiting for async unison item  
  190.      *------------------------------------------------------------------------*/
  191.     // battler: The battler needed for a marked async unison skill/item
  192.     BMATB.removeAsyncUnisonBattler = function(battler) {
  193.         if (!this._asyncUnisonItems) return;
  194.         var index;
  195.         // The 1st actor in the async unison skill/item actor list's the invoker
  196.         Object.keys(this._asyncUnisonItems).forEach(function(itemId) {
  197.             index = this._asyncUnisonItems[itemId].indexOf(battler);
  198.             if (index > 0) { this._asyncUnisonItems[itemId].splice(index, 1); }
  199.         }, this);
  200.         //
  201.     }; // BMATB.removeAsyncUnisonActor
  202.  
  203.     /*------------------------------------------------------------------------
  204.      *    Ends the ATB Turn for all unison actors if unison skill/item's used
  205.      *------------------------------------------------------------------------*/
  206.     BMATB.endATBAct = function() {
  207.         var item = this._action.item();
  208.         this._asyncUnisonItems[item.id] = [];
  209.         var ids = item.meta.unisonItemActors;
  210.         BMATB.callUnisonActors.call(this, this._subject, ids, 'endTurnAllATB');
  211.     }; // BMATB.endATBAct
  212.  
  213.     /*------------------------------------------------------------------------
  214.      *    Asks each unison actor of act to call its battler function func    
  215.      *------------------------------------------------------------------------*/
  216.     /* invoker: The unison invoker
  217.      * actorIds: The list of ids of actors needed for the unison skill/item
  218.      * func: The battler function to be called by all unison actors
  219.      */
  220.     BMATB.callUnisonActors = function(invoker, actorIds, func) {
  221.         invoker[func]();
  222.         if (actorIds.length <= 1) { return; }
  223.         var actor;
  224.         actorIds.forEach(function(actorId) {
  225.             if (actorId === invoker.actorId()) { return; }
  226.             actor = $gameActors.actor(actorId);
  227.             if (!actor) { return; }
  228.             actor[func]();
  229.         });
  230.     }; // BMATB.callUnisonActors
  231.  
  232.     var GBB = UI.Game_BattlerBase;
  233.     ATB.Game_BattlerBase = {};
  234.     var GBBATB = ATB.Game_BattlerBase;
  235.  
  236.     Game_BattlerBase.prototype.canInput = function() {
  237.         if (!GBB.canInput.apply(this, arguments)) { return false; }
  238.         if (BattleManager.isATB()) { return true; } // Added
  239.         if (!this.isActor() || !$gameParty.inBattle()) { return true; }
  240.         return this._unisonItemNumInputs < this._actions.length;
  241.     }; // Game_BattlerBase.prototype.canInput
  242.  
  243.     GBBATB.canUseUnisonSkill = GBB.canUseUnisonSkill;
  244.     GBB.canUseUnisonSkill = function(skill) {
  245.         // Rewritten to check the skill usability for all unison invokees
  246.         if (!BattleManager.isATB()) {
  247.             return GBBATB.canUseUnisonSkill.apply(this, arguments);
  248.         }
  249.         var mems = $gameParty.aliveMembers();
  250.         var actor, actorIds = skill.meta.unisonItemActors;
  251.         var learnFlags = skill.meta.unisonItemActorLearn;
  252.         for (var index = 0, length = actorIds.length; index < length; index++) {
  253.             actor = mems.filter(function(mem) {
  254.                 return mem.actorId() === actorIds[index];
  255.             })[0];
  256.             if (!actor) { return false; }
  257.             if (learnFlags[index] && actor.skills().every(function(s) {
  258.                 return s !== skill;
  259.             })) { return false; }
  260.         }
  261.         return true;
  262.         //
  263.     }; // GBB.canUseUnisonSkill
  264.  
  265.     GBBATB.canUseUnisonItem = GBB.canUseUnisonItem;
  266.     GBB.canUseUnisonItem = function(item) {
  267.         // Rewritten to check if all unison invokees are alive
  268.         if (!BattleManager.isATB()) {
  269.             return GBBATB.canUseUnisonItem.apply(this, arguments);
  270.         }
  271.         if (!this.meetsItemConditions(item)) { return false; }
  272.         var mems = $gameParty.aliveMembers();
  273.         var actor, actorIds = item.meta.unisonItemActors;
  274.         for (var index = 0, length = actorIds.length; index < length; index++) {
  275.             if (actorIds[index] === this.actorId()) { continue; }
  276.             if (!mems.filter(function(mem) {
  277.                 return mem.actorId() === actorIds[index];
  278.             })[0]) { return false; }
  279.         }
  280.         return true;
  281.         //
  282.     }; // GBB.canUseUnisonItem
  283.  
  284.     GBBATB.markUnisonActors = function() {
  285.         var item = this.currentAction().item();
  286.         if (!item) { return; }
  287.         this._unisonItemActors = item.meta.unisonItemActors;
  288.         if (item.meta.unisonItemActors.length <= 1) { return; }
  289.         GBBATB.markAsyncUnisonItemActors.call(this, item);
  290.     }; // GBBATB.markUnisonActors
  291.  
  292.     /*------------------------------------------------------------------------
  293.      *    Executes the async unison item when all unison actors inputted it  
  294.      *------------------------------------------------------------------------*/
  295.     // item: The current async unison skill/item
  296.     GBBATB.markAsyncUnisonItemActors = function(item) {
  297.         if (!BattleManager.asyncUnisonItems[item.id]) {
  298.             BattleManager.asyncUnisonItems[item.id] = [];
  299.         }
  300.         var actors = BattleManager.asyncUnisonItems[item.id];
  301.         // The 1st actor in the async unison skill/item actor list's the invoker
  302.         actors.push(this);
  303.         if (actors.length !== this._unisonItemActors.length) { return; }
  304.         var actorIds = this._unisonItemActors, func = 'setupATBCharge';
  305.         BMATB.callUnisonActors.call(BattleManager, actors[0], actorIds, func);
  306.         actors.forEach(function(actor) {
  307.             if (actor) { actor.isUnisonItemReady = true; }
  308.         });
  309.         //
  310.     }; // GBBATB.markAsyncUnisonItemActors
  311.  
  312.     ATB.Game_Battler = {};
  313.     var GBATB = ATB.Game_Battler;
  314.  
  315.     /*------------------------------------------------------------------------
  316.      *    New public instance variables                                      
  317.      *------------------------------------------------------------------------*/
  318.     Object.defineProperties(Game_Battler.prototype, {
  319.         // The cached list of ids of all unison actors
  320.         'unisonItemActors': {
  321.             get: function() { return this._unisonItemActors; },
  322.             set: function(actorIds) { this._unisonItemActors = actorIds; },
  323.             configurable: true
  324.         },
  325.         // The flag showing whether the unison skill/item can be executed
  326.         'isUnisonItemReady': {
  327.             get: function() { return this._isUnisonItemReady; },
  328.             set: function(ready) { this._isUnisonItemReady = ready; },
  329.             configurable: true
  330.         }
  331.     });
  332.  
  333.     GBATB.initMembers = Game_Battler.prototype.initMembers;
  334.     Game_Battler.prototype.initMembers = function() {
  335.         GBATB.initMembers.apply(this, arguments);
  336.         GBATB.resetUnisonItem.call(this); // Added
  337.     }; // Game_Battler.prototype.initMembers
  338.  
  339.     GBATB.onAllActionsEnd = Game_Battler.prototype.onAllActionsEnd;
  340.     Game_Battler.prototype.onAllActionsEnd = function() {
  341.         GBATB.onAllActionsEnd.apply(this, arguments);
  342.         GBATB.resetUnisonItem.call(this); // Added
  343.     }; // Game_Battler.prototype.onAllActionsEnd
  344.  
  345.     GBATB.resetAllATB = Game_Battler.prototype.resetAllATB;
  346.     Game_Battler.prototype.resetAllATB = function() {
  347.         GBATB.resetAllATB.apply(this, arguments);
  348.         GBATB.resetUnisonItem.call(this); // Added
  349.     }; // Game_Battler.prototype.resetAllATB
  350.  
  351.     GBATB.resetUnisonItem = function() {
  352.         this._unisonItemActors = [];
  353.         this._isUnisonItemReady = false;
  354.         BMATB.removeAsyncUnisonBattler.call(BattleManager, this);
  355.     }; // GBATB.resetUnisonItem
  356.  
  357.     /*------------------------------------------------------------------------
  358.      *    Ensures the charging value is the same for all unison actors        
  359.      *------------------------------------------------------------------------*/
  360.     GBATB.updateUnisonTick = function() {
  361.         var actors = this._unisonItemActors.map(function(actorId) {
  362.             return $gameActors.actor(actorId);
  363.         });
  364.         if (!actors.every(function(actor) { return actor.isAlive(); })) {
  365.             this.resetAllATB();
  366.             return;
  367.         } else if (!actors.every(function(actor) {
  368.             return actor.isUnisonItemReady && actor.isATBCharging();
  369.         })) {
  370.             this.setATBCharge(0);
  371.             return;
  372.         }
  373.         var minDiff = Number.EPSILON * this.atbChargeDenom();
  374.         var rule = $gameSystem.unisonItem.unisonFunctionRule;
  375.         var val = UI.RULES.call(this, rule, actors.map(function(actor) {
  376.             return actor.atbCharge();
  377.         }));
  378.         actors.forEach(function(actor) {
  379.             // Ensures the unison invoker will always be the fastest
  380.             if (actor === this) { val += minDiff; }
  381.             //
  382.             actor.setATBCharge(val);
  383.         }, this);
  384.     };
  385.  
  386.     var GA = UI.Game_Actor;
  387.     ATB.Game_Actor = {};
  388.     var GAATB = ATB.Game_Actor;
  389.  
  390.     Game_Actor.prototype.selectNextCommand = function() {
  391.         // Added
  392.         if (!BattleManager.isATB()) {
  393.             var maxIndex = this._actions.length - this._unisonItemNumInputs - 1;
  394.             if (this._actionInputIndex>= maxIndex) { return false; }
  395.         }
  396.         //
  397.         return GA.selectNextCommand.apply(this, arguments);
  398.     }; // Game_Actor.prototype.selectNextCommand
  399.  
  400.     /*------------------------------------------------------------------------
  401.      *    Ensures the charging value is the same for all unison actors        
  402.      *------------------------------------------------------------------------*/
  403.     Game_Party.prototype.updateTick = function() { // New
  404.         Game_Unit.prototype.updateTick.call(this);
  405.         this.aliveMembers().filter(function(mem) {
  406.             return mem.unisonItemActors.length > 1;
  407.         }).forEach(function(mem) { GBATB.updateUnisonTick.call(mem); });
  408.     }; // Game_Party.prototype.updateTick
  409.  
  410.     var WBL = UI.Window_BattleLog;
  411.  
  412.     Window_BattleLog.prototype.displayAction = function(subject, item) {
  413.         WBL.displayAction.apply(this, arguments); // Rewritten
  414.     }; // Window_BattleLog.prototype.displayAction
  415.  
  416. })(DoubleX_RMMV.Unison_Item, DoubleX_RMMV.Unison_Item_YEP_X_BattleSysATB = {});
  417.  
  418. } else {
  419.     alert('Place Unison Item YEP_X_BattleSysATB below YEP_X_BattleSysATB.');
  420. }
  421.  
  422. } else {
  423.     alert('Place Unison Item YEP_X_BattleSysATB below Unison Item Default.');
  424. }
  425.  
  426. } else {
  427.     alert('Place Unison Item YEP_X_BattleSysATB below Unison Item Config.');
  428. }
  429.  
  430. /*============================================================================*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement