The Wiki for Tale 7 is in read-only mode and is available for archival and reference purposes only. Please visit the current Tale 11 Wiki in the meantime.

If you have any issues with this Wiki, please post in #wiki-editing on Discord or contact Brad in-game.

User:Silden/Macro/Flax.lua

From ATITD7
< User:Silden‎ | Macro
Revision as of 23:31, 27 September 2015 by Silden (talk | contribs)
Jump to navigationJump to search
  • Designed to work on a very big screen (1920 width)
  • Requires cursor movements switched on, F8 F8 mode (zoom in a bit for the bed to show at least an inch in size, but it's not needed to zoom all the way in)
  • 15 beds (5 across, 3 up, from right to left to start with)
  • Change the repeat times value depending on your seed
  • Works with guilded beds.

You will also need this image: Nothing.png (Right click the image, "Save Image As" and save it into into \Automato\games\ATITD\images folder)

dofile("screen_reader_common.inc");
dofile("ui_utils.inc");
dofile("common.inc");
dofile("serialize.inc");
dofile("settings.inc");
dofile("constants.inc");

local GridAcross = 5;
local DelayBeforePlanting = 100;
local DelayMoving = 300;
local DelayAfterPlanting = 500;
local WindowAcross = 200; --How far across for each window
local WindowDown = 125; --How far down for each window
local MousePos
xyCenter = {};
local EndMessage = " \n\nTo stop the macro, press Ctrl + Shift. To pause the macro, press Alt + Shift.";

askText = singleLine([[
 Pin open the window with the desired seed, hover the mouse over the button, then press Shift to start the Macro.
]]);


function doit()
 -- mousePos is location of Seed Plant, obtained when you start the macro
 mousePos = askForWindow(askText);
 initGlobals();
 MainPlanter();
 
 local RepeatTimes = 6 
 -- Sinai Sage(w), Sunset Pond(w), Old Egypt, Nile Green(w) = 2
 -- Old Dog(w2), Symphony Ridge = 3
 -- Constitution Peak(w) = 4
 -- Jacob's Field = 6
 
 for i = 1, (RepeatTimes+1) do
    BedWatch2();
 end
end  
 
function initGlobals()
  srReadScreen();
  xyWindowSize = srGetWindowSize();
 
  xyCenter[0] = xyWindowSize[0] / 2 - 14;
  xyCenter[1] = xyWindowSize[1] / 2 + 18;
 end
 
 function BedWatch2()
   local WindowCount = clickAllImages("ThisIs.png");
   local WeedProgress = "Found " .. WindowCount .. " Flax Beds to tender. \n\n ";
   
       local intDown = 0;
       for intDown= 1, 3 do
               local intAcross = 0;
               for intAcross=1, GridAcross do
                       local windowstate=0;
                       while windowstate < 2 do
                               srReadScreen();
                               
                               local AcrossStart = (intAcross - 1) * WindowAcross;
                               local AcrossEnd = (intAcross * WindowAcross)- 50;
                               local DownStart = (intDown * WindowDown) - 75;
                               local DownEnd = (intDown * WindowDown) + 50;
                               
                               foundwindow = srFindImageInRange("ThisIs.png",AcrossStart,DownStart,AcrossEnd,DownEnd)
                               if foundwindow then
                                       --found window, now find state:
                                       srClickMouse(foundwindow[0],foundwindow[1]);
                                       sleepWithStatus(250, WeedProgress .. "(" .. intAcross .. ", " .. intDown .. ")\nWait Window\n" .. EndMessage);
                                       srReadScreen();
                                       
                                       foundWait = srFindImageInRange("Nothing.png",AcrossStart,DownStart,AcrossEnd,DownEnd)
                                       foundWeed = srFindImageInRange("Weed.png",AcrossStart,DownStart,AcrossEnd,DownEnd)
                                       foundSeeds = srFindImageInRange("HarvestSeeds.png",AcrossStart,DownStart,AcrossEnd,DownEnd)
                                       foundHarvest = srFindImageInRange("HarvestThisFlax.png",AcrossStart,DownStart,AcrossEnd,DownEnd)
                                       if foundWait then
                                               windowstate=1;
                                               sleepWithStatus(500, WeedProgress .. "(" .. intAcross .. ", " .. intDown .. ")\nWait Window\n" .. EndMessage);
                                       end
                                       if foundWeed then
                                               windowstate=2;
                                               srClickMouse(foundWeed[0]+10,foundWeed[1]+5);
                                               sleepWithStatus(500, WeedProgress .. "(" .. intAcross .. ", " .. intDown .. ")\nWeeding\n" .. EndMessage);
                                       end
                                       if foundSeeds then
                                               windowstate=2;
                                               srClickMouse(foundSeeds[0]+10,foundSeeds[1]+5);
                                               sleepWithStatus(500, WeedProgress .. "(" .. intAcross .. ", " .. intDown .. ")\nDeseeding\n" .. EndMessage);
                                       end
                                       if foundHarvest then
                                               windowstate=2;
                                               srClickMouse(foundHarvest[0]+10,foundHarvest[1]+5);  --Harvest
                                               sleepWithStatus(500, WeedProgress .. "(" .. intAcross .. ", " .. intDown .. ")\nHarvesting\n" .. EndMessage);
                                               srClickMouse(foundwindow[0],foundwindow[1],1); --Right click to Close window
                                               sleepWithStatus(500, WeedProgress .. "(" .. intAcross .. ", " .. intDown .. ")\nHarvesting\n" .. EndMessage);
                                       end
                               else
                                       error("Could not find window (" .. intAcross .. ", " .. intDown .. ") therefore aborting program.");
                               end
                       end
               end
       
           local WindowCount = clickAllImages("ThisIs.png");

       end
end

function MainPlanter()
       for i=1, (GridAcross - 1) do
               PlantSeed(i,1);
               Move(VK_LEFT);
       end

       PlantSeed(GridAcross,1);
       Move(VK_UP);

       for i=1, (GridAcross - 1) do
               PlantSeed(i,2);
               Move(VK_RIGHT);
       end

       PlantSeed(GridAcross,2);
       Move(VK_UP);

       for i=1, (GridAcross - 1) do
               PlantSeed(i,3);
               Move(VK_LEFT);
       end

       PlantSeed(GridAcross,3); 
end

function PlantSeed(intAcross, intDown)
 safeClick(mousePos[0], mousePos[1]);
 PinAt((intAcross-1)*WindowAcross,intDown*WindowDown);
end

function Move(MoveDirection)
 sleepWithStatus(DelayBeforePlanting, "Moving." .. EndMessage);
 srKeyDown(MoveDirection);
 sleepWithStatus(DelayMoving, "Moving." .. EndMessage);
 srKeyUp(VK_ALL);
 sleepWithStatus(DelayAfterPlanting, "Moving." .. EndMessage);
end

function PinAt(incX,incY)
 local deviationAcross = 60
 local deviationDown = -60
 
 srClickMouse(xyCenter[0]+deviationAcross, xyCenter[1]-deviationDown,0);
 sleepWithStatus(50, "Pinning Window." .. EndMessage);
 srClickMouse(xyCenter[0]+deviationAcross+5, xyCenter[1]-deviationDown-5,1);
 sleepWithStatus(50, "Pinning Window." .. EndMessage);
 dragWaitSource(xyCenter[0]+deviationAcross, xyCenter[1]-deviationDown,incX,incY)
 sleepWithStatus(50, "Pinning Window." .. EndMessage);
end

function dragWaitSource(x0, y0, x1, y1)
       srMouseDown(x0, y0, 0);
       sleepWithStatus(50, "Dragging Window." .. EndMessage);
       srSetMousePos(x1, y1);
       sleepWithStatus(50, "Dragging Window." .. EndMessage);
       srMouseUp(x1, y1, 0);
       sleepWithStatus(50, "Dragging Window." .. EndMessage);
       srSetMousePos(x0, y0);
end