فهرست منبع

feat(rich man): save shrine 7.25

runhey 3 سال پیش
والد
کامیت
1167d34b45

+ 49 - 0
tasks/RichMan/assets.py

@@ -10,6 +10,55 @@ from module.atom.list import RuleList
 class RichManAssets: 
 
 
+	# Click Rule Assets
+	# description 
+	C_C_SHRINE = RuleClick(roi_front=(1098,261,56,100), roi_back=(1098,261,56,100), name="c_shrine")
+
+
+	# Image Rule Assets
+	# 下期预览 
+	I_S_NEXT_PERIOD = RuleImage(roi_front=(1083,574,90,86), roi_back=(1083,574,90,86), threshold=0.8, method="Template matching", file="./tasks/RichMan/shrine/shrine_s_next_period.png")
+	# description 
+	I_S_WHITE_FIVE = RuleImage(roi_front=(769,143,77,85), roi_back=(769,143,77,85), threshold=0.8, method="Template matching", file="./tasks/RichMan/shrine/shrine_s_white_five.png")
+	# description 
+	I_S_WHITE_FOUR = RuleImage(roi_front=(951,144,73,82), roi_back=(951,144,73,82), threshold=0.8, method="Template matching", file="./tasks/RichMan/shrine/shrine_s_white_four.png")
+	# 黑蛋 
+	I_S_BLACK = RuleImage(roi_front=(588,143,78,83), roi_back=(588,143,78,83), threshold=0.8, method="Template matching", file="./tasks/RichMan/shrine/shrine_s_black.png")
+	# description 
+	I_S_BUY_BLACK = RuleImage(roi_front=(777,508,173,60), roi_back=(777,508,173,60), threshold=0.8, method="Template matching", file="./tasks/RichMan/shrine/shrine_s_buy_black.png")
+	# description 
+	I_S_BUY_WHITE_FIVE = RuleImage(roi_front=(778,512,177,56), roi_back=(778,512,177,56), threshold=0.8, method="Template matching", file="./tasks/RichMan/shrine/shrine_s_buy_white_five.png")
+	# description 
+	I_S_BUY_WHITE_FOUR = RuleImage(roi_front=(779,507,173,64), roi_back=(779,507,173,64), threshold=0.8, method="Template matching", file="./tasks/RichMan/shrine/shrine_s_buy_white_four.png")
+	# description 
+	I_S_CONFIRM_WHITE_FIVE = RuleImage(roi_front=(554,438,174,61), roi_back=(554,438,174,61), threshold=0.8, method="Template matching", file="./tasks/RichMan/shrine/shrine_s_confirm_white_five.png")
+	# description 
+	I_S_CONFIRM_WHITE_FOUR = RuleImage(roi_front=(552,509,176,62), roi_back=(552,509,176,62), threshold=0.8, method="Template matching", file="./tasks/RichMan/shrine/shrine_s_confirm_white_four.png")
+	# description 
+	I_S_CONFIRM_BLACK = RuleImage(roi_front=(552,439,180,62), roi_back=(552,439,180,62), threshold=0.8, method="Template matching", file="./tasks/RichMan/shrine/shrine_s_confirm_black.png")
+	# description 
+	I_S_BUY_UP = RuleImage(roi_front=(762,412,56,54), roi_back=(762,412,56,54), threshold=0.8, method="Template matching", file="./tasks/RichMan/shrine/shrine_s_buy_up.png")
+	# description 
+	I_S_CHECK_BLACK = RuleImage(roi_front=(811,225,108,178), roi_back=(811,225,108,178), threshold=0.8, method="Template matching", file="./tasks/RichMan/shrine/shrine_s_check_black.png")
+	# description 
+	I_S_CHECK_WHITE_FIVE = RuleImage(roi_front=(810,222,109,182), roi_back=(810,222,109,182), threshold=0.8, method="Template matching", file="./tasks/RichMan/shrine/shrine_s_check_white_five.png")
+	# description 
+	I_S_CHECK_WHITE_FOUR = RuleImage(roi_front=(808,222,113,181), roi_back=(808,222,113,181), threshold=0.8, method="Template matching", file="./tasks/RichMan/shrine/shrine_s_check_white_four.png")
+
+
+	# Ocr Rule Assets
+	# Ocr-description 
+	O_S_TOTAL = RuleOcr(roi=(1134,11,112,36), area=(1134,11,112,36), mode="Digit", method="Default", keyword="", name="s_total")
+	# 已兑换 
+	O_S_BLACK = RuleOcr(roi=(582,179,84,48), area=(582,179,84,48), mode="Single", method="Default", keyword="", name="s_black")
+	# Ocr-description 
+	O_S_WHITE_FIVE = RuleOcr(roi=(774,174,69,44), area=(774,174,69,44), mode="Single", method="Default", keyword="", name="s_white_five")
+	# Ocr-description 
+	O_S_WHITE_FOUR = RuleOcr(roi=(952,168,74,60), area=(952,168,74,60), mode="Single", method="Default", keyword="", name="s_white_four")
+	# 买两个四星蛋 
+	O_S_FOUR_NUMBER = RuleOcr(roi=(581,414,46,45), area=(581,414,46,45), mode="Digit", method="Default", keyword="2", name="s_four_number")
+
+
 	# 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")

