/* * * Magic Cutter and Banker * For use in Seer's at the Batch of 4 magic tree's * Made by Doyley & Guy * (c) 2005 */ /* *@todo better bank handaling * */ public class MagicBank extends Script implements ServerMessageListener { public static String[] commands = { "magicBank" }; /* *our axes and trees *@todo better coords */ private static final String[] TREES = { "MAGIC:1306" }; private static final String[] AXES = { "BRONZE:1351,508", "IRON:1351,510", "STEEL:1353,512", "MITHRIL:1355,516", "ADAMANT:1357,518", "RUNE:1359,520" }; private static final Tile[] TREES_TO_BANK = new Tile[] { new Tile(2696,3428), new Tile(2700,3427), new Tile(2704,3429), new Tile(2707,3435), new Tile(2709,3439), new Tile(2710,3443), new Tile(2714,3449), new Tile(2716,3454), new Tile(2721,3460), new Tile(2720,3465), new Tile(2722,3470), new Tile(2724,3477), new Tile(2727,3482), new Tile(2726,3487), new Tile(2726,3493) }; /* *log id */ /* * Time and Date functions */ private static final int PROGRESS_DELAY = 5; private final long startTime = System.currentTimeMillis(); private long start; private static final int LOGS = 1513; /* * Other Int's and things here eg banking etc */ private String treeName; private int[] treeType; private int[] axeType; private int Ent; private static final int OBJECT_BANK_BOOTH = 2213; private static final int ITEM_AXE_HANDLE = 492; private int treeCount; private int reAttachCount; private Item lostHead; private Tile treePos; private int attachStep; private boolean banking; public int bankCount; /* *Starting the Script */ public boolean start(String cmd, String[] args) { if (args.length < 2) { log("Usage: powerChopper(magic,rune"); return false; } treeType = getTreesForName(args[0]); axeType = getAxeForName(args[1]); if (treeType == null || axeType == null) { log("Tree/Axe type was invalid (" + args[0] + ", " + args[1] + args[2]+ ")"); return false; } init(); return true; } /* * Arguments for axetype and log * @todo toggle banking. like someone would drop magics :\ */ /* *load out event manager */ private void init() { EventManager.addServerMessageListener(this); } /* * Server message * @todo add more args here eg randoms */ public void serverMessage(String message) { if (message.indexOf("you are dead") != -1) { log("You died, quitting!"); shutdown(); } else if (message.indexOf("carefully re") != -1) { reAttachCount++; } else if (message.indexOf("magic") != -1) { treePos = null; treeCount++; } } /* * * Time setting of methods */ public long run(long lastExecuted) { runProgress(); long ticks = runCombat(); if (ticks != 0) return ticks; ticks = BankingMagic(); if (ticks != 0) return ticks; return runChop(); } /* progress report * @todo more goodies */ private void runProgress() { int minutes = (int) ((System.currentTimeMillis() - start) / 60000); int minutesAgo = (int) ((System.currentTimeMillis() - startTime) / 60000); if (minutes >= PROGRESS_DELAY) { log("you have banked" + bankCount); log("there have been" + Ent); log("You have cut " + treeCount + " trees!"); log("You have reattached axe head " + reAttachCount + " times!"); log("Since " + ((System.currentTimeMillis() - startTime) / 60000) +" minutes ago"); treeCount++; start = System.currentTimeMillis(); } } /* * player in trouble * @todo check the walk area for obsticles */ private long runCombat() { if (!inCombat(myPlayer())) return 0; else { log("Running away from combat... "); Tile pos = getPosition(myPlayer()); pos.x += 10; pos.y += 10; walk(pos); return 2500 + random(500, 1000); } } /* check invent count * @todo make this flawless */ private long runBank() { if (inventoryCount() == inventoryCount(axeType[0]) && banking) { banking = true; return 0; } if (banking) return BankingMagic(); if (inventoryCount() == 28) { log("Time to bank them Magics"); banking = true; return 1; } return 0; } /* * Chop chop * @todo make this faster */ private long runChop() { if (myPlayer().anim == -1) { int treeID = findObject(treeType); if (treeID != -1) { Tile pos = objectPos(treeID); if (distanceTo(pos) > 5) { walk(pos); return 2500 + random(2000, 4000); } else { treePos = pos; atObject(treeID, 1); return 2500 + random(500, 1000); } } else { log("Could not find tree, waiting"); return 2500 + random(500, 1000); } } else if (treePos != null && myPlayer().anim != -1) { NPC ent = findNearestNPCByName(treeName); if (ent == null) return 200; if (getPosition(ent).distanceTo(treePos) < 3) { log("Ent appeared near us, stop chopping."); Ent++; walk(getPosition(myPlayer())); treePos = null; } return 2500 + random(500, 1000); } return 200; } /* * Banking Method * @todo make this leet */ private long BankingMagic() { if (banking) { Tile[] path = TREES_TO_BANK; int distance = distanceTo(path[path.length - 1]); if (distance > 5) { walkPath(path, 15); return 2500 + random(500, 1000); } else { if (getInterface() != Constants.INTERFACE_BANK) { int booth = findObject(OBJECT_BANK_BOOTH); if (booth != -1) { log("Opening bank..."); atObject(booth, 2); return 2500 + random(500, 1000); } } else if (getInterface() == Constants.INTERFACE_BANK) { if (inventoryCount() > inventoryCount(axeType[0])) { return bankLogs(); } else { closeInterface(); log("Finished banking"); banking = false; /* * reversePath(path); *log("walking back to the mine"); */ } } } } if (inventoryCount() == 28 && !banking) { log("Time to bank.."); bankCount++; banking = true; return 1; } else banking = false; return 0; } /* *bank our logs */ private long bankLogs() { int[] inv = getInventory(); for (int i = 0; i < inv.length; i++) { if (inv[i] != -1 && inv[i] != axeType[0]) { depositAll(inv[i], i); return 500 + random(500, 1000); } } return 0; } /* * get our tree name * @todo make this more erm */ private final int[] getTreesForName(String name) { for (String log : TREES) { if (log.startsWith(name.toUpperCase())) { treeName = new String(log.split(":")[0].substring(0, 1).toUpperCase() + log.split(":")[0].substring(1).toLowerCase()); String[] trees = log.split(":")[1].split(","); int[] rez = new int[trees.length]; for (int i = 0; i < rez.length; i++) rez[i] = Integer.parseInt(trees[i]); return rez; } } return null; } /* * Get axe id's * */ private final int[] getAxeForName(String name) { for (String axe : AXES) { if (axe.startsWith(name.toUpperCase())) { String[] axes = axe.split(":")[1].split(","); int[] rez = new int[axes.length]; for (int i = 0; i < rez.length; i++) rez[i] = Integer.parseInt(axes[i]); return rez; } } return null; } } /* * any other shit here */