Hello all.
I'm writing a fighter bot that picks up loot from the tile where the last target died. I was wondering if someone could point me to a more efficient and clean way to write the for loops that check for relevant items on the tile and picks them up (see below).
Looking forward to learn more.
public void lootingLastKilled() {
List<GroundItem> itemsOnTile = getGroundItems().get(targetTile.getX(), targetTile.getY());
List<String> itemsToLoot = Stream.of("Feather","Bones").collect(Collectors.toList());
// Check for items on target tile that match items the bot should loot
for (int i = 0; i < itemsOnTile.size(); i++) {
for (int j = 0; j < itemsToLoot.size(); j++) {
if (itemsOnTile.get(i).getName().equals(itemsToLoot.get(j))) {
// Pick up ground item that matches items to loot
GroundItem itemToPickUp = itemsOnTile.get(i);
itemToPickUp.interact("Take");
(new ConditionalSleep(3000) {
public boolean condition() throws InterruptedException {
return myPlayer().isAnimating();
}
}).sleep();
}
}
}
}