Skip to content

Instantly share code, notes, and snippets.

@phl0w
Last active December 15, 2015 18:19
Show Gist options
  • Select an option

  • Save phl0w/5303248 to your computer and use it in GitHub Desktop.

Select an option

Save phl0w/5303248 to your computer and use it in GitHub Desktop.
import org.powerbot.core.event.listeners.PaintListener;
import org.powerbot.core.script.ActiveScript;
import org.powerbot.core.script.job.Task;
import org.powerbot.core.script.job.state.Node;
import org.powerbot.core.script.job.state.Tree;
import org.powerbot.game.api.Manifest;
import org.powerbot.game.api.methods.Game;
import org.powerbot.game.api.methods.Walking;
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.GroundItems;
import org.powerbot.game.api.methods.tab.Inventory;
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.interactive.NPC;
import org.powerbot.game.api.wrappers.node.GroundItem;
import org.powerbot.game.api.wrappers.node.Item;
import java.awt.*;
@Manifest(authors = ("Graser"), name = "Good Fight GOBLIN_IDS", description = "Kills GOBLIN_IDS", version = 15)
public class GFGoblins extends ActiveScript implements PaintListener {
private static String status;
private static final Color MOUSE_COLOR = new Color(0, 255, 255), MOUSE_BORDER_COLOR = new Color(220, 220, 220),
MOUSE_CENTER_COLOR = new Color(89, 255, 89);
private static long startTime;
private static final int bone = 526;
private static final int[] GOBLIN_IDS = {12353, 12355, 11236, 1769, 11240, 1770, 1771, 1772, 12352, 1773, 1774,
1775, 1776, 445, 444, 6181, 6180, 1438};
private static final int[] LOOT_IDS = {995, 526, 555, 558, 559, 877, 554, 886};
private static final int[] JUNK_IDS = {1439, 19830, 288, 2307, 1277, 1139, 1949, 1511, 25547, 9054, 1351, 2132,
1438, 1917, 1987, 2138, 1009, 1173, 2138, 1203};
private static final int[] FOOD_IDS = {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, 6883, 1971, 4608, 1883, 1885, 1982};
private final Tree jobs = new Tree(new Node[]{new Eat(), new Attack(), new Drop(), new Bury(), new Loot()});
private static final Filter<NPC> goblinFilter = new Filter<NPC>() {
@Override
public boolean accept(final NPC n) {
for (final int ni : GOBLIN_IDS) {
if (n.getId() == ni) {
if (!n.isInCombat()) {
return true;
}
}
}
return false;
}
};
@Override
public void onStart() {
if (Game.isLoggedIn()) {
status = "Hello";
claimTicket();
startTime = System.currentTimeMillis();
} else {
log.info("NOT logged in");
stop();
}
}
private void claimTicket() {
status = "Scanning claim";
final Item ticket = Inventory.getItem(24154);
if (ticket != null) {
if (ticket.getWidgetChild().click(true)) {
Task.sleep(750, 1000);
}
}
}
@Override
public int loop() {
final Node job = jobs.state();
if (job != null) {
getContainer().submit(job);
jobs.set(job);
job.join();
}
return Random.nextInt(100, 200);
}
private class Eat extends Node {
private Item food;
@Override
public boolean activate() {
return Players.getLocal().getHpPercent() < 40 &&
(food == null ? (food = Inventory.getItem(FOOD_IDS)) : food) != null &&
Players.getLocal().getAnimation() == -1;
}
@Override
public void execute() {
status = "Eating";
if (food.getWidgetChild().interact("Eat")) {
Task.sleep(750, 1000);
}
}
}
private class Drop extends Node {
@Override
public boolean activate() {
return Inventory.getCount(JUNK_IDS) > 0;
}
@Override
public void execute() {
for (final Item i : Inventory.getItems(true, new Filter<Item>() {
@Override
public boolean accept(final Item item) {
for (int id : JUNK_IDS) {
if (item.getId() == id) {
return true;
}
}
return false;
}
})) {
status = "Droping";
if (i.getWidgetChild().interact("Drop")) {
sleep(Random.nextInt(300, 500));
}
}
}
}
private class Bury extends Node {
private Item bone;
@Override
public boolean activate() {
return (bone == null ? (bone = Inventory.getItem(GFGoblins.bone)) : bone) != null;
}
@Override
public void execute() {
if (bone.getWidgetChild().interact("Bury")) {
Task.sleep(500, 100);
}
}
}
private class Attack extends Node {
private NPC goblin;
@Override
public boolean activate() {
if (Camera.getPitch() <= 75) {
Camera.setPitch(90);
}
return !Players.getLocal().isInCombat() && (goblin == null ? (goblin = NPCs.getNearest(goblinFilter)) :
goblin) != null;
}
@Override
public void execute() {
if (goblin.isOnScreen()) {
status = "We Should Be Attacking them Now";
if (goblin.interact("Attack")) {
Task.sleep(Random.nextInt(2000, 25000));
}
} else {
Camera.turnTo(goblin);
if (!goblin.isOnScreen()) {
Walking.walk(goblin);
}
}
}
}
private class Loot extends Node {
private GroundItem loot;
@Override
public boolean activate() {
return (loot == null ? (loot = GroundItems.getNearest(LOOT_IDS)) : loot) != null && Players.getLocal()
.getAnimation() == -1;
}
@Override
public void execute() {
status = "We see the Loot";
if (loot.isOnScreen()) {
status = "Checking if we can reach it";
status = "Looting";
if (loot.interact("Take")) {
Task.sleep(500, 650);
if (Players.getLocal().isMoving()) {
while (Players.getLocal().isMoving()) {
Task.sleep(10, 30);
}
}
}
} else {
status = "Turning to Loot";
Camera.turnTo(loot);
if (!loot.isOnScreen()) {
Walking.walk(loot);
}
}
}
}
private final static Color color1 = new Color(0, 0, 0);
private final static Color color2 = new Color(0, 204, 255);
private final static Color color3 = new Color(0, 255, 0);
private final static Font font1 = new Font("Cambria", Font.PLAIN, 20);
private final static Font font2 = new Font("Cambria", Font.PLAIN, 17);
@Override
public void onRepaint(Graphics g1) {
Graphics2D g = (Graphics2D) g1;
drawMouse(g);
g.setColor(color1);
g.fillRect(3, 314, 515, 160);
g.setColor(color2);
g.fillRect(20, 333, 478, 124);
g.setFont(font1);
g.setColor(color1);
g.drawString("Good Fight GOBLIN_IDS by: Xianb", 36, 412);
g.drawString("Version: 15", 44, 384);
g.drawString("Time running: " + Time.format(System.currentTimeMillis() - startTime), 34, 367);
g.drawString("Status: " + status, 35, 444);
g.setFont(font2);
g.setColor(color3);
g.fillRoundRect(19, 323, 491, 3, 16, 16);
g.fillRoundRect(9, 331, 4, 125, 16, 16);
g.fillRoundRect(21, 462, 478, 6, 16, 16);
g.fillRoundRect(503, 340, 7, 120, 16, 16);
g.setColor(color1);
Point p = Mouse.getLocation();
Dimension d = Game.getDimensions();
int w = (int) d.getWidth(), h = (int) d.getHeight();
g.setColor(Color.lightGray);
g.setComposite(AlphaComposite
.getInstance(AlphaComposite.SRC_OVER, 0.1f));
g.fillRect(0, 0, p.x - 1, p.y - 1);
g.fillRect(p.x + 1, 0, w - (p.x + 1), p.y - 1);
g.fillRect(0, p.y + 1, p.x - 1, h - (p.y - 1));
g.fillRect(p.x + 1, p.y + 1, w - (p.x + 1), h - (p.y - 1));
g.translate(0, 50);
}
private void drawMouse(final Graphics2D g) {
final Point p = Mouse.getLocation();
final Graphics2D spinG = (Graphics2D) g.create();
final Graphics2D spinGRev = (Graphics2D) g.create();
final Graphics2D spinG2 = (Graphics2D) g.create();
g.setRenderingHints(new RenderingHints(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON));
spinG.setColor(MOUSE_BORDER_COLOR);
spinGRev.setColor(MOUSE_COLOR);
spinG.rotate(System.currentTimeMillis() % 2000d / 2000d * (360d) * 2
* Math.PI / 180.0, p.x, p.y);
spinGRev.rotate(System.currentTimeMillis() % 2000d / 2000d * (-360d)
* 2 * Math.PI / 180.0, p.x, p.y);
final int outerSize = 20;
final int innerSize = 12;
spinG.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND,
BasicStroke.JOIN_ROUND));
spinGRev.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND,
BasicStroke.JOIN_ROUND));
spinG.drawArc(p.x - (outerSize / 2), p.y - (outerSize / 2), outerSize,
outerSize, 100, 75);
spinG.drawArc(p.x - (outerSize / 2), p.y - (outerSize / 2), outerSize,
outerSize, -100, 75);
spinGRev.drawArc(p.x - (innerSize / 2), p.y - (innerSize / 2),
innerSize, innerSize, 100, 75);
spinGRev.drawArc(p.x - (innerSize / 2), p.y - (innerSize / 2),
innerSize, innerSize, -100, 75);
g.setColor(MOUSE_CENTER_COLOR);
g.fillOval(p.x, p.y, 2, 2);
spinG2.setColor(MOUSE_CENTER_COLOR);
spinG2.rotate(System.currentTimeMillis() % 2000d / 2000d * 360d
* Math.PI / 180.0, p.x, p.y);
spinG2.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_ROUND,
BasicStroke.JOIN_ROUND));
spinG2.drawLine(p.x - 5, p.y, p.x + 5, p.y);
spinG2.drawLine(p.x, p.y - 5, p.x, p.y + 5);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment