|
|
@@ -2,14 +2,33 @@ import cv2
|
|
|
|
|
|
from cached_property import cached_property
|
|
|
from pathlib import Path
|
|
|
+from enum import Enum
|
|
|
|
|
|
from module.logger import logger
|
|
|
from module.atom.image import RuleImage
|
|
|
from tasks.Hyakkiyakou.slave.hya_device import HyaDevice
|
|
|
+from tasks.Hyakkiyakou.slave.hya_color import HyaColor
|
|
|
from tasks.Hyakkiyakou.assets import HyakkiyakouAssets
|
|
|
|
|
|
|
|
|
-class HyaSlave(HyaDevice, HyakkiyakouAssets):
|
|
|
+class HyaBuff(int, Enum):
|
|
|
+ BUFF_STATE0 = -1 # None
|
|
|
+ BUFF_STATE2 = 0 # 式神减速
|
|
|
+ BUFF_STATE3 = 1 # 砸豆加速
|
|
|
+ BUFF_STATE5 = 2 # 式神冰冻
|
|
|
+ BUFF_STATE6 = 3 # 概率UP
|
|
|
+ BUFF_STATE7 = 4 # 好友UP
|
|
|
+
|
|
|
+ @classmethod
|
|
|
+ def from_index(cls, index: int):
|
|
|
+ for member in cls:
|
|
|
+ if member.value == index:
|
|
|
+ return member
|
|
|
+ raise ValueError(f"No HyaBuff member with value {index}")
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+class HyaSlave(HyaDevice, HyaColor, HyakkiyakouAssets):
|
|
|
"""
|
|
|
主要是用来跟游戏进行交互的
|
|
|
"""
|
|
|
@@ -19,6 +38,11 @@ class HyaSlave(HyaDevice, HyakkiyakouAssets):
|
|
|
UNIT0HUNDRED: list[int] = [146, 647, 18, 25]
|
|
|
DECADE0DECADE: list[int] = [126, 647, 18, 25]
|
|
|
UNIT0DECADE: list[int] = [140, 647, 18, 25]
|
|
|
+ # buff
|
|
|
+ BUFF_ROI1: list[int] = [150, 1, 150, 50]
|
|
|
+ BUFF_ROI2: list[int] = [320, 1, 140, 50]
|
|
|
+ BUFF_ROI3: list[int] = [840, 1, 150, 50]
|
|
|
+ BUFF_ROI4: list[int] = [1100, 1, 140, 50]
|
|
|
|
|
|
@cached_property
|
|
|
def res_r(self) -> list[RuleImage]:
|
|
|
@@ -65,6 +89,24 @@ class HyaSlave(HyaDevice, HyakkiyakouAssets):
|
|
|
self.I_BEAN9,
|
|
|
]
|
|
|
|
|
|
+ @cached_property
|
|
|
+ def buff_state_rois(self) -> list[list[int]]:
|
|
|
+ return [
|
|
|
+ self.BUFF_ROI1,
|
|
|
+ self.BUFF_ROI2,
|
|
|
+ self.BUFF_ROI3,
|
|
|
+ self.BUFF_ROI4
|
|
|
+ ]
|
|
|
+
|
|
|
+ @cached_property
|
|
|
+ def buff_state_images(self) -> list[RuleImage]:
|
|
|
+ return [
|
|
|
+ self.I_HYA_STATE_BUFF02, # 式神减速
|
|
|
+ self.I_HYA_STATE_BUFF03, # 砸豆加速
|
|
|
+ self.I_HYA_STATE_BUFF05, # 冰冻
|
|
|
+ self.I_HYA_STATE_BUFF06, # 概率up
|
|
|
+ self.I_HYA_STATE_BUFF07, # 好友UP
|
|
|
+ ]
|
|
|
|
|
|
def predict_res(self, current: int) -> int:
|
|
|
for i in range(current, current-5, -1):
|
|
|
@@ -101,13 +143,11 @@ class HyaSlave(HyaDevice, HyakkiyakouAssets):
|
|
|
decade_img = self.bean[decade]
|
|
|
decade_img.roi_back = self.DECADE0DECADE
|
|
|
if not self.appear(decade_img):
|
|
|
- print(f'没有匹配十位{decade}')
|
|
|
continue
|
|
|
unit = bean % 10
|
|
|
unit_img = self.bean[unit]
|
|
|
unit_img.roi_back = self.UNIT0DECADE
|
|
|
if self.appear(unit_img):
|
|
|
- print(f'匹配到{bean}')
|
|
|
return bean
|
|
|
for i in range(10):
|
|
|
unit_img = self.bean[i]
|
|
|
@@ -117,6 +157,57 @@ class HyaSlave(HyaDevice, HyakkiyakouAssets):
|
|
|
logger.warning(f'Cannot predict bean, current: {current}')
|
|
|
return current
|
|
|
|
|
|
+ def predict_buff_state(self, pos: int, current: HyaBuff = None) -> HyaBuff:
|
|
|
+ color = self.buff_colors[pos]
|
|
|
+ if self.match_color(color):
|
|
|
+ return HyaBuff.BUFF_STATE0
|
|
|
+ roi = self.buff_state_rois[pos]
|
|
|
+ if current is not None and current != HyaBuff.BUFF_STATE0:
|
|
|
+ current_image = self.buff_state_images[current]
|
|
|
+ current_image.roi_back = roi
|
|
|
+ if self.appear(current_image):
|
|
|
+ return current
|
|
|
+ for i, img in enumerate(self.buff_state_images):
|
|
|
+ img.roi_back = roi
|
|
|
+ if self.appear(img):
|
|
|
+ # int to HyaBuff
|
|
|
+ return HyaBuff.from_index(i)
|
|
|
+ return HyaBuff.BUFF_STATE0
|
|
|
+
|
|
|
+ def recognize_bean_05(self) -> bool:
|
|
|
+ return self.appear(self.I_BEAN05)
|
|
|
+
|
|
|
+ def recognize_bean_10(self) -> bool:
|
|
|
+ return self.appear(self.I_BEAN10)
|
|
|
+
|
|
|
+ def bean_05to10(self):
|
|
|
+ self.swipe(self.S_BEAN_05TO10)
|
|
|
+
|
|
|
+ def bean_10to05(self):
|
|
|
+ self.swipe(self.S_BEAN_10TO05)
|
|
|
+
|
|
|
+ # main process
|
|
|
+ # ------------------------------------------------------------------------------------------------------------------
|
|
|
+
|
|
|
+ def invite_friend(self, same: bool = True):
|
|
|
+ logger.hr('Invite friend', 2)
|
|
|
+ while 1:
|
|
|
+ self.screenshot()
|
|
|
+ if self.appear(self.I_FRIEND_SAME_1) or self.appear(self.I_FRIEND_SAME_2):
|
|
|
+ break
|
|
|
+ if self.appear_then_click(self.I_HINVITE, interval=4):
|
|
|
+ continue
|
|
|
+ if not same:
|
|
|
+ logger.info('Invite different server friend')
|
|
|
+ self.ui_click(self.I_FRIEND_REMOTE_1, self.I_FRIEND_REMOTE_2)
|
|
|
+ while 1:
|
|
|
+ self.screenshot()
|
|
|
+ if not self.appear(self.I_HINVITE):
|
|
|
+ break
|
|
|
+ if self.click(self.C_FRIEND_1, interval=2):
|
|
|
+ continue
|
|
|
+ logger.info('Invite friend done')
|
|
|
+
|
|
|
|
|
|
def covert_rgb():
|
|
|
images_folders: Path = Path(r'E:\Project\OnmyojiAutoScript\tasks\Hyakkiyakou\temp\20240614T214216')
|
|
|
@@ -134,7 +225,6 @@ def test_predict_res():
|
|
|
from module.config.config import Config
|
|
|
from module.device.device import Device
|
|
|
|
|
|
-
|
|
|
c = Config('oas1')
|
|
|
d = Device(c)
|
|
|
hd = HyaSlave(c, d)
|
|
|
@@ -150,7 +240,6 @@ def test_predict_res():
|
|
|
# total time is 36.2ms on my computer /cpu:AMD Ryzen 5 3550H with Radeon Vega Mobile
|
|
|
# 0.362ms per predict_res
|
|
|
|
|
|
-
|
|
|
def test_predict_bean():
|
|
|
import timeit
|
|
|
from module.config.config import Config
|
|
|
@@ -169,15 +258,30 @@ def test_predict_bean():
|
|
|
print(f"执行总的时间: {execution_time * 1000} ms")
|
|
|
# total time is 17.9ms on my computer in 100 times
|
|
|
|
|
|
+def test_predict_buff():
|
|
|
+ import timeit
|
|
|
+ from module.config.config import Config
|
|
|
+ from module.device.device import Device
|
|
|
+
|
|
|
+ c = Config('oas1')
|
|
|
+ d = Device(c)
|
|
|
+ hd = HyaSlave(c, d)
|
|
|
+ img = cv2.imread(r'E:\Project\OnmyojiAutoScript\tasks\Hyakkiyakou\temp\save14\all1718372600237.png')
|
|
|
+ img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
|
|
+ hd.device.image = img
|
|
|
+ print(hd.predict_buff_state(1))
|
|
|
+
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
- # from module.config.config import Config
|
|
|
- # from module.device.device import Device
|
|
|
- #
|
|
|
- # c = Config('oas1')
|
|
|
- # d = Device(c)
|
|
|
- # hd = HyaSlave(c, d)
|
|
|
- # covert_rgb()
|
|
|
+ from module.config.config import Config
|
|
|
+ from module.device.device import Device
|
|
|
+
|
|
|
+ c = Config('oas1')
|
|
|
+ d = Device(c)
|
|
|
+ hd = HyaSlave(c, d)
|
|
|
+ hd.invite_friend(False)
|
|
|
+
|
|
|
# test_predict_res()
|
|
|
- test_predict_bean()
|
|
|
+ # test_predict_bean()
|
|
|
+ # test_predict_buff()
|
|
|
|