Advertisement
Guest User

Forager by quinsta

a guest
Jul 28th, 2013
497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //#! name = forager
  2. //#! uniq = forager_by_quinsta
  3. //#! tooltip = start foraging
  4. include("jBotAPI");
  5. var inventory = checkInventory();
  6. function getNearestFirTree() {
  7.     var trees = jGetObjects(25, jCoord(0, 0), ["trees/fir"]);
  8.     var min_len = 100500; var obj = null;
  9.     for (var i = 0; i < trees.length; i++) {
  10.         if (trees[i].position().dist(jMyCoords()) < min_len) {
  11.             obj = trees[i];
  12.             min_len = trees[i].position().dist(jMyCoords());
  13.         }
  14.     }
  15.     return obj;
  16. }
  17. var herbs = ["edelweiss","glimmermoss","frogscrown","chimingbluebell","royaltoadstool","bloadtedbolete","blueberry","dandelion","chantrelle"];
  18. function gatherHerbs() {
  19.     while(true) {
  20.         //if (jGetStamina() < 80) drinkWater();
  21.         for (var i=0;i<herbs.length;i++) {
  22.             herb = jFindObjectByName("gfx/terobjs/herbs/"+herbs[i], 200);
  23.             if (herb) break;
  24.         }
  25.          
  26.         if (herb) {
  27.             jPFMove(herb.position());
  28.             jWaitMove(2000);
  29.             herb.doClick(3,0);
  30.             jSelectContextMenu("Pick")
  31.             jWaitProgress();
  32.         } else {
  33.             return;
  34.         }
  35.     }
  36. }
  37. function huntRabbit() {
  38.     rabbit = jFindObjectByName("gfx/borka/s", 200);
  39.     if (!rabbit) return;
  40.     jPrint("rabbit found");
  41.     //jPFMove(rabbit.position());
  42. }
  43. function huntFrogs() {
  44.     var frogs = jGetObjects(25, jCoord(0, 0), ["kritter/rat/s"]);
  45.     if (frogs.length==0) return;
  46.     jPrint("frogs found: "+frogs.length);
  47.     jMoveStep(frogs[0].position());
  48.     jWaitMove(2000);
  49.     frogs[0].doClick(3,0);
  50.    
  51. }
  52.  
  53. var directions = [jCoord(10,0),jCoord(10,10),jCoord(0,10),jCoord(-10,10),jCoord(-10,0),jCoord(-10,-10),jCoord(0,-10),jCoord(10,-10)];
  54. var current_direction = 0;
  55. function wander() {
  56.     current_direction = (current_direction + Math.floor(Math.random()*3)-1+directions.length)%directions.length;
  57.     while (jIsPathFree(directions[current_direction])) current_direction=(current_direction+1)%directions.length;
  58.     jMoveStep(directions[current_direction]);
  59.     jWaitMove(2000);
  60. }
  61. var edibles = ["blueberry","ants-larvae","ants-pupae","chantrelle"];
  62. function eat() {
  63.     for (var i =0;i<edibles.length;i++) {
  64.         var found = inventory.getItems(edibles[i]);
  65.         for (var j=0;j<found.length && jGetHungry() < 95;j++) {
  66.             if (found[j].isActual()) {
  67.                 found[j].iact();
  68.                 jWaitPopup(actionTimeout);
  69.                 jSelectContextMenu("Eat");
  70.                 waitUnActual(found[j]);
  71.             }
  72.         }
  73.     }
  74. }
  75. var curiosities = ["conecow","dandelion"];
  76. function study() {
  77.    
  78.     var study = jGetStudy();
  79.     for (var i=0;i<curiosities.length;i++) {
  80.         if (study.getItems(curiosities[i]).length==0) {
  81.             var found = inventory.getItems(curiosities[i]);
  82.             if(found[0].isActual()) {
  83.                 var freeslot = study.freeSlotSizeCoord(jCoord(1,1));
  84.                 found[0].take();
  85.                 jWaitDrag();
  86.                 study.drop(freeslot);
  87.                 jWaitDrop();
  88.             }
  89.         }
  90.     }
  91.    
  92. }
  93. function main () {
  94.     while(true) {
  95.         gatherHerbs();
  96.         //huntRabbit();
  97.         //huntFrogs();
  98.         makeConecow();
  99.         eat();
  100.         study();
  101.         wander();
  102.     }
  103. }
  104. function makeConecow() {
  105.     conecow = inventory.getItems("conecow");
  106.     if (conecow.length<1) {
  107.         var tree = getNearestFirTree();
  108.         if (!tree) return;
  109.         var branches = inventory.getItems("branch");
  110.         var cones = inventory.getItems("seed-fir");
  111.         if (tree) {
  112.             if (branches.length < 4) {
  113.                 tree.doClick(3,0);
  114.                 jWaitPopup(1000);
  115.                 jSelectContextMenu("Take branch");
  116.                 while(inventory.getItems("branch").length<4)
  117.                     jSleep(100);
  118.                 jMoveStep(jCoord(10,0));
  119.             }
  120.             if (cones.length < 1) {
  121.                 tree.doClick(3,0);
  122.                 jWaitPopup(1000);
  123.                 jSelectContextMenu("Pick cone");
  124.                 jSleep(1000);
  125.             }
  126.         }
  127.         if (!jHaveCraft("Cone cow")) {
  128.             jSendDoubleAction("craft","conecow");
  129.             jWaitCraft("Cone cow",2000);
  130.         }
  131.         jCraftItem(true);
  132.         jWaitProgress();
  133.     }
  134.    
  135. }
  136. function checkSheet() {
  137.     if(!jHaveWindow("Character sheet")) {
  138.         jToggleSheet();
  139.         while(!jHaveWindow("Character sheet"))
  140.             jSleep(100);
  141.     }
  142. }
  143. main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement