Advertisement
Jragyn

[MV] J_critDamage

Dec 27th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* -------------------------------------------------------------------------- */
  2. // J_critDamage
  3. // V: 1.0
  4. //
  5. /*:@plugindesc Creates new paramters: CDM/CDR for crit damage manipulation.
  6. @author J
  7. @help This plugin uses newly created parameters for allies and enemies to
  8.         calculate crit damage multipliers/reductions.
  9.  
  10.         Use:
  11.         <cdm:+/-x>
  12.         <cdr:+/-x>
  13.  
  14.         for crit damage multiplier(cdm) or crit damage reduction(cdr).
  15.  
  16.         Example:
  17.         <cdm:+175>
  18.         <cdr:+25>
  19.  
  20.         Notes can be placed in many places.
  21.         Base parameter: actor/enemy page.
  22.         bonus parameter (adds with others): class, equipment, states
  23.  
  24.         if no base is defined, base will default to 1.5.
  25.         bonuses will add together.
  26.         use whole numbers like 150 for 1.5x, or 75 for 0.75x.
  27. */
  28. /* -------------------------------------------------------------------------- */
  29. // Base Formula for critical hits.
  30. // Gauges attacker's crit damage boost vs target's crit damage reduction
  31. Game_Action.prototype.applyCritical = function(damage) {
  32.   var attacker = this.subject();
  33.   if (attacker.cdm > 0)
  34.     var critDamageRatio = attacker.cdm;
  35.   else
  36.     var critDamageRatio = 1.5;
  37.   return damage * critDamageRatio;
  38. };
  39.  
  40. var _Game_Action_jCritDmg_mdv = Game_Action.prototype.makeDamageValue;
  41. Game_Action.prototype.makeDamageValue = function(target, critical) {
  42.    var originalDmg = _Game_Action_jCritDmg_mdv.call(this, target, critical);
  43.    if (critical) {
  44.      var modDmg = originalDmg * (1 - target.cdr);
  45.    }
  46.    return Math.round(originalDmg);
  47. };
  48.  
  49.  
  50. /* -------------------------------------------------------------------------- */
  51. // The core for defining new parameters and how they are handled.
  52. //   0 = CDM aka Crit Damage Modifier
  53. //   1 = CDR aka Crit Damage Reduction
  54. Object.defineProperties(Game_BattlerBase.prototype, {
  55.     cdm: { get: function() { return this.jparam(0); }, configurable: true },
  56.     cdr: { get: function() { return this.jparam(1); }, configurable: true },
  57. });
  58.  
  59. /* -------------------------------------------------------------------------- */
  60. // The baseline for new parameters.
  61. Game_BattlerBase.prototype.jparam = function(paramId) {
  62.   switch (paramId) {
  63.     case 0: // cdm: crit damage modifier
  64.       return 50; // base of 50% damage boost for landing critical hits.
  65.     case 1: // cdr: crit damage reduction
  66.       return 0; // base of 0% damage reduction vs critical hits.
  67.     default: return 0; // just in case.
  68.   }
  69. };
  70.  
  71. /* -------------------------------------------------------------------------- */
  72. // Provides a RegEx structure for provided parameter IDs.
  73. Game_Battler.prototype.jParamGetStructure = function(paramId) {
  74.   switch (paramId) {
  75.     case 0: var structure = /<cdm:(\-?\+?)(\d+)>/i; break;
  76.     case 1: var structure = /<cdr:(\-?\+?)(\d+)>/i; break;
  77.     default: var structure = ""; break;
  78.   }
  79.   return structure;
  80. };
  81.  
  82. /* -------------------------------------------------------------------------- */
  83. // Gets the base from actors/enemies if they have a different baseline.
  84. // Reads the notes off of actors/enemies and replaces baseline with that.
  85. Game_Battler.prototype.jParamBase = function(battler, paramId) {
  86.   var total = 0;
  87.   var structure = "";
  88.   switch (paramId) {
  89.     case 0:
  90.       total = Game_BattlerBase.prototype.jparam.call(this, 0);
  91.       structure = /<cdm:(\d+)>/i;
  92.       break;
  93.     case 1:
  94.       total = Game_BattlerBase.prototype.jparam.call(this, 1);
  95.       structure = /<cdr:(\d+)>/i;
  96.       break;
  97.     default: break;
  98.   }
  99.   var item = battler;
  100.   var notedata = item.note.split(/[\r\n]+/);
  101.   for (var n = 0; n < notedata.length; n++) {
  102.     var line = notedata[n];
  103.     if (line.match(structure)) { total = Number(RegExp.$1); }
  104.   }
  105.   return total;
  106. };
  107.  
  108. /* -------------------------------------------------------------------------- */
  109. // Specific handling for an Actor's new parameters.
  110. // Fetches the baseline, then adds up the bonuses and returns the total.
  111. // For actors, it is base + (equips + class + states).
  112. Game_Actor.prototype.jparam = function(paramId) {
  113.   var total = 0;
  114.   var base = Game_Battler.prototype.jParamBase.call(this, this.actor(), paramId);
  115.   var bonus = 0;
  116.   bonus += this.jParamFromClass(paramId);
  117.   bonus += this.jParamFromEquips(paramId);
  118.   bonus += this.jParamFromState(paramId);
  119.   total = (base + bonus) / 100; // divide by 100 to get decimal multiplier.
  120.   return total;
  121. };
  122.  
  123. /* -------------------------------------------------------------------------- */
  124. // Reads the notes of each piece of equipment an actor is wearing
  125. // and gives back the details based on the parameter in question.
  126. Game_Actor.prototype.jParamFromEquips = function(paramId) {
  127.   var total = 0;
  128.   var structure = this.jParamGetStructure(paramId);
  129.   for (var n = 0; n < this.equips().length; n++) {
  130.     if (this.equips()[n] === null) continue;
  131.     var eid = this.equips()[n].id;
  132.     if (DataManager.isWeapon(this.equips()[n])) { var item = $dataWeapons[eid]; }
  133.     else { var item = $dataArmors[eid]; }
  134.     var notedata = item.note.split(/[\r\n]+/);
  135.     for (var o = 0; o < notedata.length; o++) {
  136.       var line = notedata[o];
  137.       if (line.match(structure)) {
  138.         total += parseInt((RegExp.$1)+(RegExp.$2));
  139.       }
  140.     }
  141.   }//equips
  142.   return total;
  143. };
  144.  
  145. /* -------------------------------------------------------------------------- */
  146. // Reads the notes of the actor's class
  147. // and gives back the details based on the parameter in question.
  148. Game_Actor.prototype.jParamFromClass = function(paramId) {
  149.   var total = 0;
  150.   var structure = this.jParamGetStructure(paramId);
  151.   var item = this.currentClass();
  152.   var notedata = item.note.split(/[\r\n]+/);
  153.   for (var n = 0; n < notedata.length; n++) {
  154.     var line = notedata[n];
  155.     if (line.match(structure)) {
  156.       total = parseInt((RegExp.$1)+(RegExp.$2));
  157.     }
  158.   }
  159.   return total;
  160. };
  161.  
  162. /* -------------------------------------------------------------------------- */
  163. // Reads the notes of the actor/enemy 's current list of states
  164. // and gives back the details based on the parameter in question.
  165. Game_Battler.prototype.jParamFromState = function(paramId) {
  166.   var total = 0;
  167.   var structure = this.jParamGetStructure(paramId);
  168.   var statesList = this.states();
  169.   for (var i = 0; i < statesList.length; i++) {
  170.     var item = statesList[i];
  171.     var notedata = item.note.split(/[\r\n]+/);
  172.     for (var n = 0; n < notedata.length; n++) {
  173.       var line = notedata[n];
  174.       if (line.match(structure)) {
  175.         total += parseInt((RegExp.$1)+(RegExp.$2));
  176.       }
  177.     }
  178.   }
  179.   return total;
  180. };
  181.  
  182. /* -------------------------------------------------------------------------- */
  183. // Specific handling for an Enemy's new parameters.
  184. // Fetches the baseline, then adds up the bonuses and returns the total.
  185. // For enemies, it is base + (states).
  186. Game_Enemy.prototype.jparam = function(paramId) {
  187.   var total = 0;
  188.   var base = Game_Battler.prototype.jParamBase.call(this, this.enemy(), paramId);
  189.   var bonus = Game_Battler.prototype.jParamFromState.call(this, paramId);
  190.   total = (base + bonus) / 100; // divide by 100 to get decimal multiplier.
  191.   return total;
  192. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement