Guest User

Untitled

a guest
Mar 16th, 2022
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. let isVisible = false;
  4. let currentActionIndex = 0;
  5. let triggerCheckInterval = null;
  6. let nameIncrement = 0;
  7. let queueLoop = false;
  8. let queuePause = false;
  9. let manageMasteryInterval = null;
  10. let masteryConfigChanges = { skill: null };
  11. const lvlIndex = {};
  12. const masteryClone = {};
  13. const masteryConfig = {};
  14. const actionQueueArray = [];
  15. const shop = {};
  16. const tooltips = {};
  17. const validInputs = {
  18.   A: [null, null, null],
  19.   B: [null, null, null, null],
  20.   C: [null, null, null, null],
  21. };
  22. let currentlyEditing = { id: null, type: null };
  23. const pageIndex = {
  24.   Woodcutting: 0,
  25.   Fishing: 7,
  26.   Firemaking: 8,
  27.   Cooking: 9,
  28.   Mining: 10,
  29.   Smithing: 11,
  30.   Combat: 13,
  31.   Thieving: 14,
  32.   Farming: 15,
  33.   Fletching: 16,
  34.   Crafting: 17,
  35.   Runecrafting: 18,
  36.   Herblore: 19,
  37.   Agility: 20,
  38.   Summoning: 28,
  39.   Astrology: 31,
  40. };
  41.  
  42. function checkAmmoQty(id) {
  43.   const set = player.equipmentSets.find((a) => a.slots.Quiver.item.id == id);
  44.   return set ? set.slots.Quiver.quantity : 0;
  45. }
  46.  
  47. function checkFoodQty(id) {
  48.   const food = player.food.slots.find((a) => a.item.id == id);
  49.   return food ? food.quantity : 0;
  50. }
  51.  
  52. function actionTab() {
  53.   if (!isVisible) {
  54.     changePage(3);
  55.     $("#settings-container").attr("class", "content d-none");
  56.     $("#header-title").text("Action Queue");
  57.     $("#header-icon").attr("src", "assets/media/skills/prayer/mystic_lore.svg");
  58.     $("#header-theme").attr("class", "content-header bg-combat");
  59.     $("#page-header").attr("class", "bg-combat");
  60.     document.getElementById("action-queue-container").style.display = "";
  61.     isVisible = true;
  62.   }
  63. }
  64.  
  65. function hideActionTab() {
  66.   if (isVisible) {
  67.     document.getElementById("action-queue-container").style.display = "none";
  68.     isVisible = false;
  69.   }
  70. }
  71.  
  72. const options = {
  73.   //trigger options for dropdown menus
  74.   triggers: {
  75.     Idle: null,
  76.     "Item Quantity": {},
  77.     "Skill Level": {},
  78.     "Skill XP": {},
  79.     "Mastery Level": {
  80.       Agility: {},
  81.       Astrology: {},
  82.       Cooking: {},
  83.       Crafting: {},
  84.       Farming: {},
  85.       Firemaking: {},
  86.       Fishing: {},
  87.       Fletching: {},
  88.       Herblore: {},
  89.       Mining: {},
  90.       Runecrafting: {},
  91.       Smithing: {},
  92.       Summoning: {},
  93.       Thieving: {},
  94.       Woodcutting: {},
  95.     },
  96.     "Mastery Pool %": {},
  97.     "Pet Unlocked": {},
  98.     "Equipped Item Quantity": {},
  99.     "Prayer Points": { "≥": "num", "≤": "num" },
  100.     "Potion Depleted": {
  101.       Agility: null,
  102.       Astrology: null,
  103.       Combat: null,
  104.       Cooking: null,
  105.       Crafting: null,
  106.       Farming: null,
  107.       Firemaking: null,
  108.       Fishing: null,
  109.       Fletching: null,
  110.       Herblore: null,
  111.       Mining: null,
  112.       Runecrafting: null,
  113.       Smithing: null,
  114.       Summoning: null,
  115.       Thieving: null,
  116.       Woodcutting: null,
  117.     },
  118.     "Enemy in Combat": {},
  119.   },
  120.   //action options for dropdown menus
  121.   actions: {
  122.     "Start Skill": {
  123.       Agility: null,
  124.       Astrology: {},
  125.       Cooking: {},
  126.       Crafting: {},
  127.       Firemaking: {},
  128.       Fishing: {},
  129.       Fletching: {},
  130.       Herblore: {},
  131.       Magic: {},
  132.       Mining: {},
  133.       Runecrafting: {},
  134.       Smithing: {},
  135.       Summoning: {},
  136.       Thieving: {},
  137.       Woodcutting: {},
  138.     },
  139.     "Start Combat": {
  140.       "Slayer Task": null,
  141.     },
  142.     "Change Attack Style": { "Select Spell": { Normal: {}, Curse: {}, Aurora: {}, Ancient: {} } },
  143.     "Switch Equipment Set": { 1: null, 2: null, 3: null, 4: null },
  144.     "Equip Item": {},
  145.     "Equip Passive": {},
  146.     "Unequip Item": {},
  147.     "Buy Item": {},
  148.     "Sell Item": {},
  149.     "Use Potion": {},
  150.     "Activate Prayers": {},
  151.     "Build Agility Obstacle": {},
  152.     "Remove Agility Obstacle": {},
  153.   },
  154. };
  155.  
  156. function setTrigger(category, name, greaterThan, masteryItem, number) {
  157.   const itemID = items.findIndex((a) => a.name == name);
  158.   number = parseInt(number, 10);
  159.   switch (category) {
  160.     case "Idle":
  161.       return () => {
  162.         return !combatManager.isInCombat && !game.activeSkill;
  163.       };
  164.     case "Item Quantity":
  165.       if (greaterThan == "≥") {
  166.         return () => {
  167.           return getBankQty(itemID) >= number;
  168.         };
  169.       }
  170.       return () => {
  171.         return getBankQty(itemID) <= number;
  172.       };
  173.     case "Prayer Points":
  174.       if (name == "≥") {
  175.         return () => {
  176.           return player.prayerPoints >= number;
  177.         };
  178.       }
  179.       return () => {
  180.         return player.prayerPoints <= number;
  181.       };
  182.     case "Skill Level": {
  183.       const xp = exp.level_to_xp(number);
  184.       return () => {
  185.         return skillXP[CONSTANTS.skill[name]] >= xp;
  186.       };
  187.     }
  188.     case "Skill XP":
  189.       return () => {
  190.         return skillXP[CONSTANTS.skill[name]] >= number;
  191.       };
  192.     case "Equipped Item Quantity":
  193.       if (items.filter((a) => a.canEat).find((a) => a.name == name)) {
  194.         return () => {
  195.           return checkFoodQty(itemID) <= number;
  196.         };
  197.       }
  198.       if (items.filter((a) => a.type == "Familiar").find((a) => a.name == name)) {
  199.         return () => {
  200.           let summonSlots = player.equipment.slotArray.slice(-2);
  201.           let slot = summonSlots.findIndex((a) => a.item.id == itemID);
  202.           return (slot >= 0 ? summonSlots[slot].quantity : 0) <= number;
  203.         };
  204.       }
  205.       return () => {
  206.         return checkAmmoQty(itemID) <= number;
  207.       };
  208.     case "Mastery Level":
  209.       let masteryID = fetchMasteryID(name, masteryItem);
  210.       return () => {
  211.         return getMasteryLevel(CONSTANTS.skill[name], masteryID) >= number;
  212.       };
  213.     case "Pet Unlocked": {
  214.       const petID = PETS.findIndex((pet) => {
  215.         const re = new RegExp(`^${name.split(" (")[0]}`, "g");
  216.         return re.test(pet.name);
  217.       });
  218.       return () => {
  219.         return petUnlocked[petID];
  220.       };
  221.     }
  222.     case "Mastery Pool %": {
  223.       const skill = CONSTANTS.skill[name];
  224.       return () => {
  225.         return getMasteryPoolProgress(skill) >= number;
  226.       };
  227.     }
  228.     case "Potion Depleted":
  229.       return () => {
  230.         return herbloreBonuses[pageIndex[name]].charges <= 0;
  231.       };
  232.     case "Enemy in Combat": {
  233.       const monsterID = MONSTERS.findIndex((a) => a.name == name);
  234.       return () => {
  235.         return combatManager.isInCombat && combatManager.selectedMonster == monsterID;
  236.       };
  237.     }
  238.   }
  239. }
  240.  
  241. function fetchMasteryID(skillName, itemName) {
  242.   const itemID = items.findIndex((a) => a.name == itemName);
  243.   let masteryID = itemID >= 0 && items[itemID].masteryID ? items[itemID].masteryID[1] : null;
  244.   switch (skillName) {
  245.     case "Cooking":
  246.       masteryID = Cooking.recipes.find((a) => a.itemID == itemID).masteryID;
  247.       break;
  248.     case "Herblore":
  249.       masteryID = Herblore.potions.find((a) => a.name == itemName).masteryID;
  250.       break;
  251.     case "Thieving":
  252.       masteryID = Thieving.npcs.find((a) => a.name == itemName).id;
  253.       break;
  254.     case "Agility":
  255.       masteryID = Agility.obstacles.findIndex((a) => a.name == itemName);
  256.       break;
  257.     case "Astrology":
  258.       masteryID = Astrology.constellations.findIndex((a) => a.name == itemName);
  259.       break;
  260.     case "Mining":
  261.       masteryID = Mining.rockData.findIndex((a) => a.name == itemName);
  262.       break;
  263.   }
  264.   return masteryID;
  265. }
  266.  
  267. function setAction(actionCategory, actionName, skillItem, skillItem2, qty) {
  268.   qty = parseInt(qty, 10);
  269.   const itemID = items.findIndex((a) => a.name == actionName);
  270.   switch (actionCategory) {
  271.     case "Start Skill":
  272.       return setSkillAction(actionName, skillItem, skillItem2);
  273.     case "Start Combat": {
  274.       //slayer task selection
  275.       if (actionName == "Slayer Task") {
  276.         return () => {
  277.           if (combatManager.slayerTask.killsLeft > 0) {
  278.             const mID = combatManager.slayerTask.monster.id;
  279.             const areaData = [...areaMenus.combat.areas, ...areaMenus.slayer.areas].find((a) => a.monsters.includes(mID));
  280.             if (combatManager.isInCombat && combatManager.selectedMonster == mID) return true;
  281.             combatManager.stopCombat();
  282.             combatManager.selectMonster(mID, areaData);
  283.             return true;
  284.           }
  285.           return false;
  286.         };
  287.       }
  288.       //dungeon selection
  289.       const dungeonIndex = DUNGEONS.findIndex((a) => a.name == actionName);
  290.       if (dungeonIndex >= 0) {
  291.         return () => {
  292.           if (
  293.             DUNGEONS[dungeonIndex].requiresCompletion === undefined ||
  294.             dungeonCompleteCount[DUNGEONS[dungeonIndex].requiresCompletion] >= 1
  295.           ) {
  296.             combatManager.selectDungeon(dungeonIndex);
  297.             return true;
  298.           }
  299.           return false;
  300.         };
  301.       }
  302.       //regular monster selection
  303.       const monsterIndex = MONSTERS.findIndex((a) => a.name == actionName);
  304.       const areaData = [...areaMenus.combat.areas, ...areaMenus.slayer.areas].find((a) => a.monsters.includes(monsterIndex));
  305.       return () => {
  306.         if (checkRequirements(areaData.entryRequirements)) {
  307.           if (!(combatManager.isInCombat && combatManager.selectedMonster == monsterIndex))
  308.             combatManager.selectMonster(monsterIndex, areaData);
  309.           return true;
  310.         }
  311.         return false;
  312.       };
  313.     }
  314.     case "Change Attack Style": {
  315.       if (actionName == "Select Spell") {
  316.         switch (skillItem) {
  317.           case "Normal":
  318.             return () => {
  319.               const spellID = SPELLS.findIndex((a) => a.name == skillItem2);
  320.               //check level req
  321.               if (skillLevel[CONSTANTS.skill.Magic] < SPELLS[spellID].magicLevelRequired) return false;
  322.               player.toggleSpell(spellID);
  323.               return true;
  324.             };
  325.           case "Curse":
  326.             return () => {
  327.               const spellID = CURSES.findIndex((a) => a.name == skillItem2);
  328.               //check level req
  329.               if (skillLevel[CONSTANTS.skill.Magic] < CURSES[spellID].magicLevelRequired) return false;
  330.               player.toggleCurse(spellID);
  331.               return true;
  332.             };
  333.           case "Aurora":
  334.             return () => {
  335.               const spellID = AURORAS.findIndex((a) => a.name == skillItem2);
  336.               //check level req
  337.               if (skillLevel[CONSTANTS.skill.Magic] < AURORAS[spellID].magicLevelRequired) return false;
  338.               //check item req
  339.               if (
  340.                 AURORAS[spellID].requiredItem >= 0 &&
  341.                 !player.equipment.slotArray.map((a) => a.item.id).includes(AURORAS[spellID].requiredItem)
  342.               )
  343.                 return false;
  344.               player.toggleAurora(spellID);
  345.               return true;
  346.             };
  347.           case "Ancient":
  348.             return () => {
  349.               const spellID = ANCIENT.findIndex((a) => a.name == skillItem2);
  350.               //check level req
  351.               if (skillLevel[CONSTANTS.skill.Magic] < ANCIENT[spellID].magicLevelRequired) return false;
  352.               //check dungeon req
  353.               if (dungeonCompleteCount[ANCIENT[spellID].requiredDungeonCompletion[0]] < ANCIENT[spellID].requiredDungeonCompletion[1])
  354.                 return false;
  355.               player.toggleSpellAncient(spellID);
  356.               return true;
  357.             };
  358.         }
  359.       }
  360.       const style = CONSTANTS.attackStyle[actionName];
  361.       return () => {
  362.         if (player.attackType == "magic") {
  363.           if (style < 6) return false;
  364.         } else if (player.attackType === "ranged") {
  365.           if (style > 5 || style < 3) return false;
  366.         } else {
  367.           if (style > 2) return false;
  368.         }
  369.         player.setAttackStyle(player.attackType, actionName);
  370.         return true;
  371.       };
  372.     }
  373.     case "Switch Equipment Set": {
  374.       const equipSet = parseInt(actionName) - 1;
  375.       return () => {
  376.         if (player.equipmentSets.length > equipSet) {
  377.           player.changeEquipmentSet(equipSet);
  378.           return true;
  379.         }
  380.         return false;
  381.       };
  382.     }
  383.     case "Equip Item":
  384.       return () => {
  385.         const bankID = getBankId(itemID);
  386.         if (bankID === -1) return false;
  387.         if (sellItemMode) toggleSellItemMode();
  388.         if (items[itemID].canEat) {
  389.           selectBankItem(itemID);
  390.           equipFoodQty = bank[bankID].qty;
  391.           equipFood();
  392.           return getBankQty(itemID) == 0; //returns false if there is any of the item left in bank (couldn't equip)
  393.         }
  394.         if (items[itemID].type == "Familiar") {
  395.           let slot = player.equipment.slotArray.slice(-3).findIndex((a) => a.item.id == itemID);
  396.           if (slot >= 0) {
  397.             player.equipItem(itemID, player.selectedEquipmentSet, `Summon${slot}`, bank[bankID].qty);
  398.           } else if (player.equipment.slotArray[12].quantity == 0) {
  399.             player.equipItem(itemID, player.selectedEquipmentSet, "Summon1", bank[bankID].qty);
  400.           } else if (player.equipment.slotArray[13].quantity == 0) {
  401.             player.equipItem(itemID, player.selectedEquipmentSet, "Summon2", bank[bankID].qty);
  402.           }
  403.           return getBankQty(itemID) == 0;
  404.         }
  405.         if (items[itemID].validSlots[0] == "Quiver") {
  406.           player.equipItem(itemID, player.selectedEquipmentSet, "Quiver", bank[bankID].qty);
  407.           return getBankQty(itemID) == 0; //returns false if there is any of the item left in bank (couldn't equip)
  408.         }
  409.         player.equipItem(itemID, player.selectedEquipmentSet);
  410.         return player.equipment.slots[items[itemID].validSlots[0]].item.id === itemID; //returns false if the item is not equipped
  411.       };
  412.     case "Equip Passive":
  413.       return () => {
  414.         if (dungeonCompleteCount[15] < 1 || getBankId(itemID) === -1) return false;
  415.         player.equipCallback(itemID, "Passive");
  416.         return player.equipment.slots.Passive.item.id === itemID;
  417.       };
  418.     case "Unequip Item": {
  419.       return () => {
  420.         for (const i in player.equipment.slots) {
  421.           if (player.equipment.slots[i].item.id == itemID) {
  422.             player.unequipCallback(i)();
  423.             return getBankQty(itemID) > 0; //returns false if there is 0 of the items in bank (no space to unequip)
  424.           }
  425.         }
  426.         return false;
  427.       };
  428.     }
  429.     case "Buy Item":
  430.       return () => {
  431.         return shop[actionName].buy(qty);
  432.       };
  433.     case "Sell Item":
  434.       return () => {
  435.         if (!bank.find((a) => a.id == itemID)) return false;
  436.         if (sellItemMode) toggleSellItemMode();
  437.         selectBankItem(itemID);
  438.         sellItem();
  439.         if (showSaleNotifications) swal.clickConfirm();
  440.         return true;
  441.       };
  442.     case "Use Potion":
  443.       return () => {
  444.         if (!bank.find((a) => a.id == itemID)) return false;
  445.         usePotion(itemID);
  446.         return true;
  447.       };
  448.     case "Activate Prayers": {
  449.       let choice = [];
  450.       if (actionName != "None") {
  451.         choice.push(PRAYER.findIndex((a) => a.name == actionName));
  452.         if (skillItem != "None") {
  453.           choice.push(PRAYER.findIndex((a) => a.name == skillItem));
  454.         }
  455.       }
  456.       return () => {
  457.         const validPrayers = choice.filter((a) => skillLevel[CONSTANTS.skill.Prayer] > PRAYER[a].prayerLevel);
  458.         changePrayers(validPrayers);
  459.         return true;
  460.       };
  461.     }
  462.     case "Build Agility Obstacle": {
  463.       const obstacleID = Agility.obstacles.findIndex((a) => a.name == skillItem);
  464.       const obstacleNumber = parseInt(actionName) - 1;
  465.       return () => {
  466.         if (chosenAgilityObstacles[obstacleNumber] == obstacleID) return true;
  467.         if (!canIAffordThis(Agility.obstacles[obstacleID].cost, Agility.obstacles[obstacleID].skillRequirements, obstacleID)) return false;
  468.         if (chosenAgilityObstacles[obstacleNumber] >= 0) destroyAgilityObstacle(obstacleNumber, true);
  469.         buildAgilityObstacle(obstacleID, true);
  470.         return true;
  471.       };
  472.     }
  473.     case "Remove Agility Obstacle": {
  474.       const obstacleNumber = parseInt(actionName) - 1;
  475.       return () => {
  476.         if (chosenAgilityObstacles[obstacleNumber] >= 0) destroyAgilityObstacle(obstacleNumber, true);
  477.         return true;
  478.       };
  479.     }
  480.   }
  481. }
  482.  
  483. function setSkillAction(actionName, skillItem, skillItem2) {
  484.   const itemID = items.findIndex((a) => a.name == skillItem);
  485.   let actionID = 0;
  486.   switch (actionName) {
  487.     case "Agility":
  488.       return () => {
  489.         if (game.activeSkill !== globalThis.ActiveSkills.Agility) game.agility.start();
  490.         return true;
  491.       };
  492.     case "Astrology": {
  493.       const constellation = Astrology.constellations.find((a) => a.name == skillItem); // Find constellation
  494.       return () => {
  495.         if (skillLevel[CONSTANTS.skill.Astrology] < constellation.level) return false;
  496.         if (game.astrology.activeConstellation.id != constellation.id || game.activeSkill != globalThis.ActiveSkills.ASTROLOGY)
  497.           game.astrology.studyConstellationOnClick(constellation);
  498.         return true;
  499.       };
  500.     }
  501.     case "Cooking": {
  502.       const itemID = items.findIndex((a) => a.name == skillItem2);
  503.       const recipe = Cooking.recipes.find((a) => a.itemID == itemID);
  504.       const category = recipe.category;
  505.       if (skillItem == "Active") {
  506.         return () => {
  507.           const passives = [];
  508.           [0, 1, 2].forEach((c) => {
  509.             game.cooking.onCollectStockpileClick(c);
  510.             if (c != category && game.cooking.passiveCookTimers.has(c)) passives.push(c);
  511.           });
  512.           if (skillLevel[CONSTANTS.skill.Cooking] < recipe.cookingLevel) return false;
  513.           if (game.cooking.selectedRecipes.get(category).itemID != itemID) game.cooking.onRecipeSelectionClick(recipe);
  514.           if (game.activeSkill == globalThis.ActiveSkills.COOKING && game.cooking.activeCookingCategory == category) return true;
  515.           game.cooking.onActiveCookButtonClick(category);
  516.           passives.forEach((a) => game.cooking.onPassiveCookButtonClick(a));
  517.           return true;
  518.         };
  519.       } else {
  520.         return () => {
  521.           [0, 1, 2].forEach((category) => game.cooking.onCollectStockpileClick(category));
  522.           if (skillLevel[CONSTANTS.skill.Cooking] < Cooking.recipes.find((a) => a.itemID == itemID).level) return false;
  523.           if (game.cooking.selectedRecipes.get(category).itemID != itemID) game.cooking.onRecipeSelectionClick(recipe);
  524.           if (game.cooking.passiveCookTimers.has(category)) return true;
  525.           game.cooking.onPassiveCookButtonClick(category);
  526.           return true;
  527.         };
  528.       }
  529.     }
  530.     case "Crafting":
  531.       actionID = Crafting.recipes.find((a) => a.itemID == itemID).masteryID;
  532.       return () => {
  533.         if (skillLevel[CONSTANTS.skill.Crafting] < Crafting.recipes[actionID].level) return false;
  534.         if (game.crafting.selectedRecipeID !== actionID) game.crafting.selectRecipeOnClick(actionID);
  535.         if (game.activeSkill !== globalThis.ActiveSkills.CRAFTING) game.crafting.start(true);
  536.         return true;
  537.       };
  538.     case "Firemaking":
  539.       actionID = Firemaking.recipes.findIndex((x) => x.logID == itemID);
  540.       return () => {
  541.         if (skillLevel[CONSTANTS.skill.Firemaking] < Firemaking.recipes[actionID].levelRequired) return false;
  542.         if (!game.firemaking.activeRecipe || game.firemaking.activeRecipe.logID !== actionID) game.firemaking.selectLog(actionID);
  543.         if (!game.firemaking.isActive) game.firemaking.burnLog();
  544.         return true;
  545.       };
  546.     case "Fishing": {
  547.       const fish = Fishing.data.find((a) => a.itemID == itemID);
  548.       const area = Fishing.areas.find((a) => a.fish.includes(fish));
  549.       return () => {
  550.         if (
  551.           (!player.equipment.slotArray.map((a) => a.item.id).includes(CONSTANTS.item.Barbarian_Gloves) && area.id == 6) ||
  552.           (!game.fishing.secretAreaUnlocked && area.id == 7) ||
  553.           skillLevel[CONSTANTS.skill.Fishing] < fish.level
  554.         )
  555.           return false;
  556.         game.fishing.onAreaFishSelection(area, fish);
  557.         if (game.activeSkill !== globalThis.ActiveSkills.FISHING || game.fishing.activeFishingArea != area) {
  558.           game.fishing.onAreaStartButtonClick(area);
  559.         }
  560.         return true;
  561.       };
  562.     }
  563.     case "Fletching":
  564.       actionID = Fletching.recipes.find((a) => a.itemID == itemID).masteryID;
  565.       const log = items.findIndex((a) => a.name == skillItem2);
  566.       if (skillItem != "Arrow Shafts") {
  567.         return () => {
  568.           if (skillLevel[CONSTANTS.skill.Fletching] < Fletching.recipes[actionID].level) return false;
  569.           if (game.fletching.selectedRecipeID !== actionID) game.fletching.selectRecipeOnClick(actionID);
  570.           if (game.activeSkill !== globalThis.ActiveSkills.FLETCHING) game.fletching.start();
  571.           return true;
  572.         };
  573.       }
  574.       return () => {
  575.         if (skillLevel[CONSTANTS.skill.Fletching] < Fletching.recipes[actionID].level || !checkBankForItem(log)) return false;
  576.         if (game.fletching.selectedAltRecipe != log || selectedFletch !== actionID) game.fletching.selectAltRecipeOnClick(log);
  577.         if (game.activeSkill !== globalThis.ActiveSkills.FLETCHING) game.fletching.start();
  578.         return true;
  579.       };
  580.     case "Herblore":
  581.       actionID = Herblore.potions.findIndex((a) => a.name == skillItem);
  582.       return () => {
  583.         if (skillLevel[CONSTANTS.skill.Herblore] < Herblore.potions[actionID].level) return false;
  584.         if (game.herblore.selectedRecipeID !== actionID) game.herblore.selectRecipeOnClick(actionID);
  585.         if (!game.herblore.isActive) game.herblore.start();
  586.         return true;
  587.       };
  588.     case "Mining":
  589.       actionID = Mining.rockData.findIndex((a) => a.name == skillItem);
  590.       return () => {
  591.         if (
  592.           (actionID === 9 && !game.mining.canMineDragonite) ||
  593.           skillLevel[CONSTANTS.skill.Mining] < Mining.rockData[actionID].levelRequired
  594.         )
  595.           return false;
  596.         if (!game.mining.isActive || game.mining.selectedRockId != actionID) game.mining.onRockClick(actionID);
  597.         return true;
  598.       };
  599.     case "Magic": {
  600.       actionID = AltMagic.spells.findIndex((a) => a.name == skillItem);
  601.       const magicItem = items.findIndex((a) => a.name == skillItem2);
  602.       return () => {
  603.         if (skillLevel[CONSTANTS.skill.Magic] < AltMagic.spells[actionID].level) return false;
  604.         if (game.altMagic.selectedSpellID !== actionID) game.altMagic.selectSpellOnClick(actionID);
  605.         switch (AltMagic.spells[actionID].consumes) {
  606.           case 3:
  607.           case 2:
  608.             const bar = Smithing.recipes.find((a) => a.itemID == magicItem);
  609.             if (skillLevel[CONSTANTS.skill.Smithing] < bar.level) return false;
  610.             if (game.altMagic.selectedSmithingRecipe != bar) game.altMagic.selectBarOnClick(bar);
  611.             break;
  612.           case 1:
  613.           case 0:
  614.             if (game.altMagic.selectedConversionItem != magicItem) game.altMagic.selectItemOnClick(magicItem);
  615.             break;
  616.         }
  617.         if (!game.altMagic.isActive) game.altMagic.start();
  618.         return true;
  619.       };
  620.     }
  621.     case "Runecrafting":
  622.       actionID = Runecrafting.recipes.findIndex((a) => a.itemID == itemID);
  623.       return () => {
  624.         if (skillLevel[CONSTANTS.skill.Runecrafting] < Runecrafting.recipes[actionID].level) return false;
  625.         if (game.runecrafting.selectedRecipeID !== actionID) game.runecrafting.selectRecipeOnClick(actionID);
  626.         if (game.activeSkill !== globalThis.ActiveSkills.RUNECRAFTING) game.runecrafting.start(true);
  627.         return true;
  628.       };
  629.     case "Smithing":
  630.       actionID = Smithing.recipes.findIndex((a) => a.itemID == itemID);
  631.       return () => {
  632.         if (skillLevel[CONSTANTS.skill.Smithing] < Smithing.recipes[actionID].level) return false;
  633.         if (game.smithing.selectedRecipeID !== actionID) game.smithing.selectRecipeOnClick(actionID);
  634.         if (!game.smithing.isActive) game.smithing.start();
  635.         return true;
  636.       };
  637.     case "Summoning": {
  638.       const summonID = Summoning.marks.findIndex((a) => a.itemID == itemID);
  639.       let recipeID = 0;
  640.       if (options.actions["Start Skill"]["Summoning"][skillItem] != null) {
  641.         const ingredientID = items.findIndex((a) => a.name == skillItem2);
  642.         recipeID = Summoning.marks[summonID].nonShardItemCosts.findIndex((a) => a == ingredientID);
  643.       }
  644.       return () => {
  645.         //exit if low level
  646.         if (skillLevel[CONSTANTS.skill.Summoning] < Summoning.marks[summonID].level) return false;
  647.         //if summon is not selected, choose it
  648.         if (game.summoning.selectedRecipeID != summonID || game.summoning.selectedAltRecipe != recipeID) {
  649.           game.summoning.selectRecipeOnClick(summonID);
  650.           game.summoning.selectAltRecipeOnClick(recipeID);
  651.         }
  652.         if (game.activeSkill !== globalThis.ActiveSkills.SUMMONING) game.summoning.start();
  653.         return game.activeSkill === globalThis.ActiveSkills.SUMMONING;
  654.       };
  655.     }
  656.     case "Thieving": {
  657.       const npc = Thieving.npcs.find((a) => a.name == skillItem);
  658.       const area = Thieving.areas.find((a) => a.npcs.includes(npc.id));
  659.       const panel = thievingMenu.areaPanels.find((a) => a.area == area);
  660.       return () => {
  661.         if (skillLevel[CONSTANTS.skill.Thieving] < npc.level) return false;
  662.         if (game.activeSkill == globalThis.ActiveSkills.THIEVING && game.thieving.currentNPC == npc) return true;
  663.         thievingMenu.selectNPCInPanel(npc, panel);
  664.         game.thieving.startThieving(area, npc);
  665.         return true;
  666.       };
  667.     }
  668.     case "Woodcutting":
  669.       actionID = [itemID, items.findIndex((a) => a.name == skillItem2)].slice(0, playerModifiers.increasedTreeCutLimit + 1);
  670.       return () => {
  671.         let result = true;
  672.         let currentTrees = [];
  673.         game.woodcutting.activeTrees.forEach((a) => currentTrees.push(a.id));
  674.         currentTrees.forEach((tree) => {
  675.           if (actionID.includes(tree)) {
  676.             actionID.splice(
  677.               actionID.findIndex((a) => a == tree),
  678.               1
  679.             );
  680.           } else {
  681.             actionID.unshift(tree);
  682.           }
  683.         });
  684.  
  685.         actionID.forEach((i) => {
  686.           if (skillLevel[CONSTANTS.skill.Woodcutting] >= Woodcutting.trees[i].levelRequired) {
  687.             game.woodcutting.selectTree(Woodcutting.trees[i]);
  688.           } else {
  689.             result = false;
  690.           }
  691.         });
  692.         return result;
  693.       };
  694.   }
  695. }
  696.  
  697. class Action {
  698.   /**
  699.    * Create an action object with trigger
  700.    * @param {string} category (Tier 1 option) category for trigger
  701.    * @param {string} name (Tier 2 option) skill/item name
  702.    * @param {string} greaterThan (Tier 3 option) either ≥ or ≤
  703.    * @param {string} masteryItem (Tier 3 option) target name for mastery
  704.    * @param {string} number (Tier 4 option) target number for skill/mastery/item
  705.    * @param {string} actionCategory (Tier 1 option) category for action
  706.    * @param {string} actionName (Tier 2 option) skill/monster/item/set name
  707.    * @param {string} skillItem (Tier 3 option) name for skilling action
  708.    * @param {string} skillItem2 (Tier 4 option) name of second tree to cut or alt.magic item
  709.    * @param {string} qty (Tier 4 option) amount of item to buy if applicable
  710.    */
  711.   constructor(category, name, greaterThan, masteryItem, number, actionCategory, actionName, skillItem, skillItem2, qty) {
  712.     switch (category) {
  713.       case "Idle":
  714.         this.description = `If no active skills/combat:`;
  715.         break;
  716.       case "Item Quantity":
  717.         this.description = `If ${name} ${greaterThan} ${number}:`;
  718.         break;
  719.       case "Prayer Points":
  720.         this.description = `If prayer points ${greaterThan} ${number}:`;
  721.         break;
  722.       case "Skill Level":
  723.         this.description = `If ${name} ≥ level ${number}:`;
  724.         break;
  725.       case "Skill XP":
  726.         this.description = `If ${name} ≥ ${number}xp:`;
  727.         break;
  728.       case "Equipped Item Quantity": {
  729.         let plural = name;
  730.         if (!/s$/i.test(name)) plural += "s";
  731.         this.description = `If ≤ ${number} ${plural} equipped:`;
  732.         break;
  733.       }
  734.       case "Mastery Level":
  735.         this.description = `If ${name} ${masteryItem} mastery ≥ ${number}:`;
  736.         break;
  737.       case "Pet Unlocked":
  738.         this.description = `If ${name} unlocked:`;
  739.         break;
  740.       case "Mastery Pool %":
  741.         this.description = `If ${name} mastery pool ≥ ${number}%:`;
  742.         break;
  743.       case "Potion Depleted":
  744.         this.description = `If ${name} potion has depleted:`;
  745.         break;
  746.       case "Enemy in Combat":
  747.         this.description = `If fighting ${name}:`;
  748.     }
  749.     this.data = [category, name, greaterThan, masteryItem, number];
  750.     this.elementID = `AQ${nameIncrement++}`;
  751.     this.trigger = setTrigger(category, name, greaterThan, masteryItem, number);
  752.     if (typeof actionCategory == "string") {
  753.       this.action = [
  754.         {
  755.           elementID: `AQ${nameIncrement++}`,
  756.           data: [actionCategory, actionName, skillItem, skillItem2, qty],
  757.           start: setAction(actionCategory, actionName, skillItem, skillItem2, qty),
  758.           description: actionDescription(actionCategory, actionName, skillItem, skillItem2, qty),
  759.         },
  760.       ];
  761.     } else {
  762.       this.action = [];
  763.     }
  764.   }
  765. }
  766.  
  767. function actionDescription(actionCategory, actionName, skillItem, skillItem2, qty) {
  768.   let description = "";
  769.   switch (actionCategory) {
  770.     case "Start Skill":
  771.       description += `start ${actionName} ${skillItem}`;
  772.       if (actionName == "Summoning") {
  773.         description = `start creating ${skillItem} tablets`;
  774.         if (options.actions["Start Skill"]["Summoning"][skillItem] != null) {
  775.           description += ` from ${skillItem2}`;
  776.         }
  777.       }
  778.       if (actionName == "Astrology") description = `Start studying ${skillItem} in ${actionName}`;
  779.       if (actionName == "Cooking") description = `Start ${skillItem} Cooking ${skillItem2}`;
  780.       if (actionName == "Woodcutting") description += ` & ${skillItem2}`;
  781.       if (skillItem == "Arrow Shafts") description += ` from ${skillItem2}`;
  782.       if (actionName == "Magic") {
  783.         description += ` with ${skillItem2}`;
  784.         if (!/s$/i.test(skillItem2)) description += "s";
  785.       }
  786.       break;
  787.     case "Start Combat":
  788.       description += `start fighting ${actionName}`;
  789.       break;
  790.     case "Change Attack Style":
  791.       if (actionName == "Select Spell") {
  792.         description += `select ${skillItem2} spell`;
  793.       } else {
  794.         description += `change attack style to ${actionName}`;
  795.       }
  796.       break;
  797.     case "Switch Equipment Set":
  798.       description += `switch to equipment set ${actionName}`;
  799.       break;
  800.     case "Equip Item":
  801.       description += `equip ${actionName} to current set`;
  802.       break;
  803.     case "Equip Passive":
  804.       description += `equip ${actionName} to passive slot`;
  805.       break;
  806.     case "Unequip Item":
  807.       description += `unequip ${actionName} from current set`;
  808.       break;
  809.     case "Buy Item":
  810.       if (qty > 1) {
  811.         description += `buy ${qty} ${actionName} from shop`;
  812.       } else {
  813.         description += `buy ${actionName} from shop`;
  814.       }
  815.       break;
  816.     case "Sell Item":
  817.       description += `sell ${actionName}`;
  818.       break;
  819.     case "Use Potion":
  820.       description += `use ${actionName} potion`;
  821.       break;
  822.     case "Activate Prayers":
  823.       {
  824.         if (actionName == "None") {
  825.           description += `turn off prayers`;
  826.         } else {
  827.           description += `turn on ${actionName}`;
  828.           if (skillItem != "None") description += ` and ${skillItem}`;
  829.         }
  830.       }
  831.       break;
  832.     case "Build Agility Obstacle":
  833.       description += `build ${skillItem}`;
  834.       break;
  835.     case "Remove Agility Obstacle":
  836.       description += `remove obstacle ${actionName}`;
  837.       break;
  838.   }
  839.   return description;
  840. }
  841.  
  842. function resetForm(arr) {
  843.   arr.forEach((menu) => {
  844.     document.getElementById(`aq-num${menu}`).type = "hidden";
  845.     document.getElementById(`aq-num${menu}`).value = "";
  846.     validInputs[menu].forEach((a, i) => {
  847.       if (i != 0) {
  848.         document.getElementById(`aq-text${menu}${i}`).type = "hidden"; //hide all except first
  849.         document.getElementById(`aq-list${menu}${i}`).innerHTML = ""; //empty datalists
  850.       }
  851.       document.getElementById(`aq-text${menu}${i}`).value = ""; //clear values
  852.       validInputs[menu][i] = null;
  853.     });
  854.   });
  855. }
  856.  
  857. function submitForm() {
  858.   try {
  859.     //create array of the input values
  860.     const arr = [];
  861.     ["A", "B"].forEach((menu) => {
  862.       for (let i = 0; i < validInputs[menu].length; i++) arr.push(document.getElementById(`aq-text${menu}${i}`).value);
  863.       arr.push(document.getElementById(`aq-num${menu}`).value);
  864.     });
  865.     arr.splice(["≥", "≤", ""].includes(arr[2]) ? 3 : 2, 0, "");
  866.  
  867.     //validate trigger and action
  868.     if (
  869.       validateInput(
  870.         options.triggers,
  871.         arr.slice(0, 5).filter((a) => a !== "")
  872.       ) &&
  873.       validateInput(
  874.         options.actions,
  875.         arr.slice(5).filter((a) => a !== "")
  876.       )
  877.     ) {
  878.       addToQueue(new Action(...arr));
  879.       resetForm(["A", "B"]);
  880.     }
  881.   } catch (e) {
  882.     console.error(e);
  883.   }
  884.   return false;
  885. }
  886.  
  887. /**
  888.  * Function to validate user input
  889.  * @param {Object} obj options object to check against
  890.  * @param {Array} tier array of user inputs
  891.  * @param {number} n leave blank (used for recursion)
  892.  * @returns {boolean} true if input is valid
  893.  */
  894. function validateInput(obj, tier, n = 0) {
  895.   if (!obj.hasOwnProperty([tier[n]])) return false;
  896.   if (obj[tier[n]] === null || (obj[tier[n]] === "num" && /^\d{1,10}$/.test(tier[n + 1]))) return true;
  897.   return validateInput(obj[tier[n]], tier, n + 1);
  898. }
  899.  
  900. /**
  901.  * Updates input text boxes
  902.  * @param {string} menu ('A'||'B'||'C')
  903.  */
  904. function dropdowns(menu) {
  905.   let obj;
  906.   if (menu == "A") {
  907.     obj = options.triggers;
  908.   } else if (menu == "B") {
  909.     obj = options.actions;
  910.   } else {
  911.     obj = options[currentlyEditing.type == "triggers" ? "triggers" : "actions"];
  912.   }
  913.   for (let i = 0; i < validInputs[menu].length; i++) {
  914.     const value = document.getElementById(`aq-text${menu}${i}`).value;
  915.     if (Object.keys(obj).includes(value)) {
  916.       if (obj[value] == "num") {
  917.         document.getElementById(`aq-num${menu}`).type = "text";
  918.         break;
  919.       }
  920.       if (obj[value] == null) break;
  921.       obj = obj[value];
  922.       if (validInputs[menu][i] != value) {
  923.         validInputs[menu][i] = value;
  924.         document.getElementById(`aq-text${menu}${i + 1}`).type = "text";
  925.         document.getElementById(`aq-list${menu}${i + 1}`).innerHTML = "";
  926.         Object.keys(obj).forEach((e) => {
  927.           document.getElementById(`aq-list${menu}${i + 1}`).insertAdjacentHTML("beforeend", `<option>${e}</option>`);
  928.         });
  929.       }
  930.     } else {
  931.       validInputs[menu][i] = null;
  932.       for (i++; i < validInputs[menu].length; i++) {
  933.         try {
  934.           validInputs[menu][i] = null;
  935.           document.getElementById(`aq-text${menu}${i}`).type = "hidden";
  936.           document.getElementById(`aq-text${menu}${i}`).value = "";
  937.         } catch {}
  938.       }
  939.       document.getElementById(`aq-num${menu}`).type = "hidden";
  940.       document.getElementById(`aq-num${menu}`).value = "";
  941.     }
  942.   }
  943. }
  944.  
  945. const aqHTML = `<div class="content" id="action-queue-container" style="display: none">
  946. <div class="row row-deck">
  947.   <div class="col-md-12">
  948.     <div class="block block-rounded block-link-pop border-top border-settings border-4x">
  949.       <form class="aq-mastery-config" id="aq-mastery-config-container" style="display: none">
  950.         <div style="display: inline-block; margin-left: 20px; height: 180px; vertical-align: top">
  951.           <h3 class="aq-header">Mastery Config</h3>
  952.           <div>
  953.             <select id="aq-skill-list" class="aq-select"></select>
  954.           </div>
  955.           <div>
  956.             <select id="aq-checkpoint-list" class="aq-select">
  957.               <option value="0">0%</option>
  958.               <option value="0.1">10%</option>
  959.               <option value="0.25">25%</option>
  960.               <option value="0.5">50%</option>
  961.               <option value="0.95">95%</option>
  962.             </select>
  963.           </div>
  964.           <div>
  965.             <select id="aq-mastery-strategy" class="aq-select">
  966.               <option value="false">Lowest mastery</option>
  967.               <option value="true">Custom priority</option>
  968.             </select>
  969.           </div>
  970.           <div>
  971.             <select id="aq-base" class="aq-select"></select>
  972.           </div>
  973.           <div>
  974.             <input type="text" id="aq-mastery-array" class="aq-select"/>
  975.           </div>
  976.         </div>
  977.         <div style="margin-left: 20px">
  978.           <button type="button" class="btn btn-sm aq-green" id="aq-config-close">Done</button>
  979.         </div>
  980.       </form>
  981.       <form class="aq-popup" id="aq-edit-container" style="display: none;">
  982.         <div style="display: inline-block; margin-left: 20px; height: 180px; vertical-align: top">
  983.           <h3 id="aq-edit-form" class="aq-header">Action</h3>
  984.           <div>
  985.             <input type="text" class="aq-dropdown" id="aq-textC0" required list="aq-listC0" placeholder="Category" />
  986.           </div>
  987.           <div>
  988.             <input type="hidden" class="aq-dropdown" id="aq-textC1" list="aq-listC1" />
  989.           </div>
  990.           <div>
  991.             <input type="hidden" class="aq-dropdown" id="aq-textC2" list="aq-listC2" />
  992.           </div>
  993.           <div>
  994.             <input type="hidden" class="aq-dropdown" id="aq-textC3" list="aq-listC3" />
  995.           </div>
  996.           <div>
  997.             <input type="hidden" class="aq-dropdown" id="aq-numC" pattern="^\\d{1,10}$" placeholder="number" title="Positive integer"/>
  998.           </div>
  999.         </div>
  1000.         <div style="margin-left: 20px">
  1001.           <button type="button" id="aq-save-edit" class="btn btn-sm aq-blue">Save</button>
  1002.           <button type="button" id="aq-cancel" class="btn btn-sm btn-danger">Cancel</button>
  1003.         </div>
  1004.       </form>
  1005.       <div class="block-content">
  1006.         <div>
  1007.           <form id="aq-form">
  1008.             <div style="display: inline-block; margin-left: 20px; height: 180px; vertical-align: top">
  1009.               <h3 class="aq-header">Trigger</h3>
  1010.               <div>
  1011.                 <input type="text" class="aq-dropdown" id="aq-textA0" required list="aq-listA0" placeholder="Category" />
  1012.               </div>
  1013.               <div>
  1014.                 <input type="hidden" class="aq-dropdown" id="aq-textA1" list="aq-listA1" />
  1015.               </div>
  1016.               <div>
  1017.                 <input type="hidden" class="aq-dropdown" id="aq-textA2" list="aq-listA2" />
  1018.               </div>
  1019.               <div>
  1020.                 <input type="hidden" class="aq-dropdown" id="aq-numA" pattern="^\\d{1,10}$" placeholder="number" title="Positive integer"/>
  1021.               </div>
  1022.             </div>
  1023.             <div style="display: inline-block; margin-left: 20px; height: 180px; vertical-align: top">
  1024.               <h3 class="aq-header">Action</h3>
  1025.               <div>
  1026.                 <input type="text" class="aq-dropdown" id="aq-textB0" required list="aq-listB0" placeholder="Category" />
  1027.               </div>
  1028.               <div>
  1029.                 <input type="hidden" class="aq-dropdown" id="aq-textB1" list="aq-listB1" />
  1030.               </div>
  1031.               <div>
  1032.                 <input type="hidden" class="aq-dropdown" id="aq-textB2" list="aq-listB2" />
  1033.               </div>
  1034.               <div>
  1035.                 <input type="hidden" class="aq-dropdown" id="aq-textB3" list="aq-listB3" />
  1036.               </div>
  1037.               <div>
  1038.                 <input type="hidden" class="aq-dropdown" id="aq-numB" pattern="^\\d{1,10}$" placeholder="number" title="Positive integer"/>
  1039.               </div>
  1040.             </div>
  1041.             <div style="margin-left: 20px">
  1042.               <input type="submit" class="btn btn-sm aq-blue" value="Add to queue">
  1043.               <button type="button" id="aq-pause" class="btn btn-sm aq-yellow">Pause</button>
  1044.             </div>
  1045.           </form>
  1046.         </div>
  1047.         <form style="margin: 10px 0 5px 20px">
  1048.           <button type="button" class="btn btn-sm aq-grey" id="aq-download">Download Action List</button>
  1049.           <input type="submit" class="btn btn-sm aq-grey" value="Import Action List" />
  1050.           <input type="text" id="aq-pastebin" style="width: 236px;" required pattern="^\\[.*\\]$" placeholder="Paste data here" />
  1051.         </form>
  1052.         <div style="display: flex;justify-content: space-between;max-width: 550px;margin: 10px 0 0 25px;">
  1053.           <p style="margin: 0;">Looping</p>
  1054.           <div class="">
  1055.             <div class="custom-control custom-radio custom-control-inline custom-control-lg">
  1056.                 <input type="radio" class="custom-control-input" id="aq-loop-enable" name="aq-looping">
  1057.                 <label class="custom-control-label" for="aq-loop-enable">Enable</label>
  1058.             </div>
  1059.             <div class="custom-control custom-radio custom-control-inline custom-control-lg">
  1060.                 <input type="radio" class="custom-control-input" id="aq-loop-disable" name="aq-looping" checked="">
  1061.                 <label class="custom-control-label" for="aq-loop-disable">Disable</label>
  1062.             </div>
  1063.           </div>
  1064.         </div>
  1065.         <div style="display: flex;justify-content: space-between;max-width: 550px;margin: 10px 0 0 25px;">
  1066.           <p style="margin: 0;">Mastery Pool Management</p>
  1067.           <div class="">
  1068.             <div class="custom-control custom-radio custom-control-inline custom-control-lg">
  1069.                 <input type="radio" class="custom-control-input" id="aq-mastery-enable" name="aq-mastery">
  1070.                 <label class="custom-control-label" for="aq-mastery-enable">Enable</label>
  1071.             </div>
  1072.             <div class="custom-control custom-radio custom-control-inline custom-control-lg">
  1073.                 <input type="radio" class="custom-control-input" id="aq-mastery-disable" name="aq-mastery" checked="">
  1074.                 <label class="custom-control-label" for="aq-mastery-disable">Disable</label>
  1075.             </div>
  1076.           </div>
  1077.         </div>
  1078.         <div style="margin: 10px 0 0 25px; display: flex; justify-content: space-between">
  1079.           <button type="button" class="btn btn-sm aq-grey" id="aq-mastery-config">Advanced Mastery Options</button>
  1080.           <button type="button" style="font-size: 0.875rem" class="btn aq-delete btn-danger" id="aq-delete-all">delete all</button>
  1081.         </div>
  1082.         <h2 class="content-heading border-bottom mb-4 pb-2">Current Queue</h2>
  1083.         <div style="min-height: 50px" id="aq-item-container"></div>
  1084.       </div>
  1085.     </div>
  1086.   </div>
  1087. </div>
  1088. </div>
  1089. <datalist id="aq-listA0"></datalist>
  1090. <datalist id="aq-listA1"></datalist>
  1091. <datalist id="aq-listA2"></datalist>
  1092. <datalist id="aq-listB0"></datalist>
  1093. <datalist id="aq-listB1"></datalist>
  1094. <datalist id="aq-listB2"></datalist>
  1095. <datalist id="aq-listB3"></datalist>
  1096. <datalist id="aq-listC0"></datalist>
  1097. <datalist id="aq-listC1"></datalist>
  1098. <datalist id="aq-listC2"></datalist>
  1099. <datalist id="aq-listC3"></datalist>
  1100. <style>
  1101. .aq-dropdown {
  1102.   width: 260px;
  1103. }
  1104. .aq-header {
  1105.   margin-bottom: 10px;
  1106.   color: whitesmoke;
  1107. }
  1108. .aq-arrow {
  1109.   font-size: 2rem;
  1110.   padding: 0px 0.25rem;
  1111.   line-height: 0px;
  1112.   margin: 0.25rem 2px;
  1113.   border-radius: 0.2rem;
  1114. }
  1115. .aq-item {
  1116.   background-color: #464646;
  1117.   padding: 12px;
  1118.   margin: 12px;
  1119.   cursor: move;
  1120. }
  1121. .aq-item-inner {
  1122.   display: flex;
  1123.   justify-content: space-between;
  1124.   cursor: move;
  1125. }
  1126. .aq-delete {
  1127.   font-size: 1.2rem;
  1128.   padding: 0px 0.36rem;
  1129.   line-height: 0px;
  1130.   margin: 0.25rem 0.25rem 0.25rem 0.125rem;
  1131.   border-radius: 0.2rem;
  1132. }
  1133. .aq-grey {
  1134.   background-color: #676767;
  1135. }
  1136. .aq-grey:hover {
  1137.   background-color: #848484;
  1138. }
  1139. .aq-blue {
  1140.   background-color: #0083ff;
  1141. }
  1142. .aq-blue:hover {
  1143.   background-color: #63b4ff;
  1144. }
  1145. .aq-green {
  1146.   background-color: #5a9e00;
  1147. }
  1148. .aq-green:hover {
  1149.   background-color: #7bd900;
  1150. }
  1151. .aq-yellow {
  1152.   background-color: #e69721;
  1153. }
  1154. .aq-yellow:hover {
  1155.   background-color: #ffb445;
  1156. }
  1157. .t-drag {
  1158.   opacity: 0.5;
  1159. }
  1160. .a-drag {
  1161.   opacity: 0.5;
  1162. }
  1163. .aq-popup {
  1164.   position: fixed;
  1165.   right: 5%;
  1166.   top: 20%;
  1167.   z-index: 2;
  1168.   background-color: #3f4046;
  1169.   padding: 20px 20px 20px 0;
  1170.   border-top: 1px solid #e1e6e9;
  1171.   border-radius: 0.25rem;
  1172.   border-width: 4px;
  1173. }
  1174. .aq-mastery-config {
  1175.   position: fixed;
  1176.   right: 67%;
  1177.   top: 18%;
  1178.   z-index: 3;
  1179.   background-color: #3f4046;
  1180.   padding: 20px 20px 20px 0;
  1181.   border-top: 1px solid #e1e6e9;
  1182.   border-radius: 0.25rem;
  1183.   border-width: 4px;
  1184. }
  1185. .aq-select {
  1186.   width: 200px;
  1187. }
  1188. </style>
  1189. `;
  1190.  
  1191. function loadAQ() {
  1192.   //add item names
  1193.   for (const a of items) {
  1194.     options.triggers["Item Quantity"][a.name] = { "≥": "num", "≤": "num" };
  1195.     options.actions["Sell Item"][a.name] = null;
  1196.     if (a.validSlots && a.validSlots.includes("Passive")) options.actions["Equip Passive"][a.name] = null;
  1197.   }
  1198.  
  1199.   //add attack styles
  1200.   for (const s in CONSTANTS.attackStyle) {
  1201.     if (isNaN(s)) options.actions["Change Attack Style"][s] = null;
  1202.   }
  1203.   //add normal spells
  1204.   for (const s of SPELLS) {
  1205.     options.actions["Change Attack Style"]["Select Spell"]["Normal"][s.name] = null;
  1206.   }
  1207.   //add curse spells
  1208.   for (const s of CURSES) {
  1209.     options.actions["Change Attack Style"]["Select Spell"]["Curse"][s.name] = null;
  1210.   }
  1211.   //add aurora spells
  1212.   for (const s of AURORAS) {
  1213.     options.actions["Change Attack Style"]["Select Spell"]["Aurora"][s.name] = null;
  1214.   }
  1215.   //add ancient spells
  1216.   for (const s of ANCIENT) {
  1217.     options.actions["Change Attack Style"]["Select Spell"]["Ancient"][s.name] = null;
  1218.   }
  1219.  
  1220.   //add pet names
  1221.   for (const pet of PETS) {
  1222.     const name = `${pet.name.split(",")[0]} (${pet.acquiredBy})`;
  1223.     options.triggers["Pet Unlocked"][name] = null;
  1224.   }
  1225.  
  1226.   //add skill names
  1227.   Object.keys(CONSTANTS.skill).forEach((a) => {
  1228.     if (isNaN(a)) options.triggers["Skill Level"][a] = "num";
  1229.   });
  1230.   options.triggers["Skill XP"] = options.triggers["Skill Level"];
  1231.   Object.keys(options.triggers["Mastery Level"]).forEach((skill) => (options.triggers["Mastery Pool %"][skill] = "num"));
  1232.  
  1233.   //add mastery/action names for each skill
  1234.   {
  1235.     Astrology.constellations.forEach((item) => {
  1236.       options.triggers["Mastery Level"]["Astrology"][item.name] = "num";
  1237.       options.actions["Start Skill"]["Astrology"][item.name] = null;
  1238.     });
  1239.     Cooking.recipes.forEach((item) => {
  1240.       options.triggers["Mastery Level"]["Cooking"][items[item.itemID].name] = "num";
  1241.     });
  1242.     options.actions["Start Skill"]["Cooking"]["Active"] = Cooking.recipes.reduce((obj, a) => {
  1243.       obj[items[a.itemID].name] = null;
  1244.       return obj;
  1245.     }, {});
  1246.     options.actions["Start Skill"]["Cooking"]["Passive"] = options.actions["Start Skill"]["Cooking"]["Active"];
  1247.  
  1248.     Crafting.recipes.forEach((item) => {
  1249.       options.triggers["Mastery Level"]["Crafting"][items[item.itemID].name] = "num";
  1250.       options.actions["Start Skill"]["Crafting"][items[item.itemID].name] = null;
  1251.     });
  1252.  
  1253.     items.forEach((item) => {
  1254.       if (item.type == "Seeds") {
  1255.         options.triggers["Mastery Level"]["Farming"][item.name] = "num";
  1256.       }
  1257.     });
  1258.  
  1259.     items.forEach((item) => {
  1260.       if (item.type == "Logs") {
  1261.         options.triggers["Mastery Level"]["Firemaking"][item.name] = "num";
  1262.         options.actions["Start Skill"]["Firemaking"][item.name] = null;
  1263.       }
  1264.     });
  1265.  
  1266.     Fishing.data.forEach((item) => {
  1267.       options.triggers["Mastery Level"]["Fishing"][items[item.itemID].name] = "num";
  1268.       options.actions["Start Skill"]["Fishing"][items[item.itemID].name] = null;
  1269.     });
  1270.  
  1271.     items.forEach((item) => {
  1272.       if (item.type == "Logs") {
  1273.         options.triggers["Mastery Level"]["Woodcutting"][item.name] = "num";
  1274.         options.actions["Start Skill"]["Woodcutting"][item.name] = {};
  1275.       }
  1276.     });
  1277.     for (const log in options.actions["Start Skill"]["Woodcutting"]) {
  1278.       Object.keys(options.actions["Start Skill"]["Woodcutting"]).forEach(
  1279.         (a) => (options.actions["Start Skill"]["Woodcutting"][log][a] = null)
  1280.       );
  1281.     }
  1282.  
  1283.     Fletching.recipes.forEach((item) => {
  1284.       options.triggers["Mastery Level"]["Fletching"][items[item.itemID].name] = "num";
  1285.       options.actions["Start Skill"]["Fletching"][items[item.itemID].name] = null;
  1286.     });
  1287.     options.actions["Start Skill"]["Fletching"]["Arrow Shafts"] = {};
  1288.     for (const log in options.actions["Start Skill"]["Woodcutting"]) {
  1289.       options.actions["Start Skill"]["Fletching"]["Arrow Shafts"][log] = null;
  1290.     }
  1291.  
  1292.     Herblore.potions.forEach((item) => {
  1293.       options.triggers["Mastery Level"]["Herblore"][item.name] = "num";
  1294.       options.actions["Start Skill"]["Herblore"][item.name] = null;
  1295.     });
  1296.  
  1297.     Agility.obstacles.forEach((item) => {
  1298.       options.triggers["Mastery Level"]["Agility"][item.name] = "num";
  1299.     });
  1300.  
  1301.     Mining.rockData.forEach((item) => {
  1302.       options.triggers["Mastery Level"]["Mining"][item.name] = "num";
  1303.       options.actions["Start Skill"]["Mining"][item.name] = null;
  1304.     });
  1305.  
  1306.     Runecrafting.recipes.forEach((item) => {
  1307.       options.triggers["Mastery Level"]["Runecrafting"][items[item.itemID].name] = "num";
  1308.       options.actions["Start Skill"]["Runecrafting"][items[item.itemID].name] = null;
  1309.     });
  1310.  
  1311.     Smithing.recipes.forEach((item) => {
  1312.       options.triggers["Mastery Level"]["Smithing"][items[item.itemID].name] = "num";
  1313.       options.actions["Start Skill"]["Smithing"][items[item.itemID].name] = null;
  1314.     });
  1315.  
  1316.     Thieving.npcs.forEach((npc) => {
  1317.       options.triggers["Mastery Level"]["Thieving"][npc.name] = "num";
  1318.       options.actions["Start Skill"]["Thieving"][npc.name] = null;
  1319.     });
  1320.  
  1321.     Summoning.marks.forEach((item) => {
  1322.       options.triggers["Mastery Level"]["Summoning"][items[item.itemID].name] = "num";
  1323.       if (item.nonShardItemCosts.length == 1) {
  1324.         options.actions["Start Skill"]["Summoning"][items[item.itemID].name] = null;
  1325.       } else {
  1326.         options.actions["Start Skill"]["Summoning"][items[item.itemID].name] = {};
  1327.         item.nonShardItemCosts.forEach((ingredient) => {
  1328.           options.actions["Start Skill"]["Summoning"][items[item.itemID].name][items[ingredient].name] = null;
  1329.         });
  1330.       }
  1331.     });
  1332.   }
  1333.  
  1334.   //agility obstacles
  1335.   options.actions["Build Agility Obstacle"] = Agility.obstacles.reduce((obj, a) => {
  1336.     if (!obj.hasOwnProperty(a.category + 1)) obj[a.category + 1] = {};
  1337.     obj[a.category + 1][a.name] = null;
  1338.     return obj;
  1339.   }, {});
  1340.   Object.keys(options.actions["Build Agility Obstacle"]).forEach((a) => (options.actions["Remove Agility Obstacle"][a] = null));
  1341.  
  1342.   //potions
  1343.   options.actions["Use Potion"] = items.reduce((obj, item) => {
  1344.     if (item.type == "Potion") obj[item.name] = null;
  1345.     return obj;
  1346.   }, {});
  1347.  
  1348.   //prayer actions
  1349.   PRAYER.forEach((prayer) => (options.actions["Activate Prayers"][prayer.name] = {}));
  1350.   for (const prayer1 in options.actions["Activate Prayers"]) {
  1351.     PRAYER.forEach((prayer) => (options.actions["Activate Prayers"][prayer1][prayer.name] = null));
  1352.     options.actions["Activate Prayers"][prayer1]["None"] = null;
  1353.   }
  1354.   options.actions["Activate Prayers"]["None"] = null;
  1355.  
  1356.   //add altmagic names
  1357.   AltMagic.spells.forEach((spell) => {
  1358.     options.actions["Start Skill"]["Magic"][spell.name] = {};
  1359.     if (spell.consumes === 2 || spell.consumes === 3) {
  1360.       for (const item of AltMagic.smithingBarRecipes) {
  1361.         options.actions["Start Skill"]["Magic"][spell.name][items[item.itemID].name] = null;
  1362.       }
  1363.     } else if (spell.consumes === 1) {
  1364.       Fishing.junkItems.forEach((a) => (options.actions["Start Skill"]["Magic"][spell.name][items[a].name] = null));
  1365.     } else if (spell.consumes === 0) {
  1366.       options.actions["Start Skill"]["Magic"][spell.name] = options.actions["Sell Item"];
  1367.     } else options.actions["Start Skill"]["Magic"][spell.name] = null;
  1368.   });
  1369.  
  1370.   //add food and ammo names
  1371.   for (const a of items.filter((a) => a.canEat)) {
  1372.     options.triggers["Equipped Item Quantity"][a.name] = "num";
  1373.     options.actions["Equip Item"][a.name] = null;
  1374.   }
  1375.   for (const a of items.filter((a) => a.hasOwnProperty("validSlots") && (a.validSlots[0] == "Quiver" || a.validSlots[0] == "Summon1")))
  1376.     options.triggers["Equipped Item Quantity"][a.name] = "num";
  1377.  
  1378.   //edit buyShopItem  function so that it returns boolean based on if it met requirements
  1379.   eval(
  1380.     buyShopItem
  1381.       .toString()
  1382.       .replace(/}\s*}$/, "return canBuy}}")
  1383.       .replace(/^function (\w+)/, "window.$1 = function")
  1384.   );
  1385.  
  1386.   //add shop items
  1387.   for (const category in SHOP) {
  1388.     SHOP[category].forEach((item, id) => {
  1389.       let name = item.name;
  1390.       if (name == "Extra Equipment Set") {
  1391.         item.cost.gp > 0 ? (name += " (GP)") : (name += " (SC)");
  1392.       }
  1393.       if (category == "Materials" || category == "Gloves") {
  1394.         shop[name] = {
  1395.           buy: (qty) => {
  1396.             updateBuyQty(qty);
  1397.             return buyShopItem(category, id, true);
  1398.           },
  1399.         };
  1400.         options.actions["Buy Item"][name] = "num";
  1401.       } else {
  1402.         shop[name] = { buy: () => buyShopItem(category, id, true) };
  1403.         options.actions["Buy Item"][name] = null;
  1404.       }
  1405.     });
  1406.   }
  1407.  
  1408.   //add monster/dungeon names
  1409.   {
  1410.     //collect monster IDs
  1411.     const monsterIDs = [];
  1412.     for (const area of combatAreas) monsterIDs.push(...area.monsters);
  1413.     for (const area of slayerAreas) monsterIDs.push(...area.monsters);
  1414.     //add names to array
  1415.     for (const monster of monsterIDs) options.actions["Start Combat"][MONSTERS[monster].name] = null;
  1416.     for (const dungeon of DUNGEONS) options.actions["Start Combat"][dungeon.name] = null;
  1417.     for (const monster of MONSTERS) options.triggers["Enemy in Combat"][monster.name] = null;
  1418.   }
  1419.  
  1420.   //add equippable items
  1421.   for (const a of items.filter((a) => a.hasOwnProperty("validSlots"))) {
  1422.     options.actions["Equip Item"][a.name] = null;
  1423.     options.actions["Unequip Item"][a.name] = null;
  1424.   }
  1425.  
  1426.   //add in sidebar item
  1427.   document.getElementsByClassName("bank-space-nav")[0].parentNode.parentNode.insertAdjacentHTML(
  1428.     "afterend",
  1429.     `<li class="nav-main-item">
  1430.   <a class="nav-main-link nav-compact" style="cursor: pointer;">
  1431.     <img class="nav-img" src="assets/media/skills/prayer/mystic_lore.svg">
  1432.     <span class="nav-main-link-name">Action Queue</span>
  1433.     <small id="current-queue" style="color: rgb(210, 106, 92);">inactive</small>
  1434.   </a>
  1435. </li>`
  1436.   );
  1437.   //add click for sidebar item
  1438.   $("li.nav-main-item:contains(Action Queue)")[0].addEventListener("click", () => actionTab());
  1439.  
  1440.   const htmlCollection = $('div[onclick^="changePage"]');
  1441.   for (let i = 0; i < htmlCollection.length; i++) htmlCollection[i].addEventListener("click", () => hideActionTab());
  1442.  
  1443.   //add main html
  1444.   document.getElementById("main-container").insertAdjacentHTML("beforeend", aqHTML);
  1445.  
  1446.   //add button clicks
  1447.   document.getElementById("aq-pause").addEventListener("click", () => togglePause());
  1448.   document.getElementById("aq-download").addEventListener("click", () => downloadActions());
  1449.   document.getElementById("aq-mastery-config").addEventListener("click", () => masteryPopup(true));
  1450.   document.getElementById("aq-loop-enable").addEventListener("click", () => toggleLoop(true));
  1451.   document.getElementById("aq-loop-disable").addEventListener("click", () => toggleLoop(false));
  1452.   document.getElementById("aq-mastery-enable").addEventListener("click", () => toggleMastery(true));
  1453.   document.getElementById("aq-mastery-disable").addEventListener("click", () => toggleMastery(false));
  1454.   document.getElementById("aq-cancel").addEventListener("click", () => cancelEdit());
  1455.   document.getElementById("aq-delete-all").addEventListener("click", () => clearQueue());
  1456.   document.getElementById("aq-save-edit").addEventListener("click", () => submitEdit());
  1457.   document.getElementById("aq-form").addEventListener("submit", (e) => {
  1458.     e.preventDefault();
  1459.     submitForm();
  1460.   });
  1461.   document.getElementById("aq-item-container").parentNode.children[1].addEventListener("submit", (e) => {
  1462.     e.preventDefault();
  1463.     importActions();
  1464.   });
  1465.   for (const menu in validInputs) {
  1466.     validInputs[menu].forEach((a, i) => {
  1467.       document.getElementById(`aq-text${menu}${i}`).addEventListener("input", () => {
  1468.         dropdowns(menu);
  1469.       });
  1470.     });
  1471.   }
  1472.   document.getElementById("aq-skill-list").addEventListener("change", () => updateMasteryConfig());
  1473.   document.getElementById("aq-checkpoint-list").addEventListener("change", () => updateMasteryConfig(false));
  1474.   document.getElementById("aq-mastery-strategy").addEventListener("change", () => updateMasteryConfig(false));
  1475.   document.getElementById("aq-base").addEventListener("change", () => updateMasteryConfig(false));
  1476.   document.getElementById("aq-config-close").addEventListener("click", () => masteryPopup(false));
  1477.   document.getElementById(`aq-mastery-array`).addEventListener("input", () => updateMasteryConfig(false));
  1478.  
  1479.   //fills category lists
  1480.   Object.keys(options.triggers).forEach((a) =>
  1481.     document.getElementById("aq-listA0").insertAdjacentHTML("beforeend", `<option>${a}</option>`)
  1482.   );
  1483.   Object.keys(options.actions).forEach((a) =>
  1484.     document.getElementById("aq-listB0").insertAdjacentHTML("beforeend", `<option>${a}</option>`)
  1485.   );
  1486.  
  1487.   //add event listener for dragging trigger blocks
  1488.   const triggerContainer = document.getElementById("aq-item-container");
  1489.   triggerContainer.addEventListener("dragover", (e) => {
  1490.     e.preventDefault();
  1491.     const draggable = document.querySelector(".t-drag");
  1492.     if (!draggable || document.querySelector(".a-drag") != null) return;
  1493.     const afterElement = getDragAfterElement(triggerContainer, e.clientY, ".aq-item");
  1494.     if (afterElement == null) {
  1495.       triggerContainer.appendChild(draggable);
  1496.     } else {
  1497.       triggerContainer.insertBefore(draggable, afterElement);
  1498.     }
  1499.   });
  1500.  
  1501.   //mastery stuff
  1502.   for (let i = 1; i < 100; i++) {
  1503.     lvlIndex[i] = exp.level_to_xp(i) + 1;
  1504.   }
  1505.   for (const skill in MASTERY) {
  1506.     masteryConfig[skill] = {
  1507.       checkpoint: 0.95,
  1508.       prio: false,
  1509.       base: 87,
  1510.       arr: [],
  1511.     };
  1512.     masteryClone[skill] = {
  1513.       pool: MASTERY[skill].pool,
  1514.       lvl: [],
  1515.     };
  1516.     updateMasteryLvl(skill);
  1517.   }
  1518.  
  1519.   for (const name in CONSTANTS.skill) {
  1520.     if (Object.keys(MASTERY).includes(`${CONSTANTS.skill[name]}`))
  1521.       document.getElementById("aq-skill-list").insertAdjacentHTML("beforeend", `<option value="${CONSTANTS.skill[name]}">${name}</option>`);
  1522.   }
  1523.   for (let i = 60; i < 88; i++) document.getElementById("aq-base").insertAdjacentHTML("beforeend", `<option value="${i}">${i}</option>`);
  1524.   tooltips.masteryConfig = [
  1525.     tippy(document.getElementById("aq-checkpoint-list"), {
  1526.       content: "Minimum pool % to maintain",
  1527.       animation: false,
  1528.     }),
  1529.     tippy(document.getElementById("aq-mastery-strategy"), {
  1530.       content: "Mastery pool spending strategy",
  1531.       animation: false,
  1532.     }),
  1533.     tippy(document.getElementById("aq-base"), {
  1534.       content: "Target mastery level for custom priority list",
  1535.       animation: false,
  1536.     }),
  1537.   ];
  1538.  
  1539.   window.masteryIDs = {};
  1540.   for (const skillName in options.triggers["Mastery Level"]) {
  1541.     masteryIDs[skillName] = {};
  1542.     for (const name in options.triggers["Mastery Level"][skillName]) masteryIDs[skillName][name] = fetchMasteryID(skillName, name);
  1543.   }
  1544.  
  1545.   //load locally stored action queue if it exists
  1546.   loadLocalSave();
  1547.   console.log("Action Queue loaded");
  1548. }
  1549.  
  1550. function triggerCheck() {
  1551.   let result = true;
  1552.   if (currentActionIndex >= actionQueueArray.length) {
  1553.     if (queueLoop && actionQueueArray.length > 0) {
  1554.       currentActionIndex = 0;
  1555.       updateQueue();
  1556.       return;
  1557.     } else {
  1558.       clearInterval(triggerCheckInterval);
  1559.       triggerCheckInterval = null;
  1560.       updateTextColour("stop");
  1561.       return;
  1562.     }
  1563.   }
  1564.   if (actionQueueArray[currentActionIndex].trigger()) {
  1565.     actionQueueArray[currentActionIndex].action.forEach((action, i) => {
  1566.       result = action.start();
  1567.       document.getElementById(actionQueueArray[currentActionIndex].elementID).children[1].children[
  1568.         i
  1569.       ].children[1].children[0].style.display = result ? "none" : "";
  1570.     });
  1571.     currentActionIndex + 1 >= actionQueueArray.length && queueLoop ? (currentActionIndex = 0) : currentActionIndex++;
  1572.     updateQueue();
  1573.   }
  1574. }
  1575.  
  1576. /**
  1577.  * Updates colour and text in sidebar
  1578.  * @param {string} type ("start" || "stop" || "pause")
  1579.  */
  1580. function updateTextColour(type) {
  1581.   switch (type) {
  1582.     case "start":
  1583.       document.getElementById("current-queue").style.color = "#46c37b";
  1584.       document.getElementById("current-queue").innerHTML = "running";
  1585.       break;
  1586.     case "stop":
  1587.       document.getElementById("current-queue").style.color = "#d26a5c";
  1588.       document.getElementById("current-queue").innerHTML = "inactive";
  1589.       break;
  1590.     case "pause":
  1591.       document.getElementById("current-queue").style.color = "#f3b760";
  1592.       document.getElementById("current-queue").innerHTML = "paused";
  1593.   }
  1594. }
  1595.  
  1596. function updateQueue() {
  1597.   actionQueueArray.forEach((action, index) => {
  1598.     const element = document.getElementById(action.elementID);
  1599.     if (index === currentActionIndex) {
  1600.       for (let i = 0; i < element.children[1].children.length; i++) {
  1601.         element.children[1].children[i].children[1].children[0].style.display = "none";
  1602.       }
  1603.       element.style.backgroundColor = "#385a0b";
  1604.     } else element.style.backgroundColor = "";
  1605.   });
  1606. }
  1607.  
  1608. function toggleLoop(start) {
  1609.   queueLoop = start;
  1610. }
  1611.  
  1612. function togglePause() {
  1613.   queuePause = !queuePause;
  1614.   if (queuePause) {
  1615.     clearInterval(triggerCheckInterval);
  1616.     triggerCheckInterval = null;
  1617.     document.getElementById("aq-pause").innerHTML = "Unpause";
  1618.     document.getElementById("aq-pause").classList.add("aq-green");
  1619.     document.getElementById("aq-pause").classList.remove("aq-yellow");
  1620.     updateTextColour("pause");
  1621.   } else {
  1622.     if (actionQueueArray.length > 0) {
  1623.       updateQueue();
  1624.       triggerCheckInterval = setInterval(() => {
  1625.         triggerCheck();
  1626.       }, 1000);
  1627.       updateTextColour("start");
  1628.     } else {
  1629.       updateTextColour("stop");
  1630.     }
  1631.     document.getElementById("aq-pause").innerHTML = "Pause";
  1632.     document.getElementById("aq-pause").classList.add("aq-yellow");
  1633.     document.getElementById("aq-pause").classList.remove("aq-green");
  1634.   }
  1635. }
  1636.  
  1637. let loadCheckInterval = setInterval(() => {
  1638.   if (isLoaded) {
  1639.     clearInterval(loadCheckInterval);
  1640.     loadAQ();
  1641.   }
  1642. }, 200);
  1643.  
  1644. function autoSave() {
  1645.   const saveData = {
  1646.     index: currentActionIndex,
  1647.     data: [],
  1648.     loop: queueLoop,
  1649.     mastery: manageMasteryInterval === null ? false : true,
  1650.   };
  1651.   for (const action of actionQueueArray) {
  1652.     let actionList = [];
  1653.     action.action.forEach((a) => actionList.push(a.data));
  1654.     saveData.data.push([...action.data, actionList]);
  1655.   }
  1656.   window.localStorage.setItem("AQSAVE" + currentCharacter, JSON.stringify(saveData));
  1657.   window.localStorage.setItem("AQMASTERY", JSON.stringify(masteryConfig));
  1658. }
  1659.  
  1660. //autosave every ~minute
  1661. setInterval(() => {
  1662.   autoSave();
  1663. }, 59550);
  1664.  
  1665. function loadLocalSave() {
  1666.   const obj = JSON.parse(window.localStorage.getItem("AQSAVE" + currentCharacter));
  1667.   const config = JSON.parse(window.localStorage.getItem("AQMASTERY"));
  1668.   if (config != null) {
  1669.     for (const skill in config) {
  1670.       masteryConfig[skill] = config[skill];
  1671.     }
  1672.   }
  1673.  
  1674.   if (obj === null) return;
  1675.   if (obj.loop) {
  1676.     toggleLoop(true);
  1677.     document.getElementById("aq-loop-enable").checked = true;
  1678.   }
  1679.   if (obj.mastery) {
  1680.     toggleMastery(true);
  1681.     document.getElementById("aq-mastery-enable").checked = true;
  1682.   }
  1683.   if (obj.data.length > 0) togglePause();
  1684.   currentActionIndex = obj.index;
  1685.   for (const params of obj.data) {
  1686.     if (params.length == 6) {
  1687.       const newAction = new Action(...params.slice(0, 5));
  1688.       params[5].forEach((data) => {
  1689.         newAction.action.push({
  1690.           elementID: `AQ${nameIncrement++}`,
  1691.           data,
  1692.           start: setAction(...data),
  1693.           description: actionDescription(...data),
  1694.         });
  1695.       });
  1696.       addToQueue(newAction);
  1697.     } else {
  1698.       addToQueue(new Action(...params));
  1699.     }
  1700.   }
  1701.   updateQueue();
  1702. }
  1703.  
  1704. function setCurrentAction(id) {
  1705.   const index = actionQueueArray.findIndex((a) => a.elementID == id);
  1706.   if (index >= 0) {
  1707.     currentActionIndex = index;
  1708.     updateQueue();
  1709.   }
  1710. }
  1711.  
  1712. function importActions() {
  1713.   const string = document.getElementById("aq-pastebin").value;
  1714.   if (!queuePause && actionQueueArray.length === 0) togglePause();
  1715.   let arr = [];
  1716.   try {
  1717.     arr = JSON.parse(string.trim());
  1718.     if (!Array.isArray(arr)) return false;
  1719.     for (const params of arr) {
  1720.       try {
  1721.         let newAction = null;
  1722.         if (params.length == 10) {
  1723.           newAction = new Action(...params);
  1724.         } else if (params.length == 6) {
  1725.           newAction = new Action(...params.slice(0, 5));
  1726.           params[5].forEach((data) => {
  1727.             newAction.action.push({
  1728.               elementID: `AQ${nameIncrement++}`,
  1729.               data,
  1730.               start: setAction(...data),
  1731.               description: actionDescription(...data),
  1732.             });
  1733.           });
  1734.         }
  1735.         if (
  1736.           !newAction.description.includes("undefined") &&
  1737.           !newAction.description.includes("null") &&
  1738.           typeof newAction.trigger == "function" &&
  1739.           newAction.action.every((a) => {
  1740.             return !a.description.includes("undefined") && !a.description.includes("null") && typeof a.start == "function";
  1741.           })
  1742.         )
  1743.           addToQueue(newAction);
  1744.       } catch {}
  1745.     }
  1746.     document.getElementById("aq-pastebin").value = "";
  1747.     updateQueue();
  1748.   } catch (e) {
  1749.     console.error(e);
  1750.   } finally {
  1751.     return false;
  1752.   }
  1753. }
  1754.  
  1755. function downloadActions() {
  1756.   const saveData = [];
  1757.   for (const action of actionQueueArray) {
  1758.     let actionList = [];
  1759.     action.action.forEach((a) => actionList.push(a.data));
  1760.     saveData.push([...action.data, actionList]);
  1761.   }
  1762.   let file = new Blob([JSON.stringify(saveData)], {
  1763.     type: "text/plain",
  1764.   });
  1765.   if (window.navigator.msSaveOrOpenBlob) window.navigator.msSaveOrOpenBlob(file, "Melvor_Action_Queue.txt");
  1766.   else {
  1767.     var a = document.createElement("a"),
  1768.       url = URL.createObjectURL(file);
  1769.     a.href = url;
  1770.     a.download = "Melvor_Action_Queue.txt";
  1771.     document.body.appendChild(a);
  1772.     a.click();
  1773.     setTimeout(function () {
  1774.       document.body.removeChild(a);
  1775.       window.URL.revokeObjectURL(url);
  1776.     }, 0);
  1777.   }
  1778. }
  1779.  
  1780. function updateMasteryLvl(skill) {
  1781.   MASTERY[skill].xp.forEach((xp, i) => {
  1782.     let level = 1;
  1783.     while (xp >= lvlIndex[level + 1]) level++;
  1784.     masteryClone[skill].lvl[i] = level;
  1785.   });
  1786.   masteryClone[skill].completed = masteryClone[skill].lvl.every((a) => a == 99);
  1787.   masteryClone[skill].pool = MASTERY[skill].pool;
  1788. }
  1789.  
  1790. function manageMastery() {
  1791.   for (const skill in MASTERY) {
  1792.     //token claiming
  1793.     const maxPool = MASTERY[skill].xp.length * 500000;
  1794.     const bankID = getBankId(CONSTANTS.item[`Mastery_Token_${SKILLS[skill].name}`]);
  1795.     if (bankID !== -1 && bank[bankID].qty > 0 && MASTERY[skill].pool < maxPool * 0.999) {
  1796.       const maxTokens = Math.floor(((maxPool - MASTERY[skill].pool) * 1000) / maxPool);
  1797.       {
  1798.         let itemID = CONSTANTS.item[`Mastery_Token_${SKILLS[skill].name}`];
  1799.         let qtyToUse = Math.min(bank[bankID].qty, maxTokens);
  1800.         let totalXpToAdd = Math.floor(getMasteryPoolTotalXP(skill) * 0.001) * qtyToUse;
  1801.         addMasteryXPToPool(skill, totalXpToAdd, false, true);
  1802.         updateItemInBank(bankID, itemID, -qtyToUse);
  1803.       }
  1804.     }
  1805.  
  1806.     //exit if pool unchanged
  1807.     if (masteryClone[skill].pool == MASTERY[skill].pool && MASTERY[skill].pool < maxPool * masteryConfig[skill].checkpoint) continue;
  1808.  
  1809.     //exit if maxed mastery
  1810.     updateMasteryLvl(skill);
  1811.     if (masteryClone[skill].completed) continue;
  1812.  
  1813.     //choose masteryID
  1814.     let masteryID = 0;
  1815.     if (!masteryConfig[skill].prio || masteryClone[skill].lvl.some((a) => a < 60)) {
  1816.       for (let i = 1; i < MASTERY[skill].xp.length; i++) {
  1817.         if (MASTERY[skill].xp[i] < MASTERY[skill].xp[masteryID]) masteryID = i;
  1818.       }
  1819.     } else {
  1820.       const noncompletedPrio = masteryConfig[skill].arr.filter((a) => masteryClone[skill].lvl[a] < masteryConfig[skill].base);
  1821.       if (noncompletedPrio.length == 0) {
  1822.         //choose lowest of nonprio or lowest of prio if nonprio maxed
  1823.         let arr = MASTERY[skill].xp.map((a, i) => i);
  1824.         for (const x of masteryConfig[skill].arr) arr[x] = null;
  1825.         arr = arr.filter((a) => a != null);
  1826.         if (arr.every((a) => masteryClone[skill].lvl[a] >= 99)) arr = [...masteryConfig[skill].arr];
  1827.         arr.sort((a, b) => MASTERY[skill].xp[a] - MASTERY[skill].xp[b]);
  1828.         masteryID = arr[0];
  1829.       } else {
  1830.         for (const id of masteryConfig[skill].arr) {
  1831.           if (MASTERY[skill].xp[id] == lvlIndex[masteryConfig[skill].base]) {
  1832.             //choose lowest of [nonprio, noncompleted prio]
  1833.             let arr = MASTERY[skill].xp.map((a, i) => i);
  1834.             for (const x of masteryConfig[skill].arr) arr[x] = null;
  1835.             arr = arr.filter((a) => a != null);
  1836.             arr.push(...noncompletedPrio);
  1837.             arr.sort((a, b) => MASTERY[skill].xp[a] - MASTERY[skill].xp[b]);
  1838.             masteryID = arr[0];
  1839.             break;
  1840.           } else if (masteryClone[skill].lvl[id] < masteryConfig[skill].base) {
  1841.             masteryID = id;
  1842.             break;
  1843.           }
  1844.         }
  1845.       }
  1846.     }
  1847.     if (masteryID == undefined) continue;
  1848.  
  1849.     //level up chosen mastery
  1850.     if (
  1851.       MASTERY[skill].xp[masteryID] < 13034432 &&
  1852.       (MASTERY[skill].pool == maxPool ||
  1853.         MASTERY[skill].pool - lvlIndex[masteryClone[skill].lvl[masteryID] + 1] + MASTERY[skill].xp[masteryID] >
  1854.           masteryConfig[skill].checkpoint * maxPool)
  1855.     ) {
  1856.       if (masteryPoolLevelUp > 1) masteryPoolLevelUp = 1;
  1857.       let xp = lvlIndex[masteryClone[skill].lvl[masteryID] + 1] - MASTERY[skill].xp[masteryID];
  1858.       if (MASTERY[skill].pool >= xp) {
  1859.         addMasteryXP(skill, masteryID, 0, true, xp, false);
  1860.         addMasteryXPToPool(skill, -xp, false, true);
  1861.         updateSpendMasteryScreen(skill, masteryID);
  1862.         //showSpendMasteryXP(skill);
  1863.       }
  1864.       if (skill === CONSTANTS.skill.Fishing) {
  1865.         for (let i = 0; i < Fishing.areas.length; i++) {
  1866.           for (let f = 0; f < Fishing.areas[i].fish.length; f++) {
  1867.             if (Fishing.areas[i].fish[f] === masteryID) {
  1868.               updateFishingMastery(i, f);
  1869.               break;
  1870.             }
  1871.           }
  1872.         }
  1873.       }
  1874.     }
  1875.   }
  1876. }
  1877.  
  1878. function toggleMastery(start) {
  1879.   for (const skill in MASTERY) {
  1880.     masteryClone[skill] = {
  1881.       pool: MASTERY[skill].pool,
  1882.       lvl: [],
  1883.     };
  1884.     updateMasteryLvl(skill);
  1885.   }
  1886.   if (start && manageMasteryInterval === null) {
  1887.     manageMasteryInterval = setInterval(() => {
  1888.       manageMastery();
  1889.     }, 1000);
  1890.   } else if (!start) {
  1891.     clearInterval(manageMasteryInterval);
  1892.     manageMasteryInterval = null;
  1893.   }
  1894. }
  1895.  
  1896. function addToQueue(obj) {
  1897.   actionQueueArray.push(obj);
  1898.   document.getElementById("aq-item-container").insertAdjacentHTML(
  1899.     "beforeend",
  1900.     `<div class="aq-item" id="${obj.elementID}" draggable="true">
  1901.   <div class="aq-item-inner">
  1902.     <p style="margin: auto 0">${obj.description}</p>
  1903.     <div style="min-width: 170px; min-height: 39px; display: flex; justify-content: flex-end;">
  1904.       <button type="button" class="btn aq-arrow aq-grey" style="font-size: 0.875rem;">select</button>
  1905.       <button type="button" class="btn aq-arrow aq-grey" style="padding: 0 0.1rem 0.2rem 0.1rem;">+</button>
  1906.       <button type="button" class="btn aq-arrow aq-grey" style="padding:0 0.09rem;">
  1907.         <svg width="22" height="22" viewBox="0 0 24 24">
  1908.           <path fill-rule="evenodd" clip-rule="evenodd" d="M19.2929 9.8299L19.9409 9.18278C21.353 7.77064 21.353 5.47197 19.9409 4.05892C18.5287 2.64678 16.2292 2.64678 14.817 4.05892L14.1699 4.70694L19.2929 9.8299ZM12.8962 5.97688L5.18469 13.6906L10.3085 18.813L18.0201 11.0992L12.8962 5.97688ZM4.11851 20.9704L8.75906 19.8112L4.18692 15.239L3.02678 19.8796C2.95028 20.1856 3.04028 20.5105 3.26349 20.7337C3.48669 20.9569 3.8116 21.046 4.11851 20.9704Z" fill="currentColor"></path>
  1909.         </svg>
  1910.       </button>
  1911.       <button type="button" class="btn aq-delete btn-danger">X</button>
  1912.     </div>
  1913.   </div>
  1914.   <div style="min-height: 39px; padding-left: 10px;"></div>
  1915. </div>`
  1916.   );
  1917.  
  1918.   //add button clicks
  1919.   const buttons = document.getElementById(obj.elementID).children[0].children[1].children;
  1920.   buttons[0].addEventListener("click", () => setCurrentAction(obj.elementID));
  1921.   buttons[1].addEventListener("click", () => editQueue(obj.elementID, "add"));
  1922.   buttons[2].addEventListener("click", () => editQueue(obj.elementID, "triggers"));
  1923.   buttons[3].addEventListener("click", () => deleteAction(obj.elementID, "trigger"));
  1924.  
  1925.   //add tooltips
  1926.   tooltips[obj.elementID] = [
  1927.     tippy(document.getElementById(obj.elementID).children[0].children[1].children[0], {
  1928.       content: "Set as current trigger",
  1929.       animation: false,
  1930.     }),
  1931.     tippy(document.getElementById(obj.elementID).children[0].children[1].children[1], {
  1932.       content: "Add action",
  1933.       animation: false,
  1934.     }),
  1935.     tippy(document.getElementById(obj.elementID).children[0].children[1].children[2], {
  1936.       content: "Edit trigger",
  1937.       animation: false,
  1938.     }),
  1939.     tippy(document.getElementById(obj.elementID).children[0].children[1].children[3], {
  1940.       content: "Delete trigger & actions",
  1941.       animation: false,
  1942.     }),
  1943.   ];
  1944.   //add eventlisteners for dragging trigger block
  1945.   const element = document.getElementById(obj.elementID);
  1946.   element.addEventListener("dragstart", () => {
  1947.     element.classList.add("t-drag");
  1948.   });
  1949.   element.addEventListener("dragend", () => {
  1950.     reorderQueue();
  1951.     element.classList.remove("t-drag");
  1952.   });
  1953.  
  1954.   //append html for each action
  1955.   obj.action.forEach((action) => {
  1956.     document.getElementById(obj.elementID).children[1].insertAdjacentHTML(
  1957.       "beforeend",
  1958.       `<div id='${action.elementID}' class="aq-item-inner" draggable="true">
  1959.   <p style="margin: auto 0">${action.description}</p>
  1960.   <div style="min-width: 170px; min-height: 39px; display: flex; justify-content: flex-end;">
  1961.     <small style="display: none; margin: auto 0.25rem">action failed</small>
  1962.     <button type="button" class="btn aq-arrow aq-grey" style="padding:0 0.09rem;">
  1963.       <svg width="22" height="22" viewBox="0 0 24 24">
  1964.         <path fill-rule="evenodd" clip-rule="evenodd" d="M19.2929 9.8299L19.9409 9.18278C21.353 7.77064 21.353 5.47197 19.9409 4.05892C18.5287 2.64678 16.2292 2.64678 14.817 4.05892L14.1699 4.70694L19.2929 9.8299ZM12.8962 5.97688L5.18469 13.6906L10.3085 18.813L18.0201 11.0992L12.8962 5.97688ZM4.11851 20.9704L8.75906 19.8112L4.18692 15.239L3.02678 19.8796C2.95028 20.1856 3.04028 20.5105 3.26349 20.7337C3.48669 20.9569 3.8116 21.046 4.11851 20.9704Z" fill="currentColor"></path>
  1965.       </svg>
  1966.     </button>
  1967.     <button type="button" class="btn aq-delete btn-danger">X</button>
  1968.   </div>
  1969. </div>`
  1970.     );
  1971.     //add tooltips
  1972.     tooltips[action.elementID] = [
  1973.       tippy(document.getElementById(action.elementID).children[1].children[1], {
  1974.         content: "Edit Action",
  1975.         animation: false,
  1976.       }),
  1977.       tippy(document.getElementById(action.elementID).children[1].children[2], {
  1978.         content: "Delete Action",
  1979.         animation: false,
  1980.       }),
  1981.     ];
  1982.     //add eventlisteners for dragging actions
  1983.     const element = document.getElementById(action.elementID);
  1984.     element.addEventListener("dragstart", () => {
  1985.       element.classList.add("a-drag");
  1986.     });
  1987.     element.addEventListener("dragend", () => {
  1988.       element.classList.remove("a-drag");
  1989.     });
  1990.     //add button clicks
  1991.     const buttons = element.children[1].children;
  1992.     buttons[1].addEventListener("click", () => editQueue(action.elementID, "actions"));
  1993.     buttons[2].addEventListener("click", () => deleteAction(action.elementID, "action"));
  1994.   });
  1995.  
  1996.   //add eventlistener for dragging actions within trigger blocks
  1997.   const container = document.getElementById(obj.elementID).children[1];
  1998.   container.addEventListener("dragover", (e) => {
  1999.     e.preventDefault();
  2000.     const draggable = document.querySelector(".a-drag");
  2001.     if (!draggable) return;
  2002.     const afterElement = getDragAfterElement(container, e.clientY, ".aq-item-inner");
  2003.     if (afterElement == null) {
  2004.       container.appendChild(draggable);
  2005.     } else {
  2006.       container.insertBefore(draggable, afterElement);
  2007.     }
  2008.   });
  2009.  
  2010.   if (triggerCheckInterval === null && !queuePause) {
  2011.     currentActionIndex = 0;
  2012.     updateQueue();
  2013.     triggerCheckInterval = setInterval(() => {
  2014.       triggerCheck();
  2015.     }, 1000);
  2016.     updateTextColour("start");
  2017.   }
  2018. }
  2019.  
  2020. function deleteAction(id, type) {
  2021.   tooltips[id].forEach((a) => a.destroy());
  2022.   delete tooltips[id];
  2023.   if (type == "trigger") {
  2024.     const i = actionQueueArray.findIndex((a) => a.elementID == id);
  2025.     if (i < 0) return;
  2026.     for (const action of actionQueueArray[i].action) {
  2027.       tooltips[action.elementID].forEach((a) => a.destroy());
  2028.       delete tooltips[action.elementID];
  2029.     }
  2030.     //remove from array
  2031.     actionQueueArray.splice(i, 1);
  2032.     if (currentActionIndex > i) currentActionIndex--;
  2033.     updateQueue();
  2034.   } else if (type == "action") {
  2035.     let i = 0;
  2036.     for (const trigger of actionQueueArray) {
  2037.       i = trigger.action.findIndex((a) => a.elementID == id);
  2038.       if (i < 0) continue;
  2039.       trigger.action.splice(i, 1);
  2040.       break;
  2041.     }
  2042.   }
  2043.   //remove html
  2044.   const element = document.getElementById(id);
  2045.   if (element) element.remove();
  2046. }
  2047.  
  2048. function addAction(id, actionCategory, actionName, skillItem, skillItem2, qty) {
  2049.   let elementID = `AQ${nameIncrement++}`;
  2050.   let description = actionDescription(actionCategory, actionName, skillItem, skillItem2, qty);
  2051.   actionQueueArray
  2052.     .find((a) => a.elementID == id)
  2053.     .action.push({
  2054.       elementID,
  2055.       data: [actionCategory, actionName, skillItem, skillItem2, qty],
  2056.       start: setAction(actionCategory, actionName, skillItem, skillItem2, qty),
  2057.       description,
  2058.     });
  2059.   document.getElementById(id).children[1].insertAdjacentHTML(
  2060.     "beforeend",
  2061.     `<div id='${elementID}' class="aq-item-inner" draggable="true">
  2062.   <p style="margin: auto 0">${description}</p>
  2063.   <div style="min-width: 170px; min-height: 39px; display: flex; justify-content: flex-end;">
  2064.     <small style="display: none; margin: auto 0.25rem">action failed</small>
  2065.     <button type="button" class="btn aq-arrow aq-grey" style="padding:0 0.09rem;">
  2066.       <svg width="22" height="22" viewBox="0 0 24 24">
  2067.         <path fill-rule="evenodd" clip-rule="evenodd" d="M19.2929 9.8299L19.9409 9.18278C21.353 7.77064 21.353 5.47197 19.9409 4.05892C18.5287 2.64678 16.2292 2.64678 14.817 4.05892L14.1699 4.70694L19.2929 9.8299ZM12.8962 5.97688L5.18469 13.6906L10.3085 18.813L18.0201 11.0992L12.8962 5.97688ZM4.11851 20.9704L8.75906 19.8112L4.18692 15.239L3.02678 19.8796C2.95028 20.1856 3.04028 20.5105 3.26349 20.7337C3.48669 20.9569 3.8116 21.046 4.11851 20.9704Z" fill="currentColor"></path>
  2068.       </svg>
  2069.     </button>
  2070.     <button type="button" class="btn aq-delete btn-danger">X</button>
  2071.   </div>
  2072. </div>`
  2073.   );
  2074.   const element = document.getElementById(elementID);
  2075.   //add tooltips
  2076.   tooltips[elementID] = [
  2077.     tippy(element.children[1].children[1], {
  2078.       content: "Edit Action",
  2079.       animation: false,
  2080.     }),
  2081.     tippy(element.children[1].children[2], {
  2082.       content: "Delete Action",
  2083.       animation: false,
  2084.     }),
  2085.   ];
  2086.  
  2087.   //add eventlisteners for dragging
  2088.   element.addEventListener("dragstart", () => {
  2089.     element.classList.add("a-drag");
  2090.   });
  2091.   element.addEventListener("dragend", () => {
  2092.     element.classList.remove("a-drag");
  2093.   });
  2094.   //add button clicks
  2095.   const buttons = element.children[1].children;
  2096.   buttons[1].addEventListener("click", () => editQueue(elementID, "actions"));
  2097.   buttons[2].addEventListener("click", () => deleteAction(elementID, "action"));
  2098. }
  2099.  
  2100. function getDragAfterElement(container, y, type) {
  2101.   const not = type == "aq-item" ? ".t-drag" : ".a-drag";
  2102.   const elements = [...container.querySelectorAll(`${type}:not(${not})`)];
  2103.   return elements.reduce(
  2104.     (closest, child) => {
  2105.       const box = child.getBoundingClientRect();
  2106.       const offset = y - box.top - box.height / 2;
  2107.       if (offset < 0 && offset > closest.offset) {
  2108.         return { offset: offset, element: child };
  2109.       } else {
  2110.         return closest;
  2111.       }
  2112.     },
  2113.     { offset: Number.NEGATIVE_INFINITY }
  2114.   ).element;
  2115. }
  2116.  
  2117. function reorderQueue() {
  2118.   const targetIndex = actionQueueArray[currentActionIndex].elementID;
  2119.   //remove stray dragging classes
  2120.   document
  2121.     .getElementById("aq-item-container")
  2122.     .querySelectorAll(".a-drag")
  2123.     .forEach((a) => a.classList.remove("a-drag"));
  2124.   document
  2125.     .getElementById("aq-item-container")
  2126.     .querySelectorAll(".t-drag")
  2127.     .forEach((a) => a.classList.remove("t-drag"));
  2128.   //sort triggers
  2129.   const triggerOrder = {};
  2130.   [...document.getElementById("aq-item-container").children].forEach((item, index) => (triggerOrder[item.id] = index));
  2131.   actionQueueArray.sort((a, b) => triggerOrder[a.elementID] - triggerOrder[b.elementID]);
  2132.   //sort actions
  2133.   const actionList = actionQueueArray.reduce((a, b) => a.concat(b.action), []);
  2134.   let increment = -1;
  2135.   [...document.getElementById("aq-item-container").querySelectorAll(".aq-item-inner")].forEach((item) => {
  2136.     if (item.id == "") {
  2137.       increment++;
  2138.       actionQueueArray[increment].action = [];
  2139.     } else {
  2140.       actionQueueArray[increment].action.push(actionList.find((a) => a.elementID == item.id));
  2141.     }
  2142.   });
  2143.   //reorder currentActionIndex
  2144.   currentActionIndex = actionQueueArray.findIndex((a) => a.elementID == targetIndex);
  2145. }
  2146.  
  2147. function editQueue(id, type) {
  2148.   cancelEdit(); //reset form
  2149.   currentlyEditing = { id, type };
  2150.   let inputArray = [];
  2151.   let obj = options[type];
  2152.   //set inputArray
  2153.   if (type == "triggers") {
  2154.     inputArray = actionQueueArray.find((a) => a.elementID == id).data.filter((a) => a !== null && a !== "");
  2155.     document.getElementById("aq-edit-form").innerHTML = "Edit Trigger";
  2156.   } else if (type == "actions") {
  2157.     document.getElementById("aq-edit-form").innerHTML = "Edit Action";
  2158.     for (const item of actionQueueArray) {
  2159.       if (item.action.find((a) => a.elementID == id)) {
  2160.         inputArray = item.action.find((a) => a.elementID == id).data.filter((a) => a !== null && a !== "");
  2161.         break;
  2162.       }
  2163.     }
  2164.   } else {
  2165.     document.getElementById("aq-edit-form").innerHTML = "New Action";
  2166.     obj = options.actions;
  2167.   }
  2168.   //set datalist for category
  2169.   document.getElementById("aq-listC0").innerHTML = "";
  2170.   Object.keys(obj).forEach((e) => {
  2171.     document.getElementById("aq-listC0").insertAdjacentHTML("beforeend", `<option>${e}</option>`);
  2172.   });
  2173.  
  2174.   //populate text boxes to edit
  2175.   for (let i = 0; i < inputArray.length; i++) {
  2176.     let textBox;
  2177.     if (i == inputArray.length - 1 && /^\d{1,10}$/.test(inputArray[i])) {
  2178.       textBox = document.getElementById("aq-numC");
  2179.     } else {
  2180.       textBox = document.getElementById(`aq-textC${i}`);
  2181.       //set datalist
  2182.       document.getElementById(`aq-listC${i}`).innerHTML = "";
  2183.       Object.keys(obj).forEach((e) => {
  2184.         document.getElementById(`aq-listC${i}`).insertAdjacentHTML("beforeend", `<option>${e}</option>`);
  2185.       });
  2186.       obj = obj[inputArray[i]];
  2187.     }
  2188.     textBox.value = inputArray[i];
  2189.     textBox.type = "text";
  2190.     validInputs.C[i] = inputArray[i];
  2191.   }
  2192.   const y = Math.max(document.getElementById(id).getBoundingClientRect().top - 255, 0);
  2193.   document.getElementById("aq-edit-container").style.top = `${y}px`;
  2194.   document.getElementById("aq-edit-container").style.display = "";
  2195. }
  2196.  
  2197. function cancelEdit() {
  2198.   document.getElementById("aq-edit-container").style.display = "none";
  2199.   resetForm(["C"]);
  2200. }
  2201.  
  2202. function submitEdit() {
  2203.   const a = document.getElementById("aq-edit-form").innerHTML.includes("Trigger");
  2204.   const arr = [];
  2205.   for (let i = 0; i < validInputs.C.length; i++) arr.push(document.getElementById(`aq-textC${i}`).value);
  2206.   if (a) arr.pop();
  2207.   arr.push(document.getElementById(`aq-numC`).value);
  2208.   if (a) arr.splice(["≥", "≤", ""].includes(arr[2]) ? 3 : 2, 0, "");
  2209.  
  2210.   if (
  2211.     validateInput(
  2212.       a ? options.triggers : options.actions,
  2213.       arr.filter((a) => a !== "")
  2214.     )
  2215.   ) {
  2216.     if (currentlyEditing.type == "add") {
  2217.       addAction(currentlyEditing.id, ...arr);
  2218.     } else if (currentlyEditing.type == "triggers") {
  2219.       const action = new Action(...arr);
  2220.       const i = actionQueueArray.findIndex((a) => a.elementID == currentlyEditing.id);
  2221.       actionQueueArray[i].description = action.description;
  2222.       actionQueueArray[i].trigger = action.trigger;
  2223.       actionQueueArray[i].data = action.data;
  2224.       document.getElementById(currentlyEditing.id).children[0].children[0].innerHTML = action.description;
  2225.     } else {
  2226.       const description = actionDescription(...arr);
  2227.       const start = setAction(...arr);
  2228.       for (const item of actionQueueArray) {
  2229.         const action = item.action.find((a) => a.elementID == currentlyEditing.id);
  2230.         if (action) {
  2231.           action.data = arr;
  2232.           action.start = start;
  2233.           action.description = description;
  2234.           document.getElementById(currentlyEditing.id).children[0].innerHTML = description;
  2235.           break;
  2236.         }
  2237.       }
  2238.     }
  2239.     cancelEdit();
  2240.   }
  2241.   return false;
  2242. }
  2243.  
  2244. function updateMasteryConfig(changeSkill = true) {
  2245.   if (changeSkill) {
  2246.     if (masteryConfigChanges.skill != null) {
  2247.       updateMasteryPriority();
  2248.       let arr = masteryConfigChanges.arr == null ? [...masteryConfig[masteryConfigChanges.skill].arr] : [...masteryConfigChanges.arr];
  2249.       masteryConfig[masteryConfigChanges.skill] = {
  2250.         checkpoint: masteryConfigChanges.checkpoint,
  2251.         prio: masteryConfigChanges.prio,
  2252.         base: masteryConfigChanges.base,
  2253.         arr,
  2254.       };
  2255.     }
  2256.     const skill = document.getElementById("aq-skill-list").value;
  2257.     document.getElementById("aq-checkpoint-list").value = masteryConfig[skill].checkpoint.toString();
  2258.     document.getElementById("aq-mastery-strategy").value = masteryConfig[skill].prio.toString();
  2259.     document.getElementById("aq-base").disabled = !masteryConfig[skill].prio;
  2260.     document.getElementById("aq-mastery-array").disabled = !masteryConfig[skill].prio;
  2261.     document.getElementById("aq-base").value = masteryConfig[skill].base.toString();
  2262.     document.getElementById("aq-mastery-array").value = JSON.stringify(masteryConfig[skill].arr);
  2263.     masteryConfigChanges.skill = null;
  2264.   } else {
  2265.     masteryConfigChanges.skill = document.getElementById("aq-skill-list").value;
  2266.     masteryConfigChanges.checkpoint = parseFloat(document.getElementById("aq-checkpoint-list").value);
  2267.     masteryConfigChanges.prio = JSON.parse(document.getElementById("aq-mastery-strategy").value);
  2268.     masteryConfigChanges.base = parseInt(document.getElementById("aq-base").value);
  2269.     updateMasteryPriority();
  2270.     document.getElementById("aq-base").disabled = !JSON.parse(document.getElementById("aq-mastery-strategy").value);
  2271.     document.getElementById("aq-mastery-array").disabled = !JSON.parse(document.getElementById("aq-mastery-strategy").value);
  2272.   }
  2273. }
  2274.  
  2275. function updateMasteryPriority() {
  2276.   const string = document.getElementById("aq-mastery-array").value;
  2277.   let arr = null;
  2278.   try {
  2279.     arr = JSON.parse(string.trim());
  2280.   } catch {}
  2281.   if (!Array.isArray(arr)) return (masteryConfigChanges.arr = null);
  2282.   arr = [...new Set(arr)].filter((a) => typeof MASTERY[masteryConfigChanges.skill].xp[a] == "number");
  2283.   masteryConfigChanges.arr = [...arr];
  2284. }
  2285.  
  2286. function masteryPopup(open) {
  2287.   if (open) {
  2288.     masteryConfigChanges.skill = null;
  2289.     updateMasteryConfig();
  2290.     document.getElementById("aq-mastery-config-container").style.display = "";
  2291.   } else {
  2292.     updateMasteryConfig();
  2293.     document.getElementById("aq-mastery-config-container").style.display = "none";
  2294.   }
  2295. }
  2296.  
  2297. /**
  2298.  * Function to change active prayers
  2299.  * @param {Array} choice array of prayer IDs
  2300.  */
  2301. function changePrayers(choice = []) {
  2302.   for (const i of player.activePrayers.entries()) {
  2303.     choice.includes(i[0])
  2304.       ? choice.splice(
  2305.           choice.findIndex((a) => a == i[0]),
  2306.           1
  2307.         )
  2308.       : choice.unshift(i[0]);
  2309.   }
  2310.   for (const prayer of choice) player.togglePrayer(prayer);
  2311. }
  2312.  
  2313. /**
  2314.  * Function to delete every action
  2315.  */
  2316. function clearQueue() {
  2317.   for (let i = actionQueueArray.length - 1; i >= 0; i--) {
  2318.     deleteAction(actionQueueArray[i].elementID, "trigger");
  2319.   }
  2320. }
  2321.  
Add Comment
Please, Sign In to add comment