From 02a52f0b07b84c540ef75319de6ab82f448811b7 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 29 Oct 2018 18:21:06 +1100 Subject: [PATCH] A few bugfixes --- ADAM/adam.js | 2 +- ADAM/core.js | 18 ++++++++++------- SERVER_City/city.js | 26 +++++++++++++++++++++---- SERVER_City/scripts/create_database.sql | 2 +- 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/ADAM/adam.js b/ADAM/adam.js index efd0071..cee21e4 100644 --- a/ADAM/adam.js +++ b/ADAM/adam.js @@ -63,7 +63,7 @@ client.on('ready', async () => { //ADAM updates stamina (1) and health by 1% every 2 min. cron.schedule('*/2 * * * *', () => { //TODO: move this to Mori - console.log('Updating STAMINA every 2 min.'); +//s console.log('Updating STAMINA every 2 min.'); shared.SendServerData("updateStamina"); }); }); diff --git a/ADAM/core.js b/ADAM/core.js index f1a9e81..4fc1f6b 100644 --- a/ADAM/core.js +++ b/ADAM/core.js @@ -64,7 +64,7 @@ exports.ProcessFactionChangeAttempt = function(client, message, factionRole, dia shared.ChangeFaction(client, factionRole, message.channel, message.member, handleResponse); } -//ProcessStatsCommand +//ProcessCheckinCommand //client - discord.js client //member - discord.js member //channel - discord.js channel @@ -82,7 +82,7 @@ exports.ProcessCheckinCommand = function(client, member, channel, dialog) { dataRequest.OnServerData("checkin", handleResponse, member.user.id); //ID of the person who checked in TODO: username too } -//ProcessStatsCommand +//ProcessGiveCommand //client - discord.js client //message - discord.js message //args - arguments to the give command @@ -144,9 +144,11 @@ exports.ProcessGiveCommand = function(client, message, args, dialog) { //channel - discord.js channel //dialog - dialog function exports.ProcessStatsCommand = function(client, member, channel, dialog) { - exports.HandleLevelUp(client, member, channel, dialog); - exports.GetStats(member.user, (stats) => { - exports.PrintStats(client, member, channel, stats); + exports.HandleLevelUp(client, member, channel, dialog, () => { + //BUGFIX: this code is in a next function to resolve the stats display bug + exports.GetStats(member.user, (stats) => { + exports.PrintStats(client, member, channel, stats); + }); }); } @@ -208,7 +210,7 @@ exports.PrintStats = function(client, member, channel, stats) { //member - discord.js member //channel - discord.js channel //dialog - dialog function -exports.HandleLevelUp = function(client, member, channel, dialog) { +exports.HandleLevelUp = function(client, member, channel, dialog, next) { //handle member strings if (typeof(member) === "string") { //TODO: fold these into their own functions EVERYWHERE. //get the member @@ -226,11 +228,13 @@ exports.HandleLevelUp = function(client, member, channel, dialog) { //handle levelling up if (response === "levelUp" || response === "RankUp") { if (level >= process.env.RANK_3_THRESHOLD) { - shared.SendPublicMessage(client, member.user, channel, dialog("levelUpCap", dialog("levelUpCapRemark"), level)); + shared.SendPublicMessage(client, member.user, channel, dialog("levelUpCap", dialog("levelUpCapRemark"), process.env.RANK_3_THRESHOLD)); } else { shared.SendPublicMessage(client, member.user, channel, dialog("LevelUp", dialog("levelUpRemark"), level, upgradePoints)); } } + + if (next) next(); //BUGFIX } shared.LevelUp(client, member, handleResponse); diff --git a/SERVER_City/city.js b/SERVER_City/city.js index 986f6b2..51fa6c5 100644 --- a/SERVER_City/city.js +++ b/SERVER_City/city.js @@ -61,7 +61,7 @@ async function handleUpdateStamina({ userID, data }) { let query = "UPDATE users SET stamina = stamina + 1 WHERE stamina < maxStamina;"; dbConnection.query(query, (err, result) => { if (err) throw err; - console.log("updated stamina for all users"); +// console.log("updated stamina for all users"); }); }; @@ -257,6 +257,24 @@ async function handleLevelUp({ data }, fn) { return fn("none", result[0].level, result[0].upgradePoints); } + //handle the level cap + if (newLevel >= process.env.RANK_3_THRESHOLD) { + //update the level, add lootbox + //TODO: add lootbox item + let query = `UPDATE users SET level = ${newLevel} WHERE userID='${data[0]}' LIMIT 1;`; + return dbConnection.query(query, (err, result) => { + if (err) throw err; + + //finally, pass the level and upgrade points to the client + let query = `SELECT level, upgradePoints FROM users WHERE userID='${data[0]}' LIMIT 1;`; + return dbConnection.query(query, (err, result) => { + if (err) throw err; + dbLog(data[0], "level max", `level: ${result[0].level}, upgrade points: ${result[0].upgradePoints}, lootboxes: ???`); + return fn("levelUp", result[0].level, result[0].upgradePoints); + }); + }); + } + //update the level and the upgrade points let query = `UPDATE users SET level = ${newLevel}, upgradePoints = upgradePoints + ${newLevel - result[0].level} WHERE userID='${data[0]}' LIMIT 1;`; return dbConnection.query(query, (err, result) => { @@ -310,12 +328,12 @@ function calculateTimeAgo(seconds) { } if (seconds < 60 * 60) { - return "just this hour"; + return "this hour"; } if (seconds < 60 * 60 * 24) { - return "just today"; + return "today"; } - return "just recently"; + return "recently"; } \ No newline at end of file diff --git a/SERVER_City/scripts/create_database.sql b/SERVER_City/scripts/create_database.sql index a54a7dd..c741a29 100644 --- a/SERVER_City/scripts/create_database.sql +++ b/SERVER_City/scripts/create_database.sql @@ -18,7 +18,7 @@ CREATE TABLE IF NOT EXISTS users ( faction bigint, factionChanged DATETIME NULL, - level int NOT NULL DEFAULT 1, + level int NOT NULL DEFAULT 0, experience int NOT NULL DEFAULT 0, maxHealth int NOT NULL DEFAULT 100,