Skip to content

Commit

Permalink
检查小月卡, 需要手动开启配置
Browse files Browse the repository at this point in the history
  • Loading branch information
ok-oldking committed Jul 26, 2024
1 parent 65b31e8 commit 457b1bc
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 23 deletions.
15 changes: 15 additions & 0 deletions i18n/en_US/LC_MESSAGES/ok.po
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,18 @@ msgstr ""

msgid "Use OCR"
msgstr ""

msgid "Check Monthly Card"
msgstr ""

msgid "Check for monthly card to avoid interruption of tasks"
msgstr ""

msgid "Monthly Card Config"
msgstr ""

msgid "Monthly Card Time"
msgstr ""

msgid "Your computer's local time when the monthly card will popup, hour in (1-24)"
msgstr ""
Binary file modified i18n/zh_CN/LC_MESSAGES/ok.mo
Binary file not shown.
21 changes: 18 additions & 3 deletions i18n/zh_CN/LC_MESSAGES/ok.po
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#
msgid ""
msgstr ""

msgid ""
msgstr ""
"Project-Id-Version: 1.0\n"
Expand All @@ -9,9 +12,6 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

msgid ""
msgstr ""

msgid "(1-6) Important, Choose which level to farm, lower levels might not produce a echo"
msgstr "(1-6) 重要, 选择你对应世界等级可以产出声骸的难度, 从上到下为1-6"

Expand Down Expand Up @@ -134,3 +134,18 @@ msgstr "高配置CPU请打开,增加拾取声骸准确度,如果配置不够导

msgid "Use OCR"
msgstr "使用文字识别(中英文客户端适用)"

msgid "Check Monthly Card"
msgstr "是否检查月卡"

msgid "Check for monthly card to avoid interruption of tasks"
msgstr "设置避免小月卡弹窗打断任务"

msgid "Monthly Card Config"
msgstr "小月卡设置"

msgid "Monthly Card Time"
msgstr "月卡时间"

msgid "Your computer's local time when the monthly card will popup, hour in (1-24)"
msgstr "几点会弹出月卡提示, 本地计算机时间(1-24)"
2 changes: 1 addition & 1 deletion src/char/BaseChar.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def click_resonance(self, post_sleep=0, has_animation=False, send_click=True):
if not self.resonance_available(current_resonance):
self.logger.debug(f'click_resonance not available break')
break
self.logger.debug(f'click_resonance resonance_available click')
self.logger.debug(f'click_resonance resonance_available click {current_resonance}')
now = time.time()
if now - last_click > 0.1:
if ((current_resonance == 0) and send_click) or last_op == 'resonance':
Expand Down
10 changes: 0 additions & 10 deletions src/combat/CombatCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,6 @@ def find_target_enemy(self):
logger.debug(f'find_target_enemy {target_enemy} {time.time() - start}')
return target_enemy is not None

def handle_monthly_card(self):
monthly_card = self.find_one('monthly_card', threshold=0.8)
if monthly_card is not None:
self.click(monthly_card)
self.sleep(2)
self.click(monthly_card)
self.sleep(1)
logger.debug(f'check_monthly_card {monthly_card}')
return monthly_card is not None

def in_combat(self, rechecked=False):
if self.in_liberation or self.recent_liberation():
self.last_combat_check = time.time()
Expand Down
9 changes: 1 addition & 8 deletions src/task/BaseCombatTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,6 @@ def click(self, x=-1, y=-1, move_back=False, name=None, interval=-1):
y = self.height_of_screen(0.5)
return super().click(x, y, move_back, name, interval)

def wait_in_team_and_world(self, time_out=10, raise_if_not_found=True):
return self.wait_until(self.in_team_and_world, time_out=time_out, raise_if_not_found=raise_if_not_found)

def in_team_and_world(self):
return self.in_team()[
0] # and self.find_one(f'gray_book_button', threshold=0.7, canny_lower=50, canny_higher=150)

def get_current_char(self):
for char in self.chars:
if char.is_current_char:
Expand Down Expand Up @@ -222,7 +215,7 @@ def send_key_and_wait_f(self, direction, raise_if_not_found, time_out, running=F
else:
logger.warning(f"can't find the f to enter")
return False

remaining = time.time() - start

if self.handle_claim_button():
Expand Down
75 changes: 75 additions & 0 deletions src/task/BaseWWTask.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import re
import time
from datetime import datetime, timedelta

from ok.config.ConfigOption import ConfigOption
from ok.feature.FindFeature import FindFeature
Expand All @@ -13,12 +15,29 @@
}, config_description={
'Use OCR': 'Turn on if your CPU is Powerful for more accuracy'})

monthly_card_config_option = ConfigOption('Monthly Card Config', {
'Check Monthly Card': False,
'Monthly Card Time': 4
}, config_description={
'Check Monthly Card': 'Check for monthly card to avoid interruption of tasks',
'Monthly Card Time': 'Your computer\'s local time when the monthly card will popup, hour in (1-24)'
})


class BaseWWTask(BaseTask, FindFeature, OCR):

def __init__(self):
super().__init__()
self.pick_echo_config = self.get_config(pick_echo_config_option)
self.monthly_card_config = self.get_config(monthly_card_config_option)
self.next_monthly_card_start = 0

def validate(self, key, value):
message = self.validate_config(key, value)
if message:
return False, message
else:
return True, None

@property
def absorb_echo_text(self):
Expand All @@ -38,6 +57,21 @@ def get_feature_by_lang(self, feature):
else:
return None

def set_check_monthly_card(self):
if self.monthly_card_config.get('Check Monthly Card'):
now = datetime.now()
hour = self.monthly_card_config.get('Monthly Card Time')
# Calculate the next 4 o'clock in the morning
next_four_am = now.replace(hour=hour, minute=0, second=0, microsecond=0)
if now >= next_four_am:
next_four_am += timedelta(days=1)
next_monthly_card_start_date_time = next_four_am - timedelta(seconds=30)
# Subtract 1 minute from the next 4 o'clock in the morning
self.next_monthly_card_start = next_monthly_card_start_date_time.timestamp()
logger.info('set next monthly card start time to {}'.format(next_monthly_card_start_date_time))
else:
self.next_monthly_card_start = 0

@property
def f_search_box(self):
f_search_box = self.get_box_by_name('pick_up_f')
Expand All @@ -59,6 +93,47 @@ def find_f_with_text(self, target_text=None):
return None
return f

def check_for_monthly_card(self):
if self.next_monthly_card_start > 0:
if time.time() > self.next_monthly_card_start:
start = time.time()
logger.info(f'start waiting for monthly card')
f4_open = False
if self.in_team_and_world():
logger.info(f'in team send f4 to wait')
self.send_key('f4')
f4_open = True
monthly_card = self.wait_until(self.handle_monthly_card, time_out=120, raise_if_not_found=False)
logger.info(f'wait monthly card end {monthly_card}')
if f4_open:
self.send_key('esc')
self.sleep(2)
logger.info(f'wait monthly card close f4')
cost = time.time() - start
self.set_check_monthly_card()
return cost
return 0

def sleep(self, timeout):
return super().sleep(timeout - self.check_for_monthly_card())

def wait_in_team_and_world(self, time_out=10, raise_if_not_found=True):
return self.wait_until(self.in_team_and_world, time_out=time_out, raise_if_not_found=raise_if_not_found)

def in_team_and_world(self):
return self.in_team()[
0] # and self.find_one(f'gray_book_button', threshold=0.7, canny_lower=50, canny_higher=150)

def handle_monthly_card(self):
monthly_card = self.find_one('monthly_card', threshold=0.8)
if monthly_card is not None:
self.click(monthly_card)
self.sleep(2)
self.click(monthly_card)
self.sleep(1)
logger.debug(f'check_monthly_card {monthly_card}')
return monthly_card is not None

@property
def game_lang(self):
if '鸣潮' in self.hwnd_title:
Expand Down
1 change: 1 addition & 0 deletions src/task/FarmEchoTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self):
self.last_drop = False

def run(self):
self.set_check_monthly_card()
self.handler.post(self.mouse_reset, 0.01)
if not self.in_team()[0]:
self.log_error('must be in game world and in teams', notify=True)
Expand Down
1 change: 1 addition & 0 deletions src/task/FarmWorldBossTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def teleport_to_heal(self):
self.sleep(2)

def run(self):
self.set_check_monthly_card()
if not self.check_main():
self.log_error('must be in game world and in teams', notify=True)
self.handler.post(self.mouse_reset, 0.01)
Expand Down
3 changes: 2 additions & 1 deletion src/task/SkipDialogTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
from ok.logging.Logger import get_logger
from ok.ocr.OCR import OCR
from ok.task.TriggerTask import TriggerTask
from src.task.BaseWWTask import BaseWWTask

logger = get_logger(__name__)


class AutoDialogTask(TriggerTask, FindFeature, OCR):
class AutoDialogTask(TriggerTask, BaseWWTask, FindFeature, OCR):

def __init__(self):
super().__init__()
Expand Down

0 comments on commit 457b1bc

Please sign in to comment.