Compare commits
2 Commits
63bbeef5ac
...
bc6e82e409
Author | SHA1 | Date | |
---|---|---|---|
bc6e82e409
|
|||
a4737f548a
|
9
.idea/artifacts/CAgility_jar.xml
generated
Normal file
9
.idea/artifacts/CAgility_jar.xml
generated
Normal file
@ -0,0 +1,9 @@
|
||||
<component name="ArtifactManager">
|
||||
<artifact type="jar" name="CAgility:jar">
|
||||
<output-path>$USER_HOME$/DreamBot/Scripts</output-path>
|
||||
<root id="archive" name="CAgility.jar">
|
||||
<element id="module-output" name="CAgility" />
|
||||
<element id="module-output" name="Util" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
1
.idea/modules.xml
generated
1
.idea/modules.xml
generated
@ -2,6 +2,7 @@
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/CAgility/CAgility.iml" filepath="$PROJECT_DIR$/CAgility/CAgility.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/CBlackjack/CBlackjack.iml" filepath="$PROJECT_DIR$/CBlackjack/CBlackjack.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/CDebug/CDebug.iml" filepath="$PROJECT_DIR$/CDebug/CDebug.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/CFisher/CFisher.iml" filepath="$PROJECT_DIR$/CFisher/CFisher.iml" />
|
||||
|
13
CAgility/CAgility.iml
Normal file
13
CAgility/CAgility.iml
Normal 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>
|
24
CAgility/src/io/reisub/dreambot/cagility/CAgility.java
Normal file
24
CAgility/src/io/reisub/dreambot/cagility/CAgility.java
Normal file
@ -0,0 +1,24 @@
|
||||
package io.reisub.dreambot.cagility;
|
||||
|
||||
import io.reisub.dreambot.cagility.tasks.HandleObstacle;
|
||||
import io.reisub.dreambot.cagility.tasks.PickupMark;
|
||||
import io.reisub.dreambot.util.Constants;
|
||||
import io.reisub.dreambot.util.tasks.Eat;
|
||||
import io.reisub.dreambot.util.tasks.kitten.KittenTask;
|
||||
import org.dreambot.api.script.Category;
|
||||
import org.dreambot.api.script.ScriptManifest;
|
||||
import org.dreambot.api.script.impl.TaskScript;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@ScriptManifest(category = Category.AGILITY, name = "CAgility", description = "Runs laps for days", author = Constants.AUTHOR, version = 1.0)
|
||||
public class CAgility extends TaskScript {
|
||||
@Override
|
||||
public void onStart() {
|
||||
addNodes(
|
||||
new Eat(),
|
||||
KittenTask.createKittenTask(),
|
||||
new HandleObstacle(HandleObstacle.Course.CANIFIS),
|
||||
new PickupMark()
|
||||
);
|
||||
}
|
||||
}
|
39
CAgility/src/io/reisub/dreambot/cagility/Obstacle.java
Normal file
39
CAgility/src/io/reisub/dreambot/cagility/Obstacle.java
Normal file
@ -0,0 +1,39 @@
|
||||
package io.reisub.dreambot.cagility;
|
||||
|
||||
import org.dreambot.api.methods.interactive.GameObjects;
|
||||
import org.dreambot.api.wrappers.interactive.GameObject;
|
||||
|
||||
public class Obstacle {
|
||||
private final int id;
|
||||
private final boolean retry;
|
||||
private Obstacle next;
|
||||
|
||||
public Obstacle(int id, boolean canRetry) {
|
||||
this.id = id;
|
||||
this.retry = canRetry;
|
||||
}
|
||||
|
||||
public Obstacle(int id) {
|
||||
this(id, false);
|
||||
}
|
||||
|
||||
public int getID() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public boolean canRetry() {
|
||||
return this.retry;
|
||||
}
|
||||
|
||||
public GameObject getGameObject() {
|
||||
return GameObjects.closest(getID());
|
||||
}
|
||||
|
||||
public Obstacle getNext() {
|
||||
return this.next;
|
||||
}
|
||||
|
||||
public void setNext(Obstacle next) {
|
||||
this.next = next;
|
||||
}
|
||||
}
|
@ -0,0 +1,133 @@
|
||||
package io.reisub.dreambot.cagility.tasks;
|
||||
|
||||
import io.reisub.dreambot.cagility.Obstacle;
|
||||
import io.reisub.dreambot.util.Constants;
|
||||
import io.reisub.dreambot.util.Util;
|
||||
import io.reisub.dreambot.util.event.ListenerManager;
|
||||
import io.reisub.dreambot.util.event.health.HealthListener;
|
||||
import org.dreambot.api.input.Mouse;
|
||||
import org.dreambot.api.methods.Calculations;
|
||||
import org.dreambot.api.methods.MethodContext;
|
||||
import org.dreambot.api.methods.interactive.Players;
|
||||
import org.dreambot.api.methods.item.GroundItems;
|
||||
import org.dreambot.api.methods.skills.Skill;
|
||||
import org.dreambot.api.methods.walking.impl.Walking;
|
||||
import org.dreambot.api.script.ScriptManager;
|
||||
import org.dreambot.api.script.TaskNode;
|
||||
import org.dreambot.api.script.event.impl.ExperienceEvent;
|
||||
import org.dreambot.api.script.listener.ExperienceListener;
|
||||
import org.dreambot.api.wrappers.interactive.GameObject;
|
||||
import org.dreambot.api.wrappers.items.GroundItem;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class HandleObstacle extends TaskNode {
|
||||
public enum Course {
|
||||
CANIFIS(
|
||||
new Obstacle(14843),
|
||||
new Obstacle(14844),
|
||||
new Obstacle(14845),
|
||||
new Obstacle(14848),
|
||||
new Obstacle(14846),
|
||||
new Obstacle(14894),
|
||||
new Obstacle(14847),
|
||||
new Obstacle(14897)
|
||||
);
|
||||
|
||||
private final Obstacle firstObstacle;
|
||||
|
||||
Course(Obstacle... obstacles) {
|
||||
this.firstObstacle = obstacles[0];
|
||||
|
||||
for (int i = 0; i < obstacles.length; i++) {
|
||||
if (i + 1 == obstacles.length) {
|
||||
obstacles[i].setNext(obstacles[0]);
|
||||
} else {
|
||||
obstacles[i].setNext(obstacles[i+1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final Course course;
|
||||
private final Map<Integer, Rectangle> hoverMap;
|
||||
private Obstacle lastObstacle = null;
|
||||
private boolean failed, obstacleCompleted = false;
|
||||
|
||||
public HandleObstacle(Course course) {
|
||||
this.course = course;
|
||||
this.hoverMap = new HashMap<>();
|
||||
|
||||
ListenerManager.getInstance().addListener(new HealthListener() {
|
||||
@Override
|
||||
public void onHealthDecreased(int oldValue, int newValue) {
|
||||
failed = true;
|
||||
}
|
||||
});
|
||||
|
||||
ScriptManager.getScriptManager().addListener(new ExperienceListener() {
|
||||
@Override
|
||||
public void onGained(ExperienceEvent event) {
|
||||
if (event.getSkill().equals(Skill.AGILITY)) {
|
||||
obstacleCompleted = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept() {
|
||||
GroundItem mark = GroundItems.closest(Constants.MARK_OF_GRACE);
|
||||
|
||||
return Util.playerIsIdle() && (mark == null || !mark.canReach());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int execute() {
|
||||
Obstacle current;
|
||||
|
||||
if (lastObstacle == null) {
|
||||
current = course.firstObstacle;
|
||||
} else {
|
||||
if (failed) {
|
||||
if (lastObstacle.canRetry()) {
|
||||
current = lastObstacle;
|
||||
} else {
|
||||
current = course.firstObstacle;
|
||||
}
|
||||
failed = false;
|
||||
} else {
|
||||
current = lastObstacle.getNext();
|
||||
}
|
||||
}
|
||||
|
||||
final GameObject currentObject = current.getGameObject();
|
||||
if (currentObject == null) return Calculations.random(300, 500);
|
||||
|
||||
if (!currentObject.isOnScreen()) {
|
||||
Walking.clickTileOnMinimap(currentObject.getTile());
|
||||
MethodContext.sleepUntil(() -> Players.localPlayer().distance(currentObject) < 3, Calculations.random(5000, 5500));
|
||||
}
|
||||
|
||||
if (hoverMap.get(current.getID()) == null) {
|
||||
hoverMap.put(current.getID(), currentObject.getBoundingBox());
|
||||
}
|
||||
|
||||
currentObject.interact();
|
||||
|
||||
lastObstacle = current;
|
||||
|
||||
Rectangle hoverRect = hoverMap.get(current.getNext().getID());
|
||||
if (hoverRect != null) {
|
||||
Mouse.move(hoverRect);
|
||||
}
|
||||
|
||||
MethodContext.sleepUntil(() -> failed || obstacleCompleted, Calculations.random(9000, 10000));
|
||||
|
||||
obstacleCompleted = false;
|
||||
|
||||
return Calculations.random(180, 350);
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package io.reisub.dreambot.cagility.tasks;
|
||||
|
||||
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.item.GroundItems;
|
||||
import org.dreambot.api.script.TaskNode;
|
||||
import org.dreambot.api.wrappers.items.GroundItem;
|
||||
import org.dreambot.api.wrappers.items.Item;
|
||||
|
||||
public class PickupMark extends TaskNode {
|
||||
@Override
|
||||
public boolean accept() {
|
||||
GroundItem mark = GroundItems.closest(Constants.MARK_OF_GRACE);
|
||||
|
||||
return mark != null && mark.canReach();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int execute() {
|
||||
GroundItem mark = GroundItems.closest(Constants.MARK_OF_GRACE);
|
||||
|
||||
if (mark == null || !mark.canReach()) return 0;
|
||||
|
||||
Item marks = Inventory.get(Constants.MARK_OF_GRACE);
|
||||
final int count = marks == null ? 0 : marks.getAmount();
|
||||
|
||||
mark.interact();
|
||||
|
||||
MethodContext.sleepUntil(() -> {
|
||||
Item currentMarks = Inventory.get(Constants.MARK_OF_GRACE);
|
||||
return currentMarks != null && currentMarks.getAmount() > count;
|
||||
}, Calculations.random(5000, 5500));
|
||||
|
||||
return Calculations.random(250, 400);
|
||||
}
|
||||
}
|
@ -47,6 +47,7 @@ public class Constants {
|
||||
public static final String BRUMA_ROOTS = "Bruma roots";
|
||||
public static final String BRAZIER = "Brazier";
|
||||
public static final String BURNING_BRAZIER = "Burning brazier";
|
||||
public static final String MARK_OF_GRACE = "Mark of grace";
|
||||
|
||||
// Actions
|
||||
public static final String USE = "Use";
|
||||
|
44
Util/src/io/reisub/dreambot/util/event/AbstractEvent.java
Normal file
44
Util/src/io/reisub/dreambot/util/event/AbstractEvent.java
Normal file
@ -0,0 +1,44 @@
|
||||
package io.reisub.dreambot.util.event;
|
||||
|
||||
import java.util.EventListener;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractEvent {
|
||||
private Thread thread;
|
||||
protected volatile boolean run = false;
|
||||
protected List<EventListener> listeners = new LinkedList<>();
|
||||
|
||||
public void start() {
|
||||
if (run) return;
|
||||
|
||||
run = true;
|
||||
thread = new Thread(this::run);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
run = false;
|
||||
thread = null;
|
||||
}
|
||||
|
||||
public abstract void run();
|
||||
|
||||
public void addListener(EventListener listener) {
|
||||
this.listeners.add(listener);
|
||||
|
||||
if (this.listeners.size() == 1) this.start();
|
||||
}
|
||||
|
||||
public void removeListener(EventListener listener) {
|
||||
this.listeners.remove(listener);
|
||||
|
||||
if (this.listeners.size() == 0) this.stop();
|
||||
}
|
||||
|
||||
public void removeAllListeners() {
|
||||
this.listeners.clear();
|
||||
|
||||
this.stop();
|
||||
}
|
||||
}
|
43
Util/src/io/reisub/dreambot/util/event/ListenerManager.java
Normal file
43
Util/src/io/reisub/dreambot/util/event/ListenerManager.java
Normal file
@ -0,0 +1,43 @@
|
||||
package io.reisub.dreambot.util.event;
|
||||
|
||||
import io.reisub.dreambot.util.event.health.HealthEvent;
|
||||
import io.reisub.dreambot.util.event.health.HealthListener;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
public class ListenerManager {
|
||||
private static ListenerManager instance;
|
||||
|
||||
private HealthEvent healthEvent;
|
||||
|
||||
public static ListenerManager getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new ListenerManager();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
private AbstractEvent getEventForListener(EventListener listener) {
|
||||
if (listener instanceof HealthListener) {
|
||||
if (healthEvent == null) {
|
||||
healthEvent = new HealthEvent();
|
||||
}
|
||||
return healthEvent;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addListener(EventListener listener) {
|
||||
getEventForListener(listener).addListener(listener);
|
||||
}
|
||||
|
||||
public void removeListener(EventListener listener) {
|
||||
getEventForListener(listener).removeListener(listener);
|
||||
}
|
||||
|
||||
public void removeAllListeners() {
|
||||
healthEvent.removeAllListeners();
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package io.reisub.dreambot.util.event.health;
|
||||
|
||||
import io.reisub.dreambot.util.event.AbstractEvent;
|
||||
import org.dreambot.api.Client;
|
||||
import org.dreambot.api.methods.skills.Skill;
|
||||
import org.dreambot.api.methods.skills.Skills;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
public class HealthEvent extends AbstractEvent {
|
||||
private int lastHealth = -1;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (run && Client.getInstance().getScriptManager().isRunning()) {
|
||||
try {
|
||||
Thread.sleep(600);
|
||||
} catch (InterruptedException ignored) {}
|
||||
|
||||
if (Client.getInstance().getScriptManager().isPaused()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lastHealth == -1) {
|
||||
lastHealth = Skills.getBoostedLevels(Skill.HITPOINTS);
|
||||
continue;
|
||||
}
|
||||
|
||||
int currentHealth = Skills.getBoostedLevels(Skill.HITPOINTS);
|
||||
|
||||
if (currentHealth > lastHealth) {
|
||||
for (EventListener l : listeners) {
|
||||
((HealthListener) l).onHealthIncreased(lastHealth, currentHealth);
|
||||
((HealthListener) l).onHealthChanged(lastHealth, currentHealth);
|
||||
}
|
||||
} else if (currentHealth < lastHealth) {
|
||||
for (EventListener l : listeners) {
|
||||
((HealthListener) l).onHealthDecreased(lastHealth, currentHealth);
|
||||
((HealthListener) l).onHealthChanged(lastHealth, currentHealth);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package io.reisub.dreambot.util.event.health;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
public interface HealthListener extends EventListener {
|
||||
default void onHealthChanged(int oldValue, int newValue) {}
|
||||
|
||||
default void onHealthDecreased(int oldValue, int newValue) {}
|
||||
|
||||
default void onHealthIncreased(int oldValue, int newValue) {}
|
||||
}
|
Reference in New Issue
Block a user