const itemTable = require("../Data/items"); const constants = require("../Data/constants"); const { CATEGORIES } = constants; const { CATEGORY_ITEM } = CATEGORIES; class Item { constructor(config) { this.categoryID = CATEGORY_ITEM; this.id = config.id; this.amount = config.amount; this.affects = config.affects; this.scale = config.scale; this.isDurable = config.isDurable; this.time = config.time; this.isActive = false; } use(amount) { const itemScheme = itemTable[this.id]; if (!itemScheme) return; if (!this.amount) return global.logger.send({ event: "itemUsage", reason: "item amount is 0" }); if (!amount) amount = 1; const removedAmount = Math.min(amount, this.amount); this.amount -= removedAmount; if (!this.amount && itemScheme.isDurable) this.isActive = false; return { scale: this.scale, statusID: itemScheme.statusID, isStatusActive: this.amount && itemScheme.isDurable }; } activate(amount) { const itemScheme = itemTable[this.id]; if (!itemScheme) return; if (!this.amount) return; if (!amount) amount = 1; const removedAmount = itemScheme.useOnImpact ? Math.min(amount, this.amount) : 0; if (itemScheme.isDurable) this.isActive = true; else { this.nextUseAt = performance.now() + itemScheme.cooldown; this.amount -= removedAmount; }; return { ...this, removedAmount }; } }; module.exports = Item;