make a "level" system

This commit is contained in:
loicbersier 2019-10-09 01:32:18 +02:00
parent fc0bd392c7
commit ad707cf9d4

View file

@ -1,27 +1,15 @@
// TODO: // TODO:
// Make a level system per user and increasse difficutly based on the level // Higher the level the less time you have to complete it
// higher the level the more ingredient required // Make the command less shit
// higher the level the less time you have to complete it
const { Command } = require('discord-akairo'); const { Command } = require('discord-akairo');
const { MessageEmbed } = require('discord.js'); const { MessageEmbed } = require('discord.js');
const borgar = require('../../models').borgar;
class borgarCommand extends Command { class borgarCommand extends Command {
constructor() { constructor() {
super('borgar', { super('borgar', {
aliases: ['borgar', 'hamburgor', 'hamborgar', 'burger', 'hamburger', 'borger'], aliases: ['borgar', 'hamburgor', 'hamborgar', 'burger', 'hamburger', 'borger'],
category: 'minigame', category: 'minigame',
args: [
{
id: 'ingredientNumber',
type: 'number',
default: 4
},
{
id: 'time',
type: 'number',
default: 10
}
],
description: { description: {
content: 'Make amborgar,,,,,,,,,, ( MINI GAME VERY WIP, NO LEVEL YET )', content: 'Make amborgar,,,,,,,,,, ( MINI GAME VERY WIP, NO LEVEL YET )',
usage: '[number of ingredient] [time]', usage: '[number of ingredient] [time]',
@ -30,19 +18,48 @@ class borgarCommand extends Command {
}); });
} }
async exec(message, args) { async exec(message) {
if (args.time <= 0) args.time = 1; let level;
const ingredients = [ 'bun', 'beef', 'salade', 'tomato', 'cheese', 'pickle', 'onion', 'garlic', 'basil', 'lettuce']; let curxp;
let hamIngredient = []; let xp = Math.floor((Math.random() * 23) + 1);
for (let i = 0; i < args.ingredientNumber; i++) {
hamIngredient[i] = ingredients[Math.floor( Math.random() * ingredients.length )]; const userInfo = await borgar.findOne({where: {userID:message.author.id}});
if (userInfo) {
curxp = userInfo.get('xp');
if (curxp < 100) {
level = 1;
} else if (curxp >= 100) {
level = 2;
} else if (curxp >= 200) {
level = 3;
} else if (curxp >= 300) {
level = 4;
} else if (curxp >= 400) {
level = 5;
} else if (curxp >= 500) {
level = 6;
}
} else {
curxp = 0;
level = 1;
} }
const ingredients = ['beef', 'salade', 'tomato', 'cheese', 'pickle', 'onion', 'garlic', 'basil', 'lettuce'];
let hamIngredient = [];
hamIngredient.push('bun');
for (let i = 1; i < level + Math.floor(Math.random() * 2) + 1; i++) {
hamIngredient[i] = ingredients[Math.floor(Math.random() * ingredients.length)];
}
hamIngredient.push('bun');
let borgarEmbed = new MessageEmbed() let borgarEmbed = new MessageEmbed()
.setTitle('hamborger delivery') .setTitle('hamborger info')
.setDescription(`could you do me an **amborgar** that contain **${hamIngredient}**`) .setDescription(`could you do me an **amborgar** that contain **${hamIngredient}**`)
.setFooter(`Level 0 | Once the ingredients dissapear you have ${args.time} seconds to do it!`) .setFooter(`Level ${level} | Once the ingredients dissapear you have 10 seconds to do it!`)
.setTimestamp(); .setTimestamp();
message.util.send(borgarEmbed) message.util.send(borgarEmbed)
@ -51,25 +68,43 @@ class borgarCommand extends Command {
borgarEmbed = new MessageEmbed() borgarEmbed = new MessageEmbed()
.setTitle('hamborger delivery') .setTitle('hamborger delivery')
.setDescription('You have to put each ingredients in seperate messages!') .setDescription('You have to put each ingredients in seperate messages!')
.setFooter(`Level 0 | you have ${args.time} seconds to make that hamborgor`) .setFooter(`Level ${level} | you have 10 seconds to make that hamborgor`)
.setTimestamp(); .setTimestamp();
message.util.edit(borgarEmbed); message.util.edit(borgarEmbed);
const filter = m => m.content && m.author.id == message.author.id; const filter = m => m.content && m.author.id == message.author.id;
message.channel.awaitMessages(filter, {time: args.time * 1000, max: hamIngredient.length, errors: ['time'] }) message.channel.awaitMessages(filter, {time: 10 * 1000, max: hamIngredient.length, errors: ['time'] })
.then(messages => { .then(messages => {
let userIngredient = messages.map(messages => messages.content); let userIngredient = messages.map(messages => messages.content);
let body;
if (userIngredient.toString().toLowerCase() == hamIngredient.toString()) { if (userIngredient.toString().toLowerCase() == hamIngredient.toString().toLowerCase()) {
return message.reply('u won bro,,,, that\'s kinda epic if i do say so myself'); let totalXP = curxp + xp;
} else if (userIngredient.length == hamIngredient.length) { body = {userID: message.author.id, level: level, xp: totalXP};
return message.reply(`you failed noob... you were supposed to make **${hamIngredient}**`); if (curxp == 0) {
} else if (userIngredient.length > hamIngredient.length) { message.reply(`u won bro,,,, that's kinda epic if i do say so myself\n**you gained ${xp} xp.**`);
return message.reply('Too much ingredient...'); } else {
message.reply(`u won bro,,,, that's kinda epic if i do say so myself\n**you gained ${xp} xp. you now have ${totalXP} xp**`);
}
} else {
let totalXP = curxp - xp;
body = {userID: message.author.id, level: level, xp: totalXP};
if (curxp == 0) {
message.reply(`you failed noob... you were supposed to make **${hamIngredient}**`);
} else {
message.reply(`you failed noob... you were supposed to make **${hamIngredient}**\n**you lost ${xp} xp. you now have ${totalXP} xp**`);
}
}
if (curxp == 0) {
borgar.create(body);
} else {
borgar.update(body, {where: {userID:message.author.id}});
} }
}) })
.catch(() => { .catch(err => {
return message.reply('You ran out of time noob...'); console.error(err);
return message.reply('You ran out of time noob... ( or an error occured )');
}); });
}, 3000); }, 3000);
}); });