Advertisement
Maliki79

MalMVRollingStats

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