Jump to content

[OS] Edgeville jewellery crafter | Gold/Silver | All jewellery


soms
 Share

Recommended Posts

Crafts any jewellery using Edgeville furnace 💰 glhf

 

import com.epicbot.api.shared.APIContext;
import com.epicbot.api.shared.GameType;
import com.epicbot.api.shared.entity.SceneObject;
import com.epicbot.api.shared.entity.WidgetChild;
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.Random;
import com.epicbot.api.shared.util.time.Time;

@ScriptManifest(name = "JewelleryCrafter", gameType = GameType.OS)
public class EdgeJewelleryCrafter extends LoopScript {

    private long anim;
    private int runE = Random.nextInt(50,80);

    private static final int GOLD_FURNACE_GROUP = 446;
    private static final int SILVER_FURNACE_GROUP = 6;

    private static final Tile FURNACE_ROOM = new Tile(3108, 3499, 0);
    private static final Tile EDGE_BANK = new Tile(3096, 3496, 0);

    /*
    Settings
     */
    private static final String JEWELLERY_NAME = "Diamond bracelet";
    private static final String MOULD = "Bracelet mould";
    private static final String BAR = "Gold bar";

    private static final boolean USING_GEM = true;
    private static final String GEM = "Diamond";

    @Override
    protected int loop() {
        APIContext ctx = getAPIContext();
        int hr = Time.getHumanReaction();

        if (ctx.walking().getRunEnergy() > runE
                && !ctx.walking().isRunEnabled()
                && !localAnimating(ctx)
                && !ctx.bank().isOpen()) {
            ctx.walking().setRun(true);
            runE = Random.nextInt(30,80);
            return hr;
        }

        if (ctx.inventory().containsAll(BAR, MOULD)
                && (!USING_GEM || ctx.inventory().contains(GEM))
                && !localAnimating(ctx)) {
            if (isOpen(ctx) && initiate(ctx, JEWELLERY_NAME)) {
                Time.sleep(5000, () -> localAnimating(ctx));
                return hr;
            }

            SceneObject furnace = ctx.objects().query().named("Furnace").results().first();
            if (furnace != null) {
                if (furnace.isVisible() && furnace.interact("Smelt")) {
                    Time.sleep(10000, () -> isOpen(ctx));
                    return hr;
                } else if (!furnace.isVisible()) {
                    ctx.walking().walkTo(FURNACE_ROOM);
                    Time.sleep(10000, ()->furnace.isVisible() || furnace.distanceTo(ctx) <= 2);
                }
            }

        } else if (!ctx.inventory().containsAll(BAR, MOULD)
                || (USING_GEM && !ctx.inventory().contains(GEM))) {
            if (openBankOnScreen(ctx)) {
                ctx.bank().depositAllExcept(MOULD, BAR);
                if (JEWELLERY_NAME.startsWith("Gold")) {
                    banking(ctx, MOULD, BAR);
                } else {
                    banking(ctx, MOULD, BAR, GEM);
                }
            } else {
                ctx.walking().walkTo(EDGE_BANK.randomize(2,0));
                Time.sleep(15000,() -> openBankOnScreen(ctx));
            }
        }

        return hr;
    }

    private static boolean getItem(int amount, String name, APIContext ctx) {
        if (ctx.bank().contains(name)) {
            ctx.bank().withdraw(amount, name);
            Time.sleep(4000, () -> APIContext.get().inventory().contains(name));
            return true;
        } else {
            ctx.script().stop("No "+name+" in bank, stopping.");
        }
        return false;
    }

    public static boolean banking(APIContext ctx, String... item) {
        if (!ctx.inventory().contains(item[0]) && getItem(1, item[0], ctx))

        if (item.length == 2) {
            if (!ctx.inventory().contains(item[1]) && getItem(ctx.bank().getCount(item[1]), item[1], ctx))


            return ctx.inventory().containsAll(item[0], item[1]);

        }

        if (item.length == 3) {
            if (ctx.inventory().getCount(item[1]) < 13 && getItem(13, item[1], ctx))

            if (ctx.inventory().getCount(item[2]) < 13 && getItem(13, item[2], ctx))

            return ctx.inventory().containsAll(item[0], item[1], item[2]);
        }
        return false;
    }

    public static boolean openBankOnScreen(APIContext ctx) {
        if (ctx.bank().isOpen()) {
            return true;
        }
        SceneObject bank = ctx.objects().query().actions("Bank").visible().results().nearest();
        if (bank != null && bank.interact("Bank")) {
            Time.sleep(10000, ()->ctx.bank().isOpen());
        }
        return ctx.bank().isOpen();
    }

    @Override
    public boolean onStart(String... strings) {
        return true;
    }

    private boolean localAnimating(APIContext ctx) {
        if (ctx.localPlayer().isAnimating()) {
            anim = System.currentTimeMillis();
            return true;
        }
        return System.currentTimeMillis() <= (anim + Random.nextInt(2600, 3600));

    }

    public static boolean isOpen(APIContext ctx) {
        return ctx.widgets().query().group(GOLD_FURNACE_GROUP, SILVER_FURNACE_GROUP).visible().results().first() != null;
    }

    public static boolean initiate(APIContext ctx, String name) {
        WidgetChild named = ctx.widgets().query().visible().group(GOLD_FURNACE_GROUP, SILVER_FURNACE_GROUP).filter(w -> w.getActions().size() != 0).itemName(name).results().first();
        if (named != null) {
            return named.interact();
        }

        WidgetChild actionable = ctx.widgets().query().visible().group(GOLD_FURNACE_GROUP, SILVER_FURNACE_GROUP).filter(w -> w.hasActionMatch("Make "+name)).results().first();
        if (actionable != null) {
            return actionable.interact();
        }

        return false;
    }
}

 

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

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.

 Share

×
×
  • Create New...