Guest User

Untitled

a guest
Feb 13th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.91 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. for (i = 0; i < 5; i += 1) {
  221. if (Pather.usePortal(player.area, player.name)) {
  222. break;
  223. }
  224.  
  225. delay(1000);
  226. }
  227.  
  228. if (me.area === player.area) {
  229. Precast.doPrecast(false);
  230. Attack.clearLevel(Config.ClearType);
  231. Precast.doPrecast(true);
  232.  
  233. if (!Pather.usePortal(null, player.name)) {
  234. Town.goToTown();
  235. }
  236. } else {
  237. print("Failed to use portal.");
  238. }
  239. } else if (command.indexOf("clear") > -1) {
  240. print("ÿc4MFHelperÿc0: Clear");
  241.  
  242. split = command.split("clear ")[1];
  243.  
  244. for (i = 0; i < 5; i += 1) {
  245. if (Pather.usePortal(player.area, player.name)) {
  246. break;
  247. }
  248.  
  249. delay(1000);
  250. }
  251.  
  252. if (me.area === player.area) {
  253. Precast.doPrecast(false);
  254.  
  255. try {
  256. if (!!parseInt(split, 10)) {
  257. split = parseInt(split, 10);
  258. }
  259.  
  260. Attack.clear(15, 0, split);
  261. } catch (killerror2) {
  262. print(killerror2);
  263. }
  264.  
  265. delay(1000);
  266.  
  267. if (!me.inTown && !Pather.usePortal(null, player.name)) {
  268. Town.goToTown();
  269. }
  270. } else {
  271. print("Failed to use portal.");
  272. }
  273. } else if (command.indexOf("quit") > -1) {
  274. break MainLoop;
  275. } else if (command.indexOf("cows") > -1) {
  276. print("ÿc4MFHelperÿc0: Clear Cows");
  277.  
  278. for (i = 0; i < 5; i += 1) {
  279. if (Town.goToTown(1) && Pather.usePortal(39)) {
  280. break;
  281. }
  282.  
  283. delay(1000);
  284. }
  285.  
  286. if (me.area === 39) {
  287. Precast.doPrecast(false);
  288. this.clearCowLevel();
  289. delay(1000);
  290.  
  291. if (!Pather.usePortal(null, player.name)) {
  292. Town.goToTown();
  293. }
  294. } else {
  295. print("Failed to use portal.");
  296. }
  297. } else if (command.indexOf("council") > -1) {
  298. print("ÿc4MFHelperÿc0: Kill Council");
  299.  
  300. for (i = 0; i < 5; i += 1) {
  301. if (Pather.usePortal(player.area, player.name)) {
  302. break;
  303. }
  304.  
  305. delay(1000);
  306. }
  307.  
  308. if (me.area === player.area) {
  309. Precast.doPrecast(false);
  310. Attack.clearList(Attack.getMob([345, 346, 347], 0, 40));
  311.  
  312. if (!Pather.usePortal(null, player.name)) {
  313. Town.goToTown();
  314. }
  315. } else {
  316. print("Failed to use portal.");
  317. }
  318. }
  319. }
  320. }
  321.  
  322. delay(100);
  323. }
  324.  
  325. return true;
  326. }
Add Comment
Please, Sign In to add comment