Sfoglia il codice sorgente

fix(save): Swipe failure when do kekkai utilize

runhey 3 anni fa
parent
commit
2cd094313b
46 ha cambiato i file con 364 aggiunte e 70 eliminazioni
  1. 1 1
      module/device/handle.py
  2. 88 30
      module/device/method/window.py
  3. 1 1
      tasks/AreaBoss/assets.py
  4. 1 1
      tasks/BondlingFairyland/assets.py
  5. 1 1
      tasks/Component/BaseActivity/assets.py
  6. 1 1
      tasks/Component/GeneralBattle/assets.py
  7. 1 1
      tasks/Component/GeneralBuff/assets.py
  8. 1 1
      tasks/Component/GeneralInvite/assets.py
  9. 1 1
      tasks/Component/GeneralRoom/assets.py
  10. 1 1
      tasks/Component/ReplaceShikigami/assets.py
  11. 1 1
      tasks/Component/SwitchSoul/assets.py
  12. 1 1
      tasks/DemonEncounter/assets.py
  13. 1 1
      tasks/EternitySea/assets.py
  14. 1 1
      tasks/ExperienceYoukai/assets.py
  15. 1 1
      tasks/FallenSun/assets.py
  16. 1 1
      tasks/GameUi/assets.py
  17. 1 1
      tasks/General/assets.py
  18. 1 1
      tasks/GlobalGame/assets.py
  19. 1 1
      tasks/GoldYoukai/assets.py
  20. 1 1
      tasks/GotoMain/assets.py
  21. 1 1
      tasks/Hunt/assets.py
  22. 1 1
      tasks/KekkaiActivation/assets.py
  23. 20 2
      tasks/KekkaiUtilize/assets.py
  24. 74 2
      tasks/KekkaiUtilize/script_task.py
  25. 2 2
      tasks/KekkaiUtilize/utilize/image.json
  26. 47 0
      tasks/KekkaiUtilize/utilize/image_2.json
  27. 9 0
      tasks/KekkaiUtilize/utilize/swipe.json
  28. BIN
      tasks/KekkaiUtilize/utilize/utilize_u_moon_2.png
  29. BIN
      tasks/KekkaiUtilize/utilize/utilize_u_moon_3.png
  30. BIN
      tasks/KekkaiUtilize/utilize/utilize_u_moon_4.png
  31. BIN
      tasks/KekkaiUtilize/utilize/utilize_u_moon_5.png
  32. BIN
      tasks/KekkaiUtilize/utilize/utilize_u_moon_6.png
  33. BIN
      tasks/KekkaiUtilize/utilize/utilize_u_taiko_6.png
  34. 90 0
      tasks/KekkaiUtilize/utils.py
  35. 1 1
      tasks/Nian/assets.py
  36. 1 1
      tasks/Orochi/assets.py
  37. 2 2
      tasks/Orochi/script_task.py
  38. 1 1
      tasks/OrochiMoans/assets.py
  39. 1 1
      tasks/RealmRaid/assets.py
  40. 1 1
      tasks/Restart/assets.py
  41. 1 1
      tasks/RyouToppa/assets.py
  42. 1 1
      tasks/Script/assets.py
  43. 1 1
      tasks/Sougenbi/assets.py
  44. 1 1
      tasks/TrueOrochi/assets.py
  45. 1 1
      tasks/Utils/assets.py
  46. 1 1
      tasks/ui/assets.py

+ 1 - 1
module/device/handle.py

@@ -372,7 +372,7 @@ class Handle:
         scale_rate = window_scale_rate()
         width_before: int = winRect[2] - winRect[0]  # 右x-左x
         height_before: int = winRect[3] - winRect[1]  # 下y - 上y 计算高度
-        width, height = None, None
+        width, height = width_before, height_before
         if abs((width_before * scale_rate) - 1280) < 5:
             width = 1280
         if abs((height_before * scale_rate) - 720) < 5:

+ 88 - 30
module/device/method/window.py

@@ -11,10 +11,12 @@ from cached_property import cached_property
 from win32gui import (GetWindowText, EnumWindows, FindWindow, FindWindowEx,
                       IsWindow, GetWindowRect, GetWindowDC, DeleteObject,
                       SetForegroundWindow, IsWindowVisible, GetDC, GetParent,
-                      EnumChildWindows)
+                      EnumChildWindows, SetForegroundWindow)
 from win32con import (SRCCOPY, DESKTOPHORZRES, DESKTOPVERTRES, WM_LBUTTONUP,
                       WM_LBUTTONDOWN, WM_ACTIVATE, WA_ACTIVE, MK_LBUTTON,
-                      WM_NCHITTEST, WM_SETCURSOR, HTCLIENT, WM_MOUSEMOVE)
+                      WM_NCHITTEST, WM_SETCURSOR, HTCLIENT, WM_MOUSEMOVE,
+                      WM_PARENTNOTIFY, WM_MOUSEACTIVATE, WM_MOUSEWHEEL,
+                      WM_SETFOCUS)
 from win32ui import CreateDCFromHandle, CreateBitmap
 from win32api import GetSystemMetrics, SendMessage, MAKELONG, PostMessage
 from win32con import SRCCOPY
@@ -202,8 +204,8 @@ class Window(Handle):
         :return:
         """
         # 生成的坐标点列表
-        interval: int = 8  # 每次移动的间隔时间
-        numberList: int = int(dist(startPos, endPos) / (1.5 * interval))  # 表示每毫秒移动1.5个像素点, 总的时间除以每个点10ms就得到总的点的个数
+        interval: int = 10  # 每次移动的间隔时间
+        numberList: int = int(dist(startPos, endPos) / (1 * interval))  # 表示每毫秒移动1.5个像素点, 总的时间除以每个点10ms就得到总的点的个数
         le = random.randint(2, 4)  #
         deviation = random.randint(20, 40)  # 幅度
         _type: int = 3
@@ -218,38 +220,44 @@ class Window(Handle):
                                                   deviation=deviation, bias=0.5, type=_type, cbb=0, yhh=20)
 
         # 使用生成的点列表进行拖拽
-        emulator_type = len(self.control_handle_list)
-        if emulator_type == 1:  # 雷电模拟器
-            handleNum = self.control_handle_list[0]
-        elif emulator_type == 2:  # mumu模拟器
+        handleNum = None
+        if self.emulator_family == EmulatorFamily.FAMILY_MUMU:  # mumu模拟器
             handleNum = self.control_handle_list[1]
-        elif emulator_type > 2:  # 夜神模拟器
+        elif self.emulator_family == EmulatorFamily.FAMILY_NOX:  # 夜神模拟器
             handleNum = self.control_handle_list[3]
-        # PostMessage(handleNum, WM_ACTIVATE, WA_ACTIVE, 0)  # 激活窗口
+        elif self.emulator_family == EmulatorFamily.FAMILY_LD:  # 雷电模拟器
+            handleNum = self.control_handle_list[0]
+
+        # 激活窗口
+        # SendMessage(self.control_handle_list[0], WM_PARENTNOTIFY, WM_LBUTTONDOWN, tmpPos)
+        # SendMessage(self.control_handle_list[0], WM_MOUSEACTIVATE, WM_LBUTTONDOWN, tmpPos)
+        # PostMessage(handleNum, WM_ACTIVATE, WA_ACTIVE, 0)
+
         # 先移动到第一个点
         tmpPos = MAKELONG(trace[0][0], trace[0][1])
         SendMessage(handleNum, WM_NCHITTEST, 0, tmpPos)
         SendMessage(handleNum, WM_SETCURSOR, handleNum, MAKELONG(HTCLIENT, WM_LBUTTONDOWN))
-        PostMessage(handleNum, WM_LBUTTONDOWN, MK_LBUTTON, tmpPos)
+        PostMessage(handleNum, WM_LBUTTONDOWN, 0, tmpPos)
+
         # 一点一点移动鼠标
-        for pos in trace[:-3]:
-            tmpPos = MAKELONG(pos[0], pos[1])
-            PostMessage(handleNum, WM_MOUSEMOVE, MK_LBUTTON, tmpPos)
-            time.sleep((interval + random.randint(-2, 2)) / 1000.0)
+        manual_control: int = 3  # 手动控制最后几个点的数量
+        total_len: int = len(trace)
+        for index, pos in enumerate(trace):
+            lparam = MAKELONG(pos[0], pos[1])
+            PostMessage(handleNum, WM_MOUSEMOVE, MK_LBUTTON, lparam)
+            if manual_control >= total_len - index:
+                time.sleep(0.08)
+            else:
+                time.sleep((interval + random.randint(-2, 2)) / 1000.0)
+
         # 最后释放鼠标
-        end_pos_3 = MAKELONG(trace[-3][0], trace[-3][1])
-        end_pos_2 = MAKELONG(trace[-2][0], trace[-2][1])
-        end_pos_1 = MAKELONG(trace[-1][0], trace[-1][1])
-        PostMessage(handleNum, WM_MOUSEMOVE, MK_LBUTTON, end_pos_3)
-        time.sleep(0.08)
-        PostMessage(handleNum, WM_MOUSEMOVE, MK_LBUTTON, end_pos_2)
-        time.sleep(0.08)
-        PostMessage(handleNum, WM_MOUSEMOVE, MK_LBUTTON, end_pos_1)
-        PostMessage(handleNum, WM_LBUTTONUP, 0, end_pos_1)
+        time.sleep(0.05)
+        end_lparam = MAKELONG(trace[-1][0], trace[-1][1])
+        PostMessage(handleNum, WM_LBUTTONUP, 0, end_lparam)
 
     def swipe_vector_window_message2(self, startPos: list, endPos: list) -> None:
         """
-        后台滑动
+        后台滑动, 直线滑动
         :param startPos:
         :param endPos:
         :return:
@@ -298,10 +306,60 @@ class Window(Handle):
         tmpPos = MAKELONG(trace[-1][0], trace[-1][1])
         PostMessage(handleNum, WM_LBUTTONUP, 0, tmpPos)
 
+    def scroll_window_message(self, x: int, y: int, delta: int=-120) -> None:
+        """
+        弃置
+        https://github.com/runhey/OnmyojiAutoScript/issues/43
+        :param x:
+        :param y:
+        :param delta:
+        :return:
+        """
+        wparam = MAKELONG(0, delta)
+        lparam = MAKELONG(x, y)
+        handle_num = None
+        if self.emulator_family == EmulatorFamily.FAMILY_MUMU:  # mumu模拟器
+            handle_num = self.control_handle_list[1]
+
+        elif self.emulator_family == EmulatorFamily.FAMILY_NOX:  # 夜神模拟器
+            handle_num = self.control_handle_list[3]
+        elif self.emulator_family == EmulatorFamily.FAMILY_LD:  # 雷电模拟器
+            handle_num = self.control_handle_list[0]
+
+        SetForegroundWindow(handle_num)
+        time.sleep(2)
+        # SendMessage(handle_num, WM_SETFOCUS, 0, 0)
+        # SendMessage(handle_num, WM_ACTIVATE, WA_ACTIVE, 0)
+        # SendMessage(handle_num, WM_MOUSEACTIVATE, WM_LBUTTONDOWN, lparam)
+
+
+        SendMessage(handle_num, WM_NCHITTEST, 0, lparam)
+        SendMessage(handle_num, WM_SETCURSOR, handle_num, lparam)
+        PostMessage(handle_num, WM_MOUSEMOVE, 0, lparam)
+        self.click_window_message(x, y)
+
+        for i in range(5):
+            PostMessage(handle_num, WM_SETCURSOR, handle_num, lparam)
+            PostMessage(handle_num, WM_MOUSEMOVE, 0, lparam)
+            PostMessage(handle_num, WM_MOUSEWHEEL, wparam, lparam)
+            time.sleep(0.5)
+        # 抄网上的
+        # SendMessage(handle_num, WM_NCHITTEST, 0, lparam)
+
+
+
 
 if __name__ == "__main__":
-    w = Window(config='oas1')
-    img = w.screenshot_window_background()
-    logger.info(img.shape)
-    w.click_window_message(x=759, y=184)
-    # w.swipe_window_message(startPos=[200, 5], endPos=[300, 300])
+    # w = Window(config='oas1')
+    # img = w.screenshot_window_background()
+    # handle = 459852
+    # wparam = MAKELONG(0, -120)
+    # lparam = MAKELONG(300, 300)
+    # PostMessage(handle, WM_MOUSEWHEEL, wparam, lparam)
+
+    from pynput.mouse import Button, Controller
+    mouse = Controller()
+    mouse.position = (505, 505)
+    mouse.scroll(0, -3)
+
+

+ 1 - 1
tasks/AreaBoss/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class AreaBossAssets: 
 

+ 1 - 1
tasks/BondlingFairyland/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class BondlingFairylandAssets: 
 

+ 1 - 1
tasks/Component/BaseActivity/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class BaseActivityAssets: 
 	pass

+ 1 - 1
tasks/Component/GeneralBattle/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class GeneralBattleAssets: 
 

+ 1 - 1
tasks/Component/GeneralBuff/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class GeneralBuffAssets: 
 

+ 1 - 1
tasks/Component/GeneralInvite/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class GeneralInviteAssets: 
 

+ 1 - 1
tasks/Component/GeneralRoom/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class GeneralRoomAssets: 
 

+ 1 - 1
tasks/Component/ReplaceShikigami/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class ReplaceShikigamiAssets: 
 

+ 1 - 1
tasks/Component/SwitchSoul/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class SwitchSoulAssets: 
 

+ 1 - 1
tasks/DemonEncounter/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class DemonEncounterAssets: 
 	pass

+ 1 - 1
tasks/EternitySea/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class EternitySeaAssets: 
 	pass

+ 1 - 1
tasks/ExperienceYoukai/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class ExperienceYoukaiAssets: 
 	pass

+ 1 - 1
tasks/FallenSun/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class FallenSunAssets: 
 	pass

+ 1 - 1
tasks/GameUi/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class GameUiAssets: 
 

+ 1 - 1
tasks/General/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class GeneralAssets: 
 	pass

+ 1 - 1
tasks/GlobalGame/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class GlobalGameAssets: 
 

+ 1 - 1
tasks/GoldYoukai/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class GoldYoukaiAssets: 
 	pass

+ 1 - 1
tasks/GotoMain/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class GotoMainAssets: 
 	pass

+ 1 - 1
tasks/Hunt/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class HuntAssets: 
 	pass

+ 1 - 1
tasks/KekkaiActivation/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class KekkaiActivationAssets: 
 	pass

+ 20 - 2
tasks/KekkaiUtilize/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class KekkaiUtilizeAssets: 
 
@@ -64,7 +64,7 @@ class KekkaiUtilizeAssets:
 	# description 
 	I_U_TAIKO_5 = RuleImage(roi_front=(544,201,59,52), roi_back=(538,179,79,426), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/utilize/utilize_u_taiko_5.png")
 	# description 
-	I_U_TAIKO_6 = RuleImage(roi_front=(0,0,100,100), roi_back=(0,0,100,100), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/utilize/utilize_u_taiko_6.png")
+	I_U_TAIKO_6 = RuleImage(roi_front=(544,265,60,45), roi_back=(533,156,87,450), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/utilize/utilize_u_taiko_6.png")
 	# description 
 	I_U_FISH_3 = RuleImage(roi_front=(551,325,41,33), roi_back=(543,178,69,412), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/utilize/utilize_u_fish_3.png")
 	# description 
@@ -91,8 +91,26 @@ class KekkaiUtilizeAssets:
 	I_U_CONFIRM_SMALL = RuleImage(roi_front=(672,513,131,60), roi_back=(672,513,131,60), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/utilize/utilize_u_confirm_small.png")
 
 
+	# Image Rule Assets
+	# 太阴6 
+	I_U_MOON_6 = RuleImage(roi_front=(548,194,54,54), roi_back=(540,189,68,404), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/utilize/utilize_u_moon_6.png")
+	# description 
+	I_U_MOON_5 = RuleImage(roi_front=(548,205,48,46), roi_back=(540,196,66,407), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/utilize/utilize_u_moon_5.png")
+	# description 
+	I_U_MOON_4 = RuleImage(roi_front=(548,309,49,50), roi_back=(533,167,81,437), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/utilize/utilize_u_moon_4.png")
+	# description 
+	I_U_MOON_3 = RuleImage(roi_front=(549,305,53,53), roi_back=(535,173,77,430), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/utilize/utilize_u_moon_3.png")
+	# description 
+	I_U_MOON_2 = RuleImage(roi_front=(552,313,46,44), roi_back=(542,174,81,437), threshold=0.8, method="Template matching", file="./tasks/KekkaiUtilize/utilize/utilize_u_moon_2.png")
+
+
 	# Ocr Rule Assets
 	# 这个寄养的剩余时间 
 	O_UTILIZE_RES_TIME = RuleOcr(roi=(1140,117,100,30), area=(1140,117,100,30), mode="Duration", method="Default", keyword="", name="utilize_res_time")
 
 
+	# Swipe Rule Assets
+	# 向下滑动 
+	S_U_UP = RuleSwipe(roi_front=(235,419,50,21), roi_back=(225,177,72,21), mode="default", name="u_up")
+
+

+ 74 - 2
tasks/KekkaiUtilize/script_task.py

@@ -13,6 +13,7 @@ from tasks.GameUi.game_ui import GameUi
 from tasks.Utils.config_enum import ShikigamiClass
 from tasks.KekkaiUtilize.assets import KekkaiUtilizeAssets
 from tasks.KekkaiUtilize.config import UtilizeRule, SelectFriendList
+from tasks.KekkaiUtilize.utils import CardClass, target_to_card_class
 from tasks.Component.ReplaceShikigami.replace_shikigami import ReplaceShikigami
 
 
@@ -204,6 +205,7 @@ class ScriptTask(GameUi, ReplaceShikigami, KekkaiUtilizeAssets):
         :param friend:
         :return:
         """
+        logger.info('Switch friend list to %s', friend)
         if friend == SelectFriendList.SAME_SERVER:
             check_image = self.I_UTILIZE_FRIEND_GROUP
         else:
@@ -237,6 +239,75 @@ class ScriptTask(GameUi, ReplaceShikigami, KekkaiUtilizeAssets):
             logger.error('Unknown utilize rule')
             raise ValueError('Unknown utilize rule')
 
+    @cached_property
+    def order_cards(self) -> list[CardClass]:
+        rule = self.config.kekkai_utilize.utilize_config.utilize_rule
+        result = []
+        if rule == UtilizeRule.DEFAULT:
+            result = [CardClass.TAIKO6, CardClass.FISH6, CardClass.TAIKO5, CardClass.FISH5,
+                      CardClass.TAIKO4, CardClass.FISH4, CardClass.TAIKO3, CardClass.FISH3]
+        elif rule == UtilizeRule.FISH:
+            result = [CardClass.FISH6, CardClass.FISH5, CardClass.FISH4, CardClass.FISH3,
+                      CardClass.TAIKO6, CardClass.TAIKO5, CardClass.TAIKO4, CardClass.TAIKO3]
+        elif rule == UtilizeRule.TAIKO:
+            result = [CardClass.TAIKO6, CardClass.TAIKO5, CardClass.TAIKO4, CardClass.TAIKO3,
+                      CardClass.FISH6, CardClass.FISH5, CardClass.FISH4, CardClass.FISH3]
+        else:
+            logger.error('Unknown utilize rule')
+            raise ValueError('Unknown utilize rule')
+        return result
+
+    def run_utilize(self, friend: SelectFriendList = SelectFriendList.SAME_SERVER):
+        """
+        执行寄养
+        :param friend:
+        :param rule:
+        :return:
+        """
+        def _current_select_best(last_best: CardClass or None) -> CardClass | None:
+            """
+            当前选中的最好的卡,(会自动和记录的最好的比较)
+            包括点击这种卡
+            :return: 返回当前选中的最好的卡, 如果什么的都没有,返回None
+            """
+            self.screenshot()
+            target = self.order_targets.find_anyone(self.device.image)
+            if target is None:
+                logger.info('No target card found')
+                return None
+            card_class = target_to_card_class(target)
+            logger.info('Current find best card: %s', target)
+            # 如果当前的卡比记录的最好的卡还要好,那么就更新最好的卡
+            if last_best is not None:
+                last_index = self.order_cards.index(last_best)
+                current_index = self.order_cards.index(card_class)
+                if current_index > last_index:
+                    # 不比上一张卡好就退出不执行操作
+                    logger.info('Current card is not better than last best card')
+                    return last_best
+            logger.info('Current select card: %s', card_class)
+
+            self.appear_then_click(target, interval=0.3)
+            # 验证这张卡 的等级是否一致
+            # while 1:
+            #     self.screenshot()
+            return card_class
+
+        self.switch_friend_list(friend)
+        card_best = None
+        while 1:
+            self.screenshot()
+            current_card = _current_select_best(card_best)
+
+            if current_card is None:
+                break
+            else:
+                card_best = current_card
+
+            # 一直向下滑动
+            self.swipe(self.S_U_UP, interval=0.9)
+            time.sleep(3)
+
 if __name__ == "__main__":
     from module.config.config import Config
     from module.device.device import Device
@@ -245,6 +316,7 @@ if __name__ == "__main__":
     d = Device(c)
     t = ScriptTask(c, d)
 
-    t.switch_friend_list(SelectFriendList.DIFFERENT_SERVER)
-
+    t.swipe(t.S_U_UP, interval=0.9)
+    # t.run_utilize(SelectFriendList.SAME_SERVER)
+    # t.device.scroll_window_message(x=400, y=400)
 

+ 2 - 2
tasks/KekkaiUtilize/utilize/image.json

@@ -56,8 +56,8 @@
   {
     "itemName": "u_taiko_6",
     "imageName": "utilize_u_taiko_6.png",
-    "roiFront": "0,0,100,100",
-    "roiBack": "0,0,100,100",
+    "roiFront": "544,265,60,45",
+    "roiBack": "533,156,87,450",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "description"

+ 47 - 0
tasks/KekkaiUtilize/utilize/image_2.json

@@ -0,0 +1,47 @@
+[
+  {
+    "itemName": "u_moon_6",
+    "imageName": "utilize_u_moon_6.png",
+    "roiFront": "548,194,54,54",
+    "roiBack": "540,189,68,404",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "太阴6"
+  },
+  {
+    "itemName": "u_moon_5",
+    "imageName": "utilize_u_moon_5.png",
+    "roiFront": "548,205,48,46",
+    "roiBack": "540,196,66,407",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "u_moon_4",
+    "imageName": "utilize_u_moon_4.png",
+    "roiFront": "548,309,49,50",
+    "roiBack": "533,167,81,437",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "u_moon_3",
+    "imageName": "utilize_u_moon_3.png",
+    "roiFront": "549,305,53,53",
+    "roiBack": "535,173,77,430",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  },
+  {
+    "itemName": "u_moon_2",
+    "imageName": "utilize_u_moon_2.png",
+    "roiFront": "552,313,46,44",
+    "roiBack": "542,174,81,437",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "description"
+  }
+]

+ 9 - 0
tasks/KekkaiUtilize/utilize/swipe.json

@@ -0,0 +1,9 @@
+[
+  {
+    "itemName": "u_up",
+    "roiFront": "235,419,50,21",
+    "roiBack": "225,177,72,21",
+    "mode": "default",
+    "description": "向下滑动"
+  }
+]

BIN
tasks/KekkaiUtilize/utilize/utilize_u_moon_2.png


BIN
tasks/KekkaiUtilize/utilize/utilize_u_moon_3.png


BIN
tasks/KekkaiUtilize/utilize/utilize_u_moon_4.png


BIN
tasks/KekkaiUtilize/utilize/utilize_u_moon_5.png


BIN
tasks/KekkaiUtilize/utilize/utilize_u_moon_6.png


BIN
tasks/KekkaiUtilize/utilize/utilize_u_taiko_6.png


+ 90 - 0
tasks/KekkaiUtilize/utils.py

@@ -0,0 +1,90 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+from enum import Enum
+
+from module.atom.image import RuleImage
+
+from tasks.KekkaiUtilize.assets import KekkaiUtilizeAssets as KUA
+
+class CardClass(str, Enum):
+
+    UNKNOWN = 'unknown'  # 未知
+
+    TAIKO6 = 'taiko_6'  # 太鼓
+    TAIKO5 = 'taiko_5'
+    TAIKO4 = 'taiko_4'
+    TAIKO3 = 'taiko_3'
+    TAIKO2 = 'taiko_2'
+    TAIKO1 = 'taiko_1'
+    FISH6 = 'fish_6'  # 斗鱼
+    FISH5 = 'fish_5'
+    FISH4 = 'fish_4'
+    FISH3 = 'fish_3'
+    FISH2 = 'fish_2'
+    FISH1 = 'fish_1'
+    ROOM6 = 'room_6'  # 室内伞
+    ROOM5 = 'room_5'
+    ROOM4 = 'room_4'
+    ROOM3 = 'room_3'
+    ROOM2 = 'room_2'
+    ROOM1 = 'room_1'
+    MOON6 = 'moon_6'  # 太阴
+    MOON5 = 'moon_5'
+    MOON4 = 'moon_4'
+    MOON3 = 'moon_3'
+    MOON2 = 'moon_2'
+    MOON1 = 'moon_1'
+
+    OBOROGURUMA6 = 'oboroguruma_6'  # 胧车
+    OBOROGURUMA5 = 'oboroguruma_5'
+    OBOROGURUMA4 = 'oboroguruma_4'
+
+    # 其他的太多了 统称为一个family
+    # Onibiyaki 鬼火烧
+    ONIBIYAKI_FAMILY = 'onibiyaki_family'
+    # Gourd Wine 葫芦酒
+    GOURD_WINE_FAMILY = 'gourd_wine_family'
+    # Frog Chowder 口水蛙
+    FROG_CHOWDER_FAMILY = 'frog_chowder_family'
+    # Moubaa Soup 孟婆汤
+    MOUBAA_SOUP_FAMILY = 'moubaa_soup_family'
+    # Mein Mein Ice 绵绵冰
+    MEIN_MEIN_ICE_FAMILY = 'mein_mein_ice_family'
+    # Town Lute 阎琵琶
+    TOWN_LUTE_FAMILY = 'town_lute_family'
+    # Demon-fusing Lyre 炼妖琴
+    DEMON_FUSING_LYRE_FAMILY = 'demon_fusing_lyre_family'
+    # Thousand Year Flute 千年笛
+    THOUSAND_YEAR_FLUTE_FAMILY = 'thousand_year_flute_family'
+    # Kagura Suzu 神乐铃
+    KAGURA_SUZU_FAMILY = 'kagura_suzu_family'
+    # Heavenly Thunder Drum 天雷鼓
+    HEAVENLY_THUNDER_DRUM_FAMILY = 'heavenly_thunder_drum_family'
+
+
+
+def target_to_card_class(target: RuleImage) -> CardClass:
+    """
+    从匹配到的一张图片中获取卡片的类别
+    !!! 这个取绝于 assets.py 中的 assets 所以请不要修改
+    :param target:
+    :return:
+    """
+    match = {KUA.I_U_TAIKO_6: CardClass.TAIKO6,
+             KUA.I_U_TAIKO_5: CardClass.TAIKO5,
+             KUA.I_U_TAIKO_4: CardClass.TAIKO4,
+             KUA.I_U_TAIKO_3: CardClass.TAIKO3,
+             KUA.I_U_FISH_6: CardClass.FISH6,
+             KUA.I_U_FISH_5: CardClass.FISH5,
+             KUA.I_U_FISH_4: CardClass.FISH4,
+             KUA.I_U_FISH_3: CardClass.FISH3,
+             KUA.I_U_MOON_6: CardClass.MOON6,
+             KUA.I_U_MOON_5: CardClass.MOON5,
+             KUA.I_U_MOON_4: CardClass.MOON4,
+             KUA.I_U_MOON_3: CardClass.MOON3,
+             KUA.I_U_MOON_2: CardClass.MOON2,}
+    try:
+        return match[target]
+    except KeyError:
+        return CardClass.UNKNOWN

+ 1 - 1
tasks/Nian/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class NianAssets: 
 	pass

+ 1 - 1
tasks/Orochi/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class OrochiAssets: 
 

+ 2 - 2
tasks/Orochi/script_task.py

@@ -313,8 +313,8 @@ if __name__ == '__main__':
     d = Device(c)
     t = ScriptTask(c, d)
 
-    t.run()
-
+    # t.run()
+    t.check_layer("拾")
 
 
 

+ 1 - 1
tasks/OrochiMoans/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class OrochiMoansAssets: 
 	pass

+ 1 - 1
tasks/RealmRaid/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class RealmRaidAssets: 
 

+ 1 - 1
tasks/Restart/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class RestartAssets: 
 

+ 1 - 1
tasks/RyouToppa/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class RyouToppaAssets: 
 

+ 1 - 1
tasks/Script/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class ScriptAssets: 
 	pass

+ 1 - 1
tasks/Sougenbi/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class SougenbiAssets: 
 	pass

+ 1 - 1
tasks/TrueOrochi/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class TrueOrochiAssets: 
 

+ 1 - 1
tasks/Utils/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class UtilsAssets: 
 	pass

+ 1 - 1
tasks/ui/assets.py

@@ -5,7 +5,7 @@ from module.atom.swipe import RuleSwipe
 from module.atom.ocr import RuleOcr
 from module.atom.list import RuleList
 
-# This file was automatically generated by module/dev_tools/assets_extract.py.
+# This file was automatically generated by ./dev_tools/assets_extract.py.
 # Don't modify it manually.
 class uiAssets: 
 	pass