Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scripts;
- import java.awt.Color;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.awt.Point;
- import java.awt.Polygon;
- import java.io.IOException;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.Arrays;
- import javax.imageio.ImageIO;
- import javax.swing.JOptionPane;
- import org.Magic;
- import org.RSArea;
- import org.SPELL;
- import org.tribot.api2007.NPCChat;
- import org.tribot.api.General;
- import org.tribot.api.Timing;
- import org.tribot.api.input.Keyboard;
- import org.tribot.api.input.Mouse;
- import org.tribot.api.types.generic.Condition;
- import org.tribot.api2007.Camera;
- import org.tribot.api2007.Game;
- import org.tribot.api2007.GameTab;
- import org.tribot.api2007.GameTab.TABS;
- import org.tribot.api2007.ChooseOption;
- import org.tribot.api2007.Interfaces;
- import org.tribot.api2007.Inventory;
- import org.tribot.api2007.Login;
- import org.tribot.api2007.Objects;
- import org.tribot.api2007.Player;
- import org.tribot.api2007.Players;
- import org.tribot.api2007.Projection;
- import org.tribot.api2007.Skills;
- import org.tribot.api2007.Walking;
- import org.tribot.api2007.types.RSItem;
- import org.tribot.api2007.types.RSModel;
- import org.tribot.api2007.types.RSObject;
- import org.tribot.api2007.types.RSPlayer;
- import org.tribot.api2007.types.RSTile;
- import org.tribot.script.Script;
- import org.tribot.script.interfaces.Painting;
- public class Darks_POH_Curser extends Script implements Painting {
- enum STATE {
- STARTING, OPENING_DOOR, CREATING_COMBAT_RING_AREA, WALKING_TO_RING, GETTING_IN_RING, CURSING_PLAYER, OUTSIDE_HOUSE, LOGGING_OUT, FAILSAFE, ERROR, LOADING_HOUSE;
- }
- private Image paint = getImage("http://puu.sh/3L453.png");
- private boolean started = false;
- private RSArea combatRingArea;
- private RSArea currentDoorArea;
- private RSObject currentDoor;
- private RSTile maxTile;
- private RSTile minTile;
- private String status;
- private String debug = "DEBUG HERE";
- private RSObject[] combatRing;
- private RSObject combatRingRope;
- private STATE currentState;
- private String state;
- private String playerName = "";
- public long startTime = 0;
- public long millis = 0;
- public long hours = 0;
- public long minutes = 0;
- public long seconds = 0;
- public long last = 0;
- public int expGained = 0;
- public int expPerHour = 0;
- private final int startXp = Skills.getXP("MAGIC");
- public int expToLevel;
- public int curseTNL;
- public int curseCount;
- public int startLevel;
- public int currentLevel;
- public int levelsGained;
- // public final int startHealth = Player.getRSPlayer().getHealth();
- public long sTNL;
- public long mTNL;
- public long hTNL;
- private boolean isDoorOpen = false;
- private boolean isYourHouse = true;
- public static final int COMBAT_RING_ROPE = 13137;
- public static final int POH_TAB = 8013;
- public static final int PORTAL = 15478;
- public static final int INHOME_PORTAL = 13405;
- // DEBUG
- RSModel currentModel;
- private int countPerHour;
- private boolean usedTab = false;
- private boolean failsafe = false;
- @Override
- public void run() {
- status = " START";
- while (true) {
- currentState = getState();
- switch (currentState) {
- case CURSING_PLAYER:
- cursePlayer();
- break;
- case GETTING_IN_RING:
- getInRing();
- break;
- case OUTSIDE_HOUSE:
- getBackIntoHouse();
- break;
- case STARTING:
- onStart();
- break;
- case WALKING_TO_RING:
- walkToRing();
- break;
- case OPENING_DOOR:
- while(!isDoorOpen){
- sleep(186,250);
- }
- break;
- case CREATING_COMBAT_RING_AREA:
- while(combatRingArea == null){
- sleep(186,250);
- }
- break;
- case LOGGING_OUT:
- Login.logout();
- break;
- case FAILSAFE:
- failSafe();
- break;
- case LOADING_HOUSE:
- Timing.waitCondition(new Condition(){
- @Override
- public boolean active() {
- return Interfaces.get(399, 1) == null;
- }
- },2500);break;
- default:
- break;
- }
- }
- }
- public boolean openDoor() {
- debug = " GETTING DOOR...";
- if (getDoor() == null) {
- isDoorOpen = true;
- }
- if (!isDoorOpen && currentDoor == null) {
- currentDoor = getDoor();
- currentModel = currentDoor.getModel();
- currentDoorArea = RSArea.createRSArea(currentDoor.getPosition(), 1);
- } else {
- if (!isDoorOpen) {
- clickModel(currentModel,"",false);
- }
- debug = " DEBUG:IS Door Open? " + isDoorOpen;
- sleep(750);
- return isDoorOpen;
- }
- /**
- * if(Walking.blindWalkTo(currentDoorArea.getMaxTile())){
- * currentDoor.click();
- * while(Game.getDestination().distanceTo(Player.getPosition())!=0){
- * Walking.blindWalkTo(currentDoorArea.getMaxTile());
- * currentDoor.click(); return; } }
- */
- return isDoorOpen;
- }
- private RSObject getDoor() {
- debug = " GETTING DOOR OBJECT...";
- // First part checks to see if door is open.
- if (isDoorOpen && currentDoor != null) {
- return currentDoor;
- }
- if (!isDoorOpen) {
- debug = " DOOR ISNT OPEN!";
- for (RSObject o : Objects.findNearest(15, 13100)) {
- debug = " Found Something";
- if (o != null) {
- debug = " It's not Null "
- + (combatRingArea.getDistanceFrom(o.getPosition()) < 15);
- if (combatRingArea.getDistanceFrom(o.getPosition()) < 8) {
- debug = " It's on screen and less than 8 tiles away from ring.";
- if (Player.getPosition().distanceTo(o.getPosition()) <= 4) {
- debug = " It's less than 5 tiles away from me.";
- currentDoorArea = RSArea.createRSArea(
- o.getPosition(), 1);
- debug = " Distance To Area: "
- + currentDoorArea.getDistanceFrom(Player
- .getPosition());
- debug = "MAX TILE?: ";// +currentDoorArea.getMaxTile().toString();
- return o;
- }
- }
- }
- }
- }
- return null;
- }
- /**
- * This Method will use a tele tab to get back to their house, then if it
- * isn't their house it will leave their house and hand over control back to
- * the script. The script will continue on. Otherwise it will just continue
- * on after it is back in their house.If you have no tele tabs it will log
- * out and end the script.
- */
- private boolean failSafe() {
- failsafe = true;
- if(!usedTab){
- if(useTeleTab()){
- usedTab = true;
- if (!isYourHouse) {
- sleep(1000,1500);
- Timing.waitCondition(new Condition(){
- @Override
- public boolean active() {
- return Interfaces.get(399, 1) == null;
- }
- },2500);
- sleep(1000,1500);
- if(getNearestObject("Portal", 25) !=null)
- Timing.waitCondition(new Condition() {
- @Override
- public boolean active() {
- return getNearestObject("Portal", 25).click("Enter");
- }
- }, 650);
- failsafe = false;
- return true;
- }
- }
- }
- failsafe = false;
- return usedTab;
- }
- private boolean useTeleTab() {
- if (Inventory.getCount(POH_TAB) > 0) {
- Timing.waitCondition(new Condition() {
- @Override
- public boolean active() {
- return Inventory.find(POH_TAB)[0].hover();
- }
- }, 650);
- RSItem i=Inventory.find(POH_TAB)[0];
- int x = (int)i.getArea().getCenterX();
- int y = (int)i.getArea().getCenterY();
- Mouse.click(x, y, 3);
- ChooseOption.select("Break");
- General.println("USED TAB");
- Timing.waitCondition(new Condition(){
- @Override
- public boolean active() {
- return Interfaces.get(399, 1) != null;
- }
- },2500);
- Timing.waitCondition(new Condition() {
- @Override
- // Sleep while That interface is up.
- public boolean active() {
- return Interfaces.get(399, 1) == null;
- }
- }, 4500);
- usedTab = false;
- return true; // Return true after your player is at their house.
- } else if (Inventory.getCount(POH_TAB) == 0) {
- 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.");
- Login.logout();
- stopScript();
- // If you have no tabs it will stop the script.
- // So really this method can only return true.
- }
- return false;
- }
- private boolean hasRunes() {
- return Inventory.getCount(559) > 0;
- }
- private void cursePlayer() {
- for (final RSPlayer p : Players.getAll()) {
- if (p == null) {
- break;
- }
- if (p.getName() != Player.getRSPlayer().getName()) {
- if (GameTab.getOpen() != TABS.MAGIC) {
- GameTab.open(TABS.MAGIC);
- }
- while (hasRunes() && p.isOnScreen()
- && combatRingArea.isInArea(p.getPosition())
- && combatRingArea.isInArea(Player.getPosition())) {
- if (Magic.cast(SPELL.CURSE)) {
- curseCount++;
- Camera.turnToTile(p.getPosition());
- currentModel = p.getModel();
- Timing.waitCondition(new Condition() {
- @Override
- public boolean active() {
- return p.click();
- }
- }, 650);
- }
- }
- }
- }
- }
- private void getBackIntoHouse() {
- currentDoorArea = null;
- if (isYourHouse) {
- if (Objects.findNearest(20, PORTAL).length > 0) {
- currentModel = Objects.findNearest(20, PORTAL)[0].getModel();
- if (clickModel(currentModel, "Enter", true)) {
- if (NPCChat.selectOption("Go to your house", true)) {
- currentModel = null;
- Timing.waitCondition(new Condition() {
- @Override
- public boolean active() {
- return Interfaces.get(399, 1) == null;
- }
- }, 3500);
- }
- }
- }
- } else {
- if (Objects.findNearest(20, PORTAL).length > 0) {
- currentModel = Objects.findNearest(20, PORTAL)[0].getModel();
- if (clickModel(currentModel, "Enter", true)) {
- if (NPCChat.selectOption("Go to a friend's house", true)) {
- typeString(playerName);
- currentModel = null;
- Timing.waitCondition(new Condition() {
- @Override
- public boolean active() {
- return Interfaces.get(399, 1) == null;
- }
- }, 3500);
- }
- }
- }
- }
- }
- private void getInRing() {
- if (combatRingRope == null) {
- combatRingRope = Objects.find(50, COMBAT_RING_ROPE)[General.random(0,Objects.find(50, COMBAT_RING_ROPE).length-1)];
- }
- else{
- currentModel = combatRingRope.getModel();
- clickModel(currentModel, "", false);
- Timing.waitCondition(new Condition() {
- @Override
- public boolean active() {
- return Player.getAnimation() == -1;
- }
- }, 800);}
- currentDoorArea = null;
- currentDoor = null;
- currentModel = null;
- return;
- }
- private STATE getState() {
- if (!started) {
- return STATE.STARTING;
- }
- if(Interfaces.get(399, 1) != null){
- return STATE.LOADING_HOUSE;
- }
- if (!hasRunes()) {
- return STATE.LOGGING_OUT;
- }
- if (!failsafe&&isInsideHouse() && combatRingArea == null
- && determineCombatRingArea()) {
- return STATE.CREATING_COMBAT_RING_AREA;
- }
- if (!failsafe&&isInsideHouse() && !isDoorOpen) {
- if (combatRingArea != null
- && combatRingArea.isInArea(Player.getPosition())) {
- return STATE.CURSING_PLAYER;
- } else if (openDoor()) {
- return STATE.OPENING_DOOR;
- }
- }
- if (!failsafe&&isInsideHouse() &&combatRingArea != null&& !combatRingArea.isInArea(Player.getPosition())) {
- if (combatRingArea.getDistanceFrom(Player.getPosition()) > 2) {
- return STATE.WALKING_TO_RING;
- }
- return STATE.GETTING_IN_RING;
- }
- if (!failsafe&&isInsideHouse() && combatRingArea != null
- && combatRingArea.isInArea(Player.getPosition())) {
- return STATE.CURSING_PLAYER;
- }
- if (getNearestObject(PORTAL, 20) != null) {
- return STATE.OUTSIDE_HOUSE;
- }
- if (!failsafe&&!isInsideHouse() && Objects.findNearest(20, PORTAL).length == 0) {
- return STATE.FAILSAFE;
- }
- return STATE.ERROR;
- }
- private void walkToRing() {
- if (isDoorOpen) {
- if (combatRingRope == null) {
- combatRingRope = Objects.find(50, COMBAT_RING_ROPE)[General.random(0,Objects.find(50, COMBAT_RING_ROPE).length-1)];
- }
- Walking.walkTo(combatRingRope.getPosition());
- while (Player.isMoving()) {
- Camera.turnToTile(combatRingRope.getPosition());
- }
- } else {
- if (combatRingArea.getDistanceFrom(Player.getPosition()) > 8) {
- openDoor();
- }
- }
- }
- private boolean isInsideHouse() {
- return Objects.find(25, INHOME_PORTAL) != null
- && Objects.find(25, INHOME_PORTAL).length > 0;
- }
- private void onStart() {
- // currentState = STATE.STARTING;
- startTime = System.currentTimeMillis();
- startLevel = Skills.getActualLevel("MAGIC");
- playerName += JOptionPane.showInputDialog(
- "Enter Player's name if it's not your house. Otherwise hit enter.", Player
- .getRSPlayer().getName());
- if (!Player.getRSPlayer().getName().equalsIgnoreCase(playerName)) {
- isYourHouse = false;
- General.println("This isn't your house@");
- }
- if(playerName.length() >1){
- started = true;
- }
- }
- @Override
- public void onPaint(Graphics g) {
- // MATH
- millis = System.currentTimeMillis() - startTime;
- hours = millis / (1000 * 60 * 60);
- millis -= hours * (1000 * 60 * 60);
- minutes = millis / (1000 * 60);
- millis -= minutes * (1000 * 60);
- seconds = millis / 1000;
- int CurrentExp = Skills.getXP("Magic");
- curseCount = (CurrentExp - startXp) / 29;
- countPerHour = (int) ((curseCount) * 3600000D / (System
- .currentTimeMillis() - startTime));
- expPerHour = (int) ((expGained) * 3600000D / (System
- .currentTimeMillis() - startTime));
- expGained = Skills.getXP("MAGIC") - startXp;
- curseTNL = Skills.getXPToLevel("MAGIC", currentLevel + 1) / 29;
- currentLevel = Skills.getCurrentLevel("MAGIC");
- levelsGained = currentLevel - startLevel;
- expToLevel = Skills.getXPToNextLevel("MAGIC");
- // DEBUG
- if (currentModel != null) {
- paintRSModel(g, currentModel);
- }
- if (currentDoorArea != null) {
- currentDoorArea.paintRSArea(g);
- }
- if (combatRingArea != null) {
- combatRingArea.paintRSArea(g);
- g.drawString(debug, 250, 300);
- }
- g.drawString(debug, 250, 300);
- if (minTile != null && maxTile != null) {
- g.setColor(Color.RED);
- drawTile(minTile, (Graphics2D) g, false);
- drawTile(maxTile, (Graphics2D) g, false);
- }
- g.setColor(Color.BLUE);
- drawTile(Player.getPosition(), (Graphics2D) g, false);
- g.setColor(Color.ORANGE);
- if (Game.getDestination() != null) {
- drawTile(Game.getDestination(), (Graphics2D) g, false);
- }
- // ACTUAL Paint
- g.drawImage(paint, 0, 300, null);
- // Status
- g.setColor(Color.WHITE);
- if (currentState != null) {
- state = currentState.toString();
- g.drawString(state, 195, 375);
- }
- // Time
- g.drawString(hours + ":" + minutes + ":" + seconds, 245, 395);
- g.drawString(formatTime(millis / curseTNL), 210, 413);
- // Level
- g.drawString(currentLevel + " ( " + levelsGained + " )", 220, 432);
- // XP
- g.drawString("" + expGained, 260, 450);
- g.drawString("" + expPerHour, 225, 470);
- }
- private boolean determineCombatRingArea() {
- if (getNearestObject("Combat ring", 50) != null) {
- status = " Determining Combat Ring Area...";
- int[] xCoords;
- int[] yCoords;
- combatRing = Objects.find(50, "Combat ring");
- xCoords = new int[combatRing.length];
- yCoords = new int[combatRing.length];
- for (int x = 0; x <= combatRing.length - 1; x++) {
- RSTile pos = combatRing[x].getPosition();
- xCoords[x] = pos.getX();
- yCoords[x] = pos.getY();
- }
- status = " Sorting Coordinates";
- Arrays.sort(xCoords);
- Arrays.sort(yCoords);
- minTile = new RSTile(xCoords[8], yCoords[8]);
- maxTile = new RSTile(xCoords[xCoords.length - 8],
- yCoords[yCoords.length - 8]);
- status = "Min Tile : " + minTile.toString() + " MaxTile : "
- + maxTile.toString();
- status = " Creating Area..";
- combatRingArea = new RSArea(minTile, maxTile);
- status = " Created Area!";
- return true;
- } else {
- status = "Could Not Find Combat Ring!";
- }
- return false;
- }
- public void createDoorArea() {
- if (currentDoor != null && currentDoorArea == null) {
- int x = currentDoor.getPosition().getX();
- int y = currentDoor.getPosition().getY();
- currentDoorArea = new RSArea(x - 1, y + 1, x + 1, y - 1);
- }
- }
- private void drawTile(RSTile tile, Graphics2D g, boolean fill) {
- if (tile.isOnScreen()) {
- if (fill) {
- g.fillPolygon(Projection.getTileBoundsPoly(tile, 0));
- } else {
- g.drawPolygon(Projection.getTileBoundsPoly(tile, 0));
- }
- }
- }
- private Image getImage(String url) {
- try {
- return ImageIO.read(new URL(url));
- } catch (MalformedURLException e) {
- } catch (IOException e) {
- }
- return null;
- }
- private RSObject getNearestObject(String id, int dist) {
- for (RSObject o : Objects.find(dist, id)) {
- if (o != null) {
- return o;
- }
- }
- return null;
- }
- private RSObject getNearestObject(int id, int dist) {
- for (RSObject o : Objects.find(dist, id)) {
- if (o != null) {
- return o;
- }
- }
- return null;
- }
- public Point getBestPoint(Point[] points) {
- int sumX = 0, sumY = 0;
- int averageX, averageY;
- int count = 0;
- for (Point p : points) {
- sumX += p.getX();
- sumY += p.getY();
- count++;
- }
- averageX = sumX / count;
- averageY = sumY / count;
- return averageX > 0 && averageY > 0 ? new Point(averageX, averageY)
- : null;
- }
- public boolean clickModel(RSModel model, String option, boolean rightClick) {
- Camera.turnToTile(model.getAnimableTile());
- Camera.setCameraAngle(General.random(60,70));
- Point[] points = model.getAllVisiblePoints();
- int length = points.length;
- if (length != 0) {
- Point p = getBestPoint(points);
- Mouse.move(p);
- {
- String top = Game.getUptext();
- if (top.contains(option)) {
- Mouse.click(p, 0);
- while(Player.isMoving()){
- sleep(200,250);
- }
- return true;
- } else if (rightClick) {
- Mouse.click(3);
- Timing.waitChooseOption(option,1300);
- if (!ChooseOption.isOpen())
- return false;
- if (ChooseOption.select(option))
- return true;
- }
- }
- }
- return false;
- }
- public void paintRSModel(Graphics g, RSModel m) {
- g.setColor(Color.GREEN);
- for (Polygon p : m.getTriangles()) {
- g.drawPolygon(p);
- }
- }
- private boolean typeString(final String s) {
- if (s.length() > 0) {
- Timing.waitCondition(new Condition() {
- @Override
- public boolean active() {
- return Interfaces.get(548, 94) != null;
- }
- }, 3000);
- sleep(924,1250);
- Keyboard.typeString(s);
- Timing.waitCondition(new Condition() {
- @Override
- public boolean active() {
- return Interfaces.get(548, 94) != null&&Interfaces.get(548, 94).getText().equals(playerName);
- }
- }, 3000);
- Keyboard.pressEnter();
- General.println("SENT :"+playerName);
- return true;
- }
- return false;
- }
- private String formatTime(long time) {
- return (time / (1000 * 60 * 60) + ":" + (time / (1000 * 60)) + ":" + (time / 1000));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement