Script for transfering leafes form mulberry tree to mansion cellar. To start script you need stay outside.
Code: Select all
//#! name = leaf factory
//#! uniq = leaf_factory_by_thebender
//#! icon = gfx/invobjs/mulberryleaf
//var mulberry = null
//var house = null
var mul = choise_mulberry();
var inn = choise_house();
var count = 0;
var all_cupboard = 0;
function getRandomArbitary(min, max)
{
return Math.random() * (max - min) + min;
}
function jPFMove_LX(point) {
point = jTilify(point);
var MyX = jMyCoords().x;
var MyY = jMyCoords().y;
jPFMove(point);
cycles = 0;
while (MyX != point.x || MyY != point.y)
{
jPrint("jPFMove_LX My =" + MyX + " " + MyY + " - " + point.x + " " + point.y);
jSleep(1000);
MyX = jMyCoords().x;
MyY = jMyCoords().y;
if(cycles == 20)
{
jPrint("jPFMove_LX trying to move again");
jOffsetClick(jCoord(getRandomArbitary(-2,2),getRandomArbitary(-2,2)),1,0);
jSleep(500);
jPFMove(point);
cycles = 0
}
cycles++;
}
jPrint("jPFMove ended");
}
function jPFMoveOffset_LX(point, offset) {
offsMoveS=jCoord(0,offset);
offsMoveE=jCoord(offset,0);
offsMoveW=jCoord(-offset,0);
offsMoveN=jCoord(0,-offset);
while (1) {
if(jPFMove(point.add(offsMoveS.mul(11))) > 0) {
jPFMove_LX(point.add(offsMoveS.mul(11)));
return offsMoveS;
}
if(jPFMove(point.add(offsMoveE.mul(11))) > 0) {
jPFMove_LX(point.add(offsMoveE.mul(11)));
return offsMoveE;
}
if(jPFMove(point.add(offsMoveW.mul(11))) > 0) {
jPFMove_LX(point.add(offsMoveW.mul(11)));
return offsMoveW;
}
if(jPFMove(point.add(offsMoveN.mul(11))) > 0) {
jPFMove_LX(point.add(offsMoveN.mul(11)));
return offsMoveN;
}
jPrint("jPFMoveOffset_LX can't find path");
// break;
jOffsetClick(jCoord(getRandomArbitary(-2,2),getRandomArbitary(-2,2)),1,0);
jSleep(500);
}
}
function checkInventory() {
if(!jHaveWindow("Inventory")) {
jToggleInventory();
while(!jHaveWindow("Inventory"))
jSleep(100);
}
return jGetWindow("Inventory").getInventories()[0];
}
function choise_mulberry() {
if (mulberry == null) {
var select_mulberry = jSelectObject("Select mulberry tree");
var mulberry = jFindObjectByName(select_mulberry.name(), 50);
if (mulberry == null) {
jToConsole("Mulberry not found! Script stoped.");
jExit();
}
}
return mulberry;
}
function choise_house() {
if (house == null) {
var select_house = jSelectObject("Select house door");
var house = jFindObjectByName(select_house.name(), 50);
if (house == null) {
jToConsole("House not found! Script stoped.");
jExit();
}
}
return house;
}
function go_for_leafs(tree) {
inventory = checkInventory();
var house_outside = jFindObjectByName("arch/inn", 50);
while (house_outside = null) {
jSleep(100);
}
if (inventory.freeSlots() > 0) {
jPFMoveOffset_LX(tree.position(), 1);
jDoClick(tree.getID(),3,0);
jWaitPopup(1000);
jSelectContextMenu("Pick leaf");
while (inventory.freeSlots() > 0) {
jSleep(100);
}
}
}
function go_to_cellar(door) {
jPFMoveOffset_LX(door.position(), 1);
jDoClick(door.getID(),3,0);
jSleep(1000);
var cellar_door = jFindObjectByName("arch/door-cellar", 50);
while (cellar_door == null) {
jSleep(100);
var cellar_door = jFindObjectByName("arch/door-cellar", 50);
}
jToConsole("I'm in house");
jDoClick(cellar_door.getID(),3,0);
jSleep(100);
var cellar_stairs = jFindObjectByName("arch/stairs-cellar", 50);
while (cellar_stairs == null) {
jSleep(100);
var cellar_stairs = jFindObjectByName("arch/stairs-cellar", 50);
}
jToConsole("I'm in cellar");
jSleep(1000);
}
function transfer_leafs() {
var inventory = checkInventory();
var open_cupboard = jGetWindow("Cupboard").getInventories()[0];
var silkworms = open_cupboard.getItems("invobjs/silkworm");
var leafes_cupboard = open_cupboard.getItems("invobjs/mulberryleaf");
if (silkworms.length != 0 && leafes_cupboard.length != 48) {
var leafes_inventory = inventory.getItems("invobjs/mulberryleaf");
if (leafes_inventory.length > 48 - leafes_cupboard.length) {
for (var j = leafes_cupboard.length; j < silkworms.length * 4; j++) {
var freeSlot = open_cupboard.freeSlotsCoords()[0];
var leafes_inventory = inventory.getItems("invobjs/mulberryleaf");
leafes_inventory[0].take();
jWaitDrag();
open_cupboard.drop(freeSlot);
jWaitDrop();
}
} else {
for (var j = leafes_inventory.length; j > 1; j--) {
var freeSlot = open_cupboard.freeSlotsCoords()[0];
var leafes_inventory = inventory.getItems("invobjs/mulberryleaf");
leafes_inventory[0].take();
jWaitDrag();
open_cupboard.drop(freeSlot);
jWaitDrop();
}
}
}
}
function go_to_cupboard() {
if (cupboards == null) {
var cupboards = jGetObjects(50, jCoord(0, 0), "terobjs/cupboard");
all_cupboard = cupboards.length
}
for (var i = count; i < cupboards.length; i++) {
var leafes_inventory = inventory.getItems("invobjs/mulberryleaf");
if (leafes_inventory.length > 1) {
jPFMoveOffset_LX(cupboards[i].position(), 1);
jDoClick(cupboards[i].getID(),3,0);
jSleep(1000);
var open_cupboard = jGetWindow("Cupboard");
while (open_cupboard == null) {
jPFMoveOffset_LX(cupboards[i].position(), 1);
jDoClick(cupboards[i].getID(),3,0);
jSleep(1000);
var open_cupboard = jGetWindow("Cupboard");
}
transfer_leafs();
jSleep(1000);
var silkworms = jGetWindow("Cupboard").getInventories()[0].getItems("invobjs/silkworm");
var leafes_cupboard = jGetWindow("Cupboard").getInventories()[0].getItems("invobjs/mulberryleaf");
if (leafes_cupboard.length >= silkworms.length * 4 || silkworms == null) {
count++;
jToConsole(count);
}
}
}
}
function go_out() {
var cellar_stairs = jFindObjectByName("arch/stairs-cellar", 50);
jPFMoveOffset_LX(cellar_stairs.position(), 1);
jDoClick(cellar_stairs.getID(),3,0);
jSleep(1000);
jToConsole("I'm in house");
var out_door = jFindObjectByName("arch/door-inn", 50);
while (out_door == null) {
jSleep(100);
var cellar_door = jFindObjectByName("arch/door-inn", 50);
}
jToConsole("I'm out!");
jPFMoveOffset_LX(out_door.position(), -1);
jDoClick(out_door.getID(),3,0);
if (count == all_cupboard) {
jExit();
}
jSleep(5000);
}
function main() {
go_for_leafs(mul);
go_to_cellar(inn);
go_to_cupboard();
go_out();
}
while(1) {
main();
}