Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.89 KB | None | 0 0
  1. var StarterConfig = {
  2. MinGameTime: 90, // Minimum game length in seconds.
  3.  
  4. SwitchKeyDelay: 0, // Seconds to wait before switching a used/banned key or after realm down
  5. RealmDownDelay: 3, // Minutes to wait after getting Realm Down message
  6. UnableToConnectDelay: 5, // Minutes to wait after Unable To Connect message
  7. CDKeyInUseDelay: 5, // Minutes to wait before connecting again if CD-Key is in use.
  8. ConnectingTimeout: 20, // Seconds to wait before cancelling the 'Connecting...' screen
  9. PleaseWaitTimeout: 10, // Seconds to wait before cancelling the 'Please Wait...' screen
  10. WaitInLineTimeout: 60 // Seconds to wait before cancelling the 'Waiting in Line...' screen
  11. };
  12.  
  13.  
  14. var master, gameInfo, connectFail, makeAcc, joinInfo,
  15. muleMode, muleFilename, muleObj, handle, maxCharCount,
  16. makeNext = false,
  17. status = "loading",
  18. masterStatus = {
  19. status: ""
  20. };
  21.  
  22. // Mule Data object manipulates external mule datafile
  23. var MuleData = {
  24. // create a new mule datafile
  25. create: function () {
  26. var obj, string;
  27.  
  28. obj = {
  29. account: "",
  30. accNum: 0,
  31. character: "",
  32. charNum: 0,
  33. fullChars: [],
  34. torchChars: []
  35. };
  36.  
  37. string = JSON.stringify(obj);
  38.  
  39. FileTools.writeText(muleFilename, string);
  40. },
  41.  
  42. // read data from the mule datafile and return the data object
  43. read: function () {
  44. var obj, string;
  45.  
  46. string = FileTools.readText(muleFilename);
  47. obj = JSON.parse(string);
  48.  
  49. return obj;
  50. },
  51.  
  52. // write a data object to the mule datafile
  53. write: function (obj) {
  54. var string;
  55.  
  56. string = JSON.stringify(obj);
  57.  
  58. FileTools.writeText(muleFilename, string);
  59. }
  60. };
  61.  
  62. // stash picked items
  63. function stashItems() {
  64. var i,
  65. items = me.findItems(-1, 0, 3);
  66.  
  67. // stash large items first by sorting items by size in descending order
  68. items.sort(function(a, b) {return (b.sizex * b.sizey - a.sizex * a.sizey);});
  69.  
  70. for (i = 0; i < items.length; i += 1) {
  71. Storage.Stash.MoveTo(items[i]);
  72. }
  73.  
  74. return true;
  75. }
  76.  
  77. // pick items from ground
  78. function pickItems() {
  79. var i, items, canFit, item,
  80. rval = "fail",
  81. list = [];
  82.  
  83. while (!me.name || !me.gameReady) {
  84. if (!me.ingame) {
  85. return rval;
  86. }
  87.  
  88. delay(100);
  89. }
  90.  
  91. //delay(1000);
  92.  
  93. for (i = 0; i < 100; i += 1) {
  94. items = me.findItems(-1, 0, 3);
  95.  
  96. if (items) {
  97. break;
  98. }
  99.  
  100. delay(100);
  101. }
  102.  
  103. if (items) {
  104. for (i = 0; i < items.length; i += 1) {
  105. if (items[i].mode === 0 && items[i].location === 3 && Town.ignoredItemTypes.indexOf(items[i].itemType) > -1 // drop trash (id/tp scroll primarily)
  106. && (muleMode === 0 || items[i].classid !== 530)) { // don't drop ID scroll with torch/anni mules
  107. try {
  108. items[i].drop();
  109. } catch (dropError) {
  110. print("Failed to drop an item.");
  111. }
  112. }
  113. }
  114. }
  115.  
  116. while (me.gameReady) {
  117. if (masterStatus.status === "done") {
  118. item = getUnit(4);
  119.  
  120. if (item) {
  121. do {
  122. if (getDistance(me, item) < 20 && [3, 5].indexOf(item.mode) > -1 && Town.ignoredItemTypes.indexOf(item.itemType) === -1) { // don't pick up trash
  123. list.push(copyUnit(item));
  124. }
  125. } while (item.getNext());
  126. }
  127.  
  128. // If and only if there is nothing left are we "done"
  129. if (list.length === 0) {
  130. rval = "done";
  131.  
  132. break;
  133. }
  134.  
  135. // pick large items first by sorting items by size in descending order and move gheed's charm to the end of the list
  136. list.sort(function(a, b) {
  137. if (a.classid === 605 && a.quality === 7 && !Pickit.canPick(a)) {
  138. return 1;
  139. }
  140.  
  141. if (b.classid === 605 && b.quality === 7 && !Pickit.canPick(b)) {
  142. return -1;
  143. }
  144.  
  145. return (b.sizex * b.sizey - a.sizex * a.sizey);
  146. });
  147.  
  148. while (list.length > 0) {
  149. item = list.shift();
  150. canFit = Storage.Inventory.CanFit(item);
  151.  
  152. // Torch handling
  153. if (muleMode > 0 && item.classid === 604 && item.quality === 7 && !Pickit.canPick(item)) {
  154. D2Bot.printToConsole("Mule already has a Torch.", 7);
  155.  
  156. rval = "next";
  157. }
  158.  
  159. // Anni handling
  160. if (muleMode > 0 && item.classid === 603 && item.quality === 7 && !Pickit.canPick(item)) {
  161. D2Bot.printToConsole("Mule already has an Anni.", 7);
  162.  
  163. rval = "next";
  164. }
  165.  
  166. // Gheed's Fortune handling
  167. if (item.classid === 605 && item.quality === 7 && !Pickit.canPick(item)) {
  168. D2Bot.printToConsole("Mule already has Gheed's.", 7);
  169. rval = "next";
  170. }
  171.  
  172. if (!canFit) {
  173. stashItems();
  174.  
  175. canFit = Storage.Inventory.CanFit(item);
  176. }
  177.  
  178. if (canFit) {
  179. Pickit.pickItem(item);
  180. } else {
  181. rval = "next";
  182. }
  183. }
  184.  
  185. if (rval === "next") {
  186. break;
  187. }
  188. } else {
  189. sendCopyData(null, master, 10, JSON.stringify({status: "report"}));
  190. //D2Bot.shoutGlobal("report", 0);
  191. }
  192.  
  193. delay(500);
  194. }
  195.  
  196. return rval;
  197. }
  198.  
  199. // master/mule communication function
  200. function ReceiveCopyData(mode, msg) {
  201. var obj, masterInfo;
  202.  
  203. switch (msg) {
  204. case "Handle":
  205. handle = mode;
  206.  
  207. break;
  208. }
  209.  
  210. // mode check instead of msg check because of crashes
  211. switch (mode) {
  212. case 1: // JoinInfo
  213. //print("Got Join Info");
  214.  
  215. joinInfo = JSON.parse(msg);
  216.  
  217. break;
  218. case 2: // game info
  219. print("Recieved Game Info");
  220.  
  221. gameInfo = JSON.parse(msg);
  222.  
  223. break;
  224. case 3: // request game
  225. break;
  226. case 4:
  227. // Heartbeat ping
  228. if (msg === "pingreq") {
  229. sendCopyData(null, me.windowtitle, 4, "pingrep");
  230. }
  231.  
  232. break;
  233. // automule specific
  234. case 10: // mule request
  235. obj = JSON.parse(msg);
  236.  
  237. if (!master) {
  238. masterInfo = AutoMule.getMaster(obj);
  239.  
  240. if (masterInfo) {
  241. master = masterInfo.profile;
  242. muleMode = masterInfo.mode;
  243. }
  244. } else {
  245. if (obj.profile === master) {
  246. sendCopyData(null, master, 10, JSON.stringify({status: status}));
  247. } else {
  248. sendCopyData(null, obj.profile, 10, JSON.stringify({status: "busy"}));
  249. }
  250. }
  251.  
  252. break;
  253. case 11: // begin item pickup
  254. status = "begin";
  255.  
  256. break;
  257. case 12: // get master's status
  258. masterStatus = JSON.parse(msg);
  259.  
  260. break;
  261. }
  262. }
  263.  
  264. // set next account - increase account number in mule datafile
  265. function nextAccount() {
  266. var obj = MuleData.read();
  267.  
  268. obj.accNum = obj.accNum + 1;
  269. obj.account = muleObj.accountPrefix + obj.accNum;
  270. obj.character = "";
  271. obj.charNum = 0;
  272. obj.fullChars = [];
  273. obj.torchChars = [];
  274.  
  275. MuleData.write(obj);
  276.  
  277. return obj.account;
  278. }
  279.  
  280. // set next character - increase character number in mule datafile
  281. function nextChar() {
  282. var i, num,
  283. charSuffix = "",
  284. charNumbers = "abcdefghijklmnopqrstuvwxyz",
  285. obj = MuleData.read();
  286.  
  287. /*if (getLocation() === 12) {
  288. obj.charNum = ControlAction.getCharacters().length;
  289. }*/
  290.  
  291. // dirty
  292. if (obj.charNum > 25) {
  293. obj.charNum = 0;
  294. }
  295.  
  296. num = obj.accNum.toString();
  297.  
  298. for (i = 0; i < num.length; i += 1) {
  299. charSuffix += charNumbers[parseInt(num[i], 10)];
  300. }
  301.  
  302. charSuffix += charNumbers[obj.charNum];
  303. obj.charNum = obj.charNum + 1;
  304. obj.character = muleObj.charPrefix + charSuffix;
  305.  
  306. MuleData.write(obj);
  307.  
  308. return obj.character;
  309. }
  310.  
  311. function locationTimeout(time, location) {
  312. var endtime = getTickCount() + time;
  313.  
  314. while (getLocation() === location && endtime > getTickCount()) {
  315. delay(500);
  316. }
  317.  
  318. return (getLocation() !== location);
  319. }
  320.  
  321. function ingameTimeout(time) {
  322. var tick = getTickCount();
  323.  
  324. while (getTickCount() - tick < time) {
  325. if (me.ingame && me.gameReady) {
  326. return true;
  327. }
  328.  
  329. if (getLocation() === 28) { // game doesn't exist, might need more locs
  330. break;
  331. }
  332.  
  333. delay(100);
  334. }
  335.  
  336. return me.ingame && me.gameReady;
  337. }
  338.  
  339. function timeoutDelay(text, time) {
  340. var endTime = getTickCount() + time;
  341.  
  342. while (getTickCount() < endTime) {
  343. D2Bot.updateStatus(text + " (" + Math.floor((endTime - getTickCount()) / 1000) + "s)");
  344. delay(500);
  345. }
  346. }
  347.  
  348. function updateCount() {
  349. D2Bot.updateCount();
  350. delay(1000);
  351. ControlAction.click(6, 264, 366, 272, 35);
  352.  
  353. var info,
  354. obj = MuleData.read();
  355.  
  356. info = {
  357. realm: muleObj.realm,
  358. account: obj.account,
  359. password: muleObj.accountPassword
  360. };
  361.  
  362. MuleLogger.save(md5(info.realm.toLowerCase() + info.account.toLowerCase()), info.password);
  363. ControlAction.loginAccount(info);
  364. delay(1000);
  365. ControlAction.click(6, 33, 572, 128, 35);
  366. }
  367.  
  368. function checkAnniTorch() {
  369. while (!me.gameReady) {
  370. delay(500);
  371. }
  372.  
  373. return me.findItem(603, 0, -1, 7) || me.findItem(604, 0, -1, 7);
  374. }
  375.  
  376. function foreverAlone() {
  377. var party = getParty();
  378.  
  379. if (party) {
  380. do {
  381. if (party.name !== me.name) {
  382. return false;
  383. }
  384. } while (party.getNext());
  385. }
  386.  
  387. return true;
  388. }
  389.  
  390. include("json2.js");
  391. include("oog.js");
  392. include("automule.js");
  393. include("mulelogger.js");
  394. include("torchsystem.js");
  395. include("NTItemParser.dbl");
  396. include("common/attack.js");
  397. include("common/storage.js");
  398. include("common/pickit.js");
  399. include("common/town.js");
  400. include("common/pather.js");
  401. include("common/misc.js");
  402. include("common/config.js");
  403. include("common/prototypes.js");
  404. include("common/collmap.js");
  405.  
  406. addEventListener("copydata", ReceiveCopyData);
  407.  
  408. function main() {
  409. while (!handle) {
  410. delay(100);
  411. }
  412.  
  413. DataFile.updateStats("handle", handle);
  414. D2Bot.init();
  415. load("tools/heartbeat.js");
  416.  
  417. while (!gameInfo) {
  418. D2Bot.requestGameInfo();
  419. delay(500);
  420. }
  421.  
  422. if (gameInfo.rdBlocker) {
  423. D2Bot.printToConsole("You must disable RD Blocker for Mule Logger to work properly. Stopping.");
  424. D2Bot.stop(me.profile, true);
  425.  
  426. return;
  427. }
  428.  
  429. D2Bot.updateRuns(); // we need the mule to swap keys somehow after all
  430. delay(1000);
  431.  
  432. // Wait for master before login = give room to determine muling mode (normal or torch)
  433. while (!master) {
  434. delay(100);
  435. }
  436.  
  437. print("Master found: " + master);
  438.  
  439. muleObj = AutoMule.getMuleObject(muleMode, master);
  440. muleFilename = AutoMule.getMuleFilename(muleMode, master);
  441.  
  442. print("Mule filename: " + muleFilename);
  443.  
  444. var obj, tick,
  445. inGame = false;
  446.  
  447. try {
  448. // ugly solution to uglier problem - pickItem area update
  449. if (!FileTools.exists("data/" + me.profile + ".json")) {
  450. DataFile.create();
  451. }
  452.  
  453. // create mule datafile if it doesn't exist
  454. if (!FileTools.exists(muleFilename)) {
  455. MuleData.create();
  456. }
  457.  
  458. obj = MuleData.read();
  459.  
  460. if (obj.account && obj.account.indexOf(muleObj.accountPrefix) < 0) {
  461. MuleData.create();
  462. }
  463. } catch (e) {
  464. print("Caught exception creating data files.");
  465. print(e);
  466. D2Bot.printToConsole("DataFileException: " + e.message + " (" + e.fileName.substring(e.fileName.lastIndexOf("\\") + 1, e.fileName.length) + " #" + e.lineNumber + ")");
  467. }
  468.  
  469. while (true) {
  470. try {
  471. if (me.ingame && me.gameReady) {
  472. if (!inGame) {
  473. if (status !== "begin") {
  474. status = "ready";
  475. }
  476.  
  477. D2Bot.updateStatus("In " + (muleMode === 2 ? "anni" : muleMode === 1 ? "torch" : "") + " mule game.");
  478. D2Bot.printToConsole("In " + (muleMode === 2 ? "anni" : muleMode === 1 ? "torch" : "") + " mule game.", 7);
  479. tick = getTickCount();
  480.  
  481. while (!me.area && getTickCount() - tick < 2000) {
  482. delay(200);
  483. }
  484.  
  485. Town.goToTown(1);
  486. Town.move("stash");
  487. Storage.Init();
  488.  
  489. inGame = true;
  490. }
  491.  
  492. tick = getTickCount();
  493.  
  494. while (getTickCount() - tick < 60000) {
  495. if (status === "begin") {
  496. break;
  497. }
  498.  
  499. delay(100);
  500. }
  501.  
  502. //print("Delay: " + (getTickCount() - tick));
  503.  
  504. if (status !== "begin") {
  505. D2Bot.printToConsole("Nobody joined - stopping.", 9);
  506. D2Bot.stop(me.profile, true);
  507. }
  508.  
  509. me.overhead("begin");
  510.  
  511. switch (pickItems()) {
  512. // done picking, tell the master to leave game and kill mule profile
  513. case "done":
  514. MuleLogger.logChar();
  515.  
  516. obj = MuleData.read();
  517.  
  518. if (checkAnniTorch() && obj.torchChars.indexOf(me.name) === -1) {
  519. obj.torchChars.push(me.name);
  520. }
  521.  
  522. MuleData.write(obj);
  523. D2Bot.printToConsole("Done muling.", 7);
  524. sendCopyData(null, master, 10, JSON.stringify({status: "quit"}));
  525. //delay(500);
  526. D2Bot.stop(me.profile, true);
  527.  
  528. return;
  529. // can't fit more items, get to next character or account
  530. case "next":
  531. MuleLogger.logChar();
  532. //delay(500);
  533.  
  534. makeNext = true;
  535. obj = MuleData.read();
  536.  
  537. if (checkAnniTorch() && obj.torchChars.indexOf(me.name) === -1) {
  538. obj.torchChars.push(me.name);
  539. }
  540.  
  541. obj.fullChars.push(me.name);
  542. MuleData.write(obj);
  543. nextChar();
  544. D2Bot.printToConsole("Mule full, getting next character.", 7);
  545.  
  546. if (StarterConfig.MinGameTime && getTickCount() - tick < StarterConfig.MinGameTime * 1000) {
  547. while (getTickCount() - tick < StarterConfig.MinGameTime * 1000) {
  548. me.overhead("Stalling for " + Math.round(((tick + (StarterConfig.MinGameTime * 1000)) - getTickCount()) / 1000) + " Seconds");
  549. delay(1000);
  550. }
  551. }
  552.  
  553. quit();
  554.  
  555. // TODO: see whether a for loop is better
  556. while (me.ingame) {
  557. delay(100);
  558. }
  559.  
  560. break;
  561. case "fail":
  562. // Try again
  563. break;
  564. }
  565. }
  566.  
  567. if (!me.ingame) {
  568. delay(1000);
  569. locationAction(getLocation());
  570. }
  571. } catch (e2) {
  572. print("Caught an exception in the main loop.");
  573. print(e2);
  574. D2Bot.printToConsole("MainLoopException: " + e2.message + " (" + e2.fileName.substring(e2.fileName.lastIndexOf("\\") + 1, e2.fileName.length) + " #" + e2.lineNumber + ")");
  575. }
  576.  
  577. delay(100);
  578. }
  579. }
  580.  
  581. function locationAction(location) {
  582. var i, obj, info, control, string, text;
  583.  
  584. MainSwitch:
  585. switch (location) {
  586. case 1:
  587. case 3:
  588. D2Bot.updateStatus("Lobby");
  589.  
  590. if (makeNext) {
  591. ControlAction.click(6, 693, 490, 80, 20);
  592.  
  593. break;
  594. }
  595.  
  596. if (!ControlAction.click(6, 652, 469, 120, 20)) { // Join
  597. break;
  598. }
  599.  
  600. if (!locationTimeout(5000, location)) { // in case join button gets bugged
  601. if (!ControlAction.click(6, 533, 469, 120, 20)) { // Create
  602. break;
  603. }
  604.  
  605. if (!ControlAction.click(6, 652, 469, 120, 20)) { // Join
  606. break;
  607. }
  608. }
  609.  
  610. break;
  611. case 4: // Create Game
  612. D2Bot.updateStatus("Creating Game");
  613.  
  614. control = getControl(1, 657, 342, 27, 20);
  615.  
  616. if (control && control.disabled === 5) {
  617. ControlAction.click(6, 431, 341, 15, 16); // remove level restriction
  618. }
  619.  
  620. delay(2000);
  621. createGame(muleObj.muleGameName[0], muleObj.muleGameName[1]);
  622. ingameTimeout(5000);
  623.  
  624. break;
  625. case 2: // Waiting In Line
  626. D2Bot.updateStatus("Waiting...");
  627. locationTimeout(StarterConfig.WaitInLineTimeout * 1e3, location);
  628. ControlAction.click(6, 433, 433, 96, 32);
  629.  
  630. break;
  631. case 5: // Join Game
  632. D2Bot.updateStatus("Join Game");
  633. D2Bot.requestGame(master);
  634. delay(100);
  635.  
  636. if (joinInfo && joinInfo.gameName !== "" && joinInfo.inGame) {
  637. joinGame(joinInfo.gameName, joinInfo.gamePass);
  638. } else {
  639. joinGame(muleObj.muleGameName[0], muleObj.muleGameName[1]);
  640. }
  641.  
  642. ingameTimeout(5000);
  643. print("Ingame timeout done.");
  644.  
  645. break;
  646. case 6: // Ladder
  647. break;
  648. case 7: // Channel List
  649. break;
  650. case 8: // menu
  651. case 9: // login
  652. if (makeNext) {
  653. makeNext = false;
  654. }
  655.  
  656. obj = MuleData.read();
  657.  
  658. if (!obj.account || obj.account.indexOf(muleObj.accountPrefix) < 0) {
  659. nextAccount();
  660.  
  661. obj = MuleData.read();
  662. }
  663.  
  664. info = {
  665. realm: muleObj.realm,
  666. account: obj.account,
  667. password: muleObj.accountPassword
  668. };
  669.  
  670. if (makeAcc) {
  671. ControlAction.makeAccount(info);
  672. //FileTools.writeText("mules/" + info.account + ".txt", "");
  673. D2Bot.printToConsole("Made account: " + info.account, 7);
  674.  
  675. makeAcc = false;
  676.  
  677. break;
  678. }
  679.  
  680. MuleLogger.save(md5(info.realm.toLowerCase() + info.account.toLowerCase()), info.password);
  681. ControlAction.loginAccount(info);
  682.  
  683. break;
  684. case 10: // Login Error
  685. string = "";
  686. text = ControlAction.getText(4, 199, 377, 402, 140);
  687.  
  688. if (text) {
  689. for (i = 0; i < text.length; i += 1) {
  690. string += text[i];
  691.  
  692. if (i !== text.length - 1) {
  693. string += " ";
  694. }
  695. }
  696.  
  697. switch (string) {
  698. case getLocaleString(5207):
  699. D2Bot.updateStatus("Invalid Password");
  700. D2Bot.printToConsole("Invalid Password");
  701.  
  702. break;
  703. case getLocaleString(5208):
  704. ControlAction.click(6, 335, 412, 128, 35);
  705.  
  706. makeAcc = true;
  707.  
  708. break MainSwitch;
  709. case getLocaleString(5202): // cd key intended for another product
  710. case getLocaleString(10915): // lod key intended for another product
  711. D2Bot.updateStatus("Invalid CDKey");
  712. D2Bot.printToConsole("Invalid CDKey: " + gameInfo.mpq, 6);
  713. D2Bot.CDKeyDisabled();
  714.  
  715. if (gameInfo.switchKeys) {
  716. ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
  717. D2Bot.restart(true);
  718. } else {
  719. D2Bot.stop(me.profile, true);
  720. }
  721.  
  722. break;
  723. case getLocaleString(5199):
  724. D2Bot.updateStatus("Disabled CDKey");
  725. D2Bot.printToConsole("Disabled CDKey: " + gameInfo.mpq, 6);
  726. D2Bot.CDKeyDisabled();
  727.  
  728. if (gameInfo.switchKeys) {
  729. ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
  730. D2Bot.restart(true);
  731. } else {
  732. D2Bot.stop(me.profile, true);
  733. }
  734.  
  735. break;
  736. case getLocaleString(10913):
  737. D2Bot.updateStatus("Disabled LoD CDKey");
  738. D2Bot.printToConsole("Disabled LoD CDKey: " + gameInfo.mpq, 6);
  739. D2Bot.CDKeyDisabled();
  740.  
  741. if (gameInfo.switchKeys) {
  742. ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
  743. D2Bot.restart(true);
  744. } else {
  745. D2Bot.stop(me.profile, true);
  746. }
  747.  
  748. break;
  749. case getLocaleString(5347):
  750. D2Bot.updateStatus("Disconnected");
  751. D2Bot.printToConsole("Disconnected");
  752. ControlAction.click(6, 335, 412, 128, 35);
  753.  
  754. break MainSwitch;
  755. default:
  756. D2Bot.updateStatus("Login Error");
  757. D2Bot.printToConsole("Login Error - " + string);
  758.  
  759. if (gameInfo.switchKeys) {
  760. ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
  761. D2Bot.restart(true);
  762. } else {
  763. D2Bot.stop(me.profile, true);
  764. }
  765.  
  766. break;
  767. }
  768. }
  769.  
  770. ControlAction.click(6, 335, 412, 128, 35);
  771.  
  772. while (true) {
  773. delay(1000);
  774. }
  775.  
  776. break;
  777. case 11: // Unable To Connect
  778. D2Bot.updateStatus("Unable To Connect");
  779.  
  780. if (connectFail) {
  781. timeoutDelay("Unable to Connect", StarterConfig.UnableToConnectDelay * 6e4);
  782.  
  783. connectFail = false;
  784. }
  785.  
  786. if (!ControlAction.click(6, 335, 450, 128, 35)) {
  787. break;
  788. }
  789.  
  790. connectFail = true;
  791.  
  792. break;
  793. case 13: // Realm Down - Character Select screen
  794. D2Bot.updateStatus("Realm Down");
  795. delay(1000);
  796.  
  797. if (!ControlAction.click(6, 33, 572, 128, 35)) {
  798. break;
  799. }
  800.  
  801. updateCount();
  802. timeoutDelay("Realm Down", StarterConfig.RealmDownDelay * 6e4);
  803. D2Bot.CDKeyRD();
  804.  
  805. if (gameInfo.switchKeys) {
  806. D2Bot.printToConsole("Realm Down - Changing CD-Key");
  807. timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
  808. D2Bot.restart(true);
  809. } else {
  810. D2Bot.restart();
  811. }
  812.  
  813. break;
  814. case 14: // Character Select / Main Menu - Disconnected
  815. D2Bot.updateStatus("Disconnected");
  816. delay(500);
  817. ControlAction.click(6, 351, 337, 96, 32);
  818.  
  819. break;
  820. case 18: // splash
  821. ControlAction.click();
  822.  
  823. break;
  824. case 12: // char select
  825. case 15: // new character (selected)
  826. case 29: // new character (list)
  827. case 42: // empty char screen
  828. string = "";
  829. text = ControlAction.getText(4, 45, 318, 531, 140);
  830.  
  831. if (text) {
  832. for (i = 0; i < text.length; i += 1) {
  833. string += text[i];
  834.  
  835. if (i !== text.length - 1) {
  836. string += " ";
  837. }
  838. }
  839.  
  840. if (string === getLocaleString(11161)) { // CDKey disabled from realm play
  841. D2Bot.updateStatus("Realm Disabled CDKey");
  842. D2Bot.printToConsole("Realm Disabled CDKey: " + gameInfo.mpq, 6);
  843. D2Bot.CDKeyDisabled();
  844.  
  845. if (gameInfo.switchKeys) {
  846. ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
  847. D2Bot.restart(true);
  848. } else {
  849. D2Bot.stop(me.profile, true);
  850. }
  851. }
  852. }
  853.  
  854. // Single Player screen fix
  855. // TODO: see if this is still needed. d2bs doesn't load scripts twice anymore
  856. if (getLocation() === 12 && !getControl(4, 626, 100, 151, 44)) {
  857. ControlAction.click(6, 33, 572, 128, 35);
  858.  
  859. break;
  860. }
  861.  
  862. // Can't create character, button greyed out = high likelyhood of realm down
  863. if (getLocation() === 42 && getControl(6, 33, 528, 168, 60).disabled === 4) {
  864. D2Bot.updateStatus("Realm Down");
  865. delay(1000);
  866.  
  867. if (!ControlAction.click(6, 33, 572, 128, 35)) {
  868. break;
  869. }
  870.  
  871. updateCount();
  872. timeoutDelay("Realm Down", StarterConfig.RealmDownDelay * 6e4);
  873. D2Bot.CDKeyRD();
  874.  
  875. if (gameInfo.switchKeys) {
  876. D2Bot.printToConsole("Realm Down - Changing CD-Key");
  877. timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
  878. D2Bot.restart(true);
  879. } else {
  880. D2Bot.restart();
  881. }
  882. }
  883.  
  884. obj = MuleData.read();
  885. maxCharCount = (muleObj.charsPerAcc > 0 ? Math.min(muleObj.charsPerAcc, 18) : 8);
  886.  
  887. if (makeNext) {
  888. if (obj.fullChars.length >= maxCharCount || (muleMode > 0 && obj.torchChars.length >= maxCharCount)) {
  889. ControlAction.click(6, 33, 572, 128, 35);
  890. nextAccount();
  891.  
  892. break;
  893. }
  894.  
  895. makeNext = false;
  896. }
  897.  
  898. if (!obj.character || obj.character.indexOf(muleObj.charPrefix) < 0) {
  899. nextChar();
  900.  
  901. obj = MuleData.read();
  902. }
  903.  
  904. info = {
  905. account: obj.account,
  906. charName: obj.character,
  907. ladder: muleObj.ladder,
  908. hardcore: muleObj.hardcore,
  909. expansion: muleObj.expansion,
  910. charClass: "amazon"
  911. };
  912.  
  913. if (muleMode > 0 && obj.torchChars.indexOf(info.charName) > -1) {
  914. nextChar();
  915.  
  916. break;
  917. }
  918.  
  919. if (ControlAction.findCharacter(info)) {
  920. ControlAction.loginCharacter(info, false);
  921. } else {
  922. if (ControlAction.getCharacters().length >= maxCharCount) { // premade account that's already full
  923. ControlAction.click(6, 33, 572, 128, 35);
  924. nextAccount();
  925.  
  926. break;
  927. }
  928.  
  929. if (!ControlAction.makeCharacter(info)) {
  930. // TODO: check if acc is full and cancel location 15 and 29 if true
  931. nextChar();
  932.  
  933. break;
  934. }
  935.  
  936. D2Bot.printToConsole("Made character: " + info.charName, 7);
  937. }
  938.  
  939. break;
  940. case 16: // Character Select - Please Wait popup
  941. if (!locationTimeout(StarterConfig.PleaseWaitTimeout * 1e3, location)) {
  942. ControlAction.click(6, 351, 337, 96, 32);
  943. }
  944.  
  945. break;
  946. case 17: // Lobby - Lost Connection - just click okay, since we're toast anyway
  947. delay(1000);
  948. ControlAction.click(6, 351, 337, 96, 32);
  949.  
  950. break;
  951. case 19: // Login - Cdkey In Use
  952. D2Bot.printToConsole(gameInfo.mpq + " is in use by " + ControlAction.getText(4, 158, 310, 485, 40), 6);
  953. D2Bot.CDKeyInUse();
  954.  
  955. if (gameInfo.switchKeys) {
  956. ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
  957. D2Bot.restart(true);
  958. } else {
  959. ControlAction.click(6, 335, 450, 128, 35);
  960. ControlAction.timeoutDelay("CD-Key in use", StarterConfig.CDKeyInUseDelay * 6e4);
  961. }
  962.  
  963. break;
  964. case 20: // Single Player - Select Difficulty
  965. break;
  966. case 21: // Main Menu - Connecting
  967. if (!locationTimeout(StarterConfig.ConnectingTimeout * 1e3, location)) {
  968. ControlAction.click(6, 330, 416, 128, 35);
  969. }
  970.  
  971. break;
  972. case 22: // Login - Invalid Cdkey (classic or xpac)
  973. text = ControlAction.getText(4, 162, 270, 477, 50);
  974. string = "";
  975.  
  976. if (text) {
  977. for (i = 0; i < text.length; i += 1) {
  978. string += text[i];
  979.  
  980. if (i !== text.length - 1) {
  981. string += " ";
  982. }
  983. }
  984. }
  985.  
  986. switch (string) {
  987. case getLocaleString(10914):
  988. D2Bot.printToConsole(gameInfo.mpq + " LoD key in use by " + ControlAction.getText(4, 158, 310, 485, 40), 6);
  989. D2Bot.CDKeyInUse();
  990.  
  991. if (gameInfo.switchKeys) {
  992. ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
  993. D2Bot.restart(true);
  994. } else {
  995. ControlAction.click(6, 335, 450, 128, 35);
  996. ControlAction.timeoutDelay("LoD key in use", StarterConfig.CDKeyInUseDelay * 6e4);
  997. }
  998.  
  999. break;
  1000. default:
  1001. if (gameInfo.switchKeys) {
  1002. D2Bot.printToConsole("Invalid CD-Key");
  1003. ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
  1004. D2Bot.restart(true);
  1005. } else {
  1006. ControlAction.click(6, 335, 450, 128, 35);
  1007. ControlAction.timeoutDelay("Invalid CD-Key", StarterConfig.CDKeyInUseDelay * 6e4);
  1008. }
  1009.  
  1010. break;
  1011. }
  1012.  
  1013. break;
  1014. case 23: // Character Select - Connecting
  1015. if (!locationTimeout(StarterConfig.ConnectingTimeout * 1e3, location)) {
  1016. ControlAction.click(6, 33, 572, 128, 35);
  1017. }
  1018.  
  1019. break;
  1020. case 24: // Server Down - not much to do but wait..
  1021. break;
  1022. case 25: // Lobby - Please Wait
  1023. if (!locationTimeout(StarterConfig.PleaseWaitTimeout * 1e3, location)) {
  1024. ControlAction.click(6, 351, 337, 96, 32);
  1025. }
  1026.  
  1027. break;
  1028. case 26: // game already exists
  1029. ControlAction.click(6, 652, 469, 120, 20); // Join
  1030.  
  1031. break;
  1032. case 27: // Gateway Select
  1033. ControlAction.click(6, 436, 538, 96, 32);
  1034.  
  1035. break;
  1036. case 28: // Lobby - Game Does Not Exist
  1037. ControlAction.click(6, 533, 469, 120, 20);
  1038.  
  1039. break;
  1040. case 30: // charname already exists
  1041. ControlAction.click(6, 351, 337, 96, 32);
  1042. ControlAction.click(6, 33, 572, 128, 35);
  1043.  
  1044. break;
  1045. case 38: // Game is full
  1046. break; // not sure how/if to handle
  1047. }
  1048. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement