Advertisement
Double_X

DoubleX RMMV Substitute Edit v100b

Dec 19th, 2015 (edited)
691
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 Substitute Edit                                          
  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.  *      Abilities:                                                            
  15.  *      1. Little Javascript coding proficiency to fully utilize this plugin  
  16.  *----------------------------------------------------------------------------
  17.  *    # Links                                                                
  18.  *      This plugin:                                                          
  19.  *      1. http://pastebin.com/6TGXWV1w                                      
  20.  *      Mentioned Patreon Supporters:
  21.  *      https://www.patreon.com/posts/71738797
  22.  *----------------------------------------------------------------------------
  23.  *    # Author                                                                
  24.  *      DoubleX                                                              
  25.  *----------------------------------------------------------------------------
  26.  *    # Changelog                                                            
  27.  *      v1.00b(GMT 1500 21-12-2015):                                          
  28.  *      1. Fixed typos and calling function via call instead of directly bug  
  29.  *      v1.00a(GMT 1500 19-12-2015):                                          
  30.  *      1. 1st version of this plugin finished                                
  31.  *============================================================================*/
  32. /*:
  33.  * @plugindesc Lets you sets conditions determining the battler to substitute
  34.  * @author DoubleX
  35.  *
  36.  * @param substituteMissed
  37.  * @desc Sets if substitutions will take place if the skill/item would miss
  38.  *       This feature's not implemented yet but will possibly be implemented
  39.  * @default false
  40.  *
  41.  * @param substituteEvaded
  42.  * @desc Sets if substitutions will take place if the original target would
  43.  *       evade the skill/item
  44.  *       This feature's not implemented yet but will possibly be implemented
  45.  * @default false
  46.  *
  47.  * @param substituteCountered
  48.  * @desc Sets if substitutions will take place if the original target would
  49.  *       counterattack/reflect the skill/item
  50.  * @default false
  51.  *
  52.  * @param substituteCounter
  53.  * @desc Sets if substitutions will take place if the skill/item's a
  54.  *       counterattack/reflection of that of another action
  55.  *       Might cause infinite counter loop with substituteBattlerCounter
  56.  * @default false
  57.  *
  58.  * @param substituteBattlerMiss
  59.  * @desc Sets if the skill/item can miss the substitute battler
  60.  *       This feature's not implemented yet but will possibly be implemented
  61.  * @default true
  62.  *
  63.  * @param substituteBattlerEvade
  64.  * @desc Sets if the substitute battler can evade the skill/item
  65.  *       This feature's not implemented yet but will possibly be implemented
  66.  * @default true
  67.  *
  68.  * @param substituteBattlerCounter
  69.  * @desc Sets if the substitute battler can counterattack/reflect the
  70.  *       skill/item
  71.  *       Might cause infinite counter loop with substituteCounter
  72.  * @default true
  73.  *
  74.  * @param substituteBattlerFilters
  75.  * @desc Sets the list of filters determining which battler to substitute
  76.  *       Only movable battlers having the substitute flag will be considered
  77.  *       The battlers passing the ith filter will proceed to the (i + 1)th one
  78.  *       If only 1 battler passes the ith filter, all the remaining (i + j)th
  79.  *       ones won't be used
  80.  *       If no battler pass the ith filter, all battlers passing the (i - 1)th
  81.  *       one will proceed to the (i + 1)th one
  82.  *       Available filters:
  83.  *       hpMp0 - The battler having 0 hp/mp
  84.  *       immortal - The battler being immune to death
  85.  *       maxCntMrf - The battler having the maximum cnt/mrf
  86.  *       maxEvaMev - The battler having the maximum eva/mev
  87.  *       maxPdrMdr - The battler having the maximum pdr/mdr
  88.  *       maxHpMp - The battler having the maximum hp/mp
  89.  *       maxGrd - The battler having the maximum grd
  90.  *       maxCev - The battler having the maximum cev
  91.  *       All unavailable filters in the list will be ignored
  92.  *       The battler having the smallest party/troop member index will be the
  93.  *       substitute battler if more than 1 battlers pass all filters in the
  94.  *       list
  95.  * @default hpMp0 immortal maxCntMrf maxEvaMev maxPdrMdr maxHpMp maxGrd maxCev
  96.  *
  97.  * @help
  98.  * The plugin file name must be the same as DoubleX_RMMV.Substitute_Edit_File,
  99.  * which must be edited by editing the plugin js file directly
  100.  * The default value of DoubleX_RMMV.Substitute_Edit_File is
  101.  * DoubleX RMMV Substitute Edit v100b
  102.  *============================================================================
  103.  *    ## Plugin Call Info                                                    
  104.  *----------------------------------------------------------------------------
  105.  *    # Configuration manipulations                                          
  106.  *      1. $gameSystem.substituteEdit.param                                  
  107.  *         - Returns the value of param listed in the plugin manager          
  108.  *      2. $gameSystem.substituteEdit.param = val                            
  109.  *         - Sets the value of param listed in the plugin manager as val      
  110.  *         - All $gameSystem.substituteEdit.param changes will be saved      
  111.  *============================================================================
  112.  */
  113.  
  114. "use strict";
  115. var DoubleX_RMMV = DoubleX_RMMV || {};
  116. DoubleX_RMMV["Substitute Edit"] = "v1.00b";
  117.  
  118. // The plugin file name must be the same as DoubleX_RMMV.Substitute_Edit_File
  119. DoubleX_RMMV.Substitute_Edit_File = "DoubleX RMMV Substitute Edit v100b";
  120.  
  121. /*============================================================================
  122.  *    ## Plugin Implementations                                              
  123.  *       You need not edit this part as it's about how this plugin works      
  124.  *----------------------------------------------------------------------------
  125.  *    # Plugin Support Info:                                                  
  126.  *      1. Prerequisites                                                      
  127.  *         - Some Javascript coding proficiency to fully comprehend this      
  128.  *           plugin                                                          
  129.  *      2. Function documentation                                            
  130.  *         - The 1st part describes why this function's rewritten/extended for
  131.  *           rewritten/extended functions or what the function does for new  
  132.  *           functions                                                        
  133.  *         - The 2nd part describes what the arguments of the function are    
  134.  *         - The 3rd part informs which version rewritten, extended or created
  135.  *           this function                                                    
  136.  *         - The 4th part informs whether the function's rewritten or new    
  137.  *         - The 5th part informs whether the function's a real or potential  
  138.  *           hotspot                                                          
  139.  *         - The 6th part describes how this function works for new functions
  140.  *           only, and describes the parts added, removed or rewritten for    
  141.  *           rewritten or extended functions only                            
  142.  *         Example:                                                          
  143.  * /*----------------------------------------------------------------------
  144.  *  *    Why rewrite/extended/What this function does                      
  145.  *  *----------------------------------------------------------------------*/
  146. /* // arguments: What these arguments are                                    
  147.  * functionName = function(arguments) { // Version X+; Hotspot                
  148.  *     // Added/Removed/Rewritten to do something/How this function works    
  149.  *     functionContents                                                      
  150.  *     //                                                                    
  151.  * } // functionName                                                          
  152.  *----------------------------------------------------------------------------*/
  153.  
  154. DoubleX_RMMV.Substitute_Edit = {};
  155. (function(SE) {
  156.  
  157.     SE.BattleManager = {};
  158.     var BM = SE.BattleManager;
  159.  
  160.     /*------------------------------------------------------------------------
  161.      *    New public instance variable                                        
  162.      *------------------------------------------------------------------------*/
  163.     // Read by Game_Unit to get the currently executing action
  164.     Object.defineProperty(BattleManager, "action", {
  165.         get: function() { return this._action; },
  166.         configurable: true
  167.     });
  168.  
  169.     BattleManager.invokeAction = function(subject, target) {
  170.         this._logWindow.push('pushBaseLine');
  171.         BM.invokeAction.call(this, subject, target); // Rewritten
  172.         subject.setLastTarget(target);
  173.         this._logWindow.push('popBaseLine');
  174.         this.refreshStatus();
  175.     }; // BattleManager.invokeAction
  176.  
  177.     BattleManager.invokeNormalAction = function(subject, target) {
  178.         BM.invokeNormalAction.call(this, subject, target); // Rewritten
  179.         this._logWindow.displayActionResults(subject, realTarget);
  180.     }; // BattleManager.invokeNormalAction
  181.  
  182.     BM.invokeCounterAttack = BattleManager.invokeCounterAttack;
  183.     BattleManager.invokeCounterAttack = function(subject, target) {
  184.         // Added
  185.         if ($gameSystem.substituteEdit.substituteCounter) {
  186.             return BM.invokeCounterSubstitute.call(this, subject, target);
  187.         }
  188.         //
  189.         BM.invokeCounterAttack.apply(this, arguments);
  190.     }; // BattleManager.invokeCounterAttack
  191.  
  192.     BM.invokeMagicReflection = BattleManager.invokeMagicReflection;
  193.     BattleManager.invokeMagicReflection = function(subject, target) {
  194.         if ($gameSystem.substituteEdit.substituteCounter) {
  195.             this._logWindow.displayReflection(target);
  196.             BM.invokeNormalAction.call(this, target, subject);
  197.             this._logWindow.displayActionResults(subject, subject);
  198.             return;
  199.         }
  200.         BM.invokeMagicReflection.apply(this, arguments);
  201.     }; // BattleManager.invokeMagicReflection
  202.  
  203.     BM.invokeAction = function(subject, target) {
  204.         var se = $gameSystem.substituteEdit;
  205.         var substitute = BM.substituteBattler.call(this, target);
  206.         if (se.substituteCountered && substitute !== target) {
  207.             return this.invokeNormalAction(subject, target);
  208.         } else if (Math.random() < this._action.itemCnt(target)) {
  209.             return this.invokeCounterAttack(subject, target);
  210.         } else if (Math.random() < this._action.itemMrf(target)) {
  211.             return this.invokeMagicReflection(subject, target);
  212.         }
  213.         this.invokeNormalAction(subject, target);
  214.     }; // BM.invokeAction
  215.  
  216.     BM.substituteBattler = function(target) {
  217.         if (!this.checkSubstitute(target)) { return target; }
  218.         return target.friendsUnit().substituteBattler();
  219.     }; // BM.substituteBattler
  220.  
  221.     BM.invokeNormalAction = function(subject, target) {
  222.         var realTarget;
  223.         if (!$gameSystem.substituteEdit.substituteBattlerCounter) { return; }
  224.         realTarget = this.applySubstitute(target);
  225.         if (realTarget === target) { return; }
  226.         if (Math.random() < this._action.itemCnt(realTarget)) {
  227.             return this.invokeCounterAttack(subject, realTarget);
  228.         } else if (Math.random() < this._action.itemMrf(realTarget)) {
  229.             return this.invokeMagicReflection(subject, realTarget);
  230.         }
  231.         this._action.apply(realTarget);
  232.     }; // BM.invokeNormalAction
  233.  
  234.     BM.invokeCounterSubstitute = function(subject, target) {
  235.         var lastAct = this._action;
  236.         this._action = new Game_Action(target);
  237.         this._action.setAttack();
  238.         this._logWindow.displayCounter(target);
  239.         BM.invokeNormalAction.call(this, target, subject);
  240.         this._logWindow.displayActionResults(subject, subject);
  241.         this._action = lastAct;
  242.     }; // BM.invokeCounterSubstitute
  243.  
  244.     SE.Game_System = {};
  245.     var GS = SE.Game_System;
  246.  
  247.     /*------------------------------------------------------------------------
  248.      *    New public instance variable                                        
  249.      *------------------------------------------------------------------------*/
  250.     // The storage of all configuration values
  251.     Object.defineProperty(Game_System.prototype, "substituteEdit", {
  252.         get: function() { return this._substituteEdit; },
  253.         configurable: true
  254.     });
  255.  
  256.     GS.initialize = Game_System.prototype.initialize;
  257.     Game_System.prototype.initialize = function() {
  258.         GS.initialize.apply(this, arguments);
  259.         GS.initSubstituteEditParams.call(this); // Added
  260.     }; // Game_System.prototype.initialize
  261.  
  262.     GS.initSubstituteEditParams = function() {
  263.         var params, filters;
  264.         this._substituteEdit = {};
  265.         params = PluginManager.parameters(DoubleX_RMMV.Substitute_Edit_File);
  266.         Object.keys(params).forEach(function(param) {
  267.             this._substituteEdit[param] = params[param] === "true";
  268.         }, this);
  269.         filters = params.substituteBattlerFilters.split(/ +/);
  270.         this._substituteEdit.substituteBattlerFilters = filters;
  271.     }; // GS.initSubstituteEditParams
  272.  
  273.     SE.Game_Action = {};
  274.     var GA = SE.Game_Action;
  275.  
  276.     /*------------------------------------------------------------------------
  277.      *    Helper function easing checkings in filtering substitute battlers  
  278.      *------------------------------------------------------------------------*/
  279.     GA.effectType = function() {
  280.         return this.isHpEffect() ? "hp" : this.isMpEffect() ? "mp" : null;
  281.     }; // GA.effectType
  282.  
  283.     /*------------------------------------------------------------------------
  284.      *    Helper function easing checkings in filtering substitute battlers  
  285.      *------------------------------------------------------------------------*/
  286.     GA.hitType = function() {
  287.         return this.isPhysical() ? "pdr" : this.isMagical() ? "mdr" : null;
  288.     }; // GA.hitType
  289.  
  290.     SE.Game_Unit = {};
  291.     var GU = SE.Game_Unit;
  292.  
  293.     Game_Unit.prototype.substituteBattler = function() {
  294.         // Rewritten to use all filters in the filter list sequentially as well
  295.         var mems = this.members();
  296.         mems = mems.filter(function(mem) { return mem.isSubstitute(); });
  297.         if (mems.length === 0) { return null; }
  298.         if (mems.length === 1) { return mems[0]; }
  299.         return GU.substituteBattler(mems);
  300.         //
  301.     }; // Game_Unit.prototype.substituteBattler
  302.  
  303.     // mems: All members that can substitute
  304.     GU.substituteBattler = function(mems) {
  305.         var tempMems, eT = GA.effectType.call(BattleManager.action);
  306.         var hT = GA.hitType.call(BattleManager.action);
  307.         var filters = $gameSystem.substituteEdit.substituteBattlerFilters;
  308.         for (var index = 0, length = filters.length; index < length; index++) {
  309.             tempMems = GU.substituteBattlers(mems, filters[index], eT, hT);
  310.             if (tempMems.length === 1) { return tempMems[0]; }
  311.             if (tempMems.length > 1) { mems = tempMems; }
  312.         }
  313.         return mems[0];
  314.     }; // GU.substituteBattler
  315.  
  316.     /* mems: All members that can substitute
  317.      * filter: The added filter applied to all members that can substitute
  318.      * effectType: The hp/mp effect type of the currently executing action
  319.      * hitType: The physical/magical hit type of the currently executing action
  320.      */
  321.     GU.substituteBattlers = function(mems, filter, effectType, hitType) {
  322.         // Calls the filter function corresponding to the passed filter
  323.         switch (filter) {
  324.             case "hpMp0": return GU.hpMp0Battlers(mems, effectType);
  325.             case "immortal": return GU.immortalBattlers(mems);
  326.             case "maxCntMrf": return GU.maxCntMrfBattlers(mems, hitType);
  327.             case "maxEvaMev": return GU.maxEvaMevBattlers(mems, hitType);
  328.             case "maxPdrMdr":
  329.                 return hitType ? GU.maxParamBattlers(mems, hitType) : mems;
  330.             case "maxHpMp": return GU.maxHpMpBattlers(mems, effectType);
  331.             case "maxGrd": return GU.maxParamBattlers(mems, "grd");
  332.             case "maxCev": return GU.maxParamBattlers(mems, "cev");
  333.             default:
  334.                 console.log("Unavailable substitute battler filter " + filter);
  335.                 return mems;
  336.         }
  337.         //
  338.     }; // GU.substituteBattlers
  339.  
  340.     /* mems: All members that can substitute
  341.      * effectType: The hp/mp effect type of the currently executing action
  342.      */
  343.     GU.hpMp0Battlers = function(mems, effectType) {
  344.         if (!effectType) { return mems; }
  345.         return mems.filter(function(mem) { return mem[effectType] === 0; });
  346.     }; // GU.hpMp0Battlers
  347.  
  348.     // mems: All members that can substitute
  349.     GU.immortalBattlers = function(mems) {
  350.         return mems.filter(function(mem) {
  351.             return mem.isStateResist(mem.deathStateId());
  352.         });
  353.     }; // GU.immortalBattlers
  354.  
  355.     /* mems: All members that can substitute
  356.      * hitType: The physical/magical hit type of the currently executing action
  357.      */
  358.     GU.maxCntMrfBattlers = function(mems, hitType) {
  359.         var counter = hitType === "pdr" ? "cnt" : "mdr" ? "mrf" : null;
  360.         return counter ? GU.maxParamBattlers(mems, counter) : mems;
  361.     }; // GU.maxCntMrfBattlers
  362.  
  363.     /* mems: All members that can substitute
  364.      * hitType: The physical/magical hit type of the currently executing action
  365.      */
  366.     GU.maxEvaMevBattlers = function(mems, hitType) {
  367.         var evade = hitType === "pdr" ? "eva" : "mdr" ? "mev" : null;
  368.         return evade ? GU.maxParamBattlers(mems, evade) : mems;
  369.     }; // GU.maxEvaMevBattlers
  370.  
  371.     /* mems: All members that can substitute
  372.      * effectType: The hp/mp effect type of the currently executing action
  373.      */
  374.     GU.maxHpMpBattlers = function(mems, effectType) {
  375.         return effectType ? GU.maxParamBattlers(mems, effectType) : mems;
  376.     }; // GU.maxHpMpBattlers
  377.  
  378.     /* mems: All members that can substitute
  379.      * param: The param/ExParam/SpParam used to filter the substitute battler
  380.      */
  381.     GU.maxParamBattlers = function(mems, param) {
  382.         var maxParam = mems.slice(0).sort(function(a, b) {
  383.             return b[param] - a[param];
  384.         })[0][param];
  385.         return mems.filter(function(mem) { return mem[param] === maxParam; });
  386.     }; // GU.maxParamBattlers
  387.  
  388. })(DoubleX_RMMV.Substitute_Edit);
  389.  
  390. /*============================================================================*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement