Created
July 5, 2018 02:22
-
-
Save soccersw2/60176fd61975c09f9369be7cacde7f2f to your computer and use it in GitHub Desktop.
WildyLooter Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.rspeer.runetek.api.component.Bank; | |
import org.rspeer.runetek.api.component.Interfaces; | |
import org.rspeer.runetek.api.component.tab.Inventory; | |
import org.rspeer.runetek.api.local.Health; | |
import org.rspeer.runetek.api.movement.Movement; | |
import org.rspeer.runetek.api.movement.position.Area; | |
import org.rspeer.runetek.api.movement.position.Position; | |
import org.rspeer.runetek.api.scene.Pickables; | |
import org.rspeer.runetek.api.scene.Players; | |
import org.rspeer.runetek.api.scene.SceneObjects; | |
import org.rspeer.script.Script; | |
import org.rspeer.script.ScriptMeta; | |
import org.rspeer.ui.Log; | |
import java.util.concurrent.ThreadLocalRandom; | |
@ScriptMeta(developer = "ADivorcedFork", desc = "Loots items in wildy north of Edgeville", name = "Wildy Looter", version = 1.0) | |
public class TestScript extends Script { | |
private String status = ""; | |
private Area lootArea = Area.rectangular(3063, 3555, 3111, 3523); | |
private Area bankArea = Area.rectangular(3092, 3498, 3097, 3488); | |
private static final int NEED_FOOD_PERCENT = 50; | |
private static final int WILD_YAXIS_DIVIDE = 3522; | |
private static final Position[] WILDY_TO_DITCH = {new Position(3083, 3537), new Position(3083, 3531), new Position(3086, 3528), | |
new Position(3085, 3525), new Position(3085, 3523)}; | |
private static final Position[] DITCH_TO_EDGEVILE = {new Position(3087, 3520), new Position(3087, 3513), | |
new Position(3087, 3507), new Position(3089, 3502), new Position(3092, 3500), new Position(3093, 3496), | |
new Position(3096, 3494)}; | |
private static final Position[] EDGEVILLE_TO_DITCH = {new Position(3096, 3494), new Position(3093, 3496), new Position(3092, 3500), | |
new Position(3089, 3502), new Position(3087, 3507), new Position(3087, 3513), new Position(3087, 3520)}; | |
private static final Position[] DITCH_TO_WILDY = {new Position(3085, 3523), new Position(3085, 3525), new Position(3086, 3528), | |
new Position(3083, 3531), new Position(3083, 3537)}; | |
@Override | |
public void onStart() { | |
Log.info("Welcome to Wildy Looter"); | |
} | |
private enum State { | |
LOOT, BANK, RETURN | |
}; | |
private State getCurrentState() { | |
if(Inventory.isFull() || needsFood()) { | |
status = "State: Banking"; | |
return State.BANK; | |
} else if(!lootArea.contains(Players.getLocal())){ | |
status = "State: Returning to wild"; | |
return State.RETURN; | |
} else { | |
status = "State: Looting"; | |
return State.LOOT; | |
} | |
} | |
@Override | |
public int loop() { | |
handleRunning(); | |
logInfo(); | |
switch(getCurrentState()) { | |
case BANK: | |
if (bankArea.contains(Players.getLocal().getPosition())) { | |
if (Bank.isOpen()) { | |
Bank.depositInventory(); | |
Bank.depositEquipment(); | |
Bank.close(); | |
} else { | |
SceneObjects.getNearest("Bank booth").interact("Bank"); | |
} | |
} else if(isInWild()) { | |
if (!crossDitch()) { | |
Movement.walk(WILDY_TO_DITCH); | |
} | |
} else { | |
Movement.walk(DITCH_TO_EDGEVILE); | |
} | |
break; | |
case RETURN: | |
if(!isInWild()) { | |
if (!crossDitch()) { | |
Movement.walk(EDGEVILLE_TO_DITCH); | |
} | |
} else { | |
Movement.walk(DITCH_TO_WILDY); | |
} | |
break; | |
case LOOT: | |
if (lootArea.contains(Players.getLocal())) { | |
Pickables.getNearest(pickable -> pickable != null && lootArea.contains(pickable)).interact("Take"); | |
} else { | |
Movement.walk(DITCH_TO_WILDY); | |
} | |
break; | |
} | |
return 0; | |
} | |
private void logInfo() { | |
Log.info(status); | |
} | |
// Handles when to enable/disable run | |
private void handleRunning() { | |
int energy = Movement.getRunEnergy(); | |
if (needsFood() && Players.getLocal().getPosition().getY() > WILD_YAXIS_DIVIDE) { | |
if (!Movement.isRunEnabled()) { | |
Movement.toggleRun(true); | |
} | |
} else if (Players.getLocal().getPosition().getY() < WILD_YAXIS_DIVIDE) { | |
if (Movement.isRunEnabled()) { | |
Movement.toggleRun(false); | |
} | |
} else if (energy <= ThreadLocalRandom.current().nextInt(7, 13)) { | |
if (Movement.isRunEnabled()) { | |
Movement.toggleRun(false); | |
} | |
} else if (energy >= ThreadLocalRandom.current().nextInt(30, 40)) { | |
if (!Movement.isRunEnabled()) { | |
Movement.toggleRun(true); | |
} | |
} | |
} | |
// Withdraw Swordfish and eat until above threshold | |
// private void handleReginFood() { | |
// if (Inventory.contains("Swordfish")) { | |
// Inventory.getFirst("Swordfish").interact("Eat"); | |
// } | |
// else if (!Bank.isOpen()) { | |
// if(Bank.contains("Swordfish")) { | |
// Bank.withdraw("Swordfish", 3); | |
// } | |
// Bank.close(); | |
// } else { | |
// SceneObjects.getNearest("Bank booth").interact("Bank"); | |
// } | |
// } | |
// Returns true if player crosses ditch, otherwise returns false | |
private boolean crossDitch() { | |
if (Interfaces.getComponent(475, 11) != null) { | |
Log.info("Trying to pass safety screen"); | |
Interfaces.getComponent(475, 11).interact("Enter Wilderness"); | |
return true; | |
} else if (SceneObjects.getNearest("Wilderness Ditch") != null) { | |
SceneObjects.getNearest("Wilderness Ditch").interact("Cross"); | |
return true; | |
} else { | |
return false; | |
} | |
} | |
private boolean isInWild() { | |
if (Players.getLocal().getPosition().getY() > WILD_YAXIS_DIVIDE) return true; | |
else return false; | |
} | |
private boolean needsFood() { | |
return Health.getPercent() < NEED_FOOD_PERCENT; | |
} | |
private boolean freeToDoAction() { | |
return Players.getLocal().getAnimation() == -1 && !Players.getLocal().isMoving(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment