diff --git a/commands/minigame/borgar.js b/commands/minigame/borgar.js index 4c085024..7a127e47 100644 --- a/commands/minigame/borgar.js +++ b/commands/minigame/borgar.js @@ -1,27 +1,15 @@ // TODO: -// Make a level system per user and increasse difficutly based on the level -// higher the level the more ingredient required -// higher the level the less time you have to complete it +// Higher the level the less time you have to complete it +// Make the command less shit const { Command } = require('discord-akairo'); const { MessageEmbed } = require('discord.js'); +const borgar = require('../../models').borgar; class borgarCommand extends Command { constructor() { super('borgar', { aliases: ['borgar', 'hamburgor', 'hamborgar', 'burger', 'hamburger', 'borger'], category: 'minigame', - args: [ - { - id: 'ingredientNumber', - type: 'number', - default: 4 - }, - { - id: 'time', - type: 'number', - default: 10 - } - ], description: { content: 'Make amborgar,,,,,,,,,, ( MINI GAME VERY WIP, NO LEVEL YET )', usage: '[number of ingredient] [time]', @@ -30,19 +18,48 @@ class borgarCommand extends Command { }); } - async exec(message, args) { - if (args.time <= 0) args.time = 1; - const ingredients = [ 'bun', 'beef', 'salade', 'tomato', 'cheese', 'pickle', 'onion', 'garlic', 'basil', 'lettuce']; - let hamIngredient = []; - for (let i = 0; i < args.ingredientNumber; i++) { - hamIngredient[i] = ingredients[Math.floor( Math.random() * ingredients.length )]; + async exec(message) { + let level; + let curxp; + let xp = Math.floor((Math.random() * 23) + 1); + + 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() - .setTitle('hamborger delivery') + .setTitle('hamborger info') .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(); message.util.send(borgarEmbed) @@ -51,25 +68,43 @@ class borgarCommand extends Command { borgarEmbed = new MessageEmbed() .setTitle('hamborger delivery') .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(); message.util.edit(borgarEmbed); 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 => { let userIngredient = messages.map(messages => messages.content); + let body; - if (userIngredient.toString().toLowerCase() == hamIngredient.toString()) { - return message.reply('u won bro,,,, that\'s kinda epic if i do say so myself'); - } else if (userIngredient.length == hamIngredient.length) { - return message.reply(`you failed noob... you were supposed to make **${hamIngredient}**`); - } else if (userIngredient.length > hamIngredient.length) { - return message.reply('Too much ingredient...'); + if (userIngredient.toString().toLowerCase() == hamIngredient.toString().toLowerCase()) { + let totalXP = curxp + xp; + body = {userID: message.author.id, level: level, xp: totalXP}; + if (curxp == 0) { + message.reply(`u won bro,,,, that's kinda epic if i do say so myself\n**you gained ${xp} xp.**`); + } 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(() => { - return message.reply('You ran out of time noob...'); + .catch(err => { + console.error(err); + return message.reply('You ran out of time noob... ( or an error occured )'); }); }, 3000); });