feat: add guild help automation
This commit is contained in:
1 parent
afccc2a79a
commit
56e79dcd26
6 files changed
+55
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 8.4 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
@@ -0,0 +1,40 @@
|
||||
"""底部公会按钮上方的互助领取流程。"""
|
||||
import time
|
||||
from .engine import WorkflowError
|
||||
|
||||
|
||||
class GuildHelpRunner:
|
||||
def __init__(self, desktop, matcher, flow, region_provider, log=print, timeout=12):
|
||||
self.desktop, self.matcher, self.flow = desktop, matcher, flow
|
||||
self.region_provider, self.log, self.timeout = region_provider, log, timeout
|
||||
|
||||
def observe(self):
|
||||
shot = self.desktop.screenshot(); region = self.region_provider(shot)
|
||||
return shot, region, self.matcher.frame(shot, region)
|
||||
|
||||
def wait_reward(self):
|
||||
deadline = time.monotonic() + self.timeout; stable = 0
|
||||
while time.monotonic() < deadline:
|
||||
shot, region, frame = self.observe()
|
||||
if self.matcher.matches(frame, self.flow['reward']):
|
||||
stable += 1
|
||||
if stable >= 2: return shot, region
|
||||
else: stable = 0
|
||||
time.sleep(.25)
|
||||
raise WorkflowError('互助后未识别到奖励弹框,已停止。')
|
||||
|
||||
def run(self, dry_run=False):
|
||||
shot, region, frame = self.observe()
|
||||
spec = self.flow['help_button']; score, location = self.matcher.locate(frame, spec)
|
||||
if score < spec.get('threshold', .86):
|
||||
self.log('当前一级页面没有互助握手入口,本次跳过。'); return 'no_help'
|
||||
x, y, width, height = location
|
||||
point = ((x + width / 2) / 562, (y + height / 2) / 1002)
|
||||
if dry_run:
|
||||
self.log('已识别互助握手入口,计划点击并关闭奖励弹框。未点击。'); return 'preview'
|
||||
if self.region_provider(shot) != region: raise WorkflowError('识别后游戏窗口移动,已停止,请重新运行。')
|
||||
self.desktop.click(point, region, shot.size, hold=.8); self.log('已执行:互助。')
|
||||
reward_shot, reward_region = self.wait_reward()
|
||||
if self.region_provider(reward_shot) != reward_region: raise WorkflowError('识别后游戏窗口移动,已停止,请重新运行。')
|
||||
self.desktop.click(self.flow['clicks']['dismiss_reward'], reward_region, reward_shot.size, hold=.8)
|
||||
self.log('已确认互助奖励并关闭弹框。'); return 'claimed'
|
||||
@@ -0,0 +1,14 @@
|
||||
import argparse, sys, time
|
||||
from pathlib import Path
|
||||
from automation.engine import Matcher, load_flow
|
||||
from automation.guild_help import GuildHelpRunner
|
||||
from automation.offers import MacGameDesktop
|
||||
ROOT=Path(__file__).resolve().parent
|
||||
def main():
|
||||
p=argparse.ArgumentParser(description='领取底部公会入口上方的互助奖励'); p.add_argument('--dry-run',action='store_true'); a=p.parse_args()
|
||||
if sys.platform!='darwin': return 2
|
||||
try:
|
||||
d=MacGameDesktop(); d.activate(); print('3 秒后开始;请保持游戏在前台。',flush=True); time.sleep(3)
|
||||
GuildHelpRunner(d,Matcher(ROOT/'assets'),load_flow(ROOT/'workflows/guild_help.json'),d.region_for).run(a.dry_run); return 0
|
||||
except Exception as e: print('流程停止:'+str(e),file=sys.stderr); return 1
|
||||
if __name__=='__main__': raise SystemExit(main())
|
||||
@@ -0,0 +1 @@
|
||||
{"name":"公会互助","help_button":{"template":"guild_help_button.png","search":[455,835,562,950]},"reward":[{"template":"guild_help_reward.png","search":[120,180,440,390],"threshold":0.8},{"template":"guild_help_dismiss.png","search":[145,600,420,730]}],"clicks":{"dismiss_reward":[0.50,0.67]}}
|
||||
Reference in new issue
Block a user