Browse Source

feat(task): Add True-Orochi

runhey 3 years ago
parent
commit
b5e1b972ef

+ 4 - 0
tasks/TrueOrochi/assets.py

@@ -54,5 +54,9 @@ class TrueOrochiAssets:
 	I_ST_GREEN_5 = RuleImage(roi_front=(841,335,26,44), roi_back=(814,302,100,100), threshold=0.8, method="Template matching", file="./tasks/TrueOrochi/st/st_st_green_5.png")
 	I_ST_GREEN_5 = RuleImage(roi_front=(841,335,26,44), roi_back=(814,302,100,100), threshold=0.8, method="Template matching", file="./tasks/TrueOrochi/st/st_st_green_5.png")
 	# description 
 	# description 
 	I_ST_GREEN_6 = RuleImage(roi_front=(930,247,24,47), roi_back=(894,224,100,100), threshold=0.8, method="Template matching", file="./tasks/TrueOrochi/st/st_st_green_6.png")
 	I_ST_GREEN_6 = RuleImage(roi_front=(930,247,24,47), roi_back=(894,224,100,100), threshold=0.8, method="Template matching", file="./tasks/TrueOrochi/st/st_st_green_6.png")
+	# 60体力创建 
+	I_ST_CREATE_ROOM = RuleImage(roi_front=(528,482,223,62), roi_back=(528,482,223,62), threshold=0.8, method="Template matching", file="./tasks/TrueOrochi/st/st_st_create_room.png")
+	# 头像框 
+	I_ST_FRAME = RuleImage(roi_front=(574,441,130,63), roi_back=(574,441,130,63), threshold=0.8, method="Template matching", file="./tasks/TrueOrochi/st/st_st_frame.png")
 
 
 
 

+ 2 - 2
tasks/TrueOrochi/config.py

@@ -27,8 +27,8 @@ class TrueOrochiScheduler(Scheduler):
 
 
 class TrueOrochiConfig(BaseModel):
 class TrueOrochiConfig(BaseModel):
     find_true_orochi: bool = Field(default=True, description='find_true_orochi_help')
     find_true_orochi: bool = Field(default=True, description='find_true_orochi_help')
-    green_enable: bool = Field(default=False, description='green_enable_help')
-    green_mark_type: GreenMarkType = Field(default=GreenMarkType.LEFT_1, description='green_mark_type_help')
+    # green_enable: bool = Field(default=False, description='green_enable_help')
+    # green_mark_type: GreenMarkType = Field(default=GreenMarkType.LEFT_1, description='green_mark_type_help')
     current_success: int = Field(default=0, description='current_success_help')
     current_success: int = Field(default=0, description='current_success_help')
 
 
 class TrueOrochi(ConfigBase):
 class TrueOrochi(ConfigBase):

+ 151 - 2
tasks/TrueOrochi/script_task.py

@@ -1,24 +1,135 @@
 # This Python file uses the following encoding: utf-8
 # This Python file uses the following encoding: utf-8
 # @author runhey
 # @author runhey
 # github https://github.com/runhey
 # github https://github.com/runhey
+from time import sleep
+from datetime import datetime, time
+
 from module.logger import logger
 from module.logger import logger
 from module.exception import TaskEnd
 from module.exception import TaskEnd
+from module.base.timer import Timer
 
 
 from tasks.GameUi.game_ui import GameUi
 from tasks.GameUi.game_ui import GameUi
 from tasks.Component.GeneralBattle.general_battle import GeneralBattle
 from tasks.Component.GeneralBattle.general_battle import GeneralBattle
 from tasks.Component.GeneralInvite.general_invite import GeneralInvite
 from tasks.Component.GeneralInvite.general_invite import GeneralInvite
 from tasks.Component.GeneralRoom.general_room import GeneralRoom
 from tasks.Component.GeneralRoom.general_room import GeneralRoom
 from tasks.Orochi.script_task import ScriptTask as OrochiScriptTask
 from tasks.Orochi.script_task import ScriptTask as OrochiScriptTask
+from tasks.Orochi.config import Layer
 from tasks.GameUi.page import page_main, page_soul_zones
 from tasks.GameUi.page import page_main, page_soul_zones
+from tasks.TrueOrochi.assets import TrueOrochiAssets
 
 
 
 
-class ScriptTask(GameUi, OrochiScriptTask, GeneralBattle, GeneralInvite, GeneralRoom):
+class ScriptTask(OrochiScriptTask, TrueOrochiAssets):
 
 
     def run(self):
     def run(self):
-        config = self.config.ture_orochi
+        conf = self.config.true_orochi.true_orochi_config
+        if conf.current_success >= 2:
+            # 超过两次就说明这周打完了没有必要再打了
+            logger.warning('This week is full')
+            self.check_times(True)
+            raise TaskEnd('TrueOrochi')
         self.ui_get_current_page()
         self.ui_get_current_page()
         self.ui_goto(page_soul_zones)
         self.ui_goto(page_soul_zones)
         self.orochi_enter()
         self.orochi_enter()
