Graze prints upgrade details, fixed dialog bug

This commit is contained in:
2018-11-05 16:56:00 +11:00
parent be48756819
commit 8077d260da
3 changed files with 48 additions and 1 deletions

View File

@@ -37,6 +37,9 @@ client.on('ready', async () => {
}
console.log("Logged in as: " + client.user.username + " - " + client.user.id);
//connect to the server
shared.ConnectToServer(client.user.username, process.env.SERVER_ADDRESS, process.env.SERVER_PORT, process.env.SERVER_PASS_KEY);
});
// Create an event listener for messages
@@ -82,6 +85,16 @@ function processBasicCommands(client, message) {
}
return true;
//TODO: avoid help command collisions
case "upgrade":
if (!args[0]) {
printUpgrades(message.author, message.channel);
} else {
processUpgradeCommand(message.author, message.channel, args);
}
return true;
default:
shared.SendPublicMessage(client, message.author, message.channel, dialog(command));
return true;
@@ -89,3 +102,24 @@ function processBasicCommands(client, message) {
return false;
}
function printUpgrades(user, channel) {
let handleResponse = function(stats) {
//create the embed
let embed = new discord.RichEmbed()
.setAuthor(client.user.username, client.user.avatarURL)
.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")
.setDescription(dialog("upgradeText"))
.setFooter(`${user.username}, you have ${stats.wallet} crystals. Use !upgrade [OPTION] to buy.`); //TODO: move this to dialog?
shared.SendPublicMessage(client, user, channel, dialog("upgradeHeading"));
channel.send({ embed });
}
shared.OnServerData("userStats", handleResponse, user.id);
}
function processUpgradeCommand(uset, channel, args) {
//TODO
}

View File

@@ -1,3 +1,7 @@
{
"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.```",
"noResult": "I have no idea what you just said."
}

View File

@@ -34,8 +34,17 @@ exports.GenerateDialogFunction = function(dialogJson) {
result = dialogJson[key];
}
//handle no result
if (typeof(result) === "undefined") {
return dialogJson["noResult"];
const noResult = dialogJson["noResult"];
if (typeof(noResult) === "undefined") {
return ""; //nothing at all to show
}
if (Array.isArray(noResult)) {
result = noResult[Math.floor(Math.random() * noResult.length)];
} else {
result = noResult;
}
}
let counter = 0;