feat(campaign): 添加低心情检测

- 新增低心情检测功能,识别并处理低心情提示
- 当计算误差过大时再报错
This commit is contained in:
POLAR me 2025-01-01 06:07:30 +08:00
parent 958fcead2d
commit 9811899751
3 changed files with 50 additions and 2 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@ -14,6 +14,10 @@ from module.logger import logger
from module.notify import handle_notify
from module.ui.page import page_campaign
from module.exception import GameStuckError,GamePageUnknownError
from module.handler.assets import LOW_EMOTION_LEFT
from module.base.button import Button
from module.ocr.ocr import Ocr
class CampaignRun(CampaignEvent, ShopStatus):
folder: str
@ -326,7 +330,48 @@ class CampaignRun(CampaignEvent, ShopStatus):
logger.info('Commission notice found')
self.config.task_call('Commission', force_call=True)
self.config.task_stop('Commission notice found')
def detect_low_emotion(self,name):
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("舰队心情低")
fleets = {
"第一舰": "fleet_1",
"第二舰": "fleet_2"
}
for key, fleet in fleets.items():
if key in result:
logger.warning(f"{name} recorded {fleet} is :{getattr(self.campaign.emotion, fleet).current}")
if getattr(self.campaign.emotion, fleet).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}> {fleet} recorded is {getattr(self.campaign.emotion, fleet).current},Emotion calculate error"
)
setattr(getattr(self.campaign.emotion, fleet), 'current', 0)
self.campaign.emotion.record()
self.campaign.emotion.show()
try:
self.campaign.emotion.check_reduce(self.campaign._map_battle)
except ScriptEnd as e:
logger.hr('Script end')
logger.info(str(e))
if self.appear_then_click(LOW_EMOTION_LEFT, offset=(30, 30), interval=3):
break
else:
raise GamePageUnknownError(f'LOW EMOTION TIP FOUND, BUT NO LEFT button')
else:
logger.warning("Game stuck, but not emotion error")
raise GameStuckError(f'Wait too long but not emotion error')
def run(self, name, folder='campaign_main', mode='normal', total=0):
"""
Args:
@ -405,7 +450,9 @@ class CampaignRun(CampaignEvent, ShopStatus):
logger.hr('Script end')
logger.info(str(e))
break
except GameStuckError as e:
self.detect_low_emotion(name)
# Update config
if len(self.campaign.config.modified):
logger.info('Updating config for dashboard')

View File

@ -52,6 +52,7 @@ LOGIN_CHECK = Button(area={'cn': (1214, 653, 1268, 709), 'en': (1214, 653, 1268,
LOGIN_GAME_UPDATE = Button(area={'cn': (700, 471, 873, 529), 'en': (726, 474, 850, 519), 'jp': (704, 475, 867, 525), 'tw': (706, 477, 866, 528)}, color={'cn': (238, 170, 78), 'en': (241, 169, 73), 'jp': (234, 167, 77), 'tw': (235, 169, 80)}, button={'cn': (700, 471, 873, 529), 'en': (726, 474, 850, 519), 'jp': (704, 475, 867, 525), 'tw': (706, 477, 866, 528)}, file={'cn': './assets/cn/handler/LOGIN_GAME_UPDATE.png', 'en': './assets/en/handler/LOGIN_GAME_UPDATE.png', 'jp': './assets/jp/handler/LOGIN_GAME_UPDATE.png', 'tw': './assets/tw/handler/LOGIN_GAME_UPDATE.png'})
LOGIN_RETURN_INFO = Button(area={'cn': (960, 123, 1158, 333), 'en': (960, 123, 1158, 333), 'jp': (960, 123, 1158, 333), 'tw': (960, 123, 1158, 333)}, color={'cn': (170, 185, 166), 'en': (170, 185, 166), 'jp': (170, 185, 166), 'tw': (170, 185, 166)}, button={'cn': (960, 123, 1158, 333), 'en': (960, 123, 1158, 333), 'jp': (960, 123, 1158, 333), 'tw': (960, 123, 1158, 333)}, file={'cn': './assets/cn/handler/LOGIN_RETURN_INFO.png', 'en': './assets/en/handler/LOGIN_RETURN_INFO.png', 'jp': './assets/jp/handler/LOGIN_RETURN_INFO.png', 'tw': './assets/tw/handler/LOGIN_RETURN_INFO.png'})
LOGIN_RETURN_SIGN = Button(area={'cn': (1, 7, 104, 47), 'en': (1, 7, 118, 39), 'jp': (1, 7, 104, 47), 'tw': (1, 7, 104, 47)}, color={'cn': (158, 214, 229), 'en': (176, 223, 236), 'jp': (158, 214, 229), 'tw': (158, 214, 229)}, button={'cn': (1, 7, 104, 47), 'en': (1, 7, 118, 39), 'jp': (1, 7, 104, 47), 'tw': (1, 7, 104, 47)}, file={'cn': './assets/cn/handler/LOGIN_RETURN_SIGN.png', 'en': './assets/en/handler/LOGIN_RETURN_SIGN.png', 'jp': './assets/jp/handler/LOGIN_RETURN_SIGN.png', 'tw': './assets/tw/handler/LOGIN_RETURN_SIGN.png'})
LOW_EMOTION_LEFT = Button(area={'cn': (402, 481, 577, 541), 'en': (402, 481, 577, 541), 'jp': (402, 481, 577, 541), 'tw': (402, 481, 577, 541)}, color={'cn': (166, 167, 170), 'en': (166, 167, 170), 'jp': (166, 167, 170), 'tw': (166, 167, 170)}, button={'cn': (402, 481, 577, 541), 'en': (402, 481, 577, 541), 'jp': (402, 481, 577, 541), 'tw': (402, 481, 577, 541)}, file={'cn': './assets/cn/handler/LOW_EMOTION_LEFT.png', 'en': './assets/cn/handler/LOW_EMOTION_LEFT.png', 'jp': './assets/cn/handler/LOW_EMOTION_LEFT.png', 'tw': './assets/cn/handler/LOW_EMOTION_LEFT.png'})
MAINTENANCE_ANNOUNCE = Button(area={'cn': (923, 141, 990, 186), 'en': (923, 141, 990, 186), 'jp': (923, 141, 990, 186), 'tw': (923, 141, 990, 186)}, color={'cn': (207, 95, 91), 'en': (207, 95, 91), 'jp': (207, 95, 91), 'tw': (207, 95, 91)}, button={'cn': (923, 141, 990, 186), 'en': (923, 141, 990, 186), 'jp': (923, 141, 990, 186), 'tw': (923, 141, 990, 186)}, file={'cn': './assets/cn/handler/MAINTENANCE_ANNOUNCE.png', 'en': './assets/en/handler/MAINTENANCE_ANNOUNCE.png', 'jp': './assets/jp/handler/MAINTENANCE_ANNOUNCE.png', 'tw': './assets/tw/handler/MAINTENANCE_ANNOUNCE.png'})
MAP_AIR_RAID = Button(area={'cn': (350, 447, 1280, 472), 'en': (350, 447, 1280, 472), 'jp': (350, 447, 1280, 472), 'tw': (350, 447, 1280, 472)}, color={'cn': (154, 43, 46), 'en': (154, 43, 46), 'jp': (154, 43, 46), 'tw': (154, 43, 46)}, button={'cn': (350, 447, 1280, 472), 'en': (350, 447, 1280, 472), 'jp': (350, 447, 1280, 472), 'tw': (350, 447, 1280, 472)}, file={'cn': './assets/cn/handler/MAP_AIR_RAID.png', 'en': './assets/en/handler/MAP_AIR_RAID.png', 'jp': './assets/jp/handler/MAP_AIR_RAID.png', 'tw': './assets/tw/handler/MAP_AIR_RAID.png'})
MAP_AMBUSH = Button(area={'cn': (261, 433, 1280, 449), 'en': (261, 433, 1280, 449), 'jp': (261, 433, 1280, 449), 'tw': (261, 433, 1280, 449)}, color={'cn': (161, 41, 43), 'en': (161, 41, 43), 'jp': (161, 41, 43), 'tw': (161, 41, 43)}, button={'cn': (261, 433, 1280, 449), 'en': (261, 433, 1280, 449), 'jp': (261, 433, 1280, 449), 'tw': (261, 433, 1280, 449)}, file={'cn': './assets/cn/handler/MAP_AMBUSH.png', 'en': './assets/en/handler/MAP_AMBUSH.png', 'jp': './assets/jp/handler/MAP_AMBUSH.png', 'tw': './assets/tw/handler/MAP_AMBUSH.png'})