Advertisement
Guest User

ok_StarterCombat

a guest
Dec 7th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.29 KB | None | 0 0
  1. package scripts;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Font;
  5. import java.awt.Graphics;
  6.  
  7. import org.tribot.api.Timing;
  8. import org.tribot.api.General;
  9. import org.tribot.api2007.Screen;
  10. import org.tribot.api2007.types.RSTile;
  11. import org.tribot.api.DynamicClicking;
  12. import org.tribot.api.input.Mouse;
  13. import org.tribot.api.types.generic.Condition;
  14. import org.tribot.api2007.Camera;
  15. import org.tribot.api2007.Combat;
  16. import org.tribot.api2007.Equipment;
  17. import org.tribot.api2007.GameTab;
  18. import org.tribot.api2007.Inventory;
  19. import org.tribot.api2007.Login;
  20. import org.tribot.api2007.NPCs;
  21. import org.tribot.api2007.Objects;
  22. import org.tribot.api2007.Player;
  23. import org.tribot.api2007.Skills;
  24. import org.tribot.api2007.Walking;
  25. import org.tribot.api2007.GameTab.TABS;
  26. import org.tribot.api2007.types.RSItem;
  27. import org.tribot.api2007.types.RSNPC;
  28. import org.tribot.api2007.types.RSObject;
  29. import org.tribot.script.Script;
  30. import org.tribot.script.ScriptManifest;
  31. import org.tribot.script.interfaces.Painting;
  32. import org.tribot.script.interfaces.Pausing;
  33. import org.tribot.script.interfaces.RandomEvents;
  34.  
  35. @ScriptManifest(authors = { "Okokokok" }, category = "ok_StarterPack", name = "ok_StarterCombat")
  36. public class ok_StarterCombat extends Script implements Painting, Pausing, RandomEvents {
  37.  
  38. boolean paused;
  39.  
  40. private double version = 1.00;
  41.  
  42. private String weapon = "Training sword",
  43. armourPiece1 = "Training shield";
  44.  
  45. private final String goblinName = "Goblin",
  46. goblinOption = "Attack",
  47. doorName = "Door",
  48. openOption = "Open",
  49. closeOption = "Close";
  50.  
  51. public RSArea deathArea = new RSArea(new RSTile(3216, 3208, 0), new RSTile(3226, 3224, 0)),
  52. walkArea = new RSArea(new RSTile(3216, 3208, 0), new RSTile(3266, 3244, 0)),
  53. combatArea = new RSArea(new RSTile(3243, 3244, 0), new RSTile(3249, 3249, 0));
  54.  
  55. private final RSTile[] goblinPath = new RSTile[] {new RSTile(3228, 3218, 0),
  56. new RSTile(3234, 3222, 0),
  57. new RSTile(3239, 3225, 0),
  58. new RSTile(3246, 3226, 0),
  59. new RSTile(3252, 3226, 0),
  60. new RSTile(3254, 3230, 0),
  61. new RSTile(3252, 3235, 0),
  62. new RSTile(3247, 3239, 0),
  63. new RSTile(3246, 3242, 0)};
  64.  
  65. private RSTile openDoorTile = new RSTile(3246, 3243, 0),
  66. closeDoorTile = new RSTile(3246, 3244, 0);
  67.  
  68. // MISC METHODS
  69.  
  70. public boolean waitFor(Condition c, long timeout) {
  71. Timer t = new Timer(timeout);
  72. while (t.isRunning()) {
  73. if (c.active()) {
  74. return true;
  75. }
  76. sleep(60, 80);
  77. }
  78. return false;
  79. }
  80.  
  81. public boolean loggedOut() {
  82. return (Login.getLoginState() == Login.STATE.LOGINSCREEN)
  83. && (!Screen.getColorAt(100, 200).equals(new Color(0, 0, 0)));
  84. }
  85.  
  86. public boolean logout() {
  87. if (Login.getLoginState() == Login.STATE.INGAME)
  88. {
  89. Login.logout();
  90. for(int x = 0; x < 6; x++)
  91. {
  92. if(loggedOut())
  93. {
  94. return true;
  95. }
  96. sleep(490,510);
  97. }
  98. }
  99. return false;
  100. }
  101.  
  102. public void antiBan(int rotation) {
  103. int number = General.random(1, 500);
  104. sleep(200);
  105. switch (number) {
  106. case 1:
  107. case 2:
  108. case 3:
  109. case 4:
  110. case 5:
  111. Camera.setCameraRotation(Camera.getCameraRotation() + rotation);
  112. break;
  113. case 20:
  114. case 21:
  115. case 22:
  116. case 23:
  117. case 24:
  118. case 25:
  119. case 26:
  120. case 27:
  121. case 28:
  122. case 29:
  123. case 30:
  124. case 31:
  125. Camera.setCameraRotation(Camera.getCameraRotation() + rotation);
  126. sleep(200);
  127. break;
  128. case 50:
  129. GameTab.open(TABS.INVENTORY);
  130. sleep(200);
  131. break;
  132. case 75:
  133. case 76:
  134. break;
  135. case 89:
  136. case 90:
  137. case 91:
  138. case 92:
  139. case 93:
  140. case 94:
  141. Camera.setCameraAngle(Camera.getCameraRotation() + rotation);
  142. sleep(200, 400);
  143. break;
  144. case 95:
  145. case 96:
  146. case 97:
  147. case 98:
  148. case 99:
  149. case 100:
  150. Camera.setCameraAngle(Camera.getCameraRotation() + rotation);
  151. sleep(200, 400);
  152. break;
  153. }
  154. }
  155.  
  156.  
  157. // EQUIPMENT METHODS
  158.  
  159. private boolean haveItemEquipped(final String itemName){
  160. RSItem[] item = Equipment.find(itemName);
  161. return item != null && item.length > 0;
  162. }
  163.  
  164. private boolean haveItemsEquipped(String weaponWorn, String armourWorn1){
  165. RSItem[] weaponWorn2 = Equipment.find(weaponWorn);
  166. RSItem[] armourPieceOne = Equipment.find(armourWorn1);
  167. return weaponWorn2 != null && weaponWorn2.length > 0 && armourPieceOne != null && armourPieceOne.length > 0;
  168. }
  169.  
  170. private void equipItems(final String itemName){
  171. RSItem[] item = Inventory.find(itemName);
  172. if (item != null && item.length > 0){
  173. if (item[0].click("Wield") || item[0].click("Wear")){
  174. waitFor(new Condition(){
  175. @Override
  176. public boolean active(){
  177. return haveItemEquipped(itemName);
  178. }
  179. }, 8000);
  180. }
  181. }
  182. }
  183.  
  184. // INVENTORY METHODS
  185.  
  186. private boolean checkInvent(){
  187. RSItem[] invent = Inventory.getAll();
  188. return invent != null && invent.length > 0;
  189. }
  190.  
  191. private void dropAll(){
  192. if (checkInvent()){
  193. Inventory.dropAllExcept();
  194. }
  195. }
  196.  
  197. // COMBAT METHODS
  198.  
  199. private RSTile npcPosition(){
  200. RSNPC[] npc = NPCs.findNearest(goblinName);
  201. if (npc != null && npc.length > 0){
  202. return npc[0].getPosition();
  203. }
  204. return null;
  205. }
  206.  
  207. private void fightNPC(String npcName){
  208. final RSNPC[] npc = NPCs.findNearest(npcName);
  209. if (npc != null && npc.length > 0 && npc[0].isOnScreen() && combatArea.contains(npcPosition())){
  210. if (DynamicClicking.clickRSNPC(npc[0], goblinOption)){
  211. waitFor(new Condition(){
  212. @Override
  213. public boolean active(){
  214. return !Combat.isUnderAttack() && !npc[0].isInCombat() && !Player.isMoving();
  215. }
  216. }, 5000);
  217. }
  218. }
  219. }
  220.  
  221. // DOOR METHODS}
  222.  
  223. private boolean closeToDoor(){
  224. RSObject[] door = Objects.findNearest(5, doorName);
  225. RSTile myPos = Player.getPosition();
  226. if (door != null && door.length > 0){
  227. if (doorPosition().distanceTo(myPos) < 5){
  228. return true;
  229. }
  230. }
  231. return false;
  232. }
  233.  
  234. private RSTile doorPosition(){
  235. RSObject[] door = Objects.findNearest(5, doorName);
  236. if (door != null && door.length > 0){
  237. return door[0].getPosition();
  238. }
  239. return null;
  240. }
  241.  
  242. private boolean findDoorClosed(){
  243. RSObject[] door = Objects.findNearest(7, doorName);
  244. if (door != null && door.length > 0){
  245. if (doorPosition().equals(closeDoorTile)){
  246. return true;
  247. }
  248. }
  249. return false;
  250. }
  251.  
  252. private void openDoor(String doorName){
  253. RSObject[] door = Objects.findNearest(5, doorName);
  254. if (door != null && door.length > 0){
  255. if (doorPosition().equals(closeDoorTile)){
  256. if (DynamicClicking.clickRSObject(door[0], openOption)){
  257. waitFor(new Condition(){
  258. @Override
  259. public boolean active(){
  260. return doorPosition().equals(openDoorTile);
  261. }
  262. }, 15000);
  263. }
  264. }
  265. }
  266. }
  267.  
  268. private void closeDoor(String doorName){
  269. RSObject[] door = Objects.findNearest(5, doorName);
  270. if (door != null && door.length > 0){
  271. if (doorPosition().equals(openDoorTile)){
  272. if (DynamicClicking.clickRSObject(door[0], closeOption)){
  273. waitFor(new Condition(){
  274. @Override
  275. public boolean active(){
  276. return doorPosition().equals(closeDoorTile);
  277. }
  278. }, 15000);
  279. }
  280. }
  281. }
  282. }
  283.  
  284. // WALKING METHODS
  285.  
  286. private void walkCombatArea(){
  287. if (!Player.isMoving()){
  288. if (Walking.walkPath(goblinPath)){
  289. waitFor(new Condition(){
  290. @Override
  291. public boolean active(){
  292. return closeToDoor();
  293. }
  294. }, 3000);
  295. }
  296. }
  297. }
  298.  
  299. private void walkHut(){
  300. final RSTile myPos = Player.getPosition();
  301. if (!findDoorClosed() && !Player.isMoving()){
  302. if (Walking.walkTo(new RSTile(3247, 3246, 0))){
  303. waitFor(new Condition(){
  304. @Override
  305. public boolean active(){
  306. return !Player.isMoving() && combatArea.contains(myPos);
  307. }
  308. }, 5000);
  309. }
  310. }
  311. }
  312. // STATES
  313.  
  314. public enum State{
  315. EQUIPING_WEAPONS, WALKING_TO_COMBAT_AREA,
  316. FIGHTING, LOGING_OUT, OPENING_DOOR,
  317. WALKING_IN_HUT, CLOSING_DOOR, DROPPING;
  318. }
  319.  
  320. private State getState(){
  321. RSTile myPos2 = Player.getPosition();
  322. if (deathArea.contains(myPos2) && !combatArea.contains(myPos2)){
  323. if (haveItemsEquipped(weapon, armourPiece1)){
  324. return State.WALKING_TO_COMBAT_AREA;
  325. }
  326. if (!haveItemsEquipped(weapon, armourPiece1)){
  327. return State.EQUIPING_WEAPONS;
  328. }
  329. }
  330. if (combatArea.contains(myPos2) && !walkArea.contains(myPos2)){
  331. if (!haveItemsEquipped(weapon, armourPiece1)){
  332. return State.EQUIPING_WEAPONS;
  333. }
  334. if (checkInvent() && haveItemsEquipped(weapon, armourPiece1)){
  335. return State.DROPPING;
  336. }
  337. if (findDoorClosed() && !checkInvent() && haveItemsEquipped(weapon, armourPiece1)){
  338. return State.FIGHTING;
  339. }
  340. if (!findDoorClosed() && !checkInvent() && haveItemsEquipped(weapon, armourPiece1)){
  341. return State.CLOSING_DOOR;
  342. }
  343. }
  344. if (walkArea.contains(myPos2)){
  345. if (!closeToDoor() && !combatArea.contains(myPos2)){
  346. return State.WALKING_TO_COMBAT_AREA;
  347. }
  348. if (closeToDoor() && findDoorClosed() && !combatArea.contains(myPos2)){
  349. return State.OPENING_DOOR;
  350. }
  351. if (closeToDoor() && !findDoorClosed() && !combatArea.contains(myPos2)){
  352. return State.WALKING_IN_HUT;
  353. }
  354. }
  355. return State.LOGING_OUT;
  356. }
  357.  
  358. @Override
  359. public void onPause() {
  360. paused = true;
  361. while (paused){
  362. sleep(200, 300);
  363. }
  364.  
  365.  
  366. }
  367.  
  368. @Override
  369. public void onResume() {
  370.  
  371. paused = false;
  372. sleep(100, 200);
  373. }
  374.  
  375. private static final long startTime = System.currentTimeMillis();
  376. Font font = new Font("Calibri", Font.BOLD, 16);
  377. private State SCRIPT_STATE = getState();
  378.  
  379.  
  380. @SuppressWarnings("deprecation")
  381. private final int startXP = Skills.getXP("hitpoints");
  382. private int START_XP;
  383.  
  384. @SuppressWarnings("deprecation")
  385. @Override
  386. public void onPaint(Graphics g) {
  387.  
  388. long timeRan = System.currentTimeMillis() - startTime;
  389. double multiplier = timeRan / 3600000D;
  390. int xpGained = Skills.getXP("hitpoints") - START_XP;
  391. double totalXPGained = (xpGained / 4 * 10) + xpGained;
  392.  
  393. g.setFont(font);
  394. g.setColor(new Color(255, 255, 255));
  395. g.drawString("ok_StarterCombat V" + version, 558, 220);
  396. g.drawString("Action: " + SCRIPT_STATE, 558, 235);
  397. g.drawString("Time running: " + Timing.msToString(timeRan), 558, 250);
  398.  
  399. g.drawString("XP Gained p/h: " + (int) (totalXPGained / multiplier), 558, 265);
  400. g.drawString("XP Gained: " + (int) totalXPGained, 558, 280);
  401.  
  402. g.drawString("Kills p/h: " + (int)((totalXPGained / 16.6625) / multiplier), 558, 295);
  403. g.drawString("Kills done: " + (int) (totalXPGained / 16.6625), 558, 310);
  404. }
  405.  
  406. @SuppressWarnings("deprecation")
  407. @Override
  408. public void run() {
  409. println("Started ok_StarterCombat from the StarterPack");
  410. START_XP = startXP;
  411. super.setRandomSolverState(true);
  412. Walking.setControlClick(true);
  413.  
  414. while(true){
  415. if (loggedOut()) {
  416. super.setLoginBotState(active);
  417. } else {
  418. while (!loggedOut()) {
  419. SCRIPT_STATE = getState();
  420. int mSpeed = General.random(180, 200);
  421. Mouse.setSpeed(mSpeed);
  422. Walking.setControlClick(true);
  423.  
  424. switch (SCRIPT_STATE) {
  425.  
  426. case EQUIPING_WEAPONS:
  427. equipItems(weapon);
  428. sleep(150, 200);
  429. equipItems(armourPiece1);
  430. sleep(150, 200);
  431. break;
  432.  
  433. case FIGHTING:
  434. int rotation5 = General.random(90, 200);
  435. antiBan(rotation5);
  436.  
  437. fightNPC(goblinName);
  438. sleep(150, 200);
  439. break;
  440.  
  441. case LOGING_OUT:
  442. logout();
  443. stopScript();
  444. break;
  445.  
  446. case WALKING_TO_COMBAT_AREA:
  447. walkCombatArea();
  448. sleep(150, 200);
  449. break;
  450.  
  451. case OPENING_DOOR:
  452. openDoor(doorName);
  453. sleep(150, 200);
  454. break;
  455.  
  456. case WALKING_IN_HUT:
  457. walkHut();
  458. sleep(150, 200);
  459. break;
  460.  
  461. case CLOSING_DOOR:
  462. closeDoor(doorName);
  463. sleep(150, 200);
  464.  
  465. case DROPPING:
  466. dropAll();
  467. sleep(150, 200);
  468. }
  469. }
  470. }
  471. }
  472. }
  473.  
  474. @Override
  475. public void onRandom(RANDOM_SOLVERS arg0) {
  476. paused = true;
  477.  
  478. }
  479.  
  480. @Override
  481. public boolean randomFailed(RANDOM_SOLVERS arg0) {
  482. paused = false;
  483. return false;
  484. }
  485.  
  486. @Override
  487. public void randomSolved(RANDOM_SOLVERS arg0) {
  488. sleep(2000, 3000);
  489. paused = false;
  490.  
  491. }
  492. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement