Add automatic mining and ticket resource stages

This commit is contained in:
AttilaNet
2026-11-10 12:54:48 +08:00
parent 0109cc0d1c
commit 5082c2df5c
20 changed files with 1615 additions and 67 deletions
+78 -14
View File
@@ -3,7 +3,7 @@ from PySide6 import QtCore as C, QtWidgets as W
from .daily import DailyPolicy, entries
from .native_widgets import ComboBox, IntegerInput, RowBatch
from .stage_cache import StageCache
from .resource_stages import available_item_count, item_requirements
from .sweeping import SweepPolicy
from .table_widgets import SORT_ROLE, TreeItem, bind_controls, set_value, table_item
@@ -16,6 +16,39 @@ def number(value, maximum=9999):
class ActivityPages:
def resource_catalog(self):
return self.engine.stage_cache.catalog
def resource_cost_text(self, snapshot, stage):
base = self.resource_catalog().data.get("stage_info", {}).get(stage.stage_id, {}).get("cost") or {}
owned_ti = int(snapshot.raw.get("master", {}).get("ti") or 0)
parts = [f"体力 单次 {stage.stamina} / 可用 {owned_ti} / 保留 {self.map_keep_ti.value()}"]
reserve = self.map_keep_tickets.value()
for key, count in item_requirements(base.get("items") or []).items():
name = self.resource_catalog().data.get("item_names", {}).get(key, key)
owned = available_item_count(snapshot, key)
parts.append(f"{name} 单次 {count} / 可用 {owned} / 保留 {reserve}")
return "\n".join(parts)
def resource_status_text(self, snapshot, stage, policy, reason):
if not stage.battle_available:
return "该资源关卡缺少已提取的战斗配置,未启用"
if not policy.allow_special:
return "尚未开启“允许矿洞 / 门票关卡”资源关开关"
base = self.resource_catalog().data.get("stage_info", {}).get(stage.stage_id, {}).get("cost") or {}
owned_ti = int(snapshot.raw.get("master", {}).get("ti") or 0)
if stage.stamina + self.map_keep_ti.value() > owned_ti:
return f"体力不足:单次需 {stage.stamina},可用 {owned_ti},保留 {self.map_keep_ti.value()}"
reserve = self.map_keep_tickets.value()
for key, count in item_requirements(base.get("items") or []).items():
owned = available_item_count(snapshot, key)
if owned - count < reserve:
name = self.resource_catalog().data.get("item_names", {}).get(key, key)
return f"{name}不足:单次需 {count},可用 {owned},保留 {reserve}"
if reason:
return reason
return "将按实际模拟结果挑战;不是扫荡"
def maps_tab(self):
self.map_rules = {}
self.map_page = W.QWidget()
@@ -25,7 +58,11 @@ class ActivityPages:
self.map_search.setPlaceholderText("搜索关卡编号、名称或掉落物品")
self.only_unlocked = W.QCheckBox("只看账号已解锁")
self.only_unlocked.setChecked(True)
for widget in (self.map_search, self.only_unlocked):
self.map_category = ComboBox()
self.map_category.addItem("全部关卡", "all")
self.map_category.addItem("普通关卡", "ordinary")
self.map_category.addItem("矿洞与门票", "resource")
for widget in (self.map_search, self.map_category, self.only_unlocked):
line.addWidget(widget)
for label, function in (("刷新关卡", self.refresh_maps), ("展开地区", lambda: self.maps_tree.expandAll()),
("折叠地区", lambda: self.maps_tree.collapseAll())):
@@ -52,35 +89,50 @@ class ActivityPages:
line.addWidget(reset)
line.addStretch()
layout.addLayout(line)
line = W.QHBoxLayout()
self.map_allow_special = W.QCheckBox("允许矿洞 / 门票关卡")
self.map_allow_special.setToolTip("仅处理下方单独勾选且已检查支持的资源关卡;不会自动处理所有特殊关卡。")
self.map_keep_tickets = number(0)
self.map_keep_tickets.setToolTip("每种入场门票或工具分别保留此数量;0 表示不额外保留。")
line.addWidget(self.map_allow_special)
line.addWidget(W.QLabel("每种门票/工具保留"))
line.addWidget(self.map_keep_tickets)
line.addStretch()
layout.addLayout(line)
self.maps_summary = W.QLabel("登录后读取实际解锁状态")
self.maps_summary.setWordWrap(True)
layout.addWidget(self.maps_summary)
self.maps_tree = W.QTreeWidget()
self.maps_tree.setHeaderLabels(["刷图", "关卡", "名称", "难度", "星级", "扫荡 / 挑战状态", "体力 / 门票", "可能掉落", "本日上限", "本日已开始"])
self.maps_tree.setHeaderLabels(["刷图", "关卡", "名称", "难度", "星级", "扫荡 / 挑战状态", "体力 / 门票:单次 / 可用 / 保留", "可能掉落", "本日上限", "本日已开始"])
self.maps_tree.setAlternatingRowColors(True)
self.maps_tree.setTextElideMode(C.Qt.TextElideMode.ElideNone)
self.maps_tree.setUniformRowHeights(False)
self.maps_tree.setEditTriggers(W.QAbstractItemView.EditTrigger.NoEditTriggers)
self.maps_tree.itemChanged.connect(self.map_item_changed)
self.maps_tree.sortByColumn(1, C.Qt.SortOrder.AscendingOrder)
self.maps_tree.setSortingEnabled(True)
for col, width in enumerate((100, 82, 160, 130, 70, 210, 120, 340, 100, 92)):
for col, width in enumerate((100, 82, 160, 130, 70, 270, 300, 340, 100, 92)):
self.maps_tree.setColumnWidth(col, width)
layout.addWidget(self.maps_tree, 1)
note = W.QLabel("地图按账号保存在本地,点击“刷新关卡”可更新完整列表;挑战结束后同步实际进度。星级来自实际通关难度,不能手动修改。\n普通关卡三个难度全部通关后可扫荡;开启“未满星时自动挑战”后,其余已解锁且开放的勾选普通关卡使用内置模拟挑战,共用所选战队、保留体力和本日上限。实际战败显示“打不过”,未支持的内容显示具体原因;未解锁、特殊关卡和当前任务拦截的关卡仍不可刷图。随机掉落并非必得。")
note = W.QLabel("地图按账号保存在本地,点击“刷新关卡”可更新完整列表;挑战结束后同步实际进度。星级来自实际通关难度,不能手动修改。\n普通关卡三个难度全部通关后可扫荡;开启“未满星时自动挑战”后,其余已解锁且开放的勾选普通关卡使用内置模拟挑战,共用所选战队、保留体力和本日上限。实际战败显示“打不过”,未支持的内容显示具体原因;未解锁和当前任务拦截的关卡不可刷图。\n矿洞 / 门票关卡需同时开启资源关开关并逐关勾选,仅显示原入口难度1;体力、每种工具的需求与可用库存随账号快照更新。此类关卡按实际模拟结果挑战,不是扫荡,能力检查不通过时不会入场;其他特殊关仍不可刷图。随机掉落并非必得。")
note.setWordWrap(True)
layout.addWidget(note)
self.tabs.addTab(self.map_page, "自动扫荡")
self.map_search.textChanged.connect(self.render_maps)
self.map_category.currentIndexChanged.connect(self.render_maps)
self.only_unlocked.toggled.connect(self.render_maps)
self.map_enabled.toggled.connect(self.activity_settings_changed)
self.map_allow_challenge.toggled.connect(self.activity_settings_changed)
self.map_keep_ti.valueChanged.connect(self.activity_settings_changed)
self.map_allow_special.toggled.connect(self.activity_settings_changed)
self.map_keep_tickets.valueChanged.connect(self.activity_settings_changed)
self.map_team.currentIndexChanged.connect(self.activity_settings_changed)
def read_sweep_policy(self):
import copy
return SweepPolicy(self.map_enabled.isChecked(), copy.deepcopy(self.map_rules), self.map_keep_ti.value(),
self.map_team.currentData(), allow_challenge=self.map_allow_challenge.isChecked())
self.map_team.currentData(), allow_challenge=self.map_allow_challenge.isChecked(),
allow_special=self.map_allow_special.isChecked(), keep_tickets=self.map_keep_tickets.value())
def reset_map_view(self):
if hasattr(self, "map_render_timer"):
@@ -104,8 +156,8 @@ class ActivityPages:
if hasattr(self, "map_enabled") and not self.map_enabled.isChecked():
self.engine.sweep_policy.enabled = False
sender = self.sender()
if sender in (self.map_enabled, self.map_allow_challenge) and not sender.isChecked():
field = "enabled" if sender is self.map_enabled else "allow_challenge"
if sender in (self.map_enabled, self.map_allow_challenge, self.map_allow_special) and not sender.isChecked():
field = "enabled" if sender is self.map_enabled else "allow_challenge" if sender is self.map_allow_challenge else "allow_special"
setattr(self.engine.sweep_policy, field, False)
if self.pending_policy is not None:
setattr(self.pending_policy["sweep_policy"], field, False)
@@ -115,7 +167,7 @@ class ActivityPages:
if hasattr(self, "daily_enabled") and not self.daily_enabled.isChecked():
self.engine.daily_policy.enabled = False
self.settings_changed()
if sender is self.map_allow_challenge:
if sender in (self.map_allow_challenge, self.map_allow_special, self.map_keep_ti, self.map_keep_tickets):
self.render_maps()
def map_item_changed(self, item, column):
@@ -139,11 +191,11 @@ class ActivityPages:
if isinstance(focused, W.QLineEdit) and self.maps_tree.isAncestorOf(focused):
return
snapshot = self.engine.snapshot
if self.engine.stage_cache.catalog is not self.catalog:
self.engine.stage_cache = StageCache(self.catalog)
all_rows = self.engine.stage_cache.get(snapshot)
grouped = {}
for row in all_rows:
if row.category in ("mine", "ticket") and row.level != "1":
continue
grouped.setdefault(row.stage_id, []).append(row)
query = self.map_search.text().strip().casefold()
policy = self.read_sweep_policy()
@@ -151,6 +203,10 @@ class ActivityPages:
visible = []
for key, options in sorted(grouped.items(), key=lambda pair: (pair[1][0].city, pair[1][0].number, pair[0])):
first = options[0]
resource = first.category in ("mine", "ticket")
if ((self.map_category.currentData() == "ordinary" and first.category != "ordinary")
or (self.map_category.currentData() == "resource" and not resource)):
continue
if self.only_unlocked.isChecked() and not any(s.unlocked for s in options):
continue
if query and query not in (first.city_name + key + first.number + first.name + " ".join(s.drops for s in options)).casefold():
@@ -160,7 +216,12 @@ class ActivityPages:
chosen = chosen or next((s for s in reversed(options) if s.unlocked), first)
self.map_rules.setdefault(key, {"enabled": False, "level": chosen.level, "limit": 3})
reason = self.engine.map_stage_reason(snapshot, chosen, policy, team_ids=team_ids)
visible.append((key, options, chosen, dict(self.map_rules[key]), reason))
if resource and rule.get("enabled") and not policy.allow_special:
reason = "尚未开启“允许矿洞 / 门票关卡”资源关开关"
if resource:
reason = self.resource_status_text(snapshot, chosen, policy, reason)
cost_text = self.resource_cost_text(snapshot, chosen) if resource else str(chosen.stamina) + (" / " + chosen.tickets if chosen.tickets else "")
visible.append((key, options, chosen, dict(self.map_rules[key]), reason, cost_text))
self._map_items = getattr(self, "_map_items", {})
self._map_cities = getattr(self, "_map_cities", {})
if not hasattr(self, "map_render_timer"):
@@ -175,8 +236,11 @@ class ActivityPages:
item = self._map_items.pop(data)
item.parent().takeChild(item.parent().indexOfChild(item))
return
key, options, chosen, rule, reason = data
key, options, chosen, rule, reason, cost_text = data
first = options[0]
if first.category in ("mine", "ticket"):
reason = self.resource_status_text(snapshot, chosen, self.read_sweep_policy(), reason)
cost_text = self.resource_cost_text(snapshot, chosen)
city = self._map_cities.get(first.city)
if city is None:
city = TreeItem(self.maps_tree, [first.city_name])
@@ -198,7 +262,7 @@ class ActivityPages:
item.setSizeHint(0, C.QSize(90, max(difficulty.sizeHint().height(), limit.sizeHint().height()) + 4))
self._map_items[key] = item
values = ["", first.number, first.name, "", "★" * first.stars + "☆" * (3 - first.stars), reason or ("可扫荡" if chosen.sweep else "将模拟挑战"),
str(chosen.stamina) + (" / " + chosen.tickets if chosen.tickets else ""), chosen.drops, "", str(self.engine.sweeper.used(snapshot, chosen))]
cost_text, chosen.drops, "", str(self.engine.sweeper.used(snapshot, chosen))]
for col, text in enumerate(values):
if item.text(col) != text:
set_value(item, col, text)