Add: Event SP switch

This commit is contained in:
LmeSzinc 2020-07-28 14:56:17 +08:00
parent 8ac6ab6034
commit a0c17b4533
13 changed files with 63 additions and 44 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

View File

@ -40,6 +40,20 @@ class Switch:
return False
def get(self, main):
"""
Args:
main (ModuleBase):
Returns:
str: Status name or 'unknown'.
"""
for data in self.status_list:
if main.appear(data['check_button'], offset=data['offset']):
return data['status']
return 'unknown'
def set(self, status, main, skip_first_screenshot=True):
"""
Args:
@ -58,15 +72,10 @@ class Switch:
else:
main.device.screenshot()
matched = None
current = 'unknown'
for data in self.status_list:
if main.appear(data['check_button'], offset=data['offset']):
current = data['status']
logger.attr(self.name, current)
matched = data
if current == status:
return changed
current = self.get(main=main)
logger.attr(self.name, current)
if current == status:
return changed
if current == 'unknown':
if warning_show_timer.reached():
@ -75,7 +84,7 @@ class Switch:
continue
for data in self.status_list:
if data['status'] == status:
main.device.click(data['click_button'] if matched is None else matched['click_button'])
if data['status'] == current:
main.device.click(data['click_button'])
main.device.sleep(data['sleep'])
changed = True

View File

@ -6,5 +6,8 @@ from module.base.template import Template
CHAPTER_NEXT = Button(area={'cn': (1216, 362, 1232, 388), 'en': (1216, 362, 1232, 388), 'jp': (1216, 362, 1232, 388)}, color={'cn': (121, 150, 198), 'en': (121, 150, 198), 'jp': (121, 150, 198)}, button={'cn': (1216, 362, 1232, 388), 'en': (1216, 362, 1232, 388), 'jp': (1216, 362, 1232, 388)}, file={'cn': './assets/cn/campaign/CHAPTER_NEXT.png', 'en': './assets/en/campaign/CHAPTER_NEXT.png', 'jp': './assets/jp/campaign/CHAPTER_NEXT.png'})
CHAPTER_PREV = Button(area={'cn': (42, 360, 58, 387), 'en': (42, 360, 58, 387), 'jp': (42, 360, 58, 387)}, color={'cn': (105, 133, 169), 'en': (105, 133, 169), 'jp': (105, 133, 169)}, button={'cn': (42, 360, 58, 387), 'en': (42, 360, 58, 387), 'jp': (42, 360, 58, 387)}, file={'cn': './assets/cn/campaign/CHAPTER_PREV.png', 'en': './assets/en/campaign/CHAPTER_PREV.png', 'jp': './assets/jp/campaign/CHAPTER_PREV.png'})
MODE_CHANGE = Button(area={'cn': (69, 644, 131, 653), 'en': (75, 647, 134, 658), 'jp': (70, 684, 145, 697)}, color={'cn': (216, 114, 114), 'en': (215, 114, 114), 'jp': (220, 133, 133)}, button={'cn': (28, 647, 143, 699), 'en': (22, 646, 148, 699), 'jp': (20, 641, 148, 702)}, file={'cn': './assets/cn/campaign/MODE_CHANGE.png', 'en': './assets/en/campaign/MODE_CHANGE.png', 'jp': './assets/jp/campaign/MODE_CHANGE.png'})
OCR_OIL = Button(area={'cn': (614, 23, 714, 51), 'en': (614, 23, 714, 51), 'jp': (614, 23, 714, 51)}, color={'cn': (64, 65, 79), 'en': (64, 65, 79), 'jp': (64, 65, 79)}, button={'cn': (614, 23, 714, 51), 'en': (614, 23, 714, 51), 'jp': (614, 23, 714, 51)}, file={'cn': './assets/cn/campaign/OCR_OIL.png', 'en': './assets/en/campaign/OCR_OIL.png', 'jp': './assets/jp/campaign/OCR_OIL.png'})
SWITCH_1_HARD = Button(area={'cn': (75, 647, 140, 684), 'en': (75, 647, 140, 684), 'jp': (75, 647, 140, 684)}, color={'cn': (229, 159, 159), 'en': (229, 159, 159), 'jp': (229, 159, 159)}, button={'cn': (75, 647, 140, 684), 'en': (75, 647, 140, 684), 'jp': (75, 647, 140, 684)}, file={'cn': './assets/cn/campaign/SWITCH_1_HARD.png', 'en': './assets/cn/campaign/SWITCH_1_HARD.png', 'jp': './assets/cn/campaign/SWITCH_1_HARD.png'})
SWITCH_1_NORMAL = Button(area={'cn': (81, 645, 144, 682), 'en': (81, 645, 144, 682), 'jp': (81, 645, 144, 682)}, color={'cn': (158, 181, 228), 'en': (158, 181, 228), 'jp': (158, 181, 228)}, button={'cn': (81, 645, 144, 682), 'en': (81, 645, 144, 682), 'jp': (81, 645, 144, 682)}, file={'cn': './assets/cn/campaign/SWITCH_1_NORMAL.png', 'en': './assets/cn/campaign/SWITCH_1_NORMAL.png', 'jp': './assets/cn/campaign/SWITCH_1_NORMAL.png'})
SWITCH_2_EX = Button(area={'cn': (228, 645, 284, 680), 'en': (228, 645, 284, 680), 'jp': (228, 645, 284, 680)}, color={'cn': (254, 152, 61), 'en': (254, 152, 61), 'jp': (254, 152, 61)}, button={'cn': (228, 645, 284, 680), 'en': (228, 645, 284, 680), 'jp': (228, 645, 284, 680)}, file={'cn': './assets/cn/campaign/SWITCH_2_EX.png', 'en': './assets/cn/campaign/SWITCH_2_EX.png', 'jp': './assets/cn/campaign/SWITCH_2_EX.png'})
SWITCH_2_HARD = Button(area={'cn': (232, 647, 297, 684), 'en': (232, 647, 297, 684), 'jp': (232, 647, 297, 684)}, color={'cn': (229, 159, 159), 'en': (229, 159, 159), 'jp': (229, 159, 159)}, button={'cn': (232, 647, 297, 684), 'en': (232, 647, 297, 684), 'jp': (232, 647, 297, 684)}, file={'cn': './assets/cn/campaign/SWITCH_2_HARD.png', 'en': './assets/cn/campaign/SWITCH_2_HARD.png', 'jp': './assets/cn/campaign/SWITCH_2_HARD.png'})

View File

@ -23,7 +23,7 @@ def ensure_chapter_index(name):
else:
if name.isdigit():
return int(name)
elif name in ['a', 'c', 'sp']:
elif name in ['a', 'c', 'sp', 'ex_sp']:
return 1
elif name in ['b', 'd']:
return 2
@ -47,7 +47,9 @@ def separate_name(name):
Returns:
tuple[str]: Campaign_name and stage index in lowercase, Such as ['7', '2'], ['d', '3'], ['sp', '3'].
"""
if '-' in name:
if name == 'sp':
return 'ex_sp', '1'
elif '-' in name:
return name.split('-')
elif name.startswith('sp'):
return 'sp', name[-1]
@ -164,7 +166,7 @@ class CampaignOcr:
self.stage_entrance = {}
buttons = self.campaign_extract_name_image(image)
ocr = Ocr(buttons, name='campaign', letter=(255, 255, 255), threshold=128, alphabet='0123456789ABCDEF-')
ocr = Ocr(buttons, name='campaign', letter=(255, 255, 255), threshold=128, alphabet='0123456789ABCDEFSP-')
result = ocr.ocr(image)
if not isinstance(result, list):
result = [result]

View File

@ -1,13 +1,18 @@
import numpy as np
from module.base.utils import get_color
from module.base.switch import Switch
from module.campaign.assets import *
from module.campaign.campaign_ocr import CampaignOcr, ensure_chapter_index, separate_name
from module.exception import CampaignNameError
from module.logger import logger
from module.ui.ui import UI
from module.exception import CampaignNameError
STAGE_SHOWN_WAIT = (1, 1.2)
SWITCH_OFFSET = (30, 10)
MODE_SWITCH_1 = Switch('Mode_switch_1')
MODE_SWITCH_1.add_status('normal', SWITCH_1_NORMAL, offset=SWITCH_OFFSET, sleep=STAGE_SHOWN_WAIT)
MODE_SWITCH_1.add_status('hard', SWITCH_1_HARD, offset=SWITCH_OFFSET, sleep=STAGE_SHOWN_WAIT)
MODE_SWITCH_2 = Switch('Mode_switch_2')
MODE_SWITCH_2.add_status('hard', SWITCH_2_HARD, offset=SWITCH_OFFSET, sleep=STAGE_SHOWN_WAIT)
MODE_SWITCH_2.add_status('ex', SWITCH_2_EX, offset=SWITCH_OFFSET, sleep=STAGE_SHOWN_WAIT)
class CampaignUI(UI, CampaignOcr):
@ -23,37 +28,35 @@ class CampaignUI(UI, CampaignOcr):
prev_button=CHAPTER_PREV, next_button=CHAPTER_NEXT,
fast=True, skip_first_screenshot=True, step_sleep=STAGE_SHOWN_WAIT, finish_sleep=0)
def campaign_predict_mode(self):
"""
Returns:
str: 'normal' or 'hard'
"""
color = get_color(self.device.image, MODE_CHANGE.area)
if np.max(color) - np.min(color) < 50:
logger.warning(f'Unexpected color: {color}')
index = np.argmax(color) # R, G, B
if index == 0:
return 'normal' # Red button. (214, 117, 115)
elif index == 2:
return 'hard' # Blue button. (115, 146, 214)
else:
logger.warning(f'Unexpected color: {color}')
def campaign_ensure_mode(self, mode='normal'):
"""
Args:
mode (str): 'normal', 'hard'.
mode (str): 'normal', 'hard', 'ex'
Returns:
bool: If mode changed.
"""
if self.campaign_predict_mode() == mode:
return False
switch_2 = MODE_SWITCH_2.get(main=self)
if switch_2 == 'unknown':
if mode == 'ex':
logger.warning('Trying to goto EX, but no EX mode switch')
elif mode == 'normal':
MODE_SWITCH_1.set('hard', main=self)
elif mode == 'hard':
MODE_SWITCH_1.set('normal', main=self)
else:
logger.warning(f'Unknown campaign mode: {mode}')
else:
# Poor click. May unstable.
self.device.click(MODE_CHANGE)
self.handle_stage_icon_spawn()
return True
if mode == 'ex':
MODE_SWITCH_2.set('hard', main=self)
elif mode == 'normal':
MODE_SWITCH_2.set('ex', main=self)
MODE_SWITCH_1.set('hard', main=self)
elif mode == 'hard':
MODE_SWITCH_2.set('ex', main=self)
else:
logger.warning(f'Unknown campaign mode: {mode}')
def campaign_get_entrance(self, name):
"""
@ -86,12 +89,14 @@ class CampaignUI(UI, CampaignOcr):
if mode == 'hard':
self.campaign_ensure_mode('hard')
elif chapter in 'abcd':
elif chapter in 'abcd' or chapter == 'ex_sp':
self.ui_goto_event()
if chapter in 'ab':
self.campaign_ensure_mode('normal')
else:
elif chapter in 'cd':
self.campaign_ensure_mode('hard')
elif chapter == 'ex_sp':
self.campaign_ensure_mode('ex')
self.campaign_ensure_chapter(index=chapter)
elif chapter == 'sp':