- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Point;
- import java.awt.Polygon;
- import java.text.NumberFormat;
- import org.rsbot.event.events.ServerMessageEvent;
- import org.rsbot.event.listeners.PaintListener;
- import org.rsbot.event.listeners.ServerMessageListener;
- import org.rsbot.script.Script;
- import org.rsbot.script.ScriptManifest;
- import org.rsbot.script.methods.Skills;
- import org.rsbot.script.util.Filter;
- import org.rsbot.script.wrappers.RSArea;
- import org.rsbot.script.wrappers.RSComponent;
- import org.rsbot.script.wrappers.RSModel;
- import org.rsbot.script.wrappers.RSNPC;
- import org.rsbot.script.wrappers.RSTile;
- @ScriptManifest(authors = {"jtryba"}, keywords = "combat", name = "monkR8per",
- version = 1.0, description = ("Kills monks at the monastery... " +
- "Heals at 50% health.. Enjoy."))
- public class monkR8per extends Script implements PaintListener,
- ServerMessageListener {
- public RSTile headMonkTile = new RSTile(3056, 3483);
- public RSArea monkArea = new RSArea(new RSTile(3041, 3480),
- new RSTile(3062, 3501));
- public boolean firstRun = true, clickContinue = false, justHealed = false,
- healing = false;
- public int healAtPercent = 50;
- public int monkID = 7727, headMonkID = 801;
- public int maxHP;
- public int totalHealed = 0, deaths = 0;
- public long startTime, runTime;
- public String status = "";
- public int defExpGained = 0, strExpGained = 0, attExpGained = 0,
- conExpGained = 0, magExpGained = 0, ranExpGained = 0, totalExpGained = 0;
- public int defLvlGained = 0, strLvlGained = 0, attLvlGained = 0,
- conLvlGained = 0, magLvlGained = 0, ranLvlGained = 0, totalLvlGained = 0,
- combatLevelsGained = 0;
- public int startDefExp = 0, startAttExp = 0, startStrExp = 0, startConExp = 0,
- startMagExp = 0, startRanExp = 0;
- Color colorGreen = new Color(0, 255, 0, 50);
- Color colorBlue = new Color(0, 0, 255, 200);
- Color colorRed = new Color(255, 0, 0, 50);
- public final Filter<RSNPC> filter = new Filter<RSNPC>() {
- public boolean accept(RSNPC npc) {
- return !npc.isInCombat() && npcPresent(npc) && npc.getID() == monkID;
- }
- private boolean npcPresent(RSNPC npc) {
- return npc != null && monkArea.contains(npc.getLocation());
- }
- };
- @Override
- public int loop() {
- if (game.isLoggedIn() && skills.getCurrentLevel(Skills.CONSTITUTION) > 1) {
- if (firstRun) {
- setup();
- }
- runTime = System.currentTimeMillis() - startTime;
- keepTrackOfSkills();
- mouse.setSpeed(random(3, 6));
- camera.setPitch(true);
- checkRun();
- countHeals();
- if (clickContinue) {
- if (interfaces.canContinue()) {
- interfaces.clickContinue();
- clickContinue = false;
- return random(500, 750);
- }
- }
- if (atMonks()) {
- if (needsToHeal() || healing) {
- healing = true;
- status = "Cura";
- RSComponent interface1 = interfaces.getComponent(241, 5);
- RSComponent interface2 = interfaces.getComponent(230, 2);
- RSComponent interface3 = interfaces.getComponent(64, 5);
- RSComponent interface4 = interfaces.getComponent(210, 2);
- if (interface1.isValid()) {
- interface1.doClick();
- return random(750, 1000);
- } else if (interface2.isValid()) {
- interface2.doClick();
- return random(750, 1000);
- } else if (interface3.isValid()) {
- interface3.doClick();
- return random(750, 1000);
- } else if (interface4.isValid()) {
- interface4.doClick();
- justHealed = true;
- healing = false;
- return random(750, 1000);
- } else {
- RSNPC headMonk = npcs.getNearest(headMonkID);
- if (headMonk != null) {
- if (calc.tileOnScreen(headMonk.getLocation())) {
- camera.turnToTile(headMonk.getLocation(), 5);
- headMonk.doAction("Falar");
- return random(750, 1250);
- } else {
- if (!getMyPlayer().isMoving()) {
- RSTile path[] = walking.findPath(headMonkTile);
- walking.walkPathMM(path);
- return random(750, 1000);
- }
- }
- }
- }
- } else if (!inCombat()) {
- RSNPC monk = npcs.getNearest(filter);
- if (monk != null) {
- camera.turnToTile(monk.getLocation(), 5);
- if (monk.isOnScreen()) {
- status = "Atacar monge";
- monk.doAction("Atacar " + monk.getName());
- return random(750, 1000);
- } else if (calc.distanceTo(monk.getLocation()) < 7) {
- status = "Caminhando para monge";
- if (!getMyPlayer().isMoving()) {
- walking.walkTileOnScreen(monk.getLocation());
- return random(750, 1000);
- }
- return 1;
- } else if (calc.distanceTo(monk.getLocation()) >= 7) {
- status = "Caminhando para monge";
- if (!getMyPlayer().isMoving()) {
- RSTile path[] = walking.findPath(monk.getLocation());
- walking.walkPathMM(path);
- return random(750, 1000);
- }
- return 1;
- }
- } else {
- status = "esperando";
- return random(5, 10);
- }
- } else if (inCombat()) {
- status = "Combate";
- return random(5, 10);
- }
- } else {
- RSTile destination = monkArea.getCentralTile();
- if (!getMyPlayer().isMoving()) {
- RSTile path[] = walking.findPath(destination);
- walking.walkPathMM(path);
- return random(750, 1000);
- }
- return random(1, 5);
- }
- }
- return random(1, 5);
- }
- private void countHeals() {
- if (justHealed && !needsToHeal()) {
- totalHealed++;
- justHealed = false;
- }
- }
- private boolean needsToHeal() {
- return currentHP() <= healAt();
- }
- private double healAt() {
- String HAP = "." + healAtPercent;
- return maxHP() * Double.parseDouble(HAP);
- }
- private double maxHP() {
- return skills.getCurrentLevel(Skills.CONSTITUTION) * 10;
- }
- public int currentHP() {
- return Integer.parseInt(interfaces.getComponent(748, 8).getText());
- }
- private boolean inCombat() {
- return getMyPlayer().getInteracting() != null &&
- getMyPlayer().getInteracting().getHPPercent() > 0;
- }
- private void checkRun() {
- if (!walking.isRunEnabled() && walking.getEnergy() > random(15, 30)) {
- walking.setRun(true);
- sleep(random(500, 750));
- }
- }
- private boolean atMonks() {
- return monkArea.contains(getMyPlayer().getLocation());
- }
- private int countKills() {
- return (int) (conExpGained / 20);
- }
- public double getVersion(){
- return getClass().getAnnotation(ScriptManifest.class).version();
- }
- public String formatTime(final int milliseconds) {
- final long t_seconds = milliseconds / 1000;
- final long t_minutes = t_seconds / 60;
- final long t_hours = t_minutes / 60;
- final int seconds = (int) (t_seconds % 60);
- final int minutes = (int) (t_minutes % 60);
- final int hours = (int) (t_hours % 60);
- return NumberFormat.getInstance().format(hours) + ":"
- + NumberFormat.getInstance().format(minutes) + ":"
- + NumberFormat.getInstance().format(seconds);
- }
- private void setup() {
- startTime = System.currentTimeMillis();
- startDefExp = skills.getCurrentExp(Skills.DEFENSE);
- startAttExp = skills.getCurrentExp(Skills.ATTACK);
- startStrExp = skills.getCurrentExp(Skills.STRENGTH);
- startConExp = skills.getCurrentExp(Skills.CONSTITUTION);
- startMagExp = skills.getCurrentExp(Skills.MAGIC);
- startRanExp = skills.getCurrentExp(Skills.RANGE);
- if (combat.isAutoRetaliateEnabled()) {
- combat.setAutoRetaliate(true);
- sleep(random(1000, 1500));
- }
- firstRun = false;
- }
- private void keepTrackOfSkills() {
- int currentDefExp = skills.getCurrentExp(Skills.DEFENSE);
- int currentAttExp = skills.getCurrentExp(Skills.ATTACK);
- int currentStrExp = skills.getCurrentExp(Skills.STRENGTH);
- int currentConExp = skills.getCurrentExp(Skills.CONSTITUTION);
- int currentMagExp = skills.getCurrentExp(Skills.MAGIC);
- int currentRanExp = skills.getCurrentExp(Skills.RANGE);
- defExpGained = currentDefExp - startDefExp;
- strExpGained = currentStrExp - startStrExp;
- attExpGained = currentAttExp - startAttExp;
- conExpGained = currentConExp - startConExp;
- magExpGained = currentMagExp - startMagExp;
- ranExpGained = currentRanExp - startRanExp;
- totalExpGained = defExpGained + strExpGained + attExpGained
- + conExpGained + magExpGained + ranExpGained;
- totalLvlGained = defLvlGained + strLvlGained + attLvlGained
- + conLvlGained + magLvlGained + ranLvlGained;
- }
- @Override
- public void serverMessageRecieved(ServerMessageEvent e) {
- final String serverString = e.getMessage().toLowerCase();
- if (serverString.contains("you've just advanced")) {
- if (serverString.contains("strength level"))
- strLvlGained++;
- if (serverString.contains("attack level"))
- attLvlGained++;
- if (serverString.contains("defence level"))
- defLvlGained++;
- if (serverString.contains("constitution level"))
- conLvlGained++;
- if (serverString.contains("magic level"))
- magLvlGained++;
- if (serverString.contains("ranged level"))
- ranLvlGained++;
- log("Gratz you just gained a level");
- clickContinue = true;
- }
- if (serverString.contains("oh dear"))
- deaths++;
- if (serverString.contains("reached combat level"))
- combatLevelsGained++;
- }
- @Override
- public void onRepaint(Graphics render) { // TODO finish this
- Graphics2D g = (Graphics2D)render;
- if (game.isLoggedIn()) {
- drawNextMonk(g);
- drawMouse(g);
- g.setColor(colorGreen);
- g.fillRoundRect(10, 185, 150, 145, 16, 16);
- g.setColor(Color.BLACK);
- g.setFont(new Font("sansserif", Font.PLAIN, 12));
- g.drawString("Status: " + status, 13, 200);
- g.drawString("Kills: " + countKills(), 13, 220);
- g.drawString("Healed: " + totalHealed, 13, 240);
- g.drawString("Deaths: " + deaths, 13, 260);
- g.drawString("Runtime: " + formatTime((int) runTime), 13, 280);
- g.drawString("Levels: " + totalLvlGained, 13, 300);
- g.drawString("CB Levels: " + combatLevelsGained, 13, 320);
- }
- }
- private void drawMouse(final Graphics g) {
- final Point loc = mouse.getLocation();
- g.setColor(Color.BLACK);
- g.drawLine(0, loc.y, 766, loc.y);
- g.drawLine(loc.x, 0, loc.x, 505);
- }
- public void drawNextMonk(Graphics g) {
- RSNPC npc = npcs.getNearest(filter);
- if (npc != null) {
- RSModel model = npc.getModel();
- if (model != null) {
- g.setColor(colorGreen);
- for (Polygon p : model.getTriangles()) {
- g.fillPolygon(p);
- }
- }
- overlayText(g, npc.getLocation(), colorBlue, "Next monk");
- }
- }
- public void overlayText(final Graphics g, final RSTile t,
- final Color c, final String text) {
- final Point p = calc.tileToScreen(t);
- final Point pn = calc.tileToScreen(new RSTile
- (t.getX(), t.getY()), 0);
- final Point px = calc.tileToScreen(new RSTile
- (t.getX() + 1, t.getY()), 0);
- final Point py = calc.tileToScreen(new RSTile
- (t.getX(), t.getY() + 1), 0);
- final Point pxy = calc.tileToScreen(new RSTile
- (t.getX() + 1, t.getY() + 1), 0);
- final Point[] points = { p, pn, px, py, pxy };
- for (final Point point : points) {
- if (!calc.pointOnScreen(point)) {
- return;
- }
- }
- g.setColor(c);
- g.setFont(new Font("sansserif", Font.BOLD, 12));
- g.drawString(text, p.x - 30, p.y - 40);
- }
- }