mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-12 00:04:48 +02:00
Fix Battle timeout
This commit is contained in:
@@ -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.');
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user