Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.19 KB | None | 0 0
  1. /**
  2. * @filename DiabloHelper.js
  3. * @author kolton
  4. * @desc help leading player in clearing Chaos Sanctuary and killing Diablo
  5. */
  6.  
  7. function DiabloHelper() {
  8. // Sort function
  9. this.sort = function (a, b) {
  10. if (Config.BossPriority) {
  11. if ((a.spectype & 0x5) && (b.spectype & 0x5)) {
  12. return getDistance(me, a) - getDistance(me, b);
  13. }
  14.  
  15. if (a.spectype & 0x5) {
  16. return -1;
  17. }
  18.  
  19. if (b.spectype & 0x5) {
  20. return 1;
  21. }
  22. }
  23.  
  24. // Entrance to Star / De Seis
  25. if (me.y > 5325 || me.y < 5260) {
  26. if (a.y > b.y) {
  27. return -1;
  28. }
  29.  
  30. return 1;
  31. }
  32.  
  33. // Vizier
  34. if (me.x < 7765) {
  35. if (a.x > b.x) {
  36. return -1;
  37. }
  38.  
  39. return 1;
  40. }
  41.  
  42. // Infector
  43. if (me.x > 7825) {
  44. if (!checkCollision(me, a, 0x1) && a.x < b.x) {
  45. return -1;
  46. }
  47.  
  48. return 1;
  49. }
  50.  
  51. return getDistance(me, a) - getDistance(me, b);
  52. };
  53.  
  54. // general functions
  55. this.getLayout = function (seal, value) {
  56. var sealPreset = getPresetUnit(108, 2, seal);
  57.  
  58. if (!seal) {
  59. throw new Error("Seal preset not found. Can't continue");
  60. }
  61.  
  62. if (sealPreset.roomy * 5 + sealPreset.y === value || sealPreset.roomx * 5 + sealPreset.x === value) {
  63. return 1;
  64. }
  65.  
  66. return 2;
  67. };
  68.  
  69. this.initLayout = function () {
  70. this.vizLayout = this.getLayout(396, 5275); // 1 = "Y", 2 = "L"
  71. this.seisLayout = this.getLayout(394, 7773); // 1 = "2", 2 = "5"
  72. this.infLayout = this.getLayout(392, 7893); // 1 = "I", 2 = "J"
  73. };
  74.  
  75. this.getBoss = function (name) {
  76. var i, boss, glow;
  77.  
  78. while (true) {
  79. if (!this.preattack(name)) {
  80. delay(500);
  81. }
  82.  
  83. glow = getUnit(2, 131);
  84.  
  85. if (glow) {
  86. break;
  87. }
  88. }
  89.  
  90. for (i = 0; i < 16; i += 1) {
  91. boss = getUnit(1, name);
  92.  
  93. if (boss) {
  94. return Attack.clear(40, 0, name, this.sort);
  95. }
  96.  
  97. delay(250);
  98. }
  99.  
  100. return !!glow;
  101. };
  102.  
  103. this.vizierSeal = function () {
  104. this.followPath(this.vizLayout === 1 ? this.starToVizA : this.starToVizB, this.sort);
  105.  
  106. if (this.vizLayout === 1) {
  107. Pather.moveTo(7691, 5292);
  108. } else {
  109. Pather.moveTo(7695, 5316);
  110. }
  111.  
  112. if (!this.getBoss(getLocaleString(2851))) {
  113. throw new Error("Failed to kill Vizier");
  114. }
  115.  
  116. if (Config.FieldID) {
  117. Town.fieldID();
  118. }
  119.  
  120. return true;
  121. };
  122.  
  123. this.seisSeal = function () {
  124. this.followPath(this.seisLayout === 1 ? this.starToSeisA : this.starToSeisB, this.sort);
  125.  
  126. if (this.seisLayout === 1) {
  127. Pather.moveTo(7771, 5196);
  128. } else {
  129. Pather.moveTo(7798, 5186);
  130. }
  131.  
  132. if (!this.getBoss(getLocaleString(2852))) {
  133. throw new Error("Failed to kill de Seis");
  134. }
  135.  
  136. if (Config.FieldID) {
  137. Town.fieldID();
  138. }
  139.  
  140. return true;
  141. };
  142.  
  143. this.infectorSeal = function () {
  144. this.followPath(this.infLayout === 1 ? this.starToInfA : this.starToInfB, this.sort);
  145.  
  146. if (this.infLayout === 1) {
  147. delay(1);
  148. } else {
  149. Pather.moveTo(7928, 5295); // temp
  150. }
  151.  
  152. if (!this.getBoss(getLocaleString(2853))) {
  153. throw new Error("Failed to kill Infector");
  154. }
  155.  
  156. if (Config.FieldID) {
  157. Town.fieldID();
  158. }
  159.  
  160. return true;
  161. };
  162.  
  163. this.diabloPrep = function () {
  164. var trapCheck,
  165. tick = getTickCount();
  166.  
  167. while (getTickCount() - tick < 30000) {
  168. if (getTickCount() - tick >= 8000) {
  169. switch (me.classid) {
  170. case 1: // Sorceress
  171. if ([56, 59, 64].indexOf(Config.AttackSkill[1]) > -1) {
  172. if (me.getState(121)) {
  173. delay(500);
  174. } else {
  175. Skill.cast(Config.AttackSkill[1], 0, 7793, 5293);
  176. }
  177.  
  178. break;
  179. }
  180.  
  181. delay(500);
  182.  
  183. break;
  184. case 3: // Paladin
  185. Skill.setSkill(Config.AttackSkill[2]);
  186. Skill.cast(Config.AttackSkill[1], 1);
  187.  
  188. break;
  189. case 5: // Druid
  190. if (Config.AttackSkill[1] === 245) {
  191. Skill.cast(Config.AttackSkill[1], 0, 7793, 5293);
  192.  
  193. break;
  194. }
  195.  
  196. delay(500);
  197.  
  198. break;
  199. case 6: // Assassin
  200. if (Config.UseTraps) {
  201. trapCheck = ClassAttack.checkTraps({x: 7793, y: 5293});
  202.  
  203. if (trapCheck) {
  204. ClassAttack.placeTraps({x: 7793, y: 5293, classid: 243}, trapCheck);
  205.  
  206. break;
  207. }
  208. }
  209.  
  210. delay(500);
  211.  
  212. break;
  213. default:
  214. delay(500);
  215.  
  216. break;
  217. }
  218. } else {
  219. delay(500);
  220. }
  221.  
  222. if (getUnit(1, 243)) {
  223. return true;
  224. }
  225. }
  226.  
  227. throw new Error("Diablo not found");
  228. };
  229.  
  230. this.preattack = function (id) {
  231. var trapCheck,
  232. coords = [];
  233.  
  234. switch (id) {
  235. case getLocaleString(2851):
  236. if (this.vizLayout === 1) {
  237. coords = [7676, 5295];
  238. }
  239.  
  240. coords = [7684, 5318];
  241.  
  242. break;
  243. case getLocaleString(2852):
  244. if (this.seisLayout === 1) {
  245. coords = [7778, 5216];
  246. }
  247.  
  248. coords = [7775, 5208];
  249.  
  250. break;
  251. case getLocaleString(2853):
  252. if (this.infLayout === 1) {
  253. coords = [7913, 5292];
  254. }
  255.  
  256. coords = [7915, 5280];
  257.  
  258. break;
  259. }
  260.  
  261. switch (me.classid) {
  262. case 1:
  263. if ([56, 59, 64].indexOf(Config.AttackSkill[1]) > -1) {
  264. if (me.getState(121)) {
  265. delay(500);
  266. } else {
  267. Skill.cast(Config.AttackSkill[1], 0, coords[0], coords[1]);
  268. }
  269.  
  270. return true;
  271. }
  272.  
  273. break;
  274. case 3:
  275. break;
  276. case 6:
  277. if (Config.UseTraps) {
  278. trapCheck = ClassAttack.checkTraps({x: coords[0], y: coords[1]});
  279.  
  280. if (trapCheck) {
  281. ClassAttack.placeTraps({x: coords[0], y: coords[1]}, 5);
  282.  
  283. return true;
  284. }
  285. }
  286.  
  287. break;
  288. }
  289.  
  290. return false;
  291. };
  292.  
  293. this.followPath = function (path) {
  294. var i;
  295.  
  296. for (i = 0; i < path.length; i += 2) {
  297. if (this.cleared.length) {
  298. this.clearStrays();
  299. }
  300.  
  301. Pather.moveTo(path[i], path[i + 1], 3, getDistance(me, path[i], path[i + 1]) > 50);
  302. Attack.clear(30, 0, false, this.sort);
  303.  
  304. // Push cleared positions so they can be checked for strays
  305. this.cleared.push([path[i], path[i + 1]]);
  306.  
  307. // After 5 nodes go back 2 nodes to check for monsters
  308. if (i === 10 && path.length > 16) {
  309. path = path.slice(6);
  310. i = 0;
  311. }
  312. }
  313. };
  314.  
  315. this.clearStrays = function () {
  316. /*if (!Config.PublicMode) {
  317. return false;
  318. }*/
  319.  
  320. var i,
  321. oldPos = {x: me.x, y: me.y},
  322. monster = getUnit(1);
  323.  
  324. if (monster) {
  325. do {
  326. if (Attack.checkMonster(monster)) {
  327. for (i = 0; i < this.cleared.length; i += 1) {
  328. if (getDistance(monster, this.cleared[i][0], this.cleared[i][1]) < 30 && Attack.validSpot(monster.x, monster.y)) {
  329. me.overhead("we got a stray");
  330. Pather.moveToUnit(monster);
  331. Attack.clear(15, 0, false, this.sort);
  332.  
  333. break;
  334. }
  335. }
  336. }
  337. } while (monster.getNext());
  338. }
  339.  
  340. if (getDistance(me, oldPos.x, oldPos.y) > 5) {
  341. Pather.moveTo(oldPos.x, oldPos.y);
  342. }
  343.  
  344. return true;
  345. };
  346.  
  347. this.cleared = [];
  348.  
  349. // path coordinates
  350. this.entranceToStar = [7794, 5517, 7791, 5491, 7768, 5459, 7775, 5424, 7817, 5458, 7777, 5408, 7769, 5379, 7777, 5357, 7809, 5359, 7805, 5330, 7780, 5317, 7774, 5305];
  351. this.starToVizA = [7759, 5295, 7734, 5295, 7716, 5295, 7718, 5276, 7697, 5292, 7678, 5293, 7665, 5276, 7662, 5314];
  352. this.starToVizB = [7759, 5295, 7734, 5295, 7716, 5295, 7701, 5315, 7666, 5313, 7653, 5284];
  353. this.starToSeisA = [7781, 5259, 7805, 5258, 7802, 5237, 7776, 5228, 7775, 5205, 7804, 5193, 7814, 5169, 7788, 5153];
  354. this.starToSeisB = [7781, 5259, 7805, 5258, 7802, 5237, 7776, 5228, 7811, 5218, 7807, 5194, 7779, 5193, 7774, 5160, 7803, 5154];
  355. this.starToInfA = [7809, 5268, 7834, 5306, 7852, 5280, 7852, 5310, 7869, 5294, 7895, 5295, 7919, 5290];
  356. this.starToInfB = [7809, 5268, 7834, 5306, 7852, 5280, 7852, 5310, 7869, 5294, 7895, 5274, 7927, 5275, 7932, 5297, 7923, 5313];
  357.  
  358. var i, party;
  359.  
  360. // start
  361. Town.doChores();
  362.  
  363. if (Config.DiabloHelper.SkipIfBaal) {
  364. AreaInfoLoop:
  365. while (true) {
  366. me.overhead("Getting party area info");
  367.  
  368. if (Misc.getPlayerCount() <= 1) {
  369. throw new Error("Empty game"); // Alone in game
  370. }
  371.  
  372. party = getParty();
  373.  
  374. if (party) {
  375. do {
  376. if (party.name !== me.name && party.area) {
  377. break AreaInfoLoop; // Can read player area
  378. }
  379. } while (party.getNext());
  380. }
  381.  
  382. delay(1000);
  383. }
  384.  
  385. party = getParty();
  386.  
  387. if (party) {
  388. do {
  389. if (party.area === 131 || party.area === 132) { // Player is in Throne of Destruction or Worldstone Chamber
  390. return false; // End script
  391. }
  392. } while (party.getNext());
  393. }
  394. }
  395.  
  396. Pather.useWaypoint(Config.RandomPrecast ? "random" : 106);
  397. Precast.doPrecast(true);
  398.  
  399. if (Config.DiabloHelper.SkipTP) {
  400. if (me.area !== 106) {
  401. Pather.useWaypoint(106);
  402. }
  403.  
  404. if (!Pather.moveToExit([107, 108 ], true)) {
  405. Attack.clearLevel(Config.ClearType);
  406. }
  407. if (!Pather.moveTo(7790, 5544)) {
  408. Attack.clearLevel(Config.ClearType);
  409. }
  410.  
  411.  
  412. if (!Config.DiabloHelper.Entrance) {
  413. Pather.moveTo(7774, 5305);
  414. }
  415.  
  416. CSLoop:
  417. for (i = 0; i < Config.DiabloHelper.Wait; i += 1) {
  418. party = getParty();
  419.  
  420. if (party) {
  421. do {
  422. if (party.name !== me.name && party.area === 108 && (!Config.Leader || party.name === Config.Leader)) {
  423. break CSLoop;
  424. }
  425. } while (party.getNext());
  426. }
  427.  
  428. Attack.clear(30, 0, false, this.sort);
  429. delay(1000);
  430. }
  431.  
  432. if (i === Config.DiabloHelper.Wait) {
  433. throw new Error("Player wait timed out (" + (Config.Leader ? "Leader not" : "No players") + " found in Chaos)");
  434. }
  435. } else {
  436. Pather.useWaypoint(103);
  437. Town.move("portalspot");
  438.  
  439. for (i = 0; i < Config.DiabloHelper.Wait; i += 1) {
  440. if (Pather.getPortal(108, Config.Leader || null) && Pather.usePortal(108, Config.Leader || null)) {
  441. break;
  442. }
  443.  
  444. delay(1000);
  445. }
  446.  
  447. if (i === Config.DiabloHelper.Wait) {
  448. throw new Error("Player wait timed out (" + (Config.Leader ? "No leader" : "No player") + " portals found)");
  449. }
  450. }
  451.  
  452. this.initLayout();
  453.  
  454. if (Config.DiabloHelper.Entrance) {
  455. Attack.clear(35, 0, false, this.sort);
  456. this.followPath(this.entranceToStar);
  457. } else {
  458. Pather.moveTo(7774, 5305);
  459. Attack.clear(35, 0, false, this.sort);
  460. }
  461.  
  462. Pather.moveTo(7774, 5305);
  463. Attack.clear(35, 0, false, this.sort);
  464. this.vizierSeal();
  465. this.seisSeal();
  466. Precast.doPrecast(true);
  467. this.infectorSeal();
  468.  
  469. switch (me.classid) {
  470. case 1:
  471. Pather.moveTo(7793, 5291);
  472.  
  473. break;
  474. default:
  475. Pather.moveTo(7788, 5292);
  476.  
  477. break;
  478. }
  479.  
  480. this.diabloPrep();
  481. Attack.kill(243); // Diablo
  482. Pickit.pickItems();
  483.  
  484. return true;
  485. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement