Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 27th, 2012  |  syntax: None  |  size: 11.36 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.awt.Color;
  2. import java.awt.Font;
  3. import java.awt.Graphics;
  4. import java.awt.Graphics2D;
  5. import java.awt.Point;
  6. import java.awt.Polygon;
  7. import java.text.NumberFormat;
  8.  
  9. import org.rsbot.event.events.ServerMessageEvent;
  10. import org.rsbot.event.listeners.PaintListener;
  11. import org.rsbot.event.listeners.ServerMessageListener;
  12. import org.rsbot.script.Script;
  13. import org.rsbot.script.ScriptManifest;
  14. import org.rsbot.script.methods.Skills;
  15. import org.rsbot.script.util.Filter;
  16. import org.rsbot.script.wrappers.RSArea;
  17. import org.rsbot.script.wrappers.RSComponent;
  18. import org.rsbot.script.wrappers.RSModel;
  19. import org.rsbot.script.wrappers.RSNPC;
  20. import org.rsbot.script.wrappers.RSTile;
  21.  
  22. @ScriptManifest(authors = {"jtryba"}, keywords = "combat", name = "monkR8per",
  23.                 version = 1.0, description = ("Kills monks at the monastery... " +
  24.                                 "Heals at 50% health.. Enjoy."))
  25.  
  26. public class monkR8per extends Script implements PaintListener,
  27. ServerMessageListener   {
  28.  
  29.         public RSTile headMonkTile = new RSTile(3056, 3483);
  30.         public RSArea monkArea = new RSArea(new RSTile(3041, 3480),
  31.                 new RSTile(3062, 3501));
  32.         public boolean firstRun = true, clickContinue = false, justHealed = false,
  33.                 healing = false;
  34.         public int healAtPercent = 50;
  35.         public int monkID = 7727, headMonkID = 801;
  36.         public int maxHP;
  37.         public int totalHealed = 0, deaths = 0;
  38.         public long startTime, runTime;
  39.         public String status = "";
  40.         public int defExpGained = 0, strExpGained = 0, attExpGained = 0,
  41.                 conExpGained = 0, magExpGained = 0, ranExpGained = 0, totalExpGained = 0;
  42.         public int defLvlGained = 0, strLvlGained = 0, attLvlGained = 0,
  43.                 conLvlGained = 0, magLvlGained = 0, ranLvlGained = 0, totalLvlGained = 0,
  44.                 combatLevelsGained = 0;
  45.         public int startDefExp = 0, startAttExp = 0, startStrExp = 0, startConExp = 0,
  46.                 startMagExp = 0, startRanExp = 0;
  47.         Color colorGreen = new Color(0, 255, 0, 50);
  48.         Color colorBlue = new Color(0, 0, 255, 200);
  49.         Color colorRed = new Color(255, 0, 0, 50);
  50.        
  51.         public final Filter<RSNPC> filter = new Filter<RSNPC>() {
  52.         public boolean accept(RSNPC npc) {
  53.             return !npc.isInCombat() && npcPresent(npc) && npc.getID() == monkID;
  54.         }
  55.  
  56.                 private boolean npcPresent(RSNPC npc) {
  57.                         return npc != null && monkArea.contains(npc.getLocation());
  58.                 }
  59.     };
  60.        
  61.         @Override
  62.         public int loop() {
  63.                 if (game.isLoggedIn() && skills.getCurrentLevel(Skills.CONSTITUTION) > 1) {
  64.                         if (firstRun) {
  65.                                 setup();
  66.                         }
  67.                         runTime = System.currentTimeMillis() - startTime;
  68.                         keepTrackOfSkills();
  69.                         mouse.setSpeed(random(3, 6));
  70.                         camera.setPitch(true);
  71.                         checkRun();
  72.                         countHeals();
  73.                         if (clickContinue) {
  74.                                 if (interfaces.canContinue()) {
  75.                                         interfaces.clickContinue();
  76.                                         clickContinue = false;
  77.                                         return random(500, 750);
  78.                                 }
  79.                         }
  80.  
  81.                         if (atMonks()) {
  82.                                 if (needsToHeal() || healing) {
  83.                                         healing = true;
  84.                                         status = "Cura";
  85.                                         RSComponent interface1 = interfaces.getComponent(241, 5);
  86.                                         RSComponent interface2 = interfaces.getComponent(230, 2);
  87.                                         RSComponent interface3 = interfaces.getComponent(64, 5);
  88.                                         RSComponent interface4 = interfaces.getComponent(210, 2);
  89.                                         if (interface1.isValid()) {
  90.                                                 interface1.doClick();
  91.                                                 return random(750, 1000);
  92.                                         } else if (interface2.isValid()) {
  93.                                                 interface2.doClick();
  94.                                                 return random(750, 1000);
  95.                                         } else if (interface3.isValid()) {
  96.                                                 interface3.doClick();
  97.                                                 return random(750, 1000);
  98.                                         } else if (interface4.isValid()) {
  99.                                                 interface4.doClick();
  100.                                                 justHealed = true;
  101.                                                 healing = false;
  102.                                                 return random(750, 1000);
  103.                                     } else {
  104.                                                 RSNPC headMonk = npcs.getNearest(headMonkID);
  105.                                                 if (headMonk != null) {
  106.                                                         if (calc.tileOnScreen(headMonk.getLocation())) {
  107.                                                                 camera.turnToTile(headMonk.getLocation(), 5);
  108.                                                                 headMonk.doAction("Falar");
  109.                                                                 return random(750, 1250);
  110.                                                         } else {
  111.                                                                 if (!getMyPlayer().isMoving()) {
  112.                                                                         RSTile path[] = walking.findPath(headMonkTile);
  113.                                                                         walking.walkPathMM(path);
  114.                                                                         return random(750, 1000);
  115.                                                                 }
  116.                                                         }
  117.                                                 }
  118.                                         }
  119.                                 } else if (!inCombat()) {
  120.                                         RSNPC monk = npcs.getNearest(filter);
  121.                                         if (monk != null) {
  122.                                                 camera.turnToTile(monk.getLocation(), 5);
  123.                                                 if (monk.isOnScreen()) {
  124.                                                         status = "Atacar monge";
  125.                                                         monk.doAction("Atacar " + monk.getName());
  126.                                                         return random(750, 1000);
  127.                                                 } else if (calc.distanceTo(monk.getLocation()) < 7) {
  128.                                                         status = "Caminhando para monge";
  129.                                                         if (!getMyPlayer().isMoving()) {
  130.                                                                 walking.walkTileOnScreen(monk.getLocation());
  131.                                                                 return random(750, 1000);
  132.                                                         }
  133.                                                         return 1;
  134.                                                 } else if (calc.distanceTo(monk.getLocation()) >= 7) {
  135.                                                         status = "Caminhando para monge";
  136.                                                         if (!getMyPlayer().isMoving()) {
  137.                                                                 RSTile path[] = walking.findPath(monk.getLocation());
  138.                                                                 walking.walkPathMM(path);
  139.                                                                 return random(750, 1000);
  140.                                                         }
  141.                                                         return 1;
  142.                                                 }
  143.                                         } else {
  144.                                                 status = "esperando";
  145.                                                 return random(5, 10);
  146.                                         }
  147.                                 } else if (inCombat()) {
  148.                                         status = "Combate";
  149.                                         return random(5, 10);
  150.                                 }
  151.                         } else {
  152.                                 RSTile destination = monkArea.getCentralTile();
  153.                                 if (!getMyPlayer().isMoving()) {
  154.                                         RSTile path[] = walking.findPath(destination);
  155.                                         walking.walkPathMM(path);
  156.                                         return random(750, 1000);
  157.                                 }
  158.                                 return random(1, 5);
  159.                         }
  160.                 }
  161.                 return random(1, 5);
  162.         }
  163.  
  164.         private void countHeals() {
  165.                 if (justHealed && !needsToHeal()) {
  166.                         totalHealed++;
  167.                         justHealed = false;
  168.                 }
  169.         }
  170.        
  171.         private boolean needsToHeal() {
  172.                 return currentHP() <= healAt();
  173.         }
  174.        
  175.         private double healAt() {
  176.                 String HAP = "." + healAtPercent;
  177.                 return maxHP() * Double.parseDouble(HAP);
  178.         }
  179.  
  180.         private double maxHP() {
  181.                 return skills.getCurrentLevel(Skills.CONSTITUTION) * 10;
  182.         }
  183.  
  184.         public int currentHP() {
  185.                 return Integer.parseInt(interfaces.getComponent(748, 8).getText());
  186.         }
  187.  
  188.         private boolean inCombat() {
  189.                 return getMyPlayer().getInteracting() != null &&
  190.                         getMyPlayer().getInteracting().getHPPercent() > 0;
  191.         }
  192.  
  193.         private void checkRun() {
  194.                 if (!walking.isRunEnabled() && walking.getEnergy() > random(15, 30)) {
  195.                         walking.setRun(true);
  196.                         sleep(random(500, 750));
  197.                 }
  198.         }
  199.  
  200.         private boolean atMonks() {
  201.                 return monkArea.contains(getMyPlayer().getLocation());
  202.         }
  203.        
  204.         private int countKills() {
  205.                 return (int) (conExpGained / 20);
  206.         }
  207.        
  208.         public double getVersion(){
  209.             return getClass().getAnnotation(ScriptManifest.class).version();
  210.         }
  211.        
  212.         public String formatTime(final int milliseconds) {
  213.                 final long t_seconds = milliseconds / 1000;
  214.                 final long t_minutes = t_seconds / 60;
  215.                 final long t_hours = t_minutes / 60;
  216.                 final int seconds = (int) (t_seconds % 60);
  217.                 final int minutes = (int) (t_minutes % 60);
  218.                 final int hours = (int) (t_hours % 60);
  219.                 return NumberFormat.getInstance().format(hours) + ":"
  220.                                 + NumberFormat.getInstance().format(minutes) + ":"
  221.                                 + NumberFormat.getInstance().format(seconds);
  222.         }
  223.        
  224.         private void setup() {
  225.                 startTime = System.currentTimeMillis();
  226.                 startDefExp = skills.getCurrentExp(Skills.DEFENSE);
  227.                 startAttExp = skills.getCurrentExp(Skills.ATTACK);
  228.                 startStrExp = skills.getCurrentExp(Skills.STRENGTH);
  229.                 startConExp = skills.getCurrentExp(Skills.CONSTITUTION);
  230.                 startMagExp = skills.getCurrentExp(Skills.MAGIC);
  231.                 startRanExp = skills.getCurrentExp(Skills.RANGE);
  232.                 if (combat.isAutoRetaliateEnabled()) {
  233.                 combat.setAutoRetaliate(true);
  234.                 sleep(random(1000, 1500));
  235.         }
  236.                 firstRun = false;
  237.         }
  238.        
  239.         private void keepTrackOfSkills() {
  240.                 int currentDefExp = skills.getCurrentExp(Skills.DEFENSE);
  241.                 int currentAttExp = skills.getCurrentExp(Skills.ATTACK);
  242.                 int currentStrExp = skills.getCurrentExp(Skills.STRENGTH);
  243.                 int currentConExp = skills.getCurrentExp(Skills.CONSTITUTION);
  244.                 int currentMagExp = skills.getCurrentExp(Skills.MAGIC);
  245.                 int currentRanExp = skills.getCurrentExp(Skills.RANGE);
  246.  
  247.                 defExpGained = currentDefExp - startDefExp;
  248.                 strExpGained = currentStrExp - startStrExp;
  249.                 attExpGained = currentAttExp - startAttExp;
  250.                 conExpGained = currentConExp - startConExp;
  251.                 magExpGained = currentMagExp - startMagExp;
  252.                 ranExpGained = currentRanExp - startRanExp;
  253.                
  254.                 totalExpGained = defExpGained + strExpGained + attExpGained
  255.                         + conExpGained + magExpGained + ranExpGained;
  256.                
  257.                 totalLvlGained = defLvlGained + strLvlGained + attLvlGained
  258.                         + conLvlGained + magLvlGained + ranLvlGained;
  259.         }
  260.        
  261.         @Override
  262.         public void serverMessageRecieved(ServerMessageEvent e) {
  263.                 final String serverString = e.getMessage().toLowerCase();
  264.         if (serverString.contains("you've just advanced")) {
  265.                 if  (serverString.contains("strength level"))
  266.                         strLvlGained++;
  267.                 if (serverString.contains("attack level"))
  268.                         attLvlGained++;
  269.                 if (serverString.contains("defence level"))
  270.                         defLvlGained++;
  271.                 if (serverString.contains("constitution level"))
  272.                         conLvlGained++;
  273.                 if (serverString.contains("magic level"))
  274.                         magLvlGained++;
  275.                 if (serverString.contains("ranged level"))
  276.                         ranLvlGained++;
  277.                 log("Gratz you just gained a level");
  278.                 clickContinue = true;
  279.         }
  280.         if (serverString.contains("oh dear"))
  281.                 deaths++;
  282.         if (serverString.contains("reached combat level"))
  283.                 combatLevelsGained++;
  284.         }
  285.        
  286.         @Override
  287.         public void onRepaint(Graphics render) { // TODO finish this
  288.                 Graphics2D g = (Graphics2D)render;
  289.                 if (game.isLoggedIn()) {
  290.                         drawNextMonk(g);
  291.                 drawMouse(g);
  292.                 g.setColor(colorGreen);
  293.                 g.fillRoundRect(10, 185, 150, 145, 16, 16);
  294.                 g.setColor(Color.BLACK);
  295.                 g.setFont(new Font("sansserif", Font.PLAIN, 12));
  296.                 g.drawString("Status: " + status, 13, 200);
  297.                 g.drawString("Kills: " + countKills(), 13, 220);
  298.                 g.drawString("Healed: " + totalHealed, 13, 240);
  299.                 g.drawString("Deaths: " + deaths, 13, 260);
  300.                 g.drawString("Runtime: " + formatTime((int) runTime), 13, 280);
  301.                 g.drawString("Levels: " + totalLvlGained, 13, 300);
  302.                 g.drawString("CB Levels: " + combatLevelsGained, 13, 320);
  303.                 }
  304.         }
  305.        
  306.         private void drawMouse(final Graphics g) {
  307.                 final Point loc = mouse.getLocation();
  308.                 g.setColor(Color.BLACK);
  309.                 g.drawLine(0, loc.y, 766, loc.y);
  310.                 g.drawLine(loc.x, 0, loc.x, 505);
  311.         }
  312.        
  313.         public void drawNextMonk(Graphics g) {
  314.                 RSNPC npc = npcs.getNearest(filter);
  315.                 if (npc != null) {
  316.                         RSModel model = npc.getModel();
  317.                         if (model != null) {
  318.                                 g.setColor(colorGreen);
  319.                                 for (Polygon p : model.getTriangles()) {
  320.                                         g.fillPolygon(p);
  321.                                 }
  322.                         }
  323.                         overlayText(g, npc.getLocation(), colorBlue, "Next monk");
  324.                 }
  325.         }
  326.        
  327.         public void overlayText(final Graphics g, final RSTile t,
  328.                         final Color c, final String text) {
  329.                 final Point p = calc.tileToScreen(t);
  330.                 final Point pn = calc.tileToScreen(new RSTile
  331.                                 (t.getX(), t.getY()), 0);
  332.                 final Point px = calc.tileToScreen(new RSTile
  333.                                 (t.getX() + 1, t.getY()), 0);
  334.                 final Point py = calc.tileToScreen(new RSTile
  335.                                 (t.getX(), t.getY() + 1), 0);
  336.                 final Point pxy = calc.tileToScreen(new RSTile
  337.                                 (t.getX() + 1, t.getY() + 1), 0);
  338.                 final Point[] points = { p, pn, px, py, pxy };
  339.                 for (final Point point : points) {
  340.                         if (!calc.pointOnScreen(point)) {
  341.                                 return;
  342.                         }
  343.                 }
  344.                 g.setColor(c);
  345.                 g.setFont(new Font("sansserif", Font.BOLD, 12));
  346.                 g.drawString(text, p.x - 30, p.y - 40);
  347.         }
  348.        
  349. }