Advertisement
Maliki79

MalMVRollingStats

Aug 12th, 2021
1,463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Maliki's Rolling Stats MZ
  3. // MalMVRollingStats.js
  4. // version 1.0
  5. //=============================================================================
  6. /*:
  7.  * @target MV
  8.  *  
  9.  * @plugindesc ver1.0 - Allows HP, MP and/or TP stats to change in a more
  10.  * gradual manner during battles.
  11.  *
  12.  * @author Maliki79
  13.  *
  14.  * @param HP Tick Delay
  15.  * @type integer    
  16.  * @desc Amount of frames the plugin will wait before processing a tick
  17.  * (30 frames = approx 1 sec real time; the lower the number, the faster the stats will roll)
  18.  * @default 10
  19.  *
  20.  * @param MP Tick Delay
  21.  * @type integer    
  22.  * @desc Amount of frames the plugin will wait before processing a tick
  23.  * (30 frames = approx 1 sec real time; the lower the number, the faster the stats will roll)
  24.  * @default 10
  25.  *
  26.  * @param TP Tick Delay
  27.  * @type integer    
  28.  * @desc Amount of frames the plugin will wait before processing a tick
  29.  * (30 frames = approx 1 sec real time; the lower the number, the faster the stats will roll)
  30.  * @default 10      
  31.  *
  32.  * @help This plugin is currently plug and play.
  33.  * Just install this plugin and it will do as intended.
  34.  * Optional: You can edit the params to adjust the speed by which the stats roll.
  35.  * (Set a param to 0 to not use that stat.)
  36.  */
  37.  
  38. var MalRollingPar1  = PluginManager.parameters('MalMVRollingStats')["HP Tick Delay"];
  39. if(MalRollingPar1 < 0) MalRollingPar1 = 0;
  40. var MalRollingPar2  = PluginManager.parameters('MalMVRollingStats')["MP Tick Delay"];
  41. if(MalRollingPar2 < 0) MalRollingPar2 = 0;
  42. var MalRollingPar3  = PluginManager.parameters('MalMVRollingStats')["TP Tick Delay"];
  43. if(MalRollingPar3 < 0) MalRollingPar3 = 0;
  44.  
  45. var MalRollingDatabaseLoad = DataManager.isDatabaseLoaded;
  46. DataManager.isDatabaseLoaded = function() {
  47.   if (!MalRollingDatabaseLoad.call(this)) return false;
  48.   if (!DataManager._malRolling_DatabaseLoaded) {
  49.     this.processRollingData($dataActors);
  50.     DataManager._malRolling_DatabaseLoaded = true;
  51.   }
  52.   return true;
  53. };
  54.  
  55. DataManager.processRollingData = function (group) {
  56. for (i = 1; i < group.lenght; i++) {
  57.     var obj = group[i];
  58.     obj.rollingHP = 0;
  59.     obj.rollingMP = 0;
  60.     obj.rollingTP = 0;
  61. };
  62. };
  63.  
  64. var MalRollingHpBMSetup = BattleManager.setup
  65. BattleManager.setup = function(troopId, canEscape, canLose) {
  66.     MalRollingHpBMSetup.call(this, troopId, canEscape, canLose);
  67.     this.rollingUpdaterHP = 0;
  68.     this.rollingUpdaterMP = 0;
  69.     this.rollingUpdaterTP = 0;
  70.     this.rollingStatSetup();
  71. };
  72.  
  73. BattleManager.rollingStatSetup = function() {
  74. for(var i = 0; i < $gameParty.members().length; i++) {
  75.     actor = $gameParty.members()[i];
  76.     actor.rollingHP = actor.hp;
  77.     actor.rollingMP = actor.mp;
  78.     actor.rollingTP = actor.tp;
  79. };
  80. };
  81.  
  82. var MalRollingHpBMUpdate = BattleManager.update
  83. BattleManager.update = function(timeActive) {
  84.     this.updateRollingStats();
  85.     MalRollingHpBMUpdate.call(this, timeActive);
  86.     if(this._currentActor && this._currentActor.isDead()) this.selectNextCommand();
  87. };
  88.  
  89. BattleManager.updateRollingStats = function() {
  90. if(MalRollingPar1 != 0) this.rollingUpdaterHP++;
  91. if(MalRollingPar2 != 0) this.rollingUpdaterMP++;
  92. if(MalRollingPar3 != 0) this.rollingUpdaterTP++;
  93. if(this.rollingUpdaterHP > MalRollingPar1) {
  94.     this.rollingUpdaterHP = 0;
  95.     this.checkRollingStatHP($gameParty.members());
  96. }
  97. if(this.rollingUpdaterMP > MalRollingPar2) {
  98.     this.rollingUpdaterMP = 0;
  99.     this.checkRollingStatMP($gameParty.members());
  100. }
  101. if(this.rollingUpdaterTP > MalRollingPar3) {
  102.     this.rollingUpdaterTP = 0;
  103.     this.checkRollingStatTP($gameParty.members());
  104. }
  105. };
  106.  
  107. BattleManager.checkRollingStatHP = function(actors){
  108. for(var i = 0; i < actors.length; i++) {
  109.     var actor = actors[i];
  110.     actor.rollingHP = Math.floor(actor.rollingHP);  
  111.     if (actor.hp != actor.rollingHP){
  112.         var multi = 1;
  113.         if(actor.hp > actor.rollingHP) multi *= -1;
  114.         actor.gainHp(multi);
  115.         if(actor.hp == 0) {
  116.             actor.performCollapse();
  117.             actor.rollingHP = 0;
  118.         };
  119.         if (actor.hp > actor.mhp) {
  120.             actor.hp = actor.mhp;
  121.             actor.rollingHP = actor.mhp;
  122.         };
  123.     }
  124. };
  125. };
  126.  
  127. BattleManager.checkRollingStatMP = function(actors){
  128. for(var i = 0; i < actors.length; i++) {
  129.     var actor = actors[i];
  130.     actor.rollingMP = Math.floor(actor.rollingMP);
  131.     if (actor.mp != actor.rollingMP){
  132.     var multi = 1;
  133.     if(actor.mp > actor.rollingMP) multi *= -1;
  134.         actor.gainMp(multi);
  135.     };
  136.     if(actor.mp > actor.mmp) {
  137.         actor.mp = actor.mmp;
  138.         actor.rollingMP = actor.mmp;
  139.     };
  140. };
  141. };
  142.  
  143. BattleManager.checkRollingStatTP = function(actors){
  144. for(var i = 0; i < actors.length; i++) {
  145.     var actor = actors[i];
  146.     actor.rollingTP = Math.floor(actor.rollingTP);
  147.     if (actor._tp != actor.rollingTP){
  148.     var multi = 1;
  149.     if(actor._tp > actor.rollingTP) multi *= -1;
  150.         actor._tp += multi;
  151.     }
  152. };
  153. };
  154.  
  155. var MalRollingGAXHPDam = Game_Action.prototype.executeHpDamage;
  156. Game_Action.prototype.executeHpDamage = function(target, value) {
  157.     if (this.isDrain()) {
  158.         value = Math.min(target.hp, value);
  159.     }
  160.     this.makeSuccess(target);
  161.     if(target.isActor() && SceneManager._scene instanceof Scene_Battle && MalRollingPar1 != 0) {
  162.         var tLuck = target.luk;
  163.         var sLuck = this.subject().luk;
  164.         var perc = 50 + (Math.abs(Math.randomInt(tLuck) - Math.randomInt(sLuck)));
  165.         if(perc > 100) perc = 100;
  166.         if(tLuck < sLuck)  {
  167.             var directDam = parseInt(value * (perc / 100));
  168.             var slideDam = value - directDam;
  169.         } else {
  170.             var slideDam = parseInt(value * (perc / 100));
  171.             var directDam = value - slideDam;
  172.            
  173.         };
  174.         target.gainHp(-directDam);
  175.         target.rollingHP -= Math.floor(value);
  176.         if(target.rollingHP < 0) target.rollingHP = 0;
  177.         if(target.rollingHP > target.mhp) target.rollingHP = target.mhp;
  178.         target._result.hpDamage = value;
  179.         target._result.hpAffected = true;
  180.     } else {
  181.     target.gainHp(-value);
  182.     };
  183.     if (value > 0) {
  184.         target.onDamage(value);
  185.     }
  186.     this.gainDrainedHp(value);
  187. };
  188.  
  189. Game_Action.prototype.executeMpDamage = function(target, value) {
  190.     if (!this.isMpRecover()) {
  191.         value = Math.min(target.mp, value);
  192.     }
  193.     if (value !== 0) {
  194.         this.makeSuccess(target);
  195.         if(target.isActor() && SceneManager._scene instanceof Scene_Battle && MalRollingPar2 != 0) {
  196.             var tLuck = target.luk;
  197.             var sLuck = this.subject().luk;
  198.             var perc = 50 + (Math.abs(Math.randomInt(tLuck) - Math.randomInt(sLuck)));
  199.             if(perc > 100) perc = 100;
  200.             if(tLuck < sLuck)  {
  201.                 var directDam = parseInt(value * (perc / 100));
  202.                 var slideDam = value - directDam;
  203.             } else {
  204.                 var slideDam = parseInt(value * (perc / 100));
  205.                 var directDam = value - slideDam;
  206.            
  207.             };
  208.         target.gainMp(-directDam);
  209.         target.rollingMP -= Math.floor(value);
  210.         if(target.rollingMP < 0) target.rollingMP = 0;
  211.         if(target.rollingMP > target.mmp) target.rollingMP = target.mmp;
  212.         target._result.mpDamage = value;
  213.         } else {    
  214.         target.gainMp(-value);
  215.         };
  216.     this.gainDrainedMp(value);
  217.     };
  218. };
  219.  
  220. Game_Action.prototype.itemEffectRecoverHp = function(target, effect) {
  221.     let value = (target.mhp * effect.value1 + effect.value2) * target.rec;
  222.     if (this.isItem()) {
  223.         value *= this.subject().pha;
  224.     }
  225.     value = Math.floor(value);
  226.     if (value !== 0) {
  227.         var tLuck = target.luk;
  228.         var sLuck = this.subject().luk;
  229.         var perc = 50 + (Math.abs(Math.randomInt(tLuck) - Math.randomInt(sLuck)));
  230.         if(perc > 100) perc = 100;
  231.         if(tLuck < sLuck)  {
  232.             var directDam = parseInt(value * (perc / 100));
  233.             var slideDam = value - directDam;
  234.         } else {
  235.             var slideDam = parseInt(value * (perc / 100));
  236.             var directDam = value - slideDam;
  237.            
  238.         };
  239.         if(target.isActor() && SceneManager._scene instanceof Scene_Battle && MalRollingPar1 != 0) {
  240.         target.gainHp(directDam);
  241.         target.rollingHP += Math.floor(value);
  242.         if(target.rollingHP < 0) target.rollingHP = 0;
  243.         if(target.rollingHP > target.mhp) target.rollingHP = target.mhp;
  244.         target._result.hpDamage = -value;
  245.         target._result.hpAffected = true;
  246.     } else {
  247.         target.gainHp(value);
  248.     };
  249.         this.makeSuccess(target);
  250.     }
  251. };
  252.  
  253. Game_Action.prototype.itemEffectRecoverMp = function(target, effect) {
  254.     let value = (target.mmp * effect.value1 + effect.value2) * target.rec;
  255.     if (this.isItem()) {
  256.         value *= this.subject().pha;
  257.     }
  258.     value = Math.floor(value);
  259.     if (value !== 0) {
  260.         var tLuck = target.luk;
  261.         var sLuck = this.subject().luk;
  262.         var perc = 50 + (Math.abs(Math.randomInt(tLuck) - Math.randomInt(sLuck)));
  263.         if(perc > 100) perc = 100;
  264.         if(tLuck < sLuck)  {
  265.             var directDam = parseInt(value * (perc / 100));
  266.             var slideDam = value - directDam;
  267.         } else {
  268.             var slideDam = parseInt(value * (perc / 100));
  269.             var directDam = value - slideDam;
  270.            
  271.         };
  272.         if(target.isActor() && SceneManager._scene instanceof Scene_Battle && MalRollingPar2 != 0) {
  273.         target.gainMp(directDam);
  274.         target.rollingMP += Math.floor(value);
  275.         if(target.rollingMP < 0) target.rollingMP = 0;
  276.         if(target.rollingMP > target.mmp) target.rollingMP = target.mmp;
  277.         target._result.mpDamage = -value;
  278.     } else {
  279.         target.gainMp(value);
  280.     };
  281.         this.makeSuccess(target);
  282.     }
  283. };
  284.  
  285. Game_Battler.prototype.gainTp = function(value) {
  286.      if(this.isActor() && SceneManager._scene instanceof Scene_Battle && MalRollingPar3 != 0) {
  287.      this._result.tpDamage = -value;
  288.      this.rollingTP += value;
  289.      if(this.rollingTP > this.maxTp()) this.rollingTP = this.maxTp();
  290.      } else {
  291.     this.setTp(this.tp + value);
  292.     };
  293. };
  294.  
  295. Game_Battler.prototype.gainSilentTp = function(value) {
  296.      if(this.isActor() && SceneManager._scene instanceof Scene_Battle && MalRollingPar3 != 0) {
  297.      this.rollingTP += value;
  298.      if(this.rollingTP > this.maxTp()) this.rollingTP = this.maxTp();
  299.      } else {
  300.     this.setTp(this.tp + value);
  301.     };
  302. };
  303.  
  304. Game_Battler.prototype.chargeTpByDamage = function(damageRate) {
  305.     const value = Math.floor(50 * damageRate * this.tcr);
  306.     this.rollingTP += value;
  307.      if(this.rollingTP > this.maxTp()) this.rollingTP = this.maxTp();
  308.     this.gainSilentTp(value);
  309. };
  310.  
  311. Game_BattlerBase.prototype.paySkillCost = function(skill) {
  312.     if(this.isActor() && SceneManager._scene instanceof Scene_Battle) {
  313.         if(MalRollingPar2 != 0) {
  314.             this.rollingMP -= this.skillMpCost(skill);
  315.         } else {
  316.             this._mp -= this.skillMpCost(skill);
  317.         };
  318.         if(MalRollingPar3 != 0) {
  319.             this.rollingTP -= this.skillTpCost(skill);
  320.         } else {
  321.             this._tp -= this.skillTpCost(skill);
  322.         };
  323.     } else {
  324.         this._mp -= this.skillMpCost(skill);
  325.         this._tp -= this.skillTpCost(skill);
  326.     };
  327. };
  328.  
  329. var malRollingStatsInitTp = Game_Battler.prototype.initTp;
  330. Game_Battler.prototype.initTp = function() {
  331.     malRollingStatsInitTp.call(this);
  332.     this.rollingTP = this._tp;
  333. };
  334. /*
  335. ColorManager.hpColor = function(actor) {
  336.     if (!actor) {
  337.         return this.normalColor();
  338.     } else if (actor.isDead() || (actor.rollingHP == 0 && SceneManager._scene instanceof Scene_Battle)) {
  339.         return this.deathColor();
  340.     } else if (actor.isDying()) {
  341.         return this.crisisColor();
  342.     } else {
  343.         return this.normalColor();
  344.     }
  345. };
  346. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement