diff --git a/.idea/artifacts/CSmelter_jar.xml b/.idea/artifacts/CSmelter_jar.xml new file mode 100644 index 0000000..784169e --- /dev/null +++ b/.idea/artifacts/CSmelter_jar.xml @@ -0,0 +1,9 @@ + + + $USER_HOME$/DreamBot/Scripts + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 012255a..e0844bc 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index 0e1952a..f961fe6 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -10,6 +10,7 @@ + diff --git a/CSmelter/CSmelter.iml b/CSmelter/CSmelter.iml new file mode 100644 index 0000000..ac9e1f0 --- /dev/null +++ b/CSmelter/CSmelter.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/CSmelter/src/io/reisub/dreambot/csmelter/CSmelter.java b/CSmelter/src/io/reisub/dreambot/csmelter/CSmelter.java new file mode 100644 index 0000000..3840bb9 --- /dev/null +++ b/CSmelter/src/io/reisub/dreambot/csmelter/CSmelter.java @@ -0,0 +1,45 @@ +package io.reisub.dreambot.csmelter; + +import io.reisub.dreambot.csmelter.tasks.DoBank; +import io.reisub.dreambot.csmelter.tasks.OpenBank; +import io.reisub.dreambot.csmelter.tasks.SetCamera; +import io.reisub.dreambot.csmelter.tasks.Smelt; +import io.reisub.dreambot.util.CTaskScript; +import io.reisub.dreambot.util.Constants; +import io.reisub.dreambot.util.randomevents.GenieSolver; +import io.reisub.dreambot.util.tasks.Run; +import io.reisub.dreambot.util.tasks.kitten.KittenTask; +import org.dreambot.api.methods.skills.Skill; +import org.dreambot.api.script.Category; +import org.dreambot.api.script.ScriptManifest; +import org.dreambot.api.script.TaskNode; + +@ScriptManifest(category = Category.SMITHING, name = "CSmelter", author = Constants.AUTHOR, version = 1.0) +public class CSmelter extends CTaskScript { + public static SmeltingOption smeltingOption = SmeltingOption.GOLD_BRACELET; + + @Override + public void onStart() { + super.onStart(); + getRandomManager().registerSolver(new GenieSolver(GenieSolver.Skill.HERBLORE)); + + if (smeltingOption.getMould().equals("")) { + getUI().addSkills(Skill.SMITHING); + } else { + getUI().addSkills(Skill.CRAFTING); + } + + TaskNode kittenTask = KittenTask.getInstance(); + if (kittenTask != null) { + addNodes(kittenTask); + } + + addNodes( + new SetCamera(), + new Run(), + new Smelt(), + new OpenBank(), + new DoBank() + ); + } +} diff --git a/CSmelter/src/io/reisub/dreambot/csmelter/Ingredient.java b/CSmelter/src/io/reisub/dreambot/csmelter/Ingredient.java new file mode 100644 index 0000000..f742801 --- /dev/null +++ b/CSmelter/src/io/reisub/dreambot/csmelter/Ingredient.java @@ -0,0 +1,23 @@ +package io.reisub.dreambot.csmelter; + +public class Ingredient { + private final String name; + private final int amount; + + public Ingredient(String name, int amount) { + this.name = name; + this.amount = amount; + } + + public Ingredient(String name) { + this(name, 1); + } + + public String getName() { + return name; + } + + public int getAmount() { + return amount; + } +} diff --git a/CSmelter/src/io/reisub/dreambot/csmelter/SmeltingOption.java b/CSmelter/src/io/reisub/dreambot/csmelter/SmeltingOption.java new file mode 100644 index 0000000..6694a18 --- /dev/null +++ b/CSmelter/src/io/reisub/dreambot/csmelter/SmeltingOption.java @@ -0,0 +1,71 @@ +package io.reisub.dreambot.csmelter; + +public enum SmeltingOption { + GOLD_BAR(new Ingredient("Gold ore"), "Gold bar", 6), + GOLD_BRACELET(new Ingredient("Gold bar"), "Gold bracelet", 46, "Bracelet mould"); + + private final Ingredient[] ingredients; + private final String endProduct, mould; + private final int hotkey, maxCraftsPerInventory; + + SmeltingOption(Ingredient[] ingredients, String endProduct, int hotkey, String mould) { + this.ingredients = ingredients; + this.endProduct = endProduct; + this.hotkey = hotkey; + this.mould = mould; + + int totalIngredientsRequired = 0; + + for (Ingredient i : ingredients) { + totalIngredientsRequired += i.getAmount(); + } + + if (mould.equals("")) { + maxCraftsPerInventory = Math.floorDiv(28, totalIngredientsRequired); + } else { + maxCraftsPerInventory = Math.floorDiv(27, totalIngredientsRequired); + } + } + + SmeltingOption(Ingredient[] ingredients, String endProduct, int hotkey) { + this(ingredients, endProduct, hotkey, ""); + } + + SmeltingOption(Ingredient ingredient, String endProduct, int hotkey, String mould) { + this(new Ingredient[]{ingredient}, endProduct, hotkey, mould); + } + + SmeltingOption(Ingredient ingredient, String endProduct, int hotkey) { + this(new Ingredient[]{ingredient}, endProduct, hotkey, ""); + } + + public Ingredient[] getIngredients() { + return ingredients; + } + + public String[] getIngredientsNames() { + String[] ingredientNames = new String[ingredients.length]; + + for (int i = 0; i < ingredients.length; i++) { + ingredientNames[i] = ingredients[i].getName(); + } + + return ingredientNames; + } + + public int getMaxCraftsPerInventory() { + return maxCraftsPerInventory; + } + + public String getEndProduct() { + return endProduct; + } + + public int getHotkey() { + return hotkey; + } + + public String getMould() { + return mould; + } +} diff --git a/CSmelter/src/io/reisub/dreambot/csmelter/tasks/DoBank.java b/CSmelter/src/io/reisub/dreambot/csmelter/tasks/DoBank.java new file mode 100644 index 0000000..48ac2e4 --- /dev/null +++ b/CSmelter/src/io/reisub/dreambot/csmelter/tasks/DoBank.java @@ -0,0 +1,53 @@ +package io.reisub.dreambot.csmelter.tasks; + +import io.reisub.dreambot.csmelter.CSmelter; +import io.reisub.dreambot.csmelter.Ingredient; +import org.dreambot.api.methods.Calculations; +import org.dreambot.api.methods.MethodProvider; +import org.dreambot.api.methods.container.impl.Inventory; +import org.dreambot.api.methods.container.impl.bank.Bank; +import org.dreambot.api.script.TaskNode; + +public class DoBank extends TaskNode { + @Override + public boolean accept() { + return Bank.isOpen(); + } + + @Override + public int execute() { + if (Inventory.contains(CSmelter.smeltingOption.getEndProduct())) { + Bank.depositAllExcept(item -> item.getName().endsWith("mould")); + if (!MethodProvider.sleepUntil(() -> Inventory.isEmpty() || Inventory.onlyContains(item -> item.getName().endsWith("mould")), Calculations.random(2000, 2500))) return Calculations.random(250, 400); + } + + String mould = CSmelter.smeltingOption.getMould(); + if (!mould.equals("")) { + if (!Inventory.contains(mould)) { + Bank.withdraw(mould, 1); + if (!MethodProvider.sleepUntil(() -> Inventory.contains(mould), Calculations.random(2000, 2500))) { + return Calculations.random(250, 400); + } + } + } + + String[] names = CSmelter.smeltingOption.getIngredientsNames(); + + if (CSmelter.smeltingOption.getIngredients().length == 1) { + Bank.withdrawAll(CSmelter.smeltingOption.getIngredients()[0].getName()); + } else { + int craftsPerInventory = CSmelter.smeltingOption.getMaxCraftsPerInventory(); + + for (Ingredient i : CSmelter.smeltingOption.getIngredients()) { + if (Inventory.count(i.getName()) < i.getAmount() * craftsPerInventory) { + Bank.withdraw(i.getName(), i.getAmount() * craftsPerInventory); + } + MethodProvider.sleep(200, 400); + } + } + + MethodProvider.sleepUntil(() -> Inventory.containsAll(names), Calculations.random(2000, 2500)); + + return Calculations.random(250, 400); + } +} diff --git a/CSmelter/src/io/reisub/dreambot/csmelter/tasks/OpenBank.java b/CSmelter/src/io/reisub/dreambot/csmelter/tasks/OpenBank.java new file mode 100644 index 0000000..90b7185 --- /dev/null +++ b/CSmelter/src/io/reisub/dreambot/csmelter/tasks/OpenBank.java @@ -0,0 +1,42 @@ +package io.reisub.dreambot.csmelter.tasks; + +import io.reisub.dreambot.csmelter.CSmelter; +import io.reisub.dreambot.util.Util; +import org.dreambot.api.methods.Calculations; +import org.dreambot.api.methods.MethodProvider; +import org.dreambot.api.methods.container.impl.Inventory; +import org.dreambot.api.methods.container.impl.bank.Bank; +import org.dreambot.api.methods.interactive.GameObjects; +import org.dreambot.api.methods.walking.impl.Walking; +import org.dreambot.api.script.TaskNode; +import org.dreambot.api.wrappers.interactive.GameObject; + +public class OpenBank extends TaskNode { + @Override + public boolean accept() { + return !Bank.isOpen() + && !Inventory.containsAll(CSmelter.smeltingOption.getIngredientsNames()) + && Util.playerIsIdle(); + } + + @Override + public int execute() { + GameObject bank = GameObjects.closest("Bank booth"); + if (bank == null) return Calculations.random(250, 400); + + if (!bank.isOnScreen()) { + while (bank.distance() > Calculations.random(6, 9)) { + if (Walking.shouldWalk(Calculations.random(4, 6))) { + Walking.walk(bank); + } + } + } + + bank.interactForceLeft("Bank"); + if (!Util.sleepUntilMoving()) return Calculations.random(250, 400); + + MethodProvider.sleepUntil(Bank::isOpen, Calculations.random(10000, 11000)); + + return Calculations.random(250, 400); + } +} diff --git a/CSmelter/src/io/reisub/dreambot/csmelter/tasks/SetCamera.java b/CSmelter/src/io/reisub/dreambot/csmelter/tasks/SetCamera.java new file mode 100644 index 0000000..b770c3d --- /dev/null +++ b/CSmelter/src/io/reisub/dreambot/csmelter/tasks/SetCamera.java @@ -0,0 +1,19 @@ +package io.reisub.dreambot.csmelter.tasks; + +import org.dreambot.api.methods.Calculations; +import org.dreambot.api.methods.input.Camera; +import org.dreambot.api.script.TaskNode; + +public class SetCamera extends TaskNode { + @Override + public boolean accept() { + return Camera.getPitch() <= 380; + } + + @Override + public int execute() { + Camera.mouseRotateTo(Calculations.random(60, 302), 383); + + return Calculations.random(250, 400); + } +} diff --git a/CSmelter/src/io/reisub/dreambot/csmelter/tasks/Smelt.java b/CSmelter/src/io/reisub/dreambot/csmelter/tasks/Smelt.java new file mode 100644 index 0000000..7985e9b --- /dev/null +++ b/CSmelter/src/io/reisub/dreambot/csmelter/tasks/Smelt.java @@ -0,0 +1,71 @@ +package io.reisub.dreambot.csmelter.tasks; + +import io.reisub.dreambot.csmelter.CSmelter; +import io.reisub.dreambot.util.Util; +import org.dreambot.api.methods.Calculations; +import org.dreambot.api.methods.MethodProvider; +import org.dreambot.api.methods.container.impl.Inventory; +import org.dreambot.api.methods.container.impl.bank.Bank; +import org.dreambot.api.methods.input.Keyboard; +import org.dreambot.api.methods.interactive.GameObjects; +import org.dreambot.api.methods.interactive.Players; +import org.dreambot.api.methods.walking.impl.Walking; +import org.dreambot.api.methods.widget.Widgets; +import org.dreambot.api.script.TaskNode; +import org.dreambot.api.wrappers.interactive.GameObject; +import org.dreambot.api.wrappers.widgets.WidgetChild; + +public class Smelt extends TaskNode { + private boolean firstTime = true; + + @Override + public boolean accept() { + return Inventory.containsAll(CSmelter.smeltingOption.getIngredientsNames()) + && Util.playerIsIdle(1000); + } + + @Override + public int execute() { + GameObject furnace = GameObjects.closest("Furnace"); + if (furnace == null) return Calculations.random(250, 400); + + if (Bank.isOpen()) { + Walking.walk(furnace); + MethodProvider.sleep(300, 600); + } + + furnace.interact(); + if (!furnace.getInteractableFrom().contains(Players.localPlayer().getTile())) { + if (!Util.sleepUntilMoving()) return Calculations.random(250, 400); + } + + MethodProvider.sleepWhile(() -> furnace.distance() > Calculations.random(2, 4), Calculations.random(10000, 11000)); + + if (CSmelter.smeltingOption.getMould().equals("")) { + if (!firstTime) Keyboard.holdSpace(() -> { + WidgetChild w = Widgets.getChildWidget(270, 13); + return (w != null && w.isVisible()) || Players.localPlayer().isAnimating(); + }, Calculations.random(4000, 4500)); + + if (!MethodProvider.sleepUntil(() -> { + WidgetChild w = Widgets.getChildWidget(270, 13); + return w != null && w.isVisible(); + }, Calculations.random(5000, 5500))) return Calculations.random(250, 400); + + Keyboard.type(CSmelter.smeltingOption.getHotkey(), false, false); + if (Util.sleepUntilAnimating()) firstTime = false; + } else { + if (!MethodProvider.sleepUntil(() -> { + WidgetChild w = Widgets.getChildWidget(446, CSmelter.smeltingOption.getHotkey()); + return w != null && w.isVisible(); + }, Calculations.random(3000, 3500))) return Calculations.random(250, 400); + + WidgetChild w = Widgets.getChildWidget(446, CSmelter.smeltingOption.getHotkey()); + w.interact(); + + Util.sleepUntilAnimating(); + } + + return Calculations.random(250, 400); + } +}