mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-21 05:54:33 +02:00
Improve Battle System
This commit is contained in:
+36
-14
@@ -39,12 +39,14 @@ module.exports = class BattleCommand extends Command {
|
|||||||
let oppoHP = 500;
|
let oppoHP = 500;
|
||||||
let userTurn = true;
|
let userTurn = true;
|
||||||
let guard = false;
|
let guard = false;
|
||||||
|
let userCure = false;
|
||||||
|
let oppoCure = false;
|
||||||
while (userHP > 0 && oppoHP > 0) {
|
while (userHP > 0 && oppoHP > 0) {
|
||||||
const username = userTurn ? msg.author.username : opponent.username;
|
const username = userTurn ? msg.author.username : opponent.username;
|
||||||
await msg.say(stripIndents`
|
await msg.say(stripIndents`
|
||||||
${username}, do you fight, guard, special, or run?
|
${username}, do you **fight**, **guard**, **special**, **cure** or **run**?
|
||||||
${username}: ${userTurn ? userHP : oppoHP} HP
|
**${msg.author.username}**: ${userHP}HP
|
||||||
${userTurn ? opponent.username : msg.author.username}: ${userTurn ? oppoHP : userHP} HP
|
**${opponent.username}**: ${oppoHP}HP
|
||||||
`);
|
`);
|
||||||
try {
|
try {
|
||||||
const turn = await msg.channel.awaitMessages(res => res.author.id === (userTurn ? msg.author.id : opponent.id), {
|
const turn = await msg.channel.awaitMessages(res => res.author.id === (userTurn ? msg.author.id : opponent.id), {
|
||||||
@@ -54,34 +56,54 @@ module.exports = class BattleCommand extends Command {
|
|||||||
});
|
});
|
||||||
const choice = turn.first().content.toLowerCase();
|
const choice = turn.first().content.toLowerCase();
|
||||||
if (choice === 'fight') {
|
if (choice === 'fight') {
|
||||||
const damage = Math.floor(Math.random() * (guard ? 50 : 100)) + 1;
|
const damage = Math.floor(Math.random() * (guard ? 25 : 100)) + 1;
|
||||||
await msg.say(`${username} deals ${damage} damage!`);
|
await msg.say(`${username} deals ${damage} damage!`);
|
||||||
if (userTurn) oppoHP = oppoHP - damage;
|
if (userTurn) {
|
||||||
else userHP = userHP - damage;
|
oppoHP = oppoHP - damage;
|
||||||
|
userTurn = false;
|
||||||
|
} else {
|
||||||
|
userHP = userHP - damage;
|
||||||
|
userTurn = true;
|
||||||
|
}
|
||||||
if (guard) guard = false;
|
if (guard) guard = false;
|
||||||
if (userTurn) userTurn = false;
|
|
||||||
else userTurn = true;
|
|
||||||
} else if (choice === 'guard') {
|
} else if (choice === 'guard') {
|
||||||
await msg.say(`${username} guards!`);
|
await msg.say(`${username} guards!`);
|
||||||
guard = true;
|
guard = true;
|
||||||
if (userTurn) userTurn = false;
|
if (userTurn) userTurn = false;
|
||||||
else userTurn = true;
|
else userTurn = true;
|
||||||
} else if (choice === 'special') {
|
} else if (choice === 'special') {
|
||||||
const hit = Math.floor(Math.random() * 2) + 1;
|
const hit = Math.floor(Math.random() * 4) + 1;
|
||||||
if (hit === 1) {
|
if (hit === 1) {
|
||||||
const damage = Math.floor(Math.random() * (guard ? 150 : 300)) + 1;
|
const damage = Math.floor(Math.random() * ((guard ? 300 : 150) - 100 + 1) + 100);
|
||||||
await msg.say(`${username} deals ${damage} damage!`);
|
await msg.say(`${username} deals ${damage} damage!`);
|
||||||
if (userTurn) oppoHP = oppoHP - damage;
|
if (userTurn) {
|
||||||
else userHP = userHP - damage;
|
oppoHP = oppoHP - damage;
|
||||||
|
userTurn = false;
|
||||||
|
} else {
|
||||||
|
userHP = userHP - damage;
|
||||||
|
userTurn = true;
|
||||||
|
}
|
||||||
if (guard) guard = false;
|
if (guard) guard = false;
|
||||||
if (userTurn) userTurn = false;
|
|
||||||
else userTurn = true;
|
|
||||||
} else {
|
} else {
|
||||||
await msg.say('It missed!');
|
await msg.say('It missed!');
|
||||||
if (guard) guard = false;
|
if (guard) guard = false;
|
||||||
if (userTurn) userTurn = false;
|
if (userTurn) userTurn = false;
|
||||||
else userTurn = true;
|
else userTurn = true;
|
||||||
}
|
}
|
||||||
|
} else if (choice === 'cure') {
|
||||||
|
if (userTurn ? userCure : oppoCure) {
|
||||||
|
await msg.say(`${username} regains 250HP!`);
|
||||||
|
if (userTurn) {
|
||||||
|
userHP = userHP + 250;
|
||||||
|
userCure = true;
|
||||||
|
userTurn = false;
|
||||||
|
} else {
|
||||||
|
oppoHP = oppoHP + 250;
|
||||||
|
oppoCure = true;
|
||||||
|
userTurn = true;
|
||||||
|
}
|
||||||
|
if (guard) guard = false;
|
||||||
|
} else await msg.say('You have already cured!');
|
||||||
} else if (choice === 'run') {
|
} else if (choice === 'run') {
|
||||||
await msg.say(`${username} flees!`);
|
await msg.say(`${username} flees!`);
|
||||||
if (userTurn) userHP = 0;
|
if (userTurn) userHP = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user