const EventEmitter = require("events"); const constants = require("../Data/constants"); const { CATEGORIES } = constants; const { CATEGORY_CANNON } = CATEGORIES; const eventsMapped = { 1: 97, 2: 98, 3: 99, 4: 100, 5: 101, 6: 102, 7: 103, 8: 104, 9: 105, 10: 106 }; class Cannon extends EventEmitter { constructor(info) { super(); this.id = info.id; this.categoryID = CATEGORY_CANNON; this.eventID = eventsMapped[this.id]; this.damage = info.damage; this.range = info.range; this.reload = info.reload; this.scatter = info.scatter; this.amount = info.amount; this.amountEquipped = info.amountEquipped || 0; this.lastShotTickTimestamp = 0; this.resourceSharedLimiter = info.resourceSharedLimiter;; }; equip(quantity) { if (this.amountEquipped + quantity > this.amount) return const isTypeQunatityExhausted = this.resourceSharedLimiter.count(quantity); if (!isTypeQunatityExhausted) return this.amountEquipped += quantity; return true; } unequip(quantity) { if (this.amountEquipped - quantity < 0) return const isTypeQunatityExhausted = this.resourceSharedLimiter.count(-quantity); if (!isTypeQunatityExhausted) return this.amountEquipped -= quantity; return true; } getProperties() { return { typeID: 1, id: this.id, amount: this.amount, amountEquipped: this.amountEquipped }; } }; module.exports = Cannon;