Advertisement
Guest User

Darks POH Curser V0.7

a guest
Jul 26th, 2013
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 17.10 KB | None | 0 0
  1. package scripts;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.awt.Graphics2D;
  6. import java.awt.Image;
  7. import java.awt.Point;
  8. import java.awt.Polygon;
  9. import java.io.IOException;
  10. import java.net.MalformedURLException;
  11. import java.net.URL;
  12. import java.util.Arrays;
  13.  
  14. import javax.imageio.ImageIO;
  15. import javax.swing.JOptionPane;
  16.  
  17. import org.Magic;
  18. import org.RSArea;
  19. import org.SPELL;
  20. import org.Timer;
  21. import org.tribot.api2007.NPCChat;
  22. import org.tribot.api.General;
  23. import org.tribot.api.Timing;
  24. import org.tribot.api.input.Keyboard;
  25. import org.tribot.api.input.Mouse;
  26. import org.tribot.api.types.generic.Condition;
  27. import org.tribot.api2007.Camera;
  28. import org.tribot.api2007.Game;
  29. import org.tribot.api2007.GameTab;
  30. import org.tribot.api2007.GameTab.TABS;
  31. import org.tribot.api2007.ChooseOption;
  32. import org.tribot.api2007.Interfaces;
  33. import org.tribot.api2007.Inventory;
  34. import org.tribot.api2007.Login;
  35. import org.tribot.api2007.Objects;
  36. import org.tribot.api2007.Player;
  37. import org.tribot.api2007.Players;
  38. import org.tribot.api2007.Projection;
  39. import org.tribot.api2007.Skills;
  40. import org.tribot.api2007.Walking;
  41. import org.tribot.api2007.types.RSModel;
  42. import org.tribot.api2007.types.RSObject;
  43. import org.tribot.api2007.types.RSPlayer;
  44. import org.tribot.api2007.types.RSTile;
  45. import org.tribot.script.Script;
  46. import org.tribot.script.interfaces.Painting;
  47.  
  48. public class Darks_POH_Curser extends Script implements Painting {
  49.     enum STATE {
  50.         STARTING, OPENING_DOOR, CREATING_COMBAT_RING_AREA, WALKING_TO_RING, GETTING_IN_RING, CURSING_PLAYER, OUTSIDE_HOUSE, LOGGING_OUT, FAILSAFE, ERROR;
  51.     }
  52.    
  53.     private Image paint = getImage("http://puu.sh/3L453.png");
  54.     private boolean started = false;
  55.     private RSArea combatRingArea;
  56.     private RSArea currentDoorArea;
  57.     private RSObject currentDoor;
  58.     private RSTile maxTile;
  59.     private RSTile minTile;
  60.     private String status;
  61.     private String debug = "DEBUG HERE";
  62.     private RSObject[] combatRing;
  63.     private RSObject combatRingRope;
  64.     private STATE currentState;
  65.     private String state;
  66.     private String playerName = "";
  67.     public long startTime = 0;
  68.     public long millis = 0;
  69.     public long hours = 0;
  70.     public long minutes = 0;
  71.     public long seconds = 0;
  72.     public long last = 0;
  73.     public int expGained = 0;
  74.     public int expPerHour = 0;
  75.     private final int startXp = Skills.getXP("MAGIC");
  76.     public int expToLevel;
  77.     public int curseTNL;
  78.     public int curseCount;
  79.     public int startLevel;
  80.     public int currentLevel;
  81.     public int levelsGained;
  82.     // public final int startHealth = Player.getRSPlayer().getHealth();
  83.     public long sTNL;
  84.     public long mTNL;
  85.     public long hTNL;
  86.     private boolean isDoorOpen = false;
  87.     private boolean isYourHouse = true;
  88.     public static final int COMBAT_RING_ROPE = 13137;
  89.     public static final int POH_TAB = 8013;
  90.     public static final int PORTAL = 15478;
  91.     public static final int INHOME_PORTAL = 13405;
  92.     // DEBUG
  93.     RSModel currentModel;
  94.     private int countPerHour;
  95.  
  96.     @Override
  97.     public void run() {
  98.         status = " START";
  99.  
  100.         while (true) {
  101.             currentState = getState();
  102.             switch (currentState) {
  103.             case CURSING_PLAYER:
  104.                 cursePlayer();
  105.                 break;
  106.             case GETTING_IN_RING:
  107.                 getInRing();
  108.                 break;
  109.             case OUTSIDE_HOUSE:
  110.                 getBackIntoHouse();
  111.                 break;
  112.             case STARTING:
  113.                 break;
  114.             case WALKING_TO_RING:
  115.                 walkToRing();
  116.                 break;
  117.             case OPENING_DOOR:
  118.                 break;
  119.             case CREATING_COMBAT_RING_AREA:
  120.                 break;
  121.             case LOGGING_OUT:
  122.                 Login.logout();
  123.                 break;
  124.             case FAILSAFE:
  125.                 failSafe();
  126.                 break;
  127.             default:
  128.                 break;
  129.  
  130.             }
  131.         }
  132.  
  133.     }
  134.  
  135.     public boolean openDoor() {
  136.         debug = " GETTING DOOR...";
  137.         if (getDoor() == null) {
  138.             isDoorOpen = true;
  139.         }
  140.         if (!isDoorOpen && currentDoor == null) {
  141.             currentDoor = getDoor();
  142.             currentModel = currentDoor.getModel();
  143.             currentDoorArea = RSArea.createRSArea(currentDoor.getPosition(), 1);
  144.         } else {
  145.             if (!isDoorOpen) {
  146.                 clickModel(currentModel,"",false);
  147.             }
  148.             debug = " DEBUG:IS Door Open? " + isDoorOpen;
  149.             sleep(750);
  150.  
  151.             return isDoorOpen;
  152.         }
  153.         /**
  154.          * if(Walking.blindWalkTo(currentDoorArea.getMaxTile())){
  155.          * currentDoor.click();
  156.          * while(Game.getDestination().distanceTo(Player.getPosition())!=0){
  157.          * Walking.blindWalkTo(currentDoorArea.getMaxTile());
  158.          * currentDoor.click(); return; } }
  159.          */
  160.         return isDoorOpen;
  161.     }
  162.  
  163.     private RSObject getDoor() {
  164.         debug = " GETTING DOOR OBJECT...";
  165.         // First part checks to see if door is open.
  166.         if (isDoorOpen && currentDoor != null) {
  167.             return currentDoor;
  168.         }
  169.         if (!isDoorOpen) {
  170.             debug = " DOOR ISNT OPEN!";
  171.             for (RSObject o : Objects.findNearest(15, 13100)) {
  172.                 debug = " Found Something";
  173.                 if (o != null) {
  174.                     debug = " It's not Null "
  175.                             + (combatRingArea.getDistanceFrom(o.getPosition()) < 15);
  176.                     if (combatRingArea.getDistanceFrom(o.getPosition()) < 8) {
  177.                         debug = " It's on screen and less than 8 tiles away from ring.";
  178.                         if (Player.getPosition().distanceTo(o.getPosition()) <= 4) {
  179.                             debug = " It's less than 5 tiles away from me.";
  180.                             currentDoorArea = RSArea.createRSArea(
  181.                                     o.getPosition(), 1);
  182.                             debug = " Distance To Area: "
  183.                                     + currentDoorArea.getDistanceFrom(Player
  184.                                             .getPosition());
  185.                             debug = "MAX TILE?: ";// +currentDoorArea.getMaxTile().toString();
  186.                             return o;
  187.  
  188.                         }
  189.                     }
  190.                 }
  191.             }
  192.         }
  193.         return null;
  194.     }
  195.  
  196.     /**
  197.      * This Method will use a tele tab to get back to their house, then if it
  198.      * isn't their house it will leave their house and hand over control back to
  199.      * the script. The script will continue on. Otherwise it will just continue
  200.      * on after it is back in their house.If you have no tele tabs it will log
  201.      * out and end the script.
  202.      */
  203.     private boolean failSafe() {
  204.         if (useTeleTab() && !isYourHouse) {
  205.             Timing.waitCondition(new Condition() {
  206.                 @Override
  207.                 public boolean active() {
  208.                     return getNearestObject(INHOME_PORTAL, 5).click("Enter");
  209.                 }
  210.             }, 650);
  211.             return true;
  212.         }
  213.         return false;
  214.     }
  215.  
  216.     private boolean useTeleTab() {
  217.         if (Inventory.getCount(POH_TAB) > 0) {
  218.             Timing.waitCondition(new Condition() {
  219.                 @Override
  220.                 public boolean active() {
  221.                     return Inventory.find(POH_TAB)[0].click();
  222.                 }
  223.             }, 650);
  224.             sleep(450, 650);// Sleep just long enough for the House Loading
  225.                             // Interface to
  226.                             // pop up.
  227.             Timing.waitCondition(new Condition() {
  228.                 @Override
  229.                 // Sleep while That interface is up.
  230.                 public boolean active() {
  231.                     return Interfaces.get(399, 1) == null;
  232.                 }
  233.             }, 4500);
  234.             return true; // Return true after your player is at their house.
  235.         } else if (Inventory.getCount(POH_TAB) == 0) {
  236.             General.println("You were lost or lured away or something happened, and you had no tele tabs so this script logged you out and ended.");
  237.             Login.logout();
  238.             stopScript();
  239.             // If you have no tabs it will stop the script.
  240.             // So really this method can only return true.
  241.         }
  242.         return false;
  243.     }
  244.  
  245.     private boolean hasRunes() {
  246.         return Inventory.getCount(559) > 0;
  247.     }
  248.  
  249.     private void cursePlayer() {
  250.  
  251.         for (final RSPlayer p : Players.getAll()) {
  252.             if (p == null) {
  253.                 break;
  254.             }
  255.             if (p.getName() != Player.getRSPlayer().getName()) {
  256.                 if (GameTab.getOpen() != TABS.MAGIC) {
  257.                     GameTab.open(TABS.MAGIC);
  258.                 }
  259.                 while (hasRunes() && p.isOnScreen()
  260.                         && combatRingArea.isInArea(p.getPosition())
  261.                         && combatRingArea.isInArea(Player.getPosition())) {
  262.                     if (Magic.cast(SPELL.CURSE)) {
  263.                         curseCount++;
  264.                         Camera.turnToTile(p.getPosition());
  265.                         currentModel = p.getModel();
  266.                         Timing.waitCondition(new Condition() {
  267.                             @Override
  268.                             public boolean active() {
  269.                                 return p.click();
  270.                             }
  271.                         }, 650);
  272.                     }
  273.                 }
  274.             }
  275.         }
  276.     }
  277.  
  278.     private void getBackIntoHouse() {
  279.         currentDoorArea = null;
  280.         if (isYourHouse) {
  281.             if (Objects.findNearest(20, PORTAL).length > 0) {
  282.                 currentModel = Objects.findNearest(20, PORTAL)[0].getModel();
  283.                 if (clickModel(currentModel, "Enter", true)) {
  284.                     if (NPCChat.selectOption("Go to your house", true)) {
  285.                         currentModel = null;
  286.                         Timing.waitCondition(new Condition() {
  287.                             @Override
  288.                             public boolean active() {
  289.                                 return Interfaces.get(399, 1) == null;
  290.                             }
  291.                         }, 3500);
  292.                     }
  293.                 }
  294.             }
  295.         } else {
  296.             if (Objects.findNearest(20, PORTAL).length > 0) {
  297.                 currentModel = Objects.findNearest(20, PORTAL)[0].getModel();
  298.                 if (clickModel(currentModel, "Enter", true)) {
  299.                     if (NPCChat.selectOption("Go to a friend's house", true)) {
  300.                         typeString(playerName);
  301.                         currentModel = null;
  302.                         Timing.waitCondition(new Condition() {
  303.                             @Override
  304.                             public boolean active() {
  305.                                 return Interfaces.get(399, 1) == null;
  306.                             }
  307.                         }, 3500);
  308.                     }
  309.                 }
  310.             }
  311.         }
  312.  
  313.     }
  314.  
  315.     private void getInRing() {
  316.         if (combatRingRope == null) {
  317.             combatRingRope = Objects.find(50, COMBAT_RING_ROPE)[General.random(0,Objects.find(50, COMBAT_RING_ROPE).length-1)];
  318.         }
  319.         else{
  320.         currentModel = combatRingRope.getModel();
  321.         clickModel(currentModel, "", false);
  322.         Timing.waitCondition(new Condition() {
  323.             @Override
  324.             public boolean active() {
  325.                 return Player.getAnimation() == -1;
  326.             }
  327.         }, 800);}
  328.         currentDoorArea = null;
  329.         currentDoor = null;
  330.         return;
  331.     }
  332.  
  333.     private STATE getState() {
  334.         if (!started) {
  335.             onStart();
  336.             return STATE.STARTING;
  337.         }
  338.         if (!hasRunes()) {
  339.             return STATE.LOGGING_OUT;
  340.         }
  341.         if (isInsideHouse() && combatRingArea == null
  342.                 && determineCombatRingArea()) {
  343.             return STATE.CREATING_COMBAT_RING_AREA;
  344.         }
  345.         if (isInsideHouse() && !isDoorOpen) {
  346.             if (combatRingArea != null
  347.                     && combatRingArea.isInArea(Player.getPosition())) {
  348.                 return STATE.CURSING_PLAYER;
  349.             } else if (openDoor()) {
  350.                 return STATE.OPENING_DOOR;
  351.             }
  352.         }
  353.         if (isInsideHouse() && !combatRingArea.isInArea(Player.getPosition())) {
  354.             if (combatRingArea.getDistanceFrom(Player.getPosition()) > 3) {
  355.                 return STATE.WALKING_TO_RING;
  356.             }
  357.             return STATE.GETTING_IN_RING;
  358.         }
  359.         if (isInsideHouse() && combatRingArea != null
  360.                 && combatRingArea.isInArea(Player.getPosition())) {
  361.             return STATE.CURSING_PLAYER;
  362.         }
  363.         if (getNearestObject(PORTAL, 20) != null) {
  364.             return STATE.OUTSIDE_HOUSE;
  365.         }
  366.         if (!isInsideHouse() && Objects.findNearest(20, PORTAL).length == 0) {
  367.             return STATE.FAILSAFE;
  368.         }
  369.         return STATE.ERROR;
  370.     }
  371.  
  372.     private void walkToRing() {
  373.         if (isDoorOpen) {
  374.             if (combatRingRope == null) {
  375.                 combatRingRope = Objects.find(50, COMBAT_RING_ROPE)[General.random(0,Objects.find(50, COMBAT_RING_ROPE).length-1)];
  376.             }
  377.             Walking.walkTo(combatRingRope.getPosition());
  378.             while (Player.isMoving()) {
  379.                 Camera.turnToTile(combatRingRope.getPosition());
  380.             }
  381.         } else {
  382.             if (combatRingArea.getDistanceFrom(Player.getPosition()) > 8) {
  383.                 openDoor();
  384.             }
  385.         }
  386.     }
  387.  
  388.     private boolean isInsideHouse() {
  389.         return Objects.find(25, INHOME_PORTAL) != null
  390.                 && Objects.find(25, INHOME_PORTAL).length > 0;
  391.     }
  392.  
  393.     private void onStart() {
  394.         // currentState = STATE.STARTING;
  395.         startTime = System.currentTimeMillis();
  396.         startLevel = Skills.getActualLevel("MAGIC");
  397.         playerName += JOptionPane.showInputDialog(
  398.                 "Enter Player's name if it's not your house", Player
  399.                         .getRSPlayer().getName());
  400.         if (!Player.getRSPlayer().getName().equalsIgnoreCase(playerName)
  401.                 || playerName.equals("")) {
  402.             isYourHouse = false;
  403.             General.println("This is your house@");
  404.         }
  405.         started = true;
  406.     }
  407.  
  408.     @Override
  409.     public void onPaint(Graphics g) {
  410.         // MATH
  411.         millis = System.currentTimeMillis() - startTime;
  412.         hours = millis / (1000 * 60 * 60);
  413.         millis -= hours * (1000 * 60 * 60);
  414.         minutes = millis / (1000 * 60);
  415.         millis -= minutes * (1000 * 60);
  416.         seconds = millis / 1000;
  417.         int CurrentExp = Skills.getXP("Magic");
  418.         curseCount = (CurrentExp - startXp) / 29;
  419.         countPerHour = (int) ((curseCount) * 3600000D / (System
  420.                 .currentTimeMillis() - startTime));
  421.         expPerHour = (int) ((expGained) * 3600000D / (System
  422.                 .currentTimeMillis() - startTime));
  423.         expGained = Skills.getXP("MAGIC") - startXp;
  424.         curseTNL = Skills.getXPToLevel("MAGIC", currentLevel + 1) / 29;
  425.         currentLevel = Skills.getCurrentLevel("MAGIC");
  426.         levelsGained = currentLevel - startLevel;
  427.         expToLevel = Skills.getXPToNextLevel("MAGIC");
  428.         // DEBUG
  429.         if (currentModel != null) {
  430.             paintRSModel(g, currentModel);
  431.         }
  432.         if (currentDoorArea != null) {
  433.             currentDoorArea.paintRSArea(g);
  434.         }
  435.         if (combatRingArea != null) {
  436.             combatRingArea.paintRSArea(g);
  437.             g.drawString(debug, 250, 300);
  438.         }
  439.  
  440.         g.drawString(debug, 250, 300);
  441.  
  442.         if (minTile != null && maxTile != null) {
  443.             g.setColor(Color.RED);
  444.             drawTile(minTile, (Graphics2D) g, false);
  445.             drawTile(maxTile, (Graphics2D) g, false);
  446.  
  447.         }
  448.         g.setColor(Color.BLUE);
  449.         drawTile(Player.getPosition(), (Graphics2D) g, false);
  450.         g.setColor(Color.ORANGE);
  451.         if (Game.getDestination() != null) {
  452.             drawTile(Game.getDestination(), (Graphics2D) g, false);
  453.         }
  454.         g.setColor(Color.GREEN);
  455.         g.drawString("STATUS: " + status, 210, 410);
  456.         // ACTUAL Paint
  457.         g.drawImage(paint, 0, 300, null);
  458.         // Status
  459.         g.setColor(Color.WHITE);
  460.         if (currentState != null) {
  461.             state = currentState.toString();
  462.             g.drawString(state, 195, 375);
  463.         }
  464.         // Time
  465.         g.drawString(hours + ":" + minutes + ":" + seconds, 245, 395);
  466.         g.drawString(formatTime(millis / curseTNL), 210, 413);
  467.         // Level
  468.         g.drawString(currentLevel + " ( " + levelsGained + " )", 220, 432);
  469.         // XP
  470.         g.drawString("" + expGained, 260, 450);
  471.         g.drawString("" + expPerHour, 225, 470);
  472.  
  473.     }
  474.  
  475.     private boolean determineCombatRingArea() {
  476.         if (getNearestObject("Combat ring", 50) != null) {
  477.             status = " Determining Combat Ring Area...";
  478.             int[] xCoords;
  479.             int[] yCoords;
  480.             combatRing = Objects.find(50, "Combat ring");
  481.             xCoords = new int[combatRing.length];
  482.             yCoords = new int[combatRing.length];
  483.             for (int x = 0; x <= combatRing.length - 1; x++) {
  484.                 RSTile pos = combatRing[x].getPosition();
  485.                 xCoords[x] = pos.getX();
  486.                 yCoords[x] = pos.getY();
  487.             }
  488.             status = " Sorting Coordinates";
  489.             Arrays.sort(xCoords);
  490.             Arrays.sort(yCoords);
  491.             minTile = new RSTile(xCoords[8], yCoords[8]);
  492.             maxTile = new RSTile(xCoords[xCoords.length - 8],
  493.                     yCoords[yCoords.length - 8]);
  494.             status = "Min Tile : " + minTile.toString() + " MaxTile : "
  495.                     + maxTile.toString();
  496.             status = " Creating Area..";
  497.             combatRingArea = new RSArea(minTile, maxTile);
  498.             status = " Created Area!";
  499.             return true;
  500.         } else {
  501.             status = "Could Not Find Combat Ring!";
  502.         }
  503.         return false;
  504.     }
  505.  
  506.     public void createDoorArea() {
  507.         if (currentDoor != null && currentDoorArea == null) {
  508.             int x = currentDoor.getPosition().getX();
  509.             int y = currentDoor.getPosition().getY();
  510.             currentDoorArea = new RSArea(x - 1, y + 1, x + 1, y - 1);
  511.         }
  512.     }
  513.  
  514.     private void drawTile(RSTile tile, Graphics2D g, boolean fill) {
  515.         if (tile.isOnScreen()) {
  516.             if (fill) {
  517.                 g.fillPolygon(Projection.getTileBoundsPoly(tile, 0));
  518.             } else {
  519.                 g.drawPolygon(Projection.getTileBoundsPoly(tile, 0));
  520.             }
  521.         }
  522.     }
  523.  
  524.     private Image getImage(String url) {
  525.         try {
  526.             return ImageIO.read(new URL(url));
  527.         } catch (MalformedURLException e) {
  528.         } catch (IOException e) {
  529.         }
  530.         return null;
  531.     }
  532.  
  533.     private RSObject getNearestObject(String id, int dist) {
  534.         for (RSObject o : Objects.find(dist, id)) {
  535.             if (o != null) {
  536.                 return o;
  537.             }
  538.         }
  539.         return null;
  540.     }
  541.  
  542.     private RSObject getNearestObject(int id, int dist) {
  543.         for (RSObject o : Objects.find(dist, id)) {
  544.             if (o != null) {
  545.                 return o;
  546.             }
  547.         }
  548.         return null;
  549.     }
  550.  
  551.     public Point getBestPoint(Point[] points) {
  552.         int sumX = 0, sumY = 0;
  553.         int averageX, averageY;
  554.         int count = 0;
  555.  
  556.         for (Point p : points) {
  557.             sumX += p.getX();
  558.             sumY += p.getY();
  559.             count++;
  560.         }
  561.         averageX = sumX / count;
  562.         averageY = sumY / count;
  563.         return averageX > 0 && averageY > 0 ? new Point(averageX, averageY)
  564.                 : null;
  565.     }
  566.  
  567.     public boolean clickModel(RSModel model, String option, boolean rightClick) {
  568.         Camera.turnToTile(model.getAnimableTile());
  569.         Camera.setCameraAngle(General.random(60,70));
  570.         Point[] points = model.getAllVisiblePoints();
  571.         int length = points.length;
  572.         if (length != 0) {
  573.             Point p = getBestPoint(points);
  574.             Mouse.move(p);
  575.             {
  576.                 String top = Game.getUptext();
  577.                 if (top.contains(option)) {
  578.                     Mouse.click(p, 0);
  579.                     return true;
  580.                 } else if (rightClick) {
  581.                     Mouse.click(3);
  582.                     Timing.waitChooseOption(option,1300);
  583.                     if (!ChooseOption.isOpen())
  584.                         return false;
  585.                     if (ChooseOption.select(option))
  586.                         return true;
  587.                 }
  588.             }
  589.         }
  590.         return false;
  591.     }
  592.  
  593.     public void paintRSModel(Graphics g, RSModel m) {
  594.         g.setColor(Color.GREEN);
  595.         for (Polygon p : m.getTriangles()) {
  596.             g.drawPolygon(p);
  597.         }
  598.     }
  599.  
  600.     private boolean typeString(final String s) {
  601.         if (s.length() > 0) {
  602.             Timing.waitCondition(new Condition() {
  603.                 @Override
  604.                 public boolean active() {
  605.                     return Interfaces.get(548, 94) != null;
  606.                 }
  607.             }, 850);
  608.             Keyboard.typeSend(s);
  609.             return true;
  610.         }
  611.         return false;
  612.     }
  613.  
  614.     private String formatTime(long time) {
  615.         return (time / (1000 * 60 * 60) + ":" + (time / (1000 * 60)) + ":" + (time / 1000));
  616.     }
  617.  
  618. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement