import com.speljohan.rsbot.accessors.NPC;
import com.speljohan.rsbot.bot.Bot;
import com.speljohan.rsbot.event.listeners.PaintListener;
import com.speljohan.rsbot.plugin.NonPluginClass;
import com.speljohan.rsbot.script.Calculations;
import com.speljohan.rsbot.script.Script;
import com.speljohan.rsbot.script.wrappers.RSInterface;
import com.speljohan.rsbot.script.wrappers.RSItemTile;
import com.speljohan.rsbot.script.wrappers.RSNPC;
import com.speljohan.rsbot.script.wrappers.RSPlayer;
import com.speljohan.rsbot.script.wrappers.RSTile;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.Properties;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Map;
public class RuskisFighter extends Script implements ActionListener, PaintListener {
@Override
public int loop() {
try {
int action = getAction();
switch (action) {
case ATTACK:
RSNPC npc = npcBase.npc;
if (clickNPC(npc, "Attack")) {
return random(1120, 2310);
} else {
return random(240, 610);
}
case WALK:
if (tileBase.useHalfTile) {
RSTile tile = tileBase.getHalfWayTile();
if (tileOnMap(tile)) {
tileBase.setUseHalfTile(false);
if (walkTileMM(tile)) {
return random(820, 1410);
} else {
return random(140, 510);
}
} else {
RSTile halfWayTile = tileBase.calcHalfWayTile(getLocation(), tile);
tileBase.setHalfWayTile(halfWayTile);
return random(150, 410);
}
} else {
RSTile tile = tileBase.tile;
if (tileOnMap(tile)) {
tileBase.setUseHalfTile(false);
if (walkTileMM(tile)) {
return random(820, 1410);
} else {
return random(140, 510);
}
} else {
RSTile halfWayTile = tileBase.calcHalfWayTile(getLocation(), tile);
tileBase.setHalfWayTile(halfWayTile);
tileBase.setUseHalfTile(true);
return random(130, 410);
}
}
case EAT:
if (getInventoryCount(FOODID) > 0) {
clickInventoryFood(FOODID);
return random(1412, 2413);
} else {
return random(140, 410);
}
case PICKUP:
RSItemTile itemTile = pickUpItemSet.tile;
try {
if (pickUpItem(itemTile)) {
pickUpFail = 0;
return random(710, 2310);
} else {
pickUpFail++;
if (pickUpFail >= random(2, 4)) {
pickUpFail = 0;
int randomNum = random(0, 1);
switch (randomNum) {
case 0:
setCameraRotation(getCameraAngle() + random(35, 150));
return random(320, 710);
case 1:
setCameraRotation(getCameraAngle() - random(35, 150));
return random(320, 1410);
}
}
}
} catch (Exception e) {
System.out.print("pick up item error: " + e);
return random(120, 541);
}
case WAIT:
return random(waitRange.range[0], waitRange.range[1]);
case KILLSCRIPT:
while(getMyPlayer().isInCombat()) {
wait(random(1310, 7244));
}
stopAllScripts();
return -1;
}
} catch (Exception e) {
System.out.print("loop() error: " + e);
}
return random(320, 520);
}
@Override
public String getAuthor() {
return "Ruski";
}
@Override
public String getName() {
return "RuskisFighter";
}
@Override
public double getVersion() {
return 1.5;
}
@Override
public String getScriptCategory() {
return "Ruski/Combat";
}
@Override
public String getScriptDescription() {
String html = "<hmtl>";
html += "<center>";
html += "<p>All settings can be set on the GUI, select your character and Start!</p>";
html += "</center>";
html += "</html>";
return html;
}
@Override
public void onFinish() {
Bot.getEventManager().removeListener(PaintListener.class, this);
}
@Override
public boolean onStart(Map<String, String> args) {
if (settings.settingsExist(settingsFileName)) {
showSettingsInterface();
try {
settings.setSettings();
npcIDText.setText(settings.intArrayToString(settings.getNPCIDs()));
pickUpItemsCheck.setSelected(settings.getPickUpItems());
if (settings.getPickUpItems()) {
itemIDText.setText(settings.intArrayToString(settings.getItemIDs()));
itemNameText.setText(settings.stringArrayToString(settings.getItemNames()));
}
eatFoodCheck.setSelected(settings.getEatFood());
stopScriptWhenNoFoodCheck.setSelected(settings.getStopScriptWhenNoFood());
speedSlider.setValue(settings.getSpeed());
} catch (Exception e) {
System.out.print("error getting settings: " + e);
}
} else {
showSettingsInterface();
}
while (!START_SCRIPT) {
wait(10);
}
log("*******************************************");
log("Ruskis Fighter V" + getVersion());
if (settings.getEatFood()) {
log("Food eating is enabled");
}
if (settings.getPickUpItems()) {
log("Picking up items: " + settings.stringArrayToString(settings.getItemNames()));
}
if (settings.getStopScriptWhenNoFood()) {
log("Stopping script, when run out of food");
}
log("*******************************************");
Bot.getEventManager().addListener(PaintListener.class, this);
START_SCRIPT = false;
return true;
}
private int getAction() {
if (!isLoggedIn() || !isFullyLoggedIn()) {
return -1;
}
if (healthCheck()) {
if (settings.getStopScriptWhenNoFood() && getInventoryCount(FOODID) == 0 && isFullyLoggedIn()) {
log("Run out of food, stopping script!!!");
return KILLSCRIPT;
}
if (settings.getEatFood() && getInventoryCount(FOODID) > 0) {
return EAT;
}
}
RSPlayer thisPlayer = getMyPlayer();
if (thisPlayer.isMoving()) {
waitRange.range = new int[]{320, 610};
return WAIT;
}
if (thisPlayer.getInteracting() != null) {
waitRange.range = new int[]{210, 310};
return WAIT;
}
if (settings.getPickUpItems()) {
RSItemTile itemTile = getNearestGroundItemByID(10, settings.getItemIDs());
if (itemTile != null && canPickUpItem(itemTile.getItem().getID())) {
pickUpItemSet.setItemTile(itemTile);
try {
Point itemPoint = Calculations.tileToScreen(itemTile);
if (pointOnScreen(itemPoint)) {
return PICKUP;
} else {
tileBase.setTile(itemTile);
return WALK;
}
} catch (Exception e) {
System.out.print("itemPoint error: " + e);
}
}
}
RSNPC npc = getNearestNPC(settings.getNPCIDs());
if (npc != null) {
npcCheck = false;
if (!canReach(npc.getLocation(), false)) {
npc = getNextNearestNPC(settings.getNPCIDs());
}
npcBase.setNPC(npc);
Point npcScreen = npc.getScreenLocation();
if (!pointOnScreen(npcScreen)) {
tileBase.setTile(npc.getLocation());
return WALK;
}
return ATTACK;
} else {
if (!npcCheck) {
lastNPCCheck = System.currentTimeMillis();
npcCheck = true;
}
if (npcCheck) {
if (System.currentTimeMillis() - lastNPCCheck >= 50000) {
log("No npcs around for 50 seconds, killing script");
return KILLSCRIPT;
}
}
}
return WAIT;
}
long healthRandomTime = 0;
int hpToHealAt = 10;
private boolean healthCheck() {
try {
if (System.currentTimeMillis() - healthRandomTime > 120000) {
healthRandomTime = System.currentTimeMillis();
hpToHealAt = (int) random(skills.getRealSkillLevel(3) / 3, skills.getRealSkillLevel(3) / 1.5);
}
return (skills.getCurrentSkillLevel(3) <= hpToHealAt);
} catch (Exception e) {
System.out.print("healthCheck() error: " + e);
}
return false;
}
public RSNPC getNearestNPC(int... ids) {
int Dist = 20;
RSNPC closest = null;
int[] validNPCs = Bot.getClient().getNPCIndexArray();
NPC[] npcs = Bot.getClient().getNPCArray();
for (int element : validNPCs) {
if (npcs[element] == null) {
continue;
}
RSNPC Monster = new RSNPC(npcs[element]);
try {
for (int id : ids) {
if (id != Monster.getID() || Monster.isInCombat()) {
continue;
}
int distance = distanceTo(Monster);
if (distance < Dist) {
Dist = distance;
closest = Monster;
}
}
} catch (Exception e) {
}
}
lastNPC = closest;
return closest;
}
RSNPC lastNPC = null;
public RSNPC getNextNearestNPC(int... ids) {
int Dist = 20;
RSNPC closest = null;
int[] validNPCs = Bot.getClient().getNPCIndexArray();
NPC[] npcs = Bot.getClient().getNPCArray();
for (int element : validNPCs) {
if (npcs[element] == null) {
continue;
}
RSNPC Monster = new RSNPC(npcs[element]);
if (Monster.equals(lastNPC)) {
continue;
}
try {
for (int id : ids) {
if (id != Monster.getID() || Monster.isInCombat()) {
continue;
}
int distance = distanceTo(Monster);
if (distance < Dist) {
Dist = distance;
closest = Monster;
}
}
} catch (Exception e) {
}
}
lastNPC = closest;
return closest;
}
public boolean pickUpItem(RSItemTile tile) {
try {
Point location = Calculations.tileToScreen(tile);
if (location.x == -1 || location.y == -1) {
return false;
}
String itemName = "";
for (int a = 0; a < 5; a++) {
location = Calculations.tileToScreen(tile);
moveMouse(location, -15, 15);
if (getMenuItems().get(0).contains("Take")) {
break;
}
if (!itemName.equals("")) {
break;
}
if (getMouseLocation().equals(location)) {
break;
}
}
String[] itemNames = settings.getItemNames();
for (int c = 0; c < itemNames.length; c++) {
if (getMenuItems().get(0).contains(itemNames[c])) {
clickMouse(true);
return true;
}
for (int x = 0; x < getMenuItems().size(); x++) {
if (getMenuItems().get(x).contains(itemNames[c])) {
if (!atMenu(itemNames[c])) {
return false;
} else {
return true;
}
}
}
}
return false;
} catch (Exception e) {
System.out.print("pickUpItem(RSTile, RSItem) error: " + e);
return false;
}
}
private boolean isFullyLoggedIn() {
return RSInterface.getInterface(77).isValid();
}
public RSItemTile getNearestGroundItemByID(int range, int[] ids) {
int pX = getMyPlayer().getLocation().getX();
int pY = getMyPlayer().getLocation().getY();
int minX = pX - range;
int minY = pY - range;
int maxX = pX + range;
int maxY = pY + range;
int dist = 100;
RSItemTile nItem = null;
for (int x = minX; x <= maxX; x++) {
for (int y = minY; y <= maxY; y++) {
if (Calculations.canReach(new RSTile(x, y), false)) {
RSItemTile[] items = getGroundItemsAt(x, y);
for (RSItemTile item : items) {
int iId = item.getItem().getID();
for (int id : ids) {
if (iId == id) {
if (distanceTo(new RSTile(x, y)) < dist) {
dist = distanceTo(new RSTile(x, y));
nItem = item;
}
}
}
}
}
}
}
return nItem;
}
private boolean clickInventoryFood(int... ids) {
try {
if (getCurrentTab() != TAB_INVENTORY && !RSInterface.getInterface(INTERFACE_BANK).isValid() && !RSInterface.getInterface(INTERFACE_STORE).isValid()) {
openTab(TAB_INVENTORY);
}
int[] items = getInventoryArray();
java.util.List<Integer> possible = new ArrayList<Integer>();
for (int i = 0; i < items.length; i++) {
for (int item : ids) {
if (items[i] == item) {
possible.add(i);
}
}
}
if (possible.size() == 0) {
return false;
}
int idx = possible.get(random(0, possible.size()));
Point t = getInventoryItemPoint(idx);
clickMouse(t, 5, 5, false);
return atMenu("Eat");
} catch (Exception e) {
System.out.print("clickInventoryFood(int...) error: " + e);
return false;
}
}
private boolean canPickUpItem(int itemID) {
if (getInventoryCount() < 28) {
return true;
} else {
if (getInventoryCount(itemID) > 0 && getInventoryItemByID(itemID).getStackSize() > 1) {
return true;
}
}
return false;
}
private boolean clickNPC(RSNPC npc, String action) {
if (npc == null) {
return false;
}
RSTile tile = npc.getLocation();
if (!tile.isValid()) {
return false;
}
try {
Point screenLoc = npc.getScreenLocation();
if (distanceTo(tile) > 6 || !pointOnScreen(screenLoc)) {
turnToTile(tile);
}
if (distanceTo(tile) > 20) {
walkTileMM(tile);
return false;
}
for (int i = 0; i < 12; i++) {
screenLoc = npc.getScreenLocation();
if (!npc.isValid() || !pointOnScreen(screenLoc)) {
return false;
}
moveMouse(screenLoc, -15, 15);
if (getMenuItems().get(0).toLowerCase().contains(npc.getName().toLowerCase())) {
break;
}
if (getMouseLocation().equals(screenLoc)) {
break;
}
}
List<String> menuItems = getMenuItems();
if (menuItems.isEmpty()) {
return false;
}
for (int a = 0; a < menuItems.size(); a++) {
if (menuItems.get(a).toLowerCase().contains(npc.getName().toLowerCase())) {
if (menuItems.get(0).toLowerCase().contains(action.toLowerCase())) {
clickMouse(true);
return true;
} else {
clickMouse(false);
return atMenu(action);
}
}
}
} catch (Exception e) {
System.out.print("clickNPC(RSNPC, String) error: " + e);
return false;
}
return false;
}
public void onRepaint(Graphics g) {
if (isLoggedIn()) {
if(startTime == 0) {
startTime = System.currentTimeMillis();
}
ArrayList<String> reportList = new ArrayList<String>();
reportList.add("RuskisFight V" + getVersion());
int startAttackExp = experienceHandler.getSkillExp(STAT_ATTACK);
int startStrengthExp = experienceHandler.getSkillExp(STAT_STRENGTH);
int startDefenseExp = experienceHandler.getSkillExp(STAT_DEFENSE);
int startHitpointsExp = experienceHandler.getSkillExp(STAT_HITPOINTS);
int startRangeExp = experienceHandler.getSkillExp(STAT_RANGE);
int startMagicExp = experienceHandler.getSkillExp(STAT_MAGIC);
int currentAttackExp = skills.getCurrentSkillExp(STAT_ATTACK);
int currentStrengthExp = skills.getCurrentSkillExp(STAT_STRENGTH);
int currentDefenseExp = skills.getCurrentSkillExp(STAT_DEFENSE);
int currentHitpointsExp = skills.getCurrentSkillExp(STAT_HITPOINTS);
int currentRangeExp = skills.getCurrentSkillExp(STAT_RANGE);
int currentMagicExp = skills.getCurrentSkillExp(STAT_MAGIC);
if (startAttackExp == 0) {
experienceHandler.setExperiencePoints(STAT_ATTACK, skills.getCurrentSkillExp(STAT_ATTACK));
}
int attackExpChange = currentAttackExp - startAttackExp;
if (attackExpChange > 0) {
reportList.add("Attack Exp: " + attackExpChange);
}
if (startStrengthExp == 0) {
experienceHandler.setExperiencePoints(STAT_STRENGTH, skills.getCurrentSkillExp(STAT_STRENGTH));
}
int strengthExpChange = currentStrengthExp - startStrengthExp;
if (strengthExpChange > 0) {
reportList.add("Strength Exp: " + strengthExpChange);
}
if (startDefenseExp == 0) {
experienceHandler.setExperiencePoints(STAT_DEFENSE, skills.getCurrentSkillExp(STAT_DEFENSE));
}
int defenseExpChange = currentDefenseExp - startDefenseExp;
if (defenseExpChange > 0) {
reportList.add("Defense Exp: " + defenseExpChange);
}
if (startHitpointsExp == 0) {
experienceHandler.setExperiencePoints(STAT_HITPOINTS, skills.getCurrentSkillExp(STAT_HITPOINTS));
}
int hitpointsExpChange = currentHitpointsExp - startHitpointsExp;
if (hitpointsExpChange > 0) {
reportList.add("Hitpoints Exp: " + hitpointsExpChange);
}
if (startRangeExp == 0) {
experienceHandler.setExperiencePoints(STAT_RANGE, skills.getCurrentSkillExp(STAT_RANGE));
}
int rangeExpChange = currentRangeExp - startRangeExp;
if (rangeExpChange > 0) {
reportList.add("Range Exp: " + rangeExpChange);
}
if (startMagicExp == 0) {
experienceHandler.setExperiencePoints(STAT_MAGIC, skills.getCurrentSkillExp(STAT_MAGIC));
}
int magicExpChange = currentMagicExp - startMagicExp;
if (magicExpChange > 0) {
reportList.add("Magic Exp: " + magicExpChange);
}
long millis = System.currentTimeMillis() - startTime;
long hours = millis / (1000 * 60 * 60);
millis -= hours * 1000 * 60 * 60;
long minutes = millis / (1000 * 60);
millis -= minutes * 1000 * 60;
long seconds = millis / 1000;
reportList.add("Runtime: " + hours + ":" + minutes + ":" + seconds);
Point str = new Point(350, 25);
g.setColor(new Color(60, 155, 200, 50));
g.fill3DRect(340, 10, 165, reportList.size() * 20 + 6, true);
g.setColor(new Color(60, 155, 200, 50));
g.fill3DRect(341, 11, 163, reportList.size() * 20 + 4, true);
g.setColor(Color.WHITE);
for (int a = 0; a < reportList.size(); a++) {
g.drawString(reportList.get(a), str.x, str.y);
str = new Point(str.x, str.y + 20);
}
}
}
private final int ATTACK = 0;
private final int WALK = 1;
private final int EAT = 2;
private final int PICKUP = 3;
private final int WAIT = 4;
private final int KILLSCRIPT = 999;
private long startTime = 0;
private int pickUpFail = 0;
private boolean npcCheck = false;
private long lastNPCCheck = 0;
private NPCBase npcBase = new NPCBase();
private TileBase tileBase = new TileBase();
private PickUpItemSet pickUpItemSet = new PickUpItemSet();
private Settings settings = new Settings();
private ExperienceHandler experienceHandler = new ExperienceHandler();
private WaitRange waitRange = new WaitRange(new int[]{500, 1000});
private final String settingsFileName = "RuskisFighterSettings.ini";
private int[] FOODID = {
1895, 1893, 1891, 4293, 2142, 291, 2140, 3228, 9980, 7223,
6297, 6293, 6295, 6299, 7521, 9988, 7228, 2878, 7568, 2343,
1861, 13433, 315, 325, 319, 3144, 347, 355, 333, 339,
351, 329, 3381, 361, 10136, 5003, 379, 365, 373,
7946, 385, 397, 391, 3369, 3371, 3373, 2309, 2325, 2333,
2327, 2331, 2323, 2335, 7178, 7180, 7188, 7190, 7198, 7200,
7208, 7210, 7218, 7220, 2003, 2011, 2289, 2291, 2293, 2295,
2297, 2299, 2301, 2303, 1891, 1893, 1895, 1897, 1899, 1901,
7072, 7062, 7078, 7064, 7084, 7082, 7066, 7068, 1942, 6701,
6703, 7054, 6705, 7056, 7060, 2130, 1985, 1993, 1989, 1978,
5763, 5765, 1913, 5747, 1905, 5739, 1909, 5743, 1907, 1911,
5745, 2955, 5749, 5751, 5753, 5755, 5757, 5759, 5761, 2084,
2034, 2048, 2036, 2217, 2213, 2205, 2209, 2054, 2040, 2080,
2277, 2225, 2255, 2221, 2253, 2219, 2281, 2227, 2223, 2191,
2233, 2092, 2032, 2074, 2030, 2281, 2235, 2064, 2028, 2187,
2185, 2229
}; //Thanks to Bug for ids
//GUI
private void showSettingsInterface() {
mainFrame = new javax.swing.JFrame("Ruskis Fighter V" + getVersion());
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
npcIDText = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jPanel3 = new javax.swing.JPanel();
jLabel4 = new javax.swing.JLabel();
itemIDText = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
pickUpItemsCheck = new javax.swing.JCheckBox();
jLabel7 = new javax.swing.JLabel();
itemNameText = new javax.swing.JTextField();
jLabel8 = new javax.swing.JLabel();
jPanel4 = new javax.swing.JPanel();
jLabel6 = new javax.swing.JLabel();
eatFoodCheck = new javax.swing.JCheckBox();
stopScriptWhenNoFoodCheck = new javax.swing.JCheckBox();
startButton = new javax.swing.JButton();
saveSettingsCheck = new javax.swing.JCheckBox();
jPanel5 = new javax.swing.JPanel();
jLabel9 = new javax.swing.JLabel();
speedSlider = new javax.swing.JSlider();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
mainFrame.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
mainFrame.setAlwaysOnTop(true);
mainFrame.setResizable(false);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Welcome", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N
jLabel1.setText("<html>Fill out the below form to start auto fighting. You can also click on \"Save Settings\" to save the form input for future use.</html>");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 331, Short.MAX_VALUE).addContainerGap()));
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel1).addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "NPCs", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N
jLabel2.setText("NPC IDs:");
jLabel3.setFont(new java.awt.Font("Tahoma", 2, 11));
jLabel3.setText("(separate npc ids with a comma, e.g: 123, 423, 23)");
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addComponent(jLabel2).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel3).addComponent(npcIDText, javax.swing.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE)).addContainerGap()));
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel2).addComponent(npcIDText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel3).addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Item pickup", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N
jLabel4.setText("Item IDs:");
jLabel5.setFont(new java.awt.Font("Tahoma", 2, 11));
jLabel5.setText("(separate item ids with a comma, e.g: 123, 423, 23)");
pickUpItemsCheck.setText("Pick up items?");
jLabel7.setText("Item Names:");
jLabel8.setFont(new java.awt.Font("Tahoma", 2, 11));
jLabel8.setText("(separate item names with a comma, e.g: coins, arrow)");
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel3Layout.createSequentialGroup().addContainerGap().addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel3Layout.createSequentialGroup().addComponent(jLabel4).addGap(18, 18, 18).addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(itemIDText, javax.swing.GroupLayout.DEFAULT_SIZE, 268, Short.MAX_VALUE).addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 268, Short.MAX_VALUE).addComponent(pickUpItemsCheck).addComponent(jLabel8).addComponent(itemNameText, javax.swing.GroupLayout.DEFAULT_SIZE, 268, Short.MAX_VALUE))).addComponent(jLabel7)).addContainerGap()));
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel3Layout.createSequentialGroup().addComponent(pickUpItemsCheck).addGap(10, 10, 10).addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel4).addComponent(itemIDText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel5).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel7).addComponent(itemNameText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(jLabel8).addContainerGap()));
jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Eating/Food", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N
jLabel6.setFont(new java.awt.Font("Tahoma", 2, 11)); // NOI18N
jLabel6.setText("<html>(food is automatically found in inventory)</html>");
eatFoodCheck.setText("Eat food?");
stopScriptWhenNoFoodCheck.setText("Stop script when no food?");
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel4Layout.createSequentialGroup().addContainerGap().addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel4Layout.createSequentialGroup().addComponent(eatFoodCheck).addGap(18, 18, 18).addComponent(stopScriptWhenNoFoodCheck)).addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 313, javax.swing.GroupLayout.PREFERRED_SIZE)).addContainerGap(28, Short.MAX_VALUE)));
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel4Layout.createSequentialGroup().addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(eatFoodCheck).addComponent(stopScriptWhenNoFoodCheck)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel6).addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
startButton.setText("START SCRIPT!");
startButton.addActionListener(this);
saveSettingsCheck.setText("Save Settings?");
jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Speed", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N
jLabel9.setText("<html>Have a try at adjusting to different speeds of the script, different<br> training locations could benefit different speeds, so it's up to you.</html> ");
speedSlider.setMajorTickSpacing(25);
speedSlider.setPaintTicks(true);
speedSlider.setSnapToTicks(true);
jLabel10.setText("Min");
jLabel11.setText("Max");
javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
jPanel5.setLayout(jPanel5Layout);
jPanel5Layout.setHorizontalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel5Layout.createSequentialGroup().addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel5Layout.createSequentialGroup().addContainerGap().addComponent(jLabel9)).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup().addContainerGap().addComponent(jLabel10).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(speedSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel11).addGap(27, 27, 27))).addContainerGap(25, Short.MAX_VALUE)));
jPanel5Layout.setVerticalGroup(
jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanel5Layout.createSequentialGroup().addComponent(jLabel9).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(speedSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(jLabel10).addComponent(jLabel11)).addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(mainFrame.getContentPane());
mainFrame.getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addGroup(layout.createSequentialGroup().addGap(130, 130, 130).addComponent(saveSettingsCheck).addContainerGap(136, Short.MAX_VALUE)).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(startButton, javax.swing.GroupLayout.DEFAULT_SIZE, 343, Short.MAX_VALUE).addContainerGap()));
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(saveSettingsCheck).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(startButton).addContainerGap(27, Short.MAX_VALUE)));
mainFrame.pack();
mainFrame.setVisible(true);
}
public void actionPerformed(ActionEvent action) {
Object event = action.getSource();
if (event.equals(startButton)) {
settings.setNPCIDs(settings.extractIntegers(npcIDText.getText()));
settings.setEatFood(eatFoodCheck.isSelected());
settings.setStopScriptWhenNoFood(stopScriptWhenNoFoodCheck.isSelected());
settings.setPickUpItems(pickUpItemsCheck.isSelected());
if (settings.getPickUpItems()) {
settings.setItemIDs(settings.extractIntegers(itemIDText.getText()));
settings.setItemNames(settings.extractStrings(itemNameText.getText()));
}
settings.setSpeed(speedSlider.getValue());
if (saveSettingsCheck.isSelected()) {
try {
settings.saveSettings(settings.getSettingsArray(), settingsFileName);
log("Successfully saved settings at RuskisFighterSettings.ini");
} catch (Exception e) {
System.out.print("saving settings error: " + e);
}
}
mainFrame.setVisible(false);
mainFrame.dispose();
START_SCRIPT = true;
}
}
private boolean START_SCRIPT = false;
private javax.swing.JCheckBox eatFoodCheck;
private javax.swing.JTextField itemIDText;
private javax.swing.JTextField itemNameText;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JTextField npcIDText;
private javax.swing.JCheckBox pickUpItemsCheck;
private javax.swing.JCheckBox saveSettingsCheck;
private javax.swing.JSlider speedSlider;
private javax.swing.JButton startButton;
private javax.swing.JCheckBox stopScriptWhenNoFoodCheck;
private javax.swing.JFrame mainFrame;
}
class WaitRange implements NonPluginClass {
int[] range = new int[2];
public WaitRange(int[] range) {
this.range[0] = range[0];
this.range[1] = range[1];
}
}
class NPCBase implements NonPluginClass {
RSNPC npc;
public NPCBase() {
}
public void setNPC(RSNPC npc) {
this.npc = npc;
}
}
class TileBase implements NonPluginClass {
RSTile tile;
RSTile halfWayTile;
boolean useHalfTile = false;
public TileBase() {
}
public void setUseHalfTile(boolean a) {
this.useHalfTile = a;
}
public void setTile(RSTile tile) {
this.tile = tile;
}
public RSTile calcHalfWayTile(RSTile location, RSTile tile) {
return new RSTile((tile.getX() + location.getX()) / 2, (tile.getY() + location.getY()) / 2);
}
public void setHalfWayTile(RSTile tile) {
this.halfWayTile = tile;
}
public RSTile getHalfWayTile() {
return this.halfWayTile;
}
}
class PickUpItemSet implements NonPluginClass {
RSItemTile tile;
public PickUpItemSet() {
}
public void setItemTile(RSItemTile tile) {
this.tile = tile;
}
}
class ExperienceHandler implements NonPluginClass {
int[][] skillExp = new int[24][1];
public ExperienceHandler() {
}
public void setExperiencePoints(int skill, int exp) {
this.skillExp[skill][0] = exp;
}
public int getSkillExp(int skill) {
return this.skillExp[skill][0];
}
}
class Settings implements NonPluginClass {
protected int[] npcIDs = new int[50];
protected int[] itemIDs = new int[50];
protected String[] itemNames = new String[50];
protected boolean pickUpItems = false;
protected boolean stopScriptWhenNoFood = false;
protected boolean eatFood = false;
protected int speed = 0;
public Settings() {
}
public void setNPCIDs(int[] ids) {
this.npcIDs = ids;
}
public void setItemIDs(int[] ids) {
this.itemIDs = ids;
}
public void setItemNames(String[] names) {
this.itemNames = names;
}
public void setPickUpItems(boolean a) {
this.pickUpItems = a;
}
public void setStopScriptWhenNoFood(boolean a) {
this.stopScriptWhenNoFood = a;
}
public void setEatFood(boolean a) {
this.eatFood = a;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public int[] getNPCIDs() {
return this.npcIDs;
}
public int[] getItemIDs() {
return this.itemIDs;
}
public String[] getItemNames() {
return this.itemNames;
}
public boolean getPickUpItems() {
return this.pickUpItems;
}
public boolean getStopScriptWhenNoFood() {
return this.stopScriptWhenNoFood;
}
public boolean getEatFood() {
return this.eatFood;
}
public int getSpeed() {
return this.speed;
}
public int[] extractIntegers(String text) {
int[] ints = null;
try {
text = text.replaceAll(" ", "");
String[] strInts = text.split(",");
ints = new int[strInts.length];
for (int a = 0; a < strInts.length; a++) {
ints[a] = Integer.parseInt(strInts[a]);
}
} catch (Exception e) {
System.out.print("extractIntegers(String) error: " + e);
}
return ints;
}
public String[] extractStrings(String text) {
return text.split(",");
}
public boolean extractBoolean(String text) {
return (text.equals("true"));
}
public String booleanToString(boolean a) {
if (a) {
return "true";
} else {
return "false";
}
}
public void setSettings() {
try {
String filename = "RuskisFighterSettings.ini";
this.npcIDs = extractIntegers(getSetting("NPCIDS", filename));
this.eatFood = extractBoolean(getSetting("EATFOOD", filename));
this.pickUpItems = extractBoolean(getSetting("PICKUPITEMS", filename));
this.stopScriptWhenNoFood = extractBoolean(getSetting("STOPSCRIPTWHENNOFOOD", filename));
this.speed = Integer.parseInt(getSetting("SPEED", filename));
if (this.pickUpItems) {
this.itemIDs = extractIntegers(getSetting("ITEMIDS", filename));
this.itemNames = extractStrings(getSetting("ITEMNAMES", filename));
}
} catch (Exception e) {
System.out.print("setSettings error: " + e);
}
}
public String getSetting(String settingName, String filename) {
try {
Properties p = new Properties();
p.load(new FileInputStream(filename));
return p.getProperty(settingName);
} catch (IOException ioe) {
System.out.print("loadSettings(String) error: " + ioe);
return null;
}
}
public String intArrayToString(int[] array) {
String intArray = "";
for (int a = 0; a < array.length; a++) {
if (array[a] != 0) {
intArray += array[a];
if (a != array.length - 1) {
intArray += ",";
}
}
}
return intArray;
}
public String stringArrayToString(String[] array) {
String strArray = "";
if (array.length <= 0) {
return "";
}
for (int a = 0; a < array.length; a++) {
if (!array[a].equals(null) && !array[a].equals("")) {
strArray += array[a];
if (a != array.length - 1) {
strArray += ",";
}
}
}
return strArray;
}
public String[][] getSettingsArray() {
String[][] settingsArray;
if (getPickUpItems()) {
settingsArray = new String[7][2];
} else {
settingsArray = new String[5][2];
}
settingsArray[0][0] = "NPCIDS";
settingsArray[0][1] = intArrayToString(getNPCIDs());
settingsArray[1][0] = "PICKUPITEMS";
settingsArray[1][1] = booleanToString(getPickUpItems());
if (getPickUpItems()) {
settingsArray[2][0] = "ITEMIDS";
settingsArray[2][1] = intArrayToString(getItemIDs());
settingsArray[3][0] = "ITEMNAMES";
settingsArray[3][1] = stringArrayToString(getItemNames());
settingsArray[4][0] = "STOPSCRIPTWHENNOFOOD";
settingsArray[4][1] = booleanToString(getStopScriptWhenNoFood());
settingsArray[5][0] = "EATFOOD";
settingsArray[5][1] = booleanToString(getEatFood());
settingsArray[6][0] = "SPEED";
settingsArray[6][1] = "" + getSpeed();
} else {
settingsArray[2][0] = "STOPSCRIPTWHENNOFOOD";
settingsArray[2][1] = booleanToString(getStopScriptWhenNoFood());
settingsArray[3][0] = "EATFOOD";
settingsArray[3][1] = booleanToString(getEatFood());
settingsArray[4][0] = "SPEED";
settingsArray[4][1] = "" + getSpeed();
}
return settingsArray;
}
public void saveSettings(String[][] settings, String filename) {
try {
Properties p = new Properties();
File file = new File(filename);
file.createNewFile();
p.load(new FileInputStream(filename));
for (int a = 0; a < settings.length; a++) {
p.setProperty(settings[a][0], settings[a][1]);
}
FileOutputStream out = new FileOutputStream(filename);
p.store(out, "");
} catch (IOException ioe) {
System.out.print("saveSettings(String[][]) error: " + ioe);
}
}
public boolean settingsExist(String filename) {
File settingsFile = new File(filename);
return settingsFile.exists();
}
}