feat: add guild donation automation
This commit is contained in:
1 parent
0f9beb0055
commit
f963a3c639
8 files changed
+39
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 9.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
@@ -0,0 +1,24 @@
|
||||
"""公会每日免费捐献流程。"""
|
||||
import time
|
||||
from .engine import WorkflowError
|
||||
class GuildDonationRunner:
|
||||
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 wait(self,*names):
|
||||
end=time.monotonic()+self.timeout;prev=None;stable=0
|
||||
while time.monotonic()<end:
|
||||
shot=self.desktop.screenshot();region=self.region_provider(shot);frame=self.matcher.frame(shot,region);found=next((n for n in names if self.matcher.matches(frame,self.flow['states'][n])),None)
|
||||
stable=stable+1 if found and found==prev else (1 if found else 0);prev=found
|
||||
if stable>=2:return found,shot,region,frame
|
||||
time.sleep(.25)
|
||||
raise WorkflowError('未识别到预期页面 '+ '/'.join(names)+',已停止。')
|
||||
def action(self,name,obs):
|
||||
_,shot,region,_=obs
|
||||
if self.region_provider(shot)!=region:raise WorkflowError('识别后游戏窗口移动,已停止,请重新运行。')
|
||||
self.desktop.click(self.flow['clicks'][name],region,shot.size,hold=.8);self.log('已执行:'+name)
|
||||
def home(self,dialog):self.action('close_dialog',dialog);self.action('guild_back',self.wait('guild'));self.wait('home');self.log('已确认返回首页。')
|
||||
def run(self,dry_run=False):
|
||||
home=self.wait('home')
|
||||
if dry_run:self.log('首页识别通过。计划:公会 → 每日捐献 → 免费 → 返回首页。未点击。');return 'preview'
|
||||
self.action('guild',home);self.action('donation',self.wait('guild'));dialog=self.wait('free','claimed')
|
||||
if dialog[0]=='claimed':self.log('免费捐献已使用,本次跳过。');self.home(dialog);return 'already_claimed'
|
||||
self.action('free',dialog);reward=self.wait('reward');self.action('dismiss_reward',reward);self.home(self.wait('claimed'));return 'claimed'
|
||||
@@ -0,0 +1,14 @@
|
||||
import argparse,sys,time
|
||||
from pathlib import Path
|
||||
from automation.engine import Matcher,load_flow
|
||||
from automation.guild_donation import GuildDonationRunner
|
||||
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)
|
||||
GuildDonationRunner(d,Matcher(ROOT/'assets'),load_flow(ROOT/'workflows/guild_donation.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":"公会每日免费捐献","states":{"home":[{"template":"home.png","search":[150,730,410,865]}],"guild":[{"template":"guild_page_title.png","search":[120,110,350,200]}],"free":[{"template":"donation_title.png","search":[150,230,410,350]},{"template":"donation_free.png","search":[45,670,280,810]}],"claimed":[{"template":"donation_title.png","search":[150,230,410,350]},{"template":"donation_claimed.png","search":[45,670,280,810]}],"reward":[{"template":"donation_reward.png","search":[120,180,440,390],"threshold":0.8},{"template":"donation_dismiss.png","search":[145,600,420,730]}]},"clicks":{"guild":[0.90,0.94],"donation":[0.84,0.43],"free":[0.29,0.73],"dismiss_reward":[0.50,0.67],"close_dialog":[0.88,0.285],"guild_back":[0.90,0.94]}}
|
||||
Reference in new issue
Block a user