diff --git a/commands/drop.js b/commands/drop.js index c9046c5..c2ac80d 100644 --- a/commands/drop.js +++ b/commands/drop.js @@ -2,6 +2,7 @@ const { SlashCommandBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, Compo const { Card, User, Character, DropHistory, sequelize } = require("../models"); const { customAlphabet } = require("nanoid"); const { CardUtils, UserUtils, ReplyUtils, GeneralUtils, Rendering } = require("../util"); +const { QUALITY } = require("../config/constants"); const card = require("../models/card"); module.exports = { @@ -33,6 +34,28 @@ module.exports = { }); for (let i = 0; i < 3; i++) { + //generate quality based on drop rate + let quality = undefined; + let roll = Math.random() * 100; + if (roll <= 45.0) { + quality = QUALITY.BAD; //45% + } + if (roll > 45.0) { + quality = QUALITY.OK; //25% + } + if (roll > 70.0) { + quality = QUALITY.GOOD; //15% + } + if (roll > 85.0) { + quality = QUALITY.GREAT; //10% + } + if (roll > 95.0) { + quality = QUALITY.EXCELLENT; //5% + } + if (roll > 99.9) { + quality = QUALITY.SHINY; //0.1% + } + //get number of characters in database const characterId = characters[i].id console.log(`characterId: ${characterId}`); @@ -40,7 +63,7 @@ module.exports = { let newCard = await Card.create({ characterId: characterId, identifier: CardUtils.generateIdentifier(), - quality: Math.floor(Math.random() * 6) + 1, + quality: quality, printNr: await CardUtils.getNextPrintNumber(characterId), }); diff --git a/config/constants.js b/config/constants.js new file mode 100644 index 0000000..c25e4ce --- /dev/null +++ b/config/constants.js @@ -0,0 +1,20 @@ +const QUALITY = { + BAD : 1, + OK : 2, + GOOD : 3, + GREAT : 4, + EXCELLENT : 5, + SHINY : 6 +} + +const QUALITY_NAMES = { + 1 : "Bad", + 2 : "Ok", + 3 : "Good", + 4 : "Great", + 5 : "Excellent", + 6 : "Shiny" +} + +exports.QUALITY = QUALITY; +exports.QUALITY_NAMES = QUALITY_NAMES; \ No newline at end of file diff --git a/dropRateTest.js b/dropRateTest.js new file mode 100644 index 0000000..dafa265 --- /dev/null +++ b/dropRateTest.js @@ -0,0 +1,45 @@ +const { QUALITY, QUALITY_NAMES } = require('./config/constants'); +let results = []; +let drops = 1000; +let header = `⫭=== Quality distribution for ${drops.toLocaleString()} drops: ===⫬`; +console.log(header); +console.log(`|${' '.repeat(header.length-2)}|`); +for ( let i = 0 ; i < drops ; i++) { + //generate rarity based on drop rate + let quality = undefined; + let roll = Math.random() * 100; + if (roll <= 45.0) { + quality = QUALITY.BAD; + } + if (roll > 45.0) { + quality = QUALITY.OK; + } + if (roll > 70.0) { + quality = QUALITY.GOOD; + } + if (roll > 85.0) { + quality = QUALITY.GREAT; + } + if (roll > 95.0) { + quality = QUALITY.EXCELLENT; + } + if (roll > 99.9) { + quality = QUALITY.SHINY; + } + results.push(quality); +} + +//count the number of times each quality appears +let counts = {}; +results.forEach(function(x) { counts[x] = (counts[x] || 0)+1; }); +//print results with percentages +let p_total = 0; +for (let key in counts) { + let p = counts[key]/results.length * 100; + p_total += p; + let cpStr = `${counts[key].toLocaleString()} (${p}%)`; + let fStr = `| ${key}/${QUALITY_NAMES[key]}${' '.repeat(10-QUALITY_NAMES[key].length)}: ${cpStr}`; + console.log(`${fStr}${' '.repeat(header.length-fStr.length-1)}|`); +} +console.log(`⌊${'_'.repeat(header.length-2)}⌋`); +