Jump to content

Checking if bank contains a list of items?


Recommended Posts

Posted (edited)

I've tried a couple of ways to do this, for example if the bank contains a charged glory or stamina potion, basically I am trying to use the lowest value of charge/stamina before going back to the (6) or (4)

 

Could anyone post a snippet? I've tried searching about, but I am sort of new to lists :(

 

What I have so far:

 

String[] gloryNames = {"Amulet of glory(1)", "Amulet of glory(2)", "Amulet of glory(3)", "Amulet of glory(4)", "Amulet of glory(5)", "Amulet of glory(6)"};
			if (needGlory == true && bank.contains(gloryNames)){ 
	    			new ConditionalSleep(random(5000,7000)) {
			    	public boolean condition() {
			    			if (getBank().withdraw(bank.getSlot(gloryNames),1)) { getStatus = "Withdraw glory";}
			    				return inventory.contains(gloryNames.toString());
			    			}
			    		}.sleep();
			    		inventory.interact(inventory.getSlot(gloryNames.toString()), "Wear");
	    			}

 

Edited by OllieW
Posted
19 minutes ago, OllieW said:

 

Thats why I was avoiding that, I am certain there's a better way :\ will use that for now I guess

Optional<Item> gloryNames= Arrays.stream(getInventory().getItems()).filter(i -> i != null && (i.nameContains("Amulet of glory(1)") || i.nameContains("Amulet of glory(2)"))).findFirst();

 

Try This 

  • Like 1
Posted
18 minutes ago, dreameo said:

zz

 

Just use a for loop,

if need glory and bank open

iterate through the glory strings (1,...6)

if has glory, withdraw (cond sleep)

if inv contains a glory, break the for loop

need glory bool should be flase now

Sorry4noob but can you give an example? I haven't used for loops very much, understand how they work but don't understand how they would work in this instance.

Posted
// assuming bank is open because needGlory is true

String[] glorys = [...]

if(getBank().isOpen)
{
  for(String glory : glorys)
  {
   	if(getBank().contains(glory)
       {
       	 if(getBank().withdraw(glory, 1)
            {
             	cond sleep // inv contains glory
             	break; // exit loop since we have item
              	// needGlory should be false now
            }
       {
  }
            // script should exit here since bank contains no glory
           stop(true);
}

 

Not tested, insert the condition sleep, (maybe few syntax errors idk, just wrote it here)

  • Like 2
Posted

My favourite thing about programming is that there's literally a million different ways of doing things:

	public void withdrawGlory() {
	
		Item glory = Stream
			.of(bank.getItems())                 // stream of all bank items
			.filter(ScriptName::isAmuletOfGlory) // filter for glories
			.findFirst()                         // get first glory
			.orElse(null);                       // null
		
		if (glory != null) {
			
			// do something
			
		}
	}

	public static boolean isAmuletOfGlory(Item item) {
		return item.getName().contains("glory(");
	}

 

  • Like 1
Posted
15 minutes ago, liverare said:

My favourite thing about programming is that there's literally a million different ways of doing things:


	public void withdrawGlory() {
	
		Item glory = Stream
			.of(bank.getItems())                 // stream of all bank items
			.filter(ScriptName::isAmuletOfGlory) // filter for glories
			.findFirst()                         // get first glory
			.orElse(null);                       // null
		
		if (glory != null) {
			
			// do something
			
		}
	}

	public static boolean isAmuletOfGlory(Item item) {
		return item.getName().contains("glory(");
	}

 

This would just get any glory, he's looking to prioritize getting glories with the lowest charge (1),(2)...(n)

  • Like 1
Posted (edited)
23 minutes ago, dreameo said:

This would just get any glory, he's looking to prioritize getting glories with the lowest charge (1),(2)...(n)

You can use Explv's "min" statement. It's easy to make the adaptation:

	private void withdrawGlory() {
		Item glory = Stream
			.of(bank.getItems())                    // all bank items
			.filter(ScriptName::isAmuletOfGlory)    // glories only (which includes eternal glory)
			.min(ScriptName::sortByItemName)        // get first glory, but not before sorting them by item name
			.orElse(null);                          // return result glory, or else return null
		
		if (glory != null) {
			
			// do something
			
		}
	}
	
	public static int sortByItemName(Item a, Item b) {
		
		String aa = a.getName();
		String bb = b.getName();
		
		return aa.compareTo(bb);
	}

	public static boolean isAmuletOfGlory(Item item) {
		return item.getName().contains("glory");
	}

 

Edited by liverare
  • Like 1

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...