huangrunheng 2 лет назад
Родитель
Сommit
156c603b97

+ 1 - 1
module/config/config_menu.py

@@ -32,7 +32,7 @@ class ConfigMenu:
         # 每周任务
         self.menu["Weekly Task"] = ['TrueOrochi', 'RichMan', 'Secret', 'WeeklyTrifles', 'MysteryShop', 'Duel']
         # 活动的任务
-        self.menu["Activity Task"] = ['ActivityShikigami', 'MetaDemon']
+        self.menu["Activity Task"] = ['ActivityShikigami', 'MetaDemon', 'FrogBoss']
         # 开发工具
         self.menu["Tools"] = ['Image Rule', 'Ocr Rule', 'Click Rule', 'Long Click Rule', 'Swipe Rule', 'List Rule']
 

+ 2 - 0
module/config/config_model.py

@@ -47,6 +47,7 @@ from tasks.Hunt.config import Hunt
 # 这一部分是活动的配置-----------------------------------------------------------------------------------------------------
 from tasks.ActivityShikigami.config import ActivityShikigami
 from tasks.MetaDemon.config import MetaDemon
+from tasks.FrogBoss.config import FrogBoss
 # ----------------------------------------------------------------------------------------------------------------------
 
 # 肝帝专属---------------------------------------------------------------------------------------------------------------
@@ -99,6 +100,7 @@ class ConfigModel(ConfigBase):
     # 这些是活动的
     activity_shikigami: ActivityShikigami = Field(default_factory=ActivityShikigami)
     meta_demon: MetaDemon = Field(default_factory=MetaDemon)
+    frog_boss: FrogBoss = Field(default_factory=FrogBoss)
 
     # 这些是肝帝专属
     bondling_fairyland: BondlingFairyland = Field(default_factory=BondlingFairyland)

+ 12 - 0
tasks/Component/RightActivity/assets.py

@@ -0,0 +1,12 @@
+from module.atom.image import RuleImage
+from module.atom.click import RuleClick
+from module.atom.long_click import RuleLongClick
+from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
+from module.atom.list import RuleList
+
+# This file was automatically generated by ./dev_tools/assets_extract.py.
+# Don't modify it manually.
+class RightActivityAssets: 
+	pass
+

+ 20 - 0
tasks/Component/RightActivity/right_activity.py

@@ -0,0 +1,20 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+from module.atom.image import RuleImage
+from module.logger import logger
+
+from tasks.base_task import BaseTask
+from tasks.GameUi.game_ui import GameUi
+from tasks.GameUi.page import page_main
+
+
+class RightActivity(GameUi):
+    def enter(self, target: RuleImage):
+        self.ui_get_current_page()
+        self.ui_goto(page_main)
+        self.ui_click_until_disappear(target, interval=3.5)
+
+
+
+

+ 57 - 0
tasks/FrogBoss/assets.py

@@ -0,0 +1,57 @@
+from module.atom.image import RuleImage
+from module.atom.click import RuleClick
+from module.atom.long_click import RuleLongClick
+from module.atom.swipe import RuleSwipe
+from module.atom.ocr import RuleOcr
+from module.atom.list import RuleList
+
+# This file was automatically generated by ./dev_tools/assets_extract.py.
+# Don't modify it manually.
+class FrogBossAssets: 
+
+
+	# Image Rule Assets
+	# 左边竞猜 
+	I_BET_LEFT = RuleImage(roi_front=(88,342,145,100), roi_back=(88,342,145,100), threshold=0.8, method="Template matching", file="./tasks/FrogBoss/fb/fb_bet_left.png")
+	# 右边竞猜 
+	I_BET_RIGHT = RuleImage(roi_front=(1044,344,146,100), roi_back=(1044,344,146,100), threshold=0.8, method="Template matching", file="./tasks/FrogBoss/fb/fb_bet_right.png")
+	# description 
+	I_BET_SUCCESS_BOX = RuleImage(roi_front=(590,439,87,50), roi_back=(590,439,87,50), threshold=0.75, method="Template matching", file="./tasks/FrogBoss/fb/fb_bet_success_box.png")
+	# 左边赢了 
+	I_SUCCESS_LEFT = RuleImage(roi_front=(108,352,100,100), roi_back=(108,352,100,100), threshold=0.8, method="Template matching", file="./tasks/FrogBoss/fb/fb_success_left.png")
+	# 右边输了 
+	I_FAILURE_RIGHT = RuleImage(roi_front=(1067,341,100,100), roi_back=(1067,341,100,100), threshold=0.8, method="Template matching", file="./tasks/FrogBoss/fb/fb_failure_right.png")
+	# description 
+	I_NEXT_COMPETITION = RuleImage(roi_front=(1098,510,42,36), roi_back=(1098,510,42,36), threshold=0.8, method="Template matching", file="./tasks/FrogBoss/fb/fb_next_competition.png")
+	# 30万金币 
+	I_GOLD_30 = RuleImage(roi_front=(824,499,78,76), roi_back=(824,499,78,76), threshold=0.8, method="Template matching", file="./tasks/FrogBoss/fb/fb_gold_30.png")
+	# 确认竞猜 
+	I_BET_SURE = RuleImage(roi_front=(1014,404,100,100), roi_back=(1014,404,100,100), threshold=0.8, method="Template matching", file="./tasks/FrogBoss/fb/fb_bet_sure.png")
+	# description 
+	I_GOLD_30_CHECK = RuleImage(roi_front=(512,180,68,83), roi_back=(402,141,459,489), threshold=0.8, method="Template matching", file="./tasks/FrogBoss/fb/fb_gold_30_check.png")
+	# description 
+	I_BETTED = RuleImage(roi_front=(93,352,125,54), roi_back=(49,322,1192,100), threshold=0.8, method="Template matching", file="./tasks/FrogBoss/fb/fb_betted.png")
+	# description 
+	I_SUCCESS_RIGHT = RuleImage(roi_front=(1061,336,122,116), roi_back=(1061,336,122,116), threshold=0.8, method="Template matching", file="./tasks/FrogBoss/fb/fb_success_right.png")
+	# description 
+	I_FAILURE_LEFT = RuleImage(roi_front=(107,351,100,100), roi_back=(107,351,100,100), threshold=0.8, method="Template matching", file="./tasks/FrogBoss/fb/fb_failure_left.png")
+	# description 
+	I_BET_FAILURE = RuleImage(roi_front=(510,266,269,72), roi_back=(510,266,269,72), threshold=0.8, method="Template matching", file="./tasks/FrogBoss/fb/fb_bet_failure.png")
+	# description 
+	I_BET_SUCCESS = RuleImage(roi_front=(512,264,260,73), roi_back=(433,214,418,151), threshold=0.8, method="Template matching", file="./tasks/FrogBoss/fb/fb_bet_success.png")
+
+
+	# Image Rule Assets
+	# description 
+	I_FROG_BOSS_ENTER = RuleImage(roi_front=(1191,391,36,38), roi_back=(1174,135,78,320), threshold=0.7, method="Template matching", file="./tasks/FrogBoss/fb/fb_frog_boss_enter.png")
+
+
+	# Ocr Rule Assets
+	# Ocr-description 
+	O_LEFT_COUNT = RuleOcr(roi=(144,541,69,31), area=(144,541,69,31), mode="Digit", method="Default", keyword="", name="left_count")
+	# Ocr-description 
+	O_RIGHT_COUNT = RuleOcr(roi=(1110,542,77,32), area=(1110,542,77,32), mode="Digit", method="Default", keyword="", name="right_count")
+	# Ocr-description 
+	O_TIME_REMAIN = RuleOcr(roi=(590,601,91,35), area=(590,601,91,35), mode="Duration", method="Default", keyword="", name="time_remain")
+
+

+ 26 - 0
tasks/FrogBoss/config.py

@@ -0,0 +1,26 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+
+from enum import Enum
+from pydantic import BaseModel, Field
+
+from tasks.Component.config_base import ConfigBase, Time
+from tasks.Component.config_scheduler import Scheduler
+
+
+class Strategy(str, Enum):
+    Majority = 'frog_majority'
+    Minority = 'frog_minority'
+    Bilibili = 'frog_bilibili'
+
+class FrogBossConfig(ConfigBase):
+    before_end_frog: Time = Field(default=Time(0, 15, 0), description='before_end_frog_help')
+    strategy_frog: Strategy = Field(default=Strategy.Majority, description='strategy_frog_help')
+
+class FrogBoss(ConfigBase):
+    scheduler: Scheduler = Field(default_factory=Scheduler)
+    frog_boss_config: FrogBossConfig = Field(default_factory=FrogBossConfig)
+
+
+

BIN
tasks/FrogBoss/fb/fb_bet_failure.png


BIN
tasks/FrogBoss/fb/fb_bet_left.png


BIN
tasks/FrogBoss/fb/fb_bet_right.png


BIN
tasks/FrogBoss/fb/fb_bet_success.png


BIN
tasks/FrogBoss/fb/fb_bet_success_box.png


BIN
tasks/FrogBoss/fb/fb_bet_sure.png


BIN
tasks/FrogBoss/fb/fb_betted.png


BIN
tasks/FrogBoss/fb/fb_failure_left.png


BIN
tasks/FrogBoss/fb/fb_failure_right.png


BIN
tasks/FrogBoss/fb/fb_frog_boss_enter.png


BIN
tasks/FrogBoss/fb/fb_gold_30.png


BIN
tasks/FrogBoss/fb/fb_gold_30_check.png


BIN
tasks/FrogBoss/fb/fb_next_competition.png


BIN
tasks/FrogBoss/fb/fb_success_left.png


BIN
tasks/FrogBoss/fb/fb_success_right.png


+ 128 - 0
tasks/FrogBoss/fb/image.json

@@ -0,0 +1,128 @@
+[
+  {
+    "itemName": "bet_left",
+    "imageName": "fb_bet_left.png",
+    "roiFront": "88,342,145,100",
+    "roiBack": "88,342,145,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "左边竞猜"
+  },
+  {
+    "itemName": "bet_right",
+    "imageName": "fb_bet_right.png",
+    "roiFront": "1044,344,146,100",
+    "roiBack": "1044,344,146,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "右边竞猜"
+  },
+  {
+    "itemName": "bet_success_box",
+    "imageName": "fb_bet_success_box.png",
+    "roiFront": "590,439,87,50",
+    "roiBack": "590,439,87,50",
+    "method": "Template matching",
+    "threshold": 0.75,
+    "description": "description"
+  },
+  {
+    "itemName": "success_left",
+    "imageName": "fb_success_left.png",
+    "roiFront": "108,352,100,100",
+    "roiBack": "108,352,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "左边赢了"
+  },
+  {
+    "itemName": "failure_right",
+    "imageName": "fb_failure_right.png",
+    "roiFront": "1067,341,100,100",
+    "roiBack": "1067,341,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "右边输了"
+  },
+  {
+    "itemName": "next_competition",
+    "imageName": "fb_next_competition.png",
+    "roiFront": "1098,510,42,36",
+    "roiBack": "1098,510,42,36",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "gold_30",
+    "imageName": "fb_gold_30.png",
+    "roiFront": "824,499,78,76",
+    "roiBack": "824,499,78,76",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "30万金币"
+  },
+  {
+    "itemName": "bet_sure",
+    "imageName": "fb_bet_sure.png",
+    "roiFront": "1014,404,100,100",
+    "roiBack": "1014,404,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "确认竞猜"
+  },
+  {
+    "itemName": "gold_30_check",
+    "imageName": "fb_gold_30_check.png",
+    "roiFront": "512,180,68,83",
+    "roiBack": "402,141,459,489",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "betted",
+    "imageName": "fb_betted.png",
+    "roiFront": "93,352,125,54",
+    "roiBack": "49,322,1192,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "success_right",
+    "imageName": "fb_success_right.png",
+    "roiFront": "1061,336,122,116",
+    "roiBack": "1061,336,122,116",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "failure_left",
+    "imageName": "fb_failure_left.png",
+    "roiFront": "107,351,100,100",
+    "roiBack": "107,351,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "bet_failure",
+    "imageName": "fb_bet_failure.png",
+    "roiFront": "510,266,269,72",
+    "roiBack": "510,266,269,72",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "bet_success",
+    "imageName": "fb_bet_success.png",
+    "roiFront": "512,264,260,73",
+    "roiBack": "433,214,418,151",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  }
+]

+ 11 - 0
tasks/FrogBoss/fb/image2.json

@@ -0,0 +1,11 @@
+[
+  {
+    "itemName": "frog_boss_enter",
+    "imageName": "fb_frog_boss_enter.png",
+    "roiFront": "1191,391,36,38",
+    "roiBack": "1174,135,78,320",
+    "method": "Template matching",
+    "threshold": 0.7,
+    "description": "description"
+  }
+]

+ 29 - 0
tasks/FrogBoss/fb/ocr.json

@@ -0,0 +1,29 @@
+[
+  {
+    "itemName": "left_count",
+    "roiFront": "144,541,69,31",
+    "roiBack": "144,541,69,31",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "right_count",
+    "roiFront": "1110,542,77,32",
+    "roiBack": "1110,542,77,32",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "time_remain",
+    "roiFront": "590,601,91,35",
+    "roiBack": "590,601,91,35",
+    "mode": "Duration",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  }
+]

+ 156 - 0
tasks/FrogBoss/script_task.py

@@ -0,0 +1,156 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+from cached_property import cached_property
+from datetime import datetime
+
+from module.exception import TaskEnd
+from module.logger import logger
+from module.atom.image import RuleImage
+from module.base.timer import Timer
+
+from tasks.GameUi.game_ui import GameUi
+from tasks.GameUi.page import page_main
+from tasks.Component.RightActivity.right_activity import RightActivity
+from tasks.Component.config_base import TimeDelta
+from tasks.FrogBoss.assets import FrogBossAssets
+from tasks.FrogBoss.config import Strategy
+
+class ScriptTask(RightActivity, FrogBossAssets):
+    def run(self):
+        self.enter(self.I_FROG_BOSS_ENTER)
+        # 进入主界面
+        while 1:
+            self.screenshot()
+
+            # 已经下注
+            if self.appear(self.I_BETTED):
+                logger.info('You have betted')
+                break
+            # 竞猜成功
+            if self.appear(self.I_BET_SUCCESS):
+                logger.info('You bet win')
+                self.detect()
+                while 1:
+                    self.screenshot()
+                    if self.appear(self.I_BET_LEFT) and self.appear(self.I_BET_RIGHT):
+                        break
+                    if self.appear_then_click(self.I_BET_SUCCESS_BOX, interval=1):
+                        continue
+                    if self.appear_then_click(self.I_NEXT_COMPETITION, interval=4):
+                        continue
+                continue
+            # 竞猜失败
+            if self.appear(self.I_BET_FAILURE):
+                logger.info('You bet lose')
+                self.ui_click_until_disappear(self.I_NEXT_COMPETITION)
+                self.detect()
+                continue
+            # 正式竞猜
+            if self.appear(self.I_BET_LEFT) and self.appear(self.I_BET_RIGHT):
+                self.do_bet()
+                continue
+
+        logger.info('FrogBoss end')
+        self.next_run()
+        raise TaskEnd('FrogBoss')
+
+    def next_run(self):
+        time = self.config.model.frog_boss.frog_boss_config.before_end_frog
+        time_delta = TimeDelta(hours=time.hour, minutes=time.minute, seconds=time.second)
+        time_now = datetime.now()
+        time_set = time_now.replace(minute=0, second=0, microsecond=0)
+        if 10 <= time_now.hour < 12:
+            time_set = time_set.replace(hour=14)
+        elif 12 <= time_now.hour < 14:
+            time_set = time_set.replace(hour=16)
+        elif 14 <= time_now.hour < 16:
+            time_set = time_set.replace(hour=18)
+        elif 16 <= time_now.hour < 18:
+            time_set = time_set.replace(hour=20)
+        elif 18 <= time_now.hour < 20:
+            time_set = time_set.replace(hour=22)
+        elif 20 <= time_now.hour < 22:
+            time_set = time_set.replace(hour=24)
+        elif 22 <= time_now.hour < 24:
+            day = time_now.day + 1
+            time_set = time_set.replace(day=day, hour=10)
+        else:
+            time_set = time_set.replace(hour=10)
+
+        self.set_next_run(task='FrogBoss', target=time_set - time_delta)
+
+    def do_bet(self):
+        logger.hr('do bet', level=2)
+        self.screenshot()
+        count_left = self.O_LEFT_COUNT.ocr(self.device.image)
+        count_right = self.O_RIGHT_COUNT.ocr(self.device.image)
+        match self.config.model.frog_boss.frog_boss_config.strategy_frog:
+            case Strategy.Majority:
+                click_image = self.I_BET_LEFT if count_left > count_right else self.I_BET_RIGHT
+            case Strategy.Minority:
+                click_image = self.I_BET_LEFT if count_left < count_right else self.I_BET_RIGHT
+            case Strategy.Bilibili:
+                click_image = self.I_BET_LEFT if count_left > count_right else self.I_BET_RIGHT
+            case _:
+                raise ValueError(f'Unknown bet mode: {self.config.model.frog_boss.frog_boss_config.strategy_frog}')
+        logger.info(f'You strategy is {self.config.model.frog_boss.frog_boss_config.strategy_frog} and bet on {click_image}')
+        self.ui_click_until_disappear(click_image)
+        gold_30_timer = Timer(10)
+        gold_30_timer.start()
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_GOLD_30_CHECK):
+                break
+            if gold_30_timer.reached():
+                logger.info('Gold 30 not appear')
+                break
+            if self.appear_then_click(self.I_GOLD_30, interval=3):
+                continue
+        # 正式下注
+        logger.info('Formal bet')
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_BETTED):
+                break
+            if self.appear_then_click(self.I_GOLD_30, interval=2):
+                continue
+            if self.appear_then_click(self.I_BET_SURE, interval=2):
+                continue
+            if self.appear_then_click(self.I_UI_CONFIRM, interval=2):
+                continue
+            if self.appear_then_click(self.I_UI_CONFIRM_SAMLL, interval=2):
+                continue
+
+    def detect(self) -> bool:
+        """
+        检测是左边赢了还是右边赢的
+        :return: True 左边赢了
+        """
+        if self.appear(self.I_SUCCESS_LEFT) and self.appear(self.I_FAILURE_RIGHT):
+            result = True
+            logger.info('Left win')
+        elif self.appear(self.I_SUCCESS_RIGHT) and self.appear(self.I_FAILURE_LEFT):
+            result = False
+            logger.info('Right win')
+        else:
+            result = True
+        return result
+
+    def get_bilibili(self) -> RuleImage:
+        """
+        获取博主的策略选择
+        :return:
+        """
+        pass
+
+
+if __name__ == '__main__':
+    from module.config.config import Config
+    from module.device.device import Device
+    c = Config('oas1')
+    d = Device(c)
+    t = ScriptTask(c, d)
+
+    t.run()
+