Jump to content

Checking if bank contains a list of items?


H0rn

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

// 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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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