feat: add guild bargain automation
This commit is contained in:
1 parent
b44bb70b26
commit
4189353d61
8 files changed
+38
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 57 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 7.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 41 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
@@ -0,0 +1,23 @@
|
|||||||
|
"""公会右下红珍珠祭坛砍价流程。"""
|
||||||
|
import time
|
||||||
|
from .engine import WorkflowError
|
||||||
|
class GuildBargainRunner:
|
||||||
|
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 run(self,dry_run=False):
|
||||||
|
home=self.wait('home')
|
||||||
|
if dry_run:self.log('首页识别通过。计划:公会 → 红珍珠祭坛 → 砍价 → 返回首页。未点击。');return 'preview'
|
||||||
|
self.action('guild',home);guild=self.wait('guild');self.action('altar',guild);page=self.wait('bargain')
|
||||||
|
self.action('bargain',page);reward=self.wait('reward');self.action('dismiss_reward',reward)
|
||||||
|
self.action('altar_back',self.wait('bargain'));self.action('guild_back',self.wait('guild'));self.wait('home');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_bargain import GuildBargainRunner
|
||||||
|
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)
|
||||||
|
GuildBargainRunner(d,Matcher(ROOT/'assets'),load_flow(ROOT/'workflows/guild_bargain.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]}],"bargain":[{"template":"bargain_button.png","search":[160,480,410,640]}],"reward":[{"template":"bargain_reward.png","search":[120,180,440,390],"threshold":0.8},{"template":"bargain_dismiss.png","search":[145,600,420,730]}]},"clicks":{"guild":[0.90,0.94],"altar":[0.84,0.72],"bargain":[0.50,0.55],"dismiss_reward":[0.50,0.67],"altar_back":[0.12,0.94],"guild_back":[0.90,0.94]}}
|
||||||
Reference in new issue
Block a user