Saturday, April 7, 2012
BossExperiments
import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import javax.imageio.ImageIO;
import javax.swing.ButtonGroup;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import org.powerbot.concurrent.Task;
import org.powerbot.concurrent.strategy.Strategy;
import org.powerbot.game.api.ActiveScript;
import org.powerbot.game.api.Manifest;
import org.powerbot.game.api.methods.Calculations;
import org.powerbot.game.api.methods.Game;
import org.powerbot.game.api.methods.Tabs;
import org.powerbot.game.api.methods.Walking;
import org.powerbot.game.api.methods.Widgets;
import org.powerbot.game.api.methods.input.Keyboard;
import org.powerbot.game.api.methods.input.Mouse;
import org.powerbot.game.api.methods.interactive.Npcs;
import org.powerbot.game.api.methods.interactive.Players;
import org.powerbot.game.api.methods.node.Locations;
import org.powerbot.game.api.methods.node.Menu;
import org.powerbot.game.api.methods.tab.Inventory;
import org.powerbot.game.api.methods.tab.Skills;
import org.powerbot.game.api.methods.widget.Camera;
import org.powerbot.game.api.util.Filter;
import org.powerbot.game.api.util.Random;
import org.powerbot.game.api.util.Time;
import org.powerbot.game.api.wrappers.Tile;
import org.powerbot.game.api.wrappers.interactive.Npc;
import org.powerbot.game.api.wrappers.node.Item;
import org.powerbot.game.api.wrappers.node.Location;
import org.powerbot.game.api.wrappers.widget.Widget;
import org.powerbot.game.api.wrappers.widget.WidgetChild;
import org.powerbot.game.bot.event.MessageEvent;
import org.powerbot.game.bot.event.listener.MessageListener;
import org.powerbot.game.bot.event.listener.PaintListener;
@Manifest(authors = { "Warl0ck" }, name = "Experiments Killer", version = 2.6, description = "Kills experiments at Canifis and banks for food.")
public class BossExperiments extends ActiveScript implements PaintListener,
MessageListener, MouseListener, MouseMotionListener {
/**
* The time of which the script started.
*/
private final long startTime = System.currentTimeMillis();
/**
* Experiment npc id
*/
private final static int[] NPC_ID = { 1678, 1677 };
/**
* Experiment NPC
*/
private Filter<Npc> EXPERIMENT = new Filter<Npc>() {
@Override
public boolean accept(Npc n) {
if (NPC_ID == null) {
return false;
}
for (int i : NPC_ID) {
if (n.getId() != i || n.getHpPercent() == 0 || n.isInCombat()) {
continue;
}
return true;
}
return false;
}
};
/**
* Default food id
*/
private int food = 329;
/**
* The bank tile.
*/
private final Tile bankTile = new Tile(3512, 3481, 0);
/**
* The Ladders-top tile.
*/
private final Tile laddersTop = new Tile(3578, 3526, 0);
/**
* The Ladders-bottom tile.
*/
private final Tile laddersBottom = new Tile(3577, 9927, 0);
/**
* The the main NPC spot tile.
*/
private final Tile npcTile = new Tile(3486, 9927, 0);
/**
* Desired combat style
*/
private int combatStyle;
/**
* List of combat style names
*
* @Combat only
*/
private String[] combatStyleName = { "Attack", "Defence", "Strength",
"Hitpoints", "Ranged", "Magic" };
/**
* Starting stat information
*/
private int startLevel, startExperience, startLevelHitpoints,
startExperienceHitpoints;
/**
* Used to format numbers with a comma (,)
*/
private DecimalFormat df = new DecimalFormat();
private DecimalFormatSymbols dfs = new DecimalFormatSymbols();
/**
* List of all available foods.
*/
private final int foods[] = { 333, 329, 361, 379, 373, 7946, 385 };
/**
* Paint template image
*/
private final String templateUrl = "http://i.imgur.com/AUrku.png";
private BufferedImage paintTemplate;
/**
* Rollover hide paint image
*/
private final String rolloverUrl = "http://i.imgur.com/NTa2X.png";
private BufferedImage rolloverImage;
private boolean rollover;
/**
* Rollover show paint image
*/
private final String rolloverShowUrl = "http://i.imgur.com/ck57x.png";
private BufferedImage rolloverShowImage;
/**
* Show paint button image
*/
private final String showPaintUrl = "http://i.imgur.com/8Q1Uj.png";
private BufferedImage showPaintButton;
private boolean hide;
/**
* Highlighted tab image
*/
private final String highlightedTabUrl = "http://i.imgur.com/6CmYV.png";
private final String highlightedTabUrl2 = "http://i.imgur.com/swNNJ.png";
private BufferedImage highlightedTabImage;
private BufferedImage highlightedTabImage2;
private boolean highlightedTab1 = true;
/**
* The state of location
*/
private enum LocationState {
AT_Npcs, AT_LADDERS, AT_LADDERS_TOP, AT_BANK, UNKNOWN
}
/**
* The state of action
*/
private enum State {
GO_BANK, BANK_ITEMS, BANK_TO_LADDERS, CLIMB_UP, CLIMB_DOWN, LADDERS_TO_NPC, FIGHT, NPC_TO_LADDERS, LADDERS_TO_BANK
}
/**
* The path from the bank to the memorial
*/
private final Tile[] BANK_TO_LADDER = { new Tile(3512, 3480, 0),
new Tile(3505, 3482, 0), new Tile(3504, 3486, 0),
new Tile(3503, 3490, 0), new Tile(3501, 3494, 0),
new Tile(3502, 3498, 0), new Tile(3506, 3501, 0),
new Tile(3507, 3505, 0), new Tile(3511, 3509, 0),
new Tile(3514, 3513, 0), new Tile(3517, 3517, 0),
new Tile(3518, 3519, 0), new Tile(3523, 3524, 0),
new Tile(3527, 3527, 0), new Tile(3531, 3525, 0),
new Tile(3537, 3526, 0), new Tile(3541, 3528, 0),
new Tile(3545, 3528, 0), new Tile(3550, 3528, 0),
new Tile(3556, 3528, 0), new Tile(3562, 3526, 0),
new Tile(3568, 3525, 0), new Tile(3574, 3524, 0),
new Tile(3578, 3526, 0) };
/**
* The path from the bottom of the ladders to the npc hotspot.
*/
private final Tile[] LADDER_TO_NPC = { new Tile(3577, 9927, 0),
new Tile(3577, 9927, 0), new Tile(3574, 9927, 0),
new Tile(3572, 9930, 0), new Tile(3569, 9933, 0),
new Tile(3566, 9936, 0), new Tile(3565, 9939, 0),
new Tile(3563, 9941, 0), new Tile(3560, 9943, 0),
new Tile(3556, 9942, 0), new Tile(3552, 9938, 0),
new Tile(3551, 9934, 0), new Tile(3547, 9932, 0),
new Tile(3545, 9930, 0), new Tile(3540, 9931, 0),
new Tile(3536, 9929, 0), new Tile(3534, 9927, 0),
new Tile(3531, 9929, 0), new Tile(3530, 9933, 0),
new Tile(3526, 9933, 0), new Tile(3522, 9932, 0),
new Tile(3519, 9931, 0), new Tile(3516, 9932, 0),
new Tile(3512, 9933, 0), new Tile(3509, 9932, 0),
new Tile(3506, 9932, 0), new Tile(3502, 9934, 0),
new Tile(3501, 9936, 0), new Tile(3498, 9937, 0),
new Tile(3494, 9937, 0), new Tile(3489, 9937, 0),
new Tile(3485, 9939, 0) };
/**
* The amount of experiments killed.
*/
private int experimentsKilled;
/**
* Identifier for the current location of the player.
*
* @return
*/
private LocationState getCurrentLocation() {
if (Calculations.distance(bankTile, Players.getLocal().getPosition()) <= 5) {
return LocationState.AT_BANK;
}
if (Calculations.distance(laddersTop, Players.getLocal().getPosition()) <= 5) {
return LocationState.AT_LADDERS_TOP;
}
if (Calculations.distance(laddersBottom, Players.getLocal()
.getPosition()) <= 5) {
return LocationState.AT_LADDERS;
}
if (Calculations.distance(npcTile, Players.getLocal().getPosition()) <= 30) {
return LocationState.AT_Npcs;
}
return LocationState.UNKNOWN;
}
public boolean contains(int id) {
return (inventoryContains(id));
}
public boolean inventoryContains(int id) {
for (int i = 0; i < Inventory.getItems().length; i++) {
if (Inventory.getItems()[i] != null) {
if (Inventory.getItems()[i].getId() == id) {
return true;
}
}
}
return false;
}
private State getAction() {
final LocationState currentLoc = getCurrentLocation();
if (contains(food)) {
switch (currentLoc) {
case AT_BANK:
return State.BANK_TO_LADDERS;
case AT_LADDERS_TOP:
return State.CLIMB_DOWN;
case AT_LADDERS:
return State.LADDERS_TO_NPC;
case AT_Npcs:
return State.FIGHT;
case UNKNOWN:
if (Players.getLocal().getPosition().getY() > 9000) {
return State.LADDERS_TO_NPC;
} else {
return State.BANK_TO_LADDERS;
}
}
}
if (Inventory.getCount(food) == 0) {
switch (currentLoc) {
case AT_BANK:
return State.BANK_ITEMS;
case AT_LADDERS_TOP:
return State.LADDERS_TO_BANK;
case AT_LADDERS:
return State.CLIMB_UP;
case AT_Npcs:
return State.NPC_TO_LADDERS;
case UNKNOWN:
if (Players.getLocal().getPosition().getY() > 9000) {
return State.NPC_TO_LADDERS;
} else {
return State.LADDERS_TO_BANK;
}
}
}
return null;
}
public void sleep(int i) {
Time.sleep(i);
}
public void sleep(int i, int i2) {
Time.sleep(Random.nextInt(i, i2));
}
public class Logic extends Strategy implements Task {
@Override
public void run() {
final State state = getAction();
switch (state) {
case BANK_ITEMS:
final Location bankObject = Locations.getNearest(24914);
if (bankObject != null) {
bankObject.interact("Use-quickly");
sleep(3000);
}
if (bankisOpen()) {
withdraw(food, 28);
}
break;
case BANK_TO_LADDERS:
walkPathMM(BANK_TO_LADDER);
sleep(600);
break;
case LADDERS_TO_NPC:
walkPathMM(LADDER_TO_NPC);
sleep(600);
break;
case FIGHT:
if (!Players.getLocal().isInCombat()) {
Npc experiment = findNpc();
if (experiment != null) {
if (distanceTo(experiment.getPosition()) > 5) {
walkTileMM(experiment.getPosition());
}
if (experiment.isOnScreen()) {
experiment.interact("Attack");
sleep(500, 1500);
} else {
Camera.turnTo(experiment);
}
}
sleep(500, 1250);
} else if (Players.getLocal().isInCombat()) {
if (Players.getLocal().getInteracting().getHpPercent() == 0) {
experimentsKilled++;
sleep(500);
}
} else {
// Camera.moveRandomly(30); // TODO
if (distanceTo(new Tile(3485, 9939, 0)) > 6) {
walkTileMM(new Tile(3485, 9939, 0));
sleep(500, 1000);
}
sleep(500, 1000);
}
break;
case CLIMB_DOWN:
// final Location memorial = Locations.getTopAt(new Tile(3578,
// 3527, 0));
// if (memorial != null) {
// memorial.interact("Push");
// sleep(5000);
// }
final Location memorial = Locations
.getNearest(new Filter<Location>() {
@Override
public boolean accept(Location o) {
return (o.getPosition().getX() == 3578);
}
});
if (memorial != null) {
memorial.interact("Push");
sleep(3000);
}
break;
case CLIMB_UP:
final Location ladders = Locations.getNearest(1757);
if (ladders != null) {
ladders.interact("Climb-up");
sleep(3000);
}
break;
case NPC_TO_LADDERS:
walkPathMM(reversePath(LADDER_TO_NPC));
sleep(600);
break;
case LADDERS_TO_BANK:
walkPathMM(reversePath(BANK_TO_LADDER));
sleep(600);
break;
}
if (Walking.getEnergy() >= 30 && !Walking.isRunEnabled()) {
Walking.setRun(true);
sleep(3000);
}
// if (Players.getLocal().getHpPercent() < 50) {
// Item foods = getItem(food);
// if (foods != null) {
// foods.getWidgetChild().interact("Eat");
// }
// sleep(3000);
// }
// if (getLifepointsPercent() < 50) {
// log.info("lifepoints isless than 50%!");
// Item foods = getItem(food);
// if (foods != null) {
// Tabs.INVENTORY.open();
// foods.getWidgetChild().interact("Eat");
// }
// sleep(3000);
// }
if (contains(229)) {
final Item vial = getItem(229);
if (vial != null) {
vial.getWidgetChild().interact("Drop");
sleep(1000);
} else {
sleep(500);
}
}
}
@Override
public boolean validate() {
if (!gui.isReady) {
log.info("Gui hasn't been filled out");
return false;
}
return true;
}
}
private final static String[] FOOD_NAMES = new String[] { "Trout",
"Salmon", "Tuna", "Lobster", "Swordfish", "Monkfish", "Shark" };
public class Eat extends Strategy implements Task {
private Item getFood() {
for (Item i : Inventory.getItems()) {
for (String s : FOOD_NAMES) {
if (i.getName().equals(s)) {
return i;
}
}
}
return null;
}
public void run() {
Item food = getFood();
log.info("Eating!!!: " + getLifepointsPercent() + ".");
if (food != null) {
Tabs.INVENTORY.open();
food.getWidgetChild().interact("Eat");
}
}
public boolean validate() {
if (!gui.isReady) {
log.info("Gui hasn't been filled out");
return false;
}
if (getLifepointsPercent() < 50) {
return true;
}
return false;
}
}
public boolean withdraw(int id, int amount) {
WidgetChild[] bank = Widgets.get(762, 95).getChildren();
for (WidgetChild child : bank) {
if (child.getChildId() == id) {
Mouse.click(child.getRelativeX() + 40,
child.getRelativeY() + 100, false);
if (amount == 0)
return Menu.select("Withdraw-All");
if (amount == 1)
return Menu.select("Withdraw-1");
if (amount == 5)
return Menu.select("Withdraw-5");
if (amount == 10)
return Menu.select("Withdraw-10");
else {
Menu.select("Withdraw-X");
sleep(1000, 1500);
Keyboard.sendText("" + amount, true);
sleep(1000, 1500);
return true;
}
}
}
return false;
}
private boolean bankisOpen() {
Widget bankInterface = Widgets.get(762);
if (bankInterface.validate()) {
return true;
}
return false;
}
public int getExpToNextLevel(final int index) {
final int lvl = getRealLevel(index);
if (lvl == 99)
return 0;
return Skills.XP_TABLE[lvl + 1] - Skills.getExperience(index);
}
public int getRealLevel(final int index) {
return Skills.getLevelAt(Skills.getExperience(index));
}
@Override
public void onRepaint(Graphics render) {
((Graphics2D) render).setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
/*
* Elapsed time
*/
long elapsedTime = System.currentTimeMillis() - startTime;
/*
* Time message
*/
String message = formatTime(elapsedTime);
/*
* Level information
*/
int levelsGained = Skills.getLevels()[combatStyle] - startLevel;
int totalXp = Skills.getExperiences()[combatStyle] - startExperience;
int hitpointLevelsGained = Skills.getLevels()[3] - startLevelHitpoints;
int hitpointsExpGained = Skills.getLevels()[3]
- startExperienceHitpoints;
/*
* Kill information
*/
int profitMade = (experimentsKilled);
int killsToLevel = Math
.abs(Skills.getExperienceToLevel(combatStyle, 1) / 400);
/*
* Experience earned hourly
*/
int xpPerHour = (int) ((3600000.0 / elapsedTime) * totalXp);
int xpPerHourHitpoints = (int) ((3600000.0 / elapsedTime) * hitpointsExpGained);
/*
* Hourly profit rate
*/
int profitPerHour = (int) ((3600000.0 / elapsedTime) * profitMade);
/*
* Used to position elements in the paint template
*/
int x = 0, y = 0;
int yIncrement = 0;
/*
* Used to determine which skill to show (training skill or hitpoints)
*/
int skill = 0;
/*
* Checks if paint is hidden by the user
*/
if (hide) {
render.drawImage(showPaintButton, 6, 344, null);
if (rollover) {
render.drawImage(rolloverShowImage, 6, 344, null);
}
} else {
render.drawImage(paintTemplate, 6, 344, null);
render.drawString(message, 135, 466);
if (rollover) {
render.drawImage(rolloverImage, 6, 344, null);
}
if (highlightedTab1) {
/*
* Draw the green highlighted tab
*/
render.drawImage(highlightedTabImage, 6, 344, null);
/*
* Set tab skill to the training skill
*/
skill = combatStyle;
} else {
/*
* Draw the green highlighted tab
*/
render.drawImage(highlightedTabImage2, 6, 344, null);
/*
* Set tab skill to the constitution skill
*/
skill = 3;
}
/*
* Draw statistics tab
*/
x = 58;
y = 398;
yIncrement = 15;
render.setColor(Color.WHITE);
render.drawString(
combatStyleName[skill]
+ " level: "
+ (skill != 3 ? Skills.getLevels()[combatStyle]
: Skills.getLevels()[3])
+ " (+"
+ df.format(skill != 3 ? levelsGained
: hitpointLevelsGained) + ")", x, y);
y += yIncrement;
render.setColor(Color.GRAY);
render.drawString(
combatStyleName[skill]
+ " xp: "
+ df.format(skill != 3 ? totalXp
: hitpointsExpGained) + "", x, y);
y += yIncrement;
render.setColor(Color.WHITE);
render.drawString(
combatStyleName[skill]
+ " xp/hr: "
+ df.format(skill != 3 ? xpPerHour
: xpPerHourHitpoints) + "", x, y);
/*
* Draw loot tab
*/
x = 255;
y = 396;
yIncrement = 15;
render.setColor(Color.WHITE);
render.drawString("Experiments killed: " + df.format(profitMade)
+ "", x, y);
y += yIncrement;
render.setColor(Color.GRAY);
render.drawString(
"Experiments killed/hr: " + df.format(profitPerHour) + "",
x, y);
y += yIncrement;
render.setColor(Color.WHITE);
render.drawString(
"Kills to level: " + df.format(killsToLevel) + "", x, y);
}
// g.drawString(message, 15, 100);
// g.drawString(getLocation().toString(), 15, 120);
// g.drawString(getState().toString(), 15, 140);
// g.drawString("Dragon bones looted: " + df.format(bonesTaken), 15,
// 160);
// g.drawString("Blue dragonhides looted: " + df.format(hidesTaken), 15,
// 180);
// g.drawString("Profit made: " + df.format(profitMade), 15, 200);
// g.drawString("Profit made per hour: " + df.format(profitPerHour), 15,
// 220);
// g.drawString(combatStyleN + " experience: " + df.format(totalXp), 15,
// 240);
// g.drawString(
// combatStyleN + " experience per hour: " + df.format(xpPerHour),
// 15, 260);
}
private void drawPercentageBar(Graphics render, int skill, int posx,
int posy) {
int percent = getPercentToNextLevel(skill);
int barAdd = 50;
int barLength = (100 + barAdd);
int barHeight = 11;
int barPercent = (percent + ((percent / 2) + 15));
render.setColor(Color.YELLOW);
render.fillRect(posx, posy, (barPercent - 15), barHeight);
render.setColor(Color.WHITE);
render.drawRect(posx, posy, barLength, barHeight);
render.setColor(Color.BLACK);
render.setFont(new Font("Helvetica", barHeight, barHeight));
render.drawString(percent + "%", posx + (barLength / 2), posy
+ barHeight - 1);
}
public int getPercentToNextLevel(final int index) {
final int lvl = Skills.getLevel(index);
if (lvl == 99) {
return 0;
}
final int xpTotal = xpTable[lvl + 1] - xpTable[lvl];
if (xpTotal == 0) {
return 0;
}
final int xpDone = Skills.getExperience(index) - xpTable[lvl];
return 100 * xpDone / xpTotal;
}
private static int[] xpTable = { 0, 0, 83, 174, 276, 388, 512, 650, 801,
969, 1154, 1358, 1584, 1833, 2107, 2411, 2746, 3115, 3523, 3973,
4470, 5018, 5624, 6291, 7028, 7842, 8740, 9730, 10824, 12031,
13363, 14833, 16456, 18247, 20224, 22406, 24815, 27473, 30408,
33648, 37224, 41171, 45529, 50339, 55649, 61512, 67983, 75127,
83014, 91721, 101333, 111945, 123660, 136594, 150872, 166636,
184040, 203254, 224466, 247886, 273742, 302288, 333804, 368599,
407015, 449428, 496254, 547953, 605032, 668051, 737627, 814445,
899257, 992895, 1096278, 1210421, 1336443, 1475581, 1629200,
1798808, 1986068, 2192818, 2421087, 2673114, 2951373, 3258594,
3597792, 3972294, 4385776, 4842295, 5346332, 5902831, 6517253,
7195629, 7944614, 8771558, 9684577, 10692629, 11805606, 13034431 };
/**
* Formats the given time
*
* @param time
* @return
*/
private String formatTime(long time) {
final int sec = (int) (time / 1000), h = sec / 3600, m = sec / 60 % 60, s = sec % 60;
return (h < 10 ? "0" + h : h) + ":" + (m < 10 ? "0" + m : m) + ":"
+ (s < 10 ? "0" + s : s);
}
StartGUI gui;
@Override
public void setup() {
gui = new StartGUI();
gui.setVisible(true);
Logic logic = new Logic();
Strategy logicStrategy = new Strategy(logic, logic);
Eat eat = new Eat();
Strategy eatStrategy = new Strategy(eat, eat);
logicStrategy.setSync(true);
eatStrategy.setSync(true);
provide(logicStrategy);
provide(eatStrategy);
if (gui.attack.isSelected()) {
combatStyle = Skills.ATTACK;
} else if (gui.strength.isSelected()) {
combatStyle = Skills.STRENGTH;
} else if (gui.defence.isSelected()) {
combatStyle = Skills.DEFENSE;
} else if (gui.ranged.isSelected()) {
combatStyle = Skills.RANGE;
}
if (gui.foodTextField.getText() != null
&& gui.foodTextField.getText().length() > 0) {
int foodId = Integer.parseInt(gui.foodTextField.getText());
if (foodId > 0) {
food = foodId;
}
} else {
if (gui.foodIdField.getSelectedItem() != null) {
try {
food = foods[gui.foodIdField.getSelectedIndex()];
} catch (NumberFormatException e) {
}
}
}
startExperience = Skills.getExperience(combatStyle);
startExperienceHitpoints = Skills.getExperience(Skills.CONSTITUTION);
/*
* Sets the decimal formatter to use a comma
*/
dfs.setGroupingSeparator(',');
df.setDecimalFormatSymbols(dfs);
// updateScript();
/*
* Load images
*/
try {
paintTemplate = ImageIO.read(new URL(templateUrl));
rolloverImage = ImageIO.read(new URL(rolloverUrl));
showPaintButton = ImageIO.read(new URL(showPaintUrl));
rolloverShowImage = ImageIO.read(new URL(rolloverShowUrl));
highlightedTabImage = ImageIO.read(new URL(highlightedTabUrl));
highlightedTabImage2 = ImageIO.read(new URL(highlightedTabUrl2));
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public Npc findNpc() {
Npc interaction = interaction();
return interaction != null ? interaction : Npcs.getNearest(EXPERIMENT);
}
private Npc interaction() {
return Npcs.getNearest(INTERACTION);
}
/**
* Filter for the NPC you are interacting with, if any.
*/
private Filter<Npc> INTERACTION = new Filter<Npc>() {
@Override
public boolean accept(Npc n) {
if (n.getInteracting() == null) {
return false;
}
String[] actions = n.getActions();
if (actions == null) {
return false;
}
for (String a : actions) {
if (a == null || !a.contains("Attack")) {
continue;
}
return n.getInteracting().equals(Players.getLocal());
}
return false;
}
};
@SuppressWarnings("serial")
public class StartGUI extends JFrame {
private boolean isReady;
public StartGUI() {
initComponents();
}
private void started(ActionEvent e) {
setVisible(false);
isReady = true;
}
private void initComponents() {
setTitle("Script settings");
setAlwaysOnTop(true);
setResizable(false);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setSize(250, 350);
Container cp = getContentPane();
cp.setLayout(null);
foodIdField.setModel(new DefaultComboBoxModel(new String[] {
"Trout", "Salmon", "Tuna", "Lobster", "Swordfish",
"Monkfish", "Shark" }));
foodIdField.setSelectedIndex(2);
foodIdField.setBounds(50, 40, 150, 20);
potionList.setModel(new DefaultComboBoxModel(new String[] { "None",
"Super attack + strength" }));
potion.setText("Food:");
foodId.setText("Potions:");
attackStyle.setText("Attack style:");
attack.setText("Attack");
strength.setText("Strength");
defence.setText("Defence");
ranged.setText("Ranged");
startButton.setText("Start");
attack.setBounds(50, 140, 80, foodIdField.getPreferredSize().height);
strength.setBounds(50, 160, 80,
foodIdField.getPreferredSize().height);
strength.setSelected(true);
defence.setBounds(50, 180, 80,
foodIdField.getPreferredSize().height);
ranged.setBounds(50, 200, 80, foodIdField.getPreferredSize().height);
foodTextField.setBounds(50, 70, 100, 20);
foodId.setBounds(50, 100, 100, 20);
potionList.setBounds(50, 120, 150, 20);
attackStyle.setBounds(50, 105, 75, 50);
potion.setBounds(50, 20, 100, 20);
cp.add(startButton);
startButton.setBounds(4, 288, 238,
startButton.getPreferredSize().height);
ButtonGroup attackStyles = new ButtonGroup();
attackStyles.add(attack);
attackStyles.add(strength);
attackStyles.add(defence);
attackStyles.add(ranged);
cp.add(foodId);
cp.add(potionList);
cp.add(attackStyle);
cp.add(attack);
cp.add(strength);
cp.add(ranged);
cp.add(defence);
cp.add(potion);
cp.add(foodIdField);
cp.add(foodTextField);
cp.add(enterFoodId);
startButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
started(e);
}
});
}
private JTextField foodTextField = new JTextField();
private JLabel foodId = new JLabel();
private JComboBox foodIdField = new JComboBox();
private JRadioButton attack = new JRadioButton();
private JRadioButton strength = new JRadioButton();
private JRadioButton defence = new JRadioButton();
private JRadioButton ranged = new JRadioButton();
private JLabel attackStyle = new JLabel();
private JLabel enterFoodId = new JLabel();
private JLabel potion = new JLabel();
private JComboBox potionList = new JComboBox();
/**
* Start button
*/
private JButton startButton = new JButton();
}
@Override
public void messageReceived(MessageEvent sme) {
String msg = sme.getMessage();
if (msg.contains("creature")) {
}
}
@Override
public void mouseClicked(MouseEvent e) {
int x = e.getX();
int y = e.getY();
if (x >= 320 && x <= 390 && y >= 345 && y <= 358) {
hide = !hide;
}
}
@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
/**
* Walk to a tile via the minimap.
*
* @param tile
* the target tile to walk to.
* @param rnd
* the random number, in addition to the coordinates of the tile.
* @returns mouse click towards that location.
*/
public boolean walkTileMM(Tile tile, int rnd) {
double angle = angleTo(tile) - Camera.getAngleTo(0);
double distance = distanceTo(tile);
angle = angle * Math.PI / 180;
int x = 627, y = 85;
int dx = (int) (4 * (distance + Random.nextGaussian(0, rnd, 1)) * Math
.cos(angle));
int dy = (int) (4 * (distance + Random.nextGaussian(0, rnd, 1)) * Math
.sin(angle));
return Mouse.click(x + dx, y - dy, true);
}
public void walkPathMM(Tile[] path) {
walkPathMM(path, 16);
}
public boolean walkTileMM(Tile tile) {
double angle = angleTo(tile) - Camera.getAngleTo(0);
double distance = distanceTo(tile);
angle = angle * Math.PI / 180;
int x = 627, y = 85;
int dx = (int) (4 * (distance + Random.nextGaussian(0, 1, 1)) * Math
.cos(angle));
int dy = (int) (4 * (distance + Random.nextGaussian(0, 1, 1)) * Math
.sin(angle));
return Mouse.click(x + dx, y - dy, true);
}
/**
* Calculates the distance from our position to the specified tile.
*
* @param tile
* the target position.
* @return the squares of difference.
*/
public int distanceTo(Tile tile) {
return (int) Calculations.distance(Players.getLocal().getPosition(),
tile);
}
/**
* This finds the angle of our tiles in order to use the minimap for
* walking. Don't really understand this... but works like a charm!
*
* @param tile
* the target tile to walk to.
* @return the angle.
*/
public int angleTo(Tile tile) {
double ydif = tile.getY() - Players.getLocal().getPosition().getY();
double xdif = tile.getX() - Players.getLocal().getPosition().getX();
return (int) (Math.atan2(ydif, xdif) * 180 / Math.PI);
}
public Item getItem(int id) {
for (Item item : Inventory.getItems()) {
if (item.getId() == id)
return item;
}
return null;
}
public Item getItems(int... ids) {
Item[] items = Inventory.getItems();
for (Item item : items) {
for (int id : ids) {
if (item.getId() == id)
return item;
}
}
return null;
}
public boolean walkPathMM(Tile[] path, int maxDist) {
return walkPathMM(path, maxDist, 1, 1);
}
/**
* Walks towards the end of a path. This method should be looped.
*
* @param path
* The path to walk along.
* @param randX
* The X value to randomize each tile in the path by.
* @param randY
* The Y value to randomize each tile in the path by.
* @return <tt>true</tt> if the next tile was reached; otherwise
* <tt>false</tt>.
* @see #walkPathMM(Tile[], int, int, int)
*/
public boolean walkPathMM(Tile[] path, int randX, int randY) {
return walkPathMM(path, 16, randX, randY);
}
/**
* Walks towards the end of a path. This method should be looped.
*
* @param path
* The path to walk along.
* @param maxDist
* See {@link #nextTile(Tile[], int)}.
* @param randX
* The X value to randomize each tile in the path by.
* @param randY
* The Y value to randomize each tile in the path by.
* @return <tt>true</tt> if the next tile was reached; otherwise
* <tt>false</tt>.
*/
public boolean walkPathMM(Tile[] path, int maxDist, int randX, int randY) {
try {
Tile next = nextTile(path, maxDist);
return next != null && walkTileMM(next, 1);
} catch (Exception e) {
return false;
}
}
public Tile nextTile(Tile path[]) {
return nextTile(path, 17);
}
public Tile nextTile(Tile path[], int skipDist) {
int dist = 99;
int closest = -1;
for (int i = path.length - 1; i >= 0; i--) {
Tile tile = path[i];
int d = distanceTo(tile);
if (d < dist) {
dist = d;
closest = i;
}
}
int feasibleTileIndex = -1;
for (int i = closest; i < path.length; i++) {
if (distanceTo(path[i]) <= skipDist)
feasibleTileIndex = i;
else
break;
}
if (feasibleTileIndex == -1)
return null;
else
return path[feasibleTileIndex];
}
public Tile[] reversePath(Tile[] tile) {
Tile[] tilerev = tile.clone();
int end = tile.length - 1;
for (int begin = 0; begin < end; end--) {
Tile temp = tilerev[begin];
tilerev[begin] = tilerev[end];
tilerev[end] = temp;
begin++;
}
return tilerev;
}
@Override
public void mouseDragged(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseMoved(MouseEvent e) {
int x = e.getX();
int y = e.getY();
if (x >= 320 && x <= 390 && y >= 345 && y <= 358) {
rollover = true;
} else {
rollover = false;
}
if (x >= 26 && x <= 50) {
if (y >= 379 && y < 407) {
highlightedTab1 = true;
} else if (y >= 407 && y < 440) {
highlightedTab1 = false;
}
}
}
private double getHPPercent() {
if (Game.isLoggedIn() && Widgets.get(748).getChild(8) != null) {
double hpPercent = (Double.parseDouble(Widgets.get(748).getChild(8)
.getText()) * 100)
/ (Skills.getRealLevel(Skills.CONSTITUTION) * 10);
return hpPercent;
} else
return 0;
}
private int getCurrentLifepoints() {
Widget gamePane = Widgets.get(748);
WidgetChild lifepointsBar = gamePane.getChild(8);
if (gamePane.validate()) {
if (lifepointsBar.isVisible()) {
String txt = lifepointsBar.getText();
if (txt != null) {
return Integer.parseInt(txt);
}
}
}
return -1;
}
private int getLifepointsPercent() {
// int hitpointsLevel = Skills.getLevel(Skills.CONSTITUTION);
// final int lifepoints = hitpointsLevel * 10;
// return (getCurrentLifepoints() / lifepoints) * 100;
return (int) getHPPercent();
}
}
No comments:
Post a Comment