mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Rework battle commands
This commit is contained in:
@@ -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
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "93.1.4",
|
||||
"version": "94.0.0",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user