Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (7)
Tags (50)
master
dev
bug_fix
feature
refactor/webapp/main
v2021.10.24
v2020.07.15
v2024.04.26
v2024.04.18
v2023.12.29
v2023.12.25
v0.5.2
v0.5.1
v2023.09.10
v2023.08.28
v2023.08.20
v2023.06.04
v2023.04.19
v2023.03.28.2
v2023.03.28
v2023.03.05
v2022.10.24
v2022.06.26
v2022.01.12
v2021.10.31
v2021.10.28
v0.3.1
master
Branches (7)
Tags (50)
master
dev
bug_fix
feature
refactor/webapp/main
v2021.10.24
v2020.07.15
v2024.04.26
v2024.04.18
v2023.12.29
v2023.12.25
v0.5.2
v0.5.1
v2023.09.10
v2023.08.28
v2023.08.20
v2023.06.04
v2023.04.19
v2023.03.28.2
v2023.03.28
v2023.03.05
v2022.10.24
v2022.06.26
v2022.01.12
v2021.10.31
v2021.10.28
v0.3.1
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (7)
Tags (50)
master
dev
bug_fix
feature
refactor/webapp/main
v2021.10.24
v2020.07.15
v2024.04.26
v2024.04.18
v2023.12.29
v2023.12.25
v0.5.2
v0.5.1
v2023.09.10
v2023.08.28
v2023.08.20
v2023.06.04
v2023.04.19
v2023.03.28.2
v2023.03.28
v2023.03.05
v2022.10.24
v2022.06.26
v2022.01.12
v2021.10.31
v2021.10.28
v0.3.1
exercise.py 8.68 KB
Copy Edit Raw Blame History
LmeSzinc authored 2026年06月12日 01:11 +08:00 . Upd: [TW] enable period remain ocr
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
from datetime import timedelta
from module.config.utils import get_server_last_update
from module.exercise.assets import *
from module.exercise.combat import ExerciseCombat
from module.logger import logger
from module.ocr.ocr import Digit, Ocr, OcrYuv
from module.ui.page import page_exercise
class DatedDuration(Ocr):
def __init__(self, buttons, lang='cnocr', letter=(255, 255, 255), threshold=128, alphabet='0123456789:IDS天日d',
name=None):
super().__init__(buttons, lang=lang, letter=letter, threshold=threshold, alphabet=alphabet, name=name)
def after_process(self, result):
result = super().after_process(result)
result = result.replace('I', '1').replace('D', '0').replace('S', '5')
return result
def ocr(self, image, direct_ocr=False):
"""
Do OCR on a dated duration, such as `10d 01:30:30` or `7日01:30:30`.
Args:
image:
direct_ocr:
Returns:
list, datetime.timedelta: timedelta object, or a list of it.
"""
result_list = super().ocr(image, direct_ocr=direct_ocr)
if not isinstance(result_list, list):
result_list = [result_list]
result_list = [self.parse_time(result) for result in result_list]
if len(self.buttons) == 1:
result_list = result_list[0]
return result_list
@staticmethod
def parse_time(string):
"""
Args:
string (str): `10d 01:30:30` or `7日01:30:30`
Returns:
datetime.timedelta:
"""
import re
result = re.search(r'(\d{1,2})\D?(\d{1,2}):?(\d{2}):?(\d{2})', string)
if result:
result = [int(s) for s in result.groups()]
return timedelta(days=result[0], hours=result[1], minutes=result[2], seconds=result[3])
else:
logger.warning(f'Invalid dated duration: {string}')
return timedelta(days=0, hours=0, minutes=0, seconds=0)
class DatedDurationYuv(DatedDuration, OcrYuv):
pass
OCR_EXERCISE_REMAIN = Digit(OCR_EXERCISE_REMAIN, letter=(173, 247, 74), threshold=128)
OCR_PERIOD_REMAIN = DatedDuration(OCR_PERIOD_REMAIN, letter=(255, 255, 255), threshold=128)
ADMIRAL_TRIAL_HOUR_INTERVAL = {
# "aggressive": [336, 0]
"sun18": [6, 0],
"sun12": [12, 6],
"sun0": [24, 12],
"sat18": [30, 24],
"sat12": [36, 30],
"sat0": [48, 36],
"fri18": [56, 48]
}
class Exercise(ExerciseCombat):
opponent_change_count = 0
remain = 0
preserve = 0
def _new_opponent(self):
logger.info('New opponent')
self.appear_then_click(NEW_OPPONENT)
self.opponent_change_count += 1
logger.attr("Change_opponent_count", self.opponent_change_count)
self.config.set_record(Exercise_OpponentRefreshValue=self.opponent_change_count)
self.ensure_no_info_bar(timeout=3)
def _opponent_fleet_check_all(self):
if self.config.Exercise_OpponentChooseMode != 'leftmost':
super()._opponent_fleet_check_all()
def _opponent_sort(self, method=None):
if method is None:
method = self.config.Exercise_OpponentChooseMode
if method != 'leftmost':
return super()._opponent_sort(method=method)
else:
return [0, 1, 2, 3]
def _exercise_once(self):
"""Execute exercise once.
This method handles exercise refresh and exercise failure.
Returns:
bool: True if success to defeat one opponent. False if failed to defeat any opponent and refresh exhausted.
"""
self._opponent_fleet_check_all()
while 1:
for opponent in self._opponent_sort():
logger.hr(f'Opponent {opponent}', level=2)
success = self._combat(opponent)
if success:
return success
if self.opponent_change_count >= 5:
return False
self._new_opponent()
self._opponent_fleet_check_all()
def _exercise_easiest_else_exp(self):
"""Try easiest first, if unable to beat easiest opponent then switch to max exp opponent and accept the loss.
This method handles exercise refresh and exercise failure.
Returns:
bool: True if success to defeat one opponent. False if failed to defeat any opponent and refresh exhausted.
"""
method = "easiest_else_exp"
restore = self.config.Exercise_LowHpThreshold
threshold = self.config.Exercise_LowHpThreshold
self._opponent_fleet_check_all()
while 1:
opponents = self._opponent_sort(method=method)
logger.hr(f'Opponent {opponents[0]}', level=2)
self.config.override(Exercise_LowHpThreshold=threshold)
success = self._combat(opponents[0])
if success:
self.config.override(Exercise_LowHpThreshold=restore)
return success
else:
if self.opponent_change_count < 5:
logger.info("Cannot beat calculated easiest opponent, refresh")
self._new_opponent()
self._opponent_fleet_check_all()
continue
else:
logger.info("Cannot beat calculated easiest opponent, MAX EXP then")
method = "max_exp"
threshold = 0
def _get_opponent_change_count(self):
"""
Same day, count set to last known change count or 6 i.e. no refresh
New day, count set to 0 i.e. can change up to 5 times
Returns:
int:
"""
record = self.config.Exercise_OpponentRefreshRecord
update = get_server_last_update('00:00')
if record.date() == update.date():
# Same Day
return self.config.Exercise_OpponentRefreshValue
else:
# New Day
self.config.set_record(Exercise_OpponentRefreshValue=0)
return 0
def _get_exercise_reset_remain(self):
"""
Returns:
datetime.timedelta
"""
result = OCR_PERIOD_REMAIN.ocr(self.device.image)
return result
def _get_exercise_strategy(self):
"""
Returns:
int: ExercisePreserve, X times to remain
list, int: Admiral trial time period
"""
if self.config.Exercise_ExerciseStrategy == "aggressive":
preserve = 0
admiral_interval = None
else:
preserve = 5
admiral_interval = ADMIRAL_TRIAL_HOUR_INTERVAL[self.config.Exercise_ExerciseStrategy]
return preserve, admiral_interval
def run(self):
self.ui_ensure(page_exercise)
self.opponent_change_count = self._get_opponent_change_count()
logger.attr("Change_opponent_count", self.opponent_change_count)
logger.attr('Exercise_ExerciseStrategy', self.config.Exercise_ExerciseStrategy)
self.preserve, admiral_interval = self._get_exercise_strategy()
remain_time = OCR_PERIOD_REMAIN.ocr(self.device.image)
logger.info(f'Exercise period remain: {remain_time}')
if admiral_interval is not None and remain_time:
admiral_start, admiral_end = admiral_interval
if admiral_start > int(remain_time.total_seconds() // 3600) >= admiral_end: # set time for getting admiral
logger.info('Reach set time for admiral trial, using all attempts.')
self.preserve = 0
elif int(remain_time.total_seconds() // 3600) < 6: # if not set to "sun18", still depleting at sunday 18pm.
logger.info('Exercise period remain less than 6 hours, using all attempts.')
self.preserve = 0
else:
logger.info(f'Preserve {self.preserve} exercise')
while 1:
self.remain = OCR_EXERCISE_REMAIN.ocr(self.device.image)
if self.remain <= self.preserve:
break
logger.hr(f'Exercise remain {self.remain}', level=1)
if self.config.Exercise_OpponentChooseMode == "easiest_else_exp":
success = self._exercise_easiest_else_exp()
else:
success = self._exercise_once()
if not success:
logger.info('New opponent exhausted')
break
# self.equipment_take_off_when_finished()
# Scheduler
with self.config.multi_set():
self.config.set_record(Exercise_OpponentRefreshValue=self.opponent_change_count)
if self.remain <= self.preserve or self.opponent_change_count >= 5:
self.config.task_delay(server_update=True)
else:
self.config.task_delay(success=False)
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/coding10000/AzurLaneAutoScript.git
git@gitee.com:coding10000/AzurLaneAutoScript.git
coding10000
AzurLaneAutoScript
AzurLaneAutoScript
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /