mirror of
https://github.com/Ratstail91/SANCTUM.git
synced 2025-11-28 18:14:28 +11:00
Implemented upgrades
This commit is contained in:
@@ -111,7 +111,7 @@ function printUpgrades(user, channel) {
|
|||||||
.setColor(client.guilds.get(process.env.SANCTUM_ID).roles.find(role => role.name === "NPC").color) //NOTE: probably a better way to do this
|
.setColor(client.guilds.get(process.env.SANCTUM_ID).roles.find(role => role.name === "NPC").color) //NOTE: probably a better way to do this
|
||||||
.setTitle("Nanotech Upgrades")
|
.setTitle("Nanotech Upgrades")
|
||||||
.setDescription(dialog("upgradeText"))
|
.setDescription(dialog("upgradeText"))
|
||||||
.setFooter(`${user.username}, you have ${stats.wallet} crystals. Use !upgrade [OPTION] to buy.`); //TODO: move this to dialog?
|
.setFooter(`${user.username}, you have ${stats.upgradePoints} cannisters. Use !upgrade [OPTION] to upgrade.`); //TODO: move this to dialog?
|
||||||
|
|
||||||
shared.SendPublicMessage(client, user, channel, dialog("upgradeHeading"));
|
shared.SendPublicMessage(client, user, channel, dialog("upgradeHeading"));
|
||||||
channel.send({ embed });
|
channel.send({ embed });
|
||||||
@@ -120,6 +120,36 @@ function printUpgrades(user, channel) {
|
|||||||
shared.OnServerData("userStats", handleResponse, user.id);
|
shared.OnServerData("userStats", handleResponse, user.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function processUpgradeCommand(uset, channel, args) {
|
function processUpgradeCommand(user, channel, args) {
|
||||||
//TODO
|
//parse the stat to upgrade
|
||||||
|
let statToUpgrade;
|
||||||
|
switch(String(args[0]).toLowerCase()) {
|
||||||
|
case "str":
|
||||||
|
case "strength":
|
||||||
|
statToUpgrade = "strength";
|
||||||
|
break;
|
||||||
|
case "spd":
|
||||||
|
case "speed":
|
||||||
|
statToUpgrade = "speed";
|
||||||
|
break;
|
||||||
|
case "stam":
|
||||||
|
case "stamina":
|
||||||
|
statToUpgrade = "stamina";
|
||||||
|
break;
|
||||||
|
case "hp":
|
||||||
|
case "health":
|
||||||
|
statToUpgrade = "health";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof(statToUpgrade) === "undefined") {
|
||||||
|
shared.SendPublicMessage(client, user, channel, dialog("upgradeParseError"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let handleResponse = function(response, suffix) {
|
||||||
|
shared.SendPublicMessage(client, user, channel, dialog(response, statToUpgrade, suffix));
|
||||||
|
}
|
||||||
|
|
||||||
|
shared.OnServerData("upgrade", handleResponse, user.id, statToUpgrade);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
{
|
{
|
||||||
"upgradeHeading": "Hey buddy! Here's what we can upgrade ASAP!",
|
"upgradeHeading": "Hey buddy! Here's what we can upgrade ASAP!",
|
||||||
|
|
||||||
"upgradeText": "STR - :cannister: **1**\n```Permanently upgrades your Strength by 1, so you can hit them Ravagers harder.```\nSPD - :cannister: **1**\n```Permanently upgrades your Speed by 1, so you can get hit less in battle.```\nSTAM - :cannister: **1**\n```Permanently upgrades your Max Stamina by 1, so you can hit more Ravagers.```\nHP - :cannister: **1**\n```Permanently upgrades your Max HP by 10, so you can can take those beatings like a champ.```",
|
"upgradeText": "STR - :cannister: **1**\n```Permanently upgrades your Strength by 1, so you can hit them Ravagers harder.```\nSPD - :cannister: **1**\n```Permanently upgrades your Speed by 1, so you can get hit less in battle.```\nSTAM - :cannister: **1**\n```Permanently upgrades your Max Stamina by 1, so you can hit more Ravagers.```\nHP - :cannister: **1**\n```Permanently upgrades your Max HP by 10, so you can take those beatings like a champ.```",
|
||||||
|
|
||||||
|
"upgradeSuccess": "Sweet! I used your Nanotech Cannister to upgrade your **{1}** by {2}!",
|
||||||
|
"upgradeFailure": "Sorry, no can do right now. Come back later though, ok?",
|
||||||
|
"upgradeNotEnoughPoints": "Hey now, you don't have that many cannisters.",
|
||||||
|
"upgradeParseError": "Believe me, I wish I could upgrade things like that.",
|
||||||
|
|
||||||
"noResult": "I have no idea what you just said."
|
"noResult": "I have no idea what you just said."
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ io.on("connection", async (socket) => {
|
|||||||
socket.on("updateStamina", handleUpdateStamina);
|
socket.on("updateStamina", handleUpdateStamina);
|
||||||
socket.on("conversion", handleConversion);
|
socket.on("conversion", handleConversion);
|
||||||
socket.on("checkin", handleCheckin);
|
socket.on("checkin", handleCheckin);
|
||||||
socket.on("wallet", handleWallet); //TODO: server ping from ADAM
|
socket.on("wallet", handleWallet);
|
||||||
socket.on("transfer", handleTransfer);
|
socket.on("transfer", handleTransfer);
|
||||||
socket.on("userStats", handleUserStats);
|
socket.on("userStats", handleUserStats);
|
||||||
socket.on("addXP", handleAddXP);
|
socket.on("addXP", handleAddXP);
|
||||||
@@ -54,6 +54,7 @@ io.on("connection", async (socket) => {
|
|||||||
socket.on("reviveAll", handleReviveAll);
|
socket.on("reviveAll", handleReviveAll);
|
||||||
socket.on("revive", handleRevive);
|
socket.on("revive", handleRevive);
|
||||||
socket.on("heal", handleHeal);
|
socket.on("heal", handleHeal);
|
||||||
|
socket.on("upgrade", handleUpgrade);
|
||||||
});
|
});
|
||||||
|
|
||||||
//listen
|
//listen
|
||||||
@@ -390,6 +391,48 @@ function innerHeal(data, fn, result, logType = "unknown") {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleUpgrade({ data }, fn) {
|
||||||
|
console.log("received an upgrade request...");
|
||||||
|
//data[0] = user ID
|
||||||
|
//data[1] = statToUpgrade
|
||||||
|
|
||||||
|
//fn parameters: ["upgradeSuccess", "upgradeFailure", "upgradeNotEnoughPoints"], suffix
|
||||||
|
|
||||||
|
//check the upgrade points
|
||||||
|
let query = "SELECT upgradePoints FROM users WHERE userID = ? LIMIT 1;";
|
||||||
|
return dbConnection.query(query, [data[0]], (err, result) => {
|
||||||
|
if (err) throw err;
|
||||||
|
|
||||||
|
if (result[0].upgradePoints == 0) {
|
||||||
|
return fn("upgradeNotEnoughPoints");
|
||||||
|
}
|
||||||
|
|
||||||
|
//determine the upgrade query
|
||||||
|
let query = "UPDATE users SET ";
|
||||||
|
switch(data[1]) {
|
||||||
|
case "strength":
|
||||||
|
query += "strength = strength + 1, ";
|
||||||
|
break;
|
||||||
|
case "speed":
|
||||||
|
query += "speed = speed + 1, ";
|
||||||
|
break;
|
||||||
|
case "stamina":
|
||||||
|
query += "maxStamina = maxStamina + 1, stamina = stamina + 1, ";
|
||||||
|
break;
|
||||||
|
case "health":
|
||||||
|
query += "maxHealth = maxHealth + 10, health = health + 10, ";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
query += "upgradePoints = upgradePoints - 1 WHERE userID = ? LIMIT 1;";
|
||||||
|
|
||||||
|
return dbConnection.query(query, data[0], (err, result) => {
|
||||||
|
if (err) throw err;
|
||||||
|
dbLog(data[0], "upgrade", "upgrade " + data[1]);//TODO: better log
|
||||||
|
return fn("upgradeSuccess", data[1] === "health" ? "10 points" : "1 point");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//utility functions
|
//utility functions
|
||||||
function calculateLevel(experience) {
|
function calculateLevel(experience) {
|
||||||
const levelBase = 1.2;
|
const levelBase = 1.2;
|
||||||
|
|||||||
Reference in New Issue
Block a user