import java.text.*;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.util.Map;
import org.rsbot.bot.Bot;
import org.rsbot.bot.input.CanvasWrapper;
import org.rsbot.bot.input.Mouse;
import org.rsbot.event.events.ServerMessageEvent;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.event.listeners.ServerMessageListener;
import org.rsbot.script.Constants;
import org.rsbot.script.Script;
import org.rsbot.script.ScriptManifest;
import org.rsbot.script.wrappers.RSItemTile;
import org.rsbot.script.wrappers.RSTile;
import org.rsbot.script.wrappers.RSInterfaceComponent;
import org.rsbot.script.wrappers.RSNPC;
import org.rsbot.script.Skills;
import org.rsbot.script.wrappers.RSPlayer;
import org.rsbot.script.Methods;
@ScriptManifest(authors = { "Coco" }, category = "Combat", name = "The Devil's sent", version = 1.0, description = "<html><body><h2>" +
"The Devil's sent</h2><hr>by Coco<br><input name='bury' type='checkbox' value='1'>Bury the bones<br />"
+ "<select name=\"arrowtype\">"
+ "<option> Nothing"
+ "<option> Bronze"
+ "<option> Iron"
+ "<option> Steel"
+" </select> What arrows are you going to use? (if any)<p>Just start in the monastery</body></html>")
public class TheDevilssent extends Script implements PaintListener, ServerMessageListener {
public long startTime = System.currentTimeMillis();
public long lastExpTime;
public int levelup = 0;
public int i = 0;
public int counter = 0;
public int healcount =0;
public int failcount = 0;
public int arrow = 0; //bronze
public final int bronze = 882, iron = 884, steel = 886;
public String arrowtype = "";
public boolean burybones = false;
public RSTile center = new RSTile (3045, 3490);
public RSTile south = new RSTile (3045, 3483);
public RSTile north = new RSTile (3045, 3496);
public RSNPC monk;
public double startExp[] = null;
public double expGained[] = null;
public double expPerHour[] = null;
public int expG, auxExp, noexpcounter;
public float totalSec = 0;
@Override
public int loop() {
if (distanceTo(new RSTile(3050, 3492)) > 25 && !getMyPlayer().isMoving() && isLoggedIn()) {
walkTo(new RSTile(3050, 3492));
failcount++;
return 1;
}
if (failcount >= 5) {
log("Lost");
logout();
return -1;
}
final Methods methods = new Methods();
if (methods.getCurrentLifePoints() <= 100) { // get healed, we are dying
if (getMyPlayer().getInteracting() == null) { //doing nothing
while (methods.getCurrentLifePoints() < (skills.getRealSkillLevel(STAT_HITPOINTS)*10)) {
getHealed();
}
healcount++;
if (distanceTo(center) > 5) walkTileMM(center,0,0);
log("just healed, back to center");
//here we just got healed
failcount = 0;
return 1;
}
}
if (getDestination() != null) {
if ((getDestination().getX() < 3044 || getDestination().getY() > 3498) && monk!=null) { //going outside the monastery?
if (distanceBetween(getDestination(), north) <= 5) {
if (!tileOnScreen(north)) {
walkTileMM(north,0,0);
} else {
walkTileOnScreen(north);
}
return 450;
}
if (distanceBetween(getDestination(), south) <= 5) {
if (!tileOnScreen(south)) {
walkTileMM(south,0,0);
} else {
walkTileOnScreen(south);
}
return 450;
}
} else if (monk == null) {
if (!tileOnScreen(center)) {
walkTileMM(center,0,0);
} else {
walkTileOnScreen(center);
}
}
}
if (!isRunning() && getEnergy() > random(60, 75)) {
setRun(true);
wait(random(400, 800));
}
if (getMyPlayer().getInteracting() == null && distanceTo(getGroundItemByID(526)) < 5 && burybones && getGroundItemByID(526) != null) {
//doing nothing, bone near, we are trying to bury, there's a bone.
atTile(getGroundItemByID(526), "Take");
return(860);
}
if (getGroundItemByID(arrow) != null && distanceTo(getGroundItemByID(arrow)) < 7 && getGroundItemByID(arrow).getItem().getStackSize() > 3) { //will pick up arrows if
while (getMyPlayer().isInCombat() && getMyPlayer().getInteracting() != null) {
/* we are close to them and not fighting, AND they are 3 or more*/
wait(300);
}
atTile(getGroundItemByID(arrow), "Take");
return (1000);
}
monk = getNearestFreeNPCToAttackByID(7727);
if (getDestination() != null && monk != null) { //walking somewhere, but this monks is closer, OM NOM
if (distanceBetween(monk.getLocation(), getDestination()) > 3) { // we have a monk nearer than the one we are trying to get, probably just respawned
if (distanceTo(monk.getLocation()) +1 < distanceTo(getDestination())) { //COMPLETELY SURE, the monk is closer
if (tileOnScreen(monk.getLocation())) {
atNPC(monk, "Attack");
return 1500;
} else {
walkTileMM(monk.getLocation(),0,0);
return 1500;
}
}
}
}
if (getInventoryCount(arrow) > 50) {
atInventoryItem(arrow, "Wield");
return 600;
}
if (getInventoryCount(526) > 0 && !burybones) {
atInventoryItem(526, "Drop");
return 600;
}
if (isInventoryFull() && burybones && getInventoryCount(526) > 0) {
while (getInventoryCount(526) > 0) {
atInventoryItem(526, "Bury");
wait(500);
}
}
if (getMyPlayer().getInteracting() == null) { // doing nothing .. go attack
monk = getNearestFreeNPCToAttackByID(7727);
if (monk == null) {
if (!getMyPlayer().isMoving() && getMyPlayer().getInteracting() == null) {
if (burybones && getGroundItemByID(526) != null) { //will bury and there's a bone here
atTile(getGroundItemByID(526), "Take");
return 600;
}
if(distanceTo(center) > 5) {
if (!tileOnScreen(center)) {
walkTileMM(center,0,2); // no monk, going to the middle so we are near to the three spawnsç
} else {
walkTileOnScreen(center);
}
wait(599);
}
customRest();
//} will rest until a monk appears
}
return 500;
}// no monk what the hell
if (!tileOnScreen(monk.getLocation()) && !getMyPlayer().isMoving()){
if (distanceBetween(monk.getLocation(), north) <= 5) {
if (!tileOnScreen(north)) {
walkTileMM(north,0,0);
} else {
walkTileOnScreen(north);
}
return 350;
}
if (distanceBetween(monk.getLocation(), south) <= 5) {
if (!tileOnScreen(south)) {
walkTileMM(south,0,0);
} else {
walkTileOnScreen(south);
}
return 350;
} // center has no troubles so go there :D
if (!tileOnScreen(monk.getLocation())) {
walkTileMM(monk.getLocation(),0,0);
} else {
walkTileOnScreen(monk.getLocation());
}
return 500;
}// monk is away, go there
if(monk != null ) clickRSNPC(monk, "Attack"); // we are near the monk, DIE!
return 800;
}
return (random(100, 200));
}
public void getHealed() {
/*if (distanceTo(new RSTile(3058, 3484)) > distanceTo(center)) {
if (!tileOnScreen(new RSTile(3058, 3484))) {
walkTileMM(new RSTile(3058, 3484),0,0);
wait(800);
} else {
walkTileOnScreen(new RSTile(3058, 3484));
wait(1500);
}
return;
}*/
if (distanceTo(new RSTile(3058, 3484)) > 5 /*&& !getMyPlayer().isMoving()*/) {
if (!tileOnScreen(new RSTile(3058, 3484))) {
walkTileMM(new RSTile(3058, 3484),0,0);
wait(1500);
} else {
walkTileOnScreen(new RSTile(3058, 3484));
wait(900);
}
}
if (getInterface(241).isValid()) {
atInterface(getInterface(241).getChild(5), "Continue"); //twice
wait(1000);
return;
}
if (getInterface(230).isValid()) {
atInterface(getInterface(230).getChild(2), "Continue");
wait(800);
return;
}
if (getInterface(64).isValid()) {
atInterface(getInterface(64).getChild(5), "Continue");
wait(800);
return;
}
if (getInterface(210).isValid()) {
atInterface(getInterface(210).getChild(2), "Continue");
wait(800);
return;
}
atNPC(getNearestNPCByID(801), "Talk");
wait(700);
return;
}
public void onRepaint(final Graphics g) {
if (!isLoggedIn()) return;
long millis = System.currentTimeMillis() - startTime;
long noexpmillis =System.currentTimeMillis();
final long hours = millis / (1000 * 60 * 60);
millis -= hours * 1000 * 60 * 60;
final long minutes = millis / (1000 * 60);
millis -= minutes * 1000 * 60;
final long seconds = millis / 1000;
totalSec = hours * 3600 + minutes * 60 + seconds;
if (auxExp < expG) { //gained exp, reset counter
auxExp = expG;
lastExpTime = System.currentTimeMillis();
}
if ((noexpmillis - lastExpTime)/ 1000 >= 120 && lastExpTime> 0) { //seconds 120 = 2 mins
log("2 minutes without getting exp, logging off");
stopScript();
// mb add world swithcing?
}
g.setColor(Color.black);
g.fillRoundRect(528,281,229,181,10,10);
g.setColor(Color.white);
g.drawString("Coco's Devil sent", 593,295);
int counter = 0;
expG = 0;
for ( int i = 0; i < 7; i++ ) {
if ((startExp != null) && ((skills.getCurrentSkillExp(i) - startExp[i]) > 0)) {
expGained[i] =skills.getCurrentSkillExp(i) - startExp[i]; // exp gained
expPerHour[i] = skills.getXPToNextLevel(i) /* xp left */ / (expGained[i] / totalSec );
expPerHour[i] = expPerHour[i] / 60;
expG = expG + (int)expGained[i];
counter++;
g.drawString(skills.statsArray[i],540, 320 + (15*counter));
g.drawLine(535, 323 + (15*counter), 750,323 + (15*counter)); //separates skills
if (totalSec >=60) {
if ((double)expPerHour[i] >= 1) {
g.drawString(""+(int)expGained[i],598, 320 + (15*counter));
g.drawString(getFormattedNumber((double)expPerHour[i]) + "min", 643, 320 + (15*counter));
g.drawString(""+ (int) ((expGained[i] *3600/ totalSec)), 700, 320 + (15*counter));
}
} else {
g.drawString(""+(int)expGained[i],598, 320 + (15*counter));
g.drawString("Wait", 648, 320 + (15*counter));
g.drawString("till min >= 1", 700, 320 + (15*counter));
}
}
}
g.drawString("Got healed: " + healcount + " times", 540, 440);
g.drawString("Runtime: " + hours + " hs " + minutes + " min " + seconds + " secs.", 540, 455);
//53 cada parte, ~32 de "SKILL" -> 10 al startx
g.drawLine(535, 300, 750,300); //underlines script name
g.drawString("SKILL", 545, 315);
g.drawLine(535, 320, 750,320); //underline "SKILL",, etc
g.drawLine(588, 300,588, 410); //second column divider SKILL || EXPG
g.drawString("EXP G", 598, 315);
g.drawLine(641, 300,641, 410); //third column divider EXPG || TIME LEFT
g.drawString("Time L", 648, 315);
g.drawLine(694, 300,694, 410); //foruth column divider TIME LEFT || %
g.drawString("Exp/Hour", 700, 315);
}
@Override
protected int getMouseSpeed() {
return 4;
}
@Override
public boolean onStart(final Map<String, String> args) {
burybones = args.get("bury") != null;
arrowtype = args.get("arrowtype");
if (arrowtype != null) arrowtype = arrowtype.replace("\uc2a0", " ");
startExp = new double[7];
expGained = new double[7];
expPerHour = new double[7];
for ( int i = 0; i < 7; i++ ) {
startExp[i] = skills.getCurrentSkillExp(i);
}
if (burybones) {
log("Burying bones");
} else {
log ("Not burying bones");
}
arrow = 0;
if (arrowtype.equals("Bronze")) arrow = bronze;
if (arrowtype.equals("Iron")) arrow = iron;
if (arrowtype.equals("Steel")) arrow = steel;
//shouldn't check that..
if (getInventoryCount(arrow) > 50) {
atInventoryItem(arrow, "Wield");
wait(1500);
}
if (arrow > 0) log("Using : " + arrowtype + " arrows");
startTime = System.currentTimeMillis();
setCameraAltitude(true);
return true;
}
public void serverMessageRecieved( ServerMessageEvent arg0 ) {
String serverString = arg0.getMessage();
if (serverString.contains("You've just") || serverString.contains("Congratulations")) {
log("You just advanced a level, attempting to click continue!");
levelup++;
wait(random(1500, 2500));
if (canContinue()) {
clickContinue();
}
}
if (serverString.contains("no ammo left in") || serverString.contains("quiver")) {
log("no ammo cya");
openTab(TAB_EQUIPMENT);
atInterface(getInterface(387).getChild(17), "Remove");
stopScript();
}
}
public void onFinish() {
int i = 0;
log ("After " + getFormattedNumber((double)(totalSec / 60)) + " minutes: ");
for ( i = 0; i < 7; i++ ) {
if ((startExp != null) && ((skills.getCurrentSkillExp(i) - startExp[i]) > 0)) {
log("Gained: " + expGained[i] + " exp on " + skills.statsArray[i]);
}
}
log("and got healed " + healcount + " times. See you next time :) ");
}
public boolean customRest() {
//int energy = getEnergy();
for (int d = 0; d < 5; d++) {
atInterface(Constants.INTERFACE_RUN_ORB, 1, "Rest");
moveMouseSlightly();
wait(random(400, 600));
if (getMyPlayer().getAnimation() == 12108
|| getMyPlayer().getAnimation() == 2033
|| getMyPlayer().getAnimation() == 2716
|| getMyPlayer().getAnimation() == 11786
|| getMyPlayer().getAnimation() == 5713) {
break;
}
if (d == 4) {
log("Rest failed!");
return false;
}
}
while (monk == null) {
monk = getNearestFreeNPCToAttackByID(7727);
wait(random(250, 500));
//energy = getEnergy();
}
return true;
}
public String getFormattedNumber(Double p_number) {
NumberFormat l_nf = NumberFormat.getInstance();
String l_rVal; // Valor de retorno de la función.
l_nf.setMaximumFractionDigits(1); // 2 decimales como mucho y como poco
l_nf.setMinimumFractionDigits(1);
l_rVal = new String ( l_nf.format(p_number.doubleValue()));
return l_rVal;
}
}