Jump to content
MarWo22

Feedback

Recommended Posts

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

 

 

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.

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