From 4a2c89b0cf3671811f56a38e4c4b56321394903f Mon Sep 17 00:00:00 2001 From: Thomas Bowen <6600748+ttbowen@users.noreply.github.com> Date: Sun, 7 Jul 2024 17:20:12 +0100 Subject: [PATCH] Adjust despawn and hunger announcement frequency --- .../src/client/managers/fish-manager.ts | 46 ++++++++++--------- .../src/client/managers/hunger-manager.ts | 6 +-- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/packages/mrwhale-discord/src/client/managers/fish-manager.ts b/packages/mrwhale-discord/src/client/managers/fish-manager.ts index 08732de..64aa967 100644 --- a/packages/mrwhale-discord/src/client/managers/fish-manager.ts +++ b/packages/mrwhale-discord/src/client/managers/fish-manager.ts @@ -51,7 +51,7 @@ import { Settings } from "../../types/settings"; import { createEmbed } from "../../util/embed/create-embed"; const ATTEMPT_REGEN_INTERVAL = 15 * 60 * 1000; // 15 minutes -const NEXT_SPAWN_IN_MILLISECONDS = 60 * 60 * 1000; // 1 hour +const NEXT_SPAWN_IN_MILLISECONDS = 90 * 60 * 1000; // 1 hour and 30 minutes const NEXT_DESPAWN_IN_MILLISECONDS = 30 * 60 * 1000; // 30 minutes const DELETE_ANNOUNCEMENT_AFTER = 5 * 60 * 1000; // 5 minutes const DELAY_BETWEEN_HUNGER_ANNOUNCEMENT = 5 * 60 * 1000; // 5 minutes @@ -214,7 +214,7 @@ export class FishManager { } // Handle the caught fish (e.g., add to inventory, update guild state) - await this.handleFishCaught(guildId, userId, fishCaught); + await this.handleFishCaught(interactionOrMessage, fishCaught); // Check whether the user has earned any achievements const achievements = await checkAndAwardFishingAchievements( @@ -256,10 +256,10 @@ export class FishManager { } private async handleFishCaught( - guildId: string, - userId: string, + messageOrInteraction: Message | Interaction, fishCaught: Fish ): Promise { + const { userId, guildId } = extractUserAndGuildId(messageOrInteraction); // Find the type of fish caught in the guild and decrement it's quantity. // When the quantity is zero we delete the fish from the guild. const allGuildFish = this.getGuildFish(guildId); @@ -286,10 +286,7 @@ export class FishManager { // If we have caught all the fish in the guild we send an announcement if (!this.hasGuildFish(guildId)) { - const announcementMessage = this.getAnnouncementMessage(guildId); - if (announcementMessage) { - this.despawnFish(announcementMessage, allGuildFish); - } + this.despawnFish(messageOrInteraction, allGuildFish); } } @@ -501,20 +498,19 @@ export class FishManager { messageOrInteraction: Message | Interaction, guildFish: Record ): Promise { - const announcementChannel = await this.bot.getFishingAnnouncementChannel( - messageOrInteraction - ); const { guildId } = messageOrInteraction; - const embed = await this.getDespawnEmbedAnnouncement(guildId, guildFish); + let despawnAnnouncement: Message | Message; + const areAnnouncementsEnabled = await this.areAnnouncementsEnabled(guildId); + if (areAnnouncementsEnabled) { + despawnAnnouncement = await this.getDespawnEmbedAnnouncement( + messageOrInteraction, + guildFish + ); + } this.deleteAnnouncementMessage(guildId); - delete this.guildFishSpawn[guildId].fish; - const despawnAnnouncement = await announcementChannel.send({ - embeds: [embed], - }); - const despawnTimeout = this.guildFishSpawn[guildId].despawnTimeout; if (despawnTimeout) { clearTimeout(despawnTimeout); @@ -582,9 +578,13 @@ export class FishManager { } private async getDespawnEmbedAnnouncement( - guildId: string, + messageOrInteraction: Message | Interaction, guildFish: Record - ): Promise { + ): Promise | Message> { + const { guildId } = messageOrInteraction; + const announcementChannel = await this.bot.getFishingAnnouncementChannel( + messageOrInteraction + ); const currentMood = await this.bot.getCurrentMood(guildId); const hasGuildFish = this.hasGuildFish(guildId); @@ -594,11 +594,15 @@ export class FishManager { : this.getFishDespawnAnnouncementMessage(currentMood, guildFish); const title = !hasGuildFish ? "All Fish Caught" : "Fish Despawn"; - const spawnAnnouncement = createEmbed(announementMessage) + const announcementEmbed = createEmbed(announementMessage) .setTitle(title) .setTimestamp(); - return spawnAnnouncement; + const despawnAnnouncement = await announcementChannel.send({ + embeds: [announcementEmbed], + }); + + return despawnAnnouncement; } private getFishSpawnAnnouncementMessage( diff --git a/packages/mrwhale-discord/src/client/managers/hunger-manager.ts b/packages/mrwhale-discord/src/client/managers/hunger-manager.ts index 42166c4..a548bdb 100644 --- a/packages/mrwhale-discord/src/client/managers/hunger-manager.ts +++ b/packages/mrwhale-discord/src/client/managers/hunger-manager.ts @@ -31,9 +31,9 @@ import { drawHungerHealthBar } from "../../util/draw-hunger-health-bar"; const HUNGER_DECREASE_RATE = 1; const FULL_HUNGER_LEVEL = 100; -const NEXT_HUNGER_ANNOUNCEMENT_IN_MILLISECONDS = 30 * 60 * 1000; // 30 minutes -const DELAY_BETWEEN_FISH_SPAWN_ANNOUNCEMENT = 5 * 60 * 1000; -const DELETE_HUNGER_ANNOUNCEMENT_AFTER = 5 * 60 * 1000; // 5 minutes +const NEXT_HUNGER_ANNOUNCEMENT_IN_MILLISECONDS = 2 * 60 * 60 * 1000; // 2 hours +const DELAY_BETWEEN_FISH_SPAWN_ANNOUNCEMENT = 5 * 60 * 1000; // 5 minutes +const DELETE_HUNGER_ANNOUNCEMENT_AFTER = 15 * 60 * 1000; // 15 minutes interface HungerState { level: number;