Guest User

Untitled

a guest
Dec 15th, 2014
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.84 KB | None | 0 0
  1. import org.osbot.rs07.api.Inventory;
  2. import org.osbot.rs07.api.model.GroundItem;
  3. import org.osbot.rs07.api.ui.Skill;
  4. import org.osbot.rs07.script.Script;
  5. import org.osbot.rs07.script.ScriptManifest;
  6.  
  7. import java.awt.*;
  8. import java.io.IOException;
  9. import java.net.URL;
  10. import java.util.concurrent.TimeUnit;
  11.  
  12. import javax.imageio.ImageIO;
  13.  
  14. import java.awt.event.*;
  15.  
  16. import javax.swing.*;
  17.  
  18. @ScriptManifest(name = "AFKer", author = "Computor", version = 1.0, info = "", logo = "")
  19. public class AFKer extends Script {
  20.  
  21. private long timeBegan;
  22. private int xpPerHour;
  23. boolean test = true;
  24. public int totalXPGained;
  25. public String[] temp;
  26.  
  27. //GUI
  28. botGUI g = new botGUI();
  29. AFKerItems g2 = new AFKerItems();
  30. public boolean guiWait = true;
  31. public String foodToEat;
  32. public int skillDisplay;
  33. //end GUI
  34.  
  35. private int beginningAttack;
  36. private int currentAttackXp;
  37. private int currentAttackLevel;
  38. private int attackXpGained;
  39. private double nextAttackLevelXp;
  40. private long timeAttackTNL;
  41. private double xpTillNextAttackLevel;
  42.  
  43. private int beginningHitpoints;
  44. private int currentHitpointsXp;
  45. private int hitpointsXpGained;
  46.  
  47. private int beginningStrength;
  48. private int currentStrengthXp;
  49. private int currentStrengthLevel;
  50. private int strengthXpGained;
  51. private double nextStrengthLevelXp;
  52. private long timeStrengthTNL;
  53. private double xpTillNextStrengthLevel;
  54.  
  55. private int beginningDefense;
  56. private int currentDefenseXp;
  57. private int currentDefenseLevel;
  58. private int defenseXpGained;
  59. private double nextDefenseLevelXp;
  60. private long timeDefenseTNL;
  61. private double xpTillNextDefenseLevel;
  62.  
  63.  
  64. final int[] XP_TABLE =
  65. {
  66. 0, 0, 83, 174, 276, 388, 512, 650, 801, 969, 1154,
  67. 1358, 1584, 1833, 2107, 2411, 2746, 3115, 3523, 3973, 4470, 5018,
  68. 5624, 6291, 7028, 7842, 8740, 9730, 10824, 12031, 13363, 14833,
  69. 16456, 18247, 20224, 22406, 24815, 27473, 30408, 33648, 37224,
  70. 41171, 45529, 50339, 55649, 61512, 67983, 75127, 83014, 91721,
  71. 101333, 111945, 123660, 136594, 150872, 166636, 184040, 203254,
  72. 224466, 247886, 273742, 302288, 333804, 368599, 407015, 449428,
  73. 496254, 547953, 605032, 668051, 737627, 814445, 899257, 992895,
  74. 1096278, 1210421, 1336443, 1475581, 1629200, 1798808, 1986068,
  75. 2192818, 2421087, 2673114, 2951373, 3258594, 3597792, 3972294,
  76. 4385776, 4842295, 5346332, 5902831, 6517253, 7195629, 7944614,
  77. 8771558, 9684577, 10692629, 11805606, 13034431, 200000000
  78. };
  79.  
  80. //paint background
  81. private final Image bg = getImage("http://s12.postimg.org/wty7h6sb1/AFKer.png");
  82. private final Image bg1 = getImage("http://s1.postimg.org/hoow91tdb/Untitled_1.png");
  83. public JTextPane itemsToPickUp;
  84. private Image getImage(String url)
  85. {
  86. try
  87. {
  88. return ImageIO.read(new URL(url));
  89. }
  90. catch (IOException e) {}
  91. return null;
  92. }
  93. //end paint background
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100. @Override
  101. public void onStart() {
  102. //Code here will execute before the loop is started
  103. timeBegan = System.currentTimeMillis();
  104. beginningAttack = skills.getExperience(Skill.ATTACK);
  105. beginningHitpoints = skills.getExperience(Skill.HITPOINTS);
  106. beginningStrength = skills.getExperience(Skill.STRENGTH);
  107. beginningDefense = skills.getExperience(Skill.DEFENCE);
  108. timeAttackTNL = 0;
  109. timeStrengthTNL = 0;
  110. timeDefenseTNL = 0;
  111.  
  112. g2.setVisible(true);
  113. g.setVisible(true);
  114. }
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122. @Override
  123. public void onExit() {
  124. //Code here will execute after the script ends
  125. /**
  126. log("End of Computor's AFKer."); //logs in console
  127. log("----------------------------------------------------------------------------------------");
  128. log("You gained a total of " + totalXPGained + " XP, " + attackXpGained +
  129. " attack XP, " + strengthXpGained + " strength XP, and " + defenseXpGained + "defence XP.");
  130. log("----------------------------------------------------------------------------------------");
  131. */
  132. //for some reason the script takes forever to exit when I use the logs.
  133. }
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141. @Override
  142. public int onLoop() throws InterruptedException
  143. {
  144. int currentHP = skills.getDynamic(Skill.HITPOINTS);
  145. final int timeToEat = skills.getStatic(Skill.HITPOINTS) / 2;
  146.  
  147. if (currentHP <= timeToEat)
  148. if(foodToEat != null){
  149. inventory.interact("Eat", foodToEat);
  150. if(!inventory.contains(foodToEat)){
  151. Toolkit.getDefaultToolkit().beep();
  152. }
  153. }
  154. for (int i = 0; i < temp.length; i++){
  155. if (groundItems.closest(temp[i]) != null) {
  156. GroundItem loot = groundItems.closest(temp[i]);
  157. loot.interact("Take");
  158. }
  159. }
  160.  
  161. return random(0, 123);
  162. }
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170. @Override
  171. public void onPaint(Graphics2D g) {
  172. //This is where you will put your code for paint(s)
  173. //background paint
  174. Graphics2D gr = g;
  175. g.drawImage(bg, 4, 341, null);
  176.  
  177. if (test == false){
  178. if(!inventory.contains(foodToEat)){
  179. g.drawImage(bg1, 1, 1, null);
  180. }
  181. }
  182. //attack
  183. currentAttackXp = skills.getExperience(Skill.ATTACK);
  184. currentAttackLevel = skills.getStatic(Skill.ATTACK);
  185. attackXpGained = currentAttackXp - beginningAttack;
  186. xpPerHour = (int)( attackXpGained / ((System.currentTimeMillis() - this.timeBegan) / 3600000.0D));
  187. nextAttackLevelXp = XP_TABLE[currentAttackLevel + 1];
  188. xpTillNextAttackLevel = nextAttackLevelXp - currentAttackXp;
  189. if (attackXpGained >= 1)
  190. {
  191. timeAttackTNL = (long) ((xpTillNextAttackLevel / xpPerHour) * 3600000);
  192. }
  193.  
  194. if (skillDisplay == 1){
  195. g.drawString("" + ft(timeAttackTNL), 377, 427);
  196. }
  197. g.drawString("" + attackXpGained, 203, 427);
  198.  
  199. //strength
  200. currentStrengthXp = skills.getExperience(Skill.STRENGTH);
  201. currentStrengthLevel = skills.getStatic(Skill.STRENGTH);
  202. strengthXpGained = currentStrengthXp - beginningStrength;
  203. xpPerHour = (int)( strengthXpGained / ((System.currentTimeMillis() - this.timeBegan) / 3600000.0D));
  204. nextStrengthLevelXp = XP_TABLE[currentStrengthLevel + 1];
  205. xpTillNextStrengthLevel = nextStrengthLevelXp - currentStrengthXp;
  206. if (strengthXpGained >= 1)
  207. {
  208. timeStrengthTNL = (long) ((xpTillNextStrengthLevel / xpPerHour) * 3600000);
  209. }
  210.  
  211. if (skillDisplay == 2){
  212. g.drawString("" + ft(timeStrengthTNL), 377, 427);
  213. }
  214. g.drawString("" + strengthXpGained,220, 458);
  215.  
  216. //Defence
  217. currentDefenseXp = skills.getExperience(Skill.DEFENCE);
  218. currentDefenseLevel = skills.getStatic(Skill.DEFENCE);
  219. defenseXpGained = currentDefenseXp - beginningDefense;
  220. xpPerHour = (int)( defenseXpGained / ((System.currentTimeMillis() - this.timeBegan) / 3600000.0D));
  221. nextDefenseLevelXp = XP_TABLE[currentDefenseLevel + 1];
  222. xpTillNextDefenseLevel = nextDefenseLevelXp - currentDefenseXp;
  223. if (defenseXpGained >= 1)
  224. {
  225. timeDefenseTNL = (long) ((xpTillNextDefenseLevel / xpPerHour) * 3600000);
  226. }
  227.  
  228. if (skillDisplay == 3){
  229. g.drawString("" + ft(timeDefenseTNL), 377, 427);
  230. }
  231. g.drawString("" + defenseXpGained, 432, 401);
  232.  
  233. //hitpoints
  234. currentHitpointsXp = skills.getExperience(Skill.HITPOINTS);
  235. hitpointsXpGained = currentHitpointsXp - beginningHitpoints;
  236. g.drawString("" + hitpointsXpGained, 439, 458);
  237.  
  238. int totalxp = attackXpGained + strengthXpGained + hitpointsXpGained + defenseXpGained;
  239. g.drawString("" + totalxp, 249, 401);
  240. totalXPGained = totalxp;
  241.  
  242. }
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249. private String ft(long duration)
  250. {
  251. String res = "";
  252. long days = TimeUnit.MILLISECONDS.toDays(duration);
  253. long hours = TimeUnit.MILLISECONDS.toHours(duration)
  254. - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration));
  255. long minutes = TimeUnit.MILLISECONDS.toMinutes(duration)
  256. - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS
  257. .toHours(duration));
  258. long seconds = TimeUnit.MILLISECONDS.toSeconds(duration)
  259. - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS
  260. .toMinutes(duration));
  261. if (days == 0)
  262. {
  263. if (minutes < 10 && seconds < 10){
  264. res = (hours + ":0" + minutes + ":0" + seconds);
  265. }
  266. if (minutes < 10 && seconds >= 10){
  267. res = (hours + ":0" + minutes + ":" + seconds);
  268. }
  269. if (minutes >= 10 && seconds < 10){
  270. res = (hours + ":" + minutes + ":0" + seconds);
  271. }
  272.  
  273. if (minutes >= 10 && seconds >= 10){
  274. res = (hours + ":" + minutes + ":" + seconds);
  275. }
  276. }
  277. if (days > 0)
  278. {
  279. if (minutes < 10 && seconds < 10){
  280. res = (days + ":" + hours + ":0" + minutes + ":0" + seconds);
  281. }
  282. if (minutes < 10 && seconds >= 10){
  283. res = (days + ":" + hours + ":0" + minutes + ":" + seconds);
  284. }
  285. if (minutes >= 10 && seconds < 10){
  286. res = (days + ":" + hours + ":" + minutes + ":0" + seconds);
  287. }
  288.  
  289. if (minutes >= 10 && seconds >= 10){
  290. res = (days + ":" + hours + ":" + minutes + ":" + seconds);
  291. }
  292. }
  293. return res;
  294. }
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313. class AFKerItems extends JFrame {
  314. public AFKerItems() {
  315. initComponents();
  316. }
  317.  
  318. private void thisWindowClosed(WindowEvent e) {
  319. temp = itemsToPickUp.getText().split("\n");
  320. }
  321.  
  322. private void initComponents() {
  323. label1 = new JLabel();
  324. scrollPane1 = new JScrollPane();
  325. itemsToPickUp = new JTextPane();
  326. textPane2 = new JTextPane();
  327. textPane3 = new JTextPane();
  328.  
  329. //======== this ========
  330. setResizable(false);
  331. setBackground(Color.white);
  332. addWindowListener(new WindowAdapter() {
  333. @Override
  334. public void windowClosed(WindowEvent e) {
  335. thisWindowClosed(e);
  336. }
  337. });
  338. Container contentPane = getContentPane();
  339. contentPane.setLayout(null);
  340.  
  341. //---- label1 ----
  342. label1.setText("What would you like to pick up?");
  343. label1.setFont(new Font("Source Sans Pro Black", Font.BOLD, 16));
  344. contentPane.add(label1);
  345. label1.setBounds(new Rectangle(new Point(25, 20), label1.getPreferredSize()));
  346.  
  347. //======== scrollPane1 ========
  348. {
  349. scrollPane1.setViewportView(itemsToPickUp);
  350. }
  351. contentPane.add(scrollPane1);
  352. scrollPane1.setBounds(25, 60, 215, 105);
  353.  
  354. //---- textPane2 ----
  355. textPane2.setText("Put items in here followed by an indent.\nThe items MUST BE CASE SENSITIVE.\n\nExample:\nLobster\nBones\nFire rune\nCoins");
  356. textPane2.setEditable(false);
  357. textPane2.setBackground(UIManager.getColor("ColorChooser.background"));
  358. contentPane.add(textPane2);
  359. textPane2.setBounds(250, 60, 225, 115);
  360.  
  361. //---- textPane3 ----
  362. textPane3.setText("Press start on other window when ready to begin bot.");
  363. textPane3.setEditable(false);
  364. textPane3.setBackground(UIManager.getColor("ColorChooser.background"));
  365. textPane3.setFont(new Font("Tahoma", Font.BOLD, 18));
  366. contentPane.add(textPane3);
  367. textPane3.setBounds(125, 225, 295, 85);
  368.  
  369. contentPane.setPreferredSize(new Dimension(515, 360));
  370. pack();
  371. setLocationRelativeTo(getOwner());
  372. }
  373.  
  374. private JLabel label1;
  375. private JScrollPane scrollPane1;
  376. private JTextPane itemsToPickUp;
  377. private JTextPane textPane2;
  378. private JTextPane textPane3;
  379. }
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397. class botGUI extends JFrame {
  398. public botGUI() {
  399. initComponents();
  400. }
  401.  
  402. private void startButtonActionPerformed(ActionEvent e) {
  403.  
  404. foodToEat = whatToEat.getText().toString();
  405. if (whatToAttack.getText().equalsIgnoreCase("Attack")){
  406. skillDisplay = 1;
  407. }
  408. if (whatToAttack.getText().equalsIgnoreCase("Strength")){
  409. skillDisplay = 2;
  410. }
  411. if (whatToAttack.getText().equalsIgnoreCase("Defence")){
  412. skillDisplay = 3;
  413. }
  414.  
  415. g2.dispose();
  416. g.dispose();
  417. test = false;
  418. }
  419. private void initComponents() {
  420. startButton = new JButton();
  421. label1 = new JLabel();
  422. whatToEat = new JTextField();
  423. label2 = new JLabel();
  424. whatToAttack = new JTextField();
  425.  
  426. //======== this ========
  427. setAlwaysOnTop(true);
  428. setResizable(false);
  429. setTitle("Computor's AFKer");
  430. Container contentPane = getContentPane();
  431. contentPane.setLayout(null);
  432.  
  433. //---- startButton ----
  434. startButton.setText("Start");
  435. startButton.addActionListener(new ActionListener() {
  436. @Override
  437. public void actionPerformed(ActionEvent e) {
  438. startButtonActionPerformed(e);
  439. }
  440. });
  441. contentPane.add(startButton);
  442. startButton.setBounds(87, 175, 210, 65);
  443.  
  444. //---- label1 ----
  445. label1.setText("What are you going to train? (Attack, Strength, Defence)");
  446. contentPane.add(label1);
  447. label1.setBounds(new Rectangle(new Point(35, 40), label1.getPreferredSize()));
  448. contentPane.add(whatToEat);
  449. whatToEat.setBounds(35, 120, 130, whatToEat.getPreferredSize().height);
  450.  
  451. //---- label2 ----
  452. label2.setText("Enter any food name here:");
  453. contentPane.add(label2);
  454. label2.setBounds(new Rectangle(new Point(35, 100), label2.getPreferredSize()));
  455. contentPane.add(whatToAttack);
  456. whatToAttack.setBounds(35, 60, 140, 20);
  457.  
  458. contentPane.setPreferredSize(new Dimension(400, 300));
  459. pack();
  460. setLocationRelativeTo(getOwner());
  461. }
  462.  
  463.  
  464. private JButton startButton;
  465. private JLabel label1;
  466. private JTextField whatToEat;
  467. private JLabel label2;
  468. private JTextField whatToAttack;
  469. }
  470.  
  471.  
  472. }
Advertisement
Add Comment
Please, Sign In to add comment