Battle improvements (MP system, cure)

This commit is contained in:
Daniel Odendahl Jr
2018-10-10 14:56:04 +00:00
parent 7c9bf3842d
commit b52f698498
4 changed files with 42 additions and 9 deletions
+7 -1
View File
@@ -49,7 +49,7 @@ module.exports = class BattleCommand extends Command {
battle.attacker.changeGuard();
battle.reset(false);
} else if (choice === 'special') {
const miss = Math.floor(Math.random() * 3);
const miss = Math.floor(Math.random() * 4);
if (miss) {
await msg.say(`${battle.attacker}'s special attack missed!`);
} else {
@@ -57,6 +57,12 @@ module.exports = class BattleCommand extends Command {
await msg.say(`${battle.attacker} deals **${damage}** damage!`);
battle.defender.dealDamage(damage);
}
battle.attacker.useMP(50);
battle.reset();
} else if (choice === 'cure') {
await msg.say(`${battle.attacker} heals **${battle.attacker.mp}** HP!`);
battle.attacker.heal(battle.attacker.mp);
battle.attacker.useMP(battle.attacker.mp);
battle.reset();
} else if (choice === 'run') {
await msg.say(`${battle.attacker} flees!`);
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "94.0.0",
"version": "94.0.1",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {
+3 -1
View File
@@ -5,6 +5,7 @@ module.exports = class Battle {
this.user = new Battler(this, user);
this.opponent = new Battler(this, opponent);
this.userTurn = false;
this.turn = 1;
}
get attacker() {
@@ -19,7 +20,8 @@ module.exports = class Battle {
if (changeGuard && this.user.guard) this.user.changeGuard();
if (changeGuard && this.opponent.guard) this.opponent.changeGuard();
this.userTurn = !this.userTurn;
return null;
this.turn++;
return this.turn;
}
get winner() {
+31 -6
View File
@@ -1,7 +1,7 @@
const { stripIndents } = require('common-tags');
const { list } = require('../../util/Util');
const choices = ['attack', 'defend', 'special', 'run'];
const botChoices = ['attack', 'defend', 'special'];
const choices = ['attack', 'defend', 'special', 'cure', 'run'];
const botChoices = ['attack', 'defend', 'special', 'cure'];
module.exports = class Battler {
constructor(battle, user) {
@@ -9,17 +9,32 @@ module.exports = class Battler {
this.user = user;
this.bot = user.bot;
this.hp = 500;
this.mp = 500;
this.guard = false;
}
async chooseAction(msg) {
if (this.bot) return botChoices[Math.floor(Math.random() * botChoices.length)];
await msg.say(stripIndents`
${this}, do you ${list(choices.map(choice => `**${choice}**`), 'or')}?
let content = stripIndents`
${this}, do you ${list(choices.map(choice => `**${choice}**`), 'or')}? You have **${this.mp}** MP.
**${this.battle.user.user.tag}:** ${this.battle.user.hp} HP
**${this.battle.opponent.user.tag}:** ${this.battle.opponent.hp} HP
`);
const filter = res => res.author.id === this.user.id && choices.includes(res.content.toLowerCase());
`;
if (this.battle.turn === 1 || this.battle.turn === 2) {
content += '\n\n_Special uses 50 MP whether or not it hits. Cure uses all remaining MP, and heals that amount._';
}
await msg.say(content);
const filter = res => {
const choice = res.content.toLowerCase();
if (res.author.id === this.user.id && choices.includes(choice)) {
if ((choice === 'special' && this.mp < 50) || (choice === 'cure' && this.mp <= 0)) {
msg.say('You don\'t have enough MP for that!').catch(() => null);
return false;
}
return true;
}
return false;
};
const turn = await msg.channel.awaitMessages(filter, {
max: 1,
time: 30000
@@ -33,6 +48,16 @@ module.exports = class Battler {
return this.hp;
}
heal(amount) {
this.hp += amount;
return this.hp;
}
useMP(amount) {
this.mp -= amount;
return this.mp;
}
changeGuard() {
this.guard = !this.guard;
return this.guard;