Compare commits
No commits in common. "2809cc1014a0ac9031022f3b2672be1b1a4a66eb" and "51d97bacd57960cf6948fea0774d2ea97a8455a6" have entirely different histories.
2809cc1014
...
51d97bacd5
21 changed files with 48 additions and 382 deletions
2
.dev.env
2
.dev.env
|
@ -7,7 +7,7 @@
|
||||||
# any secret values.
|
# any secret values.
|
||||||
|
|
||||||
BOT_TOKEN=
|
BOT_TOKEN=
|
||||||
BOT_VER=0.1.0 DEV
|
BOT_VER=0.1.0
|
||||||
BOT_AUTHOR=Vylpes
|
BOT_AUTHOR=Vylpes
|
||||||
BOT_OWNERID=147392775707426816
|
BOT_OWNERID=147392775707426816
|
||||||
BOT_CLIENTID=682942374040961060
|
BOT_CLIENTID=682942374040961060
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
# any secret values.
|
# any secret values.
|
||||||
|
|
||||||
BOT_TOKEN=
|
BOT_TOKEN=
|
||||||
BOT_VER=0.1.0 BETA
|
BOT_VER=0.1.0
|
||||||
BOT_AUTHOR=Vylpes
|
BOT_AUTHOR=Vylpes
|
||||||
BOT_OWNERID=147392775707426816
|
BOT_OWNERID=147392775707426816
|
||||||
BOT_CLIENTID=1016767908740857949
|
BOT_CLIENTID=1016767908740857949
|
||||||
|
|
|
@ -5,7 +5,7 @@ import Series from "../database/entities/card/Series";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { CardRarity } from "../constants/CardRarity";
|
import { CardRarity } from "../constants/CardRarity";
|
||||||
|
|
||||||
export default class CardSetupFunction {
|
export default class CardSetupFunctions {
|
||||||
public async Execute() {
|
public async Execute() {
|
||||||
await this.ClearDatabase();
|
await this.ClearDatabase();
|
||||||
await this.ReadSeries();
|
await this.ReadSeries();
|
||||||
|
@ -42,7 +42,7 @@ export default class CardSetupFunction {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async ReadCards() {
|
private async ReadCards() {
|
||||||
const loadedSeries = await Series.FetchAll(Series, [ "Cards", "Cards.Series" ]);
|
const loadedSeries = await Series.FetchAll(Series);
|
||||||
|
|
||||||
const cardRepository = CardDataSource.getRepository(Card);
|
const cardRepository = CardDataSource.getRepository(Card);
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ export default class CardSetupFunction {
|
||||||
const cardId = filePart[0];
|
const cardId = filePart[0];
|
||||||
const cardName = filePart[0];
|
const cardName = filePart[0];
|
||||||
|
|
||||||
const card = new Card(cardId, cardName, CardRarity.Bronze, path.join(path.join(process.cwd(), 'cards', series.Path, 'BRONZE', file)), series);
|
const card = new Card(cardId, cardName, CardRarity.Bronze);
|
||||||
|
|
||||||
cardsToSave.push(card);
|
cardsToSave.push(card);
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ export default class CardSetupFunction {
|
||||||
const cardId = filePart[0];
|
const cardId = filePart[0];
|
||||||
const cardName = filePart[0];
|
const cardName = filePart[0];
|
||||||
|
|
||||||
const card = new Card(cardId, cardName, CardRarity.Gold, path.join(path.join(process.cwd(), 'cards', series.Path, 'GOLD', file)), series);
|
const card = new Card(cardId, cardName, CardRarity.Gold);
|
||||||
|
|
||||||
cardsToSave.push(card);
|
cardsToSave.push(card);
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ export default class CardSetupFunction {
|
||||||
const cardId = filePart[0];
|
const cardId = filePart[0];
|
||||||
const cardName = filePart[0];
|
const cardName = filePart[0];
|
||||||
|
|
||||||
const card = new Card(cardId, cardName, CardRarity.Legendary, path.join(path.join(process.cwd(), 'cards', series.Path, 'LEGENDARY', file)), series);
|
const card = new Card(cardId, cardName, CardRarity.Legendary);
|
||||||
|
|
||||||
cardsToSave.push(card);
|
cardsToSave.push(card);
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ export default class CardSetupFunction {
|
||||||
const cardId = filePart[0];
|
const cardId = filePart[0];
|
||||||
const cardName = filePart[0];
|
const cardName = filePart[0];
|
||||||
|
|
||||||
const card = new Card(cardId, cardName, CardRarity.Silver, path.join(path.join(process.cwd(), 'cards', series.Path, 'SILVER', file)), series);
|
const card = new Card(cardId, cardName, CardRarity.Silver);
|
||||||
|
|
||||||
cardsToSave.push(card);
|
cardsToSave.push(card);
|
||||||
}
|
}
|
|
@ -32,6 +32,5 @@ const client = new CoreClient([
|
||||||
|
|
||||||
Registry.RegisterCommands();
|
Registry.RegisterCommands();
|
||||||
Registry.RegisterEvents();
|
Registry.RegisterEvents();
|
||||||
Registry.RegisterButtonEvents();
|
|
||||||
|
|
||||||
client.start();
|
client.start();
|
|
@ -1,38 +0,0 @@
|
||||||
import { ButtonInteraction } from "discord.js";
|
|
||||||
import { ButtonEvent } from "../type/buttonEvent";
|
|
||||||
import Inventory from "../database/entities/app/Inventory";
|
|
||||||
import { CoreClient } from "../client/client";
|
|
||||||
|
|
||||||
export default class Claim extends ButtonEvent {
|
|
||||||
public override async execute(interaction: ButtonInteraction) {
|
|
||||||
if (!interaction.guild || !interaction.guildId) return;
|
|
||||||
|
|
||||||
const cardNumber = interaction.customId.split(' ')[1];
|
|
||||||
const claimId = interaction.customId.split(' ')[2];
|
|
||||||
const userId = interaction.user.id;
|
|
||||||
|
|
||||||
const claimed = await Inventory.FetchOneByClaimId(claimId);
|
|
||||||
|
|
||||||
if (claimed) {
|
|
||||||
await interaction.reply('This card has already been claimed');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (claimId != CoreClient.ClaimId) {
|
|
||||||
await interaction.reply('This card has expired');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let inventory = await Inventory.FetchOneByCardNumberAndUserId(userId, cardNumber);
|
|
||||||
|
|
||||||
if (!inventory) {
|
|
||||||
inventory = new Inventory(userId, cardNumber, 1, claimId);
|
|
||||||
} else {
|
|
||||||
inventory.SetQuantity(inventory.Quantity + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
await inventory.Save(Inventory, inventory);
|
|
||||||
|
|
||||||
await interaction.reply('Card claimed');
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,48 +0,0 @@
|
||||||
import { ActionRowBuilder, AttachmentBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, CacheType, EmbedBuilder } from "discord.js";
|
|
||||||
import { ButtonEvent } from "../type/buttonEvent";
|
|
||||||
import CardDropHelper from "../helpers/CardDropHelper";
|
|
||||||
import { readFileSync } from "fs";
|
|
||||||
import { CardRarityToColour, CardRarityToString } from "../constants/CardRarity";
|
|
||||||
import { v4 } from "uuid";
|
|
||||||
import { CoreClient } from "../client/client";
|
|
||||||
|
|
||||||
export default class Reroll extends ButtonEvent {
|
|
||||||
public override async execute(interaction: ButtonInteraction) {
|
|
||||||
if (!interaction.guild || !interaction.guildId) return;
|
|
||||||
|
|
||||||
const randomCard = await CardDropHelper.GetRandomCard();
|
|
||||||
|
|
||||||
const image = readFileSync(randomCard.Path);
|
|
||||||
|
|
||||||
const attachment = new AttachmentBuilder(image, { name: `${randomCard.Id}.png` });
|
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
|
||||||
.setTitle(randomCard.Name)
|
|
||||||
.setDescription(randomCard.Series.Name)
|
|
||||||
.setFooter({ text: CardRarityToString(randomCard.Rarity) })
|
|
||||||
.setColor(CardRarityToColour(randomCard.Rarity))
|
|
||||||
.setImage(`attachment://${randomCard.Id}.png`);
|
|
||||||
|
|
||||||
const row = new ActionRowBuilder<ButtonBuilder>();
|
|
||||||
|
|
||||||
const claimId = v4();
|
|
||||||
|
|
||||||
row.addComponents(
|
|
||||||
new ButtonBuilder()
|
|
||||||
.setCustomId(`claim ${randomCard.CardNumber} ${claimId}`)
|
|
||||||
.setLabel("Claim")
|
|
||||||
.setStyle(ButtonStyle.Primary),
|
|
||||||
new ButtonBuilder()
|
|
||||||
.setCustomId(`reroll`)
|
|
||||||
.setLabel("Reroll")
|
|
||||||
.setStyle(ButtonStyle.Secondary));
|
|
||||||
|
|
||||||
await interaction.reply({
|
|
||||||
embeds: [ embed ],
|
|
||||||
files: [ attachment ],
|
|
||||||
components: [ row ],
|
|
||||||
});
|
|
||||||
|
|
||||||
CoreClient.ClaimId = claimId;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -7,23 +7,14 @@ import { Command } from "../type/command";
|
||||||
|
|
||||||
import { Events } from "./events";
|
import { Events } from "./events";
|
||||||
import { Util } from "./util";
|
import { Util } from "./util";
|
||||||
import CardSetupFunction from "../Functions/CardSetupFunction";
|
|
||||||
import CardDataSource from "../database/dataSources/cardDataSource";
|
|
||||||
import CardDropHelper from "../helpers/CardDropHelper";
|
|
||||||
import IButtonEventItem from "../contracts/IButtonEventItem";
|
|
||||||
import { ButtonEvent } from "../type/buttonEvent";
|
|
||||||
import AppDataSource from "../database/dataSources/appDataSource";
|
import AppDataSource from "../database/dataSources/appDataSource";
|
||||||
|
|
||||||
export class CoreClient extends Client {
|
export class CoreClient extends Client {
|
||||||
private static _commandItems: ICommandItem[];
|
private static _commandItems: ICommandItem[];
|
||||||
private static _eventItems: IEventItem[];
|
private static _eventItems: IEventItem[];
|
||||||
private static _buttonEvents: IButtonEventItem[];
|
|
||||||
|
|
||||||
private _events: Events;
|
private _events: Events;
|
||||||
private _util: Util;
|
private _util: Util;
|
||||||
private _cardSetupFunc: CardSetupFunction;
|
|
||||||
|
|
||||||
public static ClaimId: string;
|
|
||||||
|
|
||||||
public static get commandItems(): ICommandItem[] {
|
public static get commandItems(): ICommandItem[] {
|
||||||
return this._commandItems;
|
return this._commandItems;
|
||||||
|
@ -33,21 +24,15 @@ export class CoreClient extends Client {
|
||||||
return this._eventItems;
|
return this._eventItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static get buttonEvents(): IButtonEventItem[] {
|
|
||||||
return this._buttonEvents;
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(intents: number[]) {
|
constructor(intents: number[]) {
|
||||||
super({ intents: intents });
|
super({ intents: intents });
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
CoreClient._commandItems = [];
|
CoreClient._commandItems = [];
|
||||||
CoreClient._eventItems = [];
|
CoreClient._eventItems = [];
|
||||||
CoreClient._buttonEvents = [];
|
|
||||||
|
|
||||||
this._events = new Events();
|
this._events = new Events();
|
||||||
this._util = new Util();
|
this._util = new Util();
|
||||||
this._cardSetupFunc = new CardSetupFunction();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async start() {
|
public async start() {
|
||||||
|
@ -57,18 +42,12 @@ export class CoreClient extends Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
await AppDataSource.initialize()
|
await AppDataSource.initialize()
|
||||||
.then(() => console.log("App Data Source Initialised"))
|
.then(() => console.log("Data Source Initialized"))
|
||||||
.catch(err => console.error("Error initialising App Data Source", err));
|
.catch((err) => console.error("Error Initialising Data Source", err));
|
||||||
|
|
||||||
await CardDataSource.initialize()
|
|
||||||
.then(() => console.log("Card Data Source Initialised"))
|
|
||||||
.catch(err => console.error("Error initialising Card Data Source", err));
|
|
||||||
|
|
||||||
super.on("interactionCreate", this._events.onInteractionCreate);
|
super.on("interactionCreate", this._events.onInteractionCreate);
|
||||||
super.on("ready", this._events.onReady);
|
super.on("ready", this._events.onReady);
|
||||||
|
|
||||||
await this._cardSetupFunc.Execute();
|
|
||||||
|
|
||||||
await super.login(process.env.BOT_TOKEN);
|
await super.login(process.env.BOT_TOKEN);
|
||||||
|
|
||||||
this._util.loadEvents(this, CoreClient._eventItems);
|
this._util.loadEvents(this, CoreClient._eventItems);
|
||||||
|
@ -93,13 +72,4 @@ export class CoreClient extends Client {
|
||||||
|
|
||||||
CoreClient._eventItems.push(item);
|
CoreClient._eventItems.push(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RegisterButtonEvent(buttonId: string, event: ButtonEvent) {
|
|
||||||
const item: IButtonEventItem = {
|
|
||||||
ButtonId: buttonId,
|
|
||||||
Event: event,
|
|
||||||
};
|
|
||||||
|
|
||||||
CoreClient._buttonEvents.push(item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,29 @@
|
||||||
import { Interaction } from "discord.js";
|
import { Interaction } from "discord.js";
|
||||||
import ChatInputCommand from "./interactionCreate/ChatInputCommand";
|
import ICommandItem from "../contracts/ICommandItem";
|
||||||
import Button from "./interactionCreate/Button";
|
import { CoreClient } from "./client";
|
||||||
|
|
||||||
export class Events {
|
export class Events {
|
||||||
public async onInteractionCreate(interaction: Interaction) {
|
public async onInteractionCreate(interaction: Interaction) {
|
||||||
|
if (!interaction.isChatInputCommand()) return;
|
||||||
if (!interaction.guildId) return;
|
if (!interaction.guildId) return;
|
||||||
|
|
||||||
if (interaction.isChatInputCommand()) {
|
const item = CoreClient.commandItems.find(x => x.Name == interaction.commandName && !x.ServerId);
|
||||||
ChatInputCommand.onChatInput(interaction);
|
const itemForServer = CoreClient.commandItems.find(x => x.Name == interaction.commandName && x.ServerId == interaction.guildId);
|
||||||
|
|
||||||
|
let itemToUse: ICommandItem;
|
||||||
|
|
||||||
|
if (!itemForServer) {
|
||||||
|
if (!item) {
|
||||||
|
await interaction.reply('Command not found');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
itemToUse = item;
|
||||||
|
} else {
|
||||||
|
itemToUse = itemForServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (interaction.isButton()) {
|
itemToUse.Command.execute(interaction);
|
||||||
Button.onButtonClicked(interaction);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit when bot is logged in and ready to use
|
// Emit when bot is logged in and ready to use
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
import { ButtonInteraction, Interaction } from "discord.js";
|
|
||||||
import { CoreClient } from "../client";
|
|
||||||
|
|
||||||
export default class Button {
|
|
||||||
public static async onButtonClicked(interaction: ButtonInteraction) {
|
|
||||||
if (!interaction.isButton) return;
|
|
||||||
|
|
||||||
const item = CoreClient.buttonEvents.find(x => x.ButtonId == interaction.customId.split(' ')[0]);
|
|
||||||
|
|
||||||
if (!item) {
|
|
||||||
await interaction.reply('Event not found');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
item.Event.execute(interaction);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
import { Interaction } from "discord.js";
|
|
||||||
import { CoreClient } from "../client";
|
|
||||||
import ICommandItem from "../../contracts/ICommandItem";
|
|
||||||
|
|
||||||
export default class ChatInputCommand {
|
|
||||||
public static async onChatInput(interaction: Interaction) {
|
|
||||||
if (!interaction.isChatInputCommand()) return;
|
|
||||||
|
|
||||||
const item = CoreClient.commandItems.find(x => x.Name == interaction.commandName && !x.ServerId);
|
|
||||||
const itemForServer = CoreClient.commandItems.find(x => x.Name == interaction.commandName && x.ServerId == interaction.guildId);
|
|
||||||
|
|
||||||
let itemToUse: ICommandItem;
|
|
||||||
|
|
||||||
if (!itemForServer) {
|
|
||||||
if (!item) {
|
|
||||||
await interaction.reply('Command not found');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
itemToUse = item;
|
|
||||||
} else {
|
|
||||||
itemToUse = itemForServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
itemToUse.Command.execute(interaction);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,54 +0,0 @@
|
||||||
import { ActionRowBuilder, AttachmentBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, EmbedBuilder, SlashCommandBuilder } from "discord.js";
|
|
||||||
import { Command } from "../type/command";
|
|
||||||
import CardDropHelper from "../helpers/CardDropHelper";
|
|
||||||
import { CardRarityToColour, CardRarityToString } from "../constants/CardRarity";
|
|
||||||
import { readFileSync } from "fs";
|
|
||||||
import { CoreClient } from "../client/client";
|
|
||||||
import { v4 } from "uuid";
|
|
||||||
|
|
||||||
export default class Drop extends Command {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
|
|
||||||
super.CommandBuilder = new SlashCommandBuilder()
|
|
||||||
.setName('drop')
|
|
||||||
.setDescription('Summon a new card drop');
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async execute(interaction: CommandInteraction) {
|
|
||||||
const randomCard = await CardDropHelper.GetRandomCard();
|
|
||||||
|
|
||||||
const image = readFileSync(randomCard.Path);
|
|
||||||
|
|
||||||
const attachment = new AttachmentBuilder(image, { name: `${randomCard.Id}.png` });
|
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
|
||||||
.setTitle(randomCard.Name)
|
|
||||||
.setDescription(randomCard.Series.Name)
|
|
||||||
.setFooter({ text: CardRarityToString(randomCard.Rarity) })
|
|
||||||
.setColor(CardRarityToColour(randomCard.Rarity))
|
|
||||||
.setImage(`attachment://${randomCard.Id}.png`);
|
|
||||||
|
|
||||||
const row = new ActionRowBuilder<ButtonBuilder>();
|
|
||||||
|
|
||||||
const claimId = v4();
|
|
||||||
|
|
||||||
row.addComponents(
|
|
||||||
new ButtonBuilder()
|
|
||||||
.setCustomId(`claim ${randomCard.CardNumber} ${claimId}`)
|
|
||||||
.setLabel("Claim")
|
|
||||||
.setStyle(ButtonStyle.Primary),
|
|
||||||
new ButtonBuilder()
|
|
||||||
.setCustomId(`reroll`)
|
|
||||||
.setLabel("Reroll")
|
|
||||||
.setStyle(ButtonStyle.Secondary));
|
|
||||||
|
|
||||||
await interaction.reply({
|
|
||||||
embeds: [ embed ],
|
|
||||||
files: [ attachment ],
|
|
||||||
components: [ row ],
|
|
||||||
});
|
|
||||||
|
|
||||||
CoreClient.ClaimId = claimId;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,34 +1,6 @@
|
||||||
import EmbedColours from "./EmbedColours";
|
|
||||||
|
|
||||||
export enum CardRarity {
|
export enum CardRarity {
|
||||||
Bronze,
|
Bronze,
|
||||||
Silver,
|
Silver,
|
||||||
Gold,
|
Gold,
|
||||||
Legendary,
|
Legendary,
|
||||||
}
|
}
|
||||||
|
|
||||||
export function CardRarityToString(rarity: CardRarity): string {
|
|
||||||
switch (rarity) {
|
|
||||||
case CardRarity.Bronze:
|
|
||||||
return "Bronze";
|
|
||||||
case CardRarity.Silver:
|
|
||||||
return "Silver";
|
|
||||||
case CardRarity.Gold:
|
|
||||||
return "Gold";
|
|
||||||
case CardRarity.Legendary:
|
|
||||||
return "Legendary";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function CardRarityToColour(rarity: CardRarity): number {
|
|
||||||
switch (rarity) {
|
|
||||||
case CardRarity.Bronze:
|
|
||||||
return EmbedColours.BronzeCard;
|
|
||||||
case CardRarity.Silver:
|
|
||||||
return EmbedColours.SilverCard;
|
|
||||||
case CardRarity.Gold:
|
|
||||||
return EmbedColours.GoldCard;
|
|
||||||
case CardRarity.Legendary:
|
|
||||||
return EmbedColours.LegendaryCard;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +1,3 @@
|
||||||
export default class EmbedColours {
|
export default class EmbedColours {
|
||||||
public static readonly Ok = 0x3050ba;
|
public static readonly Ok = 0x3050ba;
|
||||||
public static readonly BronzeCard = 0xcd7f32;
|
|
||||||
public static readonly SilverCard = 0xc0c0c0;
|
|
||||||
public static readonly GoldCard = 0xffd700;
|
|
||||||
public static readonly LegendaryCard = 0x50c878;
|
|
||||||
}
|
}
|
|
@ -1,6 +0,0 @@
|
||||||
import { ButtonEvent } from "../type/buttonEvent";
|
|
||||||
|
|
||||||
export default interface IButtonEventItem {
|
|
||||||
ButtonId: string,
|
|
||||||
Event: ButtonEvent,
|
|
||||||
}
|
|
0
src/database/entities/app/.gitkeep
Normal file
0
src/database/entities/app/.gitkeep
Normal file
|
@ -1,47 +0,0 @@
|
||||||
import { Column, Entity } from "typeorm";
|
|
||||||
import AppBaseEntity from "../../../contracts/AppBaseEntity";
|
|
||||||
import AppDataSource from "../../dataSources/appDataSource";
|
|
||||||
|
|
||||||
@Entity()
|
|
||||||
export default class Inventory extends AppBaseEntity {
|
|
||||||
constructor(userId: string, cardNumber: string, quantity: number, claimId: string) {
|
|
||||||
super();
|
|
||||||
|
|
||||||
this.UserId = userId;
|
|
||||||
this.CardNumber = cardNumber;
|
|
||||||
this.Quantity = quantity;
|
|
||||||
this.ClaimId = claimId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Column()
|
|
||||||
UserId: string;
|
|
||||||
|
|
||||||
@Column()
|
|
||||||
CardNumber: string;
|
|
||||||
|
|
||||||
@Column()
|
|
||||||
Quantity: number;
|
|
||||||
|
|
||||||
@Column()
|
|
||||||
ClaimId: string;
|
|
||||||
|
|
||||||
public SetQuantity(quantity: number) {
|
|
||||||
this.Quantity = quantity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async FetchOneByCardNumberAndUserId(userId: string, cardNumber: string): Promise<Inventory | null> {
|
|
||||||
const repository = AppDataSource.getRepository(Inventory);
|
|
||||||
|
|
||||||
const single = await repository.findOne({ where: { UserId: userId, CardNumber: cardNumber }});
|
|
||||||
|
|
||||||
return single;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async FetchOneByClaimId(claimId: string): Promise<Inventory | null> {
|
|
||||||
const repository = AppDataSource.getRepository(Inventory);
|
|
||||||
|
|
||||||
const single = await repository.findOne({ where: { ClaimId: claimId }});
|
|
||||||
|
|
||||||
return single;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,18 +1,17 @@
|
||||||
import { Column, Entity, ManyToOne } from "typeorm";
|
import { Column, Entity, OneToMany } from "typeorm";
|
||||||
import CardBaseEntity from "../../../contracts/CardBaseEntity";
|
import CardBaseEntity from "../../../contracts/CardBaseEntity";
|
||||||
import { CardRarity } from "../../../constants/CardRarity";
|
import { CardRarity } from "../../../constants/CardRarity";
|
||||||
import Series from "./Series";
|
import Series from "./Series";
|
||||||
|
import CardDataSource from "../../dataSources/cardDataSource";
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
export default class Card extends CardBaseEntity {
|
export default class Card extends CardBaseEntity {
|
||||||
constructor(cardNumber: string, name: string, rarity: CardRarity, path: string, series: Series) {
|
constructor(cardNumber: string, name: string, rarity: CardRarity) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.CardNumber = cardNumber;
|
this.CardNumber = cardNumber;
|
||||||
this.Name = name;
|
this.Name = name;
|
||||||
this.Rarity = rarity;
|
this.Rarity = rarity;
|
||||||
this.Path = path;
|
|
||||||
this.Series = series;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
|
@ -24,9 +23,14 @@ export default class Card extends CardBaseEntity {
|
||||||
@Column()
|
@Column()
|
||||||
Rarity: CardRarity;
|
Rarity: CardRarity;
|
||||||
|
|
||||||
@Column()
|
@OneToMany(() => Series, x => x.Cards)
|
||||||
Path: string
|
|
||||||
|
|
||||||
@ManyToOne(() => Series, x => x.Cards)
|
|
||||||
Series: Series;
|
Series: Series;
|
||||||
|
|
||||||
|
public static async FetchAllByRarity(rarity: CardRarity): Promise<Card[]> {
|
||||||
|
const repository = CardDataSource.getRepository(Card);
|
||||||
|
|
||||||
|
const all = await repository.find({ where: { Rarity: rarity }});
|
||||||
|
|
||||||
|
return all;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
import { Column, Entity, OneToMany } from "typeorm";
|
import { Column, Entity, ManyToOne } from "typeorm";
|
||||||
import CardBaseEntity from "../../../contracts/CardBaseEntity";
|
import CardBaseEntity from "../../../contracts/CardBaseEntity";
|
||||||
import Card from "./Card";
|
import Card from "./Card";
|
||||||
|
|
||||||
|
@ -18,6 +18,12 @@ export default class Series extends CardBaseEntity {
|
||||||
@Column()
|
@Column()
|
||||||
Path: string;
|
Path: string;
|
||||||
|
|
||||||
@OneToMany(() => Card, x => x.Series)
|
@ManyToOne(() => Card, x => x.Series)
|
||||||
Cards: Card[];
|
Cards: Card[];
|
||||||
|
|
||||||
|
public async AddCard(card: Card) {
|
||||||
|
if (!this.Cards) return;
|
||||||
|
|
||||||
|
this.Cards.push(card);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,38 +0,0 @@
|
||||||
import { CardRarity } from "../constants/CardRarity";
|
|
||||||
import CardDataSource from "../database/dataSources/cardDataSource";
|
|
||||||
import Card from "../database/entities/card/Card";
|
|
||||||
import Series from "../database/entities/card/Series";
|
|
||||||
|
|
||||||
export default class CardDropHelper {
|
|
||||||
public static async GetRandomCard(): Promise<Card> {
|
|
||||||
const seriesRepository = CardDataSource.getRepository(Series);
|
|
||||||
|
|
||||||
const allSeries = await Series.FetchAll(Series, [ "Cards", "Cards.Series" ]);
|
|
||||||
const allSeriesWithCards = allSeries.filter(x => x.Cards.length > 0);
|
|
||||||
|
|
||||||
const randomSeriesIndex = Math.floor(Math.random() * allSeriesWithCards.length);
|
|
||||||
|
|
||||||
const randomSeries = allSeriesWithCards[randomSeriesIndex];
|
|
||||||
|
|
||||||
const randomRarity = Math.random() * 100;
|
|
||||||
|
|
||||||
let cardRarity: CardRarity;
|
|
||||||
|
|
||||||
const bronzeChance = 62;
|
|
||||||
const silverChance = bronzeChance + 31;
|
|
||||||
const goldChance = silverChance + 6.4;
|
|
||||||
|
|
||||||
if (randomRarity < bronzeChance) cardRarity = CardRarity.Bronze;
|
|
||||||
else if (randomRarity < silverChance) cardRarity = CardRarity.Silver;
|
|
||||||
else if (randomRarity < goldChance) cardRarity = CardRarity.Gold;
|
|
||||||
else cardRarity = CardRarity.Legendary;
|
|
||||||
|
|
||||||
const allCards = randomSeries.Cards.filter(x => x.Rarity == cardRarity);
|
|
||||||
|
|
||||||
const randomCardIndex = Math.floor(Math.random() * allCards.length);
|
|
||||||
|
|
||||||
const randomCard = allCards[randomCardIndex];
|
|
||||||
|
|
||||||
return randomCard;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,23 +1,13 @@
|
||||||
import { CoreClient } from "./client/client";
|
import { CoreClient } from "./client/client";
|
||||||
|
|
||||||
import About from "./commands/about";
|
import About from "./commands/about";
|
||||||
import Drop from "./commands/drop";
|
|
||||||
|
|
||||||
import Claim from "./buttonEvents/Claim";
|
|
||||||
import Reroll from "./buttonEvents/Reroll";
|
|
||||||
|
|
||||||
export default class Registry {
|
export default class Registry {
|
||||||
public static RegisterCommands() {
|
public static RegisterCommands() {
|
||||||
CoreClient.RegisterCommand('about', new About());
|
CoreClient.RegisterCommand('about', new About());
|
||||||
CoreClient.RegisterCommand('drop', new Drop());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RegisterEvents() {
|
public static RegisterEvents() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RegisterButtonEvents() {
|
|
||||||
CoreClient.RegisterButtonEvent('claim', new Claim());
|
|
||||||
CoreClient.RegisterButtonEvent('reroll', new Reroll());
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,7 +0,0 @@
|
||||||
import { ButtonInteraction } from "discord.js";
|
|
||||||
|
|
||||||
export class ButtonEvent {
|
|
||||||
public execute(interaction: ButtonInteraction) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue