Advertisement
Guest User

AnkuLua script

a guest
Oct 18th, 2019
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.88 KB | None | 0 0
  1. -- ========== Settings ================
  2. Settings:setCompareDimension(true, 960)
  3. Settings:setScriptDimension(true, 960)
  4. Settings:set("MinSimilarity", 0.75)
  5. counters = {
  6.     buy = 0,
  7.     fail = 0,
  8.     success = 0
  9. }
  10. regions = {
  11.     defeatedReady = Region(241, 172, 223, 77),
  12.     drop = Region(574, 43, 153, 153),
  13.     dropAd = Region(485, 358, 224, 78),
  14.     energy = Region(137, 143, 141, 137),
  15.     energyBuy = Region(390, 392, 178, 68),
  16.     energyClose = Region(820, 44, 100, 92),
  17.     energyConfirm = Region(402, 352, 158, 68),
  18.     label = Region(340, 173, 292, 93),
  19.     replay = Region(245, 269, 231, 84),
  20.     resurrect = Region(484, 262, 232, 95),
  21.     start = Region(772, 412, 188, 128)
  22. }
  23. logFileName = scriptPath() .. "log.txt"
  24. log = io.open(logFileName, "a+")
  25. -- ==========  main program ===========
  26.  
  27. function updateStopMessage()
  28.     setStopMessage("success: " .. counters["success"] .. ", fails: " .. counters["fail"] .. ", buys: " .. counters["buy"])
  29. end
  30.  
  31. function waitAndClick(region, image, delay)
  32.     region:waitClick(image, delay)
  33. end
  34.  
  35. function buyEnergy()
  36.     waitAndClick(regions["energy"], "energyPiece.png", 2)
  37.     waitAndClick(regions["energyBuy"], "energyBuy.png", 2)
  38.     waitAndClick(regions["energyConfirm"], "energyConfirm.png", 3)
  39.     waitAndClick(regions["energyClose"], "close.png", 20)
  40.     counters["buy"] = counters["buy"] + 1
  41.     log:write("energy purchase. Total is " .. counters["buy"] .. "\n")
  42.     updateStopMessage()
  43. end
  44.  
  45. math.randomseed(os.time())
  46. while (true) do
  47.     waitAndClick(regions["start"], "startButton.png", 3)
  48.     battleWait = 120
  49.     toast('start')
  50.     while (true) do
  51.         wait(battleWait)
  52.         snapshot()
  53.         local victoryRes = regions["label"]:exists("victoryLabel.png", 2)
  54.         local failRes = regions["resurrect"]:exists("resurrectNo.png", 2)
  55.         delay = math.random(5, 20)
  56.         if (victoryRes) then
  57.             toast('success, click after ' .. delay)
  58.             counters["success"] = counters["success"] + 1
  59.             log:write("success. Total success is " .. counters["success"] .. "\n")
  60.             updateStopMessage()
  61.             wait(delay)
  62.             waitAndClick(regions["label"], "victoryLabel.png", 5)
  63.             waitAndClick(regions["drop"], "close.png", 15)
  64.             local adExists = regions["dropAd"]:exists("dropAdNo.png", 6)
  65.             if (adExists) then
  66.                 waitAndClick(regions["dropAd"], "dropAdNo.png", 2)
  67.             end
  68.             waitAndClick(regions["replay"], "victoryReplay.png", 5)
  69.             local energyRes = regions["energy"]:exists("energyPiece.png", 5)
  70.             if (energyRes) then
  71.                 buyEnergy()
  72.                 waitAndClick(regions["replay"], "victoryReplay.png", 5)
  73.             end
  74.             battleWait = 120
  75.         elseif (failRes) then
  76.             toast('fail, click after ' .. delay)
  77.             counters["fail"] = counters["fail"] + 1
  78.             log:write("fail. Total fail is " .. counters["fail"] .. "\n")
  79.             updateStopMessage()
  80.             wait(delay)
  81.             waitAndClick(regions["resurrect"], "resurrectNo.png", 5)
  82.             wait(3)
  83.             local wasFreeRes = regions["resurrect"]:exists("resurrectNo.png", 6)
  84.             if (wasFreeRes) then
  85.                 waitAndClick(regions["resurrect"], "resurrectNo.png", 2)
  86.             end
  87.             waitAndClick(regions["label"], "defeatedLabel.png", 5)
  88.             waitAndClick(regions["defeatedReady"], "defeatedReady.png", 5)
  89.             waitAndClick(regions["start"], "startButton.png", 5)
  90.             local energyRes = regions["energy"]:exists("energyPiece.png", 5)
  91.             if (energyRes) then
  92.                 buyEnergy()
  93.                 waitAndClick(regions["start"], "startButton.png", 5)
  94.             end
  95.             battleWait = 120
  96.         else
  97.             toast('not ready yet, wait 30s')
  98.             battleWait = 30
  99.         end
  100.     end
  101. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement