diff --git a/module/event_hospital/combat.py b/module/event_hospital/combat.py index 2cb9be468..90452f564 100644 --- a/module/event_hospital/combat.py +++ b/module/event_hospital/combat.py @@ -1,3 +1,5 @@ +import re +from module.config.deep import deep_get from module.base.decorator import run_once from module.base.timer import Timer from module.campaign.campaign_event import CampaignEvent @@ -135,3 +137,63 @@ class HospitalCombat(Combat, HospitalUI, CampaignEvent): out: is_in_clue """ self.combat(balance_hp=False, expected_end=self.hospital_expected_end) + + def detect_low_emotion(self,name='Hospital'): + from module.ocr.ocr import Ocr + from module.notify import handle_notify + from module.exception import ScriptEnd, GamePageUnknownError + from module.handler.assets import LOW_EMOTION_LEFT + EMOTION_TIP_L1=Button(area=(352, 311, 929, 348), color=(), button=(352, 311, 929, 348)) + EMOTION_TIP_L2=Button(area=(352, 350, 929, 387), color=(), button=(352, 350, 929, 387)) + EMOTION_TIP_L3=Button(area=(352, 390, 929, 427), color=(), button=(352, 390, 929, 427)) + # 获取识别结果 + result = Ocr(EMOTION_TIP_L1, lang= 'cnocr').ocr(self.device.image) + result += Ocr(EMOTION_TIP_L2, lang= 'cnocr').ocr(self.device.image) + result += Ocr(EMOTION_TIP_L3, lang= 'cnocr').ocr(self.device.image) + logger.info(result) + if "强制" in result or "继续出击" in result: + logger.warning("=====舰队心情低=====") + + logger.warning(f"{name} emotion recorded is :{self.emotion.fleet_1.current}") + if self.emotion.fleet_1.current > 75: + handle_notify( + self.config.Error_OnePushConfig, + title=f"Alas <{self.config.config_name}> {name} Emotion calculate error ", + content=f"<{self.config.config_name}> emotion recorded is {self.emotion.fleet_1.current},Emotion calculate error" + ) + self.emotion.fleet_1.current = 0 + self.emotion.record() + self.emotion.show() + try: + self.emotion.check_reduce(battle=1) + except ScriptEnd as e:#delay success + logger.hr('Script end') + logger.info(str(e)) + if self.appear_then_click(LOW_EMOTION_LEFT, offset=(30, 30), interval=3):#back + return True + else: + raise GamePageUnknownError(f'LOW EMOTION TIP FOUND, BUT NO LEFT button') + + def event_pt_limit_triggered(self): + """ + Returns: + bool: + + Pages: + in: page_event or page_sp + """ + tasks = ['Hospital'] + pt_limit = int(re.sub(r'[,.\'",。]', '', + str(deep_get(self.config.data, 'EventGeneral.EventGeneral.PtLimit')))) + logger.warning(f'=======ptlimit: {pt_limit}========') + if pt_limit <= 0: + self.get_event_pt() + return False + pt = self.get_event_pt() + logger.attr('Event_PT_limit', f'{pt}/{pt_limit}') + if pt >= pt_limit: + logger.hr(f'Reach event PT limit: {pt_limit}') + self._disable_tasks(tasks) + return True + else: + return False \ No newline at end of file diff --git a/module/event_hospital/hospital.py b/module/event_hospital/hospital.py index 4dd50c8d8..c01251eef 100644 --- a/module/event_hospital/hospital.py +++ b/module/event_hospital/hospital.py @@ -369,12 +369,16 @@ class Hospital(HospitalClue, HospitalCombat): self.device.stuck_record_clear() self.device.click_record_clear() try: + from module.exception import GameStuckError self.combat(balance_hp=False, expected_end=self.hospital_expected_end_combat) self.handle_combat_exit() except ScriptEnd as e: logger.hr('Script end') logger.info(str(e)) break + except GameStuckError as e: + if self.detect_low_emotion(): + return False # Scheduler if self.config.task_switched(): self.config.task_stop() @@ -384,14 +388,18 @@ class Hospital(HospitalClue, HospitalCombat): self.daily_reward_receive() self.clue_enter() + delay = True try: if not self.config.Hospital_mapName.endswith("Q"): self.loop_aside() if not self.config.Hospital_mapName.startswith("0"): self.clue_exit() - self.ptRun() + if not self.ptRun(): + delay = False + # Scheduler - self.config.task_delay(server_update=True) + if delay: + self.config.task_delay(server_update=True) except OilExhausted: self.clue_exit() logger.hr('Triggered stop condition: Oil limit')