Create sacrifice command and embed
All checks were successful
Test / build (push) Successful in 2m29s
All checks were successful
Test / build (push) Successful in 2m29s
This commit is contained in:
parent
f07058d369
commit
11fd859615
3 changed files with 92 additions and 0 deletions
73
src/commands/sacrifice.ts
Normal file
73
src/commands/sacrifice.ts
Normal file
|
@ -0,0 +1,73 @@
|
|||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, CacheType, CommandInteraction, EmbedBuilder, SlashCommandBuilder } from "discord.js";
|
||||
import { Command } from "../type/command";
|
||||
import Inventory from "../database/entities/app/Inventory";
|
||||
import { CardRarityToString, GetSacrificeAmount } from "../constants/CardRarity";
|
||||
import CardDropHelperMetadata from "../helpers/CardDropHelperMetadata";
|
||||
import EmbedColours from "../constants/EmbedColours";
|
||||
|
||||
export default class Sacrifice extends Command {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.CommandBuilder = new SlashCommandBuilder()
|
||||
.setName("sacrifice")
|
||||
.setDescription("Sacrifices a card for currency")
|
||||
.addStringOption(x =>
|
||||
x
|
||||
.setName("cardnumber")
|
||||
.setDescription("The card to sacrifice from your inventory")
|
||||
.setRequired(true));
|
||||
}
|
||||
|
||||
public override async execute(interaction: CommandInteraction<CacheType>): Promise<void> {
|
||||
const cardnumber = interaction.options.get("cardnumber", true);
|
||||
|
||||
const cardInInventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, cardnumber.value! as string);
|
||||
|
||||
if (!cardInInventory || cardInInventory.Quantity == 0) {
|
||||
await interaction.reply("Unable to find card in your inventory.");
|
||||
return;
|
||||
}
|
||||
|
||||
const cardData = CardDropHelperMetadata.GetCardByCardNumber(cardnumber.value! as string);
|
||||
|
||||
if (!cardData) {
|
||||
await interaction.reply("Unable to find card in the database.");
|
||||
return;
|
||||
}
|
||||
|
||||
const cardValue = GetSacrificeAmount(cardData.card.type);
|
||||
const cardRarityString = CardRarityToString(cardData.card.type);
|
||||
|
||||
let description = [
|
||||
`Card: ${cardData.card.name}`,
|
||||
`Series: ${cardData.series.name}`,
|
||||
`Rarity: ${cardRarityString}`,
|
||||
`Quantity Owned: ${cardInInventory.Quantity}`,
|
||||
`Sacrifice Amount: ${cardValue}`,
|
||||
];
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle("Sacrifice")
|
||||
.setDescription(description.join("\n"))
|
||||
.setColor(EmbedColours.Grey)
|
||||
.setFooter({ text: `${interaction.user.username} · ${cardData.card.name}` });
|
||||
|
||||
const row = new ActionRowBuilder<ButtonBuilder>()
|
||||
.addComponents([
|
||||
new ButtonBuilder()
|
||||
.setCustomId(`sacrifice confirm ${interaction.user.id} ${cardnumber.value!}`)
|
||||
.setLabel("Confirm")
|
||||
.setStyle(ButtonStyle.Success),
|
||||
new ButtonBuilder()
|
||||
.setCustomId(`sacrifice cancel`)
|
||||
.setLabel("Cancel")
|
||||
.setStyle(ButtonStyle.Secondary),
|
||||
]);
|
||||
|
||||
await interaction.reply({
|
||||
embeds: [ embed ],
|
||||
components: [ row ],
|
||||
});
|
||||
}
|
||||
}
|
|
@ -58,4 +58,21 @@ export function CardRarityParse(rarity: string): CardRarity {
|
|||
default:
|
||||
return CardRarity.Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
export function GetSacrificeAmount(rarity: CardRarity): number {
|
||||
switch (rarity) {
|
||||
case CardRarity.Bronze:
|
||||
return 5;
|
||||
case CardRarity.Silver:
|
||||
return 15;
|
||||
case CardRarity.Gold:
|
||||
return 30;
|
||||
case CardRarity.Manga:
|
||||
return 50;
|
||||
case CardRarity.Legendary:
|
||||
return 100;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ import Gdrivesync from "./commands/gdrivesync";
|
|||
import Give from "./commands/give";
|
||||
import Inventory from "./commands/inventory";
|
||||
import Resync from "./commands/resync";
|
||||
import Sacrifice from "./commands/sacrifice";
|
||||
import Series from "./commands/series";
|
||||
import Trade from "./commands/trade";
|
||||
import View from "./commands/view";
|
||||
|
@ -32,6 +33,7 @@ export default class Registry {
|
|||
CoreClient.RegisterCommand("give", new Give());
|
||||
CoreClient.RegisterCommand("inventory", new Inventory());
|
||||
CoreClient.RegisterCommand("resync", new Resync());
|
||||
CoreClient.RegisterCommand("sacrifice", new Sacrifice());
|
||||
CoreClient.RegisterCommand("series", new Series());
|
||||
CoreClient.RegisterCommand("trade", new Trade());
|
||||
CoreClient.RegisterCommand("view", new View());
|
||||
|
|
Loading…
Reference in a new issue