自动使用全部理智药选项

This commit is contained in:
zhbaor 2024-12-03 09:37:13 +08:00
parent 258c83aeda
commit dfc28cd1a2
5 changed files with 80 additions and 48 deletions

View file

@ -8,12 +8,12 @@ from mower.solvers.navigation.utils import generate_name
from mower.utils import config from mower.utils import config
from mower.utils import typealias as tp from mower.utils import typealias as tp
from mower.utils.datetime import get_server_weekday from mower.utils.datetime import get_server_weekday
from mower.utils.email import drop_template, send_message from mower.utils.email import drop_template, notify, send_message
from mower.utils.graph import SceneGraphSolver
from mower.utils.image import cropimg, diff_ratio, loadimg from mower.utils.image import cropimg, diff_ratio, loadimg
from mower.utils.log import logger from mower.utils.log import logger
from mower.utils.path import get_path from mower.utils.path import get_path
from mower.utils.recognize import Scene from mower.utils.recognize import Scene
from mower.utils.solver import BaseSolver
from mower.utils.vector import va from mower.utils.vector import va
drop_data = {} drop_data = {}
@ -27,29 +27,40 @@ for i in get_path("@install/ui/public/depot").iterdir():
drop_digits = [generate_name(str(i), font_size=28, style="dark") for i in range(10)] drop_digits = [generate_name(str(i), font_size=28, style="dark") for i in range(10)]
class OperationSolver(SceneGraphSolver): class OperationSolver(BaseSolver):
"不是标准Solver容器,接入调度器需使用OperationManager"
solver_name = "代理作战" solver_name = "代理作战"
def set_stop_time(self): def set_stop_time(self):
if self.operation_start_time is None: "计算刷关停止时间"
operation_time = timedelta(minutes=3)
else:
operation_time = datetime.now() - self.operation_start_time
if self.scheduler_stop_time is None: if self.scheduler_stop_time is None:
self.stop_time = None self.stop_time = None
else: else:
if self.operation_start_time is None:
operation_time = timedelta(minutes=3)
else:
operation_time = datetime.now() - self.operation_start_time
logger.info(f"作战时间:{operation_time}")
self.stop_time = self.scheduler_stop_time - operation_time self.stop_time = self.scheduler_stop_time - operation_time
def check_timeout(self):
"检查是否应该提前退出"
if self.stop_time and datetime.now() > self.stop_time:
self.timeout = True
return True
return False
def run(self): def run(self):
# 计算刷关时间和超时时间 # 计算刷关时间和超时时间
self.operation_start_time = None self.operation_start_time = None # 最后一次刷关的开始时间
self.set_stop_time() self.set_stop_time()
self.sanity_drain = False self.sanity_drain = False # 退出原因:理智耗尽
self.timeout = False self.timeout = False # 退出原因:时间不够
self.drop_list: list[dict[str, int]] = [] self.drop_list: list[dict[str, int]] = [] # 掉落列表
self.drop_recog_complete = False self.drop_recog_complete = False # 本轮作战识别是否完成
return super().run() return super().run()
def number(self, scope: tp.Scope, height: Optional[int] = None): def number(self, scope: tp.Scope, height: Optional[int] = None):
@ -105,38 +116,41 @@ class OperationSolver(SceneGraphSolver):
logger.debug(f"{drop_result=}") logger.debug(f"{drop_result=}")
self.drop_list.append(drop_result) self.drop_list.append(drop_result)
self.drop_recog_complete = True
def ope_start(self):
self.operation_start_time = datetime.now()
self.drop_recog_complete = False
self.tap("ope_start")
def transition(self): def transition(self):
if (scene := self.scene()) == Scene.OPERATOR_BEFORE: if (scene := self.scene()) == Scene.OPERATOR_BEFORE:
if self.check_timeout():
return True
if config.recog.gray[65][1333] < 200: if config.recog.gray[65][1333] < 200:
self.sleep() self.sleep()
return return
if config.recog.gray[907][1600] < 127: if config.recog.gray[907][1600] < 127:
self.tap((1776, 908)) self.tap((1776, 908))
return return
repeat = self.number(((1520, 890), (1545, 930)), 28) if self.number(((1520, 890), (1545, 930)), 28) > 1:
if repeat > 1:
self.tap((1500, 910)) self.tap((1500, 910))
self.tap((1500, 801)) self.tap((1500, 801))
return return
self.operation_start_time = datetime.now() self.ope_start()
self.drop_recog_complete = False
self.tap("ope_start")
elif scene == Scene.OPERATOR_SELECT: elif scene == Scene.OPERATOR_SELECT:
if self.stop_time and datetime.now() > self.stop_time:
self.timeout = True
return True
self.tap((1655, 781)) self.tap((1655, 781))
elif scene == Scene.OPERATOR_FINISH: elif scene == Scene.OPERATOR_FINISH:
self.set_stop_time()
if self.drop_animation(): if self.drop_animation():
self.solver_update_before_transition = False self.solver_update_before_transition = False
return return
self.set_stop_time()
self.tap((310, 330), interval=0) self.tap((310, 330), interval=0)
if not self.drop_recog_complete: if not self.drop_recog_complete:
self.drop_recog() self.drop_recog()
elif scene == Scene.OPERATOR_FAILED: elif scene == Scene.OPERATOR_FAILED:
self.tap((310, 330)) notify("代理作战失败!", "ERROR")
return True
elif scene == Scene.OPERATOR_ONGOING: elif scene == Scene.OPERATOR_ONGOING:
if self.find("ope_agency_fail"): if self.find("ope_agency_fail"):
self.tap((121, 79)) self.tap((121, 79))
@ -145,6 +159,13 @@ class OperationSolver(SceneGraphSolver):
elif scene == Scene.OPERATOR_GIVEUP: elif scene == Scene.OPERATOR_GIVEUP:
self.tap("fight/give_up") self.tap("fight/give_up")
elif scene == Scene.OPERATOR_RECOVER_POTION: elif scene == Scene.OPERATOR_RECOVER_POTION:
confirm = (1635, 865)
if config.conf.use_all_medicine:
if self.check_timeout():
return True
logger.info("自动使用全部理智药")
self.tap(confirm)
return
use_medicine = False use_medicine = False
# 先看设置是否吃药 # 先看设置是否吃药
if config.conf.maa_expiring_medicine: if config.conf.maa_expiring_medicine:
@ -152,27 +173,27 @@ class OperationSolver(SceneGraphSolver):
use_medicine = get_server_weekday() >= 5 use_medicine = get_server_weekday() >= 5
else: else:
use_medicine = True use_medicine = True
# 再看是否有药可吃 # 再看是否有快要过期的药可吃
if use_medicine: if use_medicine:
img = cropimg(config.recog.img, ((1015, 515), (1170, 560))) img = cropimg(config.recog.hsv, ((1015, 515), (1170, 560)))
img = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
img = cv2.inRange(img, (170, 0, 0), (174, 255, 255)) img = cv2.inRange(img, (170, 0, 0), (174, 255, 255))
count = cv2.countNonZero(img) count = cv2.countNonZero(img)
logger.debug(f"{count=}") logger.debug(f"{count=}")
use_medicine = count > 3000 use_medicine = count > 3000
if use_medicine: if use_medicine:
if self.check_timeout():
return True
logger.info("使用即将过期的理智药") logger.info("使用即将过期的理智药")
self.tap((1635, 865)) self.tap(confirm)
return return
else: self.sanity_drain = True
self.sanity_drain = True return True
return True
elif scene == Scene.OPERATOR_RECOVER_ORIGINITE: elif scene == Scene.OPERATOR_RECOVER_ORIGINITE:
self.sanity_drain = True self.sanity_drain = True
return True return True
elif scene == Scene.OPERATOR_ELIMINATE: elif scene == Scene.OPERATOR_ELIMINATE:
if self.find("ope_agency_lock"): if self.find("ope_agency_lock"):
logger.error("无法代理当期剿灭") notify("无法代理当期剿灭", "ERROR")
return True return True
if self.find("1800"): if self.find("1800"):
logger.info("本周剿灭已完成") logger.info("本周剿灭已完成")
@ -180,12 +201,10 @@ class OperationSolver(SceneGraphSolver):
if pos := self.find("ope_elimi_agency"): if pos := self.find("ope_elimi_agency"):
self.tap(pos) self.tap(pos)
return return
self.operation_start_time = datetime.now() self.ope_start()
self.drop_recog_complete = False
self.tap("ope_start")
elif scene == Scene.OPERATOR_ELIMINATE_AGENCY: elif scene == Scene.OPERATOR_ELIMINATE_AGENCY:
if self.find("can_not_use_ope"): if self.find("can_not_use_ope"):
logger.warning("当期剿灭代理获取合成玉数量为0") notify("当期剿灭代理获取合成玉数量为0", "WARNING")
return True return True
self.tap("ope_elimi_agency_confirm", interval=2) self.tap("ope_elimi_agency_confirm", interval=2)
elif scene == Scene.UPGRADE: elif scene == Scene.UPGRADE:

View file

@ -262,6 +262,8 @@ class RegularTaskPart(ConfModel):
"日常任务" "日常任务"
maa_gap: float = 3 maa_gap: float = 3
"日常任务间隔" "日常任务间隔"
use_all_medicine: bool = False
"自动使用全部理智药"
maa_expiring_medicine: bool = True maa_expiring_medicine: bool = True
"自动使用将要过期(约3天)的理智药" "自动使用将要过期(约3天)的理智药"
exipring_medicine_on_weekend: bool = False exipring_medicine_on_weekend: bool = False

View file

@ -1 +1 @@
.sss-container[data-v-2dffb781]{display:flex;width:100%;gap:8px}.wrapper[data-v-2dffb781]{white-space:pre-wrap;-webkit-user-select:text;user-select:text}.title[data-v-2dffb781]{font-size:18px;font-weight:500;margin-bottom:6px}p[data-v-d479d5bf]{margin:0 0 10px}.misc-container[data-v-d479d5bf]{display:flex;align-items:center;gap:12px}.header[data-v-d479d5bf]{margin:12px 0}.tasktable[data-v-d529959c]{margin-top:4px;width:100%;overflow:scroll}.tasktable table[data-v-d529959c]{border-collapse:collapse;width:100%}.btn-clear[data-v-d529959c]{margin:4px}@media screen and (max-width: 1399px){.tasktable[data-v-d529959c]{max-height:300px}.tasktable td[data-v-d529959c]{width:10.2857142857%}.tasktable td[data-v-d529959c]:first-child{width:10%}.tasktable td[data-v-d529959c]:nth-child(2){width:18%}.tasktable thead[data-v-d529959c]{position:sticky;top:0;background-color:#7ea5b4;z-index:1}}@media screen and (min-width: 1400px){.tasktable td[data-v-d529959c]{width:10.2857142857%}.tasktable td[data-v-d529959c]:first-child{width:10%}.tasktable td[data-v-d529959c]:nth-child(2){width:18%}.tasktable thead[data-v-d529959c]{background-color:#7ea5b4}}.class1[data-v-d529959c]{background-color:var(--79d4eb29);text-align:center;vertical-align:middle}.class2[data-v-d529959c]{background-color:var(--df5d9e36);text-align:center;vertical-align:middle}.custom-tag[data-v-d529959c]{width:100%;height:100%;justify-content:space-between}.today[data-v-d529959c]{font-weight:400;font-size:12px}.activity[data-v-d529959c]{align-items:center;gap:4px!important}.card-title[data-v-d529959c]{transition:.3s}.disabled[data-v-d529959c]{color:var(--02ceb894)}p[data-v-748f667d]{margin:2px 0}h4[data-v-748f667d]{margin:12px 0 8px}table[data-v-748f667d]{width:100%}td[data-v-748f667d]:nth-child(1){width:80px}.ignore-blacklist[data-v-748f667d]{margin-bottom:10px;display:flex;gap:12px}.h4[data-v-748f667d]{font-size:16px;font-weight:500}.maa-shop[data-v-748f667d]{margin:8px 0}.item[data-v-748f667d]{font-weight:500;font-size:16px}p[data-v-707c6f48]{margin:0 0 8px}h4[data-v-707c6f48]{margin:12px 0 10px}.big-table[data-v-707c6f48]{margin-top:10px;max-width:320px}.big-table th[data-v-707c6f48]{text-align:center}.big-table tr[data-v-707c6f48]{width:70px}.big-table td[data-v-707c6f48]{height:24px}.big-table td[data-v-707c6f48]:nth-child(1){width:70px;text-align:center}.big-table td[data-v-707c6f48]:nth-child(2){width:420px}.final[data-v-707c6f48]{margin:16px 0 0}.item[data-v-e95953da]{font-weight:500;font-size:16px}.n-divider[data-v-e95953da]:not(.n-divider--vertical){margin:6px 0}.subtitle[data-v-4ca1d6ac]{margin:12px 0 6px}.misc-container{margin-top:12px;display:flex;align-items:center;gap:12px}.email-title[data-v-7cbc22ce]{width:100%}.expand[data-v-7cbc22ce]{flex-grow:1}.email-table[data-v-7cbc22ce]{width:100%;margin-bottom:12px}.email-test[data-v-7cbc22ce]{display:flex;align-items:center;gap:16px}.email-mode[data-v-7cbc22ce]{margin-left:20px}.email-label[data-v-7cbc22ce]{width:68px}p[data-v-7cbc22ce]{margin:0 0 10px}.mt-16[data-v-7cbc22ce]{margin-top:16px}.threshold[data-v-d846d278]{display:flex;align-items:center;gap:14px;width:100%}.mower-basic[data-v-d846d278]{width:100%}.mower-basic td[data-v-d846d278]:nth-child(1){width:120px}.mower-basic td[data-v-d846d278]:nth-child(3){padding-left:6px;width:40px}.riic-conf[data-v-d846d278]{width:100%}.riic-conf td[data-v-d846d278]:nth-child(1){width:130px}.riic-conf td[data-v-d846d278]:nth-child(3){padding-left:12px;width:120px}.coord td[data-v-d846d278]{width:120px}.coord td[data-v-d846d278]:nth-child(1),.coord td[data-v-d846d278]:nth-child(3){width:30px}.coord td[data-v-d846d278]:nth-child(2){padding-right:30px}.coord-label[data-v-d846d278]{width:40px;padding-left:8px}p[data-v-d846d278]{margin:0 0 8px}h4[data-v-d846d278]{margin:12px 0 10px}.time-table[data-v-d846d278]{width:100%;margin-bottom:12px}.time-table td[data-v-d846d278]:nth-child(1){width:40px}.scale[data-v-d846d278]{width:60px;text-align:right}.scale-apply[data-v-d846d278]{margin-left:24px}.waiting-table th[data-v-d846d278],.waiting-table td[data-v-d846d278]{padding:4px;min-width:70px;width:100px}.waiting-table th[data-v-d846d278]:first-child,.waiting-table td[data-v-d846d278]:first-child{width:auto;padding:4px 8px}@media (max-width: 1399px){.grid-two{margin:0 0 -10px;width:100%;max-width:600px}.grid-left{display:grid;row-gap:10px;grid-template-columns:100%}.grid-right{display:grid;row-gap:10px;grid-template-columns:100%;margin-top:10px}}@media (min-width: 1400px){.grid-two{display:grid;grid-template-columns:minmax(0px,1fr) minmax(0px,1fr);align-items:flex-start;gap:5px}.grid-left,.grid-right{display:grid;gap:5px;grid-template-columns:100%;max-width:600px}}.n-divider:not(.n-divider--vertical){margin:14px 0 8px} .sss-container[data-v-2dffb781]{display:flex;width:100%;gap:8px}.wrapper[data-v-2dffb781]{white-space:pre-wrap;-webkit-user-select:text;user-select:text}.title[data-v-2dffb781]{font-size:18px;font-weight:500;margin-bottom:6px}p[data-v-d479d5bf]{margin:0 0 10px}.misc-container[data-v-d479d5bf]{display:flex;align-items:center;gap:12px}.header[data-v-d479d5bf]{margin:12px 0}.tasktable[data-v-6e42e723]{margin-top:4px;width:100%;overflow:scroll}.tasktable table[data-v-6e42e723]{border-collapse:collapse;width:100%}.btn-clear[data-v-6e42e723]{margin:4px}@media screen and (max-width: 1399px){.tasktable[data-v-6e42e723]{max-height:300px}.tasktable td[data-v-6e42e723]{width:10.2857142857%}.tasktable td[data-v-6e42e723]:first-child{width:10%}.tasktable td[data-v-6e42e723]:nth-child(2){width:18%}.tasktable thead[data-v-6e42e723]{position:sticky;top:0;background-color:#7ea5b4;z-index:1}}@media screen and (min-width: 1400px){.tasktable td[data-v-6e42e723]{width:10.2857142857%}.tasktable td[data-v-6e42e723]:first-child{width:10%}.tasktable td[data-v-6e42e723]:nth-child(2){width:18%}.tasktable thead[data-v-6e42e723]{background-color:#7ea5b4}}.class1[data-v-6e42e723]{background-color:var(--06f96d6a);text-align:center;vertical-align:middle}.class2[data-v-6e42e723]{background-color:var(--292d8683);text-align:center;vertical-align:middle}.custom-tag[data-v-6e42e723]{width:100%;height:100%;justify-content:space-between}.today[data-v-6e42e723]{font-weight:400;font-size:12px}.activity[data-v-6e42e723]{align-items:center;gap:4px!important}.card-title[data-v-6e42e723]{transition:.3s}.disabled[data-v-6e42e723]{color:var(--6d545694)}.form-item[data-v-6e42e723]{margin:0 0 4px}p[data-v-748f667d]{margin:2px 0}h4[data-v-748f667d]{margin:12px 0 8px}table[data-v-748f667d]{width:100%}td[data-v-748f667d]:nth-child(1){width:80px}.ignore-blacklist[data-v-748f667d]{margin-bottom:10px;display:flex;gap:12px}.h4[data-v-748f667d]{font-size:16px;font-weight:500}.maa-shop[data-v-748f667d]{margin:8px 0}.item[data-v-748f667d]{font-weight:500;font-size:16px}p[data-v-707c6f48]{margin:0 0 8px}h4[data-v-707c6f48]{margin:12px 0 10px}.big-table[data-v-707c6f48]{margin-top:10px;max-width:320px}.big-table th[data-v-707c6f48]{text-align:center}.big-table tr[data-v-707c6f48]{width:70px}.big-table td[data-v-707c6f48]{height:24px}.big-table td[data-v-707c6f48]:nth-child(1){width:70px;text-align:center}.big-table td[data-v-707c6f48]:nth-child(2){width:420px}.final[data-v-707c6f48]{margin:16px 0 0}.item[data-v-e95953da]{font-weight:500;font-size:16px}.n-divider[data-v-e95953da]:not(.n-divider--vertical){margin:6px 0}.subtitle[data-v-4ca1d6ac]{margin:12px 0 6px}.misc-container{margin-top:12px;display:flex;align-items:center;gap:12px}.email-title[data-v-7cbc22ce]{width:100%}.expand[data-v-7cbc22ce]{flex-grow:1}.email-table[data-v-7cbc22ce]{width:100%;margin-bottom:12px}.email-test[data-v-7cbc22ce]{display:flex;align-items:center;gap:16px}.email-mode[data-v-7cbc22ce]{margin-left:20px}.email-label[data-v-7cbc22ce]{width:68px}p[data-v-7cbc22ce]{margin:0 0 10px}.mt-16[data-v-7cbc22ce]{margin-top:16px}.threshold[data-v-d846d278]{display:flex;align-items:center;gap:14px;width:100%}.mower-basic[data-v-d846d278]{width:100%}.mower-basic td[data-v-d846d278]:nth-child(1){width:120px}.mower-basic td[data-v-d846d278]:nth-child(3){padding-left:6px;width:40px}.riic-conf[data-v-d846d278]{width:100%}.riic-conf td[data-v-d846d278]:nth-child(1){width:130px}.riic-conf td[data-v-d846d278]:nth-child(3){padding-left:12px;width:120px}.coord td[data-v-d846d278]{width:120px}.coord td[data-v-d846d278]:nth-child(1),.coord td[data-v-d846d278]:nth-child(3){width:30px}.coord td[data-v-d846d278]:nth-child(2){padding-right:30px}.coord-label[data-v-d846d278]{width:40px;padding-left:8px}p[data-v-d846d278]{margin:0 0 8px}h4[data-v-d846d278]{margin:12px 0 10px}.time-table[data-v-d846d278]{width:100%;margin-bottom:12px}.time-table td[data-v-d846d278]:nth-child(1){width:40px}.scale[data-v-d846d278]{width:60px;text-align:right}.scale-apply[data-v-d846d278]{margin-left:24px}.waiting-table th[data-v-d846d278],.waiting-table td[data-v-d846d278]{padding:4px;min-width:70px;width:100px}.waiting-table th[data-v-d846d278]:first-child,.waiting-table td[data-v-d846d278]:first-child{width:auto;padding:4px 8px}@media (max-width: 1399px){.grid-two{margin:0 0 -10px;width:100%;max-width:600px}.grid-left{display:grid;row-gap:10px;grid-template-columns:100%}.grid-right{display:grid;row-gap:10px;grid-template-columns:100%;margin-top:10px}}@media (min-width: 1400px){.grid-two{display:grid;grid-template-columns:minmax(0px,1fr) minmax(0px,1fr);align-items:flex-start;gap:5px}.grid-left,.grid-right{display:grid;gap:5px;grid-template-columns:100%;max-width:600px}}.n-divider:not(.n-divider--vertical){margin:14px 0 8px}

File diff suppressed because one or more lines are too long

View file

@ -245,15 +245,22 @@ const disabled_color = computed(() => {
:show-feedback="false" :show-feedback="false"
label-width="72" label-width="72"
label-align="left" label-align="left"
style="margin-bottom: 16px"
> >
<n-form-item :show-label="false"> <n-form-item class="form-item" :show-label="false">
<n-checkbox v-model:checked="conf.use_all_medicine">自动使用全部理智药</n-checkbox>
</n-form-item>
<n-form-item class="form-item" :show-label="false">
<n-flex> <n-flex>
<n-checkbox v-model:checked="conf.maa_expiring_medicine"> <n-checkbox
v-model:checked="conf.maa_expiring_medicine"
:disabled="conf.use_all_medicine"
>
自动使用将要过期约3天的理智药 自动使用将要过期约3天的理智药
</n-checkbox> </n-checkbox>
<n-checkbox <n-checkbox
v-model:checked="conf.exipring_medicine_on_weekend" v-model:checked="conf.exipring_medicine_on_weekend"
:disabled="!conf.maa_expiring_medicine" :disabled="conf.use_all_medicine || !conf.maa_expiring_medicine"
> >
仅在周末使用 仅在周末使用
</n-checkbox> </n-checkbox>
@ -443,4 +450,8 @@ const disabled_color = computed(() => {
.disabled { .disabled {
color: v-bind(disabled_color); color: v-bind(disabled_color);
} }
.form-item {
margin: 0 0 4px 0;
}
</style> </style>