Advertisement
Guest User

Pfft what, no I'm not drunk. I'm just a bit tipsy.

a guest
Oct 18th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require("discord.js");
  2. const FS = require("fs");
  3. const auth = require("./auth.json");
  4. const config = require("./config.json");
  5. var game = {};
  6.  
  7. var GameStates = Object.freeze({
  8.     IDLE: 'IDLE',
  9.     SETUP_GM: 'SETUP_GM',
  10.     SETUP_PL: 'SETUP_PL'
  11. });
  12.  
  13. var Races = Object.freeze({
  14.     HUMAN: {
  15.         name: 'Human',
  16.         classification: ['humanoid'],
  17.         description: 'Humans are unremarkable-looking humanoids that cover the surface of the globe. Their great intelligence, tight sense of community, and natural resilience allowed them to become the most represented race in the world, with several million inhabitants. They favour bladed weapons, shields, and protective magic for combat. They make spectacular traders and diplomats.',
  18.         specs: {
  19.             constitution: 2,
  20.             intelligence: 2,
  21.             charisma: 2
  22.         },
  23.         skills: {
  24.             bartering: 5,
  25.             diplomacy: 5,
  26.             persuasion: 3,
  27.             defensive_spellcraft: 3,
  28.             bladed_weapons: 3,
  29.             shielding: 3
  30.         }
  31.     },
  32.     HIGHELF: {
  33.         name: 'High Elf',
  34.         classification: ['elf', 'solitary', 'humanoid'],
  35.         description: 'High elves are slender figures known for their elegance and swiftness. High elven communities are ruled by a noble corps, and are highly hierarchized into three strata, the noble class, the warrior class, and the commoner class. They live in very large citadels, scarcely scattered around the globe. Their agility is spectacular, even among other elves, and they make highly skilled marksmen.',
  36.         specs: {
  37.             dexterity: 4,
  38.             charisma: 2
  39.         },
  40.         skills: {
  41.             marksmanship: 5,
  42.             instinct: 5,
  43.             agility: 3,
  44.             stealth: 3,
  45.             concentration: 3,
  46.             evasion: 3
  47.         }
  48.     },
  49.     HALFELF: {
  50.         name: 'Half Elf',
  51.         classification: ['elf', 'humanoid'],
  52.         description: 'Half elves are the result of an union between humans and elves. Despite their lineage, half elven are not permitted entry within high elven citadels, being forced to live with humans instead. Though still agile, they are not completely on par with their high elven predecessors. They do, however, boast superior strength. They make capable warriors, preferring the long range of polearms and spears over their high elven weaponry.',
  53.         specs: {
  54.             strength: 2,
  55.             dexterity: 2,
  56.             charisma: 2
  57.         },
  58.         skills: {
  59.             thrusting_weapons: 5,
  60.             evasion: 5,
  61.             instinct: 3,
  62.             stealth: 3,
  63.             lockpicking: 3,
  64.             alchemy: 3
  65.         }
  66.     },
  67.     DWARF: {
  68.         name: 'Dwarf',
  69.         classificaton: ['subterranean', 'humanoid'],
  70.         description: 'Dwarves are an ancient species of subterranean humanoids, usually found living in fortresses built inside of mountains. Dwarven fortresses are ruled by an absolute king. They boast tremendous strength despite their shorter body, and favour blunt weapons along with sturdy shields. They make amazing brawlers and superb craftsmen.',
  71.         specs: {
  72.             strength: 4,
  73.             constitution: 2
  74.         },
  75.         skills: {
  76.             craftmanship: 8,
  77.             blunt_weapons: 5,
  78.             shielding: 5,
  79.             intimidation: 3,
  80.             unarmed: 3,
  81.             spellcraft: -2
  82.         }
  83.     },
  84.     ORC: {
  85.         name: 'Orc',
  86.         classification: ['unloved', 'humanoid'],
  87.         description: 'Orcs are robust, tall beings, usually found living nomadic lives in small tribal communities. Tribes are usually ruled by the strongest male orc, and he gets to decide where the tribe goes. Orcs are very strong and hardy, albeit sort of unpleasant to look at. They are master swordmen, and boast good magic compatibility. They are awe-inspiring fighters capable of conbat magic.',
  88.         specs: {
  89.             strength: 3,
  90.             constitution: 3,
  91.             intelligence: 1,
  92.             charisma: -1
  93.         },
  94.         skills: {
  95.             bladed_weapons: 8,
  96.             craftmanship: 5,
  97.             intimidation: 5,
  98.             offensive_spellcraft: 3,
  99.             instinct: 3,
  100.             lore: 3,
  101.             stealth: -2,
  102.             diplomacy: -2,
  103.             supportive_spellcraft: -3
  104.         }
  105.     },
  106.     GOBLIN: {
  107.         name: 'Goblin',
  108.         classification: ['unloved', 'subterranean', 'humanoid'],
  109.         description: '',
  110.         specs: {
  111.             dexterity: 3,
  112.             intelligence: 3
  113.         }
  114.     },
  115.     SPIRIT: '',
  116.     BEASTLING: '',
  117.     INCHLING: '',
  118.     DEMON: '',
  119.     UNDEAD: ''
  120. });
  121.  
  122. // Initialize Discord Bot
  123. const client = new Discord.Client();
  124.  
  125. client.on("ready", () => {
  126.     console.log("AI Scroll V" + config.version);
  127.     console.log("");
  128.  
  129.     console.log("Initial settings ready");
  130.     console.log("All systems nominal!");
  131.     console.log("");
  132.  
  133.     reset();
  134. });
  135.  
  136. /**
  137.  * Callback on message (in any server where AIScroll is enabled)
  138.  */
  139. client.on('message', message => {
  140.     if (message.content.substring(0, 1) == config.prefix) {
  141.         var args = message.content.substring(1).split(' ');
  142.         var cmd = args[0];
  143.         args = args.splice(1);
  144.  
  145.         if (GameState() == GameStates.IDLE) {
  146.  
  147.             // Idle state, waiting for someone to initiate a game
  148.             switch(cmd) {
  149.                 case 'newgame':
  150.                     game.initiator = message.author;
  151.                     game.gameid = Math.floor(Math.random() * 1000000000);
  152.  
  153.                     console.log(getTime() + ' [SETUP] ' + game.initiator.username + ' initiated a new game with id \'' + game.gameid + '\'.');
  154.                     game.gamemaster = game.initiator;
  155.  
  156.                     message.channel.send('Let\'s start a new game!');
  157.                     message.channel.send('<@' + game.initiator.id + '>: Who will be the players? There can be up to four!');
  158.  
  159.                     setState(GameStates.SETUP_GM);
  160.                     return;
  161.  
  162.                 case 'loadgame':
  163.                     console.log('[SETUP] Loading game... not yet functional');
  164.                     return;
  165.             }
  166.  
  167.         } else if (GameState() == GameStates.SETUP_GM) {
  168.  
  169.             // Game setup, initializes the number and names of the participants
  170.             if (message.author == game.initiator) {
  171.                 switch(cmd) {
  172.                     case 'set':
  173.                         if (args.length < 1) {
  174.                             message.channel.send("We need at least one player!");
  175.                             return;
  176.                         }
  177.                         if (args.length > 4) {
  178.                             message.channel.send("We can't play with over four players!");
  179.                             return;
  180.                         }
  181.  
  182.                         for (var i = 0; i < args.length; i++) {
  183.                             game.players[i] = getUserByMention(args[i]);
  184.                         }
  185.                         message.channel.send(getPlayers());
  186.  
  187.                         message.channel.send('Shall we begin?');
  188.  
  189.                         return;
  190.  
  191.                     case 'start':
  192.                         if (game.players.length <= 0 || game.players.length > 4) {
  193.                             message.channel.send('Invalid number of players! We currently have ' + game.players.length + ' players and can have up to 4.');
  194.                             return;
  195.                         }
  196.  
  197.                         console.log(getTime() + '[SETUP] Starting game \'' + game.gameid + '\'. This process will create 6 text channels, and one voice channel.');
  198.  
  199.                         message.channel.send('Let\'s go then!');
  200.                         message.channel.send('<@' + game.gamemaster.id + '>: You are the gamemaster, here is your game ID: `' + game.gameid + '`.');
  201.                         message.channel.send('Do not forget it! You can load your game with this ID in the future.');
  202.  
  203.                         game.guild = message.guild;
  204.  
  205.                         // Creates the 3 to 6 channels for the game to take place in
  206.                         game.guild.createChannel('Game', 'category').then((channel) => {
  207.                             console.log(getTime() + ' [CHANNEL] Created ' + channel.type + ' channel \'' + channel.name + '\' successfully.');
  208.                             game.gamechan = channel;
  209.                         });
  210.  
  211.                         game.guild.createChannel('gamemaster').then((channel) => {
  212.                             console.log(getTime() + ' [CHANNEL] Created ' + channel.type + ' channel \'' + channel.name + '\' successfully.');
  213.                             channel.setParent(game.gamechan)
  214.                         });
  215.                         game.guild.createChannel('party').then((channel) => {
  216.                             console.log(getTime() + ' [CHANNEL] Created ' + channel.type + ' channel \'' + channel.name + '\' successfully.');
  217.                             channel.setParent(game.gamechan)
  218.                         });
  219.                         game.guild.createChannel('Game', 'voice').then((channel) => {
  220.                             console.log(getTime() + ' [CHANNEL] Created ' + channel.type + ' channel \'' + channel.name + '\' successfully.');
  221.                             channel.setParent(game.gamechan)
  222.                         });
  223.                        
  224.                         for (i = 0; i < game.players.length; i++) {
  225.                             game.guild.createChannel(game.players[i]).then((channel) => {
  226.                             console.log(getTime() + ' [CHANNEL] Created ' + channel.type + ' channel \'' + channel.name + '\' successfully.');
  227.                             channel.setParent(game.gamechan)
  228.                         });
  229.                         }
  230.  
  231.                         setState(GameStates.SETUP_PL);
  232.  
  233.                         return;
  234.  
  235.                     case 'cancel':
  236.                         message.channel.send('Fair enough, we\'ll play later.');
  237.                         reset();
  238.                 }
  239.             } else if (GameState() == GameStates.SETUP_PL) {
  240.  
  241.                 // Game setup, initializes player characters, character sheet creation
  242.                 // TODO
  243.  
  244.             }
  245.  
  246.         }
  247.     }
  248. });
  249.  
  250. function setState(state) {
  251.     console.log(getTime() + ' [STATE] Setting state to ' + state + '.');
  252.  
  253.     game.state = state;
  254.     return GameState();
  255. }
  256. function GameState() {
  257.     return game.state; 
  258. }
  259.  
  260. function getTime() {
  261.     var d = new Date();
  262.     h = (d.getHours()<10?'0':'') + d.getHours(),
  263.     m = (d.getMinutes()<10?'0':'') + d.getMinutes();
  264.     s = (d.getSeconds()<10?'0':'') + d.getSeconds();
  265.     return h + ':' + m + ':' + s;
  266. }
  267.  
  268. function getUserByMention(mention) {
  269.     return mention.replace(/[\\<>@#&!]/g, "");
  270. }
  271.  
  272. function getPlayers() {
  273.     if (game.players.length == 1) return '<@' + game.players[0] + '> is the sole player.';
  274.     if (game.players.length == 2) return '<@' + game.players[0] + '> and <@' + game.players[1] + '> are our two players.';
  275.     if (game.players.length == 3) return '<@' + game.players[0] + '>, <@' + game.players[1] + '> and <@' + game.players[2] + '> are our three players.';
  276.     if (game.players.length == 4) return '<@' + game.players[0] + '>, <@' + game.players[1] + '>, <@' + game.players[2] + '> and <@' + game.players[3] + '> are our four players.';
  277. }
  278.  
  279. function getGamemaster() {
  280.     if (game.gamemaster == "") return 'We do not have a gamemaster!';
  281.     else return game.gamemaster.username + ' is our gamemaster!';
  282. }
  283.  
  284. function reset() {
  285.     game = {};
  286.     game.players = [];
  287.     game.gamemaster = "";
  288.  
  289.     setState(GameStates.IDLE);
  290. }
  291.  
  292. function createChar() {
  293.     defaultChar = {
  294.         desc: {
  295.             name: '',
  296.             race: '',
  297.             profession: '',
  298.             deity: '',
  299.             alignment: 0
  300.         },
  301.         vitals: {
  302.             hp: 20,
  303.             mp: 10,
  304.             lvl: 1,
  305.             exp: 0
  306.         },
  307.         stats: {
  308.             strength: 10,
  309.             dexterity: 10,
  310.             constitution: 10,
  311.             intelligence: 10,
  312.             charisma: 10
  313.         },
  314.         skills: {
  315.             alchemy: 0,
  316.             bartering: 0,
  317.             persuasion: 0,
  318.             diplomacy: 0,
  319.             intimidation: 0,
  320.             craftmanship: 0,
  321.             stealth: 0,
  322.             lore: 0,
  323.             observation: 0,
  324.             instinct: 0,
  325.             spellcraft: 0,
  326.             offensive_spellcraft: 0,
  327.             defensive_spellcraft: 0,
  328.             supportive_spellcraft: 0,
  329.             bladed_weapons: 0,
  330.             blunt_weapons: 0,
  331.             thrusting_weapons: 0,
  332.             marksmanship: 0,
  333.             unarmed: 0,
  334.             shielding: 0,
  335.             lockpicking: 0,
  336.             concentration: 0,
  337.             agility: 0,
  338.             evasion: 0
  339.         }
  340.     }
  341. }
  342.  
  343. client.login(auth.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement