Advertisement
Maliki79

MalMZRollingStats

Nov 14th, 2020 (edited)
2,884
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Maliki's Rolling Stats MZ
  3. // MalMZRollingStats.js
  4. // version 1.1b
  5. //=============================================================================
  6. /*:
  7.  * @target MZ
  8.  *  
  9.  * @plugindesc ver1.1b - 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('MalMZRollingStats')["HP Tick Delay"];
  39. if(MalRollingPar1 < 0) MalRollingPar1 = 0;
  40. var MalRollingPar2  = PluginManager.parameters('MalMZRollingStats')["MP Tick Delay"];
  41. if(MalRollingPar2 < 0) MalRollingPar2 = 0;
  42. var MalRollingPar3  = PluginManager.parameters('MalMZRollingStats')["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.     obj.playDeathSE = true;
  62. };
  63. };
  64.  
  65. var MalRollingHpBMSetup = BattleManager.setup
  66. BattleManager.setup = function(troopId, canEscape, canLose) {
  67.     MalRollingHpBMSetup.call(this, troopId, canEscape, canLose);
  68.     this.rollingUpdaterHP = 0;
  69.     this.rollingUpdaterMP = 0;
  70.     this.rollingUpdaterTP = 0;
  71.     this.rollingStatSetup();
  72. };
  73.  
  74. BattleManager.rollingStatSetup = function() {
  75. for(var i = 0; i < $gameParty.members().length; i++) {
  76.     actor = $gameParty.members()[i];
  77.     actor.rollingHP = actor.hp;
  78.     actor.rollingMP = actor.mp;
  79.     actor.rollingTP = actor.tp;
  80. };
  81. };
  82.  
  83. var MalRollingHpBMUpdate = BattleManager.update
  84. BattleManager.update = function(timeActive) {
  85.     this.updateRollingStats();
  86.     MalRollingHpBMUpdate.call(this, timeActive);
  87.     if(this._currentActor && this._currentActor.isDead()) this.selectNextCommand();
  88. };
  89.  
  90. BattleManager.updateRollingStats = function() {
  91. if(MalRollingPar1 != 0) this.rollingUpdaterHP++;
  92. if(MalRollingPar2 != 0) this.rollingUpdaterMP++;
  93. if(MalRollingPar3 != 0) this.rollingUpdaterTP++;
  94. if(this.rollingUpdaterHP > MalRollingPar1) {
  95.     this.rollingUpdaterHP = 0;
  96.     this.checkRollingStatHP($gameParty.members());
  97. }
  98. if(this.rollingUpdaterMP > MalRollingPar2) {
  99.     this.rollingUpdaterMP = 0;
  100.     this.checkRollingStatMP($gameParty.members());
  101. }
  102. if(this.rollingUpdaterTP > MalRollingPar3) {
  103.     this.rollingUpdaterTP = 0;
  104.     this.checkRollingStatTP($gameParty.members());
  105. }
  106. };
  107.  
  108. BattleManager.checkRollingStatHP = function(actors){
  109. for(var i = 0; i < actors.length; i++) {
  110.     var actor = actors[i];
  111.     actor.rollingHP = Math.floor(actor.rollingHP);  
  112.     if(actor.isDead()) actor.rollingHP = 0;
  113.     if (actor.hp != actor.rollingHP){
  114.         var multi = 1;
  115.         if(actor.hp > actor.rollingHP) multi *= -1;
  116.         actor.setHp(actor.hp + multi); //actor.gainHp(multi);
  117.         if(actor.hp == 0) {
  118.             actor.performCollapse();
  119.             actor.rollingHP = 0;
  120.         };
  121.         if (actor.hp > actor.mhp) {
  122.             actor.hp = actor.mhp;
  123.             actor.rollingHP = actor.mhp;
  124.         };
  125.     }
  126. };
  127. };
  128.  
  129. BattleManager.checkRollingStatMP = function(actors){
  130. for(var i = 0; i < actors.length; i++) {
  131.     var actor = actors[i];
  132.     actor.rollingMP = Math.floor(actor.rollingMP);
  133.     if (actor.mp != actor.rollingMP){
  134.     var multi = 1;
  135.     if(actor.mp > actor.rollingMP) multi *= -1;
  136.         actor.gainMp(multi);
  137.     };
  138.     if(actor.mp > actor.mmp) {
  139.         actor.mp = actor.mmp;
  140.         actor.rollingMP = actor.mmp;
  141.     };
  142. };
  143. };
  144.  
  145. BattleManager.checkRollingStatTP = function(actors){
  146. for(var i = 0; i < actors.length; i++) {
  147.     var actor = actors[i];
  148.     actor.rollingTP = Math.floor(actor.rollingTP);
  149.     if (actor._tp != actor.rollingTP){
  150.     var multi = 1;
  151.     if(actor._tp > actor.rollingTP) multi *= -1;
  152.         actor._tp += multi;
  153.     }
  154. };
  155. };
  156.  
  157. var MalRollingGAXHPDam = Game_Action.prototype.executeHpDamage;
  158. Game_Action.prototype.executeHpDamage = function(target, value) {
  159.     if (this.isDrain()) {
  160.         value = Math.min(target.hp, value);
  161.     }
  162.     this.makeSuccess(target);
  163.     if(target.isActor() && SceneManager._scene instanceof Scene_Battle && MalRollingPar1 != 0) {
  164.         var tLuck = target.luk;
  165.         var sLuck = this.subject().luk;
  166.         var perc = 50 + (Math.abs(Math.randomInt(tLuck) - Math.randomInt(sLuck)));
  167.         if(perc > 100) perc = 100;
  168.         if(tLuck < sLuck)  {
  169.             var directDam = parseInt(value * (perc / 100));
  170.             var slideDam = value - directDam;
  171.         } else {
  172.             var slideDam = parseInt(value * (perc / 100));
  173.             var directDam = value - slideDam;
  174.            
  175.         };
  176.         target.gainHp(-directDam);
  177.         target.rollingHP -= Math.floor(value);
  178.         if(target.rollingHP < 0) target.rollingHP = 0;
  179.         if (target.rollingHP == 0 && target.playDeathSE) this.playDeathSound(target);
  180.         if(target.rollingHP > target.mhp) target.rollingHP = target.mhp;
  181.         target._result.hpDamage = value;
  182.         target._result.hpAffected = true;
  183.     } else {
  184.     target.gainHp(-value);
  185.     };
  186.     if (value > 0) {
  187.         target.onDamage(value);
  188.     }
  189.     this.gainDrainedHp(value);
  190. };
  191.  
  192. Game_Action.prototype.executeMpDamage = function(target, value) {
  193.     if (!this.isMpRecover()) {
  194.         value = Math.min(target.mp, value);
  195.     }
  196.     if (value !== 0) {
  197.         this.makeSuccess(target);
  198.         if(target.isActor() && SceneManager._scene instanceof Scene_Battle && MalRollingPar2 != 0) {
  199.             var tLuck = target.luk;
  200.             var sLuck = this.subject().luk;
  201.             var perc = 50 + (Math.abs(Math.randomInt(tLuck) - Math.randomInt(sLuck)));
  202.             if(perc > 100) perc = 100;
  203.             if(tLuck < sLuck)  {
  204.                 var directDam = parseInt(value * (perc / 100));
  205.                 var slideDam = value - directDam;
  206.             } else {
  207.                 var slideDam = parseInt(value * (perc / 100));
  208.                 var directDam = value - slideDam;
  209.            
  210.             };
  211.         target.gainMp(-directDam);
  212.         target.rollingMP -= Math.floor(value);
  213.         if(target.rollingMP < 0) target.rollingMP = 0;
  214.         if(target.rollingMP > target.mmp) target.rollingMP = target.mmp;
  215.         target._result.mpDamage = value;
  216.         } else {    
  217.         target.gainMp(-value);
  218.         };
  219.     this.gainDrainedMp(value);
  220.     };
  221. };
  222.  
  223. Game_Action.prototype.itemEffectRecoverHp = function(target, effect) {
  224.     let value = (target.mhp * effect.value1 + effect.value2) * target.rec;
  225.     if (this.isItem()) {
  226.         value *= this.subject().pha;
  227.     }
  228.     value = Math.floor(value);
  229.     if (value !== 0) {
  230.         var tLuck = target.luk;
  231.         var sLuck = this.subject().luk;
  232.         var perc = 50 + (Math.abs(Math.randomInt(tLuck) - Math.randomInt(sLuck)));
  233.         if(perc > 100) perc = 100;
  234.         if(tLuck < sLuck)  {
  235.             var directDam = parseInt(value * (perc / 100));
  236.             var slideDam = value - directDam;
  237.         } else {
  238.             var slideDam = parseInt(value * (perc / 100));
  239.             var directDam = value - slideDam;
  240.            
  241.         };
  242.         if(target.isActor() && SceneManager._scene instanceof Scene_Battle && MalRollingPar1 != 0) {
  243.         target.gainHp(directDam);
  244.         target.rollingHP += Math.floor(value);
  245.         if(target.rollingHP < 0) target.rollingHP = 0;
  246.         if(target.rollingHP > target.mhp) target.rollingHP = target.mhp;
  247.         target._result.hpDamage = -value;
  248.         target._result.hpAffected = true;
  249.     } else {
  250.         target.gainHp(value);
  251.     };
  252.         this.makeSuccess(target);
  253.     }
  254. };
  255.  
  256.  Game_Battler.prototype.regenerateHp = function() {
  257.     const minRecover = -this.maxSlipDamage();
  258.     const value = Math.max(Math.floor(this.mhp * this.hrg), minRecover);
  259.     if (value !== 0) {
  260.         if (this.isActor() && SceneManager._scene instanceof Scene_Battle && MalRollingPar1 != 0) {
  261.             this.rollingHP += value;
  262.             if(this.rollingHP < 0) this.rollingHP = 0;
  263.         } else {
  264.         this.gainHp(value);
  265.         }
  266.     }
  267. };
  268.  
  269.  
  270. Game_Battler.prototype.regenerateMp = function() {
  271.     const value = Math.floor(this.mmp * this.mrg);
  272.     if (value !== 0) {
  273.         if(this.isActor() && SceneManager._scene instanceof Scene_Battle && MalRollingPar2 != 0) {
  274.             this.rollingMP += value;
  275.             if(this.rollingMP < 0) this.rollingMP = 0;
  276.         } else {
  277.         this.gainMp(value);
  278.         }
  279.     }
  280. };
  281.  
  282.  
  283. Game_Action.prototype.gainDrainedHp = function(value) {
  284.     if (this.isDrain()) {
  285.         let gainTarget = this.subject();
  286.         if (this._reflectionTarget) {
  287.             gainTarget = this._reflectionTarget;
  288.         }
  289.         if(gainTarget.isActor() && SceneManager._scene instanceof Scene_Battle && MalRollingPar1 != 0) {
  290.             gainTarget.rollingHP += value;
  291.             if(gainTarget.rollingHP < 0) gainTarget.rollingHP = 0;
  292.         } else {
  293.         gainTarget.gainHp(value);
  294.         }
  295.     }
  296. };
  297.  
  298. Game_Action.prototype.gainDrainedMp = function(value) {
  299.     if (this.isDrain()) {
  300.         let gainTarget = this.subject();
  301.         if (this._reflectionTarget) {
  302.             gainTarget = this._reflectionTarget;
  303.         }
  304.         if(gainTarget.isActor() && SceneManager._scene instanceof Scene_Battle && MalRollingPar2 != 0) {
  305.             gainTarget.rollingMP += value;
  306.             if(gainTarget.rollingMP < 0) gainTarget.rollingMP = 0;
  307.         } else {
  308.         gainTarget.gainMp(value);
  309.         }
  310.     }
  311. };
  312.  
  313. Game_Action.prototype.itemEffectRecoverMp = function(target, effect) {
  314.     let value = (target.mmp * effect.value1 + effect.value2) * target.rec;
  315.     if (this.isItem()) {
  316.         value *= this.subject().pha;
  317.     }
  318.     value = Math.floor(value);
  319.     if (value !== 0) {
  320.         var tLuck = target.luk;
  321.         var sLuck = this.subject().luk;
  322.         var perc = 50 + (Math.abs(Math.randomInt(tLuck) - Math.randomInt(sLuck)));
  323.         if(perc > 100) perc = 100;
  324.         if(tLuck < sLuck)  {
  325.             var directDam = parseInt(value * (perc / 100));
  326.             var slideDam = value - directDam;
  327.         } else {
  328.             var slideDam = parseInt(value * (perc / 100));
  329.             var directDam = value - slideDam;
  330.            
  331.         };
  332.         if(target.isActor() && SceneManager._scene instanceof Scene_Battle && MalRollingPar2 != 0) {
  333.         target.gainMp(directDam);
  334.         target.rollingMP += Math.floor(value);
  335.         if(target.rollingMP < 0) target.rollingMP = 0;
  336.         if(target.rollingMP > target.mmp) target.rollingMP = target.mmp;
  337.         target._result.mpDamage = -value;
  338.     } else {
  339.         target.gainMp(value);
  340.     };
  341.         this.makeSuccess(target);
  342.     }
  343. };
  344.  
  345. Game_Action.prototype.playDeathSound = function (actor) {
  346.     var sound = {
  347.             name: "Bell1",
  348.             volume: 100,
  349.             pitch: 100,
  350.             pan: 0,
  351.             };
  352.     AudioManager.playSe(sound);
  353. };
  354.  
  355. Game_Battler.prototype.gainTp = function(value) {
  356.      if(this.isActor() && SceneManager._scene instanceof Scene_Battle && MalRollingPar3 != 0) {
  357.      this._result.tpDamage = -value;
  358.      this.rollingTP += value;
  359.      if(this.rollingTP > this.maxTp()) this.rollingTP = this.maxTp();
  360.      } else {
  361.     this.setTp(this.tp + value);
  362.     };
  363. };
  364.  
  365. Game_Battler.prototype.gainSilentTp = function(value) {
  366.      if(this.isActor() && SceneManager._scene instanceof Scene_Battle && MalRollingPar3 != 0) {
  367.      this.rollingTP += value;
  368.      if(this.rollingTP > this.maxTp()) this.rollingTP = this.maxTp();
  369.      } else {
  370.     this.setTp(this.tp + value);
  371.     };
  372. };
  373.  
  374. Game_Battler.prototype.chargeTpByDamage = function(damageRate) {
  375.     const value = Math.floor(50 * damageRate * this.tcr);
  376.     this.rollingTP += value;
  377.      if(this.rollingTP > this.maxTp()) this.rollingTP = this.maxTp();
  378.     this.gainSilentTp(value);
  379. };
  380.  
  381. Game_BattlerBase.prototype.paySkillCost = function(skill) {
  382.     if(this.isActor() && SceneManager._scene instanceof Scene_Battle) {
  383.         if(MalRollingPar2 != 0) {
  384.             this.rollingMP -= this.skillMpCost(skill);
  385.         } else {
  386.             this._mp -= this.skillMpCost(skill);
  387.         };
  388.         if(MalRollingPar3 != 0) {
  389.             this.rollingTP -= this.skillTpCost(skill);
  390.         } else {
  391.             this._tp -= this.skillTpCost(skill);
  392.         };
  393.     } else {
  394.         this._mp -= this.skillMpCost(skill);
  395.         this._tp -= this.skillTpCost(skill);
  396.     };
  397. };
  398.  
  399. var malRollingStatsInitTp = Game_Battler.prototype.initTp;
  400. Game_Battler.prototype.initTp = function() {
  401.     malRollingStatsInitTp.call(this);
  402.     this.rollingTP = this._tp;
  403. };
  404. ColorManager.hpColor = function(actor) {
  405.     if (!actor) {
  406.         return this.normalColor();
  407.     } else if (actor.isDead() || (actor.rollingHP == 0 && SceneManager._scene instanceof Scene_Battle)) {
  408.         return this.deathColor();
  409.     } else if (actor.isDying()) {
  410.         return this.crisisColor();
  411.     } else {
  412.         return this.normalColor();
  413.     }
  414. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement