runhey 3 лет назад
Родитель
Сommit
217a68fc26

+ 33 - 0
tasks/Component/GeneralBattle/general_battle.py

@@ -257,3 +257,36 @@ class GeneralBattle(BaseTask, GeneralBattleAssets):
         return True
         return True
 
 
 
 
+    def exit_battle(self, skip_first: bool=False) -> bool:
+        """
+        在战斗的时候强制退出战斗
+        :return:
+        """
+        if skip_first:
+            self.screenshot()
+
+        if not self.appear(self.I_EXIT):
+            return False
+
+        # 点击返回
+        logger.info(f"Click {self.I_EXIT.name}")
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_EXIT, interval=1.5):
+                continue
+            if self.appear(self.I_EXIT_ENSURE):
+                break
+
+        # 点击返回确认
+        while 1:
+            self.screenshot()
+            if self.appear_then_click(self.I_EXIT_ENSURE, interval=1.5):
+                continue
+            if self.appear_then_click(self.I_FALSE, interval=1.5):
+                continue
+            if not self.appear(self.I_EXIT):
+                break
+
+        return True
+
+

+ 4 - 0
tasks/Component/GeneralInvite/assets.py

@@ -90,6 +90,10 @@ class GeneralInviteAssets:
 	I_GI_EMOJI_1 = RuleImage(roi_front=(25,538,50,56), roi_back=(25,538,50,56), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_gi_emoji_1.png")
 	I_GI_EMOJI_1 = RuleImage(roi_front=(25,538,50,56), roi_back=(25,538,50,56), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_gi_emoji_1.png")
 	# description 
 	# description 
 	I_GI_EMOJI_2 = RuleImage(roi_front=(21,632,53,64), roi_back=(21,632,53,64), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_gi_emoji_2.png")
 	I_GI_EMOJI_2 = RuleImage(roi_front=(21,632,53,64), roi_back=(21,632,53,64), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_gi_emoji_2.png")
+	# 判断是不是在庭院界面 
+	I_GI_HOME = RuleImage(roi_front=(359,44,34,46), roi_back=(359,44,34,46), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_gi_home.png")
+	# 判断是不是在探索界面 
+	I_GI_EXPLORE = RuleImage(roi_front=(1138,119,41,48), roi_back=(1138,119,41,48), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralInvite/gi/gi_gi_explore.png")
 
 
 
 
 	# Ocr Rule Assets
 	# Ocr Rule Assets

+ 75 - 7
tasks/Component/GeneralInvite/general_invite.py

@@ -2,11 +2,11 @@
 # @author runhey
 # @author runhey
 # github https://github.com/runhey
 # github https://github.com/runhey
 import time
 import time
-
 import numpy as np
 import numpy as np
 
 
 from enum import Enum
 from enum import Enum
 from cached_property import cached_property
 from cached_property import cached_property
+from datetime import timedelta, time
 
 
 from module.base.timer import Timer
 from module.base.timer import Timer
 from tasks.base_task import BaseTask
 from tasks.base_task import BaseTask
@@ -175,12 +175,13 @@ class GeneralInvite(BaseTask, GeneralInviteAssets):
                 return False
                 return False
 
 
     # 判断是否在房间里面
     # 判断是否在房间里面
-    def is_in_room(self) -> bool:
+    def is_in_room(self, is_screenshot: bool = True) -> bool:
         """
         """
         判断是否在房间里面
         判断是否在房间里面
         :return:
         :return:
         """
         """
-        self.screenshot()
+        if is_screenshot:
+            self.screenshot()
         if self.appear(self.I_GI_EMOJI_1):
         if self.appear(self.I_GI_EMOJI_1):
             return True
             return True
         if self.appear(self.I_GI_EMOJI_2):
         if self.appear(self.I_GI_EMOJI_2):
@@ -555,19 +556,86 @@ class GeneralInvite(BaseTask, GeneralInviteAssets):
 
 
 
 
 
 
-    def accept_invite(self) -> bool:
+    def check_then_accept(self) -> bool:
         """
         """
-        队员接受邀请, 保持在庭院界面
+        队员接受邀请
         :return:
         :return:
         """
         """
+        if not self.appear(self.I_I_ACCEPT):
+            return False
+        logger.info('Click accept')
         while 1:
         while 1:
             self.screenshot()
             self.screenshot()
-            if self.appear(self.I_GI_BUFF):
-                break
+            if self.is_in_room():
+                return True
+            if self.appear_then_click(self.I_I_NO_DEFAULT, interval=1):
+                continue
+            if self.appear_then_click(self.I_GI_SURE, interval=1):
+                continue
             if self.appear_then_click(self.I_I_ACCEPT_DEFAULT, interval=1):
             if self.appear_then_click(self.I_I_ACCEPT_DEFAULT, interval=1):
                 continue
                 continue
             if self.appear_then_click(self.I_I_ACCEPT, interval=1):
             if self.appear_then_click(self.I_I_ACCEPT, interval=1):
                 continue
                 continue
+        return True
+
+    def wait_battle(self, wait_time: time) -> bool:
+        """
+        在房间等待,(要求保证在房间里面) 队长开启战斗
+        如果队长跑路了,或者的等待了很久还没开始
+        :return: 如果成功进入战斗(反正就是不在房间 )返回 True
+                 如果失败了,(退出房间)返回 False
+        """
+        self.timer_emoji = Timer(15)
+        self.timer_emoji.start()
+        wait_second = wait_time.second + wait_time.minute * 60
+        self.timer_wait = Timer(wait_second)
+        self.timer_wait.start()
+        logger.info(f'Wait battle {wait_second} seconds')
+        success = True
+        while 1:
+            self.screenshot()
+
+            # 如果自己在探索界面或者是庭院,那就是房间已经被销毁了
+            if self.appear(self.I_GI_HOME) or self.appear(self.I_GI_EXPLORE):
+                logger.warning('Room destroyed')
+                success = False
+                break
+
+
+            if self.timer_wait.reached():
+                logger.warning('Wait battle time out')
+                success = False
+                break
+
+            # 如果队长跑路了,自己变成了队长: 自己也要跑路
+            if self.appear(self.I_FIRE) or self.appear(self.I_FIRE_SEA):
+                logger.warning('Leader run away while wait battle and become leader now')
+                success = False
+                break
+
+            # 判断是否进入战斗
+            if self.is_in_room(is_screenshot=False):
+                if self.timer_emoji.reached():
+                    self.timer_emoji.reset()
+                    self.appear_then_click(self.I_GI_EMOJI_1)
+                    self.appear_then_click(self.I_GI_EMOJI_2)
+            else:
+                break
+
+
+        # 调出循环只有这些可能性:
+        # 1. 进入战斗(ui是战斗)
+        # 2. 队长跑路(自己还是在房间里面)
+        # 3. 等待时间到没有开始(还是在房间里面)
+        # 4. 房间的时间到了被迫提出房间(这个时候来到了探索界面)
+        if not success:
+            logger.info('Leave room')
+            self.exit_room()
+
+        return success
+
+
+
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':
     from module.config.config import Config
     from module.config.config import Config

BIN
tasks/Component/GeneralInvite/gi/gi_gi_explore.png


BIN
tasks/Component/GeneralInvite/gi/gi_gi_home.png


+ 18 - 0
tasks/Component/GeneralInvite/gi/member.json

@@ -16,5 +16,23 @@
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "description"
     "description": "description"
+  },
+  {
+    "itemName": "gi_home",
+    "imageName": "gi_gi_home.png",
+    "roiFront": "359,44,34,46",
+    "roiBack": "359,44,34,46",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "判断是不是在庭院界面"
+  },
+  {
+    "itemName": "gi_explore",
+    "imageName": "gi_gi_explore.png",
+    "roiFront": "1138,119,41,48",
+    "roiBack": "1138,119,41,48",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "判断是不是在探索界面"
   }
   }
 ]
 ]

+ 1 - 1
tasks/GameUi/assets.py

@@ -12,7 +12,7 @@ class GameUiAssets:
 
 
 	# Image Rule Assets
 	# Image Rule Assets
 	# description 
 	# description 
-	I_CHECK_MAIN = RuleImage(roi_front=(54,228,38,37), roi_back=(30,205,1033,96), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_main.png")
+	I_CHECK_MAIN = RuleImage(roi_front=(801,109,38,37), roi_back=(49,98,1033,61), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_main.png")
 	# description 
 	# description 
 	I_MAIN_GOTO_EXPLORATION = RuleImage(roi_front=(493,116,45,75), roi_back=(243,100,933,211), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_main_goto_exploration.png")
 	I_MAIN_GOTO_EXPLORATION = RuleImage(roi_front=(493,116,45,75), roi_back=(243,100,933,211), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_main_goto_exploration.png")
 	# description 
 	# description 

BIN
tasks/GameUi/page/page_check_main.png


+ 2 - 2
tasks/GameUi/page/page_img.json

@@ -2,8 +2,8 @@
   {
   {
     "itemName": "check_main",
     "itemName": "check_main",
     "imageName": "page_check_main.png",
     "imageName": "page_check_main.png",
-    "roiFront": "54,228,38,37",
-    "roiBack": "30,205,1033,96",
+    "roiFront": "801,109,38,37",
+    "roiBack": "49,98,1033,61",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "description"
     "description": "description"

+ 42 - 2
tasks/Orochi/script_task.py

@@ -35,7 +35,7 @@ class ScriptTask(GeneralBattle, GeneralInvite, GeneralBuff, GeneralRoom, GameUi,
         success = True
         success = True
         match config.orochi_config.user_status:
         match config.orochi_config.user_status:
             case UserStatus.LEADER: success = self.run_leader()
             case UserStatus.LEADER: success = self.run_leader()
-            case UserStatus.MEMBER: self.run_member()
+            case UserStatus.MEMBER: success = self.run_member()
             case UserStatus.ALONE: self.run_alone()
             case UserStatus.ALONE: self.run_alone()
             case UserStatus.WILD: self.run_wild()
             case UserStatus.WILD: self.run_wild()
             case _: logger.error('Unknown user status')
             case _: logger.error('Unknown user status')
@@ -196,7 +196,47 @@ class ScriptTask(GeneralBattle, GeneralInvite, GeneralBuff, GeneralRoom, GameUi,
         return True
         return True
 
 
     def run_member(self):
     def run_member(self):
-        pass
+        logger.info('Start run member')
+        self.ui_get_current_page()
+        self.ui_goto(page_soul_zones)
+        self.orochi_enter()
+        self.check_lock(self.config.orochi.general_battle_config.lock_team_enable)
+
+        # 进入战斗流程
+        while 1:
+            self.screenshot()
+
+            if self.current_count >= self.limit_count:
+                logger.info('Orochi count limit out')
+                break
+            if datetime.now() - self.start_time >= self.limit_time:
+                logger.info('Orochi time limit out')
+                break
+
+            if self.check_then_accept():
+                continue
+
+            if self.is_in_room():
+                if self.wait_battle(wait_time=self.config.orochi.invite_config.wait_time):
+                    self.run_general_battle(config=self.config.orochi.general_battle_config)
+                else:
+                    break
+
+        while 1:
+            # 有一种情况是本来要退出的,但是队长邀请了进入的战斗的加载界面
+            if self.appear(self.I_GI_HOME) or self.appear(self.I_GI_EXPLORE):
+                break
+            # 如果可能在房间就退出
+            if self.exit_room():
+                pass
+            # 如果还在战斗中,就退出战斗
+            if self.exit_battle():
+                pass
+
+
+        self.ui_get_current_page()
+        self.ui_goto(page_main)
+        return True
 
 
     def run_alone(self):
     def run_alone(self):
         logger.info('Start run alone')
         logger.info('Start run alone')