Advertisement
Maliki79

MalMZRollingStats

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