Finished Mori

This commit is contained in:
2018-11-03 00:12:18 +11:00
parent 4d57cd12c3
commit c724ae75cd
3 changed files with 78 additions and 9 deletions

View File

@@ -12,14 +12,14 @@
"Good day. All the travelers are back up. Time for some sleep. Goodnight everybody."
],
"heal": "Here's what I've got at the moment. My prices are based on availability, it's hard to find stuff these days.",
"healHeading": "Here's what I've got at the moment. My prices are based on availability, it's hard to find stuff these days.",
"healSuccess": "I've applied a {1} via nanotech .\n**-{2}**:crystals: | **{3}**HP.",
"healFailure": "Sorry, not sure I understand what procedure you'd like to purchase.",
"healLocked": "Sorry, you don't meet the requirements for this procedure.",
"healNotEnoughInWallet": "Sorry, looks like you don't have the funds for that.",
"healKnockedOut": "You're currently knoecked out (0HP). You require a revive procdure to heal immediately, or you can wait until 7 AM when I revive everyone.",
"healFullHealth": "Looks like you're already full health. Why would you want to heal?",
"healNotKnockedOut": "Sorry, you don't meet the requirements for this procedure.",
"healKnockedOut": "You're currently knocked out (0HP). You require a revive procdure to heal immediately, or you can wait until 7 AM when I revive everyone.",
"healFullHealth": "Looks like you're already at full health. Why would you want to heal?",
"noResult": [
"Try again, genius.",

View File

@@ -72,7 +72,7 @@ client.on('ready', async () => {
console.log("Trying to revive...");
shared.OnServerData("reviveAll", () => { //TODO: server-side reviveAll command
console.log("Revive successful");
shared.SendPublicMessage(client, process.env.TAVERN_CHANNEL_ID, dialog("reviveAll"));
shared.SendPublicMessage(client, process.env.TAVERN_CHANNEL_ID, dialog("reviveAll")); //TODO: add a reference to Alexis in the dialog here
});
resetInventory(itemCount);
});
@@ -125,6 +125,10 @@ function processBasicCommands(client, message) {
}
return true;
case "help":
printTreatments(message.author, message.channel);
return true;
case "heal":
if (!args[0]) {
printTreatments(message.author, message.channel);
@@ -185,7 +189,7 @@ function printTreatments(user, channel) {
.setDescription(treatmentMessage)
.setFooter(`${user.username}, you have ${stats.wallet} crystals. Use !heal [OPTION] to buy.`);
shared.SendPublicMessage(client, user, channel, dialog("heal"));
shared.SendPublicMessage(client, user, channel, dialog("healHeading"));
channel.send({ embed });
}
@@ -196,6 +200,14 @@ function processHealCommand(user, channel, args) {
//get the selected treatment
let selectedTreatment = availableTreatments.filter((treatment) => treatment[0].toLowerCase() === args[0].toLowerCase())[0];
if (!selectedTreatment) {
shared.SendPublicMessage(client, user, channel, dialog("healFailure"));
}
let handleResponse = function(response) {
shared.SendPublicMessage(client, user, channel, dialog(response, selectedTreatment[0], selectedTreatment[1], selectedTreatment[2]));
}
if (selectedTreatment[3]) { //should it be a revive command?
shared.OnServerData("revive", handleResponse, user.id, selectedTreatment[1], selectedTreatment[2]);
} else {

View File

@@ -315,7 +315,18 @@ async function handleRevive({ data }, fn) {
//data[1] = cost
//data[2] = amount (potentially percentage)
//TODO
//WARNING: copy/paste
let query = `SELECT health, maxHealth, wallet FROM users WHERE userID=${data[0]} LIMIT 1;`;
return dbConnection.query(query, (err, result) => {
if (err) throw err;
//not knocked out
if (result[0].health != 0) {
return fn("healNotKnockedOut");
}
return innerHeal(data, fn, result, "revive");
});
}
//handle healing a specific player
@@ -325,7 +336,53 @@ async function handleHeal({ data }, fn) {
//data[1] = cost
//data[2] = amount (potentially percentage)
//TODO
let query = `SELECT health, maxHealth, wallet FROM users WHERE userID=${data[0]} LIMIT 1;`;
return dbConnection.query(query, (err, result) => {
if (err) throw err;
//not knocked out
if (result[0].health == 0) {
return fn("healKnockedOut");
}
return innerHeal(data, fn, result, "heal");
});
}
//avoid copy/paste in the healing functions
function innerHeal(data, fn, result, logType = 'unknown') {
//not enough money
if (result[0].wallet < data[1]) {
return fn("healNotEnoughInWallet");
}
if (result[0].health == result[0].maxHealth) {
return fn("healFullHealth");
}
//parse out the amount that needs regening
let regenAmount = data[2];
if (regenAmount[regenAmount.length-1] == "%") {
regenAmount = regenAmount.slice(0, -1);
regenAmount = Math.floor(parseFloat(regenAmount) / 100 * result[0].maxHealth);
} else {
regenAmount = Math.floor(parseFloat(regenAmount));
}
//actually do the regen
let newHealth = Math.min(result[0].health + regenAmount, result[0].maxHealth); //I tried making this an SQL function, didn't work
let query = `UPDATE users SET health = ${newHealth}, wallet = wallet - ${data[1]} WHERE userID='${data[0]}' LIMIT 1;`;
return dbConnection.query(query, (err, result) => {
if (err) throw err;
//logging touch
dbConnection.query(`SELECT health, maxHealth FROM users WHERE userID='${data[0]}' LIMIT 1;`, (err, result) => {
dbLog(data[0], `health ${logType}`, `healed ${regenAmount} - ${result[0].health}/${result[0].maxHealth}`);
});
return fn("healSuccess");
});
}
//utility functions
@@ -365,7 +422,7 @@ function calculateTimeAgo(seconds) {
}
if (seconds < 60 * 60) {
return "this hour";
return "just this hour";
}
if (seconds < 60 * 60 * 24) {