feat: add planet mine collection automation
This commit is contained in:
1 parent
a976b844cd
commit
b0a88b9979
14 files changed
+49
No files matched your search
@@ -0,0 +1,35 @@
|
||||
"""玩法大厅星球矿场:排行榜奖励与扫荡上一层。"""
|
||||
import time
|
||||
from .engine import WorkflowError
|
||||
class PlanetMineRunner:
|
||||
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 dot(self,frame,spec):return self.matcher.score(frame,self.flow[spec])>=self.flow[spec].get('threshold',.86)
|
||||
def return_home(self,planet):
|
||||
self.action('planet_back',planet);self.action('hall_close',self.wait('hall'));self.action('territory_back',self.wait('territory'));self.wait('home');self.log('已确认返回首页。')
|
||||
def run(self,dry_run=False):
|
||||
home=self.wait('home')
|
||||
if dry_run:self.log('首页识别通过。计划:领地 → 玩法大厅 → 星球矿场 → 排行榜奖励与扫荡 → 返回首页。未点击。');return 'preview'
|
||||
self.action('territory',home);self.action('hall',self.wait('territory'));self.action('planet',self.wait('hall'));planet=self.wait('planet')
|
||||
if self.dot(planet[3],'rank_dot'):
|
||||
self.action('rank',planet);rank=self.wait('rank');self.action('progress',rank);dialog=self.wait('progress_dialog')
|
||||
spec=self.flow['progress_claim'];score,loc=self.matcher.locate(dialog[3],spec)
|
||||
if score>=spec.get('threshold',.86):
|
||||
x,y,w,h=loc;self.action('progress_claim',('x',dialog[1],dialog[2],dialog[3])) if False else self.desktop.click(((x+w/2)/562,(y+h/2)/1002),dialog[2],dialog[1].size,hold=.8)
|
||||
reward=self.wait('reward');self.action('dismiss_reward',reward)
|
||||
self.action('progress_close',self.wait('progress_dialog'));self.action('rank_back',self.wait('rank'));planet=self.wait('planet')
|
||||
count=0
|
||||
while count<2 and self.matcher.matches(planet[3],self.flow['states']['sweep_available']):
|
||||
self.action('sweep',planet);dialog=self.wait('sweep_dialog');self.action('sweep_up',dialog);reward=self.wait('reward');self.action('dismiss_reward',reward);planet=self.wait('planet');count+=1;self.log('已完成第 %s 次扫荡。'%count)
|
||||
self.return_home(planet);return 'claimed'
|
||||
Reference in new issue
Block a user