Rework battle commands

This commit is contained in:
Daniel Odendahl Jr
2018-10-09 21:19:09 +00:00
parent 01e5331dc4
commit 3b14bbcaf0
3 changed files with 14 additions and 14 deletions
+8 -8
View File
@@ -24,8 +24,8 @@ module.exports = class BattleCommand extends Command {
}
async run(msg, { opponent }) {
if (opponent.id === msg.author.id) return msg.reply('You may not fight yourself.');
if (this.battles.has(msg.channel.id)) return msg.reply('Only one fight may be occurring per channel.');
if (opponent.id === msg.author.id) return msg.reply('You may not battle yourself.');
if (this.battles.has(msg.channel.id)) return msg.reply('Only one battle may be occurring per channel.');
this.battles.set(msg.channel.id, new Battle(msg.author, opponent));
const battle = this.battles.get(msg.channel.id);
try {
@@ -39,21 +39,21 @@ module.exports = class BattleCommand extends Command {
}
while (!battle.winner) {
const choice = await battle.attacker.chooseAction(msg);
if (choice === 'fight') {
const damage = randomRange(battle.defender.guarding ? 5 : 20, battle.defender.guarding ? 20 : 50);
if (choice === 'attack') {
const damage = randomRange(battle.defender.guard ? 5 : 20, battle.defender.guard ? 20 : 50);
await msg.say(`${battle.attacker} deals **${damage}** damage!`);
battle.defender.dealDamage(damage);
battle.reset();
} else if (choice === 'guard') {
await msg.say(`${battle.attacker} guards!`);
} else if (choice === 'defend') {
await msg.say(`${battle.attacker} defends!`);
battle.attacker.changeGuard();
battle.reset(false);
} else if (choice === 'special') {
const miss = Math.floor(Math.random() * 3);
if (miss) {
await msg.say(`${battle.attacker}'s attack missed!`);
await msg.say(`${battle.attacker}'s special attack missed!`);
} else {
const damage = randomRange(battle.defender.guarding ? 50 : 100, battle.defender.guarding ? 100 : 200);
const damage = randomRange(battle.defender.guard ? 50 : 100, battle.defender.guard ? 100 : 200);
await msg.say(`${battle.attacker} deals **${damage}** damage!`);
battle.defender.dealDamage(damage);
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "93.1.4",
"version": "94.0.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {
+5 -5
View File
@@ -1,7 +1,7 @@
const { stripIndents } = require('common-tags');
const { list } = require('../../util/Util');
const choices = ['fight', 'guard', 'special', 'run'];
const botChoices = ['fight', 'guard', 'special'];
const choices = ['attack', 'defend', 'special', 'run'];
const botChoices = ['attack', 'defend', 'special'];
module.exports = class Battler {
constructor(battle, user) {
@@ -9,7 +9,7 @@ module.exports = class Battler {
this.user = user;
this.bot = user.bot;
this.hp = 500;
this.guarding = false;
this.guard = false;
}
async chooseAction(msg) {
@@ -34,8 +34,8 @@ module.exports = class Battler {
}
changeGuard() {
this.guarding = !this.guarding;
return this.guarding;
this.guard = !this.guard;
return this.guard;
}
forfeit() {