Maliki79

MalMZRollingStats

Nov 14th, 2020 (edited)
1,390
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.1
  5. //=============================================================================
  6. /*:
  7.  * @target MZ
  8.  *  
  9.  * @plugindesc ver1.1 - 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.  * @param DeathSound
  33.  * @type string    
  34.  * @desc Name of sound that plays if an blow would cause rolling damage to hit 0.
  35.  * @default Scream  
  36.  *
  37.  * @help This plugin is currently plug and play.
  38.  * Just install this plugin and it will do as intended.
  39.  * Optional: You can edit the params to adjust the speed by which the stats roll.
  40.  * (Set a param to 0 to not use that stat.)
  41.  */
  42.  
  43. var MalRollingPar1  = PluginManager.parameters('MalMZRollingStats')["HP Tick Delay"];
  44. if(MalRollingPar1 < 0) MalRollingPar1 = 0;
  45. var MalRollingPar2  = PluginManager.parameters('MalMZRollingStats')["MP Tick Delay"];
  46. if(MalRollingPar2 < 0) MalRollingPar2 = 0;
  47. var MalRollingPar3  = PluginManager.parameters('MalMZRollingStats')["TP Tick Delay"];
  48. if(MalRollingPar3 < 0) MalRollingPar3 = 0;
  49. var deathSound = PluginManager.parameters('MalMZRollingStats')["DeathSound"];
  50. var MalRollingDatabaseLoad = DataManager.isDatabaseLoaded;
  51. DataManager.isDatabaseLoaded = function() {
  52.   if (!MalRollingDatabaseLoad.call(this)) return false;
  53.   if (!DataManager._malRolling_DatabaseLoaded) {
  54.     this.processRollingData($dataActors);
  55.     DataManager._malRolling_DatabaseLoaded = true;
  56.   }
  57.   return true;
  58. };
  59.  
  60. DataManager.processRollingData = function (group) {
  61. for (i = 1; i < group.lenght; i++) {
  62.     var obj = group[i];
  63.     obj.rollingHP = 0;
  64.     obj.rollingMP = 0;
  65.     obj.rollingTP = 0;
  66.     obj.playDeathSE = true;
  67. };
  68. };
  69.  
  70. var MalRollingHpBMSetup = BattleManager.setup
  71. BattleManager.setup = function(troopId, canEscape, canLose) {
  72.     MalRollingHpBMSetup.call(this, troopId, canEscape, canLose);
  73.     this.rollingUpdaterHP = 0;
  74.     this.rollingUpdaterMP = 0;
  75.     this.rollingUpdaterTP = 0;
  76.     this.rollingStatSetup();
  77. };
  78.  
  79. BattleManager.rollingStatSetup = function() {
  80. for(var i = 0; i < $gameParty.members().length; i++) {
  81.     actor = $gameParty.members()[i];
  82.     actor.rollingHP = actor.hp;
  83.     actor.rollingMP = actor.mp;
  84.     actor.rollingTP = actor.tp;
  85.     actor.playDeathSE = true;
  86. };
  87. };
  88.  
  89. var MalRollingHpBMUpdate = BattleManager.update
  90. BattleManager.update = function(timeActive) {
  91.     this.updateRollingStats();
  92.     MalRollingHpBMUpdate.call(this, timeActive);
  93.     if(this._currentActor && this._currentActor.isDead()) this.selectNextCommand();
  94. };
  95.  
  96. BattleManager.updateRollingStats = function() {
  97. if(MalRollingPar1 != 0) this.rollingUpdaterHP++;
  98. if(MalRollingPar2 != 0) this.rollingUpdaterMP++;
  99. if(MalRollingPar3 != 0) this.rollingUpdaterTP++;
  100. if(this.rollingUpdaterHP > MalRollingPar1) {
  101.     this.rollingUpdaterHP = 0;
  102.     this.checkRollingStatHP($gameParty.members());
  103. }
  104. if(this.rollingUpdaterMP > MalRollingPar2) {
  105.     this.rollingUpdaterMP = 0;
  106.     this.checkRollingStatMP($gameParty.members());
  107. }
  108. if(this.rollingUpdaterTP > MalRollingPar3) {
  109.     this.rollingUpdaterTP = 0;
  110.     this.checkRollingStatTP($gameParty.members());
  111. }
  112. };
  113.  
  114. BattleManager.checkRollingStatHP = function(actors){
  115. for(var i = 0; i < actors.length; i++) {
  116.     var actor = actors[i];
  117.     actor.rollingHP = Math.floor(actor.rollingHP);  
  118.     if (actor.hp != actor.rollingHP){
  119.         var multi = 1;
  120.         if(actor.hp > actor.rollingHP) multi *= -1;
  121.         actor.gainHp(multi);
  122.         if(actor.hp == 0) {
  123.             actor.performCollapse();
  124.             actor.rollingHP = 0;
  125.         };
  126.         if (actor.hp > actor.mhp) {
  127.             actor.hp = actor.mhp;
  128.             actor.rollingHP = actor.mhp;
  129.         };
  130.     }
  131. };
  132. };
  133.  
  134. BattleManager.checkRollingStatMP = function(actors){
  135. for(var i = 0; i < actors.length; i++) {
  136.     var actor = actors[i];
  137.     actor.rollingMP = Math.floor(actor.rollingMP);
  138.     if (actor.mp != actor.rollingMP){
  139.     var multi = 1;
  140.     if(actor.mp > actor.rollingMP) multi *= -1;
  141.         actor.gainMp(multi);
  142.     };
  143.     if(actor.mp > actor.mmp) {
  144.         actor.mp = actor.mmp;
  145.         actor.rollingMP = actor.mmp;
  146.     };
  147. };
  148. };
  149.  
  150. BattleManager.checkRollingStatTP = function(actors){
  151. for(var i = 0; i < actors.length; i++) {
  152.     var actor = actors[i];
  153.     actor.rollingTP = Math.floor(actor.rollingTP);
  154.     if (actor._tp != actor.rollingTP){
  155.     var multi = 1;
  156.     if(actor._tp > actor.rollingTP) multi *= -1;
  157.         actor._tp += multi;
  158.     }
  159. };
  160. };
  161.  
  162. var MalRollingGAXHPDam = Game_Action.prototype.executeHpDamage;
  163. Game_Action.prototype.executeHpDamage = function(target, value) {
  164.     if (this.isDrain()) {
  165.         value = Math.min(target.hp, value);
  166.     }
  167.     this.makeSuccess(target);
  168.     if(target.isActor() && SceneManager._scene instanceof Scene_Battle && MalRollingPar1 != 0) {
  169.         var tLuck = target.luk;
  170.         var sLuck = this.subject().luk;
  171.         var perc = 50 + (Math.abs(Math.randomInt(tLuck) - Math.randomInt(sLuck)));
  172.         if(perc > 100) perc = 100;
  173.         if(tLuck < sLuck)  {
  174.             var directDam = parseInt(value * (perc / 100));
  175.             var slideDam = value - directDam;
  176.         } else {
  177.             var slideDam = parseInt(value * (perc / 100));
  178.             var directDam = value - slideDam;
  179.            
  180.         };
  181.         target.gainHp(-directDam);
  182.         target.rollingHP -= Math.floor(value);
  183.         if(target.rollingHP < 0) target.rollingHP = 0;
  184.         if(target.rollingHP == 0){
  185.             if (target.playDeathSE) this.playDeathSound(target);
  186.         } else {
  187.             target.playDeathSE = true;
  188.         };
  189.         if(target.rollingHP > target.mhp) target.rollingHP = target.mhp;
  190.         target._result.hpDamage = value;
  191.         target._result.hpAffected = true;
  192.     } else {
  193.     target.gainHp(-value);
  194.     };
  195.     if (value > 0) {
  196.         target.onDamage(value);
  197.     }
  198.     this.gainDrainedHp(value);
  199. };
  200.  
  201. Game_Action.prototype.executeMpDamage = function(target, value) {
  202.     if (!this.isMpRecover()) {
  203.         value = Math.min(target.mp, value);
  204.     }
  205.     if (value !== 0) {
  206.         this.makeSuccess(target);
  207.         if(target.isActor() && SceneManager._scene instanceof Scene_Battle && MalRollingPar2 != 0) {
  208.             var tLuck = target.luk;
  209.             var sLuck = this.subject().luk;
  210.             var perc = 50 + (Math.abs(Math.randomInt(tLuck) - Math.randomInt(sLuck)));
  211.             if(perc > 100) perc = 100;
  212.             if(tLuck < sLuck)  {
  213.                 var directDam = parseInt(value * (perc / 100));
  214.                 var slideDam = value - directDam;
  215.             } else {
  216.                 var slideDam = parseInt(value * (perc / 100));
  217.                 var directDam = value - slideDam;
  218.            
  219.             };
  220.         target.gainMp(-directDam);
  221.         target.rollingMP -= Math.floor(value);
  222.         if(target.rollingMP < 0) target.rollingMP = 0;
  223.         if(target.rollingMP > target.mmp) target.rollingMP = target.mmp;
  224.         target._result.mpDamage = value;
  225.         } else {    
  226.         target.gainMp(-value);
  227.         };
  228.     this.gainDrainedMp(value);
  229.     };
  230. };
  231.  
  232. Game_Action.prototype.itemEffectRecoverHp = function(target, effect) {
  233.     let value = (target.mhp * effect.value1 + effect.value2) * target.rec;
  234.     if (this.isItem()) {
  235.         value *= this.subject().pha;
  236.     }
  237.     value = Math.floor(value);
  238.     if (value !== 0) {
  239.         var tLuck = target.luk;
  240.         var sLuck = this.subject().luk;
  241.         var perc = 50 + (Math.abs(Math.randomInt(tLuck) - Math.randomInt(sLuck)));
  242.         if(perc > 100) perc = 100;
  243.         if(tLuck < sLuck)  {
  244.             var directDam = parseInt(value * (perc / 100));
  245.             var slideDam = value - directDam;
  246.         } else {
  247.             var slideDam = parseInt(value * (perc / 100));
  248.             var directDam = value - slideDam;
  249.            
  250.         };
  251.         if(target.isActor() && SceneManager._scene instanceof Scene_Battle && MalRollingPar1 != 0) {
  252.         target.gainHp(directDam);
  253.         target.rollingHP += Math.floor(value);
  254.         if(target.rollingHP < 0) target.rollingHP = 0;
  255.         if(target.rollingHP == 0){
  256.             if (target.playDeathSE) this.playDeathSound(target);
  257.         } else {
  258.             target.playDeathSE = true;
  259.         };
  260.         if(target.rollingHP > target.mhp) target.rollingHP = target.mhp;
  261.         target._result.hpDamage = -value;
  262.         target._result.hpAffected = true;
  263.     } else {
  264.         target.gainHp(value);
  265.     };
  266.         this.makeSuccess(target);
  267.     }
  268. };
  269.  
  270. Game_Action.prototype.itemEffectRecoverMp = function(target, effect) {
  271.     let value = (target.mmp * effect.value1 + effect.value2) * target.rec;
  272.     if (this.isItem()) {
  273.         value *= this.subject().pha;
  274.     }
  275.     value = Math.floor(value);
  276.     if (value !== 0) {
  277.         var tLuck = target.luk;
  278.         var sLuck = this.subject().luk;
  279.         var perc = 50 + (Math.abs(Math.randomInt(tLuck) - Math.randomInt(sLuck)));
  280.         if(perc > 100) perc = 100;
  281.         if(tLuck < sLuck)  {
  282.             var directDam = parseInt(value * (perc / 100));
  283.             var slideDam = value - directDam;
  284.         } else {
  285.             var slideDam = parseInt(value * (perc / 100));
  286.             var directDam = value - slideDam;
  287.            
  288.         };
  289.         if(target.isActor() && SceneManager._scene instanceof Scene_Battle && MalRollingPar2 != 0) {
  290.         target.gainMp(directDam);
  291.         target.rollingMP += Math.floor(value);
  292.         if(target.rollingMP < 0) target.rollingMP = 0;
  293.         if(target.rollingMP > target.mmp) target.rollingMP = target.mmp;
  294.         target._result.mpDamage = -value;
  295.     } else {
  296.         target.gainMp(value);
  297.     };
  298.         this.makeSuccess(target);
  299.     }
  300. };
  301.  
  302. Game_Action.prototype.playDeathSound = function (actor) {
  303.     var sound = {
  304.             name: deathSound,
  305.             volume: 100,
  306.             pitch: 100,
  307.             pan: 0,
  308.             };
  309.     AudioManager.playSe(sound);
  310.     actor.playDeathSE = false;
  311.     console.log("Played Sound?");
  312. };
  313.  
  314. Game_Battler.prototype.gainTp = function(value) {
  315.      if(this.isActor() && SceneManager._scene instanceof Scene_Battle && MalRollingPar3 != 0) {
  316.      this._result.tpDamage = -value;
  317.      this.rollingTP += value;
  318.      if(this.rollingTP > this.maxTp()) this.rollingTP = this.maxTp();
  319.      } else {
  320.     this.setTp(this.tp + value);
  321.     };
  322. };
  323.  
  324. Game_Battler.prototype.gainSilentTp = function(value) {
  325.      if(this.isActor() && SceneManager._scene instanceof Scene_Battle && MalRollingPar3 != 0) {
  326.      this.rollingTP += value;
  327.      if(this.rollingTP > this.maxTp()) this.rollingTP = this.maxTp();
  328.      } else {
  329.     this.setTp(this.tp + value);
  330.     };
  331. };
  332.  
  333. Game_Battler.prototype.chargeTpByDamage = function(damageRate) {
  334.     const value = Math.floor(50 * damageRate * this.tcr);
  335.     this.rollingTP += value;
  336.      if(this.rollingTP > this.maxTp()) this.rollingTP = this.maxTp();
  337.     this.gainSilentTp(value);
  338. };
  339.  
  340. Game_BattlerBase.prototype.paySkillCost = function(skill) {
  341.     if(this.isActor() && SceneManager._scene instanceof Scene_Battle) {
  342.         if(MalRollingPar2 != 0) {
  343.             this.rollingMP -= this.skillMpCost(skill);
  344.         } else {
  345.             this._mp -= this.skillMpCost(skill);
  346.         };
  347.         if(MalRollingPar3 != 0) {
  348.             this.rollingTP -= this.skillTpCost(skill);
  349.         } else {
  350.             this._tp -= this.skillTpCost(skill);
  351.         };
  352.     } else {
  353.         this._mp -= this.skillMpCost(skill);
  354.         this._tp -= this.skillTpCost(skill);
  355.     };
  356. };
  357.  
  358. var malRollingStatsInitTp = Game_Battler.prototype.initTp;
  359. Game_Battler.prototype.initTp = function() {
  360.     malRollingStatsInitTp.call(this);
  361.     this.rollingTP = this._tp;
  362. };
  363. ColorManager.hpColor = function(actor) {
  364.     if (!actor) {
  365.         return this.normalColor();
  366.     } else if (actor.isDead() || (actor.rollingHP == 0 && SceneManager._scene instanceof Scene_Battle)) {
  367.         return this.deathColor();
  368.     } else if (actor.isDying()) {
  369.         return this.crisisColor();
  370.     } else {
  371.         return this.normalColor();
  372.     }
  373. };
Add Comment
Please, Sign In to add comment