Advertisement
Guest User

ChickenKiller.java

a guest
Dec 30th, 2013
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.47 KB | None | 0 0
  1. package scripts;
  2.  
  3. import java.awt.Graphics;
  4.  
  5. import org.tribot.api.General;
  6. import org.tribot.api.Timing;
  7. import org.tribot.api.input.Mouse;
  8. import org.tribot.api2007.Combat;
  9. import org.tribot.api2007.Game;
  10. import org.tribot.api2007.GameTab;
  11. import org.tribot.api2007.GroundItems;
  12. import org.tribot.api2007.Inventory;
  13. import org.tribot.api2007.Login;
  14. import org.tribot.api2007.NPCs;
  15. import org.tribot.api2007.Options;
  16. import org.tribot.api2007.Player;
  17. import org.tribot.api2007.Skills;
  18. import org.tribot.api2007.Walking;
  19. import org.tribot.api2007.WebWalking;
  20. import org.tribot.api2007.ext.Doors;
  21. import org.tribot.api2007.types.RSArea;
  22. import org.tribot.api2007.types.RSGroundItem;
  23. import org.tribot.api2007.types.RSItem;
  24. import org.tribot.api2007.types.RSNPC;
  25. import org.tribot.api2007.types.RSObject;
  26. import org.tribot.api2007.types.RSTile;
  27. import org.tribot.script.Script;
  28. import org.tribot.script.ScriptManifest;
  29. import org.tribot.script.interfaces.Painting;
  30.  
  31. @ScriptManifest(authors = { "Cloudnine" }, category = "Local", name = "Chicken Killer")
  32. public class ChickenKiller extends Script implements Painting {
  33. private String status = "Starting up";
  34. private RSTile OUTSIDE_GATE_TILE = new RSTile(3237, 3296);
  35. private RSTile INSIDE_GATE_TILE = new RSTile(3236, 3296);
  36. private RSArea PEN_AREA = new RSArea(new RSTile(3235, 3301), new RSTile(
  37. 3225, 3295));
  38. private RSArea ENTIRE_PEN_AREA = new RSArea(new RSTile(3235, 3301),
  39. new RSTile(3225, 3287));
  40. private static boolean lootFeathers;
  41. private static boolean buryBones;
  42. private static boolean waitingOnGUI = true;
  43. private final int START_STRENGTH_XP = Skills.getXP(Skills.SKILLS.STRENGTH);
  44.  
  45. @Override
  46. public void run() {
  47. ChickenKillerGUI.openGUI();
  48. while (true) {
  49. sleep(loop());
  50. }
  51. }
  52.  
  53. @Override
  54. public void onPaint(Graphics g) {
  55. g.drawString("Chicken Killer v1.1 by Cloudnine", 300, 300);
  56. g.drawString("Status: " + status, 300, 315);
  57. g.drawString("Run Time: " + Timing.msToString(getRunningTime()), 300,
  58. 330);
  59. int strengthLevel = Skills.getActualLevel(Skills.SKILLS.STRENGTH);
  60. int xpGain = Skills.getXP(Skills.SKILLS.STRENGTH) - START_STRENGTH_XP;
  61. int hourly = (int) (((double) xpGain * 3600000D) / (double) this
  62. .getRunningTime());
  63. g.drawString("Strength Level: " + strengthLevel + " XP Gained: "
  64. + xpGain + "(" + hourly + "/hr)", 300, 345);
  65. }
  66.  
  67. private int loop() {
  68. if (waitingOnGUI) {
  69. status = "Waiting on user input";
  70. return 250;
  71. }
  72. if (Login.getLoginState() != Login.STATE.INGAME) {
  73. status = "Not logged in";
  74. return 250;
  75. }
  76. if (Player.isMoving()) {
  77. status = "Moving";
  78. return 250;
  79. }
  80. if (!PEN_AREA.contains(Player.getPosition())) {
  81. status = "Walking to pen";
  82. walkToPen();
  83. return 250;
  84. }
  85. if (!Combat.isUnderAttack()) {
  86. status = "In combat";
  87. return 250;
  88. }
  89. Mouse.setSpeed(General.random(200, 250));
  90. enableRun();
  91. lootDrops();
  92. handleEdibles();
  93. attackChicken();
  94. return 250;
  95. }
  96.  
  97. private void lootDrops() {
  98. if (lootFeathers) {
  99. RSGroundItem[] feathers = GroundItems.findNearest("Feather");
  100. for (RSGroundItem feather : feathers) {
  101. if (PEN_AREA.contains(feather.getPosition())) {
  102. status = "Taking feathers";
  103. if (!feather.isOnScreen()) {
  104. Walking.walkTo(feather.getPosition());
  105. sleepWhileMoving();
  106. }
  107. feather.click("Take Feather");
  108. sleepWhileMoving();
  109. }
  110. }
  111. }
  112. if (buryBones) {
  113. RSGroundItem[] bones = GroundItems.findNearest("Bones");
  114. for (RSGroundItem bone : bones) {
  115. if (PEN_AREA.contains(bone.getPosition())) {
  116. status = "Taking bones";
  117. if (!bone.isOnScreen()) {
  118. Walking.walkTo(bone.getPosition());
  119. sleepWhileMoving();
  120. }
  121. if (bones != null) {
  122. bone.click("Take Bones");
  123. sleepWhileMoving();
  124. }
  125. }
  126. }
  127. RSItem[] bonesInInventory = Inventory.find("Bones");
  128. for (RSItem boneInInventory : bonesInInventory) {
  129. status = "Burying bones";
  130. boneInInventory.click("Bury");
  131. int count = 0;
  132. while (count < 5 && Player.getAnimation() != 827) {
  133. count++;
  134. sleep(100);
  135. }
  136. while (Player.getAnimation() == 827) {
  137. sleep(100);
  138. }
  139. }
  140. }
  141. }
  142.  
  143. private void handleEdibles() {
  144. for (int i = 0; i < 4; i++) {
  145. if (Inventory.find("Strength potion(" + i + ")").length > 0
  146. && Inventory.find("Strength potion(" + i + ")")[0] != null) {
  147. status = "Drinking Strength Potion";
  148. Inventory.find("Strength potion(" + i + ")")[0].click("Drink");
  149. int count = 0;
  150. while (count < 10
  151. && Inventory.getCount(new String[] { "Strength potion("
  152. + i + ")" }) > 0) {
  153. count++;
  154. sleep(100);
  155. }
  156. }
  157. }
  158. if (Inventory.find("Vial").length > 0
  159. && Inventory.find("Vial")[0] != null) {
  160. status = "Dropping empty strength potion";
  161. Inventory.find("Vial")[0].click("Drop");
  162. int count = 0;
  163. while (count < 10
  164. && Inventory.getCount(new String[] { "Vial" }) > 0) {
  165. count++;
  166. sleep(100);
  167. }
  168. }
  169. }
  170.  
  171. private void attackChicken() {
  172. RSNPC[] chickens = NPCs.findNearest("Chicken");
  173. for (RSNPC chicken : chickens) {
  174. if (chicken != null && chicken.getCombatCycle() == -1000
  175. && PEN_AREA.contains(chicken.getPosition())) {
  176. status = "Attacking Chicken";
  177. if (chicken.click("Attack")) {
  178. sleepWhileMoving();
  179. break;
  180. }
  181. }
  182. }
  183. }
  184.  
  185. private void enableRun() {
  186. if (Game.getRunEnergy() >= 50) {
  187. Options.setRunOn(true);
  188. if (Game.isRunOn()) {
  189. if (GameTab.getOpen() != GameTab.TABS.INVENTORY) {
  190. GameTab.open(GameTab.TABS.STATS);
  191. }
  192. }
  193. }
  194. }
  195.  
  196. private void handleGate(boolean openGate) {
  197. RSObject gate = Doors.getDoorAt(INSIDE_GATE_TILE);
  198. if (gate != null) {
  199. if (!gate.isOnScreen()) {
  200. Walking.walkTo(OUTSIDE_GATE_TILE);
  201. sleepWhileMoving();
  202. }
  203. Doors.handleDoor(gate, openGate);
  204. sleepWhileMoving();
  205. } else {
  206. status = "No gate found!";
  207. }
  208. }
  209.  
  210. private void walkToPen() {
  211. if (!ENTIRE_PEN_AREA.contains(Player.getPosition())) {
  212. WebWalking.walkTo(OUTSIDE_GATE_TILE);
  213. sleepWhileMoving();
  214. handleGate(true);
  215. }
  216. Walking.walkTo(PEN_AREA.getRandomTile());
  217. }
  218.  
  219. private void sleepWhileMoving() {
  220. int count = 0;
  221. while (count < 5 && !Player.isMoving()) {
  222. count++;
  223. sleep(100);
  224. }
  225. while (Player.isMoving()) {
  226. sleep(100);
  227. }
  228. }
  229.  
  230. public static void passVariables(boolean feathers, boolean bones) {
  231. lootFeathers = feathers;
  232. buryBones = bones;
  233. waitingOnGUI = false;
  234. }
  235. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement