Răsfoiți Sursa

feat(rich man): add friendship_points store

runhey 3 ani în urmă
părinte
comite
45dac39e7c

+ 12 - 3
tasks/Component/Buy/buy.py

@@ -9,6 +9,7 @@ from module.atom.image import RuleImage
 from module.atom.ocr import RuleOcr
 from module.atom.click import RuleClick
 from module.logger import logger
+from module.base.timer import Timer
 
 from tasks.base_task import BaseTask
 from tasks.Component.Buy.assets import BuyAssets
@@ -45,7 +46,7 @@ class Buy(BaseTask, BuyAssets):
                 while 1:
                     self.screenshot()
                     # 等待动画结束
-                    if not self.appear(self.I_UI_REWARD, threshold=1):
+                    if not self.appear(self.I_UI_REWARD):
                         logger.info('Get reward success')
                         break
                     # 一直点击
@@ -90,8 +91,17 @@ class Buy(BaseTask, BuyAssets):
         else:
             # 四次截图数字都一样,就可以退出了
             number_record = []
+            ocr_timer = Timer(0.8)
+            ocr_timer.start()
             while 1:
                 self.screenshot()
+
+                if self.appear_then_click(self.I_BUY_ADD, interval=0.8):
+                    continue
+
+                if not ocr_timer.reached():
+                    continue
+                ocr_timer.reset()
                 current = self.O_BUY_NUMBER.ocr(self.device.image)
                 if current >= number:
                     break
@@ -101,8 +111,7 @@ class Buy(BaseTask, BuyAssets):
                         break
                     number_record.pop(0)
 
-                if self.appear_then_click(self.I_BUY_ADD, interval=1):
-                    continue
+
         # 购买确认
         while 1:
             self.screenshot()

+ 11 - 0
tasks/RichMan/assets.py

@@ -81,6 +81,17 @@ class RichManAssets:
 	O_CON_NUMBER = RuleOcr(roi=(813,140,34,38), area=(813,140,34,38), mode="Digit", method="Default", keyword="", name="con_number")
 
 
+	# Image Rule Assets
+	# 红蛋 
+	I_FS_RED = RuleImage(roi_front=(423,158,100,100), roi_back=(423,158,100,100), threshold=0.8, method="Template matching", file="./tasks/RichMan/mall/friendship_points/friendship_points_fs_red.png")
+	# 破碎的咒符 
+	I_FS_BROKEN = RuleImage(roi_front=(200,153,100,100), roi_back=(200,153,100,100), threshold=0.8, method="Template matching", file="./tasks/RichMan/mall/friendship_points/friendship_points_fs_broken.png")
+	# description 
+	I_FS_WHITE_CLICK = RuleImage(roi_front=(647,157,100,100), roi_back=(647,157,100,100), threshold=0.8, method="Template matching", file="./tasks/RichMan/mall/friendship_points/friendship_points_fs_white_click.png")
+	# 白蛋确认 
+	I_FS_WHITE_CHECK = RuleImage(roi_front=(452,229,100,100), roi_back=(452,229,100,100), threshold=0.8, method="Template matching", file="./tasks/RichMan/mall/friendship_points/friendship_points_fs_white_check.png")
+
+
 	# Image Rule Assets
 	# 蓝票 
 	I_HONOR_BLUE = RuleImage(roi_front=(868,152,100,100), roi_back=(154,113,864,476), threshold=0.8, method="Template matching", file="./tasks/RichMan/mall/honor/honor_honor_blue.png")

+ 116 - 7
tasks/RichMan/mall/friendship_points.py

@@ -4,25 +4,134 @@
 import time
 
 from module.logger import logger
+from module.atom.image import RuleImage
+from module.atom.ocr import RuleOcr
 
-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.mall.special import Special
 from tasks.RichMan.config import FriendshipPoints as FriendshipPointsConfig
 
 
-class FriendshipPoints(GameUi, Buy, RichManAssets):
+class FriendshipPoints(Special):
 
     def execute_friendship(self, con: FriendshipPointsConfig = None):
-        pass
+        if not con:
+            con = self.config.rich_man.friendship_points
+        if not con.enable:
+            logger.info('Friendship points is not enable')
+            return
+        self._enter_friendship()
+
+        # 购买
+        if con.white_daruma:
+            self.buy_mall_one(buy_button=self.I_FS_WHITE_CLICK, buy_check=self.I_FS_WHITE_CHECK,
+                              money_ocr=self.O_MALL_RESOURCE_5, buy_money=1000)
+        if con.red_daruma != 0:
+            logger.warning('进入')
+            self.buy_mall_more(buy_button=self.I_FS_RED, remain_number=False, money_ocr=self.O_MALL_RESOURCE_5,
+                                 buy_number=con.red_daruma, buy_max=99, buy_money=150)
+        if con.broken_amulet != 0:
+            self.buy_mall_more(buy_button=self.I_FS_BROKEN, remain_number=False, money_ocr=self.O_MALL_RESOURCE_5,
+                                 buy_number=con.broken_amulet, buy_max=99, buy_money=100)
+
+    def buy_mall_one(self, buy_button: RuleImage, buy_check: RuleImage, money_ocr: RuleOcr, buy_money: int):
+        """
+        针对只能买一个的
+        :param buy_button:
+        :param buy_check:
+        :param money_ocr:
+        :param buy_money: 买这一个花多少
+        :return:
+        """
+        logger.hr(buy_button.name, 3)
+        self.screenshot()
+        # 检查是否出现了购买按钮
+        if not self.appear(buy_button):
+            logger.warning('Buy button is not appear')
+            return
+        # 是否检查剩余数量
+        _remain = self._special_check_remain(buy_button)
+        if _remain == 0:
+            logger.warning('Remain number is 0')
+            return
+        # 检查钱
+        current_money = money_ocr.ocr(self.device.image)
+        if not isinstance(current_money, int):
+            logger.warning('Money ocr failed')
+            return
+        money_enough = current_money >= buy_money
+        if not money_enough:
+            logger.warning(f'No enough money {current_money}')
+            return
+        # 点击购买
+        self.buy_one(buy_button, buy_check)
+
+    def buy_mall_more(self, buy_button: RuleImage, remain_number: bool, money_ocr: RuleOcr,
+                       buy_number: int, buy_max: int, buy_money: int):
+        """
+        针对可以买多个的
+        :param money_ocr:  检查钱的第几个
+        :param remain_number: 是否需要检查剩余数量
+        :param buy_button:
+        :param buy_number:
+        :param buy_max:
+        :param buy_money:
+        :return:
+        """
+        logger.hr(buy_button.name, 3)
+        if buy_number == 0:
+            logger.info('Buy number is 0')
+            return
+        self.screenshot()
+        # 检查是否出现了购买按钮
+        if not self.appear(buy_button):
+            logger.warning('Buy button is not appear')
+            return
+        # 是否检查剩余数量
+        if remain_number:
+            _remain = self._special_check_remain(buy_button)
+            if _remain == 0:
+                logger.warning('Remain number is 0')
+                return
+            if _remain < buy_number:
+                logger.warning(f'Remain number is {_remain}, buy number is {buy_number}')
+                buy_number = _remain
+        # 检查钱够不够
+        current_money = money_ocr.ocr(self.device.image)
+        if not isinstance(current_money, int):
+            logger.warning('Money ocr failed')
+            return
+        money_enough = current_money >= buy_money * buy_number
+        if not money_enough:
+            logger.warning(f'Money is not enough {current_money}')
+            # 判断够不够买2个
+            if current_money < buy_money * 2:
+                logger.warning('Money is not enough 2')
+                return
+            buy_number = current_money // buy_money
+        # 购买
+        logger.info(f'Buy number is {buy_number}')
+        if buy_number >= buy_max:
+            buy_cycles_number = buy_number // buy_max
+            buy_res_number = buy_number % buy_max
+        else:
+            buy_cycles_number = None
+            buy_res_number = buy_number
+        if buy_cycles_number:
+            for i in range(buy_cycles_number):
+                self.buy_more(buy_button)
+                time.sleep(0.5)
+        if buy_res_number:
+            self.buy_more(buy_button, buy_res_number)
+            time.sleep(0.5)
+
 
 
 if __name__ == '__main__':
     from module.config.config import Config
     from module.device.device import Device
 
-    c = Config('oas1')
+    c = Config('test')
     d = Device(c)
     t = FriendshipPoints(c, d)
 
+    t.execute_friendship()

BIN
tasks/RichMan/mall/friendship_points/friendship_points_fs_broken.png


BIN
tasks/RichMan/mall/friendship_points/friendship_points_fs_red.png


BIN
tasks/RichMan/mall/friendship_points/friendship_points_fs_white_check.png


BIN
tasks/RichMan/mall/friendship_points/friendship_points_fs_white_click.png


+ 38 - 0
tasks/RichMan/mall/friendship_points/image.json

@@ -0,0 +1,38 @@
+[
+  {
+    "itemName": "fs_red",
+    "imageName": "friendship_points_fs_red.png",
+    "roiFront": "423,158,100,100",
+    "roiBack": "423,158,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "红蛋"
+  },
+  {
+    "itemName": "fs_broken",
+    "imageName": "friendship_points_fs_broken.png",
+    "roiFront": "200,153,100,100",
+    "roiBack": "200,153,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "破碎的咒符"
+  },
+  {
+    "itemName": "fs_white_click",
+    "imageName": "friendship_points_fs_white_click.png",
+    "roiFront": "647,157,100,100",
+    "roiBack": "647,157,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "fs_white_check",
+    "imageName": "friendship_points_fs_white_check.png",
+    "roiFront": "452,229,100,100",
+    "roiBack": "452,229,100,100",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "白蛋确认"
+  }
+]