kolton

Untitled

Jun 16th, 2026
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.70 KB | None | 0 0
  1. var roles, items, botched, mode, doubleDip, gameLength, useAutoMule, itemcount,
  2. actions = [],
  3. duper = "",
  4. trader = "",
  5. mule = "",
  6. supplier = {
  7. profile : ""
  8. },
  9. invItems = 0,
  10. stashOpen = false,
  11. cubeOpen = false,
  12. blocked = false,
  13. leaveGame = false,
  14. startTime = me.gamestarttime,
  15. exit = {
  16. town: false,
  17. out: false
  18. },
  19. rollCheck = {
  20. code: "",
  21. rolled: false
  22. },
  23. rolls = 0,
  24. rpm = 0,
  25. peakRPM = 0,
  26. rpd = 0,
  27. Doup = {};
  28.  
  29. // EXPERIMENTAL
  30. // used for rolling. must have items equpped on duper and trader's inv must be 100% full
  31. doubleDip = true;
  32. gameLength = 90; // minutes
  33.  
  34. Town.useTk = false;
  35.  
  36. function packetSend(packet) {
  37. if (packet[0] === 0x30) {
  38. blocked = true;
  39.  
  40. print("Packet send blocked");
  41.  
  42. return true;
  43. }
  44.  
  45. return false;
  46. }
  47.  
  48. function packetRecv(packet) {
  49. if (packet[0] === 0x77) {
  50. switch (packet[1]) {
  51. case 0x10: // open stash
  52. print("stash open/cube closed");
  53.  
  54. stashOpen = true;
  55.  
  56. return true;
  57. case 0x11: // cube
  58. return true;
  59. case 0x15: // cube
  60. print("cube open");
  61.  
  62. cubeOpen = true;
  63.  
  64. return true;
  65. }
  66. }
  67.  
  68. return false;
  69. }
  70.  
  71. function itemEvent(gid, mode, code, global) {
  72. if (mode === 4 && code === rollCheck.code) {
  73. rollCheck.rolled = true;
  74. }
  75. }
  76.  
  77. function keyEvent(key) {
  78. if (key === 35) { // END key
  79. showConsole();
  80. print("Wait until the current roll is done.");
  81.  
  82. leaveGame = true;
  83. }
  84. }
  85.  
  86. function gameEvent(mode, param1, param2, name1, name2) {
  87. switch (mode) {
  88. case 0x11:
  89. if (me.profile === duper) {
  90. D2Bot.printToConsole("SoJ sold", 9);
  91.  
  92. leaveGame = true;
  93. }
  94.  
  95. break;
  96. }
  97. }
  98.  
  99. function scriptMsgEvent(msg) {
  100. if (me.profile === duper && msg === "bad modem") {
  101. D2Bot.printToConsole("Bad Modem", 9);
  102.  
  103. leaveGame = true;
  104.  
  105. return;
  106. }
  107.  
  108. var i, obj;
  109.  
  110. try {
  111. obj = JSON.parse(msg);
  112.  
  113. if (obj && obj.master) {
  114. for (i in Doop.DupeTeams) {
  115. if (Doop.DupeTeams.hasOwnProperty(i) && obj.master === Doop.DupeTeams[i].duper) {
  116. print("Detected team: " + i);
  117.  
  118. duper = Doop.DupeTeams[i].duper;
  119. trader = Doop.DupeTeams[i].trader;
  120.  
  121. break;
  122. }
  123. }
  124. }
  125. } catch (err) {
  126. return;
  127. }
  128. }
  129.  
  130. function copyDataEvent(mode, msg) {
  131. var obj;
  132.  
  133. switch (mode) {
  134. case 22:
  135. obj = JSON.parse(msg);
  136.  
  137. if (obj) {
  138. switch (obj.message.type) {
  139. case "trade":
  140. actions.push({
  141. cmd: "trade",
  142. name: obj.message.name
  143. });
  144.  
  145. break;
  146. case "cancel":
  147. actions.push({
  148. cmd: "cancel"
  149. });
  150.  
  151. break;
  152. case "accept":
  153. actions.push({
  154. cmd: "accept"
  155. });
  156.  
  157. break;
  158. case "pick":
  159. actions.push({
  160. cmd: "pick"
  161. });
  162.  
  163. break;
  164. case "quit":
  165. actions.push({
  166. cmd: "quit"
  167. });
  168.  
  169. break;
  170. case "a1":
  171. actions.push({
  172. cmd: "a1"
  173. });
  174.  
  175. break;
  176. case "done":
  177. actions.push({
  178. cmd: "done"
  179. });
  180.  
  181. break;
  182. default:
  183. break;
  184. }
  185. }
  186.  
  187. break;
  188. case 50:
  189. obj = JSON.parse(msg);
  190.  
  191. if (obj.message === "ipcheck") {
  192. Messaging.sendToProfile(obj.sender, 50, me.ingame ? me.gameserverip : "nothing");
  193. }
  194.  
  195. break;
  196. }
  197. }
  198.  
  199. function Dupze() {
  200. include("doop.js");
  201. load("tools/badmodem.js");
  202.  
  203. var i, jer, wp, unit, tick;
  204.  
  205. roles = Doop.Info.getRoles();
  206.  
  207. if (roles) {
  208. duper = roles.duper;
  209. trader = roles.trader;
  210. mule = roles.mule;
  211. mode = roles.mode;
  212. supplier = roles.supplier;
  213. invItems = roles.invItems;
  214. useAutoMule = roles.useAutoMule;
  215. }
  216.  
  217. addEventListener("gameevent", gameEvent);
  218. addEventListener("copydata", copyDataEvent);
  219.  
  220. try {
  221. switch (me.profile.toLowerCase()) {
  222. case duper.toLowerCase():
  223. if (mode === "roll") {
  224. addEventListener("keyup", keyEvent);
  225. addEventListener("scriptmsg", scriptMsgEvent);
  226.  
  227. // Set all recipes to ilvl 0 to allow lld rolling
  228. for (i = 0; i < Cubing.recipes.length; i += 1) {
  229. Cubing.recipes[i].Level = 0;
  230. }
  231. }
  232.  
  233. tick = getTickCount();
  234.  
  235. while (Doup.getPlayerCount() < (mule ? 3 : 2)) {
  236. if (getTickCount() - tick >= 30000) {
  237. throw new Error("Player wait timed out");
  238. }
  239.  
  240. delay(500);
  241. }
  242.  
  243. items = me.findItems(-1, 0, 3);
  244.  
  245. if (!invItems || !supplier.profile) {
  246. if (!items || !items.length) {
  247. D2Bot.printToConsole("All ingredients lost. Stopping profile.", 9);
  248. D2Bot.stop(trader);
  249. D2Bot.stop(mule);
  250. D2Bot.stop();
  251.  
  252. return;
  253. }
  254. } else if (supplier.profile && (!items || items.length < invItems)) {
  255. D2Bot.printToConsole("Ingredients lost, trying to restock.", 9);
  256.  
  257. if (items.length > 0) {
  258. // Unlock slots
  259. Config.Inventory = [
  260. [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
  261. [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
  262. [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
  263. [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
  264. ];
  265.  
  266. Town.goToTown(2, true);
  267. Cubing.update();
  268. Doup.doCubing();
  269. // maybe add rws?
  270. Doup.dropInv();
  271. }
  272.  
  273. delay(1000);
  274. Town.goToTown(1, true);
  275. Town.move("stash");
  276. Messaging.sendToProfile(trader, 22, {type: "a1"});
  277.  
  278. while (!Doup.callSupply()) {
  279. delay(5000);
  280. }
  281.  
  282. Doup.resupply();
  283.  
  284. items = me.findItems(-1, 0, 3);
  285.  
  286. if (!items || items.length < invItems) {
  287. D2Bot.printToConsole("Failed to get enough items from supplier. Stopping profile.", 9);
  288. D2Bot.stop(trader);
  289. D2Bot.stop(mule);
  290. D2Bot.stop();
  291.  
  292. return;
  293. }
  294. }
  295.  
  296. // Jerry Setup
  297. if (mode === "roll") {
  298. if (me.act > 2) {
  299. Town.goToTown(1, true);
  300. }
  301.  
  302. if (me.act === 2) {
  303. Doup.entityAction("warriv");
  304.  
  305. for (i = 0; i < 5; i += 1) {
  306. delay(300 + me.ping);
  307.  
  308. if (me.area === 1) {
  309. break;
  310. }
  311. }
  312.  
  313. Town.goToTown(1, true);
  314. }
  315.  
  316. if (me.act === 1) {
  317. wp = getUnit(2, "waypoint");
  318.  
  319. if (wp) {
  320. Packet.teleWalk(wp.x, wp.y);
  321. delay(100 + me.ping);
  322. Packet.flash(me.gid);
  323. } else {
  324. Town.move("waypoint");
  325.  
  326. wp = getUnit(2, "waypoint");
  327.  
  328. if (!wp) {
  329. throw new Error("Waypoint not found");
  330. }
  331. }
  332.  
  333. Town.goToTown(2, true);
  334. }
  335.  
  336. Doup.exitTown();
  337. Doup.enterTown();
  338. Town.goToTown(1, true);
  339. Doup.entityAction("warriv");
  340.  
  341. for (i = 0; i < 5; i += 1) {
  342. delay(300 + me.ping);
  343.  
  344. if (me.area === 40) {
  345. break;
  346. }
  347. }
  348.  
  349. Town.goToTown(2, true);
  350. }
  351.  
  352. while (true) {
  353. if (getTickCount() - startTime >= gameLength * 6e4) {
  354. leaveGame = true;
  355. }
  356.  
  357. if (leaveGame) {
  358. print("Leaving game");
  359.  
  360. break;
  361. }
  362.  
  363. if (me.act > 2) {
  364. Town.goToTown(2, true);
  365. Town.move("warriv");
  366. }
  367.  
  368. if (me.act === 1) {
  369. Doup.entityAction("warriv");
  370.  
  371. for (i = 0; i < 5; i += 1) {
  372. delay(300 + me.ping);
  373.  
  374. if (me.area === 40) {
  375. break;
  376. }
  377. }
  378. }
  379.  
  380. Town.goToTown(2, true);
  381. Town.move("warriv");
  382.  
  383. jer = getUnit(1, "jerhyn");
  384.  
  385. if (mule === "" && !jer) {
  386. Messaging.sendToProfile(trader, 22, {type: "a1"});
  387. Town.goToTown(1, true);
  388. delay(2000);
  389. Town.goToTown(2, true);
  390. Town.move("warriv");
  391.  
  392. jer = getUnit(1, "jerhyn");
  393.  
  394. if (jer) {
  395. D2Bot.printToConsole("Jerry re-glitched.");
  396. }
  397. }
  398.  
  399. if (!jer || jer.x < 5118) {
  400. // If joined a RollMaker's game, it can't be botched because it's always new
  401. if (mule !== "") {
  402. botched = true;
  403. }
  404.  
  405. throw new Error("Jerhyn is in bad spot.");
  406. }
  407.  
  408. if (!jer || !jer.openMenu()) {
  409. throw new Error("Failed to open Jerhyn's menu");
  410. }
  411.  
  412. blocked = false;
  413.  
  414. addEventListener("gamepacketsent", packetSend);
  415. delay(me.ping + 1);
  416. me.cancel();
  417.  
  418. while (!blocked) {
  419. delay(100);
  420. }
  421.  
  422. removeEventListener("gamepacketsent", packetSend);
  423. Doup.entityAction("warriv");
  424.  
  425. for (i = 0; i < 5; i += 1) {
  426. delay(300 + me.ping);
  427.  
  428. if (me.area === 1) {
  429. break;
  430. }
  431. }
  432.  
  433. Town.goToTown(1, true);
  434.  
  435. wp = getUnit(2, "waypoint");
  436.  
  437. if (wp) {
  438. Packet.teleWalk(wp.x, wp.y);
  439. delay(100 + me.ping);
  440. Packet.flash(me.gid);
  441. } else {
  442. Town.move("waypoint");
  443.  
  444. wp = getUnit(2, "waypoint");
  445.  
  446. if (!wp) {
  447. throw new Error("Waypoint not found");
  448. }
  449. }
  450.  
  451. while (getDistance(me, wp) > 3) {
  452. Pather.moveToUnit(wp);
  453. Packet.flash(me.gid);
  454. delay(500);
  455. }
  456.  
  457. sendPacket(1, 0x49, 4, wp.gid, 4, 0);
  458. delay(500 + me.ping);
  459. Town.goToTown(2, true);
  460. Doup.startTrade(trader);
  461. getPacket(1, 0x77, 1, 0xC);
  462. delay(500 + me.ping);
  463. Doup.exitTown();
  464. Doup.enterTown();
  465.  
  466. if (mode === "dupe") {
  467. Town.goToTown(1, true);
  468. Town.move("stash");
  469. Doup.dropInv();
  470. Messaging.sendToProfile(mule, 22, {type: "pick"});
  471. Messaging.sendToProfile(trader, 22, {type: "cancel"});
  472. delay(500);
  473. Doup.startTrade(mule);
  474. sendPacket(1, 0x4f, 2, 0x2, 4, 0);
  475. Messaging.sendToProfile(mule, 22, {type: "quit"});
  476. Town.goToTown(2, true);
  477.  
  478. break;
  479. } else if (mode === "roll") {
  480. // Unlock slots
  481. Config.Inventory = [
  482. [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
  483. [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
  484. [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
  485. [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
  486. ];
  487.  
  488. if (leaveGame) {
  489. break;
  490. }
  491.  
  492. //Cubing.init();
  493. Cubing.update();
  494. Runewords.init();
  495. Doup.doCubing();
  496. Doup.makeRunewords();
  497.  
  498. if (doubleDip) {
  499. itemcount = me.itemcount;
  500. tick = getTickCount();
  501.  
  502. Messaging.sendToProfile(trader, 22, {type: "accept"});
  503.  
  504. while (me.itemcount === itemcount) {
  505. if (getTickCount() - tick >= 10000) {
  506. throw new Error("Roll failed 1");
  507. }
  508.  
  509. delay(100);
  510. }
  511.  
  512. Doup.closeStash();
  513. Cubing.update();
  514. Runewords.init();
  515. Doup.doCubing();
  516. Doup.makeRunewords();
  517. }
  518.  
  519. if (leaveGame) {
  520. break;
  521. }
  522.  
  523. itemcount = me.itemcount;
  524. tick = getTickCount();
  525.  
  526. Messaging.sendToProfile(trader, 22, {type: "cancel"});
  527.  
  528. while (me.itemcount === itemcount) {
  529. if (getTickCount() - tick >= 10000) {
  530. throw new Error("Roll failed 2");
  531. }
  532.  
  533. delay(100);
  534. }
  535.  
  536. Doup.closeStash();
  537. Town.goToTown(1, true);
  538. }
  539. }
  540.  
  541. break;
  542. case mule.toLowerCase():
  543. // In case full mule joined somehow
  544. if (mode === "dupe" && me.itemcount > 8) {
  545. delay(1000);
  546. scriptBroadcast("quit");
  547.  
  548. return;
  549. }
  550.  
  551. if (mode === "dupe") {
  552. Doup.dropInv();
  553. }
  554.  
  555. while (true) {
  556. if (actions.length > 0) {
  557. switch (actions[0].cmd) {
  558. case "pick":
  559. print("Pick items");
  560.  
  561. for (i = 0; i < 3; i += 1) {
  562. Doup.pickStuff();
  563. }
  564.  
  565. delay(1000);
  566.  
  567. if (mode === "roll") {
  568. Doup.stashItems();
  569. }
  570.  
  571. Doop.Info.update("char");
  572. actions.shift();
  573.  
  574. break;
  575. case "trade":
  576. me.cancel();
  577.  
  578. unit = getUnit(0, actions[0].name);
  579.  
  580. if (unit) {
  581. MainLoop:
  582. for (i = 0; i < 10; i += 1) {
  583. if (getDistance(me, unit) > 5) {
  584. Pather.moveToUnit(unit);
  585. }
  586.  
  587. unit.interact();
  588.  
  589. tick = getTickCount();
  590.  
  591. while (getTickCount() - tick < 1000) {
  592. if (getUIFlag(0x17)) {
  593. actions.shift();
  594.  
  595. break MainLoop;
  596. }
  597.  
  598. delay(50);
  599. }
  600. }
  601. }
  602.  
  603. break;
  604. case "quit":
  605. delay(500);
  606. scriptBroadcast("quit");
  607. actions.shift();
  608.  
  609. break;
  610. }
  611. }
  612.  
  613. delay(100);
  614. }
  615.  
  616. break;
  617. case trader.toLowerCase():
  618. if (me.act === 2) {
  619. Doup.entityAction("warriv");
  620.  
  621. for (i = 0; i < 5; i += 1) {
  622. delay(300 + me.ping);
  623.  
  624. if (me.area === 1) {
  625. break;
  626. }
  627. }
  628. }
  629.  
  630. Town.goToTown(1, true);
  631. Town.move("waypoint");
  632.  
  633. while (true) {
  634. if (actions.length > 0) {
  635. switch (actions[0].cmd) {
  636. case "trade":
  637. Town.goToTown(2, true);
  638.  
  639. unit = getUnit(0, actions[0].name);
  640.  
  641. if (unit) {
  642. MainLoop2:
  643. for (i = 0; i < 10; i += 1) {
  644. Packet.flash();
  645. delay(250);
  646.  
  647. if (getDistance(me, unit) > 5) {
  648. Pather.moveToUnit(unit);
  649. }
  650.  
  651. unit.interact();
  652.  
  653. tick = getTickCount();
  654.  
  655. while (getTickCount() - tick < 1000) {
  656. if (getUIFlag(0x17)) {
  657. break MainLoop2;
  658. }
  659.  
  660. delay(50);
  661. }
  662. }
  663. }
  664.  
  665. actions.shift();
  666.  
  667. break;
  668. case "cancel":
  669. sendPacket(1, 0x4f, 2, 0x2, 4, 0);
  670. actions.shift();
  671.  
  672. break;
  673. case "accept":
  674. //acceptTrade();
  675. sendPacket(1, 0x4f, 2, 0x4, 4, 0);
  676. actions.shift();
  677.  
  678. break;
  679. case "a1":
  680. me.cancel();
  681. Town.goToTown(1, true);
  682. actions.shift();
  683.  
  684. break;
  685. case "quit":
  686. delay(2000);
  687. scriptBroadcast("quit");
  688. actions.shift();
  689.  
  690. break;
  691. }
  692. } else {
  693. tick = getTickCount();
  694.  
  695. while (Doup.getPlayerCount() < 2) {
  696. if (getTickCount() - tick >= 10000) {
  697. D2Bot.printToConsole("Alone in game");
  698. scriptBroadcast("quit");
  699.  
  700. return;
  701. }
  702.  
  703. delay(500);
  704. }
  705. }
  706.  
  707. delay(200);
  708. }
  709.  
  710. break;
  711. case supplier.profile.toLowerCase():
  712. // We need to find the current team, reset and get proper data for trader and duper
  713. trader = false;
  714. duper = false;
  715.  
  716. addEventListener("scriptmsg", scriptMsgEvent);
  717.  
  718. for (i = 0; i < 3; i += 1) {
  719. scriptBroadcast("getMaster");
  720. delay(500);
  721.  
  722. if (trader && duper) {
  723. break;
  724. }
  725. }
  726.  
  727. removeEventListener("scriptmsg", scriptMsgEvent);
  728.  
  729. tick = getTickCount();
  730.  
  731. while (Doup.getPlayerCount() < 3) {
  732. if (getTickCount() - tick >= 30000) {
  733. throw new Error("Player wait timed out");
  734. }
  735.  
  736. delay(500);
  737. }
  738.  
  739. if (me.act > 2) {
  740. Town.goToTown(2, true);
  741. Town.move("warriv");
  742. }
  743.  
  744. if (me.act === 1) {
  745. Doup.entityAction("warriv");
  746.  
  747. for (i = 0; i < 5; i += 1) {
  748. delay(300 + me.ping);
  749.  
  750. if (me.area === 40) {
  751. break;
  752. }
  753. }
  754. }
  755.  
  756. Town.goToTown(2, true);
  757. Town.move("warriv");
  758.  
  759. jer = getUnit(1, "jerhyn");
  760.  
  761. if (!jer || jer.x < 5118) {
  762. throw new Error("Jerhyn is in bad spot.");
  763. }
  764.  
  765. if (!jer || !jer.openMenu()) {
  766. throw new Error("Failed to open Jerhyn's menu");
  767. }
  768.  
  769. blocked = false;
  770.  
  771. addEventListener("gamepacketsent", packetSend);
  772. delay(me.ping + 1);
  773. me.cancel();
  774.  
  775. while (!blocked) {
  776. delay(100);
  777. }
  778.  
  779. removeEventListener("gamepacketsent", packetSend);
  780. Doup.entityAction("warriv");
  781.  
  782. for (i = 0; i < 5; i += 1) {
  783. delay(300 + me.ping);
  784.  
  785. if (me.area === 1) {
  786. break;
  787. }
  788. }
  789.  
  790. Town.goToTown(1, true);
  791.  
  792. wp = getUnit(2, "waypoint");
  793.  
  794. if (wp) {
  795. Packet.teleWalk(wp.x, wp.y);
  796. delay(100 + me.ping);
  797. Packet.flash(me.gid);
  798. } else {
  799. Town.move("waypoint");
  800.  
  801. wp = getUnit(2, "waypoint");
  802.  
  803. if (!wp) {
  804. throw new Error("Waypoint not found");
  805. }
  806. }
  807.  
  808. while (getDistance(me, wp) > 4) {
  809. Pather.moveToUnit(wp);
  810. Packet.flash(me.gid);
  811. delay(500);
  812. }
  813.  
  814. sendPacket(1, 0x49, 4, wp.gid, 4, 0);
  815. delay(250 + me.ping);
  816. Town.goToTown(2, true);
  817. Doup.startTrade(trader);
  818. getPacket(1, 0x77, 1, 0xC);
  819. delay(500 + me.ping);
  820. Doup.exitTown();
  821. Doup.enterTown();
  822. Town.goToTown(1, true);
  823. Town.move("stash");
  824. Doup.dropInv();
  825. Messaging.sendToProfile(duper, 22, {type: "pick"});
  826. Messaging.sendToProfile(trader, 22, {type: "cancel"});
  827. delay(500);
  828. Town.goToTown(2, true);
  829. Doup.startTrade(trader);
  830. sendPacket(1, 0x4f, 2, 0x2, 4, 0);
  831. delay(500 + me.ping);
  832. Messaging.sendToProfile(duper, 22, {type: "done"});
  833. D2Bot.printToConsole("Restock successful.");
  834. D2Bot.stop();
  835.  
  836. return;
  837. default:
  838. tick = getTickCount();
  839.  
  840. while (Doup.getPlayerCount() < 3) {
  841. if (getTickCount() - tick >= 60000) {
  842. throw new Error("Player wait timed out");
  843. }
  844.  
  845. delay(500);
  846. }
  847.  
  848. delay(2500);
  849. scriptBroadcast("quit");
  850.  
  851. break;
  852. }
  853. } catch (err) {
  854. Misc.errorReport(err, "Dupze");
  855.  
  856. if (err.message === "Trade with " + trader + " failed.") {
  857. botched = true;
  858. }
  859. } finally {
  860. if (me.profile !== duper) {
  861. return;
  862. }
  863.  
  864. if (me.profile === supplier.profile) {
  865. D2Bot.printToConsole("Restock failed.", 9);
  866. D2Bot.stop();
  867.  
  868. return;
  869. }
  870.  
  871. Messaging.sendToProfile(trader, 22, {type: "cancel"});
  872. delay(500);
  873. me.cancel();
  874. Town.goToTown(2, true);
  875. Town.move("waypoint");
  876.  
  877. if (botched) { // won't be able to start trade with trader
  878. delay(500);
  879. Town.goToTown(1, true);
  880. Town.move("stash");
  881. Doup.startTrade(mule);
  882. sendPacket(1, 0x4f, 2, 0x2, 4, 0);
  883. } else {
  884. try {
  885. Doup.startTrade(trader);
  886. sendPacket(1, 0x4f, 2, 0x2, 4, 0);
  887. } catch (e) {
  888. delay(500);
  889. Town.goToTown(1, true);
  890. Town.move("stash");
  891. Doup.startTrade(mule);
  892. sendPacket(1, 0x4f, 2, 0x2, 4, 0);
  893. }
  894. }
  895.  
  896. Messaging.sendToProfile(trader, 22, {type: "quit"});
  897.  
  898. if (botched || mode === "roll") {
  899. Messaging.sendToProfile(mule, 22, {type: "quit"});
  900. }
  901.  
  902. delay(500 + me.ping);
  903. scriptBroadcast("quit");
  904. }
  905. }
  906.  
  907. Doup.dropInv = function () {
  908. var items = me.findItems(-1, 0, 3);
  909.  
  910. while (items && items.length) {
  911. Packet.dropItem(items.shift());
  912. }
  913. };
  914.  
  915. Doup.pickStuff = function () {
  916. var item, list;
  917.  
  918. item = getUnit(4, -1, 3); // item, on ground
  919. list = [];
  920.  
  921. if (item) {
  922. do {
  923. if (Town.ignoredItemTypes.indexOf(item.itemType) === -1) { // don't pick up trash
  924. list.push(copyUnit(item));
  925. }
  926. } while (item.getNext());
  927. }
  928.  
  929. while (list.length > 0) {
  930. list.sort(Sort.units);
  931.  
  932. item = list.shift();
  933.  
  934. if (Storage.Inventory.CanFit(item)) {
  935. Pickit.pickItem(item);
  936.  
  937. if (item.mode === 1) { // item equipped
  938. Storage.Inventory.MoveTo(item);
  939. }
  940. }
  941. }
  942. };
  943.  
  944. Doup.stashItems = function () {
  945. var i,
  946. items = me.findItems(-1, 0, 3);
  947.  
  948. if (items) {
  949. for (i = 0; i < items.length; i += 1) {
  950. if (Storage.Stash.CanFit(items[i])) {
  951. Storage.Stash.MoveTo(items[i]);
  952. }
  953. }
  954. }
  955. };
  956.  
  957. Doup.closeStash = function (force) {
  958. while (getUIFlag(0x1A)) {
  959. me.cancel();
  960. delay(300 + me.ping);
  961. }
  962.  
  963. while (getUIFlag(0x19)) {
  964. me.cancel();
  965. delay(300 + me.ping);
  966. }
  967.  
  968. if (force || (stashOpen && cubeOpen)) {
  969. sendPacket(1, 0x4f, 2, 0x17, 4, 0);
  970. delay(100 + me.ping * 2);
  971. sendPacket(1, 0x4f, 2, 0x12, 4, 0);
  972. delay(100 + me.ping * 2);
  973.  
  974. stashOpen = false;
  975. cubeOpen = false;
  976. }
  977. };
  978.  
  979. Doup.startTrade = function (profile) {
  980. var i, item, items, tick;
  981.  
  982. if (!profile) {
  983. return;
  984. }
  985.  
  986. Messaging.sendToProfile(profile, 22, {type: "trade", name: me.name});
  987.  
  988. tick = getTickCount();
  989.  
  990. while (getTickCount() - tick < 60000) {
  991. if (getUIFlag(0x17)) {
  992. break;
  993. }
  994.  
  995. delay(100);
  996. }
  997.  
  998. if (getTickCount() - tick >= 60000) {
  999. throw new Error("Trade with " + profile + " failed.");
  1000. }
  1001.  
  1002. delay(1000);
  1003.  
  1004. TradeLoop:
  1005. for (i = 0; i < 10; i += 1) {
  1006. tradeOk();
  1007.  
  1008. tick = getTickCount();
  1009.  
  1010. while (getTickCount() - tick < 1000 + me.ping) {
  1011. if (acceptTrade(2) === 3) {
  1012. delay(300 + me.ping);
  1013.  
  1014. break TradeLoop;
  1015. }
  1016.  
  1017. delay(100);
  1018. }
  1019. }
  1020.  
  1021. if (i === 10) {
  1022. throw new Error("Trade with " + profile + " failed.");
  1023. }
  1024.  
  1025. if (profile === trader && me.profile === duper && mode === "roll" && doubleDip) {
  1026. items = me.findItems(-1, 0, 5); // Items already stuck in trade
  1027.  
  1028. if (!items || items.length === 0) {
  1029. item = me.getItem(-1, 1); // equipped item
  1030.  
  1031. if (item) {
  1032. do {
  1033. if ([8, 11, 12].indexOf(item.bodylocation) < 0) {
  1034. if (!Storage.TradeScreen.MoveTo(item)) {
  1035. throw new Error("Trade with " + profile + " failed.");
  1036. }
  1037.  
  1038. delay(300 + me.ping);
  1039.  
  1040. break;
  1041. }
  1042. } while (item.getNext());
  1043. }
  1044. }
  1045.  
  1046. AcceptLoop:
  1047. for (i = 0; i < 10; i += 1) {
  1048. acceptTrade();
  1049.  
  1050. tick = getTickCount();
  1051.  
  1052. while (getTickCount() - tick < 1000 + me.ping * 2) {
  1053. if (acceptTrade(1)) {
  1054. delay(300 + me.ping);
  1055.  
  1056. break AcceptLoop;
  1057. }
  1058.  
  1059. delay(100);
  1060. }
  1061. }
  1062.  
  1063. if (i === 10) {
  1064. throw new Error("Trade with " + profile + " failed.");
  1065. }
  1066. }
  1067. };
  1068.  
  1069. Doup.getPlayerCount = function () {
  1070. var count = 0,
  1071. party = getParty();
  1072.  
  1073. if (party) {
  1074. do {
  1075. count += 1;
  1076. } while (party.getNext());
  1077. }
  1078.  
  1079. return count;
  1080. };
  1081.  
  1082. Doup.doCubing = function () {
  1083. if (!Config.Cubing) {
  1084. return false;
  1085. }
  1086.  
  1087. if (!me.getItem(549)) {
  1088. return false;
  1089. }
  1090.  
  1091. var i, n, item, items, result, cubeItems, tick, oldGid, oldClassid;
  1092.  
  1093. for (i = 0; i < Cubing.recipes.length; i += 1) {
  1094. if (leaveGame) {
  1095. return false;
  1096. }
  1097.  
  1098. items = Cubing.checkRecipe(Cubing.recipes[i]);
  1099.  
  1100. if (items) {
  1101. if (!Doup.openCube()) {
  1102. return false;
  1103. }
  1104.  
  1105. Cubing.cursorCheck();
  1106.  
  1107. cubeItems = me.findItems(-1, 0, 6);
  1108.  
  1109. if (cubeItems && ((cubeItems.length === 1 && cubeItems[0].gid !== items[0].gid) || cubeItems.length > 1)) {
  1110. print("Empty cuz items already in or base item is bad.");
  1111. Cubing.emptyCube();
  1112. }
  1113.  
  1114. oldClassid = items[0].classid;
  1115. oldGid = items[0].gid;
  1116. i = -1;
  1117.  
  1118. while (items.length) {
  1119. if (items[0].location !== 6) {
  1120. Storage.Cube.MoveTo(items[0]);
  1121. }
  1122.  
  1123. items.shift();
  1124. }
  1125.  
  1126. itemcount = me.itemcount;
  1127.  
  1128. Dique:
  1129. for (n = 0; n < 10; n += 1) {
  1130. //transmute();
  1131. sendPacket(1, 0x4f, 2, 0x18, 4, 0);
  1132.  
  1133. tick = getTickCount();
  1134.  
  1135. while (getTickCount() - tick < 1000 + me.ping * 2) {
  1136. if (me.itemcount < itemcount) {
  1137. item = me.findItem(oldClassid, 0, 6);
  1138.  
  1139. if (item && item.gid !== oldGid) {
  1140. break Dique;
  1141. }
  1142. }
  1143.  
  1144. delay(100);
  1145. }
  1146. }
  1147.  
  1148. rolls += 1;
  1149. rpm = rolls / ((getTickCount() - me.gamestarttime) / 6e4);
  1150. rpd = rpm * 60 * 24;
  1151.  
  1152. if (rpm > peakRPM) {
  1153. peakRPM = rpm;
  1154. }
  1155.  
  1156. //removeEventListener("itemaction", itemEvent);
  1157. print("[Roll: " + rolls + "] [Average RPM: " + rpm.toFixed(2) + "] [Peak RPM: " + peakRPM.toFixed(2) + "] [Est. RPD: " + rpd.toFixed(2) + "]");
  1158. Cubing.update();
  1159.  
  1160. items = me.findItems(-1, 0, 6);
  1161.  
  1162. if (items.length > 1) {
  1163. print("Empty cuz more than 1 item are in the cube after transmute.");
  1164. Cubing.emptyCube();
  1165.  
  1166. return false;
  1167. }
  1168.  
  1169. item = me.findItem(-1, 0, 6);
  1170.  
  1171. if (item) {
  1172. result = Pickit.checkItem(item);
  1173.  
  1174. switch (result.result) {
  1175. case 0:
  1176. print("Empty cuz pickit result is 0.");
  1177. Cubing.emptyCube();
  1178.  
  1179. break;
  1180. case 1:
  1181. //Misc.itemLogger("Cubing Kept", item);
  1182. beep();
  1183. D2Bot.printToConsole("Kept something! It only took " + rolls + " rolls!");
  1184.  
  1185. rolls = 0;
  1186.  
  1187. Misc.logItem("Cubing Kept", item, result.line);
  1188. Doup.closeStash();
  1189. Town.goToTown(1, true);
  1190. //Town.openStash();
  1191. Doup.openCube();
  1192.  
  1193. if (useAutoMule) {
  1194. while (true) {
  1195. if (Doup.callMule()) {
  1196. break;
  1197. } else {
  1198. delay(5000);
  1199. }
  1200.  
  1201. delay(5000);
  1202. }
  1203.  
  1204. item.drop();
  1205. Doup.finishMule();
  1206. } else {
  1207. item.drop();
  1208. }
  1209.  
  1210. Doup.closeStash();
  1211. delay(500 + me.ping);
  1212. Messaging.sendToProfile(mule, 22, {type: "pick"});
  1213. Doup.entityAction("warriv");
  1214.  
  1215. for (i = 0; i < 5; i += 1) {
  1216. delay(300 + me.ping);
  1217.  
  1218. if (me.area === 40) {
  1219. break;
  1220. }
  1221. }
  1222.  
  1223. Town.goToTown(2, true);
  1224.  
  1225. return true;
  1226. }
  1227. }
  1228. }
  1229. }
  1230.  
  1231. return true;
  1232. };
  1233.  
  1234. Doup.makeRunewords = function () {
  1235. if (!Config.MakeRunewords) {
  1236. return false;
  1237. }
  1238.  
  1239. var i, items;
  1240.  
  1241. while (true) {
  1242. Runewords.buildLists();
  1243.  
  1244. items = Runewords.checkRunewords(); // get a runeword. format = [base, runes...]
  1245.  
  1246. if (!items) { // can't make runewords - exit loop
  1247. print("No rw ingredients found.");
  1248.  
  1249. break;
  1250. }
  1251.  
  1252. if (!getUIFlag(0x1A) && !getUIFlag(0x19)) {
  1253. if (!Town.openStash()) {
  1254. print("Couldn't open stash.");
  1255.  
  1256. return false;
  1257. }
  1258. }
  1259.  
  1260. for (i = 1; i < items.length; i += 1) {
  1261. Runewords.socketItem(items[0], items[i]);
  1262. }
  1263.  
  1264. print("ÿc4Runewords: ÿc0Made runeword: " + items[0].fname.split("\n").reverse().join(" ").replace(/ÿc[0-9!"+<;.*]/, ""));
  1265. //D2Bot.printToConsole("Made runeword: " + items[0].fname.split("\n").reverse().join(" ").replace(/ÿc[0-9!"+<;.*]/, ""), 5);
  1266.  
  1267. if (NTIP.CheckItem(items[0], Runewords.pickitEntries)) {
  1268. //Misc.itemLogger("Runeword Kept", items[0]);
  1269. D2Bot.printToConsole("Kept something!");
  1270. Misc.logItem("Runeword Kept", items[0]);
  1271. me.cancel();
  1272. Town.goToTown(1, true);
  1273. Town.openStash();
  1274.  
  1275. if (useAutoMule) {
  1276. while (true) {
  1277. if (Doup.callMule()) {
  1278. break;
  1279. }
  1280.  
  1281. delay(5000);
  1282. }
  1283.  
  1284. items[0].drop();
  1285. Doup.finishMule();
  1286. } else {
  1287. items[0].drop();
  1288. }
  1289.  
  1290. me.cancel();
  1291. delay(500 + me.ping);
  1292. Messaging.sendToProfile(mule, 22, {type: "pick"});
  1293. //Town.goToTown(2, true);
  1294.  
  1295. Doup.entityAction("warriv");
  1296.  
  1297. for (i = 0; i < 5; i += 1) {
  1298. delay(300 + me.ping);
  1299.  
  1300. if (me.area === 40) {
  1301. break;
  1302. }
  1303. }
  1304.  
  1305. return true;
  1306. }
  1307.  
  1308. Doup.rerollRunewords();
  1309. }
  1310.  
  1311. return true;
  1312. };
  1313.  
  1314. Doup.rerollRunewords = function () {
  1315. var i, base, scroll, hel;
  1316.  
  1317. for (i = 0; i < Config.Runewords.length; i += 1) {
  1318. hel = me.getItem(624, 0);
  1319.  
  1320. if (!hel) {
  1321. return false;
  1322. }
  1323.  
  1324. base = Runewords.getBase(Config.Runewords[i][0], Config.Runewords[i][1], true); // get a bad runeword
  1325.  
  1326. if (!base) {
  1327. print("base not found");
  1328. }
  1329.  
  1330. if (base) {
  1331. scroll = Runewords.getScroll();
  1332.  
  1333. // failed to get scroll or open stash most likely means we're stuck somewhere in town, so it's better to return false
  1334. if (!scroll) {
  1335. print("scroll not found");
  1336.  
  1337. return false;
  1338. }
  1339.  
  1340. if (!getUIFlag(0x1A) && !getUIFlag(0x19)) {
  1341. if (!Town.openStash()) {
  1342. print("Couldn't open stash 2.");
  1343.  
  1344. return false;
  1345. }
  1346. }
  1347.  
  1348. if (base.location !== 6) {
  1349. Storage.Cube.MoveTo(base);
  1350. }
  1351.  
  1352. Storage.Cube.MoveTo(hel);
  1353. Storage.Cube.MoveTo(scroll);
  1354.  
  1355. transmute();
  1356. delay(500);
  1357. }
  1358. }
  1359.  
  1360. Runewords.buildLists();
  1361.  
  1362. return true;
  1363. };
  1364.  
  1365. Runewords.getBase = function (runeword, base, reroll) {
  1366. var item;
  1367.  
  1368. if (typeof base === "object") {
  1369. item = base;
  1370. } else {
  1371. item = me.getItem(base);
  1372. }
  1373.  
  1374. if (item) {
  1375. do {
  1376. if (item && item.quality < 4 && item.getStat(194) === runeword.length) {
  1377. /* check if item has items socketed in it
  1378. better check than getFlag(0x4000000) because randomly socketed items return false for it
  1379. */
  1380.  
  1381. if (reroll && item.getItem() && !NTIP.CheckItem(item, Runewords.pickitEntries)) {
  1382. return copyUnit(item);
  1383. }
  1384.  
  1385. if (!reroll && !item.getItem()) {
  1386. return copyUnit(item);
  1387. }
  1388. }
  1389. } while (typeof base !== "object" && item.getNext());
  1390. }
  1391.  
  1392. return false;
  1393. };
  1394.  
  1395. if (!Packet.hasOwnProperty("dropItem")) {
  1396. Packet.itemToCursor = function (item) {
  1397. var i, tick;
  1398.  
  1399. for (i = 0; i < 15; i += 1) {
  1400. if (item.mode === 1) { // equipped
  1401. sendPacket(1, 0x1c, 2, item.bodylocation);
  1402. } else {
  1403. sendPacket(1, 0x19, 4, item.gid);
  1404. }
  1405.  
  1406. tick = getTickCount();
  1407.  
  1408. while (getTickCount() - tick < Math.max(500, me.ping * 2 + 200)) {
  1409. if (me.itemoncursor) {
  1410. return true;
  1411. }
  1412.  
  1413. delay(10);
  1414. }
  1415. }
  1416.  
  1417. return false;
  1418. };
  1419.  
  1420. Packet.dropItem = function (item) {
  1421. var i, tick;
  1422.  
  1423. if (me.itemoncursor) {
  1424. sendPacket(1, 0x17, 4, getUnit(100).gid);
  1425. }
  1426.  
  1427. if (!Packet.itemToCursor(item)) {
  1428. return false;
  1429. }
  1430.  
  1431. for (i = 0; i < 15; i += 1) {
  1432. sendPacket(1, 0x17, 4, item.gid);
  1433.  
  1434. tick = getTickCount();
  1435.  
  1436. while (getTickCount() - tick < Math.max(500, me.ping * 2 + 200)) {
  1437. if (!me.itemoncursor) {
  1438. return true;
  1439. }
  1440.  
  1441. delay(10);
  1442. }
  1443. }
  1444.  
  1445. return false;
  1446. };
  1447. }
  1448.  
  1449. Doup.entityAction = function (id) {
  1450. if (id === undefined) {
  1451. return false;
  1452. }
  1453.  
  1454. var unit;
  1455.  
  1456. unit = getUnit(1, id);
  1457.  
  1458. if (!unit) {
  1459. switch (id) {
  1460. case "warriv":
  1461. case "meshif":
  1462. Town.move(id);
  1463.  
  1464. unit = getUnit(1, id);
  1465.  
  1466. break;
  1467. }
  1468. }
  1469.  
  1470. if (!unit) {
  1471. return false;
  1472. }
  1473.  
  1474. // 38 13 Entity action 38 [DWORD action] [DWORD entity id] [DWORD complement]
  1475. delay(100 + me.ping);
  1476. sendPacket(1, 0x38, 4, 0, 4, unit.gid, 4, 0);
  1477.  
  1478. return true;
  1479. };
  1480.  
  1481. Storage.Cube.MoveTo = function (item) {
  1482. var i, spot, tick;
  1483.  
  1484. if (!cubeOpen) {
  1485. return false;
  1486. }
  1487.  
  1488. if (Packet.itemToCursor(item)) {
  1489. //delay(me.ping / 2 + 1);
  1490.  
  1491. for (i = 0; i < 15; i += 1) {
  1492. spot = Storage.Cube.FindSpot(item); // returns inverted coords...
  1493.  
  1494. if (spot) {
  1495. // 18 [DWORD id] [DWORD xpos] [DWORD ypos] [DWORD buffer]
  1496. sendPacket(1, 0x18, 4, item.gid, 4, spot.y, 4, spot.x, 4, 0x3);
  1497. }
  1498.  
  1499. tick = getTickCount();
  1500.  
  1501. while (getTickCount() - tick < Math.max(1000, me.ping * 2 + 200)) {
  1502. if (!me.itemoncursor) {
  1503. return true;
  1504. }
  1505.  
  1506. delay(10);
  1507. }
  1508. }
  1509. }
  1510.  
  1511. return false;
  1512. };
  1513.  
  1514. Storage.Inventory.MoveTo = function (item) {
  1515. var i, spot, tick;
  1516.  
  1517. if (Packet.itemToCursor(item)) {
  1518. //delay(me.ping / 2 + 1);
  1519.  
  1520. for (i = 0; i < 15; i += 1) {
  1521. spot = Storage.Inventory.FindSpot(item); // returns inverted coords...
  1522.  
  1523. if (spot) {
  1524. // 18 [DWORD id] [DWORD xpos] [DWORD ypos] [DWORD buffer]
  1525. sendPacket(1, 0x18, 4, item.gid, 4, spot.y, 4, spot.x, 4, 0);
  1526. }
  1527.  
  1528. tick = getTickCount();
  1529.  
  1530. while (getTickCount() - tick < Math.max(1000, me.ping * 2 + 200)) {
  1531. if (!me.itemoncursor) {
  1532. return true;
  1533. }
  1534.  
  1535. delay(10);
  1536. }
  1537. }
  1538. }
  1539.  
  1540. return false;
  1541. };
  1542.  
  1543. Storage.TradeScreen.MoveTo = function (item) {
  1544. var i, spot, tick;
  1545.  
  1546. if (Packet.itemToCursor(item)) {
  1547. //delay(me.ping / 2 + 1);
  1548.  
  1549. for (i = 0; i < 15; i += 1) {
  1550. spot = Storage.TradeScreen.FindSpot(item); // returns inverted coords...
  1551.  
  1552. if (spot) {
  1553. // 18 [DWORD id] [DWORD xpos] [DWORD ypos] [DWORD buffer]
  1554. sendPacket(1, 0x18, 4, item.gid, 4, spot.y, 4, spot.x, 4, 0x2);
  1555. }
  1556.  
  1557. tick = getTickCount();
  1558.  
  1559. while (getTickCount() - tick < Math.max(1000, me.ping * 2 + 200)) {
  1560. if (!me.itemoncursor) {
  1561. return true;
  1562. }
  1563.  
  1564. delay(10);
  1565. }
  1566. }
  1567. }
  1568.  
  1569. return false;
  1570. };
  1571.  
  1572. Doup.callMule = function () {
  1573. var muleObj,
  1574. rval = true,
  1575. stopCheck = false,
  1576. muleInfo = {status: ""},
  1577. failCount = 0;
  1578.  
  1579. AutoMule.check = true;
  1580.  
  1581. muleObj = AutoMule.getMule();
  1582.  
  1583. if (!muleObj) {
  1584. print("you fail");
  1585.  
  1586. return false;
  1587. }
  1588.  
  1589. function MuleCheckEvent(mode, msg) {
  1590. if (mode === 10) {
  1591. muleInfo = JSON.parse(msg);
  1592. }
  1593. }
  1594.  
  1595. addEventListener("copydata", MuleCheckEvent);
  1596. D2Bot.printToConsole("Starting" + (AutoMule.torchCheck ? " torch " : " ") + "mule profile: " + muleObj.muleProfile, 7);
  1597.  
  1598. MainLoop:
  1599. while (true) {
  1600. // If nothing received our copy data start the mule profile
  1601. if (!sendCopyData(null, muleObj.muleProfile, 10, JSON.stringify({profile: me.profile, mode: AutoMule.torchCheck ? 1 : 0}))) {
  1602. D2Bot.start(muleObj.muleProfile);
  1603. }
  1604.  
  1605. delay(1000);
  1606.  
  1607. switch (muleInfo.status) {
  1608. case "loading":
  1609. if (!stopCheck && muleObj.stopProfile && me.profile.toLowerCase() !== muleObj.stopProfile.toLowerCase()) {
  1610. D2Bot.stop(muleObj.stopProfile);
  1611.  
  1612. stopCheck = true;
  1613. }
  1614.  
  1615. failCount += 1;
  1616.  
  1617. break;
  1618. case "busy":
  1619. case "begin":
  1620. D2Bot.printToConsole("Mule profile is busy.", 9);
  1621.  
  1622. // Can't do ingame stuff
  1623. rval = false;
  1624.  
  1625. break MainLoop;
  1626. case "ready":
  1627. // No need
  1628. break MainLoop;
  1629. default:
  1630. failCount += 1;
  1631.  
  1632. break;
  1633. }
  1634.  
  1635. if (failCount >= 60) {
  1636. D2Bot.printToConsole("No response from mule profile.", 9);
  1637.  
  1638. break;
  1639. }
  1640. }
  1641.  
  1642. removeEventListener("copydata", MuleCheckEvent);
  1643.  
  1644. AutoMule.inGame = false;
  1645. //AutoMule.check = false;
  1646. AutoMule.torchCheck = false;
  1647.  
  1648. // No response - stop mule profile
  1649. if (failCount >= 60) {
  1650. D2Bot.stop(muleObj.muleProfile);
  1651. delay(1000);
  1652.  
  1653. // Don't do ingame stuff
  1654. rval = false;
  1655. }
  1656.  
  1657. if (stopCheck && muleObj.stopProfile) {
  1658. D2Bot.start(muleObj.stopProfile);
  1659. }
  1660.  
  1661. return rval;
  1662. };
  1663.  
  1664. Doup.finishMule = function () {
  1665. var muleObj, tick, info,
  1666. timeout = 150 * 1000, // Ingame mule timeout
  1667. status = "muling";
  1668.  
  1669. info = AutoMule.getInfo();
  1670.  
  1671. // Profile is not a part of AutoMule
  1672. if (!info) {
  1673. print("You fail #2");
  1674.  
  1675. return false;
  1676. }
  1677.  
  1678. function DropStatusEvent(mode, msg) {
  1679. if (mode === 10) {
  1680. switch (JSON.parse(msg).status) {
  1681. case "report": // reply to status request
  1682. sendCopyData(null, muleObj.muleProfile, 12, JSON.stringify({status: status}));
  1683.  
  1684. break;
  1685. case "quit": // quit command
  1686. status = "quit";
  1687.  
  1688. break;
  1689. }
  1690. }
  1691. }
  1692.  
  1693. addEventListener("copydata", DropStatusEvent);
  1694. delay(500);
  1695.  
  1696. muleObj = AutoMule.getMule();
  1697. me.maxgametime = 0;
  1698.  
  1699. if (!muleObj) {
  1700. print("You fairuuuu");
  1701.  
  1702. return false;
  1703. }
  1704.  
  1705. Town.goToTown(1, true);
  1706. sendCopyData(null, muleObj.muleProfile, 11, "begin");
  1707. D2Bot.printToConsole("AutoMule: Transfering items.", 7);
  1708.  
  1709. status = "done";
  1710. tick = getTickCount();
  1711.  
  1712. while (true) {
  1713. if (status === "quit") {
  1714. break;
  1715. }
  1716.  
  1717. if (getTickCount() - tick > timeout) {
  1718. D2Bot.printToConsole("Mule didn't rejoin. Picking up items.", 9);
  1719. Pickit.pickItems();
  1720.  
  1721. break;
  1722. }
  1723.  
  1724. delay(500);
  1725. }
  1726.  
  1727. removeEventListener("copydata", DropStatusEvent);
  1728. D2Bot.stop(muleObj.muleProfile);
  1729. delay(1000);
  1730.  
  1731. if (muleObj.stopProfile) {
  1732. D2Bot.start(muleObj.stopProfile);
  1733. }
  1734.  
  1735. delay(2000);
  1736. //OrganSystem.organHandler();
  1737.  
  1738. //quit();
  1739. //delay(10000);
  1740.  
  1741. return true;
  1742. };
  1743.  
  1744. Doup.resupply = function () {
  1745. print("Resupply start");
  1746.  
  1747. var i, tick, unit,
  1748. timeout = 180000;
  1749.  
  1750. tick = getTickCount();
  1751.  
  1752. while (true) {
  1753. if (actions.length > 0) {
  1754. switch (actions[0].cmd) {
  1755. case "pick":
  1756. for (i = 0; i < 3; i += 1) {
  1757. Doup.pickStuff();
  1758. }
  1759.  
  1760. actions.shift();
  1761.  
  1762. break;
  1763. case "done":
  1764. D2Bot.printToConsole("Resupply successful!", 5);
  1765. actions.shift();
  1766.  
  1767. return;
  1768. }
  1769. }
  1770.  
  1771. if (getTickCount() - tick >= timeout) {
  1772. throw new Error("Resupply failed.");
  1773. }
  1774.  
  1775. delay(100);
  1776. }
  1777. };
  1778.  
  1779. Doup.callSupply = function () {
  1780. if (!supplier.profile) {
  1781. return false;
  1782. }
  1783.  
  1784. var master,
  1785. rval = true,
  1786. status = "",
  1787. failCount = 0;
  1788.  
  1789. function CopyDataEv(mode, msg) {
  1790. var obj;
  1791.  
  1792. if (mode === 10) {
  1793. obj = JSON.parse(msg);
  1794.  
  1795. if (obj) {
  1796. status = obj.status;
  1797. }
  1798. }
  1799. }
  1800.  
  1801. addEventListener("copydata", CopyDataEv);
  1802. D2Bot.printToConsole("Call down the flavor", 7);
  1803.  
  1804. MainLoop:
  1805. while (true) {
  1806. // If nothing received our copy data start the mule profile
  1807. if (!sendCopyData(null, supplier.profile, 10, JSON.stringify({profile: me.profile, accInfo: supplier.accountInfo}))) {
  1808. D2Bot.start(supplier.profile);
  1809.  
  1810. master = true;
  1811. }
  1812.  
  1813. delay(1000);
  1814.  
  1815. switch (status) {
  1816. case "busy":
  1817. case "begin":
  1818. if (master) {
  1819. print("Supplier in game");
  1820.  
  1821. break MainLoop;
  1822. }
  1823.  
  1824. D2Bot.printToConsole("Supplier is busy.", 9);
  1825.  
  1826. // Can't do ingame stuff
  1827. rval = false;
  1828.  
  1829. break MainLoop;
  1830. case "ready":
  1831. // No need
  1832. break MainLoop;
  1833. default:
  1834. failCount += 1;
  1835.  
  1836. break;
  1837. }
  1838.  
  1839. if (failCount >= 60) {
  1840. D2Bot.printToConsole("No response from supplier.", 9);
  1841.  
  1842. break;
  1843. }
  1844. }
  1845.  
  1846. removeEventListener("copydata", CopyDataEv);
  1847.  
  1848. if (failCount >= 60) {
  1849. D2Bot.stop(supplier.profile);
  1850. delay(1000);
  1851.  
  1852. // Don't do ingame stuff
  1853. rval = false;
  1854. }
  1855.  
  1856. return rval;
  1857. };
  1858.  
  1859. Doup.openCube = function () {
  1860. if (stashOpen && cubeOpen) {
  1861. return true;
  1862. }
  1863.  
  1864. var i, tick, stash, cube;
  1865.  
  1866. Town.move("stash");
  1867.  
  1868. addEventListener("gamepacket", packetRecv);
  1869.  
  1870. stash = getUnit(2, 267);
  1871.  
  1872. if (!stash) {
  1873. removeEventListener("gamepacket", packetRecv);
  1874.  
  1875. return false;
  1876. }
  1877.  
  1878. StashLoop:
  1879. for (i = 0; i < 10; i += 1) {
  1880. sendPacket(1, 0x13, 4, stash.type, 4, stash.gid);
  1881.  
  1882. tick = getTickCount();
  1883.  
  1884. while (getTickCount() - tick < 1000 + me.ping * 2) {
  1885. if (stashOpen) {
  1886. break StashLoop;
  1887. }
  1888.  
  1889. delay(100);
  1890. }
  1891.  
  1892. if (!stashOpen) {
  1893. print("force close");
  1894. Doup.closeStash(true);
  1895. }
  1896. }
  1897.  
  1898. if (!stashOpen) {
  1899. removeEventListener("gamepacket", packetRecv);
  1900.  
  1901. return false;
  1902. }
  1903.  
  1904. cube = me.getItem(549);
  1905.  
  1906. if (!cube) {
  1907. removeEventListener("gamepacket", packetRecv);
  1908.  
  1909. return false;
  1910. }
  1911.  
  1912. CubeLoop:
  1913. for (i = 0; i < 10; i += 1) {
  1914. cube.interact();
  1915.  
  1916. tick = getTickCount();
  1917.  
  1918. while (getTickCount() - tick < 1000 + me.ping) {
  1919. if (cubeOpen) {
  1920. break CubeLoop;
  1921. }
  1922.  
  1923. delay(100);
  1924. }
  1925.  
  1926. if (!cubeOpen) {
  1927. Doup.closeStash(true);
  1928. }
  1929. }
  1930.  
  1931. if (!cubeOpen) {
  1932. removeEventListener("gamepacket", packetRecv);
  1933.  
  1934. return false;
  1935. }
  1936.  
  1937. removeEventListener("gamepacket", packetRecv);
  1938.  
  1939. return true;
  1940. };
  1941.  
  1942. Doup.exitTown = function () {
  1943. var i, exits;
  1944.  
  1945. if (!exit.out) {
  1946. exits = getArea().exits;
  1947.  
  1948. if (!exits) {
  1949. return Pather.moveToExit(41, true);
  1950. }
  1951.  
  1952. for (i = 0; i < exits.length; i += 1) {
  1953. if (exits[i].target === 41) {
  1954. switch (exits[i].x) {
  1955. case 5094: // next to drog
  1956. exit.out = {
  1957. x: 5096,
  1958. y: 4995
  1959. };
  1960.  
  1961. exit.town = {
  1962. x: 5096,
  1963. y: 5016
  1964. };
  1965.  
  1966. break;
  1967. case 5000: // next to greiz
  1968. exit.out = {
  1969. x: 4995,
  1970. y: 5066
  1971. };
  1972.  
  1973. exit.town = {
  1974. x: 5015,
  1975. y: 5066
  1976. };
  1977.  
  1978. break;
  1979. default:
  1980. throw new Error("Exit code sux, bro");
  1981. }
  1982. }
  1983. }
  1984. }
  1985.  
  1986. while (getDistance(me, exit.out.x, exit.out.y) > 5) {
  1987. Pather.moveTo(exit.out.x, exit.out.y);
  1988. Packet.flash(me.gid);
  1989. delay(500);
  1990. }
  1991.  
  1992. return true;
  1993. };
  1994.  
  1995. Doup.enterTown = function () {
  1996. var target;
  1997.  
  1998. if (!exit.town) {
  1999. //Pather.moveToExit(40, false);
  2000.  
  2001. target = Pather.getNearestRoom(40);
  2002.  
  2003. if (target) {
  2004. exit.town = {
  2005. x: target[0],
  2006. y: target[1]
  2007. };
  2008. } else { // backup
  2009. return Pather.moveToExit(40, true);
  2010. }
  2011. }
  2012.  
  2013. Pather.moveTo(exit.town.x, exit.town.y);
  2014.  
  2015. while (getDistance(me, exit.town.x, exit.town.y) > 5) {
  2016. Pather.moveTo(exit.town.x, exit.town.y);
  2017. Packet.flash(me.gid);
  2018. delay(500);
  2019. }
  2020.  
  2021. return true;
  2022. };
Add Comment
Please, Sign In to add comment