Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package priv.hashy.flax;
- import org.dreambot.api.script.listener.*;
- import org.dreambot.api.script.*;
- import org.dreambot.api.wrappers.widgets.*;
- import org.dreambot.api.utilities.*;
- import org.dreambot.api.methods.map.*;
- import javax.swing.*;
- import org.dreambot.api.randoms.*;
- import org.dreambot.api.methods.skills.*;
- import org.dreambot.api.methods.*;
- import org.dreambot.api.methods.container.impl.bank.*;
- import org.dreambot.api.methods.tabs.*;
- import org.dreambot.api.wrappers.interactive.*;
- import org.dreambot.api.wrappers.items.*;
- import java.awt.*;
- import org.dreambot.api.wrappers.widgets.message.*;
- import org.dreambot.api.methods.world.*;
- @ScriptManifest(category = Category.MONEYMAKING, name = "PrivFlaxSpinner", author = "Hashtag", version = 1.0)
- public class Main extends AbstractScript implements InventoryListener, MessageListener
- {
- private WidgetChild widget;
- private WidgetChild craftWidget;
- private WidgetChild type;
- private Timer timer;
- private long nextDo;
- private long nextSpin;
- private long nextAB;
- private long nextMule;
- private long nextHop;
- private static final Tile SPIN_TILE;
- private int remaining;
- private String mule;
- private int spinned;
- private Main.State currentState;
- private boolean activeStairs;
- public Main() {
- this.remaining = 5;
- this.mule = "";
- }
- public void onStart() {
- this.timer = new Timer();
- this.mule = JOptionPane.showInputDialog(null, "Input mule's name");
- this.nextHop = this.timer.elapsed() + 2700000L;
- this.getMouse().getMouseSettings().setWordsPerMinute(100.0);
- this.getRandomManager().disableSolver(RandomEvent.DISMISS);
- this.getRandomManager().unregisterSolver(RandomEvent.DISMISS);
- this.getRandomManager().registerSolver((RandomSolver)new CustomDismissSolver(this.getClient().getInstance()));
- }
- public void onStart(final String... args) {
- this.timer = new Timer();
- this.mule = args[0].replace("_", " ");
- this.nextHop = this.timer.elapsed() + 2700000L;
- this.getRandomManager().disableSolver(RandomEvent.DISMISS);
- this.getRandomManager().unregisterSolver(RandomEvent.DISMISS);
- this.getRandomManager().registerSolver((RandomSolver)new CustomDismissSolver(this.getClient().getInstance()));
- }
- private WidgetChild getBestCraftable() {
- final int lvl = this.getSkills().getRealLevel(Skill.CRAFTING);
- if (lvl >= 9) {
- return this.getWidgets().getWidgetChild(new int[] { 154, 137 });
- }
- if (lvl >= 7) {
- return this.getWidgets().getWidgetChild(new int[] { 154, 129 });
- }
- return this.getWidgets().getWidgetChild(new int[] { 154, 127 });
- }
- public int onLoop() {
- final int[] $SwitchMap$priv$hashy$flax$Main$State = Main.Main$1.$SwitchMap$priv$hashy$flax$Main$State;
- final Main.State state = this.getState();
- this.currentState = state;
- switch ($SwitchMap$priv$hashy$flax$Main$State[state.ordinal()]) {
- case 1: {
- if (this.getBank().isOpen()) {
- if (this.shouldDo() && this.getBank().close()) {
- this.nextDo(2000);
- break;
- }
- break;
- }
- else if (this.shouldSpin()) {
- if (!this.isCraftWidgetOpen()) {
- final Item needle = this.getInventory().get("Needle");
- if (needle != null && needle.useOn("Leather")) {
- this.nextSpin(1000);
- }
- break;
- }
- if (!this.getClient().getMenu().isMenuVisible()) {
- final WidgetChild best = this.getBestCraftable();
- if (best != null && best.isVisible() && this.getMouse().click(best.getRectangle(), true)) {
- this.nextSpin(700);
- }
- break;
- }
- if (this.getClient().getMenu().getMenuCount() >= 3) {
- if (this.getClient().getMenu().clickIndex(3)) {
- this.nextSpin(2500);
- break;
- }
- break;
- }
- else {
- if (this.getClient().getMenu().close()) {
- this.nextSpin(500);
- break;
- }
- break;
- }
- }
- else {
- if (this.getMouse().isMouseInScreen() && this.getLocalPlayer().isAnimating()) {
- this.getMouse().moveMouseOutsideScreen();
- break;
- }
- if (this.timer.elapsed() > this.nextAB) {
- this.getCamera().rotateTo(Calculations.random(0, 2000), Calculations.random(100, 300));
- this.nextAB = this.timer.elapsed() + Calculations.random(1, 4) * 10 * 1000;
- break;
- }
- break;
- }
- break;
- }
- case 2: {
- if (!this.shouldDo()) {
- break;
- }
- if (this.getBank().isOpen()) {
- if (this.getSkills().getRealLevel(Skill.CRAFTING) >= 10) {
- if (!this.getInventory().isEmpty()) {
- if (this.getBank().depositAllItems()) {
- this.nextDo(300);
- break;
- }
- break;
- }
- else if (this.getBank().contains("Flax")) {
- if (this.getBank().getWithdrawMode().equals((Object)BankMode.ITEM)) {
- if (this.getBank().withdrawAll("Flax")) {
- this.activeStairs = (Calculations.random(3) == 1);
- this.nextDo(700);
- break;
- }
- break;
- }
- else {
- if (this.getBank().setWithdrawMode(BankMode.ITEM)) {
- this.nextDo(700);
- break;
- }
- break;
- }
- }
- else {
- if (this.getBank().close()) {
- this.getTabs().logout();
- this.stop();
- break;
- }
- break;
- }
- }
- else if (this.getBank().getWithdrawMode().equals((Object)BankMode.ITEM)) {
- if (!this.getInventory().contains("Needle")) {
- if (this.getBank().withdrawAll("Needle")) {
- this.nextDo(700);
- break;
- }
- break;
- }
- else if (!this.getInventory().contains("Thread")) {
- if (this.getBank().withdrawAll("Thread")) {
- this.nextDo(700);
- break;
- }
- break;
- }
- else if (!this.getInventory().onlyContains(new String[] { "Needle", "Thread" })) {
- if (this.getBank().depositAllExcept(new String[] { "Needle", "Thread" })) {
- this.nextDo(700);
- break;
- }
- break;
- }
- else {
- if (this.getBank().withdrawAll("Leather")) {
- this.nextDo(700);
- break;
- }
- break;
- }
- }
- else {
- if (this.getBank().setWithdrawMode(BankMode.ITEM)) {
- this.nextDo(700);
- break;
- }
- break;
- }
- }
- else {
- if (this.isWidgetOpen()) {
- this.getKeyboard().closeInterfaceWithESC();
- sleep(350 + Calculations.random(150));
- break;
- }
- if (this.getLocalPlayer().getZ() != 1 || !this.getClient().getMenu().isMenuVisible()) {
- final int z = this.getLocalPlayer().getZ();
- if ((this.getWalking().getDestinationDistance() < 4 && z == 2) || ((z == 1 || z == 0) && !this.getLocalPlayer().isMoving())) {
- if ((z == 1 && this.getMap().canReach(new Tile(3206, 3211, 1))) || z != 1) {
- if (this.getBank().openClosest()) {
- sleepUntil(() -> this.getBank().isOpen() || z != this.getLocalPlayer().getZ(), 2000L);
- }
- }
- else if (this.getWalking().walk(new Tile(3206, 3211, 1))) {
- sleepUntil(() -> this.getLocalPlayer().isMoving(), 2000L);
- }
- }
- break;
- }
- if (this.getClient().getMenu().contains("Climb-up")) {
- if (this.getClient().getMenu().clickAction("Climb-up")) {
- this.nextDo(2000);
- break;
- }
- break;
- }
- else {
- if (this.getClient().getMenu().close()) {
- this.nextDo(500);
- break;
- }
- break;
- }
- }
- break;
- }
- case 3: {
- if (this.getLocalPlayer().getZ() != 1) {
- if (this.getWalking().getDestinationDistance() < 3 && this.shouldDo() && this.getTabs().open(Tab.INVENTORY)) {
- final GameObject stairs = (GameObject)this.getGameObjects().closest(go -> go != null && go.getName().equals("Staircase") && go.getY() < 3210);
- if (this.getLocalPlayer().distance((Entity)stairs) < 7.0 && stairs.interact("Climb-" + ((this.getLocalPlayer().getZ() == 0) ? "up" : "down"))) {
- this.nextDo(2000);
- }
- else if (this.getWalking().walk(this.randomTileFrom(stairs.getTile(), 4))) {
- sleep(300);
- this.getCamera().mouseRotateToEntity((Entity)stairs);
- this.nextDo(2000);
- }
- break;
- }
- break;
- }
- else if (this.isWidgetOpen()) {
- if (this.shouldDo()) {
- final int c = this.getInventory().count("Flax");
- final String action = (c > 10) ? "Make X" : ((c > 5) ? "Make 10" : ((c > 1) ? "Make 5" : "Make 1"));
- if (this.widget.interact(action)) {
- this.nextDo(700);
- }
- break;
- }
- break;
- }
- else if (this.shouldSpin()) {
- if (this.shouldType()) {
- this.remaining = Calculations.random(3, 7);
- this.nextAB = this.timer.elapsed() + Calculations.random(1, 4) * 10 * 1000;
- this.getKeyboard().type((Object)Calculations.random(30, 999), true);
- this.nextDo(2000);
- this.nextSpin(2000);
- break;
- }
- final GameObject wheel = (GameObject)this.getGameObjects().closest(new String[] { "Spinning wheel" });
- if (wheel != null && !this.getLocalPlayer().isMoving() && !this.getLocalPlayer().isAnimating()) {
- if (this.getLocalPlayer().distance((Entity)wheel) < 7.0 && this.getMap().canReach(Main.SPIN_TILE)) {
- if (wheel.interact("Spin")) {
- this.nextSpin(2500);
- }
- }
- else if (this.getWalking().walk((Entity)wheel)) {
- this.nextSpin(1000);
- }
- }
- break;
- }
- else {
- if (this.getInventory().count("Flax") <= this.remaining) {
- break;
- }
- if (this.getMouse().isMouseInScreen() && this.getLocalPlayer().isAnimating()) {
- if (this.remaining % 2 == 0) {
- this.getCamera().mouseRotateTo(Calculations.random(0, 2000), Calculations.random(100, 300));
- }
- this.getMouse().moveMouseOutsideScreen();
- break;
- }
- if (this.timer.elapsed() > this.nextAB) {
- this.getCamera().rotateTo(Calculations.random(0, 2000), Calculations.random(100, 300));
- this.nextAB = this.timer.elapsed() + Calculations.random(1, 4) * 10 * 1000;
- break;
- }
- break;
- }
- break;
- }
- case 4: {
- if (!this.shouldDo()) {
- break;
- }
- if (this.getTrade().isOpen() || this.getInventory().contains(i -> i != null && i.isNoted() && i.getName().equals("Bow string"))) {
- if (this.getBank().isOpen()) {
- if (this.getBank().close()) {
- this.nextDo(700);
- break;
- }
- break;
- }
- else if (this.getClient().getCurrentWorld() == this.getFriends().getFriend(this.mule).getWorld()) {
- if (!this.getTrade().isOpen()) {
- break;
- }
- if (this.getTrade().getMyItems() == null || this.getTrade().getMyItems().length == 0) {
- if (this.getTrade().addItem("Bow string", this.getInventory().count("Bow string"))) {
- this.nextDo(1000);
- break;
- }
- break;
- }
- else {
- if (this.getTrade().acceptTrade()) {
- this.nextDo(2000);
- break;
- }
- break;
- }
- }
- else {
- if (this.getWorldHopper().quickHop(this.getFriends().getFriend(this.mule).getWorld())) {
- this.nextDo(2000);
- break;
- }
- break;
- }
- }
- else if (this.getBank().isOpen()) {
- if (this.getInventory().contains("Bow string")) {
- if (this.getBank().depositAllItems()) {
- this.nextDo(700);
- break;
- }
- break;
- }
- else if (this.getBank().getWithdrawMode().equals((Object)BankMode.NOTE)) {
- if (this.getBank().withdrawAll("Bow string")) {
- this.nextDo(700);
- break;
- }
- break;
- }
- else {
- if (this.getBank().setWithdrawMode(BankMode.NOTE)) {
- this.nextDo(700);
- break;
- }
- break;
- }
- }
- else if (this.getLocalPlayer().getZ() == 1 && this.getClient().getMenu().isMenuVisible()) {
- if (this.getClient().getMenu().clickAction("Climb-up")) {
- this.nextDo(2000);
- break;
- }
- break;
- }
- else {
- if (!this.getLocalPlayer().isMoving() && this.getBank().openClosest()) {
- this.nextDo(2000);
- break;
- }
- break;
- }
- break;
- }
- case 5: {
- if (this.getWorldHopper().hopWorld(this.getWorlds().getRandomWorld(w -> w != null && w.isMembers() && !w.isDeadmanMode() && !w.isLastManStanding() && !w.isPVP() && w.getMinimumLevel() == 0))) {
- this.nextDo(2000);
- this.nextHop = this.timer.elapsed() + 2700000L;
- break;
- }
- break;
- }
- }
- return 200;
- }
- private Tile randomTileFrom(final Tile t, final int max) {
- return new Tile(t.getX(), t.getY() + Calculations.random(max), t.getZ());
- }
- public void onPaint(final Graphics g) {
- if (!this.hasAttackOptionsHidden()) {
- g.setColor(Color.RED);
- g.setFont(new Font("Helvetica", 1, 15));
- g.drawString("WARNING: Hide NPC attack options from the ingame settings!", 10, 50);
- }
- if (!this.hasESCEnabled()) {
- g.drawString("TIP: Enable ESC closes interfaces from the ingame settings!", 10, 65);
- }
- g.setColor(Color.WHITE);
- g.setFont(new Font("Helvetica", 1, 12));
- g.drawString("Time: " + this.timer.formatTime(), 10, 80);
- g.drawString("Spinned: " + this.spinned, 10, 95);
- g.drawString("Hourly: " + this.timer.getHourlyRate(this.spinned), 10, 110);
- g.drawString("Mule: " + this.mule, 10, 125);
- g.drawString("State: " + this.currentState, 10, 140);
- }
- public void onItemChange(final Item[] items) {
- for (final Item i : items) {
- if (i != null) {
- if (i.getName().equals("Flax")) {
- if (i.getAmount() < 0) {
- ++this.spinned;
- this.nextSpin(3000);
- if (this.activeStairs && this.getInventory().count("Flax") < this.remaining) {
- if (!this.getClient().getMenu().isMenuVisible()) {
- final GameObject stairs = (GameObject)this.getGameObjects().closest(new String[] { "Staircase" });
- if (stairs != null && this.getMap().canReach((Entity)stairs)) {
- while (!this.getDialogues().inDialogue() && this.getInventory().contains("Flax") && !this.getClient().getMenu().isMenuVisible()) {
- if (stairs.isOnScreen()) {
- if (stairs.getBoundingBox().contains(this.getMouse().getPosition())) {
- this.getMouse().click(true);
- }
- else {
- this.getMouse().move(stairs.getClickablePoint());
- }
- }
- else {
- this.getCamera().rotateToEntity((Entity)stairs);
- }
- this.nextSpin(2500);
- sleep(300);
- }
- }
- }
- else if (!this.getClient().getMenu().isMouseOnAction("Climb-up")) {
- if (this.getClient().getMenu().contains("Climb-up")) {
- this.getClient().getMenu().mouseOverAction("Climb-up");
- }
- else {
- this.getClient().getMenu().close();
- this.getCamera().rotateTo(Calculations.random(0, 2000), Calculations.random(100, 300));
- }
- }
- }
- }
- else {
- this.nextDo(50);
- }
- }
- else if (i.getName().equals("Leather") && i.getAmount() < 0) {
- this.nextSpin(2500);
- }
- }
- }
- }
- private Main.State getState() {
- if (this.getSkills().getRealLevel(Skill.CRAFTING) >= 10) {
- if (this.getWorlds().getWorld(this.getClient().getCurrentWorld()).isF2P()) {
- return Main.State.HOP;
- }
- if (this.getInventory().contains(i -> i != null && i.getName().equals("Flax") && !i.isNoted())) {
- return Main.State.SPIN;
- }
- if (this.mule != null && this.timer.elapsed() > this.nextMule && this.getFriends().getFriend(this.mule) != null && this.getFriends().getFriend(this.mule).isOnline()) {
- return Main.State.TO_MULE;
- }
- if (this.timer.elapsed() > this.nextHop) {
- return Main.State.HOP;
- }
- }
- else if (this.getInventory().contains("Leather")) {
- return Main.State.CRAFT;
- }
- return Main.State.WITHDRAW;
- }
- private boolean shouldType() {
- final WidgetChild widgetChild = this.getWidgets().getWidgetChild(new int[] { 162, 32 });
- this.type = widgetChild;
- return widgetChild != null && this.type.isVisible();
- }
- private boolean isWidgetOpen() {
- final WidgetChild widgetChild = this.getWidgets().getWidgetChild(new int[] { 459, 95 });
- this.widget = widgetChild;
- return widgetChild != null && this.widget.isVisible();
- }
- private boolean isCraftWidgetOpen() {
- final WidgetChild widgetChild = this.getWidgets().getWidgetChild(new int[] { 154, 0 });
- this.craftWidget = widgetChild;
- return widgetChild != null && this.craftWidget.isVisible();
- }
- private boolean hasAttackOptionsHidden() {
- return this.getPlayerSettings().getConfig(1306) == 3;
- }
- private boolean hasESCEnabled() {
- return this.getPlayerSettings().getConfig(1224) < 0;
- }
- private boolean shouldDo() {
- return this.timer.elapsed() > this.nextDo;
- }
- private void nextDo(final int next) {
- this.nextDo = this.timer.elapsed() + next;
- }
- private boolean shouldSpin() {
- return this.timer.elapsed() > this.nextSpin;
- }
- private void nextSpin(final int next) {
- this.nextSpin = this.timer.elapsed() + next;
- }
- public void onGameMessage(final Message message) {
- if (message.getMessage().contains("Accepted trade")) {
- this.nextMule = this.timer.elapsed() + 600000L;
- }
- }
- public void onPlayerMessage(final Message message) {
- }
- public void onTradeMessage(final Message message) {
- if (message.getMessage().contains("wishes to trade") && message.getUsername().toLowerCase().equals(this.mule.toLowerCase()) && this.getTrade().tradeWithPlayer(message.getUsername())) {
- this.nextDo(2000);
- }
- }
- public void onPrivateInMessage(final Message message) {
- }
- public void onPrivateOutMessage(final Message message) {
- }
- static {
- SPIN_TILE = new Tile(3209, 3213, 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement