Advertisement
jeneeus

DrainRate

Nov 2nd, 2015
996
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //==============================================================================
  2. // ** Special Parameter: Drain Rate
  3. // by: Jeneeus Guruman
  4. //------------------------------------------------------------------------------
  5.  
  6. var Jene = Jene || {};
  7.  
  8. /*:
  9.  * @plugindesc Special Parameter: Drain Rate v1.1.0
  10.  * @author Jeneeus Guruman
  11.  *
  12.  * @help
  13.  *
  14.  *     This plugin allows to include a paramter that will PASSIVELY drains
  15.  *   a percentage of damage based on the damage dealt to the target as long
  16.  *   as the one that has a drain rate parameter.
  17.  *
  18.  *       <dhr: percent>
  19.  *
  20.  *       percent: The percentage of amount of HP to be drained based on
  21.  *     the damage. The default is 0. Multiple tags will add all values
  22.  *     by percentage (e.g. 200% + -50% = 150%). Note: no percent sign
  23.  *     should be added (e.g. <dhr: 50>).
  24.  *
  25.  *       <dmr: percent>
  26.  *
  27.  *       percent: The percentage of amount of MP to be drained based on
  28.  *     the damage. The default is 0. Multiple tags will add all values
  29.  *     by percentage (e.g. 200% + -50% = 150%). Note: no percent sign
  30.  *     should be added (e.g. <dmr: 50>).
  31.  *
  32.  *       <dsr: percent>
  33.  *
  34.  *       percent: The percentage of amount of either HP or MP to be drained
  35.  *     on the skills and items assigned. The default is 100. Note: no
  36.  *     percent sign should be added (e.g. <dsr: 50>).
  37.  *
  38.  *       <dhr_exclude>
  39.  *       <dmr_exclude>
  40.  *
  41.  *       Skills and items assigned to this will not drain any damage.
  42.  *
  43.  *       <dsr_switch>
  44.  *
  45.  *       Skills and items assigned to this will switch the restored value
  46.  *     in draining skills and items (e.g. HP Drain damage will restore
  47.  *     MP instead).
  48.  *
  49.  *       Notes:
  50.  *       * This will only affect the damage formula and not the effects.
  51.  *       * This can be placed with negative values and thus can be used as
  52.  *       a recoil state instead.
  53.  *       * "dhr" and "dsr" will only work on "HP Damage" damage type skills
  54.  *       and items.
  55.  *       * "dsr" will only work on "HP Drain" and "MP Drain" damage type
  56.  *       skills.
  57.  *
  58.  *   Changelog:
  59.  *
  60.  *     * v1.1.0: Added "dsr" to manipulate the absorb percentage of skills
  61.  *     and items and "dsr_switch" to swap the portion to be restored.
  62.  */
  63.  
  64. Object.defineProperty(Game_BattlerBase.prototype, 'dhr', {
  65.     get: function() {  
  66.         var value = 0;
  67.         this.traitObjects().forEach(function(trait) {
  68.             var dhr = parseFloat(trait.meta.dhr) || 0;
  69.             value += dhr;
  70.         });
  71.         return value / 100;
  72.     },
  73.     configurable: true
  74. });
  75.  
  76. Object.defineProperty(Game_BattlerBase.prototype, 'dmr', {
  77.     get: function() {
  78.         var value = 0;
  79.         this.traitObjects().forEach(function(trait) {
  80.             var dmr = parseFloat(trait.meta.dmr) || 0;
  81.             value += dmr;
  82.         });
  83.         return value / 100;
  84.     },
  85.     configurable: true
  86. });
  87.  
  88. Jene.gameActionExecuteDamage = Game_Action.prototype.executeDamage;
  89.  
  90. Game_Action.prototype.executeDamage = function(target, value) {
  91.     Jene.gameActionExecuteDamage.call(this, target, value);
  92.     if (this.isHpEffect() && value > 0) {
  93.         if (this.subject().dhr != 0 && !this.item().meta.dhr_exclude) {
  94.             this.subject().gainHp(Math.round(value * this.subject().dhr));
  95.         }
  96.         if (this.subject().dmr != 0 && !this.item().meta.dmr_exclude) {
  97.             this.subject().gainMp(Math.round(value * this.subject().dmr));
  98.         }
  99.     }
  100. };
  101.  
  102. Jene.gameActionGainedDrainedHp = Game_Action.prototype.gainDrainedHp;
  103.  
  104. Game_Action.prototype.gainDrainedHp = function(value) {
  105.     var item = this.item();
  106.     if (!item.meta.dsr) {
  107.         Jene.gameActionGainedDrainedHp.call(this, value);
  108.     }
  109.     else {
  110.         console.log(item.meta.dsr);
  111.         if (item.meta.dsr_switch) {
  112.             this.subject().gainMp(Math.ceil(value * Number(item.meta.dsr) / 100));
  113.         }
  114.         else {
  115.             this.subject().gainHp(Math.ceil(value * Number(item.meta.dsr) / 100));
  116.         }
  117.     }
  118. };
  119.  
  120. Jene.gameActionGainedDrainedMp = Game_Action.prototype.gainDrainedMp;
  121.  
  122. Game_Action.prototype.gainDrainedMp = function(value) {
  123.     var item = this.item();
  124.     if (!item.meta.dsr) {
  125.         Jene.gameActionGainedDrainedMp.call(this, value);
  126.     }
  127.     else { 
  128.         if (item.meta.dsr_switch) {
  129.             this.subject().gainHp(Math.ceil(value * Number(item.meta.dsr) / 100));
  130.         }
  131.         else {
  132.             this.subject().gainMp(Math.ceil(value * Number(item.meta.dsr) / 100));
  133.         }
  134.     }
  135. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement