Info:
Here you can find some information about groovy maid engine.
It's bundled with Anemone client, with few improvements.
Here's my plowdrink script, as written in the description, it plows a single tile, drinks water, and gets more water from a well. To succesfully run it, you need a bucket, waterflask / waterskin, and a well in given radius (30 tiles by default).
- Code: Select all
/* ====================================================================================================
Simple script to burn hunger, it plows a single tile and drinks water.
To properly works, it requires: A bucket, waterflask or waterskin, an accessible well.
It will keep plowing, drinking water, and refilling water when needed.
Stops working when hunger drops below 30% (default value) of very hungry bar.
Although it uses a pathfinder, it may occasionally get stuck if there are too many items
between the well and plowing place.
*///====================================================================================================
import java.util.*;
import java.lang.*;
import haven.event.*;
import haven.*;
// ==================================================
// Settings
// ==================================================
// Script will look for a well in given radius
int wellRadius = 30;
// A stop condition, minimum value of very hungry bar
int minHunger = 30;
// ==================================================
// Some checks
// ==================================================
Item cup;
Item bucket;
Gob well;
inv = maid.getInventory();
Coord pos = maid.getCoord();
// Checking for a waterflask / waterskin
if (hasItem("waterflask") == true) {
cup = maid.getItems(inv, "waterflask")[0];
} else if (hasItem("waterskin") == true) {
cup = maid.getItems(inv, "waterskin")[0];
} else {
println("Waterflask or waterskin is missing.");
return;
}
// Checking for a bucket
if (hasItem("bucket") == true) {
bucket = maid.getItems(inv, "bucket")[0];
} else {
println("Bucket is missing.");
return;
}
// Looking for a well
well = maid.doAreaFind(wellRadius, "well");
if (well == null) {
println("Well was not found.");
return;
}
// ==================================================
// Main loop
// ==================================================
// Will work until the hunger bar drops below the given value of very hungry bar
starving = checkStarvation(minHunger);
while (!starving) {
if (maid.meterStamina.value < 50) {
if (getWaterValue(bucket) < 1) {
getWater(well, bucket); // If we're running out of water, get some
bucket = maid.getItems(inv, "bucket")[0]; // Need to reload the dropped bucket
maid.pathFind(pos, 6, false); // Return to previous place
}
drinkSome(cup, bucket);
bucket = maid.getItems(inv, "bucket")[0]; // Need to reload the dropped bucket
}
maid.doAction("act", "plow"); // Time to plow!
maid.doLeftClick(pos)
maid.doRightClick(pos); // Get rid of plow icon
maid.waitForTask();
starving = checkStarvation(minHunger);
}
// ==================================================
// Helper functions
// ==================================================
boolean checkStarvation(int minHunger) {
if (maid.meterHunger.type == MeterEventObjectHunger.HungerType.VERY_HUNGRY && maid.meterHunger.value < minHunger) {
return true;
}
return false;
}
void getWater(Gob well, Item bucket) {
maid.pathFind(maid.getCoord(well), 6, false);
Coord bucketplace = maid.getCoord(bucket);
maid.doTake(bucket);
maid.waitForGrab();
maid.doInteract(well);
Thread.sleep(4500); // Not event based, error-prone
inv.drop(null, new Coord(bucketplace.x*32,bucketplace.y*32)); // meh
maid.waitForItemCreate();
}
boolean hasItem(String itemName) {
if (maid.getItems(inv, itemName).length != 0) return true;
return false;
}
void drinkSome(Item cup, Item bucket) {
Coord bucketplace = maid.getCoord(bucket);
maid.doTake(bucket);
maid.waitForGrab();
maid.doInteract(cup, 1);
inv.drop(null, new Coord(bucketplace.x*32,bucketplace.y*32));
maid.doInteract(cup);
menu = maid.waitForFlowerMenu();
maid.doSelect(menu, "Drink");
maid.waitForTask();
}
// Stolen, I mean, adapted from Anemone client code. Slightly modified. Lemme know if there's a better way to do that
double getWaterValue(Item bucket) {
if (bucket.tooltip.indexOf('/') < 0) return 0;
String valStr = bucket.tooltip.substring(bucket.tooltip.indexOf('(') + 1, bucket.tooltip.indexOf('/'));
double val = Double.parseDouble(valStr);
}
Over time, I'll keep adding other scripts.