Skip to content

Instantly share code, notes, and snippets.

@HostOnNet
Created August 2, 2011 12:49
Show Gist options
  • Save HostOnNet/1120115 to your computer and use it in GitHub Desktop.
Save HostOnNet/1120115 to your computer and use it in GitHub Desktop.
HunterFalconry
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.Vector;
import java.util.regex.Pattern;
import javax.swing.JOptionPane;
import bergCoder.BergUtils;
import impsoft.bots.ColorBot;
import impsoft.bots.reflection.NPC;
import impsoft.bots.reflection.NPCIterator;
import impsoft.bots.reflection.Player;
import impsoft.bots.reflection.PlayerIterator;
import impsoft.scripting.ibot.builtin.itemrec.ItemSlot;
import impsoft.scripting.ibot.builtin.ocr.NPCChat;
import impsoft.scripting.ibot.enums.Skill;
import impsoft.scripting.ibot.interfaces.AutoPaint;
import impsoft.scripting.ibot.interfaces.ChatListener;
import impsoft.scripting.ibot.itemrec.ItemNameExact;
import impsoft.scripting.ibot.structs.AryanTile;
import impsoft.scripting.ibot.structs.AryanTileZone;
import impsoft.scripting.types.ColorScript;
import impsoft.utils.general.Timer;
import impsoft.utils.ibot.RandomGenerator;
import impsoft.utils.ruler.RulerClickOptions;
import impsoft.utils.ruler.RulerScriptUtils;
import impsoft.values.constant.Areas;
import impsoft.values.variable.MouseSettings;
public class HunterFalconry extends ColorScript implements AutoPaint, ChatListener
{
AryanTileZone falconryZone = new AryanTileZone(new AryanTile(2367, 3591), new AryanTile(2379, 3580));
public int[] kebbitID;
public int[] falconID;
int lvlStartHunter;
int xpStartHunter, xpNowHunter, xpStartPrayer, xpNowPrayer;
Timer timeRan = new Timer(0);
Timer antiBanTimer = null;
BergUtils berg = new BergUtils(this);
int dropAt;
boolean lostFalconry = false;
boolean huntSucess = false;
boolean huntFail = false;
boolean falconBack = false;
public static String author = "FlashWeb";
public static String name = "HunterFalconry FW";
public static String description = "Hunts Spotted/Dark Kebbit using Falconry in Piscatoris Hunter area";
public static String version = "3";
public HunterFalconry(ColorBot c)
{
super(c);
}
public enum State
{
WALK, HUNT, LOOT, DROP, ANTIBAN, LOST
}
State botState;
NPC kebbit;
@Override
public void script() throws InterruptedException, Exception
{
sleep(100);
boolean noFalcon = false;
if (this.theTabs.Equipment.getWeapon() == null)
{
noFalcon = true;
}
else if (!this.theTabs.Equipment.getWeapon().equalsIgnoreCase("Falconer's glove"))
{
noFalcon = true;
}
if (noFalcon)
{
getGyrFalcon();
}
RulerScriptUtils.useModels = true;
antiBanTimer = new Timer(random(90000, 240000));
lvlStartHunter = this.theTabs.Statistics.getStatBottom(Skill.HUNTER);
xpStartHunter = this.theTabs.Statistics.getStatExperience(Skill.HUNTER);
xpStartPrayer = this.theTabs.Statistics.getStatExperience(Skill.PRAYER);
dropAt();
if (lvlStartHunter < 43)
{
slowExit("You need Level 43 to catch Spotted Kebbit");
}
else if (lvlStartHunter < 57)
{
log("You can catch Spotted Kebbit");
kebbitID = new int[] { 5098 };
falconID = new int[] { 5094 };
}
else if (lvlStartHunter >= 57)
{
log("You can catch Spotted Kebbit and Dark Kebbit");
kebbitID = new int[] { 5098, 5099 };
falconID = new int[] { 5094, 5096 };
}
while (true)
{
getBotState();
switch (this.botState)
{
case WALK:
walk();
break;
case HUNT:
hunt();
break;
case LOOT:
loot();
break;
case DROP:
drop();
break;
case ANTIBAN:
antiBan();
break;
case LOST:
getGyrFalcon();
break;
}
}
}
private void getBotState() throws InterruptedException
{
if (this.huntSucess)
{
this.botState = State.LOOT;
}
else if (this.lostFalconry)
{
this.botState = State.LOST;
}
else if (antiBanTimer.isUp())
{
this.botState = State.ANTIBAN;
}
else if (this.theTabs.Inventory.count(new ItemNameExact("Bones")) > dropAt)
{
this.botState = State.DROP;
}
else
{
kebbit = getNearestNpcById(kebbitID);
if (this.kebbit == null)
{
this.botState = State.WALK;
}
else
{
this.botState = State.HUNT;
}
}
log("[getBotState()] " + this.botState);
}
private void dropAt()
{
dropAt = random(6, 10);
}
private void slowExit(String msg) throws InterruptedException
{
log("FORCE SHUTDOWN");
this.startAllRandoms();
log(msg);
JOptionPane.showMessageDialog(null, msg, "HunterFalconry FW", JOptionPane.ERROR_MESSAGE);
sleep(1000);
shutDown();
}
private void drop() throws InterruptedException
{
if (!this.theTabs.Inventory.isSelected())
{
this.theTabs.Inventory.click();
}
int[] clickOrder = { 0, 4, 8, 12, 16, 20, 24, 1, 5, 9, 13, 17, 21, 25, 2, 6, 10, 14, 18, 22, 26, 3, 7, 11, 15, 19, 23, 27 };
for (int i = 0; i < clickOrder.length; i++)
{
ItemSlot itemSlot = theTabs.Inventory.SLOTS[clickOrder[i]];
if (itemSlot.isItemInSlot())
{
if (itemSlot.getItemName().equals("Bones"))
{
itemSlot.mouseMoveOn();
itemSlot.mouseClickLeftOn();
sleep(800, 900);
}
}
}
xpNowPrayer = this.theTabs.Statistics.getStatExperience(Skill.PRAYER);
for (int i = 0; i < clickOrder.length; i++)
{
ItemSlot itemSlot = theTabs.Inventory.SLOTS[clickOrder[i]];
if (itemSlot.isItemInSlot())
{
if (itemSlot.getItemName().contains("kebbit fur"))
{
itemSlot.mouseMoveOn();
itemSlot.mouseClickRightOn();
this.theMenuFinder.doMenuContains("Drop");
sleep(1000, 1500);
}
}
}
dropAt();
}
private void loot() throws InterruptedException
{
log("[loot()] looting");
kebbit = getNearestNpcById(falconID);
if (kebbit != null)
{
falconBack = false;
Pattern lootPattern = Pattern.compile(".*Retrieve.*" + kebbit.getName() + ".*", Pattern.CASE_INSENSITIVE);
RulerScriptUtils.clickWorldObject(this, null, this.kebbit, null, lootPattern, lootPattern, EnumSet.of(RulerClickOptions.GOAL_NORMAL_CLICK,
RulerClickOptions.WALK_USING_ANY, RulerClickOptions.PAINT_GAMESCREEN_WALKING, RulerClickOptions.PAINT_PREDICTION_POLYGON));
sleep(500, 800);
while (!this.falconBack)
{
sleep(50, 100);
log("[loot()] waiting for chat update");
}
this.huntSucess = false;
}
else
{
kebbit = getNearestNpcById(falconID);
if (kebbit == null)
{
this.huntSucess = false;
}
}
xpNowHunter = this.theTabs.Statistics.getStatExperience(Skill.HUNTER);
}
public NPC getNearestNpcById(int[] id)
{
log("[getNearestNpcById()] " + Arrays.toString(id));
NPC closest = null;
double closeDistance = 100;
AryanTile here = getLocation();
for (NPCIterator po = getNPCIterator(); po.hasNext();)
{
NPC npc = po.next();
Integer ID = npc.getType();
for (int i : id)
{
if (ID == i)
{
double distance = npc.getLocation().distanceToPrecise(here);
if (distance < closeDistance)
{
closest = npc;
closeDistance = distance;
}
}
}
}
return closest;
}
private void hunt() throws InterruptedException
{
checkPlayers();
log("[hunt()] start");
kebbit = this.getNearestNpcById(kebbitID);
Timer moveTimer = new Timer(1000);
while (kebbit.isMoving())
{
sleep(50, 75);
if (moveTimer.isUp())
{
log("[hunt()] NPC moving for long time, finding another NPC");
return;
}
}
log("[hunt()] Clicking");
this.huntFail = false;
this.huntSucess = false;
Pattern catchSpotted = Pattern.compile(".*Catch.*" + kebbit.getName() + ".*", Pattern.CASE_INSENSITIVE);
RulerScriptUtils.clickWorldObject(this, null, this.kebbit, null, catchSpotted, catchSpotted, EnumSet.of(RulerClickOptions.GOAL_MENU_CLICK,
RulerClickOptions.WALK_USING_ANY, RulerClickOptions.PAINT_GAMESCREEN_WALKING, RulerClickOptions.PAINT_PREDICTION_POLYGON,
RulerClickOptions.PEND_FOR_MOVEMENT_TO_STOP));
Timer huntFailTimer = new Timer(2000);
while (this.huntFail == false && this.huntSucess == false)
{
log("[hunt()] waiting for ChatListener to update hunt status");
sleep(50, 100);
if (huntFailTimer.isUp())
{
log("[hunt()] breaking as no hunt status update from ChatListener");
break;
}
}
log("[hunt()] end");
}
private void walk() throws InterruptedException
{
log("[walk()] start");
this.theWorldMap.walkTo(this.falconryZone.random());
log("[walk()] end");
}
public void antiBan() throws InterruptedException
{
switch (random(1, 10))
{
case 1:
log("[antiBan()] Short pause and mouse of screen");
berg.moveMouseOffscreen();
sleep(random(10, 30) * 1000);
break;
case 2:
log("[antiBan()] Mouse movement");
mouseMove(Areas.ENTIRE);
if (theTopText.isTopTextContaining("level"))
{
mouseClickRight(getCurrentMouseXY());
log("We found a player or an NPC. Right clicked");
}
break;
case 3:
log("[antiBan()] Right clicking");
mouseClickRight(Areas.GAME);
sleep(150, 200);
if (random(1, 5) < 3)
theMenuFinder.doMenuContains("ancel");
break;
case 4:
log("[antiBan()] Reverting mouse speed");
setMouseSpeed(random(100, 106));
break;
case 5:
log("[antiBan()] Speeding mouse movements by 5-10%");
increaseMouseSpeed(random(5, 11));
break;
case 6:
log("[antiBan()] Decreasing mouse movements by 5-10%");
decreaseMouseSpeed(random(5, 11));
break;
case 7:
log("[antiBan()] move mouse out of screen");
berg.moveMouseOffscreen();
break;
case 8:
log("[antiBan()] skill checking");
if (!this.theTabs.Statistics.isSelected())
{
this.theTabs.Statistics.setSelected();
}
this.mouseMove(new Rectangle(617, 408, 42, 15));
sleep(600, 1500);
this.theTabs.Inventory.click();
sleep(100, 200);
this.mouseMove(Areas.ENTIRE);
default:
log("[antiBan()] compass movement");
theParallelCompass.setYawRandom();
break;
}
antiBanTimer.reset();
sleep(500, 900);
}
// Credits Perfecticus
private void increaseMouseSpeed(int percent)
{
final int increase = (100 + percent);
getColorBot().currentSpeed = new MouseSettings()
{
public double getSpeed(int dist)
{
if (dist > 300)
{
return RandomGenerator.randomNormalDouble(0.5, 1.5) / ((double) increase / 100);
}
else if (dist > 150)
{
return RandomGenerator.randomNormalDouble(1, 2.3) / ((double) increase / 100);
}
else
{
return RandomGenerator.randomNormalDouble(3, 5) / ((double) increase / 100);
}
}
};
}
// Credits Perfecticus
private void decreaseMouseSpeed(int percent)
{
final int increase = (100 - percent);
getColorBot().currentSpeed = new MouseSettings()
{
public double getSpeed(int dist)
{
if (dist > 300)
{
return RandomGenerator.randomNormalDouble(0.5, 1.5) / ((double) increase / 100);
}
else if (dist > 150)
{
return RandomGenerator.randomNormalDouble(1, 2.3) / ((double) increase / 100);
}
else
{
return RandomGenerator.randomNormalDouble(3, 5) / ((double) increase / 100);
}
}
};
}
private void setMouseSpeed(final int percent)
{
getColorBot().currentSpeed = new MouseSettings()
{
public double getSpeed(int dist)
{
if (dist > 300)
{
return RandomGenerator.randomNormalDouble(0.5, 1.5) / ((double) percent / 100);
}
else if (dist > 150)
{
return RandomGenerator.randomNormalDouble(1, 2.3) / ((double) percent / 100);
}
else
{
return RandomGenerator.randomNormalDouble(3, 5) / ((double) percent / 100);
}
}
};
}
public void checkPlayers() throws InterruptedException
{
Vector<Player> players = new Vector<Player>();
PlayerIterator playerz = getPlayerIterator();
while (playerz.hasNext())
{
if (playerz.next() != null)
players.add(playerz.next());
}
if (players.size() > 1)
{
slowExit("HOP TO WORLD WITH NO ONE IN FALCONRY AREA");
}
}
private void getGyrFalcon() throws InterruptedException
{
NPCChat chat = null;
NPC Matthias = null;
while(Matthias == null)
{
Matthias = theWorldObjectFinder.findNPC(5092);
}
while (!theNPCChatFinder.isNPCChatUp())
{
berg.clickNPCByName(new String[] { "Matthias" }, Matthias.getLocation(), "Falconry");
Timer waitTimer = new Timer(3000);
while (!theNPCChatFinder.isNPCChatUp())
{
log("waiting for npc chat");
sleep(100, 200);
if (waitTimer.isUp())
{
break;
}
}
}
if (this.theTabs.Equipment.getWeapon() == null)
{
if (this.theTabs.Inventory.countStackOf(new ItemNameExact("Coins")) < 500)
{
slowExit("You need 500 GP to get Gyr Falcon");
}
log("Get Gyr Falcon");
chat = theNPCChatFinder.getNPCChat();
if (chat.contains("Yes"))
{
chat.selectContains("Yes");
this.waitTillNPCChatChangesFrom(chat);
sleep(1000, 2000);
}
}
else if (this.theTabs.Equipment.getWeapon().equalsIgnoreCase("Falconer's glove"))
{
}
else
{
slowExit("You must get Falconer's glove");
}
}
@Override
public void paint(Graphics g1)
{
int xpGained = 0, xpPerHour = 0, xpPrayer = 0;
Graphics2D g = (Graphics2D) g1;
if (this.xpNowHunter > this.xpStartHunter)
{
xpGained = this.xpNowHunter - this.xpStartHunter;
xpPerHour = (int) (xpGained / (timeRan.getTimeElapsed() / 1000D)) * 3600;
}
if (xpNowPrayer > xpStartPrayer)
{
xpPrayer = xpNowPrayer - xpStartPrayer;
}
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setColor(new Color(0, 102, 0, 200));
g.fillRoundRect(15, 15, 222, 105, 30, 30);
g.setColor(new Color(100, 100, 100));
g.setStroke(new BasicStroke(1));
g.drawRoundRect(15, 15, 222, 105, 30, 30);
g.setFont(new Font("Comic Sans MS", 1, 13));
g.setColor(Color.WHITE);
g.drawString(name + " V" + version, 60, 40);
g.setFont(new Font("Verdana", 0, 9));
g.drawString("By: FlashWeb", 140, 50);
g.drawString("Time Ran: " + timeRan.toStringTimeElapsed(), 40, 60);
g.drawString("Hunter XP: " + xpGained, 40, 75);
g.drawString("Hunter XP/H: " + xpPerHour, 40, 90);
g.drawString("Prayer XP: " + xpPrayer, 40, 105);
}
@Override
public void chat(String m) throws InterruptedException
{
log(m);
if (m.contains("quick for you"))
{
lostFalconry = true;
}
else if (m.contains("successfully swoops down"))
{
huntSucess = true;
}
else if (m.contains("misses catching"))
{
huntFail = true;
}
else if (m.contains("retrieve the falcon"))
{
falconBack = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment