mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-23 17:11:42 +00:00
164 lines
4.7 KiB
Python
164 lines
4.7 KiB
Python
from module.combat.combat import *
|
|
from module.exercise.assets import *
|
|
from module.exercise.equipment import ExerciseEquipment
|
|
from module.exercise.hp_daemon import HpDaemon
|
|
from module.exercise.opponent import OpponentChoose, OPPONENT
|
|
from module.ui.assets import BACK_ARROW
|
|
|
|
|
|
class ExerciseCombat(HpDaemon, OpponentChoose, ExerciseEquipment):
|
|
def _in_exercise(self):
|
|
return self.appear(NEW_OPPONENT)
|
|
|
|
def _combat_preparation(self):
|
|
logger.info('Combat preparation')
|
|
while 1:
|
|
self.device.screenshot()
|
|
if self.appear(BATTLE_PREPARATION):
|
|
|
|
self.equipment_take_on()
|
|
pass
|
|
|
|
self.device.click(BATTLE_PREPARATION)
|
|
continue
|
|
|
|
# End
|
|
if self.appear(PAUSE):
|
|
break
|
|
|
|
def _combat_execute(self):
|
|
"""
|
|
Returns:
|
|
bool: True if wins. False if quit.
|
|
"""
|
|
logger.info('Combat execute')
|
|
self.low_hp_confirm_timer = Timer(self.config.LOW_HP_CONFIRM_WAIT)
|
|
self.low_hp_confirm_timer.start()
|
|
show_hp_timer = Timer(5)
|
|
success = True
|
|
end = False
|
|
|
|
while 1:
|
|
self.device.screenshot()
|
|
|
|
# Finish
|
|
if self.appear_then_click(BATTLE_STATUS_S):
|
|
success = True
|
|
end = True
|
|
continue
|
|
if self.appear_then_click(GET_ITEMS_1):
|
|
continue
|
|
if self.appear_then_click(EXP_INFO_S):
|
|
continue
|
|
|
|
# Quit
|
|
if not end:
|
|
if self._at_low_hp(image=self.device.image):
|
|
logger.info('Exercise quit')
|
|
if self.appear_then_click(PAUSE):
|
|
self.device.sleep(0.3)
|
|
continue
|
|
else:
|
|
if show_hp_timer.reached():
|
|
show_hp_timer.reset()
|
|
self._show_hp()
|
|
|
|
if self.appear_then_click(QUIT_CONFIRM, offset=True, interval=1):
|
|
success = False
|
|
end = True
|
|
continue
|
|
|
|
if self.appear_then_click(QUIT_RECONFIRM, offset=True, interval=1):
|
|
self.interval_reset(QUIT_CONFIRM)
|
|
continue
|
|
|
|
# End
|
|
if end and self.appear(BACK_ARROW):
|
|
logger.hr('Combat end')
|
|
break
|
|
|
|
return success
|
|
|
|
def _choose_opponent(self, index):
|
|
"""
|
|
Args:
|
|
index (int): From left to right. 0 to 3.
|
|
"""
|
|
logger.hr('Opponent: %s' % str(index))
|
|
opponent_timer = Timer(1)
|
|
preparation_timer = Timer(1)
|
|
|
|
while 1:
|
|
self.device.screenshot()
|
|
|
|
if opponent_timer.reached() and self._in_exercise():
|
|
self.device.click(OPPONENT[index, 0])
|
|
opponent_timer.reset()
|
|
|
|
if preparation_timer.reached() and self.appear_then_click(EXERCISE_PREPARATION):
|
|
# self.device.sleep(0.3)
|
|
preparation_timer.reset()
|
|
opponent_timer.reset()
|
|
continue
|
|
|
|
# End
|
|
if self.appear(BATTLE_PREPARATION):
|
|
break
|
|
|
|
def _preparation_quit(self):
|
|
logger.info('Preparation quit')
|
|
quit_timer = Timer(1)
|
|
|
|
while 1:
|
|
self.device.screenshot()
|
|
|
|
# End
|
|
if self._in_exercise():
|
|
break
|
|
|
|
if quit_timer.reached() and self.appear(BACK_ARROW):
|
|
# self.device.sleep(1)
|
|
self.device.click(BACK_ARROW)
|
|
quit_timer.reset()
|
|
continue
|
|
|
|
def _combat(self, opponent):
|
|
"""
|
|
Args:
|
|
opponent(int): From left to right. 0 to 3.
|
|
|
|
Returns:
|
|
bool: True if wins. False if challenge times exhausted.
|
|
"""
|
|
self._choose_opponent(opponent)
|
|
|
|
for n in range(1, self.config.OPPONENT_CHALLENGE_TRIAL + 1):
|
|
logger.hr('Try: %s' % n)
|
|
self._combat_preparation()
|
|
success = self._combat_execute()
|
|
if success:
|
|
return success
|
|
|
|
self._preparation_quit()
|
|
return False
|
|
|
|
def equipment_take_off_when_finished(self):
|
|
if self.config.EXERCISE_FLEET_EQUIPMENT is None:
|
|
return False
|
|
if not self.equipment_has_take_on:
|
|
return False
|
|
|
|
self._choose_opponent(0)
|
|
super().equipment_take_off()
|
|
self._preparation_quit()
|
|
|
|
# def equipment_take_on(self):
|
|
# if self.config.EXERCISE_FLEET_EQUIPMENT is None:
|
|
# return False
|
|
# if self.equipment_has_take_on:
|
|
# return False
|
|
#
|
|
# self._choose_opponent(0)
|
|
# super().equipment_take_on()
|
|
# self._preparation_quit()
|