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.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.Skills.SKILLS;
- import org.tribot.api.Timing;
- import org.tribot.api.input.Keyboard;
- 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.Inventory;
- import org.tribot.api2007.Login;
- import org.tribot.api2007.Objects;
- import org.tribot.api2007.PathFinding;
- 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.RSObject;
- import org.tribot.api2007.types.RSPlayer;
- import org.tribot.api2007.types.RSTile;
- import org.tribot.script.Script;
- import org.tribot.script.interfaces.Painting;
- import org.tribot.script.interfaces.RandomEvents;
- 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;}
- 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 ="";
- private long time;
- 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;
- private int countPerHour;
- 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;
- @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:
- break;
- case WALKING_TO_RING: walkToRing();
- break;
- case OPENING_DOOR:
- break;
- case CREATING_COMBAT_RING_AREA:
- break;
- case LOGGING_OUT:Login.logout();
- break;
- case FAILSAFE: failSafe();
- break;
- default:
- break;
- }
- }
- }
- public boolean openDoor(){
- debug = " GETTING DOOR...";
- if(getDoor() == null){
- isDoorOpen = true;
- }
- if(!isDoorOpen&¤tDoor == null){
- currentDoor =getDoor();
- currentDoorArea = RSArea.createRSArea(currentDoor.getPosition(),1);
- }
- else{
- if(!isDoorOpen){
- isDoorOpen = currentDoor.click();
- }
- debug = " DEBUG: "+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 currentDoor;
- }
- private boolean failSafe(){
- if(useTeleTab()&&!isYourHouse){
- sleep(2500);
- return getNearestObject(INHOME_PORTAL,5).click("Enter");
- }
- return false;
- }
- private boolean useTeleTab() {
- if(Inventory.getCount(POH_TAB)>0){
- if(Inventory.find(POH_TAB)[0].click())
- sleepWhileAnimating(3000,4500);
- return true;
- }
- else if(Inventory.getCount(POH_TAB)==0){
- Login.logout();
- stopScript();
- }
- return false;
- }
- private boolean hasRunes(){
- return Inventory.getCount(559)>0;
- }
- private void cursePlayer() {
- for(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());
- p.click();
- }
- }
- }
- }
- }
- private void getBackIntoHouse(){
- if(isYourHouse){
- if(Objects.findNearest(20,PORTAL).length >0){
- if(Objects.findNearest(20,PORTAL)[0].click("Enter")){
- if(NPCChat.selectOption("Go to your house",true)){
- sleep(3500);
- }
- }
- }
- }
- else{
- if(Objects.findNearest(20,PORTAL).length >0){
- if(Objects.findNearest(20,PORTAL)[0].click("Enter")){
- if(NPCChat.selectOption("Go to a friend's house",true)){
- sleep(650);
- Keyboard.typeString(playerName);
- sleep(250);
- Keyboard.pressEnter();
- sleep(3500);
- }
- }
- }
- }
- }
- private void getInRing() {
- if(combatRingRope == null){combatRingRope = getNearestObject(COMBAT_RING_ROPE,15);}
- if(combatRingRope.hover()){
- combatRingRope.click();
- sleepWhileAnimating(450,750);
- return;}
- return;
- }
- private STATE getState() {
- if(!started){
- onStart();
- return STATE.STARTING;
- }
- if(!hasRunes()){
- return STATE.LOGGING_OUT;
- }
- if(isInsideHouse()&&combatRingArea == null&&determineCombatRingArea()){
- return STATE.CREATING_COMBAT_RING_AREA;
- }
- if(isInsideHouse()&&!isDoorOpen&&openDoor()){
- return STATE.OPENING_DOOR;
- }
- if(isInsideHouse()&&!combatRingArea.isInArea(Player.getPosition())){
- if(combatRingArea.getDistanceFrom(Player.getPosition())>3){
- return STATE.WALKING_TO_RING;
- }
- return STATE.GETTING_IN_RING;
- }
- if(isInsideHouse()&&combatRingArea != null&&combatRingArea.isInArea(Player.getPosition())){
- return STATE.CURSING_PLAYER;
- }
- if(getNearestObject(PORTAL,20) !=null){
- return STATE.OUTSIDE_HOUSE;
- }
- if(!isInsideHouse()&&Objects.findNearest(20,PORTAL).length==0 ){
- return STATE.FAILSAFE;
- }
- return null;
- }
- private void walkToRing(){
- if(isDoorOpen){
- if(combatRingRope == null){combatRingRope = getNearestObject(COMBAT_RING_ROPE,50);}
- Walking.walkTo(combatRingRope.getPosition());
- while(Player.isMoving()){
- if(Game.getDestination() != null )
- Camera.turnToTile(getNearestObject("Combat ring",50).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",Player.getRSPlayer().getName());
- if(!Player.getRSPlayer().getName().equalsIgnoreCase(playerName)||playerName.equals("")){
- isYourHouse = false;
- General.println("This is your house@");
- }
- 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(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);}
- g.setColor(Color.GREEN);
- g.drawString("STATUS: "+status,210,410);
- // 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){
- 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));
- }
- }
- }
- /**@author Druid
- * @return Sleeps while your Animation isn't 1*/
- private void sleepWhileAnimating(int min,int max) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < 3000 && Player.getAnimation() != -1) {
- General.println("Sleeping....");
- sleep(min,max);
- }
- }
- 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;
- }
- 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