StarRailCopilot/module/equipment/equipment.py
LmeSzinc be00742c3c Add: 适配第一章, 修复大量bug
- 修复处理夜间委托时, 出现递归调用的问题
- 增加红脸出击确认的功能
- 增加了透视识别错误图片保存的开关
- 修复了地图太小时, 透视识别报错的问题
- 修复了相机位于地图外时, 透视识别出错的问题
- 修复了离开退役时, 会连击的问题
- 修复了同时出现低心情和船坞已满弹窗时, 卡住的问题
- 更新了一键退役实装后的安全点击的位置
- 修复了换装滑动失败时, 卡住的问题
- 修复了关闭自动收获后, 出现委托完成的提示是, 进图卡住的问题
- 修复了, 无正在跑的委托时, 报错的问题
2020-04-11 15:26:42 +08:00

160 lines
4.8 KiB
Python

from module.base.timer import Timer
from module.equipment.assets import *
from module.handler.info_bar import InfoBarHandler
from module.logger import logger
from module.ui.assets import BACK_ARROW
SWIPE_DISTANCE = 250
SWIPE_RANDOM_RANGE = (-40, -20, 40, 20)
class Equipment(InfoBarHandler):
equipment_has_take_on = False
def _view_swipe(self, distance):
while 1:
SWIPE_CHECK.load_color(self.device.image)
self.device.swipe(vector=(distance, 0), box=SWIPE_AREA.area, random_range=SWIPE_RANDOM_RANGE,
padding=0, duration=(0.1, 0.12))
self.device.sleep(0.3)
self.device.screenshot()
if SWIPE_CHECK.match(self.device.image):
continue
if self.appear(EQUIPMENT_OPEN) and not SWIPE_CHECK.match(self.device.image):
break
def _view_next(self):
self._view_swipe(distance=-SWIPE_DISTANCE)
def _view_prev(self):
self._view_swipe(distance=SWIPE_DISTANCE)
def _equip_enter(self, enter):
enter_timer = Timer(5)
while 1:
if enter_timer.reached():
self.device.long_click(enter, duration=(1.5, 1.7))
enter_timer.reset()
self.device.screenshot()
# End
if self.appear(EQUIPMENT_OPEN):
break
def _equip_exit(self, out):
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
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
if confirm_timer.reached() and self.appear_then_click(EQUIP_OFF_CONFIRM, offset=10):
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')
self._equip_enter(enter)
for index in '9'.join([str(x) for x in fleet if x > 0]):
index = int(index)
if index == 9:
self._view_next()
else:
self._equip_take_off_one()
self._equip_exit(out)
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')
self._equip_enter(enter)
for index in '9'.join([str(x) for x in fleet if x > 0]):
index = int(index)
if index == 9:
self._view_next()
else:
self._equip_take_on_one(index=index)
self._equip_exit(out)
self.equipment_has_take_on = True