!function(e, t) { "object" == typeof exports && "undefined" != typeof module ? t(exports, require("lodash-es")) : "function" == typeof define && define.amd ? define([ "exports", "lodash-es" ], t) : t((e = "undefined" != typeof globalThis ? globalThis : e || self).BlueloversRpglevel = {}, e.lodashEs); }(this, (function(e, t) { "use strict"; class RPGLevel { constructor() { this._exp = 0, this._necessaryExps = [], this._minLevel = 1, this._cachedStates = null; } defineExpTable(e, t) { this._necessaryExps = this._generateNecessaryExps(e, t); } defineExpTableByArray(e) { this._necessaryExps = [ ...e ]; } _generateNecessaryExps(e, s) { const r = this; s = t.assign({ startLevel: 1, maxLevel: 99 }, s || {}); const l = []; let i = 0, a = 0; const n = {}; return t.range(this._minLevel, s.maxLevel + 1).map((function(t) { let h; return t <= s.startLevel ? h = 0 : (h = e(t, { minLevel: r._minLevel, startLevel: s.startLevel, maxLevel: s.maxLevel, exps: l.slice(), previousExp: i, previousTotalExp: a, memo: n }), i = h, a += h), l.push(h), h; })); } getMinLevel() { return this._minLevel; } getMaxLevel() { return this._necessaryExps.length; } _getIndexByLevel(e) { return e - 1; } _getLevelByIndex(e) { return Number(e) + 1; } _getStartIndex() { for (let e = 0; e < this._necessaryExps.length; e++) if (this._necessaryExps[e] > 0) return Number(e) - 1; } getStartLevel() { return this._getLevelByIndex(this._getStartIndex()); } getExp() { return this._exp; } getNecessaryExpByLevel(e) { return this._necessaryExps[this._getIndexByLevel(e)]; } getTotalNecessaryExp(e, s) { const r = this; if (e > s) throw new Error("toLevel should be greater than fromLevel"); if (e < this._minLevel || s > this.getMaxLevel()) throw new Error("fromLevel or toLevel is out of range"); return t.reduce(t.range(e, s + 1), (function(e, t) { return e + r.getNecessaryExpByLevel(t); }), 0); } getMaxExp() { return this.getTotalNecessaryExp(this.getMinLevel(), this.getMaxLevel()); } _cleanCaches() { this._cachedStates = null; } setExp(e) { this._exp = parseInt(e, 10), this._cleanCaches(); } resetExp() { this.setExp(0); } setLevel(e) { const t = this.getTotalNecessaryExp(this.getStartLevel(), e); this.setExp(t); } _hasCachedStates() { return !!this._cachedStates; } getStates() { const e = this; if (this._hasCachedStates()) return t.cloneDeep(this._cachedStates); let s = 0, r = 0, l = 0, i = 0; this._necessaryExps.every((function(t, a) { const n = e._getLevelByIndex(a); return r += t, e.getExp() >= r ? (s = n, !0) : (l = t, i = e.getExp() - (r - t), !1); })); const a = { level: s, necessaryExpForNext: l, gainedExpForNext: i, lackExpForNext: l - i }; return this._cachedStates = t.cloneDeep(a), a; } getLevel() { return this.getStates().level; } isMaxLevel() { return this.getLevel() === this.getMaxLevel(); } _updateExp(e) { const t = this.getLevel(); let s = this.getExp() + e; return s > this.getMaxExp() ? s = this.getMaxExp() : s < 0 && (s = 0), this.setExp(s), { beforeLevel: t, afterLevel: this.getLevel() }; } _createExpUpdateResults(e, t, s, r) { return { beforeExp: e, afterExp: t, expDelta: t - e, beforeLevel: s, afterLevel: r, levelDelta: r - s, isLevelUp: r > s, isLevelDown: r < s }; } gainExp(e) { const t = this.getExp(), s = this._updateExp(e); return this._createExpUpdateResults(t, this.getExp(), s.beforeLevel, s.afterLevel); } drainExp(e) { const t = this.getExp(), s = this._updateExp(-e); return this._createExpUpdateResults(t, this.getExp(), s.beforeLevel, s.afterLevel); } gainLevel(e) { let t = this.getLevel() + e; t > this.getMaxLevel() && (t = this.getMaxLevel()); const s = this.getTotalNecessaryExp(this.getMinLevel(), t) - this.getExp(); return this.gainExp(s); } drainLevel(e) { let t = this.getLevel() - e; t < this.getMinLevel() && (t = this.getMinLevel()); const s = this.getExp() - this.getTotalNecessaryExp(this.getMinLevel(), t + 1) + 1; return this.drainExp(s); } } Object.defineProperty(RPGLevel, "__esModule", { value: !0 }), Object.defineProperty(RPGLevel, "RPGLevel", { value: RPGLevel }), Object.defineProperty(RPGLevel, "default", { value: RPGLevel }), e.RPGLevel = RPGLevel, e.default = RPGLevel, Object.defineProperty(e, "__esModule", { value: !0 }); })); //# sourceMappingURL=index.umd.production.min.cjs.map