Initial commit

This commit is contained in:
2021-10-16 17:25:28 +02:00
commit 98dd5c66b6
41 changed files with 1484 additions and 0 deletions

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="module" module-name="Util" />
<orderEntry type="library" name="client" level="project" />
</component>
</module>

View File

@ -0,0 +1,23 @@
package io.reisub.dreambot.cwintertodt;
import io.reisub.dreambot.cwintertodt.tasks.Wait;
import io.reisub.dreambot.cwintertodt.tasks.WintertodtTask;
import io.reisub.dreambot.util.Constants;
import io.reisub.dreambot.util.tasks.Eat;
import org.dreambot.api.script.Category;
import org.dreambot.api.script.ScriptManifest;
import org.dreambot.api.script.impl.TaskScript;
@SuppressWarnings("unused")
@ScriptManifest(name = "CWintertodt", description = "Wintertodt runner", author = Constants.AUTHOR,
version = 1.0, category = Category.MINIGAME, image = "")
public class CWintertodt extends TaskScript {
public void onStart() {
addNodes(
new Eat(),
new Wait(),
WintertodtTask.createWintertodtTask()
);
}
}

View File

@ -0,0 +1,55 @@
package io.reisub.dreambot.cwintertodt.tasks;
import io.reisub.dreambot.util.Constants;
import io.reisub.dreambot.util.Util;
import org.dreambot.api.methods.Calculations;
import org.dreambot.api.methods.container.impl.Inventory;
import org.dreambot.api.methods.interactive.GameObjects;
import org.dreambot.api.methods.interactive.Players;
import org.dreambot.api.script.TaskNode;
import org.dreambot.api.wrappers.interactive.GameObject;
public class Burn extends TaskNode {
private final WintertodtTask parent;
public Burn(WintertodtTask parent) {
this.parent = parent;
}
@Override
public boolean accept() {
if (!parent.isInterrupted() && !Util.playerIsIdle(1400)) {
return false;
}
return (parent.getRootCount() == 0 && parent.getKindlingCount() > 0) || parent.shouldBurnBeforeRunningOutOfTime();
}
@Override
public int execute() {
parent.setInterrupted(false);
parent.setBurning(true);
if (!Inventory.contains(Constants.BRUMA_ROOT, Constants.BRUMA_KINDLING)) return 0;
GameObject burningBrazier = GameObjects.closest(Constants.BURNING_BRAZIER);
GameObject brazier = GameObjects.closest(Constants.BRAZIER);
if (burningBrazier == null) return 0;
if (brazier != null && Players.localPlayer().distance(burningBrazier) > Players.localPlayer().distance(brazier)) {
brazier.interact();
Util.sleepUntilMovingOrAnimating();
return Calculations.random(200, 300);
}
burningBrazier.interactForceLeft(Constants.FEED);
Util.sleepUntilMovingAndAnimating();
return Calculations.random(200, 300);
}
}

View File

@ -0,0 +1,41 @@
package io.reisub.dreambot.cwintertodt.tasks;
import io.reisub.dreambot.util.Constants;
import io.reisub.dreambot.util.Util;
import org.dreambot.api.methods.Calculations;
import org.dreambot.api.methods.container.impl.Inventory;
import org.dreambot.api.methods.interactive.GameObjects;
import org.dreambot.api.script.TaskNode;
import org.dreambot.api.wrappers.interactive.GameObject;
public class Chop extends TaskNode {
private final WintertodtTask parent;
public Chop(WintertodtTask parent) {
this.parent = parent;
}
@Override
public boolean accept() {
return !Inventory.isFull() && parent.getKindlingCount() == 0 && !parent.shouldBurnBeforeRunningOutOfTime() && !parent.isBurning() && parent.getEnergy() >= 5;
}
@Override
public int execute() {
if (parent.isInterrupted()) {
parent.setInterrupted(false);
return 0;
}
GameObject roots = GameObjects.closest(Constants.BRUMA_ROOTS);
if (roots == null) return 0;
roots.interactForceLeft(Constants.CHOP);
Util.sleepUntilMovingAndAnimating();
return Calculations.random(200, 300);
}
}

View File

@ -0,0 +1,32 @@
package io.reisub.dreambot.cwintertodt.tasks;
import io.reisub.dreambot.util.CInventory;
import io.reisub.dreambot.util.Constants;
import io.reisub.dreambot.util.Util;
import org.dreambot.api.methods.Calculations;
import org.dreambot.api.script.TaskNode;
public class Fletch extends TaskNode {
private WintertodtTask parent;
public Fletch(WintertodtTask parent) {
this.parent = parent;
}
@Override
public boolean accept() {
return parent.getRootCount() > 0 && !parent.shouldBurnBeforeRunningOutOfTime() && !parent.isBurning();
}
@Override
public int execute() {
parent.setInterrupted(false);
CInventory.useOnNearest(Constants.KNIFE, Constants.BRUMA_ROOT);
Util.sleepUntilAnimating();
return Calculations.random(200, 300);
}
}

View File

