Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Graphics2D;
- import java.util.Arrays;
- import java.util.List;
- import java.util.concurrent.TimeUnit;
- import org.dreambot.api.methods.Calculations;
- import org.dreambot.api.methods.filter.Filter;
- import org.dreambot.api.methods.map.Tile;
- import org.dreambot.api.methods.skills.Skill;
- import org.dreambot.api.script.AbstractScript;
- import org.dreambot.api.script.Category;
- import org.dreambot.api.script.ScriptManifest;
- import org.dreambot.api.utilities.impl.Condition;
- import org.dreambot.api.wrappers.interactive.GameObject;
- import org.dreambot.api.wrappers.interactive.NPC;
- import org.dreambot.api.wrappers.items.GroundItem;
- @ScriptManifest(author = "Rand", name = "EdgeManFighter", version = 1.0, description = "AttacksMenInEdgeville", category = Category.COMBAT)
- public class main extends AbstractScript {
- private String food = "Trout";
- private int foodWithdrawConstant = 1; //starting food to withdraw
- private int lootDistance = 10;
- private boolean lowLevel = false; //set true to bank when out of food, when false bank only when inventory full
- private boolean wantToLoot = true;
- private boolean lootBones = true;
- /////////////////////////////////////////////////////////////////////////////////////////
- int withdrawingFood = foodWithdrawConstant;//these 2 variables used to increase food withdrawn conditionally
- private boolean tooLittleFood; //each time health drops < 10% increase food withdrawn by 1
- private int runEnergy = 0;
- private long timeRan;
- private long timeBegan;
- private long timeFight;
- private int[] beginningXP = new int[4];
- private int[] currentXp = new int[4];
- private int[] xpGained = new int[4];
- private int[] currentLevel = new int[4];
- private int[] beginningLevel = new int[4];
- private int[] levelsGained = new int[4];
- private boolean postIncrementEat = false;
- private boolean lootTurn = true;
- private int[] xpPerHour = new int[4];
- private double[] nextLevelXp = new double[4];
- private double[] xpTillNextLevel = new double[4];
- private long[] tTL = new long[] {0,0,0,0}; //time to level
- private String currentState;
- //20 positions
- private Tile[] outsideHouse = new Tile[] {new Tile(3101, 3511, 0), new Tile(3102, 3511, 0), new Tile(3103, 3511, 0), new Tile(3104, 3511, 0), new Tile(3105, 3511, 0),
- new Tile(3101, 3510, 0), new Tile(3102, 3510, 0), new Tile(3103, 3510, 0), new Tile(3104, 3510, 0), new Tile(3105, 3510, 0),
- new Tile(3101, 3509, 0), new Tile(3102, 3509, 0), new Tile(3103, 3509, 0), new Tile(3104, 3509, 0), new Tile(3105, 3509, 0),
- new Tile(3101, 3508, 0), new Tile(3102, 3508, 0), new Tile(3103, 3508, 0), new Tile(3104, 3508, 0), new Tile(3105, 3508, 0)};
- //20 positions
- private Tile[] bank = new Tile[] {new Tile(3094, 3497, 0), new Tile(3095, 3497, 0), new Tile(3096, 3497, 0), new Tile(3097, 3497, 0), new Tile(3098, 3497, 0),
- new Tile(3094, 3496, 0), new Tile(3095, 3496, 0), new Tile(3096, 3496, 0), new Tile(3097, 3496, 0), new Tile(3098, 3496, 0),
- new Tile(3094, 3495, 0), new Tile(3095, 3495, 0), new Tile(3096, 3495, 0), new Tile(3097, 3495, 0), new Tile(3098, 3495, 0),
- new Tile(3094, 3494, 0), new Tile(3095, 3494, 0), new Tile(3096, 3494, 0), new Tile(3097, 3494, 0), new Tile(3098, 3494, 0)};
- //all positions inside house 1st floor
- private Tile[] insideH = new Tile[] {new Tile(3091, 3512, 0), new Tile(3092, 3512, 0), new Tile(3093, 3512, 0), new Tile(3094, 3512, 0), new Tile(3095, 3512, 0), new Tile(3096, 3512, 0), new Tile(3097, 3512, 0), new Tile(3098, 3512, 0), new Tile(3099, 3512, 0), new Tile(3100, 3512, 0),
- new Tile(3091, 3511, 0), new Tile(3092, 3511, 0), new Tile(3093, 3511, 0), new Tile(3094, 3511, 0), new Tile(3095, 3511, 0), new Tile(3096, 3511, 0), new Tile(3097, 3511, 0), new Tile(3098, 3511, 0), new Tile(3099, 3511, 0), new Tile(3100, 3511, 0),
- new Tile(3091, 3510, 0), new Tile(3092, 3510, 0), new Tile(3093, 3510, 0), new Tile(3094, 3510, 0), new Tile(3095, 3510, 0), new Tile(3096, 3510, 0), new Tile(3097, 3510, 0), new Tile(3098, 3510, 0), new Tile(3099, 3510, 0), new Tile(3100, 3510, 0),
- new Tile(3091, 3509, 0), new Tile(3092, 3509, 0), new Tile(3093, 3509, 0), new Tile(3094, 3509, 0), new Tile(3095, 3509, 0), new Tile(3096, 3509, 0), new Tile(3097, 3509, 0), new Tile(3098, 3509, 0), new Tile(3099, 3509, 0), new Tile(3100, 3509, 0),
- new Tile(3091, 3508, 0), new Tile(3092, 3508, 0), new Tile(3093, 3508, 0), new Tile(3094, 3508, 0), new Tile(3095, 3508, 0), new Tile(3096, 3508, 0), new Tile(3097, 3508, 0), new Tile(3098, 3508, 0), new Tile(3099, 3508, 0), new Tile(3100, 3508, 0),};
- List<Tile> bankLocationsList = Arrays.asList(bank);
- List<Tile> insideHouse = Arrays.asList(insideH);
- final int[] XP_TABLE =
- {
- 0, 0, 83, 174, 276, 388, 512, 650, 801, 969, 1154,
- 1358, 1584, 1833, 2107, 2411, 2746, 3115, 3523, 3973, 4470, 5018,
- 5624, 6291, 7028, 7842, 8740, 9730, 10824, 12031, 13363, 14833,
- 16456, 18247, 20224, 22406, 24815, 27473, 30408, 33648, 37224,
- 41171, 45529, 50339, 55649, 61512, 67983, 75127, 83014, 91721,
- 101333, 111945, 123660, 136594, 150872, 166636, 184040, 203254,
- 224466, 247886, 273742, 302288, 333804, 368599, 407015, 449428,
- 496254, 547953, 605032, 668051, 737627, 814445, 899257, 992895,
- 1096278, 1210421, 1336443, 1475581, 1629200, 1798808, 1986068,
- 2192818, 2421087, 2673114, 2951373, 3258594, 3597792, 3972294,
- 4385776, 4842295, 5346332, 5902831, 6517253, 7195629, 7944614,
- 8771558, 9684577, 10692629, 11805606, 13034431, 200000000
- };
- public void onStart() {
- timeBegan = System.currentTimeMillis();
- timeFight = System.currentTimeMillis();
- beginningXP[0] = getSkills().getExperience(Skill.ATTACK);
- beginningXP[1] = getSkills().getExperience(Skill.STRENGTH);
- beginningXP[2] = getSkills().getExperience(Skill.DEFENCE);
- beginningXP[3] = getSkills().getExperience(Skill.HITPOINTS);
- beginningLevel[0] = getSkills().getRealLevel(Skill.ATTACK);
- beginningLevel[1] = getSkills().getRealLevel(Skill.STRENGTH);
- beginningLevel[2] = getSkills().getRealLevel(Skill.DEFENCE);
- beginningLevel[3] = getSkills().getRealLevel(Skill.HITPOINTS);
- }
- public void onExit() {
- }
- private enum State {
- BANK, EMERGENCY_EAT, EAT, LOOT, LOOT_BONES, FIGHT, WAIT;
- }
- private State getState() //top to bottom order of priority: (run, eatHighRisk, fight&loot, eatLowRisk)
- {
- if ((!getInventory().contains(food) && lowLevel) || getInventory().isFull())
- return State.BANK;
- if (getCombat().getHealthPercent() <= 20) {
- if(getCombat().getHealthPercent() <= 10 && !postIncrementEat) {//prevent doing immediately after incrementing
- tooLittleFood = true; //start withdrawing more food
- lowLevel = true; //start banking when out of food
- }
- return State.EMERGENCY_EAT;
- }
- if (!getLocalPlayer().isInCombat() && getCombat().getHealthPercent() < 50 && getInventory().contains(food))
- return State.EAT;
- if (wantToLoot && lootTurn && !getLocalPlayer().isInCombat() && null != getGroundItems().closest(new Filter<GroundItem>() {
- @Override
- public boolean match (GroundItem target) {
- return (target.getName().equals("Earth rune") || target.getName().equals("Mind rune") ||
- target.getName().equals("Chaos rune") || target.getName().equals("Fire rune") ||
- target.getName().equals("Bronze arrow") || target.getName().equals("Earth Talisman"))
- && getMap().canReach(target) && getInventory().getEmptySlots() >= 1;
- }
- } )) { //end of if statement test
- return State.LOOT;
- }
- if (lootBones && lootTurn && !getLocalPlayer().isInCombat() && null != getGroundItems().closest(new Filter<GroundItem>() {
- @Override
- public boolean match (GroundItem target) {
- return target.getName().equals("Bones") && getMap().canReach(target) && getInventory().getEmptySlots() >= 1;
- }
- })) { //end of if statement test
- return State.LOOT_BONES;
- }
- if (!getLocalPlayer().isInCombat())
- return State.FIGHT;
- return State.WAIT; //default reached if no cases pass
- }
- public int onLoop() {
- //////////////////////////////////////////////////////////////////////////////////////////////////
- runningAntiban();
- if(getLocalPlayer().getZ() == 1) { //is on 2nd floor
- GameObject ladder = getGameObjects().closest("Ladder");
- ladder.interact("Climb-down");
- }
- //hasn't been in fight for 2 minutes
- if((double)(System.currentTimeMillis() - timeFight) > 120 * 1000) {
- antiBanDoor();
- }
- if(getLocalPlayer().isInCombat()) {
- timeFight = System.currentTimeMillis();
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////
- int returnThis = -1;
- State state = getState();
- switch(state) {
- case BANK:
- currentState = "bank";
- goBank();
- returnThis = Calculations.random(500,600);
- break;
- case EMERGENCY_EAT:
- currentState = "Emergency Eat";
- eat(food);
- eat(food);
- returnThis = Calculations.random(500,600);
- break;
- case EAT:
- currentState = "eat";
- eat(food);
- returnThis = Calculations.random(500,600);
- break;
- case LOOT:
- currentState ="looting";
- pickupLoot(1);
- returnThis = Calculations.random(500,600);
- break;
- case LOOT_BONES:
- currentState = "looting bones";
- pickupLoot(2);
- returnThis = Calculations.random(500,600);
- break;
- case FIGHT:
- lootTurn = true;
- currentState = "fight";
- NPC man = getNpcs().closest(new Filter<NPC>() { //finds closest man not in combat that is reachable
- @Override
- public boolean match(NPC npc) {
- return npc != null && npc.getName().equals("Man") && npc.getActions().length > 0 && !npc.isInCombat() && getMap().canReach(npc);
- }
- }); //closing parentheses for filter object that was created
- if (man != null) {
- man.interact("Attack"); //attack closest man that matches filter
- }
- returnThis = Calculations.random(500,600);
- break;
- case WAIT:
- currentState = "wait";
- returnThis = Calculations.random(500,600);
- break;
- }
- return returnThis;
- }
- private void goBank() { //returns true when done banking, otherwise returns false
- timeFight = System.currentTimeMillis();
- if(tooLittleFood) {
- currentState = "increasing food withdraw amt";
- withdrawingFood += 1;
- tooLittleFood = false; //increase food withdrawn by 1 and reset trigger
- postIncrementEat = true; //to eat after withdrawing food
- sleepUntil(new Condition(){
- public boolean verify(){
- return !tooLittleFood;
- }
- },1200);
- }
- if (bankLocationsList.contains(getLocalPlayer().getTile())) {//player is in bank
- if(getBank().isOpen()) {
- getBank().depositAllItems();
- sleepUntil(new Condition(){
- public boolean verify(){
- return getInventory().isEmpty();
- }
- },1200);
- if(getBank().contains(food)) {
- getBank().withdraw(food, withdrawingFood);
- sleepUntil(new Condition() {
- public boolean verify() {
- return getInventory().count(food) == withdrawingFood;
- }
- },1200);
- antiBanDoor();
- if (postIncrementEat) {
- postIncrementEat = false;
- sleepUntil(new Condition() {
- public boolean verify() {
- return !postIncrementEat;
- }
- },1200);
- eat(food);
- eat(food);
- }
- sleep(8000);
- } else {
- getBank().close();
- sleepUntil(new Condition(){ //sleep preferably stop script and log if method exists
- public boolean verify(){
- return false;
- }
- },600000);
- }
- } else {
- getBank().open();
- sleepUntil(new Condition(){
- public boolean verify(){
- return getBank().isOpen();
- }
- },1200);
- }
- } else { //player not in bank
- if (insideHouse.contains(getLocalPlayer().getTile())) { //player inside house
- GameObject door = getGameObjects().closest("Large door");
- if (door != null) {
- currentState = "BankingDoor" + door.getName();
- String[] actions = door.getActions();
- List<String> possibleActions = Arrays.asList(actions);
- if(possibleActions.contains("Open")) { //door is closed
- currentState = "door is closed";
- door.interact("Open");
- sleep(5000);
- }
- }
- }
- getWalking().walk(bank[Calculations.random(20)]);
- sleep(5000);
- }
- }
- public void runningAntiban() {
- if((getWalking().getRunEnergy() > runEnergy) && !getWalking().isRunEnabled()) {
- getWalking().toggleRun();
- runEnergy = Calculations.random(0, 90);
- }
- }
- public void pickupLoot(int lootChoice) {
- lootTurn = false;
- GroundItem loot;
- if(lootChoice == 1) {
- loot = getGroundItems().closest(new Filter<GroundItem>() {
- @Override
- public boolean match (GroundItem target) {
- return (target.getName().equals("Earth rune") || target.getName().equals("Mind rune") ||
- target.getName().equals("Chaos rune") || target.getName().equals("Fire rune") ||
- target.getName().equals("Bronze arrow") || target.getName().equals("Earth Talisman"))
- && getMap().canReach(target) && getInventory().getEmptySlots() >= 1;
- }
- });
- } else {//lootCoice == 2
- loot = getGroundItems().closest(new Filter<GroundItem>() {
- @Override
- public boolean match (GroundItem target) {
- return (target.getName().equals("Bones")) && getMap().canReach(target) && getInventory().getEmptySlots() >= 1;
- }
- });
- }
- if(loot != null) { //valid loot was found by filter
- if (loot.distance(getLocalPlayer().getTile()) < lootDistance) {//loot is close
- if (Calculations.random(2) > 0) { //do 1/2 of the time
- loot.interact("Take");
- } else {
- loot.interactForceRight("Take"); //do 1/2 of the time
- }
- }
- }
- }
- public void eat(String foodToEat) {
- if (foodToEat != null && getInventory().contains(foodToEat)) {
- getInventory().interact(foodToEat, "eat");
- }
- sleep(2000); //3 tics or 1854 milliseconds to eat fish
- }
- public void antiBanDoor() {
- getWalking().walk(outsideHouse[Calculations.random(20)]);
- GameObject door = getGameObjects().closest("Large door");
- if (door != null) {
- currentState = "antibanDoor " + door.getName();
- String[] actions = door.getActions();
- List<String> possibleActions = Arrays.asList(actions);
- if(possibleActions.contains("Open")) { //door is closed
- door.interact("Open");
- sleep(5000);
- }
- }
- timeFight = System.currentTimeMillis();
- }
- public void onPaint(Graphics2D g) {
- currentXp[0] = getSkills().getExperience(Skill.ATTACK);
- currentXp[1] = getSkills().getExperience(Skill.STRENGTH);
- currentXp[2] = getSkills().getExperience(Skill.DEFENCE);
- currentXp[3] = getSkills().getExperience(Skill.HITPOINTS);
- xpGained[0] = currentXp[0] - beginningXP[0];
- xpGained[1] = currentXp[1] - beginningXP[1];
- xpGained[2] = currentXp[2] - beginningXP[2];
- xpGained[3] = currentXp[3] - beginningXP[3];
- xpPerHour[0] = (int)( xpGained[0] / ((System.currentTimeMillis() - this.timeBegan) / 3600000.0D));
- xpPerHour[1] = (int)( xpGained[1] / ((System.currentTimeMillis() - this.timeBegan) / 3600000.0D));
- xpPerHour[2] = (int)( xpGained[2] / ((System.currentTimeMillis() - this.timeBegan) / 3600000.0D));
- xpPerHour[3] = (int)( xpGained[3] / ((System.currentTimeMillis() - this.timeBegan) / 3600000.0D));
- currentLevel[0] = getSkills().getRealLevel(Skill.ATTACK);
- currentLevel[1] = getSkills().getRealLevel(Skill.STRENGTH);
- currentLevel[2] = getSkills().getRealLevel(Skill.DEFENCE);
- currentLevel[3] = getSkills().getRealLevel(Skill.HITPOINTS);
- nextLevelXp[0] = XP_TABLE[currentLevel[0] + 1];
- nextLevelXp[1] = XP_TABLE[currentLevel[1] + 1];
- nextLevelXp[2] = XP_TABLE[currentLevel[2] + 1];
- nextLevelXp[3] = XP_TABLE[currentLevel[3] + 1];
- levelsGained[0] = currentLevel[0] - beginningLevel[0];
- levelsGained[1] = currentLevel[1] - beginningLevel[1];
- levelsGained[2] = currentLevel[2] - beginningLevel[2];
- levelsGained[3] = currentLevel[3] - beginningLevel[3];
- xpTillNextLevel[0] = nextLevelXp[0] - currentXp[0];
- xpTillNextLevel[1] = nextLevelXp[1] - currentXp[1];
- xpTillNextLevel[2] = nextLevelXp[2] - currentXp[2];
- xpTillNextLevel[3] = nextLevelXp[3] - currentXp[3];
- if (xpGained[0] >= 1)
- tTL[0] = (long) ((xpTillNextLevel[0] / xpPerHour[0]) * 3600000);
- if (xpGained[1] >= 1)
- tTL[1] = (long) ((xpTillNextLevel[1] / xpPerHour[1]) * 3600000);
- if (xpGained[2] >= 1)
- tTL[2] = (long) ((xpTillNextLevel[2] / xpPerHour[2]) * 3600000);
- if (xpGained[3] >= 1)
- tTL[3] = (long) ((xpTillNextLevel[3] / xpPerHour[3]) * 3600000);
- //seconds to next level at current rate
- timeRan = System.currentTimeMillis() - this.timeBegan;
- g.drawString(ft(timeRan), 1, 30);
- g.drawString("xp |(xp/hr) |levels gained |time to levelup", 1, 40);
- //xp|(xp/hour)|gained levels|time to next level no idea why math.round returns a long
- g.drawString("Attack: " + xpGained[0] +" (" + xpPerHour[0] + ") " + levelsGained[0] + ", " + ft(tTL[0]), 1, 50);
- g.drawString("Strength: " + xpGained[1] +" (" + xpPerHour[1] + ") " + levelsGained[1] + ", " + ft(tTL[1]), 1, 60);
- g.drawString("Defence: " + xpGained[2] +" (" + xpPerHour[2] + ") " + levelsGained[2] + ", " + ft(tTL[2]), 1, 70);
- g.drawString("Hitpoints: " + xpGained[3] +" (" + xpPerHour[3] + ") " + levelsGained[3] + ", " + ft(tTL[3]), 1, 80);
- g.drawString(currentState, 1, 100);
- }
- //return a string of time from milliseconds
- private String ft(long duration) {
- String min;
- String sec;
- String hr;
- long days = TimeUnit.MILLISECONDS.toDays(duration);
- long hours = TimeUnit.MILLISECONDS.toHours(duration)
- - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration));
- long minutes = TimeUnit.MILLISECONDS.toMinutes(duration)
- - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS
- .toHours(duration));
- long seconds = TimeUnit.MILLISECONDS.toSeconds(duration)
- - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS
- .toMinutes(duration));
- if(days > 365) {
- return "> 365 days";
- }
- if(hours < 10) {
- hr = "0" + hours;
- } else {
- hr = "" + hours;
- }
- if(minutes < 10) {
- min = "0" + minutes;
- } else {
- min = "" + minutes;
- }
- if(seconds < 10) {
- sec = "0" + seconds;
- } else {
- sec = "" + seconds;
- }
- if (days == 0) {
- if (hours == 0) { //show minutes + seconds
- return (min + ":" + sec);
- } else // show hours
- return (hr + ":" + min + ":" + sec);
- } else { //show days
- return (days + ":" + hr + ":" + min + ":" + sec);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement