Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ```
  2. module.exports.scavangeCommand = function (message){
  3.     var discordUserId = message.author.id;
  4.    
  5.     // roll the number of items to get
  6.     var tacoRoll = Math.floor(Math.random() * 100) + 1;
  7.     var tacosFound = 0
  8.     var rolls = Math.floor(Math.random() * 100) + 1;
  9.     var rollsCount = 1;
  10.     // 25 + = 2, 80 + = 3, 95 + = 4, 98 + = 5
  11.     if (rolls > 98){
  12.         rollsCount = 5;
  13.     }
  14.     else if (rolls > 95){
  15.         rollsCount = 4;
  16.     }
  17.     else if (rolls > 80){
  18.         rollsCount = 3;
  19.     }
  20.     else if (rolls > 25){
  21.         rollsCount = 2;
  22.     }
  23.     else{
  24.         rollsCount = 1
  25.     }
  26.     // only scavenge if the user has a pickaxe
  27.     profileDB.getUserProfileData( discordUserId, function(error, getUserResponse) {
  28.         if(error){
  29.             console.log(error);
  30.             // create user profile then send a message saying they need a pickaxe
  31.             var userData = initialUserProfile(discordUserId);
  32.  
  33.             profileDB.createUserProfile(userData, function(error, createUserResponse){
  34.                 if (error){
  35.                     console.log(error); // cant create user RIP
  36.                 }
  37.                 else{
  38.                     message.channel.send(message.author + " You need a pickaxe!");
  39.                 }
  40.             })
  41.         }
  42.         else if (getUserResponse.data.pickaxe && getUserResponse.data.pickaxe != "none"){
  43.             // get all the possible items from items DB - Bad implementation but idgaf
  44.             var userLevel = getUserResponse.data.level;
  45.             wearStats.getUserWearingStats(message, discordUserId, userLevel, function(wearErr, wearRes){
  46.                 if (wearErr){
  47.                     console.log(wearErr);
  48.                 }else{
  49.                     var minutesToRemove = wearStats.calculateMinutesReduced(wearRes, "scavenge");
  50.                     console.log("MINUTES TO REMOVE " + minutesToRemove);
  51.                     //check for more than 1 hours
  52.                     var now = new Date();
  53.                     var oneHourAgo = new Date();
  54.                     ///////// CALCULATE THE MINUTES REDUCED HERE
  55.                     oneHourAgo = new Date(oneHourAgo.setHours(oneHourAgo.getHours() - SCAVENGE_COOLDOWN_HOURS));
  56.                     oneHourAgo = new Date(oneHourAgo.setMinutes(oneHourAgo.getMinutes() + minutesToRemove));
  57.  
  58.                     if ( oneHourAgo > getUserResponse.data.lastscavangetime ){
  59.                         profileDB.getItemData(function(err, getItemResponse){
  60.                             if (err){
  61.                                 console.log(err);
  62.                             }
  63.                             else{
  64.                                 var ARTIFACT_MIN_ROLL = 9995;
  65.                                 var ANCIENT_MAX_ROLL = 9995
  66.                                 var ANCIENT_MIN_ROLL = 9975;
  67.                                 var RARE_MAX_ROLL = 9975;
  68.                                 var RARE_MIN_ROLL = 9800;
  69.                                 var UNCOMMON_MAX_ROLL = 9800;
  70.                                 var UNCOMMON_MIN_ROLL = 8000;
  71.                                 var COMMON_MAX_ROLL = 8000;
  72.                                 var COMMON_ITEMS_TO_OBTAIN = 1;
  73.                                 var TACOS_FOUND_MULTIPLIER = 1;
  74.                                 var EXPERIENCE_MULTIPLIER = 1;
  75.  
  76.                                 if (getUserResponse.data.pickaxe == "improved"){
  77.                                     COMMON_ITEMS_TO_OBTAIN = 3
  78.                                     TACOS_FOUND_MULTIPLIER = 3
  79.                                     ARTIFACT_MIN_ROLL = 9992
  80.                                     ANCIENT_MAX_ROLL = 9992;
  81.                                     ANCIENT_MIN_ROLL = 9955;
  82.                                     RARE_MAX_ROLL = 9955;
  83.                                     RARE_MIN_ROLL = 9750;
  84.                                     UNCOMMON_MAX_ROLL = 9750;
  85.                                     EXPERIENCE_MULTIPLIER = 2;
  86.  
  87.                                 }
  88.                                 else if (getUserResponse.data.pickaxe == "master"){
  89.                                     COMMON_ITEMS_TO_OBTAIN = 7
  90.                                     TACOS_FOUND_MULTIPLIER = 8
  91.                                     EXPERIENCE_MULTIPLIER = 6
  92.                                 }
  93.  
  94.                                 var allItems = getItemResponse.data
  95.                                 var commonItems = [];
  96.                                 var uncommonItems = [];
  97.                                 var rareItems = [];
  98.                                 var ancientItems = [];
  99.                                 var artifactItems = [];
  100.                                 var mythItems = [];
  101.                                 // TODO: add check for rarity chance % to be > 0
  102.                                 for (var item in allItems){
  103.                                     if (allItems[item].itemraritycategory == "common"){
  104.                                         commonItems.push(allItems[item]);
  105.                                     }
  106.                                     else if(allItems[item].itemraritycategory == "uncommon"){
  107.                                         uncommonItems.push(allItems[item]);
  108.                                     }
  109.                                     else if(allItems[item].itemraritycategory == "rare"){
  110.                                         rareItems.push(allItems[item]);
  111.                                     }
  112.                                     else if(allItems[item].itemraritycategory == "ancient"){
  113.                                         ancientItems.push(allItems[item]);
  114.                                     }
  115.                                     else if(allItems[item].itemraritycategory == "artifact"){
  116.                                         artifactItems.push(allItems[item]);
  117.                                     }
  118.                                     else if(allItems[item].itemraritycategory == "myth"){
  119.                                         mythItems.push(allItems[item]);
  120.                                     }
  121.                                 }
  122.                                 // roll rarity, roll item from rarity
  123.                                 var gotUncommon = false;
  124.                                 var itemsObtainedArray = [];
  125.                                 var highestRarityFound = 1
  126.  
  127.                                 for (var i = 0; i < rollsCount; i++){
  128.                                     var rarityRoll = Math.floor(Math.random() * 10000) + 1;
  129.                                     var rarityString = "";
  130.                                     console.log(rarityRoll);
  131.                                     if (!gotUncommon && rollsCount > 4){
  132.                                         // guaranteed more than uncommon +
  133.                                         rarityRoll = Math.floor(Math.random() * 1500) + 8501;
  134.                                         gotUncommon = true;
  135.                                     }
  136.                                     else if(!gotUncommon && rollsCount > 3){
  137.                                         // guaranteed uncommon +
  138.                                         rarityRoll = Math.floor(Math.random() * 2000) + 8001;
  139.                                         gotUncommon = true;
  140.                                     }
  141.                                     if (rarityRoll > ARTIFACT_MIN_ROLL){
  142.                                         rarityString = "artifact"
  143.                                         var itemRoll = Math.floor(Math.random() * artifactItems.length);
  144.                                         console.log(artifactItems[itemRoll]);
  145.                                         itemsObtainedArray.push(artifactItems[itemRoll]);
  146.                                         if (highestRarityFound <= 4){
  147.                                             highestRarityFound = 5;
  148.                                         }
  149.                                     }
  150.                                     else if(rarityRoll > ANCIENT_MIN_ROLL && rarityRoll <= ANCIENT_MAX_ROLL){
  151.                                         rarityString = "ancient"
  152.                                         var itemRoll = Math.floor(Math.random() * ancientItems.length);
  153.                                         console.log(ancientItems[itemRoll]);
  154.                                         itemsObtainedArray.push(ancientItems[itemRoll])
  155.                                         if (highestRarityFound <= 3){
  156.                                             highestRarityFound = 4;
  157.                                         }
  158.                                     }
  159.                                     else if(rarityRoll > RARE_MIN_ROLL && rarityRoll <= RARE_MAX_ROLL){
  160.                                         rarityString = "rare"
  161.                                         var itemRoll = Math.floor(Math.random() * rareItems.length);
  162.                                         console.log(rareItems[itemRoll]);
  163.                                         itemsObtainedArray.push(rareItems[itemRoll]);
  164.                                         if (highestRarityFound <= 2){
  165.                                             highestRarityFound = 3;
  166.                                         }
  167.                                     }
  168.                                     else if (rarityRoll > UNCOMMON_MIN_ROLL && rarityRoll <= UNCOMMON_MAX_ROLL){
  169.                                         rarityString = "uncommon"
  170.                                         var itemRoll = Math.floor(Math.random() * uncommonItems.length);
  171.                                         console.log(uncommonItems[itemRoll]);
  172.                                         itemsObtainedArray.push( uncommonItems[itemRoll] );
  173.                                         if (highestRarityFound <= 1){
  174.                                             highestRarityFound = 2;
  175.                                         }
  176.                                     }
  177.                                     else {
  178.                                         rarityString = "common"
  179.                                         var itemRoll = Math.floor(Math.random() * commonItems.length);
  180.                                         console.log(commonItems[itemRoll]);
  181.                                         commonItems[itemRoll].itemAmount = COMMON_ITEMS_TO_OBTAIN
  182.                                         itemsObtainedArray.push( commonItems[itemRoll] );
  183.                                     }
  184.                                 }
  185.                                 if (tacoRoll > SCAVENGE_TACO_FIND_CHANCE_HIGHER){
  186.                                     tacosFound = 2 * TACOS_FOUND_MULTIPLIER;
  187.                                 }
  188.                                 else if(tacoRoll > SCAVENGE_TACO_FIND_CHANCE){
  189.                                     tacosFound = 1 * TACOS_FOUND_MULTIPLIER;
  190.                                 }
  191.                                 // send the items to be written all at once
  192.                                 addToUserInventory(discordUserId, itemsObtainedArray);
  193.  
  194.                                 // send message of all items obtained
  195.                                 scavengeEmbedBuilder(message, itemsObtainedArray, tacosFound);
  196.                                 // update lastscavengetime
  197.                                 profileDB.updateLastScavengeTime(discordUserId, function(updateLSErr, updateLSres){
  198.                                     if(updateLSErr){
  199.                                         console.log(updateLSErr);
  200.                                     }
  201.                                     else{
  202.                                         console.log(updateLSres);
  203.                                         experience.gainExperience(message, discordUserId, EXPERIENCE_GAINS.scavenge * EXPERIENCE_MULTIPLIER, getUserResponse);
  204.                                     }
  205.                                 })
  206.                                 // add the tacos to user
  207.                                 ///////// CALCULATE THE EXTRA TACOS HERE
  208.                                 var extraTacosFromItems = wearStats.calculateExtraTacos(wearRes, "scavenge"); // 0 or extra
  209.                                 if (extraTacosFromItems > 0){
  210.                                     message.channel.send(message.author + " received `" + extraTacosFromItems + "` for scavenging! :taco:" + " received `" + extraTacosFromItems + "` extra tacos" );
  211.                                 }
  212.                                 profileDB.updateUserTacos(discordUserId, tacosFound + extraTacosFromItems, function(updateLSErr, updateLSres){
  213.                                     if(updateLSErr){
  214.                                         console.log(updateLSErr);
  215.                                     }
  216.                                     else{
  217.                                         console.log(updateLSres);
  218.                                         // add to statistics
  219.                                         var achievements = getUserResponse.data.achievements;
  220.                                         stats.statisticsManage(discordUserId, "scavengecount", 1, function(err, statSuccess){
  221.                                             if (err){
  222.                                                 console.log(err);
  223.                                             }
  224.                                             else{
  225.                                                 // check achievements
  226.                                                 var data = {}
  227.                                                 data.achievements = achievements;
  228.                                                 // add the highestRarity
  229.                                                 if (highestRarityFound == 5){
  230.                                                     data.rarity = "artifact"
  231.                                                 }
  232.                                                 else if (highestRarityFound == 4){
  233.                                                     data.rarity = "ancient"
  234.                                                 }
  235.                                                 else if (highestRarityFound == 3){
  236.                                                     data.rarity = "rare"
  237.                                                 }
  238.                                                 else if (highestRarityFound == 2){
  239.                                                     data.rarity = "uncommon"
  240.                                                 }
  241.                                                 if (highestRarityFound == 1){
  242.                                                     data.rarity = "common"
  243.                                                 }
  244.                                                 console.log(data);
  245.                                                 achiev.checkForAchievements(discordUserId, data, message);
  246.                                             }
  247.                                         })
  248.                                     }
  249.                                 })
  250.                             }
  251.                         })
  252.                     }
  253.                     else{
  254.                         now = new Date(now.setMinutes(now.getMinutes() + minutesToRemove));
  255.                         var numberOfHours = getDateDifference(getUserResponse.data.lastscavangetime, now, 1);
  256.                         message.channel.send(message.author + " You have scavenged too recently! please wait `" + numberOfHours +"` ");
  257.                     }
  258.                 }
  259.             })
  260.            
  261.         }
  262.         else{
  263.             message.channel.send(message.author + " You need a pickaxe!");
  264.         }
  265.     })
  266. }
  267. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement