2023-10-02 04:28:51 +00:00
|
|
|
import re
|
|
|
|
|
2023-07-10 15:36:35 +00:00
|
|
|
from module.logger import logger
|
|
|
|
from module.ocr.ocr import DigitCounter
|
|
|
|
from tasks.base.ui import UI
|
2023-08-20 16:51:10 +00:00
|
|
|
from tasks.dungeon.assets.assets_dungeon_event import (
|
|
|
|
DOUBLE_CALYX_EVENT_TAG,
|
|
|
|
DOUBLE_RELIC_EVENT_TAG,
|
2024-01-12 14:37:20 +00:00
|
|
|
DOUBLE_ROGUE_EVENT_TAG,
|
2023-10-03 12:06:44 +00:00
|
|
|
OCR_DOUBLE_EVENT_REMAIN,
|
|
|
|
OCR_DOUBLE_EVENT_REMAIN_AT_COMBAT,
|
2024-04-10 15:29:25 +00:00
|
|
|
OCR_DOUBLE_ROGUE_REMAIN,
|
2023-08-20 16:51:10 +00:00
|
|
|
)
|
2023-07-10 15:36:35 +00:00
|
|
|
|
|
|
|
|
2023-10-02 04:28:51 +00:00
|
|
|
class DoubleEventOcr(DigitCounter):
|
|
|
|
def after_process(self, result):
|
|
|
|
result = super().after_process(result)
|
2023-10-03 12:06:44 +00:00
|
|
|
# re.sub as last resort, just in case
|
|
|
|
# x12 -> x/12 but x112 does not change
|
|
|
|
result = re.sub(r'(?<!\d)(\d[02-9]*)12$', r'\1/12', result)
|
|
|
|
# x112 -> x/12
|
2023-10-02 04:28:51 +00:00
|
|
|
result = re.sub(r'112$', '/12', result)
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
2023-07-10 15:36:35 +00:00
|
|
|
class DungeonEvent(UI):
|
|
|
|
def has_double_calyx_event(self) -> bool:
|
|
|
|
"""
|
|
|
|
Pages:
|
|
|
|
in: page_guide, Survival_Index, nav at top
|
|
|
|
"""
|
|
|
|
has = self.image_color_count(DOUBLE_CALYX_EVENT_TAG, color=(252, 209, 123), threshold=221, count=50)
|
2023-08-20 16:51:10 +00:00
|
|
|
has |= self.image_color_count(DOUBLE_CALYX_EVENT_TAG, color=(252, 251, 140), threshold=221, count=50)
|
2024-04-26 16:24:15 +00:00
|
|
|
# Anniversary 3x rogue event
|
|
|
|
has |= self.image_color_count(DOUBLE_CALYX_EVENT_TAG, color=(229, 62, 44), threshold=221, count=50)
|
2023-07-10 15:36:35 +00:00
|
|
|
logger.attr('Double calyx', has)
|
|
|
|
return has
|
|
|
|
|
2023-08-20 16:51:10 +00:00
|
|
|
def has_double_relic_event(self) -> bool:
|
|
|
|
"""
|
|
|
|
Pages:
|
|
|
|
in: page_guide, Survival_Index, nav at top
|
|
|
|
"""
|
|
|
|
has = self.image_color_count(DOUBLE_RELIC_EVENT_TAG, color=(252, 209, 123), threshold=221, count=50)
|
|
|
|
has |= self.image_color_count(DOUBLE_RELIC_EVENT_TAG, color=(252, 251, 140), threshold=221, count=50)
|
2024-04-26 16:24:15 +00:00
|
|
|
# Anniversary 3x rogue event
|
|
|
|
has |= self.image_color_count(DOUBLE_RELIC_EVENT_TAG, color=(229, 62, 44), threshold=221, count=50)
|
2023-08-20 16:51:10 +00:00
|
|
|
logger.attr('Double relic', has)
|
|
|
|
return has
|
|
|
|
|
2024-01-12 14:37:20 +00:00
|
|
|
def has_double_rogue_event(self) -> bool:
|
|
|
|
"""
|
|
|
|
Pages:
|
|
|
|
in: page_guide, Survival_Index, nav at top
|
|
|
|
"""
|
|
|
|
has = self.image_color_count(DOUBLE_ROGUE_EVENT_TAG, color=(252, 209, 123), threshold=221, count=50)
|
|
|
|
has |= self.image_color_count(DOUBLE_ROGUE_EVENT_TAG, color=(252, 251, 140), threshold=221, count=50)
|
2024-04-10 15:29:25 +00:00
|
|
|
# Anniversary 3x rogue event
|
|
|
|
has |= self.image_color_count(DOUBLE_ROGUE_EVENT_TAG, color=(229, 62, 44), threshold=221, count=50)
|
2024-01-12 14:37:20 +00:00
|
|
|
logger.attr('Double rogue', has)
|
|
|
|
return has
|
|
|
|
|
2023-10-03 12:06:44 +00:00
|
|
|
def has_double_event_at_combat(self) -> bool:
|
2023-07-10 15:36:35 +00:00
|
|
|
"""
|
|
|
|
Pages:
|
2023-10-03 12:06:44 +00:00
|
|
|
in: COMBAT_PREPARE
|
2023-07-10 15:36:35 +00:00
|
|
|
"""
|
2023-10-03 12:06:44 +00:00
|
|
|
has = self.image_color_count(
|
|
|
|
OCR_DOUBLE_EVENT_REMAIN_AT_COMBAT,
|
2023-11-03 06:02:54 +00:00
|
|
|
color=(231, 188, 103),
|
|
|
|
threshold=240, count=1000
|
2023-10-03 12:06:44 +00:00
|
|
|
)
|
2024-05-01 17:02:34 +00:00
|
|
|
# Anniversary 3x event
|
|
|
|
has |= self.image_color_count(
|
|
|
|
OCR_DOUBLE_EVENT_REMAIN_AT_COMBAT,
|
|
|
|
color=(229, 62, 44),
|
|
|
|
threshold=221, count=50
|
|
|
|
)
|
2023-10-03 12:06:44 +00:00
|
|
|
logger.attr('Double event at combat', has)
|
|
|
|
return has
|
|
|
|
|
|
|
|
def _get_double_event_remain(self, button) -> int:
|
|
|
|
ocr = DoubleEventOcr(button)
|
2023-07-10 15:36:35 +00:00
|
|
|
remain, _, total = ocr.ocr_single_line(self.device.image)
|
2024-05-27 15:32:11 +00:00
|
|
|
# 3 is double relic
|
|
|
|
# 12 is double calyx
|
|
|
|
# 6 is double calyx on beginner account
|
|
|
|
if total not in [3, 6, 12]:
|
2023-07-10 15:36:35 +00:00
|
|
|
logger.warning(f'Invalid double event remain')
|
|
|
|
remain = 0
|
2023-10-03 12:06:44 +00:00
|
|
|
return remain
|
|
|
|
|
|
|
|
def get_double_event_remain(self) -> int:
|
|
|
|
"""
|
|
|
|
Pages:
|
|
|
|
in: page_guide, Survival_Index, selected at the nav with double event
|
|
|
|
"""
|
|
|
|
remain = self._get_double_event_remain(OCR_DOUBLE_EVENT_REMAIN)
|
2023-07-10 15:36:35 +00:00
|
|
|
logger.attr('Double event remain', remain)
|
|
|
|
return remain
|
2023-10-03 12:06:44 +00:00
|
|
|
|
2024-04-10 15:29:25 +00:00
|
|
|
def get_double_rogue_remain(self) -> int:
|
|
|
|
"""
|
|
|
|
Pages:
|
|
|
|
in: page_guide, Survival_Index, selected at the nav with double event
|
|
|
|
"""
|
|
|
|
remain = self._get_double_event_remain(OCR_DOUBLE_ROGUE_REMAIN)
|
|
|
|
logger.attr('Double event remain', remain)
|
|
|
|
return remain
|
|
|
|
|
2023-11-03 06:02:54 +00:00
|
|
|
def get_double_event_remain_at_combat(self) -> int | None:
|
2023-10-03 12:06:44 +00:00
|
|
|
"""
|
|
|
|
Pages:
|
|
|
|
in: COMBAT_PREPARE
|
|
|
|
"""
|
2023-11-03 06:02:54 +00:00
|
|
|
if not self.has_double_event_at_combat():
|
|
|
|
logger.attr('Double event remain at combat', 0)
|
|
|
|
return 0
|
|
|
|
|
|
|
|
ocr = DoubleEventOcr(OCR_DOUBLE_EVENT_REMAIN_AT_COMBAT)
|
|
|
|
for row in ocr.detect_and_ocr(self.device.image):
|
2024-01-01 20:13:40 +00:00
|
|
|
if not ocr.is_format_matched(row.ocr_text):
|
2023-11-03 06:02:54 +00:00
|
|
|
continue
|
|
|
|
remain, _, total = ocr.format_result(row.ocr_text)
|
2024-06-13 15:01:22 +00:00
|
|
|
if total in [3, 6, 12]:
|
2023-11-03 06:02:54 +00:00
|
|
|
logger.attr('Double event remain at combat', remain)
|
|
|
|
return remain
|
|
|
|
logger.warning('Double event appears but failed to get remain')
|
|
|
|
logger.attr('Double event remain at combat', None)
|
|
|
|
return None
|