Fixed the problem with the hp overwrite

This commit is contained in:
ION606
2022-05-30 20:37:15 +03:00
parent 65f4de28ed
commit 5edae8d097
3 changed files with 6 additions and 6 deletions
+1 -1
View File
@@ -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)
}
});
+2 -2
View File
@@ -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();
});
+3 -3
View File
@@ -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!`);
});
}
}