package scripts.HarpoonBuyer.Tasks;
import com.runemate.game.api.hybrid.entities.Npc;
import com.runemate.game.api.hybrid.local.Camera;
import com.runemate.game.api.hybrid.local.hud.Menu;
import com.runemate.game.api.hybrid.local.hud.interfaces.InterfaceComponent;
import com.runemate.game.api.hybrid.local.hud.interfaces.Interfaces;
import com.runemate.game.api.hybrid.local.hud.interfaces.Inventory;
import com.runemate.game.api.hybrid.location.Area;
import com.runemate.game.api.hybrid.location.Coordinate;
import com.runemate.game.api.hybrid.queries.InterfaceComponentQueryBuilder;
import com.runemate.game.api.hybrid.queries.NpcQueryBuilder;
import com.runemate.game.api.hybrid.queries.results.InterfaceComponentQueryResults;
import com.runemate.game.api.hybrid.queries.results.LocatableEntityQueryResults;
import com.runemate.game.api.hybrid.region.Npcs;
import com.runemate.game.api.hybrid.region.Players;
import com.runemate.game.api.script.Execution;
import com.runemate.game.api.script.framework.task.Task;
public class Purchase extends Task {
public static Area shopArea = new Area.Polygonal(new Coordinate(3010, 3230, 0), new Coordinate(3018, 3230, 0), new Coordinate(3018, 3223, 0), new Coordinate(3010, 3220, 0));
private NpcQueryBuilder shopKeeperQuery = Npcs.newQuery().within(shopArea).names("Gerrant");
private InterfaceComponentQueryBuilder shopInterfaceQuery = Interfaces.newQuery().texts("Gerrant's Fishy Business");
public boolean validate() {
return !Inventory.isFull() && shopArea.contains(Players.getLocal()) ;
}
@Override
public void execute() {
System.out.println("Purchasing ACTIVE");
InterfaceComponentQueryResults validShopInterfaces = shopInterfaceQuery.results();
if (!validShopInterfaces.isEmpty()) {
InterfaceComponentQueryResults validHarpoonInterfaces = Interfaces.newQuery().names("Harpoon").results();
if (!validHarpoonInterfaces.isEmpty()) {
InterfaceComponent harpoonInterface = (InterfaceComponent)validHarpoonInterfaces.first();
if (harpoonInterface != null) {
int inventoryCount = Inventory.getQuantity();
if (harpoonInterface.interact("Buy All")) {
Execution.delayUntil(() -> Inventory.getQuantity() > inventoryCount, 1200, 1600);
if (Menu.isOpen()) {
Menu.close();
}
}
}
}
} else {
LocatableEntityQueryResults<Npc> validShopKeepers = shopKeeperQuery.results();
if (!validShopKeepers.isEmpty()) {
Npc shopKeeper = validShopKeepers.first();
if (shopKeeper != null && shopKeeper.isValid()) {
if (shopKeeper.isVisible()) {
if (shopKeeper.interact("Trade")) {
Execution.delayUntil(() -> !shopInterfaceQuery.results().isEmpty(), 1200, 1600);
}
} else {
Camera.turnTo(shopKeeper);
}
}
}
}
}
}