Jump to content

Farming leprechaun ToolShed


TheScrub

Recommended Posts

Bit Picture

7Ya4L.png

 

etc...

 

 

ToolShed class

package com.scrub.farming.leprechaun;

import org.osbot.script.Script;

public class ToolShed {
    private final int SHED_CONFIG = 615;
    private Script script;

    public ToolShed(Script script) {
        this.script = script;
    }

    public boolean contains(Tool t) {
        return  getCurrentAmount(t) > 0;
    }

    public int getCurrentAmount(Tool t) {
        return (script.client.getConfig(SHED_CONFIG) & t.getBitMask()) / t.getDecimalValue();
    }
    
    public int getSpaceLeft(Tool t){
        return t.getMaxAmount() - getCurrentAmount(t);
    }

}

 

Tool enum

 

package com.scrub.farming.leprechaun;

public enum Tool {

    RAKE("Rake", 1, 1, 0b1), SEED_DRIBBER("Seed dibber", 1, 2, 0b10), SPADE(
            "Spade", 1, 4, 0b100), SECATEURS("Secateurs", 1, 8, 0b1000), WATERING_CAN(
            "Watering can", 1, 16, 0b10000), GARDENING_TROWEL(
            "Gardening trowel", 1, 256, 0b100000000), BUCKET("Bucket", 31, 512,
            0b1111100000000), COMPOST("Compost", 255, 16384,
            0b111111100000000000000), SUPER_COMPOST("Super compost", 255,
            4194304, 0b11111111000000000000000000000);

    private final String name;
    private final int maxAmount;
    private final int decimalValue;
    private final int bitMask;

    Tool(final String name, final int maxAmount, final int decimalValue,
            final int bitMask) {
        this.name = name;
        this.maxAmount = maxAmount;
        this.decimalValue = decimalValue;
        this.bitMask = bitMask;
    }

    public String getName() {
        return name;
    }

    public int getMaxAmount() {
        return maxAmount;
    }

    public int getDecimalValue() {
        return decimalValue;
    }

    public int getBitMask() {
        return bitMask;
    }

    public int getSlotNumber() {
        for (int i = 0; i < Tool.values().length; i++) {
            if (equals(Tool.values()[i])) {
                return i;
            }
        }
        return -1;
    }

}



 

ShedContainer class

 

package com.scrub.farming.leprechaun;

import java.awt.Point;
import java.awt.Rectangle;

import org.osbot.script.Script;
import org.osbot.script.mouse.RectangleDestination;
import org.osbot.script.rs2.ui.RS2InterfaceChild;

public class ShedContainer {

	private Script script;

	private final int START_WIDTH = 172;
	private final int START_HEIGHT = 105;
	private final int WIDTH = 95;
	private final int HEIGHT = 64;

	private Point getPoint(int slot) {
		int column = slot / 3;
		int row = slot % 3;
		int x = (int) (START_WIDTH + (row * WIDTH));
		int y = (int) START_HEIGHT + (column * HEIGHT);
		return new Point(x, y);
	}

	private Rectangle getRectangle(int slot) {
		Point p = getPoint(slot);
		return new Rectangle(p.x, p.y, 35, 44);
	}

	public ShedContainer(Script script) {
		this.script = script;
	}

	private boolean interact(Rectangle rec, String action)
			throws InterruptedException {
		return script.selectOption(null, new RectangleDestination(rec), action);
	}

	public boolean interact(Tool t, String action) throws InterruptedException {
		return interact(getRectangle(t.getSlotNumber()), action);
	}
	
	public boolean closeScreen() throws InterruptedException{
		return isOpen() && getChild(125,88) !=null && getChild(125,88).interact("Close");
	}

	public boolean isOpen(){
		return getChild(125,67) !=null;
	}
	
	private RS2InterfaceChild getChild(int parent, int child) {
		if (script.client.getInterface(parent) != null) {
			RS2InterfaceChild c = script.client.getInterface(parent).getChild(child);
			if (c != null && c.isVisible()) {
				return c;
			}
		}
		return null;
	}


}

7ZB8A.png

Edited by TheScrub
  • Like 2
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...