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:
2022-09-12 03:37:45 +02:00
parent fb1f4b346e
commit ed7096fac0
5 changed files with 37 additions and 4 deletions

View File

@@ -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