Skip to content

Instantly share code, notes, and snippets.

@evinjaff
Created September 20, 2020 21:50
Show Gist options
  • Save evinjaff/a2f56394c6c0ccf9cdf7f427ff63e546 to your computer and use it in GitHub Desktop.
Save evinjaff/a2f56394c6c0ccf9cdf7f427ff63e546 to your computer and use it in GitHub Desktop.
//JS Module compatible with Discord.js
//Ideally if you were going to use this often, you'd try and find a better randomness library, but that's neither here nor there.
module.exports = {
name: 'statroll',
description: 'rolls stats',
execute(message, args) {
console.log("args: " + args);
//message.reply("args is " + args.toString());
if(args.includes("4d6")){
var arr = [0, 0, 0, 0, 0, 0];
var msg = " you rolled: \n";
const reducer = (accumulator, currentValue) => accumulator + currentValue;
const stdarraysum = 72;
for(var i=0;i<6;i++){ //for each stat
var statroll = [0, 0, 0, 0];
for (var j=0;j<4;j++){
statroll[j] = (Math.floor(Math.random()*6) + 1);
console.log ("statroll: " + statroll)
//console.log("min # = " + );
}
//msg += ")";
var sum = statroll.reduce(reducer);
var minned = sum-Math.min(...statroll);
arr[i] = minned;
msg += "(" + statroll.toString() + " - " + (Math.min(...statroll)) + "), " + "= " + minned + " ";
}
msg += "\nStats: "
msg += arr.toString();
var statsum = arr.reduce(reducer);
msg += " = " + statsum + "\n";
if(statsum > stdarraysum){
msg += ("Sum of stats is " + (statsum-stdarraysum) + " greater than standard array, nice!");
}
else if(statsum == stdarraysum){
msg += "Sum of stats is equal to standard array."
}
else{
msg += "Sum of stats is " + (Math.abs(statsum-stdarraysum)) + " less than standard array- yikes"
}
var ticker = 0;
for(var i=0;i<arr.length;i++){
if(arr[i] >= 16){
ticker++;
}
}
msg += ("\nYou have " + ticker + " high stats (16 or greater)." );
switch (ticker) {
case 0:
msg += " Uh oh!";
break;
case 1:
msg+= " SAD is cool";
break;
case 2:
msg+= " Not bad!"
break;
case 3:
msg+= " Wow! Really good!"
break;
case 4:
msg+= " Holy cow! That's insane!"
break;
case 5:
msg+= " Holy shit! This is amazing, you are going to wreck your next campaign!"
break;
case 6:
msg+= " Holy fuck! You must have been blessed by the dice gods!"
break;
}
var ticker = 0;
for(var i=0;i<arr.length;i++){
if(arr[i] <= 10){
ticker++;
}
}
msg += ("\nYou have " + ticker + " bad stats (10 or less)." );
switch (ticker) {
case 0:
msg += " Awesome! The Dice gods have blessed you!";
break;
case 1:
msg+= " You only have one bad stat- cool!";
break;
case 2:
msg+= " Two bad stats. Not bad!"
break;
case 3:
msg+= " 3 bad stats, RIP multiclassing"
break;
case 4:
msg+= " Wow that's probabaly not playable"
break;
case 5:
msg+= " Holy shit! You must be really unlucky. Don't walk down any staircases anytime soon."
break;
case 6:
msg+= " Holy fuck! The dice gods smote you!"
break;
}
console.log("ARR: " + arr);
console.log("MSG: " + msg);
message.reply(msg);
}
if(args.includes("3d6")){
var arr = [0, 0, 0, 0, 0, 0];
var msg = " you rolled: \n";
const reducer = (accumulator, currentValue) => accumulator + currentValue;
const stdarraysum = 72;
for(var i=0;i<6;i++){ //for each stat
var statroll = [0, 0, 0];
for (var j=0;j<3;j++){
statroll[j] = (Math.floor(Math.random()*6) + 1);
console.log ("statroll: " + statroll)
//console.log("min # = " + );
}
//msg += ")";
var sum = statroll.reduce(reducer);
arr[i] = sum;
msg += "(" + statroll.toString() + "), " + "= " + sum + " ";
}
msg += "\nStats: "
msg += arr.toString();
var statsum = arr.reduce(reducer);
msg += " = " + statsum + "\n";
if(statsum > stdarraysum){
msg += ("Sum of stats is " + (statsum-stdarraysum) + " greater than standard array, nice!");
}
else if(statsum == stdarraysum){
msg += "Sum of stats is equal to standard array."
}
else{
msg += "Sum of stats is " + (Math.abs(statsum-stdarraysum)) + " less than standard array- yikes"
}
var ticker = 0;
for(var i=0;i<arr.length;i++){
if(arr[i] >= 16){
ticker++;
}
}
msg += ("\nYou have " + ticker + " high stats (16 or greater)." );
switch (ticker) {
case 0:
msg += " Uh oh!";
break;
case 1:
msg+= " SAD is cool";
break;
case 2:
msg+= " Not bad!"
break;
case 3:
msg+= " Wow! Really good!"
break;
case 4:
msg+= " Holy cow! That's insane!"
break;
case 5:
msg+= " Holy shit! This is amazing, you are going to wreck your next campaign!"
break;
case 6:
msg+= " Holy fuck! You must have been blessed by the dice gods!"
break;
}
for(var i=0;i<arr.length;i++){
if(arr[i] <= 10){
ticker++;
}
}
msg += ("\nYou have " + ticker + " bad stats (10 or less)." );
switch (ticker) {
case 0:
msg += " Awesome! The Dice gods have blessed you!";
break;
case 1:
msg+= " You only have one bad stat- cool!";
break;
case 2:
msg+= " Two bad stats. Not bad!"
break;
case 3:
msg+= " 3 bad stats, RIP multiclassing"
break;
case 4:
msg+= " Wow that's probabaly not playable"
break;
case 5:
msg+= " Holy shit! You must be really unlucky. Don't walk down any staircases anytime soon."
break;
case 6:
msg+= " Holy fuck! The dice gods smote you!"
break;
}
console.log("ARR: " + arr);
console.log("MSG: " + msg);
message.reply(msg);
}
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment