Advertisement
Double_X

DoubleX RMMV Intercept Item v100b

Dec 16th, 2015 (edited)
477
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 Intercept Item                                          
  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/s12dFf6S                                      
  20.  *      Video:                                                                
  21.  *      1. https://www.youtube.com/watch?v=jsuqdjY3FyE                        
  22.  *      Mentioned Patreon Supporters:
  23.  *      https://www.patreon.com/posts/71738797
  24.  *----------------------------------------------------------------------------
  25.  *    # Author                                                                
  26.  *      DoubleX                                                              
  27.  *----------------------------------------------------------------------------
  28.  *    # Changelog                                                            
  29.  *      v1.00b(GMT 1000 30-1-2016):                                          
  30.  *      1. Fixed typo $dataStates(stateId) instead of $dataStates[stateId]    
  31.  *      2. Fixed undefined BM.interceptors when changing states outside battle
  32.  *      3. Fixed missing argument item in GB.possibleInterceptStates bug      
  33.  *      4. Fixed searching interceptors in the interceptor state id pairs bug
  34.  *      5. Fixed returning interceptor state id pair in GU.interceptor bug    
  35.  *      6. Fixed learning skills that are already learnt bug                  
  36.  *      7. Fixed passing a battler instead of an Array to showNormalAnimation
  37.  *      v1.00a(GMT 1500 16-12-2015):                                          
  38.  *      1. 1st version of this plugin finished                                
  39.  *============================================================================*/
  40. /*:
  41.  * @plugindesc Lets users set states intercepting skills/items conditionally
  42.  *             Designed to mimic FF5's Blue Magic and FF6's Runic command
  43.  * @author DoubleX
  44.  *
  45.  * @help
  46.  *============================================================================
  47.  *    ## Notetag Info                                                        
  48.  *----------------------------------------------------------------------------
  49.  *    # Skill/Item/State Notetags:                                            
  50.  *      1. <intercept item tier: x>                                          
  51.  *         - Lets battlers having states with this notetag intercept          
  52.  *           skills/items with this notetag if x is positive for those states
  53.  *           and skills/items                                                
  54.  *         - If the intercept tiers of the states are greater than or equal to
  55.  *           that of the skills/items, they'll be intercepted if other        
  56.  *           conditions that are set by you are also met                      
  57.  *         - If more than 1 battler can intercept a skill/item, the one having
  58.  *           any intercept state for the shortest time will intercept it      
  59.  *         - If more than 1 state of the same battler can intercept a        
  60.  *           skill/item, the one having the highest priority will intercept it
  61.  *         - This notetag needs <ally intercept item> and/or                  
  62.  *           <foe intercept item> to be present as well to work              
  63.  *      2. <ally intercept item>                                              
  64.  *         - Interceptors having states with this notetag can intercept      
  65.  *           skills/items with this notetag if their users are allies and    
  66.  *           other conditions are met                                        
  67.  *         - Putting this notetag above <foe intercept item> means allies    
  68.  *           will always intercept the skills/items if enemies can also      
  69.  *           intercept them                                                  
  70.  *         - The ordering of <ally intercept item> and <foe intercept item>  
  71.  *           in skills/items to be intercepted will be used if intercepting  
  72.  *           states also has both of those notetags                          
  73.  *      3. <foe intercept item>                                              
  74.  *         - Interceptors having states with this notetag can intercept      
  75.  *           skills/items with this notetag if their users are foes and other
  76.  *           conditions are met                                              
  77.  *         - Putting this notetag above <ally intercept item> means foes will
  78.  *           always intercept the skills/items if enemies can also intercept  
  79.  *           them                                                            
  80.  *         - The ordering of <ally intercept item> and <foe intercept item>  
  81.  *           in skills/items to be intercepted will be used if intercepting  
  82.  *           states also has both of those notetags                          
  83.  *      4. <intercept item chance: x>                                        
  84.  *         - Interceptors having states with this notetag have a x% chance to
  85.  *           intercept skills/items that can be intercepted if other          
  86.  *           conditions are met                                              
  87.  *         - Skills/items that can be intercepted with this notetag have a x%
  88.  *           chance to be intercepted by interceptors if other conditions are
  89.  *           met                                                              
  90.  *         - The real chance of success is that of intercepting states        
  91.  *           multiplied by that of skills/items to be intercepted            
  92.  *         - If this notetag is absent, the chance of success will be 100%    
  93.  *      5. <intercept item mp>                                                
  94.  *         - Interceptors having states with this notetag absorb mp equal to  
  95.  *           the mp cost of the skills/items intercepted if those skills/items
  96.  *           also have this notetag                                          
  97.  *      6. <intercept item tp>                                                
  98.  *         - Interceptors having states with this notetag absorb tp equal to  
  99.  *           the tp cost of the skills/items intercepted if those skills/items
  100.  *           also have this notetag                                          
  101.  *      7. <hit intercept item mp>                                            
  102.  *         - Failed interceptions due to <intercept item mp limit> will cause
  103.  *           the skill/item to only hit the interceptor if both the          
  104.  *           skills/items and states have this notetag                        
  105.  *      8. <hit intercept item tp>                                            
  106.  *         - Failed interceptions due to <intercept item tp limit> will cause
  107.  *           the skill/item to only hit the interceptor if both the          
  108.  *           skills/items and states have this notetag                        
  109.  *      9. <intercept item learnt>                                            
  110.  *         - Only skills/items that are currently learnt by its battler can be
  111.  *           intercepted if both them and states have this notetag            
  112.  *      10. <intercept item usable>                                          
  113.  *          - Only skills/items that are currently usable by its battler can  
  114.  *            be intercepted if both them and states have this notetag        
  115.  *      11. <learn intercept item>                                            
  116.  *          - Successful interceptions will cause its battler to learn the    
  117.  *            intercepted skill/item if both them and states have this notetag
  118.  *            and they're not already learnt                                  
  119.  *----------------------------------------------------------------------------
  120.  *    # State Notetags:                                                      
  121.  *      1. <intercept item animation: id>                                    
  122.  *         - Animation with id id will be played upon successful interceptions
  123.  *      2. <intercept item count: x, f>                                      
  124.  *         - The intercepting state will worn off after its battler used it to
  125.  *           intercept x skills/items                                        
  126.  *         - Failed interceptions will also be counted is f is true          
  127.  *      3. <intercept item mp limit>                                          
  128.  *         - If this state's used to intercept skills/items and intercepting  
  129.  *           them would lead to the battler's mp being greater than that      
  130.  *           battler's mmp, the intercept will fail                          
  131.  *      4. <intercept item tp limit>                                          
  132.  *         - If this state's used to intercept skills/items and intercepting  
  133.  *           them would lead to the battler's tp being greater than that      
  134.  *           battler's maximum tp, the intercept will fail                    
  135.  *      5. <intercept item mcr>                                              
  136.  *         - The mp absorbed by the battler using this state to intercept    
  137.  *           skills/items will be the actual mp used by their users          
  138.  *============================================================================
  139.  *    ## Plugin Call Info                                                    
  140.  *----------------------------------------------------------------------------
  141.  *    # Skill/Item/State manipulations                                        
  142.  *      1. meta.interceptItemTier                                            
  143.  *         - Returns the intercept item tier in <intercept item tier: x>      
  144.  *      2. meta.interceptItemTier = tier                                      
  145.  *         - Sets the intercept item tier in <intercept item tier: x> as tier
  146.  *         - All meta.interceptItemTier changes can be saved if              
  147.  *           DoubleX RMMV Dynamic Data is used                                
  148.  *      3. meta.battlerInterceptItem                                          
  149.  *         - Returns the ally/foe intercept item tier in                      
  150.  *           <ally intercept item tier> and <foe intercept item tier> in the  
  151.  *           form of { ally: true, foe: true }                                
  152.  *         - Property name ally and foe will be defined only if the former and
  153.  *           latter notetags are used respectively                            
  154.  *         - The ordering of those property names is that of those notetags  
  155.  *      4. meta.battlerInterceptItem = { ally: true, foe: true }              
  156.  *         - Sets the ally/foe intercept item tier in                        
  157.  *           <ally intercept item tier> and <foe intercept item tier> in the  
  158.  *           form of { ally: true, foe: true }                                
  159.  *         - Property name ally and foe will be defined only if the former and
  160.  *           latter notetags are used respectively                            
  161.  *         - The ordering of those property names is that of those notetags  
  162.  *         - All meta.battlerInterceptItem changes can be saved if            
  163.  *           DoubleX RMMV Dynamic Data is used                                
  164.  *      5. meta.interceptItemChance                                          
  165.  *         - Returns the intercept item chance in <intercept item chance: x>  
  166.  *      6. meta.interceptItemChance = percent                                
  167.  *         - Sets the intercept item chance in <intercept item chance: x> as  
  168.  *           percent%                                                        
  169.  *         - All meta.interceptItemChance changes can be saved if            
  170.  *           DoubleX RMMV Dynamic Data is used                                
  171.  *      7. meta.interceptItemMp                                              
  172.  *         - Returns the intercept item mp flag in <intercept item mp>        
  173.  *      8. meta.interceptItemMp = flag                                        
  174.  *         - Sets the intercept item mp flag in <intercept item mp> as flag  
  175.  *         - All meta.interceptItemMp changes can be saved if                
  176.  *           DoubleX RMMV Dynamic Data is used                                
  177.  *      9. meta.interceptItemTp                                              
  178.  *         - Returns the intercept item tp flag in <intercept item tp>        
  179.  *      10. meta.interceptItemTp = flag                                      
  180.  *          - Sets the intercept item tp flag in <intercept item tp> as flag  
  181.  *          - All meta.interceptItemTp changes can be saved if                
  182.  *            DoubleX RMMV Dynamic Data is used                              
  183.  *      11. meta.hitInterceptItemMp                                          
  184.  *          - Returns the hit intercept item mp flag in                      
  185.  *            <hit intercept item mp>                                        
  186.  *      12. meta.hitInterceptItemMp = flag                                    
  187.  *          - Sets the hit intercept item mp flag in <hit intercept item mp>  
  188.  *            as flag                                                        
  189.  *          - All meta.hitInterceptItemMp changes can be saved if            
  190.  *            DoubleX RMMV Dynamic Data is used                              
  191.  *      13. meta.hitInterceptItemTp                                          
  192.  *          - Returns the hit intercept item tp flag in                      
  193.  *            <hit intercept item tp>                                        
  194.  *      14. meta.hitInterceptItemTp = flag                                    
  195.  *          - Sets the hit intercept item tp flag in <hit intercept item tp>  
  196.  *            as flag                                                        
  197.  *          - All meta.hitInterceptItemTp changes can be saved if            
  198.  *            DoubleX RMMV Dynamic Data is used                              
  199.  *      15. meta.interceptItemLearnt                                          
  200.  *          - Returns the intercept item learnt flag in                      
  201.  *            <intercept item learnt>                                        
  202.  *      16. meta.interceptItemLearnt = flag                                  
  203.  *          - Sets the intercept item learnt flag in <intercept item learnt>  
  204.  *            as flag                                                        
  205.  *          - All meta.interceptItemLearnt changes can be saved if            
  206.  *            DoubleX RMMV Dynamic Data is used                              
  207.  *      17. meta.interceptItemUsable                                          
  208.  *          - Returns the intercept item usable flag in                      
  209.  *            <intercept item usable>                                        
  210.  *      18. meta.interceptItemUsable = flag                                  
  211.  *          - Sets the intercept item usable flag in <intercept item usable>  
  212.  *            as flag                                                        
  213.  *          - All meta.interceptItemUsable changes can be saved if            
  214.  *            DoubleX RMMV Dynamic Data is used                              
  215.  *      19. meta.learnInterceptItem                                          
  216.  *          - Returns the learn intercept item flag in <learn intercept item>
  217.  *      20. meta.learnInterceptItem = flag                                    
  218.  *          - Sets the learn intercept item flag in <learn intercept item> as
  219.  *            flag                                                            
  220.  *          - All meta.learnInterceptItem changes can be saved if            
  221.  *            DoubleX RMMV Dynamic Data is used                              
  222.  *----------------------------------------------------------------------------
  223.  *    # State manipulations                                                  
  224.  *      1. meta.interceptItemAnimation                                        
  225.  *         - Returns the intercept item animation id in                      
  226.  *           <intercept item animation: id>                                  
  227.  *      2. meta.interceptItemAnimation = id                                  
  228.  *         - Sets the intercept item animation id in                          
  229.  *           <intercept item animation: id> as id                            
  230.  *         - All meta.interceptItemAnimation changes can be saved if          
  231.  *           DoubleX RMMV Dynamic Data is used                                
  232.  *      3. meta.interceptItemCount                                            
  233.  *         - Returns the intercept item count with the fail flag in the form  
  234.  *           of { count: count, fail: fail }                                  
  235.  *      4. meta.interceptItemCount = { count: count, fail: fail }            
  236.  *         - Sets the intercept item count with the fail flag as count and    
  237.  *           fail in the form of { count: count, fail: fail }                
  238.  *         - All meta.interceptItemCount changes can be saved if              
  239.  *           DoubleX RMMV Dynamic Data is used                                
  240.  *      5. meta.interceptItemMpLimit                                          
  241.  *         - Returns the intercept item mp limit flag in                      
  242.  *           <intercept item mp limit>                                        
  243.  *      6. meta.interceptItemMpLimit = flag                                  
  244.  *         - Sets the intercept item mp limit flag in                        
  245.  *           <intercept item mp limit> as flag                                
  246.  *         - All meta.interceptItemMpLimit changes can be saved if            
  247.  *           DoubleX RMMV Dynamic Data is used                                
  248.  *      7. meta.interceptItemTpLimit                                          
  249.  *         - Returns the intercept item tp limit flag in                      
  250.  *           <intercept item tp limit>                                        
  251.  *      8. meta.interceptItemTpLimit = flag                                  
  252.  *         - Sets the intercept item tp limit flag in                        
  253.  *           <intercept item tp limit> as flag                                
  254.  *         - All meta.interceptItemTpLimit changes can be saved if            
  255.  *           DoubleX RMMV Dynamic Data is used                                
  256.  *      9. meta.interceptItemMcr                                              
  257.  *        - Returns the intercept item mcr flag in <intercept item mcr>      
  258.  *      10. meta.interceptItemMcr = flag                                      
  259.  *          - Sets the intercept item mcr flag in <intercept item mcr> as flag
  260.  *          - All meta.interceptItemMcr changes can be saved if              
  261.  *            DoubleX RMMV Dynamic Data is used                              
  262.  *============================================================================
  263.  */
  264.  
  265. "use strict";
  266. var DoubleX_RMMV = DoubleX_RMMV || {};
  267. DoubleX_RMMV["Intercept Item"] = "v1.00b";
  268.  
  269. /*============================================================================
  270.  *    ## Plugin Implementations                                              
  271.  *       You need not edit this part as it's about how this plugin works      
  272.  *----------------------------------------------------------------------------
  273.  *    # Plugin Support Info:                                                  
  274.  *      1. Prerequisites                                                      
  275.  *         - Some Javascript coding proficiency to fully comprehend this      
  276.  *           plugin                                                          
  277.  *      2. Function documentation                                            
  278.  *         - The 1st part describes why this function's rewritten/extended for
  279.  *           rewritten/extended functions or what the function does for new  
  280.  *           functions                                                        
  281.  *         - The 2nd part describes what the arguments of the function are    
  282.  *         - The 3rd part informs which version rewritten, extended or created
  283.  *           this function                                                    
  284.  *         - The 4th part informs whether the function's rewritten or new    
  285.  *         - The 5th part informs whether the function's a real or potential  
  286.  *           hotspot                                                          
  287.  *         - The 6th part describes how this function works for new functions
  288.  *           only, and describes the parts added, removed or rewritten for    
  289.  *           rewritten or extended functions only                            
  290.  *         Example:                                                          
  291.  * /*----------------------------------------------------------------------
  292.  *  *    Why rewrite/extended/What this function does                      
  293.  *  *----------------------------------------------------------------------*/
  294. /* // arguments: What these arguments are                                    
  295.  * function_name = function(arguments) { // Version X+; Hotspot              
  296.  *     // Added/Removed/Rewritten to do something/How this function works    
  297.  *     function_name_code                                                    
  298.  *     //                                                                    
  299.  * } // function_name                                                        
  300.  *----------------------------------------------------------------------------*/
  301.  
  302. DoubleX_RMMV.Intercept_Item = {};
  303. (function(II) {
  304.  
  305.     II.DataManager = {};
  306.     var DM = II.DataManager;
  307.  
  308.     DM.isDatabaseLoaded = DataManager.isDatabaseLoaded;
  309.     DataManager.isDatabaseLoaded = function() {
  310.         // Rewritten
  311.         return DM.isDatabaseLoaded.apply(this, arguments) && DM.loadAllNotes();
  312.         //
  313.     }; // DataManager.isDatabaseLoaded
  314.  
  315.     DM.loadAllNotes = function() {
  316.         [$dataSkills, $dataItems, $dataStates].forEach(function(type) {
  317.             type.forEach(function(data) {
  318.                 if (data) { DM.loadDataNotes(data); }
  319.             });
  320.         });
  321.         return true;
  322.     }; // DM.loadAllNotes
  323.  
  324.     DM.loadDataNotes = function(data) {
  325.         var meta = data.meta, state = $dataStates.indexOf(data) >= 0;
  326.         var tier = /< *intercept +item +tier *: *(\d+) *>/i;
  327.         var ally = /< *ally intercept +item *>/i;
  328.         var foe = /< *foe intercept +item *>/i;
  329.         var chance = /< *intercept +item +chance *: *(\d+) *>/i;
  330.         var mp = /< *intercept +item +mp *>/i;
  331.         var tp = /< *intercept +item +tp *>/i;
  332.         var hitMp = /< *hit +intercept +item +mp *>/i;
  333.         var hitTp = /< *hit +intercept +item +tp *>/i;
  334.         var learnt = /< *intercept +item +learnt *>/i;
  335.         var usable = /< *intercept +item +usable *>/i;
  336.         var learn = /< *learn +intercept +item *>/i;
  337.         var animation, count, mpLimit, tpLimit, mcr;
  338.         meta.interceptItemTier = 0;
  339.         meta.battlerInterceptItem = {};
  340.         meta.interceptItemChance = 100;
  341.         if (state) {
  342.             meta.interceptItemAnimation = 0;
  343.             meta.interceptItemCount = {};
  344.             animation = /< *intercept +item +animation *: *(\d+) *>/i;
  345.             count = /< *intercept +item +count *: *(\d+) *, *(\w+) *>/i;
  346.             mpLimit = /< *intercept +item +mp + limit *>/i;
  347.             tpLimit = /< *intercept +item +tp + limit *>/i;
  348.             mcr = /< *intercept +item +mcr *>/i;
  349.         }
  350.         data.note.split(/[\r\n]+/).forEach(function(line) {
  351.             if (line.match(mp)) { return meta.interceptItemMp = true; }
  352.             if (line.match(tp)) { return meta.interceptItemTp = true; }
  353.             if (line.match(hitMp)) { return meta.hitInterceptItemMp = true; }
  354.             if (line.match(hitTp)) { return meta.hitInterceptItemTp = true; }
  355.             if (line.match(learnt)) { return meta.interceptItemLearnt = true; }
  356.             if (line.match(usable)) { return meta.interceptItemUsable = true; }
  357.             if (line.match(learn)) { return meta.learnInterceptItem = true; }
  358.             if (line.match(tier)) {
  359.                 meta.interceptItemTier = +RegExp.$1;
  360.             } else if (line.match(ally)) {
  361.                 meta.battlerInterceptItem.ally = true;
  362.             } else if (line.match(foe)) {
  363.                 meta.battlerInterceptItem.foe = true;
  364.             } else if (line.match(chance)) {
  365.                 meta.interceptItemChance = +RegExp.$1;
  366.             } else if (state) {
  367.                 if (line.match(mcr)) { return meta.interceptItemMcr = true; }
  368.                 if (line.match(animation)) {
  369.                     meta.interceptItemAnimation = +RegExp.$1;
  370.                 } else if (line.match(count)) {
  371.                     meta.interceptItemCount.count = +RegExp.$1;
  372.                     meta.interceptItemCount.fail = RegExp.$2 === "true";
  373.                 } else if (line.match(mpLimit)) {
  374.                     meta.interceptItemMpLimit = true;
  375.                 } else if (line.match(tpLimit)) {
  376.                     meta.interceptItemTpLimit = true;
  377.                 }
  378.             }
  379.         });
  380.         meta.interceptItemChance /= 100;
  381.     }; // DM.loadDataNotes
  382.  
  383.     II.BattleManager = {};
  384.     var BM = II.BattleManager;
  385.  
  386.     /*------------------------------------------------------------------------
  387.      *    New public instance variable                                        
  388.      *------------------------------------------------------------------------*/
  389.     // BM.interceptors: The conditional LIFO interceptor-state id pair list
  390.  
  391.     BM.initMembers = BattleManager.initMembers;
  392.     BattleManager.initMembers = function() {
  393.         BM.interceptors = []; // Added
  394.         BM.initMembers.apply(this, arguments);
  395.     }; // BattleManager.initMembers
  396.  
  397.     BM.startAction = BattleManager.startAction;
  398.     BattleManager.startAction = function() {
  399.         BM.startAction.apply(this, arguments);
  400.         BM.tryInitIntercept.call(this); // Added
  401.     }; // BattleManager.startAction
  402.  
  403.     BM.tryInitIntercept = function() {
  404.         var interceptor, subject = this._subject;
  405.         var act = subject.currentAction(), item = act.item();
  406.         if (item.meta.interceptItemTier <= 0) { return; };
  407.         if (Math.random() >= item.meta.interceptItemChance) { return; };
  408.         interceptor = GA.interceptor.call(act);
  409.         if (!interceptor) { return; }
  410.         BM.initIntercept.call(this, interceptor, subject, act, item);
  411.     }; // BM.tryInitIntercept
  412.  
  413.     BM.initIntercept = function(interceptor, subject, act, item) {
  414.         if (GB.canSetInterceptState.call(interceptor, subject, item)) {
  415.             BM.successIntercept.call(this, interceptor, subject, act, item);
  416.         } else {
  417.             BM.failIntercept.call(this, interceptor, act, item);
  418.         }
  419.         interceptor.possibleInterceptItemStates.length = 0;
  420.         interceptor.interceptItemState = null;
  421.     }; // BM.initIntercept
  422.  
  423.     BM.successIntercept = function(interceptor, subject, act, item) {
  424.         var window = this._logWindow;
  425.         WBL.showSuccessIntercept.call(window, interceptor, act, item.name);
  426.         GB.interceptMpTp.call(interceptor, subject, item);
  427.         if (GB.canLearnInterceptItem.call(interceptor, item)) {
  428.             WBL.showLearnItem.call(window, interceptor, item.name);
  429.             interceptor.learnSkill(item.id);
  430.         }
  431.         BattleManager.endAction();
  432.     }; // BM.successIntercept
  433.  
  434.     BM.failIntercept = function(interceptor, act, item) {
  435.         WBL.showFailIntercept.call(this._logWindow, interceptor, item.name);
  436.         if (GB.isHitInterceptor.call(interceptor, this._subject, item)) {
  437.             this._targets = GA.failInterceptTargets.call(act, interceptor);
  438.         }
  439.     }; // BM.failIntercept
  440.  
  441.     II.Game_Action = {};
  442.     var GA = II.Game_Action;
  443.  
  444.     /*------------------------------------------------------------------------
  445.      *    Returns the battler that will try to intercept the action          
  446.      *------------------------------------------------------------------------*/
  447.     GA.interceptor = function() {
  448.         var interceptor, mems, item = this.item();
  449.         Object.keys(item.meta.battlerInterceptItem).forEach(function(side) {
  450.             if (interceptor) { return; }
  451.             mems = side === "ally" ? this.friendsUnit() : this.opponentsUnit();
  452.             interceptor = GU.interceptor.call(mems, item, side);
  453.         }, this);
  454.         return interceptor;
  455.     }; // GA.interceptor
  456.  
  457.     /*------------------------------------------------------------------------
  458.      *    Returns the target list replaced by the failed interceptor only    
  459.      *------------------------------------------------------------------------*/
  460.     GA.failInterceptTargets = function(interceptor) {
  461.         var num, targets = [];
  462.         if (this.isForUser() || this.isForOne()) {
  463.             targets.push(interceptor);
  464.         } else if (this.isForRandom()) {
  465.             for (var index = 0, num = this.numTargets(); index < num; index++) {
  466.                 targets.push(interceptor);
  467.             }
  468.         } else {
  469.             if (this.isForOpponent()) {
  470.                 num = this.opponentsUnit().aliveMembers().length;
  471.             } else if (this.isForDeadFriend()) {
  472.                 num = this.friendsUnit().deadMembers().length;
  473.             } else if (this.isForFriend()) {
  474.                 num = this.friendsUnit().aliveMembers().length;
  475.             }
  476.             for (var i = 0; i < num; i++) { targets.push(interceptor); }
  477.         }
  478.         return this.repeatTargets(targets);
  479.     }; // GA.failInterceptTargets
  480.  
  481.     II.Game_BattlerBase = {};
  482.     var GBB = II.Game_BattlerBase;
  483.  
  484.     GBB.initMembers = Game_BattlerBase.prototype.initMembers;
  485.     Game_BattlerBase.prototype.initMembers = function() {
  486.         GBB.initInterceptStates.call(this); // Added
  487.         GBB.initMembers.apply(this, arguments);
  488.     }; // Game_BattlerBase.prototype.initMembers
  489.  
  490.     GBB.clearStates = Game_BattlerBase.prototype.clearStates;
  491.     Game_BattlerBase.prototype.clearStates = function() {
  492.         GBB.clearStates.apply(this, arguments);
  493.         GBB.clearInterceptStates.call(this);// Added
  494.     }; // Game_BattlerBase.prototype.clearStates
  495.  
  496.     GBB.eraseState = Game_BattlerBase.prototype.eraseState;
  497.     Game_BattlerBase.prototype.eraseState = function(stateId) {
  498.         // Added
  499.         if ($dataStates[stateId].meta.interceptItemTier > 0) {
  500.             GBB.eraseInterceptStates.call(this, stateId);
  501.         }
  502.         //
  503.         GBB.eraseState.apply(this, arguments);
  504.     }; // Game_BattlerBase.prototype.eraseState
  505.  
  506.     GBB.addNewState = Game_BattlerBase.prototype.addNewState;
  507.     Game_BattlerBase.prototype.addNewState = function(stateId) {
  508.         GBB.addNewState.apply(this, arguments);
  509.         // Added
  510.         if ($dataStates[stateId].meta.interceptItemTier > 0) {
  511.             GBB.addInterceptStates.call(this, stateId);
  512.         }
  513.         //
  514.     }; // Game_BattlerBase.prototype.addNewState
  515.  
  516.     GBB.initInterceptStates = function() {
  517.         this._interceptItemStates = [];
  518.         this._possibleInterceptItemStates = [];
  519.         this._interceptItemStateTimes = {};
  520.     }; // GBB.initInterceptStates
  521.  
  522.     GBB.clearInterceptStates = function() {
  523.         if (!BM.interceptors) { return; } // Fixes crashes upon game starts
  524.         BM.interceptors = BM.interceptors.filter(function(interceptor) {
  525.             return interceptor[0] !== this;
  526.         }, this);
  527.         this._interceptItemStates.length = 0;
  528.         this._interceptItemStateTimes = {};
  529.     }; // GBB.clearInterceptStates
  530.  
  531.     GBB.eraseInterceptStates = function(stateId) {
  532.         if (!BM.interceptors) { return; } // Fixes crashes outside battles
  533.         var index = BM.interceptors.indexOf([this, stateId]);
  534.         if (index >= 0) { BM.interceptors.splice(index, 1); }
  535.         index = this._interceptItemStates.indexOf($dataStates[stateId]);
  536.         if (index >= 0) { this._interceptItemStates.splice(index, 1); }
  537.         this._interceptItemStateTimes[stateId] = null;
  538.     }; // GBB.eraseInterceptStates
  539.  
  540.     GBB.addInterceptStates = function(stateId) {
  541.         if (!BM.interceptors) { return; } // Fixes crashes outside battles
  542.         var index = BM.interceptors.indexOf([this, stateId]);
  543.         if (index >= 0) { BM.interceptors.splice(index, 1); }
  544.         BM.interceptors.push([this, stateId]);
  545.         this._interceptItemStates.push($dataStates[stateId]);
  546.         this._interceptItemStateTimes[stateId] = 0;
  547.     }; // GBB.addInterceptStates
  548.  
  549.     II.Game_Battler = {};
  550.     var GB = II.Game_Battler;
  551.  
  552.     /*------------------------------------------------------------------------
  553.      *    New public instance variables                                      
  554.      *------------------------------------------------------------------------*/
  555.     Object.defineProperties(Game_Battler.prototype, {
  556.         // The state tried to intercept the skill/item
  557.         "interceptItemState": { get: function() {
  558.             return this._interceptItemState;
  559.         }, set: function(state) {
  560.             this._interceptItemState = state;
  561.         }, configurable: true },
  562.         // The list of states possible to intercept the skill/item
  563.         "possibleInterceptItemStates": { get: function() {
  564.             return this._possibleInterceptItemStates;
  565.         } , configurable: true }
  566.     });
  567.  
  568.     /*------------------------------------------------------------------------
  569.      *    New private instance variables                                      
  570.      *------------------------------------------------------------------------*/
  571.     // _interceptItemStates: The list of states that can intercept skills/items
  572.     // _interceptItemStateTimes: The number of times each state intercepted
  573.  
  574.     // side: The ally/foe flag
  575.     GB.hasPossibleInterceptStates = function(item, side) {
  576.         var states = GB.possibleInterceptStates.call(this, item, side);
  577.         if (states.length <= 0) { return false; }
  578.         this._possibleInterceptItemStates = states;
  579.         return true;
  580.     }; // GB.hasPossibleInterceptStates
  581.  
  582.     // side: The ally/foe flag
  583.     GB.possibleInterceptStates = function(item, side) {
  584.         return this._interceptItemStates.filter(function(state) {
  585.             if (!state.meta.battlerInterceptItem[side]) { return false; }
  586.             if (item.meta.interceptItemTier > state.meta.interceptItemTier) {
  587.                 return false;
  588.             } else if (Math.random() >= state.meta.interceptItemChance) {
  589.                 return false;
  590.             } else if (GB.isFailInterceptLearnt.call(this, item, state)) {
  591.                 return false;
  592.             }
  593.             return !GB.isFailInterceptUsable.call(this, item, state);
  594.         }, this);
  595.     }; // GB.possibleInterceptStates
  596.  
  597.     GB.isFailInterceptLearnt = function(item, state) {
  598.         if (!item.meta.interceptItemLearnt) { return false; }
  599.         if (!state.meta.interceptItemLearnt) { return false; }
  600.         return this.isActor() && !this.isLearnedSkill(item.id);
  601.     }; // GB.isFailInterceptLearnt
  602.  
  603.     GB.isFailInterceptUsable = function(item, state) {
  604.         if (!item.meta.interceptItemUsable) { return false; }
  605.         return state.meta.interceptItemUsable && !this.canUse(item);
  606.     }; // GB.isFailInterceptUsable
  607.  
  608.     /*------------------------------------------------------------------------
  609.      *    Tries to set an intercept state that works and returns the result  
  610.      *------------------------------------------------------------------------*/
  611.     GB.canSetInterceptState = function(subject, item) {
  612.         var states = GB.interceptStates.call(this, subject, item);
  613.         if (states.length > 0) {
  614.             this._interceptItemState = states[0];
  615.             GB.addInterceptStateTimes.call(this, this._interceptItemState);
  616.             return true;
  617.         }
  618.         this._interceptItemState = this._possibleInterceptItemStates[0];
  619.         if (this._interceptItemState.meta.interceptItemCount.fail) {
  620.             GB.addInterceptStateTimes.call(this, this._interceptItemState);
  621.         }
  622.         return false;
  623.     }; // GB.canSetInterceptState
  624.  
  625.     /*------------------------------------------------------------------------
  626.      *    Returns the list of all intercept states that will work            
  627.      *------------------------------------------------------------------------*/
  628.     GB.interceptStates = function(subject, item) {
  629.         return this._possibleInterceptItemStates.filter(function(state) {
  630.             if (GB.isFailInterceptMp.call(this, subject, item, state)) {
  631.                 return false;
  632.             }
  633.             return !GB.isFailInterceptTp.call(this, subject, item, state);
  634.         }, this);
  635.     }; // GB.interceptStates
  636.  
  637.     GB.addInterceptStateTimes = function(state) {
  638.         var count = state.meta.interceptItemCount.count;
  639.         if (!count) { return; }
  640.         this._interceptItemStateTimes[state.id] += 1;
  641.         if (this._interceptItemStateTimes[state.id] < count) { return; }
  642.         this.removeState(state.id);
  643.     }; // GB.addInterceptStateTimes
  644.  
  645.     GB.interceptMpTp = function(subject, item) {
  646.         var state = this._interceptItemState;
  647.         if (item.meta.interceptItemMp && state.meta.interceptItemMp) {
  648.             this._mp += GB.interceptMp.call(this, subject, item);
  649.             this._mp.clamp(0, this.mmp);
  650.         }
  651.         if (item.meta.interceptItemTp && state.meta.interceptItemTp) {
  652.             this._tp += subject.skillTpCost(item);
  653.             this._tp.clamp(0, this.maxTp());
  654.         }
  655.     }; // GB.interceptMpTp
  656.  
  657.     GB.canLearnInterceptItem = function(item) {
  658.         if (item.id === this.attackSkillId()) { return false; }
  659.         if (item.id === this.guardSkillId()) { return false; }
  660.         if (!item.meta.learnInterceptItem) { return false; }
  661.         if (!this._interceptItemState.meta.learnInterceptItem) { return false; }
  662.         if (!DataManager.isSkill(item) || !this.isActor()) { return false; }
  663.         return !this.isLearnedSkill(item.id);
  664.     }; // GB.canLearnInterceptItem
  665.  
  666.     GB.isHitInterceptor = function(subject, item) {
  667.         var state = this._interceptItemState;
  668.         if (GB.isFailInterceptMp.call(this, subject, item, state)) {
  669.             if (item.meta.hitInterceptItemMp && state.meta.hitInterceptItemMp) {
  670.                 return true;
  671.             }
  672.         }
  673.         if (GB.isFailInterceptTp.call(this, subject, item, state)) {
  674.             if (item.meta.hitInterceptItemTp && state.meta.hitInterceptItemTp) {
  675.                 return true;
  676.             }
  677.         }
  678.         return false;
  679.     }; // GB.isHitInterceptor
  680.  
  681.     GB.isFailInterceptMp = function(subject, item, state) {
  682.         if (!item.meta.interceptItemMp) { return false; }
  683.         if (!state.meta.interceptItemMp) { return false; }
  684.         if (!state.meta.interceptItemMpLimit) { return false; }
  685.         return this.mmp - this._mp < GB.interceptMp.call(this, subject, item);
  686.     }; // GB.isFailInterceptMp
  687.  
  688.     GB.isFailInterceptTp = function(subject, item, state) {
  689.         if (!item.meta.interceptItemTp) { return false; }
  690.         if (!state.meta.interceptItemTp) { return false; }
  691.         if (!state.meta.interceptItemTpLimit) { return false; }
  692.         return this.maxTp() - this._tp < subject.skillTpCost(item);
  693.     }; // GB.isFailInterceptTp
  694.  
  695.     GB.interceptMp = function(subject, item) {
  696.         if (this._interceptItemState.meta.interceptItemMcr) {
  697.             return subject.skillMpCost(item);
  698.         }
  699.         return item.mpCost;
  700.     }; // GB.interceptMp
  701.  
  702.     II.Game_Unit = {};
  703.     var GU = II.Game_Unit;
  704.        
  705.     /*------------------------------------------------------------------------
  706.      *    Returns the battler that will try to intercept the action          
  707.      *------------------------------------------------------------------------*/
  708.     // side: The ally/foe flag
  709.     GU.interceptor = function(item, side) {
  710.         var mems = this.aliveMembers().filter(function(mem) {
  711.             return GB.hasPossibleInterceptStates.call(mem, item, side);
  712.         });
  713.         var interceptors = BM.interceptors.filter(function(interceptor) {
  714.             return mems.indexOf(interceptor[0]) >= 0;
  715.         });
  716.         if (interceptors.length <= 0) { return null; }
  717.         return interceptors[interceptors.length - 1][0];
  718.     }; // GU.interceptor
  719.  
  720.     II.Window_BattleLog = {};
  721.     var WBL = II.Window_BattleLog;
  722.  
  723.     // name: The intercepted skill/item name
  724.     WBL.showSuccessIntercept = function(interceptor, act, name) {
  725.         var numMethods, text, id;
  726.         this.push('performActionStart', interceptor, act);
  727.         this.push('waitForMovement');
  728.         this.push('performAction', interceptor, act);
  729.         id = interceptor.interceptItemState.meta.interceptItemAnimation;
  730.         this.push('showNormalAnimation', [interceptor], id);
  731.         numMethods = this._methods.length;
  732.         text = interceptor.name() + " intercepts " + name + "!";
  733.         this.push('addText', text);
  734.         if (this._methods.length === numMethods) { this.push('wait'); }
  735.     }; // WBL.showSuccessIntercept
  736.  
  737.     // name: The intercepted skill/item name
  738.     WBL.showLearnItem = function(interceptor, name) {
  739.         var numMethods = this._methods.length;
  740.         var text = interceptor.name() + " learns " + name + "!";
  741.         this.push('addText', text);
  742.         if (this._methods.length === numMethods) { this.push('wait'); }
  743.     }; // WBL.showLearnItem
  744.  
  745.     // name: The intercepted skill/item name
  746.     WBL.showFailIntercept = function(interceptor, name) {
  747.         var numMethods = this._methods.length;
  748.         var text = interceptor.name() + " fails to intercept " + name + "!";
  749.         this.push('addText', text);
  750.         if (this._methods.length === numMethods) { this.push('wait'); }
  751.     }; // WBL.showFailIntercept
  752.  
  753. })(DoubleX_RMMV.Intercept_Item);
  754.  
  755. /*============================================================================*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement