Advertisement
Maliki79

MalVarianceVZ

Dec 8th, 2024 (edited)
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // MalVarianceVZ
  3. // MalVarianceVZ.js
  4. // version 1.0b
  5. //=============================================================================
  6. /*:
  7.  * @plugindesc Allows Actors, enemies, weapons, classes, armors and states to influnce damage variance independently.
  8.  *
  9.  * @author Maliki79
  10.  * @param variDamageReversal
  11.  * @desc If 0, will allow variance to go into the negative, converting damage to healing and vice-versa.
  12.  * Else will set damage to 0.
  13.  * Default: 1
  14.  * @default 1
  15.  * @help
  16.  * Actor, Enemy, Class, Weapon, Armor and State Notetags :
  17.  * <malvariP: integer, integer>
  18.  * <malvariM: integer, integer>
  19.  * <malvariC: integer, integer>
  20.  *  
  21.  * Where integers are typically from lowest to highest.
  22.  * Note that 100 is the normal damage.
  23.  * The malvariP tag will affect all skill noted as Physical skills, malvariM, Magical and malvariC for Certain Hit skills.
  24.  * Note that database items do NOT need to have all three tags.  Any missing tags will default to 100% for their respective skills.
  25.  * Only the FIRST tag listed per type on an object will have an effect.
  26.  *  
  27.  * Examples:
  28.  * Notetag: <malvariP: 100, 200>
  29.  * Result: ALL physical skills from the applied user will have their damage adjusted by up to 100%
  30.  *
  31.  * Notetag: <malvariM: 10, 90>
  32.  * Result: ALL magical skills from the applied user will have their damage adjust to between 10 and 90%
  33.  *
  34.  * Tags placed on equipment will each be taken into account as will tags placed on states that are present on the battler.
  35.  *
  36.  * Negative numbers can be used in tags.  They will allow damage to potentially be a negative number.
  37.  * The param variDamageReversal if set to 1, will reset the damage to 0, disallowing unintentional healing.
  38.  *
  39.  * Note that this plugin's filename must not be changed.
  40.  */
  41.  
  42. var Mal = Mal || {};
  43.  
  44. Mal.VarianceParameters = PluginManager.parameters('MalVarianceVZ');
  45. Mal.Param = Mal.Param || {};
  46.  
  47. //Mal.Param.allowRevesal = Number(Mal.DurabilityParameters['variDamageReversal']);
  48.  
  49. var MalVariDatabaseLoad = DataManager.isDatabaseLoaded;
  50. DataManager.isDatabaseLoaded = function() {
  51.   if (!MalVariDatabaseLoad.call(this)) return false;
  52.   if (!DataManager._malVari_DatabaseLoaded) {
  53.     this.processMalVariNotetags($dataActors);
  54.     this.processMalVariNotetags($dataClasses);
  55.     this.processMalVariNotetags($dataWeapons);
  56.     this.processMalVariNotetags($dataArmors);
  57.     this.processMalVariNotetags($dataEnemies);
  58.     this.processMalVariNotetags($dataStates);
  59.     DataManager._malVari_DatabaseLoaded = true;
  60.   }
  61.   return true;
  62. };
  63.  
  64. DataManager.processMalVariNotetags = function(object) {
  65.     for (var n = 1; n < object.length; n++) {
  66.         var weaponset  = [100, 100];
  67.         var magicSet   = [100, 100];
  68.         var certainSet = [100, 100];
  69.         var obj = object[n];
  70.         var noteread = obj.note;
  71.         while(noteread.indexOf("malvariP") > -1) {
  72.             var notereg = noteread.split("<malvariP: ");
  73.             var match = notereg[1].split(" ");
  74.             weaponset = [parseInt(match[0]), parseInt(match[1])];
  75.             noteread = noteread.replace("malvariP", " ");
  76.         };
  77.         while(noteread.indexOf("malvariM") > -1) {
  78.             var notereg = noteread.split("<malvariM: ");
  79.             var match = notereg[1].split(" ");
  80.             magicSet = [parseInt(match[0]), parseInt(match[1])];
  81.             noteread = noteread.replace("malvariM", " ");
  82.         };
  83.         while(noteread.indexOf("malvariC") > -1) {
  84.             var notereg = noteread.split("<malvariC: ");
  85.             var match = notereg[1].split(" ");
  86.             certainSet = [parseInt(match[0]), parseInt(match[1])];
  87.             noteread = noteread.replace("malvariC", " ");
  88.         };
  89.         obj._physVariance = weaponset;
  90.         obj._magVariance  = magicSet;
  91.         obj._certVariance = certainSet;
  92.     };
  93. };
  94.  
  95. var MalVariActorSetup = Game_Actor.prototype.setup;
  96. Game_Actor.prototype.setup = function(actorId) {
  97.     MalVariActorSetup.call(this, actorId);
  98.     this.physVariance = $dataActors[actorId]._physVariance;
  99.     this.magVariance  = $dataActors[actorId]._magVariance;
  100.     this.certVariance = $dataActors[actorId]._certVariance;
  101. };
  102.  
  103. var MalVariEnemySetup = Game_Enemy.prototype.setup;
  104. Game_Enemy.prototype.setup = function(enemyId, x, y) {
  105.     MalVariEnemySetup.call(this, enemyId, x, y);
  106.     this.physVariance = $dataEnemies[enemyId]._physVariance;
  107.     this.magVariance  = $dataEnemies[enemyId]._magVariance;
  108.     this.certVariance = $dataEnemies[enemyId]._certVariance;
  109. };
  110.  
  111. var MalVariApplyVariance = Game_Action.prototype.applyVariance
  112. Game_Action.prototype.applyVariance = function(damage, variance) {
  113.     var damage = MalVariApplyVariance.call(this, damage, variance);
  114.     var newDamage = this.varianceEX(damage);
  115.     return newDamage;
  116. };
  117.  
  118. Game_Action.prototype.varianceEX = function(damage) {
  119.     var damage = damage;
  120.     var mode = 0;
  121.     var min = 0;
  122.     var max = 0;
  123.     var diff = 0;
  124.     var subject = this.subject();
  125.    
  126.     if (this.isPhysical())   mode = 1;
  127.     if (this.isMagical())    mode = 2;
  128.     if (this.isCertainHit()) mode = 3;
  129.     if (mode == 0) return damage;
  130.    
  131.     //Basic calc of actor/enemy.
  132.     if (mode == 1) {
  133.         min = subject.physVariance[0];
  134.         max = subject.physVariance[1];
  135.     };
  136.     if (mode == 2) {
  137.         min = subject.magVariance[0];
  138.         max = subject.magVariance[1];
  139.     };
  140.     if (mode == 3) {
  141.         min = subject.certVariance[0];
  142.         max = subject.certVariance[1];
  143.     };
  144.     if (min != 100 || max != 100) {
  145.         diff = (Math.randomInt(max - min) + min) / 100.0;
  146.         damage *= diff;
  147.     };
  148.        
  149.     if (subject.isActor()) { //actor only calc of class and equipment
  150.         if (mode == 1) {
  151.             min = subject.currentClass()._physVariance[0];
  152.             max = subject.currentClass()._physVariance[1];
  153.         };
  154.         if (mode == 2) {
  155.             min = subject.currentClass()._magVariance[0];
  156.             max = subject.currentClass()._magVariance[1];
  157.         };
  158.         if (mode == 3) {
  159.             min = subject.currentClass()._certVariance[0];
  160.             max = subject.currentClass()._certVariance[1];
  161.         };
  162.         if (min != 100 || max != 100) {
  163.             diff = (Math.randomInt(max - min) + min) / 100.0;
  164.             damage *= diff;
  165.         };
  166.         var equips = subject.equips();
  167.         for (var i = 0; i < equips.length; i++) {
  168.             var item = equips[i];
  169.             if (item) {
  170.                 if (mode == 1) {
  171.                     min = item._physVariance[0];
  172.                     max = item._physVariance[1];
  173.                 };
  174.                 if (mode == 2) {
  175.                     min = item._magVariance[0];
  176.                     max = item._magVariance[1];
  177.                 };
  178.                 if (mode == 3) {
  179.                     min = item._certVariance[0];
  180.                     max = item._certVariance[1];
  181.                 };
  182.                 if (min != 100 || max != 100) {
  183.                     diff = (Math.randomInt(max - min) + min) / 100.0;
  184.                     damage *= diff;
  185.                 };
  186.             }
  187.         }
  188.     }
  189.     //Calc for Actor/Enemy States
  190.     var states = subject.states();
  191.     for (var i = 0; i < states.length; i++) {
  192.         var item = states[i];
  193.         if (item) {
  194.             if (mode == 1) {
  195.                 min = item._physVariance[0];
  196.                 max = item._physVariance[1];
  197.             };
  198.             if (mode == 2) {
  199.                 min = item._magVariance[0];
  200.                 max = item._magVariance[1];
  201.             };
  202.             if (mode == 3) {
  203.                 min = item._certVariance[0];
  204.                 max = item._certVariance[1];
  205.             };
  206.             if (min != 100 || max != 100) {
  207.                 diff = (Math.randomInt(max - min) + min) / 100.0;
  208.                 damage *= diff;
  209.             };
  210.         }
  211.     };
  212. //if(Mal.Param.allowRevesal != 0 && damage < 0) damage = 0;
  213. return damage;
  214. };
  215.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement