daily pastebin goal
43%
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from manager import *
  2. from core import Helpers, ImageMatch, ScreenImage, Point2D
  3. import settings, time, random
  4. from manager import ActionInstance
  5.  
  6. eventMgr = ActionManager('_Event')
  7. behaviourMgr = BehaviourManager()
  8. screen = ScreenImage(region=([0, 0], [1924, 968]))
  9.  
  10. def Action_ResupplyCorn(instance):
  11.  
  12.     # Refresh screen image buffer
  13.     screen.refresh()
  14.  
  15.     # Drag chopped corn to container (Fix a random result position a bit)
  16.     Helpers.loopUntilSuccess(lambda:
  17.         behaviourMgr.mouseDrag(
  18.             ImageMatch(screen.image, 'inventory/stackedchoppedcorn_item.png', tolerance=95, offset=Point2D(30, 0)),
  19.             ImageMatch(screen.image, 'storage/choppedcorn_item.png', tolerance=95)
  20.         ),
  21.         delay = settings.DELAY_BEETWEN_OPERATION
  22.     )
  23.  
  24.     # Refresh screen image buffer & sleep before next operation
  25.     Helpers.randomSleep(*settings.DELAY_BEETWEN_OPERATION)
  26.     screen.refresh()
  27.  
  28.     # Drag corn from container to inventory
  29.     Helpers.loopUntilSuccess(lambda:
  30.         behaviourMgr.dragItemFromStorageContainer(
  31.             ImageMatch(screen.image, 'storage/corn_item.png', tolerance=95),
  32.             ImageMatch(screen.image, 'inventory/inventory_group.png', tolerance=90),
  33.             amount = 80
  34.         ),
  35.         delay = settings.DELAY_BEETWEN_OPERATION
  36.     )
  37.  
  38.     # Refresh screen image buffer & sleep before next operation
  39.     Helpers.randomSleep(*settings.DELAY_BEETWEN_OPERATION)
  40.     screen.refresh()
  41.  
  42.     # Drag corn from inventory to empty slot in crafting window
  43.     Helpers.loopUntilSuccess(lambda:
  44.         behaviourMgr.craftingWindowDragToEmptySlot(
  45.             screen.image,
  46.             ImageMatch(screen.image, 'inventory/stackedcorn_item.png', offset=Point2D(30, 0))
  47.         ),
  48.         delay = settings.DELAY_BEETWEN_OPERATION
  49.     )
  50.  
  51.  
  52. def Action_OnCreate_ChoppedCorn(instance):
  53.  
  54.     # Refresh screen image buffer
  55.     screen.refresh()
  56.  
  57.     # Calculate action duration (-+ thread sleep duraction)
  58.     actionTime = time.time() - float(instance.get('actionTimer') or 0)
  59.  
  60.     # If there is no corn on crafting window left
  61.     if not ImageMatch(screen.image, 'craftingwindow/corn_icon.png').isValid():
  62.  
  63.         # Try to resupply corn until success
  64.         Action_ResupplyCorn(instance)
  65.  
  66.     # Hold on for a sec when timer will be too long
  67.     print(actionTime)
  68.     if actionTime >= 2.3:
  69.         Helpers.randomSleep(4200, 7000)
  70.     else:
  71.         Helpers.randomSleep(100, 700)
  72.  
  73.     behaviourMgr.craftingWindowCreate(screen.image)
  74.  
  75.  
  76. def Action_OnQueue_ChoppedCorn(instance):
  77.     instance.set('actionTimer', time.time())
  78.  
  79.  
  80. def main():
  81.     sharedInstance = ActionInstance()
  82.     eventMgr.addEvent(Action_OnCreate_ChoppedCorn, 'You create a raw\+chopped corn.', onlyOnce=False, instance=sharedInstance)
  83.     eventMgr.addEvent(Action_OnQueue_ChoppedCorn, 'You start to work with the knife on the corn.',  onlyOnce=True, instance=sharedInstance)
  84.  
  85.     try:
  86.         eventMgr.start(attached=True, interval=[10, 50])
  87.     except KeyboardInterrupt:
  88.         eventMgr.stop()
  89.  
  90. if __name__ == '__main__':
  91.     main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top