diff --git a/commands/games-mp/battle.js b/commands/games-mp/battle.js index ac5585c3..521a0247 100644 --- a/commands/games-mp/battle.js +++ b/commands/games-mp/battle.js @@ -36,7 +36,6 @@ module.exports = class BattleCommand extends Command { return msg.say('Looks like they declined...'); } } - let lastTurnTimeout = false; while (!battle.winner) { const choice = await battle.attacker.chooseAction(msg); if (choice === 'attack') { @@ -81,16 +80,15 @@ module.exports = class BattleCommand extends Command { } else if (choice === 'failed:time') { await msg.say(`Time's up, ${battle.attacker}!`); battle.reset(); - if (lastTurnTimeout) { - battle.winner = 'time'; + if (battle.lastTurnTimeout) { break; } else { - lastTurnTimeout = true; + battle.lastTurnTimeout = true; } } else { await msg.say('I do not understand what you want to do.'); } - if (choice !== 'failed:time' && lastTurnTimeout) lastTurnTimeout = false; + if (choice !== 'failed:time' && battle.lastTurnTimeout) battle.lastTurnTimeout = false; } this.client.games.delete(msg.channel.id); if (battle.winner === 'time') return msg.say('Game ended due to inactivity.'); diff --git a/structures/battle/Battle.js b/structures/battle/Battle.js index e66e11a9..271de3a3 100644 --- a/structures/battle/Battle.js +++ b/structures/battle/Battle.js @@ -6,6 +6,7 @@ module.exports = class Battle { this.opponent = new Battler(this, opponent); this.userTurn = false; this.turn = 1; + this.lastTurnTimeout = false; } get attacker() { @@ -25,6 +26,7 @@ module.exports = class Battle { } get winner() { + if (this.lastTurnTimeout) return 'time'; if (this.user.hp <= 0) return this.opponent; if (this.opponent.hp <= 0) return this.user; return null;