diff --git a/ressources/text/commands/report.json b/ressources/text/commands/report.json index 0e01428df..1b091e7c5 100644 --- a/ressources/text/commands/report.json +++ b/ressources/text/commands/report.json @@ -10,7 +10,19 @@ "healthLoose": "** | :broken_heart: Vie perdue : ** {health}", "health": "** | :heart: Vie gagnée : ** {health}", "timeLost": "** | :clock10: Temps perdu : ** {timeLost}", - "noReport": ":newspaper: ** Journal de {pseudo} : ** :x: Aucun nouveau rapport n'a été transmis ! Revenez dans quelques heures !" + "noReport": ":newspaper: ** Journal de {pseudo} : ** :x: Aucun nouveau rapport n'a été transmis ! Revenez dans quelques heures !", + "nothingToSay": [ + "** | :smiley: Aucun incident ni évènement notable à signaler.", + "** | :smiley: Il ne s'est rien passé de particulier depuis le précédent rapport.", + "** | :smiley: Vous n'avez rencontré aucune difficulté à progresser durant les dernières heures, vous continuez d'avancer tranquillement.", + "** | :smiley: Rien à signaler, vous continuez d'avancer.", + "** | :smiley: Pas d'obstacle en vue, rien ne semble être contre vous en ce moment. Vous continuez d'avancer.", + "** | :smiley: La voie est libre, aucune raison de s'arrêter, vous continuez d'avancer", + "** | :smiley: Rien d'important ne s'est passé depuis le rapport précédent.", + "** | :smiley: Pas d'évènement notable depuis la dernière fois.", + "** | :smiley: Les chiens aboient et la caravane passe. Vous continuez tranquillement votre route", + "** | :smiley: La princesse se rapproche de vous ! Du moins c'est l'impression que vous avez... Vous continuez votre route." + ] }, "en": { "doEvent": ":newspaper: ** Journal of {pseudo} {event}", @@ -22,7 +34,19 @@ "healthLoose": "** | :broken_heart: Life lost: ** {health}", "health": "** | :heart: Life gained: ** {health}", "timeLost": "** | :clock10: Time spent: ** {timeLost}", - "noReport": ":newspaper: ** Journal of {pseudo} : ** :x: You don’t have any new reports! Come back in a few hours!" + "noReport": ":newspaper: ** Journal of {pseudo} : ** :x: You don’t have any new reports! Come back in a few hours!", + "nothingToSay": [ + "** | :smiley: No incidents or significant events to report.", + "** | :smiley: Nothing special happened since the previous report.", + "** | :smiley: You haven't encountered any difficulty in your progress during the last few hours, and you continue to progress quietly.", + "** | :smiley: Nothing to report, you keep moving forward.", + "** | :smiley: No obstacles in sight, nothing seems to be against you right now. You keep moving forward.", + "** | :smiley: The way is clear, no reason to stop, you keep moving forward", + "** | :smiley: Nothing significant has happened since the previous report.", + "** | :smiley: No significant events since last time.", + "** | :smiley: The dogs bark and the caravan passes by. You continue quietly on your way", + "** | :smiley: The princess got closer to you! At least that's the impression you got... You carry on." + ] } }, "timeMinimal": 60, diff --git a/src/commands/admin/TestCommand.js b/src/commands/admin/TestCommand.js index 02116aff3..3a8c6d616 100644 --- a/src/commands/admin/TestCommand.js +++ b/src/commands/admin/TestCommand.js @@ -224,6 +224,12 @@ const TestCommand = async (language, message, args) => { author.Player.Inventory.backup_id = 0; author.Player.Inventory.save(); break; + case 'atime': + if (args.length === 2) { + author.Player.lastReportAt -= parseInt(args[1]) * 60000; + author.Player.save(); + } + break; default: await message.channel.send('Argument inconnu !'); return; diff --git a/src/commands/player/ReportCommand.js b/src/commands/player/ReportCommand.js index e2008715d..9a83bd9e5 100644 --- a/src/commands/player/ReportCommand.js +++ b/src/commands/player/ReportCommand.js @@ -10,29 +10,37 @@ const ReportCommand = async function(language, message, args) { if ((await canPerformCommand(message, language, PERMISSION.ROLE.ALL, [EFFECT.DEAD], entity)) !== true) { return; } - + if (await sendBlockedError(message.author, message.channel, language)) { + return; + } let time = millisecondsToMinutes(message.createdAt.getTime() - entity.Player.lastReportAt.valueOf()); if (time > JsonReader.commands.report.timeLimit) { time = JsonReader.commands.report.timeLimit; } if (entity.Player.score === 0 && entity.effect === EFFECT.BABY) { - // TODO add player to blocked + addBlockedPlayer(entity.discordUser_id, "report"); const event = await Events.findOne({where: {id: 0}}); return await doEvent(message, language, event, entity, time); } - // if (time < JsonReader.commands.report.timeMinimal) { - // await getRepository('player').update(player); - // return await message.channel.send(format(JsonReader.commands.report.noReport, {pseudo: message.author.username})); - // } - // - // // TODO add player to blocked - // - // if (time <= JsonReader.commands.report.timeMaximal && Math.round(Math.random() * JsonReader.commands.report.timeMaximal) > time) { - // // TODO Exec special event nothingToSay - // return; - // } + if (time < JsonReader.commands.report.timeMinimal) { + return await message.channel.send(format(JsonReader.commands.report.getTranslation(language).noReport, {pseudo: message.author.username})); + } + + if (time <= JsonReader.commands.report.timeMaximal && Math.round(Math.random() * JsonReader.commands.report.timeMaximal) > time) { + return await message.channel.send( + format( + JsonReader.commands.report.getTranslation(language).doEvent, + { + pseudo: message.author.username, + event: JsonReader.commands.report.getTranslation(language).nothingToSay[randInt(0, JsonReader.commands.report.getTranslation(language).length - 1)] + } + ) + ); + } + + addBlockedPlayer(entity.discordUser_id, "report"); const event = await Events.findOne({order: (require('sequelize')).literal('RANDOM()')}); return await doEvent(message, language, event, entity, time); @@ -49,7 +57,7 @@ const ReportCommand = async function(language, message, args) { const doEvent = async (message, language, event, entity, time) => { const eventDisplayed = await message.channel.send(format(JsonReader.commands.report.getTranslation(language).doEvent, {pseudo: message.author.username, event: event[language]})); const reactions = await event.getReactions(); - const collector = eventDisplayed.createReactionCollector(async (reaction, user) => { + const collector = eventDisplayed.createReactionCollector((reaction, user) => { return (reactions.indexOf(reaction.emoji.name) !== -1 && user.id === message.author.id); }, {time: 120000}); @@ -66,7 +74,9 @@ const doEvent = async (message, language, event, entity, time) => { } }); for (const reaction of reactions) { - await eventDisplayed.react(reaction); + if (reaction !== 'end') { + eventDisplayed.react(reaction); + } } }; @@ -80,60 +90,66 @@ const doEvent = async (message, language, event, entity, time) => { */ const doPossibility = async (message, language, possibility, entity, time) => { const player = entity.Player; + possibility = possibility[randInt(0, possibility.length)]; + const pDataValues = possibility.dataValues; const scoreChange = time + Math.round(Math.random() * (time / 10 + player.level)); - let moneyChange = possibility.money + Math.round(time / 10 + Math.round(Math.random() * (time / 10 + player.level / 5))); - if (possibility.money < 0 && moneyChange > 0) { - moneyChange = Math.round(possibility.money / 2); + let moneyChange = pDataValues.money + Math.round(time / 10 + Math.round(Math.random() * (time / 10 + player.level / 5))); + if (pDataValues.money < 0 && moneyChange > 0) { + moneyChange = Math.round(pDataValues.money / 2); } let result = ''; - result += (moneyChange >= 0) ? format(JsonReader.commands.report.getTranslation(language).money, {money: moneyChange}) : result += format(JsonReader.commands.report.getTranslation(language).moneyLoose, {money: moneyChange}); - if (possibility.experience > 0) { - result += format(JsonReader.commands.report.getTranslation(language).experience, {experience: possibility.experience}); + result += format(JsonReader.commands.report.getTranslation(language).points, { score: scoreChange }); + result += (moneyChange >= 0) ? format(JsonReader.commands.report.getTranslation(language).money, {money: moneyChange}) : format(JsonReader.commands.report.getTranslation(language).moneyLoose, {money: -moneyChange}); + if (pDataValues.experience > 0) { + result += format(JsonReader.commands.report.getTranslation(language).experience, {experience: pDataValues.experience}); } - if (possibility.health < 0) { - result += format(JsonReader.commands.report.getTranslation(language).health, {health: possibility.health}); + if (pDataValues.health < 0) { + result += format(JsonReader.commands.report.getTranslation(language).health, {health: pDataValues.health}); } - if (possibility.health > 0) { - result += format(JsonReader.commands.report.getTranslation(language).healthLoose, {health: possibility.health}); + if (pDataValues.health > 0) { + result += format(JsonReader.commands.report.getTranslation(language).healthLoose, {health: pDataValues.health}); } // TODO Mettre le temps + le temps de l'effet - if (possibility.lostTime > 0) { - result += format(JsonReader.commands.report.getTranslation(language).timeLost, {timeLost: possibility.lostTime}); + if (pDataValues.lostTime > 0) { + let hours = Math.floor(pDataValues.lostTime / 60); + let minutes = Math.round(pDataValues.lostTime % 60); + const timeMsg = hours === 0 ? (minutes + " min") : (hours + " H " + minutes + " Min"); + result += format(JsonReader.commands.report.getTranslation(language).timeLost, {timeLost: timeMsg}); } result = format(JsonReader.commands.report.getTranslation(language).doPossibility, {pseudo: message.author, result: result, event: possibility[language]}); - entity.effect = possibility.effect; - entity.addHealth(possibility.health); + entity.effect = pDataValues.effect; + entity.addHealth(pDataValues.health); player.addScore(scoreChange); player.addMoney(moneyChange); player.experience += possibility.experience; - player.setLastReportWithEffect(message.createdTimestamp, possibility.lostTime, possibility.effect); + player.setLastReportWithEffect(message.createdTimestamp, pDataValues.lostTime, pDataValues.effect); if (possibility.item === true) { - // TODO - // player = await player.giveRandomItem(message, player, false); + await giveRandomItem((await message.guild.members.fetch(entity.discordUser_id)).user, message.channel, language, entity); } - if (possibility.eventId === 0) { + if (pDataValues.eventId === 0) { player.money = 0; player.score = 0; - if (possibility.emoji !== 'end') { + if (pDataValues.emoji !== 'end') { player.money = 10; player.score = 100; } } - await getRepository('player').update(player); await message.channel.send(result); - // TODO remove player of blocked + removeBlockedPlayer(entity.discordUser_id); // TODO CHECK STATUS (LVL UP / DEAD) if (player.needLevelUp()) { // DO lvlUp } + player.save(); + // return await XXX; }; diff --git a/src/commands_old/Fight.js b/src/commands_old/Fight.js deleted file mode 100644 index 9d448ee34..000000000 --- a/src/commands_old/Fight.js +++ /dev/null @@ -1,832 +0,0 @@ -const PlayerManager = require('../core/PlayerManager'); -const Tools = require('../utils/Tools'); -const DefaultValues = require('data/text/DefaultValues'); -const moment = require('moment'); -const Discord = require('discord.js'); -let Text; -let language; - - -/** - * Allow the user to launch a fight - * @param message - The message that caused the function to be called. Used to retrieve the author of the message. - */ -const fightCommand = async function(message, args, client, talkedRecently) { - Text = await Tools.chargeText(message); - language = await Tools.detectLanguage(message); - const diffMinutes = getMinutesBeforeReset(); - if (resetIsNow(diffMinutes)) { - const embed = await generateResetTopWeekEmbed(message); - return message.channel.send(embed); - } - if (talkedRecently.has(message.author.id)) { - return message.channel.send(Text.commands.sell.cancelStart + message.author + Text.commands.shop.tooMuchShop); - } - const playerManager = new PlayerManager; - const attacker = message.author; - let defender = undefined; - let spamchecker = 0; - const attackerDefenseAdd = 20; - const defenderDefenseAdd = 20; - const attackerSpeedAdd = 30; - const defenderSpeedAdd = 30; - const nbTours = 0; - // loading of the current player - const player = await playerManager.getCurrentPlayer(message); - - if (player.level < DefaultValues.fight.minimalLevel) { - displayErrorSkillMissing(message, attacker); - } else { - if (playerManager.checkState(player, message, ':smiley:', language)) { // check if the player is not dead or sick or something else - let chosenOpponent = undefined; - if (askForAnotherPlayer(args)) { // check if an opponent was asked - let chosenOpponentId; - chosenOpponent = await getAskedPlayer(chosenOpponentId, chosenOpponent, playerManager, message, args); - if (askedPlayerIsInvalid(chosenOpponent)) { - return message.channel.send(Text.commands.fight.errorEmoji + message.author + Text.commands.fight.chosenOpponentDontPlay); - } - if (chosenOpponent.id === player.id) { - return message.channel.send(Text.commands.fight.errorEmoji + attacker + Text.commands.fight.alreadyAttackerError); - } - if (chosenOpponent.getLevel() < DefaultValues.fight.minimalLevel) { - return message.channel.send(Text.commands.fight.errorEmoji + message.author + Text.commands.fight.chosenOpponentNotEnoughSkill1 + DefaultValues.fight.minimalLevel + Text.commands.fight.chosenOpponentNotEnoughSkill2); - } - } - - playerManager.setPlayerAsOccupied(player); - - const messageIntro = await displayIntroMessage(message, attacker, chosenOpponent); - - let fightIsOpen = true; - - let filter; - if (chosenOpponent === undefined) { - filter = (reaction, user) => { // filter if no one was asked - return (reactionIsCorrect(reaction, user)); - }; - } else { - filter = (reaction, user) => { // filter if an opponent was asked - if (chosenOpponent.id === user.id || attacker.id === user.id) { - return (reactionIsCorrect(reaction, user)); - } - }; - } - - const collector = messageIntro.createReactionCollector(filter, { - time: 120000, - }); - - // execute this if a user answer to the demand - collector.on('collect', async (reaction) => { - if (fightIsOpen) { - defender = reaction.users.last(); - if (fightHasToBeCanceled(reaction)) { - ({fightIsOpen, spamchecker} = treatFightCancel(defender, message, fightIsOpen, attacker, playerManager, player, spamchecker)); - } else { - if (defender.id === message.author.id) { // le defenseur et l'attaquant sont la même personne - ({spamchecker, fightIsOpen} = cancelFightLaunch(spamchecker, message, attacker, fightIsOpen, playerManager, player)); - } else {// le defenseur n'est pas l'attaquant - const defenderPlayer = await playerManager.getPlayerById(defender.id, message); - if (defenderPlayer.level < DefaultValues.fight.minimalLevel) { - displayErrorSkillMissing(message, defender); - } else { - if (talkedRecently.has(defender.id)) { - return message.channel.send(Text.commands.sell.cancelStart + defender + Text.commands.shop.tooMuchShop); - } - if (playerManager.checkState(defenderPlayer, message, ':smiley:', language, defender.username)) { // check if the player is not dead or sick or something else - playerManager.setPlayerAsOccupied(defenderPlayer); - fightIsOpen = false; - displayFightStartMessage(message, attacker, defender); - const actualUser = attacker; - const actuelPlayer = player; - const opponentUser = defender; - const opponentPlayer = defenderPlayer; - const lastMessageFromBot = undefined; - const lastEtatFight = undefined; - const attackerPower = player.getFightPower(); - const defenderPower = defenderPlayer.getFightPower(); - - await Tools.addItemBonus(player); - await Tools.addItemBonus(defenderPlayer); - fight(lastMessageFromBot, message, actualUser, player, actuelPlayer, opponentPlayer, opponentUser, attacker, defender, defenderPlayer, attackerPower, defenderPower, defenderDefenseAdd, attackerDefenseAdd, lastEtatFight, attackerSpeedAdd, defenderSpeedAdd, nbTours); - } - } - } - } - } - }); - - // end of the time the users have to answer to the demand - collector.on('end', () => { - if (fightIsOpen) { - message.channel.send(Text.commands.fight.errorEmoji + attacker + Text.commands.fight.noAnswerError); - playerManager.setPlayerAsUnOccupied(player); - } - }); - } - } -}; - - -/** - * Generate the embed that the bot has to send if the top week is curently beeing reset - * @param {*} message - the message used to get this embed - */ -async function generateResetTopWeekEmbed(message) { - const embed = new Discord.RichEmbed(); - const Text = await Tools.chargeText(message); - embed.setColor(DefaultValues.embed.color); - embed.setTitle(Text.commandReader.resetIsNowTitle); - embed.setDescription(Text.commandReader.resetIsNowFooterFight); - return embed; -} - -/** - * True if the reset is now (every sunday at midnight) - * @param {*} diffMinutes - The amount of minutes before the next reset - */ -function resetIsNow(diffMinutes) { - return diffMinutes < 15 && diffMinutes > -1; -} - -/** - * Get the amount of minutes before the next reset - */ -function getMinutesBeforeReset() { - const now = new Date(); // The current date - const dateOfReset = new Date(); // The next Sunday - dateOfReset.setDate(now.getDate() + (0 + (7 - now.getDay())) % 7); // Calculating next Sunday - dateOfReset.setHours(22, 59, 59); // Defining hours, min, sec to 23, 59, 59 - // Parsing dates to moment - const nowMoment = new moment(now); - const momentOfReset = new moment(dateOfReset); - const diffMinutes = momentOfReset.diff(nowMoment, 'minutes'); - return diffMinutes; -} - - -/** - * Allow to display the message that announce the begining of the fight - * @param {*} message - * @param {*} attacker - The first player - * @param {*} defender - */ -function displayFightStartMessage(message, attacker, defender) { - message.channel.send(Text.commands.fight.startStart + attacker + Text.commands.fight.startJoin + defender + Text.commands.fight.startEnd); -} - -async function displayIntroMessage(message, attacker, chosenOpponent) { - const messageIntro = await generateIntroMessage(message, attacker, chosenOpponent); - messageIntro.react('⚔').then((a) => { - messageIntro.react('❌'); - }); - return messageIntro; -} - - -/** - * Allow to make one round of the fight - * @param {*} lastMessageFromBot - * @param {*} message - * @param {*} actualUser - The user that is currently playing - * @param {*} player - The first player - * @param {*} actuelPlayer - * @param {*} opponentPlayer - * @param {*} opponentUser - * @param {*} attacker - The first player - * @param {*} defender - * @param {*} defenderPlayer - * @param {*} attackerPower - * @param {*} defenderPower - * @param {*} defenderDefenseAdd - * @param {*} attackerDefenseAdd - * @param {*} lastEtatFight - * @param {*} attackerSpeedAdd - * @param {*} defenderSpeedAdd - * @param {*} nbTours - */ -async function fight(lastMessageFromBot, message, actualUser, player, actuelPlayer, opponentPlayer, opponentUser, attacker, defender, defenderPlayer, attackerPower, defenderPower, defenderDefenseAdd, attackerDefenseAdd, lastEtatFight, attackerSpeedAdd, defenderSpeedAdd, nbTours) { - let actualUserPoints = 0; - let opponentUserPoints = 0; - if (actualUser == attacker) { - actualUserPoints = attackerPower; - opponentUserPoints = defenderPower; - } else { - actualUserPoints = defenderPower; - opponentUserPoints = attackerPower; - } - if (lastMessageFromBot != undefined) { - lastMessageFromBot.delete(5000).catch(); - } - if (lastEtatFight != undefined) { - lastEtatFight.delete(5000).catch(); - } - lastEtatFight = await message.channel.send(Text.commands.fight.statusIntro + Text.commands.fight.attackerEmoji + actualUser.username + - Text.commands.fight.statusPoints + actualUserPoints + Text.commands.profile.statsAttack + actuelPlayer.attack + - Text.commands.profile.statsDefense + actuelPlayer.defense + Text.commands.profile.statsSpeed + actuelPlayer.speed + - Text.commands.fight.endLine + Text.commands.fight.defenderEmoji + opponentUser.username + - Text.commands.fight.statusPoints + opponentUserPoints + Text.commands.profile.statsAttack + opponentPlayer.attack + - Text.commands.profile.statsDefense + opponentPlayer.defense + Text.commands.profile.statsSpeed + opponentPlayer.speed); - - - lastMessageFromBot = await displayFightMenu(message, actualUser); - - let playerHasResponded = true; - - const filter = (reaction, user) => { - return (reactionFightIsCorrect(reaction, user)); - }; - - const collector = lastMessageFromBot.createReactionCollector(filter, { - time: 30000, - }); - - // execute this if a user answer to the demand - collector.on('collect', async (reaction) => { - if (playerHasResponded) { - if (reaction.users.last() === actualUser) { // On check que c'est le bon joueur qui réagis - playerHasResponded = false; - let attackPower; - switch (reaction.emoji.name) { - case '🗡': // attaque rapide - // 75% des points d'attaque sont utilisés - // 30% des points de défense sont utilisés - // Taux de réussite de 30% qui monte à 95% sur un adversaire plus lent - ({defenderPower, attackerPower} = quickAttack(attackPower, player, opponentPlayer, actuelPlayer, defenderPower, attackerPower, attacker, actualUser, reaction, message)); - break; - case '⚔': // attaque simple - // 100% ou 50% des points d'attaque sont utilisés - // 100% des points de défense sont utilisés - // Taux de réussite de 60% qui monte à 80% sur un adversaire plus lent - // En plus des 60% de réussite, 30% de chance de réussite partielle sur un adversaire plus rapide - ({defenderPower, attackerPower} = simpleAttack(attackPower, player, opponentPlayer, actuelPlayer, defenderPower, attackerPower, attacker, actualUser, reaction, message)); - break; - case '💣': // attaque puissante - // 125% ou 200% des points d'attaque sont utilisés - // 100% des points de défense sont utilisés - // Diminue la vitesse de 10 ou 25 % pour le prochain tour - // 5% de réussite totale sur un adversaire plus rapide et 40% de réussite partielle - // 30% de réussite totale sur un adversaire plus lent et 70% de réusite partielle - ({defenderPower, attackerPower} = powerfullAttack(attackPower, player, opponentPlayer, actuelPlayer, defenderPower, attackerPower, attacker, actualUser, reaction, message)); - break; - case '🛡': // defendre - // augmente la défense - ({attackerDefenseAdd, defenderDefenseAdd} = ImproveDefense(actualUser, attacker, actuelPlayer, attackerDefenseAdd, message, reaction, defenderDefenseAdd)); - break; - default: // esquive - // augmente la vitesse de 30 points - ({attackerSpeedAdd, defenderSpeedAdd} = ImproveSpeed(actualUser, attacker, actuelPlayer, attackerSpeedAdd, message, reaction, defenderSpeedAdd)); - break; - } - ({actualUser, actuelPlayer, opponentPlayer, opponentUser} = switchActiveUser(actualUser, attacker, defender, actuelPlayer, defenderPlayer, player, opponentPlayer, opponentUser)); - if (nobodyLooses(attackerPower, defenderPower)) { - if (nbTours < 25) { - nbTours++; - fight(lastMessageFromBot, message, actualUser, player, actuelPlayer, opponentPlayer, opponentUser, attacker, defender, defenderPlayer, attackerPower, defenderPower, defenderDefenseAdd, attackerDefenseAdd, lastEtatFight, attackerSpeedAdd, defenderSpeedAdd, nbTours); - } else { - const playerManager = new PlayerManager(); - playerManager.setPlayerAsUnOccupied(player); - playerManager.setPlayerAsUnOccupied(defenderPlayer); - message.channel.send(Text.commands.fight.finStart + attacker + Text.commands.fight.finEgalite + defender + Text.commands.fight.finEgaliteEnd); - } - } else { - finDeCombat(player, defenderPlayer, attackerPower, defender, attacker, message, lastMessageFromBot, lastEtatFight); - } - } - } - }); - // end of the time the users have to answer to the demand - collector.on('end', () => { - if (playerHasResponded) { // the player has quit the fight - playerHasResponded = false; - if (actualUser == attacker) { - attackerPower = 0; - } - finDeCombat(player, defenderPlayer, attackerPower, defender, attacker, message, lastMessageFromBot, lastEtatFight); - } - }); -} - -/** - * Allow to end properly a fight - * @param {*} player - The first player - * @param {*} defenderPlayer - The other player - * @param {*} attackerPower - The current power point of the first player - * @param {*} defender - The second User - * @param {*} attacker - The first User - * @param {*} message - The message that ran the command - * @param {*} lastMessageFromBot - The las message the bot has send - * @param {*} lastEtatFight - The last message containing the stats of the fight the bot sent - */ -function finDeCombat(player, defenderPlayer, attackerPower, defender, attacker, message, lastMessageFromBot, lastEtatFight) { - let elo = 0; - let messageFinCombat; - elo = calculateElo(player, defenderPlayer, elo); - let pts; - if (attackerPower <= 0) { // the attacker has loose - pts = Math.round(100 + 10 * player.level * Math.round((player.score / defenderPlayer.score) * 100) / 100); - pts = capMaxWin(pts); - messageFinCombat = Text.commands.fight.finStart + defender + Text.commands.fight.finDebut + attacker + - Text.commands.fight.finEndLine + elo + Text.commands.fight.finPts + pts + Text.commands.fight.finFin; - player.score = player.score - pts; - player.weeklyScore = player.weeklyScore - pts; - defenderPlayer.score = defenderPlayer.score + pts; - defenderPlayer.weeklyScore = defenderPlayer.weeklyScore + pts; - } else { // the defender has loose - pts = Math.round(100 + 10 * defenderPlayer.level * Math.round((defenderPlayer.score / player.score) * 100) / 100); - pts = capMaxWin(pts); - messageFinCombat = Text.commands.fight.finStart + attacker + Text.commands.fight.finDebut + defender + - Text.commands.fight.finEndLine + elo + Text.commands.fight.finPts + pts + Text.commands.fight.finFin; - player.score = player.score + pts; - player.weeklyScore = player.weeklyScore + pts; - defenderPlayer.score = defenderPlayer.score - pts; - defenderPlayer.weeklyScore = defenderPlayer.weeklyScore - pts; - } - const playerManager = new PlayerManager; - playerManager.updatePlayerScore(player); - playerManager.updatePlayerScore(defenderPlayer); - playerManager.setPlayerAsUnOccupied(player); - playerManager.setPlayerAsUnOccupied(defenderPlayer); - - message.channel.send(messageFinCombat); - if (lastMessageFromBot != undefined) { - lastMessageFromBot.delete(5000).catch(); - } - if (lastEtatFight != undefined) { - lastEtatFight.delete(5000).catch(); - } -} - -/** - * Permet de limiter les gains maximals lors d'un combat - * @param {*} pts - */ -function capMaxWin(pts) { - if (pts > 2000) { - Math.round(pts = 2000 - Tools.generateRandomNumber(5, 1000)); - } - return pts; -} - -/** - * Allow to calculate the elo fo the game - * @param {*} player - The first player - * @param {*} defenderPlayer - The other player - * @param {*} elo - The elo - */ -function calculateElo(player, defenderPlayer, elo) { - if (player.score < defenderPlayer.score) { - elo = Math.round((player.score / defenderPlayer.score) * 100) / 100; - } else { - elo = Math.round((defenderPlayer.score / player.score) * 100) / 100; - } - return elo; -} - -/** - * Allow to improve the defense stats of a player - * @param {*} actualUser - The user that is currently playing - * @param {*} attacker - The first player - * @param {*} actuelPlayer - The player that is currently playing - * @param {*} attackerDefenseAdd - The amount of defense the bot has to give to the attacker - * @param {*} message - The message that ran the command - * @param {*} reaction - The reaction the user clicked on - * @param {*} defenderDefenseAdd - The amount of defense the bot has to give to the defender - */ -function ImproveDefense(actualUser, attacker, actuelPlayer, attackerDefenseAdd, message, reaction, defenderDefenseAdd) { - if (actualUser == attacker) { - attackerDefenseAdd += Tools.generateRandomNumber(0, Math.round(attackerDefenseAdd / 2)); - actuelPlayer.defense += attackerDefenseAdd; - message.channel.send(reaction.emoji.name + Text.commands.fight.endIntroStart + actualUser.username + Text.commands.fight.defenseAdd + attackerDefenseAdd + Text.commands.fight.degatsOutro); - attackerDefenseAdd = Math.floor(attackerDefenseAdd * 0.5); - } else { - defenderDefenseAdd += Tools.generateRandomNumber(0, Math.round(defenderDefenseAdd / 2)); - actuelPlayer.defense += defenderDefenseAdd; - message.channel.send(reaction.emoji.name + Text.commands.fight.endIntroStart + actualUser.username + Text.commands.fight.defenseAdd + defenderDefenseAdd + Text.commands.fight.degatsOutro); - defenderDefenseAdd = Math.floor(defenderDefenseAdd * 0.5); - } - return {attackerDefenseAdd, defenderDefenseAdd}; -} - -/** - * Allow to improve the speed stats of a player - * @param {*} actualUser - The user that is currently playing - * @param {*} attacker - The first player - * @param {*} actuelPlayer - The player that is currently playing - * @param {*} attackerSpeedAdd - The amount of speed the bot has to give to the attacker - * @param {*} message - The message that ran the command - * @param {*} reaction - The reaction the user clicked on - * @param {*} defenderSpeedAdd - The amount of speed the bot has to give to the defender - */ -function ImproveSpeed(actualUser, attacker, actuelPlayer, attackerSpeedAdd, message, reaction, defenderSpeedAdd) { - if (actualUser == attacker) { - attackerSpeedAdd += Tools.generateRandomNumber(0, Math.round(attackerSpeedAdd / 2)); - actuelPlayer.speed += attackerSpeedAdd; - message.channel.send(reaction.emoji.name + Text.commands.fight.endIntroStart + actualUser.username + Text.commands.fight.speedAdd + attackerSpeedAdd + Text.commands.fight.degatsOutro); - attackerSpeedAdd = Math.floor(attackerSpeedAdd * 0.5); - } else { - defenderSpeedAdd += Tools.generateRandomNumber(0, Math.round(defenderSpeedAdd / 2)); - actuelPlayer.speed += defenderSpeedAdd; - message.channel.send(reaction.emoji.name + Text.commands.fight.endIntroStart + actualUser.username + Text.commands.fight.speedAdd + defenderSpeedAdd + Text.commands.fight.degatsOutro); - defenderSpeedAdd = Math.floor(defenderSpeedAdd * 0.5); - } - return {attackerSpeedAdd, defenderSpeedAdd}; -} - -/** - * Allow to pake a powerfull attack - * @param {*} attackPower - * @param {*} player - The first player - * @param {*} opponentPlayer - * @param {*} actuelPlayer - * @param {*} defenderPower - * @param {*} attackerPower - * @param {*} attacker - The first player - * @param {*} actualUser - The user that is currently playing - * @param {*} reaction - * @param {*} message - */ -function powerfullAttack(attackPower, player, opponentPlayer, actuelPlayer, defenderPower, attackerPower, attacker, actualUser, reaction, message) { - // test which player is quicker - const succes = Tools.generateRandomNumber(1, 100); - let powerchanger = 0; - if (opponentPlayer.speed > actuelPlayer.speed) { - if (succes <= 40 && succes > 5) { // partial success - powerchanger = 1.25; - } - if (succes <= 5) { // total success - powerchanger = 2; - } - } else { - if (succes <= 80 && succes > 30) { // partial success - powerchanger = 1.25; - } - if (succes <= 40) { // total success - powerchanger = 2; - } - } - lowerSpeed(powerchanger, actuelPlayer); - attackPower = actuelPlayer.attack * powerchanger; - let messagePowerfulAttack = ''; - const defensePower = opponentPlayer.defense; - let degats = Math.round(attackPower - Math.round(defensePower)); - const random = Tools.generateRandomNumber(1, 8); - if (degats > 0) { - if (powerchanger == 2) { - ({defenderPower, attackerPower} = updatePlayerPower(attacker, actualUser, defenderPower, degats, attackerPower)); - messagePowerfulAttack = reaction.emoji.name + Text.commands.fight.endIntroStart + actualUser.username + Text.commands.fight.powerfulAttack.ok[random] + Text.commands.fight.degatsIntro + degats + Text.commands.fight.degatsOutro; - } else { - ({defenderPower, attackerPower} = updatePlayerPower(attacker, actualUser, defenderPower, degats, attackerPower)); - messagePowerfulAttack = reaction.emoji.name + Text.commands.fight.endIntroStart + actualUser.username + Text.commands.fight.powerfulAttack.meh[random] + Text.commands.fight.degatsIntro + degats + Text.commands.fight.degatsOutro; - } - } else { - degats = 0; - messagePowerfulAttack = reaction.emoji.name + Text.commands.fight.endIntroStart + actualUser.username + Text.commands.fight.powerfulAttack.ko[random] + Text.commands.fight.degatsIntro + degats + Text.commands.fight.degatsOutro; - } - message.channel.send(messagePowerfulAttack); - return {defenderPower, attackerPower}; -} - -/** - * lower speed after a powerful attack - * @param {*} powerchanger - * @param {*} actuelPlayer - */ -function lowerSpeed(powerchanger, actuelPlayer) { - if (powerchanger > 1) { - actuelPlayer.speed = Math.round(actuelPlayer.speed * 0.75); - } else { - actuelPlayer.speed = Math.round(actuelPlayer.speed * 0.9); - } -} - -/** - * allow to perform a basic attack - * @param {*} attackPower - * @param {*} player - The first player - * @param {*} opponentPlayer - * @param {*} actuelPlayer - * @param {*} defenderPower - * @param {*} attackerPower - * @param {*} attacker - The first player - * @param {*} actualUser - The user that is currently playing - * @param {*} reaction - * @param {*} message - */ -function simpleAttack(attackPower, player, opponentPlayer, actuelPlayer, defenderPower, attackerPower, attacker, actualUser, reaction, message) { - const succes = Tools.generateRandomNumber(1, 100); - let powerchanger = 0.1; - if (opponentPlayer.speed > actuelPlayer.speed) { - if (succes <= 60) { // total success - powerchanger = 1; - } - if (succes <= 90 && succes > 60) { // partial success - powerchanger = 0.5; - } - } else { - if (succes <= 80) { // total success - powerchanger = 1; - } - } - attackPower = actuelPlayer.attack * powerchanger; - let messageAttaqueSimple = ''; - const defensePower = opponentPlayer.defense; - let degats = Math.round(attackPower - Math.round(defensePower)); - const random = Tools.generateRandomNumber(1, 8); - if (degats > 0) { - if (degats >= 100) { - ({defenderPower, attackerPower} = updatePlayerPower(attacker, actualUser, defenderPower, degats, attackerPower)); - messageAttaqueSimple = reaction.emoji.name + Text.commands.fight.endIntroStart + actualUser.username + Text.commands.fight.attackSimple.ok[random] + Text.commands.fight.degatsIntro + degats + Text.commands.fight.degatsOutro; - } else { - ({defenderPower, attackerPower} = updatePlayerPower(attacker, actualUser, defenderPower, degats, attackerPower)); - messageAttaqueSimple = reaction.emoji.name + Text.commands.fight.endIntroStart + actualUser.username + Text.commands.fight.attackSimple.meh[random] + Text.commands.fight.degatsIntro + degats + Text.commands.fight.degatsOutro; - } - } else { - degats = 0; - messageAttaqueSimple = reaction.emoji.name + Text.commands.fight.endIntroStart + actualUser.username + Text.commands.fight.attackSimple.ko[random] + Text.commands.fight.degatsIntro + degats + Text.commands.fight.degatsOutro; - } - message.channel.send(messageAttaqueSimple); - return {defenderPower, attackerPower}; -} - -/** - * Allow to perform a quick attack - * @param {*} attackPower - * @param {*} player - The first player - * @param {*} opponentPlayer - * @param {*} actuelPlayer - * @param {*} defenderPower - * @param {*} attackerPower - * @param {*} attacker - The first player - * @param {*} actualUser - The user that is currently playing - * @param {*} reaction - * @param {*} message - */ -function quickAttack(attackPower, player, opponentPlayer, actuelPlayer, defenderPower, attackerPower, attacker, actualUser, reaction, message) { - const succes = Tools.generateRandomNumber(1, 100); - let powerchanger = 0.1; - if (opponentPlayer.speed > actuelPlayer.speed) { - if (succes <= 30) { // total success - powerchanger = 0.75; - } - } else { - if (succes <= 95) { // total success - powerchanger = 0.75; - } - } - attackPower = actuelPlayer.attack * powerchanger; - let messageAttaqueRapide = ''; - const defensePower = opponentPlayer.defense; - let degats = Math.round(attackPower - Math.round(defensePower * 0.3)); - const random = Tools.generateRandomNumber(1, 8); - if (degats > 0) { - if (degats >= actuelPlayer.attack - defensePower) { - ({defenderPower, attackerPower} = updatePlayerPower(attacker, actualUser, defenderPower, degats, attackerPower)); - messageAttaqueRapide = reaction.emoji.name + Text.commands.fight.endIntroStart + actualUser.username + Text.commands.fight.attackRapide.ok[random] + Text.commands.fight.degatsIntro + degats + Text.commands.fight.degatsOutro; - } else { - ({defenderPower, attackerPower} = updatePlayerPower(attacker, actualUser, defenderPower, degats, attackerPower)); - messageAttaqueRapide = reaction.emoji.name + Text.commands.fight.endIntroStart + actualUser.username + Text.commands.fight.attackRapide.meh[random] + Text.commands.fight.degatsIntro + degats + Text.commands.fight.degatsOutro; - } - } else { - degats = 0; - messageAttaqueRapide = reaction.emoji.name + Text.commands.fight.endIntroStart + actualUser.username + Text.commands.fight.attackRapide.ko[random] + Text.commands.fight.degatsIntro + degats + Text.commands.fight.degatsOutro; - } - message.channel.send(messageAttaqueRapide); - return {defenderPower, attackerPower}; -} - -/** - * - * @param {*} attacker - The first player - * @param {*} actualUser - The user that is currently playing - * @param {*} defenderPower - * @param {*} degats - * @param {*} attackerPower - */ -function updatePlayerPower(attacker, actualUser, defenderPower, degats, attackerPower) { - if (attacker == actualUser) { - defenderPower = defenderPower - degats; - } else { - attackerPower = attackerPower - degats; - } - return {defenderPower, attackerPower}; -} - -/** - * - * @param {*} message - * @param {*} actualUser - The user that is currently playing - */ -async function displayFightMenu(message, actualUser) { - const lastMessageFromBot = await message.channel.send(Text.commands.fight.menuStart + actualUser + Text.commands.fight.menuEnd); - await lastMessageFromBot.react('⚔'); - await lastMessageFromBot.react('🗡'); - await lastMessageFromBot.react('💣'); - await lastMessageFromBot.react('🛡'); - await lastMessageFromBot.react('🚀'); - return lastMessageFromBot; -} - -/** - * - * @param {*} message - * @param {*} user - */ -function displayErrorSkillMissing(message, user) { - message.channel.send(Text.commands.fight.errorEmoji + user + Text.commands.fight.notEnoughSkillError1 + DefaultValues.fight.minimalLevel + Text.commands.fight.notEnoughSkillError2); -} - -/** - * - * @param {*} actualUser - The user that is currently playing - * @param {*} attacker - The first player - * @param {*} defender - * @param {*} actuelPlayer - * @param {*} defenderPlayer - * @param {*} player - The first player - */ -function switchActiveUser(actualUser, attacker, defender, actuelPlayer, defenderPlayer, player) { - if (actualUser == attacker) { - actualUser = defender; - actuelPlayer = defenderPlayer; - opponentUser = attacker; - opponentPlayer = player; - } else { - actualUser = attacker; - actuelPlayer = player; - opponentUser = defender; - opponentPlayer = defenderPlayer; - } - return {actualUser, actuelPlayer, opponentUser, opponentPlayer}; -} - -/** - * - * @param {*} spamchecker - * @param {*} message - * @param {*} attacker - The first player - * @param {*} fightIsOpen - * @param {*} playerManager - * @param {*} player - The first player - */ -function cancelFightLaunch(spamchecker, message, attacker, fightIsOpen, playerManager, player) { - spamchecker++; - message.channel.send(Text.commands.fight.errorEmoji + attacker + Text.commands.fight.alreadyAttackerError); - if (spamchecker > 1) { - message.channel.send(Text.commands.fight.errorEmoji + attacker + Text.commands.fight.spamError); - fightIsOpen = false; - playerManager.setPlayerAsUnOccupied(player); - } - return {spamchecker, fightIsOpen}; -} - -/** - * - * @param {*} defender - * @param {*} message - * @param {*} fightIsOpen - * @param {*} attacker - The first player - * @param {*} playerManager - * @param {*} player - The first player - * @param {*} spamchecker - */ -function treatFightCancel(defender, message, fightIsOpen, attacker, playerManager, player, spamchecker) { - if (defender.id === message.author.id) { // le defenseur et l'attaquant sont la même personne - fightIsOpen = cancelFight(message, attacker, fightIsOpen, playerManager, player); - } else { // le defenseur n'est pas l'attaquant - if (spamchecker < 3) { - spamchecker++; - message.channel.send(Text.commands.fight.errorEmoji + defender + Text.commands.fight.fightNotCanceled); - } - } - return {fightIsOpen, spamchecker}; -} - - -/** - * Allow to cancel a fight - * @param {*} message - The message that caused the fight to be created - * @param {*} attacker - The attacker - * @param {Boolean} fightIsOpen - Is true if the fight has not already been canceled or launched - * @param {*} playerManager - The player manager - * @param {*} player - the attacker - */ -function cancelFight(message, attacker, fightIsOpen, playerManager, player) { - message.channel.send(Text.commands.fight.validEmoji + attacker + Text.commands.fight.fightCanceled); - fightIsOpen = false; - playerManager.setPlayerAsUnOccupied(player); - return fightIsOpen; -} - - -/** - * Check if the reaction recieved correspond to a fight cancel - * @param {*} reaction - The reaction that has been recieved - */ -function fightHasToBeCanceled(reaction) { - return reaction.emoji.name == '❌'; -} - -/** - * Allow to display the intro message that will taunch the fight - * @param {*} message - The message that caused the function to be called. Used to retrieve the channel of the message. - * @param {*} attacker - The attacker that asked for the fight - */ - -async function generateIntroMessage(message, attacker, chosenOpponent) { - if (chosenOpponent === undefined) { - return await message.channel.send(Text.commands.fight.startEmoji + attacker.username + Text.commands.fight.startIntro + Text.commands.fight.endIntro); - } else { - return await message.channel.send(Text.commands.fight.startEmoji + attacker.username + Text.commands.fight.startIntro + Text.commands.fight.introAgainstSomeone + '<@' + chosenOpponent.discordId + '>' + Text.commands.fight.endIntro); - } -} - -/** - * Allow to check if someone looses during the previous round - * @param {Number} attackerPower - The power of the attacker - * @param {Number} defenderPower - The power of his opponent - */ -function nobodyLooses(attackerPower, defenderPower) { - return attackerPower > 0 && defenderPower > 0; -} - -/** -* Check if the reaction recieved is valid -* @param {*} reaction - The reaction recieved -* @return {Boolean} - true is the reaction is correct -*/ -const reactionIsCorrect = function(reaction, user) { - let contains = false; - if (reaction.emoji.name == '⚔' && !user.bot) { - contains = true; - } - if (reaction.emoji.name == '❌' && !user.bot) { - contains = true; - } - return contains; -}; - -/** -* Check if the reaction recieved is valid -* @param {*} reaction - The reaction recieved -* @return {Boolean} - true is the reaction is correct -*/ -const reactionFightIsCorrect = function(reaction, user) { - let contains = false; - if (reaction.emoji.name == '⚔' && !user.bot) { - contains = true; - } - if (reaction.emoji.name == '🗡' && !user.bot) { - contains = true; - } - if (reaction.emoji.name == '💣' && !user.bot) { - contains = true; - } - if (reaction.emoji.name == '🛡' && !user.bot) { - contains = true; - } - if (reaction.emoji.name == '🚀' && !user.bot) { - contains = true; - } - return contains; -}; - -/** - * Allow to recover the asked player if needed - * @param {*} playerId - The asked id of the player - * @param {*} player - The player that is asked for - * @param {*} playerManager - The player manager - * @param {*} message - The message that initiate the command - - */ -async function getAskedPlayer(playerId, player, playerManager, message, args) { - if (isNaN(args[1])) { - try { - playerId = message.mentions.users.last().id; - } catch (err) { // the input is not a mention or a user rank - playerId = '0'; - } - } else { - playerId = await playerManager.getIdByRank(args[1]); - } - player = await playerManager.getPlayerById(playerId, message); - return player; -} - -/** - * check if the asked player is valid - * @param {*} player - The player that has been asked for - */ -function askedPlayerIsInvalid(player) { - return player.getEffect() == ':baby:'; -} - -/** - * check if the user ask for its own profile or the one of someone else - * @param {*} args - The args given by the user that made the command - */ -function askForAnotherPlayer(args) { - return args[1] != undefined; -} - -module.exports.FightCommand = fightCommand; diff --git a/src/commands_old/Sell.js b/src/commands_old/Sell.js deleted file mode 100644 index a0d7daa65..000000000 --- a/src/commands_old/Sell.js +++ /dev/null @@ -1,131 +0,0 @@ -const ItemManager = require('../core/ItemManager'); -const PlayerManager = require('../core/PlayerManager'); -const ObjectManager = require('../core/ObjectManager'); -const InventoryManager = require('../core/InventoryManager'); -const DefaultValues = require('data/text/DefaultValues'); -const Tools = require('../utils/Tools'); - -let Text; - - -/** - * Allow to sell the item that is stored in the backup position of the inventory of the player - * @param message - The message that caused the function to be called. Used to retrieve the author of the message. - */ -const sellCommand = async function(message, args, client, talkedRecently) { - Text = await Tools.chargeText(message); - if (talkedRecently.has(message.author.id)) { - message.channel.send(Text.commands.sell.cancelStart + message.author + Text.commands.shop.tooMuchShop); - } else { - talkedRecently.add(message.author.id); - const playerManager = new PlayerManager(); - const player = await playerManager.getCurrentPlayer(message); - const inventoryManager = new InventoryManager(); - const inventory = await inventoryManager.getCurrentInventory(message); - const objectManager = new ObjectManager(); - const object = objectManager.getObjectById(inventory.getBackupItemId()); - if (object.id == DefaultValues.inventory.object) { - const messageSell = generateErrorSellMessage(message); - message.channel.send(messageSell); - talkedRecently.delete(message.author.id); - } else { - generateConfirmation(message, object, player, inventory, inventoryManager, playerManager, talkedRecently); - } - } -}; -/** - * Returns a string containing the error sell message. - * @return {String} - A string containing the error sell message. - * @param message - The message that caused the function to be called. Used to retrieve the author of the message. - */ -const generateErrorSellMessage = function(message) { - return Text.commands.sell.noDebut + message.author.username + Text.commands.sell.noFin; -}; - -/** - * Allow to check if the user know what he is doing and to lanch the sell - * @param {*} message - The message that cause the event do be generated - * @param {*} object - The object that could be sold - * @param {*} player - The player that did the sell command - * @param {*} inventory - The inventory of the player - * @param {*} inventoryManager - The manager of the inventory - * @param {*} playerManager - The manager of the player - */ -async function generateConfirmation(message, object, player, inventory, inventoryManager, playerManager, talkedRecently) { - const confirmMessage = await generateConfirmMessage(message, object); - let confirmIsOpen = true; - - const msg = await displayConfirmMessage(message, confirmMessage); - const language = await Tools.detectLanguage(message); - const filter = (reaction, user) => { - return (reactionIsCorrect(reaction) && user.id === message.author.id); - }; - const collector = msg.createReactionCollector(filter, { - time: 120000, - }); - // execute this if a user answer to the event - collector.on('collect', (reaction) => { - if (confirmIsOpen) { - talkedRecently.delete(message.author.id); - if (reaction.emoji.name == '✅') { - playerManager.sellItem(player, object, false, message, language); - inventory.setBackupItemId(DefaultValues.inventory.object); - inventoryManager.updateInventory(inventory); - playerManager.updatePlayer(player); - } else { - message.channel.send(Text.commands.sell.cancelStart + message.author + Text.commands.sell.cancelEnd); - } - confirmIsOpen = false; - } - }); - // end of the time the user have to answer to the event - collector.on('end', () => { - if (confirmIsOpen) { - talkedRecently.delete(message.author.id); - message.channel.send(Text.commands.sell.cancelStart + message.author + Text.commands.sell.cancelEnd); - } - }); -} - - -/** - * send a confirmation and display reactions - * @param message - The message that caused the function to be called. Used to retrieve the author of the message. - * @param {*} confirmMessage - The string of the confirmation message - */ -const displayConfirmMessage = function(message, confirmMessage) { - return message.channel.send(confirmMessage).then((msg) => { - const valid = '✅'; - msg.react(valid); - const notValid = '❌'; - msg.react(notValid); - return msg; - }); -}; - -/** -* Check if the reaction recieved is valid -* @param {*} reaction - The reaction recieved -* @return {Boolean} - true is the reaction is correct -*/ -const reactionIsCorrect = function(reaction) { - let contains = false; - if (reaction.emoji.name == '✅' || reaction.emoji.name == '❌') { - contains = true; - } - return contains; -}; - - -/** - * Returns a string containing the error sell message. - * @return {String} - A string containing the error sell message. - * @param message - The message that caused the function to be called. Used to retrieve the author of the message. - */ -const generateConfirmMessage = async function(message, object) { - const value = object.getValue(); - const language = await Tools.detectLanguage(message); - return Text.commands.sell.confirmDebut + message.author.username + Text.commands.sell.confirmIntro + new ItemManager().getItemSimpleName(object, language) + Text.commands.sell.confirmMiddle + value + Text.commands.sell.confirmEnd; -}; - -module.exports.SellCommand = sellCommand; diff --git a/src/core/Fight.js b/src/core/Fight.js index 89721ba15..4bec87df1 100644 --- a/src/core/Fight.js +++ b/src/core/Fight.js @@ -360,7 +360,7 @@ class Fight { resMsg = 'notGood'; } const resultSection = JsonReader.commands.fight.getTranslation(this.language).actions.attacksResults[resMsg]; - msg += resultSection[randInt(0, resultSection.length - 1)]; + msg += resultSection[randInt(0, resultSection.length)]; await this.addActionMessage(format(msg, {emote: section.emote, player: player, attack: section.name}) + section.end[resMsg] + format(JsonReader.commands.fight.getTranslation(this.language).actions.damages, {damages: fightActionResult.damage})); diff --git a/src/core/Tools.js b/src/core/Tools.js index a2d24da43..18cf65f7b 100644 --- a/src/core/Tools.js +++ b/src/core/Tools.js @@ -230,7 +230,7 @@ global.format = (string, replacement) => { }; /** - * Generates a random int between min and max both included + * Generates a random int between min and max, max excluded * @param {Number} min * @param {Number} max * @return {number}