Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package core;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics2D;
- import java.awt.Window;
- import javax.swing.*;
- import java.lang.reflect.InvocationTargetException;
- import org.osbot.rs07.api.model.NPC;
- import org.osbot.rs07.api.ui.RS2Widget;
- import org.osbot.rs07.api.ui.Skill;
- import org.osbot.rs07.api.ui.Spells.NormalSpells;
- import org.osbot.rs07.api.ui.Tab;
- import org.osbot.rs07.script.Script;
- import org.osbot.rs07.script.ScriptManifest;
- @ScriptManifest(author = "Heist", info = "Trains magic on the demon in the wizard tower", name = "Heist's Demon Killer", version = 0.1, logo = "https://i.imgur.com/zW8GXPt.jpg")
- public class Main extends Script {
- private GUI gui = new GUI();
- private Spell spell;
- private Style style;
- //time
- private long timeBegan;
- private long timeRan;
- // magic
- private int beginningXp;
- private int currentXp;
- private int xpGained;
- private int currentLevel;
- private int beginningLevel;
- private int levelsGained;
- // defense
- private int beginningXp1;
- private int currentXp1;
- private int xpGained1;
- private int currentLevel1;
- private int beginningLevel1;
- private int levelsGained1;
- @Override
- public void onStart() throws InterruptedException {
- setWindowTitle();
- timeBegan = System.currentTimeMillis();
- beginningXp = skills.getExperience(Skill.MAGIC);
- beginningLevel = skills.getStatic(Skill.MAGIC);
- beginningXp1 = skills.getExperience(Skill.DEFENCE);
- beginningLevel1 = skills.getStatic(Skill.DEFENCE);
- try {
- SwingUtilities.invokeAndWait(() -> {
- gui = new GUI();
- gui.open();
- });
- } catch (InterruptedException | InvocationTargetException e) {
- e.printStackTrace();
- stop();
- return;
- }
- if (!gui.isStarted()) { // If the user closed the dialog and didn't click the Start button
- stop();
- return;
- }
- log("Heist's Demon Killer has started!");
- zoomOut();
- spell = gui.getSelectedSpell();
- style = gui.getSelectedCombatStyle();
- if (style.toString().toLowerCase().contentEquals("defensive")) {
- log("Setting combat style to defensive.");
- canAttack();
- getTabs().open(Tab.ATTACK);
- Sleep.sleepUntil(() -> getTabs().isOpen(Tab.ATTACK), 5000);
- RS2Widget w = widgets.get(593, 22);
- if (w != null && w.isVisible()) {
- w.interact("Choose spell");
- } else {
- log("[Error] Spellbook widget not found.");
- }
- Sleep.sleepUntil(() -> widgets.isVisible(201), 5000);
- selectSpell();
- } else {
- log("Setting combat style to offensive.");
- canAttack();
- getTabs().open(Tab.ATTACK);
- Sleep.sleepUntil(() -> getTabs().isOpen(Tab.ATTACK), 5000);
- RS2Widget w = widgets.get(593, 26);
- if (w != null && w.isVisible()) {
- w.interact("Choose spell");
- } else {
- log("[Error] Spellbook widget not found.");
- }
- Sleep.sleepUntil(() -> widgets.isVisible(201), 5000);
- selectSpell();
- }
- }
- private void setWindowTitle() {
- Window w = SwingUtilities.getWindowAncestor(bot.getCanvas());
- JFrame f = (JFrame) w;
- f.setTitle("RuneLite");
- }
- private void zoomOut() {
- if (client.accessor.getScaleZ() > 1200) {
- log("Zooming out.");
- getTabs().open(Tab.SETTINGS);
- Sleep.sleepUntil(() -> getTabs().isOpen(Tab.SETTINGS), 5000);
- RS2Widget w = widgets.get(261, 9);
- if (w != null && w.isVisible()) {
- w.interact();
- } else {
- log("[Error] Zoom function not found.");
- }
- }
- }
- @Override
- public int onLoop() throws InterruptedException {
- NPC LesserDemon = npcs.closest("Lesser demon");
- dismissDialogue();
- if(!canAttack()) {
- this.stop();
- log("[Error] Out of runes.");
- }
- if (LesserDemon != null) {
- if (LesserDemon.isVisible()) {
- if (((!myPlayer().isAnimating()) && !getCombat().isFighting()) && !myPlayer().isMoving()
- && LesserDemon.getHealthPercent() > 0) {
- attack();
- }
- } else {
- getCamera().toEntity(LesserDemon); // move camera to demon if it isn't visible
- }
- }
- return (random(600, 900)); // time before loop starts over
- }
- private void dismissDialogue() throws InterruptedException { // dismiss level-up dialogue
- if (dialogues.inDialogue()) {
- dialogues.clickContinue();
- log("Dismissing dialogue.");
- }
- }
- private boolean canAttack() throws InterruptedException {
- if(spell.toString().toLowerCase().equals("firestrike")) {
- return canUseFireStrike();
- }
- if(spell.toString().toLowerCase().equals("earthstrike")) {
- return canUseEarthStrike();
- }
- if(spell.toString().toLowerCase().equals("waterstrike")) {
- return canUseWaterStrike();
- }
- if(spell.toString().toLowerCase().equals("airstrike")) {
- return canUseAirStrike();
- }
- return false;
- }
- private boolean canUseFireStrike() throws InterruptedException {
- return getMagic().canCast(NormalSpells.FIRE_STRIKE, false);
- }
- private boolean canUseEarthStrike() throws InterruptedException {
- return getMagic().canCast(NormalSpells.EARTH_STRIKE, false);
- }
- private boolean canUseWaterStrike() throws InterruptedException {
- return getMagic().canCast(NormalSpells.WATER_STRIKE, false);
- }
- private boolean canUseAirStrike() throws InterruptedException {
- return getMagic().canCast(NormalSpells.WIND_STRIKE, false);
- }
- private void attack() throws InterruptedException {
- if (canAttack()) {
- NPC LesserDemon = npcs.closest("Lesser demon");
- if(LesserDemon != null && LesserDemon.isVisible()) {
- LesserDemon.interact("Attack");
- log("Attacking demon.");
- } else {
- log("[Error] Demon not found.");
- }
- }
- }
- private void selectSpell() throws InterruptedException {
- if (spell.toString().toLowerCase().equals("firestrike")) {
- RS2Widget w = widgets.get(201, 1, 4);
- if (w != null && w.isVisible()) {
- w.interact("Fire Strike");
- }
- Sleep.sleepUntil(() -> widgets.isVisible(593), 5000);
- }
- if (spell.toString().toLowerCase().equals("earthstrike")) {
- RS2Widget w = widgets.get(201, 1, 3);
- if (w != null && w.isVisible()) {
- w.interact("Earth Strike");
- }
- Sleep.sleepUntil(() -> widgets.isVisible(593), 5000);
- }
- if (spell.toString().toLowerCase().equals("waterstrike")) {
- RS2Widget w = widgets.get(201, 1, 2);
- if (w != null && w.isVisible()) {
- w.interact("Water Strike");
- }
- Sleep.sleepUntil(() -> widgets.isVisible(593), 5000);
- }
- if (spell.toString().toLowerCase().equals("airstrike")) {
- RS2Widget w = widgets.get(201, 1, 1);
- if (w != null && w.isVisible()) {
- w.interact("Wind Strike");
- }
- Sleep.sleepUntil(() -> widgets.isVisible(593), 5000);
- }
- }
- @Override
- public void onExit() {
- if (gui != null) {
- gui.close();
- }
- log("Heist's Demon Killer has exited.");
- }
- private final String ft(final long ms){
- long s = ms / 1000, m = s / 60, h = m / 60, d = h / 24;
- s %= 60; m %= 60; h %= 24;
- return d > 0 ? String.format("%02d:%02d:%02d:%02d", d, h, m, s) :
- h > 0 ? String.format("%02d:%02d:%02d", h, m, s) :
- String.format("%02d:%02d", m, s);
- }
- @Override
- public void onPaint(Graphics2D g) {
- Font font = new Font("Open Sans", Font.BOLD, 18);
- g.setFont(font);
- g.setFont(g.getFont().deriveFont(18.0f));
- g.setColor(new Color(0, 0, 0, 175));
- g.fillRect(0, 0, 200, 123);
- g.setColor(new Color(255, 255, 255, 200));
- g.drawString("Heist's Demon Killer", 12, 21);
- g.setFont(g.getFont().deriveFont(12.0f));
- timeRan = System.currentTimeMillis() - this.timeBegan;
- g.drawString("Run time: " + ft(timeRan), 10, 36);
- currentXp = skills.getExperience(Skill.MAGIC);
- xpGained = currentXp - beginningXp;
- g.drawString("Magic XP Gained: " + xpGained, 10, 49);
- currentXp1 = skills.getExperience(Skill.DEFENCE);
- xpGained1 = currentXp1 - beginningXp1;
- g.drawString("Defence XP Gained: " + xpGained1, 10, 62);
- currentLevel = skills.getStatic(Skill.MAGIC);
- levelsGained = currentLevel - beginningLevel;
- currentLevel1 = skills.getStatic(Skill.DEFENCE);
- levelsGained1 = currentLevel1 - beginningLevel1;
- g.drawString("Magic Levels gained: " + levelsGained, 10, 75);
- g.drawString("Magic level: " + currentLevel + "(" + beginningLevel + ")", 10,88);
- g.drawString("Defence Levels gained: " + levelsGained1, 10, 101);
- g.drawString("Defence level: " + currentLevel1 + "(" + beginningLevel1 + ")", 10,114);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement