Sorry, I forgot to test this in battle, so it only worked if the characters lost MP through an event.
Here's the fixed version:
Spoiler
Code:
/*:
* @plugindesc Restore MP some time after it's used.
* @author Nolonar
*
* @param Delay
* @desc How long to wait before recovering the MP used.
* @type number
* @min 1
*
* @param Delay unit
* @desc Whether the delay is in seconds, minutes, or hours
* @type select
* @option Seconds
* @option Minutes
* @option Hours
*/
(function() {
let Parameters = PluginManager.parameters('MpDelayedAutorecovery');
let Param = {
Delay: Parameters['Delay'],
DelayUnit: Parameters['Delay unit']
};
let Seconds = 1000;
let Minutes = 60 * Seconds;
let Hours = 60 * Minutes;
let factor = {
Seconds: Seconds,
Minutes: Minutes,
Hours: Hours
};
let recoveryQueue = [];
Game_BattlerBase.prototype.trackMpLoss = function(mpLoss) {
if (mpLoss <= 0)
return;
recoveryQueue.push({
time: Date.now() + Param.Delay * factor[Param.DelayUnit],
battler: this,
amount: mpLoss
});
}
let Game_Battler_gainMp = Game_Battler.prototype.gainMp;
Game_Battler.prototype.gainMp = function(value) {
Game_Battler_gainMp.call(this, value);
this.trackMpLoss(-value);
};
let Game_BattlerBase_paySkillCost = Game_BattlerBase.prototype.paySkillCost;
Game_BattlerBase.prototype.paySkillCost = function(skill) {
Game_BattlerBase_paySkillCost.call(this, skill);
this.trackMpLoss(this.skillMpCost(skill));
};
let SceneManager_update = SceneManager.update;
SceneManager.update = function() {
SceneManager_update.call(this);
while (recoveryQueue.length) {
let recoveryData = recoveryQueue[0];
if (Date.now() < recoveryData.time)
return;
recoveryData.battler.gainMp(recoveryData.amount);
recoveryQueue.shift();
}
};
})();
As for how to change the implementation from real clock to ingame clock:
1. Replace any instance of
Date.now() with whatever your current ingame time is.
Note that
Date.now() returns the number of milliseconds that have elapsed since 1970. It's a number that keeps growing.
I'm assuming that your ingame clock may be split into seconds, minutes, and hours, and each of these values are reset to 0 when they grow beyond 60 (24 for hours).
If that's the case, I can help you modify the plugin to work with your ingame clock, but then I need to know how your clock's implemented.
2. Adjust the values to the right of
let Seconds,
let Minutes, and
let Hours.
For instance, if your clock is based on seconds instead of milliseconds,
Seconds must be
1. If it takes 10 seconds for 1 minute, then
Minutes must be
10 * Seconds, etc.
Note that this only applies if your clock has a unified value. If the clock is separated into seconds, minutes, and hours, then I need to know how the clock is implemented to make the necessary modifications.