Advertisement
gtoilet

Enchantbo

Jun 23rd, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.35 KB | None | 0 0
  1. /**
  2. * @filename Enchantbo.js
  3. * @author kolton
  4. * @desc Enchant other players, open cow portal and give waypoints on command
  5. *
  6. * Config.Enchant.Triggers = ["chant", "cows", "wps","bo"]; //
  7. */
  8.  
  9. function Enchantbo() {
  10. var command, hostile, nick, spot, tick, s, m,
  11. startTime = getTickCount(),
  12. shitList = [],
  13. greet = [];
  14. this.haveCTA = -1;
  15. this.checkCTA = function () {
  16. var item;
  17.  
  18. if (this.haveCTA > -1) {
  19. return true;
  20. }
  21.  
  22. item = me.getItem(-1, 1);
  23.  
  24. if (item) {
  25. do {
  26. if (item.getPrefix(20519)) { // Call to Arms
  27. switch (item.bodylocation) {
  28. case 4:
  29. case 5:
  30. this.haveCTA = me.weaponswitch;
  31.  
  32. return true;
  33. case 11:
  34. case 12:
  35. this.haveCTA = me.weaponswitch ^ 1;
  36.  
  37. return true;
  38. }
  39. }
  40. } while (item.getNext());
  41. }
  42.  
  43. return false;
  44. };
  45.  
  46. this.bo = function (nick) {
  47. Pather.useWaypoint(35, true);
  48. Attack.weaponSwitch(this.haveCTA);
  49. Skill.cast(155, 0); // Battle Command
  50. Skill.cast(149, 0); // Battle Orders
  51. Attack.weaponSwitch();
  52. Pather.useWaypoint(1, true);
  53. };
  54.  
  55. this.enchant = function (nick) {
  56. if (!Misc.inMyParty(nick)) {
  57. say("Accept party invite, noob.");
  58.  
  59. return false;
  60. }
  61.  
  62. var partyUnit,
  63. unit = getUnit(0, nick);
  64.  
  65. if (getDistance(me, unit) > 35) {
  66. say("Get closer.");
  67.  
  68. return false;
  69. }
  70.  
  71. if (!unit) {
  72. partyUnit = getParty(nick);
  73.  
  74. // wait until party area is readable?
  75.  
  76. if ([40, 75, 103, 109].indexOf(partyUnit.area) > -1) {
  77. say("Wait for me at waypoint.");
  78. Town.goToTown([1, 40, 75, 103, 109].indexOf(partyUnit.area) + 1); // index+1 for town 2,3,4,5
  79.  
  80. unit = getUnit(0, nick);
  81. } else {
  82. say("You need to be in one of the towns.");
  83.  
  84. return false;
  85. }
  86. }
  87.  
  88. if (unit) {
  89. do {
  90. if (!unit.dead) { // player is alive
  91. if (getDistance(me, unit) >= 35) {
  92. say("You went too far away.");
  93.  
  94. return false;
  95. }
  96.  
  97. Skill.setSkill(52, 0);
  98. sendPacket(1, 0x11, 4, unit.type, 4, unit.gid);
  99. delay(500);
  100. }
  101. } while (unit.getNext());
  102. } else {
  103. say("Couldn't find you, champ.");
  104. }
  105.  
  106. unit = getUnit(1);
  107.  
  108. if (unit) {
  109. do {
  110. if (unit.getParent() && unit.getParent().name === nick) { // merc or any other owned unit
  111. Skill.setSkill(52, 0);
  112. sendPacket(1, 0x11, 4, unit.type, 4, unit.gid);
  113. delay(500);
  114. }
  115. } while (unit.getNext());
  116. }
  117.  
  118. return true;
  119. };
  120.  
  121. this.autoChant = function () {
  122. var unit,
  123. chanted = [];
  124.  
  125. // Player
  126. unit = getUnit(0);
  127.  
  128. if (unit) {
  129. do {
  130. if (unit.name !== me.name && !unit.dead && shitList.indexOf(unit.name) === -1 && Misc.inMyParty(unit.name) && !unit.getState(16) && getDistance(me, unit) <= 40) {
  131. Skill.setSkill(52, 0);
  132. sendPacket(1, 0x11, 4, unit.type, 4, unit.gid);
  133. delay(500);
  134. chanted.push(unit.name);
  135. }
  136. } while (unit.getNext());
  137. }
  138.  
  139. // Minion
  140. unit = getUnit(1);
  141.  
  142. if (unit) {
  143. do {
  144. if (unit.getParent() && chanted.indexOf(unit.getParent().name) > -1 && !unit.getState(16) && getDistance(me, unit) <= 40) {
  145. Skill.setSkill(52, 0);
  146. sendPacket(1, 0x11, 4, unit.type, 4, unit.gid);
  147. delay(500);
  148. }
  149. } while (unit.getNext());
  150. }
  151.  
  152. return true;
  153. };
  154.  
  155. this.getLeg = function () {
  156. var i, portal, wirt, leg, gid, wrongLeg;
  157.  
  158. if (me.getItem(88)) {
  159. return me.getItem(88);
  160. }
  161.  
  162. if (!Config.Enchant.GetLeg) {
  163. leg = getUnit(4, 88);
  164.  
  165. if (leg) {
  166. do {
  167. if (leg.name.indexOf("ÿc1") > -1) {
  168. wrongLeg = true;
  169. } else if (getDistance(me, leg) <= 15) {
  170. gid = leg.gid;
  171.  
  172. Pickit.pickItem(leg);
  173.  
  174. return me.getItem(-1, -1, gid);
  175. }
  176. } while (leg.getNext());
  177. }
  178.  
  179. say("Bring the leg " + (wrongLeg ? "from this difficulty" : "") + " close to me.");
  180.  
  181. return false;
  182. }
  183.  
  184. Pather.useWaypoint(4);
  185. Precast.doPrecast(true);
  186. Pather.moveToPreset(me.area, 1, 737, 8, 8);
  187.  
  188. for (i = 0; i < 6; i += 1) {
  189. portal = Pather.getPortal(38);
  190.  
  191. if (portal) {
  192. Pather.usePortal(null, null, portal);
  193.  
  194. break;
  195. }
  196.  
  197. delay(500);
  198. }
  199.  
  200. if (!portal) {
  201. say("Failed to enter Tristram :(");
  202. Town.goToTown();
  203.  
  204. return false;
  205. }
  206.  
  207. Pather.moveTo(25048, 5177);
  208.  
  209. wirt = getUnit(2, 268);
  210.  
  211. for (i = 0; i < 8; i += 1) {
  212. wirt.interact();
  213. delay(500);
  214.  
  215. leg = getUnit(4, 88);
  216.  
  217. if (leg) {
  218. gid = leg.gid;
  219.  
  220. Pickit.pickItem(leg);
  221. Town.goToTown();
  222.  
  223. return me.getItem(-1, -1, gid);
  224. }
  225. }
  226.  
  227. Town.goToTown();
  228. say("Failed to get the leg :(");
  229.  
  230. return false;
  231. };
  232.  
  233. this.getTome = function () {
  234. var tome, akara, myTome;
  235.  
  236. myTome = me.findItem("tbk", 0, 3);
  237. tome = me.getItem("tbk");
  238.  
  239. // In case of 2 tomes or tome stuck in cube
  240. if (tome) {
  241. do {
  242. if (!myTome || tome.gid !== myTome.gid) {
  243. return copyUnit(tome);
  244. }
  245. } while (tome.getNext());
  246. }
  247.  
  248. Town.move(NPC.Akara);
  249.  
  250. akara = getUnit(1, NPC.Akara);
  251.  
  252. if (!akara || akara.area !== me.area || getDistance(me, akara) > 20) {
  253. say("Akara not found.");
  254.  
  255. return false;
  256. }
  257.  
  258. myTome = me.findItem("tbk", 0, 3);
  259. tome = me.getItem("tbk");
  260.  
  261. if (tome) {
  262. do {
  263. if (!myTome || tome.gid !== myTome.gid) {
  264. return copyUnit(tome);
  265. }
  266. } while (tome.getNext());
  267. }
  268.  
  269. akara = Town.initNPC("Shop");
  270.  
  271. if (!akara) {
  272. say("Failed to buy tome :(");
  273.  
  274. return false;
  275. }
  276.  
  277. tome = akara.getItem("tbk");
  278.  
  279. if (tome.buy()) {
  280. tome = me.getItem("tbk");
  281.  
  282. if (tome) {
  283. do {
  284. if (!myTome || tome.gid !== myTome.gid) {
  285. return copyUnit(tome);
  286. }
  287. } while (tome.getNext());
  288. }
  289. }
  290.  
  291. return false;
  292. };
  293.  
  294. this.openPortal = function (nick) {
  295. if (!Misc.inMyParty(nick)) {
  296. say("Accept party invite, noob.");
  297.  
  298. return true;
  299. }
  300.  
  301. if (Pather.getPortal(39)) {
  302. say("Cow portal already open.");
  303.  
  304. return true;
  305. }
  306.  
  307. if (me.getQuest(4, 10)) { // king dead or cain not saved
  308. say("Can't open the portal because I killed Cow King.");
  309.  
  310. return false;
  311. }
  312.  
  313. if (Config.Enchant.GetLeg && !me.getQuest(4, 0)) {
  314. say("Can't get leg because I don't have Cain quest.");
  315.  
  316. return false;
  317. }
  318.  
  319. switch (me.gametype) {
  320. case 0: // classic
  321. if (!me.getQuest(26, 0)) { // diablo not completed
  322. say("I don't have Diablo quest.");
  323.  
  324. return false;
  325. }
  326.  
  327. break;
  328. case 1: // expansion
  329. if (!me.getQuest(40, 0)) { // baal not completed
  330. say("I don't have Baal quest.");
  331.  
  332. return false;
  333. }
  334.  
  335. break;
  336. }
  337.  
  338. var i, leg, tome;
  339.  
  340. leg = this.getLeg();
  341.  
  342. if (!leg) {
  343. return false;
  344. }
  345.  
  346. tome = this.getTome();
  347.  
  348. if (!tome) {
  349. return false;
  350. }
  351.  
  352. if (!Town.openStash() || !Cubing.emptyCube() || !Storage.Cube.MoveTo(leg) || !Storage.Cube.MoveTo(tome) || !Cubing.openCube()) {
  353. return false;
  354. }
  355.  
  356. transmute();
  357. delay(500);
  358.  
  359. for (i = 0; i < 10; i += 1) {
  360. if (Pather.getPortal(39)) {
  361. return true;
  362. }
  363.  
  364. delay(200);
  365. }
  366.  
  367. say("Failed to open cow portal.");
  368.  
  369. return false;
  370. };
  371.  
  372. this.getWpNick = function (nick) {
  373. if (!this.wpNicks) {
  374. this.wpNicks = {};
  375. }
  376.  
  377. if (this.wpNicks.hasOwnProperty(nick)) {
  378. if (this.wpNicks[nick].requests > 4) {
  379. return "maxrequests";
  380. }
  381.  
  382. if (getTickCount() - this.wpNicks[nick].timer < 60000) {
  383. return "mintime";
  384. }
  385.  
  386. return true;
  387. }
  388.  
  389. return false;
  390. };
  391.  
  392. this.addWpNick = function (nick) {
  393. this.wpNicks[nick] = {timer: getTickCount(), requests: 0};
  394. };
  395.  
  396. this.giveWps = function (nick) {
  397. if (!Misc.inMyParty(nick)) {
  398. say("Accept party invite, noob.");
  399.  
  400. return false;
  401. }
  402.  
  403. var i, act, timeout, wpList;
  404.  
  405. switch (this.getWpNick(nick)) {
  406. case "maxrequests":
  407. say(nick + ", you have spent all your waypoint requests for this game.");
  408.  
  409. return false;
  410. case "mintime":
  411. say(nick + ", you may request waypoints every 60 seconds.");
  412.  
  413. return false;
  414. case false:
  415. this.addWpNick(nick);
  416.  
  417. break;
  418. }
  419.  
  420. act = this.getPlayerAct(nick);
  421.  
  422. switch (act) {
  423. case 1:
  424. wpList = [3, 4, 5, 6, 27, 29, 32, 35];
  425.  
  426. break;
  427. case 2:
  428. wpList = [48, 42, 57, 43, 44, 52, 74, 46];
  429.  
  430. break;
  431. case 3:
  432. wpList = [76, 77, 78, 79, 80, 81, 83, 101];
  433.  
  434. break;
  435. case 4:
  436. wpList = [106, 107];
  437.  
  438. break;
  439. case 5:
  440. wpList = [111, 112, 113, 115, 123, 117, 118, 129];
  441.  
  442. break;
  443. }
  444.  
  445. MainLoop:
  446. for (i = 0; i < wpList.length; i += 1) {
  447. if (this.checkHostiles()) {
  448. break;
  449. }
  450.  
  451. try {
  452. Pather.useWaypoint(wpList[i], true);
  453. Pather.makePortal();
  454. say(getArea().name + " TP up");
  455.  
  456. for (timeout = 0; timeout < 20; timeout += 1) {
  457. if (getUnit(0, nick)) {
  458. break;
  459. }
  460.  
  461. delay(1000);
  462. }
  463.  
  464. if (timeout >= 20) {
  465. say("Aborting wp giving.");
  466.  
  467. break MainLoop;
  468. }
  469.  
  470. delay(5000);
  471. } catch (error) {
  472.  
  473. }
  474. }
  475.  
  476. Town.doChores();
  477. Town.goToTown(1);
  478. Town.move("portalspot");
  479.  
  480. this.wpNicks[nick].requests += 1;
  481. this.wpNicks[nick].timer = getTickCount();
  482.  
  483. return true;
  484. };
  485.  
  486. this.getPlayerAct = function (name) {
  487. var unit = getParty();
  488.  
  489. if (unit) {
  490. do {
  491. if (unit.name === name) {
  492. if (unit.area <= 39) {
  493. return 1;
  494. }
  495.  
  496. if (unit.area >= 40 && unit.area <= 74) {
  497. return 2;
  498. }
  499.  
  500. if (unit.area >= 75 && unit.area <= 102) {
  501. return 3;
  502. }
  503.  
  504. if (unit.area >= 103 && unit.area <= 108) {
  505. return 4;
  506. }
  507.  
  508. return 5;
  509. }
  510. } while (unit.getNext());
  511. }
  512.  
  513. return false;
  514. };
  515.  
  516. this.checkHostiles = function () {
  517. var rval = false,
  518. party = getParty();
  519.  
  520. if (party) {
  521. do {
  522. if (party.name !== me.name && getPlayerFlag(me.gid, party.gid, 8)) {
  523. rval = true;
  524.  
  525. if (Config.ShitList && shitList.indexOf(party.name) === -1) {
  526. shitList.push(party.name);
  527. }
  528. }
  529. } while (party.getNext());
  530. }
  531.  
  532. return rval;
  533. };
  534.  
  535. this.floodCheck = function (command) {
  536. var cmd = command[0],
  537. nick = command[1];
  538.  
  539. if (!nick) { // ignore overhead messages
  540. return true;
  541. }
  542.  
  543. if ([ "help", "timeleft",
  544. Config.Enchant.Triggers[0].toLowerCase(),
  545. Config.Enchant.Triggers[1].toLowerCase(),
  546. Config.Enchant.Triggers[2].toLowerCase(),
  547. Config.Enchant.Triggers[3].toLowerCase()
  548. ].indexOf(cmd.toLowerCase()) === -1) {
  549. return false;
  550. }
  551.  
  552. if (!this.cmdNicks) {
  553. this.cmdNicks = {};
  554. }
  555.  
  556. if (!this.cmdNicks.hasOwnProperty(nick)) {
  557. this.cmdNicks[nick] = {
  558. firstCmd: getTickCount(),
  559. commands: 0,
  560. ignored: false
  561. };
  562. }
  563.  
  564. if (this.cmdNicks[nick].ignored) {
  565. if (getTickCount() - this.cmdNicks[nick].ignored < 60000) {
  566. return true; // ignore flooder
  567. }
  568.  
  569. // unignore flooder
  570. this.cmdNicks[nick].ignored = false;
  571. this.cmdNicks[nick].commands = 0;
  572. }
  573.  
  574. this.cmdNicks[nick].commands += 1;
  575.  
  576. if (getTickCount() - this.cmdNicks[nick].firstCmd < 10000) {
  577. if (this.cmdNicks[nick].commands > 5) {
  578. this.cmdNicks[nick].ignored = getTickCount();
  579.  
  580. say(nick + ", you are being ignored for 60 seconds because of flooding.");
  581. }
  582. } else {
  583. this.cmdNicks[nick].firstCmd = getTickCount();
  584. this.cmdNicks[nick].commands = 0;
  585. }
  586.  
  587. return false;
  588. };
  589.  
  590. function ChatEvent(nick, msg) {
  591. command = [msg, nick];
  592. }
  593.  
  594. function GreetEvent(mode, param1, param2, name1, name2) {
  595. switch (mode) {
  596. case 0x02:
  597. if (me.inTown && me.mode === 5) { // idle in town
  598. greet.push(name1);
  599. }
  600.  
  601. break;
  602. }
  603. }
  604.  
  605. // START
  606. if (Config.ShitList) {
  607. shitList = ShitList.read();
  608. }
  609.  
  610. addEventListener("chatmsg", ChatEvent);
  611. addEventListener("gameevent", GreetEvent);
  612. Town.doChores();
  613. Town.goToTown(1);
  614. Town.move("portalspot");
  615.  
  616. spot = {
  617. x: me.x,
  618. y: me.y
  619. };
  620.  
  621. while (true) {
  622. while (greet.length > 0) {
  623. nick = greet.shift();
  624.  
  625. if (shitList.indexOf(nick) === -1) {
  626. say("Welcome, " + nick + "! For a list of commands say 'help'");
  627. }
  628. }
  629.  
  630. if (spot && getDistance(me, spot) > 10) {
  631. Pather.moveTo(spot.x, spot.y);
  632. }
  633.  
  634. if (command && !this.floodCheck(command)) {
  635. switch (command[0].toLowerCase()) {
  636. case "help":
  637. this.checkHostiles();
  638.  
  639. if (shitList.indexOf(command[1]) > -1) {
  640. say("No " + command[0] + " for the shitlisted.");
  641.  
  642. break;
  643. }
  644.  
  645. say("Commands:");
  646. say("Remaining time: timeleft" +
  647. (Config.Enchant.Triggers[0] ? " | Enhant: " + Config.Enchant.Triggers[0] : "") +
  648. (Config.Enchant.Triggers[1] ? " | Open cow level: " + Config.Enchant.Triggers[1] : "") +
  649. (Config.Enchant.Triggers[2] ? " | Give waypoints: " + Config.Enchant.Triggers[2] : "")+
  650. (Config.Enchant.Triggers[3] ? " | bo: " + Config.Enchant.Triggers[3] : ""));
  651.  
  652. if (Config.Enchant.AutoChant) {
  653. say("Auto enchant is ON");
  654. }
  655.  
  656. break;
  657. case "timeleft":
  658. tick = Config.Enchant.GameLength * 6e4 - getTickCount() + startTime;
  659. m = Math.floor(tick / 60000);
  660. s = Math.floor((tick / 1000) % 60);
  661.  
  662. say("Time left: " + (m ? m + " minute" + (m > 1 ? "s" : "") + ", " : "") + s + " second" + (s > 1 ? "s." : "."));
  663.  
  664. break;
  665. case Config.Enchant.Triggers[0].toLowerCase(): // chant
  666. this.checkHostiles();
  667.  
  668. if (shitList.indexOf(command[1]) > -1) {
  669. say("No chant for the shitlisted.");
  670.  
  671. break;
  672. }
  673.  
  674. this.enchant(command[1]);
  675.  
  676. break;
  677. case Config.Enchant.Triggers[1].toLowerCase(): // cows
  678. hostile = this.checkHostiles();
  679.  
  680. if (shitList.indexOf(command[1]) > -1) {
  681. say("No cows for the shitlisted.");
  682.  
  683. break;
  684. }
  685.  
  686. this.openPortal(command[1]);
  687. me.cancel();
  688.  
  689. break;
  690. case Config.Enchant.Triggers[2].toLowerCase(): // wps
  691. hostile = this.checkHostiles();
  692.  
  693. if (shitList.indexOf(command[1]) > -1) {
  694. say("No waypoints for the shitlisted.");
  695.  
  696. break;
  697. }
  698. case Config.Enchant.Triggers[3].toLowerCase(): // bo
  699. hostile = this.checkHostiles();
  700.  
  701. if (shitList.indexOf(command[1]) > -1) {
  702. say("No waypoints for the shitlisted.");
  703.  
  704. break;
  705. }
  706. if (hostile) {
  707. say("Command disabled because of hostiles.");
  708.  
  709. break;
  710. }
  711.  
  712. this.bo(command[1]);
  713.  
  714. break;
  715. }
  716. }
  717.  
  718. command = "";
  719.  
  720. if (me.act > 1) {
  721. Town.goToTown(1);
  722. }
  723.  
  724. if (Config.Enchant.AutoChant) {
  725. this.autoChant();
  726. }
  727.  
  728. if (getTickCount() - startTime >= Config.Enchant.GameLength * 6e4) {
  729. say("Use kolbot or die!");
  730. delay(1000);
  731.  
  732. break;
  733. }
  734.  
  735. delay(200);
  736. }
  737.  
  738. return true;
  739. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement