2020-06-01 00:20:13 +00:00
|
|
|
from module.base.button import ButtonGrid
|
2020-03-28 17:22:46 +00:00
|
|
|
from module.base.timer import Timer
|
|
|
|
from module.equipment.assets import *
|
2020-05-15 06:18:14 +00:00
|
|
|
from module.handler.info_handler import InfoHandler
|
2020-03-28 17:22:46 +00:00
|
|
|
from module.logger import logger
|
|
|
|
from module.ui.assets import BACK_ARROW
|
2020-06-01 00:20:13 +00:00
|
|
|
from module.base.utils import color_similarity_2d
|
|
|
|
import numpy as np
|
2020-03-28 17:22:46 +00:00
|
|
|
|
2020-04-06 17:52:47 +00:00
|
|
|
SWIPE_DISTANCE = 250
|
2020-03-28 17:22:46 +00:00
|
|
|
SWIPE_RANDOM_RANGE = (-40, -20, 40, 20)
|
2020-06-01 00:20:13 +00:00
|
|
|
DETAIL_SIDEBAR = ButtonGrid(
|
|
|
|
origin=(21, 118), delta=(0, 94.5), button_shape=(60, 75), grid_shape=(1, 5), name='DETAIL_SIDEBAR')
|
2020-03-28 17:22:46 +00:00
|
|
|
|
|
|
|
|
2020-05-15 06:18:14 +00:00
|
|
|
class Equipment(InfoHandler):
|
2020-03-28 17:22:46 +00:00
|
|
|
equipment_has_take_on = False
|
|
|
|
|
2020-06-01 00:20:13 +00:00
|
|
|
def _view_swipe(self, distance, check_button=EQUIPMENT_OPEN):
|
|
|
|
swipe_timer = Timer(3, count=5)
|
|
|
|
SWIPE_CHECK.load_color(self.device.image)
|
2020-04-06 17:52:47 +00:00
|
|
|
while 1:
|
2020-05-08 11:07:06 +00:00
|
|
|
if not swipe_timer.started() or swipe_timer.reached():
|
|
|
|
swipe_timer.reset()
|
|
|
|
self.device.swipe(vector=(distance, 0), box=SWIPE_AREA.area, random_range=SWIPE_RANDOM_RANGE,
|
|
|
|
padding=0, duration=(0.1, 0.12))
|
2020-04-06 17:52:47 +00:00
|
|
|
|
Add: 适配第一章, 修复大量bug
- 修复处理夜间委托时, 出现递归调用的问题
- 增加红脸出击确认的功能
- 增加了透视识别错误图片保存的开关
- 修复了地图太小时, 透视识别报错的问题
- 修复了相机位于地图外时, 透视识别出错的问题
- 修复了离开退役时, 会连击的问题
- 修复了同时出现低心情和船坞已满弹窗时, 卡住的问题
- 更新了一键退役实装后的安全点击的位置
- 修复了换装滑动失败时, 卡住的问题
- 修复了关闭自动收获后, 出现委托完成的提示是, 进图卡住的问题
- 修复了, 无正在跑的委托时, 报错的问题
2020-04-11 07:23:51 +00:00
|
|
|
self.device.screenshot()
|
|
|
|
if SWIPE_CHECK.match(self.device.image):
|
|
|
|
continue
|
|
|
|
|
2020-06-01 00:20:13 +00:00
|
|
|
if self.appear(check_button, offset=(30, 30)) and not SWIPE_CHECK.match(self.device.image):
|
2020-04-06 17:52:47 +00:00
|
|
|
break
|
|
|
|
|
2020-06-01 00:20:13 +00:00
|
|
|
def equip_view_next(self, check_button=EQUIPMENT_OPEN):
|
|
|
|
self._view_swipe(distance=-SWIPE_DISTANCE, check_button=check_button)
|
2020-03-28 17:22:46 +00:00
|
|
|
|
2020-06-01 00:20:13 +00:00
|
|
|
def equip_view_prev(self, check_button=EQUIPMENT_OPEN):
|
|
|
|
self._view_swipe(distance=SWIPE_DISTANCE, check_button=check_button)
|
2020-03-28 17:22:46 +00:00
|
|
|
|
2020-06-01 00:20:13 +00:00
|
|
|
def equip_enter(self, click_button, check_button=EQUIPMENT_OPEN, long_click=True):
|
2020-03-28 17:22:46 +00:00
|
|
|
enter_timer = Timer(5)
|
|
|
|
|
|
|
|
while 1:
|
|
|
|
if enter_timer.reached():
|
2020-06-01 00:20:13 +00:00
|
|
|
if long_click:
|
|
|
|
self.device.long_click(click_button, duration=(1.5, 1.7))
|
|
|
|
else:
|
|
|
|
self.device.click(click_button)
|
2020-03-28 17:22:46 +00:00
|
|
|
enter_timer.reset()
|
|
|
|
|
|
|
|
self.device.screenshot()
|
|
|
|
|
|
|
|
# End
|
2020-06-01 00:20:13 +00:00
|
|
|
if self.appear(check_button):
|
2020-03-28 17:22:46 +00:00
|
|
|
break
|
|
|
|
|
2020-06-01 00:20:13 +00:00
|
|
|
def equip_quit(self, out):
|
2020-03-28 17:22:46 +00:00
|
|
|
quit_timer = Timer(3)
|
|
|
|
|
|
|
|
while 1:
|
|
|
|
self.device.screenshot()
|
|
|
|
|
|
|
|
# End
|
|
|
|
if self.appear(out):
|
|
|
|
break
|
|
|
|
|
|
|
|
if quit_timer.reached() and self.appear(BACK_ARROW):
|
|
|
|
# self.device.sleep(1)
|
|
|
|
self.device.click(BACK_ARROW)
|
|
|
|
self.device.sleep((0.2, 0.3))
|
|
|
|
quit_timer.reset()
|
|
|
|
continue
|
|
|
|
|
2020-06-01 00:20:13 +00:00
|
|
|
def _equip_sidebar_click(self, index):
|
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
index (int):
|
|
|
|
5 for retrofit.
|
|
|
|
4 for enhancement.
|
|
|
|
3 for limit break.
|
|
|
|
2 for gem / equipment.
|
|
|
|
1 for detail.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
bool: if changed.
|
|
|
|
"""
|
|
|
|
current = 0
|
|
|
|
total = 0
|
|
|
|
|
|
|
|
for idx, button in enumerate(DETAIL_SIDEBAR.buttons()):
|
|
|
|
image = np.array(self.device.image.crop(button.area))
|
|
|
|
if np.sum(image[:, :, 0] > 235) > 100:
|
|
|
|
current = idx + 1
|
|
|
|
total = idx + 1
|
|
|
|
continue
|
|
|
|
if np.sum(color_similarity_2d(image, color=(140, 162, 181)) > 221) > 100:
|
|
|
|
total = idx + 1
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
if not current:
|
|
|
|
logger.warning('No ship details sidebar active.')
|
|
|
|
if total == 4:
|
|
|
|
current = 5 - current
|
|
|
|
elif total == 5:
|
|
|
|
current = 6 - current
|
|
|
|
else:
|
|
|
|
logger.warning('Ship details sidebar total count error.')
|
|
|
|
|
|
|
|
logger.attr('Detail_sidebar', f'{current}/{total}')
|
|
|
|
if current == index:
|
|
|
|
return False
|
|
|
|
|
|
|
|
self.device.click(DETAIL_SIDEBAR[0, total - index])
|
|
|
|
return True
|
|
|
|
|
|
|
|
def equip_sidebar_ensure(self, index, skip_first_screenshot=True):
|
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
index (int):
|
|
|
|
5 for retrofit.
|
|
|
|
4 for enhancement.
|
|
|
|
3 for limit break.
|
|
|
|
2 for gem / equipment.
|
|
|
|
1 for detail.
|
|
|
|
"""
|
|
|
|
while 1:
|
|
|
|
if skip_first_screenshot:
|
|
|
|
skip_first_screenshot = False
|
|
|
|
else:
|
|
|
|
self.device.screenshot()
|
|
|
|
|
|
|
|
if self._equip_sidebar_click(index):
|
|
|
|
self.device.sleep((0.3, 0.5))
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
|
2020-03-28 17:22:46 +00:00
|
|
|
def _equip_take_off_one(self):
|
|
|
|
bar_timer = Timer(5)
|
|
|
|
off_timer = Timer(5)
|
|
|
|
confirm_timer = Timer(5)
|
|
|
|
|
|
|
|
while 1:
|
|
|
|
self.device.screenshot()
|
|
|
|
if bar_timer.reached() and not self.appear(EQUIP_1, offset=10):
|
|
|
|
self.device.click(EQUIPMENT_OPEN)
|
|
|
|
bar_timer.reset()
|
|
|
|
continue
|
|
|
|
|
|
|
|
if off_timer.reached() and not self.info_bar_count() and self.appear_then_click(EQUIP_OFF, offset=10):
|
|
|
|
off_timer.reset()
|
|
|
|
continue
|
|
|
|
|
2020-04-13 15:00:19 +00:00
|
|
|
if confirm_timer.reached() and self.handle_popup_confirm():
|
2020-03-28 17:22:46 +00:00
|
|
|
confirm_timer.reset()
|
|
|
|
continue
|
|
|
|
|
|
|
|
# End
|
|
|
|
# if self.handle_info_bar():
|
|
|
|
# break
|
|
|
|
if off_timer.started() and self.info_bar_count():
|
|
|
|
break
|
|
|
|
|
|
|
|
def equipment_take_off(self, enter, out, fleet):
|
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
enter (Button): Long click to edit equipment.
|
|
|
|
out (Button): Button to confirm exit success.
|
|
|
|
fleet (list[int]): list of equipment record. [3, 1, 1, 1, 1, 1]
|
|
|
|
"""
|
|
|
|
logger.hr('Equipment take off')
|
2020-06-01 00:20:13 +00:00
|
|
|
self.equip_enter(enter)
|
2020-03-28 17:22:46 +00:00
|
|
|
|
|
|
|
for index in '9'.join([str(x) for x in fleet if x > 0]):
|
|
|
|
index = int(index)
|
|
|
|
if index == 9:
|
2020-06-01 00:20:13 +00:00
|
|
|
self.equip_view_next()
|
2020-03-28 17:22:46 +00:00
|
|
|
else:
|
|
|
|
self._equip_take_off_one()
|
|
|
|
|
2020-06-01 00:20:13 +00:00
|
|
|
self.equip_quit(out)
|
2020-03-28 17:22:46 +00:00
|
|
|
self.equipment_has_take_on = False
|
|
|
|
|
|
|
|
def _equip_take_on_one(self, index):
|
|
|
|
bar_timer = Timer(5)
|
|
|
|
on_timer = Timer(5)
|
|
|
|
|
|
|
|
while 1:
|
|
|
|
self.device.screenshot()
|
|
|
|
|
|
|
|
if bar_timer.reached() and not self.appear(EQUIP_1, offset=10):
|
|
|
|
self.device.click(EQUIPMENT_OPEN)
|
|
|
|
# self.device.sleep(0.3)
|
|
|
|
bar_timer.reset()
|
|
|
|
continue
|
|
|
|
|
|
|
|
if on_timer.reached() and self.appear(EQUIP_1, offset=10) and not self.info_bar_count():
|
|
|
|
if index == 1:
|
|
|
|
self.device.click(EQUIP_1)
|
|
|
|
elif index == 2:
|
|
|
|
self.device.click(EQUIP_2)
|
|
|
|
elif index == 3:
|
|
|
|
self.device.click(EQUIP_3)
|
|
|
|
|
|
|
|
on_timer.reset()
|
|
|
|
continue
|
|
|
|
|
|
|
|
# End
|
|
|
|
# if self.handle_info_bar():
|
|
|
|
# break
|
|
|
|
if on_timer.started() and self.info_bar_count():
|
|
|
|
break
|
|
|
|
|
|
|
|
def equipment_take_on(self, enter, out, fleet):
|
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
enter (Button): Long click to edit equipment.
|
|
|
|
out (Button): Button to confirm exit success.
|
|
|
|
fleet (list[int]): list of equipment record. [3, 1, 1, 1, 1, 1]
|
|
|
|
"""
|
|
|
|
logger.hr('Equipment take on')
|
2020-06-01 00:20:13 +00:00
|
|
|
self.equip_enter(enter)
|
2020-03-28 17:22:46 +00:00
|
|
|
|
|
|
|
for index in '9'.join([str(x) for x in fleet if x > 0]):
|
|
|
|
index = int(index)
|
|
|
|
if index == 9:
|
2020-06-01 00:20:13 +00:00
|
|
|
self.equip_view_next()
|
2020-03-28 17:22:46 +00:00
|
|
|
else:
|
|
|
|
self._equip_take_on_one(index=index)
|
|
|
|
|
2020-06-01 00:20:13 +00:00
|
|
|
self.equip_quit(out)
|
2020-03-28 17:22:46 +00:00
|
|
|
self.equipment_has_take_on = True
|