Jump to content

Feedback


Recommended Posts

Posted

Hey guys, I recently made this code for one of my scripts. Its the part that handles the GE interactions. It would be awesome if you could leave me some feedback because i just recently started with scripting and im also not very familiar with java. The snippet i use for getting the prices for the certain items returns it in Optional<String>.

 

Spoiler

import java.io.IOException;
import java.util.Optional;

import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.MethodProvider;
import org.osbot.rs07.utility.ConditionalSleep;

import data.ItemLookup;
import data.Property;


public class GE {

	public GE(MethodProvider mp) throws IOException, InterruptedException {
		
		Optional<String> braceletMax = null;
		Optional<String> braceletMin = null;
		Optional<String> etherMax = null;
		Optional<String> etherMin = null;
		Optional<String> runeMax = null;
		Optional<String> runeMin = null;
		
		int braceletPrice;
		int etherPrice;
		int runePrice;
		int buyingAmount;
		
		
		if(!mp.getGrandExchange().isOpen()) {
			NPC clerk = mp.getNpcs().closest("Grand Exchange Clerk");
			if(clerk != null) {
				if(clerk.interact("Exchange")) new ConditionalSleep(2000) {
					
					@Override
					public boolean condition() throws InterruptedException {
						return mp.getGrandExchange().isOpen();
					}
				}.sleep();
			}
					
		} else {
			
			braceletMax = ItemLookup.get("Bracelet of ethereum (uncharged)", Property.BUY_AVERAGE); 
			braceletMin = ItemLookup.get("Bracelet of ethereum (uncharged)", Property.SELL_AVERAGE); 
			etherMax = ItemLookup.get("Revenant ether", Property.BUY_AVERAGE); 
			etherMin = ItemLookup.get("Revenant ether", Property.SELL_AVERAGE); 
			runeMax = ItemLookup.get("Nature rune", Property.BUY_AVERAGE); 
			runeMin = ItemLookup.get("Nature rune", Property.SELL_AVERAGE); 
			
			braceletPrice = Math.max(Integer.valueOf(braceletMax.get()), Integer.valueOf(braceletMin.get())) + 500;
			etherPrice = Math.max(Integer.valueOf(etherMax.get()), Integer.valueOf(etherMin.get())) + 20;
			runePrice = Math.max(Integer.valueOf(runeMax.get()), Integer.valueOf(runeMin.get())) + 20;
			buyingAmount = (int) (mp.getInventory().getAmount("Coins") / (braceletPrice + etherPrice + runePrice));
			
			
				if(mp.getGrandExchange().buyItem(21817, "ether", braceletPrice, buyingAmount)) new ConditionalSleep(5000) {
					
					@Override
					public boolean condition() throws InterruptedException {
						return !mp.getGrandExchange().isBuyOfferOpen();
					}
				}.sleep();
			
			if(!mp.getGrandExchange().isBuyOfferOpen()) {
				if(mp.getGrandExchange().buyItem(21820, "ether", etherPrice, buyingAmount)) new ConditionalSleep(5000) {
					
					@Override
					public boolean condition() throws InterruptedException {
						return !mp.getGrandExchange().isBuyOfferOpen();
					}
				}.sleep();
			}
			
			if(!mp.getGrandExchange().isBuyOfferOpen()) {
				if(mp.getGrandExchange().buyItem(561, "nature", runePrice, buyingAmount)) new ConditionalSleep(5000) {
					
					@Override
					public boolean condition() throws InterruptedException {
						return !mp.getGrandExchange().isBuyOfferOpen();
					}
				}.sleep();
			}
			
			if(mp.getGrandExchange().collect(true)) {
				new ConditionalSleep(2000) {
					
					@Override
					public boolean condition() throws InterruptedException {
						return !mp.getWidgets().isVisible(465, 6);
					}
				}.sleep();
			}
			
			if(mp.getGrandExchange().close()) new ConditionalSleep(2000) {
				
				@Override
				public boolean condition() throws InterruptedException {
					return !mp.getGrandExchange().isOpen();
				}
			}.sleep();
			
			Banker.bankStocked = true;
			
		}
	}
	
}

 

 

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