+ 135 - 0
tasks/RichMan/shrine.py

@@ -0,0 +1,135 @@
+# 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_summon
+from tasks.GameUi.game_ui import GameUi
+from tasks.RichMan.assets import RichManAssets
+from tasks.RichMan.config import Shrine as ConfigShrine
+
+
+class Shrine(GameUi, RichManAssets):
+
+    def execute_shrine(self, con: ConfigShrine):
+        logger.hr('Start Shrine')
+        if not con.enable:
+            logger.info('Shrine is disabled')
+            return
+        self.ui_get_current_page()
+        self.ui_goto(page_summon)
+
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_S_NEXT_PERIOD):
+                break
+            if self.click(self.C_C_SHRINE, interval=1):
+                continue
+        logger.info('Enter Shrine')
+        time.sleep(0.5)
+        if con.black_daruma:
+            self.shrine_black_daruma()
+        if con.white_daruma_five:
+            self.shrine_white_five()
+        if con.white_daruma_four:
+            self.shrine_white_four()
+
+    def shrine_check_money(self, mix: int) -> bool:
+        self.screenshot()
+        current = self.O_TT_TOTOL.ocr(self.device.image)
+        if not isinstance(current, int):
+            logger.warning('OCR current money failed')
+            return False
+        if current >= mix:
+            logger.info('Money is enough')
+            return True
+        logger.info('Money is not enough')
+        return False
+
+    def _check_bought(self, target) -> bool:
+        """
+        检查是否已经购买, 弃用,无法识别任何文字
+        :return: True 已经购买
+        """
+        self.screenshot()
+        result = target.ocr(self.device.image)
+        if '已' in result or '兑' in result or '换' in result:
+            logger.info('Already bought')
+            return True
+        logger.info('Not bought')
+        return False
+
+    def shrine_black_daruma(self):
+        logger.hr('Shrine black daruma', 2)
+        self.screenshot()
+        if not self.shrine_check_money(1500):
+            return
+        self.ui_click(self.I_S_BLACK, self.I_S_CHECK_BLACK)
+        self.screenshot()
+        if not self.appear(self.I_S_BUY_BLACK, threshold=0.9):
+            logger.info('Already bought black daruma')
+            self.ui_click_until_disappear(self.I_UI_BACK_RED)
+            time.sleep(0.5)
+            return
+        self.ui_click(self.I_S_BUY_BLACK, self.I_S_CONFIRM_BLACK)
+        self.ui_get_reward(self.I_S_CONFIRM_BLACK)
+        self.ui_click_until_disappear(self.I_UI_BACK_RED)
+        time.sleep(1)
+
+    def shrine_white_five(self):
+        logger.hr('Shrine white five', 2)
+        self.screenshot()
+        if not self.appear(self.I_S_WHITE_FIVE):
+            logger.info('White five is not available')
+            return
+        if not self.shrine_check_money(1200):
+            return
+        self.ui_click(self.I_S_WHITE_FIVE, self.I_S_CHECK_WHITE_FIVE)
+        self.screenshot()
+        if not self.appear(self.I_S_BUY_WHITE_FIVE, threshold=0.9):
+            logger.info('Already bought white five')
+            self.ui_click_until_disappear(self.I_UI_BACK_RED)
+            time.sleep(1)
+            return
+        self.ui_click(self.I_S_BUY_WHITE_FIVE, self.I_S_CONFIRM_WHITE_FIVE)
+        self.ui_get_reward(self.I_S_CONFIRM_WHITE_FIVE)
+        self.ui_click_until_disappear(self.I_UI_BACK_RED)
+        time.sleep(1)
+
+    def shrine_white_four(self):
+        logger.hr('Shrine white four', 2)
+        self.screenshot()
+        if not self.appear(self.I_S_WHITE_FOUR):
+            logger.info('White four is not available')
+            return
+        if not self.shrine_check_money(400):
+            return
+        self.ui_click(self.I_S_WHITE_FOUR, self.I_S_CHECK_WHITE_FOUR)
+        self.screenshot()
+        if not self.appear(self.I_S_BUY_WHITE_FOUR, threshold=0.9):
+            logger.info('Already bought white four')
+            self.ui_click_until_disappear(self.I_UI_BACK_RED)
+            time.sleep(1)
+            return
+        self.ui_click(self.I_S_BUY_WHITE_FOUR, self.I_S_CONFIRM_WHITE_FOUR)
+        self.ui_get_reward(self.I_S_CONFIRM_WHITE_FOUR)
+        self.ui_click_until_disappear(self.I_UI_BACK_RED)
+        time.sleep(1)
+
+
+
+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 = Shrine(c, d)
+
+    t.shrine_white_four()
+    # t.screenshot()
+    # print(t.appear(t.I_S_BUY_WHITE_FIVE, threshold=0.9))
+

