Add ability to sacrifice multiple cards at once (#354)
- The `/sacrifice` command now accepts an optional parameter to be able to specify the quantity - The `Sacrifice` button event now accepts a parameter to specify the quantity, this one is required but the command will default it to 1 if not supplied #337 Reviewed-on: #354 Reviewed-by: VylpesTester <tester@vylpes.com> Co-authored-by: Ethan Lane <ethan@vylpes.com> Co-committed-by: Ethan Lane <ethan@vylpes.com>
This commit is contained in:
parent
52c93c7803
commit
c0e9378813
2 changed files with 36 additions and 9 deletions
|
@ -16,11 +16,18 @@ 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<CacheType>): Promise<void> {
|
||||
const cardnumber = interaction.options.get("cardnumber", true);
|
||||
const quantityInput = interaction.options.get("quantity")?.value ?? 1;
|
||||
|
||||
const quantity = Number(quantityInput) || 1;
|
||||
|
||||
const cardInInventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, cardnumber.value! as string);
|
||||
|
||||
|
@ -29,6 +36,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) {
|
||||
|
@ -36,7 +48,7 @@ export default class Sacrifice extends Command {
|
|||
return;
|
||||
}
|
||||
|
||||
const cardValue = GetSacrificeAmount(cardData.card.type);
|
||||
const cardValue = GetSacrificeAmount(cardData.card.type) * quantity;
|
||||
const cardRarityString = CardRarityToString(cardData.card.type);
|
||||
|
||||
const description = [
|
||||
|
@ -44,6 +56,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 +69,11 @@ export default class Sacrifice extends Command {
|
|||
const row = new ActionRowBuilder<ButtonBuilder>()
|
||||
.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),
|
||||
]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue