diff --git a/assets/profile/profile.svg b/assets/profile/profile.svg index d2357a3..0a56ded 100644 --- a/assets/profile/profile.svg +++ b/assets/profile/profile.svg @@ -66,10 +66,10 @@ - + - + diff --git a/commands/drop.js b/commands/drop.js index b51349f..610d5c3 100644 --- a/commands/drop.js +++ b/commands/drop.js @@ -61,6 +61,8 @@ module.exports = { .setStyle(ButtonStyle.Primary), ); } + //add 10 experience to the user + await user.addExperience(10); const file = new AttachmentBuilder(deckImage); @@ -93,7 +95,7 @@ module.exports = { cards[cardId].userId = claimUser.id; await UserUtils.setCooldown(claimUser, "pull", await GeneralUtils.getBotProperty("pullTimeout")); await cards[cardId].save(); - + await claimUser.addExperience(5); //fetch character name from database given the character id let character = await Character.findOne({ attributes: ["name"], diff --git a/commands/profile.js b/commands/profile.js index 96a94a7..0178e6c 100644 --- a/commands/profile.js +++ b/commands/profile.js @@ -20,7 +20,7 @@ module.exports = { profileTemplate = profileTemplate.replace(/{{USERNAME}}/g, interaction.member.displayName.substr(0,15)+(interaction.member.displayName.length>15?'...':'')); profileTemplate = profileTemplate.replace(/{{HEADER_COLOR}}/g, '190,31,97'); profileTemplate = profileTemplate.replace(/{{CC}}/g, await Card.count({where: {userId: user.id}})); - profileTemplate = profileTemplate.replace(/{{LVL}}/g, "0"); + profileTemplate = profileTemplate.replace(/{{LVL}}/g, await user.getLevel()); let slots = ['slotOne', 'slotTwo', 'slotThree', 'slotFour']; let renderedCards = []; diff --git a/migrations/20220911230203-add-user-experience.js b/migrations/20220911230203-add-user-experience.js new file mode 100644 index 0000000..3e0e326 --- /dev/null +++ b/migrations/20220911230203-add-user-experience.js @@ -0,0 +1,21 @@ +'use strict'; + +module.exports = { + async up (queryInterface, Sequelize) { + /** + * Add field experience to table users + */ + await queryInterface.addColumn('Users', 'experience', { + type: Sequelize.INTEGER, + allowNull: false, + defaultValue: 0 + }); + }, + + async down (queryInterface, Sequelize) { + /** + * Remove field experience from table users + */ + await queryInterface.removeColumn('Users', 'experience'); + } +}; diff --git a/models/user.js b/models/user.js index 10fd486..744568b 100644 --- a/models/user.js +++ b/models/user.js @@ -15,6 +15,15 @@ module.exports = (sequelize, DataTypes) => { User.hasMany(models.Card); User.hasOne(models.Profile); } + async addExperience(amount) { + console.log(`Adding ${amount} experience to user ${this.id}`); + await this.update({ + experience: this.experience + amount + }); + } + async getLevel() { + return Math.ceil(0.5 * Math.sqrt(this.experience)); + } //instance methods async getCardsWithCharactersCounted() { let cards = await sequelize.models.Card.findAndCountAll({ @@ -39,6 +48,7 @@ module.exports = (sequelize, DataTypes) => { discordId: DataTypes.BIGINT, active: DataTypes.INTEGER, privacy: DataTypes.INTEGER, + experience: DataTypes.INTEGER, nextDrop: DataTypes.DATE, nextPull: DataTypes.DATE, nextDaily: DataTypes.DATE