+ 8 - 0
tasks/RichMan/shrine/click.json

@@ -0,0 +1,8 @@
+[
+  {
+    "itemName": "c_shrine",
+    "roiFront": "1098,261,56,100",
+    "roiBack": "1098,261,56,100",
+    "description": "description"
+  }
+]

+ 128 - 0
tasks/RichMan/shrine/image.json

@@ -0,0 +1,128 @@
+[
+  {
+    "itemName": "s_next_period",
+    "imageName": "shrine_s_next_period.png",
+    "roiFront": "1083,574,90,86",
+    "roiBack": "1083,574,90,86",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "下期预览"
+  },
+  {
+    "itemName": "s_white_five",
+    "imageName": "shrine_s_white_five.png",
+    "roiFront": "769,143,77,85",
+    "roiBack": "769,143,77,85",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "s_white_four",
+    "imageName": "shrine_s_white_four.png",
+    "roiFront": "951,144,73,82",
+    "roiBack": "951,144,73,82",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "s_black",
+    "imageName": "shrine_s_black.png",
+    "roiFront": "588,143,78,83",
+    "roiBack": "588,143,78,83",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "黑蛋"
+  },
+  {
+    "itemName": "s_buy_black",
+    "imageName": "shrine_s_buy_black.png",
+    "roiFront": "777,508,173,60",
+    "roiBack": "777,508,173,60",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "s_buy_white_five",
+    "imageName": "shrine_s_buy_white_five.png",
+    "roiFront": "778,512,177,56",
+    "roiBack": "778,512,177,56",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "s_buy_white_four",
+    "imageName": "shrine_s_buy_white_four.png",
+    "roiFront": "779,507,173,64",
+    "roiBack": "779,507,173,64",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "s_confirm_white_five",
+    "imageName": "shrine_s_confirm_white_five.png",
+    "roiFront": "554,438,174,61",
+    "roiBack": "554,438,174,61",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "s_confirm_white_four",
+    "imageName": "shrine_s_confirm_white_four.png",
+    "roiFront": "552,509,176,62",
+    "roiBack": "552,509,176,62",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "s_confirm_black",
+    "imageName": "shrine_s_confirm_black.png",
+    "roiFront": "552,439,180,62",
+    "roiBack": "552,439,180,62",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "s_buy_up",
+    "imageName": "shrine_s_buy_up.png",
+    "roiFront": "762,412,56,54",
+    "roiBack": "762,412,56,54",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "s_check_black",
+    "imageName": "shrine_s_check_black.png",
+    "roiFront": "811,225,108,178",
+    "roiBack": "811,225,108,178",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "s_check_white_five",
+    "imageName": "shrine_s_check_white_five.png",
+    "roiFront": "810,222,109,182",
+    "roiBack": "810,222,109,182",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "s_check_white_four",
+    "imageName": "shrine_s_check_white_four.png",
+    "roiFront": "808,222,113,181",
+    "roiBack": "808,222,113,181",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  }
+]

+ 47 - 0
tasks/RichMan/shrine/ocr.json

@@ -0,0 +1,47 @@
+[
+  {
+    "itemName": "s_total",
+    "roiFront": "1134,11,112,36",
+    "roiBack": "1134,11,112,36",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "s_black",
+    "roiFront": "582,179,84,48",
+    "roiBack": "582,179,84,48",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "",
+    "description": "已兑换"
+  },
+  {
+    "itemName": "s_white_five",
+    "roiFront": "774,174,69,44",
+    "roiBack": "774,174,69,44",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "s_white_four",
+    "roiFront": "952,168,74,60",
+    "roiBack": "952,168,74,60",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "s_four_number",
+    "roiFront": "581,414,46,45",
+    "roiBack": "581,414,46,45",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "2",
+    "description": "买两个四星蛋"
+  }
+]

BIN
tasks/RichMan/shrine/shrine_s_black.png


BIN
tasks/RichMan/shrine/shrine_s_buy_black.png


BIN
tasks/RichMan/shrine/shrine_s_buy_up.png


BIN
tasks/RichMan/shrine/shrine_s_buy_white_five.png


BIN
tasks/RichMan/shrine/shrine_s_buy_white_four.png


BIN
tasks/RichMan/shrine/shrine_s_check_black.png


BIN
tasks/RichMan/shrine/shrine_s_check_white_five.png


BIN
tasks/RichMan/shrine/shrine_s_check_white_four.png


BIN
tasks/RichMan/shrine/shrine_s_confirm_black.png


BIN
tasks/RichMan/shrine/shrine_s_confirm_white_five.png


BIN
tasks/RichMan/shrine/shrine_s_confirm_white_four.png


BIN
tasks/RichMan/shrine/shrine_s_next_period.png


BIN
tasks/RichMan/shrine/shrine_s_white_five.png


BIN
tasks/RichMan/shrine/shrine_s_white_four.png


+ 8 - 8
tasks/RichMan/thousand_things.py

@@ -59,7 +59,7 @@ class ThousandThings(GameUi, RichManAssets):
         if not self.appear(self.I_TT_TICKET_BULE):
             logger.info('No mystery amulet')
             return False
-        if not self.tt_check_memory(2000):
+        if not self.tt_check_money(2000):
             return False
         while 1:
             self.screenshot()
@@ -79,7 +79,7 @@ class ThousandThings(GameUi, RichManAssets):
         if not self.appear(self.I_TT_BLACK):
             logger.info('No black daruma scrap')
             return False
-        if not self.tt_check_memory(350):
+        if not self.tt_check_money(350):
             return False
         while 1:
             self.screenshot()
@@ -98,7 +98,7 @@ class ThousandThings(GameUi, RichManAssets):
         if not self.appear(self.I_TT_AP):
             logger.info('No ap')
             return False
-        if not self.tt_check_memory(600):
+        if not self.tt_check_money(600):
             return False
         self.O_TT_NUMBER.keyword = '2'
         while 1:
@@ -115,16 +115,16 @@ class ThousandThings(GameUi, RichManAssets):
         time.sleep(0.5)
         return True
 
-    def tt_check_memory(self, mix: int) -> bool:
+    def tt_check_money(self, mix: int) -> bool:
         self.screenshot()
-        current = self.O_TT_TOTOL.ocr(self.device.image)
+        current = self.O_S_TOTAL.ocr(self.device.image)
         if not isinstance(current, int):
-            logger.warning('OCR current memory failed')
+            logger.warning('OCR current money failed')
             return False
         if current >= mix:
-            logger.info('Memory is enough')
+            logger.info('Money is enough')
             return True
-        logger.info('Memory is not enough')
+        logger.info('Money is not enough')
         return False
 
 

+ 34 - 1
tasks/base_task.py

@@ -429,6 +429,9 @@ class BaseTask(GlobalGameAssets):
             start_time = self.start_time
         self.config.task_delay(task, start_time=start_time, success=success, server=server, target=target)
 
+    #  ---------------------------------------------------------------------------------------------------------------
+    #
+    #  ---------------------------------------------------------------------------------------------------------------
     def ui_reward_appear_click(self, screenshot=False) -> bool:
         """
         如果出现 ‘获得奖励’ 就点击
@@ -452,7 +455,7 @@ class BaseTask(GlobalGameAssets):
                 while 1:
                     self.screenshot()
                     # 等待动画结束
-                    if not self.appear(self.I_UI_REWARD, threshold=0.6):
+                    if not self.appear(self.I_UI_REWARD, threshold=1):
                         logger.info('Get reward success')
                         break
 
@@ -469,3 +472,33 @@ class BaseTask(GlobalGameAssets):
                     continue
 
         return True
+
+
+    def ui_click(self, click, stop):
+        """
+        循环的一个操作,直到出现stop
+        :param click:
+        :param stop:
+        :return:
+        """
+        while 1:
+            self.screenshot()
+            if self.appear(stop):
+                break
+            if self.appear_then_click(click, interval=1):
+                continue
+
+    def ui_click_until_disappear(self, click):
+        """
+        点击一个按钮直到消失
+        :param click:
+        :return:
+        """
+        while 1:
+            self.screenshot()
+            if not self.appear(click):
+                break
+            elif self.appear_then_click(click, interval=1):
+                continue
+
+