Advertisement
Jragyn

[MV] J_Elementalistics

Dec 20th, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* -------------------------------------------------------------------------- */
  2. // J_Elementalistics
  3. // V: 1.0
  4. //
  5.  
  6. /*:@plugindesc Grants elemental affinity bonuses for calculating damage. See Help.
  7. @author J
  8.  
  9. @help More specifically, this plugin grants actors a new "stat" of sorts that
  10.         acts as an amplifier for elemental damage. It hooks into the
  11.         "Game_Action.prototype.calcElementRate" function, and multiplies the
  12.         result by said elemental amplifier based on category:
  13.         actor/class/equip/state of notetags.
  14.  
  15.         Structure of notetag:
  16.         <eATK:eID:amp>
  17.  
  18.         where
  19.         eID = the ID of the element you want to affect.
  20.         amp = percent bonus of the above element, this can be negative.
  21.  
  22.         example:
  23.         <eATK:1:200>
  24.  
  25.         translates to:
  26.         Element ID of 1 (slash element) gains +200% bonus damage for all skills.
  27.  
  28.         By default, if you set nothing, all elements get "100" granted to each
  29.         element in the base(actor) category, and "0" granted to each element in
  30.         all of the bonus(class/equip/state) categories.
  31.  
  32.         This stacks additively with other notetags across other categories.
  33.         example math:
  34.         if you have <eATK:1:50> in a class,
  35.         <eATK:1:-10> on an weapon,
  36.         <eATK:1:25> on an armor,
  37.         and <eATK:1:100> on an afflicted state,
  38.         the result is:
  39.         100(base) + 50(class) - 10(wpn) + 25(arm) + 100(state) = 275.
  40.         Using any skill that shares the element ID of 1 will deal 275% base
  41.         damage against the target.
  42.  
  43.         Note: Enemies do not use or benefit from this feature.
  44. */
  45. /* -------------------------------------------------------------------------- */
  46. /* -------------------------------------------------------------------------- */
  47. var J = J || {}; J.Elementalistic = J.Elementalistic || {};
  48.  
  49. /* -------------------------------------------------------------------------- */
  50. // a simple function that returns an array full of 0's,
  51. // one for each element in the database.
  52. J.Elementalistic.initElements = function() {
  53.   var arr = {};
  54.   for (var e = 0; e < $dataSystem.elements.length; e++) { arr[e] = 0; }
  55.   return arr;
  56. };
  57. (function() { // start plugin.
  58. /* -------------------------------------------------------------------------- */
  59. // Called on actor creation.
  60. // This sets up the two arrays used for handling elemental amplification.
  61. // The first is used for an actor's base elements, second for all the bonuses.
  62. var _Game_Actor_jElem_setup = Game_Actor.prototype.setup;
  63. Game_Actor.prototype.setup = function(actorId) {
  64.     _Game_Actor_jElem_setup.call(this, actorId);
  65.     this._elemAmpBase = this.getActorElements(actorId);
  66.     this._elemAmpPlus = {};
  67. };
  68.  
  69. /* -------------------------------------------------------------------------- */
  70. // The baseline setup for an actor's elemental affinities.
  71. // Bonuses stack ontop of these baselines.
  72. // If no baseline is designated for a given element, it defaults to 100(1.0x).
  73. Game_Actor.prototype.getActorElements = function(id) {
  74.   var structure = /<eATK:(\d+):(\d+)>/i;
  75.   var actor = $dataActors[id];
  76.   var notedata = actor.note.split(/[\r\n]+/);
  77.   var eATK = {};
  78.   for (var e = 0; e < $dataSystem.elements.length; e++) { eATK[e] = 100; }
  79.   for (var n = 0; n < notedata.length; n++) {
  80.     var line = notedata[n];
  81.     if (line.match(structure)) {
  82.       eATK[Number(RegExp.$1)] = Number(RegExp.$2);
  83.     }
  84.   }
  85.   return eATK;
  86. };
  87.  
  88. /* -------------------------------------------------------------------------- */
  89. // Bonuses part 1: Equipment.
  90. // Skims all notes of each of the actor's equipment, adding to the bonus array.
  91. Game_Actor.prototype.getEquipElements = function() {
  92.   var eATK_equips = J.Elementalistic.initElements();
  93.   var structure = /<eATK:(\d+):(\-?\+?)(\d+)>/i;
  94.   for (var n = 0; n < this.equips().length; n++) {
  95.     if (this.equips()[n] === null)
  96.       continue;
  97.     var eid = this.equips()[n].id;
  98.     if (DataManager.isWeapon(this.equips()[n])) {var item = $dataWeapons[eid];}
  99.     else { var item = $dataArmors[eid];}
  100.     var notedata = item.note.split(/[\r\n]+/);
  101.     for (var o = 0; o < notedata.length; o++) {
  102.       var line = notedata[o];
  103.       if (line.match(structure)) {
  104.         eATK_equips[Number(RegExp.$1)] += parseInt((RegExp.$2)+(RegExp.$3));
  105.       }
  106.     }
  107.   }
  108.   return eATK_equips;
  109. };
  110.  
  111. /* -------------------------------------------------------------------------- */
  112. // Bonuses part 2: Classes.
  113. // Skims the note of the actor's class, adding to the bonus array.
  114. Game_Actor.prototype.getClassElements = function() {
  115.   var eATK_classes = J.Elementalistic.initElements();
  116.   var structure = /<eATK:(\d+):(\-?\+?)(\d+)>/i;
  117.   var item = this.currentClass();
  118.   var notedata = item.note.split(/[\r\n]+/);
  119.   for (var n = 0; n < notedata.length; n++) {
  120.     var line = notedata[n];
  121.     if (line.match(structure)) {
  122.       eATK_classes[Number(RegExp.$1)] = parseInt((RegExp.$2)+(RegExp.$3));
  123.     }
  124.   }
  125.   return eATK_classes;
  126. };
  127.  
  128. /* -------------------------------------------------------------------------- */
  129. // Bonuses part 3: States.
  130. // Skims all notes of the actor's active states, adding to the bonus array.
  131. Game_Actor.prototype.getStateElements = function() {
  132.   var eATK_states = J.Elementalistic.initElements();
  133.   var structure = /<eATK:(\d+):(\-?\+?)(\d+)>/i;
  134.   var statesList = this.states();
  135.   for (var i = 0; i < statesList.length; i++) {
  136.     var item = statesList[i];
  137.     var notedata = item.note.split(/[\r\n]+/);
  138.     for (var n = 0; n < notedata.length; n++) {
  139.       var line = notedata[n];
  140.       if (line.match(structure)) {
  141.         eATK_states[Number(RegExp.$1)] = parseInt((RegExp.$2)+(RegExp.$3));
  142.       }
  143.     }
  144.   }
  145.   return eATK_states;
  146. };
  147.  
  148. /* -------------------------------------------------------------------------- */
  149. // This is where extra notes like equipment/classes/etc is read.
  150. Game_Actor.prototype.getElementPlus = function() {
  151.   this._elemAmpPlus = {};
  152.   var eqEle = this.getEquipElements();
  153.   var clEle = this.getClassElements();
  154.   var stEle = this.getStateElements();
  155.   for (var i = 0; i < $dataSystem.elements.length; i++) {
  156.     var temp = 0;
  157.     temp += eqEle[i]; // equip element bonuses
  158.     temp += clEle[i]; // class element bonuses
  159.     temp += stEle[i]; // state element bonuses
  160.     this._elemAmpPlus[i] = temp;
  161.   }
  162. }
  163.  
  164. /* -------------------------------------------------------------------------- */
  165. // Here is where the actor's elemental affinity bonuses are calculated.
  166. // This location was chosen as lowest common denominator.
  167. var _Game_Actor_jelem_refresh = Game_Actor.prototype.refresh;
  168. Game_Actor.prototype.refresh = function() {
  169.   _Game_Actor_jelem_refresh.call(this);
  170.   this.getElementPlus();
  171. };
  172.  
  173. /* -------------------------------------------------------------------------- */
  174. // This is the method that performs the multiplication to determine the amp.
  175. // Either one of two things happen here:
  176. // 1.) "normal attack" is selected, where it will look at the actor who is
  177. //      using the skill, and average all of their attack elemental amps.
  178. // 2.) the skill has an element, so it will take the user's elemental amp
  179. //      for that element based on all the sources, and return the amp.
  180. // NOTE: this always returns 1.0 amp for enemies.
  181. Game_Action.prototype.elementAmpRate = function(user, se) {
  182.   var result = 1;
  183.   if (user._enemyId > 0) // if the user is an enemy, return 1.0 amp.
  184.     return result;
  185.   if (se === -1) { // if "normal attack" element selected:
  186.     var userElements = user.attackElements();
  187.     var total = 0;
  188.     for (var i = 0; i < userElements.length; i++) {
  189.       total += user._elemAmpBase[userElements[i]];
  190.       total += user._elemAmpPlus[userElements[i]];
  191.     }
  192.     result = (total / userElements.length) / 100;
  193.   }
  194.   else { // if designated skill has a designated element:
  195.     result = (user._elemAmpBase[se] + user._elemAmpPlus[se]) / 100;
  196.   }
  197.   console.log(user._elemAmpBase[se] + " base");
  198.   console.log(user._elemAmpPlus[se] + " plus");
  199.   return result;
  200. };
  201.  
  202. /* -------------------------------------------------------------------------- */
  203. // This modifies the existing elemental calculation to accommodate
  204. // my new changes of "amplification".
  205. var _Game_Action_jElem_calcElementRate = Game_Action.prototype.calcElementRate;
  206. Game_Action.prototype.calcElementRate = function(target) {
  207.   var amp = this.elementAmpRate(this.subject(), this.item().damage.elementId);
  208.   return (_Game_Action_jElem_calcElementRate.call(this, target) * amp);
  209. };
  210. /* -------------------------------------------------------------------------- */
  211. })(); // end plugin.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement