Guest User

Untitled

a guest
Mar 19th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.58 KB | None | 0 0
  1. /**
  2. * @filename OrgTorch.js
  3. * @author kolton
  4. * @desc Convert keys to organs and organs to torches. It can work with TorchSystem to get keys from other characters
  5. * @notes Search for the word "Start" and follow the comments if you want to know what this script does and when.
  6. */
  7.  
  8. function OrgTorch() {
  9. this.doneAreas = [];
  10.  
  11. // Identify & mule
  12. this.checkTorch = function () {
  13. if (me.area === 136) {
  14. Pather.moveTo(25105, 5140);
  15. Pather.usePortal(109);
  16. }
  17.  
  18. Town.doChores();
  19.  
  20. if (!Config.OrgTorch.MakeTorch) {
  21. return false;
  22. }
  23.  
  24. var item = me.getItem("cm2");
  25.  
  26. if (item) {
  27. do {
  28. if (item.quality === 7 && Pickit.checkItem(item).result === 1) {
  29. if (AutoMule.getInfo() && AutoMule.getInfo().hasOwnProperty("torchMuleInfo")) {
  30. scriptBroadcast("muleTorch");
  31. //quit();
  32. scriptBroadcast("quit");
  33. //delay(10000);
  34. }
  35.  
  36. return true;
  37. }
  38. } while (item.getNext());
  39. }
  40.  
  41. return false;
  42. };
  43.  
  44. // Check whether the killer is alone in the game
  45. this.aloneInGame = function () {
  46. var party = getParty();
  47.  
  48. if (party) {
  49. do {
  50. if (party.name !== me.name) {
  51. return false;
  52. }
  53. } while (party.getNext());
  54. }
  55.  
  56. return true;
  57. };
  58.  
  59. // Try to lure a monster - wait until it's close enough
  60. this.lure = function (bossId) {
  61. var tick,
  62. unit = getUnit(1, bossId);
  63.  
  64. if (unit) {
  65. tick = getTickCount();
  66.  
  67. while (getTickCount() - tick < 2000) {
  68. if (getDistance(me, unit) <= 10) {
  69. return true;
  70. }
  71.  
  72. delay(50);
  73. }
  74. }
  75.  
  76. return false;
  77. };
  78.  
  79. // Check if we have complete sets of organs
  80. this.completeSetCheck = function () {
  81. var horns = me.findItems("dhn"),
  82. brains = me.findItems("mbr"),
  83. eyes = me.findItems("bey");
  84.  
  85. if (!horns || !brains || !eyes) {
  86. return false;
  87. }
  88.  
  89. // We just need one set to make a torch
  90. if (Config.OrgTorch.MakeTorch) {
  91. return horns.length && brains.length && eyes.length;
  92. }
  93.  
  94. return horns.length === brains.length && horns.length === eyes.length && brains.length === eyes.length;
  95. };
  96.  
  97. // Get fade in River of Flames
  98. this.getFade = function () {
  99. if (Config.OrgTorch.GetFade && me.classid === 3) {
  100. if (!me.getState(159)) {
  101. print("Getting Fade");
  102. Pather.useWaypoint(107);
  103. Precast.doPrecast(true);
  104. Pather.moveTo(7811, 5872);
  105.  
  106. if (me.classid === 3 && me.getSkill(125, 1)) {
  107. Skill.setSkill(125, 0);
  108. }
  109.  
  110. while (!me.getState(159)) {
  111. delay(100);
  112. }
  113.  
  114. print("Fade Achieved.");
  115. }
  116. }
  117.  
  118. return true;
  119. };
  120.  
  121. // Open a red portal. Mode 0 = mini ubers, mode 1 = Tristram
  122. this.openPortal = function (mode) {
  123. var portal,
  124. item1 = mode === 0 ? me.findItem("pk1", 0) : me.findItem("dhn", 0),
  125. item2 = mode === 0 ? me.findItem("pk2", 0) : me.findItem("bey", 0),
  126. item3 = mode === 0 ? me.findItem("pk3", 0) : me.findItem("mbr", 0);
  127.  
  128. Town.goToTown(5);
  129. Town.doChores();
  130.  
  131. if (Town.openStash() && Cubing.emptyCube()) {
  132. if (!this.sendToCube(item1) || !this.sendToCube(item2) || !this.sendToCube(item3)) {
  133. return false;
  134. }
  135. return false;
  136. }
  137.  
  138. if (!Cubing.openCube()) {
  139. return false;
  140. }
  141.  
  142. transmute();
  143. delay(1000);
  144.  
  145. portal = getUnit(2, "portal");
  146.  
  147. if (portal) {
  148. do {
  149. switch (mode) {
  150. case 0:
  151. if ([133, 134, 135].indexOf(portal.objtype) > -1 && this.doneAreas.indexOf(portal.objtype) === -1) {
  152. this.doneAreas.push(portal.objtype);
  153.  
  154. return copyUnit(portal);
  155. }
  156.  
  157. break;
  158. case 1:
  159. if (portal.objtype === 136) {
  160. return copyUnit(portal);
  161. }
  162.  
  163. break;
  164. }
  165. } while (portal.getNext());
  166. }
  167. }
  168.  
  169. return false;
  170. };
  171.  
  172. this.sendToCube = function (item) {
  173. var i, tick;
  174.  
  175. if (Packet.itemToCursor(item)) {
  176. for (i = 0; i < 10; i += 1) {
  177. sendPacket(1, 0x2a, 4, item.gid, 4, me.getItem(549).gid);
  178.  
  179. tick = getTickCount();
  180.  
  181. while (getTickCount() - tick < Math.max(500, me.ping * 2 + 200)) {
  182. if (!me.itemoncursor) {
  183. return true;
  184. }
  185.  
  186. delay(10);
  187. }
  188. }
  189. }
  190.  
  191. return false;
  192. };
  193.  
  194. // Do mini ubers or Tristram based on area we're already in
  195. this.pandemoniumRun = function () {
  196. var i, findLoc, skillBackup;
  197.  
  198. switch (me.area) {
  199. case 133: // Matron's Den
  200. Precast.doPrecast(true);
  201. Pather.moveToPreset(133, 2, 397, 2, 2);
  202. Attack.kill(707);
  203. //Attack.clear(5);
  204. Pickit.pickItems();
  205. Town.goToTown();
  206.  
  207. break;
  208. case 134: // Forgotten Sands
  209. Precast.doPrecast(true);
  210.  
  211. findLoc = [20196, 8694, 20308, 8588, 20187, 8639, 20100, 8550, 20103, 8688, 20144, 8709, 20263, 8811, 20247, 8665];
  212.  
  213. for (i = 0; i < findLoc.length; i += 2) {
  214. Pather.moveTo(findLoc[i], findLoc[i + 1]);
  215. delay(500);
  216.  
  217. if (getUnit(1, 708)) {
  218. break;
  219. }
  220. }
  221.  
  222. Attack.kill(708);
  223. Pickit.pickItems();
  224. Town.goToTown();
  225.  
  226. break;
  227. case 135: // Furnace of Pain
  228. Precast.doPrecast(true);
  229. Pather.moveToPreset(135, 2, 397, 2, 2);
  230. Attack.kill(706);
  231. Pickit.pickItems();
  232. Town.goToTown();
  233.  
  234. break;
  235. case 136: // Tristram
  236. Pather.moveTo(25068, 5078);
  237. Precast.doPrecast(true);
  238.  
  239. findLoc = [25040, 5101, 25040, 5166, 25122, 5170];
  240.  
  241. for (i = 0; i < findLoc.length; i += 2) {
  242. Pather.moveTo(findLoc[i], findLoc[i + 1]);
  243. }
  244.  
  245. Skill.setSkill(125, 0);
  246. this.lure(704);
  247. Pather.moveTo(25129, 5198);
  248. Skill.setSkill(125, 0);
  249. this.lure(704);
  250.  
  251. if (!getUnit(1, 704)) {
  252. Pather.moveTo(25122, 5170);
  253. }
  254.  
  255. if (Config.OrgTorch.UseSalvation && me.classid === 3 && me.getSkill(125, 1)) {
  256. skillBackup = Config.AttackSkill[2];
  257. Config.AttackSkill[2] = 125;
  258.  
  259. Attack.init();
  260. }
  261.  
  262. Attack.kill(704);
  263.  
  264. if (skillBackup && me.classid === 3 && me.getSkill(125, 1)) {
  265. Config.AttackSkill[2] = skillBackup;
  266.  
  267. Attack.init();
  268. }
  269.  
  270. Pather.moveTo(25162, 5141);
  271. delay(3250);
  272.  
  273. if (!getUnit(1, 709)) {
  274. Pather.moveTo(25122, 5170);
  275. }
  276.  
  277. Attack.kill(709);
  278.  
  279. if (!getUnit(1, 705)) {
  280. Pather.moveTo(25122, 5170);
  281. }
  282.  
  283. Attack.kill(705);
  284. Pickit.pickItems();
  285. this.checkTorch();
  286.  
  287. break;
  288. }
  289. };
  290.  
  291. this.juvCheck = function () {
  292. var i,
  293. needJuvs = 0,
  294. col = Town.checkColumns(Storage.BeltSize());
  295.  
  296. for (i = 0; i < 4; i += 1) {
  297. if (Config.BeltColumn[i] === "rv") {
  298. needJuvs += col[i];
  299. }
  300. }
  301.  
  302. print("Need " + needJuvs + " juvs.");
  303.  
  304. return needJuvs;
  305. };
  306.  
  307. // Start
  308. var i, portal, tkeys, hkeys, dkeys, brains, eyes, horns, timer, farmer, busy, busyTick,
  309. neededItems = {pk1: 0, pk2: 0, pk3: 0, rv: 0};
  310.  
  311. // Do town chores and quit if MakeTorch is true and we have a torch.
  312. this.checkTorch();
  313.  
  314. // Wait for other bots to drop off their keys. This works only if TorchSystem.js is configured properly.
  315. if (Config.OrgTorch.WaitForKeys) {
  316. timer = getTickCount();
  317.  
  318. // Check if current character is the farmer
  319. farmer = TorchSystem.isFarmer();
  320.  
  321. this.torchSystemEvent = function (mode, msg) {
  322. var obj, farmer;
  323.  
  324. if (mode === 6) {
  325. farmer = TorchSystem.isFarmer();
  326.  
  327. if (farmer) {
  328. obj = JSON.parse(msg);
  329.  
  330. if (obj) {
  331. switch (obj.name) {
  332. case "gameCheck":
  333. if (busy) {
  334. break;
  335. }
  336.  
  337. if (farmer.KeyFinderProfiles.indexOf(obj.profile) > -1) {
  338. print("Got game request from: " + obj.profile);
  339. sendCopyData(null, obj.profile, 6, JSON.stringify({name: "gameName", value: {gameName: me.gamename, password: me.gamepassword}}));
  340.  
  341. busy = true;
  342. busyTick = getTickCount();
  343. }
  344.  
  345. break;
  346. case "keyCheck":
  347. if (farmer.KeyFinderProfiles.indexOf(obj.profile) > -1) {
  348. print("Got key count request from: " + obj.profile);
  349.  
  350. // Get the number of needed keys
  351. neededItems = {pk1: 3 - tkeys, pk2: 3 - hkeys, pk3: 3 - dkeys, rv: this.juvCheck()};
  352.  
  353. sendCopyData(null, obj.profile, 6, JSON.stringify({name: "neededItems", value: neededItems}));
  354. }
  355.  
  356. break;
  357. }
  358. }
  359. }
  360. }
  361. };
  362.  
  363. // Register event that will communicate with key hunters, go to Act 1 town and wait by stash
  364. addEventListener('copydata', this.torchSystemEvent);
  365. Town.goToTown(1);
  366. Town.move("stash");
  367.  
  368. while (true) {
  369. // Abort if the current character isn't a farmer
  370. if (!farmer) {
  371. break;
  372. }
  373.  
  374. // Free up inventory
  375. if (Town.needStash()) {
  376. Town.stash();
  377. }
  378.  
  379. // Get the number keys
  380. tkeys = me.findItems("pk1", 0).length || 0;
  381. hkeys = me.findItems("pk2", 0).length || 0;
  382. dkeys = me.findItems("pk3", 0).length || 0;
  383.  
  384. // Stop the loop if we have enough keys or if wait time expired
  385. if (((tkeys >= 3 && hkeys >= 3 && dkeys >= 3) || (Config.OrgTorch.WaitTimeout && (getTickCount() - timer > Config.OrgTorch.WaitTimeout * 1000 * 60))) && this.aloneInGame()) {
  386. removeEventListener('copydata', this.torchSystemEvent);
  387.  
  388. break;
  389. }
  390.  
  391. if (busy) {
  392. while (getTickCount() - busyTick < 30000) {
  393. if (!this.aloneInGame()) {
  394. break;
  395. }
  396.  
  397. delay(100);
  398. }
  399.  
  400. if (getTickCount() - busyTick > 30000 || this.aloneInGame()) {
  401. busy = false;
  402. }
  403. }
  404.  
  405. // Wait for other characters to leave
  406. while (!this.aloneInGame()) {
  407. delay(500);
  408. }
  409.  
  410. delay(1000);
  411.  
  412. // Pick the keys after the hunters drop them and leave the game
  413. Pickit.pickItems();
  414. }
  415. }
  416.  
  417. // Count keys and organs
  418. tkeys = me.findItems("pk1", 0).length || 0;
  419. hkeys = me.findItems("pk2", 0).length || 0;
  420. dkeys = me.findItems("pk3", 0).length || 0;
  421. brains = me.findItems("mbr", 0).length || 0;
  422. eyes = me.findItems("bey", 0).length || 0;
  423. horns = me.findItems("dhn", 0).length || 0;
  424.  
  425. // End the script if we don't have enough keys nor organs
  426. if ((tkeys < 3 || hkeys < 3 || dkeys < 3) && (brains < 1 || eyes < 1 || horns < 1)) {
  427. print("Not enough keys or organs.");
  428.  
  429. return true;
  430. }
  431.  
  432. Config.UseMerc = false;
  433.  
  434. // We have enough keys, do mini ubers
  435. if (tkeys >= 3 && hkeys >= 3 && dkeys >= 3) {
  436. this.getFade();
  437. print("Making organs.");
  438. D2Bot.printToConsole("OrgTorch: Making organs.", 7);
  439.  
  440. for (i = 0; i < 3; i += 1) {
  441. // Abort if we have a complete set of organs
  442. // If Config.OrgTorch.MakeTorch is false, check after at least one portal is made
  443. if ((Config.OrgTorch.MakeTorch || i > 0) && this.completeSetCheck()) {
  444. break;
  445. }
  446.  
  447. portal = this.openPortal(0);
  448.  
  449. if (portal) {
  450. Pather.usePortal(null, null, portal);
  451. }
  452.  
  453. this.pandemoniumRun();
  454. }
  455. }
  456.  
  457. // Don't make torches if not configured to OR if the char already has one
  458. if (!Config.OrgTorch.MakeTorch || this.checkTorch()) {
  459. return true;
  460. }
  461.  
  462. // Count organs
  463. brains = me.findItems("mbr", 0).length || 0;
  464. eyes = me.findItems("bey", 0).length || 0;
  465. horns = me.findItems("dhn", 0).length || 0;
  466.  
  467. // We have enough organs, do Tristram
  468. if (brains && eyes && horns) {
  469. this.getFade();
  470. print("Making torch");
  471. D2Bot.printToConsole("OrgTorch: Making torch.", 7);
  472.  
  473. portal = this.openPortal(1);
  474.  
  475. if (portal) {
  476. Pather.usePortal(null, null, portal);
  477. }
  478.  
  479. this.pandemoniumRun();
  480. }
  481.  
  482. return true;
  483. }
Add Comment
Please, Sign In to add comment