mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-23 10:02:05 +02:00
Rework battle commands
This commit is contained in:
@@ -24,8 +24,8 @@ module.exports = class BattleCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async run(msg, { opponent }) {
|
async run(msg, { opponent }) {
|
||||||
if (opponent.id === msg.author.id) return msg.reply('You may not fight yourself.');
|
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 fight may be occurring per channel.');
|
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));
|
this.battles.set(msg.channel.id, new Battle(msg.author, opponent));
|
||||||
const battle = this.battles.get(msg.channel.id);
|
const battle = this.battles.get(msg.channel.id);
|
||||||
try {
|
try {
|
||||||
@@ -39,21 +39,21 @@ module.exports = class BattleCommand extends Command {
|
|||||||
}
|
}
|
||||||
while (!battle.winner) {
|
while (!battle.winner) {
|
||||||
const choice = await battle.attacker.chooseAction(msg);
|
const choice = await battle.attacker.chooseAction(msg);
|
||||||
if (choice === 'fight') {
|
if (choice === 'attack') {
|
||||||
const damage = randomRange(battle.defender.guarding ? 5 : 20, battle.defender.guarding ? 20 : 50);
|
const damage = randomRange(battle.defender.guard ? 5 : 20, battle.defender.guard ? 20 : 50);
|
||||||
await msg.say(`${battle.attacker} deals **${damage}** damage!`);
|
await msg.say(`${battle.attacker} deals **${damage}** damage!`);
|
||||||
battle.defender.dealDamage(damage);
|
battle.defender.dealDamage(damage);
|
||||||
battle.reset();
|
battle.reset();
|
||||||
} else if (choice === 'guard') {
|
} else if (choice === 'defend') {
|
||||||
await msg.say(`${battle.attacker} guards!`);
|
await msg.say(`${battle.attacker} defends!`);
|
||||||
battle.attacker.changeGuard();
|
battle.attacker.changeGuard();
|
||||||
battle.reset(false);
|
battle.reset(false);
|
||||||
} else if (choice === 'special') {
|
} else if (choice === 'special') {
|
||||||
const miss = Math.floor(Math.random() * 3);
|
const miss = Math.floor(Math.random() * 3);
|
||||||
if (miss) {
|
if (miss) {
|
||||||
await msg.say(`${battle.attacker}'s attack missed!`);
|
await msg.say(`${battle.attacker}'s special attack missed!`);
|
||||||
} else {
|
} 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!`);
|
await msg.say(`${battle.attacker} deals **${damage}** damage!`);
|
||||||
battle.defender.dealDamage(damage);
|
battle.defender.dealDamage(damage);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "93.1.4",
|
"version": "94.0.0",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Xiao.js",
|
"main": "Xiao.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const { stripIndents } = require('common-tags');
|
const { stripIndents } = require('common-tags');
|
||||||
const { list } = require('../../util/Util');
|
const { list } = require('../../util/Util');
|
||||||
const choices = ['fight', 'guard', 'special', 'run'];
|
const choices = ['attack', 'defend', 'special', 'run'];
|
||||||
const botChoices = ['fight', 'guard', 'special'];
|
const botChoices = ['attack', 'defend', 'special'];
|
||||||
|
|
||||||
module.exports = class Battler {
|
module.exports = class Battler {
|
||||||
constructor(battle, user) {
|
constructor(battle, user) {
|
||||||
@@ -9,7 +9,7 @@ module.exports = class Battler {
|
|||||||
this.user = user;
|
this.user = user;
|
||||||
this.bot = user.bot;
|
this.bot = user.bot;
|
||||||
this.hp = 500;
|
this.hp = 500;
|
||||||
this.guarding = false;
|
this.guard = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async chooseAction(msg) {
|
async chooseAction(msg) {
|
||||||
@@ -34,8 +34,8 @@ module.exports = class Battler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
changeGuard() {
|
changeGuard() {
|
||||||
this.guarding = !this.guarding;
|
this.guard = !this.guard;
|
||||||
return this.guarding;
|
return this.guard;
|
||||||
}
|
}
|
||||||
|
|
||||||
forfeit() {
|
forfeit() {
|
||||||
|
|||||||
Reference in New Issue
Block a user