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

feat(rich man): guild store done!

runhey 3 лет назад
Родитель
Сommit
8c8fe71037

+ 1 - 1
tasks/AreaBoss/script_task.py

@@ -171,7 +171,7 @@ class ScriptTask(GeneralBattle, GameUi, AreaBossAssets):
 
         # 退出
         self.go_back()
-        self.set_next_run(task='AreaBoss', success=True)
+        self.set_next_run(task='AreaBoss', success=True, finish=False)
 
         # 以抛出异常的形式结束
         raise TaskEnd

+ 33 - 0
tasks/Component/Buy/assets.py

@@ -0,0 +1,33 @@
+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 BuyAssets: 
+
+
+	# Click Rule Assets
+	# description 
+	C_BUY_ONE = RuleClick(roi_front=(553,435,174,61), roi_back=(553,435,174,61), name="buy_one")
+	# description 
+	C_BUY_MORE = RuleClick(roi_front=(551,510,174,60), roi_back=(551,510,174,60), name="buy_more")
+
+
+	# Image Rule Assets
+	# 拉满 
+	I_BUY_PLUS = RuleImage(roi_front=(762,410,50,58), roi_back=(762,410,50,58), threshold=0.8, method="Template matching", file="./tasks/Component/Buy/buy/buy_buy_plus.png")
+	# 加一个 
+	I_BUY_ADD = RuleImage(roi_front=(686,411,51,54), roi_back=(686,411,51,54), threshold=0.8, method="Template matching", file="./tasks/Component/Buy/buy/buy_buy_add.png")
+	# 减 
+	I_BUY_SUB = RuleImage(roi_front=(471,416,50,48), roi_back=(471,416,50,48), threshold=0.8, method="Template matching", file="./tasks/Component/Buy/buy/buy_buy_sub.png")
+
+
+	# Ocr Rule Assets
+	# Ocr-description 
+	O_BUY_NUMBER = RuleOcr(roi=(578,416,52,46), area=(578,416,52,46), mode="Digit", method="Default", keyword="", name="buy_number")
+
+

+ 155 - 0
tasks/Component/Buy/buy.py

@@ -0,0 +1,155 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+import time
+
+from typing import Union
+
+from module.atom.image import RuleImage
+from module.atom.ocr import RuleOcr
+from module.atom.click import RuleClick
+from module.logger import logger
+
+from tasks.base_task import BaseTask
+from tasks.Component.Buy.assets import BuyAssets
+
+class Buy(BaseTask, BuyAssets):
+
+    def buy_one(self, start_click: Union[RuleImage, RuleOcr, RuleClick],
+                check_image: RuleImage):
+        """
+        购买一个物品
+        :param check_image: 购买确认时候的图片
+        :param start_click: 开始点击
+        :return:
+        """
+        while 1:
+            self.screenshot()
+
+            if self.appear(check_image):
+                break
+
+            if isinstance(start_click, RuleImage):
+                if self.appear_then_click(start_click, interval=1):
+                    continue
+            elif isinstance(start_click, RuleOcr):
+                if self.ocr_appear_click(start_click, interval=1):
+                    continue
+            elif isinstance(start_click, RuleClick):
+                if self.click(start_click, interval=1):
+                    continue
+        while 1:
+            self.screenshot()
+
+            if self.ui_reward_appear_click():
+                while 1:
+                    self.screenshot()
+                    # 等待动画结束
+                    if not self.appear(self.I_UI_REWARD, threshold=1):
+                        logger.info('Get reward success')
+                        break
+                    # 一直点击
+                    if self.ui_reward_appear_click():
+                        continue
+                break
+
+            if self.click(self.C_BUY_ONE, interval=2):
+                continue
+
+        return True
+
+
+    def buy_more(self, start_click: Union[RuleImage, RuleOcr, RuleClick],
+                 number: int = None):
+        """
+        购买多个物品
+        :param start_click:
+        :param number: 不指定就是拉满
+        :return:
+        """
+        while 1:
+            self.screenshot()
+
+            if self.appear(self.I_BUY_PLUS):
+                break
+
+            if isinstance(start_click, RuleImage):
+                if self.appear_then_click(start_click, interval=1):
+                    continue
+            elif isinstance(start_click, RuleOcr):
+                if self.ocr_appear_click(start_click, interval=1):
+                    continue
+            elif isinstance(start_click, RuleClick):
+                if self.click(start_click, interval=1):
+                    continue
+        # 设置购买的数量
+        if number is None:
+            self.appear_then_click(self.I_BUY_PLUS, interval=0.4)
+            time.sleep(0.5)
+            self.appear_then_click(self.I_BUY_PLUS, interval=0.4)
+        else:
+            # 四次截图数字都一样,就可以退出了
+            number_record = []
+            while 1:
+                self.screenshot()
+                current = self.O_BUY_NUMBER.ocr(self.device.image)
+                if current >= number:
+                    break
+                number_record.append(current)
+                if len(number_record) >= 4:
+                    if number_record[0] == number_record[1] == number_record[2] == number_record[3]:
+                        break
+                    number_record.pop(0)
+
+                if self.appear_then_click(self.I_BUY_ADD, interval=0.6):
+                    continue
+        # 购买确认
+        while 1:
+            self.screenshot()
+
+            if self.ui_reward_appear_click():
+                while 1:
+                    self.screenshot()
+                    # 等待动画结束
+                    if not self.appear(self.I_UI_REWARD, threshold=1):
+                        logger.info('Get reward success')
+                        break
+                    # 一直点击
+                    if self.ui_reward_appear_click():
+                        continue
+                break
+
+            if self.click(self.C_BUY_MORE, interval=2):
+                continue
+
+    def buy_check_money(self, target: RuleOcr, minimum: int):
+        """
+        检查钱是否足够
+        :param target:
+        :param minimum:
+        :return:
+        """
+        self.screenshot()
+        if not isinstance(target, RuleOcr):
+            logger.error('Target is not RuleOcr')
+            return False
+        current = target.ocr(self.device.image)
+        if not isinstance(current, int):
+            logger.warning('OCR current money failed')
+            return False
+        if current >= minimum:
+            logger.info('Money is enough')
+            return True
+        logger.info('Money is not enough')
+        return False
+
+
+
+if __name__ == '__main__':
+    from module.config.config import Config
+    from module.device.device import Device
+
+    c = Config('oas1')
+    d = Device(c)
+    t = Buy(c, d)
+

BIN
tasks/Component/Buy/buy/buy_buy_add.png


BIN
tasks/Component/Buy/buy/buy_buy_plus.png


BIN
tasks/Component/Buy/buy/buy_buy_sub.png


+ 14 - 0
tasks/Component/Buy/buy/click.json

@@ -0,0 +1,14 @@
+[
+  {
+    "itemName": "buy_one",
+    "roiFront": "553,435,174,61",
+    "roiBack": "553,435,174,61",
+    "description": "description"
+  },
+  {
+    "itemName": "buy_more",
+    "roiFront": "551,510,174,60",
+    "roiBack": "551,510,174,60",
+    "description": "description"
+  }
+]

+ 29 - 0
tasks/Component/Buy/buy/image.json

@@ -0,0 +1,29 @@
+[
+  {
+    "itemName": "buy_plus",
+    "imageName": "buy_buy_plus.png",
+    "roiFront": "762,410,50,58",
+    "roiBack": "762,410,50,58",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "拉满"
+  },
+  {
+    "itemName": "buy_add",
+    "imageName": "buy_buy_add.png",
+    "roiFront": "686,411,51,54",
+    "roiBack": "686,411,51,54",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "加一个"
+  },
+  {
+    "itemName": "buy_sub",
+    "imageName": "buy_buy_sub.png",
+    "roiFront": "471,416,50,48",
+    "roiBack": "471,416,50,48",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "减"
+  }
+]

+ 11 - 0
tasks/Component/Buy/buy/ocr.json

@@ -0,0 +1,11 @@
+[
+  {
+    "itemName": "buy_number",
+    "roiFront": "578,416,52,46",
+    "roiBack": "578,416,52,46",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  }
+]

+ 33 - 0
tasks/RichMan/assets.py

@@ -10,6 +10,39 @@ from module.atom.list import RuleList
 class RichManAssets: 
 
 
+	# Image Rule Assets
+	# 神社 
+	I_GUILD_SHRINE = RuleImage(roi_front=(869,623,64,62), roi_back=(869,623,64,62), threshold=0.8, method="Template matching", file="./tasks/RichMan/guild/guild_guild_shrine.png")
+	# 功勋商店 
+	I_GUILD_STORE = RuleImage(roi_front=(651,420,212,161), roi_back=(651,420,212,161), threshold=0.8, method="Template matching", file="./tasks/RichMan/guild/guild_guild_store.png")
+	# description 
+	I_GUILD_CLOSE_RED = RuleImage(roi_front=(1029,120,53,57), roi_back=(1029,120,53,57), threshold=0.8, method="Template matching", file="./tasks/RichMan/guild/guild_guild_close_red.png")
+	# 蓝票 
+	I_GUILD_BLUE = RuleImage(roi_front=(793,179,74,80), roi_back=(793,179,74,80), threshold=0.8, method="Template matching", file="./tasks/RichMan/guild/guild_guild_blue.png")
+	# 黑蛋碎片 
+	I_GUILD_SCRAP = RuleImage(roi_front=(570,442,71,68), roi_back=(570,442,71,68), threshold=0.8, method="Template matching", file="./tasks/RichMan/guild/guild_guild_scrap.png")
+	# 皮肤券 
+	I_GUILD_SKIN = RuleImage(roi_front=(795,436,71,74), roi_back=(795,436,71,74), threshold=0.8, method="Template matching", file="./tasks/RichMan/guild/guild_guild_skin.png")
+	# 购买检查 
+	I_GUILD_CHECK_SCRAP = RuleImage(roi_front=(454,240,90,88), roi_back=(454,240,90,88), threshold=0.8, method="Template matching", file="./tasks/RichMan/guild/guild_guild_check_scrap.png")
+
+
+	# Ocr Rule Assets
+	# 总的功勋 
+	O_GUILD_TOTAL = RuleOcr(roi=(1151,6,100,42), area=(1151,6,100,42), mode="Digit", method="Default", keyword="", name="guild_total")
+	# Ocr-description 
+	O_GUILD_NUMBER_BLUE = RuleOcr(roi=(888,269,25,33), area=(888,269,25,33), mode="Digit", method="Default", keyword="", name="guild_number_blue")
+	# Ocr-description 
+	O_GUILD_NUMBER_BLACK = RuleOcr(roi=(663,520,22,31), area=(663,520,22,31), mode="Digit", method="Default", keyword="", name="guild_number_black")
+	# Ocr-description 
+	O_GUILD_NUMBER_SKIN = RuleOcr(roi=(889,519,21,35), area=(889,519,21,35), mode="Digit", method="Default", keyword="", name="guild_number_skin")
+
+
+	# Swipe Rule Assets
+	# description 
+	S_GUILD_STORE = RuleSwipe(roi_front=(807,460,46,35), roi_back=(720,214,90,34), mode="default", name="guild_store")
+
+
 	# Click Rule Assets
 	# description 
 	C_C_SHRINE = RuleClick(roi_front=(1098,261,56,100), roi_back=(1098,261,56,100), name="c_shrine")

+ 119 - 0
tasks/RichMan/guild.py

@@ -0,0 +1,119 @@
+# 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_guild
+from tasks.GameUi.game_ui import GameUi
+from tasks.Component.Buy.buy import Buy
+from tasks.RichMan.assets import RichManAssets
+from tasks.RichMan.config import GuildStore
+
+class Guild(GameUi, Buy, RichManAssets):
+
+    def execute_guild(self, con: GuildStore=None):
+        self.ui_get_current_page()
+        self.ui_goto(page_guild)
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_GUILD_CLOSE_RED):
+                break
+            if self.appear_then_click(self.I_GUILD_SHRINE, interval=0.8):
+                continue
+            if self.appear_then_click(self.I_GUILD_STORE, interval=1.1):
+                continue
+        logger.info('Enter guild store success')
+        time.sleep(0.5)
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_GUILD_SCRAP):
+                break
+            if self.swipe(self.S_GUILD_STORE, interval=1.5):
+                time.sleep(2)
+                continue
+
+        # 开始购买
+        if con.mystery_amulet:
+            self._guild_mystery_amulet()
+        if con.black_daruma_scrap:
+            self._guild_black_daruma_scrap()
+        if con.skin_ticket:
+            self._guild_skin_ticket(con.skin_ticket)
+
+        # 回去
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_GUILD_SHRINE):
+                break
+            if self.appear_then_click(self.I_GUILD_CLOSE_RED, interval=1):
+                continue
+            if self.appear_then_click(self.I_UI_BACK_YELLOW, interval=1):
+                continue
+
+    def _guild_mystery_amulet(self):
+        logger.hr('Guild mystery amulet', 2)
+        self.screenshot()
+        if not self.buy_check_money(self.O_GUILD_TOTAL, 240):
+            return False
+        number = self.O_GUILD_NUMBER_BLUE.ocr(self.device.image)
+        if not isinstance(number, int):
+            logger.warning('OCR number failed')
+            return False
+        if number == 0:
+            logger.warning('No mystery amulet can buy')
+            return False
+        self.buy_more(self.I_GUILD_BLUE, number)
+        time.sleep(0.5)
+        return True
+
+    def _guild_black_daruma_scrap(self):
+        logger.hr('Guild black daruma scrap', 2)
+        self.screenshot()
+        if not self.buy_check_money(self.O_GUILD_TOTAL, 200):
+            return False
+        number = self.O_GUILD_NUMBER_BLACK.ocr(self.device.image)
+        if not isinstance(number, int):
+            logger.warning('OCR number failed')
+            return False
+        if number == 0:
+            logger.warning('No black daruma can buy')
+            return False
+        self.buy_one(self.I_GUILD_SCRAP, self.I_GUILD_CHECK_SCRAP)
+        time.sleep(0.5)
+        return True
+
+    def _guild_skin_ticket(self, num: int=0):
+        logger.hr('Guild skin ticket', 2)
+        if num == 0:
+            logger.warning('No buy skin ticket')
+            return False
+        self.screenshot()
+        if not self.buy_check_money(self.O_GUILD_TOTAL, 50):
+            return False
+        number = self.O_GUILD_NUMBER_SKIN.ocr(self.device.image)
+        if not isinstance(number, int):
+            logger.warning('OCR number failed')
+            return False
+        if number == 0:
+            logger.warning('No skin ticket can buy')
+            return False
+        self.buy_more(self.I_GUILD_SKIN, number)
+        time.sleep(0.5)
+        return True
+
+
+
+if __name__ == '__main__':
+    from module.config.config import Config
+    from module.device.device import Device
+
+    c = Config('oas1')
+    d = Device(c)
+    t = Guild(c, d)
+
+    t._guild_skin_ticket(5)
+
+
+

BIN
tasks/RichMan/guild/guild_guild_blue.png


BIN
tasks/RichMan/guild/guild_guild_check_scrap.png


BIN
tasks/RichMan/guild/guild_guild_close_red.png


BIN
tasks/RichMan/guild/guild_guild_scrap.png


BIN
tasks/RichMan/guild/guild_guild_shrine.png


BIN
tasks/RichMan/guild/guild_guild_skin.png


BIN
tasks/RichMan/guild/guild_guild_store.png


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

@@ -0,0 +1,65 @@
+[
+  {
+    "itemName": "guild_shrine",
+    "imageName": "guild_guild_shrine.png",
+    "roiFront": "869,623,64,62",
+    "roiBack": "869,623,64,62",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "神社"
+  },
+  {
+    "itemName": "guild_store",
+    "imageName": "guild_guild_store.png",
+    "roiFront": "651,420,212,161",
+    "roiBack": "651,420,212,161",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "功勋商店"
+  },
+  {
+    "itemName": "guild_close_red",
+    "imageName": "guild_guild_close_red.png",
+    "roiFront": "1029,120,53,57",
+    "roiBack": "1029,120,53,57",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "guild_blue",
+    "imageName": "guild_guild_blue.png",
+    "roiFront": "793,179,74,80",
+    "roiBack": "793,179,74,80",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "蓝票"
+  },
+  {
+    "itemName": "guild_scrap",
+    "imageName": "guild_guild_scrap.png",
+    "roiFront": "570,442,71,68",
+    "roiBack": "570,442,71,68",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "黑蛋碎片"
+  },
+  {
+    "itemName": "guild_skin",
+    "imageName": "guild_guild_skin.png",
+    "roiFront": "795,436,71,74",
+    "roiBack": "795,436,71,74",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "皮肤券"
+  },
+  {
+    "itemName": "guild_check_scrap",
+    "imageName": "guild_guild_check_scrap.png",
+    "roiFront": "454,240,90,88",
+    "roiBack": "454,240,90,88",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "购买检查"
+  }
+]

+ 38 - 0
tasks/RichMan/guild/ocr.json

@@ -0,0 +1,38 @@
+[
+  {
+    "itemName": "guild_total",
+    "roiFront": "1151,6,100,42",
+    "roiBack": "1151,6,100,42",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "总的功勋"
+  },
+  {
+    "itemName": "guild_number_blue",
+    "roiFront": "888,269,25,33",
+    "roiBack": "888,269,25,33",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "guild_number_black",
+    "roiFront": "663,520,22,31",
+    "roiBack": "663,520,22,31",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  },
+  {
+    "itemName": "guild_number_skin",
+    "roiFront": "889,519,21,35",
+    "roiBack": "889,519,21,35",
+    "mode": "Digit",
+    "method": "Default",
+    "keyword": "",
+    "description": "Ocr-description"
+  }
+]

+ 9 - 0
tasks/RichMan/guild/swipe.json

@@ -0,0 +1,9 @@
+[
+  {
+    "itemName": "guild_store",
+    "roiFront": "807,460,46,35",
+    "roiBack": "720,214,90,34",
+    "mode": "default",
+    "description": "description"
+  }
+]