예제 #1
0
def staff_set(handle, name_or_xy, target_xy, direction):
    """
    部署干员,自动检查费用是否足够及部署目标位置是否正确
    :param handle: 窗口句柄
    :param name_or_xy: 部署干员名称或xy坐标
    :param target_xy: 部署位置xy坐标
    :return:  true部署正确,false未知错误
    """
    if isinstance(name_or_xy, str):
        #干员名称
        assert (name_or_xy in config_ark.staff_pic.keys())
        staff_pic = config_ark.staff_pic[name_or_xy]
        i = 0
        while (i < 30):
            i += 1
            position = pic_position(handle,
                                    staff_pic,
                                    globalvar.get_thresh_pic(),
                                    once=True)
            if position != None:
                mouse_drag(handle, (position["result"], target_xy),
                           globalvar.get_drag_speed())
                time.sleep(1)

                if pic_position(handle,
                                config_ark.pic_confirm["bushu_fangxiang"],
                                thresh=globalvar.get_thresh_pic() - 0.1,
                                once=True) != None:
                    set_direction(handle, target_xy, direction)
                    time.sleep(2)
                    return True
            else:
                print("No staff{} detected".format(name_or_xy))

        return False
예제 #2
0
def pic_position(handle, pic_data, thresh=None, findall=False, once=False):
    #寻找图像位于模拟器的像素位置,左上为(0,0)
    if thresh == None:
        thresh = globalvar.get_thresh_pic()
    count = 0
    if once != False and once != True:
        count_max = once
    else:
        count_max = 60
    while (1):
        im = prtsc(handle)
        position = pic_locate(pic_data, im, thresh, findall, rgb_bool=False)
        if position != None or once == True:
            break
        time.sleep(2)
        count += 1
        if count >= count_max:
            if count_max == 60:
                temp_im = Image.fromarray(im)
                temp_im.save(
                    os.path.join(
                        config_ark.IMG_SAVE, 'error_{}.png'.format(
                            time.strftime('%Y-%m-%d-%H-%M-%S',
                                          time.localtime(time.time())))))
                # io.imsave(os.path.join(config_ark.IMG_SAVE,'error_{}.png'.format(
                #     time.strftime('%Y-%m-%d-%H-%M-%S',time.localtime(time.time())))), im)
                raise Exception('模拟器可能卡死')
            else:
                return position
    return position
예제 #3
0
 def _judge(im):
     for keys, pic_data in config_ark.pic_where.items():
         if pic_locate(pic_data, im, globalvar.get_thresh_pic(), False,
                       True) != None:
             current_pos = keys
             return current_pos
     return None
예제 #4
0
 def _judge(im):
     if pic_locate(pic_data,
                   im,
                   globalvar.get_thresh_pic(),
                   rgb_bool=rgb_bool,
                   findall=False) != None:
         return True
     else:
         return False