Merge branch 'main' into develop
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
commit
3be95bf1ac
6 changed files with 63 additions and 57 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "card-drop",
|
"name": "card-drop",
|
||||||
"version": "0.1.6",
|
"version": "0.1.7",
|
||||||
"main": "./dist/bot.js",
|
"main": "./dist/bot.js",
|
||||||
"typings": "./dist",
|
"typings": "./dist",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -3,7 +3,7 @@ import CardDataSource from "../database/dataSources/cardDataSource";
|
||||||
import Card from "../database/entities/card/Card";
|
import Card from "../database/entities/card/Card";
|
||||||
import Series from "../database/entities/card/Series";
|
import Series from "../database/entities/card/Series";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { CardRarity } from "../constants/CardRarity";
|
import { CardRarity, CardRarityToString } from "../constants/CardRarity";
|
||||||
|
|
||||||
export default class CardSetupFunction {
|
export default class CardSetupFunction {
|
||||||
public async Execute() {
|
public async Execute() {
|
||||||
|
@ -49,63 +49,47 @@ export default class CardSetupFunction {
|
||||||
const cardsToSave: Card[] = [];
|
const cardsToSave: Card[] = [];
|
||||||
|
|
||||||
for (let series of loadedSeries) {
|
for (let series of loadedSeries) {
|
||||||
const bronzeExists = existsSync(path.join(process.cwd(), 'cards', series.Path, 'BRONZE'));
|
const cardDirBronze = this.GetCardFiles(CardRarity.Bronze, series);
|
||||||
const goldExists = existsSync(path.join(process.cwd(), 'cards', series.Path, 'GOLD'));
|
const cardDirGold = this.GetCardFiles(CardRarity.Gold, series);
|
||||||
const legendaryExists = existsSync(path.join(process.cwd(), 'cards', series.Path, 'LEGENDARY'));
|
const cardDirLegendary = this.GetCardFiles(CardRarity.Legendary, series);
|
||||||
const silverExists = existsSync(path.join(process.cwd(), 'cards', series.Path, 'SILVER'));
|
const cardDirSilver = this.GetCardFiles(CardRarity.Silver, series);
|
||||||
|
const cardDirManga = this.GetCardFiles(CardRarity.Manga, series);
|
||||||
|
|
||||||
const cardDirBronze = bronzeExists ? readdirSync(path.join(process.cwd(), 'cards', series.Path, 'BRONZE')) : [];
|
cardsToSave.push(
|
||||||
const cardDirGold = goldExists ? readdirSync(path.join(process.cwd(), 'cards', series.Path, 'GOLD')) : [];
|
...this.GenerateCardData(cardDirBronze, CardRarity.Bronze, series),
|
||||||
const cardDirLegendary = legendaryExists ? readdirSync(path.join(process.cwd(), 'cards', series.Path, 'LEGENDARY')) : [];
|
...this.GenerateCardData(cardDirGold, CardRarity.Gold, series),
|
||||||
const cardDirSilver = silverExists ? readdirSync(path.join(process.cwd(), 'cards', series.Path, 'SILVER')) : [];
|
...this.GenerateCardData(cardDirLegendary, CardRarity.Legendary, series),
|
||||||
|
...this.GenerateCardData(cardDirSilver, CardRarity.Silver, series),
|
||||||
for (let file of cardDirBronze.filter(x => !x.startsWith('.') && (x.endsWith('.png') || x.endsWith('.jpg') || x.endsWith('.gif')))) {
|
...this.GenerateCardData(cardDirManga, CardRarity.Manga, series)
|
||||||
const filePart = file.split('.');
|
);
|
||||||
|
|
||||||
const cardId = 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)), file, series);
|
|
||||||
|
|
||||||
cardsToSave.push(card);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let file of cardDirGold.filter(x => !x.startsWith('.') && (x.endsWith('.png') || x.endsWith('.jpg') || x.endsWith('.gif')))) {
|
|
||||||
const filePart = file.split('.');
|
|
||||||
|
|
||||||
const cardId = 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)), file, series);
|
|
||||||
|
|
||||||
cardsToSave.push(card);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let file of cardDirLegendary.filter(x => !x.startsWith('.') && (x.endsWith('.png') || x.endsWith('.jpg') || x.endsWith('.gif')))) {
|
|
||||||
const filePart = file.split('.');
|
|
||||||
|
|
||||||
const cardId = 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)), file, series);
|
|
||||||
|
|
||||||
cardsToSave.push(card);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let file of cardDirSilver.filter(x => !x.startsWith('.') && (x.endsWith('.png') || x.endsWith('.jpg') || x.endsWith('.gif')))) {
|
|
||||||
const filePart = file.split('.');
|
|
||||||
|
|
||||||
const cardId = 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)), file, series);
|
|
||||||
|
|
||||||
cardsToSave.push(card);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await cardRepository.save(cardsToSave);
|
await cardRepository.save(cardsToSave);
|
||||||
|
|
||||||
console.log(`Loaded ${cardsToSave.length} cards to database`);
|
console.log(`Loaded ${cardsToSave.length} cards to database`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private GenerateCardData(files: string[], rarity: CardRarity, series: Series): Card[] {
|
||||||
|
const result: Card[] = [];
|
||||||
|
|
||||||
|
for (let file of files.filter(x => !x.startsWith('.') && (x.endsWith('.png') || x.endsWith('.jpg') || x.endsWith('.gif')))) {
|
||||||
|
const filePart = file.split('.');
|
||||||
|
|
||||||
|
const cardId = filePart[0];
|
||||||
|
const cardName = filePart[0];
|
||||||
|
|
||||||
|
const card = new Card(cardId, cardName, rarity, path.join(process.cwd(), 'cards', series.Path, CardRarityToString(rarity).toUpperCase(), file), file, series);
|
||||||
|
|
||||||
|
result.push(card);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private GetCardFiles(rarity: CardRarity, series: Series): string[] {
|
||||||
|
const folder = path.join(process.cwd(), 'cards', series.Path, CardRarityToString(rarity).toUpperCase());
|
||||||
|
const folderExists = existsSync(folder);
|
||||||
|
|
||||||
|
return folderExists ? readdirSync(folder) : [];
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,14 +1,18 @@
|
||||||
import EmbedColours from "./EmbedColours";
|
import EmbedColours from "./EmbedColours";
|
||||||
|
|
||||||
export enum CardRarity {
|
export enum CardRarity {
|
||||||
|
Unknown,
|
||||||
Bronze,
|
Bronze,
|
||||||
Silver,
|
Silver,
|
||||||
Gold,
|
Gold,
|
||||||
|
Manga,
|
||||||
Legendary,
|
Legendary,
|
||||||
}
|
}
|
||||||
|
|
||||||
export function CardRarityToString(rarity: CardRarity): string {
|
export function CardRarityToString(rarity: CardRarity): string {
|
||||||
switch (rarity) {
|
switch (rarity) {
|
||||||
|
case CardRarity.Unknown:
|
||||||
|
return "Unknown";
|
||||||
case CardRarity.Bronze:
|
case CardRarity.Bronze:
|
||||||
return "Bronze";
|
return "Bronze";
|
||||||
case CardRarity.Silver:
|
case CardRarity.Silver:
|
||||||
|
@ -17,11 +21,15 @@ export function CardRarityToString(rarity: CardRarity): string {
|
||||||
return "Gold";
|
return "Gold";
|
||||||
case CardRarity.Legendary:
|
case CardRarity.Legendary:
|
||||||
return "Legendary";
|
return "Legendary";
|
||||||
|
case CardRarity.Manga:
|
||||||
|
return "Manga";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function CardRarityToColour(rarity: CardRarity): number {
|
export function CardRarityToColour(rarity: CardRarity): number {
|
||||||
switch (rarity) {
|
switch (rarity) {
|
||||||
|
case CardRarity.Unknown:
|
||||||
|
return EmbedColours.Grey;
|
||||||
case CardRarity.Bronze:
|
case CardRarity.Bronze:
|
||||||
return EmbedColours.BronzeCard;
|
return EmbedColours.BronzeCard;
|
||||||
case CardRarity.Silver:
|
case CardRarity.Silver:
|
||||||
|
@ -30,5 +38,7 @@ export function CardRarityToColour(rarity: CardRarity): number {
|
||||||
return EmbedColours.GoldCard;
|
return EmbedColours.GoldCard;
|
||||||
case CardRarity.Legendary:
|
case CardRarity.Legendary:
|
||||||
return EmbedColours.LegendaryCard;
|
return EmbedColours.LegendaryCard;
|
||||||
|
case CardRarity.Manga:
|
||||||
|
return EmbedColours.MangaCard;
|
||||||
}
|
}
|
||||||
}
|
}
|
7
src/constants/CardRarityChances.ts
Normal file
7
src/constants/CardRarityChances.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
export default class CardRarityChances {
|
||||||
|
public static readonly Bronze = 62;
|
||||||
|
public static readonly Silver = 31;
|
||||||
|
public static readonly Gold = 4.4;
|
||||||
|
public static readonly Manga = 2;
|
||||||
|
// Legendary therefore = 0.6;
|
||||||
|
}
|
|
@ -1,7 +1,9 @@
|
||||||
export default class EmbedColours {
|
export default class EmbedColours {
|
||||||
public static readonly Ok = 0x3050ba;
|
public static readonly Ok = 0x3050ba;
|
||||||
|
public static readonly Grey = 0xd3d3d3;
|
||||||
public static readonly BronzeCard = 0xcd7f32;
|
public static readonly BronzeCard = 0xcd7f32;
|
||||||
public static readonly SilverCard = 0xc0c0c0;
|
public static readonly SilverCard = 0xc0c0c0;
|
||||||
public static readonly GoldCard = 0xffd700;
|
public static readonly GoldCard = 0xffd700;
|
||||||
public static readonly LegendaryCard = 0x50c878;
|
public static readonly LegendaryCard = 0x50c878;
|
||||||
|
public static readonly MangaCard = 0xffffff;
|
||||||
}
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } from "discord.js";
|
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } from "discord.js";
|
||||||
import { CardRarity, CardRarityToColour, CardRarityToString } from "../constants/CardRarity";
|
import { CardRarity, CardRarityToColour, CardRarityToString } from "../constants/CardRarity";
|
||||||
|
import CardRarityChances from "../constants/CardRarityChances";
|
||||||
import Card from "../database/entities/card/Card";
|
import Card from "../database/entities/card/Card";
|
||||||
|
|
||||||
export default class CardDropHelper {
|
export default class CardDropHelper {
|
||||||
|
@ -8,13 +9,15 @@ export default class CardDropHelper {
|
||||||
|
|
||||||
let cardRarity: CardRarity;
|
let cardRarity: CardRarity;
|
||||||
|
|
||||||
const bronzeChance = 62;
|
const bronzeChance = CardRarityChances.Bronze;
|
||||||
const silverChance = bronzeChance + 31;
|
const silverChance = bronzeChance + CardRarityChances.Silver;
|
||||||
const goldChance = silverChance + 6.4;
|
const goldChance = silverChance + CardRarityChances.Gold;
|
||||||
|
const mangaChance = goldChance + CardRarityChances.Manga;
|
||||||
|
|
||||||
if (randomRarity < bronzeChance) cardRarity = CardRarity.Bronze;
|
if (randomRarity < bronzeChance) cardRarity = CardRarity.Bronze;
|
||||||
else if (randomRarity < silverChance) cardRarity = CardRarity.Silver;
|
else if (randomRarity < silverChance) cardRarity = CardRarity.Silver;
|
||||||
else if (randomRarity < goldChance) cardRarity = CardRarity.Gold;
|
else if (randomRarity < goldChance) cardRarity = CardRarity.Gold;
|
||||||
|
else if (randomRarity < mangaChance) cardRarity = CardRarity.Manga;
|
||||||
else cardRarity = CardRarity.Legendary;
|
else cardRarity = CardRarity.Legendary;
|
||||||
|
|
||||||
const randomCard = await this.GetRandomCardByRarity(cardRarity);
|
const randomCard = await this.GetRandomCardByRarity(cardRarity);
|
||||||
|
|
Loading…
Reference in a new issue