- Joined
- Feb 21, 2017
- Messages
- 7
- Thread Author
- #1
Hi, I'm attempting to make a simple swamp toad collecting bot that collects toads efficiently in a path, as a player would. Eventually I'd like to implement some randomization and configuration for different paths, but for now I'm just trying to get it working with one order.
I'm wondering if there's a best practice for determining the next toad to collect based on the last toad collected.
As of now, my onItemAdded method is calling a public function in my root class that sets the bot property currrentToad to the next toad to be picked up. This property is then passed through the necessary branches in my tree when it reaches isNearby which nullchecks and takeToad which attempts to collect the toad. I use switch statements in both of those nodes to determine the coordinates of the currentToad.
My implementation seems to skip the last few toads, randomly breaks and overall just looks like a mess. I'm thinking there has to be a better way to do this, ideally one that makes it easy for modular toad orders and some randomization.
Below are some snippets of my source code:
toadSpawn.java
TreeToads.java
Root.java
isNearby.java
takeToad.java
map of toads:
https://s1.postimg.org/ww848tsjz/Swamp_Toad_Spawns.png
Credit to proxi, who's code I'mbuilding ondestroying
I'm wondering if there's a best practice for determining the next toad to collect based on the last toad collected.
As of now, my onItemAdded method is calling a public function in my root class that sets the bot property currrentToad to the next toad to be picked up. This property is then passed through the necessary branches in my tree when it reaches isNearby which nullchecks and takeToad which attempts to collect the toad. I use switch statements in both of those nodes to determine the coordinates of the currentToad.
My implementation seems to skip the last few toads, randomly breaks and overall just looks like a mess. I'm thinking there has to be a better way to do this, ideally one that makes it easy for modular toad orders and some randomization.
Below are some snippets of my source code:
toadSpawn.java
Code:
public enum ToadSpawn {
toad1,
toad2,
toad3,
toad4,
toad5,
toad6,
toad7,
toad8,
toad9,
toad10,
toad11,
toad12,
toad13,
toad14,
toad15,
toad16,
toad17,
toad18
}
TreeToads.java
Code:
public class TreeToads extends TreeBot implements InventoryListener {
...
public ToadSpawn currentToad;
...
public final Coordinate toad1Coordinate = new Coordinate(2421,3509,0);
public final Coordinate toad2Coordinate = new Coordinate(2417,3508,0);
public final Coordinate toad3Coordinate = new Coordinate(2418,3511,0);
public final Coordinate toad4Coordinate = new Coordinate(2417,3512,0);
public final Coordinate toad5Coordinate = new Coordinate(2416,3512,0);
public final Coordinate toad6Coordinate = new Coordinate(2413,3511,0);
public final Coordinate toad7Coordinate = new Coordinate(2411,3512,0);
public final Coordinate toad8Coordinate = new Coordinate(2409,3514,0);
public final Coordinate toad9Coordinate = new Coordinate(2407,3516,0);
public final Coordinate toad10Coordinate = new Coordinate(2412,3519,0);
public final Coordinate toad11Coordinate = new Coordinate(2415,3518,0);
public final Coordinate toad12Coordinate = new Coordinate(2417,3516,0);
public final Coordinate toad13Coordinate = new Coordinate(2417,3515,0);
public final Coordinate toad14Coordinate = new Coordinate(2418,3517,0);
public final Coordinate toad15Coordinate = new Coordinate(2421,3519,0);
public final Coordinate toad16Coordinate = new Coordinate(2424,3517,0);
public final Coordinate toad17Coordinate = new Coordinate(2424,3514,0);
public final Coordinate toad18Coordinate = new Coordinate(2428,3501,0);
...
public TreeToads(){
currentToad = toad1;
}
@Override
public TreeTask createRootTask() {
return new Root(this, currentToad);
}
...
@Override
public void onItemAdded(ItemEvent event) {
ItemDefinition definition = event.getItem().getDefinition();
if (definition != null) {
if (definition.getName().contains("Swamp toad")) {
updateCurrentToad(false);
}
}
}
}
Root.java
Code:
public class Root extends BranchTask {
private TreeToads bot;
private static ToadSpawn currentToad;
public Root(TreeToads bot, ToadSpawn currentToad){
this.bot = bot;
this.currentToad = currentToad;
}
...
public static void updateCurrentToad(boolean reset){
if(reset){
System.out.println("Leaving, resetting toad");
currentToad = toad1;
} else {
System.out.println("Toad added, determineCurrentToad called");
switch (currentToad){
case toad1: currentToad = toad2;
break;
case toad2: currentToad = toad3;
break;
case toad3: currentToad = toad4;
break;
case toad4: currentToad = toad5;
break;
case toad5: currentToad = toad6;
break;
case toad6: currentToad = toad7;
break;
case toad7: currentToad = toad8;
break;
case toad8: currentToad = toad9;
break;
case toad9: currentToad = toad10;
break;
case toad10: currentToad = toad11;
break;
case toad11: currentToad = toad12;
break;
case toad12: currentToad = toad13;
break;
case toad13: currentToad = toad14;
break;
case toad14: currentToad = toad15;
break;
case toad15: currentToad = toad16;
break;
case toad16: currentToad = toad17;
break;
case toad17: currentToad = toad18;
break;
case toad18: currentToad = toad1;
break;
}
}
}
}
isNearby.java
Code:
public class IsNearby extends BranchTask {
private TreeToads bot;
private Locatables locatable;
private ToadSpawn currentToad;
private GameObject obj;
private GroundItem obj2;
public IsNearby(TreeToads bot, Locatables locatable, ToadSpawn currentToad){
this.bot = bot;
this.locatable = locatable;
this.currentToad = currentToad;
}
@Override
public boolean validate() {
if(locatable == Locatables.bank) {
obj = GameObjects.newQuery().actions("Bank").within(bot.bankArea).results().nearest();
} else if(locatable == Locatables.toad) {
switch (currentToad) {
case toad1: obj2 = GroundItems.getLoadedOn(bot.toad1Coordinate, "Swamp toad").first();
break;
case toad2: obj2 = GroundItems.getLoadedOn(bot.toad2Coordinate, "Swamp toad").first();
break;
case toad3: obj2 = GroundItems.getLoadedOn(bot.toad3Coordinate, "Swamp toad").first();
break;
case toad4: obj2 = GroundItems.getLoadedOn(bot.toad4Coordinate, "Swamp toad").first();
break;
case toad5: obj2 = GroundItems.getLoadedOn(bot.toad5Coordinate, "Swamp toad").first();
break;
case toad6: obj2 = GroundItems.getLoadedOn(bot.toad6Coordinate, "Swamp toad").first();
break;
case toad7: obj2 = GroundItems.getLoadedOn(bot.toad7Coordinate, "Swamp toad").first();
break;
case toad8: obj2 = GroundItems.getLoadedOn(bot.toad8Coordinate, "Swamp toad").first();
break;
case toad9: obj2 = GroundItems.getLoadedOn(bot.toad9Coordinate, "Swamp toad").first();
break;
case toad10: obj2 = GroundItems.getLoadedOn(bot.toad10Coordinate, "Swamp toad").first();
break;
case toad11: obj2 = GroundItems.getLoadedOn(bot.toad11Coordinate, "Swamp toad").first();
break;
case toad12: obj2 = GroundItems.getLoadedOn(bot.toad12Coordinate, "Swamp toad").first();
break;
case toad13: obj2 = GroundItems.getLoadedOn(bot.toad13Coordinate, "Swamp toad").first();
break;
case toad14: obj2 = GroundItems.getLoadedOn(bot.toad14Coordinate, "Swamp toad").first();
break;
case toad15: obj2 = GroundItems.getLoadedOn(bot.toad15Coordinate, "Swamp toad").first();
break;
case toad16: obj2 = GroundItems.getLoadedOn(bot.toad16Coordinate, "Swamp toad").first();
break;
case toad17: obj2 = GroundItems.getLoadedOn(bot.toad17Coordinate, "Swamp toad").first();
break;
case toad18: obj2 = GroundItems.getLoadedOn(bot.toad18Coordinate, "Swamp toad").first();
break;
}
}
return (obj != null && obj.distanceTo(Players.getLocal()) < 12) || (obj2 != null && obj2.distanceTo(Players.getLocal()) < 25);
}
@Override
public TreeTask successTask() {
if(locatable == Locatables.bank)
return new OpenBankLeaf(bot);
else if(locatable == Locatables.toad)
return new TakeToad(bot, currentToad, obj2);
else
return new EmptyLeaf();
}
@Override
public TreeTask failureTask() {
if(locatable == Locatables.bank)
return new TraversalLeaf(bot, TraversalLocation.bankArea);
else if(locatable == Locatables.toad)
return new TraversalLeaf(bot, TraversalLocation.toadArea);
else
return new EmptyLeaf();
}
takeToad.java
Code:
public class TakeToad extends LeafTask {
private TreeToads bot;
private ToadSpawn currentToad;
private GroundItem toad;
public TakeToad(TreeToads bot, ToadSpawn currentToad, GroundItem obj2){
this.bot = bot;
this.currentToad = currentToad;
this.toad = obj2;
}
@Override
public void execute()
{
switch (currentToad) {
case toad1: toad = GroundItems.getLoadedOn(bot.toad1Coordinate, "Swamp toad").first();
break;
case toad2: toad = GroundItems.getLoadedOn(bot.toad2Coordinate, "Swamp toad").first();
break;
case toad3: toad = GroundItems.getLoadedOn(bot.toad3Coordinate, "Swamp toad").first();
break;
case toad4: toad = GroundItems.getLoadedOn(bot.toad4Coordinate, "Swamp toad").first();
break;
case toad5: toad = GroundItems.getLoadedOn(bot.toad5Coordinate, "Swamp toad").first();
break;
case toad6: toad = GroundItems.getLoadedOn(bot.toad6Coordinate, "Swamp toad").first();
break;
case toad7: toad = GroundItems.getLoadedOn(bot.toad7Coordinate, "Swamp toad").first();
break;
case toad8: toad = GroundItems.getLoadedOn(bot.toad8Coordinate, "Swamp toad").first();
break;
case toad9: toad = GroundItems.getLoadedOn(bot.toad9Coordinate, "Swamp toad").first();
break;
case toad10: toad = GroundItems.getLoadedOn(bot.toad10Coordinate, "Swamp toad").first();
break;
case toad11: toad = GroundItems.getLoadedOn(bot.toad11Coordinate, "Swamp toad").first();
break;
case toad12: toad = GroundItems.getLoadedOn(bot.toad12Coordinate, "Swamp toad").first();
break;
case toad13: toad = GroundItems.getLoadedOn(bot.toad13Coordinate, "Swamp toad").first();
break;
case toad14: toad = GroundItems.getLoadedOn(bot.toad14Coordinate, "Swamp toad").first();
break;
case toad15: toad = GroundItems.getLoadedOn(bot.toad15Coordinate, "Swamp toad").first();
break;
case toad16: toad = GroundItems.getLoadedOn(bot.toad16Coordinate, "Swamp toad").first();
break;
case toad17: toad = GroundItems.getLoadedOn(bot.toad17Coordinate, "Swamp toad").first();
break;
case toad18: toad = GroundItems.getLoadedOn(bot.toad18Coordinate, "Swamp toad").first();
break;
}
if(toad != null)
{
if (!toad.isVisible())
Camera.concurrentlyTurnTo(toad);
if (toad.interact("Take"))
Execution.delay(100, 500);
}
}
}
map of toads:
https://s1.postimg.org/ww848tsjz/Swamp_Toad_Spawns.png
Credit to proxi, who's code I'm
Last edited: