Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- window.Stat = class Stat {
- // Designed by Akjosch
- constructor (base) {
- this._base = base;
- this._mods = {};
- this._current = undefined;
- }
- clearCache () {
- this._current = undefined;
- }
- addMod (id, mod, equipment) {
- console.log("addMod called");
- id = String(id);
- if (!this._mods[id]) {
- this._mods[id] = [];
- }
- if(Number.isFinite(mod)) {
- mod = { add: mod };
- if (equipment === true) {
- mod.equipment = true;
- }
- }
- if(typeof mod === "object") {
- this._mods[id].push(mod);
- this.clearCache();
- return this._mods[id].indexOf(mod);
- }
- }
- removeMod (id, index) {
- console.log("removeMod called");
- if (Number.isFinite(index)) {
- console.log("index detected");
- this._mods[String(id)].deleteAt(index);
- } else {
- delete this._mods[String(id)];
- }
- this.clearCache();
- }
- clearMods () {
- this._mods = {};
- this.clearCache();
- }
- get base () {
- return this._base;
- }
- set base (newBase) {
- newBase = Number(newBase);
- /* alternative: newBase = setup.roll(newBase) for "3d6" as inputs */
- if(!Number.isFinite(newBase)) {
- newBase = 0;
- }
- if (this._base !== newBase) {
- this._base = newBase;
- this.clearCache();
- }
- }
- get current () {
- if (this._current === undefined) {
- /* gather multipliers */
- var mult = Object.values(this._mods)
- .reduce(function(bigSum, entry) { return bigSum + entry
- .map(function(m) { return Number.isFinite(m.mult) ? m.mult : 0; })
- .reduce(function(sum, add) { return sum + add; }, 0);
- }, 0);
- /* gather sums */
- var add = Object.values(this._mods)
- .reduce(function(bigSum, entry) { return bigSum + entry
- .map(function(m) { return Number.isFinite(m.add) ? m.add : 0; })
- .reduce(function(sum, add) { return sum + add; }, 0);
- }, 0);
- this._current = this.base * (mult + 1) + add;
- }
- return this._current;
- }
- get bonus () {
- return this.current - this.base;
- }
- get equipBonus () {
- var mult = Object.values(this._mods)
- .reduce(function(bigSum, entry) { return bigSum + entry
- .map(function(m) { return m.equipment === true ? m : {}; })
- .map(function(m) { return Number.isFinite(m.mult) ? m.mult : 0; })
- .reduce(function(sum, add) { return sum + add; }, 0);
- }, 0);
- var add = Object.values(this._mods)
- .reduce(function(bigSum, entry) { return bigSum + entry
- .map(function(m) { return m.equipment === true ? m : {}; })
- .map(function(m) { return Number.isFinite(m.add) ? m.add : 0; })
- .reduce(function(sum, add) { return sum + add; }, 0);
- }, 0);
- return this.base * (mult + 1) + add - this.base;
- }
- toString () {
- var mult = Object.values(this._mods)
- .map(function(m) { return Number.isFinite(m.mult) ? m.mult : 0; })
- .reduce(function(sum, add) { return sum + add; }, 0);
- var add = Object.values(this._mods)
- .map(function(m) { return Number.isFinite(m.add) ? m.add : 0; })
- .reduce(function(sum, add) { return sum + add; }, 0);
- return this.current.toFixed(2)
- + " [" + this.base.toFixed(2)
- + " x " + (mult + 1).toFixed(2)
- + (add >= 0 ? " + " + add.toFixed(2) : " - " + (-add).toFixed(2))
- + "]";
- }
- /* SugarCube support */
- clone () {
- return Stat.create(this);
- }
- toJSON () {
- return JSON.reviveWrapper('Stat.create($ReviveData$)', Object.assign({}, clone(this)));
- }
- };
- Stat.create = function(vals) {
- vals = vals || {};
- var result = new Stat();
- result._base = vals._base;
- result._mods = clone(vals._mods);
- result._current = vals._current;
- return result;
- };
- Map.prototype.addMod = function (key, id, mod, equipment) {
- return this.get(key).addMod(id,mod,equipment);
- }
- Map.prototype.removeMod = function (key, id, index) {
- this.get(key).removeMod(id, index);
- }
- ----
- class Effect {
- constructor(name,time,power,target){
- this.name = name;
- (...)
- switch (name) {
- case 'ATK Boost':
- this.buff = true;
- this.stackable = true;
- this.statmod = true;
- this.onApply = (puppet) => {
- this.id = puppet.stats.addMod("Attack","ATK Boost",this.power);
- console.log("Applying ATK Boost. ID = "+this.id);
- }
- this.onRemove = (puppet) => {
- console.log("Removing ATK Boost. ID = "+this.id);
- puppet.stats.removeMod("Attack","ATK Boost",this.id);
- }
- this.info = function () {
- return `Attack boosted by ${this.power}.`;
- }
- this.addText = function (target) {
- return `${target} is surging with strength!`;
- }
- this.removeText = remBuff;
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement