Jump to content

Need someone to give feedback


Recommended Posts

Posted

I wrote a constructor for banking. I need one because the script i'm going to write requires a lot of banking. I just need someone to give me feedback because it is really messy. I'm also not that advanced in Java so the way I wrote it is probably really basic. 

 

Spoiler

	public Banking(Script sI, int depositMode, String[] depositFilter, String item1, int quantity1, BankMode mode1, String item2, int quantity2, BankMode mode2) throws InterruptedException {
		
		if(!sI.getBank().isOpen()) {
			sI.getBank().open();
			
			new ConditionalSleep(2000) {
				
				@Override
				public boolean condition() throws InterruptedException {
					return sI.getBank().isOpen();
				}
			}.sleep();
		} else {
			if(depositMode == 1) {
				sI.getBank().depositAll();
				new ConditionalSleep(2000) {
					
					@Override
					public boolean condition() throws InterruptedException {
						return sI.getInventory().isEmpty();
					}
				}.sleep();
			} else if (depositMode == 2){
				sI.getBank().depositAllExcept(depositFilter);
				new ConditionalSleep(2000) {
					
					@Override
					public boolean condition() throws InterruptedException {
						return !sI.getInventory().contains(depositFilter);
					}
				}.sleep();
			}
			
			if(item1 != null) {
				if(sI.getBank().contains(item1)) {
				if(!sI.getBank().getWithdrawMode().equals(mode1)) {
					sI.getBank().enableMode(mode1);
					new ConditionalSleep(2000) {
						
						@Override
						public boolean condition() throws InterruptedException {
							return sI.getBank().getWithdrawMode().equals(mode1);
						}
					}.sleep();
				}
				if(quantity1 > 0) {
				sI.getBank().withdraw(item1, quantity1);
				new ConditionalSleep(2000) {
					
					@Override
					public boolean condition() throws InterruptedException {
						return sI.getInventory().contains(item1);
					}
				}.sleep();	
				} else {
					sI.getBank().withdrawAll(item1);
					new ConditionalSleep(2000) {
						
						@Override
						public boolean condition() throws InterruptedException {
							return sI.getInventory().contains(item1);
						}
					}.sleep();
				}
			} else {
				sI.log("The bank is missing: " + item1);
			}
			}
			
			if(item2 != null) {
				if(sI.getBank().contains(item2)) {
				if(!sI.getBank().getWithdrawMode().equals(mode2)) {
					sI.getBank().enableMode(mode2);
					new ConditionalSleep(2000) {
						
						@Override
						public boolean condition() throws InterruptedException {
							return sI.getBank().getWithdrawMode().equals(mode2);
						}
					}.sleep();
				}
				if(quantity2 > 0) {
				sI.getBank().withdraw(item2, quantity2);
				new ConditionalSleep(2000) {
					
					@Override
					public boolean condition() throws InterruptedException {
						return sI.getInventory().contains(item2);
					}
				}.sleep();	
				} else {
					sI.getBank().withdrawAll(item2);
					new ConditionalSleep(2000) {
						
						@Override
						public boolean condition() throws InterruptedException {
							return sI.getInventory().contains(item2);
						}
					}.sleep();
				}
			} else {
				sI.log("The bank is missing: " + item2);
			}
			}
			
			if(sI.getBank().isOpen()) {
				sI.getBank().close();
				new ConditionalSleep(2000) {
					
					@Override
					public boolean condition() throws InterruptedException {
						return !sI.getBank().isOpen();
					}
				}.sleep();
			}
		}
		
	}

 

 

Posted (edited)

I'd start by making a banking class, breaking down each type of interaction with the bank. For example I'd have a method for both withdrawing and depositing - that's a good start.

Here's a quick example I use for withdrawing items from the bank on a script I'm currently working on:

MethodProvider api;
Area bank;
Settings settings; // Custom class - not part of the api

public void withdraw(HashMap<String, Integer> items) throws InterruptedException {
      if (!bank.contains(api.myPosition())) {
          api.getWalking().webWalk(bank);
      } else {
          if (!api.getBank().isOpen()) {
              if (api.getBank().open()) {
                  Sleep.sleepUntil(() -> api.getBank().isOpen(), 5000);
              }
          } else {
              for(Map.Entry<String, Integer> entry : items.entrySet()) {
                  String key = entry.getKey();
                  Integer amount = entry.getValue();
                  if (api.getBank().getAmount(key) >= amount) {
                      if (api.getBank().withdraw(key, amount)) {
                          Sleep.sleepUntil(() -> api.getInventory().getAmount(key) == amount, 5000);
                      }
                  } else {
                      settings.setQuit(true);
                  }
              }
          }
      }
  }

 

Edited by Ragnar Lothbrok

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