Advertisement
Guest User

Code Bot v3

a guest
Mar 22nd, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.96 KB | None | 0 0
  1. const Discord = require("discord.js");
  2. const config = require("./config.json");
  3. var chalk = require("chalk");
  4. const bot = new Discord.Client();
  5. bot.login(config.token);
  6.  
  7. var version = "1.0.3";
  8.  
  9.  
  10. //Called When bot becomes functional.
  11. bot.on("ready", () => {
  12. console.log(`Bot version ${version}`);
  13. console.log(`Logged in as ${bot.user.username}!`);
  14. if (config.maxRollsPerDie >= 100) {
  15. console.warn(chalk.white.bgRed("!!!WARNING!!! maxRollsPerDie in config.json must be set between 1-99 otherwise errors may occur in rolls"));
  16. }
  17. //console.log(chalk.red('Hello', chalk.underline.bgBlue('world') + '!'));
  18. });
  19.  
  20. //Called whenever a users send a message to the server
  21. bot.on("message", message => {
  22. //Ignore messages sent by the bot
  23. if (message.author.bot) return;
  24.  
  25. //Ignore messages that dont start with the command symbol
  26. if (!message.content.startsWith(config.prefix)) return;
  27.  
  28. //Seperate and create a list of parameters. A space in the message denotes a new parameter
  29. const params = message.content.split(" ").slice(1);
  30. //;for(var i=0;i<params.length;i++){
  31. // message.channel.sendMessage("Array ele: " + i + " " + params[i]);
  32. //}
  33.  
  34. //************************COMMANDS START HERE************************
  35.  
  36. // Command to kill the bot application
  37. // if(message.content.startsWith(config.prefix + "kill")){
  38. // console.log("!kill command was called... Now Exiting");
  39. // process.exit();
  40. // }
  41.  
  42. var roll = 0, base = 0, modfr = 0;
  43.  
  44. if(params[1]){
  45. modfr = params[1];
  46. base = Math.floor((Math.random() * 100) + 1);
  47. roll = parseInt(base) + parseInt(modfr);
  48. }
  49. else {
  50. roll = Math.floor((Math.random() * 100) + 1);
  51. }
  52.  
  53. message.channel.sendMessage("You rolled: " + roll);
  54.  
  55. // Roll the dice command
  56. if (message.content.startsWith(config.prefix + "roll")) {
  57. console.log("Rolling dice for " + message.author.username);
  58. /*Sorting the dice types by suffix
  59. 7 unique dice in total
  60. y = Yellow
  61. g = Green
  62. b = Blue
  63. blk = Black
  64. r = red
  65. p = Purple
  66. d/w = destiny/white
  67. */
  68.  
  69.  
  70. //check off colors as they are rolled to make sure users don't accidentally roll duplicates
  71. var yellowRolled = false;
  72. var greenRolled = false;
  73. var blueRolled = false;
  74. var blackRolled = false;
  75. var redRolled = false;
  76. var purpleRolled = false;
  77. var whiteRolled = false;
  78.  
  79. //Init the dice results to zero
  80. var diceResult = {
  81. success: 0,
  82. failure: 0,
  83. advantage: 0,
  84. threat: 0,
  85. triumph: 0,
  86. despair: 0,
  87. light: 0,
  88. dark: 0
  89. };
  90.  
  91. //Switch to abort command if ever turns true
  92. var abandonShip = false;
  93.  
  94. //init the descriptor string to an empty string
  95. var desc = "";
  96.  
  97. //var descArr = [];
  98. var beg, end = 0;
  99. var begF, endF = false;
  100. for (var i = 0; i < params.length; i++) {
  101. if (params[i].includes('"')) {
  102. if (!begF) {
  103. beg = i;
  104. begF = true;
  105. } else if (begF && !endF) {
  106. end = i;
  107. endF = true;
  108. }
  109. }
  110. }
  111.  
  112. console.log("Beg: " + beg + " End: " + end);
  113. for (i = beg; i < end + 1; i++) {
  114. console.log(params[i]);
  115. desc += " " + params[i];
  116. }
  117.  
  118. var spliceAmnt = end + 1 - beg;
  119.  
  120. //remove the text field arguments from the list of parameters before checking for dice.
  121. params.splice(beg, spliceAmnt);
  122.  
  123.  
  124.  
  125.  
  126. //Iterate over the parameters and call the dice roll functions respective to color
  127. // this allows users to list dice colors in any order
  128. for (var i = 0; i < params.length; i++) {
  129. if (abandonShip) break;
  130. //Begin checking for any dice rolls
  131.  
  132. /*
  133. NOTE: made redundant by update version 1.0.2
  134. Given that dice rolls must be between 1-99 and the suffix with the most chars is "blk" we must only check for
  135. arguments that are equal or less than 5 chars. Example !roll 99blk has 5 chars in the dice argument.
  136. This allows dynamic dice argument order in conjunction with a string descriptor, but requires string descriptors
  137. to be greater than 5 characters.
  138. */
  139. if (params[i].length <= 5) {
  140. //check command for yellow dice roll
  141. if (params[i].endsWith("y")) {
  142. //make sure they haven't already rolled these dice
  143. if (yellowRolled == true) {
  144. message.channel.sendMessage("Duplicate dice argument detected. The roll " + params[i] + " will be ignored");
  145. console.log(chalk.white.bgRed("User error, tried to call multiple " + chalk.black.bgYellow("yellow") + " dice rolls"));
  146. } else if (yellowRolled == false) {
  147. yellowRolled = true;
  148. //Extract the number of dice to roll from the string
  149. var diceQty = extractNumbers(params[i]);
  150. if (diceQty > config.maxRollsPerDie) {
  151. abandonShip = true;
  152. break;
  153. }
  154.  
  155. console.log("Rolling " + diceQty + " Proficiency Dice.");
  156.  
  157. //Call the function that rolls the yellow dice
  158.  
  159. var yellowResult = rollYellow(diceQty);
  160.  
  161.  
  162. //Add the result of all the yellow dice rolls to the standing count
  163. for (var k in yellowResult) {
  164. diceResult[k] += yellowResult[k];
  165. }
  166.  
  167. }
  168. }
  169. //check command for green dice roll
  170. if (params[i].endsWith("g")) {
  171. //make sure they haven't already rolled these dice
  172. if (greenRolled == true) {
  173. message.channel.sendMessage("Duplicate dice argument detected. The roll " + params[i] + " will be ignored");
  174. console.log(chalk.white.bgRed("User error, tried to call multiple " + chalk.white.bgGreen("green") + " dice rolls"));
  175. } else if (greenRolled == false) {
  176. greenRolled = true;
  177. //Extract the number of dice to roll from the string
  178. var diceQty = extractNumbers(params[i]);
  179. if (diceQty > config.maxRollsPerDie) {
  180. abandonShip = true;
  181. break;
  182. }
  183.  
  184. console.log("Rolling " + diceQty + " Ability Dice.");
  185.  
  186. //Call the function that rolls the green dice
  187. var greenResult = rollGreen(diceQty);
  188.  
  189. //Add the result of all the green dice rolls to the standing count
  190. for (var k in greenResult) {
  191. diceResult[k] += greenResult[k];
  192. }
  193.  
  194. }
  195. }
  196. //check command for Blue dice roll
  197. if (params[i].endsWith("b")) {
  198. //make sure they haven't already rolled these dice
  199. if (blueRolled == true) {
  200. message.channel.sendMessage("Duplicate dice argument detected. The roll " + params[i] + " will be ignored");
  201. console.log(chalk.white.bgRed("User error, tried to call multiple " + chalk.white.bgBlue("blue") + " dice rolls"));
  202. } else if (blueRolled == false) {
  203. blueRolled = true;
  204.  
  205. //Extract the number of dice to troll from the string
  206. var diceQty = extractNumbers(params[i]);
  207. if (diceQty > config.maxRollsPerDie) {
  208. abandonShip = true;
  209. break;
  210. }
  211.  
  212. console.log("Rolling " + diceQty + " Boost Dice.");
  213.  
  214. //Call the function that rolls the blue dice
  215. var blueResult = rollBlue(diceQty);
  216.  
  217. //Add the result of all the blue dice rolls to the standing count
  218. for (var k in blueResult) {
  219. diceResult[k] += blueResult[k];
  220. }
  221. }
  222. }
  223.  
  224. //check command for Black dice roll
  225. if (params[i].endsWith("blk")) {
  226. //make sure they haven't already rolled these dice
  227. if (blackRolled == true) {
  228. message.channel.sendMessage("Duplicate dice argument detected. The roll " + params[i] + " will be ignored");
  229. console.log(chalk.white.bgRed("User error, tried to call multiple " + chalk.white.bgBlack("black") + " dice rolls"));
  230. } else if (blackRolled == false) {
  231. blackRolled = true;
  232. //Extract the number of dice to troll from the string
  233. var diceQty = extractNumbers(params[i]);
  234. if (diceQty > config.maxRollsPerDie) {
  235. abandonShip = true;
  236. break;
  237. }
  238.  
  239. console.log("Rolling " + diceQty + " Setback Dice.");
  240.  
  241. //Call the function that rolls the black dice
  242. var blackResult = rollBlack(diceQty);
  243.  
  244. //Add the result of all the black dice rolls to the standing count
  245. for (var k in blackResult) {
  246. diceResult[k] += blackResult[k];
  247. }
  248. }
  249. }
  250.  
  251. //check command for red dice roll
  252. if (params[i].endsWith("r")) {
  253. //make sure they haven't already rolled these dice
  254. if (redRolled == true) {
  255. message.channel.sendMessage("Duplicate dice argument detected. The roll " + params[i] + " will be ignored");
  256. console.log(chalk.white.bgRed("User error, tried to call multiple " + chalk.black.bgRed("red") + " dice rolls"));
  257. } else if (redRolled == false) {
  258. redRolled = true;
  259.  
  260. //Extract the number of dice to troll from the string
  261. var diceQty = extractNumbers(params[i]);
  262. if (diceQty > config.maxRollsPerDie) {
  263. abandonShip = true;
  264. break;
  265. }
  266.  
  267. console.log("Rolling " + diceQty + " Challenge Dice.");
  268.  
  269. //Call the function that rolls the red dice
  270. var redResult = rollRed(diceQty);
  271.  
  272. //Add the result of all the red dice rolls to the standing count
  273. for (var k in redResult) {
  274. diceResult[k] += redResult[k];
  275. }
  276. }
  277. }
  278. //check command for Purple dice roll
  279. if (params[i].endsWith("p")) {
  280. //make sure they haven't already rolled these dice
  281. if (purpleRolled == true) {
  282. message.channel.sendMessage("Duplicate dice argument detected. The roll " + params[i] + " will be ignored");
  283. console.log(chalk.white.bgRed("User error, tried to call multiple " + chalk.white.bgMagenta("purple") + " dice rolls"));
  284. } else if (purpleRolled == false) {
  285. purpleRolled = true;
  286. //Extract the number of dice to troll from the string
  287. var diceQty = extractNumbers(params[i]);
  288. if (diceQty > config.maxRollsPerDie) {
  289. abandonShip = true;
  290. break;
  291. }
  292.  
  293. console.log("Rolling " + diceQty + " Difficulty Dice.");
  294.  
  295. //Call the function that rolls the purple dice
  296. var purpleResult = rollPurple(diceQty);
  297.  
  298. //Add the result of all the purple dice rolls to the standing count
  299. for (var k in purpleResult) {
  300. diceResult[k] += purpleResult[k];
  301. }
  302. }
  303. }
  304. //check command for destiny/white dice roll
  305. if (params[i].endsWith("d") || params[i].endsWith("w")) {
  306. //make sure they haven't already rolled these dice
  307. if (whiteRolled == true) {
  308. message.channel.sendMessage("Duplicate dice argument detected. The roll " + params[i] + " will be ignored");
  309. console.log(chalk.white.bgRed("User error, tried to call multiple " + chalk.black.bgWhite("white") + " dice rolls"));
  310. } else if (whiteRolled == false) {
  311. whiteRolled = true;
  312.  
  313. //Extract the number of dice to troll from the string
  314. var diceQty = extractNumbers(params[i]);
  315. if (diceQty > config.maxRollsPerDie) {
  316. abandonShip = true;
  317. break;
  318. }
  319.  
  320. console.log("Rolling " + diceQty + " Destiny Dice.");
  321.  
  322. //Call the function that rolls the white dice
  323. var whiteResult = rollWhite(diceQty);
  324.  
  325. //Add the result of all the white dice rolls to the standing count
  326. for (var k in whiteResult) {
  327. diceResult[k] += whiteResult[k];
  328. }
  329. }
  330. }
  331. }
  332. } //end of For loop
  333.  
  334. console.log("\nThe Standing Count is");
  335. console.log(diceResult);
  336.  
  337. //BEGIN PREPARING THE MESSAGE TO SEND
  338.  
  339. var cancelledDiceResult = {
  340. success: 0,
  341. failure: 0,
  342. advantage: 0,
  343. threat: 0,
  344. triumph: 0,
  345. despair: 0,
  346. light: 0,
  347. dark: 0
  348. };
  349.  
  350.  
  351. //Extract the descriptor from the command assuming it's the only param greater than 5 chars
  352. //Poetnetially obsolete
  353. for (var i = 0; i < params.length; i++) {
  354. if (params[i].length > 5) {
  355. desc = params[i];
  356. break;
  357. }
  358. }
  359.  
  360.  
  361. //Do the cancellations
  362. if (!abandonShip) {
  363.  
  364. var response = message.author.username + " roll results: ";
  365.  
  366. //cancel success/failures
  367. if (diceResult.success > diceResult.failure) {
  368. var successRemaining = diceResult.success - diceResult.failure;
  369. cancelledDiceResult.success = successRemaining;
  370. response += " " + "Success: " + successRemaining;
  371. } else if (diceResult.success < diceResult.failure) {
  372. var failureRemaining = diceResult.failure - diceResult.success;
  373. cancelledDiceResult.failure = failureRemaining;
  374. response += " " + "Failure: " + failureRemaining;
  375. }
  376.  
  377. //cancel Advantage/Threat
  378. if (diceResult.advantage > diceResult.threat) {
  379. var advantageRemaining = diceResult.advantage - diceResult.threat;
  380. cancelledDiceResult.advantage = advantageRemaining;
  381. response += " " + "Advantage: " + advantageRemaining;
  382. } else if (diceResult.advantage < diceResult.threat) {
  383. var threatRemaining = diceResult.threat - diceResult.advantage;
  384. cancelledDiceResult.threat = threatRemaining;
  385. response += " " + "Threat: " + threatRemaining;
  386. }
  387. //Check for any Triumphs
  388. if (diceResult.triumph != 0) {
  389. cancelledDiceResult.triumph = diceResult.triumph;
  390. response += " " + "Triumph: " + diceResult.triumph;
  391. }
  392. //Check for any Despair
  393. if (diceResult.despair != 0) {
  394. cancelledDiceResult.despair = diceResult.despair;
  395. response += " " + "Despair: " + diceResult.despair;
  396. }
  397.  
  398. //check for force
  399. if (diceResult.light != 0) {
  400. response += " " + "Light Force: " + diceResult.light;
  401. }
  402.  
  403. if (diceResult.dark != 0) {
  404. response += " " + "Dark Force: " + diceResult.dark;
  405. }
  406.  
  407. //remove Quotes from descriptor
  408. desc = desc.replace(/['"]+/g, '');
  409.  
  410. //response += " " + desc;
  411. message.channel.sendMessage(config.descriptorPrepend + " " + desc + "\n" + response);
  412. //message.channel.sendMessage(response);
  413. } else if (abandonShip) {
  414. message.reply("Roll exceeds max roll per die limit of " + config.maxRollsPerDie + " . Please try again.");
  415. }
  416. }
  417. });
  418.  
  419. //Function for extracting the number of times to roll a dice from the command string
  420. function extractNumbers(str) {
  421. var num = str.replace(/\D/g, "");
  422. return num;
  423. }
  424.  
  425. //Function that generates random numbers based on varying dice sizes
  426. function randomInteger(num) {
  427. var result = Math.floor(Math.random() * num) + 1;
  428. return result;
  429. }
  430.  
  431.  
  432.  
  433. function rollBlue(diceQty) {
  434. //Blue "Boost" die (d6)
  435. //1 Blank
  436. //2 Blank
  437. //3 Success
  438. //4 Advantage
  439. //5 Advantage + Advantage
  440. //6 Success + Advantage
  441. var roll = 0;
  442. var diceResult = {
  443. success: 0,
  444. failure: 0,
  445. advantage: 0,
  446. threat: 0,
  447. triumph: 0,
  448. despair: 0,
  449. light: 0,
  450. dark: 0
  451. };
  452.  
  453. for (var i = 1; i <= diceQty; i++) {
  454.  
  455. roll = randomInteger(6);
  456. //console.log(chalk.white.bgBlue("Dice landed on side " + roll));
  457.  
  458. switch (roll) {
  459. case 1:
  460. console.log(chalk.white.bgBlue("Blank"));
  461. break;
  462. case 2:
  463. console.log(chalk.white.bgBlue("Blank"));
  464. break;
  465. case 3:
  466. console.log(chalk.white.bgBlue("Success"));
  467. diceResult.success = diceResult.success + 1;
  468. break;
  469. case 4:
  470. console.log(chalk.white.bgBlue("Advantage"));
  471. diceResult.advantage = diceResult.advantage + 1;
  472. break;
  473. case 5:
  474. console.log(chalk.white.bgBlue("Advantage x2"));
  475. diceResult.advantage = diceResult.advantage + 2;
  476. break;
  477. case 6:
  478. console.log(chalk.white.bgBlue("Success + Advantage"));
  479. diceResult.success = diceResult.success + 1;
  480. diceResult.advantage = diceResult.advantage + 1;
  481. break;
  482. }
  483. }
  484. return diceResult;
  485. }
  486.  
  487. function rollGreen(diceQty) {
  488. //Green "Ability" die (d8)
  489. //1 Blank
  490. //2 Success
  491. //3 Success
  492. //4 Advantage
  493. //5 Advantage
  494. //6 Success + Advantage
  495. //7 Advantage + Advantage
  496. //8 Success + Success
  497. var roll = 0;
  498. var diceResult = {
  499. success: 0,
  500. failure: 0,
  501. advantage: 0,
  502. threat: 0,
  503. triumph: 0,
  504. despair: 0,
  505. light: 0,
  506. dark: 0
  507. };
  508.  
  509. for (var i = 1; i <= diceQty; i++) {
  510.  
  511. roll = randomInteger(8);
  512.  
  513.  
  514. switch (roll) {
  515. case 1:
  516. console.log(chalk.white.bgGreen("Blank"));
  517. break;
  518. case 2:
  519. console.log(chalk.white.bgGreen("Success"));
  520. diceResult.success = diceResult.success + 1;
  521. break;
  522. case 3:
  523. console.log(chalk.white.bgGreen("Success"));
  524. diceResult.success = diceResult.success + 1;
  525. break;
  526. case 4:
  527. console.log(chalk.white.bgGreen("Advantage"));
  528. diceResult.advantage = diceResult.advantage + 1;
  529. break;
  530. case 5:
  531. console.log(chalk.white.bgGreen("Advantage"));
  532. diceResult.advantage = diceResult.advantage + 1;
  533. break;
  534. case 6:
  535. console.log(chalk.white.bgGreen("Success + Advantage"));
  536. diceResult.success = diceResult.success + 1;
  537. diceResult.advantage = diceResult.advantage + 1;
  538. break;
  539. case 7:
  540. console.log(chalk.white.bgGreen("Advantage x2"));
  541. diceResult.advantage = diceResult.advantage + 2;
  542. break;
  543. case 8:
  544. console.log(chalk.white.bgGreen("Success x2"));
  545. diceResult.success = diceResult.success + 2;
  546. break;
  547. }
  548. }
  549. return diceResult;
  550. }
  551. //
  552. function rollYellow(diceQty) {
  553. //Yellow "Proficiency" die (d12)
  554. //1 Blank
  555. //2 success
  556. //3 success
  557. //4 success x2
  558. //5 success x2
  559. //6 advantage
  560. //7 success + advantage
  561. //8 success + advantage
  562. //9 success + advantage
  563. //10 advantage + advantage
  564. //11 advantage + advantage
  565. //12 triumph
  566. var roll = 0;
  567. var diceResult = {
  568. success: 0,
  569. failure: 0,
  570. advantage: 0,
  571. threat: 0,
  572. triumph: 0,
  573. despair: 0,
  574. light: 0,
  575. dark: 0
  576. };
  577.  
  578. for (var i = 1; i <= diceQty; i++) {
  579.  
  580. roll = randomInteger(12);
  581.  
  582.  
  583. switch (roll) {
  584. case 1:
  585. console.log(chalk.black.bgYellow("blank"));
  586. break;
  587. case 2:
  588. console.log(chalk.black.bgYellow("Success"));
  589. diceResult.success = diceResult.success + 1;
  590. break;
  591. case 3:
  592. console.log(chalk.black.bgYellow("Success"));
  593. diceResult.success = diceResult.success + 1;
  594. break;
  595. case 4:
  596. console.log(chalk.black.bgYellow("Success x2"));
  597. diceResult.success = diceResult.success + 2;
  598. break;
  599. case 5:
  600. console.log(chalk.black.bgYellow("Success x2"));
  601. diceResult.success = diceResult.success + 2;
  602. break;
  603. case 6:
  604. console.log(chalk.black.bgYellow("Advantage"));
  605. diceResult.advantage = diceResult.advantage + 1;
  606. break;
  607. case 7:
  608. console.log(chalk.black.bgYellow("Success + Advantage"));
  609. diceResult.success = diceResult.success + 1;
  610. diceResult.advantage = diceResult.advantage + 1;
  611. break;
  612. case 8:
  613. console.log(chalk.black.bgYellow("Success + Advantage"));
  614. diceResult.success = diceResult.success + 1;
  615. diceResult.advantage = diceResult.advantage + 1;
  616. break;
  617. case 9:
  618. console.log(chalk.black.bgYellow("Success + Advantage"));
  619. diceResult.success = diceResult.success + 1;
  620. diceResult.advantage = diceResult.advantage + 1;
  621. break;
  622. case 10:
  623. console.log(chalk.black.bgYellow("Advantage x2"));
  624. diceResult.advantage = diceResult.advantage + 2;
  625. break;
  626. case 11:
  627. console.log(chalk.black.bgYellow("Advantage x2"));
  628. diceResult.advantage = diceResult.advantage + 2;
  629. break;
  630. case 12:
  631. console.log(chalk.black.bgYellow("Triumph"));
  632. diceResult.triumph = diceResult.triumph + 1;
  633. break;
  634. }
  635. }
  636. return diceResult;
  637. }
  638. //
  639. function rollBlack(diceQty) {
  640. //Black "Setback" die (d6)
  641. //1 Blank
  642. //2 Blank
  643. //3 Failure
  644. //4 Failure
  645. //5 Threat
  646. //6 Threat
  647. var roll = 0;
  648. var diceResult = {
  649. success: 0,
  650. failure: 0,
  651. advantage: 0,
  652. threat: 0,
  653. triumph: 0,
  654. despair: 0,
  655. light: 0,
  656. dark: 0
  657. };
  658.  
  659. for (var i = 1; i <= diceQty; i++) {
  660.  
  661. roll = randomInteger(6);
  662.  
  663. switch (roll) {
  664. case 1:
  665. console.log(chalk.white.bgBlack("Blank"));
  666. break;
  667. case 2:
  668. console.log(chalk.white.bgBlack("Blank"));
  669. break;
  670. case 3:
  671. console.log(chalk.white.bgBlack("Failure"));
  672. diceResult.failure = diceResult.failure + 1;
  673. break;
  674. case 4:
  675. console.log(chalk.white.bgBlack("Failure"));
  676. diceResult.failure = diceResult.failure + 1;
  677. break;
  678. case 5:
  679. console.log(chalk.white.bgBlack("Threat"));
  680. diceResult.threat = diceResult.threat + 1;
  681. break;
  682. case 6:
  683. console.log(chalk.white.bgBlack("Threat"));
  684. diceResult.threat = diceResult.threat + 1;
  685. break;
  686. }
  687. }
  688. return diceResult;
  689. }
  690. //
  691. function rollPurple(diceQty) {
  692. //Purple "Difficulty" die (d8)
  693. //1 Blank
  694. //2 Failure
  695. //3 Failure x2
  696. //4 Threat
  697. //5 Threat
  698. //6 Threat
  699. //7 Threat + Threat
  700. //8 Failure + Threat
  701. var roll = 0;
  702. var diceResult = {
  703. success: 0,
  704. failure: 0,
  705. advantage: 0,
  706. threat: 0,
  707. triumph: 0,
  708. despair: 0,
  709. light: 0,
  710. dark: 0
  711. };
  712.  
  713. for (var i = 1; i <= diceQty; i++) {
  714.  
  715. roll = randomInteger(8);
  716.  
  717.  
  718. switch (roll) {
  719. case 1:
  720. console.log(chalk.white.bgMagenta("Blank"));
  721. break;
  722. case 2:
  723. console.log(chalk.white.bgMagenta("Failure"));
  724. diceResult.failure = diceResult.failure + 1;
  725. break;
  726. case 3:
  727. console.log(chalk.white.bgMagenta("Failure x2"));
  728. diceResult.failure = diceResult.failure + 2;
  729. break;
  730. case 4:
  731. console.log(chalk.white.bgMagenta("Threat"));
  732. diceResult.threat = diceResult.threat + 1;
  733. break;
  734. case 5:
  735. console.log(chalk.white.bgMagenta("Threat"));
  736. diceResult.threat = diceResult.threat + 1;
  737. break;
  738. case 6:
  739. console.log(chalk.white.bgMagenta("Threat"));
  740. diceResult.threat = diceResult.threat + 1;
  741. break;
  742. case 7:
  743. console.log(chalk.white.bgMagenta("Threat x2"));
  744. diceResult.threat = diceResult.threat + 2;
  745. break;
  746. case 8:
  747. console.log(chalk.white.bgMagenta("Failure + Threat"));
  748. diceResult.failure = diceResult.failure + 1;
  749. diceResult.threat = diceResult.threat + 1;
  750. break;
  751. }
  752. }
  753. return diceResult;
  754. }
  755. //
  756. function rollRed(diceQty) {
  757. //Red "Challenge" die (d12)
  758. //1 Blank
  759. //2 Despair
  760. //3 Failure
  761. //4 Failure
  762. //5 Threat
  763. //6 Threat
  764. //7 Failure + Failure
  765. //8 Failure + Failure
  766. //9 Threat + Threat
  767. //10 Threat + Threat
  768. //11 Failure + Threat
  769. //12 Failure + Threat
  770. var roll = 0;
  771. var diceResult = {
  772. success: 0,
  773. failure: 0,
  774. advantage: 0,
  775. threat: 0,
  776. triumph: 0,
  777. despair: 0,
  778. light: 0,
  779. dark: 0
  780. };
  781.  
  782.  
  783. for (var i = 1; i <= diceQty; i++) {
  784.  
  785. roll = randomInteger(12);
  786.  
  787.  
  788. switch (roll) {
  789. case 1:
  790. console.log(chalk.black.bgRed("Blank"));
  791. break;
  792. case 2:
  793. console.log(chalk.black.bgRed("Despair"));
  794. diceResult.despair = diceResult.despair + 1;
  795. break;
  796. case 3:
  797. console.log(chalk.black.bgRed("Failure"));
  798. diceResult.failure = diceResult.failure + 1;
  799. break;
  800. case 4:
  801. console.log(chalk.black.bgRed("Failure"));
  802. diceResult.failure = diceResult.failure + 1;
  803. break;
  804. case 5:
  805. console.log(chalk.black.bgRed("Threat"));
  806. diceResult.threat = diceResult.threat + 1;
  807. break;
  808. case 6:
  809. console.log(chalk.black.bgRed("Threat"));
  810. diceResult.threat = diceResult.threat + 1;
  811. break;
  812. case 7:
  813. console.log(chalk.black.bgRed("Failure x2"));
  814. diceResult.failure = diceResult.failure + 2;
  815. break;
  816. case 8:
  817. console.log(chalk.black.bgRed("Failure x2"));
  818. diceResult.failure = diceResult.failure + 2;
  819. break;
  820. case 9:
  821. console.log(chalk.black.bgRed("Threat x2"));
  822. diceResult.threat = diceResult.threat + 2;
  823. break;
  824. case 10:
  825. console.log(chalk.black.bgRed("Threat x2"));
  826. diceResult.threat = diceResult.threat + 2;
  827. break;
  828. case 11:
  829. console.log(chalk.black.bgRed("Failure + Threat"));
  830. diceResult.failure = diceResult.failure + 1;
  831. diceResult.threat = diceResult.threat + 1;
  832. break;
  833. case 12:
  834. console.log(chalk.black.bgRed("Failure + Threat"));
  835. diceResult.failure = diceResult.failure + 1;
  836. diceResult.threat = diceResult.threat + 1;
  837. break;
  838. }
  839. }
  840. return diceResult;
  841. }
  842. //
  843. function rollWhite(diceQty) {
  844. //White "Force" die (d12)
  845. //1 Light
  846. //2 Light
  847. //3 Light + Light
  848. //4 Light + Light
  849. //5 Light + Light
  850. //6 Dark
  851. //7 Dark
  852. //8 Dark
  853. //9 Dark
  854. //10 Dark
  855. //11 Dark
  856. //12 Dark + Dark
  857. var roll = 0;
  858. var diceResult = {
  859. success: 0,
  860. failure: 0,
  861. advantage: 0,
  862. threat: 0,
  863. triumph: 0,
  864. despair: 0,
  865. light: 0,
  866. dark: 0
  867. };
  868.  
  869.  
  870. for (var i = 1; i <= diceQty; i++) {
  871.  
  872. roll = randomInteger(12);
  873.  
  874.  
  875. switch (roll) {
  876. case 1:
  877. console.log(chalk.black.bgWhite("Light"));
  878. diceResult.light = diceResult.light + 1;
  879. break;
  880. case 2:
  881. console.log(chalk.black.bgWhite("Light"));
  882. diceResult.light = diceResult.light + 1;
  883. break;
  884. case 3:
  885. console.log(chalk.black.bgWhite("Light x2"));
  886. diceResult.light = diceResult.light + 2;
  887. break;
  888. case 4:
  889. console.log(chalk.black.bgWhite("Light x2"));
  890. diceResult.light = diceResult.light + 2;
  891. break;
  892. case 5:
  893. console.log(chalk.black.bgWhite("Light x2"));
  894. diceResult.light = diceResult.light + 2;
  895. break;
  896. case 6:
  897. console.log(chalk.black.bgWhite("Dark"));
  898. diceResult.dark = diceResult.dark + 1;
  899. break;
  900. case 7:
  901. console.log(chalk.black.bgWhite("Dark"));
  902. diceResult.dark = diceResult.dark + 1;
  903. break;
  904. case 8:
  905. console.log(chalk.black.bgWhite("Dark"));
  906. diceResult.dark = diceResult.dark + 1;
  907. break;
  908. case 9:
  909. console.log(chalk.black.bgWhite("Dark"));
  910. diceResult.dark = diceResult.dark + 1;
  911. break;
  912. case 10:
  913. console.log(chalk.black.bgWhite("Dark"));
  914. diceResult.dark = diceResult.dark + 1;
  915. break;
  916. case 11:
  917. console.log(chalk.black.bgWhite("Dark"));
  918. diceResult.dark = diceResult.dark + 1;
  919. break;
  920. case 12:
  921. console.log(chalk.black.bgWhite("Dark x2"));
  922. diceResult.dark = diceResult.dark + 2;
  923. break;
  924. }
  925. }
  926. return diceResult;
  927. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement