From 5edae8d0972dfaefd39de7701a5f7e2942c6fb0a Mon Sep 17 00:00:00 2001 From: ION606 Date: Mon, 30 May 2022 20:37:15 +0300 Subject: [PATCH] Fixed the problem with the hp overwrite --- commands/db/battle.js | 2 +- commands/db/external_game_functions.js | 4 ++-- commands/db/game.js | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/commands/db/battle.js b/commands/db/battle.js index 33c5ef3..37a986f 100644 --- a/commands/db/battle.js +++ b/commands/db/battle.js @@ -45,7 +45,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: { hp :new_hp }}); //THIS DOES NOT WORK (OVERWRITES HPMP MAP WITH ONE VALUE) + other_dbo.updateOne({'equipped': {$exists: true}}, { $set: { 'hpmp.hp' :new_hp }}); //THIS DOES NOT WORK (OVERWRITES HPMP MAP WITH ONE VALUE) } }); diff --git a/commands/db/external_game_functions.js b/commands/db/external_game_functions.js index 0e03536..9cb0d44 100644 --- a/commands/db/external_game_functions.js +++ b/commands/db/external_game_functions.js @@ -22,7 +22,7 @@ function loseGame(user_dbo, xp_collection, message, bot = null) { //Update the player's xp addxp(message, user_dbo, Math.ceil((BASE.XP * doc.rank)/2),xp_collection) - user_dbo.updateOne({"game": {$exists: true}}, { $set: { game: null, opponent: null, state: STATE.IDLE, hp: doc.hpmp.maxhp, mp: doc.hpmp.maxmp }}); + user_dbo.updateOne({"game": {$exists: true}}, { $set: { game: null, opponent: null, state: STATE.IDLE, 'hpmp.hp': doc.hpmp.maxhp, 'hpmp.mp': doc.hpmp.maxmp }}); resolve(addbal); }); @@ -51,7 +51,7 @@ function winGame(client, bot, db, user_dbo, xp_collection, message) { //Update the player with xp - user_dbo.updateOne({"game": {$exists: true}}, { $set: { game: null, opponent: null, state: STATE.IDLE, xp: doc.xp + (BASE.XP * doc.rank), hp: doc.hpmp.maxhp, mp: doc.hpmp.maxmp }}); + user_dbo.updateOne({"game": {$exists: true}}, { $set: { game: null, opponent: null, state: STATE.IDLE, xp: doc.xp + (BASE.XP * doc.rank), 'hpmp.hp': doc.hpmp.maxhp, 'hpmp.mp': doc.hpmp.maxmp }}); message.channel.delete(); }); diff --git a/commands/db/game.js b/commands/db/game.js index ccf03b2..29266c2 100644 --- a/commands/db/game.js +++ b/commands/db/game.js @@ -117,14 +117,14 @@ function acceptIsValid(bot, other_discord, message, msg, tag_len) { function hpmp(message, command, dbo) { - throw 'THIS HAS NOT BEEN UPDATED WITH THE MOST RECENT VERSION OF THE MONGODB STRUCTURE!'; + // throw 'THIS HAS NOT BEEN UPDATED WITH THE MOST RECENT VERSION OF THE MONGODB STRUCTURE!'; if (command == 'hp') { dbo.find({"hp": {$exists: true}}).toArray(function(err, doc) { - return message.reply(`You have ${String(doc[0].hp)} hp left!`); + return message.reply(`You have ${String(doc[0].hpmp.hp)} hp left!`); }); } else if (command == 'mp') { dbo.find({"mp": {$exists: true}}).toArray(function(err, doc) { - return message.reply(`You have ${String(doc[0].hp)} mp left!`); + return message.reply(`You have ${String(doc[0].hpmp.hp)} mp left!`); }); } }