Advertisement
Guest User

Untitled

a guest
Jan 13th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.03 KB | None | 0 0
  1. package scripts;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.util.ArrayList;
  6.  
  7. import javax.swing.JOptionPane;
  8.  
  9. import org.tribot.api.DynamicClicking;
  10. import org.tribot.api.General;
  11. import org.tribot.api.Timing;
  12. import org.tribot.api.input.Mouse;
  13. import org.tribot.api2007.Banking;
  14. import org.tribot.api2007.Camera;
  15. import org.tribot.api2007.ChooseOption;
  16. import org.tribot.api2007.Game;
  17. import org.tribot.api2007.Inventory;
  18. import org.tribot.api2007.NPCs;
  19. import org.tribot.api2007.Objects;
  20. import org.tribot.api2007.Player;
  21. import org.tribot.api2007.Skills;
  22. import org.tribot.api2007.Walking;
  23. import org.tribot.api2007.WebWalking;
  24. import org.tribot.api2007.Skills.SKILLS;
  25. import org.tribot.api2007.types.RSArea;
  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.api2007.types.RSTile;
  30. import org.tribot.script.Script;
  31. import org.tribot.script.ScriptManifest;
  32. import org.tribot.script.interfaces.MessageListening07;
  33. import org.tribot.script.interfaces.Painting;
  34.  
  35. @ScriptManifest(authors = { "ITryNotToTroll" }, category = "Thieving", name = "Troll Thieving")
  36. public class TrollThieving extends Script implements Painting, MessageListening07{
  37.  
  38. private State state;
  39. private RSTile lummyTile;
  40. private RSTile stallTile = new RSTile(3268, 3410, 0);
  41. private boolean running = true;
  42. private String foodName = "Monkfish";
  43. private int foodAmount = 5;
  44. private RSTile farmerTile = new RSTile(3080, 3250, 0);
  45. private RSArea bankArea = new RSArea(new RSTile(3097, 3240, 0), new RSTile(3092, 3246, 0));
  46. private boolean stunned = false;
  47. private int eatAtHitpoints = 40;
  48. private int mouseSpeedMin = 100;
  49. private int mouseSpeedMax = 120;
  50. private long startXP;
  51. private int startLevel;
  52. private long startTime;
  53. private long currentXP;
  54. private int currentLevel;
  55.  
  56. private final double VERSION = 1.3;
  57.  
  58. private ArrayList<String> loot = new ArrayList<>();
  59.  
  60. @Override
  61. public void run()
  62. {
  63.  
  64. initializeScript();
  65.  
  66. while(running)
  67. {
  68. state = getState();
  69. switch(state)
  70. {
  71. case DEPOSIT_ALL_EXCEPT_FOOD:
  72. depositAllExceptFood();
  73. break;
  74. case OPEN_BANK:
  75. Banking.openBank();
  76. break;
  77. case WALK_TO_FARMER_NPC:
  78. walkToFarmerNPC();
  79. break;
  80. case WITHDRAW_FOOD:
  81. withdrawFood();
  82. break;
  83. case WALK_TO_BANK:
  84. WebWalking.walkToBank();
  85. while(Player.isMoving())
  86. {
  87. sleep(50, 100);
  88. }
  89. break;
  90. case EAT_FOOD:
  91. eatFood();
  92. break;
  93. case SLEEP:
  94. break;
  95. case PICKPOCKET_FARMER:
  96. pickPocketNPC("Master Farmer");
  97. sleep(300, 700);
  98. break;
  99. case DROP_TEA:
  100. dropAllTea();
  101. break;
  102. case ANIMATING:
  103. break;
  104. case STEAL_TEA:
  105. stealTea();
  106. break;
  107. case DEPOSIT_ALL:
  108. Banking.depositAll();
  109. break;
  110. case WALK_TO_STALL:
  111. WebWalking.walkTo(stallTile);
  112. break;
  113. case PICK_POCKET_MAN:
  114. pickPocketNPC("Man");
  115. sleep(300, 700);
  116. break;
  117. case WALK_TO_LUMMY_TILE:
  118. WebWalking.walkTo(lummyTile);
  119. break;
  120. case DROP_JUNK:
  121. dropJunk();
  122. break;
  123. case OUT_OF_FOOD:
  124. println("We have run out of food!");
  125. running = false;
  126. }
  127. sleep(50, 100);
  128. }
  129.  
  130. }
  131.  
  132. enum State{
  133. DEPOSIT_ALL_EXCEPT_FOOD,
  134. OPEN_BANK,
  135. WALK_TO_FARMER,
  136. WITHDRAW_FOOD,
  137. WALK_TO_BANK,
  138. EAT_FOOD,
  139. SLEEP,
  140. PICKPOCKET_FARMER,
  141. DROP_TEA,
  142. ANIMATING,
  143. STEAL_TEA,
  144. DEPOSIT_ALL,
  145. WALK_TO_STALL,
  146. PICK_POCKET_MAN,
  147. WALK_TO_LUMMY_TILE,
  148. DROP_JUNK,
  149. WALK_TO_FARMER_NPC, OUT_OF_FOOD
  150. }
  151.  
  152. private State getState()
  153. {
  154. if(Skills.getActualLevel(SKILLS.THIEVING) < 5)
  155. {
  156. if(Player.getPosition().distanceTo(lummyTile) < 10)
  157. {
  158. if(NPCs.find("Man").length > 0 && NPCs.find("Man")[0].getPosition().distanceTo(Player.getPosition()) < 8)
  159. {
  160. return state.PICK_POCKET_MAN;
  161. }
  162. else
  163. {
  164. if(Player.getPosition().distanceTo(lummyTile) > 2)
  165. {
  166. return state.WALK_TO_LUMMY_TILE;
  167. }
  168. else
  169. {
  170. return state.SLEEP;
  171. }
  172. }
  173. }
  174. else
  175. {
  176. return state.WALK_TO_LUMMY_TILE;
  177. }
  178. }
  179. else
  180. {
  181. if(Skills.getActualLevel(SKILLS.THIEVING) < 38)
  182. {
  183. if(Player.getPosition().distanceTo(stallTile) < 6)
  184. {
  185. if(Inventory.getCount("Cup of tea") > 0)
  186. {
  187. return state.DROP_TEA;
  188. }
  189. else
  190. {
  191. if(Inventory.isFull())
  192. {
  193. return state.WALK_TO_BANK;
  194. }
  195. else
  196. {
  197. if(isAnimating())
  198. {
  199. return state.ANIMATING;
  200. }
  201. else
  202. {
  203. if(teaAvaliable())
  204. {
  205. return state.STEAL_TEA;
  206. }
  207. else
  208. {
  209. return state.SLEEP;
  210. }
  211. }
  212. }
  213. }
  214. }
  215. else
  216. {
  217. if(Inventory.isFull())
  218. {
  219. if(Banking.isInBank()){
  220. if(Banking.isBankScreenOpen())
  221. {
  222. return state.DEPOSIT_ALL;
  223. }
  224. else
  225. {
  226. return state.OPEN_BANK;
  227. }
  228. }
  229. else
  230. {
  231. return state.WALK_TO_BANK;
  232. }
  233. }
  234. else
  235. {
  236. return state.WALK_TO_STALL;
  237. }
  238. }
  239. }
  240. else
  241. {
  242. if(isInBank())
  243. {
  244. if(Inventory.getCount(foodName) >= foodAmount && !Inventory.isFull())
  245. {
  246. if(Inventory.getAll().length != Inventory.getCount(foodName))
  247. {
  248. if(Banking.isBankScreenOpen())
  249. {
  250. return state.DEPOSIT_ALL_EXCEPT_FOOD;
  251. }
  252. else
  253. {
  254. return state.OPEN_BANK;
  255. }
  256. }
  257. else
  258. {
  259. println("Bank walk to farmer");
  260. return state.WALK_TO_FARMER_NPC;
  261. }
  262. }
  263. else
  264. {
  265. if(Banking.isBankScreenOpen())
  266. {
  267. if(inventoryOnlyContainsFood() && !Inventory.isFull())
  268. {
  269. if(hasFoodInBank())
  270. {
  271. return state.WITHDRAW_FOOD;
  272. }
  273. else
  274. {
  275. return state.OUT_OF_FOOD;
  276. }
  277. }
  278. else
  279. {
  280. return state.DEPOSIT_ALL;
  281. }
  282. }
  283. else
  284. {
  285. return state.OPEN_BANK;
  286. }
  287. }
  288. }
  289. else
  290. {
  291. if(distanceFromFarmer() < 10)
  292. {
  293. if(Inventory.isFull() || Inventory.getCount(foodName) == 0)
  294. {
  295. return state.WALK_TO_BANK;
  296. }
  297. else
  298. {
  299. if(Skills.getCurrentLevel(SKILLS.HITPOINTS) < eatAtHitpoints)
  300. {
  301. return state.EAT_FOOD;
  302. }
  303. else
  304. {
  305. if(isBeingAttackedByGuard())
  306. {
  307. return state.WALK_TO_BANK;
  308. }
  309. else
  310. {
  311. if(stunned)
  312. {
  313. return state.DROP_JUNK;
  314. }
  315. else
  316. {
  317. return state.PICKPOCKET_FARMER;
  318. }
  319. }
  320. }
  321. }
  322. }
  323. else
  324. {
  325. println("Else else walk to farmer");
  326. println("Distance to Farmer:" + distanceFromFarmer());
  327. return state.WALK_TO_FARMER_NPC;
  328. }
  329. }
  330. }
  331. }
  332. }
  333.  
  334. private void withdrawFood()
  335. {
  336. Banking.withdraw(foodAmount - Inventory.getCount(foodName), foodName);
  337. long currTime = System.currentTimeMillis();
  338. while(Inventory.getCount(foodName) != foodAmount && System.currentTimeMillis() - 2000 < currTime)
  339. {
  340. sleep(50, 100);
  341. }
  342. }
  343.  
  344. private void initializeScript()
  345. {
  346. foodName = JOptionPane.showInputDialog("Master Farmer - Please enter food name (Correct capitalization required)");
  347. foodAmount = Integer.parseInt(JOptionPane.showInputDialog("Master Farmer - Please enter the amount of food to withdraw"));
  348. eatAtHitpoints = Integer.parseInt(JOptionPane.showInputDialog("Master Farmer - Please enter the hitpoints at which we should eat"));
  349. mouseSpeedMin = Integer.parseInt(JOptionPane.showInputDialog("Master Farmer - Please enter the minimum mouse speed"));
  350. mouseSpeedMax = Integer.parseInt(JOptionPane.showInputDialog("Master Farmer - Please enter the maximum mouse speed"));
  351. loot.add("Ranarr seed");
  352. loot.add("Snapdragon seed");
  353. loot.add("Watermelon seed");
  354. loot.add("Kwuarm seed");
  355. loot.add("Limpwurt seed");
  356. loot.add("Strawberry seed");
  357. loot.add("Sweetcorn seed");
  358. loot.add("Torstol seed");
  359. int y = JOptionPane.showOptionDialog(null,
  360. "Master Farmer - Do you wish to the extended loot table? (More seeds kept)", "Loot",
  361. JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,
  362. null, new Object[] { "Yes", "No" }, 0);
  363. if (y == 0)
  364. {
  365. loot.add("Guam seed");
  366. loot.add("Marrentill seed");
  367. loot.add("Tarromin seed");
  368. loot.add("Harralander seed");
  369. loot.add("Irit seed");
  370. loot.add("Avantoe seed");
  371. loot.add("Toadflax seed");
  372. loot.add("Onion seed");
  373. loot.add("Potato seed");
  374. loot.add("Cabbage seed");
  375. loot.add("Tomato seed");
  376. loot.add("Cadantine seed");
  377. }
  378.  
  379. Mouse.setSpeed(General.random(mouseSpeedMin, mouseSpeedMax));
  380. startXP = Skills.getXP(SKILLS.THIEVING);
  381. startLevel = Skills.getActualLevel(SKILLS.THIEVING);
  382. startTime = System.currentTimeMillis();
  383. }
  384.  
  385. private boolean isInBank()
  386. {
  387. return bankArea.contains(Player.getPosition());
  388. }
  389.  
  390. private boolean isBeingAttackedByGuard()
  391. {
  392. RSNPC[] guard = NPCs.find("Market Guard");
  393. if(guard.length > 0)
  394. {
  395. return guard[0].isInteractingWithMe();
  396. }
  397. return false;
  398. }
  399.  
  400. private boolean inventoryOnlyContainsFood()
  401. {
  402. RSItem[] inventoryItems = Inventory.getAll();
  403. for(int i = 0;i<inventoryItems.length;i++)
  404. {
  405. if(!inventoryItems[i].getDefinition().getName().contains(foodName))
  406. {
  407. return false;
  408. }
  409. }
  410. return true;
  411. }
  412.  
  413. private boolean isAnimating()
  414. {
  415. for (int i = 0; i < 20 && Player.getAnimation() == -1;i++)
  416. {
  417. sleep(20, 30);
  418. }
  419. return Player.getAnimation() != -1;
  420. }
  421.  
  422. private boolean hasFoodInBank()
  423. {
  424. RSItem[] foodInBank = Banking.find(foodName);
  425. return foodInBank.length > 0 && foodInBank[0] != null;
  426. }
  427.  
  428. private int distanceFromFarmer()
  429. {
  430. RSNPC[] farmer = NPCs.find("Master Farmer");
  431. if(farmer.length > 0 && farmer[0] != null)
  432. {
  433. return Player.getPosition().distanceTo(farmer[0].getPosition());
  434. }
  435. return 50;
  436. }
  437.  
  438. private void eatFood()
  439. {
  440. RSItem[] food = Inventory.find(foodName);
  441. if(food.length > 0)
  442. {
  443. food[0].click("Eat");
  444. }
  445. }
  446.  
  447. private void pickPocketNPC(String name)
  448. {
  449. RSNPC[] NPC = NPCs.find(name);
  450. if(NPC.length > 0)
  451. {
  452. if(name != "Man" && Player.getPosition().distanceTo(NPC[0].getPosition()) > 5)
  453. {
  454. Walking.walkTo(NPC[0]);
  455. }
  456. if(!NPC[0].isOnScreen())
  457. {
  458. Camera.turnToTile(NPC[0].getPosition());
  459. }
  460. DynamicClicking.clickRSNPC(NPC[0], "Pickpocket");
  461. }
  462. }
  463.  
  464. private boolean teaAvaliable()
  465. {
  466. RSObject[] teaStall = Objects.find(10, "Tea stall");
  467. return teaStall.length > 0 && teaStall[0] != null;
  468. }
  469.  
  470. private void dropAllTea()
  471. {
  472. Inventory.drop(new String[] {"Cup of tea"});
  473. RSObject[] teaStall = Objects.find(10, "Tea stall");
  474. if(teaStall.length > 0){
  475. teaStall[0].hover();
  476. }
  477. else{
  478. RSObject[] marketStall = Objects.find(10, "Market stall");
  479. if(marketStall.length > 0){
  480. marketStall[0].hover();
  481. }
  482. };
  483. long timeout = System.currentTimeMillis();
  484. while(timeout + 2000 > System.currentTimeMillis()
  485. && Inventory.getCount("Cup of tea") > 0)
  486. {
  487. sleep(20, 40);
  488. }
  489. }
  490.  
  491. private void stealTea()
  492. {
  493. if(Game.isUptext("Steal-from Tea stall")){
  494. Mouse.click(1);
  495. }
  496. else{
  497.  
  498. RSObject[] teaStall = Objects.find(10, "Tea stall");
  499. if(teaStall.length > 0){
  500. DynamicClicking.clickRSObject(teaStall[0], "Steal-from Tea stall");
  501. }
  502. }
  503. }
  504.  
  505. private void depositAllExceptFood()
  506. {
  507. Banking.depositAllExcept(foodName);
  508. long timeout = System.currentTimeMillis();
  509. while(timeout + 2000 > System.currentTimeMillis()
  510. && Inventory.getAll().length != Inventory.getCount(foodName))
  511. {
  512. sleep(20, 40);
  513. }
  514. }
  515.  
  516. private void dropJunk()
  517. {
  518. boolean dropItem;
  519. RSItem[] inventoryItems = Inventory.getAll();
  520. for(int i=0;i<inventoryItems.length;i++)
  521. {
  522. dropItem = true;
  523. for(int j=0;j<loot.size();j++)
  524. {
  525. if(inventoryItems[i].getDefinition().getName().contains(loot.get(j))
  526. ||inventoryItems[i].getDefinition().getName().contains(foodName))
  527. {
  528. dropItem = false;
  529. break;
  530. }
  531. }
  532. if(dropItem)
  533. {
  534. inventoryItems[i].click("Drop");
  535. }
  536. }
  537. stunned = false;
  538. }
  539.  
  540. private void walkToFarmerNPC()
  541. {
  542. RSNPC[] farmer = NPCs.find("Master Farmer");
  543. if(farmer.length > 0 && farmer[0] != null)
  544. {
  545. WebWalking.walkTo(farmer[0].getPosition());
  546. }
  547. else
  548. {
  549. WebWalking.walkTo(farmerTile);
  550. }
  551. }
  552.  
  553. @Override
  554. public void onPaint(Graphics g) {
  555. currentXP = Skills.getXP(SKILLS.THIEVING);
  556. currentLevel = Skills.getActualLevel(SKILLS.THIEVING);
  557. long timeRan = System.currentTimeMillis() - startTime;
  558. long xpGained = currentXP - startXP;
  559. double multiplier = timeRan / 3600000D;
  560. int xpPerHour = (int) (xpGained / multiplier);
  561. int levelsGained = currentLevel - startLevel;
  562. g.setColor(Color.WHITE);
  563. g.drawString("ITryNotToTroll's Thieving", 10, 70);
  564. g.drawString("Running for: " + Timing.msToString(timeRan), 10, 90);
  565. g.drawString("Levels Gained: " + levelsGained, 10, 110);
  566. g.drawString("Xp gained: " + xpGained + " (" + xpPerHour + "/h)", 10,
  567. 130);
  568. g.drawString("Version " + VERSION, 10, 150);
  569. g.drawString("Status: " + state, 10, 170);
  570.  
  571. }
  572.  
  573. @Override
  574. public void clanMessageReceived(String arg0, String arg1) {
  575. // TODO Auto-generated method stub
  576.  
  577. }
  578.  
  579. @Override
  580. public void duelRequestReceived(String arg0, String arg1) {
  581. // TODO Auto-generated method stub
  582.  
  583. }
  584.  
  585. @Override
  586. public void personalMessageReceived(String arg0, String arg1) {
  587. // TODO Auto-generated method stub
  588.  
  589. }
  590.  
  591. @Override
  592. public void playerMessageReceived(String arg0, String arg1) {
  593. // TODO Auto-generated method stub
  594.  
  595. }
  596.  
  597. @Override
  598. public void serverMessageReceived(String message) {
  599. if(message.contains("You've been stunned"))
  600. {
  601. stunned = true;
  602. }
  603.  
  604. }
  605.  
  606. @Override
  607. public void tradeRequestReceived(String arg0) {
  608. // TODO Auto-generated method stub
  609.  
  610. }
  611.  
  612. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement