feat: add arena points claim automation
This commit is contained in:
1 parent
576515d2cf
commit
7def63b3b9
10 files changed
+206
-4
No files matched your search
@@ -0,0 +1,53 @@
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from PIL import Image
|
||||
|
||||
from automation.arena import ArenaRunner
|
||||
from automation.engine import Matcher, Region, load_flow
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
class ArenaDesktop:
|
||||
def __init__(self, images):
|
||||
self.images = images
|
||||
self.index = 0
|
||||
self.clicks = []
|
||||
|
||||
def screenshot(self):
|
||||
return self.images[min(self.index, len(self.images) - 1)]
|
||||
|
||||
def click(self, point, region, size, hold=0.2):
|
||||
self.clicks.append((point, hold))
|
||||
self.index += 1
|
||||
|
||||
|
||||
class ArenaTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.flow = load_flow(ROOT / 'workflows/arena_points.json')
|
||||
self.matcher = Matcher(ROOT / 'assets')
|
||||
self.region = Region(0, 0, 562, 1002)
|
||||
|
||||
def image(self, state):
|
||||
image = Image.new('RGB', (562, 1002), (62, 52, 35))
|
||||
for spec in self.flow['states'][state]:
|
||||
template = Image.open(ROOT / 'assets' / spec['template']).convert('RGB')
|
||||
x, y, _, _ = spec['search']
|
||||
image.paste(template, (x + 5, y + 5))
|
||||
return image
|
||||
|
||||
def runner(self, states):
|
||||
desktop = ArenaDesktop([self.image(state) for state in states])
|
||||
return desktop, ArenaRunner(desktop, self.matcher, self.flow,
|
||||
lambda _: self.region, log=lambda _: None, timeout=0.8)
|
||||
|
||||
def test_claims_points_and_returns_home(self):
|
||||
desktop, runner = self.runner(['home', 'territory', 'selection', 'arena_page', 'reward', 'arena_page', 'territory', 'home'])
|
||||
self.assertEqual(runner.run(), 'claimed')
|
||||
expected = ('territory', 'peak_duel', 'arena', 'claim_points',
|
||||
'dismiss_reward', 'arena_back', 'territory_back')
|
||||
self.assertEqual([point for point, _ in desktop.clicks], [self.flow['clicks'][name] for name in expected])
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user