/*:
* @target MV
* @plugindesc Lets you add random values to base parameters on level-up.
* @author Caethyril
* @url https://forums.rpgmakerweb.com/posts/985630/
* @help Actor/Class notetag (case-sensitive!):
* <Level Up STAT: X>
* <Level Up STAT: X to Y>
* - Replace STAT with one of these:
* MHP, MMP, ATK, DEF, MAT, MDF, AGI, LUK
* - Replace X with the minimum amount to add (integer)
* - Replace Y with the maximum amount to add (integer)
* -> Note: Y should be greater than X.
* Examples:
* <Level Up MHP: 40> + 40 max HP per level
* <Level Up ATK: 5 to 15> + 5~15 (inclusive) ATK per level
* <Level Up LUK: 0 to 8> + 0~8 (inclusive) LUK per level
*
* Note that this is not designed to work with "level-downs".
* The stat gains are permanent and are not tracked separately.
*
* [Edit: stat gains are now applied once per level per actor,
* for use with level-downs & class changes.]
*
* Terms of use:
* Free to use and/or modify for any project, no credit required.
*/
;void (function() {
'use strict';
/** Name of notetag for this plugin. %1 = param name, cf {@linkcode PARAMS}. */
const TAGNAME = 'Level Up %1';
/** Param names used in notetag. */
const PARAMS = ['MHP', 'MMP', 'ATK', 'DEF', 'MAT', 'MDF', 'AGI', 'LUK'];
/** Splitter for random ranges used in notetag. */
const SPLITTER = 'to';
/** Property name for storing highest level for which bonus params have been received. */
const MAX_LVUP = "_maxLevelBonusGained"; // for Change Class
const alias = Game_Actor.prototype.levelUp;
Game_Actor.prototype.levelUp = function() {
alias.apply(this, arguments);
if (!this[MAX_LVUP] || this[MAX_LVUP] < this._level) {
this[MAX_LVUP] = this._level;
PARAMS.forEach(function(p, n) {
for (const o of [this.actor(), this.currentClass()]) {
const tag = o.meta[TAGNAME.format(p)];
if (tag) {
const arr = tag.split(SPLITTER).map(function(num) {
return parseInt(num, 10);
});
let add = 0;
if (!isNaN(arr[0]))
add += arr[0];
if (!isNaN(arr[1])) {
const m = arr[1] - (isNaN(arr[0]) ? 0 : arr[0]) + 1;
if (m > 0)
add += Math.randomInt(m);
}
this.addParam(n, add);
}
}
}, this);
}
};
})();