Exemplo n.º 1
0
  public int getParentId() {
    final Object inter = getInternal();
    if (inter == null) {
      return -1;
    }
    final Client client = Context.client();
    final Multipliers multipliers = Context.multipliers();

    final int parentId =
        ((RSInterfaceParentID) ((RSInterfaceInts) inter).getRSInterfaceInts())
                .getRSInterfaceParentID()
            * multipliers.INTERFACE_PARENTID;

    if (parentId != -1) {
      return parentId;
    }

    final int mainID = getId() >>> 0x10;
    final HashTable ncI = new HashTable(client.getRSInterfaceNC());
    for (RSInterfaceNode node = (RSInterfaceNode) ncI.getFirst();
        node != null;
        node = (RSInterfaceNode) ncI.getNext()) {
      if (mainID
          == ((RSInterfaceNodeMainID)
                      ((RSInterfaceNodeInts) node.getData()).getRSInterfaceNodeInts())
                  .getRSInterfaceNodeMainID()
              * multipliers.INTERFACENODE_MAINID) {
        final long multiplier =
            (((long) multipliers.NODE_ID) << 32) + ((multipliers.NODE_ID_p2 & 0xffffffffL));
        return (int) (node.getID() * multiplier);
      }
    }

    return -1;
  }
Exemplo n.º 2
0
 public Point getAbsoluteLocation() {
   if (getInternal() == null) {
     return new Point(-1, -1);
   }
   final Client client = Context.client();
   final int parentId = getParentId();
   int x = 0, y = 0;
   if (parentId != -1) {
     final Point point = Widgets.get(parentId >> 0x10, parentId & 0xffff).getAbsoluteLocation();
     x = point.x;
     y = point.y;
   } else {
     final Rectangle[] bounds = client.getRSInterfaceBoundsArray();
     final int index = getBoundsArrayIndex();
     if (bounds != null && index > 0 && index < bounds.length && bounds[index] != null) {
       return new Point(bounds[index].x, bounds[index].y);
     }
     // x = getMasterX();
     // y = getMasterY();
   }
   if (parentId != -1) {
     final WidgetChild child = Widgets.getChild(parentId);
     final int horizontalScrollSize = child.getScrollableContentWidth(),
         verticalScrollSize = child.getScrollableContentHeight();
     if (horizontalScrollSize > 0 || verticalScrollSize > 0) {
       x -= child.getHorizontalScrollPosition();
       y -= child.getVerticalScrollPosition();
     }
   }
   x += getRelativeX();
   y += getRelativeY();
   return new Point(x, y);
 }
Exemplo n.º 3
0
 public static Tile getDestination() {
   final Client client = Context.client();
   final int lx = client.getDestX();
   final int ly = client.getDestY();
   if (lx == -1 || ly == -1) {
     return new Tile(-1, -1, -1);
   }
   return new Tile(Game.getBaseX() + lx, Game.getBaseY() + ly, Game.getPlane());
 }
Exemplo n.º 4
0
 /**
  * @param filter The filtering <code>Filter</code> to accept all the Npcs through.
  * @return An array of the currently loaded Npcs in the game that are accepted by the provided
  *     filter.
  */
 public static NPC[] getLoaded(final Filter<NPC> filter) {
   final Client client = Context.client();
   final int[] indices = client.getRSNPCIndexArray();
   final Set<NPC> npcs = new HashSet<>();
   for (final int index : indices) {
     final Node node = Nodes.lookup((HashTable) client.getRSNPCNC(), index);
     if (node != null) {
       NPC npc = null;
       if (node instanceof RSNPCNode) {
         npc = new NPC((RSNPC) ((RSNPCNode) node).getRSNPC());
       } else if (node instanceof SoftReference) {
         npc =
             new NPC(
                 (RSNPC) ((java.lang.ref.SoftReference<?>) ((SoftReference) node).get()).get());
       }
       if (filter.accept(npc)) {
         npcs.add(npc);
       }
     }
   }
   return npcs.toArray(new NPC[npcs.size()]);
 }
Exemplo n.º 5
0
 /**
  * @param filter The filtering <code>Filter</code> NPCs have to pass.
  * @return The nearest Npc passing the filter if any present, else <i>null</i>.
  */
 public static NPC getNearest(final Filter<NPC> filter) {
   final Client client = Context.client();
   final int[] indices = client.getRSNPCIndexArray();
   NPC npc = null;
   double distance = Double.MAX_VALUE;
   final RegionOffset position = Players.getLocal().getRegionOffset();
   for (final int index : indices) {
     final Node node = Nodes.lookup((HashTable) client.getRSNPCNC(), index);
     if (node != null && node instanceof RSNPCNode) {
       final NPC t_npc = new NPC((RSNPC) ((RSNPCNode) node).getRSNPC());
       try {
         if (filter.accept(t_npc)) {
           final double dist = Calculations.distance(position, t_npc.getRegionOffset());
           if (dist < distance) {
             distance = dist;
             npc = t_npc;
           }
         }
       } catch (final Exception ignored) {
       }
     }
   }
   return npc;
 }