feat: add guild donation automation
This commit is contained in:
1 parent
0f9beb0055
commit
f963a3c639
8 files changed
+39
No files matched your search
@@ -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'
|
||||
Reference in new issue
Block a user