Created
March 9, 2015 08:26
-
-
Save kryogenic/9b69581cbd8bdae92577 to your computer and use it in GitHub Desktop.
λCurser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.kryogenic.powerbot; | |
import org.powerbot.script.*; | |
import org.powerbot.script.rt4.*; | |
import org.powerbot.script.rt4.ClientContext; | |
import java.awt.*; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
/** | |
* @author: Kale | |
* @date: 2015-03-08 | |
*/ | |
@Script.Manifest(name = "λCurser", description = "Curses the monk in Varrock castle") | |
public class YCurser extends PollingScript<ClientContext> implements MessageListener, PaintListener { | |
int monkId = 2886; | |
Npc monk; | |
long lastCursed; | |
long nextCurse = getNextCurse(); | |
long startXp; | |
long startTime = 1; | |
@Override | |
public void start() { | |
startXp = ctx.skills.experience(Skills.MAGIC); | |
startTime = System.currentTimeMillis(); | |
} | |
@Override | |
public void poll() { | |
if(ctx.players.local().animation() == -1) { | |
if(System.currentTimeMillis() - lastCursed > nextCurse) { | |
if(!ctx.npcs.select().id(monkId).isEmpty()) { | |
monk = ctx.npcs.nearest().poll(); | |
ctx.magic.cast(Magic.Spell.CURSE); | |
if(!monk.inViewport()) { | |
ctx.camera.turnTo(monk); | |
} | |
if(monk.interact(true, "Cast", "Curse -> Monk of Zamorak")) { | |
lastCursed = System.currentTimeMillis(); | |
} | |
monk = null; | |
} | |
} | |
} | |
} | |
@Override | |
public void messaged(MessageEvent e) { | |
if(e.text().startsWith("You do not have enough")) { | |
ctx.controller.stop(); | |
} | |
} | |
@Override | |
public void repaint(Graphics g) { | |
if(monk != null) { | |
g.setColor(Color.RED); | |
monk.draw(g); | |
} | |
Color mouseColor = Color.BLACK; | |
Rectangle gameScreen = new Rectangle(ctx.game.dimensions()); | |
Point mouseLoc = ctx.input.getLocation(); | |
g.setColor(mouseColor); | |
g.drawLine(mouseLoc.x, 0, mouseLoc.x, gameScreen.height); | |
g.drawLine(0, mouseLoc.y, gameScreen.width, mouseLoc.y); | |
Color paintColor = new Color(175, 0, 0); | |
int x = 7; | |
int y = 345; | |
int pad = 5; | |
int height = 52; | |
int width = 506; | |
g.setColor(new Color(paintColor.getRed(), paintColor.getGreen(), paintColor.getBlue(), 200)); | |
g.fill3DRect(x, y, width, height, true); | |
y += 6; | |
g.setColor(Color.WHITE); | |
double xp = ctx.skills.experience(Skills.MAGIC) - startXp; | |
double runtime = System.currentTimeMillis() - startTime; | |
double xpph = xp / runtime * 3600000d; | |
g.drawString("λCurser", x + pad, y + pad); | |
y += 12; | |
g.drawString("Running for: " + getRuntimeString((long) runtime), x + pad, y + pad); | |
y += 12; | |
g.drawString("Magic XP Gained: " + xp, x + pad, y + pad); | |
y += 12; | |
g.drawString(String.format("Magic XP/hour: %.2f", xpph), x + pad, y + pad); | |
} | |
private String getRuntimeString(long runtime) { | |
long diffInDays = runtime/1000/86400; | |
long diffInHours = (runtime/1000 - 86400*diffInDays) / 3600; | |
long diffInMins = (runtime/1000 - 86400*diffInDays - 3600*diffInHours) / 60; | |
long diffInSecs = (runtime/1000 - 86400*diffInDays - 3600*diffInHours - 60*diffInMins); | |
StringBuilder sb = new StringBuilder(); | |
if(diffInDays > 0) { | |
sb.append(diffInDays).append(" days"); | |
} | |
if(diffInHours > 0) { | |
if(sb.length() > 0) { | |
sb.append(", "); | |
} | |
sb.append(diffInHours).append(" hours"); | |
} | |
if(diffInMins > 0) { | |
if(sb.length() > 0) { | |
sb.append(", "); | |
} | |
sb.append(diffInMins).append(" minutes"); | |
} | |
if(diffInSecs > 0) { | |
if(sb.length() > 0) { | |
sb.append(" and "); | |
} | |
sb.append(diffInSecs).append(" seconds"); | |
} | |
return sb.toString(); | |
} | |
private long getNextCurse() { | |
return Random.nextInt(42, 999); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment