Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.69 KB | None | 0 0
  1. package DustDevil;
  2.  
  3. import com.kbotpro.scriptsystem.events.PaintEventListener;
  4. import com.kbotpro.scriptsystem.events.ServerMessageListener;
  5. import com.kbotpro.scriptsystem.fetch.Game;
  6. import com.kbotpro.scriptsystem.fetch.Interfaces;
  7. import com.kbotpro.scriptsystem.fetch.Skills;
  8. import com.kbotpro.scriptsystem.interfaces.Looped;
  9. import com.kbotpro.scriptsystem.runnable.Script;
  10. import com.kbotpro.scriptsystem.various.KTimer;
  11. import com.kbotpro.scriptsystem.wrappers.*;
  12. import com.kbotpro.scriptsystem.wrappers.Character;
  13.  
  14. import java.awt.*;
  15. import java.util.ArrayList;
  16.  
  17. /**
  18. * Created by IntelliJ IDEA.
  19. * User: Brian Vartan
  20. * Date: May 1, 2010
  21. * Time: 5:11:53 PM
  22. * To change this template use File | Settings | File Templates.
  23. */
  24. public class DustDevil extends Script implements PaintEventListener, ServerMessageListener {
  25.  
  26. public void onRepaint(Graphics graphics) {
  27. //To change body of implemented methods use File | Settings | File Templates.
  28. }
  29.  
  30. public void onServerMessage(String s) {
  31. //To change body of implemented methods use File | Settings | File Templates.
  32. }
  33.  
  34. final int BONE = 526;
  35. final int PEACH = 6883;
  36. final int KEBAB = 1885;
  37. final int B2P = 8015;
  38. final int[] DUST_DEVIL = {1624};
  39. final int[] FOOD_IDS = {KEBAB, PEACH};
  40. final int[] CHARM = {12158,12159,12160,12163};
  41. final int DRAGON_CHAIN = 3140;
  42. final int[] ITEMS = {DRAGON_CHAIN, CHARM[0],CHARM[1],CHARM[2],CHARM[3], KEBAB};
  43. final String[] ITEM_NAMES = {"charm", "kebab"};
  44. MTimer failSafe;
  45. MTimer combat;
  46. @Override
  47. public void registerWorkers() {
  48. createWorker(new Looped() {
  49. public int loop() {
  50. try{
  51.  
  52. game.openTab(Game.TAB_INVENTORY);
  53.  
  54. if(failSafe.isDone()) {
  55. log("Failsafe activated. logging out");
  56. game.exitGame();
  57. return -1;
  58. }
  59. if(menu.isOpen())
  60. menu.atMenu("Cancel");
  61. int hp = hp();
  62. if(!inventory.contains(FOOD_IDS)) {
  63.  
  64. if(!inventory.contains(BONE) || !inventory.contains(B2P)) {
  65. game.exitGame();
  66. return -1;
  67. }
  68. if(inventory.isFull() || (hp!=-1 && hp<500))
  69. inventory.atItem(B2P, "Break");
  70. sleep(random(4000,5000));
  71. }
  72. if(getMyPlayer().isMoving())
  73. return random(50,100);
  74. if(!combat()) {
  75. GroundItem[] pickup = groundItems.getItems(10,ITEMS);
  76. for (GroundItem loot : pickup) {
  77. boolean pick = shouldPickup(loot, false);
  78.  
  79. if (pick) {
  80. Point p = loot.getScreenPos();
  81. if(!calculations.isInGameArea(p)) {
  82. camera.setAngleTo(loot.getLocation());
  83. p = loot.getScreenPos();
  84. if(!calculations.isInGameArea(p)) {
  85. walking.walkPath(fixPath(loot.getLocation()));
  86. p = loot.getScreenPos();
  87. }
  88. }
  89. if(!calculations.isInGameArea(p)) {
  90. return random(50,100);
  91. }
  92. mouse.moveMouse(p);
  93. for (String mi : menu.getMenuItems())
  94. for (String in : ITEM_NAMES)
  95. if (mi.contains(in)) {
  96. menu.atMenu(in);
  97. return random(200, 300);
  98. }
  99. }
  100. return random(50,100);
  101.  
  102. }
  103. if(inventory.isFull() || eat(false)) {
  104. GroundItem bone = groundItems.getClosestItem(3, BONE);
  105. if(bone!=null)
  106. if(shouldPickup(bone,true))
  107. if(bone.doAction("Take Bone"))
  108. return random(300,400);
  109.  
  110. }
  111. if(!combat.isDone())
  112. return random(50,100);
  113. NPC monster = npcs.getClosestFree(15,DUST_DEVIL);
  114. if(monster.doAction("Attack Dust devil")) {
  115. failSafe.reset();
  116. return random(1000,1500);
  117. }
  118. camera.setAngleTo(monster.getLocation());
  119. if(monster.doAction("Attack Dust devil")) {
  120. failSafe.reset();
  121.  
  122. return random(1000,1500);
  123. }
  124. walking.walkPath(fixPath(monster.getLocation()));
  125. if(monster.doAction("Attack Dust devil")) {
  126. failSafe.reset();
  127. return random(1000,1500);
  128. }
  129.  
  130. return random(50,100);
  131. } else {
  132.  
  133. combat.reset();
  134. eat(true);
  135. return random(50,100);
  136. }
  137. } catch(Exception e) {
  138. e.printStackTrace();
  139. }
  140. return random(50,100);
  141. }//To change body of implemented methods use File | Settings | File Templates.
  142. });
  143. }
  144. public int getHeal(int i) {
  145. if(i==PEACH)
  146. return 80;
  147. if(i==KEBAB)
  148. return 190;
  149. return 999999;
  150. }
  151. public int hp() {
  152. try {
  153. IComponent hpi = interfaces.getComponent(748,8);
  154. return Integer.parseInt(hpi.getText());
  155. } catch(Exception e) {
  156. e.printStackTrace();
  157. }
  158. return -1;
  159.  
  160. }
  161. public boolean eat(boolean combat) {
  162.  
  163. try {
  164. int hp = hp();
  165. if(hp==-1)
  166. return false;
  167. int starting = hp;
  168. int max = 10*skills.getCurrentLevel(Skills.SKILL_HITPOINTS)-random(random(random(50,100),100),100);
  169. boolean eat=false;
  170. if(hp<400 && combat)
  171. eat=true;
  172. if(!combat && hp+80<max)
  173. eat=true;
  174. if(eat) {
  175. Item[] items = inventory.getItems(FOOD_IDS);
  176. if(items.length==0)
  177. return false;
  178. for(Item item : items) {
  179. int heal = getHeal(item.getID());
  180. if(hp+heal<=max) {
  181. item.doAction("Eat");
  182. hp+=heal;
  183. sleep(random(1200,1300));
  184. }
  185. }
  186. }
  187. if(hp()!=starting)
  188. return true;
  189. } catch(Exception e) {
  190. e.printStackTrace();
  191. }
  192. return false;
  193. }
  194.  
  195. public Tile[] fixPath(Tile t) {
  196. int startX = getMyPlayer().getLocation().getX();
  197. int startY = getMyPlayer().getLocation().getY();
  198. int destinationX = t.getX();
  199. int destinationY = t.getY();
  200. double dx, dy;
  201. ArrayList<Tile> list = new ArrayList<Tile>();
  202. list.add(new Tile(startX, startY));
  203. while (Math.hypot(destinationY - startY, destinationX - startX) > 8) {
  204. dx = destinationX - startX;
  205. dy = destinationY - startY;
  206. int gamble = random(14, 17);
  207. while (Math.hypot(dx, dy) > gamble) {
  208. dx *= .95;
  209. dy *= .95;
  210. }
  211. startX += (int) dx;
  212. startY += (int) dy;
  213. list.add(new Tile(startX, startY));
  214. }
  215. list.add(new Tile(destinationX, destinationY));
  216.  
  217. return list.toArray(new Tile[list.size()]);
  218. }
  219.  
  220.  
  221. public boolean combat() {
  222. try {
  223.  
  224. Player p = getMyPlayer();
  225. Character c = p.getInteracting();
  226.  
  227. if(c==null)
  228. return false;
  229. Character d = c.getInteracting();
  230. if(d!=null || d.getModel()==p.getModel())
  231. return true;
  232. }catch(Exception e) {
  233. e.printStackTrace();
  234. }
  235. return false;
  236. }
  237. public boolean shouldPickup(GroundItem loot, boolean bone) {
  238. int id = loot.getID();
  239. if(inventory.getCount(true,id)>1 && inventory.getItems(id)[0].getStackSize()>1) {
  240. return true;
  241. }
  242.  
  243. if(inventory.isFull() && eat(false))
  244. sleep(random(1000,1200));
  245. if(inventory.isFull()) {
  246. if(!bone && inventory.contains(BONE)) {
  247. inventory.atItem(BONE, "Drop Bone");
  248. return true;
  249. } else
  250. return false;
  251.  
  252. }
  253. return !inventory.isFull();
  254. }
  255. @Override
  256. public void stop() {
  257. //To change body of implemented methods use File | Settings | File Templates.
  258. }
  259.  
  260. @Override
  261. public void onStart() {
  262. game.openTab(Game.TAB_INVENTORY);
  263. failSafe = new MTimer(300000);
  264. combat = new MTimer(3000);
  265.  
  266.  
  267. //To change body of implemented methods use File | Settings | File Templates.
  268. }
  269.  
  270. @Override
  271. public String getName() {
  272. return "Dust Devil"; //To change body of implemented methods use File | Settings | File Templates.
  273. }
  274. class MTimer {
  275. long time = 0;
  276. long start = 0;
  277. public MTimer(long ms) {
  278. start = System.currentTimeMillis();
  279. time=ms;
  280. }
  281. public boolean isDone() {
  282. return start+time<System.currentTimeMillis();
  283. }
  284. public void reset() {
  285. start = System.currentTimeMillis();
  286. }
  287. }
  288. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement