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

12
Util/Util.iml Normal file
View File

@ -0,0 +1,12 @@
<?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" />
</component>
</module>

View File

@ -0,0 +1,101 @@
package io.reisub.dreambot.util;
import org.dreambot.api.input.Mouse;
import org.dreambot.api.methods.MethodContext;
import org.dreambot.api.methods.container.impl.DropPattern;
import org.dreambot.api.methods.container.impl.Inventory;
import org.dreambot.api.methods.filter.Filter;
import org.dreambot.api.wrappers.items.Item;
import java.awt.*;
import java.util.Comparator;
import java.util.List;
@SuppressWarnings("unused")
public class CInventory {
public static final Filter<Item> foodItemFilter = item -> item.hasAction(Constants.EAT) || item.hasAction(Constants.DRINK);
public final static DropPattern verticalDropPattern = () -> (Comparator<Item>) (o1, o2) -> {
int o1Col = o1.getSlot() % 4;
int o1Row = o1.getSlot() / 4;
int o2Col = o2.getSlot() % 4;
int o2Row = o2.getSlot() / 4;
if (o1Col == o2Col) {
return o1Row - o2Row;
} else {
return o1Col - o2Col;
}
};
public final static DropPattern verticalSnakeDropPattern = () -> (Comparator<Item>) (o1, o2) -> {
int o1Col = o1.getSlot() % 4;
int o1Row = o1.getSlot() / 4;
int o2Col = o2.getSlot() % 4;
int o2Row = o2.getSlot() / 4;
if (o1Col == o2Col) {
if (o1Col == 0 || o1Col == 2) {
return o1Row - o2Row;
} else {
return o2Row - o1Row;
}
} else {
return o1Col - o2Col;
}
};
public static boolean useOnNearest(String source, String... targetNames) {
Item sourceItem = Inventory.get(source);
List<Item> targets = Inventory.all(item -> {
for (String targetName : targetNames) {
if (item.getName().equals(targetName)) {
return true;
}
}
return false;
});
if (sourceItem == null || targets.isEmpty()) {
return false;
}
return useOnNearest(sourceItem, targets);
}
public static boolean useOnNearest(Item source, List<Item> targets) {
double lowestDistance = Double.MAX_VALUE;
Item nearest = null;
Point sPoint = source.getDestination().getCenterPoint();
for (Item target : targets) {
Point tPoint = target.getDestination().getCenterPoint();
double distance = sPoint.distance(tPoint);
if (distance < lowestDistance) {
lowestDistance = distance;
nearest = target;
}
}
if (nearest == null) {
return false;
}
Mouse.click(source.getDestination());
MethodContext.sleep(200, 400);
return Mouse.click(nearest.getDestination());
}
public static boolean hasFood() {
return Inventory.contains(foodItemFilter);
}
}

View File

@ -0,0 +1,38 @@
package io.reisub.dreambot.util;
import org.dreambot.api.methods.interactive.NPCs;
import org.dreambot.api.methods.interactive.Players;
import org.dreambot.api.wrappers.interactive.Character;
import org.dreambot.api.wrappers.interactive.NPC;
import javax.annotation.Nullable;
import java.util.List;
@SuppressWarnings("unused")
public class CNPC {
@Nullable
public static NPC getNPCInteractingWithPlayer(String name) {
List<NPC> npcs;
if (name.equals("")) {
npcs = NPCs.all();
} else {
npcs = NPCs.all(name);
}
for (NPC npc : npcs) {
Character c = npc.getInteractingCharacter();
if (c != null && c.getName().equals(Players.localPlayer().getName())) {
return npc;
}
}
return null;
}
@Nullable
public static NPC getNPCInteractingWithPlayer() {
return getNPCInteractingWithPlayer("");
}
}

View File

@ -0,0 +1,74 @@
package io.reisub.dreambot.util;
public class Constants {
public static final String AUTHOR = "ChaosEnergy";
// Items/GameObjects/NPCs
public static final String KITTEN = "Kitten";
public static final String CAT = "Cat";
public static final String[] KITTEN_FISH_NAMES = new String[]{
"Shrimp",
"Sardine",
"Karambwanji",
"Herring",
"Anchovies",
"Mackerel",
"Trout",
"Cod",
"Pike",
"Slimy eel",
"Salmon",
"Tuna",
"Rainbow fish",
"Cave eel",
"Lobster",
"Fish chunks",
"Bass",
"Roe",
"Caviar",
"Swordfish",
"Lava eel",
"Monkfish",
"Karambwan",
"Shark",
"Manta ray",
"Anglerfish",
"Dark crab"
};
public static final String[] BARBARIAN_FISH_NAMES = new String[]{
"Leaping sturgeon",
"Leaping salmon",
"Leaping trout",
};
public static final String FISHING_SPOT = "Fishing spot";
public static final String KNIFE = "Knife";
public static final String BRUMA_ROOT = "Bruma root";
public static final String BRUMA_KINDLING = "Bruma kindling";
public static final String BRUMA_ROOTS = "Bruma roots";
public static final String BRAZIER = "Brazier";
public static final String BURNING_BRAZIER = "Burning brazier";
// Actions
public static final String USE = "Use";
public static final String USE_ROD = "Use-rod";
public static final String INTERACT = "Interact";
public static final String PICK_UP = "Pick-up";
public static final String FEED = "Feed";
public static final String CHOP = "Chop";
public static final String EAT = "Eat";
public static final String DRINK = "Drink";
public static final String LIGHT = "Light";
public static final String FIX = "Fix";
// Messages
public static final String KITTEN_WANTS_ATTENTION_MSG = "Your kitten wants attention.";
public static final String KITTEN_IS_HUNGRY_MSG = "Your kitten is hungry.";
public static final String KITTEN_WAS_STROKED_MSG = "You softly stroke your cat.";
public static final String KITTEN_HAS_EATEN_MSG = "The kitten gobbles up the fish.";
public static final String WINTERTODT_COLD = "The cold of the Wintertodt";
public static final String WINTERTODT_FREEZING_ATTACK = "The freezing cold attack";
public static final String WINTERTODT_RETURNS_IN = "The Wintertodt returns in";
// Dialog options
public static final String STROKE = "Stroke";
}

View File

@ -0,0 +1,33 @@
package io.reisub.dreambot.util;
import org.dreambot.api.methods.Calculations;
import org.dreambot.api.script.TaskNode;
public abstract class TaskNodeParent extends TaskNode {
private TaskNode[] children;
public void setChildren(TaskNode... children) {
this.children = children;
}
public boolean accept() {
for (TaskNode n : children) {
if (n.accept()) {
return true;
}
}
return false;
}
@Override
public int execute() {
for (TaskNode n : children) {
if (n.accept()) {
return n.execute();
}
}
return Calculations.random(40, 80);
}
}

View File

@ -0,0 +1,92 @@
package io.reisub.dreambot.util;
import org.dreambot.api.methods.Calculations;
import org.dreambot.api.methods.MethodContext;
import org.dreambot.api.methods.interactive.Players;
import org.dreambot.api.methods.skills.Skill;
import org.dreambot.api.methods.skills.Skills;
import org.dreambot.api.wrappers.interactive.Player;
@SuppressWarnings("unused")
public class Util {
public static boolean playerIsIdle() {
return playerIsIdle(0);
}
public static boolean playerIsIdle(long timeout) {
Player player = Players.localPlayer();
MethodContext.sleepWhile(() -> !player.isMoving() && !player.isAnimating(), timeout);
return !player.isMoving() && !player.isAnimating();
}
public static int sleepUntilMoving() {
return sleepUntilMoving(Calculations.random(3000, 3500));
}
public static int sleepUntilMoving(long timeout) {
long start = System.currentTimeMillis();
Player player = Players.localPlayer();
MethodContext.sleepUntil(() -> player.isMoving(), timeout);
return (int) (System.currentTimeMillis() - start);
}
public static int sleepUntilAnimating() {
return sleepUntilAnimating(Calculations.random(3000, 3500));
}
public static int sleepUntilAnimating(long timeout) {
long start = System.currentTimeMillis();
Player player = Players.localPlayer();
MethodContext.sleepUntil(() -> player.isAnimating(), timeout);
return (int) (System.currentTimeMillis() - start);
}
public static int sleepUntilMovingOrAnimating() {
return sleepUntilMovingOrAnimating(Calculations.random(3000, 3500));
}
public static int sleepUntilMovingOrAnimating(long timeout) {
long start = System.currentTimeMillis();
Player player = Players.localPlayer();
MethodContext.sleepUntil(() -> player.isMoving() || player.isAnimating(), timeout);
return (int) (System.currentTimeMillis() - start);
}
public static int sleepUntilMovingAndAnimating() {
return sleepUntilMovingAndAnimating(Calculations.random(5000, 5500));
}
public static int sleepUntilMovingAndAnimating(long timeout) {
int elapsed = sleepUntilMovingOrAnimating(timeout);
long start = System.currentTimeMillis();
if (timeout - elapsed < 0) {
return elapsed;
}
MethodContext.sleepWhile(() -> Players.localPlayer().isMoving(), timeout - elapsed);
elapsed += (System.currentTimeMillis() - start);
if (timeout - elapsed < 0) {
return elapsed;
}
elapsed += sleepUntilAnimating(timeout - elapsed);
return elapsed;
}
public static int getCurrentHP() {
return Skills.getBoostedLevels(Skill.HITPOINTS);
}
}

View File

@ -0,0 +1,121 @@
package io.reisub.dreambot.util.randomevents;
import org.dreambot.api.methods.Calculations;
import org.dreambot.api.methods.MethodContext;
import org.dreambot.api.methods.container.impl.Inventory;
import org.dreambot.api.methods.interactive.NPCs;
import org.dreambot.api.methods.interactive.Players;
import org.dreambot.api.methods.widget.Widgets;
import org.dreambot.api.randoms.RandomEvent;
import org.dreambot.api.randoms.RandomSolver;
import org.dreambot.api.wrappers.interactive.NPC;
import org.dreambot.api.wrappers.widgets.WidgetChild;
import java.util.List;
public class GenieSolver extends RandomSolver {
@SuppressWarnings("unused")
public enum Skill {
ATTACK(2),
STRENGTH(3),
RANGED(4),
MAGIC(5),
DEFENSE(6),
CONSTITUTION(7),
PRAYER(8),
AGILITY(9),
HERBLORE(10),
THIEVING(11),
CRAFTING(12),
RUNECRAFTING(13),
SLAYER(14),
FARMING(15),
MINING(16),
SMITHING(17),
FISHING(18),
COOKING(19),
FIREMAKING(20),
WOODCUTTING(21),
FLETCHING(22),
CONSTRUCTION(23),
HUNTING(24);
private final int index;
Skill(int index) {
this.index = index;
}
public int getIndex() {
return index;
}
}
private final Skill skill;
private NPC playerGenie;
public GenieSolver(Skill skill) {
super(RandomEvent.GENIE);
this.skill = skill;
}
@Override
public boolean shouldExecute() {
List<NPC> genies = NPCs.all("Genie");
String playerName = Players.localPlayer().getName();
if (playerGenie != null || Inventory.contains(2528)) {
return true;
}
if (genies.isEmpty()) {
return false;
}
for (NPC genie : genies) {
String overheadMsg = genie.getOverhead();
if (overheadMsg == null) {
continue;
}
if (overheadMsg.contains(playerName)) {
playerGenie = genie;
return true;
}
}
return false;
}
@Override
public int onLoop() {
WidgetChild lampInterface = Widgets.getChildWidget(240, 0);
if (lampInterface != null && lampInterface.isVisible()) {
MethodContext.log("[GenieSolver] Choosing " + skill.name());
WidgetChild skillOption = Widgets.getChildWidget(240, skill.getIndex());
skillOption.interact();
WidgetChild confirm = Widgets.getChildWidget(240, 26);
confirm.interact();
MethodContext.sleepUntil(() -> Widgets.getChildWidget(240, 0) == null, 2000);
} else if (Inventory.contains(2528)) {
MethodContext.log("[GenieSolver] Rubbing lamp");
playerGenie = null;
Inventory.interact(2528, "Rub");
MethodContext.sleepUntil(() -> Widgets.getChildWidget(240, 0) != null, 2000);
} else {
MethodContext.log("[GenieSolver] Interacting with Genie");
playerGenie.interact();
MethodContext.sleepUntil(() -> Inventory.contains(2528), Calculations.random(4000, 5000));
}
return Calculations.random(150, 350);
}
}

View File

@ -0,0 +1,41 @@
package io.reisub.dreambot.util.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.methods.MethodContext;
import org.dreambot.api.methods.container.impl.Inventory;
import org.dreambot.api.methods.skills.Skill;
import org.dreambot.api.methods.skills.Skills;
import org.dreambot.api.script.TaskNode;
public class Eat extends TaskNode {
private final int threshold;
public Eat(int threshold) {
this.threshold = threshold;
}
public Eat() {
this(Skills.getRealLevel(Skill.HITPOINTS) / 2);
}
@Override
public boolean accept() {
return CInventory.hasFood() && Util.getCurrentHP() < threshold;
}
@Override
public int execute() {
int count = Inventory.count(CInventory.foodItemFilter);
if (!Inventory.interact(CInventory.foodItemFilter, Constants.EAT)) {
Inventory.interact(CInventory.foodItemFilter, Constants.DRINK);
}
MethodContext.sleepUntil(() -> Inventory.count(CInventory.foodItemFilter) < count, Calculations.random(2000, 2500));
return 0;
}
}

View File

@ -0,0 +1,47 @@
package io.reisub.dreambot.util.tasks.kitten;
import io.reisub.dreambot.util.CInventory;
import io.reisub.dreambot.util.Constants;
import org.dreambot.api.methods.Calculations;
import org.dreambot.api.methods.MethodContext;
import org.dreambot.api.methods.container.impl.Inventory;
import org.dreambot.api.methods.filter.Filter;
import org.dreambot.api.script.TaskNode;
import org.dreambot.api.wrappers.items.Item;
public class CutFoodForKitten extends TaskNode {
private final KittenTask parent;
private final Filter<Item> cutFishItemFilter = item -> {
for (String fishName : Constants.BARBARIAN_FISH_NAMES) {
if (item.getName().contains(fishName)) {
return true;
}
}
return false;
};
public CutFoodForKitten(KittenTask parent) {
this.parent = parent;
}
@Override
public boolean accept() {
return parent.isHungry() &&
!Inventory.contains(parent.fishItemFilter) &&
Inventory.contains(cutFishItemFilter) &&
Inventory.contains(Constants.KNIFE);
}
@Override
public int execute() {
int count = Inventory.count(cutFishItemFilter);
CInventory.useOnNearest(Constants.KNIFE, Constants.BARBARIAN_FISH_NAMES);
MethodContext.sleepUntil(() -> Inventory.count(cutFishItemFilter) < count, Calculations.random(2500, 3000));
return Calculations.random(250, 400);
}
}

View File

@ -0,0 +1,35 @@
package io.reisub.dreambot.util.tasks.kitten;
import io.reisub.dreambot.util.CNPC;
import io.reisub.dreambot.util.Constants;
import org.dreambot.api.methods.Calculations;
import org.dreambot.api.methods.MethodContext;
import org.dreambot.api.methods.container.impl.Inventory;
import org.dreambot.api.script.TaskNode;
import org.dreambot.api.wrappers.interactive.NPC;
public class FeedKitten extends TaskNode {
private final KittenTask parent;
public FeedKitten(KittenTask parent) {
this.parent = parent;
}
@Override
public boolean accept() {
return parent.isHungry() && Inventory.contains(parent.fishItemFilter);
}
@Override
public int execute() {
NPC kitten = CNPC.getNPCInteractingWithPlayer(Constants.KITTEN);
if (kitten == null) return 0;
Inventory.get(parent.fishItemFilter).useOn(kitten);
MethodContext.sleepUntil(() -> !parent.isHungry(), Calculations.random(5000, 5500));
return Calculations.random(250, 400);
}
}

View File

@ -0,0 +1,47 @@
package io.reisub.dreambot.util.tasks.kitten;
import io.reisub.dreambot.util.CNPC;
import io.reisub.dreambot.util.Constants;
import org.dreambot.api.methods.Calculations;
import org.dreambot.api.methods.MethodContext;
import org.dreambot.api.methods.dialogues.Dialogues;
import org.dreambot.api.script.TaskNode;
import org.dreambot.api.wrappers.interactive.NPC;
public class InteractKitten extends TaskNode {
private final KittenTask parent;
public InteractKitten(KittenTask parent) {
this.parent = parent;
}
@Override
public boolean accept() {
return parent.wantsAttention();
}
@Override
public int execute() {
NPC kitten = CNPC.getNPCInteractingWithPlayer(Constants.KITTEN);
if (kitten == null) return 0;
stroke(kitten);
stroke(kitten);
return Calculations.random(250, 400);
}
public void stroke(NPC kitten) {
if (!kitten.interact(Constants.INTERACT)) {
return;
}
MethodContext.sleepUntil(Dialogues::areOptionsAvailable, Calculations.random(3000, 3500));
Dialogues.chooseFirstOptionContaining(Constants.STROKE);
MethodContext.sleep(1500, 2000);
MethodContext.sleepUntil(Dialogues::inDialogue, Calculations.random(4000, 4500));
}
}

View File

@ -0,0 +1,99 @@
package io.reisub.dreambot.util.tasks.kitten;
import io.reisub.dreambot.util.CNPC;
import io.reisub.dreambot.util.Constants;
import io.reisub.dreambot.util.TaskNodeParent;
import org.dreambot.api.methods.container.impl.Inventory;
import org.dreambot.api.methods.filter.Filter;
import org.dreambot.api.script.ScriptManager;
import org.dreambot.api.script.listener.ChatListener;
import org.dreambot.api.wrappers.interactive.NPC;
import org.dreambot.api.wrappers.items.Item;
import org.dreambot.api.wrappers.widgets.message.Message;
import javax.annotation.Nullable;
import java.util.Locale;
public class KittenTask extends TaskNodeParent {
private boolean hungry, attention;
public final Filter<Item> fishItemFilter = item -> {
for (String fishName : Constants.KITTEN_FISH_NAMES) {
String rawFishName = "Raw " + fishName.toLowerCase(Locale.ROOT);
if (item.getName().equals(fishName) || item.getName().equals(rawFishName)) {
return true;
}
}
return false;
};
@Nullable
public static KittenTask createKittenTask() {
KittenTask task = null;
if (Inventory.contains(Constants.KITTEN)) {
Inventory.drop(Constants.KITTEN);
task = new KittenTask();
}
NPC kitten = CNPC.getNPCInteractingWithPlayer(Constants.KITTEN);
NPC cat = CNPC.getNPCInteractingWithPlayer(Constants.CAT);
if (kitten != null || cat != null) {
task = new KittenTask();
}
if (task != null) {
task.setChildren(
new CutFoodForKitten(task),
new FeedKitten(task),
new InteractKitten(task),
new PickupCat()
);
}
return task;
}
private KittenTask() {
ScriptManager.getScriptManager().addListener(new ChatListener() {
@Override
public void onMessage(Message message) {
if (message.getMessage().contains(Constants.KITTEN_WANTS_ATTENTION_MSG)) {
setAttention(true);
}
if (message.getMessage().contains(Constants.KITTEN_WAS_STROKED_MSG)) {
setAttention(false);
}
if (message.getMessage().contains(Constants.KITTEN_IS_HUNGRY_MSG)) {
setHungry(true);
}
if (message.getMessage().contains(Constants.KITTEN_HAS_EATEN_MSG)) {
setHungry(false);
}
}
});
}
public void setHungry(boolean hungry) {
this.hungry = hungry;
}
public boolean isHungry() {
return hungry;
}
public void setAttention(boolean attention) {
this.attention = attention;
}
public boolean wantsAttention() {
return attention;
}
}

View File

@ -0,0 +1,31 @@
package io.reisub.dreambot.util.tasks.kitten;
import io.reisub.dreambot.util.CNPC;
import io.reisub.dreambot.util.Constants;
import org.dreambot.api.methods.Calculations;
import org.dreambot.api.methods.MethodContext;
import org.dreambot.api.methods.container.impl.Inventory;
import org.dreambot.api.script.TaskNode;
import org.dreambot.api.wrappers.interactive.NPC;
public class PickupCat extends TaskNode {
@Override
public boolean accept() {
NPC cat = CNPC.getNPCInteractingWithPlayer(Constants.CAT);
return cat != null && !Inventory.isFull();
}
@Override
public int execute() {
NPC cat = CNPC.getNPCInteractingWithPlayer(Constants.CAT);
if (cat == null) return 0;
cat.interact(Constants.PICK_UP);
MethodContext.sleepUntil(() -> Inventory.contains(Constants.CAT), Calculations.random(3000, 3500));
return Calculations.random(250, 400);
}
}