1
0
mirror of https://gitee.com/sui-feng-cb/AzurLaneAutoScript1 synced 2026-03-21 19:29:18 +08:00
Files
AzurLaneAutoScript/module/equipment/equipment_change.py

153 lines
4.8 KiB
Python
Raw Normal View History

2021-06-30 01:24:30 +08:00
from module.base.button import ButtonGrid
from module.base.decorator import Config
from module.base.utils import *
from module.equipment.assets import *
2021-08-13 03:21:24 +08:00
from module.equipment.equipment import Equipment
from module.ui.scroll import Scroll
2021-06-30 01:24:30 +08:00
EQUIP_INFO_BAR = ButtonGrid(
origin=(723, 111), delta=(94, 0), button_shape=(76, 76), grid_shape=(5, 1), name="EQUIP_INFO_BAR"
)
2021-08-13 03:21:24 +08:00
EQUIPMENT_SCROLL = Scroll(EQUIP_SCROLL, color=(247, 211, 66), name='EQUIP_SCROLL')
2021-06-30 01:24:30 +08:00
SIM_VALUE = 0.90
class EquipmentChange(Equipment):
def __init__(self, config, device):
super().__init__(config, device=device)
self.equip_list = {}
def record_equipment(self):
'''
通过强化界面记录装备
'''
self.device.screenshot()
2021-08-12 05:19:39 +08:00
self.equip_side_navbar_ensure(bottom=1)
2021-06-30 01:24:30 +08:00
for index in range(0, 5):
while 1:
self.device.screenshot()
if self.appear(EQUIPMENT_OPEN, interval=3):
2021-06-30 01:24:30 +08:00
self.device.click(EQUIP_INFO_BAR[(index, 0)])
# time.sleep(1)
continue
if self.appear_then_click(UPGRADE_ENTER, interval=3):
2021-06-30 01:24:30 +08:00
continue
if self.appear(UPGRADE_ENTER_CHECK, interval=3):
2021-06-30 01:24:30 +08:00
self.wait_until_stable(EQUIP_SAVE)
self.equip_list[index] = self.image_area(EQUIP_SAVE)
self.device.click(UPGRADE_QUIT)
self.wait_until_stable(UPGRADE_QUIT)
break
# self.equip_list[index].show()
# print(index)
def equipment_take_on(self):
'''
通过之前记录的装备装备回来
'''
self.device.screenshot()
2021-08-12 05:19:39 +08:00
self.equip_side_navbar_ensure(bottom=2)
2021-06-30 01:24:30 +08:00
self.ensure_no_info_bar(1)
2021-06-30 01:24:30 +08:00
for index in range(0, 5):
enter_button = globals()[
'EQUIP_TAKE_ON_{index}'.format(index=index)]
while 1:
2021-06-30 01:24:30 +08:00
self.device.screenshot()
if self.appear(enter_button, offset=(5,5), threshold=0.90, interval=2):
self.device.click(enter_button)
2021-06-30 01:24:30 +08:00
self._find_equip(index)
self.wait_until_stable(UPGRADE_QUIT)
break
2021-08-13 03:49:29 +08:00
2021-06-30 01:24:30 +08:00
@Config.when(DEVICE_CONTROL_METHOD='minitouch')
def _equipment_swipe(self, distance=190):
# Distance of two commission is 146px
p1, p2 = random_rectangle_vector(
(0, -distance), box=(620, 67, 1154, 692), random_range=(-20, -5, 20, 5))
self.device.drag(p1, p2, segments=2, shake=(25, 0),
point_random=(0, 0, 0, 0), shake_random=(-5, 0, 5, 0))
self.device.sleep(0.3)
self.device.screenshot()
@Config.when(DEVICE_CONTROL_METHOD=None)
def _equipment_swipe(self, distance=300):
# Distance of two commission is 146px
p1, p2 = random_rectangle_vector(
(0, -distance), box=(620, 67, 1154, 692), random_range=(-20, -5, 20, 5))
self.device.drag(p1, p2, segments=2, shake=(25, 0),
point_random=(0, 0, 0, 0), shake_random=(-5, 0, 5, 0))
self.device.sleep(0.3)
self.device.screenshot()
2021-08-13 03:49:29 +08:00
def _equip_equipment(self, point, offset=(100, 100)):
2021-06-30 01:24:30 +08:00
'''
in: 仓库
do退
'''
2021-08-13 03:49:29 +08:00
have_equipped = False
2021-06-30 01:24:30 +08:00
while 1:
self.device.screenshot()
2021-08-13 03:49:29 +08:00
if not have_equipped and self.appear(EQUIPPING_OFF, interval=5):
2021-06-30 01:24:30 +08:00
self.device.click(
Button(button=(point[0], point[1], point[0]+offset[0], point[1]+offset[1]), color=None, area=None))
2021-08-13 03:49:29 +08:00
have_equipped = True
2021-06-30 01:24:30 +08:00
continue
2021-08-13 03:49:29 +08:00
if have_equipped and self.appear_then_click(EQUIP_CONFIRM, interval=2):
2021-06-30 01:24:30 +08:00
continue
if self.info_bar_count():
self.wait_until_stable(UPGRADE_QUIT)
break
def _find_equip(self, index):
'''
in: 仓库
do:
'''
self.wait_until_stable(UPGRADE_QUIT, skip_first_screenshot=False)
2021-06-30 01:24:30 +08:00
self.equipping_set(False)
2021-06-30 01:24:30 +08:00
res = cv2.matchTemplate(np.array(self.device.screenshot()), np.array(
self.equip_list[index]), cv2.TM_CCOEFF_NORMED)
_, sim, _, point = cv2.minMaxLoc(res)
if sim > SIM_VALUE:
2021-08-13 03:49:29 +08:00
self._equip_equipment(point)
2021-06-30 01:24:30 +08:00
return
for _ in range(0, 15):
self._equipment_swipe()
res = cv2.matchTemplate(np.array(self.device.screenshot()), np.array(
self.equip_list[index]), cv2.TM_CCOEFF_NORMED)
_, sim, _, point = cv2.minMaxLoc(res)
if sim > SIM_VALUE:
2021-08-13 03:49:29 +08:00
self._equip_equipment(point)
2021-06-30 01:24:30 +08:00
break
if self.appear(EQUIPMENT_SCROLL_BOTTOM):
print(23333)
break
return