Jump to content

Rune Essence Portal Interaction (NPC and Object). SOLVED


Recommended Posts

Posted (edited)

Previous thread: 

So it seems as if the portal in the rune essence mine changes types from object to NPC to whatever. I'm having trouble implementing a solution for this.

I've used some of the ideas explored in the previous thread, but my understanding is still weak.

I originally wanted to filter through both objects and NPCs but Chris told me this wasn't possible.

Instead he suggested for me to add both types to a list then filter through them.

// Is this the correct way of creating and adding to a list?

// Create
List <Object> portals = new ArrayList<>();

//Add
portals.add(getObjects().getAll().stream().filter(object -> object.getName().contains("Portal")).findAny());

//Add
portals.add(getNpcs().getAll().stream().filter(object -> object.getName().contains("Portal")).findAny());

I'm not sure how to interact with the list of type Object. I was thinking of  iterating through the list checking if the object was present, then interacting with it, but you can't interact unless the list is <Entity> not <Object>. If the list is <Entity> it's difficult to add to it...

Basically... I have no idea what I'm doing, and I need some more assistance :).

It should be common knowledge now, but in case it's forgotten, I take a while to learn, so pls be patient :).

EDIT

Read the 4th post for the solution.

Edited by Lexhanatin
Solved
Posted

		NPC portalNpc = null;
		RS2Object portalObj = null;
		int portalNpcDist = Integer.MAX_VALUE;
		int portalObjDist = Integer.MAX_VALUE;
		Entity portalEntity;
		
		// Find objects
		portalNpc = npcs.closest("Portal");
		portalObj = objects.closest("Portal");
		
		// Check if either NPC or OBJ is valid
		if (portalNpc != null || portalObj != null) {
			
			// Calculate distance to NPC
			if (portalNpc != null) {
				portalNpcDist = map.distance(portalNpc);
			}
			
			// Calculate distance to OBJ
			if (portalObj != null) {
				portalObjDist = map.distance(portalObj);
			}
			
			// Check distance
			// Note: NPC or OBJ may be null
			if (portalNpcDist < portalObjDist) {
				// NPC is closer
				portalEntity = portalNpc;
			} else {
				// OBJ is same distance/closer
				portalEntity = portalObj;
			}
			
			// Finally, check portal
			if (portalEntity != null) {
				// Interact
				if (portalEntity.interact("Exit")) {
					// TODO: Conditional sleep
				}
			}
		}

 

Posted

I found the problem in @liverare solution.

Simply the portals name isn't "Portal". Extra tags are added to the name preventing the below code from working.

portalNpc = npcs.closest("Portal");
portalObj = objects.closest("Portal");

Instead partial matching should be used instead.

portalNpc = getNpcs().closestThatContains("Portal");
portalObj = getObjects().closestThatContains("Portal");

This will always find a portal.

 

The second problem in the solution was the implementation of distance.

The current instance of portal would be of type NPC or Object, but when comparing distances, another instance was deemed closer. This would prevent interaction.

A possible reason for this could be that the current portal instance was being compared to a previous instances distance. I'm not sure.

I fixed this by taking out the distance comparison. Below is the find product.

private void bank() throws InterruptedException { 
    log("Bank method");
    if (getObjects().closest("Rune Essence") != null) {
      log("Rune Essence Exists");
      portalNpc = getNpcs().closestThatContains("Portal");
      portalObj = getObjects().closestThatContains("Portal");

      if (portalNpc != null || portalObj != null) {
        log("Entity not null");
        if (portalNpc != null) {
          log("Portal is NPC");
          portalEntity = portalNpc;
        }

        if (portalObj != null) {
          log("Portal is Object");
          portalEntity = portalObj;
        }
        if (portalEntity != null) {
          log("Portal Interaction");
          if (portalEntity.interact("Exit", "Use")) {
            new ConditionalSleep(8000) {
              @Override
                public boolean condition() throws InterruptedException {
                return !myPlayer().isMoving();
              }
            }.sleep();
          }
        }
      }
      else {
        log ("Entity null");
      }
    }

 

I would like to thank everyone for helping me solve this problem over the week. Hopefully this thread will help people with similar problems in the future.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...