Added the framework for the 'game battle --> item' command, fixed the 'buy' command, changed the currency symbol, added the 'game equip' command, added extra fields to the 'items --> wepaons category

This commit is contained in:
ION606
2022-06-17 16:41:02 +03:00
parent eb828a59c0
commit 388c65c6dc
8 changed files with 328 additions and 218 deletions
+63 -16
View File
@@ -3,6 +3,7 @@ const { MessageActionRow, MessageButton, MessageSelectMenu } = require('discord.
const { STATE } = require('./econ');
const { winGame, getCustomEmoji } = require('./external_game_functions.js');
const { changeTurn } = require('../turnManager.js');
const { default: mongoose } = require('mongoose');
function postActionBar(thread, user_dbo) {
@@ -39,7 +40,7 @@ function attack_special() {
//Bow special phrase: Σ>―(´・ω・`)→
function attack(client, user_dbo, other_dbo, bot, thread, command, mongouri, items, xp_collection, interaction) {
function attack(client, user_dbo, other_dbo, bot, thread, xp_collection, interaction) {
//Get the weapon
user_dbo.find({'equipped': {$exists: true}}).toArray(function(err, docs) {
const doc = docs[0];
@@ -53,7 +54,7 @@ function attack(client, user_dbo, other_dbo, bot, thread, command, mongouri, ite
dmg = doc.rank;
} else {
dmg = (doc.rank - 1) + Math.round(weapon.cost/5);
}
}
other_dbo.find({'equipped': {$exists: true}}).toArray(function (err, docs) {
const odoc = docs[0];
@@ -71,7 +72,7 @@ function attack(client, user_dbo, other_dbo, bot, thread, command, mongouri, ite
if (new_hp <= 0) {
winGame(client, bot, client.db(user_dbo.s.namespace.db), user_dbo, xp_collection, interaction.message);
} else {
other_dbo.updateOne({'equipped': {$exists: true}}, { $set: { 'hpmp.hp' :new_hp }});
other_dbo.updateOne({'equipped': {$exists: true}}, { $set: { 'hpmp.hp' :new_hp, state: STATE.FIGHTING }});
}
});
@@ -85,13 +86,13 @@ function attack(client, user_dbo, other_dbo, bot, thread, command, mongouri, ite
}
/**
* Called by "item"
*/
async function heal(interaction, client, user_dbo, bot, thread, command, mongouri, items) {
if (interaction.message.content.toLowerCase().indexOf('Which item would you like to use?') != -1) {
// The person picked out an item
//I think this is unecessary
}
//Get the 'healing' items (stored in "{item}: num" format)
user_dbo.find({'equipped': {$exists: true}}).toArray(async function(err, docs) {
const doc = docs[0];
@@ -100,8 +101,8 @@ async function heal(interaction, client, user_dbo, bot, thread, command, mongour
if (JSON.stringify(items) == '[]') {
postActionBar(thread, user_dbo);
return interaction.editReply("You don't have any items!");
interaction.editReply("You don't have any items!");
return postActionBar(thread, user_dbo);
} else { console.log(JSON.stringify(items))}
var itemlist = [];
@@ -142,22 +143,66 @@ async function heal(interaction, client, user_dbo, bot, thread, command, mongour
//Gets items by section/name, reacts with them to the message, when pressed, trigger a response
function item() {
throw 'THE "ITEM" COMMAND HAS NOT BEEN SET UP YET!';
function presentItems(interaction, client, user_dbo, bot, thread) {
// throw 'THE "ITEM" COMMAND HAS NOT BEEN SET UP YET!';
user_dbo.find({'equipped': {$exists: true}}).toArray(async function(err, docs) {
const doc = docs[0];
const items = doc.equipped.items;
// const items = rawitems.filter(function(f) { return (f.sect.toLowerCase() == 'hp') });
if (JSON.stringify(items) == '[]' || JSON.stringify(items) == '{}') {
interaction.editReply("You don't have any items!");
return postActionBar(thread, user_dbo);
} else { console.log(JSON.stringify(items))}
var itemlist = [];
items.forEach(function(item) {
let n = item.name;
itemlist.push({label: n, description: `${item.num} equipped!`, value: `${n}`});
});
//Find something to heal with
const row = new MessageActionRow()
.addComponents(
new MessageSelectMenu()
.setCustomId(`${interaction.user.id}|heal`)
.setPlaceholder('Nothing selected')
.addOptions(itemlist)
);
await interaction.editReply({ content: 'Please choose a health potion!', components: [row] });
});
}
function defend(user_dbo, bot, thread, command, mongouri, items) {
function defend(client, interaction, user_dbo, bot, thread) {
user_dbo.find({'equipped': {$exists: true}}).toArray(function(err, docs) {
const doc = docs[0];
const all_weapons = doc.get('weapons');
const shield = all_weapons.get('secondary');
//They don't have a shield
if (shield == undefined) {
thread.send("You don't have a shield equipped!");
return postActionBar(thread, user_dbo);
}
//Change state
user_dbo.updateOne({state: {$exists: true}}, {$set: {state: STATE.DEFENDING}});
})
changeTurn(client, bot, interaction);
postActionBar(thread, user_dbo);
}
function usePotion(interaction, client, user_dbo, bot, thread, command, mongouri) {
function usePotion(interaction, client, user_dbo, bot, thread) {
const name = interaction.values[0];
const cursor = user_dbo.find({'equipped.items': {$exists: true}});
@@ -176,7 +221,7 @@ function usePotion(interaction, client, user_dbo, bot, thread, command, mongouri
//If there's more than 1, subtract 1
if (items.num > 1) { items.num -= 1; allitems[ind] = items; }
else { allitems.splice(ind, 1) }
user_dbo.updateOne({'equipped.items': {$exists: true}}, {$set: {'equipped.items': allitems}});
})
@@ -196,14 +241,16 @@ async function handle(client, user_dbo, other_dbo, bot, thread, command, mongour
if (command == 'initalize') {
return postActionBar(thread, user_dbo);
} else if (command == 'attack') {
attack(client, user_dbo, other_dbo, bot, thread, command, mongouri, items, xp_collection, interaction);
attack(client, user_dbo, other_dbo, bot, thread, xp_collection, interaction);
postActionBar(thread, other_dbo);
} else if (command == 'items') {
item();
presentItems(interaction, client, user_dbo, bot, thread);
} else if (command == 'heal') {
heal(interaction, client, user_dbo, bot, thread, command, mongouri, items); //.then(() => {postActionBar(thread, other_dbo)});
} else if (command == 'usepotion') {
usePotion(interaction, client, user_dbo, bot, thread, command, mongouri);
usePotion(interaction, client, user_dbo, bot, thread);
} else if (command == 'defend') {
defend(client, interaction, user_dbo, bot, thread);
}
// initiate(user_dbo, other_dbo, command, message);