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",
|
||||
"version": "0.1.6",
|
||||
"version": "0.1.7",
|
||||
"main": "./dist/bot.js",
|
||||
"typings": "./dist",
|
||||
"scripts": {
|
||||
|
|
|
@ -3,7 +3,7 @@ import CardDataSource from "../database/dataSources/cardDataSource";
|
|||
import Card from "../database/entities/card/Card";
|
||||
import Series from "../database/entities/card/Series";
|
||||
import path from "path";
|
||||
import { CardRarity } from "../constants/CardRarity";
|
||||
import { CardRarity, CardRarityToString } from "../constants/CardRarity";
|
||||
|
||||
export default class CardSetupFunction {
|
||||
public async Execute() {
|
||||
|
@ -49,63 +49,47 @@ export default class CardSetupFunction {
|
|||
const cardsToSave: Card[] = [];
|
||||
|
||||
for (let series of loadedSeries) {
|
||||
const bronzeExists = existsSync(path.join(process.cwd(), 'cards', series.Path, 'BRONZE'));
|
||||
const goldExists = existsSync(path.join(process.cwd(), 'cards', series.Path, 'GOLD'));
|
||||
const legendaryExists = existsSync(path.join(process.cwd(), 'cards', series.Path, 'LEGENDARY'));
|
||||
const silverExists = existsSync(path.join(process.cwd(), 'cards', series.Path, 'SILVER'));
|
||||
const cardDirBronze = this.GetCardFiles(CardRarity.Bronze, series);
|
||||
const cardDirGold = this.GetCardFiles(CardRarity.Gold, series);
|
||||
const cardDirLegendary = this.GetCardFiles(CardRarity.Legendary, series);
|
||||
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')) : [];
|
||||
const cardDirGold = goldExists ? readdirSync(path.join(process.cwd(), 'cards', series.Path, 'GOLD')) : [];
|
||||
const cardDirLegendary = legendaryExists ? readdirSync(path.join(process.cwd(), 'cards', series.Path, 'LEGENDARY')) : [];
|
||||
const cardDirSilver = silverExists ? readdirSync(path.join(process.cwd(), 'cards', series.Path, 'SILVER')) : [];
|
||||
|
||||
for (let file of cardDirBronze.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.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);
|
||||
}
|
||||
cardsToSave.push(
|
||||
...this.GenerateCardData(cardDirBronze, CardRarity.Bronze, series),
|
||||
...this.GenerateCardData(cardDirGold, CardRarity.Gold, series),
|
||||
...this.GenerateCardData(cardDirLegendary, CardRarity.Legendary, series),
|
||||
...this.GenerateCardData(cardDirSilver, CardRarity.Silver, series),
|
||||
...this.GenerateCardData(cardDirManga, CardRarity.Manga, series)
|
||||
);
|
||||
}
|
||||
|
||||
await cardRepository.save(cardsToSave);
|
||||
|
||||
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";
|
||||
|
||||
export enum CardRarity {
|
||||
Unknown,
|
||||
Bronze,
|
||||
Silver,
|
||||
Gold,
|
||||
Manga,
|
||||
Legendary,
|
||||
}
|
||||
|
||||
export function CardRarityToString(rarity: CardRarity): string {
|
||||
switch (rarity) {
|
||||
case CardRarity.Unknown:
|
||||
return "Unknown";
|
||||
case CardRarity.Bronze:
|
||||
return "Bronze";
|
||||
case CardRarity.Silver:
|
||||
|
@ -17,11 +21,15 @@ export function CardRarityToString(rarity: CardRarity): string {
|
|||
return "Gold";
|
||||
case CardRarity.Legendary:
|
||||
return "Legendary";
|
||||
case CardRarity.Manga:
|
||||
return "Manga";
|
||||
}
|
||||
}
|
||||
|
||||
export function CardRarityToColour(rarity: CardRarity): number {
|
||||
switch (rarity) {
|
||||
case CardRarity.Unknown:
|
||||
return EmbedColours.Grey;
|
||||
case CardRarity.Bronze:
|
||||
return EmbedColours.BronzeCard;
|
||||
case CardRarity.Silver:
|
||||
|
@ -30,5 +38,7 @@ export function CardRarityToColour(rarity: CardRarity): number {
|
|||
return EmbedColours.GoldCard;
|
||||
case CardRarity.Legendary:
|
||||
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 {
|
||||
public static readonly Ok = 0x3050ba;
|
||||
public static readonly Grey = 0xd3d3d3;
|
||||
public static readonly BronzeCard = 0xcd7f32;
|
||||
public static readonly SilverCard = 0xc0c0c0;
|
||||
public static readonly GoldCard = 0xffd700;
|
||||
public static readonly LegendaryCard = 0x50c878;
|
||||
public static readonly MangaCard = 0xffffff;
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder } from "discord.js";
|
||||
import { CardRarity, CardRarityToColour, CardRarityToString } from "../constants/CardRarity";
|
||||
import CardRarityChances from "../constants/CardRarityChances";
|
||||
import Card from "../database/entities/card/Card";
|
||||
|
||||
export default class CardDropHelper {
|
||||
|
@ -8,13 +9,15 @@ export default class CardDropHelper {
|
|||
|
||||
let cardRarity: CardRarity;
|
||||
|
||||
const bronzeChance = 62;
|
||||
const silverChance = bronzeChance + 31;
|
||||
const goldChance = silverChance + 6.4;
|
||||
const bronzeChance = CardRarityChances.Bronze;
|
||||
const silverChance = bronzeChance + CardRarityChances.Silver;
|
||||
const goldChance = silverChance + CardRarityChances.Gold;
|
||||
const mangaChance = goldChance + CardRarityChances.Manga;
|
||||
|
||||
if (randomRarity < bronzeChance) cardRarity = CardRarity.Bronze;
|
||||
else if (randomRarity < silverChance) cardRarity = CardRarity.Silver;
|
||||
else if (randomRarity < goldChance) cardRarity = CardRarity.Gold;
|
||||
else if (randomRarity < mangaChance) cardRarity = CardRarity.Manga;
|
||||
else cardRarity = CardRarity.Legendary;
|
||||
|
||||
const randomCard = await this.GetRandomCardByRarity(cardRarity);
|
||||
|
|
Loading…
Reference in a new issue