diff --git a/src/class/Aquarium.js b/src/class/Aquarium.js index c0a0186..0ef1682 100644 --- a/src/class/Aquarium.js +++ b/src/class/Aquarium.js @@ -54,6 +54,10 @@ class Aquarium { return this.aquarium.lastAdjusted; } + async isFull() { + return this.aquarium.fish.length >= this.aquarium.size; + } + async updateStatus() { const now = new Date(); const lastCleaned = new Date(this.aquarium.lastCleaned); diff --git a/src/class/User.js b/src/class/User.js index 8821067..edca099 100644 --- a/src/class/User.js +++ b/src/class/User.js @@ -72,7 +72,7 @@ class User { async removeBait(baitId) { this.user.inventory.baits = this.user.inventory.baits.filter((b) => b.valueOf() !== baitId); - await this.save(); + return await this.save(); } async getItems() { diff --git a/src/commands/slash/Fish/fish.js b/src/commands/slash/Fish/fish.js index 74f9184..82125b0 100644 --- a/src/commands/slash/Fish/fish.js +++ b/src/commands/slash/Fish/fish.js @@ -34,7 +34,7 @@ const updateUserWithFish = async (interaction, userId) => { const stats = await user.getStats(); stats.latestFish = []; if (bait) { - bait.count -= fishArray.length; + bait.count -= fishArray.reduce((acc, f) => acc + (f.count || 1), 0); if (bait.count <= 0) { await user.setEquippedBait(null); // delete bait from user inventory @@ -288,7 +288,7 @@ module.exports = { const collector = followUp.createMessageComponentCollector({ componentType: ComponentType.Button, // filter, - time: 10000, + time: 30_000, }); collector.on('collect', async collectionInteraction => { diff --git a/src/commands/slash/Pet/adopt.js b/src/commands/slash/Pet/adopt.js index 5144541..499051f 100644 --- a/src/commands/slash/Pet/adopt.js +++ b/src/commands/slash/Pet/adopt.js @@ -88,12 +88,27 @@ module.exports = { const aquariumData = await aquariums.find((a) => a.name.toLowerCase() === aquariumName.toLowerCase()); const aquarium = new Aquarium(aquariumData); + // check if aquarium is full + if (await aquarium.isFull()) { + if (process.env.ANALYTICS || config.client.analytics) { + await analyticsObject.setStatus('failed'); + await analyticsObject.setStatusMessage('Aquarium is full.'); + } + return interaction.editReply({ content: 'Your aquarium is full! Use the `upgrade` command to increase its capacity.', ephemeral: true }); + } + // find the desired fish in user's inventory const fishes = await user.getFish(); const fishInInventory = await fishes.find((f) => f.name.toLowerCase() === species.toLowerCase() && !f.locked); // check if biome origin is the same as the aquarium's water type - if (!await aquarium.compareBiome(fishInInventory.biome)) return await interaction.followUp(`**${fishInInventory.name}** cannot live in a ${await aquarium.getWaterType()} aquarium.`); + if (!await aquarium.compareBiome(fishInInventory.biome)) { + if (process.env.ANALYTICS || config.client.analytics) { + await analyticsObject.setStatus('failed'); + await analyticsObject.setStatusMessage(`Fish cannot live in a ${await aquarium.getWaterType()} aquarium.`); + } + return await interaction.followUp(`**${fishInInventory.name}** cannot live in a ${await aquarium.getWaterType()} aquarium.`); + } // remove fish from inventory await user.removeFish(fishInInventory.id); diff --git a/src/commands/slash/User/equip.js b/src/commands/slash/User/equip.js index aa59d1e..f6c4685 100644 --- a/src/commands/slash/User/equip.js +++ b/src/commands/slash/User/equip.js @@ -21,7 +21,7 @@ const selectionOptions = async (inventoryPath, userData, allowNone = true) => { } if (uniqueValues.has(name)) { - counts[name] = (counts[name] || 1) + (item.count || 1); + counts[name] += (item.count || 1); continue; } else { diff --git a/src/components/buttons/buy-bait.js b/src/components/buttons/buy-bait.js index 87db3de..1177caf 100644 --- a/src/components/buttons/buy-bait.js +++ b/src/components/buttons/buy-bait.js @@ -221,6 +221,7 @@ const hasEnoughMoney = async (userData, item, amount) => { const buyItem = async (userData, item, amount) => { await userData.addMoney(-item.price * amount); + item.count = amount; let baitItem; const baits = await userData.getAllBaits(); const itemId = baits.find((bait) => bait.name === item.name);