Jump to content

Need someone to give feedback


MarWo22

Recommended Posts

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();
			}
		}
		
	}

 

 

Link to comment
Share on other sites

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