Advertisement
Czogista

Zbieranie miodu margonem

Nov 28th, 2020 (edited)
1,720
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Zbieranko
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  Wymagany cBot!
  6. // @author       Czogi
  7. // @match        http://*.margonem.pl/
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. window.g.loadQueue.push({
  12.   fun: async function () {
  13.     if (!window.czogisBot || window.map.id !== 5147) {
  14.       while (window.map.id === 5145) {
  15.         await sleep(1000);
  16.         window.czogisBot.talkToNpc(203510);
  17.       }
  18.       return;
  19.     }
  20.     let closestNpcOnMap;
  21.     if (!localStorage["honeyTimeouts"])
  22.       localStorage.setItem("honeyTimeouts", "{}");
  23.  
  24.     const npcs = Object.values(czogisBot.npc).filter((npc) => {
  25.       return npc.nick === "Gniazdo leśnych pszczół";
  26.     });
  27.  
  28.     function sleep(ms) {
  29.       return new Promise((resolve) => setTimeout(resolve, ms));
  30.     }
  31.     const delWithDelay = async (a) => {
  32.       if (a.d && a.d[0] === 4 && a.h?.x) {
  33.         console.log("Teleport się stanął");
  34.         await sleep(300);
  35.         closestNpcOnMap = undefined;
  36.       }
  37.     };
  38.     const oldParseInput = window.parseInput;
  39.     window.parseInput = function (a, b, c) {
  40.       oldParseInput(a, b, c);
  41.       const recent = JSON.parse(localStorage["honeyTimeouts"]);
  42.       delWithDelay(a);
  43.       if (closestNpcOnMap && a.d && a.d[2] == closestNpcOnMap.id) {
  44.         recent[closestNpcOnMap.id] = window.unix_time() + 300;
  45.         closestNpcOnMap = undefined;
  46.         localStorage.setItem("honeyTimeouts", JSON.stringify(recent));
  47.       }
  48.  
  49.       const currUnix = window.unix_time();
  50.       for (const [key, value] of Object.entries(recent)) {
  51.         if (currUnix >= value) {
  52.           delete recent[key];
  53.         }
  54.       }
  55.       localStorage.setItem("honeyTimeouts", JSON.stringify(recent));
  56.       if (!closestNpcOnMap) {
  57.         closestNpcOnMap = getClosest(npcs);
  58.       }
  59.       if (!window.czogisBot.talking) {
  60.         czogisBot.talkToNpc(closestNpcOnMap.id);
  61.       } else {
  62.         window.czogisBot.clickText(
  63.           "Powoli wkładam rękę w poszukiwaniu plastrów wosku."
  64.         );
  65.       }
  66.     };
  67.  
  68.     function getClosest(npcs) {
  69.       const recent = JSON.parse(localStorage["honeyTimeouts"]);
  70.       if (closestNpcOnMap && !recent[closestNpcOnMap.id]) {
  71.         return closestNpcOnMap;
  72.       }
  73.       let localNpcs = [];
  74.  
  75.       for (const npc of npcs) {
  76.         if (recent[npc.id]) {
  77.           continue;
  78.         }
  79.         localNpcs.push(npc);
  80.       }
  81.       if (!localNpcs.length) {
  82.         return undefined;
  83.       }
  84.       if (localNpcs.length > 15) {
  85.         localNpcs = window.czogisBot.sortNpcs(localNpcs);
  86.       }
  87.       let closestNpc = [];
  88.       for (const npc of localNpcs) {
  89.         const dist = window.czogisBot.closest(npc);
  90.         if (dist == false || dist == -1) {
  91.           continue;
  92.         }
  93.  
  94.         if (!closestNpc.length || dist < closestNpc[1]) {
  95.           closestNpc = [npc, dist];
  96.         }
  97.       }
  98.       return closestNpc[0];
  99.     }
  100.   }
  101. });
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement