Advertisement
kolton

Untitled

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