A few bugfixes

This commit is contained in:
2018-10-29 18:21:06 +11:00
parent a3886fc863
commit 02a52f0b07
4 changed files with 35 additions and 13 deletions

View File

@@ -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");
});
});

View File

@@ -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);

View File

@@ -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";
}

View File

@@ -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,