Guest User

TS

a guest
Apr 12th, 2018
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*jshint esversion: 6*/
  2. const commando = require('discord.js-commando');
  3. const db = require('../config/db');
  4.  
  5. module.exports = {
  6.   tradeSkill: (msg, what, type, amount, userData, stats) => {
  7.     // Update userData
  8.     let userSQL = 'SELECT * FROM users_meta WHERE userid = ?';
  9.     db.query(userSQL, userData.id, (err, row) => {
  10.       userData.game = row[0];
  11.     });
  12.  
  13.     var matgain = null;
  14.     var expgain = null;
  15.  
  16.     let sql;
  17.  
  18.     // Start gathering Blocks
  19.     if (what === 'farming' || what === 'food') {
  20.       // exp and yield calculations
  21.       switch (type) {
  22.         case 'wheat':
  23.           matgain = (1 + userData.game.farming_matgain) - 1;
  24.           expgain = (1 + userData.game.farming_expgain) - 1;
  25.           break;
  26.         case 'carrot':
  27.           matgain = (1 + userData.game.farming_matgain) - 1;
  28.           expgain = (4 + userData.game.farming_expgain) - 1;
  29.           break;
  30.         case 'tomato':
  31.           matgain = (1 + userData.game.farming_matgain) - 1;
  32.           expgain = (9 + userData.game.farming_expgain) - 1;
  33.           break;
  34.         case 'cucumber':
  35.           matgain = (1 + userData.game.farming_matgain) - 1;
  36.           expgain = (16 + userData.game.farming_expgain) - 1;
  37.           break;
  38.         case 'potato':
  39.           matgain = (1 + userData.game.farming_matgain) - 1;
  40.           expgain = (25 + userData.game.farming_expgain) - 1;
  41.           break;
  42.         default:
  43.           return msg.reply('You did not produce the correct arguments');
  44.       }
  45.  
  46.       // Update table
  47.       sql = `UPDATE users_meta SET ${type} = ${type} + ${matgain}, tsexp = tsexp + ${expgain} WHERE userid = ?`;
  48.       db.query(sql, userData.id, (err) => {
  49.         if (err) { return console.log(err); }
  50.         stats.yield += matgain;
  51.         stats.exp += expgain;
  52.         stats.actions--;
  53.  
  54.       });
  55.  
  56.       if (stats.actions <= 0) {
  57.  
  58.         // The report DM
  59.         userData.send({ embed: {
  60.           color: 3447003,
  61.           title: `Farming Report For ${type}`,
  62.           fields: [{
  63.             name: 'Stats',
  64.             value:
  65.             'Gathered: ' + stats.yield +
  66.             '\nEXP Gained: ' + stats.exp,
  67.           },
  68.         ],
  69.         },
  70.         });
  71.  
  72.         //Reset stats for Report
  73.         stats = {
  74.           exp: 0,
  75.           actions: amount,
  76.           yield: 0,
  77.         };
  78.  
  79.       }
  80.  
  81.       // Start herbolgoy
  82.     } else if (what === 'herbology' || what === 'herbs') {
  83.       switch (type) {
  84.         case 'basil':
  85.           matgain = (1 + userData.game.herbology_matgain) - 1;
  86.           expgain = (1 + userData.game.herbology_expgain) - 1;
  87.           break;
  88.         case 'cilantro':
  89.           matgain = (1 + userData.game.herbology_matgain) - 1;
  90.           expgain = (4 + userData.game.herbology_expgain) - 1;
  91.           break;
  92.         case 'dill':
  93.           matgain = (1 + userData.game.herbology_matgain) - 1;
  94.           expgain = (9 + userData.game.herbology_expgain) - 1;
  95.           break;
  96.         case 'thyme':
  97.           matgain = (1 + userData.game.herbology_matgain) - 1;
  98.           expgain = (16 + userData.game.herbology_expgain) - 1;
  99.           break;
  100.         case 'garlic':
  101.           matgain = (1 + userData.game.herbology_matgain) - 1;
  102.           expgain = (25 + userData.game.herbology_expgain) - 1;
  103.           break;
  104.         default:
  105.           return msg.reply('You did not produce the correct arguments');
  106.       }
  107.  
  108.       // Update table
  109.       sql = `UPDATE users_meta SET ${type} = ${type} + ${matgain}, tsexp = tsexp + ${expgain} WHERE userid = ?`;
  110.       db.query(sql, userData.id, (err) => {
  111.         if (err) { return console.log(err); }
  112.  
  113.         stats.yield += matgain;
  114.         stats.exp += expgain;
  115.         stats.actions--;
  116.       });
  117.  
  118.       if (stats.actions <= 0) {
  119.         // The report DM
  120.         userData.send({ embed: {
  121.           color: 3447003,
  122.           title: `Herbology For ${type}`,
  123.           fields: [{
  124.             name: 'Stats',
  125.             value:
  126.             'Gathered: ' + stats.yield +
  127.             '\nEXP Gained: ' + stats.exp,
  128.           },
  129.         ],
  130.         },
  131.         });
  132.  
  133.         //Reset stats for Report
  134.         stats = {
  135.           exp: 0,
  136.           actions: amount,
  137.           yield: 0,
  138.         };
  139.       }
  140.  
  141.       // Start Hunting Block
  142.     } else if (what === 'hunting' || what === 'hunt') {
  143.       // exp and yield calculations
  144.       var scraps;
  145.       switch (type) {
  146.         case 'rabbit':
  147.           matgain = (1 + userData.game.hunting_matgain) - 1;
  148.           expgain = (1 + userData.game.hunting_expgain) - 1;
  149.           scraps = 'fur_scraps';
  150.           break;
  151.         case 'wolf':
  152.           matgain = (1 + userData.game.hunting_matgain) - 1;
  153.           expgain = (4 + userData.game.hunting_expgain) - 1;
  154.           scraps = 'pelt_scraps';
  155.           break;
  156.         case 'deer':
  157.           matgain = (1 + userData.game.hunting_matgain) - 1;
  158.           expgain = (9 + userData.game.hunting_expgain) - 1;
  159.           scraps = 'leather_scraps';
  160.           break;
  161.         case 'bear':
  162.           matgain = (1 + userData.game.hunting_matgain) - 1;
  163.           expgain = (16 + userData.game.hunting_expgain) - 1;
  164.           scraps = 'hide_scraps';
  165.           break;
  166.         case 'dragon':
  167.           matgain = (1 + userData.game.hunting_matgain) - 1;
  168.           expgain = (25 + userData.game.hunting_expgain) - 1;
  169.           scraps = 'scale_scraps';
  170.           break;
  171.         default:
  172.           return msg.reply('You did not produce the correct arguments');
  173.       }
  174.  
  175.       // Update table
  176.       sql = `UPDATE users_meta SET ${scraps} = ${scraps} + ${matgain}, tsexp = tsexp + ${expgain} WHERE userid = ?`;
  177.       db.query(sql, userData.id, (err) => {
  178.         if (err) { return console.log(err); }
  179.  
  180.         stats.yield += matgain;
  181.         stats.exp += expgain;
  182.         stats.actions--;
  183.       });
  184.  
  185.       if (stats.actions <= 0) {
  186.         // The report DM
  187.         userData.send({ embed: {
  188.           color: 3447003,
  189.           title: `Hunting Report For ${type}`,
  190.           fields: [{
  191.             name: 'Stats',
  192.             value:
  193.             'Gathered: ' + stats.yield + ' ' + scraps +
  194.             '\nEXP Gained: ' + stats.exp,
  195.           },
  196.         ],
  197.         },
  198.         });
  199.  
  200.         //Reset stats for Report
  201.         stats = {
  202.           exp: 0,
  203.           actions: amount,
  204.           yield: 0,
  205.         };
  206.       }
  207.     } else if (what === 'lumber' || what === 'wood') {
  208.       // exp and yield calculations
  209.       var logs;
  210.       switch (type) {
  211.         case 'oak':
  212.           matgain = (1 + userData.game.lumber_matgain) - 1;
  213.           expgain = (1 + userData.game.lumber_expgain) - 1;
  214.           logs = 'oak_logs';
  215.           break;
  216.         case 'birch':
  217.           matgain = (1 + userData.game.lumber_matgain) - 1;
  218.           expgain = (4 + userData.game.lumber_expgain) - 1;
  219.           logs = 'birch_logs';
  220.           break;
  221.         case 'cyrpuss':
  222.           matgain = (1 + userData.game.lumber_matgain) - 1;
  223.           expgain = (9 + userData.game.lumber_expgain) - 1;
  224.           logs = 'cypruss_logs';
  225.           break;
  226.         case 'pine':
  227.           matgain = (1 + userData.game.lumber_matgain) - 1;
  228.           expgain = (16 + userData.game.lumber_expgain) - 1;
  229.           logs = 'pine_logs';
  230.           break;
  231.         case 'spruce':
  232.           matgain = (1 + userData.game.lumber_matgain) - 1;
  233.           expgain = (25 + userData.game.lumber_expgain) - 1;
  234.           logs = 'spruce_logs';
  235.           break;
  236.         default:
  237.           return msg.reply('You did not produce the correct arguments');
  238.       }
  239.  
  240.       // Update table
  241.       sql = `UPDATE users_meta SET ${logs} = ${logs} + ${matgain}, tsexp = tsexp + ${expgain} WHERE userid = ?`;
  242.       db.query(sql, userData.id, (err) => {
  243.         if (err) { return console.log(err); }
  244.  
  245.         stats.yield += matgain;
  246.         stats.exp += expgain;
  247.         stats.actions--;
  248.       });
  249.  
  250.       if (stats.actions <= 0) {
  251.         // The report DM
  252.         userData.send({ embed: {
  253.           color: 3447003,
  254.           title: `Lumber Report For ${type}`,
  255.           fields: [{
  256.             name: 'Stats',
  257.             value:
  258.             'Gathered: ' + stats.yield +
  259.             '\nEXP Gained: ' + stats.exp,
  260.           },
  261.         ],
  262.         },
  263.         });
  264.  
  265.         //Reset stats for Report
  266.         stats = {
  267.           exp: 0,
  268.           actions: amount,
  269.           yield: 0,
  270.         };
  271.       }
  272.  
  273.       // Start mining block
  274.     } else if (what === 'mining' || what === 'mine') {
  275.       // exp and yield calculations
  276.       var ore;
  277.       switch (type) {
  278.         case 'copper':
  279.           matgain = (1 + userData.game.mining_matgain) - 1;
  280.           expgain = (1 + userData.game.mining_expgain) - 1;
  281.           ore = 'copper_ore';
  282.           break;
  283.         case 'iron':
  284.           matgain = (1 + userData.game.mining_matgain) - 1;
  285.           expgain = (4 + userData.game.mining_expgain) - 1;
  286.           ore = 'iron_ore';
  287.           break;
  288.         case 'silver':
  289.           matgain = (1 + userData.game.mining_matgain) - 1;
  290.           expgain = (9 + userData.game.mining_expgain) - 1;
  291.           ore = 'silver_ore';
  292.           break;
  293.         case 'malachite':
  294.           matgain = (1 + userData.game.mining_matgain) - 1;
  295.           expgain = (16 + userData.game.mining_expgain) - 1;
  296.           ore = 'malachite_ore';
  297.           break;
  298.         case 'cobalt':
  299.           matgain = (1 + userData.game.mining_matgain) - 1;
  300.           expgain = (25 + userData.game.mining_expgain) - 1;
  301.           ore = 'cobalt_ore';
  302.           break;
  303.         default:
  304.           return msg.reply('You did not produce the correct arguments');
  305.       }
  306.  
  307.       // Update table
  308.       sql = `UPDATE users_meta SET ${ore} = ${ore} + ${matgain}, tsexp = tsexp + ${expgain} WHERE userid = ?`;
  309.       db.query(sql, userData.id, (err) => {
  310.         if (err) { return console.log(err); }
  311.  
  312.         stats.yield += matgain;
  313.         stats.exp += expgain;
  314.         stats.actions--;
  315.       });
  316.  
  317.       if (stats.actions <= 0) {
  318.         // The report DM
  319.         userData.send({ embed: {
  320.           color: 3447003,
  321.           title: `Lumber Report For ${type}`,
  322.           fields: [{
  323.             name: 'Stats',
  324.             value:
  325.             'Gathered: ' + stats.yield +
  326.             '\nEXP Gained: ' + stats.exp,
  327.           },
  328.         ],
  329.         },
  330.         });
  331.  
  332.         //Reset stats for Report
  333.         stats = {
  334.           exp: 0,
  335.           actions: amount,
  336.           yield: 0,
  337.         };
  338.       }
  339.  
  340.       // start stone block
  341.     } else if (what === 'stone') {
  342.       // exp and yield calculations
  343.       var chunks;
  344.       switch (type) {
  345.         case 'basalt':
  346.           matgain = (1 + userData.game.mining_matgain) - 1;
  347.           expgain = (1 + userData.game.mining_expgain) - 1;
  348.           chunks = 'basalt_chunk';
  349.           break;
  350.         case 'granite':
  351.           matgain = (1 + userData.game.mining_matgain) - 1;
  352.           expgain = (4 + userData.game.mining_expgain) - 1;
  353.           chunks = 'granite_chunk';
  354.           break;
  355.         case 'quartz':
  356.           matgain = (1 + userData.game.mining_matgain) - 1;
  357.           expgain = (9 + userData.game.mining_expgain) - 1;
  358.           chunks = 'quartz_chunk';
  359.           break;
  360.         case 'marble':
  361.           matgain = (1 + userData.game.mining_matgain) - 1;
  362.           expgain = (16 + userData.game.mining_expgain) - 1;
  363.           chunks = 'marble_chunk';
  364.           break;
  365.         case 'obsidian':
  366.           matgain = (1 + userData.game.mining_matgain) - 1;
  367.           expgain = (25 + userData.game.mining_expgain) - 1;
  368.           chunks = 'obsidian_chunk';
  369.           break;
  370.         default:
  371.           return msg.reply('You did not produce the correct arguments');
  372.       }
  373.  
  374.       // Update table
  375.       sql = `UPDATE users_meta SET ${chunks} = ${chunks} + ${matgain}, tsexp = tsexp + ${expgain} WHERE userid = ?`;
  376.       db.query(sql, userData.id, (err) => {
  377.         if (err) { return console.log(err); }
  378.  
  379.         stats.yield += matgain;
  380.         stats.exp += expgain;
  381.         stats.actions--;
  382.       });
  383.  
  384.       if (stats.actions <= 0) {
  385.         // The report DM
  386.         userData.send({ embed: {
  387.           color: 3447003,
  388.           title: `Lumber Report For ${type}`,
  389.           fields: [{
  390.             name: 'Stats',
  391.             value:
  392.             'Gathered: ' + stats.yield +
  393.             '\nEXP Gained: ' + stats.exp,
  394.           },
  395.         ],
  396.         },
  397.         });
  398.  
  399.         //Reset stats for Report
  400.         stats = {
  401.           exp: 0,
  402.           actions: amount,
  403.           yield: 0,
  404.         };
  405.       }
  406.     }
  407.  
  408.   },
  409. };
Advertisement
Add Comment
Please, Sign In to add comment