Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.chandler.spinner;
- import java.awt.Color;
- import java.awt.Graphics2D;
- import java.awt.Point;
- import java.util.List;
- import org.dreambot.api.methods.Calculations;
- import org.dreambot.api.methods.filter.Filter;
- import org.dreambot.api.methods.map.Tile;
- 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.utilities.Timer;
- import org.dreambot.api.utilities.impl.Condition;
- import org.dreambot.api.wrappers.interactive.GameObject;
- import org.dreambot.api.wrappers.widgets.WidgetChild;
- import org.dreambot.api.wrappers.widgets.message.Message;
- import org.dreambot.api.wrappers.widgets.message.MessageType;
- @ScriptManifest(author = "Chandler", category = Category.CRAFTING, name = "Chandler's Improved Spinner", version = 1.2)
- public class SpinnerMain extends AbstractScript {
- public String status = "Starting...";
- public long lastIdle = 0;
- public int numSpun = 0;
- public Timer timer = new Timer();
- public int profit = 100;
- public double tiredness = 0.0;
- public long loopCount = 0L;
- public double tMultiplier;
- public Filter<GameObject> stairs1Filter = new Filter<GameObject>() {
- @Override
- public boolean match(GameObject obj) {
- return obj.getName().equals("Staircase") && obj.getY() == 3208;
- }
- };
- public Filter<GameObject> doorFilter = new Filter<GameObject>() {
- @Override
- public boolean match(GameObject obj) {
- return obj.getName().equals("Door") && obj.getX() == 3207 && obj.getY() == 3214;
- }
- };
- @Override
- public void onMessage(Message m) {
- if(m.getType() == MessageType.GAME && m.getMessage().contains("run out of")) {
- numSpun += getInventory().count("Bow string");
- }
- }
- @Override
- public void onStart() {
- getSkillTracker().start(Skill.CRAFTING);
- tMultiplier = Calculations.random(0.1D, 0.4D);
- }
- @Override
- public void onPaint(Graphics2D g) {
- g.setColor(Color.BLACK);
- g.fillRect(5, 30, 210, 105);
- g.setColor(Color.RED);
- g.drawString("Chandler's Better Spinner", 10, 45);
- g.drawString("Status: " + status, 10, 60);
- g.drawString("Runtime: " + Timer.formatTime(timer.elapsed()), 10, 75);
- g.drawString("BS Spun (Hr.): " + (getSkillTracker().getGainedExperience(Skill.CRAFTING) / 15) + " (" + timer.getHourlyRate((int)(getSkillTracker().getGainedExperience(Skill.CRAFTING) / 15)) + ")", 10, 90);
- g.drawString("XP Gained (Hr.): " + getSkillTracker().getGainedExperience(Skill.CRAFTING) + " (" + getSkillTracker().getGainedExperiencePerHour(Skill.CRAFTING) + ")", 10, 105);
- g.drawString("Profit (Hr.): " + ((getSkillTracker().getGainedExperience(Skill.CRAFTING) / 15)*100) + " (" + timer.getHourlyRate((int)((getSkillTracker().getGainedExperience(Skill.CRAFTING) / 15)*100)), 10, 120);
- g.drawString("Tiredness: " + tiredness, 10, 135);
- }
- @Override
- public int onLoop() {
- loopCount++;
- if(getCamera().getPitch() < 180) {
- getCamera().rotateToPitch(250 + Calculations.random(130));
- }
- if(getFloor() == 1) {
- if(getInventory().count("Flax") == 0) {
- if(getGameObjects().closest(doorFilter) != null && d2Spinner() < 2) {
- status = "Opening the door";
- openDoor();
- } else {
- if(d2Stairs2() < 5) {
- if(stairs1IsVisible()) {
- status = "Going up stairs";
- goUpStairs();
- } else {
- status = "Turning to stairs";
- turnTowardsStairs1();
- }
- } else {
- status = "Walking to stairs";
- getCloserToStairs1();
- }
- }
- } else {
- if(d2Spinner() < 5) {
- if(getGameObjects().closest(doorFilter) != null && d2Spinner() > 1) {
- status = "Opening door";
- openDoor();
- }
- //does nothing.
- /*if(isLevelUp()) {
- status = "Clicking continue";
- getKeyboard().type(" ", false);
- AbstractScript.sleepUntil(new Condition(){
- @Override
- public boolean verify() {
- return !isLevelUp();
- }
- }, 2000);
- return 500;
- }*/
- if(isSpinInterfaceUp()) {
- //click make x
- status = "Clicking widget";
- lastIdle = 0;
- clickMakeX();
- AbstractScript.sleepUntil(new Condition(){
- @Override
- public boolean verify() {
- return isEnterAmountUp();
- }
- }, 4000);
- if(isEnterAmountUp()) {
- status = "Inputting 28";
- getKeyboard().type("28");
- }
- return Calculations.random(4000);
- } else {
- if(getPlayers().localPlayer().getAnimation() == -1) {
- if(lastIdle != 0) {
- if(System.currentTimeMillis() - lastIdle > 2000) {
- getGameObjects().closest("Spinning wheel").interactForceLeft("Spin");
- lastIdle = 0;
- status = "Using wheel";
- }
- } else {
- lastIdle = System.currentTimeMillis();
- }
- } else {
- status = "Spinning";
- doAntiBan();
- lastIdle = 0;
- }
- }
- } else {
- getCloseToSpinner();
- }
- }
- } else if(getFloor() == 2) {
- if(bankIsOpen()) {
- if(getInventory().count("Bow string") > 0) {
- status = "Depositing bow strings";
- depositBowstrings();
- }
- if(getInventory().getEmptySlots() > 0) {
- status = "Withdrawing flax";
- withdrawFlax();
- }
- if(getInventory().count("Flax") > 0) {
- status = "Closing bank";
- closeBank();
- }
- } else {
- if(getInventory().count("Bow string") > 0 ||
- (getInventory().count("Bow string") == 0 & getInventory().count("Flax") == 0)) {
- if(d2Bank() < 5) {
- if(bankIsVisible()) {
- status = "Opening bank";
- openBank();
- } else {
- status = "Turning to bank";
- turnTowardsBank();
- }
- } else {
- status = "Going to bank";
- getCloser();
- }
- } else {
- if(d2Stairs1() < 5) {
- if(stairs1IsVisible()) {
- status = "Going down stairs";
- goDownStairs();
- } else {
- status = "Turning to stairs";
- turnTowardsStairs1();
- }
- } else {
- status = "Going to stairs";
- getCloserToStairs1();
- }
- }
- }
- }
- //TODO implement tiredness?
- return Calculations.random(400, 750) + (int)tiredness;
- }
- public double getTired() {
- if(tiredness < 2500) { //if not too tired
- tiredness = Math.pow(loopCount/30, 2) * tMultiplier;
- }
- return tiredness;
- }
- private void doAntiBan() {
- if(getPercent(90)) {
- status = "Acting natural";
- switch(Calculations.random(3)) {
- case 0:
- //Check something off screen
- getMouse().moveMouseOutsideScreen();
- break;
- case 1:
- //Check open stats
- if(getInventory().count("Flax") > 2) {
- getTabs().open(Tab.STATS);
- sleep(Calculations.random(3000, 5000));
- getTabs().open(Tab.INVENTORY);
- }
- break;
- case 2:
- //Move the camera a bit
- getCamera().rotateToYaw(getCamera().getYaw() + Calculations.random(30));
- break;
- case 3:
- //Move the mouse a little
- getMouse().move(new Point(getMouse().getX() + Calculations.random(10), getMouse().getY() + Calculations.random(10)));
- break;
- }
- }
- }
- private boolean isLevelUp() {
- List<WidgetChild> children = getWidgets().getWidgetChildrenContainingText("just advanced a Crafting");
- List<WidgetChild> c2 = getWidgets().getWidgetChildrenContainingText("to continue");
- return children.size() > 0 && children.get(0).isVisible() && c2.size() > 0 && c2.get(0).isVisible();
- }
- private boolean isEnterAmountUp() {
- List<WidgetChild> children = getWidgets().getWidgetChildrenContainingText("Enter amount:");
- return children.size() > 0 && children.get(0).isVisible();
- }
- private boolean isSpinInterfaceUp() {
- List<WidgetChild> children = getWidgets().getWidgetChildrenContainingText("Bow String");
- return children.size() > 0 && children.get(0).isVisible();
- }
- private void clickMakeX() {
- List<WidgetChild> children = getWidgets().getWidgetChildrenContainingText("Bow String");
- if(children.size() > 0 && children.get(0).isVisible()) {
- children.get(0).interact("Make X");
- }
- }
- private void getCloseToSpinner() {
- if(getPercent(80)) {
- if(getGameObjects().closest("Spinning wheel").isOnScreen()) {
- getGameObjects().closest("Spinning wheel").interactForceLeft("Spin");
- }
- } else {
- Tile random = new Tile(getGameObjects().closest("Spinning wheel").getTile().getX()+ Calculations.random(1), getGameObjects().closest("Spinning wheel").getTile().getY()+1 + Calculations.random(1));
- getWalking().clickTileOnMinimap(random);
- }
- AbstractScript.sleepUntil(new Condition() {
- @Override
- public boolean verify() {
- return d2Spinner() < 5;
- }
- }, 6000);
- }
- private void getCloserToStairs1() {
- GameObject stairs = getGameObjects().closest(stairs1Filter);
- getWalking().clickTileOnMinimap(stairs.getTile());
- AbstractScript.sleepUntil(new Condition(){
- @Override
- public boolean verify(){
- return d2Stairs1() < 3;
- }
- }, 6000);
- }
- private void goDownStairs() {
- GameObject stairs = getGameObjects().closest(stairs1Filter);
- getMouse().move(stairs);
- stairs.interact("Climb-down");
- AbstractScript.sleepUntil(new Condition(){
- @Override
- public boolean verify() {
- return getPlayers().localPlayer().getZ() == 1;
- }
- }, 4000);
- }
- private void goUpStairs() {
- GameObject stairs = getGameObjects().closest(stairs1Filter);
- getMouse().move(stairs);
- stairs.interact("Climb-up");
- AbstractScript.sleepUntil(new Condition(){
- @Override
- public boolean verify() {
- return getPlayers().localPlayer().getZ() == 2;
- }
- }, 4000);
- }
- private void turnTowardsStairs1() {
- GameObject stairs = getGameObjects().closest(stairs1Filter);
- getCamera().rotateToEntity(stairs);
- getCamera().rotateToYaw(getCamera().getYaw() + Calculations.random(30));
- }
- private int getCloser() {
- GameObject booth = getGameObjects().closest("Bank booth");
- Tile t = new Tile(booth.getTile().getX(), booth.getTile().getY() - 2);
- getWalking().clickTileOnMinimap(t);
- AbstractScript.sleepUntil(new Condition(){
- @Override
- public boolean verify(){
- return d2Bank() < 3;
- }
- }, 6000);
- return 500;
- }
- public int depositBowstrings() {
- getBank().depositAllItems();
- AbstractScript.sleepUntil(new Condition(){
- @Override
- public boolean verify() {
- return getInventory().getEmptySlots() == 28;
- }
- }, 3000);
- return 500;
- }
- public int withdrawFlax() {
- if(getBank().count("Flax") > 0) {
- getBank().withdraw("Flax", 28);
- AbstractScript.sleepUntil(new Condition(){
- @Override
- public boolean verify(){
- return getInventory().count("Flax") > 0;
- }
- }, 2500);
- return 500;
- } else {
- getBank().close();
- getTabs().logout();
- log("Out of flax. Logging out! Don't wanna stand there and look suspicious, do we?");
- stop();
- }
- return 0;
- }
- public int openDoor() {
- getGameObjects().closest(doorFilter).interact("Open");
- Timer t = new Timer();
- while(t.elapsed() < 6000 && getGameObjects().closest(doorFilter).exists()) {
- sleep(Calculations.random(50, 100));
- }
- return 0;
- }
- public boolean getPercent(int percent) {
- return Calculations.random(100) > percent;
- }
- public int closeBank() {
- if(getPercent(85)) {
- Tile random = new Tile(getPlayers().localPlayer().getTile().getX() + Calculations.random(2),
- getPlayers().localPlayer().getTile().getY() + Calculations.random(2));
- getWalking().clickTileOnMinimap(random);
- } else {
- getBank().close();
- }
- AbstractScript.sleepUntil(new Condition(){
- @Override
- public boolean verify() {
- return !getBank().isOpen();
- }
- }, 2000);
- return 450;
- }
- public double d2Spinner() {
- return Calculations.distance(getPlayers().localPlayer().getTile(), getGameObjects().closest("Spinning wheel").getTile());
- }
- public double d2Bank() {
- return Calculations.distance(getPlayers().localPlayer().getTile(), getGameObjects().closest("Bank booth").getTile());
- }
- public double d2Stairs1() {
- return Calculations.distance(getPlayers().localPlayer().getTile(), getGameObjects().closest(stairs1Filter).getTile());
- }
- public double d2Stairs2() {
- return Calculations.distance(getPlayers().localPlayer().getTile(), getGameObjects().closest(stairs1Filter).getTile());
- }
- public int turnTowardsBank() {
- GameObject booth = getGameObjects().closest("Bank booth");
- getCamera().rotateToEntity(booth);
- getCamera().rotateToYaw(getCamera().getYaw() + Calculations.random(20));
- return 0;
- }
- public boolean stairs1IsVisible() {
- return getGameObjects().closest(stairs1Filter).isOnScreen();
- }
- public boolean bankIsVisible() {
- return getGameObjects().closest("Bank booth").isOnScreen();
- }
- public int openBank() {
- GameObject booth = getGameObjects().closest("Bank booth");
- getMouse().move(booth);
- if(getPercent(75)) {
- booth.interactForceLeft("Bank");
- } else {
- booth.interact("Bank");
- }
- AbstractScript.sleepUntil(new Condition(){
- @Override
- public boolean verify() {
- return getBank().isOpen();
- }
- }, 3000);
- return 500;
- }
- public boolean bankIsOpen() {
- return getBank().isOpen();
- }
- public int getFloor() {
- return getPlayers().localPlayer().getZ();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement