Skip to content

Commit

Permalink
adding and subtracting cash from the bag works
Browse files Browse the repository at this point in the history
  • Loading branch information
roganhamby committed Jun 24, 2019
1 parent aef50e5 commit 201ca8c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
36 changes: 33 additions & 3 deletions bag.js
Expand Up @@ -10,7 +10,6 @@ module.exports = {
var inventory = false;
var deposit = false;
var withdraw = false;
var wipe = false;
var consolidate = false;
var split = false; // will split the coins, which also liquidates them
var r = [];
Expand All @@ -20,7 +19,6 @@ module.exports = {
if (args[i] == "i" || args[i] == "inv" || args[i] == "inventory") { inventory = true; pass = true; }
if (args[i] == "d" || args[i] == "dp" || args[i] == "deposit") { deposit = true; pass = true; }
if (args[i] == "w" || args[i] == "with" || args[i] == "withdraw") { withdraw = true; pass = true; }
if (args[i] == "nuke" || args[i] == "wipe") { wipe = true; pass = true; }
if (args[i] == "split") { split = true; pass = true; }
if (args[i] == "consolidate" || args[i] == "cons") { liquidate = true; pass = true; }
if (args[i].includes("cp")) { cp = cp + parseInt(args[i].split("cp")[0]); pass = true; }
Expand All @@ -39,7 +37,6 @@ module.exports = {
r[7] = withdraw;
r[8] = split;
r[9] = consolidate;
r[10] = wipe;
return r;
},
checkForBag: function (userID) {
Expand All @@ -52,6 +49,39 @@ module.exports = {
}
return true;
},
depositOrWithdraw: function (userID,args) {
var util = require('./util.js');
var cp = args[0];
var sp = args[1];
var gp = args[2];
var pp = args[3];
var stuff = args[4];
var deposit = args[6];
var withdraw = args[7];
var msg;
var sql = "SELECT cp, sp, gp, pp FROM money WHERE name = '" + userID + "';";
var row = util.querySingleRow(sql);
if (withdraw == true) {
cp = row.cp - cp;
sp = row.sp - sp;
gp = row.gp - gp;
pp = row.pp - pp;
}
if (deposit == true) {
cp = cp + row.cp;
sp = sp + row.sp;
gp = gp + row.gp;
pp = pp + row.pp;
}
if (cp >= 0 && sp >= 0 && gp >= 0 && pp >= 0) {
sql = "UPDATE money SET cp = " + cp + ", sp = " + sp + ", gp = " + gp + ", pp = " + pp + " WHERE name = '" + userID + "';";
util.runSQL(sql);
msg = "The ferrets have adjusted your wares. Beware.";
} else {
msg = "The ferrets say your math doesn't work. Don't scame a ferret. They know ferrets.";
}
return msg;
},
splitArguments: function (args) {
var array_length = args.length;
var ways = 0;
Expand Down
13 changes: 10 additions & 3 deletions core.js
Expand Up @@ -51,6 +51,7 @@ bot.on('message', function (user, userID, channelID, message, evt) {
var roll;
var modifier;
var multiplier;
var badparams = false;
var msg;
args = args.splice(1);
switch(cmd) {
Expand All @@ -67,16 +68,22 @@ bot.on('message', function (user, userID, channelID, message, evt) {
var withdraw = returned_args[7];
var split = returned_args[8];
var consolidate = returned_args[9];
var wipe = returned_args[10];
badparams = false;
msg = "The ferrets are waiting.";
//msg = bag.depositOrWithdraw(user,cp,sp,gp,pp,stuff,deposit,withdraw);
if (deposit == true && withdraw == true) { badparams = true; msg = "You can't have depoit and withdraw on the same command."; }
if (inventory == false && deposit == false && withdraw == false && split == false && consolidate == false) { badparams = true; msg = "You haven't given the ferrets anything to do. They are now bored. In your bag."; }
if (badparams == false) {
msg = "Actions taken: ";
//if (consolidate == true) { msg = msg + " " + bag.consolidate; }
if (deposit == true || withdraw == true) { msg = msg + " " + bag.depositOrWithdraw(userID,returned_args); }
}
if (typeof comment !== 'undefined') { msg = msg + "\n" + "#" + comment; }
bot.sendMessage({
to: channelID,
message: msg
});
break;
case 'dndstats':
case 'dndstats':
returned_args = rolling.rollArguments(args);
roll = returned_args[0];
rr = returned_args[1];
Expand Down

0 comments on commit 201ca8c

Please sign in to comment.