Advertisement
linspatz

aardvark arcanum auto

Oct 23rd, 2019
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         aardvark arcanum auto
  3. // @version      0.4
  4. // @author       aardvark
  5. // @description  Automates casting buffs, buying gems making types gems, making lore. Adds sell junk/dupe item buttons. Must open the main tab and the spells tab once to work.
  6. // @match        http://www.lerpinglemur.com/arcanum/
  7. // @match        https://game312933.konggames.com/gamez/0031/2933/*
  8. // ==/UserScript==
  9.  
  10. var tc_debug = false;    // set to true to see debug messages
  11.  
  12. var tc_suspend = false;        // set this to true in console to suspend all auto functions
  13.  
  14. // Setting to false will stop individual actions
  15. var tc_auto_misc = true;
  16. var tc_auto_cast = true;
  17. var tc_auto_focus = true;
  18. var tc_auto_heal = true;
  19.  
  20. var tc_auto_speed = 200; // Speed in ms, going to low will cause performance issues.
  21.  
  22. var tc_spells = new Map();
  23. var tc_resources = new Map();
  24. var tc_actions = new Map();
  25. var tc_bars = new Map();
  26. var tc_focus;
  27.  
  28. var tc_time_offset = 0;
  29.  
  30. // List of Gems that needs to be updated manually if changed.
  31. var tc_gems = {
  32.     "arcane gem" : "imbue gem (arcane)",
  33.     "fire gem" : "imbue gem (fire)",
  34.     "water gem" : "imbue gem (water)",
  35.     "nature gem" : "imbue lifegem",
  36.     "earth gem" : "imbue stone",
  37.     "air gem" : "imbue gem (air)",
  38.     "shadow gem" : "imbue gem (shadow)",
  39.     "light gem" : "imbue gem (light)",
  40.     "spirit gem" : "imbue gem (spirit)",
  41.     "blood gem" : "coagulate gem",
  42. };
  43.  
  44. // List of spells to autocast when needed without using quickbar (and interval to cast at)
  45. var tc_autospells = {
  46.     "minor mana" : 30,
  47.     "lesser mana" : 60,
  48.     "mana" : 120,
  49.     "minor fount" : 30,
  50.     "fount" : 60,
  51.     "wild growth" : 45,
  52.     "abundance" : 60,
  53.     "unseen servant" : 45,
  54.     "guided strike" : 45,
  55.     "true strike" : 45,
  56.     "perfect strike" : 45,
  57.     "whisper" : 50,
  58.     "insight" : 60,
  59.     "whirling step III" : 80,
  60.     "dust devil II" : 45,
  61.     "adamant shell" : 180,
  62.     "pulsing light" : 45,
  63.     "pulsing light II" : 60,
  64.     "pulsing light III" : 120,
  65. };
  66.  
  67. // Call this every second - will automatically pick up new spells
  68. function tc_populate_spells()
  69. {
  70.     if (tc_gettab() !== "spells") return;
  71.  
  72.     for (let qs of document.querySelectorAll(".spells .bottom .spellbook table tr")) {
  73.         if (qs.childElementCount == 3) {
  74.             var spell = qs.children[1].innerHTML.toLowerCase();
  75.             if (!tc_spells.get(spell) && !qs.children[2].firstChild.disabled) {
  76.                 tc_spells.set(spell, qs.children[2].firstChild);
  77.                 if (tc_debug) console.log("Saved spell: " + spell);
  78.             }
  79.         }
  80.     }
  81. }
  82.  
  83. // Call this every second - automatically grabs resource values
  84. function tc_populate_resources()
  85. {
  86.     for (let n of document.querySelectorAll("div.game-main div.resource-list tr.item-name:not(.locked)")) {
  87.         var name = n.firstElementChild.innerHTML.toLowerCase();
  88.         var vals = n.lastElementChild.innerHTML.split("/");
  89.         var val0 = parseInt(vals[0]);
  90.         var val1 = parseInt(vals[1]);
  91.         tc_resources.set(name, [ val0, val1 ]);
  92.     }
  93. }
  94.  
  95. function tc_populate_bars()
  96. {
  97.     for (let n of document.querySelectorAll("div.game-main div.vitals table.bars tr")) {
  98.             var name = n.firstElementChild.innerHTML.toLowerCase();
  99.             var vals = n.querySelectorAll("span.bar-text")[0].innerText.split("/");
  100.             var val0 = parseInt(vals[0]);
  101.             var val1 = parseInt(vals[1]);
  102.             tc_bars.set(name, [ val0, val1 ]);
  103.     }
  104. }
  105.  
  106. // Call every second to look for new buttons and ones that are now active.
  107. function tc_populate_actions()
  108. {
  109.     if (tc_gettab() !== "main") return;
  110.  
  111.     for (let qs of document.querySelectorAll(".main-actions .action-list .action-btn:not(.locked) .wrapped-btn:not([disabled])")) {
  112.         var key = qs.innerHTML.toLowerCase();
  113.         if (!tc_actions.get(key)) {
  114.             tc_actions.set(key, qs);
  115.             if (tc_debug) console.log("Action stored: " + qs.innerHTML);
  116.         }
  117.     }
  118. }
  119.  
  120. // Create a gem of a certian type. NOT USED
  121. function tc_create_gem(gem)
  122. {
  123.     var action = tc_gems.get(gem);
  124.     if (!action) return false;
  125.     return tc_click_action(action);
  126. }
  127.  
  128. // Checks if a given resource is at it's max value. FAZING OUT
  129. function tc_maxed(resource) {
  130.     return !tc_resources.get(resource) || tc_resources.get(resource)[0] == tc_resources.get(resource)[1];
  131. }
  132.  
  133. // Check if a resource is above a percentage. example: tc_check_resource("gold",.5);
  134. function tc_check_resource(resource,percent) {
  135.     return !tc_resources.get(resource) || tc_resources.get(resource)[0] >= tc_resources.get(resource)[1] * percent;
  136. }
  137. // Check if a bar(mana etc) is above a percentage.
  138. function tc_check_bars(bars,percent) {
  139. return !tc_bars.get(bars) || tc_bars.get(bars)[0] >= tc_bars.get(bars)[1] * percent;}
  140.  
  141. // Return name of current tab
  142. function tc_gettab()
  143. {
  144.     for (let tab of document.querySelectorAll("div.menu-items div.menu-item span")) {
  145.         var s = tab.innerHTML;
  146.         if (! /<u>/.test(s))
  147.             return s.slice(1, -1);    // strip off leading and trailing space
  148.     }
  149. }
  150.  
  151. // Set current tab to "name"
  152. function tc_settab(newtab)
  153. {
  154.     for (let tab of document.querySelectorAll("div.menu-items div.menu-item span")) {
  155.         if (tab.innerHTML.indexOf(newtab) != -1) {
  156.             tab.click();
  157.             return;
  158.         }
  159.     }
  160. }
  161.  
  162. // Clicks the action button
  163. function tc_click_action(action)
  164. {
  165.     var act = tc_actions.get(action);
  166.     if (!act) return false;
  167.  
  168.     if (act.disabled) {    // not sure how this happens, but seems to prevent action ever being called again
  169.         if (tc_debug) console.log("Action '" + action + "' was disabled - deleting it");
  170.         tc_actions.delete(action);
  171.         return false;
  172.     }
  173.  
  174.     if (tc_debug) console.log("Clicking: " + action);
  175.     act.click();
  176.     return true;    // click might still have failed
  177. }
  178. // Clicks the spell button
  179. function tc_cast_spell(spell)
  180. {
  181.     var spl = tc_spells.get(spell);
  182.     if (!spl) return false;
  183.  
  184.     if (spl.disabled) {    // not sure how this happens, but seems to prevent action ever being called again
  185.         if (tc_debug) console.log("Spell '" + spell + "' was disabled - deleting it");
  186.         tc_spells.delete(spell);
  187.         return false;
  188.     }
  189.  
  190.     if (tc_debug) console.log("Casting: " + spell);
  191.     spl.click();
  192.     return true;
  193. }
  194.  
  195. // For AUTOING. Casts spells listed under autospells
  196. function tc_autocast()
  197. {
  198.     if (tc_suspend) return;
  199.     if (!tc_auto_cast) return;
  200.  
  201.     for (var spell in tc_autospells) {
  202.         var rpt = tc_autospells[spell];
  203.         if (tc_time_offset % rpt == 0) {
  204.             if (tc_debug) console.log("try casting " + spell);
  205.             tc_cast_spell(spell);
  206.         }
  207.     }
  208.     tc_time_offset++;
  209. }
  210. // For AUTOING. Does several actions, MORE DOCUMENTATION
  211. function tc_automate()
  212. {
  213.     if (tc_suspend) return;
  214.     if (!tc_auto_misc) return;
  215.  
  216.     tc_populate_resources();
  217.  
  218.     if (tc_check_resource("herbs",1) && !tc_check_resource("gold",1))
  219.         for (let i=0; i < 10; ++i)
  220.             tc_click_action("sell herbs");
  221.  
  222.     if (tc_check_resource("research",1) && !tc_check_resource("scrolls",1) && tc_check_bars("mana",.75))
  223.         tc_click_action("scribe scroll");
  224.     if (!tc_check_resource("codices",1) && tc_check_resource("scrolls",1) && tc_check_bars("mana",.5))
  225.         tc_click_action("bind codex");
  226.     if (!tc_check_resource("gold",1) && tc_check_resource("scrolls",1))
  227.         tc_click_action("sell scroll");
  228.     else if (tc_check_resource("gold",1) && !tc_check_resource("scrolls",1))
  229.         tc_click_action("buy scroll");    // could fail if scribe above maxed them
  230.  
  231.     // If money maxed, buy gem
  232.     if (tc_check_resource("gold",1) && !tc_check_resource("gems",1))
  233.         tc_click_action("purchase gem");
  234.  
  235.     // If gems maxed, try making some different ones
  236.     if (tc_check_resource("gems",1)) {
  237.         for (var gem in tc_gems) {    // try to make one of each
  238.             if (!tc_check_resource(gem,1)) {
  239.                 if (tc_debug) console.log("not maxed " + gem + " calling " + tc_gems[gem]);
  240.                 tc_click_action(tc_gems[gem]);
  241.             }
  242.         }
  243.     }
  244.  
  245.     // Sublimate lore
  246.     if (tc_check_resource("codices",1)) {
  247.         if (tc_click_action("sublimate lore"))
  248.             for (let qs of document.querySelectorAll(".popup"))
  249.                 if (qs.firstElementChild.innerHTML == "sublimate lore")
  250.                     qs.children[3].firstElementChild.click();
  251.     }
  252. }
  253.  
  254. // Sells all items that are considered junk
  255. function tc_selljunk()
  256. {
  257.     var sell_exact = [ "amulet", "band", "belt", "boots", "broomstick", "cane", "cap", "cape", "cincture", "cloak", "club", "collar", "conical helm", "dagger", "girdle", "gloves", "greaves", "hat", "jerkin", "knife", "loop", "necklace", "pendant", "ring", "robe", "sash", "shortsword", "spear", "staff" ];
  258.     var sell_match = [ "silk ", "cotton ", "stone ", "leather ", "^wood ", "bone ", "bronze ", "iron ", "^steel " ];
  259.  
  260.         // "silk ", "cotton ", "stone ", "leather ", "^wood ", "bone ", "bronze ", "iron ", "^steel ", "quicksteel ", "mithril ", "ebonwood ", "ethereal ", "adamant "
  261.  
  262.     function checkmatch(m) { for (let i of sell_match) if (RegExp(i).test(m)) return true; return false; }
  263.  
  264.     for (let row of document.querySelectorAll(".adventure .raid-bottom .inv table tr")) {
  265.         // table has 4 columns: name + 3 buttons: Equip, Take, Sell
  266.         if (row.children[3].children[0].innerText == "Sell") {
  267.             var item = row.children[0].innerText;
  268.             if (sell_exact.indexOf(item) != -1 || checkmatch(item)) {
  269. //              console.log("Selling: " + item);
  270.                 row.children[3].children[0].click();
  271.             }
  272.         }
  273.     }
  274. }
  275.  
  276. // Sells any item that you have more than one of
  277. function tc_selldups()
  278. {
  279.     var items = new Map(); // test
  280.  
  281.     // Build a map of item -> qty
  282.     for (let row of document.querySelectorAll(".adventure .raid-bottom .inv table tr")) {
  283.         // table has 4 columns: name + 3 buttons: Equip, Take, Sell
  284.         if (row.children[3].children[0].innerText == "Sell") {
  285.             var item = row.children[0].innerText;
  286.             var qty = items.get(item);
  287.             items.set(item, qty ? qty+1 : 1);
  288.         }
  289.     }
  290.  
  291.     // Now iterate over rows, selling items where qty > 1
  292.     for (let row of document.querySelectorAll(".adventure .raid-bottom .inv table tr")) {
  293.         // table has 4 columns: name + 3 buttons: Equip, Take, Sell
  294.         if (row.children[3].children[0].innerText == "Sell") {
  295.             var item = row.children[0].innerText;
  296.             var qty = items.get(item);
  297.             var maxqty = 1;
  298.             var itemtype = "";
  299.             switch(item.split(" ").pop()){
  300.                 case "pendant": case "collar": case "amulet": case "necklace":
  301.                     maxqty = 3;
  302.                     break;
  303.                 case "band": case "loop": case "ring":
  304.                     maxqty = 4;
  305.                     break;
  306.                 case "shortsword": case "club": case "cane": case "knife": case "broomstick": case "dagger": case "axe": case "mace":
  307.                     maxqty = 2;
  308.                     break;
  309.                 default:
  310.                     maxqty = 1
  311.                     break;
  312.             }
  313.         }
  314.         if (qty > maxqty) {
  315. //          console.log("Selling: " + item);
  316.             row.children[3].children[0].click();
  317.             items.set(item, qty-1);
  318.         }
  319.     }
  320. }
  321.  
  322. // Create junk and dupe sell buttons if not already present
  323. function tc_sellsetup()
  324. {
  325.     if (tc_gettab() != "adventure") return;
  326.     if (document.querySelectorAll("#selldups").length > 0) return;
  327.  
  328.     var sellall = document.querySelectorAll(".adventure .raid-bottom .inv div.flex-row button")[0];
  329.     if(!sellall) return;
  330.     var selljunk = document.createElement("button");
  331.     var t1 = document.createTextNode("Sell Junk");
  332.     selljunk.appendChild(t1);
  333.     selljunk.addEventListener("click", tc_selljunk);
  334.  
  335.     var selldups = document.createElement("button");
  336.     var t2 = document.createTextNode("Sell Dupes");
  337.     selldups.appendChild(t2);
  338.     selldups.addEventListener("click", tc_selldups);
  339.     selldups.id = "selldups";
  340.  
  341.     sellall.parentNode.insertBefore(selljunk, null);
  342.     sellall.parentNode.insertBefore(selldups, null);
  343.     console.log("buttons added");
  344. }
  345.  
  346.  
  347. // Uses focus until you have only 10 mana left.
  348. function tc_autofocus()
  349. {
  350.     if (!tc_auto_focus) return;
  351.     if (!tc_focus)
  352.     for (let qs of document.querySelectorAll(".vitals div.separate button.btn-sm")) {
  353.         if (!tc_focus && qs.innerHTML === "Focus")
  354.             tc_focus = qs;
  355.         }
  356.     var amt = tc_bars.get("mana")[0];
  357.     var max = tc_bars.get("mana")[1];
  358.  
  359.     // 10 mana required for compile tome
  360.     var min = max < 11 ? max-1 : 10;
  361.     if (amt >= min) {
  362.         for (let i = 10 * (amt-min); i > 0; i--)
  363.             tc_focus.click();
  364.     }
  365. }
  366.  
  367. function tc_autoheal()
  368. {
  369.     if (!tc_auto_heal) return;
  370.  
  371.     if (tc_spells.has("sealing light ii")){
  372.         if (tc_bars.get("hp")[1]-tc_bars.get("hp")[0] >= 50 && tc_bars.get("light")[1] >= 5)
  373.             tc_cast_spell("sealing light ii");
  374.     }else if (tc_spells.has("sealing light")){
  375.         if (tc_bars.get("hp")[1]-tc_bars.get("hp")[0] >= 15 && tc_bars.get("light")[1] >= 5)
  376.             tc_cast_spell("sealing light");
  377.     }
  378. }
  379.  
  380.  
  381. /*
  382.     Basic Automation Stuff
  383. */
  384. // Can't guarantee that timer will work exactly every second, so reduce interval here to compensate so spells don't run out
  385. var tc_timer_ac = window.setInterval(function(){
  386.     tc_autocast();
  387.     tc_automate();
  388.     tc_autofocus();
  389.     tc_autoheal();
  390. }, tc_auto_speed);
  391.  
  392.  
  393. // timer to populate the maps of spells, resources, and actions
  394. var tc_timer_populate = window.setInterval(function(){
  395.     tc_populate_spells();
  396.     tc_populate_resources();
  397.     tc_populate_actions();
  398.     tc_populate_bars();
  399. }, tc_auto_speed);
  400.  
  401. var tc_timer_as = window.setInterval(tc_sellsetup, tc_auto_speed);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement