63 lines
1.5 KiB
JavaScript
63 lines
1.5 KiB
JavaScript
const EventEmitter = require("events");
|
|
|
|
const constants = require("../Data/constants");
|
|
const { CATEGORIES } = constants;
|
|
const { CATEGORY_HARPOONER } = CATEGORIES;
|
|
|
|
const eventsMapped = {
|
|
1: 197,
|
|
2: 198,
|
|
3: 199,
|
|
4: 200,
|
|
5: 201,
|
|
6: 202
|
|
};
|
|
|
|
class Harpooner extends EventEmitter {
|
|
constructor(info) {
|
|
super();
|
|
|
|
this.id = info.id;
|
|
this.categoryID = CATEGORY_HARPOONER;
|
|
this.eventID = eventsMapped[this.id];
|
|
this.damage = info.damage;
|
|
this.range = info.range;
|
|
this.reload = info.reload;
|
|
this.amount = info.amount;
|
|
this.amountEquipped = info.amountEquipped || 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: 2,
|
|
id: this.id,
|
|
amount: this.amount,
|
|
amountEquipped: this.amountEquipped
|
|
};
|
|
}
|
|
};
|
|
|
|
module.exports = Harpooner; |