Advertisement
kolton

Untitled

Dec 15th, 2011
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     /*
  2.         This function moves to an existing unit or object with x, y properties.
  3.         It can also accept a preset unit.
  4.         If you want to go to a preset unit based on its area, type and id, use Pather.moveToPreset().
  5.     */
  6.     moveToUnit: function (unit, offX, offY, clearPath) { // Maybe use range instead of offsets
  7.         switch (arguments.length) {
  8.         case 1:
  9.             offX = 0;
  10.         case 2:
  11.             offY = 0;
  12.         case 3:
  13.             clearPath = false;
  14.             break;
  15.         }
  16.        
  17.         if (!unit || !unit.hasOwnProperty("x") || !unit.hasOwnProperty("y")) {
  18.             throw new Error("moveToUnit: Invalid unit.");
  19.         }
  20.        
  21.         if (unit instanceof PresetUnit) {
  22.             return this.moveTo(unit.roomx * 5 + unit.x + offX, unit.roomy * 5 + unit.y + offY, 2, clearPath);
  23.         }
  24.        
  25.         return this.moveTo(unit.x + offX, unit.y + offY, 2, clearPath);
  26.     },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement