Prechádzať zdrojové kódy

Merge branch 'master' of http://192.168.50.108:37829/pcacc/yys_auto

pcacc 4 mesiacov pred
rodič
commit
aad5e0a131
4 zmenil súbory, kde vykonal 92 pridanie a 43 odobranie
  1. 7 4
      dongri_task.py
  2. 16 33
      scriptBase/comon.py
  3. 61 5
      scriptBase/imgFind.py
  4. 8 1
      templates/index_dongri.html

+ 7 - 4
dongri_task.py

@@ -907,8 +907,11 @@ class task_paticipateInTeam(dongri_task):
         basic_operate.go_outside()
         if waitClickImg_noWait_withBool(check_img.conflits, 2, 1) == False:
             return False
-        if waitClickImg_noWait_withBool(monster_img.participate, 1, 1) == False:
-            return False
+        if waitClickImg_noWait_withBool(monster_img.participate, 1, 1, True) == False:
+            yys_dragAuto(check_img.move_down)
+            myTimeSleep_big()
+            if waitClickImg_noWait_withBool(monster_img.participate, 1, 1, True) == False:
+                return False
         
         while True:
             if waitClickImg_noWait_withBool(monster_img.line1, 0.1, 1) == False:
@@ -1170,7 +1173,7 @@ if __name__ == '__main__':
     #task_fightMonster(False, False,False).run()
     #task_checkHelp().run()
     #task_checkStoreRoom().run()
-    task_activity_lianmeng().run()
+    #task_activity_lianmeng().run()
     #task_fight_yongbing(True).run()
     #task_collect([4,3,2,1]).run()
     #task_train("upgrade").run()
@@ -1182,5 +1185,5 @@ if __name__ == '__main__':
     #task_collect(3).run()
     #task_collect(4).run()
     #task_returnAllLine().run()
-    #task_paticipateInTeam().run()
+    task_paticipateInTeam().run()
     #task_fight_jina(True).run()

+ 16 - 33
scriptBase/comon.py

@@ -46,13 +46,13 @@ def binarize_image(image):
     return threshold
 
 
-def waitFindImg(imgPath, waitTime, preWaitTime):
+def waitFindImg(imgPath, waitTime, preWaitTime, isCV=False):
     if preWaitTime > 0:
         myTimeSleep(preWaitTime)
     #sleep 0.2s per times
     curTime = 0
     while waitTime == -1 or curTime < waitTime:
-        ret, pos_cur = pcacc_img.find_imgs(imgPath)
+        ret, pos_cur = pcacc_img.find_imgs(imgPath, isCV)
         if ret:
             return ret, pos_cur
         else:
@@ -61,35 +61,18 @@ def waitFindImg(imgPath, waitTime, preWaitTime):
     
     return False, None
 
-def waitFindImg_withBool(imgPath, waitTime, preWaitTime):
-    ret, pos = waitFindImg(imgPath, waitTime, preWaitTime)
+def waitFindImg_withBool(imgPath, waitTime, preWaitTime, isCV=False):
+    ret, pos = waitFindImg(imgPath, waitTime, preWaitTime, isCV)
     return ret
 
-def waitFindImgPosition(imgPath, waitTime, preWaitTime):
-    if preWaitTime > 0:
-        myTimeSleep(preWaitTime)
-    #sleep 0.2s per times
-    curTime = 0
-    while waitTime == -1 or curTime < waitTime:
-        ret, pos_cur = pcacc_img.find_img_position(imgPath)
-        if ret:
-            return ret, pos_cur
-        else:
-            myTimeSleep(0.2)
-            curTime = curTime + 0.2
-    return False, None
-
-def waitFindImgPosition_withBool(imgPath, waitTime, preWaitTime):
-    ret, pos = waitFindImgPosition(imgPath, waitTime, preWaitTime)
-    return ret
 
-def waitClickImg_noWait(imgPath, waitTime, preWaitTime):
+def waitClickImg_noWait(imgPath, waitTime, preWaitTime, isCV=False):
     if preWaitTime > 0:
         myTimeSleep(preWaitTime)
     #sleep 0.2s per times
     curTime = 0
     while waitTime == -1 or curTime < waitTime:
-        ret, pos_cur = pcacc_img.find_imgs(imgPath)
+        ret, pos_cur = pcacc_img.find_imgs(imgPath, isCV)
         if ret:
             pcacc_mouse.click(pos_cur[0], pos_cur[1])
             myTimeSleep(0.5)
@@ -99,8 +82,8 @@ def waitClickImg_noWait(imgPath, waitTime, preWaitTime):
             curTime = curTime + 0.2
     return False, (-1, -1)
 
-def waitClickImg_noWait_withBool(imgPath, waitTime, preWaitTime):
-    ret, pos = waitClickImg_noWait(imgPath, waitTime, preWaitTime)
+def waitClickImg_noWait_withBool(imgPath, waitTime, preWaitTime, isCV=False):
+    ret, pos = waitClickImg_noWait(imgPath, waitTime, preWaitTime, isCV)
     return ret
 
 
@@ -130,34 +113,34 @@ def waitclickMultiImg(imgArr, waitTime, preWaitTime):
     return False, (-1, -1)
 
 
-def waitClickImg(imgPath, waitTime, preWaitTime):
+def waitClickImg(imgPath, waitTime, preWaitTime, isCV=False):
     if preWaitTime > 0:
         myTimeSleep(preWaitTime)
     #sleep 0.2s per times
     curTime = 0
     while waitTime == -1 or curTime < waitTime:
-        ret, pos_cur = pcacc_img.find_imgs(imgPath)
+        ret, pos_cur = pcacc_img.find_imgs(imgPath, isCV)
         if ret:
             pcacc_mouse.move_mouse(pos_cur[0], pos_cur[1])
-            ret, pos_cur2 = pcacc_img.find_imgs(imgPath)
+            ret, pos_cur2 = pcacc_img.find_imgs(imgPath, isCV)
             if ret:
                 pcacc_mouse.click(pos_cur2[0], pos_cur2[1])
             else:
                 pcacc_mouse.click(pos_cur[0], pos_cur[1])
             myTimeSleep(0.5)
-            ret, pos_cur = pcacc_img.find_imgs(imgPath)
+            ret, pos_cur = pcacc_img.find_imgs(imgPath, isCV)
             if ret == False:
                 return True, pos_cur
             
             pcacc_mouse.move_mouse(pos_cur[0], pos_cur[1])
-            ret, pos_cur2 = pcacc_img.find_imgs(imgPath)
+            ret, pos_cur2 = pcacc_img.find_imgs(imgPath, isCV)
             if ret:
                 pcacc_mouse.click(pos_cur2[0], pos_cur2[1])
             else:
                 pcacc_mouse.click(pos_cur[0], pos_cur[1])
 
             myTimeSleep(0.5)
-            ret, pos_cur = pcacc_img.find_imgs(imgPath)
+            ret, pos_cur = pcacc_img.find_imgs(imgPath, isCV)
             if ret == False:
                 return True, pos_cur
             else:
@@ -167,8 +150,8 @@ def waitClickImg(imgPath, waitTime, preWaitTime):
             curTime = curTime + 0.2
     return False, (-1, -1)
 
-def waitClickImg_withBool(imgPath, waitTime, preWaitTime):
-    ret, pos = waitClickImg(imgPath, waitTime, preWaitTime)
+def waitClickImg_withBool(imgPath, waitTime, preWaitTime, isCV=False):
+    ret, pos = waitClickImg(imgPath, waitTime, preWaitTime, isCV)
     return ret
 
 def myTimeSleep(curTime , FunStatus=None):

+ 61 - 5
scriptBase/imgFind.py

@@ -133,7 +133,7 @@ class pcacc_img:
     def find_all_img(image_path):
 
         # 设置查找的置信度(confidence)阈值,范围从0到1,默认为0.999
-        confidence_threshold = 0.85
+        confidence_threshold = 0.95
 
         # 查找模糊图片在屏幕上的位置
         positions = pyautogui.locateAllOnScreen(image_path, confidence=confidence_threshold)
@@ -142,6 +142,43 @@ class pcacc_img:
             return False, []
 
         return True, positions
+    
+    @staticmethod
+    def find_img_cv(image_path, region=None):
+        # 读取模板和屏幕截图
+        confidence_threshold = 0.95
+
+        template = cv2.imread(image_path, cv2.IMREAD_COLOR)
+        screenshot = cv2.cvtColor(np.array(pyautogui.screenshot(region=region)), cv2.COLOR_RGB2BGR)
+        
+        # 模板匹配
+        result = cv2.matchTemplate(screenshot, template, cv2.TM_CCOEFF_NORMED)
+        _, max_val, _, max_loc = cv2.minMaxLoc(result)
+        
+        if max_val > confidence_threshold:  # 置信度阈值
+            left, top = max_loc  # 左上角坐标
+            width, height = template.shape[1], template.shape[0]  # 模板宽高
+
+            #mid
+            mid_left = int(left + width / 4)
+            mid_right = int(left + width / 4 * 3)
+            mid_top = int(top + height / 4)
+            mid_bottom = int(top + height / 4 * 3)
+
+            #want_position
+            want_x = random.randint(mid_left, mid_right)
+            want_y = random.randint(mid_top, mid_bottom)
+
+            #dst_position
+            dst_x = random.randint(int(want_x - width / 3), int(want_x + width / 3))
+            dst_y = random.randint(int(want_y - height / 3), int(want_y + height / 3))
+            
+
+            print(f"{image_path}:({dst_x}, {dst_y})")
+            return True, (dst_x, dst_y)
+        else:
+            print(f"{image_path} cv图片未找到")
+            return False, (-1, -1)
 
     @staticmethod
     def find_img(image_path):
@@ -154,7 +191,6 @@ class pcacc_img:
 
         if position is not None:
             # 图片找到了,获取图片的中心点坐标
-
             #mid
             mid_left = int(position.left + position.width / 4)
             mid_right = int(position.left + position.width / 4 * 3)
@@ -183,13 +219,33 @@ class pcacc_img:
             if ret:
                 return ret, pos
         return False, None
+    
+    @staticmethod
+    def find_imgArr_cv(imgArr):
+        for cur_img in imgArr:
+            ret, pos = pcacc_img.find_img_cv(cur_img)
+            if ret:
+                return ret, pos
+        return False, None
 
     @staticmethod
-    def find_imgs(images):
+    def find_imgs(images, is_cv=False):
+        if is_cv:
+            return pcacc_img.find_imgs_cv(images)
+        else:
+            if isinstance(images, str):
+                return pcacc_img.find_img(images)
+            elif isinstance(images, (list, tuple)):
+                return pcacc_img.find_imgArr(images)
+            else:
+                raise ValueError("Invalid input type for 'images' parameter.")
+        
+    @staticmethod
+    def find_imgs_cv(images):
         if isinstance(images, str):
-            return pcacc_img.find_img(images)
+            return pcacc_img.find_img_cv(images)
         elif isinstance(images, (list, tuple)):
-            return pcacc_img.find_imgArr(images)
+            return pcacc_img.find_imgArr_cv(images)
         else:
             raise ValueError("Invalid input type for 'images' parameter.")
 

+ 8 - 1
templates/index_dongri.html

@@ -281,7 +281,14 @@
         }
 
         function isWorkingHours() {
-            return false;
+            // 检查是否为本地域名
+            const isLocalDomain = window.location.hostname === 'localhost' || 
+                                window.location.hostname === '127.0.0.1' || 
+                                window.location.hostname === '';
+            
+            if (isLocalDomain) {
+                return false;
+            }
             const now = new Date();
             const day = now.getDay(); // 0是周日,1是周一,...,6是周六
             const hours = now.getHours();