Jump to content

[Open Source] Λ Low Level Thief [Men/Tea Stall]


Recommended Posts

Here you go boys. Have fun. Any problems or queries, hit me up.

 

To clarify, it's written to thieve men and then progress to the Varrock tea stall at level 5. Traversal is dependant on the EB web walker and I haven't had chance to do much testing, so bare that in mind.

import com.epicbot.api.shared.APIContext;
import com.epicbot.api.shared.GameType;
import com.epicbot.api.shared.entity.*;
import com.epicbot.api.shared.model.Skill;
import com.epicbot.api.shared.model.Tile;
import com.epicbot.api.shared.script.LoopScript;
import com.epicbot.api.shared.script.ScriptManifest;
import com.epicbot.api.shared.util.details.Completable;
import com.epicbot.api.shared.util.time.Time;
import com.epicbot.api.shared.util.time.Timer;

import java.awt.*;
import java.util.function.Predicate;

@ScriptManifest(name = "Λ Low Level Thief", gameType = GameType.OS)
public class LambdaLowLevelThief extends LoopScript {

    private final Timer runTimer = new Timer(0);

    private final Timer experienceTimer = new Timer(5000);

    private final double version = 0.1;

    private int experienceGained, startExperience = 0;

    private final Predicate<Item> dropItemsPredicate = i -> i != null && (i.getName().contains("up") || i.getName().contains("pouch"));

    private final Tile teaStallTile = new Tile(3267, 3414, 0);
    private final Tile manAreaTile = new Tile(3235, 3399, 0);

    private String status = "";

    @Override
    protected int loop() {

        if (getAPIContext().client().isLoggedIn()) {
            handleCalculations();
            doTasks();
        }

        return 50;
    }

    private enum Task {
        PICKPOCKET_MEN, TEA_STALL, DROP_GARBAGE, OPEN_COIN_POUCHES
    }

    private void handleCalculations() {
        if (startExperience == 0) {
            startExperience = getAPIContext().skills().get(Skill.Skills.THIEVING).getExperience();
        } else {
            if (!experienceTimer.isRunning()) {
                experienceGained = getAPIContext().skills().get(Skill.Skills.THIEVING).getExperience() - startExperience;
                experienceTimer.reset();
            }
        }
    }

    private void doTasks() {

        status = getCurrentTask().toString();

        switch (getCurrentTask()) {
            case DROP_GARBAGE:
                getAPIContext().inventory().dropAll(dropItemsPredicate);
                break;
            case OPEN_COIN_POUCHES:
                handleItem("Coin pouch", "Open-all", 1200, () -> !getAPIContext().inventory().contains("Coin pouch"));
                break;
            case PICKPOCKET_MEN:
                handlePickpocketing();
                break;
            case TEA_STALL:
                handleTeaStall();
                break;
        }
    }

    private boolean handleTeaStall() {
        SceneObject emptyStall = getAPIContext().objects().query().nameMatches("Market stall").results().nearest();
        int cupsOfTea = getAPIContext().inventory().contains(i -> i.getName().contains("up")) ? getAPIContext().inventory().getCount(i -> i.getName().contains("up")) : 0;
        if (emptyStall == null) {
            SceneObject teaStall = getAPIContext().objects().query().nameMatches("Tea stall").actions("Steal-from").results().nearest();
            if (handleEntity(teaStall, "Steal-from", teaStallTile)) {
                return Time.sleep(1200, 1800, () -> getAPIContext().inventory().getCount(cupsOfTea) > cupsOfTea);
            }
        }
        return false;
    }

    private boolean handleEntity(GameEntity entity, String action, Tile entityLocation) {
        if (entity == null) {
            getAPIContext().webWalking().walkTo(entityLocation);
        } else if (!entity.canReach(getAPIContext())) {
            getAPIContext().walking().walkTo(entityLocation);
        } else {
            if (entity.isVisible()) {
                return entity.contains(getAPIContext().mouse().getLocation()) ? getAPIContext().mouse().click() : entity.interact(action);
            } else {
                getAPIContext().camera().turnTo(entity);
            }
        }
        return false;
    }

    private boolean handlePickpocketing() {
        if (!isStunned()) {
            int thievingExperience = getAPIContext().skills().get(Skill.Skills.THIEVING).getExperience();
            NPC man = getAPIContext().npcs().query().nameMatches("Man").actions("Pickpocket").results().nearest();
            if (handleEntity(man, "Pickpocket", manAreaTile)) {
                return Time.sleep(1000, 2000, () -> getAPIContext().skills().get(Skill.Skills.THIEVING).getExperience() > thievingExperience);
            }
        } else {
            status = "STUNNED";
        }
        return false;
    }

    private boolean isStunned() {
        return getAPIContext().localPlayer() != null && getAPIContext().localPlayer().getModelHeight() >= 1000;
    }

    private Task getCurrentTask() {
        if (getAPIContext().inventory().isFull()) {
            return Task.DROP_GARBAGE;
        } else {
            ItemWidget coinPouch = getAPIContext().inventory().getItem("Coin pouch");
            if (coinPouch != null && coinPouch.getStackSize() >= getRandomNumber(5, 25)) {
                return Task.OPEN_COIN_POUCHES;
            } else {
                int thievingLevel = getAPIContext().skills().get(Skill.Skills.THIEVING).getRealLevel();
                return thievingLevel < 5 ? Task.PICKPOCKET_MEN : Task.TEA_STALL;
            }
        }
    }

    private boolean handleItem(String itemName, String action, int timeOut, Completable condition) {
        ItemWidget itemWidget = getAPIContext().inventory().getItem(itemName);
        if (itemWidget == null) return false;
        if (itemWidget.interact(action)) {
            return Time.sleep(timeOut, condition);
        }
        return false;
    }

    private int getRandomNumber(int min, int max) {
        return (int) ((Math.random() * (max - min)) + min);
    }

    @Override
    public boolean onStart(String... strings) {
        System.out.println("Starting " + getManifest().name() + " v" + version);
        return true;
    }


    private int getHourlyRate(int i) {
        return (int) (i / (runTimer.getElapsed() / 3600000.0D));
    }

    @Override
    protected void onPaint(Graphics2D g2d, APIContext ctx) {
        g2d.setColor(Color.WHITE);
        g2d.drawString(getManifest().name() + " v" + version, 20, 30);
        g2d.drawString("Time running: " + runTimer.toElapsedString(), 20, 50);
        g2d.drawString("Status: " + status, 20, 70);
        g2d.drawString("Experience gained: " + experienceGained + " (" + getHourlyRate(experienceGained) + ")", 20, 90);
        super.onPaint(g2d, ctx);
    }
}

 

Edited by Pseudo
  • Thanks 1
Link to post
Share on other sites
  • Pseudo changed the title to [Open Source] Λ Low Level Thief [Men/Tea Stall]

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.

×
×
  • Create New...