From f524f42e9ccaa2b1debc577d66fe62dc732e85a0 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Wed, 10 Oct 2018 15:01:29 +0000 Subject: [PATCH] Fix bot choices --- structures/battle/Battler.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/structures/battle/Battler.js b/structures/battle/Battler.js index 6c0dc402..3e62d597 100644 --- a/structures/battle/Battler.js +++ b/structures/battle/Battler.js @@ -1,7 +1,6 @@ const { stripIndents } = require('common-tags'); const { list } = require('../../util/Util'); const choices = ['attack', 'defend', 'special', 'cure', 'run']; -const botChoices = ['attack', 'defend', 'special', 'cure']; module.exports = class Battler { constructor(battle, user) { @@ -14,7 +13,12 @@ module.exports = class Battler { } async chooseAction(msg) { - if (this.bot) return botChoices[Math.floor(Math.random() * botChoices.length)]; + if (this.bot) { + const botChoices = ['attack', 'defend']; + if (this.canSpecial) botChoices.push('special'); + if (this.canHeal) botChoices.push('cure'); + return botChoices[Math.floor(Math.random() * botChoices.length)]; + } let content = stripIndents` ${this}, do you ${list(choices.map(choice => `**${choice}**`), 'or')}? You have **${this.mp}** MP. **${this.battle.user.user.tag}:** ${this.battle.user.hp} HP @@ -27,7 +31,7 @@ module.exports = class Battler { const filter = res => { const choice = res.content.toLowerCase(); if (res.author.id === this.user.id && choices.includes(choice)) { - if ((choice === 'special' && this.mp < 50) || (choice === 'cure' && this.mp <= 0)) { + if ((choice === 'special' && !this.canSpecial) || (choice === 'cure' && !this.canHeal)) { msg.say('You don\'t have enough MP for that!').catch(() => null); return false; } @@ -53,6 +57,14 @@ module.exports = class Battler { return this.hp; } + get canHeal() { + return this.mp > 0; + } + + get canSpecial() { + return this.mp >= 50; + } + useMP(amount) { this.mp -= amount; return this.mp;