tzhaarown Posted June 5, 2015 Share Posted June 5, 2015 http://pastebin.com/0TmpyquE I will implement node structure later. package kfc; import org.osbot.rs07.api.filter.Filter; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.api.model.Player; import org.osbot.rs07.api.util.GraphicUtilities; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import org.osbot.rs07.utility.Condition; import java.awt.*; @ScriptManifest(author = "t", info = "Start at the Falador chicken farm", name = "KFC", logo = "", version = 1.00) public class KFC extends Script { private static final Filter TARGET_FILTER = new Filter<NPC>() { @Override public boolean match(NPC npc) { return npc.getName().equals(Constants.TARGET_NAME) && npc.isAttackable() && Constants.FALADOR_CHICKEN_FARM.contains(npc); } }; private NPC target; private long lastAttack = System.currentTimeMillis(); @Override public int onLoop() throws InterruptedException { final Player player = myPlayer(); if (target == null) { getNewTarget(); } else { if (target.exists() && target.getHealth() > 0 && Constants.FALADOR_CHICKEN_FARM.contains(target)) { if (target.isVisible()) { if (!player.isInteracting(target)) { if (player.isUnderAttack()) { getCurrentTarget(); } else { attack(); } } else if (idle()) { getNewTarget(); } } else { reposition(); } } else { getNewTarget(); } } return random(10, 15); } private boolean idle() { return System.currentTimeMillis() - lastAttack > random((int) (Constants.FAIL_SAFE_TIMEOUT - (Constants.FAIL_SAFE_TIMEOUT * 0.1)), Constants.FAIL_SAFE_TIMEOUT) * 1000; } private void attack() { lastAttack = System.currentTimeMillis(); if (!target.isUnderAttack()) { if (target.interact("Attack")) { dynamicSleep(new Condition() { @Override public boolean evaluate() { return myPlayer().isInteracting(target); } }, random(800, 1000)); } } else { getNewTarget(); } } private void reposition() { camera.toEntity(target); dynamicSleep(new Condition() { @Override public boolean evaluate() { return target.isVisible(); } }, random(4000, 5000)); if (!target.isVisible()) { getLocalWalker().walk(target); dynamicSleep(new Condition() { @Override public boolean evaluate() { return myPlayer().isMoving(); } }, random(4000, 5000)); } } private void getCurrentTarget() { target = npcs.singleFilter(npcs.getAll(), new Filter<NPC>() { @Override public boolean match(NPC npc) { return npc.isInteracting(myPlayer()) && npc.getName().equals(Constants.TARGET_NAME) && Constants.FALADOR_CHICKEN_FARM.contains(npc); } }); } private void getNewTarget() { try { sleep(random(300, 400)); } catch (InterruptedException e) { e.printStackTrace(); } target = npcs.closest(TARGET_FILTER); } public boolean dynamicSleep(Condition c, long timeout) { long start = System.currentTimeMillis(); while (System.currentTimeMillis() - start < timeout && !c.evaluate()) { try { sleep(random(100, 110)); } catch (InterruptedException e) { e.printStackTrace(); } } return c.evaluate(); } @Override public void onPaint(Graphics2D g) { g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (target != null && target.isVisible()) { g.setColor(Color.CYAN); g.draw(GraphicUtilities.getModelArea(this.bot, target.getGridX(), target.getGridY(), target.getZ(), target.getModel())); } } } Quote Link to comment Share on other sites More sharing options...
Apaec Posted June 5, 2015 Share Posted June 5, 2015 package kfc; 2 Quote Link to comment Share on other sites More sharing options...
Alek Posted June 5, 2015 Share Posted June 5, 2015 You might want to look into ConditionalSleep and ConditionalLoop. Glad to see some filter use though. Quote Link to comment Share on other sites More sharing options...