User: Add experience / levels
Each drop and claim hands out 10 and 5 xp respectively. The profile then renders the users current level based on the formula 0.5 * sqrt(exp)
This commit is contained in:
@@ -66,10 +66,10 @@
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
<g transform="matrix(0.116211,0,0,0.116211,749.774,13.2261)">
|
||||
<g transform="matrix(0.116211,0,0,0.116211,742.774,13.2261)">
|
||||
<use xlink:href="#_Image4" x="0" y="0" width="512px" height="512px"/>
|
||||
</g>
|
||||
<g transform="matrix(0.166016,0,0,0.166016,504.979,0.476193)">
|
||||
<g transform="matrix(0.166016,0,0,0.166016,499.979,0.476193)">
|
||||
<use xlink:href="#_Image5" x="0" y="0" width="512px" height="512px"/>
|
||||
</g>
|
||||
<g id="USER_IMAGE" transform="matrix(0.853333,0,0,0.853333,73.7407,8.57671)">
|
||||
|
||||
|
Before Width: | Height: | Size: 91 KiB After Width: | Height: | Size: 91 KiB |
@@ -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"],
|
||||
|
||||
@@ -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 = [];
|
||||
|
||||
21
migrations/20220911230203-add-user-experience.js
Normal file
21
migrations/20220911230203-add-user-experience.js
Normal file
@@ -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');
|
||||
}
|
||||
};
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user