Add CSmelter script

This commit is contained in:
Yuri Moens 2021-10-28 00:01:08 +02:00
parent 1aa793b4bf
commit ab50d739c1
Signed by: ymo
GPG Key ID: F6D51D6FE15BE924
11 changed files with 348 additions and 1 deletions

9
.idea/artifacts/CSmelter_jar.xml generated Normal file
View File

@ -0,0 +1,9 @@
<component name="ArtifactManager">
<artifact type="jar" name="CSmelter:jar">
<output-path>$USER_HOME$/DreamBot/Scripts</output-path>
<root id="archive" name="CSmelter.jar">
<element id="module-output" name="CSmelter" />
<element id="module-output" name="Util" />
</root>
</artifact>
</component>

2
.idea/misc.xml generated
View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="11" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

1
.idea/modules.xml generated
View File

@ -10,6 +10,7 @@
<module fileurl="file://$PROJECT_DIR$/CMiner/CMiner.iml" filepath="$PROJECT_DIR$/CMiner/CMiner.iml" /> <module fileurl="file://$PROJECT_DIR$/CMiner/CMiner.iml" filepath="$PROJECT_DIR$/CMiner/CMiner.iml" />
<module fileurl="file://$PROJECT_DIR$/CPlanker/CPlanker.iml" filepath="$PROJECT_DIR$/CPlanker/CPlanker.iml" /> <module fileurl="file://$PROJECT_DIR$/CPlanker/CPlanker.iml" filepath="$PROJECT_DIR$/CPlanker/CPlanker.iml" />
<module fileurl="file://$PROJECT_DIR$/CShopper/CShopper.iml" filepath="$PROJECT_DIR$/CShopper/CShopper.iml" /> <module fileurl="file://$PROJECT_DIR$/CShopper/CShopper.iml" filepath="$PROJECT_DIR$/CShopper/CShopper.iml" />
<module fileurl="file://$PROJECT_DIR$/CSmelter/CSmelter.iml" filepath="$PROJECT_DIR$/CSmelter/CSmelter.iml" />
<module fileurl="file://$PROJECT_DIR$/CThiever/CThiever.iml" filepath="$PROJECT_DIR$/CThiever/CThiever.iml" /> <module fileurl="file://$PROJECT_DIR$/CThiever/CThiever.iml" filepath="$PROJECT_DIR$/CThiever/CThiever.iml" />
<module fileurl="file://$PROJECT_DIR$/CWintertodt/CWintertodt.iml" filepath="$PROJECT_DIR$/CWintertodt/CWintertodt.iml" /> <module fileurl="file://$PROJECT_DIR$/CWintertodt/CWintertodt.iml" filepath="$PROJECT_DIR$/CWintertodt/CWintertodt.iml" />
<module fileurl="file://$PROJECT_DIR$/DreambotScripts.iml" filepath="$PROJECT_DIR$/DreambotScripts.iml" /> <module fileurl="file://$PROJECT_DIR$/DreambotScripts.iml" filepath="$PROJECT_DIR$/DreambotScripts.iml" />

13
CSmelter/CSmelter.iml Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="client" level="project" />
<orderEntry type="module" module-name="Util" />
</component>
</module>

View File

@ -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()
);
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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