Hey, thanks for the script.
I am just getting into this and it was handy, however I ran into a few problems.
I've made some changes that I think improve the script, let me know what you think 🙂
import com.epicbot.api.shared.APIContext;
import com.epicbot.api.shared.GameType;
import com.epicbot.api.shared.model.Tile;
import com.epicbot.api.shared.script.LoopScript;
import com.epicbot.api.shared.script.ScriptManifest;
import com.epicbot.api.shared.util.paint.frame.PaintFrame;
import com.epicbot.api.shared.util.time.Time;
import java.awt.*;
@ScriptManifest(name = "Gfxnick's Chocolate Duster", gameType = GameType.OS)
public class Main extends LoopScript {
//Ids
private final int knifeId = 946;
private final int chocolateId = 1973;
private final int notedChocolateId = 1974;
private final int crushedChocolateId = 1975;
//Bank location
private final Tile BankTile = new Tile(3167, 3490, 0);
//Delays
private final int minUseDelay = 10;
private final int maxUseDelay = 40;
//UI Info variables
private int actionsPerformed = 0;
private int chocolateCut = 0;
private long startTime;
@Override
public boolean onStart(String... strings)
{
startTime = System.currentTimeMillis();
return true;
}
@Override
protected int loop()
{
if(!getAPIContext().inventory().contains(chocolateId) || getAPIContext().inventory().contains(notedChocolateId))
{
Bank();
}
else if(getAPIContext().inventory().getItemAt(27) == null ||
getAPIContext().inventory().getItemAt(27).getId() != knifeId)
{
MoveItem(knifeId, 27);
}
else if(getAPIContext().inventory().getItemAt(26) == null ||
getAPIContext().inventory().getItemAt(26).getId() != chocolateId)
{
MoveItem(chocolateId, 26);
}
else if(getAPIContext().bank().isOpen())
{
CloseBank();
}
else
{
CutChocolate();
}
return 0;
}
public void MoveItem(int itemId, int indexToMoveTo)
{
if(!getAPIContext().inventory().contains(itemId))
{
return;
}
int itemIndex = getAPIContext().inventory().getItem(itemId).getIndex();
getAPIContext().inventory().moveItem(itemIndex, indexToMoveTo);
Time.sleep(5_000, ()->getAPIContext().inventory().getItemAt(indexToMoveTo).getId() == itemId);
}
public boolean IsPlayerAtBank()
{
return getAPIContext().localPlayer().getLocation().equals(BankTile);
}
public void Bank()
{
getAPIContext().inventory().deselectItem();
if (!IsPlayerAtBank())
{
getAPIContext().walking().walkTo(BankTile);
System.out.println("Walking to bank");
Time.sleep(5_000, this::IsPlayerAtBank);
}
else
{
OpenBank();
if (getAPIContext().bank().isOpen())
{
chocolateCut += getAPIContext().inventory().getItems(crushedChocolateId).size();
getAPIContext().bank().depositAllExcept(knifeId, chocolateId);
if (!getAPIContext().inventory().contains(knifeId))
{
getAPIContext().bank().withdraw(1, knifeId);
Time.sleep(1_000, ()->getAPIContext().inventory().contains(knifeId));
}
getAPIContext().bank().withdrawAll(chocolateId);
Time.sleep(1_000, ()->getAPIContext().inventory().contains(chocolateId));
if(getAPIContext().inventory().isFull())
{
CloseBank();
}
}
}
}
public void CutChocolate()
{
if(getAPIContext().inventory().interactItem("Use" , knifeId))
{
getAPIContext().inventory().getItemAt(26).interact("Use");
Time.sleep(minUseDelay, maxUseDelay);
actionsPerformed++;
}
}
public void OpenBank()
{
if (IsPlayerAtBank())
{
if (!getAPIContext().bank().isOpen())
{
System.out.println("Trying to open bank");
getAPIContext().bank().open();
Time.sleep(5_000, () -> getAPIContext().bank().isOpen());
}
}
}
public void CloseBank()
{
if(getAPIContext().bank().isOpen())
{
System.out.println("Trying to close bank");
getAPIContext().bank().close();
Time.sleep(5_000, () -> !getAPIContext().bank().isOpen());
}
}
@Override
protected void onPaint(Graphics2D g, APIContext ctx) {
long runningTime = System.currentTimeMillis() - startTime;
long crushedPerHour = (int) (chocolateCut * 3600000.0D / runningTime);
PaintFrame frame = new PaintFrame("Gfxnick's Chocolate Crusher");
frame.addLine("Title", "Value");
frame.addLine("Runtime: ", Time.getFormattedRuntime(startTime));
frame.addLine("Actions: ", actionsPerformed);
frame.addLine("Chocolate Crushed: ", chocolateCut);
frame.addLine("Crushed/Hr: ", crushedPerHour);
frame.draw(g, 0, 170, ctx);
}
}