Advertisement
Guest User

MelvorIdle - Auto planter by priorities

a guest
May 29th, 2020
578
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*  Disclaimer: Use at your own risk!
  2.     Done for: Chrome (probably runs on others as well, no clue how those work, though)
  3.     Done by: Dejv (Discord: Dejv#3141, feel free to ask, or pin-point some mistakes, cause I don't do javascript)
  4.     Done why: For personal use, so thus lack of polish.
  5.     How to run tl;dr: Once these functions are on MelvorIdle page (which you can do by just copy/pasting this into browsers console) just do setInterval(loopPlantByPriority, 60000); -> this checks for replanting every minute, if you want to stop it do clearInterval(number_that_setinterval_returned), if you want to run just once do loopPlantByPriority();
  6.     IMPORTANT NOTE: Harvest function doesn't check if there are free bank slots to store the harvest!
  7.     Note: This script is quite talkative in the console, if it's too annoying just comment out (//) the "console.log"s
  8.     The other note: You can use the harvest function separatly by custHarvestAll();, or if you feel like that one's cheating, use the default instead, should work just alright.
  9. */
  10.  
  11. // ** FARMING SCRIPTS **
  12.  
  13. //Goes through all farming areas and plants the highest tier of seed unlocked and avaible in bank
  14. function loopPlantByPriority() {
  15.   //These are the default lists of plant priorities taken from farmable stuff global lists -> see getFloraIDs
  16.   //I've taken advantage of those being sorted from lowest skill to highest and just reverted those, then planting highest->lowest tier
  17.   //Customization: If you want to have different priority, just make your own list! -> proly use custom function with plantHighestTier
  18.   var floraSeeds = getFloraIDs();
  19.  
  20.   //First just harvesting what's grown
  21.   custHarvestAll();
  22.  
  23.   //Going through all farming areas while planting seeds by priority
  24.   for(var i = 0; i < floraSeeds.length; i++) {
  25.     plantByPriority(i, floraSeeds[i]);
  26.   }
  27. }
  28.  
  29. //Id of area to plant seeds into and list of seeds sorted by their priority to plant (highest->lowest)
  30. function plantByPriority(area, seedList) {
  31.   var seedPerPlant = 3 - area; //(allo)0 -> 3, (herb)1 -> 2, (tree)2 -> 1
  32.   var floraWords = ["allotments", "herbs", "trees"];
  33.   var farmingLevel = skillLevel[11];
  34.   var areaLen = newFarmingAreas[area].patches.length;
  35.   var seedLen = seedList.length;
  36.   var currentSeed = 0;
  37.  
  38.   for(var i = 0; i < areaLen; i++) {
  39.     //Only want to plant in unlocked farming slots and where's not anything growing atm
  40.     if(newFarmingAreas[area].patches[i].unlocked && !newFarmingAreas[area].patches[i].seedID) {
  41.       //Have high enough farming, have seed in bank, have enough seeds for planting
  42.       if(seedList[currentSeed].level <= farmingLevel && checkBankForItem(seedList[currentSeed].itemID) && bank[getBankId(seedList[currentSeed].itemID)].qty >= seedPerPlant) {
  43.         console.log("Currently planting " + items[seedList[currentSeed].itemID].name + ", into patch: " + i);
  44.         selectSeed(seedList[currentSeed].itemID, false);
  45.         selectedPatch[0] = area;
  46.         selectedPatch[1] = i;
  47.         plantSeed();
  48.       } else {
  49.         console.log("Cannot plant " + items[seedList[currentSeed].itemID].name + ", skipping.");
  50.         i--; //Wanna repeat for the lower tier on the same slot
  51.         currentSeed++; //Couldn't plant this tier, moving to lower tier seed
  52.         if(currentSeed >= seedLen) { //If I reached the end of list while failing to plant, just exit the loop and post message
  53.           console.log("Cannot finish planting " + floraWords[area] + " area, not enough seeds. Ended at slot: " + i);
  54.           break;
  55.         }
  56.       }
  57.     }
  58.   }
  59.   console.log("Planting " + floraWords[area] + " finished.");
  60. }
  61.  
  62. //Makes a copy of all seed types and sorts them from highest skill to lowest required
  63. function getFloraIDs() {
  64.   var floraSeedInfo = [];
  65.  
  66.   //Making a copy of each list of seeds so I don't mess up some stuffs
  67.   floraSeedInfo[0] = [...allotmentSeeds];
  68.   floraSeedInfo[1] = [...herbSeeds];
  69.   floraSeedInfo[2] = [...treeSeeds];
  70.  
  71.   //They are sorted from lowest skill to highest, I want the highest value, eg. highest skill first
  72.   //If in the future those'd stored different way there should be a sorting function
  73.   floraSeedInfo[0].reverse();
  74.   floraSeedInfo[1].reverse();
  75.   floraSeedInfo[2].reverse();
  76.  
  77.   return floraSeedInfo;
  78. }
  79.  
  80. //Goes through all areas and harvests what's grown
  81. function custHarvestAll() {
  82.   for (var i = 0; i < newFarmingAreas.length; i++) {
  83.     for (var j = 0; j < newFarmingAreas[i].patches.length; j++) {
  84.         if(newFarmingAreas[i].patches[j].hasGrown) {
  85.             harvestSeed(i, j);
  86.         }
  87.     }
  88.   }
  89.   console.log("Harvesting finished.");
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement