Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ```
- module.exports.scavangeCommand = function (message){
- var discordUserId = message.author.id;
- // roll the number of items to get
- var tacoRoll = Math.floor(Math.random() * 100) + 1;
- var tacosFound = 0
- var rolls = Math.floor(Math.random() * 100) + 1;
- var rollsCount = 1;
- // 25 + = 2, 80 + = 3, 95 + = 4, 98 + = 5
- if (rolls > 98){
- rollsCount = 5;
- }
- else if (rolls > 95){
- rollsCount = 4;
- }
- else if (rolls > 80){
- rollsCount = 3;
- }
- else if (rolls > 25){
- rollsCount = 2;
- }
- else{
- rollsCount = 1
- }
- // only scavenge if the user has a pickaxe
- profileDB.getUserProfileData( discordUserId, function(error, getUserResponse) {
- if(error){
- console.log(error);
- // create user profile then send a message saying they need a pickaxe
- var userData = initialUserProfile(discordUserId);
- profileDB.createUserProfile(userData, function(error, createUserResponse){
- if (error){
- console.log(error); // cant create user RIP
- }
- else{
- message.channel.send(message.author + " You need a pickaxe!");
- }
- })
- }
- else if (getUserResponse.data.pickaxe && getUserResponse.data.pickaxe != "none"){
- // get all the possible items from items DB - Bad implementation but idgaf
- var userLevel = getUserResponse.data.level;
- wearStats.getUserWearingStats(message, discordUserId, userLevel, function(wearErr, wearRes){
- if (wearErr){
- console.log(wearErr);
- }else{
- var minutesToRemove = wearStats.calculateMinutesReduced(wearRes, "scavenge");
- console.log("MINUTES TO REMOVE " + minutesToRemove);
- //check for more than 1 hours
- var now = new Date();
- var oneHourAgo = new Date();
- ///////// CALCULATE THE MINUTES REDUCED HERE
- oneHourAgo = new Date(oneHourAgo.setHours(oneHourAgo.getHours() - SCAVENGE_COOLDOWN_HOURS));
- oneHourAgo = new Date(oneHourAgo.setMinutes(oneHourAgo.getMinutes() + minutesToRemove));
- if ( oneHourAgo > getUserResponse.data.lastscavangetime ){
- profileDB.getItemData(function(err, getItemResponse){
- if (err){
- console.log(err);
- }
- else{
- var ARTIFACT_MIN_ROLL = 9995;
- var ANCIENT_MAX_ROLL = 9995
- var ANCIENT_MIN_ROLL = 9975;
- var RARE_MAX_ROLL = 9975;
- var RARE_MIN_ROLL = 9800;
- var UNCOMMON_MAX_ROLL = 9800;
- var UNCOMMON_MIN_ROLL = 8000;
- var COMMON_MAX_ROLL = 8000;
- var COMMON_ITEMS_TO_OBTAIN = 1;
- var TACOS_FOUND_MULTIPLIER = 1;
- var EXPERIENCE_MULTIPLIER = 1;
- if (getUserResponse.data.pickaxe == "improved"){
- COMMON_ITEMS_TO_OBTAIN = 3
- TACOS_FOUND_MULTIPLIER = 3
- ARTIFACT_MIN_ROLL = 9992
- ANCIENT_MAX_ROLL = 9992;
- ANCIENT_MIN_ROLL = 9955;
- RARE_MAX_ROLL = 9955;
- RARE_MIN_ROLL = 9750;
- UNCOMMON_MAX_ROLL = 9750;
- EXPERIENCE_MULTIPLIER = 2;
- }
- else if (getUserResponse.data.pickaxe == "master"){
- COMMON_ITEMS_TO_OBTAIN = 7
- TACOS_FOUND_MULTIPLIER = 8
- EXPERIENCE_MULTIPLIER = 6
- }
- var allItems = getItemResponse.data
- var commonItems = [];
- var uncommonItems = [];
- var rareItems = [];
- var ancientItems = [];
- var artifactItems = [];
- var mythItems = [];
- // TODO: add check for rarity chance % to be > 0
- for (var item in allItems){
- if (allItems[item].itemraritycategory == "common"){
- commonItems.push(allItems[item]);
- }
- else if(allItems[item].itemraritycategory == "uncommon"){
- uncommonItems.push(allItems[item]);
- }
- else if(allItems[item].itemraritycategory == "rare"){
- rareItems.push(allItems[item]);
- }
- else if(allItems[item].itemraritycategory == "ancient"){
- ancientItems.push(allItems[item]);
- }
- else if(allItems[item].itemraritycategory == "artifact"){
- artifactItems.push(allItems[item]);
- }
- else if(allItems[item].itemraritycategory == "myth"){
- mythItems.push(allItems[item]);
- }
- }
- // roll rarity, roll item from rarity
- var gotUncommon = false;
- var itemsObtainedArray = [];
- var highestRarityFound = 1
- for (var i = 0; i < rollsCount; i++){
- var rarityRoll = Math.floor(Math.random() * 10000) + 1;
- var rarityString = "";
- console.log(rarityRoll);
- if (!gotUncommon && rollsCount > 4){
- // guaranteed more than uncommon +
- rarityRoll = Math.floor(Math.random() * 1500) + 8501;
- gotUncommon = true;
- }
- else if(!gotUncommon && rollsCount > 3){
- // guaranteed uncommon +
- rarityRoll = Math.floor(Math.random() * 2000) + 8001;
- gotUncommon = true;
- }
- if (rarityRoll > ARTIFACT_MIN_ROLL){
- rarityString = "artifact"
- var itemRoll = Math.floor(Math.random() * artifactItems.length);
- console.log(artifactItems[itemRoll]);
- itemsObtainedArray.push(artifactItems[itemRoll]);
- if (highestRarityFound <= 4){
- highestRarityFound = 5;
- }
- }
- else if(rarityRoll > ANCIENT_MIN_ROLL && rarityRoll <= ANCIENT_MAX_ROLL){
- rarityString = "ancient"
- var itemRoll = Math.floor(Math.random() * ancientItems.length);
- console.log(ancientItems[itemRoll]);
- itemsObtainedArray.push(ancientItems[itemRoll])
- if (highestRarityFound <= 3){
- highestRarityFound = 4;
- }
- }
- else if(rarityRoll > RARE_MIN_ROLL && rarityRoll <= RARE_MAX_ROLL){
- rarityString = "rare"
- var itemRoll = Math.floor(Math.random() * rareItems.length);
- console.log(rareItems[itemRoll]);
- itemsObtainedArray.push(rareItems[itemRoll]);
- if (highestRarityFound <= 2){
- highestRarityFound = 3;
- }
- }
- else if (rarityRoll > UNCOMMON_MIN_ROLL && rarityRoll <= UNCOMMON_MAX_ROLL){
- rarityString = "uncommon"
- var itemRoll = Math.floor(Math.random() * uncommonItems.length);
- console.log(uncommonItems[itemRoll]);
- itemsObtainedArray.push( uncommonItems[itemRoll] );
- if (highestRarityFound <= 1){
- highestRarityFound = 2;
- }
- }
- else {
- rarityString = "common"
- var itemRoll = Math.floor(Math.random() * commonItems.length);
- console.log(commonItems[itemRoll]);
- commonItems[itemRoll].itemAmount = COMMON_ITEMS_TO_OBTAIN
- itemsObtainedArray.push( commonItems[itemRoll] );
- }
- }
- if (tacoRoll > SCAVENGE_TACO_FIND_CHANCE_HIGHER){
- tacosFound = 2 * TACOS_FOUND_MULTIPLIER;
- }
- else if(tacoRoll > SCAVENGE_TACO_FIND_CHANCE){
- tacosFound = 1 * TACOS_FOUND_MULTIPLIER;
- }
- // send the items to be written all at once
- addToUserInventory(discordUserId, itemsObtainedArray);
- // send message of all items obtained
- scavengeEmbedBuilder(message, itemsObtainedArray, tacosFound);
- // update lastscavengetime
- profileDB.updateLastScavengeTime(discordUserId, function(updateLSErr, updateLSres){
- if(updateLSErr){
- console.log(updateLSErr);
- }
- else{
- console.log(updateLSres);
- experience.gainExperience(message, discordUserId, EXPERIENCE_GAINS.scavenge * EXPERIENCE_MULTIPLIER, getUserResponse);
- }
- })
- // add the tacos to user
- ///////// CALCULATE THE EXTRA TACOS HERE
- var extraTacosFromItems = wearStats.calculateExtraTacos(wearRes, "scavenge"); // 0 or extra
- if (extraTacosFromItems > 0){
- message.channel.send(message.author + " received `" + extraTacosFromItems + "` for scavenging! :taco:" + " received `" + extraTacosFromItems + "` extra tacos" );
- }
- profileDB.updateUserTacos(discordUserId, tacosFound + extraTacosFromItems, function(updateLSErr, updateLSres){
- if(updateLSErr){
- console.log(updateLSErr);
- }
- else{
- console.log(updateLSres);
- // add to statistics
- var achievements = getUserResponse.data.achievements;
- stats.statisticsManage(discordUserId, "scavengecount", 1, function(err, statSuccess){
- if (err){
- console.log(err);
- }
- else{
- // check achievements
- var data = {}
- data.achievements = achievements;
- // add the highestRarity
- if (highestRarityFound == 5){
- data.rarity = "artifact"
- }
- else if (highestRarityFound == 4){
- data.rarity = "ancient"
- }
- else if (highestRarityFound == 3){
- data.rarity = "rare"
- }
- else if (highestRarityFound == 2){
- data.rarity = "uncommon"
- }
- if (highestRarityFound == 1){
- data.rarity = "common"
- }
- console.log(data);
- achiev.checkForAchievements(discordUserId, data, message);
- }
- })
- }
- })
- }
- })
- }
- else{
- now = new Date(now.setMinutes(now.getMinutes() + minutesToRemove));
- var numberOfHours = getDateDifference(getUserResponse.data.lastscavangetime, now, 1);
- message.channel.send(message.author + " You have scavenged too recently! please wait `" + numberOfHours +"` ");
- }
- }
- })
- }
- else{
- message.channel.send(message.author + " You need a pickaxe!");
- }
- })
- }
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement