1
0
mirror of https://gitee.com/sui-feng-cb/AzurLaneAutoScript1 synced 2026-03-12 09:48:20 +08:00
Files
AzurLaneAutoScript/module/equipment/equipment_change.py

157 lines
6.1 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
2021-08-14 23:10:32 +08:00
from module.logger import logger
2021-08-13 03:21:24 +08:00
from module.ui.scroll import Scroll
2021-06-30 01:24:30 +08:00
# Button of 5 equipments
2021-06-30 01:24:30 +08:00
EQUIP_INFO_BAR = ButtonGrid(
origin=(695, 127), delta=(86.25, 0), button_shape=(73, 73), grid_shape=(5, 1), name="EQUIP_INFO_BAR")
# Bottom-left corner of EQUIP_INFO_BAR, to detect whether the grid has an equipment
2021-09-19 20:02:24 +08:00
EQUIPMENT_GRID = ButtonGrid(
origin=(696, 170), delta=(86.25, 0), button_shape=(32, 32), grid_shape=(5, 1), name='EQUIPMENT_GRID')
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):
equip_list = {}
equipping_list = []
2021-08-14 21:48:21 +08:00
def get_equiping_list(self, skip_first_screenshot=True):
'''
Pages:
2021-09-19 20:02:24 +08:00
in: ship's details
'''
2021-08-14 23:10:32 +08:00
logger.info("Get equipping list")
2021-08-14 21:48:21 +08:00
if skip_first_screenshot:
pass
else:
2021-08-14 23:10:32 +08:00
self.device.screenshot()
2021-09-19 20:02:24 +08:00
index = 0
self.equipping_list = []
2021-09-19 20:02:24 +08:00
for button in EQUIPMENT_GRID.buttons:
crop_image = self.image_crop(button)
2022-08-07 17:28:41 +08:00
edge_value = np.mean(np.abs(cv2.Sobel(crop_image, 3, 1, 1)))
# Nothing is 0.15~1
# +1 is 40
# +10 is 46
if edge_value > 10:
self.equipping_list.append(index)
2021-09-19 20:02:24 +08:00
index += 1
2021-08-14 23:10:32 +08:00
logger.info(f"Equipping list: {self.equipping_list}")
2021-06-30 01:24:30 +08:00
2021-08-16 23:04:23 +08:00
def record_equipment(self, index_list=range(0, 5)):
2021-06-30 01:24:30 +08:00
'''
2021-08-13 17:48:44 +08:00
Record equipment through upgrade page
Notice: The equipment icons in the upgrade page are the same size as the icons in the equipment status
2021-06-30 01:24:30 +08:00
'''
2021-08-14 23:10:32 +08:00
logger.info('RECORD EQUIPMENT')
2021-08-12 05:19:39 +08:00
self.equip_side_navbar_ensure(bottom=1)
2021-09-19 20:02:24 +08:00
self.get_equiping_list()
2021-06-30 01:24:30 +08:00
for index in index_list:
if index in self.equipping_list:
2021-08-14 23:10:32 +08:00
logger.info(f'Record {index}')
logger.info('Enter equipment info')
self.ui_click(appear_button=EQUIPMENT_OPEN, click_button=EQUIP_INFO_BAR[(
index, 0)], check_button=UPGRADE_ENTER)
logger.info('Enter upgrade inform')
self.ui_click(click_button=UPGRADE_ENTER,
check_button=UPGRADE_ENTER_CHECK, skip_first_screenshot=True)
logger.info('Save equipment tamplate')
self.equip_list[index] = self.image_crop(EQUIP_SAVE)
logger.info('Quit upgrade inform')
self.ui_click(
click_button=UPGRADE_QUIT, check_button=EQUIPMENT_OPEN, appear_button=UPGRADE_ENTER_CHECK,
skip_first_screenshot=True)
2021-06-30 01:24:30 +08:00
2021-08-14 02:10:36 +08:00
def equipment_take_on(self, index_list=range(0, 5), skip_first_screenshot=True):
2021-06-30 01:24:30 +08:00
'''
2021-08-13 17:48:44 +08:00
Equip the equipment previously recorded
2021-06-30 01:24:30 +08:00
'''
2021-08-14 23:10:32 +08:00
logger.info('Take on equipment')
2021-08-12 05:19:39 +08:00
self.equip_side_navbar_ensure(bottom=2)
2021-06-30 01:24:30 +08:00
for index in index_list:
if index in self.equipping_list:
2021-08-14 23:10:32 +08:00
logger.info(f'Take on {index}')
enter_button = globals()[
'EQUIP_TAKE_ON_{index}'.format(index=index)]
2021-06-30 01:24:30 +08:00
self.ui_click(enter_button, check_button=EQUIPPING_ON,
2021-08-14 23:10:32 +08:00
skip_first_screenshot=skip_first_screenshot, offset=(5, 5))
self.handle_info_bar()
self._find_equip(index)
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()
def _equip_equipment(self, point, offset=(100, 100)):
2021-06-30 01:24:30 +08:00
'''
2021-08-13 17:48:44 +08:00
Equip Equipment then back to ship details
2021-08-14 23:10:32 +08:00
Confirm the popup
2021-08-13 17:48:44 +08:00
Pages:
in: EQUIPMENT STATUS
out: SHIP_SIDEBAR_EQUIPMENT
2021-06-30 01:24:30 +08:00
'''
logger.info('Equip equipment')
button = Button(area=(), color=(), button=(point[0], point[1], point[0] + offset[0], point[1] + offset[1]),
name='EQUIPMENT')
self.ui_click(appear_button=EQUIPPING_OFF, click_button=button, check_button=EQUIP_CONFIRM)
logger.info('Equip confirm')
self.ui_click(click_button=EQUIP_CONFIRM, check_button=SHIP_INFO_EQUIPMENT_CHECK)
2021-06-30 01:24:30 +08:00
def _find_equip(self, index):
'''
2022-06-25 20:04:45 +08:00
Find the equipment previously recorded
2021-08-13 17:48:44 +08:00
Pages:
in: EQUIPMENT STATUS
2021-06-30 01:24:30 +08:00
'''
self.equipping_set(False)
2021-06-30 01:24:30 +08:00
res = cv2.matchTemplate(self.device.screenshot(), np.array(
2021-06-30 01:24:30 +08:00
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(self.device.screenshot(), np.array(
2021-06-30 01:24:30 +08:00
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):
2021-08-14 23:10:32 +08:00
logger.warning('No recorded equipment was found.')
self.ui_back(check_button=globals()[f'EQUIP_TAKE_ON_{index}'], appear_button=EQUIPPING_OFF)
2021-06-30 01:24:30 +08:00
break
return