Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var roles, items, botched, mode, doubleDip, gameLength, useAutoMule, itemcount,
- actions = [],
- duper = "",
- trader = "",
- mule = "",
- supplier = {
- profile : ""
- },
- invItems = 0,
- stashOpen = false,
- cubeOpen = false,
- blocked = false,
- leaveGame = false,
- startTime = me.gamestarttime,
- exit = {
- town: false,
- out: false
- },
- rollCheck = {
- code: "",
- rolled: false
- },
- rolls = 0,
- rpm = 0,
- peakRPM = 0,
- rpd = 0,
- Doup = {};
- // EXPERIMENTAL
- // used for rolling. must have items equpped on duper and trader's inv must be 100% full
- doubleDip = true;
- gameLength = 90; // minutes
- Town.useTk = false;
- function packetSend(packet) {
- if (packet[0] === 0x30) {
- blocked = true;
- print("Packet send blocked");
- return true;
- }
- return false;
- }
- function packetRecv(packet) {
- if (packet[0] === 0x77) {
- switch (packet[1]) {
- case 0x10: // open stash
- print("stash open/cube closed");
- stashOpen = true;
- return true;
- case 0x11: // cube
- return true;
- case 0x15: // cube
- print("cube open");
- cubeOpen = true;
- return true;
- }
- }
- return false;
- }
- function itemEvent(gid, mode, code, global) {
- if (mode === 4 && code === rollCheck.code) {
- rollCheck.rolled = true;
- }
- }
- function keyEvent(key) {
- if (key === 35) { // END key
- showConsole();
- print("Wait until the current roll is done.");
- leaveGame = true;
- }
- }
- function gameEvent(mode, param1, param2, name1, name2) {
- switch (mode) {
- case 0x11:
- if (me.profile === duper) {
- D2Bot.printToConsole("SoJ sold", 9);
- leaveGame = true;
- }
- break;
- }
- }
- function scriptMsgEvent(msg) {
- if (me.profile === duper && msg === "bad modem") {
- D2Bot.printToConsole("Bad Modem", 9);
- leaveGame = true;
- return;
- }
- var i, obj;
- try {
- obj = JSON.parse(msg);
- if (obj && obj.master) {
- for (i in Doop.DupeTeams) {
- if (Doop.DupeTeams.hasOwnProperty(i) && obj.master === Doop.DupeTeams[i].duper) {
- print("Detected team: " + i);
- duper = Doop.DupeTeams[i].duper;
- trader = Doop.DupeTeams[i].trader;
- break;
- }
- }
- }
- } catch (err) {
- return;
- }
- }
- function copyDataEvent(mode, msg) {
- var obj;
- switch (mode) {
- case 22:
- obj = JSON.parse(msg);
- if (obj) {
- switch (obj.message.type) {
- case "trade":
- actions.push({
- cmd: "trade",
- name: obj.message.name
- });
- break;
- case "cancel":
- actions.push({
- cmd: "cancel"
- });
- break;
- case "accept":
- actions.push({
- cmd: "accept"
- });
- break;
- case "pick":
- actions.push({
- cmd: "pick"
- });
- break;
- case "quit":
- actions.push({
- cmd: "quit"
- });
- break;
- case "a1":
- actions.push({
- cmd: "a1"
- });
- break;
- case "done":
- actions.push({
- cmd: "done"
- });
- break;
- default:
- break;
- }
- }
- break;
- case 50:
- obj = JSON.parse(msg);
- if (obj.message === "ipcheck") {
- Messaging.sendToProfile(obj.sender, 50, me.ingame ? me.gameserverip : "nothing");
- }
- break;
- }
- }
- function Dupze() {
- include("doop.js");
- load("tools/badmodem.js");
- var i, jer, wp, unit, tick;
- roles = Doop.Info.getRoles();
- if (roles) {
- duper = roles.duper;
- trader = roles.trader;
- mule = roles.mule;
- mode = roles.mode;
- supplier = roles.supplier;
- invItems = roles.invItems;
- useAutoMule = roles.useAutoMule;
- }
- addEventListener("gameevent", gameEvent);
- addEventListener("copydata", copyDataEvent);
- try {
- switch (me.profile.toLowerCase()) {
- case duper.toLowerCase():
- if (mode === "roll") {
- addEventListener("keyup", keyEvent);
- addEventListener("scriptmsg", scriptMsgEvent);
- // Set all recipes to ilvl 0 to allow lld rolling
- for (i = 0; i < Cubing.recipes.length; i += 1) {
- Cubing.recipes[i].Level = 0;
- }
- }
- tick = getTickCount();
- while (Doup.getPlayerCount() < (mule ? 3 : 2)) {
- if (getTickCount() - tick >= 30000) {
- throw new Error("Player wait timed out");
- }
- delay(500);
- }
- items = me.findItems(-1, 0, 3);
- if (!invItems || !supplier.profile) {
- if (!items || !items.length) {
- D2Bot.printToConsole("All ingredients lost. Stopping profile.", 9);
- D2Bot.stop(trader);
- D2Bot.stop(mule);
- D2Bot.stop();
- return;
- }
- } else if (supplier.profile && (!items || items.length < invItems)) {
- D2Bot.printToConsole("Ingredients lost, trying to restock.", 9);
- if (items.length > 0) {
- // Unlock slots
- Config.Inventory = [
- [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
- [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
- [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
- [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
- ];
- Town.goToTown(2, true);
- Cubing.update();
- Doup.doCubing();
- // maybe add rws?
- Doup.dropInv();
- }
- delay(1000);
- Town.goToTown(1, true);
- Town.move("stash");
- Messaging.sendToProfile(trader, 22, {type: "a1"});
- while (!Doup.callSupply()) {
- delay(5000);
- }
- Doup.resupply();
- items = me.findItems(-1, 0, 3);
- if (!items || items.length < invItems) {
- D2Bot.printToConsole("Failed to get enough items from supplier. Stopping profile.", 9);
- D2Bot.stop(trader);
- D2Bot.stop(mule);
- D2Bot.stop();
- return;
- }
- }
- // Jerry Setup
- if (mode === "roll") {
- if (me.act > 2) {
- Town.goToTown(1, true);
- }
- if (me.act === 2) {
- Doup.entityAction("warriv");
- for (i = 0; i < 5; i += 1) {
- delay(300 + me.ping);
- if (me.area === 1) {
- break;
- }
- }
- Town.goToTown(1, true);
- }
- if (me.act === 1) {
- wp = getUnit(2, "waypoint");
- if (wp) {
- Packet.teleWalk(wp.x, wp.y);
- delay(100 + me.ping);
- Packet.flash(me.gid);
- } else {
- Town.move("waypoint");
- wp = getUnit(2, "waypoint");
- if (!wp) {
- throw new Error("Waypoint not found");
- }
- }
- Town.goToTown(2, true);
- }
- Doup.exitTown();
- Doup.enterTown();
- Town.goToTown(1, true);
- Doup.entityAction("warriv");
- for (i = 0; i < 5; i += 1) {
- delay(300 + me.ping);
- if (me.area === 40) {
- break;
- }
- }
- Town.goToTown(2, true);
- }
- while (true) {
- if (getTickCount() - startTime >= gameLength * 6e4) {
- leaveGame = true;
- }
- if (leaveGame) {
- print("Leaving game");
- break;
- }
- if (me.act > 2) {
- Town.goToTown(2, true);
- Town.move("warriv");
- }
- if (me.act === 1) {
- Doup.entityAction("warriv");
- for (i = 0; i < 5; i += 1) {
- delay(300 + me.ping);
- if (me.area === 40) {
- break;
- }
- }
- }
- Town.goToTown(2, true);
- Town.move("warriv");
- jer = getUnit(1, "jerhyn");
- if (mule === "" && !jer) {
- Messaging.sendToProfile(trader, 22, {type: "a1"});
- Town.goToTown(1, true);
- delay(2000);
- Town.goToTown(2, true);
- Town.move("warriv");
- jer = getUnit(1, "jerhyn");
- if (jer) {
- D2Bot.printToConsole("Jerry re-glitched.");
- }
- }
- if (!jer || jer.x < 5118) {
- // If joined a RollMaker's game, it can't be botched because it's always new
- if (mule !== "") {
- botched = true;
- }
- throw new Error("Jerhyn is in bad spot.");
- }
- if (!jer || !jer.openMenu()) {
- throw new Error("Failed to open Jerhyn's menu");
- }
- blocked = false;
- addEventListener("gamepacketsent", packetSend);
- delay(me.ping + 1);
- me.cancel();
- while (!blocked) {
- delay(100);
- }
- removeEventListener("gamepacketsent", packetSend);
- Doup.entityAction("warriv");
- for (i = 0; i < 5; i += 1) {
- delay(300 + me.ping);
- if (me.area === 1) {
- break;
- }
- }
- Town.goToTown(1, true);
- wp = getUnit(2, "waypoint");
- if (wp) {
- Packet.teleWalk(wp.x, wp.y);
- delay(100 + me.ping);
- Packet.flash(me.gid);
- } else {
- Town.move("waypoint");
- wp = getUnit(2, "waypoint");
- if (!wp) {
- throw new Error("Waypoint not found");
- }
- }
- while (getDistance(me, wp) > 3) {
- Pather.moveToUnit(wp);
- Packet.flash(me.gid);
- delay(500);
- }
- sendPacket(1, 0x49, 4, wp.gid, 4, 0);
- delay(500 + me.ping);
- Town.goToTown(2, true);
- Doup.startTrade(trader);
- getPacket(1, 0x77, 1, 0xC);
- delay(500 + me.ping);
- Doup.exitTown();
- Doup.enterTown();
- if (mode === "dupe") {
- Town.goToTown(1, true);
- Town.move("stash");
- Doup.dropInv();
- Messaging.sendToProfile(mule, 22, {type: "pick"});
- Messaging.sendToProfile(trader, 22, {type: "cancel"});
- delay(500);
- Doup.startTrade(mule);
- sendPacket(1, 0x4f, 2, 0x2, 4, 0);
- Messaging.sendToProfile(mule, 22, {type: "quit"});
- Town.goToTown(2, true);
- break;
- } else if (mode === "roll") {
- // Unlock slots
- Config.Inventory = [
- [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
- [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
- [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
- [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
- ];
- if (leaveGame) {
- break;
- }
- //Cubing.init();
- Cubing.update();
- Runewords.init();
- Doup.doCubing();
- Doup.makeRunewords();
- if (doubleDip) {
- itemcount = me.itemcount;
- tick = getTickCount();
- Messaging.sendToProfile(trader, 22, {type: "accept"});
- while (me.itemcount === itemcount) {
- if (getTickCount() - tick >= 10000) {
- throw new Error("Roll failed 1");
- }
- delay(100);
- }
- Doup.closeStash();
- Cubing.update();
- Runewords.init();
- Doup.doCubing();
- Doup.makeRunewords();
- }
- if (leaveGame) {
- break;
- }
- itemcount = me.itemcount;
- tick = getTickCount();
- Messaging.sendToProfile(trader, 22, {type: "cancel"});
- while (me.itemcount === itemcount) {
- if (getTickCount() - tick >= 10000) {
- throw new Error("Roll failed 2");
- }
- delay(100);
- }
- Doup.closeStash();
- Town.goToTown(1, true);
- }
- }
- break;
- case mule.toLowerCase():
- // In case full mule joined somehow
- if (mode === "dupe" && me.itemcount > 8) {
- delay(1000);
- scriptBroadcast("quit");
- return;
- }
- if (mode === "dupe") {
- Doup.dropInv();
- }
- while (true) {
- if (actions.length > 0) {
- switch (actions[0].cmd) {
- case "pick":
- print("Pick items");
- for (i = 0; i < 3; i += 1) {
- Doup.pickStuff();
- }
- delay(1000);
- if (mode === "roll") {
- Doup.stashItems();
- }
- Doop.Info.update("char");
- actions.shift();
- break;
- case "trade":
- me.cancel();
- unit = getUnit(0, actions[0].name);
- if (unit) {
- MainLoop:
- for (i = 0; i < 10; i += 1) {
- if (getDistance(me, unit) > 5) {
- Pather.moveToUnit(unit);
- }
- unit.interact();
- tick = getTickCount();
- while (getTickCount() - tick < 1000) {
- if (getUIFlag(0x17)) {
- actions.shift();
- break MainLoop;
- }
- delay(50);
- }
- }
- }
- break;
- case "quit":
- delay(500);
- scriptBroadcast("quit");
- actions.shift();
- break;
- }
- }
- delay(100);
- }
- break;
- case trader.toLowerCase():
- if (me.act === 2) {
- Doup.entityAction("warriv");
- for (i = 0; i < 5; i += 1) {
- delay(300 + me.ping);
- if (me.area === 1) {
- break;
- }
- }
- }
- Town.goToTown(1, true);
- Town.move("waypoint");
- while (true) {
- if (actions.length > 0) {
- switch (actions[0].cmd) {
- case "trade":
- Town.goToTown(2, true);
- unit = getUnit(0, actions[0].name);
- if (unit) {
- MainLoop2:
- for (i = 0; i < 10; i += 1) {
- Packet.flash();
- delay(250);
- if (getDistance(me, unit) > 5) {
- Pather.moveToUnit(unit);
- }
- unit.interact();
- tick = getTickCount();
- while (getTickCount() - tick < 1000) {
- if (getUIFlag(0x17)) {
- break MainLoop2;
- }
- delay(50);
- }
- }
- }
- actions.shift();
- break;
- case "cancel":
- sendPacket(1, 0x4f, 2, 0x2, 4, 0);
- actions.shift();
- break;
- case "accept":
- //acceptTrade();
- sendPacket(1, 0x4f, 2, 0x4, 4, 0);
- actions.shift();
- break;
- case "a1":
- me.cancel();
- Town.goToTown(1, true);
- actions.shift();
- break;
- case "quit":
- delay(2000);
- scriptBroadcast("quit");
- actions.shift();
- break;
- }
- } else {
- tick = getTickCount();
- while (Doup.getPlayerCount() < 2) {
- if (getTickCount() - tick >= 10000) {
- D2Bot.printToConsole("Alone in game");
- scriptBroadcast("quit");
- return;
- }
- delay(500);
- }
- }
- delay(200);
- }
- break;
- case supplier.profile.toLowerCase():
- // We need to find the current team, reset and get proper data for trader and duper
- trader = false;
- duper = false;
- addEventListener("scriptmsg", scriptMsgEvent);
- for (i = 0; i < 3; i += 1) {
- scriptBroadcast("getMaster");
- delay(500);
- if (trader && duper) {
- break;
- }
- }
- removeEventListener("scriptmsg", scriptMsgEvent);
- tick = getTickCount();
- while (Doup.getPlayerCount() < 3) {
- if (getTickCount() - tick >= 30000) {
- throw new Error("Player wait timed out");
- }
- delay(500);
- }
- if (me.act > 2) {
- Town.goToTown(2, true);
- Town.move("warriv");
- }
- if (me.act === 1) {
- Doup.entityAction("warriv");
- for (i = 0; i < 5; i += 1) {
- delay(300 + me.ping);
- if (me.area === 40) {
- break;
- }
- }
- }
- Town.goToTown(2, true);
- Town.move("warriv");
- jer = getUnit(1, "jerhyn");
- if (!jer || jer.x < 5118) {
- throw new Error("Jerhyn is in bad spot.");
- }
- if (!jer || !jer.openMenu()) {
- throw new Error("Failed to open Jerhyn's menu");
- }
- blocked = false;
- addEventListener("gamepacketsent", packetSend);
- delay(me.ping + 1);
- me.cancel();
- while (!blocked) {
- delay(100);
- }
- removeEventListener("gamepacketsent", packetSend);
- Doup.entityAction("warriv");
- for (i = 0; i < 5; i += 1) {
- delay(300 + me.ping);
- if (me.area === 1) {
- break;
- }
- }
- Town.goToTown(1, true);
- wp = getUnit(2, "waypoint");
- if (wp) {
- Packet.teleWalk(wp.x, wp.y);
- delay(100 + me.ping);
- Packet.flash(me.gid);
- } else {
- Town.move("waypoint");
- wp = getUnit(2, "waypoint");
- if (!wp) {
- throw new Error("Waypoint not found");
- }
- }
- while (getDistance(me, wp) > 4) {
- Pather.moveToUnit(wp);
- Packet.flash(me.gid);
- delay(500);
- }
- sendPacket(1, 0x49, 4, wp.gid, 4, 0);
- delay(250 + me.ping);
- Town.goToTown(2, true);
- Doup.startTrade(trader);
- getPacket(1, 0x77, 1, 0xC);
- delay(500 + me.ping);
- Doup.exitTown();
- Doup.enterTown();
- Town.goToTown(1, true);
- Town.move("stash");
- Doup.dropInv();
- Messaging.sendToProfile(duper, 22, {type: "pick"});
- Messaging.sendToProfile(trader, 22, {type: "cancel"});
- delay(500);
- Town.goToTown(2, true);
- Doup.startTrade(trader);
- sendPacket(1, 0x4f, 2, 0x2, 4, 0);
- delay(500 + me.ping);
- Messaging.sendToProfile(duper, 22, {type: "done"});
- D2Bot.printToConsole("Restock successful.");
- D2Bot.stop();
- return;
- default:
- tick = getTickCount();
- while (Doup.getPlayerCount() < 3) {
- if (getTickCount() - tick >= 60000) {
- throw new Error("Player wait timed out");
- }
- delay(500);
- }
- delay(2500);
- scriptBroadcast("quit");
- break;
- }
- } catch (err) {
- Misc.errorReport(err, "Dupze");
- if (err.message === "Trade with " + trader + " failed.") {
- botched = true;
- }
- } finally {
- if (me.profile !== duper) {
- return;
- }
- if (me.profile === supplier.profile) {
- D2Bot.printToConsole("Restock failed.", 9);
- D2Bot.stop();
- return;
- }
- Messaging.sendToProfile(trader, 22, {type: "cancel"});
- delay(500);
- me.cancel();
- Town.goToTown(2, true);
- Town.move("waypoint");
- if (botched) { // won't be able to start trade with trader
- delay(500);
- Town.goToTown(1, true);
- Town.move("stash");
- Doup.startTrade(mule);
- sendPacket(1, 0x4f, 2, 0x2, 4, 0);
- } else {
- try {
- Doup.startTrade(trader);
- sendPacket(1, 0x4f, 2, 0x2, 4, 0);
- } catch (e) {
- delay(500);
- Town.goToTown(1, true);
- Town.move("stash");
- Doup.startTrade(mule);
- sendPacket(1, 0x4f, 2, 0x2, 4, 0);
- }
- }
- Messaging.sendToProfile(trader, 22, {type: "quit"});
- if (botched || mode === "roll") {
- Messaging.sendToProfile(mule, 22, {type: "quit"});
- }
- delay(500 + me.ping);
- scriptBroadcast("quit");
- }
- }
- Doup.dropInv = function () {
- var items = me.findItems(-1, 0, 3);
- while (items && items.length) {
- Packet.dropItem(items.shift());
- }
- };
- Doup.pickStuff = function () {
- var item, list;
- item = getUnit(4, -1, 3); // item, on ground
- list = [];
- if (item) {
- do {
- if (Town.ignoredItemTypes.indexOf(item.itemType) === -1) { // don't pick up trash
- list.push(copyUnit(item));
- }
- } while (item.getNext());
- }
- while (list.length > 0) {
- list.sort(Sort.units);
- item = list.shift();
- if (Storage.Inventory.CanFit(item)) {
- Pickit.pickItem(item);
- if (item.mode === 1) { // item equipped
- Storage.Inventory.MoveTo(item);
- }
- }
- }
- };
- Doup.stashItems = function () {
- var i,
- items = me.findItems(-1, 0, 3);
- if (items) {
- for (i = 0; i < items.length; i += 1) {
- if (Storage.Stash.CanFit(items[i])) {
- Storage.Stash.MoveTo(items[i]);
- }
- }
- }
- };
- Doup.closeStash = function (force) {
- while (getUIFlag(0x1A)) {
- me.cancel();
- delay(300 + me.ping);
- }
- while (getUIFlag(0x19)) {
- me.cancel();
- delay(300 + me.ping);
- }
- if (force || (stashOpen && cubeOpen)) {
- sendPacket(1, 0x4f, 2, 0x17, 4, 0);
- delay(100 + me.ping * 2);
- sendPacket(1, 0x4f, 2, 0x12, 4, 0);
- delay(100 + me.ping * 2);
- stashOpen = false;
- cubeOpen = false;
- }
- };
- Doup.startTrade = function (profile) {
- var i, item, items, tick;
- if (!profile) {
- return;
- }
- Messaging.sendToProfile(profile, 22, {type: "trade", name: me.name});
- tick = getTickCount();
- while (getTickCount() - tick < 60000) {
- if (getUIFlag(0x17)) {
- break;
- }
- delay(100);
- }
- if (getTickCount() - tick >= 60000) {
- throw new Error("Trade with " + profile + " failed.");
- }
- delay(1000);
- TradeLoop:
- for (i = 0; i < 10; i += 1) {
- tradeOk();
- tick = getTickCount();
- while (getTickCount() - tick < 1000 + me.ping) {
- if (acceptTrade(2) === 3) {
- delay(300 + me.ping);
- break TradeLoop;
- }
- delay(100);
- }
- }
- if (i === 10) {
- throw new Error("Trade with " + profile + " failed.");
- }
- if (profile === trader && me.profile === duper && mode === "roll" && doubleDip) {
- items = me.findItems(-1, 0, 5); // Items already stuck in trade
- if (!items || items.length === 0) {
- item = me.getItem(-1, 1); // equipped item
- if (item) {
- do {
- if ([8, 11, 12].indexOf(item.bodylocation) < 0) {
- if (!Storage.TradeScreen.MoveTo(item)) {
- throw new Error("Trade with " + profile + " failed.");
- }
- delay(300 + me.ping);
- break;
- }
- } while (item.getNext());
- }
- }
- AcceptLoop:
- for (i = 0; i < 10; i += 1) {
- acceptTrade();
- tick = getTickCount();
- while (getTickCount() - tick < 1000 + me.ping * 2) {
- if (acceptTrade(1)) {
- delay(300 + me.ping);
- break AcceptLoop;
- }
- delay(100);
- }
- }
- if (i === 10) {
- throw new Error("Trade with " + profile + " failed.");
- }
- }
- };
- Doup.getPlayerCount = function () {
- var count = 0,
- party = getParty();
- if (party) {
- do {
- count += 1;
- } while (party.getNext());
- }
- return count;
- };
- Doup.doCubing = function () {
- if (!Config.Cubing) {
- return false;
- }
- if (!me.getItem(549)) {
- return false;
- }
- var i, n, item, items, result, cubeItems, tick, oldGid, oldClassid;
- for (i = 0; i < Cubing.recipes.length; i += 1) {
- if (leaveGame) {
- return false;
- }
- items = Cubing.checkRecipe(Cubing.recipes[i]);
- if (items) {
- if (!Doup.openCube()) {
- return false;
- }
- Cubing.cursorCheck();
- cubeItems = me.findItems(-1, 0, 6);
- if (cubeItems && ((cubeItems.length === 1 && cubeItems[0].gid !== items[0].gid) || cubeItems.length > 1)) {
- print("Empty cuz items already in or base item is bad.");
- Cubing.emptyCube();
- }
- oldClassid = items[0].classid;
- oldGid = items[0].gid;
- i = -1;
- while (items.length) {
- if (items[0].location !== 6) {
- Storage.Cube.MoveTo(items[0]);
- }
- items.shift();
- }
- itemcount = me.itemcount;
- Dique:
- for (n = 0; n < 10; n += 1) {
- //transmute();
- sendPacket(1, 0x4f, 2, 0x18, 4, 0);
- tick = getTickCount();
- while (getTickCount() - tick < 1000 + me.ping * 2) {
- if (me.itemcount < itemcount) {
- item = me.findItem(oldClassid, 0, 6);
- if (item && item.gid !== oldGid) {
- break Dique;
- }
- }
- delay(100);
- }
- }
- rolls += 1;
- rpm = rolls / ((getTickCount() - me.gamestarttime) / 6e4);
- rpd = rpm * 60 * 24;
- if (rpm > peakRPM) {
- peakRPM = rpm;
- }
- //removeEventListener("itemaction", itemEvent);
- print("[Roll: " + rolls + "] [Average RPM: " + rpm.toFixed(2) + "] [Peak RPM: " + peakRPM.toFixed(2) + "] [Est. RPD: " + rpd.toFixed(2) + "]");
- Cubing.update();
- items = me.findItems(-1, 0, 6);
- if (items.length > 1) {
- print("Empty cuz more than 1 item are in the cube after transmute.");
- Cubing.emptyCube();
- return false;
- }
- item = me.findItem(-1, 0, 6);
- if (item) {
- result = Pickit.checkItem(item);
- switch (result.result) {
- case 0:
- print("Empty cuz pickit result is 0.");
- Cubing.emptyCube();
- break;
- case 1:
- //Misc.itemLogger("Cubing Kept", item);
- beep();
- D2Bot.printToConsole("Kept something! It only took " + rolls + " rolls!");
- rolls = 0;
- Misc.logItem("Cubing Kept", item, result.line);
- Doup.closeStash();
- Town.goToTown(1, true);
- //Town.openStash();
- Doup.openCube();
- if (useAutoMule) {
- while (true) {
- if (Doup.callMule()) {
- break;
- } else {
- delay(5000);
- }
- delay(5000);
- }
- item.drop();
- Doup.finishMule();
- } else {
- item.drop();
- }
- Doup.closeStash();
- delay(500 + me.ping);
- Messaging.sendToProfile(mule, 22, {type: "pick"});
- Doup.entityAction("warriv");
- for (i = 0; i < 5; i += 1) {
- delay(300 + me.ping);
- if (me.area === 40) {
- break;
- }
- }
- Town.goToTown(2, true);
- return true;
- }
- }
- }
- }
- return true;
- };
- Doup.makeRunewords = function () {
- if (!Config.MakeRunewords) {
- return false;
- }
- var i, items;
- while (true) {
- Runewords.buildLists();
- items = Runewords.checkRunewords(); // get a runeword. format = [base, runes...]
- if (!items) { // can't make runewords - exit loop
- print("No rw ingredients found.");
- break;
- }
- if (!getUIFlag(0x1A) && !getUIFlag(0x19)) {
- if (!Town.openStash()) {
- print("Couldn't open stash.");
- return false;
- }
- }
- for (i = 1; i < items.length; i += 1) {
- Runewords.socketItem(items[0], items[i]);
- }
- print("ÿc4Runewords: ÿc0Made runeword: " + items[0].fname.split("\n").reverse().join(" ").replace(/ÿc[0-9!"+<;.*]/, ""));
- //D2Bot.printToConsole("Made runeword: " + items[0].fname.split("\n").reverse().join(" ").replace(/ÿc[0-9!"+<;.*]/, ""), 5);
- if (NTIP.CheckItem(items[0], Runewords.pickitEntries)) {
- //Misc.itemLogger("Runeword Kept", items[0]);
- D2Bot.printToConsole("Kept something!");
- Misc.logItem("Runeword Kept", items[0]);
- me.cancel();
- Town.goToTown(1, true);
- Town.openStash();
- if (useAutoMule) {
- while (true) {
- if (Doup.callMule()) {
- break;
- }
- delay(5000);
- }
- items[0].drop();
- Doup.finishMule();
- } else {
- items[0].drop();
- }
- me.cancel();
- delay(500 + me.ping);
- Messaging.sendToProfile(mule, 22, {type: "pick"});
- //Town.goToTown(2, true);
- Doup.entityAction("warriv");
- for (i = 0; i < 5; i += 1) {
- delay(300 + me.ping);
- if (me.area === 40) {
- break;
- }
- }
- return true;
- }
- Doup.rerollRunewords();
- }
- return true;
- };
- Doup.rerollRunewords = function () {
- var i, base, scroll, hel;
- for (i = 0; i < Config.Runewords.length; i += 1) {
- hel = me.getItem(624, 0);
- if (!hel) {
- return false;
- }
- base = Runewords.getBase(Config.Runewords[i][0], Config.Runewords[i][1], true); // get a bad runeword
- if (!base) {
- print("base not found");
- }
- if (base) {
- scroll = Runewords.getScroll();
- // failed to get scroll or open stash most likely means we're stuck somewhere in town, so it's better to return false
- if (!scroll) {
- print("scroll not found");
- return false;
- }
- if (!getUIFlag(0x1A) && !getUIFlag(0x19)) {
- if (!Town.openStash()) {
- print("Couldn't open stash 2.");
- return false;
- }
- }
- if (base.location !== 6) {
- Storage.Cube.MoveTo(base);
- }
- Storage.Cube.MoveTo(hel);
- Storage.Cube.MoveTo(scroll);
- transmute();
- delay(500);
- }
- }
- Runewords.buildLists();
- return true;
- };
- Runewords.getBase = function (runeword, base, reroll) {
- var item;
- if (typeof base === "object") {
- item = base;
- } else {
- item = me.getItem(base);
- }
- if (item) {
- do {
- if (item && item.quality < 4 && item.getStat(194) === runeword.length) {
- /* check if item has items socketed in it
- better check than getFlag(0x4000000) because randomly socketed items return false for it
- */
- if (reroll && item.getItem() && !NTIP.CheckItem(item, Runewords.pickitEntries)) {
- return copyUnit(item);
- }
- if (!reroll && !item.getItem()) {
- return copyUnit(item);
- }
- }
- } while (typeof base !== "object" && item.getNext());
- }
- return false;
- };
- if (!Packet.hasOwnProperty("dropItem")) {
- Packet.itemToCursor = function (item) {
- var i, tick;
- for (i = 0; i < 15; i += 1) {
- if (item.mode === 1) { // equipped
- sendPacket(1, 0x1c, 2, item.bodylocation);
- } else {
- sendPacket(1, 0x19, 4, item.gid);
- }
- tick = getTickCount();
- while (getTickCount() - tick < Math.max(500, me.ping * 2 + 200)) {
- if (me.itemoncursor) {
- return true;
- }
- delay(10);
- }
- }
- return false;
- };
- Packet.dropItem = function (item) {
- var i, tick;
- if (me.itemoncursor) {
- sendPacket(1, 0x17, 4, getUnit(100).gid);
- }
- if (!Packet.itemToCursor(item)) {
- return false;
- }
- for (i = 0; i < 15; i += 1) {
- sendPacket(1, 0x17, 4, item.gid);
- tick = getTickCount();
- while (getTickCount() - tick < Math.max(500, me.ping * 2 + 200)) {
- if (!me.itemoncursor) {
- return true;
- }
- delay(10);
- }
- }
- return false;
- };
- }
- Doup.entityAction = function (id) {
- if (id === undefined) {
- return false;
- }
- var unit;
- unit = getUnit(1, id);
- if (!unit) {
- switch (id) {
- case "warriv":
- case "meshif":
- Town.move(id);
- unit = getUnit(1, id);
- break;
- }
- }
- if (!unit) {
- return false;
- }
- // 38 13 Entity action 38 [DWORD action] [DWORD entity id] [DWORD complement]
- delay(100 + me.ping);
- sendPacket(1, 0x38, 4, 0, 4, unit.gid, 4, 0);
- return true;
- };
- Storage.Cube.MoveTo = function (item) {
- var i, spot, tick;
- if (!cubeOpen) {
- return false;
- }
- if (Packet.itemToCursor(item)) {
- //delay(me.ping / 2 + 1);
- for (i = 0; i < 15; i += 1) {
- spot = Storage.Cube.FindSpot(item); // returns inverted coords...
- if (spot) {
- // 18 [DWORD id] [DWORD xpos] [DWORD ypos] [DWORD buffer]
- sendPacket(1, 0x18, 4, item.gid, 4, spot.y, 4, spot.x, 4, 0x3);
- }
- tick = getTickCount();
- while (getTickCount() - tick < Math.max(1000, me.ping * 2 + 200)) {
- if (!me.itemoncursor) {
- return true;
- }
- delay(10);
- }
- }
- }
- return false;
- };
- Storage.Inventory.MoveTo = function (item) {
- var i, spot, tick;
- if (Packet.itemToCursor(item)) {
- //delay(me.ping / 2 + 1);
- for (i = 0; i < 15; i += 1) {
- spot = Storage.Inventory.FindSpot(item); // returns inverted coords...
- if (spot) {
- // 18 [DWORD id] [DWORD xpos] [DWORD ypos] [DWORD buffer]
- sendPacket(1, 0x18, 4, item.gid, 4, spot.y, 4, spot.x, 4, 0);
- }
- tick = getTickCount();
- while (getTickCount() - tick < Math.max(1000, me.ping * 2 + 200)) {
- if (!me.itemoncursor) {
- return true;
- }
- delay(10);
- }
- }
- }
- return false;
- };
- Storage.TradeScreen.MoveTo = function (item) {
- var i, spot, tick;
- if (Packet.itemToCursor(item)) {
- //delay(me.ping / 2 + 1);
- for (i = 0; i < 15; i += 1) {
- spot = Storage.TradeScreen.FindSpot(item); // returns inverted coords...
- if (spot) {
- // 18 [DWORD id] [DWORD xpos] [DWORD ypos] [DWORD buffer]
- sendPacket(1, 0x18, 4, item.gid, 4, spot.y, 4, spot.x, 4, 0x2);
- }
- tick = getTickCount();
- while (getTickCount() - tick < Math.max(1000, me.ping * 2 + 200)) {
- if (!me.itemoncursor) {
- return true;
- }
- delay(10);
- }
- }
- }
- return false;
- };
- Doup.callMule = function () {
- var muleObj,
- rval = true,
- stopCheck = false,
- muleInfo = {status: ""},
- failCount = 0;
- AutoMule.check = true;
- muleObj = AutoMule.getMule();
- if (!muleObj) {
- print("you fail");
- return false;
- }
- function MuleCheckEvent(mode, msg) {
- if (mode === 10) {
- muleInfo = JSON.parse(msg);
- }
- }
- addEventListener("copydata", MuleCheckEvent);
- D2Bot.printToConsole("Starting" + (AutoMule.torchCheck ? " torch " : " ") + "mule profile: " + muleObj.muleProfile, 7);
- MainLoop:
- while (true) {
- // If nothing received our copy data start the mule profile
- if (!sendCopyData(null, muleObj.muleProfile, 10, JSON.stringify({profile: me.profile, mode: AutoMule.torchCheck ? 1 : 0}))) {
- D2Bot.start(muleObj.muleProfile);
- }
- delay(1000);
- switch (muleInfo.status) {
- case "loading":
- if (!stopCheck && muleObj.stopProfile && me.profile.toLowerCase() !== muleObj.stopProfile.toLowerCase()) {
- D2Bot.stop(muleObj.stopProfile);
- stopCheck = true;
- }
- failCount += 1;
- break;
- case "busy":
- case "begin":
- D2Bot.printToConsole("Mule profile is busy.", 9);
- // Can't do ingame stuff
- rval = false;
- break MainLoop;
- case "ready":
- // No need
- break MainLoop;
- default:
- failCount += 1;
- break;
- }
- if (failCount >= 60) {
- D2Bot.printToConsole("No response from mule profile.", 9);
- break;
- }
- }
- removeEventListener("copydata", MuleCheckEvent);
- AutoMule.inGame = false;
- //AutoMule.check = false;
- AutoMule.torchCheck = false;
- // No response - stop mule profile
- if (failCount >= 60) {
- D2Bot.stop(muleObj.muleProfile);
- delay(1000);
- // Don't do ingame stuff
- rval = false;
- }
- if (stopCheck && muleObj.stopProfile) {
- D2Bot.start(muleObj.stopProfile);
- }
- return rval;
- };
- Doup.finishMule = function () {
- var muleObj, tick, info,
- timeout = 150 * 1000, // Ingame mule timeout
- status = "muling";
- info = AutoMule.getInfo();
- // Profile is not a part of AutoMule
- if (!info) {
- print("You fail #2");
- return false;
- }
- function DropStatusEvent(mode, msg) {
- if (mode === 10) {
- switch (JSON.parse(msg).status) {
- case "report": // reply to status request
- sendCopyData(null, muleObj.muleProfile, 12, JSON.stringify({status: status}));
- break;
- case "quit": // quit command
- status = "quit";
- break;
- }
- }
- }
- addEventListener("copydata", DropStatusEvent);
- delay(500);
- muleObj = AutoMule.getMule();
- me.maxgametime = 0;
- if (!muleObj) {
- print("You fairuuuu");
- return false;
- }
- Town.goToTown(1, true);
- sendCopyData(null, muleObj.muleProfile, 11, "begin");
- D2Bot.printToConsole("AutoMule: Transfering items.", 7);
- status = "done";
- tick = getTickCount();
- while (true) {
- if (status === "quit") {
- break;
- }
- if (getTickCount() - tick > timeout) {
- D2Bot.printToConsole("Mule didn't rejoin. Picking up items.", 9);
- Pickit.pickItems();
- break;
- }
- delay(500);
- }
- removeEventListener("copydata", DropStatusEvent);
- D2Bot.stop(muleObj.muleProfile);
- delay(1000);
- if (muleObj.stopProfile) {
- D2Bot.start(muleObj.stopProfile);
- }
- delay(2000);
- //OrganSystem.organHandler();
- //quit();
- //delay(10000);
- return true;
- };
- Doup.resupply = function () {
- print("Resupply start");
- var i, tick, unit,
- timeout = 180000;
- tick = getTickCount();
- while (true) {
- if (actions.length > 0) {
- switch (actions[0].cmd) {
- case "pick":
- for (i = 0; i < 3; i += 1) {
- Doup.pickStuff();
- }
- actions.shift();
- break;
- case "done":
- D2Bot.printToConsole("Resupply successful!", 5);
- actions.shift();
- return;
- }
- }
- if (getTickCount() - tick >= timeout) {
- throw new Error("Resupply failed.");
- }
- delay(100);
- }
- };
- Doup.callSupply = function () {
- if (!supplier.profile) {
- return false;
- }
- var master,
- rval = true,
- status = "",
- failCount = 0;
- function CopyDataEv(mode, msg) {
- var obj;
- if (mode === 10) {
- obj = JSON.parse(msg);
- if (obj) {
- status = obj.status;
- }
- }
- }
- addEventListener("copydata", CopyDataEv);
- D2Bot.printToConsole("Call down the flavor", 7);
- MainLoop:
- while (true) {
- // If nothing received our copy data start the mule profile
- if (!sendCopyData(null, supplier.profile, 10, JSON.stringify({profile: me.profile, accInfo: supplier.accountInfo}))) {
- D2Bot.start(supplier.profile);
- master = true;
- }
- delay(1000);
- switch (status) {
- case "busy":
- case "begin":
- if (master) {
- print("Supplier in game");
- break MainLoop;
- }
- D2Bot.printToConsole("Supplier is busy.", 9);
- // Can't do ingame stuff
- rval = false;
- break MainLoop;
- case "ready":
- // No need
- break MainLoop;
- default:
- failCount += 1;
- break;
- }
- if (failCount >= 60) {
- D2Bot.printToConsole("No response from supplier.", 9);
- break;
- }
- }
- removeEventListener("copydata", CopyDataEv);
- if (failCount >= 60) {
- D2Bot.stop(supplier.profile);
- delay(1000);
- // Don't do ingame stuff
- rval = false;
- }
- return rval;
- };
- Doup.openCube = function () {
- if (stashOpen && cubeOpen) {
- return true;
- }
- var i, tick, stash, cube;
- Town.move("stash");
- addEventListener("gamepacket", packetRecv);
- stash = getUnit(2, 267);
- if (!stash) {
- removeEventListener("gamepacket", packetRecv);
- return false;
- }
- StashLoop:
- for (i = 0; i < 10; i += 1) {
- sendPacket(1, 0x13, 4, stash.type, 4, stash.gid);
- tick = getTickCount();
- while (getTickCount() - tick < 1000 + me.ping * 2) {
- if (stashOpen) {
- break StashLoop;
- }
- delay(100);
- }
- if (!stashOpen) {
- print("force close");
- Doup.closeStash(true);
- }
- }
- if (!stashOpen) {
- removeEventListener("gamepacket", packetRecv);
- return false;
- }
- cube = me.getItem(549);
- if (!cube) {
- removeEventListener("gamepacket", packetRecv);
- return false;
- }
- CubeLoop:
- for (i = 0; i < 10; i += 1) {
- cube.interact();
- tick = getTickCount();
- while (getTickCount() - tick < 1000 + me.ping) {
- if (cubeOpen) {
- break CubeLoop;
- }
- delay(100);
- }
- if (!cubeOpen) {
- Doup.closeStash(true);
- }
- }
- if (!cubeOpen) {
- removeEventListener("gamepacket", packetRecv);
- return false;
- }
- removeEventListener("gamepacket", packetRecv);
- return true;
- };
- Doup.exitTown = function () {
- var i, exits;
- if (!exit.out) {
- exits = getArea().exits;
- if (!exits) {
- return Pather.moveToExit(41, true);
- }
- for (i = 0; i < exits.length; i += 1) {
- if (exits[i].target === 41) {
- switch (exits[i].x) {
- case 5094: // next to drog
- exit.out = {
- x: 5096,
- y: 4995
- };
- exit.town = {
- x: 5096,
- y: 5016
- };
- break;
- case 5000: // next to greiz
- exit.out = {
- x: 4995,
- y: 5066
- };
- exit.town = {
- x: 5015,
- y: 5066
- };
- break;
- default:
- throw new Error("Exit code sux, bro");
- }
- }
- }
- }
- while (getDistance(me, exit.out.x, exit.out.y) > 5) {
- Pather.moveTo(exit.out.x, exit.out.y);
- Packet.flash(me.gid);
- delay(500);
- }
- return true;
- };
- Doup.enterTown = function () {
- var target;
- if (!exit.town) {
- //Pather.moveToExit(40, false);
- target = Pather.getNearestRoom(40);
- if (target) {
- exit.town = {
- x: target[0],
- y: target[1]
- };
- } else { // backup
- return Pather.moveToExit(40, true);
- }
- }
- Pather.moveTo(exit.town.x, exit.town.y);
- while (getDistance(me, exit.town.x, exit.town.y) > 5) {
- Pather.moveTo(exit.town.x, exit.town.y);
- Packet.flash(me.gid);
- delay(500);
- }
- return true;
- };
Add Comment
Please, Sign In to add comment