Fix sacrificing a dropped card taking from your inventory first (#448)
All checks were successful
Test / build (push) Successful in 46s
All checks were successful
Test / build (push) Successful in 46s
- Fix sacrificing a dropped card trying to take it from your inventory instead of just directly from the drop - Did it by creating a separate subaction for the sacrifice command, which does the same logic except without checking your inventory, since it wont be coming from there. - Fix the sacrificed card image showing outside of the embed #435, #436 Reviewed-on: #448 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
f2c949c78a
commit
ecc879cf13
2 changed files with 77 additions and 1 deletions
|
@ -5,6 +5,7 @@ import { CardRarityToString, GetSacrificeAmount } from "../constants/CardRarity"
|
||||||
import EmbedColours from "../constants/EmbedColours";
|
import EmbedColours from "../constants/EmbedColours";
|
||||||
import User from "../database/entities/app/User";
|
import User from "../database/entities/app/User";
|
||||||
import GetCardsHelper from "../helpers/DropHelpers/GetCardsHelper";
|
import GetCardsHelper from "../helpers/DropHelpers/GetCardsHelper";
|
||||||
|
import CardConstants from "../constants/CardConstants";
|
||||||
|
|
||||||
export default class Sacrifice extends ButtonEvent {
|
export default class Sacrifice extends ButtonEvent {
|
||||||
public override async execute(interaction: ButtonInteraction) {
|
public override async execute(interaction: ButtonInteraction) {
|
||||||
|
@ -17,6 +18,8 @@ export default class Sacrifice extends ButtonEvent {
|
||||||
case "cancel":
|
case "cancel":
|
||||||
await this.cancel(interaction);
|
await this.cancel(interaction);
|
||||||
break;
|
break;
|
||||||
|
case "give":
|
||||||
|
await this.give(interaction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,4 +171,77 @@ export default class Sacrifice extends ButtonEvent {
|
||||||
components: [ row ],
|
components: [ row ],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async give(interaction: ButtonInteraction) {
|
||||||
|
const userId = interaction.customId.split(" ")[2];
|
||||||
|
const cardNumber = interaction.customId.split(" ")[3];
|
||||||
|
const quantity = Number(interaction.customId.split(" ")[4]) || 1;
|
||||||
|
|
||||||
|
if (userId != interaction.user.id) {
|
||||||
|
await interaction.reply("Only the user who created this sacrifice can confirm it.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const cardData = GetCardsHelper.GetCardByCardNumber(cardNumber);
|
||||||
|
|
||||||
|
if (!cardData) {
|
||||||
|
await interaction.reply("Unable to find card in the database.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let user = await User.FetchOneById(User, userId);
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
user = new User(userId, CardConstants.StartingCurrency);
|
||||||
|
}
|
||||||
|
|
||||||
|
const cardInInventory = await Inventory.FetchOneByCardNumberAndUserId(userId, cardNumber);
|
||||||
|
let cardQuantity = 0;
|
||||||
|
|
||||||
|
if (cardInInventory) {
|
||||||
|
cardQuantity = cardInInventory.Quantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
const cardValue = GetSacrificeAmount(cardData.card.type) * quantity;
|
||||||
|
const cardRarityString = CardRarityToString(cardData.card.type);
|
||||||
|
|
||||||
|
user.AddCurrency(cardValue);
|
||||||
|
|
||||||
|
await user.Save(User, user);
|
||||||
|
|
||||||
|
const description = [
|
||||||
|
`Card: ${cardData.card.name}`,
|
||||||
|
`Series: ${cardData.series.name}`,
|
||||||
|
`Rarity: ${cardRarityString}`,
|
||||||
|
`Quantity Owned: ${cardQuantity}`,
|
||||||
|
`Quantity To Sacrifice: ${quantity}`,
|
||||||
|
`Sacrifice Amount: ${cardValue}`,
|
||||||
|
];
|
||||||
|
|
||||||
|
const embed = new EmbedBuilder()
|
||||||
|
.setTitle("Card Sacrificed")
|
||||||
|
.setDescription(description.join("\n"))
|
||||||
|
.setColor(EmbedColours.Green)
|
||||||
|
.setFooter({ text: `${interaction.user.username}` });
|
||||||
|
|
||||||
|
const row = new ActionRowBuilder<ButtonBuilder>()
|
||||||
|
.addComponents([
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setCustomId(`sacrifice confirm ${interaction.user.id} ${cardNumber}`)
|
||||||
|
.setLabel("Confirm")
|
||||||
|
.setStyle(ButtonStyle.Success)
|
||||||
|
.setDisabled(true),
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setCustomId("sacrifice cancel")
|
||||||
|
.setLabel("Cancel")
|
||||||
|
.setStyle(ButtonStyle.Secondary)
|
||||||
|
.setDisabled(true),
|
||||||
|
]);
|
||||||
|
|
||||||
|
await interaction.update({
|
||||||
|
embeds: [ embed ],
|
||||||
|
components: [ row ],
|
||||||
|
attachments: [],
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -77,7 +77,7 @@ export default class DropEmbedHelper {
|
||||||
.setStyle(ButtonStyle.Success)
|
.setStyle(ButtonStyle.Success)
|
||||||
.setDisabled(disabled),
|
.setDisabled(disabled),
|
||||||
new ButtonBuilder()
|
new ButtonBuilder()
|
||||||
.setCustomId(`sacrifice confirm ${userId} ${drop.card.id} 1`)
|
.setCustomId(`sacrifice give ${userId} ${drop.card.id} 1`)
|
||||||
.setLabel(`Sacrifice`)
|
.setLabel(`Sacrifice`)
|
||||||
.setStyle(ButtonStyle.Danger),
|
.setStyle(ButtonStyle.Danger),
|
||||||
new ButtonBuilder()
|
new ButtonBuilder()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue