const Entity = require("./Entity"); const Reward = require("./Reward"); const constants = require("../Data/constants"); const { TYPES, TIMING_EVENTS } = constants; const { ENTITY_TYPE_COLLECTABLE } = TYPES; const { TIMING_EVENT_RESPAWN } = TIMING_EVENTS; class Collectable extends Entity { constructor(info) { super({ type: ENTITY_TYPE_COLLECTABLE, id: info.id, map: info.map, isAlive: true, position: info.position }); this.respawnTime = 10000; this.entityTypeID = info.entityTypeID; this.dieCallback = info.dieCallback; this.rewardCallback = info.rewardCallback; this.reward = new Reward({ distributionType: 2, baseReward: info.rewardEntries.reduce((result, entry) => { if (result[entry.categoryId]) result[entry.categoryId][entry.itemId] = { amountMinimum: entry.min, amountMaximum: entry.max, chance: entry.chance }; else result[entry.categoryId] = { [entry.itemId]: { amountMinimum: entry.min, amountMaximum: entry.max, chance: entry.chance } }; return result; }, {}) }); this.map.collectables.set(this.id, this); } die(deathEvent) { super.die(); const die = { typeID: this.typeID, entityTypeID: this.entityTypeID, id: this.id, authorID: deathEvent.authorID, targetEntityTypeID: this.entityTypeID }; this.dieCallback(die); this.setSingleEvent(TIMING_EVENT_RESPAWN, this.respawnTime); } getProperties() { const { position, type, typeID, entityTypeID, id } = this; return { position, type, typeID, entityTypeID, id }; } }; module.exports = Collectable;