Compare commits
2 commits
2963850de8
...
cb5dfad1c4
Author | SHA1 | Date | |
---|---|---|---|
cb5dfad1c4 | |||
8cd579df91 |
5 changed files with 99 additions and 6 deletions
|
@ -58,7 +58,7 @@ export default class Claim extends ButtonEvent {
|
|||
if (!inventory) {
|
||||
inventory = new Inventory(userId, cardNumber, 1);
|
||||
} else {
|
||||
inventory.SetQuantity(inventory.Quantity + 1);
|
||||
inventory.AddQuantity(1);
|
||||
}
|
||||
|
||||
await inventory.Save(Inventory, inventory);
|
||||
|
|
78
src/buttonEvents/Multidrop.ts
Normal file
78
src/buttonEvents/Multidrop.ts
Normal file
|
@ -0,0 +1,78 @@
|
|||
import { ButtonInteraction, EmbedBuilder } from "discord.js";
|
||||
import { ButtonEvent } from "../type/buttonEvent";
|
||||
import AppLogger from "../client/appLogger";
|
||||
import { CoreClient } from "../client/client";
|
||||
import CardDropHelperMetadata from "../helpers/CardDropHelperMetadata";
|
||||
import Inventory from "../database/entities/app/Inventory";
|
||||
import EmbedColours from "../constants/EmbedColours";
|
||||
import { readFileSync } from "fs";
|
||||
import path from "path";
|
||||
|
||||
export default class Multidrop extends ButtonEvent {
|
||||
public override async execute(interaction: ButtonInteraction) {
|
||||
const action = interaction.customId.split(" ")[1];
|
||||
|
||||
switch (action) {
|
||||
case "keep":
|
||||
await this.Keep(interaction);
|
||||
break;
|
||||
default:
|
||||
await interaction.reply("Invalid action");
|
||||
AppLogger.LogError("Button/Multidrop", `Invalid action, ${action}`);
|
||||
}
|
||||
}
|
||||
|
||||
public async Keep(interaction: ButtonInteraction) {
|
||||
const cardNumber = interaction.customId.split(" ")[2];
|
||||
let cardsRemaining = Number(interaction.customId.split(" ")[3]) || 0;
|
||||
const userId = interaction.customId.split(" ")[4];
|
||||
|
||||
if (interaction.user.id != userId) {
|
||||
await interaction.reply("You're not the user this drop was made for!");
|
||||
return;
|
||||
}
|
||||
|
||||
const card = CardDropHelperMetadata.GetCardByCardNumber(cardNumber);
|
||||
|
||||
if (!card) {
|
||||
await interaction.reply("Unable to find card.");
|
||||
AppLogger.LogWarn("Button/Multidrop/Keep", `Card not found, ${cardNumber}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (cardsRemaining < 0) {
|
||||
await interaction.reply("Your multidrop has ran out! Please buy a new one!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Claim
|
||||
let inventory = await Inventory.FetchOneByCardNumberAndUserId(interaction.user.id, cardNumber);
|
||||
|
||||
if (!inventory) {
|
||||
inventory = new Inventory(interaction.user.id, cardNumber, 1);
|
||||
} else {
|
||||
inventory.AddQuantity(1);
|
||||
}
|
||||
|
||||
await inventory.Save(Inventory, inventory);
|
||||
|
||||
// Pack has ran out
|
||||
if (cardsRemaining == 0) {
|
||||
const embed = new EmbedBuilder()
|
||||
.setDescription("Your multidrop has ran out! Please buy a new one!")
|
||||
.setColor(EmbedColours.Ok);
|
||||
|
||||
await interaction.update({ embeds: [ embed ]});
|
||||
return;
|
||||
}
|
||||
|
||||
// Drop next card
|
||||
cardsRemaining -= 1;
|
||||
|
||||
await interaction.deferUpdate();
|
||||
|
||||
try {
|
||||
const image = readFileSync(path.join(process.env.DATA_DIR!, "cards", ))
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@ export default class Multidrop extends Command {
|
|||
super();
|
||||
|
||||
this.CommandBuilder = new SlashCommandBuilder()
|
||||
.setName("mutlidrop")
|
||||
.setName("multidrop")
|
||||
.setDescription("Drop 11 cards for the price of 10!");
|
||||
}
|
||||
|
||||
|
@ -70,6 +70,18 @@ export default class Multidrop extends Command {
|
|||
const quantityClaimed = inventory ? inventory.Quantity : 0;
|
||||
|
||||
const embed = CardDropHelperMetadata.GenerateMultidropEmbed(randomCard, quantityClaimed, imageFileName, cardsRemaining, undefined, user.Currency);
|
||||
|
||||
const row = CardDropHelperMetadata.GenerateMultidropButtons(randomCard, cardsRemaining, interaction.user.id);
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [ embed ],
|
||||
files: [ attachment ],
|
||||
components: [ row ],
|
||||
});
|
||||
} catch (e) {
|
||||
AppLogger.LogError("Commands/Multidrop", `Error sending next drop for card ${randomCard.card.id}: ${e}`);
|
||||
|
||||
await interaction.editReply(`Unable to send next drop. Please try again, and report this if it keeps happening. (${randomCard.card.id})`);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } from "discord.js";
|
||||
import { CardRarity, CardRarityToColour, CardRarityToString } from "../constants/CardRarity";
|
||||
import { CardRarity, CardRarityToColour, CardRarityToString, GetSacrificeAmount } from "../constants/CardRarity";
|
||||
import CardRarityChances from "../constants/CardRarityChances";
|
||||
import { DropResult } from "../contracts/SeriesMetadata";
|
||||
import { CoreClient } from "../client/client";
|
||||
|
@ -158,16 +158,17 @@ export default class CardDropHelperMetadata {
|
|||
return dropEmbed;
|
||||
}
|
||||
|
||||
public static GenerateMultidropButtons(drop: DropResult, cardsRemaining: number, disabled = false): ActionRowBuilder<ButtonBuilder> {
|
||||
public static GenerateMultidropButtons(drop: DropResult, cardsRemaining: number, userId: string, disabled = false): ActionRowBuilder<ButtonBuilder> {
|
||||
return new ActionRowBuilder<ButtonBuilder>()
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId(`multidrop keep ${drop.card.id} ${cardsRemaining}`)
|
||||
.setCustomId(`multidrop keep ${drop.card.id} ${cardsRemaining} ${userId}`)
|
||||
.setLabel("Keep")
|
||||
.setStyle(ButtonStyle.Primary)
|
||||
.setDisabled(disabled),
|
||||
new ButtonBuilder()
|
||||
.setCustomId(`multidrop sacrifice ${drop.card.id} ${cardsRemaining}`)
|
||||
.setCustomId(`multidrop sacrifice ${drop.card.id} ${cardsRemaining} ${userId}`)
|
||||
.setLabel(`Sacrifice (+${GetSacrificeAmount(drop.card.type)} 🪙)`)
|
||||
.setStyle(ButtonStyle.Secondary));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import Gdrivesync from "./commands/gdrivesync";
|
|||
import Give from "./commands/give";
|
||||
import Id from "./commands/id";
|
||||
import Inventory from "./commands/inventory";
|
||||
import Multidrop from "./commands/multidrop";
|
||||
import Resync from "./commands/resync";
|
||||
import Sacrifice from "./commands/sacrifice";
|
||||
import Series from "./commands/series";
|
||||
|
@ -46,6 +47,7 @@ export default class Registry {
|
|||
CoreClient.RegisterCommand("give", new Give());
|
||||
CoreClient.RegisterCommand("id", new Id());
|
||||
CoreClient.RegisterCommand("inventory", new Inventory());
|
||||
CoreClient.RegisterCommand("multidrop", new Multidrop());
|
||||
CoreClient.RegisterCommand("resync", new Resync());
|
||||
CoreClient.RegisterCommand("sacrifice", new Sacrifice());
|
||||
CoreClient.RegisterCommand("series", new Series());
|
||||
|
|
Loading…
Reference in a new issue