KhalDrogonerr 1 Posted March 13 Hi, I've been stuck in muling for a day now, and it's the first time I've tried to implement a socket and I'm having a lot of difficulty as I'm not an expert. I tried to use an AI regarding delivery and recognition via Socket, but I'm stuck and I don't know. how to solve import org.dreambot.api.methods.container.impl.Inventory; import org.dreambot.api.methods.container.impl.bank.Bank; import org.dreambot.api.methods.interactive.GameObjects; import org.dreambot.api.methods.interactive.Players; import org.dreambot.api.methods.map.Area; import org.dreambot.api.methods.walking.impl.Walking; import org.dreambot.api.script.AbstractScript; import org.dreambot.api.script.Category; import org.dreambot.api.script.ScriptManifest; import org.dreambot.api.wrappers.interactive.GameObject; import org.dreambot.api.utilities.Sleep; import org.dreambot.api.methods.map.Tile; import java.io.*; import java.net.Socket; import java.io.OutputStream; import java.io.Serializable; import org.dreambot.api.methods.container.impl.bank.BankMode; import org.dreambot.api.methods.trade.Trade; import org.dreambot.api.wrappers.interactive.Player; import org.dreambot.api.wrappers.cache.nodes.NodeWrapper; import org.dreambot.api.wrappers.widgets.WidgetChild; import org.dreambot.api.wrappers.interactive.Entity; @ScriptManifest(author = "KhalDrogonerr", name = "Iron", version = 1.0, description = "Simple Iron Miner", category = Category.MINING) public class Worker extends AbstractScript { private static final String MULE_IP = "indirizzo_ip_mulo"; private static final int MULE_PORT = 12345; // Porta del server del mulo private long lastDeliveryTime; public static class DeliveryData implements Serializable { private int ironOreCount; public DeliveryData(int ironOreCount) { this.ironOreCount = ironOreCount; } public int getIronOreCount() { return ironOreCount; } } public static class MuleClient { public static void sendDeliveryData(DeliveryData deliveryData) { try (Socket socket = new Socket(MULE_IP, MULE_PORT)) { ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream()); objectOutputStream.writeObject(deliveryData); } catch (IOException e) { e.printStackTrace(); } } } State state; Area bankArea = new Area(3009, 3355, 3018, 3354); Area ironOre = new Area(2977, 3231, 2967, 3243); Area GE = new Area(3155, 3499, 3174, 3480); public enum State { WALKING_TO_BANK, USE_BANK, BANKING, TAKE_PICKAXE, FINDING_ORE, MINING_ORE, DElIVER_TO_GE, DELIVER_TO_MULE } public void onStart() { log("Welcome to Simple Mining Script."); log("If you experience any issues while running this script please report them to me on the forums."); log("Enjoy the script!."); } @Override public int onLoop() { switch (getState()) { case WALKING_TO_BANK: if (bankArea.distance(Players.getLocal().getTile()) > 1) Walking.walk(bankArea.getCenter().getRandomized()); break; case USE_BANK: if (!Bank.isOpen() || !Players.getLocal().isMoving()) { GameObject bankBooth = GameObjects.closest("Bank booth"); bankBooth.interact("Bank"); Sleep.sleepUntil(Bank::isOpen, 1000); return 1000; } break; case BANKING: if (Bank.isOpen()) { if (Inventory.isFull()) { Sleep.sleep(2000, 5000); Bank.depositAllExcept(item -> item.getName().equals("Bronze pickaxe")); if (!Inventory.contains("Iron ore")) { Bank.close(); } } } break; case TAKE_PICKAXE: if (!Inventory.contains("Bronze pickaxe")) { if (Bank.open()) { if (Bank.contains("Bronze pickaxe")) { Bank.withdraw("Bronze pickaxe", 1); Sleep.sleepUntil(() -> Inventory.contains("Bronze pickaxe"), 6000); } else { log("Bronze pickaxe not found in bank!"); } Bank.close(); } } break; case FINDING_ORE: if (ironOre.distance(Players.getLocal().getTile()) > 1) Walking.walk(ironOre.getCenter().getRandomized()); break; case MINING_ORE: if (!Players.getLocal().isAnimating() && !Players.getLocal().isMoving()) { GameObject ironRocks = GameObjects.closest(t -> t.getName().equalsIgnoreCase("iron rocks") && ironOre.contains(t.getTile())); if (ironRocks != null && ironRocks.interact("Mine")) { Sleep.sleepUntil(() -> Players.getLocal().isAnimating(), 4000); } } break; case DElIVER_TO_GE: if (!muleIsAtGE()) { if (GE.distance(Players.getLocal().getTile()) > 1) { Walking.walk(GE.getCenter().getRandomized()); } } break; case DELIVER_TO_MULE: long currentTime = System.currentTimeMillis(); if (currentTime - lastDeliveryTime >= 3 * 60 * 60 * 1000) { // 3 ore in millisecondi try (Socket socket = new Socket(MULE_IP, MULE_PORT)) { OutputStream outputStream = socket.getOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream); Bank.setWithdrawMode(BankMode.NOTE); Bank.withdrawAll("Iron ore"); DeliveryData deliveryData = new DeliveryData(getIronOreCount()); objectOutputStream.writeObject(deliveryData); objectOutputStream.close(); outputStream.close(); lastDeliveryTime = currentTime; Player mule = getMuleByIP(MULE_IP); if (mule != null) { mule.interact("Trade with"); Sleep.sleepUntil(() -> Trade.isOpen(), 5000); } } catch (IOException e) { e.printStackTrace(); } } break; } return 500; } private State getState() { long currentTime = System.currentTimeMillis(); if (Inventory.isFull() && !bankArea.contains(Players.getLocal().getTile())) { return State.WALKING_TO_BANK; } else if (Inventory.isFull() && bankArea.contains(Players.getLocal().getTile()) && !Bank.isOpen()) { return State.USE_BANK; } else if (Bank.isOpen() && Inventory.isFull()) { return State.BANKING; } else if (!Inventory.contains("Bronze pickaxe")) { return State.TAKE_PICKAXE; } else if (!Inventory.isFull() && !ironOre.contains(Players.getLocal().getTile())) { return State.FINDING_ORE; } else if (!Inventory.isFull() && ironOre.contains(Players.getLocal().getTile())) { return State.MINING_ORE; } else if (currentTime - lastDeliveryTime >= 3 * 60 * 60 * 1000) { if (muleIsAtGE()) { return State.DELIVER_TO_MULE; } else { return State.DElIVER_TO_GE; } } return state; } private int getIronOreCount() { return Inventory.count("Iron ore") + Bank.count("Iron ore"); } private boolean muleIsAtGE() { Tile botPosition = Players.getLocal().getTile(); return GE.contains(botPosition); } }
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now