Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Created July 5, 2016 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/0798a95f11766d549e7602b2e79a70ed to your computer and use it in GitHub Desktop.
Save anonymous/0798a95f11766d549e7602b2e79a70ed to your computer and use it in GitHub Desktop.
package nation.draynorwillows;
import org.dreambot.api.input.event.impl.mouse.impl.click.ClickMode;
import org.dreambot.api.methods.Calculations;
import org.dreambot.api.methods.container.impl.bank.BankType;
import org.dreambot.api.methods.skills.Skill;
import org.dreambot.api.methods.tabs.Tab;
import org.dreambot.api.script.AbstractScript;
import org.dreambot.api.script.Category;
import org.dreambot.api.script.ScriptManifest;
import org.dreambot.api.script.listener.MessageListener;
import org.dreambot.api.utilities.Timer;
import org.dreambot.api.wrappers.interactive.Entity;
import org.dreambot.api.wrappers.interactive.GameObject;
import org.dreambot.api.wrappers.interactive.Player;
import org.dreambot.api.wrappers.widgets.message.Message;
import java.awt.*;
import static nation.draynorwillows.State.CHOPPING;
/**
* Created by Nation
* Date: 2016-07-05
*/
@ScriptManifest(name = "National Draynor Willows", author = "Nation", version = 1.0, category = Category.WOODCUTTING)
public class DraynorWillows extends AbstractScript implements MessageListener {
private long antiBanTime = System.currentTimeMillis();
private int antiBanDelay = 0;
private int logsChopped = 0;
private int startingXP;
private int startingLevel;
private Timer timer;
@Override
public void onStart() {
log("National Draynor Willows version " + getVersion() + " started.");
startingLevel = getSkills().getRealLevel(Skill.WOODCUTTING);
startingXP = getSkills().getExperience(Skill.WOODCUTTING);
timer = new Timer();
}
private State getState() {
return getInventory().isFull() ? State.BANKING : CHOPPING;
}
@Override
public int onLoop() {
switch (getState()) {
case CHOPPING:
GameObject willow = getGameObjects().closest("Willow");
if(getLocalPlayer().getAnimation() != 867) {
if(willow != null) {
if(willow.distance() > 4) {
getWalking().walk(willow.getTile());
sleepUntil(() -> !getLocalPlayer().isMoving(), 3000);
}
if(willow.distance() <= 4) {
getCamera().mouseRotateToEntity(willow);
sleep(50, 200);
willow.interact("Chop down");
sleepUntil(() -> getLocalPlayer().isAnimating(), 500);
}
}
} else {
doAntiBan();
}
break;
case BANKING:
Entity bank = getBank().getClosestBank(BankType.BOOTH);
if(!getBank().isOpen()) {
if(bank.distance() > 5) {
getWalking().walk(bank);
sleepUntil(() -> !getLocalPlayer().isMoving(), 3000);
}
if(bank.distance() <= 4) {
getBank().openClosest();
sleepUntil(() -> getBank().isOpen(), 1500);
}
}
if(getBank().isOpen()) {
logsChopped += getInventory().count("Willow logs");
getBank().depositAll("Willow logs");
sleep(200, 500);
if(!getInventory().contains("Willow logs"))
getBank().close();
}
break;
}
return 30;
}
private void doAntiBan() {
long time = System.currentTimeMillis();
if(time - antiBanTime >= antiBanDelay) {
int antiBanType = random(0, 8);
antiBanTime = System.currentTimeMillis();
switch (antiBanType) {
case 0:
case 1:
getMouse().move(new Point(random(0, 765), random(0, 503)));
sleep(10, 500);
break;
case 2:
case 3:
getCamera().rotateTo(random(0, 360), random(0, 360));
sleep(10, 500);
break;
case 4:
getTabs().open(Tab.FRIENDS);
sleep(500, 1500);
getTabs().open(Tab.INVENTORY);
sleep(10, 300);
break;
case 5:
getTabs().open(Tab.STATS);
sleep(100, 300);
getSkills().hoverSkill(Skill.WOODCUTTING);
sleep(1500, 3000);
getTabs().open(Tab.INVENTORY);
sleep(10, 300);
break;
case 6:
case 7:
getMouse().moveMouseOutsideScreen();
sleep(200, 800);
break;
case 8:
Player randomPlayer = getPlayers().all().get(random(0, getPlayers().all().size()));
getMouse().move(getMap().tileToScreen(randomPlayer.getTile()));
sleep(100, 300);
getMouse().click(ClickMode.RIGHT_CLICK);
sleep(500, 1500);
break;
}
antiBanDelay = random(5000, 10000);
}
}
private int random(int min, int max) {
return Calculations.random(min, max);
}
public void onPaint(Graphics g1) {
Graphics2D g = (Graphics2D)g1;
g.setColor(color1);
g.fillRect(355, 1, 160, 148);
g.setColor(color2);
g.setStroke(stroke1);
g.drawRect(355, 1, 160, 148);
g.setFont(font1);
g.setColor(color3);
g.drawString("National Draynor Willows", 362, 17);
g.drawString("Run time: " + Timer.formatTime(timer.elapsed()), 366, 51);
g.drawString("Logs(hr): " + logsChopped + " (" + timer.getHourlyRate(logsChopped) + ")", 366, 67);
g.setColor(color4);
g.drawString("Made by Nation", 365, 144);
g.setFont(font2);
g.drawString("v1.0", 489, 143);
g.setFont(font1);
g.setColor(color3);
int xpGained = getSkills().getExperience(Skill.WOODCUTTING) - startingXP;
g.drawString("XP Gained: " + xpGained, 367, 85);
g.drawString("XP/hr: " + timer.getHourlyRate(xpGained), 368, 101);
int wcLevel = getSkills().getRealLevel(Skill.WOODCUTTING);
g.drawString("Woodcutting Level: " + wcLevel + "(" + (wcLevel - startingLevel) + ")", 367, 117);
}
@Override
public void onGameMessage(Message message) {
if(message.getMessage().contains("log"))
logsChopped++;
}
@Override
public void onPlayerMessage(Message message) {}
@Override
public void onTradeMessage(Message message) {}
@Override
public void onPrivateInMessage(Message message) {}
@Override
public void onPrivateOutMessage(Message message) {}
/** Generated Easel Code **/
private final BasicStroke stroke1 = new BasicStroke(1);
private final Font font1 = new Font("Arial", 0, 13);
private final Font font2 = new Font("Arial", 0, 10);
private final Color color1 = new Color(0, 0, 0, 66);
private final Color color2 = new Color(0, 0, 0);
private final Color color3 = new Color(255, 255, 255);
private final Color color4 = new Color(204, 204, 204);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment