Advertisement
kolton

Untitled

May 7th, 2012
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var Pather = {
  2.     teleport: true,
  3.     walkDistance: 15,
  4.     teleDistance: 40,
  5.     wpAreas: [1, 3, 4, 5, 6, 27, 29, 32, 35, 40, 48, 42, 57, 43, 44, 52, 74, 46, 75, 76, 77, 78, 79, 80, 81, 83, 101, 103, 106, 107, 109, 111, 112, 113, 115, 123, 117, 118, 129],
  6.  
  7.     moveTo: function (x, y, retry, clearPath, pop) {
  8.         if (getDistance(me, x, y) < 2) {
  9.             return true;
  10.         }
  11.  
  12.         if (arguments.length < 2) {
  13.             throw new Error("moveTo: Function must be called with at least 2 arguments.");
  14.         }
  15.  
  16.         if (typeof (x) !== "number" || typeof (y) !== "number") {
  17.             throw new Error("moveTo: Coords must be numbers");
  18.         }
  19.  
  20.         if (getUIFlag(0x01) || getUIFlag(0x02) || getUIFlag(0x04) || getUIFlag(0x16) || getUIFlag(0x0C) || getUIFlag(0x0F)) {
  21.             me.cancel();
  22.         }
  23.  
  24.         switch (arguments.length) {
  25.         case 2:
  26.             retry = 3;
  27.             clearPath = false;
  28.             pop = false;
  29.  
  30.             break;
  31.         case 3:
  32.             clearPath = false;
  33.             pop = false;
  34.  
  35.             break;
  36.         case 4:
  37.             pop = false;
  38.  
  39.             break;
  40.         }
  41.  
  42.         var path, mob,
  43.             node = {x: x, y: y},
  44.             fail = 0;
  45.  
  46.         this.useTeleport = this.teleport && !me.inTown && me.getSkill(54, 1);
  47.  
  48.         // Teleport without calling getPath if the spot is close enough
  49.         if (this.useTeleport && getDistance(me, x, y) <= this.teleDistance) {
  50.             return this.teleportTo(x, y);
  51.         }
  52.  
  53.         // Walk without calling getPath if the spot is close enough
  54.         if (!this.useTeleport && getDistance(me, x, y) <= 5) {
  55.             return this.walkTo(x, y);
  56.         }
  57.  
  58.         //path = getPath(me.area, x, y, me.x, me.y, this.useTeleport ? 1 : 0, this.useTeleport ? this.teleDistance : this.walkDistance);
  59.         path = getPath(me.area, me.x, me.y, x, y, this.useTeleport ? 1 : 0, this.useTeleport ? this.teleDistance : this.walkDistance);
  60.  
  61.         if (!path) {
  62.             throw new Error("moveTo: Failed to generate path.");
  63.         }
  64.  
  65.         //path.reverse();
  66.  
  67.         if (pop) {
  68.             path.pop();
  69.         }
  70.  
  71.         if (this.useTeleport && Config.TeleSwitch) {
  72.             Misc.teleSwitch();
  73.         }
  74.  
  75.         while (path.length > 0) {
  76.             if (getUIFlag(0x01) || getUIFlag(0x02) || getUIFlag(0x04) || getUIFlag(0x16) || getUIFlag(0x0C) || getUIFlag(0x0F)) {
  77.                 me.cancel();
  78.             }
  79.  
  80.             node = path.shift();
  81.  
  82.             /* Right now getPath's first node is our own position so it's not necessary to take it into account
  83.                 This will be removed if getPath changes
  84.             */
  85.             if (this.useTeleport && getDistance(me, node) < 2) {
  86.                 continue;
  87.             }
  88.  
  89.             if (!(this.useTeleport ? this.teleportTo(node.x, node.y) : this.walkTo(node.x, node.y))) {
  90.                 // Reduce node distance in new path
  91.                 //path = getPath(me.area, x, y, me.x, me.y, this.useTeleport ? 1 : 0, this.useTeleport ? 30 : 10);
  92.                 path = getPath(me.area, me.x, me.y, x, y, this.useTeleport ? 1 : 0, this.useTeleport ? 30 : 10);
  93.  
  94.                 if (!path) {
  95.                     throw new Error("moveTo: Failed to generate path.");
  96.                 }
  97.  
  98.                 //path.reverse();
  99.  
  100.                 if (fail === 2 && !this.useTeleport) {
  101.                     Attack.clear(5);
  102.                 }
  103.  
  104.                 fail += 1;
  105.  
  106.                 print("move retry " + fail);
  107.             }
  108.  
  109.             if (fail >= retry) {
  110.                 break;
  111.             }
  112.  
  113.             if (clearPath) {
  114.                 Attack.clear(15, typeof clearPath === "number" ? clearPath : false);
  115.  
  116.                 if (getDistance(me, node.x, node.y) > 4) {
  117.                     this.moveTo(node.x, node.y);
  118.                 }
  119.             }
  120.  
  121.             if (Config.Countess.KillGhosts) { // TODO: expand&improve
  122.                 mob = Attack.getMob("ghost", 0, 30);
  123.  
  124.                 if (mob) {
  125.                     Attack.clearList(mob);
  126.                 }
  127.  
  128.                 if (getDistance(me, node.x, node.y) > 4) {
  129.                     this.moveTo(node.x, node.y);
  130.                 }
  131.             }
  132.  
  133.             if (Misc.townCheck(false)) {
  134.                 this.useTeleport = this.teleport && !me.inTown && me.getSkill(54, 1);
  135.             }
  136.         }
  137.  
  138.         if (this.useTeleport && Config.TeleSwitch) {
  139.             Precast.weaponSwitch(Misc.oldSwitch);
  140.         }
  141.  
  142.         return getDistance(me, node.x, node.y) < 4;
  143.     },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement