Advertisement
Double_X

DoubleX RMMV State Resistance v100a

May 28th, 2016 (edited)
551
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 State Resistance                                        
  6.  *----------------------------------------------------------------------------
  7.  *    # Introduction                                                          
  8.  *      In the default RMMV setting, a state's either added with a fixed x-y  
  9.  *      remaining turns for all battlers, or not added at all.                
  10.  *      Also, battlers don't have their own resistance protecting their states
  11.  *      from being removed                                                    
  12.  *      With this plugin, you can set some states to have different remaining
  13.  *      turns on different battlers, and set some battlers to have their own  
  14.  *      resistance protecting their states from being removed                
  15.  *----------------------------------------------------------------------------
  16.  *    # Terms Of Use                                                          
  17.  *      1. Commercial use's always allowed and crediting me's always optional.
  18.  *      2. You shall keep this plugin's Plugin Info part's contents intact.  
  19.  *      3. You shalln't claim that this plugin's written by anyone other than
  20.  *         DoubleX or my aliases. I always reserve the right to deny you from
  21.  *         using any of my plugins anymore if you've violated this.          
  22.  *      4. CC BY 4.0, except those conflicting with any of the above, applies
  23.  *         to this plugin, unless you've my permissions not needing follow so.
  24.  *      5. I always reserve the right to deny you from using this plugin      
  25.  *         anymore if you've violated any of the above.                      
  26.  *----------------------------------------------------------------------------
  27.  *    # Prerequisites                                                        
  28.  *      Abilities:                                                            
  29.  *      1. Little Javascript coding proficiency to fully utilize this plugin  
  30.  *----------------------------------------------------------------------------
  31.  *    # Links                                                                
  32.  *      This plugin:                                                          
  33.  *      1. http://pastebin.com/6dh43cfC                                      
  34.  *      Mentioned Patreon Supporters:
  35.  *      https://www.patreon.com/posts/71738797
  36.  *----------------------------------------------------------------------------
  37.  *    # Author                                                                
  38.  *      DoubleX                                                              
  39.  *----------------------------------------------------------------------------
  40.  *    # Changelog                                                            
  41.  *      v1.00a(GMT 0800 28-5-2016):                                          
  42.  *      1. 1st version of this plugin finished                                
  43.  *============================================================================*/
  44. /*:
  45.  * @plugindesc Lets you set some states to have state removal/turn resistances
  46.  * @author DoubleX
  47.  *
  48.  * @help
  49.  *============================================================================
  50.  *    ## Notetag Info                                                        
  51.  *----------------------------------------------------------------------------
  52.  *    # Actor/Class/Weapon/Armor/Enemy Notetags:                              
  53.  *      Equip notetags take the highest priority, followed by class, actor and  
  54.  *      enemy                                                                
  55.  *      1. <operator state resist turn: stateId, turn>                        
  56.  *         - Assigns turn to the modifiers of the remaining turns of state    
  57.  *           with stateId when applying the state to the battler              
  58.  *         - operator can be either =, +, -, *, / or %, meaning set to, add  
  59.  *           by, subtract by, multiply by, divide by or modulo by respectively
  60.  *         - All instances of this notetag will be used sequentially          
  61.  *         - If the final remaining turn's nonpositive, the state won't be    
  62.  *           added                                                            
  63.  *         - This notetag won't work for states not having remaining turns    
  64.  *         - E.g.: <+ state resist turn: 2, 1> means the remaining turns of  
  65.  *           state with id 2 will be increased by 1                          
  66.  *      2. <operator state resist step: stateId, step>                        
  67.  *         - Assigns step to the modifiers of the remaining steps of state    
  68.  *           with stateId when applying the state to the battler              
  69.  *         - operator can be either =, +, -, *, / or %, meaning set to, add  
  70.  *           by, subtract by, multiply by, divide by or modulo by respectively
  71.  *         - All instances of this notetag will be used sequentially          
  72.  *         - If the final remaining step's nonpositive, the state won't be    
  73.  *           added outside battle and will be instantly removed outside battle
  74.  *         - This notetag won't work for states not having remaining steps    
  75.  *         - E.g.: <+ state resist step: 2, 1> means the remaining steps of  
  76.  *           state with id 2 will be increased by 1                          
  77.  *      3. <operator state resist damage remove: stateId, chance>            
  78.  *         - Assigns chance to the removal chance% of state with stateId when
  79.  *           removing the state from the battler due to damaging that battler
  80.  *         - operator can be either =, +, -, *, / or %, meaning set to, add  
  81.  *           by, subtract by, multiply by, divide by or modulo by respectively
  82.  *         - All instances of this notetag will be used sequentially          
  83.  *         - If the final removal chance's negative, it'll be regarded as 0%  
  84.  *         - This notetag only works if the state has remove by damage checked
  85.  *         - E.g.: <= state resist damage remove: 2, 50> means the removal    
  86.  *           chance of state with id 2 due to damaging the battler will be set
  87.  *           as 50%                                                          
  88.  *      4. <operator state resist effect remove: stateId, chance>            
  89.  *         - Assigns chance to the removal chance% of state with stateId when
  90.  *           removing the state from the battler due to skill/item effects    
  91.  *         - operator can be either =, +, -, *, / or %, meaning set to, add  
  92.  *           by, subtract by, multiply by, divide by or modulo by respectively
  93.  *         - All instances of this notetag will be used sequentially          
  94.  *         - If the final removal chance's negative, it'll be regarded as 0%  
  95.  *         - E.g.: <- state resist effect remove: 2, 50> means the removal    
  96.  *           chance of state with id 2 due to skill/item effects will be      
  97.  *           reduced by 50%                                                  
  98.  *      5. <state resist luk effect remove: stateId>                          
  99.  *         - Applies the same luk formula for modifying the state rate to the
  100.  *           removal chance of state with id stateId due to skill/item effects
  101.  *         - It'll be applied after calculating the final state removal chance
  102.  *         - E.g.: <state resist effect luk remove: 2> sets the luk formula  
  103.  *           for modifying the state rate to the removal chance of state with
  104.  *           id 2 due to skill/item effects                                  
  105.  *============================================================================
  106.  *    ## Plugin Call Info                                                    
  107.  *----------------------------------------------------------------------------
  108.  *    # Actor/Class/Weapon/Armor/Enemy manipulations                          
  109.  *      1. meta.stateResistTurn[stateId]                                      
  110.  *         - Returns the Array of state turn modifiers turns with their      
  111.  *           corresponding operators stored in                                
  112.  *           <operator state resist turn: stateId, turn> in the form of      
  113.  *           [opeartor, turn] for state with stateId                          
  114.  *      2. meta.stateResistTurn[stateId] = [[opeartor, turn], ...]            
  115.  *         - Sets the Array of state turn modifiers turns with their          
  116.  *           corresponding operators stored in                                
  117.  *           <operator state resist turn: stateId, turn> in the form of      
  118.  *           [opeartor, turn] for state with stateId                          
  119.  *         - All meta.stateResistanceTurn changes can be saved if            
  120.  *           DoubleX RMMV Dynamic Data is used                                
  121.  *      3. meta.stateResistStep[stateId]                                      
  122.  *         - Returns the Array of state step modifiers steps with their      
  123.  *           corresponding operators stored in                                
  124.  *           <operator state resist step: stateId, step> in the form of      
  125.  *           [opeartor, step] for state with stateId                          
  126.  *      4. meta.stateResistStep[stateId] = [[opeartor, turn], ...]            
  127.  *         - Sets the Array of state step modifiers steps with their          
  128.  *           corresponding operators stored in                                
  129.  *           <operator state resist step: stateId, turn> in the form of      
  130.  *           [opeartor, step] for state with stateId                          
  131.  *         - All meta.stateResistanceStep changes can be saved if            
  132.  *           DoubleX RMMV Dynamic Data is used                                
  133.  *      5. meta.stateResistDamageRemove[stateId]                              
  134.  *         - Returns the Array of state removal chance modifiers chance with  
  135.  *           their corresponding operators stored in                          
  136.  *           <operator state resist damage eemove: stateId, chance> in the    
  137.  *           form of [opeartor, chance] for state with stateId being removed  
  138.  *           due to damaging the battler                                      
  139.  *      6. meta.stateResistDamageRemove[stateId] = [[opeartor, turn], ...]    
  140.  *         - Sets the Array of state removal chance modifiers chance with    
  141.  *           their corresponding operators stored in                          
  142.  *           <operator state resist damage remove: stateId, chance> in the    
  143.  *           form of [opeartor, chance] for state with stateId being removed  
  144.  *           due to damaging the battler                                      
  145.  *         - All meta.stateResistanceDamageRemove changes can be saved if    
  146.  *           DoubleX RMMV Dynamic Data is used                                
  147.  *      7. meta.stateResistEffectRemove[stateId]                              
  148.  *         - Returns the Array of state removal chance modifiers chance with  
  149.  *           their corresponding operators stored in                          
  150.  *           <operator state resist effect remove: stateId, chance> in the    
  151.  *           form of [opeartor, chance] for state with stateId being removed  
  152.  *           due to skill/item effects                                        
  153.  *      8. meta.stateResistEffectRemove[stateId] = [[opeartor, turn], ...]    
  154.  *         - Sets the Array of state removal chance modifiers chance with    
  155.  *           their corresponding operators stored in                          
  156.  *           <operator state resist effect remove: stateId, chance> in the    
  157.  *           form of [opeartor, chance] for state with stateId being removed  
  158.  *           due to skill/item effects                                        
  159.  *         - All meta.stateResistanceEffectRemove changes can be saved if    
  160.  *           DoubleX RMMV Dynamic Data is used                                
  161.  *      9. meta.stateResistLukEffectRemove                                    
  162.  *         - Returns the Array of id of states having the luk formula for    
  163.  *           modifying the state rate to also be applied to the final state  
  164.  *           removal chance, stored in                                        
  165.  *           <state resist luk effect remove: stateId>, in the form of        
  166.  *           [stateId, stateId, stateId, ...]                                
  167.  *      10. meta.stateResistLukEffectRemove = [stateId, stateId, stateId, ...]
  168.  *          - Sets the Array of id of states having the luk formula for      
  169.  *            modifying the state rate to also be applied to the final state  
  170.  *            removal chance, stored in                                        
  171.  *           <state resist luk effect remove: stateId>, in the form of        
  172.  *           [stateId, stateId, stateId, ...]                                
  173.  *          - All meta.stateResistLukEffectRemove changes can be saved if    
  174.  *            DoubleX RMMV Dynamic Data is used                              
  175.  *============================================================================
  176.  */
  177.  
  178. var DoubleX_RMMV = DoubleX_RMMV || {};
  179. DoubleX_RMMV['State Resist'] = 'v1.00a';
  180.  
  181. /*============================================================================
  182.  *    ## Plugin Implementations                                              
  183.  *       You need not edit this part as it's about how this plugin works      
  184.  *----------------------------------------------------------------------------
  185.  *    # Plugin Support Info:                                                  
  186.  *      1. Prerequisites                                                      
  187.  *         - Some plugin development proficiency to fully comprehend this    
  188.  *           plugin                                                          
  189.  *----------------------------------------------------------------------------*/
  190.  
  191. (function(SR) {
  192.  
  193.     'use strict';
  194.  
  195.     /* Assigns modifier to current using operator
  196.      * Functional cohesion/Data coupling/Referentially transperant
  197.      * (Number)current: The current value
  198.      * (String)operator: The operator used in modifying the current value
  199.      * (Number)modifier: The value used in modifying the current value
  200.      * Return: The new value(Number)
  201.      */
  202.     SR.operateNotes = function(current, operator, modifier) {
  203.     // v1.00a - v1.00a; New
  204.         switch (operator) {
  205.             case '=': return modifier;
  206.             case '+': return current + modifier;
  207.             case '-': return current - modifier;
  208.             case '*': return current * modifier;
  209.             case '/': return current / modifier;
  210.             case '%': return current % modifier;
  211.             default:
  212.                 console.log('Invalid notetag operator: ' + operator);
  213.                 console.log('All notetags having this operator are ignored');
  214.                 return current;
  215.         }
  216.     }; // SR.operateNotes
  217.  
  218.     SR.DataManager = {};
  219.     var DM = SR.DataManager;
  220.  
  221.     DM.isDatabaseLoaded = DataManager.isDatabaseLoaded;
  222.     DataManager.isDatabaseLoaded = function() { // v1.00a - v1.00a; Extend
  223.         // Rewritten to load all notetags from all data as well
  224.         return DM.isDatabaseLoaded.apply(this, arguments) && DM.loadAllNotes();
  225.         //
  226.     }; // DataManager.isDatabaseLoaded
  227.  
  228.     /* Loads all notetags from all data
  229.      * Return success(Boolean)
  230.      * Functional cohesion/Message coupling/Referentially transperant
  231.      */
  232.     DM.loadAllNotes = function() { // v1.00a - v1.00a; New
  233.         var types = [$dataActors, $dataClasses, $dataWeapons, $dataArmors];
  234.         types.concat([$dataEnemies]).forEach(DM.loadTypeNote);
  235.         return true;
  236.     }; // DM.loadAllNotes
  237.  
  238.     /* Loads all notetags from all data belonging to type
  239.      * Functional cohesion/Message coupling/Referentially transperant
  240.      */
  241.     DM.loadTypeNote = function(type) { // v1.00a - v1.00a; New
  242.         type.forEach(function(data) {
  243.             if (data) DM.loadDataNotes(data.meta, data.note);
  244.         });
  245.     }; // DM.loadTypeNote
  246.  
  247.     /* Loads all notetags from a data notebox into a data notetag container
  248.      * (Object)meta: The data notetag container
  249.      * (String)note: The data notebox contents
  250.      * Functional cohesion/Data coupling/Referentially transperant
  251.      */
  252.     DM.loadDataNotes = function(meta, note) { // v1.00a - v1.00a; New
  253.         var sRT = meta.stateResistTurn = {};
  254.         var sRS = meta.stateResistStep = {};
  255.         var sRDR = meta.stateResistDamageRemove = {};
  256.         var sRER = meta.stateResistEffectRemove = {};
  257.         var sRELR = meta.stateResistLukEffectRemove = [];
  258.         var turn = /< *(.+) +state +resist +turn *: *(\d+) *, * (\d+) *>/i;
  259.         var step = /< *(.+) +state +resist +step *: *(\d+) *, * (\d+) *>/i;
  260.         var damage = /< *(.+) +state +resist +damage +remove *: *(\d+) *, *(\d+) *>/i;
  261.         var effect = /< *(.+) +state +resist +effect +remove *: *(\d+) *, *(\d+) *>/i;
  262.         var effectLuk = /< *state +resist +luk +effect +remove *: *(\d+) *>/i;
  263.         // Skips to the next line if the current contains any notetag instance
  264.         note.split(/[\r\n]+/).forEach(function(line) {
  265.             if (line.match(turn)) return DM.storeDataNotes(sRT, RegExp.$2);
  266.             if (line.match(step)) return DM.storeDataNotes(sRS, RegExp.$2);
  267.             if (line.match(damage)) return DM.storeDataNotes(sRDR, RegExp.$2);
  268.             if (line.match(effect)) return DM.storeDataNotes(sRER, RegExp.$2);
  269.             if (line.match(effectLuk)) return sRELR.push(RegExp.$1);
  270.         });
  271.         //
  272.     }; // DM.loadDataNotes
  273.  
  274.     /* Helper function
  275.      * (Object)note: The data notetag value container
  276.      * (String)stateId: The id of the state affected by the notetag container
  277.      * Functional cohesion/Data coupling
  278.      */
  279.     DM.storeDataNotes = function(note, stateId) { // v1.00a - v1.00a; New
  280.         note[stateId] = note[stateId] || [];
  281.         note[stateId].push([RegExp.$1, +RegExp.$3]);
  282.     }; // DM.storeDataNotes
  283.  
  284.     SR.Game_Action = {};
  285.     var GA = SR.Game_Action;
  286.  
  287.     GA.itemEffectRemoveState = Game_Action.prototype.itemEffectRemoveState;
  288.     Game_Action.prototype.itemEffectRemoveState = function(target, effect) {
  289.     // v1.00a - v1.00a; Rewrite
  290.         // Rewritten to use all effect remove and effect luk remove notetags too
  291.         var stateId = effect.dataId, note = 'EffectRemove';
  292.         var chance = effect.value1;
  293.         chance = GBB.getMultiNoteVal.call(target, note, stateId, chance);
  294.         chance *= GA.removeStateLukEffectRate.call(this, target, note, stateId);
  295.         if (Math.random() >= chance) return;
  296.         target.removeState(stateId);
  297.         this.makeSuccess(target);
  298.         //
  299.     }; // Game_Action.prototype.itemEffectRemoveState
  300.  
  301.     /* Returns the luk effect rate applied to removing states(Number)
  302.      * (Object)target: The action target
  303.      * (String)note: The notetag identifier
  304.      * (String)stateId: The id of the state affected by the notetag instances
  305.      * Functional cohesion/Data coupling
  306.      */
  307.     GA.removeStateLukEffectRate = function(target, note, stateId) {
  308.     // v1.00a - v1.00a; New
  309.         note = 'stateResistLuk' + note;
  310.         var types = target.stateResistNoteTypes(), type;
  311.         // Use the luk effect rate if a state removal luk notetag's found
  312.         for (var i = 0, typeL = types.length; i < typeL; i++) {
  313.             type = types[i];
  314.             for (var j = 0, dataL = type.length; j < dataL; j++) {
  315.                 if (type[j].meta[note].indexOf(stateId) >= 0) {
  316.                     return this.removeStateLukEffectRate(target);
  317.                 }
  318.             }
  319.         }
  320.         //
  321.         return 1;
  322.     }; // GA.removeStateLukEffectRate
  323.  
  324.     SR.Game_BattlerBase = {};
  325.     var GBB = SR.Game_BattlerBase;
  326.  
  327.     GBB.resetStateCounts = Game_BattlerBase.prototype.resetStateCounts;
  328.     Game_BattlerBase.prototype.resetStateCounts = function(stateId) {
  329.     // v1.00a - v1.00a; Extend
  330.         GBB.resetStateCounts.apply(this, arguments);
  331.         // Added to use all state turn modifying notetags too
  332.         var turn = this._stateTurns[stateId];
  333.         turn = GBB.getMultiNoteVal.call(this, 'Turn', stateId, turn);
  334.         this._stateTurns[stateId] = turn;
  335.         //
  336.     }; // Game_BattlerBase.prototype.resetStateCounts
  337.  
  338.     /* Returns the array of all notetag types(Array)
  339.      * Functional cohesion/Data coupling/Referentially transperant
  340.      */
  341.     Game_Battler.prototype.stateResistNoteTypes = function() {
  342.      // v1.00a - v1.00a; New
  343.         // Ensures this plugin works for battlers not being actors nor enemies
  344.         return [];
  345.         //
  346.     }; // Game_Battler.prototype.stateResistNoteTypes
  347.  
  348.     /* Calculates the final value using all notetags instances(Number)
  349.      * (String)note: The notetag identifier
  350.      * (String)stateId: The id of the state affected by the notetag instances
  351.      * (Number)val: The value to be modified by all notetags instances
  352.      * Functional cohesion/Data coupling
  353.      */
  354.     GBB.getMultiNoteVal = function(note, stateId, val) { // v1.00a - v1.00a; New
  355.         note = 'stateResist' + note;
  356.         // Iteratively use all notetag instances sequentially
  357.         this.stateResistNoteTypes().forEach(function(type) {
  358.             type.forEach(function(data) {
  359.                 if (!data.meta[note][stateId]) return;
  360.                 data.meta[note][stateId].forEach(function(vals) {
  361.                     val = SR.operateNotes(val, vals[0], vals[1]);
  362.                 });
  363.             });
  364.         });
  365.         //
  366.         return val;
  367.     }; // GBB.getMultiNoteVal
  368.  
  369.     SR.Game_Battler = {};
  370.     var GB = SR.Game_Battler;
  371.  
  372.     GB.removeStatesByDamage = Game_Battler.prototype.removeStatesByDamage;
  373.     Game_Battler.prototype.removeStatesByDamage = function() {
  374.     // v1.00a - v1.00a; Rewrite
  375.         // Rewritten to use all damage remove and damage luk remove notetags too
  376.         var chance, note = 'DamageRemove', stateId;
  377.         this.states().forEach(function(state) {
  378.             stateId = state.id;
  379.             chance = state.chanceByDamage;
  380.             chance = GBB.getMultiNoteVal.call(this, note, stateId, chance);
  381.             if (state.removeByDamage && Math.randomInt(100) < chance) {
  382.                 this.removeState(state.id);
  383.             }
  384.         }, this);
  385.         //
  386.     }; // Game_Battler.prototype.removeStatesByDamage
  387.  
  388.     SR.Game_Actor = {};
  389.     var GActor = SR.Game_Actor;
  390.  
  391.     GActor.resetStateCounts = Game_Actor.prototype.resetStateCounts;
  392.     Game_Actor.prototype.resetStateCounts = function(stateId) {
  393.     // v1.00a - v1.00a; Extend
  394.         GActor.resetStateCounts.apply(this, arguments);
  395.         // Added to use all state step modifying notetags too
  396.         var step = this._stateSteps[stateId];
  397.         step = GBB.getMultiNoteVal.call(this, 'Step', stateId, step);
  398.         this._stateSteps[stateId] = step;
  399.         //
  400.     }; // Game_Actor.prototype.resetStateCounts
  401.  
  402.     /* Returns the array of all notetag types
  403.      * Return: The array of all notetag types(Array)
  404.      * Functional cohesion/Data coupling
  405.      */
  406.     Game_Actor.prototype.stateResistNoteTypes = function() {
  407.     // v1.00a - v1.00a; New
  408.         var types = Game_Battler.prototype.stateResistNoteTypes.call(this);
  409.         // Ensures the returned array won't contain null
  410.         return types.concat([this.equips().filter(function(equip) {
  411.             return equip;
  412.         })]).concat([[this.currentClass()], [this.actor()]]);
  413.         //
  414.     }; // Game_Battler.prototype.stateResistNoteTypes
  415.  
  416.     /* Returns the array of all notetag types
  417.      * Return: The array of all notetag types(Array)
  418.      * Functional cohesion/Data coupling
  419.      */
  420.     Game_Enemy.prototype.stateResistNoteTypes = function() {
  421.     // v1.00a - v1.00a; New
  422.         var types = Game_Battler.prototype.stateResistNoteTypes.call(this);
  423.         // Ensures the returned array won't contain null
  424.         return types.concat([[this.enemy()]]);
  425.         //
  426.     }; // Game_Battler.prototype.stateResistNoteTypes
  427.  
  428. })(DoubleX_RMMV.State_Resist = {});
  429.  
  430. /*============================================================================*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement