Advertisement
randalthor7

Dreambot - EdgevilleManFighter 7

Aug 26th, 2015
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.71 KB | None | 0 0
  1. import java.awt.Graphics2D;
  2. import java.util.Arrays;
  3. import java.util.List;
  4. import java.util.concurrent.TimeUnit;
  5.  
  6. import org.dreambot.api.methods.Calculations;
  7. import org.dreambot.api.methods.filter.Filter;
  8. import org.dreambot.api.methods.map.Tile;
  9. import org.dreambot.api.methods.skills.Skill;
  10. import org.dreambot.api.script.AbstractScript;
  11. import org.dreambot.api.script.Category;
  12. import org.dreambot.api.script.ScriptManifest;
  13. import org.dreambot.api.utilities.impl.Condition;
  14. import org.dreambot.api.wrappers.interactive.GameObject;
  15. import org.dreambot.api.wrappers.interactive.NPC;
  16. import org.dreambot.api.wrappers.items.GroundItem;
  17.  
  18. @ScriptManifest(author = "Rand", name = "EdgeManFighter", version = 1.0, description = "AttacksMenInEdgeville", category = Category.COMBAT)
  19. public class main extends AbstractScript {
  20. private String food = "Trout";
  21. private int foodWithdrawConstant = 1; //starting food to withdraw
  22. private int lootDistance = 10;
  23. private boolean lowLevel = false; //set true to bank when out of food, when false bank only when inventory full
  24. private boolean wantToLoot = true;
  25. private boolean lootBones = true;
  26. /////////////////////////////////////////////////////////////////////////////////////////
  27. int withdrawingFood = foodWithdrawConstant;//these 2 variables used to increase food withdrawn conditionally
  28. private boolean tooLittleFood; //each time health drops < 10% increase food withdrawn by 1
  29. private int runEnergy = 0;
  30. private long timeRan;
  31. private long timeBegan;
  32. private long timeFight;
  33. private int[] beginningXP = new int[4];
  34. private int[] currentXp = new int[4];
  35. private int[] xpGained = new int[4];
  36. private int[] currentLevel = new int[4];
  37. private int[] beginningLevel = new int[4];
  38. private int[] levelsGained = new int[4];
  39. private boolean postIncrementEat = false;
  40. private boolean lootTurn = true;
  41. private int[] xpPerHour = new int[4];
  42. private double[] nextLevelXp = new double[4];
  43. private double[] xpTillNextLevel = new double[4];
  44. private long[] tTL = new long[] {0,0,0,0}; //time to level
  45. private String currentState;
  46. //20 positions
  47. 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),
  48. 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),
  49. 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),
  50. 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)};
  51. //20 positions
  52. 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),
  53. 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),
  54. 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),
  55. 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)};
  56. //all positions inside house 1st floor
  57. 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),
  58. 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),
  59. 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),
  60. 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),
  61. 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),};
  62. List<Tile> bankLocationsList = Arrays.asList(bank);
  63. List<Tile> insideHouse = Arrays.asList(insideH);
  64. final int[] XP_TABLE =
  65. {
  66. 0, 0, 83, 174, 276, 388, 512, 650, 801, 969, 1154,
  67. 1358, 1584, 1833, 2107, 2411, 2746, 3115, 3523, 3973, 4470, 5018,
  68. 5624, 6291, 7028, 7842, 8740, 9730, 10824, 12031, 13363, 14833,
  69. 16456, 18247, 20224, 22406, 24815, 27473, 30408, 33648, 37224,
  70. 41171, 45529, 50339, 55649, 61512, 67983, 75127, 83014, 91721,
  71. 101333, 111945, 123660, 136594, 150872, 166636, 184040, 203254,
  72. 224466, 247886, 273742, 302288, 333804, 368599, 407015, 449428,
  73. 496254, 547953, 605032, 668051, 737627, 814445, 899257, 992895,
  74. 1096278, 1210421, 1336443, 1475581, 1629200, 1798808, 1986068,
  75. 2192818, 2421087, 2673114, 2951373, 3258594, 3597792, 3972294,
  76. 4385776, 4842295, 5346332, 5902831, 6517253, 7195629, 7944614,
  77. 8771558, 9684577, 10692629, 11805606, 13034431, 200000000
  78. };
  79.  
  80. public void onStart() {
  81. timeBegan = System.currentTimeMillis();
  82. timeFight = System.currentTimeMillis();
  83. beginningXP[0] = getSkills().getExperience(Skill.ATTACK);
  84. beginningXP[1] = getSkills().getExperience(Skill.STRENGTH);
  85. beginningXP[2] = getSkills().getExperience(Skill.DEFENCE);
  86. beginningXP[3] = getSkills().getExperience(Skill.HITPOINTS);
  87. beginningLevel[0] = getSkills().getRealLevel(Skill.ATTACK);
  88. beginningLevel[1] = getSkills().getRealLevel(Skill.STRENGTH);
  89. beginningLevel[2] = getSkills().getRealLevel(Skill.DEFENCE);
  90. beginningLevel[3] = getSkills().getRealLevel(Skill.HITPOINTS);
  91. }
  92.  
  93. public void onExit() {
  94. }
  95.  
  96. private enum State {
  97. BANK, EMERGENCY_EAT, EAT, LOOT, LOOT_BONES, FIGHT, WAIT;
  98. }
  99.  
  100. private State getState() //top to bottom order of priority: (run, eatHighRisk, fight&loot, eatLowRisk)
  101. {
  102. if ((!getInventory().contains(food) && lowLevel) || getInventory().isFull())
  103. return State.BANK;
  104. if (getCombat().getHealthPercent() <= 20) {
  105. if(getCombat().getHealthPercent() <= 10 && !postIncrementEat) {//prevent doing immediately after incrementing
  106. tooLittleFood = true; //start withdrawing more food
  107. lowLevel = true; //start banking when out of food
  108. }
  109. return State.EMERGENCY_EAT;
  110. }
  111. if (!getLocalPlayer().isInCombat() && getCombat().getHealthPercent() < 50 && getInventory().contains(food))
  112. return State.EAT;
  113. if (wantToLoot && lootTurn && !getLocalPlayer().isInCombat() && null != getGroundItems().closest(new Filter<GroundItem>() {
  114. @Override
  115. public boolean match (GroundItem target) {
  116. return (target.getName().equals("Earth rune") || target.getName().equals("Mind rune") ||
  117. target.getName().equals("Chaos rune") || target.getName().equals("Fire rune") ||
  118. target.getName().equals("Bronze arrow") || target.getName().equals("Earth Talisman"))
  119. && getMap().canReach(target) && getInventory().getEmptySlots() >= 1;
  120. }
  121. } )) { //end of if statement test
  122. return State.LOOT;
  123. }
  124.  
  125. if (lootBones && lootTurn && !getLocalPlayer().isInCombat() && null != getGroundItems().closest(new Filter<GroundItem>() {
  126. @Override
  127. public boolean match (GroundItem target) {
  128. return target.getName().equals("Bones") && getMap().canReach(target) && getInventory().getEmptySlots() >= 1;
  129. }
  130. })) { //end of if statement test
  131. return State.LOOT_BONES;
  132. }
  133. if (!getLocalPlayer().isInCombat())
  134. return State.FIGHT;
  135. return State.WAIT; //default reached if no cases pass
  136. }
  137.  
  138. public int onLoop() {
  139. //////////////////////////////////////////////////////////////////////////////////////////////////
  140. runningAntiban();
  141. if(getLocalPlayer().getZ() == 1) { //is on 2nd floor
  142. GameObject ladder = getGameObjects().closest("Ladder");
  143. ladder.interact("Climb-down");
  144. }
  145. //hasn't been in fight for 2 minutes
  146. if((double)(System.currentTimeMillis() - timeFight) > 120 * 1000) {
  147. antiBanDoor();
  148. }
  149.  
  150. if(getLocalPlayer().isInCombat()) {
  151. timeFight = System.currentTimeMillis();
  152. }
  153. //////////////////////////////////////////////////////////////////////////////////////////////////
  154. int returnThis = -1;
  155. State state = getState();
  156. switch(state) {
  157. case BANK:
  158. currentState = "bank";
  159. goBank();
  160. returnThis = Calculations.random(500,600);
  161. break;
  162. case EMERGENCY_EAT:
  163. currentState = "Emergency Eat";
  164. eat(food);
  165. eat(food);
  166. returnThis = Calculations.random(500,600);
  167. break;
  168. case EAT:
  169. currentState = "eat";
  170. eat(food);
  171. returnThis = Calculations.random(500,600);
  172. break;
  173. case LOOT:
  174. currentState ="looting";
  175. pickupLoot(1);
  176. returnThis = Calculations.random(500,600);
  177. break;
  178. case LOOT_BONES:
  179. currentState = "looting bones";
  180. pickupLoot(2);
  181. returnThis = Calculations.random(500,600);
  182. break;
  183. case FIGHT:
  184. lootTurn = true;
  185. currentState = "fight";
  186. NPC man = getNpcs().closest(new Filter<NPC>() { //finds closest man not in combat that is reachable
  187. @Override
  188. public boolean match(NPC npc) {
  189. return npc != null && npc.getName().equals("Man") && npc.getActions().length > 0 && !npc.isInCombat() && getMap().canReach(npc);
  190. }
  191. }); //closing parentheses for filter object that was created
  192. if (man != null) {
  193. man.interact("Attack"); //attack closest man that matches filter
  194. }
  195. returnThis = Calculations.random(500,600);
  196. break;
  197. case WAIT:
  198. currentState = "wait";
  199. returnThis = Calculations.random(500,600);
  200. break;
  201. }
  202. return returnThis;
  203. }
  204.  
  205. private void goBank() { //returns true when done banking, otherwise returns false
  206. timeFight = System.currentTimeMillis();
  207. if(tooLittleFood) {
  208. currentState = "increasing food withdraw amt";
  209. withdrawingFood += 1;
  210. tooLittleFood = false; //increase food withdrawn by 1 and reset trigger
  211. postIncrementEat = true; //to eat after withdrawing food
  212. sleepUntil(new Condition(){
  213. public boolean verify(){
  214. return !tooLittleFood;
  215. }
  216. },1200);
  217. }
  218. if (bankLocationsList.contains(getLocalPlayer().getTile())) {//player is in bank
  219. if(getBank().isOpen()) {
  220. getBank().depositAllItems();
  221. sleepUntil(new Condition(){
  222. public boolean verify(){
  223. return getInventory().isEmpty();
  224. }
  225. },1200);
  226. if(getBank().contains(food)) {
  227. getBank().withdraw(food, withdrawingFood);
  228. sleepUntil(new Condition() {
  229. public boolean verify() {
  230. return getInventory().count(food) == withdrawingFood;
  231. }
  232. },1200);
  233. antiBanDoor();
  234. if (postIncrementEat) {
  235. postIncrementEat = false;
  236. sleepUntil(new Condition() {
  237. public boolean verify() {
  238. return !postIncrementEat;
  239. }
  240. },1200);
  241. eat(food);
  242. eat(food);
  243. }
  244. sleep(8000);
  245. } else {
  246. getBank().close();
  247. sleepUntil(new Condition(){ //sleep preferably stop script and log if method exists
  248. public boolean verify(){
  249. return false;
  250. }
  251. },600000);
  252. }
  253. } else {
  254. getBank().open();
  255. sleepUntil(new Condition(){
  256. public boolean verify(){
  257. return getBank().isOpen();
  258. }
  259. },1200);
  260. }
  261. } else { //player not in bank
  262. if (insideHouse.contains(getLocalPlayer().getTile())) { //player inside house
  263. GameObject door = getGameObjects().closest("Large door");
  264. if (door != null) {
  265. currentState = "BankingDoor" + door.getName();
  266. String[] actions = door.getActions();
  267. List<String> possibleActions = Arrays.asList(actions);
  268. if(possibleActions.contains("Open")) { //door is closed
  269. currentState = "door is closed";
  270. door.interact("Open");
  271. sleep(5000);
  272. }
  273. }
  274. }
  275. getWalking().walk(bank[Calculations.random(20)]);
  276. sleep(5000);
  277. }
  278. }
  279.  
  280. public void runningAntiban() {
  281. if((getWalking().getRunEnergy() > runEnergy) && !getWalking().isRunEnabled()) {
  282. getWalking().toggleRun();
  283. runEnergy = Calculations.random(0, 90);
  284. }
  285. }
  286.  
  287. public void pickupLoot(int lootChoice) {
  288. lootTurn = false;
  289. GroundItem loot;
  290. if(lootChoice == 1) {
  291. loot = getGroundItems().closest(new Filter<GroundItem>() {
  292. @Override
  293. public boolean match (GroundItem target) {
  294. return (target.getName().equals("Earth rune") || target.getName().equals("Mind rune") ||
  295. target.getName().equals("Chaos rune") || target.getName().equals("Fire rune") ||
  296. target.getName().equals("Bronze arrow") || target.getName().equals("Earth Talisman"))
  297. && getMap().canReach(target) && getInventory().getEmptySlots() >= 1;
  298. }
  299. });
  300. } else {//lootCoice == 2
  301. loot = getGroundItems().closest(new Filter<GroundItem>() {
  302. @Override
  303. public boolean match (GroundItem target) {
  304. return (target.getName().equals("Bones")) && getMap().canReach(target) && getInventory().getEmptySlots() >= 1;
  305. }
  306. });
  307. }
  308. if(loot != null) { //valid loot was found by filter
  309. if (loot.distance(getLocalPlayer().getTile()) < lootDistance) {//loot is close
  310. if (Calculations.random(2) > 0) { //do 1/2 of the time
  311. loot.interact("Take");
  312. } else {
  313. loot.interactForceRight("Take"); //do 1/2 of the time
  314. }
  315. }
  316. }
  317. }
  318.  
  319. public void eat(String foodToEat) {
  320. if (foodToEat != null && getInventory().contains(foodToEat)) {
  321. getInventory().interact(foodToEat, "eat");
  322. }
  323. sleep(2000); //3 tics or 1854 milliseconds to eat fish
  324. }
  325.  
  326. public void antiBanDoor() {
  327. getWalking().walk(outsideHouse[Calculations.random(20)]);
  328. GameObject door = getGameObjects().closest("Large door");
  329. if (door != null) {
  330. currentState = "antibanDoor " + door.getName();
  331. String[] actions = door.getActions();
  332. List<String> possibleActions = Arrays.asList(actions);
  333. if(possibleActions.contains("Open")) { //door is closed
  334. door.interact("Open");
  335. sleep(5000);
  336. }
  337. }
  338. timeFight = System.currentTimeMillis();
  339. }
  340.  
  341. public void onPaint(Graphics2D g) {
  342. currentXp[0] = getSkills().getExperience(Skill.ATTACK);
  343. currentXp[1] = getSkills().getExperience(Skill.STRENGTH);
  344. currentXp[2] = getSkills().getExperience(Skill.DEFENCE);
  345. currentXp[3] = getSkills().getExperience(Skill.HITPOINTS);
  346. xpGained[0] = currentXp[0] - beginningXP[0];
  347. xpGained[1] = currentXp[1] - beginningXP[1];
  348. xpGained[2] = currentXp[2] - beginningXP[2];
  349. xpGained[3] = currentXp[3] - beginningXP[3];
  350. xpPerHour[0] = (int)( xpGained[0] / ((System.currentTimeMillis() - this.timeBegan) / 3600000.0D));
  351. xpPerHour[1] = (int)( xpGained[1] / ((System.currentTimeMillis() - this.timeBegan) / 3600000.0D));
  352. xpPerHour[2] = (int)( xpGained[2] / ((System.currentTimeMillis() - this.timeBegan) / 3600000.0D));
  353. xpPerHour[3] = (int)( xpGained[3] / ((System.currentTimeMillis() - this.timeBegan) / 3600000.0D));
  354. currentLevel[0] = getSkills().getRealLevel(Skill.ATTACK);
  355. currentLevel[1] = getSkills().getRealLevel(Skill.STRENGTH);
  356. currentLevel[2] = getSkills().getRealLevel(Skill.DEFENCE);
  357. currentLevel[3] = getSkills().getRealLevel(Skill.HITPOINTS);
  358. nextLevelXp[0] = XP_TABLE[currentLevel[0] + 1];
  359. nextLevelXp[1] = XP_TABLE[currentLevel[1] + 1];
  360. nextLevelXp[2] = XP_TABLE[currentLevel[2] + 1];
  361. nextLevelXp[3] = XP_TABLE[currentLevel[3] + 1];
  362. levelsGained[0] = currentLevel[0] - beginningLevel[0];
  363. levelsGained[1] = currentLevel[1] - beginningLevel[1];
  364. levelsGained[2] = currentLevel[2] - beginningLevel[2];
  365. levelsGained[3] = currentLevel[3] - beginningLevel[3];
  366. xpTillNextLevel[0] = nextLevelXp[0] - currentXp[0];
  367. xpTillNextLevel[1] = nextLevelXp[1] - currentXp[1];
  368. xpTillNextLevel[2] = nextLevelXp[2] - currentXp[2];
  369. xpTillNextLevel[3] = nextLevelXp[3] - currentXp[3];
  370. if (xpGained[0] >= 1)
  371. tTL[0] = (long) ((xpTillNextLevel[0] / xpPerHour[0]) * 3600000);
  372. if (xpGained[1] >= 1)
  373. tTL[1] = (long) ((xpTillNextLevel[1] / xpPerHour[1]) * 3600000);
  374. if (xpGained[2] >= 1)
  375. tTL[2] = (long) ((xpTillNextLevel[2] / xpPerHour[2]) * 3600000);
  376. if (xpGained[3] >= 1)
  377. tTL[3] = (long) ((xpTillNextLevel[3] / xpPerHour[3]) * 3600000);
  378. //seconds to next level at current rate
  379. timeRan = System.currentTimeMillis() - this.timeBegan;
  380. g.drawString(ft(timeRan), 1, 30);
  381. g.drawString("xp |(xp/hr) |levels gained |time to levelup", 1, 40);
  382. //xp|(xp/hour)|gained levels|time to next level no idea why math.round returns a long
  383. g.drawString("Attack: " + xpGained[0] +" (" + xpPerHour[0] + ") " + levelsGained[0] + ", " + ft(tTL[0]), 1, 50);
  384. g.drawString("Strength: " + xpGained[1] +" (" + xpPerHour[1] + ") " + levelsGained[1] + ", " + ft(tTL[1]), 1, 60);
  385. g.drawString("Defence: " + xpGained[2] +" (" + xpPerHour[2] + ") " + levelsGained[2] + ", " + ft(tTL[2]), 1, 70);
  386. g.drawString("Hitpoints: " + xpGained[3] +" (" + xpPerHour[3] + ") " + levelsGained[3] + ", " + ft(tTL[3]), 1, 80);
  387. g.drawString(currentState, 1, 100);
  388. }
  389.  
  390. //return a string of time from milliseconds
  391. private String ft(long duration) {
  392. String min;
  393. String sec;
  394. String hr;
  395. long days = TimeUnit.MILLISECONDS.toDays(duration);
  396. long hours = TimeUnit.MILLISECONDS.toHours(duration)
  397. - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration));
  398. long minutes = TimeUnit.MILLISECONDS.toMinutes(duration)
  399. - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS
  400. .toHours(duration));
  401. long seconds = TimeUnit.MILLISECONDS.toSeconds(duration)
  402. - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS
  403. .toMinutes(duration));
  404. if(days > 365) {
  405. return "> 365 days";
  406. }
  407. if(hours < 10) {
  408. hr = "0" + hours;
  409. } else {
  410. hr = "" + hours;
  411. }
  412. if(minutes < 10) {
  413. min = "0" + minutes;
  414. } else {
  415. min = "" + minutes;
  416. }
  417. if(seconds < 10) {
  418. sec = "0" + seconds;
  419. } else {
  420. sec = "" + seconds;
  421. }
  422.  
  423. if (days == 0) {
  424. if (hours == 0) { //show minutes + seconds
  425. return (min + ":" + sec);
  426. } else // show hours
  427. return (hr + ":" + min + ":" + sec);
  428. } else { //show days
  429. return (days + ":" + hr + ":" + min + ":" + sec);
  430. }
  431. }
  432. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement