Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.36 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. this.FadeTick = 0;
  11. this.PreBuffTick = 0;
  12. // Level 15 fade lasts for 288 seconds
  13. this.FadeDuration = 288000;
  14.  
  15. // Identify & mule
  16. this.checkTorch = function () {
  17. var tkeys, hkeys, dkeys;
  18. if (me.area === 136) {
  19. Pather.moveTo(25105, 5140);
  20. Pather.usePortal(109);
  21. }
  22.  
  23. Town.doChores();
  24.  
  25. if (!Config.OrgTorch.MakeTorch) {
  26. return false;
  27. }
  28.  
  29. var item = me.getItem("cm2");
  30.  
  31. if (item) {
  32. print("checking for torch");
  33. do {
  34. if (item.quality === 7 && Pickit.checkItem(item).result === 1) {
  35. print("found torch, thinking about automule");
  36. D2Bot.printToConsole("Torch finish gold: " + me.gold);
  37.  
  38. if (this.needComponents()) {
  39. D2Bot.setProfile("qsd2", "forquinton", "rioteer", "Normal", "Asia", "", "B:\\D2_2\\Game.exe");
  40. }
  41.  
  42. if (AutoMule.getInfo() && AutoMule.getInfo().hasOwnProperty("torchMuleInfo")) {
  43. print("trying to start muling");
  44. scriptBroadcast("muleTorch");
  45. //quit();
  46. scriptBroadcast("quit");
  47. //delay(10000);
  48. } else {
  49. print("not muling for some reason...");
  50. }
  51.  
  52. // We are about to mule, let's check if we need to switch to normal mode
  53. // TODO: Switch profile based on keys and organs
  54.  
  55. return true;
  56. }
  57. } while (item.getNext());
  58. } else {
  59. print("no medium charms, no need to check them");
  60. }
  61. return false;
  62. };
  63.  
  64. // Check whether the killer is alone in the game
  65. this.aloneInGame = function () {
  66. var party = getParty();
  67.  
  68. if (party) {
  69. do {
  70. if (party.name !== me.name) {
  71. return false;
  72. }
  73. } while (party.getNext());
  74. }
  75.  
  76. return true;
  77. };
  78.  
  79. // Try to lure a monster - wait until it's close enough
  80. this.lure = function (bossId) {
  81. var tick,
  82. unit = getUnit(1, bossId);
  83.  
  84. if (unit) {
  85. tick = getTickCount();
  86.  
  87. while (getTickCount() - tick < 2000) {
  88. if (getDistance(me, unit) <= 10) {
  89. return true;
  90. }
  91.  
  92. delay(50);
  93. }
  94. }
  95.  
  96. return false;
  97. };
  98.  
  99. // Check if we have complete sets of organs
  100. this.completeSetCheck = function () {
  101. var horns = me.findItems("dhn"),
  102. brains = me.findItems("mbr"),
  103. eyes = me.findItems("bey");
  104.  
  105. if (!horns || !brains || !eyes) {
  106. return false;
  107. }
  108.  
  109. // We just need one set to make a torch
  110. if (Config.OrgTorch.MakeTorch) {
  111. return horns.length && brains.length && eyes.length;
  112. }
  113.  
  114. return horns.length === brains.length && horns.length === eyes.length && brains.length === eyes.length;
  115. };
  116.  
  117. this.checkRunewordItem = function(prefixId) {
  118. return getRunewordItem(prefixId).length > 0;
  119. };
  120.  
  121. this.getRunewordItem = function(prefixId) {
  122. print("Checking for runeword " + prefixId);
  123. var item;
  124. var returnItems = [];
  125.  
  126. item = me.getItem();
  127.  
  128. if (item) {
  129. do {
  130. if(item.prefixnums.indexOf(prefixId) >= 0) {
  131. returnItems.push(copyUnit(item));
  132. print(prefixId + " found at " + item.location);
  133. }
  134. } while (item.getNext());
  135. }
  136.  
  137. return returnItems;
  138. };
  139.  
  140. // This is specifically for equipping an item from the stash
  141. // it assumes we already have the stash open
  142. this.equipFromStash = function(item, bodyLoc) {
  143. var cursorItem;
  144. for (i = 0; i < 3; i += 1) {
  145. if (item.toCursor()) {
  146. clickItem(0, bodyLoc);
  147. delay(me.ping * 2 + 500);
  148.  
  149. if (item.bodylocation === bodyLoc) {
  150. if (getCursorType() === 3) {
  151. cursorItem = getUnit(100);
  152.  
  153. if (cursorItem) {
  154. if (!Storage.Stash.CanFit(cursorItem) || !Storage.Stash.MoveTo(cursorItem)) {
  155. D2Bot.printToConsole("equipFromStash: Issue swapping armor. Stopping profile to protect gear.");
  156. D2Bot.stop();
  157. }
  158. }
  159. }
  160.  
  161. return true;
  162. }
  163. }
  164. }
  165.  
  166. return false;
  167. }
  168.  
  169. this.equipFade = function(restoreArmor) {
  170. var treacheryArmor, foundArmor, originalArmor;
  171.  
  172. print("Calling equip fade");
  173. Town.openStash();
  174. delay(me.ping * 2);
  175.  
  176. treacheryArmor = this.getRunewordItem(20653);
  177. originalArmor = Item.getEquippedItem(3, true); // get a full copy of the item
  178.  
  179. if (treacheryArmor) { treacheryArmor = treacheryArmor[0]; }
  180.  
  181. delay(me.ping * 2);
  182. if (restoreArmor) {
  183. print("We were passed the original armor");
  184. // Item.equip has a REALLY bad habit of dropping things, and puts in inventory first
  185. // we will manually click the items
  186. this.equipFromStash(restoreArmor, 3);
  187. delay(me.ping * 2 + 500);
  188. } else if (treacheryArmor) {
  189. print("Found treachery, equipping...");
  190. this.equipFromStash(treacheryArmor, 3);
  191. print("Equipped");
  192. delay(me.ping * 2);
  193. } else {
  194. // This means we aren't restoring the restoreArmor
  195. // and we did not find a treachery armor
  196. print("No treachery found");
  197. }
  198.  
  199. me.cancel();
  200.  
  201. if (getUnit(100)) {
  202. // We have something on our cursor
  203. D2Bot.printToConsole("EquipFade: Issue swapping armor. Stopping profile to protect gear.");
  204. D2Bot.stop();
  205. } else {
  206. print("Nothing on cursor, seems good!");
  207. }
  208.  
  209. return originalArmor;
  210. }
  211.  
  212. // Get fade in River of Flames
  213. this.getFade = function (durationRequired = 0) {
  214. var originalArmor, endTime;
  215. if (Config.OrgTorch.GetFade && me.classid === 3) {
  216. // If we don' have fade, or the required duration is not met, get fade
  217. print("fade tick: " + this.FadeTick);
  218. print("fade duration: " + this.FadeDuration);
  219. endTime = this.FadeTick + this.FadeDuration;
  220. print("end time: " + endTime);
  221.  
  222. if (me.getState(159) && (this.FadeTick == 0 || (endTime - durationRequired) > 0 && (endTime - durationRequired) <= getTickCount())) {
  223. D2Bot.printToConsole("Waiting " + (endTime - getTickCount()) / 1000 + " seconds for fade to lapse");
  224. }
  225.  
  226. while (me.getState(159) && (this.FadeTick == 0 || (endTime - durationRequired) > 0 && (endTime - durationRequired) <= getTickCount())) {
  227. // we dont have enough time left... wait
  228. delay(1000);
  229. }
  230.  
  231. if (!me.getState(159)) {
  232. print("Putting on Treachery");
  233. originalArmor = equipFade();
  234.  
  235. print("Getting Fade");
  236. Pather.useWaypoint(107);
  237. Precast.doPrecast(true);
  238. Pather.moveTo(7811, 5872);
  239.  
  240. // Turn on Salvation as Paladin to avoid damage
  241. if (me.classid === 3 && me.getSkill(125, 1)) {
  242. Skill.setSkill(125, 0);
  243. // If we can't do salvation, try Resist Fire instead
  244. } else if (me.classid === 3 && me.getSkill(100, 1)) {
  245. Skill.setSkill(100, 0);
  246. }
  247.  
  248. while (!me.getState(159)) {
  249. delay(100);
  250. }
  251.  
  252. print("Fade Achieved.");
  253.  
  254. this.FadeTick = getTickCount();
  255. // Do pre-cast again before leaving
  256. Precast.doPrecast(true);
  257. print("Getting original Armor");
  258. // Go back to A5
  259. Town.goToTown(5);
  260. equipFade(originalArmor);
  261. Town.buyPotions(); // Buy potions again since we just used some to get fade
  262. }
  263. }
  264.  
  265. return true;
  266. };
  267.  
  268. // Open a red portal. Mode 0 = mini ubers, mode 1 = Tristram
  269. this.openPortal = function (mode) {
  270. var portal,
  271. item1 = mode === 0 ? me.findItem("pk1", 0) : me.findItem("dhn", 0),
  272. item2 = mode === 0 ? me.findItem("pk2", 0) : me.findItem("bey", 0),
  273. item3 = mode === 0 ? me.findItem("pk3", 0) : me.findItem("mbr", 0);
  274.  
  275. Town.goToTown(5);
  276.  
  277. Town.doChores();
  278.  
  279. if (Town.openStash() && Cubing.emptyCube()) {
  280. if (!Storage.Cube.MoveTo(item1) || !Storage.Cube.MoveTo(item2) || !Storage.Cube.MoveTo(item3)) {
  281. return false;
  282. }
  283.  
  284. if (!Cubing.openCube()) {
  285. return false;
  286. }
  287.  
  288. transmute();
  289. delay(1000);
  290.  
  291. portal = getUnit(2, "portal");
  292.  
  293. if (portal) {
  294. do {
  295. switch (mode) {
  296. case 0:
  297. if ([133, 134, 135].indexOf(portal.objtype) > -1 && this.doneAreas.indexOf(portal.objtype) === -1) {
  298. return copyUnit(portal);
  299. }
  300.  
  301. break;
  302. case 1:
  303. if (portal.objtype === 136) {
  304. return copyUnit(portal);
  305. }
  306.  
  307. break;
  308. }
  309. } while (portal.getNext());
  310. }
  311. }
  312.  
  313. return false;
  314. };
  315.  
  316. // Performs a check before trying to kill to allow recovery mode
  317. // to continue on with the script
  318. this.recoverableKill = function (unit, recoveryMode = false) {
  319. if (getUnit(1, unit)) {
  320. Attack.kill(unit);
  321. return true;
  322. } else if (!recoveryMode) {
  323. // We are not in recovery mode and we didn't find the boss
  324. throw new Error(unit + " not found");
  325. } else {
  326. // No else needed, we will go back to town and then mark this area as cleared
  327. // but there was a Strict Warning from the compiler
  328. print(unit + " not found");
  329. return false;
  330. }
  331. }
  332.  
  333. // Do mini ubers or Tristram based on area we're already in
  334. this.pandemoniumRun = function (recoveryMode = false) {
  335. var i, findLoc, skillBackup;
  336.  
  337. switch (me.area) {
  338. case 133: // Matron's Den
  339. Precast.doPrecast(true);
  340. Pather.moveToPreset(133, 2, 397, 2, 2);
  341.  
  342. // If Lilith is there and we have ED, go heal first
  343. // the minions may apply again, but if we caught on the way it should still help
  344. if (me.getState(9) && (getUnit(1, 707))) {
  345. D2Bot.printToConsole("We have ED! Getting Heals")
  346. // Get healing
  347. Town.initNPC("Heal", "heal");
  348. // move back to portal
  349. D2Bot.printToConsole("Going back for more")
  350. Town.move("portalspot");
  351. // Take portal 133, we just came from it
  352. D2Bot.printToConsole("Jumping in")
  353. Pather.usePortal(133);
  354. // Move to her again just to be sure
  355. Pather.moveToPreset(133, 2, 397, 2, 2);
  356. }
  357.  
  358. this.recoverableKill(707, recoveryMode);
  359. Pickit.pickItems();
  360. Town.goToTown();
  361.  
  362. break;
  363. case 134: // Forgotten Sands
  364. Precast.doPrecast(true);
  365.  
  366. findLoc = [20196, 8694, 20308, 8588, 20187, 8639, 20100, 8550, 20103, 8688, 20144, 8709, 20263, 8811, 20247, 8665];
  367.  
  368. for (i = 0; i < findLoc.length; i += 2) {
  369. Pather.moveTo(findLoc[i], findLoc[i + 1]);
  370. delay(500);
  371.  
  372. if (getUnit(1, 708)) {
  373. break;
  374. }
  375. }
  376.  
  377. this.recoverableKill(708, recoveryMode);
  378. Pickit.pickItems();
  379. Town.goToTown();
  380.  
  381. break;
  382. case 135: // Furnace of Pain
  383. Precast.doPrecast(true);
  384. Pather.moveToPreset(135, 2, 397, 2, 2);
  385.  
  386. this.recoverableKill(706, recoveryMode);
  387. Pickit.pickItems();
  388. Town.goToTown();
  389.  
  390. break;
  391. case 136: // Tristram
  392. Pather.moveTo(25068, 5078);
  393. Precast.doPrecast(true);
  394.  
  395. findLoc = [25040, 5101, 25040, 5166, 25122, 5170];
  396.  
  397. for (i = 0; i < findLoc.length; i += 2) {
  398. Pather.moveTo(findLoc[i], findLoc[i + 1]);
  399. }
  400.  
  401. var antiMephistoSpell = 0;
  402.  
  403. if (Config.OrgTorch.UseSalvation && me.classid === 3 && me.getSkill(125, 1)) {
  404. antiMephistoSpell = 125;
  405. } else if (Config.OrgTorch.UseConviction && me.classid === 3 && me.getSkill(123, 1)) {
  406. antiMephistoSpell = 123;
  407. }
  408.  
  409. Skill.setSkill(antiMephistoSpell, 0);
  410. this.lure(704);
  411. Pather.moveTo(25129, 5198);
  412. Skill.setSkill(antiMephistoSpell, 0);
  413. this.lure(704);
  414.  
  415. if (!getUnit(1, 704)) {
  416. Pather.moveTo(25122, 5170);
  417. }
  418.  
  419. if (antiMephistoSpell) {
  420. skillBackup = Config.AttackSkill[2];
  421. Config.AttackSkill[2] = antiMephistoSpell;
  422.  
  423. Attack.init();
  424. }
  425.  
  426. this.recoverableKill(704, recoveryMode);
  427.  
  428. if (skillBackup && me.classid === 3 && me.getSkill(skillBackup, 1)) {
  429. Config.AttackSkill[2] = skillBackup;
  430.  
  431. Attack.init();
  432. }
  433.  
  434. Pather.moveTo(25162, 5141);
  435. // TODO: Change this to a loop to wait for baal. use 100ms loops
  436. delay(3250);
  437.  
  438. if (!getUnit(1, 709)) {
  439. Pather.moveTo(25122, 5170);
  440. }
  441.  
  442. this.recoverableKill(709, recoveryMode);
  443.  
  444. if (!getUnit(1, 705)) {
  445. Pather.moveTo(25122, 5170);
  446. }
  447.  
  448. this.recoverableKill(705, recoveryMode);
  449. Pickit.pickItems();
  450. this.checkTorch();
  451.  
  452. break;
  453. }
  454. };
  455.  
  456. this.juvCheck = function () {
  457. var i,
  458. needJuvs = 0,
  459. col = Town.checkColumns(Storage.BeltSize());
  460.  
  461. for (i = 0; i < 4; i += 1) {
  462. if (Config.BeltColumn[i] === "rv") {
  463. needJuvs += col[i];
  464. }
  465. }
  466.  
  467. // print("Need " + needJuvs + " juvs.");
  468.  
  469. return needJuvs;
  470. };
  471.  
  472. // Assumes we are in town. Moves to vendor, buys potions and drinks 1 at a time to save space
  473. // Parts copied from AutoSmurf
  474. this.vendorBuyAndDrink = function(vendorName, potionId, potionCount) {
  475. var i, vendor, vendorPotions, myPotions;
  476. Town.move(vendorName);
  477.  
  478. print("Pre-buffing potion " + potionId + " x" + potionCount + " from " + vendorName);
  479. vendor = getUnit(1, vendorName);
  480.  
  481. if (vendor) {
  482. //print("Starting trade");
  483. vendor.startTrade();
  484.  
  485. // high ping delay
  486. delay(me.ping * 2);
  487.  
  488. // print("finding drink");
  489. // Buy and drink Antidote potions
  490. vendorPotions = vendor.getItem(potionId);
  491.  
  492. // high ping delay
  493. delay(me.ping * 2);
  494.  
  495. for (i = 0 ; i < potionCount ; i += 1) {
  496. vendorPotions.buy();
  497. // print("buying drink");
  498. myPotions = me.findItems(potionId, -1, 3);
  499.  
  500. if (myPotions.length) {
  501. // print("drinking drink");
  502. myPotions[0].interact();
  503. delay(me.ping * 2);
  504. }
  505. }
  506.  
  507. me.cancel();
  508. }
  509. };
  510.  
  511. // TODO: Improve this to use run time for configuration
  512. this.preBuffResistance = function(potionCount = 24) {
  513. this.vendorBuyAndDrink("malah", 514, potionCount);
  514. this.vendorBuyAndDrink("malah", 517, potionCount);
  515.  
  516. this.PreBuffTick = getTickCount() + potionCount * 30000;
  517.  
  518. return true;
  519. };
  520.  
  521. this.needComponents = function() {
  522. var tkeys, hkeys, dkeys, brains, eyes, horns;
  523. tkeys = me.findItems("pk1", 0).length || 0;
  524. hkeys = me.findItems("pk2", 0).length || 0;
  525. dkeys = me.findItems("pk3", 0).length || 0;
  526. brains = me.findItems("mbr", 0).length || 0;
  527. eyes = me.findItems("bey", 0).length || 0;
  528. horns = me.findItems("dhn", 0).length || 0;
  529.  
  530. if ((tkeys >= 3 && hkeys >= 3 && dkeys >= 3) ||
  531. (brains >= 1 && eyes >= 1 && horns >= 1)) {
  532.  
  533. return false;
  534. } else {
  535. return true;
  536. }
  537. };
  538.  
  539. this.getRecoverPortals = function() {
  540. var checkPortal, checkPortals;
  541.  
  542. // Make sure we are in A5 by stash
  543. Town.goToTown(5);
  544. Town.move("stash");
  545.  
  546. // Try to get a portal
  547. checkPortal = getUnit(2, "portal");
  548. checkPortals = [];
  549.  
  550. if (checkPortal) {
  551. do {
  552. // Look for a pandemonium portal that is not in our list of done areas
  553. if ([133, 134, 135, 136].indexOf(checkPortal.objtype) > -1 && this.doneAreas.indexOf(checkPortal.objtype) === -1) {
  554. checkPortals.push(copyUnit(checkPortal));
  555. }
  556. } while (checkPortal.getNext());
  557. }
  558.  
  559. if (checkPortals.length > 0) {
  560. // Sort the portals descending so we get Uber Tristram first if it's open
  561. checkPortals.sort(function(a,b) { return a.objtype <= b.objtype; });
  562.  
  563. // If the first portal is uber tristram then drop the rest to avoid too many loops
  564. if (checkPortals[0].objtype == 136) {
  565. checkPortals = checkPortals.slice(0,1);
  566. }
  567. }
  568.  
  569. return checkPortals;
  570. };
  571.  
  572. this.recoverPortal = function(checkPortals) {
  573. var targetPortal;
  574. print("Attempting portal recovery");
  575.  
  576. // Make sure we are in A5 by stash
  577. Town.goToTown(5);
  578. Town.move("stash");
  579.  
  580. if (checkPortals.length > 0) {
  581. checkPortals.forEach((targetPortal) => {
  582. D2Bot.printToConsole("Recovering portal " + targetPortal.objtype);
  583. D2Bot.printToConsole("OrgTorch: Recovering portal " + targetPortal.objtype, 7);
  584.  
  585. // We already did chores at the beginning of the script, so now we just need to pre-bufferDepth
  586. this.getFade();
  587. Town.move("stash");
  588. print("Done pre-buffing");
  589. Pather.usePortal(null, null, targetPortal);
  590. this.pandemoniumRun(true);
  591. this.doneAreas.push(targetPortal.objtype); // Don't count the area as done until we're complete
  592. });
  593. return true;
  594. } else {
  595. print("No portal to recover");
  596. return false;
  597. }
  598. };
  599.  
  600. // Start
  601. var i, portal, recoverPortals, tkeys, hkeys, dkeys, neededKeys, brains, eyes, horns, timer, farmer, busy, busyTick,
  602. neededItems = {pk1: 0, pk2: 0, pk3: 0, rv: 0};
  603.  
  604. // Do town chores and quit if MakeTorch is true and we have a torch.
  605. // This does not guarantee which act we are in
  606. print("Doing initial torch check");
  607. this.checkTorch();
  608.  
  609. print("Done checking torch, moving on");
  610.  
  611. if (me.diff == 2) {
  612. // we are in hell. let's see if there's any portals to recover
  613. var recoverPortals = this.getRecoverPortals();
  614.  
  615. if (recoverPortals.length > 0) {
  616. this.preBuffResistance();
  617.  
  618. // Try to recover an existing portal before running the check
  619. // TODO: Improve item check to count completed areas + remaining keysets
  620. while (this.recoverPortal(recoverPortals)) {
  621. // Run until all portals are checked
  622. }
  623. } else {
  624. print("No portals to recover");
  625. }
  626. }
  627.  
  628. // Do an initial count so we can decide if we need to
  629. // do run, wait for keys, or close profile
  630. tkeys = me.findItems("pk1", 0).length || 0;
  631. hkeys = me.findItems("pk2", 0).length || 0;
  632. dkeys = me.findItems("pk3", 0).length || 0;
  633.  
  634. // Get the number of needed keys
  635. neededItems = {pk1: 3 * Config.OrgTorch.WaitForKeys - tkeys, pk2: 3 * Config.OrgTorch.WaitForKeys - hkeys, pk3: 3 * Config.OrgTorch.WaitForKeys - dkeys, rv: this.juvCheck()};
  636.  
  637. // We won't wait for keys until we don't have enough for a run
  638. if (this.needComponents() &&
  639. Config.OrgTorch.WaitForKeys) {
  640. // This means we don't have enough keys to do a run
  641. // but we are configured to wait for them
  642.  
  643. // TODO: Make this a profile config to determine where to wait for keys
  644. if (me.diff == 2) {
  645. D2Bot.setProfile("qsd2", "forquinton", "rioteer", "Normal", "Asia", "", "B:\\D2_2\\Game.exe");
  646. D2Bot.restart(false);
  647. }
  648.  
  649. D2Bot.printToConsole("Waiting for keys: " + neededItems.pk1 + "x T, " + neededItems.pk2 + "x H, " + neededItems.pk3 + "x D");
  650.  
  651. timer = getTickCount();
  652.  
  653. // Check if current character is the farmer
  654. farmer = TorchSystem.isFarmer();
  655.  
  656. this.torchSystemEvent = function (mode, msg) {
  657. var obj, farmer;
  658.  
  659. if (mode === 6) {
  660. farmer = TorchSystem.isFarmer();
  661.  
  662. if (farmer) {
  663. obj = JSON.parse(msg);
  664.  
  665. if (obj) {
  666. switch (obj.name) {
  667. case "gameCheck":
  668. if (busy) {
  669. break;
  670. }
  671.  
  672. if (farmer.KeyFinderProfiles.indexOf(obj.profile) > -1) {
  673. print("Got game request from: " + obj.profile);
  674. sendCopyData(null, obj.profile, 6, JSON.stringify({name: "gameName", value: {gameName: me.gamename, password: me.gamepassword}}));
  675.  
  676. busy = true;
  677. busyTick = getTickCount();
  678. }
  679.  
  680. break;
  681. case "keyCheck":
  682. if (farmer.KeyFinderProfiles.indexOf(obj.profile) > -1) {
  683. print("Got key count request from: " + obj.profile);
  684.  
  685. sendCopyData(null, obj.profile, 6, JSON.stringify({name: "neededItems", value: neededItems}));
  686. }
  687.  
  688. break;
  689. }
  690. }
  691. }
  692. }
  693. };
  694.  
  695. // Register event that will communicate with key hunters, go to Act 1 town and wait by stash
  696. addEventListener('copydata', this.torchSystemEvent);
  697. Town.goToTown(1);
  698. Town.move("stash");
  699.  
  700. // clearing potions, need to optimize this
  701. Town.clearInventory();
  702.  
  703. print("Starting to wait...");
  704. while (true) {
  705. // Abort if the current character is a farmer
  706. if (farmer) {
  707. break;
  708. }
  709.  
  710. // Free up inventory
  711. if (Town.needStash()) {
  712. Town.stash();
  713. me.cancel();
  714. D2Bot.printToConsole("keys needed: " + neededItems.pk1 + "x T, " + neededItems.pk2 + "x H, " + neededItems.pk3 + "x D");
  715. }
  716.  
  717. // Get the number keys
  718. tkeys = me.findItems("pk1", 0).length || 0;
  719. hkeys = me.findItems("pk2", 0).length || 0;
  720. dkeys = me.findItems("pk3", 0).length || 0;
  721.  
  722. neededItems = {pk1: 3 * Config.OrgTorch.WaitForKeys - tkeys, pk2: 3 * Config.OrgTorch.WaitForKeys - hkeys, pk3: 3 * Config.OrgTorch.WaitForKeys - dkeys, rv: this.juvCheck()};
  723.  
  724. // Stop the loop if we have enough keys or if wait time expired
  725. if (((neededItems.pk1 == 0 &&
  726. neededItems.pk2 == 0 &&
  727. neededItems.pk3 == 0) ||
  728. (Config.OrgTorch.WaitTimeout && (getTickCount() - timer > Config.OrgTorch.WaitTimeout * 1000 * 60))) && this.aloneInGame()) {
  729. removeEventListener('copydata', this.torchSystemEvent);
  730.  
  731. break;
  732. }
  733.  
  734. if (busy) {
  735. busyTick = getTickCount();
  736. while (getTickCount() - busyTick < 30000) {
  737. if (!this.aloneInGame()) {
  738. break;
  739. }
  740.  
  741. delay(100);
  742. }
  743.  
  744. if (getTickCount() - busyTick > 30000 || this.aloneInGame()) {
  745. busy = false;
  746. }
  747. }
  748.  
  749. // Wait for other characters to leave
  750. while (!this.aloneInGame()) {
  751. delay(500);
  752. }
  753.  
  754. delay(1000);
  755.  
  756. // Pick the keys after the hunters drop them and leave the game
  757. Pickit.pickItems();
  758.  
  759. }
  760. print("Done waiting...");
  761.  
  762. }
  763.  
  764. D2Bot.printToConsole("Finished with keys needed: " + neededItems.pk1 + "x T, " + neededItems.pk2 + "x H, " + neededItems.pk3 + "x D");
  765.  
  766. // We are about to start our run script. Make sure we are in hell
  767. if (me.diff < 2) {
  768. D2Bot.printToConsole("OrgTorch: Ready to run, but we're not in Hell. Changing profile and returning");
  769. D2Bot.setProfile("qsd2", "forquinton", "rioteer", "Hell", "Asia", "", "B:\\D2_2\\Game.exe");
  770. D2Bot.restart(false);
  771. return true;
  772. }
  773.  
  774.  
  775. // Count keys and organs
  776. tkeys = me.findItems("pk1", 0).length || 0;
  777. hkeys = me.findItems("pk2", 0).length || 0;
  778. dkeys = me.findItems("pk3", 0).length || 0;
  779. brains = me.findItems("mbr", 0).length || 0;
  780. eyes = me.findItems("bey", 0).length || 0;
  781. horns = me.findItems("dhn", 0).length || 0;
  782.  
  783. // We only need as many keys as unopened red portals
  784. // We assume we have recovered all portals or have the organs already
  785. neededKeys = 3 - this.doneAreas.length;
  786.  
  787. // End the script if we don't have enough keys nor organs
  788. if ((tkeys < neededKeys || hkeys < neededKeys || dkeys < neededKeys) && (brains < 1 || eyes < 1 || horns < 1)) {
  789. D2Bot.printToConsole("Not enough keys or organs. Stopping Profile");
  790. D2Bot.stop();
  791. return true;
  792. }
  793.  
  794. Config.UseMerc = false;
  795.  
  796. // Todo - optimize this to only re-buff if we waited for keys
  797. this.preBuffResistance();
  798.  
  799. // We have enough keys, do mini ubers
  800. if (tkeys >= neededKeys && hkeys >= neededKeys && dkeys >= neededKeys) {
  801. this.getFade(75000); // We need at least 75 seconds for the mini bosses
  802. print("Making organs.");
  803. D2Bot.printToConsole("OrgTorch: Making organs.", 7);
  804.  
  805. for (i = 0; i < neededKeys; i += 1) {
  806. // Abort if we have a complete set of organs
  807. // If Config.OrgTorch.MakeTorch is false, check after at least one portal is made
  808. if ((Config.OrgTorch.MakeTorch || i > 0) && this.completeSetCheck()) {
  809. break;
  810. }
  811.  
  812. portal = this.openPortal(0);
  813.  
  814. if (portal) {
  815. Pather.usePortal(null, null, portal);
  816. }
  817.  
  818. this.pandemoniumRun();
  819. this.doneAreas.push(portal.objtype); // Don't count the area as done until we're complete
  820. }
  821. }
  822.  
  823. // Don't make torches if not configured to OR if the char already has one
  824. if (!Config.OrgTorch.MakeTorch || this.checkTorch()) {
  825. return true;
  826. }
  827.  
  828. // Count organs
  829. brains = me.findItems("mbr", 0).length || 0;
  830. eyes = me.findItems("bey", 0).length || 0;
  831. horns = me.findItems("dhn", 0).length || 0;
  832.  
  833. // We have enough organs, do Tristram
  834. if (brains && eyes && horns) {
  835. this.getFade(95000);
  836. print("Making torch");
  837. D2Bot.printToConsole("OrgTorch: Making torch.", 7);
  838.  
  839. portal = this.openPortal(1);
  840.  
  841. if (portal) {
  842. Pather.usePortal(null, null, portal);
  843. }
  844.  
  845. this.pandemoniumRun();
  846. }
  847.  
  848. D2Bot.printToConsole("Full Finish gold: " + me.gold);
  849.  
  850. if (this.needComponents()) {
  851. D2Bot.setProfile("qsd2", "forquinton", "rioteer", "Normal", "West", "", "B:\\D2_1\\Game5.exe");
  852. }
  853.  
  854. return true;
  855. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement