From 08949d0af33543a99a64272f956c316ff9d7eabf Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Thu, 5 Sep 2024 19:40:15 +0100 Subject: [PATCH] Update the sacrifice command to allow input of quantity --- src/commands/sacrifice.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/commands/sacrifice.ts b/src/commands/sacrifice.ts index 4d1c51a..d6300e4 100644 --- a/src/commands/sacrifice.ts +++ b/src/commands/sacrifice.ts @@ -16,11 +16,16 @@ export default class Sacrifice extends Command { x .setName("cardnumber") .setDescription("The card to sacrifice from your inventory") - .setRequired(true)); + .setRequired(true)) + .addNumberOption(x => + x + .setName("quantity") + .setDescription("The amount to sacrifice (default 1)")); } public override async execute(interaction: CommandInteraction): Promise { const cardnumber = interaction.options.get("cardnumber", true); + const quantity = interaction.options.get("quantity")?.value as number ?? 1; const cardInInventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, cardnumber.value! as string); @@ -29,6 +34,11 @@ export default class Sacrifice extends Command { return; } + if (cardInInventory.Quantity < quantity) { + await interaction.reply(`You can only sacrifice what you own! You have ${cardInInventory.Quantity} of this card`); + return; + } + const cardData = CardDropHelperMetadata.GetCardByCardNumber(cardnumber.value! as string); if (!cardData) { @@ -44,6 +54,7 @@ export default class Sacrifice extends Command { `Series: ${cardData.series.name}`, `Rarity: ${cardRarityString}`, `Quantity Owned: ${cardInInventory.Quantity}`, + `Quantity To Sacrifice: ${quantity}`, `Sacrifice Amount: ${cardValue}`, ]; @@ -56,11 +67,11 @@ export default class Sacrifice extends Command { const row = new ActionRowBuilder() .addComponents([ new ButtonBuilder() - .setCustomId(`sacrifice confirm ${interaction.user.id} ${cardnumber.value!}`) + .setCustomId(`sacrifice confirm ${interaction.user.id} ${cardnumber.value!} ${quantity}`) .setLabel("Confirm") .setStyle(ButtonStyle.Success), new ButtonBuilder() - .setCustomId(`sacrifice cancel ${interaction.user.id} ${cardnumber.value!}`) + .setCustomId(`sacrifice cancel ${interaction.user.id} ${cardnumber.value!} ${quantity}`) .setLabel("Cancel") .setStyle(ButtonStyle.Secondary), ]);