@ -0,0 +1,45 @@
package io.reisub.dreambot.cwintertodt.tasks;
import io.reisub.dreambot.util.Constants;
import io.reisub.dreambot.util.Util;
import org.dreambot.api.methods.Calculations;
import org.dreambot.api.methods.interactive.GameObjects;
import org.dreambot.api.methods.interactive.Players;
import org.dreambot.api.script.TaskNode;
import org.dreambot.api.wrappers.interactive.GameObject;
import org.dreambot.api.wrappers.interactive.Player;
public class LightOrFix extends TaskNode {
private WintertodtTask parent;
public LightOrFix(WintertodtTask parent) {
this.parent = parent;
}
@Override
public boolean accept() {
GameObject brazier = GameObjects.closest(Constants.BRAZIER);
if (brazier == null) return false;
Player player = Players.localPlayer();
return (player.distance(brazier) < 2);
}
@Override
public int execute() {
GameObject brazier = GameObjects.closest(Constants.BRAZIER);
if (brazier.hasAction(Constants.LIGHT)) {
brazier.interactForceLeft(Constants.LIGHT);
} else {
brazier.interactForceLeft(Constants.FIX);
}
Util.sleepUntilMovingOrAnimating();
return Calculations.random(200, 300);
}
}

View File

@ -0,0 +1,25 @@
package io.reisub.dreambot.cwintertodt.tasks;
import io.reisub.dreambot.util.Constants;
import org.dreambot.api.methods.Calculations;
import org.dreambot.api.methods.widget.Widgets;
import org.dreambot.api.script.TaskNode;
import org.dreambot.api.wrappers.widgets.WidgetChild;
public class Wait extends TaskNode {
@Override
public boolean accept() {
WidgetChild child = Widgets.getChildWidget(396, 3);
if (child == null) return false;
String text = child.getText();
return text.startsWith(Constants.WINTERTODT_RETURNS_IN) && !text.endsWith("0:00");
}
@Override
public int execute() {
return Calculations.random(200, 300);
}
}

View File

@ -0,0 +1,111 @@
package io.reisub.dreambot.cwintertodt.tasks;
import io.reisub.dreambot.util.Constants;
import io.reisub.dreambot.util.TaskNodeParent;
import io.reisub.dreambot.util.Util;
import org.dreambot.api.methods.container.impl.Inventory;
import org.dreambot.api.methods.widget.Widgets;
import org.dreambot.api.script.ScriptManager;
import org.dreambot.api.script.listener.ChatListener;
import org.dreambot.api.script.listener.InventoryListener;
import org.dreambot.api.wrappers.items.Item;
import org.dreambot.api.wrappers.widgets.WidgetChild;
import org.dreambot.api.wrappers.widgets.message.Message;
public class WintertodtTask extends TaskNodeParent {
private int rootCount, kindlingCount, energy;
private boolean burnBeforeRunningOutOfTime, interrupted, burning;
public static WintertodtTask createWintertodtTask() {
WintertodtTask task = new WintertodtTask();
task.setChildren(
new LightOrFix(task),
new Chop(task),
new Fletch(task),
new Burn(task)
);
return task;
}
private WintertodtTask() {
ScriptManager.getScriptManager().addListener(new ChatListener() {
@Override
public void onMessage(Message message) {
String msg = message.getMessage();
if (msg.startsWith(Constants.WINTERTODT_COLD) || msg.startsWith(Constants.WINTERTODT_FREEZING_ATTACK)) {
setInterrupted(true);
}
}
});
ScriptManager.getScriptManager().addListener(new InventoryListener() {
@Override
public void onItemChange(Item[] items) {
int burnableItems = Inventory.count(Constants.BRUMA_KINDLING) + Inventory.count(Constants.BRUMA_ROOT);
if (burnableItems >= getEnergy() && !isBurning()) {
setInterrupted(true);
}
}
});
}
@Override
public boolean accept() {
rootCount = Inventory.count(Constants.BRUMA_ROOT);
kindlingCount = Inventory.count(Constants.BRUMA_KINDLING);
energy = getWintertodtEnergy();
burnBeforeRunningOutOfTime = rootCount + kindlingCount >= energy;
if (isBurning() && rootCount == 0 && kindlingCount == 0) {
setBurning(false);
}
return Util.playerIsIdle() || interrupted;
}
private int getWintertodtEnergy() {
WidgetChild child = Widgets.getWidgetChild(396, 21);
if (child == null) return -1;
String text = child.getText();
return Integer.parseInt(text.replaceAll("[\\D]", ""));
}
public int getEnergy() {
return energy;
}
public int getRootCount() {
return rootCount;
}
public int getKindlingCount() {
return kindlingCount;
}
public boolean isInterrupted() {
return interrupted;
}
public void setInterrupted(boolean interrupted) {
this.interrupted = interrupted;
}
public boolean isBurning() {
return burning;
}
public void setBurning(boolean burning) {
this.burning = burning;
}
public boolean shouldBurnBeforeRunningOutOfTime() {
return burnBeforeRunningOutOfTime;
}
}