Advertisement
Guest User

Louisssss

a guest
Aug 12th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.73 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.Button;
  3. import java.awt.Choice;
  4. import java.awt.Frame;
  5. import java.awt.GridLayout;
  6. import java.awt.Label;
  7. import java.awt.Panel;
  8. import java.awt.TextField;
  9. import java.awt.event.ActionEvent;
  10. import java.awt.event.ActionListener;
  11. import java.text.DecimalFormat;
  12. import java.util.Arrays;
  13. import java.util.Map;
  14. import java.util.TreeMap;
  15. import java.util.Iterator;
  16. import java.util.Locale;
  17. import static java.lang.System.currentTimeMillis;
  18.  
  19. import javax.swing.BoxLayout;
  20.  
  21. import com.aposbot.Constants;
  22. import com.aposbot.StandardCloseHandler;
  23.  
  24.  
  25. //Made by Abyte0
  26. //Modified by Justin 4/13/2017
  27.  
  28. /* What's Changed:
  29. - Script doesn't try to pick the chest to teleport if user isn't 72 thief.
  30. - Eat when your HP becomes < whatever your food heals
  31. - Fixed issue that's present in s_pickpocket; when you run out of food in bank if food is still in inventory continue until fully out.
  32. - Added GUI, code snippets from s_pickpocket/s_catherby/s_fighter
  33. - Loot stuff the paladins you kill drop, if drop is a DSQ & inv is full, eat food then loot.
  34. - Removed Abyte0_Script dependency & replaced use of parameters using frame code from s_fighter.
  35. */
  36.  
  37. public class Abyte0_Paladin extends Script
  38. implements ActionListener {
  39.  
  40. private final DecimalFormat iformat = new DecimalFormat("#,##0");
  41. private int[] start_xp = new int[SKILL.length];
  42.  
  43.  
  44. private static final int SKILL_HITS = 3;
  45. private static final int SKILL_THIEV = 17;
  46.  
  47. private static final Map<String, int[]> map_food;
  48.  
  49. static {
  50. map_food = new TreeMap<>();
  51. map_food.put("Swordfish", new int[] { 370 });
  52. map_food.put("Lobster", new int[] { 373 });
  53. map_food.put("Bass", new int[] { 555 });
  54. map_food.put("Shark", new int[] { 546 });
  55. map_food.put("Manta ray", new int[] { 1191 });
  56. map_food.put("Sea turtle", new int[] { 1193 });
  57. map_food.put("Cake", new int[] { 330, 333, 335 });
  58. map_food.put("Chocolate cake", new int[] { 332, 334, 336 });
  59. map_food.put("Meat pizza", new int[] { 326, 328 });
  60. map_food.put("Anchovy pizza", new int[] { 327, 329 });
  61. }
  62.  
  63. private static final int[] ids_loot = {
  64. 21,619,170,171,173,72,67,109,10,160,159,158,157,526,527,1277
  65. };
  66.  
  67. private static final int[] ids_bank = {
  68. 10,21,41,619,170,171,173,72,67,109,10,160,159,158,157,526,527,1277,427,545,160,154
  69. };
  70.  
  71. private int last_combat_x;
  72. private int last_combat_y;
  73.  
  74. private int[] ids_food;
  75. private int sleep_at;
  76. private long bank_time;
  77. private boolean init_path;
  78. private long move_time;
  79. private long menu_time;
  80. private int eat_at;
  81.  
  82. private int[] bank_counts = new int[ids_bank.length];
  83. private boolean[] has_banked = new boolean[ids_bank.length];
  84.  
  85.  
  86. private Frame frame;
  87. private Choice ch_fm;
  88. private Choice ch_food;
  89. private TextField tf_food;
  90. private TextField tf_eat;
  91. private TextField tf_sleep;
  92.  
  93. private long start_time;
  94. private int levels_gained;
  95. private int total_withdraw;
  96.  
  97. private int paint_max_y;
  98.  
  99. int fightMode = 3;
  100. boolean chestReady = true;
  101. boolean canLootChest = true;
  102.  
  103. int[] npcID = new int[]
  104. {
  105. 323 //Paladin
  106. };
  107.  
  108. public Abyte0_Paladin(Extension e) {super(e);}
  109.  
  110. public static void main(String[] argv) {
  111. Abyte0_Paladin p = new Abyte0_Paladin(null);
  112. p.init(null);
  113. }
  114.  
  115. public void init(String params)
  116. {
  117. for (int i = 0; i < start_xp.length; ++i) {
  118. start_xp[i] = getXpForLevel(i);
  119. }
  120.  
  121. if(getLevel(SKILL_THIEV)<72) {
  122. canLootChest = false;
  123. }
  124.  
  125. Arrays.fill(has_banked, false);
  126. Arrays.fill(bank_counts, 0);
  127. total_withdraw = 0;
  128. levels_gained = 0;
  129. move_time = -1L;
  130. bank_time = -1L;
  131. menu_time = -1L;
  132. start_time = -1L;
  133. init_path = false;
  134. if (frame == null) {
  135.  
  136. ch_fm = new Choice();
  137. for (String str : FIGHTMODES) {
  138. ch_fm.add(str);
  139. }
  140.  
  141. Iterator<String> sit;
  142.  
  143. ch_food = new Choice();
  144. sit = map_food.keySet().iterator();
  145. while (sit.hasNext()) {
  146. ch_food.add(sit.next());
  147. }
  148.  
  149. Panel pInput = new Panel(new GridLayout(0, 2, 2, 2));
  150. pInput.add(new Label("Combat style:"));
  151. pInput.add(ch_fm);
  152. pInput.add(new Label("Withdraw food:"));
  153. pInput.add(ch_food);
  154. pInput.add(new Label("What does food heal? Lobs: 12, Shark: 20"));
  155. pInput.add(tf_eat = new TextField("12"));
  156. pInput.add(new Label("Sleep at fatigue %:"));
  157. pInput.add(tf_sleep = new TextField("95"));
  158.  
  159. ch_food.setEnabled(true);
  160.  
  161. Button button;
  162. Panel pButtons = new Panel();
  163. button = new Button("OK");
  164. button.addActionListener(this);
  165. pButtons.add(button);
  166. button = new Button("Cancel");
  167. button.addActionListener(this);
  168. pButtons.add(button);
  169.  
  170. frame = new Frame(getClass().getSimpleName());
  171. frame.setLayout(new BoxLayout(frame, BoxLayout.Y_AXIS));
  172. frame.addWindowListener(
  173. new StandardCloseHandler(frame, StandardCloseHandler.HIDE)
  174. );
  175. frame.setIconImages(Constants.ICONS);
  176. frame.add(pInput, BorderLayout.NORTH);
  177. frame.add(new Label(
  178. "Start this script in east bank or 2nd floor ardy castle.",
  179. Label.CENTER
  180. ), BorderLayout.SOUTH);
  181. frame.add(pButtons, BorderLayout.SOUTH);
  182. frame.setResizable(false);
  183. frame.pack();
  184. }
  185. frame.setLocationRelativeTo(null);
  186. frame.toFront();
  187. frame.requestFocus();
  188. frame.setVisible(true);
  189. }
  190.  
  191. public int main()
  192. {
  193. if (start_time == -1L) {
  194. start_time = System.currentTimeMillis();
  195. }
  196. int ideal_fm = ch_fm.getSelectedIndex();
  197. if (getFightMode() != ideal_fm) {
  198. setFightMode(ideal_fm);
  199. return random(400, 600);
  200. }
  201. if(inCombat())
  202. {
  203. last_combat_x = getX();
  204. last_combat_y = getY();
  205. walkTo(getX(), getY());
  206. return random(400, 600);
  207. }
  208.  
  209. //Current HP is less than max heal of your food
  210. if (getCurrentLevel(SKILL_HITS) <= eat_at) {
  211. int slot = getFoodSlot();
  212. if (slot != -1) {
  213. useItem(slot);
  214. return random(800, 1000);
  215. }
  216. }
  217.  
  218. if (getFatigue() >= sleep_at) {
  219. useSleepingBag();
  220. return random(2000, 3000);
  221. }
  222.  
  223. if (move_time != -1L && System.currentTimeMillis() >= move_time) {
  224. System.out.println("Moving for 5 min timer");
  225. walk_approx(getX(), getY(), 1);
  226. move_time = -1L;
  227. return random(1500, 2500);
  228. }
  229.  
  230. if (isQuestMenu()) {
  231. answer(0);
  232. menu_time = -1L;
  233. bank_time = System.currentTimeMillis();
  234. return random(600, 800);
  235. } else if (menu_time != -1L) {
  236. if (System.currentTimeMillis() >= (menu_time + 8000L)) {
  237. menu_time = -1L;
  238. }
  239. return random(300, 400);
  240. }
  241.  
  242. if(isBanking()) {
  243. bank_time = -1L;
  244. int array_sz = ids_bank.length;
  245. for (int i = 0; i < array_sz; ++i) {
  246. int count = getInventoryCount(ids_bank[i]);
  247. if (count > 0) {
  248. deposit(ids_bank[i], count);
  249. if (!has_banked[i]) {
  250. bank_counts[i] += count;
  251. has_banked[i] = true;
  252. }
  253. return random(1000, 2000);
  254. }
  255. }
  256.  
  257. //Take out max food
  258. int food_count = getInventoryCount(ids_food);
  259. if (food_count < 28 - getInventoryCount()) {
  260. for (int id : ids_food) {
  261. int bank_count = bankCount(id);
  262. if (bank_count <= 0) continue;
  263. int w = 28 - getInventoryCount() - food_count;
  264. if (w > bank_count) w = bank_count;
  265. total_withdraw += w;
  266. withdraw(id, w);
  267. return random(1000, 2000);
  268. }
  269. // should not log out if there is still food in inventory
  270. if (getInventoryCount(ids_food) <= 0) {
  271. System.out.println("ERROR: Out of food!");
  272. stopScript(); setAutoLogin(false);
  273. return 0;
  274. }
  275. }
  276.  
  277.  
  278. Arrays.fill(has_banked, false);
  279. closeBank();
  280.  
  281. return random(500, 600);
  282.  
  283. } else if (bank_time != -1L) {
  284. if (System.currentTimeMillis() >= (bank_time + 8000L)) {
  285. bank_time = -1L;
  286. }
  287. return random(300, 400);
  288.  
  289. }
  290.  
  291. //Loot stuffs
  292. int[] item = getItemById(ids_loot);
  293. if ((item[1] == getX() && item[2] == getY()) ||
  294. (item[1] == last_combat_x && item[2] == last_combat_y)) {
  295. if (getInventoryCount() < MAX_INV_SIZE ||
  296. (getInventoryIndex(item[0]) != -1 &&
  297. isItemStackableId(item[0]))) {
  298. pickupItem(item[0], item[1], item[2]);
  299. return random(600, 1000);
  300. }
  301. if (item[0] == 1127) {
  302. int slot = getFoodSlot();
  303. if (slot != -1) {
  304. useItem(slot);
  305. return random(800, 1000);
  306. }
  307. }
  308. }
  309.  
  310. if(getInventoryCount(ids_food) > 0) {
  311. if(getHpPercent() < 30)
  312. {
  313. System.out.println("hp is dangerously low with no food.");
  314. setAutoLogin(false);
  315. stopScript();
  316. return 0;
  317. }
  318.  
  319. //are we near paladins
  320. if(getX() >= 602 && getX() <= 615 && getY() >= 1548)
  321. {
  322. int[] npc = getNpcById(npcID);
  323. if(npc[0] != -1)
  324. {
  325. thieveNpc(npc[0]);
  326. chestReady = true;
  327. return random(500, 1000);
  328. }
  329. }
  330. else
  331. {
  332. int[] doorObj;
  333. int[] stairs;
  334.  
  335. if(getX() == 551 && getY() == 612)
  336. {
  337. stairs = getObjectById(64);
  338. if(stairs[0] != -1)
  339. {
  340. atObject(stairs[1], stairs[2]);
  341. return random(1000,1200);
  342. }
  343. walkTo(550,612);
  344. return random(600,800);
  345. }
  346.  
  347. //behind steps to climb
  348. if(getX() == 613 && getY() == 601)
  349. {
  350. stairs = getObjectById(342);
  351. if(stairs[0] != -1)
  352. {
  353. atObject(stairs[1], stairs[2]);
  354. return random(1500,3200);
  355. }
  356. }
  357.  
  358. //in bank
  359. if(getX() >= 551 && getX() <= 554 && getY() >= 609 && getY() <= 616)
  360. {
  361. walkTo(551,612);
  362. return random(600,800);
  363. }
  364.  
  365. if(getX() >= 608 && getY() >= 597 && getY() <= 609)
  366. {
  367. walkTo(613,601);
  368. return random(400,1300);
  369. }
  370. //Top of steps
  371. if(getX() >= 602 && getX() <= 615 && getY() > 1500 && getY() < 1548)
  372. {
  373. int[] door = getWallObjectById(97);
  374. if(door[0] != -1 && isAtApproxCoords(door[1], door[2],5))
  375. {
  376. atWallObject2(door[1], door[2]);
  377. return random(1000, 1500);
  378. }
  379. }
  380.  
  381. //On way to zoo
  382. if(getX() < 567)
  383. {
  384. walkTo(567,606);
  385. return random(500,1000);
  386. }
  387. //general store
  388. if(getX() < 580)
  389. {
  390. walkTo(580,606);
  391. return random(500,1000);
  392. }
  393. //to door
  394. if(getX() < 598)
  395. {
  396. walkTo(598,604);
  397. return random(500,1000);
  398. }
  399. if(getX() < 599)
  400. {
  401. //Passing the Metal Gate
  402. stairs = getObjectById(57);
  403. if(stairs[0] != -1 && isAtApproxCoords(stairs[1], stairs[2],10))
  404. {
  405. atObject(stairs[1], stairs[2]);
  406. return random(800,1000);
  407. }
  408. walkTo(599,604);
  409. return random(500,1000);
  410. }
  411. if(getX() < 608)
  412. {
  413. //Passing the Wooden Door
  414. stairs = getObjectById(64);
  415. if(stairs[0] != -1)
  416. {
  417. if(stairs[1] >= 605 && stairs[1] <= 610 && stairs[2] >= 600 && stairs[2] <= 608)
  418. {
  419. atObject(stairs[1], stairs[2]);
  420. return random(800,1000);
  421. }
  422. }
  423. walkTo(608,604);
  424. return random(500,1000);
  425. }
  426. }
  427. return 500;
  428. }
  429. else
  430. {
  431. int[] doorObj;
  432. int[] stairs;
  433.  
  434. if(getX() >= 602 && getX() <= 615 && getY() >= 1548 && getY() <= 1648)
  435. {
  436. //If the chest is ready we go up and teleport
  437. if(chestReady && canLootChest)
  438. {
  439. stairs = getObjectById(5);
  440. if(stairs[0] != -1 && isAtApproxCoords(stairs[1], stairs[2],10))
  441. {
  442. atObject(stairs[1], stairs[2]);
  443. return random(1500,3200);
  444. }
  445. }
  446. else
  447. {
  448. doorObj = getWallObjectById(97);
  449. if(doorObj[0] != -1 && isAtApproxCoords(doorObj[1], doorObj[2],10))
  450. {
  451. atWallObject(doorObj[1], doorObj[2]);
  452. return random(1000,1200);
  453. }
  454. }
  455. return random(800,900);
  456. }
  457.  
  458. //bank walk
  459. if(getX() == 550)
  460. {
  461. stairs = getObjectById(64);
  462. if(stairs[0] != -1 && isAtApproxCoords(stairs[1], stairs[2],5))
  463. {
  464. atObject(stairs[1], stairs[2]);
  465. return random(1000,1200);
  466. }
  467. walkTo(551,612);
  468. return random(600,800);
  469. }
  470. //in the bank
  471. if(getX() >= 551 && getX() <= 554 && getY() >= 609 && getY() <= 616)
  472. {
  473. int banker[] = getNpcByIdNotTalk(BANKERS);
  474. if(banker[0] != -1)
  475. {
  476. talkToNpc(banker[0]);
  477. return 1000;
  478. }
  479. }
  480.  
  481. //-----
  482. //Walking To Bank Manualy
  483. //-----
  484.  
  485. //We at chest
  486. if(isAtApproxCoords(611,2491,10))
  487. {
  488. int[] groundItem = getItemById(427);
  489. if(groundItem[0] != -1)
  490. {
  491. pickupItem(groundItem[0], groundItem[1], groundItem[2]);
  492. return random(1000, 1500);
  493. }
  494. //chest isn't ready for us
  495. if(getObjectIdFromCoords(610,2487) != 338)
  496. {
  497. chestReady = false;
  498. stairs = getObjectById(6);
  499. if(stairs[0] != -1)
  500. {
  501. atObject(stairs[1], stairs[2]);
  502. return random(1000,1200);
  503. }
  504. }
  505. else
  506. {
  507. System.out.println("loot the chest PLZ");
  508. atObject2(610,2487);
  509. return random(2000,3000);
  510. }
  511. }
  512. //Down the stairs we go
  513. if(getX() >= 602 && getX() <= 615 && getY() > 1500 && getY() < 1548)
  514. {
  515. stairs = getObjectById(44);
  516. if(stairs[0] != -1)
  517. {
  518. atObject(stairs[1], stairs[2]);
  519. return random(1000,1200);
  520. }
  521. }
  522. //Near stairs, exit castle
  523. if(getX() >= 608 && getY() >= 597 && getY() <= 609)
  524. {
  525. //Passing the Wooden Door
  526. stairs = getObjectById(64);
  527. if(stairs[0] != -1 && isAtApproxCoords(stairs[1], stairs[2],5))
  528. {
  529. atObject(stairs[1], stairs[2]);
  530. return random(800,1000);
  531. }
  532. walkTo(607,604);
  533. return random(500,1000);
  534. }
  535. //Near warriors
  536. if(getX() >= 599)
  537. {
  538. //Passing the Metal Gate
  539. stairs = getObjectById(57);
  540. if(stairs[0] != -1 && isAtApproxCoords(stairs[1], stairs[2],10))
  541. {
  542. atObject(stairs[1], stairs[2]);
  543. return random(800,1000);
  544. }
  545. walkTo(598,604);
  546. return random(500,1000);
  547. }
  548. //just keep walking
  549. if(getX() >= 585)
  550. {
  551. walkTo(584,606);
  552. return random(500,1000);
  553. }
  554. //see animals
  555. if(getX() >= 570)
  556. {
  557. walkTo(569,606);
  558. return random(500,1000);
  559. }
  560. //more animals
  561. if(getX() >= 551)
  562. {
  563. walkTo(550,608);
  564. return random(500,1000);
  565. }
  566.  
  567. //-----
  568. //----- Walking to Bank By Teleport
  569. //-----
  570.  
  571. //Si on est proche du Teleport
  572. if(isAtApproxCoords(523,606,5))
  573. {
  574. walkTo(528,615);
  575. return random(500,1000);
  576. }
  577. //Chickens spotted
  578. if(getX() <= 542)
  579. {
  580. walkTo(543,615);
  581. return random(500,1000);
  582. }
  583. //Boat spotted almost there.
  584. if(getX() <= 549)
  585. {
  586. walkTo(550,612);
  587. return random(500,1000);
  588. }
  589. return 500;
  590. }
  591. }
  592.  
  593. private void walk_approx(int x, int y, int range) {
  594. int dx, dy;
  595. int loop = 0;
  596. do {
  597. dx = x + random(-range, range);
  598. dy = y + random(-range, range);
  599. if ((++loop) > 1000) return;
  600. } while ((dx == getX() && dy == getY()) ||
  601. !isReachable(dx, dy));
  602. walkTo(dx, dy);
  603. }
  604.  
  605. @Override
  606. public void paint() {
  607. if (start_time == -1L) {
  608. return;
  609. }
  610.  
  611. final int orangey = 0xFFD900;
  612. final int white = 0xFFFFFF;
  613. int x = (512 / 2) - 50;
  614. int y = 60;
  615. drawBoxAlphaFill(x - 8, y - 18, 300, paint_max_y - y, 120, 0x0);
  616. drawString("Abyte0 Paladin (Updated by Justin)", x, y, 1, orangey);
  617. y += 15;
  618. drawString("Runtime: " + get_time_since(start_time),
  619. x + 10, y, 1, white);
  620. y += 15;
  621. drawString(String.format("Current Level: %d (Gained: %d) ",getLevel(SKILL_THIEV),
  622. levels_gained),
  623. x, y, 1, orangey);
  624. y += 15;
  625. if (total_withdraw != 0) {
  626. drawString(String.format("%s food withdrawn",
  627. iformat.format(total_withdraw)),
  628. x + 10, y, 1, white);
  629. y += 15;
  630. }
  631. drawString("XP Gained:", x, y, 1, orangey);
  632. y += 15;
  633.  
  634. for (int i = 0; i < start_xp.length; ++i) {
  635. int gained = getXpForLevel(i) - start_xp[i];
  636. if (gained == 0) continue;
  637. drawString(String.format("%s XP gained: %s (%s/h)",
  638. SKILL[i], iformat.format(gained), per_hour(gained)),
  639. x, y, 2, 0xFFFFFF);
  640. y += 15;
  641. }
  642.  
  643. drawString("Items Banked:", x, y, 1, orangey);
  644. y += 15;
  645. for (int i = 0; i < ids_bank.length; ++i) {
  646. if (bank_counts[i] == 0) continue;
  647. drawString(String.format("%s banked: %s (%s/h)",
  648. getItemNameId(ids_bank[i]),
  649. iformat.format(bank_counts[i]),
  650. per_hour(bank_counts[i])),
  651. x, y, 2, 0xFFFFFF);
  652. y += 15;
  653. }
  654. paint_max_y = y + 15;
  655. }
  656.  
  657. private String per_hour(int count) {
  658. double amount, secs;
  659.  
  660. if (count == 0) return "0";
  661. amount = count * 60.0 * 60.0;
  662. secs = (currentTimeMillis() - start_time) / 1000.0;
  663. return iformat.format(amount / secs);
  664. }
  665.  
  666. private static String get_time_since(long t) {
  667. long millis = (System.currentTimeMillis() - t) / 1000;
  668. long second = millis % 60;
  669. long minute = (millis / 60) % 60;
  670. long hour = (millis / (60 * 60)) % 24;
  671. long day = (millis / (60 * 60 * 24));
  672.  
  673. if (day > 0L) {
  674. return String.format("%02d days, %02d hrs, %02d mins",
  675. day, hour, minute);
  676. }
  677. if (hour > 0L) {
  678. return String.format("%02d hours, %02d mins, %02d secs",
  679. hour, minute, second);
  680. }
  681. if (minute > 0L) {
  682. return String.format("%02d minutes, %02d seconds",
  683. minute, second);
  684. }
  685. return String.format("%02d seconds", second);
  686. }
  687.  
  688. @Override
  689. public void onServerMessage(String str) {
  690. str = str.toLowerCase(Locale.ENGLISH);
  691. if (str.contains("standing here")) {
  692. move_time = (System.currentTimeMillis() + random(1500, 1800));
  693. } else if (str.contains("busy")) {
  694. menu_time = -1L;
  695. } else if (str.contains("advanced")) {
  696. System.out.println("You just advanced a level.");
  697. System.out.print("Runtime: ");
  698. System.out.println(get_time_since(start_time));
  699. ++levels_gained;
  700. }
  701.  
  702. }
  703.  
  704. private int getFoodSlot() {
  705. int count = getInventoryCount();
  706. for (int i = 0; i < count; i++) {
  707. if (getItemCommand(i).toLowerCase(Locale.ENGLISH).equals("eat")) {
  708. return i;
  709. }
  710. }
  711. return -1;
  712. }
  713.  
  714. @Override
  715. public void actionPerformed(ActionEvent e) {
  716. if (e.getActionCommand().equals("OK")) {
  717. eat_at = getLevel(SKILL_HITS) - Integer.parseInt(tf_eat.getText());
  718. sleep_at = Integer.parseInt(tf_sleep.getText());
  719. ids_food = map_food.get(ch_food.getSelectedItem());
  720. }
  721. frame.setVisible(false);
  722. }
  723. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement