Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package DustDevil;
- import com.kbotpro.scriptsystem.events.PaintEventListener;
- import com.kbotpro.scriptsystem.events.ServerMessageListener;
- import com.kbotpro.scriptsystem.fetch.Game;
- import com.kbotpro.scriptsystem.fetch.Interfaces;
- import com.kbotpro.scriptsystem.fetch.Skills;
- import com.kbotpro.scriptsystem.interfaces.Looped;
- import com.kbotpro.scriptsystem.runnable.Script;
- import com.kbotpro.scriptsystem.various.KTimer;
- import com.kbotpro.scriptsystem.wrappers.*;
- import com.kbotpro.scriptsystem.wrappers.Character;
- import java.awt.*;
- import java.util.ArrayList;
- /**
- * Created by IntelliJ IDEA.
- * User: Brian Vartan
- * Date: May 1, 2010
- * Time: 5:11:53 PM
- * To change this template use File | Settings | File Templates.
- */
- public class DustDevil extends Script implements PaintEventListener, ServerMessageListener {
- public void onRepaint(Graphics graphics) {
- //To change body of implemented methods use File | Settings | File Templates.
- }
- public void onServerMessage(String s) {
- //To change body of implemented methods use File | Settings | File Templates.
- }
- final int BONE = 526;
- final int PEACH = 6883;
- final int KEBAB = 1885;
- final int B2P = 8015;
- final int[] DUST_DEVIL = {1624};
- final int[] FOOD_IDS = {KEBAB, PEACH};
- final int[] CHARM = {12158,12159,12160,12163};
- final int DRAGON_CHAIN = 3140;
- final int[] ITEMS = {DRAGON_CHAIN, CHARM[0],CHARM[1],CHARM[2],CHARM[3], KEBAB};
- final String[] ITEM_NAMES = {"charm", "kebab"};
- MTimer failSafe;
- MTimer combat;
- @Override
- public void registerWorkers() {
- createWorker(new Looped() {
- public int loop() {
- try{
- game.openTab(Game.TAB_INVENTORY);
- if(failSafe.isDone()) {
- log("Failsafe activated. logging out");
- game.exitGame();
- return -1;
- }
- if(menu.isOpen())
- menu.atMenu("Cancel");
- int hp = hp();
- if(!inventory.contains(FOOD_IDS)) {
- if(!inventory.contains(BONE) || !inventory.contains(B2P)) {
- game.exitGame();
- return -1;
- }
- if(inventory.isFull() || (hp!=-1 && hp<500))
- inventory.atItem(B2P, "Break");
- sleep(random(4000,5000));
- }
- if(getMyPlayer().isMoving())
- return random(50,100);
- if(!combat()) {
- GroundItem[] pickup = groundItems.getItems(10,ITEMS);
- for (GroundItem loot : pickup) {
- boolean pick = shouldPickup(loot, false);
- if (pick) {
- Point p = loot.getScreenPos();
- if(!calculations.isInGameArea(p)) {
- camera.setAngleTo(loot.getLocation());
- p = loot.getScreenPos();
- if(!calculations.isInGameArea(p)) {
- walking.walkPath(fixPath(loot.getLocation()));
- p = loot.getScreenPos();
- }
- }
- if(!calculations.isInGameArea(p)) {
- return random(50,100);
- }
- mouse.moveMouse(p);
- for (String mi : menu.getMenuItems())
- for (String in : ITEM_NAMES)
- if (mi.contains(in)) {
- menu.atMenu(in);
- return random(200, 300);
- }
- }
- return random(50,100);
- }
- if(inventory.isFull() || eat(false)) {
- GroundItem bone = groundItems.getClosestItem(3, BONE);
- if(bone!=null)
- if(shouldPickup(bone,true))
- if(bone.doAction("Take Bone"))
- return random(300,400);
- }
- if(!combat.isDone())
- return random(50,100);
- NPC monster = npcs.getClosestFree(15,DUST_DEVIL);
- if(monster.doAction("Attack Dust devil")) {
- failSafe.reset();
- return random(1000,1500);
- }
- camera.setAngleTo(monster.getLocation());
- if(monster.doAction("Attack Dust devil")) {
- failSafe.reset();
- return random(1000,1500);
- }
- walking.walkPath(fixPath(monster.getLocation()));
- if(monster.doAction("Attack Dust devil")) {
- failSafe.reset();
- return random(1000,1500);
- }
- return random(50,100);
- } else {
- combat.reset();
- eat(true);
- return random(50,100);
- }
- } catch(Exception e) {
- e.printStackTrace();
- }
- return random(50,100);
- }//To change body of implemented methods use File | Settings | File Templates.
- });
- }
- public int getHeal(int i) {
- if(i==PEACH)
- return 80;
- if(i==KEBAB)
- return 190;
- return 999999;
- }
- public int hp() {
- try {
- IComponent hpi = interfaces.getComponent(748,8);
- return Integer.parseInt(hpi.getText());
- } catch(Exception e) {
- e.printStackTrace();
- }
- return -1;
- }
- public boolean eat(boolean combat) {
- try {
- int hp = hp();
- if(hp==-1)
- return false;
- int starting = hp;
- int max = 10*skills.getCurrentLevel(Skills.SKILL_HITPOINTS)-random(random(random(50,100),100),100);
- boolean eat=false;
- if(hp<400 && combat)
- eat=true;
- if(!combat && hp+80<max)
- eat=true;
- if(eat) {
- Item[] items = inventory.getItems(FOOD_IDS);
- if(items.length==0)
- return false;
- for(Item item : items) {
- int heal = getHeal(item.getID());
- if(hp+heal<=max) {
- item.doAction("Eat");
- hp+=heal;
- sleep(random(1200,1300));
- }
- }
- }
- if(hp()!=starting)
- return true;
- } catch(Exception e) {
- e.printStackTrace();
- }
- return false;
- }
- public Tile[] fixPath(Tile t) {
- int startX = getMyPlayer().getLocation().getX();
- int startY = getMyPlayer().getLocation().getY();
- int destinationX = t.getX();
- int destinationY = t.getY();
- double dx, dy;
- ArrayList<Tile> list = new ArrayList<Tile>();
- list.add(new Tile(startX, startY));
- while (Math.hypot(destinationY - startY, destinationX - startX) > 8) {
- dx = destinationX - startX;
- dy = destinationY - startY;
- int gamble = random(14, 17);
- while (Math.hypot(dx, dy) > gamble) {
- dx *= .95;
- dy *= .95;
- }
- startX += (int) dx;
- startY += (int) dy;
- list.add(new Tile(startX, startY));
- }
- list.add(new Tile(destinationX, destinationY));
- return list.toArray(new Tile[list.size()]);
- }
- public boolean combat() {
- try {
- Player p = getMyPlayer();
- Character c = p.getInteracting();
- if(c==null)
- return false;
- Character d = c.getInteracting();
- if(d!=null || d.getModel()==p.getModel())
- return true;
- }catch(Exception e) {
- e.printStackTrace();
- }
- return false;
- }
- public boolean shouldPickup(GroundItem loot, boolean bone) {
- int id = loot.getID();
- if(inventory.getCount(true,id)>1 && inventory.getItems(id)[0].getStackSize()>1) {
- return true;
- }
- if(inventory.isFull() && eat(false))
- sleep(random(1000,1200));
- if(inventory.isFull()) {
- if(!bone && inventory.contains(BONE)) {
- inventory.atItem(BONE, "Drop Bone");
- return true;
- } else
- return false;
- }
- return !inventory.isFull();
- }
- @Override
- public void stop() {
- //To change body of implemented methods use File | Settings | File Templates.
- }
- @Override
- public void onStart() {
- game.openTab(Game.TAB_INVENTORY);
- failSafe = new MTimer(300000);
- combat = new MTimer(3000);
- //To change body of implemented methods use File | Settings | File Templates.
- }
- @Override
- public String getName() {
- return "Dust Devil"; //To change body of implemented methods use File | Settings | File Templates.
- }
- class MTimer {
- long time = 0;
- long start = 0;
- public MTimer(long ms) {
- start = System.currentTimeMillis();
- time=ms;
- }
- public boolean isDone() {
- return start+time<System.currentTimeMillis();
- }
- public void reset() {
- start = System.currentTimeMillis();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement