Jump to content

Closest bank to you


k9thebeast

Recommended Posts

    public Area getNearBank(){
    	Field bank = null;
    	int minDist = Integer.MAX_VALUE;
    	for(Field f : Banks.class.getDeclaredFields()){
    		try {
    			int distance = getMap().distance(((Area) f.get(f.getName())).getRandomPosition());
    			if(distance < minDist && distance != -1){
    				minDist = distance;
    				bank = f;
    			}
			} catch (IllegalArgumentException | IllegalAccessException e) {
				e.printStackTrace();
			}
    	}
    	
    	if(bank != null)
			try {
				return (Area) bank.get(bank.getName());
			} catch (IllegalArgumentException | IllegalAccessException e) {
				return null;
			}
		else
    		return null;
    }

Can someone plz update this with streams. Thanks

@Alek plz turn Banks into actual enums so I dont have to do this gunk

Edited by k9thebeast
Link to comment
Share on other sites

6 minutes ago, the wamie said:

There is a snipper around on the forum which lets you get the closest bank in a cleaner way imo.

It does it by creating an Enum yourself and filling it with the appropriate Area.
Link: 

 

Wouldn't really call filling your own enum up with all the possible banks cleaner, but your pick lol. Combine the two if you like, his does have some nice components. @LoudPacks

Link to comment
Share on other sites

Personally I think it is cleaner because it allows you to easily add multiple custom banks that are not defined in the API. Without needing to alter any code, while if I wanted to add some to your snippet I would need to alter the way you check each bank. But that is just me. (Just explaining why I personally think it is cleaner, not saying its the best option)

Edited by the wamie
Link to comment
Share on other sites

1 hour ago, Alek said:

Both your solution and LoudPacks solution won't work with web walking. 

Well I use webwalking, and it works just fine in the script I am currently testing, I just use the enum to populate a JComboBox and fill the variables inside the Settings class.
Then for walking I get the Area from the Settings, and web walking works perfectly fine.

Link to comment
Share on other sites

8 minutes ago, the wamie said:

Well I use webwalking, and it works just fine in the script I am currently testing, I just use the enum to populate a JComboBox and fill the variables inside the Settings class.
Then for walking I get the Area from the Settings, and web walking works perfectly fine.

Not to vent on you, but I have to explain this topic so many times its getting annoying.

The closest bank in regards to the map coords is different than actual traversing. Consider wanting to grab the closest bank to you. The closest bank in coords is on the other side of a river which; you can't cross the river but its the closest. This is a common error in such approaches, because although its physically closer, actually walking there is much longer.

 

 

Link to comment
Share on other sites

17 minutes ago, Alek said:

Not to vent on you, but I have to explain this topic so many times its getting annoying.

The closest bank in regards to the map coords is different than actual traversing. Consider wanting to grab the closest bank to you. The closest bank in coords is on the other side of a river which; you can't cross the river but its the closest. This is a common error in such approaches, because although its physically closer, actually walking there is much longer.

 

 

No worries, I was just curious and thought you meant the coords won't work with the webwalk in that way, my appologies for not understanding correctly.
But that makes a lot of sense. Should have thought about that myself. Ah well, thanks for the explanation.

Link to comment
Share on other sites

3 minutes ago, the wamie said:

No worries, I was just curious and thought you meant the coords won't work with the webwalk in that way, my appologies for not understanding correctly.
But that makes a lot of sense. Should have thought about that myself. Ah well, thanks for the explanation.

When you pass an array/list of positions into webwalkevent, it automatically generates the fastest route. If you use prefetchrequirements, you can grab the closest bank without actually walking there.

  • Like 1
Link to comment
Share on other sites

On 6/20/2017 at 3:12 AM, k9thebeast said:

Wouldn't really call filling your own enum up with all the possible banks cleaner, but your pick lol. Combine the two if you like, his does have some nice components. @LoudPacks

But yea like Alek said it doesn't account for the actual path distance so it might not be the best way.

Edited by LoudPacks
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...