Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Tampermonkey script **/
- // ==UserScript==
- // @name Mazmorra Script
- // @namespace mazmorra
- // @version 1.4.5
- // @description Hotkeys and hacks for mazmorra.io!
- // @author goblin
- // @match https://mazmorra.io/
- // @grant unsafeWindow
- // ==/UserScript==
- // PARAMETERS' : (Modify to fit your needs and your character stats!)
- // INIT:
- var HELLO = "Mazmorra script ready! Version compatibile with: \n\n '(19/07/2019), Settings update, skill balancing, bug fixes.'";
- var USERNAME = "goblin";
- // script SETUP:
- var HP_WOUND = 160; // configuration for S hotkey - will not quick-drink hp-potion if hp missing is less than HP_WOUND
- var MP_WOUND = 80; // configuration for S hotkey - will not quick-drink mp-potion if mp missing is less than MP_WOUND
- var HP_CRITICAL = 400; // (if = 0 or >= maxhp, then HP_WOUND is considered, else:) if hp <= HP_CRITICAL, "Health Keeper" (if can't drink hp-potion) will try to portal-escape to spawn
- var INVENTORY_KEEP = 4; // prevents 'oldest'/top-left set amount of items from being quick-sold with A while at spawn (set to 15 to disable quick-sell / set to 0 to allow to sell everything)
- var KEEP_STACKABLES = false; // if true, hotkey scripts ignore at least one instance of stackables. (which means if you have exactly 1 portal/potion, then you don't have it.)
- // bot SETUP:
- var INTERVAL = 90; // refresh interval for auto-scripts in ms (Example: "Health Keeper")
- var PORTAL_ESCAPE_FAIL = 4; // if "Health Keeper" fails to escape via portal this many times (surrounded by enemies?), then it starts running to previous floor (while retrying) - fixes unable to portal while surrounded by enemies
- var CHECKPOINT_WALK_DELAY = 800; // delay to prevent double-enter-bug on checkpoints
- // bot MODES:
- var NO_LOOT = false; // if true, "Dungeon Clear" will not pickup loot, only kill enemies for xp
- var ASCEND_MODE = true; // if true, "Autoloop X" will ascend (until last floor) instead of returning to spawn directly, after the floor is "clean"
- var AVOID_PLAYERS = true; // if true, "Autoloop X" will temporarily go farm to previous checkpoint if it encounters a player blocking its farm floor X, instead of retreating to spawn
- var PREFEER_SPAWN = true; // if true, any CHECKPOINT request to 120 will be redirected to 1 instead.
- var ALLOWED_MANA_GAP = 50; // allowed mana gap for "Dungeon Clear" level fountain function (to prevent getting stuck on fountain if skill spam is triggered)
- var STATIONARY_HP_TIMEOUT = 6000; // used to avoid "Dungeon Clear" getting trapped by the monkey minion BUG
- // Script functions help' : (some keys have multiple functions depending on location)
- /**
- HOTKEYS:
- (if player is NOT AT SPAWN)
- Key: Action:
- A - auto-attack nearest enemy (built-in-game)
- S - quick-restore (drink hp potion if HP_WOUND or more hp missing && drink mp potion if MP_WOUND or more mana missing)
- D - cast a portal (if not avaliable in room) / walk into portal (if avaliable in room)
- F - fountain: clicks on fountain tile (if avaliable and reachable)
- E - explore: clicks on door_to_next_floor tile (if reachable - can be blocked by lever gates?)
- R - return: clicks on door_to_previous_floor tile (always reachable?)
- C - checkpoint: clicks on check-point tile (always reachable?)
- L - lever: clicks on lever-tile (tip: sometimes E won't budge since lever-gates can block door_to_next_floor)
- (if player is AT SPAWN - * indicates a new function - ! indicates bugs)
- Key: Action:
- A * walk to Merchant (if shop not open) / quick-sell an item right after INVENTORY_KEEP amount of items (if shop open)
- S * walk to Elder (if shop not open) / buy hp potion from Elder (if shop open)
- D * walk to portal (if avaliable in room) / buy scroll_regular from Elder (if shop open)
- F - fountain: clicks on fountain tile (if avaliable and reachable)
- E - explore: clicks on door_to_next_floor tile (if reachable - can be blocked by lever gates?)
- R - return: clicks on door_to_pvp (door_to_previous_floor tile at spawn)
- C - checkpoint: clicks on check-point tile (always reachable?)
- L *! leaderboard: clicks on leaderboard tile (WARNN: bug: You must manually click away to close it or it gets broke D:)
- M * Majesty: clicks on majesty tile / refreshes majesty
- SCRIPTS:
- (Numpad keys && NumLock = ON)
- Key: Action:
- 7 - toggle "Health Keeper": + if HP_WOUND hp missing, it will try drink hp-potion. Else, if no potion: (TIP: Always have a scroll)
- + if hp is <= HP_CRITICAL (or HP_CRITICAL invalid), it will try reach checkpoint OR (if not avaliable) auto_portal escape to spawn
- + if no checkpoint and can't portal escape to spawn (surrounded by enemies?) it will try to flee to previous floor first, then retry
- + if at spawn and hp != max_hp (or mp), it'll go force drink from fountain
- + if at spawn, and has no portals in inventory, it'll go try forcefully buy a scroll
- 8 - toggle "Dungeon Clear" + if loot avaliable, it will run to pick it up first (doesn't open chests)
- + if no loot dropped, it will auto attack a random enemy on the floor
- + if no enemies left, it'll drink from a level fountain if avaliable, AND IF UNDER ALLOWED_MANA_GAP
- + if at spawn, it will autosell inventory (modify INVENTORY_KEEP)
- 9 - toggle "Autoloop X" ? RECOMMENDED: "Dungeon Clear" mode alongside it, so they together farm the checkpoint X floor (Or from X to 120 if ASCEND_MODE is active)
- + if in ASCEND_MODE, it fill first go trigger (one-player) levers (to unblock possibly blocked doors)
- + if no loot or enemies at the current floor, it will (auto-flee to spawn) OR (ascend to next floor)
- + if nothing to do at spawn, it will autowalk back to checkpoint X
- 4 - toggle "Skill-1 Spam" + Spam Q key to activate attack speed skill (if not at spawn)
- 5 - toggle "Skill-2 Spam" + Spam W key to activate movement speed skill (if not at spawn)
- **/
- // DOCUMENTATION' :
- if ("name" === "Helper functions") {
- myplayer.name; // get USERNAME from PARAMETERS'
- myplayer.data(); // get user data from in-game myplayer object
- myplayer.inventory(); // get inventory slots in raw form
- room.entities('type', 'kind', 'only_first'); // get entities of type,kind (returns all if type is not speficied) from current room
- room.shop(); // get shop slots from current room/stage/floor if avaliable
- room.floor(); // get room (floor) number
- }
- if ("name" === "Control functions") {
- controller.inventory_find('type'); // finds first item from inventory of whose type string starts with 'type'
- controller.inventory_consume('slot_id') // consumes item from inventory from slot slot_id
- controller.shop_buy('type'); // buy item from shop of whose type string starts with 'type' (if shop avaliable - returns false if not found)
- controller.shop_sell('slot_id'); // sell item to shop from slot_id of inventory - returns false if shop not enabled
- controller.myplayer_click('x','y'); // clicks on x,y position tile (moves/attacks/collects loot/...)
- controller.myplayer_click_on('type','kind'); // clicks on random (first returned by room.entities) entity of type,kind - return true if found
- controller.checkpoint_click('floor'); // click CP (enter valid floor number pls, ty.)
- }
- if ("name" == "Action functions") {
- action.auto_attack(); // auto-attack nearest enemy (use 'false' if binded again to A key)
- action.hp_potion(80); // drinks a hp potion if it will fully use the fattest one (80 hp currently) (returns false if item not found)
- action.mp_potion(1); // consumes a mp potion if there's at least 1 missing mana (returns false if item not found)
- action.scroll_regular(); // (re)cast a portal in the room (returns false if item not found)
- }
- if ("name" == "Debug functions") {
- room.entities('', '', '', '', true); // DEBUG: logs entities: x, y, type, kind, e*
- controller.inventory_find('',true); // DEBUG: logs item types from inventory in console
- }
- if ("name" == "Document worker") {
- document_worker.set_info_text('string'); // replaces "discord" div text with 'string'
- document_worker.update_info_text(); // replaces "discord" div text with active scripts info
- document_worker.loop_start(INTERVAL); // starts scripts loop interval function (at INTERVAL refresh rate)
- document_worker.loop_stop(); // stops scripts loop interval function
- document_worker.are_scripts_running(); // returns true if at least one loop-script is running
- loop_function(); // exectues one iteration of loop function
- }
- // DEFINE SCRIPT KEY BINDINGS' :
- // helper function for writting bindings
- function key_code(KEY_CHAR) {return KEY_CHAR.toUpperCase().charCodeAt(0);};
- // key bindings
- document.addEventListener('keydown', function(event){
- let key = event.keyCode;
- // hotkeys script is disabled?
- if (document_worker.state_activity[0] === false) return;
- if (key == key_code("A")) {
- if (room.floor() == 1 || room.floor() == 120) {
- // if shop not enabled
- if(controller.shop_sell(INVENTORY_KEEP) === false) {
- // NPCs are type "20", and Merchant is "merchant" kind
- controller.myplayer_click_on("20","merchant");
- }
- } else {
- action.auto_attack(false);
- }
- } else
- if (key == key_code("S")) {
- if (room.floor() == 1 || room.floor() == 120) {
- // if didn't found hp_potion to buy
- if (controller.shop_buy("hp-potion") === false) {
- // NPCs are type "20", and Elder is "elder" kind
- controller.myplayer_click_on("20","elder");
- }
- } else {
- action.hp_potion(HP_WOUND);
- action.mp_potion(MP_WOUND);
- }
- } else
- if (key == key_code("D")) {
- if ((room.floor() == 1 || room.floor() == 120) && (controller.shop_buy("scroll-regular") === true)) {
- //
- } else {
- let portal = room.entities("portal",undefined,true);
- if (portal.length === 0) {
- action.scroll_regular();
- } else {
- controller.myplayer_click(portal[0].position.x, portal[0].position.y);
- }
- }
- } else
- if (key == key_code("F")) {
- controller.myplayer_click_on("fountain");
- } else
- if (key == key_code("E")) {
- if (room.floor() == 1) {
- // doors forward are of type 0 and kind 2 at spawn
- controller.myplayer_click_on("0",2);
- } else {
- // doors forward are of type 0 and kind -2
- controller.myplayer_click_on("0",-2);
- }
- } else
- if (key == key_code("R")) {
- if (room.floor() == 1) {
- // doors to pvp are of type 0 and kind 'pvp'
- controller.myplayer_click_on("0","pvp");
- } else {
- // doors backwards are of type 0 and kind -1
- controller.myplayer_click_on("0",-1);
- }
- } else
- if (key == key_code("C")) {
- controller.myplayer_click_on("check-point");
- } else
- if (key == key_code("L")) {
- if (room.floor() == 1 || room.floor() == 120) {
- controller.myplayer_click_on("leaderboard");
- } else {
- controller.myplayer_click_on("lever");
- }
- } else
- if (key == key_code("M")) {
- if (room.floor() == 1 || room.floor() == 120) {
- // NPCs are type "20", and Majesty is "majesty" kind
- controller.myplayer_click_on("20","majesty");
- } else {
- //
- }
- } else if (key === 103) { // numpad 7 key - toggle "Health Keeper"
- document_worker.toggle_script(1);
- } else if (key === 104) { // numpad 8 key - toggle "Dungeon Clear"
- document_worker.toggle_script(2);
- } else if (key === 105) { // numpad 9 key - toggle "Autoloop X "
- if (document_worker.state_activity[3] === false) {
- let target_floor = prompt('Enter floor (valid checkpoint) number:');
- document_worker.autowalk_target = target_floor;
- } else {
- document_worker.autowalk_target = 1;
- }
- document_worker.toggle_script(3);
- } else if (key === 100) { // numpad 4 key - toggle "Skill-1 Spam"
- document_worker.toggle_script(4);
- } else if (key === 101) { // numpad 5 key - toggle "Skill-2 Spam"
- document_worker.toggle_script(5);
- }
- });
- // DEFINE SCRIPT OBJECTS' :
- //* action object */
- function Action() {};
- //
- // auto-attack nearest enemy
- Action.prototype.auto_attack = function(repeat = true) {
- // AUTO ATTACK IS BUILT IN GAME: (no need to call it twice if binded to A key)
- if (repeat === true) {
- window.factory.level.room.send(['atk']);
- }
- }
- //
- // consumes a hp potion if there's at least hp_missing missing health (returns false if item not found)
- Action.prototype.hp_potion = function(hp_missing = 1) {
- if (myplayer.data().hp.max - myplayer.data().hp.current >= hp_missing) {
- let slot = controller.inventory_find("hp-potion");
- if (slot[0] === undefined) return false;
- controller.inventory_consume(slot[0]);
- return true;
- }
- return undefined;
- }
- //
- // consumes a mp potion if there's at least mp_missing missing mana (returns false if item not found)
- Action.prototype.mp_potion = function(mp_missing = 1) {
- if (myplayer.data().mp.max - myplayer.data().mp.current >= mp_missing) {
- let slot = controller.inventory_find("mp-potion");
- if (slot[0] === undefined) return false;
- controller.inventory_consume(slot[0]);
- return true;
- }
- return undefined;
- }
- //
- // (re)cast a portal in the room
- Action.prototype.scroll_regular = function() {
- let slot = controller.inventory_find("scroll-regular");
- if (slot[0] === undefined) return false;
- controller.inventory_consume(slot[0]);
- return true;
- }
- //* myplayer object */
- function Player(name) {this.name = name;};
- //
- // get user data from in-game myplayer object
- Player.prototype.data = function() {
- return window.hud.controller.playerObject.userData;
- };
- //
- // get inventory slots either form main or quick inventory
- Player.prototype.inventory = function(quick = false) {
- return window.hud.inventory.slots.slots;
- };
- //* room object */
- function Room() {};
- //
- // get entities of type,kind (returns all if type is not speficied) from current room
- Room.prototype.entities = function(type = undefined, kind = undefined, only_first = false, alive = false, debug = false, exact = false) {
- if (type === '') type = undefined;
- if (kind === '') kind = undefined;
- if (only_first === '') only_first = false;
- if (alive === '') alive = false;
- let all_entities = window.factory.level.entities;
- let my_entities = [];
- let count = 0;
- for (let id in all_entities) {
- let e = all_entities[id].userData;
- if (
- (type === undefined || (exact === false && e.type.substring(0,type.length) === type) || (exact === true && e.type === type)) &&
- ((type === "lever" && kind === e.active) || (type === "fountain" && kind === e.active) || kind === undefined || e.kind === kind || (e._destiny !== undefined && (e._destiny.progress === kind || e._destiny._room === kind)))
- ) {
- if (alive === false || (e.hp !== undefined && e.hp.current > 0)) {
- my_entities[count] = e;
- count = count + 1;
- if (debug === true) {
- console.log(e.position.y,e.position.x,e.type,e.kind,e);
- }
- if (only_first === true) return my_entities;
- }
- }
- }
- return my_entities;
- }
- //
- // get shop slots from current room/stage/floor if avaliable
- Room.prototype.shop = function() {
- return window.hud.inventory.purchaseSlots;
- }
- //
- // get floor number
- Room.prototype.floor = function() {
- if (window.factory === undefined || window.factory.level === undefined || window.factory.level.room === undefined || window.factory.level.room.state === undefined)
- return 0;
- let floor = window.factory.level.room.state.progress;
- if (floor === undefined) {
- if (window.factory.level.room.options === undefined || window.factory.level.room.options.progress === undefined)
- return 0;
- else
- return window.factory.level.room.options.progress;
- }
- else {
- return floor;
- }
- }
- //* controller object */
- function Controller() {};
- // consume item from inventory of whose type string starts with 'type'
- // DEBUG: if second parameter is 'true', it'll log item types from inventory in console
- Controller.prototype.inventory_find = function(type, debug = false) {
- let i, item_id;
- let found_item = false;
- // search for item in inventory
- let inventory = myplayer.inventory();
- for (i = 0; i < 15; i++) {
- let item_type = inventory[i].item;
- if (item_type != null) {
- // will ignore kept stackable items
- if (controller.is_kept(inventory[i]) === false) {
- if (type == item_type.userData.item.type.substring(0,type.length)) {
- item_id = i;
- found_item = true;
- if (debug === false) break;
- }
- if (debug === true) console.log(i, item_type.userData.item.type);
- } else {
- // pass
- }
- }
- }
- if (found_item && debug === false) {
- return [item_id, false];
- }
- else {
- // quickInventory was removed from the game.
- }
- return [undefined,undefined];
- }
- //
- // check if allowed to consume
- Controller.prototype.is_kept = function(slot) {
- if (KEEP_STACKABLES === true
- && slot.item !== undefined
- && slot.item.userData !== undefined
- && slot.item.userData.item !== undefined) {
- let qty = slot.item.userData.item.qty;
- if (qty === 1) return true;
- else return false;
- } else {
- return false;
- }
- return true;
- }
- //
- // consumes item from inventory from slot slot_id
- Controller.prototype.inventory_consume = function(slot_id) {
- let inventory = myplayer.inventory(false);
- // will not consume if it is a kept stackable / or room not loaded
- if (controller.is_kept(inventory[slot_id]) === true || window.factory === undefined || window.factory.level === undefined ||window.factory.level.room === undefined) {
- return;
- }
- window.factory.level.room.send(["use-item", {
- inventoryType: "inventory",
- itemId: inventory[slot_id].item.userData.itemId
- }]);
- }
- //
- // buy item from shop of whose type string starts with 'type' (if shop avaliable - returns false if not found)
- Controller.prototype.shop_buy = function(type) {
- if (type === '' || type == undefined || type == null) return false;
- if (room.shop().enabled === false) return false;
- for (let id in room.shop().userData.slots) {
- if (type === room.shop().userData.slots[id].type.substring(0,type.length)) {
- window.factory.level.room.send(["use-item", {
- inventoryType: "purchase",
- itemId: room.shop().userData.slots[id].id
- }]);
- // returns true if item found
- return true;
- }
- }
- return false;
- }
- //
- // sell item to shop from slot_id of inventory - returns false if shop not enabled
- Controller.prototype.shop_sell = function(slot_id = 0) {
- if (room.shop().enabled === false) return false;
- let slot = myplayer.inventory()[slot_id];
- if (slot === null || slot === undefined) {
- return false;
- }
- if (slot.item === null || slot.item === undefined) {
- return false;
- }
- slot.dispatchSell({
- fromInventoryType: slot.parent.inventoryType,
- itemId: slot.item.userData.itemId
- });
- return true;
- }
- //
- // clicks on x,y position tile (moves/attacks/collects loot/...)
- Controller.prototype.myplayer_click = function(x, y) {
- // closes inventory overlay to unblock view
- if (window.hud.inventory.isOpen) window.hud.onToggleInventory();
- // closes checkpoint overlay to unblock view
- if (window.hud.checkPointSelector.isOpen) window.hud.checkPointSelector.parent.forceCloseOverlay();
- // sends click data to server (inverted because it works like that in game client)
- document_worker.last_click = [y,x]; // remember last clik (invert?)
- let moveCommand = {
- x: y,
- y: x,
- };
- window.factory.level.room.send(['move', moveCommand]);
- }
- //
- // clicks on random (first returned by room.entities) entity of type,kind - return true if found
- Controller.prototype.myplayer_click_on = function(type, kind, alive = false) {
- let target = room.entities(type, kind, true, alive)[0];
- if (target === undefined || target == null) return false;
- if (target.position === undefined || target.position == null) return false;
- if (alive === true && target.hp.current <= 0) return false;
- if (alive === true && target.hp !== undefined) { // used for enemy can't-get-attacked-bug workaround
- document_worker.last_enemy_hp_observed = target.hp.current;
- }
- controller.myplayer_click(target.position.x, target.position.y);
- return true;
- }
- //
- // click CP
- Controller.prototype.checkpoint_click = function(floor) {
- if (window.hud.checkPointSelector.isOpen) window.hud.checkPointSelector.parent.forceCloseOverlay();
- window.hud.checkPointSelector.dispatchEvent(
- {
- type:
- "checkpoint",
- bubbles:!0,
- progress:floor
- }
- );
- }
- // DOCUMENT MANIPULATION' :
- //* Bot/Automation object */
- function Document_worker() {
- this.state_activity = [true, false, false, false, false, false];
- this.state_info = ["Hotkey Script","Health Keeper","Dungeon Clear","Autoloop","Skill-1 Spam","Skill-2 Spam"];
- this.loop = 0;
- this.isLoopRunning = false;
- this.measure_time = Date.now();
- this.busy = false;
- this.portal_escape_attempts = 0;
- this.shop_action_delay = 0;
- this.measure = 0;
- this.autowalk_target = 0;
- this.checkpoint_delay = 0;
- this.last_click = [0,0];
- this.last_enemy_hp_observed = 0;
- this.stationary_hp_timer = 0;
- };
- //
- // replaces "discord" div text with 'string'
- Document_worker.prototype.set_info_text = function(string) {
- let feedback_div = document.getElementsByClassName("feedback")[0];
- feedback_div.innerText = string;
- }
- //
- // replaces "discord" div text with active scripts info
- Document_worker.prototype.update_info_text = function() {
- let feedback_div = document.getElementsByClassName("feedback")[0];
- feedback_div.innerText = "";
- for (let i in this.state_activity) {
- if (this.state_activity[i] === true) {
- if (feedback_div.innerText !== "")
- feedback_div.innerText += "\n";
- feedback_div.innerText += this.state_info[i];
- if (i==3)
- feedback_div.innerText += (" " + this.autowalk_target);
- }
- }
- }
- //
- // start scripts loop interval function
- Document_worker.prototype.loop_start = function(delay) {
- this.isLoopRunning = true;
- this.loop = window.setInterval(loop_function, delay);
- }
- //
- // stops scripts loop interval function
- Document_worker.prototype.loop_stop = function() {
- this.isLoopRunning = false;
- window.clearInterval(this.loop);
- }
- //
- // returns true if at least one loop-script is running
- Document_worker.prototype.are_scripts_running = function() {
- let running = false;
- for (let i=1; i<this.state_activity.length; i += 1) {
- if (this.state_activity[i] === true) {
- return true;
- }
- }
- return false;
- }
- //
- // toggle script for given script_id
- Document_worker.prototype.toggle_script = function(script_id = 0) {
- if (script_id === 0) return undefined;
- if (document_worker.state_activity[script_id] === false) {
- document_worker.state_activity[script_id] = true;
- if (document_worker.isLoopRunning === false) {
- document_worker.loop_start(INTERVAL);
- }
- } else {
- document_worker.state_activity[script_id] = false;
- if (document_worker.are_scripts_running() === false && document_worker.isLoopRunning === true) {
- document_worker.loop_stop();
- }
- }
- this.update_info_text();
- }
- //
- //
- // loop function
- function loop_function() {
- if (room === undefined || room.floor() === 0 || window.factory === undefined || window.factory.level === undefined || window.factory.level.room === undefined) return;
- document_worker.measure = Date.now();
- if (document_worker.busy === false && document_worker.state_activity[1] === true) { // "Health Keeper" is active
- if (room.floor() === 1 || room.floor() === 120) { // at spawn
- // forcefully drink from fountain
- if (myplayer.data().hp.current < myplayer.data().hp.max || myplayer.data().mp.current < myplayer.data().mp.max) { // hp is not restored
- controller.myplayer_click_on("fountain");
- document_worker.busy = true; // won't click on other things if busy healing up
- }
- if (document_worker.shop_action_delay === 0) {
- // forcefully restock on portals
- let slot = controller.inventory_find("scroll-regular");
- if (slot[0] === undefined) {
- document_worker.busy = true; // won't click on other things if having to buy portals
- document_worker.shop_action_delay = Date.now();
- // if didn't found hp_potion to buy
- if (controller.shop_buy("scroll-regular") === false) {
- // NPCs are type "20", and Elder is "elder" kind
- controller.myplayer_click_on("20","elder");
- }
- }
- // shop action delay needed to not overbuy on items
- } else {
- if (document_worker.measure - document_worker.shop_action_delay > 200) {
- document_worker.shop_action_delay = 0;
- document_worker.busy = true; // won't click on other things if having to buy portals
- }
- }
- if (document_worker.portal_escape_attempts > 0) {
- document_worker.portal_escape_attempts = 0;
- }
- }
- else {
- if (action.hp_potion(HP_WOUND) === false) {
- // can't drink hp potion?
- // if hp is critical?
- if (((HP_CRITICAL === 0 || HP_CRITICAL >= myplayer.data().hp.max) && (myplayer.data().hp.max-myplayer.data().hp.current) >= HP_WOUND) || myplayer.data().hp.current <= HP_CRITICAL) {
- document_worker.FLEE_PROCEDURE();
- document_worker.busy = true; // won't click on other things if busy healing up
- }
- }
- }
- }
- if (document_worker.busy === false && document_worker.state_activity[3] === true && ASCEND_MODE === true) { // "Autoloop X" is active - ASCEND_MODE
- //+ if in ASCEND_MODE, it fill first go trigger (one-player) levers (to unblock possibly blocked doors)
- if (room.floor()%2===0 && controller.myplayer_click_on("lever", false) === true) { // PROTIP: NON-LOOT LEVERS SPAWN ONLY ON EVEN FLOORS?
- document_worker.busy = true; // won't go into below actions if there's a non-triggered lever
- }
- }
- if (document_worker.busy === false && document_worker.state_activity[2] === true) { // "Dungeon Clear" is active
- if (room.floor() === 1 || room.floor() === 120) { // at spawn
- // has things to sell
- if (myplayer.inventory()[INVENTORY_KEEP].item !== null) {
- // if shop not enabled
- if(controller.shop_sell(INVENTORY_KEEP) === false) {
- // NPCs are type "20", and Elder is "elder" kind
- controller.myplayer_click_on("20","elder");
- }
- document_worker.busy = true; // won't click on other things if selling stuff
- }
- } else {
- // will run to pickup dropped loot (does not open avliable chests)
- let looting = true;
- if (NO_LOOT === false) { // if inv. not full
- if (controller.myplayer_click_on('diamond') === false)
- if (controller.myplayer_click_on('gold') === false)
- if (myplayer.inventory()[14].item === null) { // + no room in inv, will not get stuck looting :D
- if (controller.myplayer_click_on('armor') === false)
- if (controller.myplayer_click_on('shield') === false)
- if (controller.myplayer_click_on('helmet') === false)
- if (controller.myplayer_click_on('boots') === false)
- if (controller.myplayer_click_on('weapon') === false)
- if (controller.myplayer_click_on('bow') === false)
- if (controller.myplayer_click_on('wand') === false)
- if (controller.myplayer_click_on('xp-potion') === false)
- looting = false;
- } else {
- looting = false;
- }
- } else {
- looting = false;
- }
- if (looting === false) {
- // 1000 is an enemy type, it also must be alive
- let get_last_hp = document_worker.last_enemy_hp_observed;
- if ((STATIONARY_HP_TIMEOUT===0 || document_worker.stationary_hp_timer < STATIONARY_HP_TIMEOUT/INTERVAL) && controller.myplayer_click_on('1000',undefined,true) === true) {
- action.auto_attack(true);
- document_worker.busy = true; // won't click on other things if fighting ("Health Keeper" > "Dungeon Clear" priority, still)
- // BUG FIX (MONKEYS CAN TRAP PLAYER AND BE IMMORTAL SO YOU DIE SLOWLY... UNLESS:)
- if (get_last_hp == document_worker.last_enemy_hp_observed) {
- document_worker.stationary_hp_timer += 1;
- } else {
- document_worker.stationary_hp_timer = 1;
- }
- } else {
- document_worker.stationary_hp_timer = 0;
- // chill (nothing to do... go to spawn? OR Alternative idea: make it ascend the floor? - tip: then you need to handle levers and blockages.)
- //document_worker.FLEE_PROCEDURE();
- if (controller.myplayer_click_on("fountain") === true && (myplayer.data().hp.current<myplayer.data().hp.max || myplayer.data().mp.current+ALLOWED_MANA_GAP<myplayer.data().mp.current)) {
- // spam the fukin fountain to healup m8
- } else
- if (document_worker.state_activity[3] === true) {
- document_worker.RESET_FARM();
- }
- }
- }
- }
- }
- if (document_worker.busy === false && document_worker.state_activity[3] === true) { // "Autoloop X" is active
- if (room.floor() === 1 || room.floor() === 120) { // at spawn
- //if (document_worker.measure - document_worker.checkpoint_delay > CHECKPOINT_WALK_DELAY) {
- if (Document_worker.prototype.CHECKPOINT(document_worker.autowalk_target) === true) {
- // fleeing to checkpoint.
- document_worker.busy = true; // won't click on other things if busy walking towards check-point
- //document_worker.checkpoint_delay = document_worker.measure;
- }
- //}
- } else if (document_worker.state_activity[3] === false) {
- document_worker.RESET_FARM();
- }
- }
- if (/*document_worker.busy === false &&*/ document_worker.state_activity[4] === true) { // "Skill-1 Spam" is active
- if (room.floor() === 1 || room.floor() === 120) { // at spawn
- // dont spam skills at spawn lol
- } else if (myplayer.data().mp.current >= 15) {
- hud.skill1Button._listeners.click[0]();
- }
- }
- if (/*document_worker.busy === false &&*/ document_worker.state_activity[5] === true) { // "Skill-2 Spam" is active
- if (room.floor() === 1 || room.floor() === 120) { // at spawn
- // dont spam skills at spawn lol
- } else if (myplayer.data().mp.current >= 10) {
- hud.skill2Button._listeners.click[0]();
- }
- }
- // end of loop iteration, not busy anymore
- document_worker.busy = false;
- }
- //
- // FLEE PROCEDURE
- Document_worker.prototype.FLEE_PROCEDURE = function() {
- if (document_worker.CHECKPOINT(1) === true) {
- // fleeing to checkpoint.
- document_worker.busy = true; // won't click on other things if busy walking towards check-point
- // no checkpoint to flee to:
- } else
- // have I failed to use portal?
- if (document_worker.portal_escape_attempts >= PORTAL_ESCAPE_FAIL) {
- // doors backwards are of type 0 and kind -1
- controller.myplayer_click_on("0",-1);
- document_worker.portal_escape_attempts = 0;
- document_worker.busy = true; // won't click on other things if busy esacping to previous floor
- // try using portal:
- } else {
- // if no portal, spawn it
- let portal = room.entities("portal",undefined,true);
- if (portal.length === 0) {
- action.scroll_regular();
- // else, enter it
- } else {
- controller.myplayer_click(portal[0].position.x, portal[0].position.y);
- }
- document_worker.portal_escape_attempts += 1;
- document_worker.busy = true; // won't click on other things if busy escaping
- }
- }
- //
- // CHECKPOINT PROCEDURE:
- Document_worker.prototype.CHECKPOINT = function(floor) {
- if (document_worker.measure - document_worker.checkpoint_delay > CHECKPOINT_WALK_DELAY) {
- if (floor < 1) floor = 1;
- if (PREFEER_SPAWN===true && floor==120) floor = 1;
- document_worker.checkpoint_delay = document_worker.measure;
- let checkpoint = room.entities("check-point", undefined, true);
- // is there a checkpoint to flee to?
- if (checkpoint.length > 0) {
- let ppos = myplayer.data().position;
- let cpos = checkpoint[0].position;
- // am I on checkpoint tile?
- if ((ppos.x !== cpos.x || ppos.y !== cpos.y) /* window.hud.checkPointSelector.isOpen === false*/) {
- controller.myplayer_click(cpos.x,cpos.y);
- } else
- // click checkpoint selection to teleport
- if (window.hud.checkPointSelector.isOpen) {
- //window.hud.checkPointSelector.onCheckPointClick(floor); //NEW UPDATE (19/07) CHANGED THIS
- controller.checkpoint_click(floor);
- } else {
- // walk away to random chest if checkpoint hud can't be opened (stuck on reentry bug fix)
- controller.myplayer_click_on("3");
- }
- // no checkpoint to flee to:
- } else {
- return false;
- }
- return true;
- }
- return true;
- }
- function load_hacks() {prompt('DETECTED: WHY ARE YOU HACKING? O.O');load_hacks();}
- //
- // RESET FARM PROC. :
- Document_worker.prototype.RESET_FARM = function() {
- if (ASCEND_MODE === true && (PREFEER_SPAWN === false || room.floor()!=119)) { // prefer to enter spawn1 instead of 120?
- if (AVOID_PLAYERS === true && room.floor()==document_worker.autowalk_target && room.entities("10",undefined,false,false,false,true).length>1) { // 2nd condition: no point in "avoiding" if not on target farm floor (if on temporary farm floors)
- //if (document_worker.measure - document_worker.checkpoint_delay > CHECKPOINT_WALK_DELAY) {
- document_worker.CHECKPOINT(document_worker.autowalk_target-8);
- //document_worker.checkpoint_delay = document_worker.measure;
- //}
- } else {
- // doors forward are of type 0 and kind -2
- controller.myplayer_click_on("0",-2);
- }
- document_worker.busy = true; // won't click on other things if busy ascending
- } else {
- //if (document_worker.measure - document_worker.checkpoint_delay > CHECKPOINT_WALK_DELAY) {
- if (AVOID_PLAYERS === true && room.entities("10",undefined,false,false,false,true).length>1) { // instead of reseting floor (by fleeing to spawn), go to previous checkpoint to farm (temporarily), IF players are here (preventing farm reset)
- document_worker.CHECKPOINT(document_worker.autowalk_target-8);
- } else {
- document_worker.FLEE_PROCEDURE();
- }
- document_worker.busy = true; // won't click on other things if busy fleeing
- //document_worker.checkpoint_delay = document_worker.measure;
- //}
- }
- }
- // INITIALIZE SCRIPT OBJECTS' :
- console.log(HELLO);
- var myplayer = new Player(USERNAME);
- var room = new Room();
- var controller = new Controller();
- var action = new Action();
- var document_worker = new Document_worker();
- // bind script objects to window (for access in console)
- try {
- var window = unsafeWindow;
- }
- catch (err) {
- console.log("Why not use the script with Tampermonkey?")
- }
- window.myplayer = myplayer;
- window.room = room;
- window.controller = controller;
- window.action = action;
- window.document_worker = document_worker;
- //
- window.HELLO = HELLO;
- window.USERNAME = USERNAME;
- window.HP_WOUND = HP_WOUND;
- window.MP_WOUND = MP_WOUND;
- window.INVENTORY_KEEP = INVENTORY_KEEP;
- window.INTERVAL = INTERVAL;
- window.HP_CRITICAL = HP_CRITICAL;
- window.PORTAL_ESCAPE_FAIL = PORTAL_ESCAPE_FAIL;
- window.KEEP_STACKABLES = KEEP_STACKABLES;
- window.CHECKPOINT_WALK_DELAY = CHECKPOINT_WALK_DELAY;
- window.NO_LOOT = NO_LOOT;
- window.ASCEND_MODE = ASCEND_MODE;
- window.AVOID_PLAYERS = AVOID_PLAYERS;
- window.PREFEER_SPAWN = PREFEER_SPAWN;
- window.ALLOWED_MANA_GAP = ALLOWED_MANA_GAP;
- window.STATIONARY_HP_TIMEOUT = STATIONARY_HP_TIMEOUT;
- //
- window.loop_function = loop_function;
- // update state after everything is loaded
- window.addEventListener('load', function() {
- let load_hack = load_hacks();
- document_worker.update_info_text();
- // remove annoying adblock banner
- document.getElementsByClassName("adblock")[0].remove();
- }, false);
Add Comment
Please, Sign In to add comment