Fix Battle timeout

This commit is contained in:
Dragon Fire
2020-05-07 17:01:37 -04:00
parent 762e5de525
commit 418760a8cb
2 changed files with 5 additions and 5 deletions
+3 -5
View File
@@ -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.');
+2
View File
@@ -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;