Skip to content

Instantly share code, notes, and snippets.

/maddev_App.java Secret

Created May 29, 2016 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/58587c6565a1e0311038c2c08451622d to your computer and use it in GitHub Desktop.
Save anonymous/58587c6565a1e0311038c2c08451622d to your computer and use it in GitHub Desktop.
package org.maddev;
import org.tbot.internal.AbstractScript;
import org.tbot.methods.*;
import org.tbot.methods.tabs.Inventory;
import org.tbot.methods.walking.Path;
import org.tbot.methods.walking.Walking;
import org.tbot.wrappers.Item;
import org.tbot.wrappers.NPC;
import org.tbot.wrappers.Tile;
/**
* Created by Mad on 5/29/16.
*/
public class App extends AbstractScript
{
private FishSpot current = FishSpot.LUMBRIDGE_RIVER;
private boolean hasEquipment(FishSpot spot)
{
for (String name : spot.getRequiredEquipment())
{
if(!Inventory.contains(name)) return false;
}
return true;
}
private boolean shouldWalk(FishSpot spot)
{
return !spot.getLocation().isOnMiniMap();
}
private boolean isAnimating()
{
return Players.getLocal().getAnimation() != -1;
}
private boolean shouldDrop()
{
return Inventory.isFull();
}
private boolean dropFish(FishSpot current)
{
for (Item item : Inventory.getItems())
{
if(!doesEquipmentContainItem(current, item))
{
Inventory.drop(item.getID());
}
}
return Inventory.getCount() == current.getRequiredEquipment().length;
}
private boolean doesEquipmentContainItem(FishSpot current, Item item)
{
for (String name : current.getRequiredEquipment())
{
if(item.getName().equals(name)) return true;
}
return false;
}
/*
Now our whole loop should look like so, and our script
should be complete.
*/
@Override
public int loop()
{
if(!hasEquipment(current))
{
getEquipmentFromBank(current);
}
else if (shouldDrop())
{
dropFish(current);
}
else if (shouldWalk(current))
{
final Path p = Walking.findPath(current.getLocation());
if(p != null)
{
p.traverse();
Time.sleep(860, 920);
}
}
else
{
fish(current);
}
return Random.nextInt(385, 565);
}
private void getEquipmentFromBank(FishSpot current)
{
if(!Bank.isOpen())
{
Bank.openNearestBank();
}
else
{
final String[] items = current.getRequiredEquipment();
for (String name : items)
{
if(!Inventory.contains(name))
{
Bank.withdraw(name, 1);
Time.sleep(950, 1120);
}
}
}
}
private void fish(FishSpot current)
{
final NPC fishSpot = Npcs.getNearest("Fishing spot");
if(fishSpot == null) return;
if(!fishSpot.isOnScreen())
{
final Tile t = fishSpot.getLocation().getRandomized(2);
Path p = Walking.findLocalPath(t);
if(p != null)
{
p.traverse();
Time.sleep(650, 891);
}
}
/*
Ok so now we can be sure the spot is on screen,
one last thing we need to do is check to see
if we are already animating, if not we can interact.
Use the method we created earlier, and apply "!" to inverse it.
*/
else if (!isAnimating())
{
/*
If we aren't animating,
interact and then sleep until we are animating.
*/
fishSpot.interact(current.getAction());
Time.sleepUntil(() -> isAnimating(), 2500);
}
}
}
package org.maddev;
import org.tbot.wrappers.Tile;
/**
* Created by Mad on 5/29/16.
*/
public enum FishSpot
{
/*
So now lets add our data...
*/
LUMBRIDGE_SWAMP(new Tile(3202, 2322, 0), "Net",
"Small fishing net"),
LUMBRIDGE_RIVER(new Tile(3202, 3432, 0), "Bait",
"Fishing rod", "Fishing bait");
private final Tile location;
private final String action;
private final String[] requiredEquipment;
FishSpot(Tile location, String action, String ... requiredEquipment)
{
this.location = location;
this.action = action;
this.requiredEquipment = requiredEquipment;
}
public Tile getLocation()
{
return location;
}
public String getAction()
{
return action;
}
public String[] getRequiredEquipment()
{
return requiredEquipment;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment