Skip to content

Commit

Permalink
update Ethans API
Browse files Browse the repository at this point in the history
  • Loading branch information
zeruth committed Feb 27, 2024
1 parent 45acba7 commit 03e24be
Show file tree
Hide file tree
Showing 16 changed files with 744 additions and 716 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,6 @@ public static boolean isOpen() {
return client.getWidget(WidgetInfo.BANK_ITEM_CONTAINER) != null && !client.getWidget(WidgetInfo.BANK_ITEM_CONTAINER).isHidden();
}

// @Subscribe
// public void onItemContainerChanged(ItemContainerChanged e) {
// if (e.getContainerId() == 95) {
// int i = 0;
// Bank.bankItems.clear();
// for (Item item : e.getItemContainer().getItems()) {
// try {
// if (item == null) {
// i++;
// continue;
// }
// if (EthanApiPlugin.itemDefs.get(item.getId()).getPlaceholderTemplateId() == 14401) {
// i++;
// continue;
// }
// Bank.bankItems.add(new BankItemWidget(EthanApiPlugin.itemDefs.get(item.getId()).getName(), item.getId(), item.getQuantity(), i));
// } catch (NullPointerException | ExecutionException ex) {
// //todo fix this
// }
// i++;
// }
// }
// }

@Subscribe
public void onGameStateChanged(GameStateChanged gameStateChanged) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,6 @@ public String[] getActions() {
return actions;
}

public Widget createStaticChild(int type) {
return null;
}

@Override
public Widget createChild(int index, int type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static EquipmentItemQuery search() {
if (w == null || w.getActions() == null) {
continue;
}
equipment.add(new EquipmentItemWidget(w.getName(), item.getId(), w.getId(), i, w.getActions()));
equipment.add(new EquipmentItemWidget(w.getName(), item.getId(), w.getId(), -1, w.getActions()));
}
lastUpdateTick = client.getTickCount();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public Widget setHidden(boolean hidden) {

@Override
public int getIndex() {
return -1;
return index;
}

@Override
Expand Down Expand Up @@ -323,7 +323,7 @@ public Rectangle getBounds() {

@Override
public int getItemId() {
return -1;
return equipmentItemId;
}

@Override
Expand Down Expand Up @@ -452,10 +452,6 @@ public String[] getActions() {
return actions;
}

public Widget createStaticChild(int type) {
return null;
}

@Override
public Widget createChild(int index, int type) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.runelite.client.eventbus.Subscribe;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

public class TileObjects {
Expand All @@ -19,6 +20,7 @@ public static TileObjectQuery search() {

@Subscribe(priority = 10000)
public void onGameTick(GameTick e) {
HashSet<TileObject> tileObjectHashSet = new HashSet<>();
tileObjects.clear();
TileItems.tileItems.clear();
for (Tile[] tiles : client.getScene().getTiles()[client.getPlane()]) {
Expand All @@ -44,27 +46,32 @@ public void onGameTick(GameTick e) {
if (gameObject.getId() == -1) {
continue;
}
tileObjects.add(gameObject);
tileObjectHashSet.add(gameObject);
//tileObjects.add(gameObject);
}
if (tile.getGroundObject() != null) {
if (tile.getGroundObject().getId() == -1) {
continue;
}
tileObjects.add(tile.getGroundObject());
tileObjectHashSet.add(tile.getGroundObject());
//tileObjects.add(tile.getGroundObject());
}
if (tile.getWallObject() != null) {
if (tile.getWallObject().getId() == -1) {
continue;
}
tileObjects.add(tile.getWallObject());
tileObjectHashSet.add(tile.getWallObject());
//tileObjects.add(tile.getWallObject());
}
if (tile.getDecorativeObject() != null) {
if (tile.getDecorativeObject().getId() == -1) {
continue;
}
tileObjects.add(tile.getDecorativeObject());
tileObjectHashSet.add(tile.getDecorativeObject());
//tileObjects.add(tile.getDecorativeObject());
}
}
}
tileObjects.addAll(tileObjectHashSet);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

import com.example.EthanApiPlugin.Collections.Players;
import com.example.EthanApiPlugin.EthanApiPlugin;
import net.runelite.api.*;
import com.example.EthanApiPlugin.PathFinding.GlobalCollisionMap;
import com.example.EthanApiPlugin.Utility.WorldAreaUtility;
import net.runelite.api.Actor;
import net.runelite.api.Client;
import net.runelite.api.NPC;
import net.runelite.api.NPCComposition;
import net.runelite.api.coords.WorldArea;
import net.runelite.api.coords.WorldPoint;
import net.runelite.client.RuneLite;
Expand Down Expand Up @@ -89,7 +94,7 @@ public NPCQuery withinWorldArea(WorldArea area) {
return this;
}

public NPCQuery withinBounds(WorldPoint min, WorldPoint max){
public NPCQuery withinBounds(WorldPoint min, WorldPoint max) {
int x1 = min.getX();
int x2 = max.getX();
int y1 = min.getY();
Expand Down Expand Up @@ -141,11 +146,22 @@ public NPCQuery notInteracting() {
npcs = npcs.stream().filter(npc -> !npc.isInteracting()).collect(Collectors.toList());
return this;
}
public NPCQuery noOneInteractingWith(){

public NPCQuery noOneInteractingWith() {
npcs = npcs.stream().filter(npc -> Players.search().interactingWith(npc).isEmpty()).collect(Collectors.toList());
return this;
}

public NPCQuery playerInteractingWith() {
npcs = npcs.stream().filter(npc -> client.getLocalPlayer().isInteracting() && client.getLocalPlayer().getInteracting() == npc).collect(Collectors.toList());
return this;
}

public NPCQuery playerNotInteractingWith() {
npcs = npcs.stream().filter(npc -> !client.getLocalPlayer().isInteracting() || client.getLocalPlayer().getInteracting() != npc).collect(Collectors.toList());
return this;
}

public NPCQuery meleeable() {
List<WorldPoint> meleeTiles = new ArrayList<>();
meleeTiles.add(client.getLocalPlayer().getWorldLocation().dx(1));
Expand Down Expand Up @@ -189,4 +205,29 @@ public static NPCComposition getNPCComposition(NPC npc) {
}
return npc.getTransformedComposition();
}

public Optional<NPC> nearestByPath() {
HashMap<WorldPoint, NPC> npcMap = new HashMap<>();
for (NPC npc : npcs) {
for (WorldPoint wp : npc.getWorldArea().toWorldPointList()) {
npcMap.put(wp, npc);
}

for (WorldPoint wp : WorldAreaUtility.objectInteractableTiles(npc)) {
npcMap.put(wp, npc);
}
}
List<WorldPoint> path = EthanApiPlugin.pathToGoalSetFromPlayerNoCustomTiles(new HashSet<>(npcMap.keySet()));
if (path == null) {
return Optional.empty();
}
if (path.isEmpty()) {
if (npcMap.containsKey(client.getLocalPlayer().getWorldLocation())) {
return Optional.ofNullable(npcMap.get(client.getLocalPlayer().getWorldLocation()));
} else {
return Optional.empty();
}
}
return Optional.ofNullable(npcMap.get(path.get(path.size() - 1)));
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.example.EthanApiPlugin.Collections.query;

import com.example.EthanApiPlugin.EthanApiPlugin;
import com.example.EthanApiPlugin.PathFinding.GlobalCollisionMap;
import com.example.EthanApiPlugin.Utility.WorldAreaUtility;
import net.runelite.api.Actor;
import net.runelite.api.Client;
import net.runelite.api.NPC;
import net.runelite.api.Player;
import net.runelite.api.coords.WorldArea;
import net.runelite.api.coords.WorldPoint;
import net.runelite.client.RuneLite;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -102,4 +105,29 @@ public Optional<Player> first() {
public List<Player> result() {
return players;
}

public Optional<Player> nearestByPath() {
HashMap<WorldPoint, Player> playerMap = new HashMap<>();
for (Player player : players) {
for (WorldPoint wp : player.getWorldArea().toWorldPointList()) {
playerMap.put(wp, player);
}

for (WorldPoint wp : WorldAreaUtility.objectInteractableTiles(player)) {
playerMap.put(wp, player);
}
}
List<WorldPoint> path = EthanApiPlugin.pathToGoalSetFromPlayerNoCustomTiles(new HashSet<>(playerMap.keySet()));
if (path == null) {
return Optional.empty();
}
if (path.isEmpty()) {
if (playerMap.containsKey(client.getLocalPlayer().getWorldLocation())) {
return Optional.ofNullable(playerMap.get(client.getLocalPlayer().getWorldLocation()));
} else {
return Optional.empty();
}
}
return Optional.ofNullable(playerMap.get(path.get(path.size() - 1)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

import com.example.EthanApiPlugin.Collections.ETileItem;
import com.example.EthanApiPlugin.EthanApiPlugin;
import com.example.EthanApiPlugin.PathFinding.GlobalCollisionMap;
import lombok.SneakyThrows;
import net.runelite.api.Client;
import net.runelite.api.ItemComposition;
import net.runelite.api.TileItem;
import net.runelite.api.TileObject;
import net.runelite.api.coords.WorldPoint;
import net.runelite.client.RuneLite;
import net.runelite.client.game.ItemManager;
import net.runelite.client.util.Text;
import net.runelite.client.util.WildcardMatcher;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.function.Predicate;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -179,6 +179,10 @@ public TileItemQuery withinDistanceToPoint(int distance, WorldPoint point) {
tileItems = tileItems.stream().filter(tileItem -> tileItem.getLocation().distanceTo(point) <= distance).collect(Collectors.toList());
return this;
}
public TileItemQuery alchValueAbove(int value){
tileItems = tileItems.stream().filter(tileItem -> itemManager.getItemComposition(tileItem.getTileItem().getId()).getHaPrice() > value).collect(Collectors.toList());
return this;
}

public Optional<ETileItem> nearestToPlayer() {
return nearestToPoint(client.getLocalPlayer().getWorldLocation());
Expand All @@ -196,4 +200,22 @@ public boolean isNoted(ETileItem item) {
ItemComposition itemComposition = EthanApiPlugin.itemDefs.get(item.tileItem.getId());
return itemComposition.getNote() != -1;
}

public Optional<ETileItem> nearestByPath() {
HashSet<WorldPoint> tiles = new HashSet<>();
HashMap<WorldPoint, ETileItem> map = new HashMap<>();
WorldPoint playerLoc = client.getLocalPlayer().getWorldLocation();
for (var t : tileItems) {
if (playerLoc.equals(t.getLocation())) {
return Optional.of(t);
}
map.put(t.getLocation(), t);
tiles.add(t.getLocation());
}
List<WorldPoint> path = EthanApiPlugin.pathToGoalSetFromPlayerNoCustomTiles(new HashSet<>(tiles));
if (path == null || path.isEmpty()) {
return Optional.empty();
}
return Optional.ofNullable(map.get(path.get(path.size() - 1)));
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.example.EthanApiPlugin.Collections.query;

import com.example.EthanApiPlugin.EthanApiPlugin;
import com.example.EthanApiPlugin.PathFinding.GlobalCollisionMap;
import com.example.EthanApiPlugin.Utility.WorldAreaUtility;
import net.runelite.api.Client;
import net.runelite.api.ObjectComposition;
import net.runelite.api.TileObject;
import net.runelite.api.coords.WorldPoint;
import net.runelite.client.RuneLite;

import javax.swing.text.html.Option;
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -136,6 +140,27 @@ public Optional<TileObject> nearestToPlayer() {
return tileObjects.stream().min(Comparator.comparingInt(o -> client.getLocalPlayer().getWorldLocation().distanceTo(o.getWorldLocation())));
}

public Optional<TileObject> nearestByPath() {
HashMap<WorldPoint, TileObject> map = new HashMap<>();
var playerLoc = client.getLocalPlayer().getWorldLocation();
for (TileObject tileObject : tileObjects) {
List<WorldPoint> adjacentTiles = WorldAreaUtility.objectInteractableTiles(tileObject);
for (WorldPoint worldPoint : adjacentTiles) {
if (playerLoc.equals(worldPoint)) {
return Optional.of(tileObject);
}
map.put(worldPoint, tileObject);
}
}

List<WorldPoint> path = EthanApiPlugin.pathToGoalSetFromPlayerNoCustomTiles(new HashSet<>(map.keySet()));
if (path == null || path.isEmpty()) {
return Optional.empty();
}

return Optional.ofNullable(map.get(path.get(path.size() - 1)));
}

public Optional<TileObject> nearestToPoint(WorldPoint point) {
return tileObjects.stream().min(Comparator.comparingInt(o -> point.distanceTo(o.getWorldLocation())));
}
Expand Down
Loading

0 comments on commit 03e24be

Please sign in to comment.