Advertisement
kolton

Untitled

Dec 16th, 2011
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     usePortal: function (area, owner, unit) {
  2.         var i, tick, portal,
  3.             preArea = me.area;
  4.        
  5.         if (unit) {
  6.             portal = unit;
  7.         } else {
  8.             portal = this.getPortal(area, owner);
  9.         }
  10.        
  11.         if (!portal) {
  12.             return false;
  13.         }
  14.        
  15.         if (getDistance(me, portal) > 3) {
  16.             this.moveToUnit(portal);
  17.         }
  18.        
  19.         for (i = 0; i < 3; i += 1) {
  20.             portal.interact();
  21.            
  22.             tick = getTickCount();
  23.            
  24.             while (getTickCount() - tick < 1000) {
  25.                 if (me.area !== preArea) {
  26.                     delay(750);
  27.                    
  28.                     return true;
  29.                 }
  30.                
  31.                 delay(10);
  32.             }
  33.         }
  34.        
  35.         return false;
  36.     },
  37.     /*
  38.         Without using blue portal check there's only 2 scenarios where the bot would take player's own blue portal to the area instead of a red one:
  39.         - Secret Cow Level portal
  40.         - Nihlathak's Temple
  41.         However, I don't see a reason to go out with a blue portal and go back through a red one, so the check won't be added for now.
  42.     */
  43.     getPortal: function (area, owner) {
  44.         var portal = getUnit(2, getLocaleString(3308)); // "Portal"
  45.        
  46.         if (!owner) {
  47.             owner = me.name;
  48.         }
  49.        
  50.         if (portal) {
  51.             do {
  52.                 /* Portal is good in following cases:
  53.                     - if portal's area matches area argument OR there's no area argument specified (null)
  54.                     - there's no Parent (red portals) OR Parent matches owner argument
  55.                     - player is the Parent (own portal)
  56.                     - Parent is in player's party (someone else's portal)
  57.                 */
  58.                 if ((!area || portal.objtype === area) && ((owner === me.name || NTC_InMyParty(owner)) && portal.getParent() === owner || !portal.getParent())) { // TODO: Replace party check
  59.                     return copyUnit(portal);
  60.                 }
  61.             } while (portal.getNext());
  62.         }
  63.        
  64.         return false;
  65.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement