Advertisement
Guest User

Untitled

a guest
Feb 13th, 2020
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.88 KB | None | 0 0
  1. /**
  2. * @filename MFHelper.js
  3. * @author kolton
  4. * @desc help another player kill bosses or clear areas
  5. */
  6.  
  7. function MFHelper() {
  8. var i, player, playerAct, split,
  9. oldCommand = "",
  10. command = "";
  11.  
  12. function ChatEvent(name, msg) {
  13. if (!player) {
  14. var i,
  15. match = ["kill", "clearlevel", "clear", "quit", "cows", "council"];
  16.  
  17. if (msg) {
  18. for (i = 0; i < match.length; i += 1) {
  19. if (msg.match(match[i])) {
  20. player = this.findPlayer(name);
  21.  
  22. break;
  23. }
  24. }
  25. }
  26. }
  27.  
  28. if (player && name === player.name) {
  29. command = msg;
  30. }
  31. }
  32.  
  33. this.findPlayer = function (name) {
  34. var party = getParty();
  35.  
  36. if (party) {
  37. do {
  38. if (party.name !== me.name && party.name === name) {
  39. return party;
  40. }
  41. } while (party.getNext());
  42. }
  43.  
  44. return false;
  45. };
  46.  
  47. this.getPlayerAct = function (player) {
  48. if (player.area > 0 && player.area <= 39) {
  49. return 1;
  50. }
  51.  
  52. if (player.area >= 40 && player.area <= 74) {
  53. return 2;
  54. }
  55.  
  56. if (player.area >= 75 && player.area <= 102) {
  57. return 3;
  58. }
  59.  
  60. if (player.area >= 103 && player.area <= 108) {
  61. return 4;
  62. }
  63.  
  64. if (player.area >= 109) {
  65. return 5;
  66. }
  67.  
  68. return false;
  69. };
  70.  
  71. this.buildCowRooms = function () {
  72. var i, j, room, kingPreset, badRooms, badRooms2,
  73. finalRooms = [],
  74. indexes = [];
  75.  
  76. kingPreset = getPresetUnit(me.area, 1, 773);
  77. badRooms = getRoom(kingPreset.roomx * 5 + kingPreset.x, kingPreset.roomy * 5 + kingPreset.y).getNearby();
  78.  
  79. for (i = 0; i < badRooms.length; i += 1) {
  80. badRooms2 = badRooms[i].getNearby();
  81.  
  82. for (j = 0; j < badRooms2.length; j += 1) {
  83. if (indexes.indexOf(badRooms2[j].x.toString() + badRooms2[j].y.toString()) === -1) {
  84. indexes.push(badRooms2[j].x.toString() + badRooms2[j].y.toString());
  85. }
  86. }
  87. }
  88.  
  89. room = getRoom();
  90.  
  91. do {
  92. if (indexes.indexOf(room.x.toString() + room.y.toString()) === -1) {
  93. finalRooms.push([room.x * 5 + room.xsize / 2, room.y * 5 + room.ysize / 2]);
  94. }
  95. } while (room.getNext());
  96.  
  97. return finalRooms;
  98. };
  99.  
  100. this.clearCowLevel = function () {
  101. var room, result, myRoom,
  102. rooms = this.buildCowRooms();
  103.  
  104. function RoomSort(a, b) {
  105. return getDistance(myRoom[0], myRoom[1], a[0], a[1]) - getDistance(myRoom[0], myRoom[1], b[0], b[1]);
  106. }
  107.  
  108. while (rooms.length > 0) {
  109. // get the first room + initialize myRoom var
  110. if (!myRoom) {
  111. room = getRoom(me.x, me.y);
  112. }
  113.  
  114. if (room) {
  115. if (room instanceof Array) { // use previous room to calculate distance
  116. myRoom = [room[0], room[1]];
  117. } else { // create a new room to calculate distance (first room, done only once)
  118. myRoom = [room.x * 5 + room.xsize / 2, room.y * 5 + room.ysize / 2];
  119. }
  120. }
  121.  
  122. rooms.sort(RoomSort);
  123. room = rooms.shift();
  124.  
  125. result = Pather.getNearestWalkable(room[0], room[1], 10, 2);
  126.  
  127. if (result) {
  128. Pather.moveTo(result[0], result[1], 3);
  129.  
  130. if (!Attack.clear(30)) {
  131. return false;
  132. }
  133. }
  134. }
  135.  
  136. return true;
  137. };
  138.  
  139. addEventListener("chatmsg", ChatEvent);
  140. Town.doChores();
  141. Town.move("portalspot");
  142.  
  143. if (Config.Leader) {
  144. for (i = 0; i < 30; i += 1) {
  145. if (Misc.inMyParty(Config.Leader)) {
  146. break;
  147. }
  148.  
  149. delay(1000);
  150. }
  151.  
  152. if (i === 30) {
  153. throw new Error("MFHelper: Leader not partied");
  154. }
  155.  
  156. player = this.findPlayer(Config.Leader);
  157. }
  158.  
  159. // START
  160. MainLoop:
  161. while (true) {
  162. if (player) {
  163. while (!player.area) {
  164. delay(100);
  165. }
  166.  
  167. playerAct = this.getPlayerAct(player);
  168.  
  169. if (playerAct && playerAct !== me.act) {
  170. Town.goToTown(playerAct);
  171. Town.move("portalspot");
  172. }
  173.  
  174. // Finish if leader is in chaos or throne
  175. if ([108, 131].indexOf(player.area) > -1) {
  176. break;
  177. }
  178.  
  179. if (command !== oldCommand) {
  180. oldCommand = command;
  181.  
  182. if (command.indexOf("kill") > -1) {
  183. print("ÿc4MFHelperÿc0: Kill");
  184.  
  185. split = command.split("kill ")[1];
  186.  
  187. for (i = 0; i < 5; i += 1) {
  188. if (Pather.usePortal(player.area, player.name)) {
  189. break;
  190. }
  191.  
  192. delay(1000);
  193. }
  194.  
  195. if (me.area === player.area) {
  196. Precast.doPrecast(false);
  197.  
  198. try {
  199. if (!!parseInt(split, 10)) {
  200. split = parseInt(split, 10);
  201. }
  202.  
  203. Attack.kill(split);
  204. Pickit.pickItems();
  205. } catch (killerror) {
  206. print(killerror);
  207. }
  208.  
  209. delay(1000);
  210.  
  211. if (!me.inTown && !Pather.usePortal(null, player.name)) {
  212. Town.goToTown();
  213. }
  214. } else {
  215. print("Failed to use portal.");
  216. }
  217. } else if (command.indexOf("clearlevel") > -1) {
  218. print("ÿc4MFHelperÿc0: Clear Level");
  219.  
  220. while (!Pather.usePortal(player.area, player.name)) {
  221. me.overhead("ÿc1Failed to use leader portal.");
  222.  
  223. if (playerAct !== me.act) {
  224. break;
  225. }
  226.  
  227. delay(100);
  228. }
  229.  
  230. if (me.area === player.area) {
  231. Precast.doPrecast(true);
  232. Attack.clearLevel(Config.ClearType);
  233.  
  234. if (!me.inTown && !Pather.usePortal(null, player.name)) {
  235. Town.goToTown();
  236. }
  237. }
  238. } else if (command.indexOf("clear") > -1) {
  239. print("ÿc4MFHelperÿc0: Clear");
  240.  
  241. split = command.split("clear ")[1];
  242.  
  243. for (i = 0; i < 5; i += 1) {
  244. if (Pather.usePortal(player.area, player.name)) {
  245. break;
  246. }
  247.  
  248. delay(1000);
  249. }
  250.  
  251. if (me.area === player.area) {
  252. Precast.doPrecast(false);
  253.  
  254. try {
  255. if (!!parseInt(split, 10)) {
  256. split = parseInt(split, 10);
  257. }
  258.  
  259. Attack.clear(15, 0, split);
  260. } catch (killerror2) {
  261. print(killerror2);
  262. }
  263.  
  264. delay(1000);
  265.  
  266. if (!me.inTown && !Pather.usePortal(null, player.name)) {
  267. Town.goToTown();
  268. }
  269. } else {
  270. print("Failed to use portal.");
  271. }
  272. } else if (command.indexOf("quit") > -1) {
  273. break MainLoop;
  274. } else if (command.indexOf("cows") > -1) {
  275. print("ÿc4MFHelperÿc0: Clear Cows");
  276.  
  277. for (i = 0; i < 5; i += 1) {
  278. if (Town.goToTown(1) && Pather.usePortal(39)) {
  279. break;
  280. }
  281.  
  282. delay(1000);
  283. }
  284.  
  285. if (me.area === 39) {
  286. Precast.doPrecast(false);
  287. this.clearCowLevel();
  288. delay(1000);
  289.  
  290. if (!Pather.usePortal(null, player.name)) {
  291. Town.goToTown();
  292. }
  293. } else {
  294. print("Failed to use portal.");
  295. }
  296. } else if (command.indexOf("council") > -1) {
  297. print("ÿc4MFHelperÿc0: Kill Council");
  298.  
  299. for (i = 0; i < 5; i += 1) {
  300. if (Pather.usePortal(player.area, player.name)) {
  301. break;
  302. }
  303.  
  304. delay(1000);
  305. }
  306.  
  307. if (me.area === player.area) {
  308. Precast.doPrecast(false);
  309. Attack.clearList(Attack.getMob([345, 346, 347], 0, 40));
  310.  
  311. if (!Pather.usePortal(null, player.name)) {
  312. Town.goToTown();
  313. }
  314. } else {
  315. print("Failed to use portal.");
  316. }
  317. }
  318. }
  319. }
  320.  
  321. delay(100);
  322. }
  323.  
  324. return true;
  325. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement