import java.awt.*;
import java.util.*;
import java.util.List;
import com.speljohan.rsbot.bot.Bot;
import com.speljohan.rsbot.script.*;
import com.speljohan.rsbot.script.wrappers.*;
import java.awt.*;
public class RuskisGoblin extends Script {
private final int KILLGOBLIN = 0;
private final int DEATHWALK = 1;
private final int WALKBACK = 2;
private final int KILLSCRIPT = 3;
int ActionState = 0;
public RSTile[] deathWalkPathArr = {
new RSTile(3234, 3219),
new RSTile(3237, 3225),
new RSTile(3252, 3225),
new RSTile(3261, 3233)
};
int goblinAreaX[] = new int[]{3266,3250,3243,3264,3267};
int goblinAreaY[] = new int[]{3218,3225,3258,3254,3227};
Polygon goblinArea = new Polygon(goblinAreaX, goblinAreaY, 5);
int deathAreaX[] = new int[]{3229,3226,3217,3217,3226};
int deathAreaY[] = new int[]{3219,3209,3210,3229,3228};
Polygon deathArea = new Polygon(deathAreaX, deathAreaY, 5);
public double getVersion() {
return 1.0;
}
public String getName() {
return "RuskisGoblin";
}
public String getAuthor() {
return "Ruski";
}
public String getScriptCategory() {
return "Ruski/Combat";
}
public boolean onStart(Map<String, String> args) {
return true;
}
public void onFinish() {
}
public void selectActionState() {
if(playerInArea(goblinArea)) {
ActionState = KILLGOBLIN;
}
if(playerInArea(deathArea)) {
ActionState = DEATHWALK;
}
if(!playerInArea(goblinArea) && distanceToArea(goblinAreaX, goblinAreaY) > 15 && distanceToArea(goblinAreaX, goblinAreaY) < 150) {
ActionState = WALKBACK;
}
if(distanceToArea(goblinAreaX, goblinAreaY) > 200 && distanceToArea(deathAreaX, deathAreaY) > 200) {
log("we are lost, stopping script");
ActionState = KILLSCRIPT;
}
}
public int loop() {
selectActionState();
checkLastFight();
runControl();
switch(ActionState) {
case KILLGOBLIN:
if(getMyPlayer().getInteracting() != null && getMyPlayer().isMoving()) {
return random(200, 400);
}
RSNPC goblin = getNearestFreeNPCByName("Goblin");
if(goblin != null) {
if(goblin.getInteracting() != null) {
return random(100, 200);
}
if(!canReach(goblin, false)) {
return random(300, 500);
}
if(getMyPlayer().getInteracting() == null) {
clickNPC(goblin, "attack");
}
return random(1700, 2500);
}
return random(100, 200);
case DEATHWALK:
log("walking back from death");
walkAlongPath(deathWalkPathArr);
return random(100, 500);
case WALKBACK:
log("walking back to goblin area");
walkAlongPath(generatePath(3259, 3235));
return random(100, 600);
case KILLSCRIPT:
stopAllScripts();
return random(100, 200);
}
return random(200, 800);
}
/** ---------------------- METHODOLOGY ------------------------- **/
long lastFightTime = System.currentTimeMillis();
public void checkLastFight() {
if(getMyPlayer().isInCombat()) {
lastFightTime = System.currentTimeMillis();
}
if(System.currentTimeMillis() - lastFightTime > 30000) {
log("no fights for over 30secs, walking to goblins");
lastFightTime = System.currentTimeMillis();
ActionState = WALKBACK;
}
}
/********************************\
* Boolean playerInArea( Polygon )
* Returns true/false if player is in area
* by Ruski
\********************************/
public boolean playerInArea(Polygon area) {
return area.contains(new Point(getMyPlayer().getLocation().getX(), getMyPlayer().getLocation().getY()));
}
/********************************\
* Integer distanceToArea( int[], int[] )
* Returns the distance to nearest point in area
* by Ruski
\********************************/
public int distanceToArea(int x[], int y[]) {
int lastDist = 9999999;
if(x.length <= 0 || y.length <= 0) {
return -1;
}
for(int a = 0; a < x.length; a++) {
int curDist = distanceTo(new RSTile(x[a], y[a]));
if(curDist < lastDist) {
lastDist = curDist;
}
}
return lastDist;
}
/********************************\
* Function waitTilStopped( )
* Waits untill player is stopped running
\********************************/
public void waitTilStopped() {
while (true && isLoggedIn()) {
if (!getMyPlayer().isMoving()) {
break;
}
wait(random(100, 200));
}
}
/********************************\
* Function runControl( )
* Turns run on if energy is more than 20
* by Ruski
\********************************/
public void runControl() {
if (!isRunning() && getEnergy() > 20) {
setRun(true);
}
}
/********************************\
* Boolean generatePath( int, int )
* Creates a path to tile coords
* by aftermath
\********************************/
public RSTile[] generatePath(int destinationX, int destinationY) {
int startX = getMyPlayer().getLocation().getX();
int startY = getMyPlayer().getLocation().getY();
double dx, dy;
ArrayList<RSTile> list = new ArrayList<RSTile>();
list.add(new RSTile(startX, startY));
while(Math.hypot(destinationY - startY, destinationX - startX) > 8) {
dx = destinationX - startX;
dy = destinationY - startY;
int gamble = random(14,17);
while(Math.hypot(dx, dy) > gamble) {
dx *= .95;
dy *= .95;
}
startX += (int) dx;
startY += (int) dy;
list.add(new RSTile(startX, startY));
}
list.add(new RSTile(destinationX, destinationY));
return list.toArray(new RSTile[list.size()]);
}
/********************************\
* Boolean walkAlongPath( RSTile[] )
* Walks/joins the path and finishes it
* by Ruski
\********************************/
public void walkAlongPath(RSTile[] path) {
int index = 0;
for (int i = 1; i < path.length; i++) {
if (distanceTo(path[i]) < distanceTo(path[index])) {
index = i;
}
}
for (int i = index; i < path.length; i++) {
runControl();
walkTileMM(new RSTile(path[i].getX() + random(-2, 2), path[i].getY() + random(-2, 2)));
wait(random(300, 550));
waitTilStopped();
}
}
/********************************\
* Boolean rotateCameraTo( Point )
* Rotates camera to the screen location
* by Ruski
\********************************/
public boolean rotateCameraTo(Point p) {
if(p == null) {
return false;
}
int currentAngle = getCameraAngle();
int curAltitude = Bot.getClient().getCamPosZ();
if(curAltitude > 40) {
setCameraAltitude(random(20, 40));
}
if(p.getX() > 1000 || p.getX() < -1000 || p.getY() > 800 || p.getY() < -800) {
return false;
}
if(p.getX() > 400) {
if(p.getY() < 168) {
setCameraRotation(currentAngle - 45);
return true;
}
if(p.getY() >= 168) {
setCameraRotation(currentAngle - 135);
return true;
}
}
if(p.getX() < 100) {
if(p.getY() < 168) {
setCameraRotation(currentAngle + 45);
return true;
}
if(p.getY() >= 168) {
setCameraRotation(currentAngle + 125);
return true;
}
}
if(p.getX() > 90 && p.getX() < 410) {
if(p.getY() > 325) {
setCameraRotation(currentAngle + 180);
return true;
}
if(p.getY() < 10) {
setCameraAltitude(curAltitude - random(1, 5));
return true;
}
}
return false;
}
/********************************\
* Boolean clickNPC( RSNPC, String )
* Modified mouse click for faster performance
* by Ruski
\********************************/
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, 5, 5);
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;
}
}