Просмотр исходного кода

feat(rich man): add thousand things store

runhey 3 лет назад
Родитель
Сommit
9fe35ea381

+ 4 - 0
tasks/GameUi/assets.py

@@ -159,6 +159,10 @@ class GameUiAssets:
 	I_CHECK_SUMMON = RuleImage(roi_front=(581,594,68,66), roi_back=(316,528,594,174), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_summon.png")
 	# 就是一个红叉 
 	I_REALM_RAID_GOTO_EXPLORATION = RuleImage(roi_front=(1192,107,36,43), roi_back=(1192,107,36,43), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_realm_raid_goto_exploration.png")
+	# description 
+	I_MAIN_GOTO_TRAVEL = RuleImage(roi_front=(202,619,64,61), roi_back=(202,619,64,61), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_main_goto_travel.png")
+	# 珍旅居 
+	I_CHECK_TRAVEL = RuleImage(roi_front=(1134,583,78,77), roi_back=(1134,583,78,77), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_travel.png")
 
 
 	# Image Rule Assets

+ 4 - 1
tasks/GameUi/page.py

@@ -151,7 +151,10 @@ page_main.link(button=G.I_MAIN_GOTO_TEAM, destination=page_team)
 page_collection = Page(G.I_CHECK_COLLECTION)
 page_collection.link(button=G.I_BACK_Y, destination=page_main)
 page_main.link(button=G.I_MAIN_GOTO_COLLECTION, destination=page_collection)
-
+# 珍旅居
+page_travel = Page(G.I_CHECK_TRAVEL)
+page_travel.link(button=G.I_BACK_Y, destination=page_main)
+page_main.link(button=G.I_MAIN_GOTO_TRAVEL, destination=page_travel)
 
 
 

BIN
tasks/GameUi/page/page_check_travel.png


+ 18 - 0
tasks/GameUi/page/page_img_supplement.json

@@ -34,5 +34,23 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "就是一个红叉"
+  },
+  {
+    "itemName": "main_goto_travel",
+    "imageName": "page_main_goto_travel.png",
+    "roiFront": "202,619,64,61",
+    "roiBack": "202,619,64,61",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "check_travel",
+    "imageName": "page_check_travel.png",
+    "roiFront": "1134,583,78,77",
+    "roiBack": "1134,583,78,77",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "珍旅居"
   }
 ]

BIN
tasks/GameUi/page/page_main_goto_travel.png


+ 44 - 0
tasks/RichMan/assets.py

@@ -0,0 +1,44 @@
+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 RichManAssets: 
+
+
+	# Image Rule Assets
+	# 千物宝库 
+	I_TT_ENTER = RuleImage(roi_front=(1140,585,73,76), roi_back=(1140,585,73,76), threshold=0.8, method="Template matching", file="./tasks/RichMan/tt/tt_tt_enter.png")
+	# 确认进入 
+	I_TT_CHECK = RuleImage(roi_front=(141,61,228,67), roi_back=(141,61,228,67), threshold=0.8, method="Template matching", file="./tasks/RichMan/tt/tt_tt_check.png")
+	# description 
+	I_TT_BLACK = RuleImage(roi_front=(710,176,91,90), roi_back=(453,171,589,109), threshold=0.8, method="Template matching", file="./tasks/RichMan/tt/tt_tt_black.png")
+	# description 
+	I_TT_TICKET_BULE = RuleImage(roi_front=(484,176,85,91), roi_back=(475,170,562,110), threshold=0.8, method="Template matching", file="./tasks/RichMan/tt/tt_tt_ticket_bule.png")
+	# description 
+	I_TT_AP = RuleImage(roi_front=(938,177,88,87), roi_back=(467,167,581,123), threshold=0.8, method="Template matching", file="./tasks/RichMan/tt/tt_tt_ap.png")
+	# 提高 
+	I_TT_BUY_UP = RuleImage(roi_front=(761,411,59,57), roi_back=(761,411,59,57), threshold=0.8, method="Template matching", file="./tasks/RichMan/tt/tt_tt_buy_up.png")
+	# description 
+	I_TT_BUY_CONFIRM = RuleImage(roi_front=(584,512,53,53), roi_back=(553,508,169,60), threshold=0.8, method="Template matching", file="./tasks/RichMan/tt/tt_tt_buy_confirm.png")
+
+
+	# Ocr Rule Assets
+	# Ocr-description 
+	O_TT_TOTOL = RuleOcr(roi=(1121,10,116,35), area=(1121,10,116,35), mode="Digit", method="Default", keyword="", name="tt_totol")
+	# Ocr-description 
+	O_TT_BLUE_TICKET = RuleOcr(roi=(509,307,531,92), area=(509,307,531,92), mode="Full", method="Default", keyword="2000", name="tt_blue_ticket")
+	# Ocr-description 
+	O_TT_BLACK = RuleOcr(roi=(498,313,528,89), area=(498,313,528,89), mode="Full", method="Default", keyword="350", name="tt_black")
+	# Ocr-description 
+	O_TT_AP = RuleOcr(roi=(502,311,535,91), area=(502,311,535,91), mode="Full", method="Default", keyword="300", name="tt_ap")
+	# Ocr-description 
+	O_TT_BUY = RuleOcr(roi=(602,509,104,61), area=(602,509,104,61), mode="Full", method="Default", keyword="", name="tt_buy")
+	# Ocr-description 
+	O_TT_NUMBER = RuleOcr(roi=(576,415,58,49), area=(576,415,58,49), mode="Digit", method="Default", keyword="", name="tt_number")
+
+

+ 39 - 0
tasks/RichMan/script_task.py

@@ -0,0 +1,39 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+from time import sleep
+from datetime import time, datetime, timedelta
+
+from module.logger import logger
+from module.exception import TaskEnd
+
+from tasks.base_task import BaseTask
+from tasks.RichMan.assets import RichManAssets
+
+
+class ScriptTask(BaseTask):
+
+    def run(self):
+        pass
+
+
+
+
+
+
+
+
+
+
+
+
+
+if __name__ == '__main__':
+    from module.config.config import Config
+    from module.device.device import Device
+    from memory_profiler import profile
+    c = Config('oas1')
+    d = Device(c)
+    t = ScriptTask(c, d)
+
+

+ 143 - 0
tasks/RichMan/thousand_things.py

@@ -0,0 +1,143 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+import time
+
+from module.logger import logger
+
+from tasks.GameUi.page import page_main, page_travel
+from tasks.GameUi.game_ui import GameUi
+from tasks.RichMan.assets import RichManAssets
+from tasks.RichMan.config import ThousandThings as ConfigThousandThings
+
+class ThousandThings(GameUi, RichManAssets):
+
+    def execute_tt(self, con: ConfigThousandThings) -> None:
+        """
+
+        :param con:
+        :return:
+        """
+        logger.hr('Start Thousand Things')
+        if not con.enable:
+            logger.info('Thousand Things is disabled')
+            return
+        self.ui_get_current_page()
+        self.ui_goto(page_travel)
+
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_TT_CHECK):
+                break
+            if self.appear_then_click(self.I_TT_ENTER, interval=1):
+                continue
+        logger.info('Enter Thousand Things')
+        self.screenshot()
+        if not self.appear(self.I_TT_TICKET_BULE) and not self.appear(self.I_TT_BLACK) and not self.appear(self.I_TT_AP):
+            time.sleep(1)
+        if con.mystery_amulet:
+            self.tt_buy_mystery_amulet()
+        if con.black_daruma_fragment:
+            self.tt_buy_black_daruma_scrap()
+        if con.ap:
+            self.tt_buy_ap()
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_TT_ENTER):
+                break
+            if self.appear_then_click(self.I_UI_BACK_RED, interval=1):
+                continue
+        logger.info('Exit Thousand Things')
+
+
+    def tt_buy_mystery_amulet(self) -> bool:
+        """
+
+        :return: 成功购买返回True,找不到或者是钱不够返回False
+        """
+        self.screenshot()
+        if not self.appear(self.I_TT_TICKET_BULE):
+            logger.info('No mystery amulet')
+            return False
+        if not self.tt_check_memory(2000):
+            return False
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_TT_BUY_UP):
+                break
+            if self.ocr_appear_click(self.O_TT_BLUE_TICKET, interval=1):
+                continue
+        logger.info('Buy mystery amulet')
+        self.ui_get_reward(self.I_TT_BUY_CONFIRM)
+        logger.info('Buy mystery amulet success')
+        time.sleep(0.5)
+        return True
+
+
+    def tt_buy_black_daruma_scrap(self):
+        self.screenshot()
+        if not self.appear(self.I_TT_BLACK):
+            logger.info('No black daruma scrap')
+            return False
+        if not self.tt_check_memory(350):
+            return False
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_TT_BUY_UP):
+                break
+            if self.ocr_appear_click(self.O_TT_BLACK, interval=1):
+                continue
+        logger.info('Buy black daruma scrap')
+        self.ui_get_reward(self.I_TT_BUY_CONFIRM)
+        logger.info('Buy black daruma scrap success')
+        time.sleep(0.5)
+        return True
+
+    def tt_buy_ap(self):
+        self.screenshot()
+        if not self.appear(self.I_TT_AP):
+            logger.info('No ap')
+            return False
+        if not self.tt_check_memory(600):
+            return False
+        self.O_TT_NUMBER.keyword = '2'
+        while 1:
+            self.screenshot()
+            if self.ocr_appear(self.O_TT_NUMBER):
+                break
+            if self.appear_then_click(self.I_TT_BUY_UP, interval=0.5):
+                continue
+            if self.ocr_appear_click(self.O_TT_AP, interval=1):
+                continue
+        logger.info('Buy ap')
+        self.ui_get_reward(self.I_TT_BUY_CONFIRM)
+        logger.info('Buy ap success')
+        time.sleep(0.5)
+        return True
+
+    def tt_check_memory(self, mix: int) -> bool:
+        self.screenshot()
+        current = self.O_TT_TOTOL.ocr(self.device.image)
+        if not isinstance(current, int):
+            logger.warning('OCR current memory failed')
+            return False
+        if current >= mix:
+            logger.info('Memory is enough')
+            return True
+        logger.info('Memory is not enough')
+        return False
+
+
+if __name__ == '__main__':
+    from module.config.config import Config
+    from module.device.device import Device
+    from memory_profiler import profile
+    c = Config('oas1')
+    d = Device(c)
+    t = ThousandThings(c, d)
+
+    t.execute_tt(t.config.rich_man.thousand_things)
+
+
+
+

+ 65 - 0
tasks/RichMan/tt/image.json

@@ -0,0 +1,65 @@
+[
+  {
+    "itemName": "tt_enter",
+    "imageName": "tt_tt_enter.png",
+    "roiFront": "1140,585,73,76",
+    "roiBack": "1140,585,73,76",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "千物宝库"
+  },
+  {
+    "itemName": "tt_check",
+    "imageName": "tt_tt_check.png",
+    "roiFront": "141,61,228,67",
+    "roiBack": "141,61,228,67",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "确认进入"
+  },
+  {
+    "itemName": "tt_black",
+    "imageName": "tt_tt_black.png",
+    "roiFront": "710,176,91,90",
+    "roiBack": "453,171,589,109",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "tt_ticket_bule",
+    "imageName": "tt_tt_ticket_bule.png",
+    "roiFront": "484,176,85,91",
+    "roiBack": "475,170,562,110",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "tt_ap",
+    "imageName": "tt_tt_ap.png",
+    "roiFront": "938,177,88,87",
+    "roiBack": "467,167,581,123",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "tt_buy_up",
+    "imageName": "tt_tt_buy_up.png",
+    "roiFront": "761,411,59,57",
+    "roiBack": "761,411,59,57",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "提高"
+  },
+  {
+    "itemName": "tt_buy_confirm",
+    "imageName": "tt_tt_buy_confirm.png",
+    "roiFront": "584,512,53,53",
+    "roiBack": "553,508,169,60",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  }
+]

+ 56 - 0
tasks/RichMan/tt/ocr.json

@@ -0,0 +1,56 @@
+[
+  {
+    "itemName": "tt_totol",
+    "roiFront": "1121,10,116,35",
+    "roiBack": "1121,10,116,35",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "tt_blue_ticket",
+    "roiFront": "509,307,531,92",
+    "roiBack": "509,307,531,92",
+    "mode": "Full",
+    "method": "Default",
+    "keyword": "2000",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "tt_black",
+    "roiFront": "498,313,528,89",
+    "roiBack": "498,313,528,89",
+    "mode": "Full",
+    "method": "Default",
+    "keyword": "350",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "tt_ap",
+    "roiFront": "502,311,535,91",
+    "roiBack": "502,311,535,91",
+    "mode": "Full",
+    "method": "Default",
+    "keyword": "300",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "tt_buy",
+    "roiFront": "602,509,104,61",
+    "roiBack": "602,509,104,61",
+    "mode": "Full",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "tt_number",
+    "roiFront": "576,415,58,49",
+    "roiBack": "576,415,58,49",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  }
+]

BIN
tasks/RichMan/tt/tt_tt_ap.png


BIN
tasks/RichMan/tt/tt_tt_black.png


BIN
tasks/RichMan/tt/tt_tt_buy_confirm.png


BIN
tasks/RichMan/tt/tt_tt_buy_up.png


BIN
tasks/RichMan/tt/tt_tt_check.png


BIN
tasks/RichMan/tt/tt_tt_enter.png


BIN
tasks/RichMan/tt/tt_tt_ticket_bule.png


+ 8 - 4
tasks/base_task.py

@@ -438,9 +438,9 @@ class BaseTask(GlobalGameAssets):
             self.screenshot()
         return self.appear_then_click(self.I_UI_REWARD, action=self.C_UI_REWARD, interval=0.4, threshold=0.6)
 
-    def ui_get_reward(self, click_image: RuleImage):
+    def ui_get_reward(self, click_image: RuleImage or RuleOcr):
         """
-        传进来一个点击图片, 会点击这个图片,然后等待‘获得奖励’,
+        传进来一个点击图片 或是 一个ocr, 会点击这个图片,然后等待‘获得奖励’,
         最后当获得奖励消失后 退出
         :param click_image:
         :return:
@@ -461,7 +461,11 @@ class BaseTask(GlobalGameAssets):
                         continue
                 break
 
-            if self.appear_then_click(click_image, interval=0.8):
-                continue
+            if isinstance(click_image, RuleImage):
+                if self.appear_then_click(click_image, interval=1):
+                    continue
+            elif isinstance(click_image, RuleOcr):
+                if self.ocr_appear_click(click_image, interval=1):
+                    continue
 
         return True