+        battle = self.check_true_orochi(True)
+        if not battle:
+            logger.warning('Not find true orochi')
+            logger.warning('Try to battle orochi for ten times')
+            self.check_layer(Layer.TEN)
+            self.check_lock(False)
+            count_orochi_ten = 0
+            while 1:
+                self.screenshot()
+                # 检查猫咪奖励
+                if self.appear_then_click(self.I_PET_PRESENT, action=self.C_WIN_3, interval=1):
+                    continue
+                if not self.appear(self.I_OROCHI_FIRE):
+                    continue
+                if self.check_true_orochi(False):
+                    logger.info('Find true orochi')
+                    battle = True
+                    break
+                if count_orochi_ten >= 10:
+                    logger.warning('Not find true orochi')
+                    battle = False
+                    break
+                # 否则点击挑战
+                if self.appear(self.I_OROCHI_FIRE):
+                    self.ui_click_until_disappear(self.I_OROCHI_FIRE)
+                    self.run_general_battle()
+                    count_orochi_ten += 1
+                    continue
+
+        if not battle:
+            # 如果还没有真蛇,那么就退出
+            self.check_times(battle)
+            raise TaskEnd('TrueOrochi')
+        # 如果有真蛇,那么就开始战斗
+        logger.hr('True Orochi Battle')
+        conf.current_success += 1
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_ST_CREATE_ROOM):
+                break
+            if self.appear_then_click(self.I_UI_CONFIRM, interval=1):
+                continue
+            if self.appear_then_click(self.I_ST_FIRE, interval=1):
+                continue
+            if self.appear_then_click(self.I_FIND_TS, interval=1):
+                continue
+        self.ensure_private()
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_ST_FIRE_PREPARE):
+                break
+            if self.appear_then_click(self.I_FIRE, interval=1, threshold=0.7):
+                continue
+            if self.appear_then_click(self.I_UI_CONFIRM, interval=1):
+                continue
+            if self.appear_then_click(self.I_ST_CREATE_ROOM, interval=1):
+                continue
+        # 战斗准备
+        logger.info('Battle prepare')
+        self.ui_click(self.I_ST_FIRE_PREPARE, self.I_BUFF)
+        while 1:
+            self.screenshot()
+            if not self.appear(self.I_BUFF):
+                break
+            if self.appear_then_click(self.I_ST_AUTO_FALSE, interval=0.8):
+                continue
+            if self.appear_then_click(self.I_PREPARE_HIGHLIGHT, interval=1.8):
+                continue
+        self.device.stuck_record_add('BATTLE_STATUS_S')
+        self.device.click_record_clear()
+        logger.info("Start battle process")
+        check_timer = Timer(280)
+        check_timer.start()
+        while 1:
+            self.screenshot()
+            if self.appear(self.I_GREED_GHOST):
+                sleep(0.7)
+                self.screenshot()
+                if not self.appear(self.I_GREED_GHOST):
+                    continue
+                # 左上角的贪吃鬼
+                while 1:
+                    self.screenshot()
+                    if not self.appear(self.I_GREED_GHOST):
+                        break
+                    if self.appear_then_click(self.I_GREED_GHOST, interval=1):
+                        continue
+                    # if self.appear_then_click(self.I_GREED_GHOST, action=self.C_REWARD_1, interval=1):
+                    #     continue
+                break
+            if self.appear_then_click(self.I_ST_FRAME, interval=1):
+                continue
+            if check_timer.reached():
+                logger.warning('Battle timeout')
+                check_timer.reset()
+            sleep(0.5)
+
+        logger.info("Battle process end")
+        self.check_times(battle)
+        raise TaskEnd('TrueOrochi')
 
 
 
 
     def check_true_orochi(self, screenshot=False) -> bool:
     def check_true_orochi(self, screenshot=False) -> bool:
@@ -30,6 +141,44 @@ class ScriptTask(GameUi, OrochiScriptTask, GeneralBattle, GeneralInvite, General
             self.screenshot()
             self.screenshot()
         return self.appear(self.I_FIND_TS)
         return self.appear(self.I_FIND_TS)
 
 
+    def check_times(self, battle: bool):
+        """
+        后续的次数和时间设置
+        :param battle:
+        :param current_success: 这周的成功次数
+        :return:
+        """
+        now = datetime.now()
+        now_year, now_week_number, now_weekday = now.isocalendar()
+        if battle:
+            next_run = now + self.config.true_orochi.scheduler.success_interval
+        else:
+            next_run = now + self.config.true_orochi.scheduler.fail_interval
+        next_run_year, next_run_week_number, next_run_weekday = next_run.isocalendar()
+        self.set_next_run(task='TrueOrochi', target=next_run)
+        # 如果下次运行的时间是下一周,那么就重置成功次数
+        if now_week_number != next_run_week_number:
+            self.config.true_orochi.true_orochi_config.current_success = 0
+        else:
+            # 如果不是下一周,那么就加一
+            self.config.true_orochi.true_orochi_config.current_success += 1
+
+
+
+
+
+
     def run_true_orochi(self) -> bool:
     def run_true_orochi(self) -> bool:
         pass
         pass
 
 
+
+if __name__ == '__main__':
+    from module.config.config import Config
+    from module.device.device import Device
+    c = Config('test')
+    d = Device(c)
+    t = ScriptTask(c, d)
+    t.screenshot()
+
+    t.run()
+

+ 18 - 0
tasks/TrueOrochi/st/image.json

@@ -106,5 +106,23 @@
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "description"
     "description": "description"
+  },
+  {
+    "itemName": "st_create_room",
+    "imageName": "st_st_create_room.png",
+    "roiFront": "528,482,223,62",
+    "roiBack": "528,482,223,62",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "60体力创建"
+  },
+  {
+    "itemName": "st_frame",
+    "imageName": "st_st_frame.png",
+    "roiFront": "574,441,130,63",
+    "roiBack": "574,441,130,63",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "头像框"
   }
   }
 ]
 ]

BIN
tasks/TrueOrochi/st/st_st_create_room.png


BIN
tasks/TrueOrochi/st/st_st_frame.png