Guest User

Melvor Action Queue codefix

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