fix(web): finalize quick battle and commission procurement for 2.0.9

This commit is contained in:
AttilaNet
2026-11-13 11:28:14 +08:00
parent cfce3e0bc5
commit 7845751cf6
21 changed files with 2442 additions and 117 deletions
+13 -1
View File
@@ -4,7 +4,7 @@
把现有桌面助手的功能和操作结构迁移至单管理员 Web 工作台。桌面版是页面顺序、信息密度、业务名称、保护条件与交互的依据,保留桌面兼容。Web `2.0.9`,源码发布入口 `main`,游戏数据版本 `1.9.68`;桌面正式版保留 `1.2.0`。启动与配置见 [运行说明](README.md),Docker 与更新条件见 [部署说明](../deploy/web/README.md),既有功能与历史验证见 [2.0.8 发布说明](../analysis/RELEASE_2_0_8.md)。
2.0.9 仅整理设置页重复运行提示,保留账号简短状态、错误、表格、表单与原单一底部分类日志;后端、日志及策略逻辑不变,21项相关测试通过,历史结果不计入本补丁,见 [本版发布说明](../analysis/RELEASE_2_0_9.md)。
2.0.9 包含界面清理、委托补缺、默认快速战斗与潜能误报修复;保留账号简短状态、错误、表格、表单与原单一底部分类日志,见 [本版发布说明](../analysis/RELEASE_2_0_9.md)。
使用者在 Windows 本机配置、验证,随后可在 Linux Docker 常驻运行。多个浏览器访问同一个管理员工作台;账号互相隔离,各账号串行执行,账号之间可以并行。
@@ -28,6 +28,14 @@
- 帮助可检查 GitHub 正式版本并提交受控更新请求。未配置部署器时明确显示原因,更新提交不表示更新成功。
- 已在 2.0.1 完成私有仓库和 GHCR 认证的部署,稳定 Release 与正式镜像发布后,可直接通过“帮助 → 检查版本更新…”升级,无需先安装 2.0.2、重复初始化或替换宿主机更新器;升级完成后刷新网页以加载新版界面,安装结果以宿主机健康检查为准。
## 2.0.9 本轮范围
默认使用快速数值模型,委托按剩余步骤统一计算采购和提交需求:
- 委托用明确中文说明未接取的实际原因;成熟魔物交付需求联动购蛋、孵化,优先备齐所需资源再接取。锁定、培养、优质备份等魔物继续受保护,采购与孵蛋遵守耗用预算和需求缺口限制。
- 正常执行默认使用现有内置实验运行时入口的快速 HP/DPS 模型,保留现有伤害配置,无需选择新模式;逐帧实现仅供研发。模型结合双方属性、血量、每秒伤害(DPS)、有效血量(EHP)、时间与关卡目标估算胜利、战败或超时,仍有机制简化,不保证全部关卡可通关或与客户端结果一致。
- 潜能检查依据合法的 `PotentialPanel` 上限区分正常数值与异常,修复正常潜能的误报。
## 2.0.8 自动委托与每日历史
- 自动委托包含“当前委托 / 每日记录”。当前页展示原始候选、任务状态、标注奖励及选择 / 回退原因;城市锁定候选显示不可接取。
@@ -81,6 +89,10 @@
## 安全与验证
2.0.9 快速模型可读取358/358份主线与委托战斗配置,表示输入可计算。离线样本有胜有败,8个20氪金委托战斗为5胜3败;当前卡点样本的默认路径结果及耗时见 [发布说明](../analysis/RELEASE_2_0_9.md#验证)。
617项唯一回归用例中615项通过,2项因Windows环境跳过;另有8项界面浏览器测试通过。多步骤采购修复已通过独立复核;未在线提交游戏结算。
2.0.8 共验证739项独立测试:736通过、3项 Windows 跳过;其中非浏览器662项(659通过、3跳过),浏览器77项全部验证通过。证据与发布门禁见 [发布说明](../analysis/RELEASE_2_0_8.md#验证);历史版本结果不计入本版。
不发真实游戏 API 测试,不读取或更改私人 `local_state` 账号。浏览器测试仅使用临时目录、fake 后端或服务端离线演示。所有游戏文本用 `textContent` 呈现;日志使用服务端脱敏数据。管理登录、同源校验与 cookie 由 API 负责。
+7 -1
View File
@@ -2,7 +2,9 @@
Web **2.0.9**,源码发布入口 `main`,游戏资料基线 **1.9.68**。桌面正式版保留 **1.2.0**,入口为 `python -m ranch_assistant`;Web 使用独立依赖与数据根。自动委托提供当前委托与每日记录,功能和历史验证状态见 [2.0.8 发布说明](../analysis/RELEASE_2_0_8.md)。
2.0.9 仅整理设置页重复运行提示,21项相关测试通过,历史结果不计入本补丁,见 [本版发布说明](../analysis/RELEASE_2_0_9.md)。
2.0.9 清理重复运行提示,补齐委托资源准备、默认快速战斗及正常潜能误报修复。委托明确显示中文未接取原因,成熟魔物需求联动购蛋、孵化;按剩余步骤备料,遵守预算、需求缺口及魔物保护设置。详情继续使用原单一底部分类日志,见 [本版发布说明](../analysis/RELEASE_2_0_9.md)。
正常执行默认使用现有内置实验运行时入口的快速 HP/DPS 模型,保留现有伤害配置,无需选择新模式;逐帧实现仅供研发。模型按双方属性、血量、每秒伤害、时间与目标估算胜利、战败或超时,仍有机制简化,不保证全部关卡可通关或与客户端结果一致。
Web 采用 FastAPI / Uvicorn 和原生 HTML/CSS/ES 模块,无 Node、npm 或前端编译步骤,不安装 PySide6。页面和策略能力沿用现有核心,详细业务范围与原有限制见 [桌面使用说明](../ranch_assistant/README.md)。多浏览器连接同一个管理员工作台;一个服务实例内,各账号独立线程并行,同一账号操作串行。
@@ -110,6 +112,10 @@ Web 检查固定官方 GitHub Releases 的稳定 `v2.x.y`,跳过桌面 1.x、
## 离线验证
2.0.9 快速模型的输入预检覆盖358/358份主线与委托战斗配置。当前卡点的真实账号离线样本预计战斗5秒,直接计算约1.2毫秒,含隔离进程启动与检查约0.21秒;8个20氪金委托战斗的离线结果为5胜3败,见 [本版发布说明](../analysis/RELEASE_2_0_9.md#验证)。
617项唯一回归用例中615项通过,2项因Windows环境跳过;另有8项界面浏览器测试通过。多步骤采购循环已经修复并独立复核。本轮未在线提交游戏结算或手动部署X99。
2.0.8 共验证739项独立测试:736通过、3项 Windows 跳过;其中非浏览器662项(659通过、3跳过),浏览器77项全部验证通过。分组结果与证据见 [发布说明](../analysis/RELEASE_2_0_8.md#验证)。2.0.7 的结果保留在 [历史发布说明](../analysis/RELEASE_2_0_7.md#验证),以下历史记录也不计入本版验收。
### 历史验证记录(不计入 2.0.8)
@@ -0,0 +1,89 @@
"""Commission diagnostics use offline fake clients and source-derived cities."""
import json
from pathlib import Path
import unittest
from ranch_assistant.engine import Engine
from ranch_assistant.game_data import load_progression_data
from ranch_assistant.model import Catalog, Policy, Snapshot
from ranch_assistant.progression import ProgressionPlanner
from ranch_assistant.quests import QuestPolicy
from ranch_assistant.tests import test_commission_procurement as fixtures
from ranch_assistant.tests.test_progression import snapshot
from ranch_web.policies import default_config
from ranch_web.views import build_view
class CommissionProcurementViewTests(unittest.TestCase):
def test_preparable_is_distinct_from_receivable_and_has_exact_counts(self):
fixture = fixtures.CommissionProcurementTests()
fixture.setUp()
self.addCleanup(fixture.doCleanups)
fixture.catalog.data["task_info"] = fixture.tasks
engine, client = fixture.engine()
dto = build_view(engine, "commissions", default_config())
high = next(r for r in dto["rows"] if r["task_type_id"] == "400")
self.assertEqual(high["status"], "补齐后接取")
self.assertEqual(high["reason_kind"], "temp_resource")
self.assertEqual((high["resources"][0]["needed"], high["resources"][0]["available"]), (1, 0))
self.assertTrue(high["progress_plan"])
self.assertIn("不消耗接取次数", high["reason"])
self.assertEqual(client.writes, [])
engine._run_progression_intent(fixture.intent(engine))
self.assertEqual(engine.commission_history()["summary"]["accepted_count"], 0)
self.assertIn("未消耗接取次数", engine.commission_history()["events"][0]["description"])
def test_packaged_offers_replay_quota_and_city_gates(self):
from unittest.mock import patch
data, catalog = load_progression_data(), Catalog()
cities = (4, 5, 8, 9)
offers = {str(city): [key for key, info in sorted(data.task_info.items())
if info.get("type") == 4 and (info.get("reward") or {}).get("ke") == 20
and any(str(step.get("position") or "").split("_", 1)[0] == f"city{city}"
for step in info.get("steps") or [])] for city in cities}
self.assertTrue(all(offers.values()))
for quota in (0, 4):
with self.subTest(quota=quota), patch("ranch_assistant.model.time.time", return_value=1700000000):
snap = snapshot(currentTasks=[])
snap.raw["history"].update(loopTask=offers, loopTaskNum=quota, loopTaskTime=snap.now,
unlockCity={str(city): False for city in cities})
planner = ProgressionPlanner(catalog, data)
diagnostics = planner.commission_offers(snap, QuestPolicy(enabled=True, allow_items=True, allow_monsters=True),
Policy())
twenty = [row for row in diagnostics if row["expected_ke"] == 20]
self.assertEqual(len(twenty), sum(map(len, offers.values())))
self.assertEqual({row["city"] for row in twenty}, set(cities))
self.assertTrue(all(row["remaining_quota"] == quota for row in diagnostics))
if quota == 0:
self.assertTrue(all(row["reason_kind"] == "quota" and not row["eligible"] and not row["preparable"]
for row in diagnostics))
self.assertEqual(planner.commission_plan(snap, QuestPolicy(enabled=True), Policy()), [])
else:
for row in twenty:
city_info = data.game_setting["cityInfo"][str(row["city"])]
self.assertEqual(row["reason_kind"], "city_locked")
self.assertFalse(row["eligible"] or row["preparable"])
self.assertEqual(row["city_name"], city_info["name"])
self.assertEqual(row["unlock_task_id"], city_info["openTask"])
self.assertTrue(row["unlock_task_id"])
self.assertIn(row["city_name"], row["reason"])
self.assertIn(row["unlock_task_id"], row["reason"])
def test_mainline_controller_reason_is_chinese_and_does_not_claim_victory(self):
engine = Engine(Catalog())
engine.snapshot = snapshot()
engine._progression_rows = [{"task_type_id": "1002013", "name": "猫狗的恩怨", "state": "received", "category": "mainline",
"step_number": 1, "total_steps": 1, "supported": False, "battle_kind": "task",
"block_reason": "Unsupported battle triggers: monDead; Unsupported monster controller: monMaker; Unsupported monster controller: monSteps"}]
dto = build_view(engine, "mainline", default_config())
reason = dto["rows"][0]["support"]
self.assertIn("魔物死亡事件", reason)
self.assertIn("生成魔物", reason)
self.assertIn("脚本行动", reason)
self.assertNotIn("Unsupported", reason)
self.assertNotIn("胜利", reason)
if __name__ == "__main__":
unittest.main()
+10 -4
View File
@@ -790,14 +790,15 @@ class FreshProcessIntegrationTests(unittest.TestCase):
def test_real_engine_battle_worker_subprocess_still_runs_after_web_imports(self):
result = self.child('''
import json, tempfile
import json, sys, tempfile
from pathlib import Path
from unittest.mock import patch
import subprocess
from ranch_web.app import create_app
from ranch_web.service import WebManager
from ranch_web.tests.test_web_integration import NoExternalSockets, real_engine_factory
from ranch_assistant.battle_simulator import combat_tables, simulate
from ranch_assistant.battle_simulator import combat_tables
from ranch_assistant.battle_quick import simulate_quick
row = combat_tables()['monster_info']['1001010']
mon = {'id': 101, 'typeId': 1001010, 'level': 20, 'mode': 2, 'tpLevel': 0, 'feel': 0, 'upStar': 0, 'pAtk': 0, 'pDef': 0, 'pHp': 0, 'pDex': 0}
for name in ('Atk', 'Def', 'Hp', 'Dex'):
@@ -819,15 +820,20 @@ class FreshProcessIntegrationTests(unittest.TestCase):
result = engine.battles.runtime.run(request, timeout=15)
assert launch.call_count == 1
assert 'ranch_assistant.battle_simulator' in launch.call_args.args[0]
assert result == simulate(request), result
expected = simulate_quick(request)
assert {k: v for k, v in result.items() if k != 'wall_time_ms'} == {
k: v for k, v in expected.items() if k != 'wall_time_ms'}, result
assert result['simulation_method'] == 'aggregate_hp_dps', result
assert result['outcome'] == 'win', result
assert not any(n.startswith('PySide6') or n == 'ranch_assistant.gui' or n.endswith('_gui') for n in sys.modules)
assert not network.attempts
print(json.dumps({'outcome': result['outcome'], 'execution_mode': result['execution_mode'], 'real_worker_processes': launch.call_count}))
print(json.dumps({'outcome': result['outcome'], 'execution_mode': result['execution_mode'], 'simulation_method': result['simulation_method'], 'real_worker_processes': launch.call_count}))
finally:
manager.close()
''')
self.assertEqual(result["real_worker_processes"], 1)
self.assertEqual(result["outcome"], "win")
self.assertEqual(result["simulation_method"], "aggregate_hp_dps")
if __name__ == "__main__":
+45 -10
View File
@@ -13,7 +13,7 @@ from ranch_assistant.drop_statistics import analyze
from ranch_assistant.presentation import monster_rows
from ranch_assistant.battle_messages import battle_message
from ranch_assistant.resource_stages import available_item_count, item_requirements, with_resource_data
from ranch_assistant.quests import commission_priority, commission_selection
from ranch_assistant.quests import commission_priority, commission_selection, commission_reason_kind
from .policies import default_config, validate_config
@@ -478,6 +478,26 @@ def _category(value):
return value if value in CATEGORIES else "unknown"
def _task_diagnostic_reason(reason):
# Keep concrete mechanism names visible while presenting Chinese reasons.
text = str(reason or "")
import re
labels = {"monMaker": "生成魔物", "monSteps": "脚本行动", "skill": "脚本技能", "monDead": "魔物死亡事件"}
for source, label in (("Unsupported monster controller", "当前模型尚未支持的魔物行为"),
("Unsupported battle controller", "当前模型尚未支持的战斗机制"),
("Unsupported battle triggers", "当前模型尚未支持的战斗触发事件")):
text = re.sub(re.escape(source) + r":\s*([^;;\n]+)",
lambda match: label + ":" + "、".join(labels.get(k.strip(), k.strip()) for k in match[1].split(",")), text)
text = text.replace("+15overpoten", "潜能字段(+15overpoten)尚未兼容")
return battle_message(text)
REASON_KINDS = {"ready": "条件齐备", "city_locked": "城市未解锁", "prerequisite": "前置条件", "quota": "次数用尽",
"offline": "账号离线", "busy": "当前占用", "cooldown": "等待时间", "temp_resource": "资源暂缺",
"protection": "保护限制", "model_unsupported": "模型尚未支持", "policy": "策略限制",
"uncertain_write": "请求待核对", "priority": "奖励排序"}
def _mainline(dto, engine, config, query):
selected, state = str(query.get("category", "mainline")), str(query.get("state", "current"))
dto["filters"] = [_filter("category", "任务类别", selected, [("", "全部类别"), *CATEGORIES.items()]),
@@ -492,7 +512,8 @@ def _mainline(dto, engine, config, query):
lifecycle = STATE_ALIASES.get(raw_state, raw_state)
if selected and category != selected or state == "current" and lifecycle not in ("received", "unlocked", "ready_to_reward") or state not in ("", "current") and lifecycle != state:
continue
reason = battle_message(source.get("blocked_reason") or source.get("block_reason") or source.get("reason") or "")
raw_reason = source.get("blocked_reason") or source.get("block_reason") or source.get("reason") or ""
reason = _task_diagnostic_reason(raw_reason)
support = "受阻:" + reason if reason else "已支持" if source.get("supported") is True else "暂不支持" if source.get("supported") is False else "支持状态未确认"
battle = _text(source.get("battle_kind"), "未确认")
battle = BATTLE_ALIASES.get(battle, battle)
@@ -500,11 +521,15 @@ def _mainline(dto, engine, config, query):
"category_label": CATEGORIES[category], "name": _text(source.get("name")), "state": raw_state, "lifecycle_state": lifecycle,
"state_label": STATES.get(raw_state, raw_state), "step": _text(source.get("step_number")) + " / " + _text(source.get("total_steps")),
"location": _text(source.get("location_text") or source.get("location") or source.get("position")), "requirement": _text(source.get("requirement")),
"next_action": _text(source.get("next_action")), "battle": BATTLE_KINDS.get(battle, battle), "support": support}
"next_action": _task_diagnostic_reason(_text(source.get("next_action"))), "battle": BATTLE_KINDS.get(battle, battle), "support": support,
"reason_kind": source.get("reason_kind") or commission_reason_kind(raw_reason),
"resources": source.get("resources") or [], "progress_plan": source.get("progress_plan") or []}
detail = {"任务": row["name"], "类别": row["category_label"], "状态": row["state_label"], "步骤": row["step"],
"目标 / 位置": row["location"], "NPC": _text(source.get("npc_name")), "需求": row["requirement"],
"对话": _text(source.get("dialogue") or source.get("dialogue_text") or source.get("dialogue_status"), "当前未提供对话内容"),
"下一步": row["next_action"], "战斗": row["battle"], "运行状态": _text(source.get("status"), row["state_label"]), "支持状态 / 阻塞原因": support}
"下一步": row["next_action"], "战斗": row["battle"], "运行状态": _text(source.get("status"), row["state_label"]), "支持状态 / 阻塞原因": support,
"原因类型": REASON_KINDS.get(row["reason_kind"], "条件待核对"), "资源需求与可用量": row["resources"],
"补齐计划": ";".join(row["progress_plan"])}
if search and search not in " ".join(map(str, [*row.values(), *detail.values()])).casefold():
continue
dto["rows"].append(row)
@@ -645,11 +670,11 @@ def _commissions(dto, engine, config, query):
snapshot, catalog = engine.snapshot, engine.catalog
search = _search(dto, query)
dto["columns"] = [_column(key, label) for key, label in (("task_type_id", "编号"), ("name", "委托"), ("city", "城市"), ("status", "状态"),
("reward_money", "标注金币"), ("reward_ke", "标注氪金"), ("selection_reason", "选择 / 回退原因"), ("reason", "需求 / 下一步 / 阻塞原因"))]
("reward_money", "标注金币"), ("reward_ke", "标注氪金"), ("reason_type", "原因类型"), ("selection_reason", "选择 / 回退原因"), ("reason", "需求 / 下一步 / 阻塞原因"))]
diagnostics = {str(row.get("task_type_id")): row for row in engine.progression_rows() if _category(row.get("category")) == "commission"}
offer_rows = engine.commission_offer_diagnostics()
offers = {(str(row.get("task_type_id")), str(row.get("city"))): row for row in offer_rows}
selected = next((row for row in offer_rows if row.get("eligible") is True), {})
selected = next((row for row in offer_rows if row.get("eligible") is True or row.get("preparable")), {})
selection = commission_selection({"reward": {"ke": selected.get("expected_ke", 0)}}, offer_rows,
[row for row in offer_rows if row.get("eligible") is False]) if selected else {}
source = sorted(engine.tasks.rows(snapshot, engine.quest_policy, engine.policy), key=lambda row: (
@@ -661,15 +686,23 @@ def _commissions(dto, engine, config, query):
status = "可接取" if offer.get("eligible") is True else "候选 / 条件待核对"
reason = (offer.get("reason") if offer.get("eligible") is False else None) if offer else diagnostic.get("block_reason") or diagnostic.get("blocked_reason")
if reason:
status = "暂不接取" if "city" in meta else "等待条件"
status = "补齐后接取" if offer.get("preparable") else "暂不接取" if "city" in meta else "等待条件"
text = reason
elif not offer and diagnostic.get("next_action"):
text = diagnostic["next_action"]
info = catalog.data.get("task_info", {}).get(str(key), {})
reward = info.get("reward") or {}
reason_kind = offer.get("reason_kind") or diagnostic.get("reason_kind") or commission_reason_kind(reason)
if offer and offer != selected and offer.get("eligible"):
reason_kind = "priority"
text = f"当前优先处理《{selected.get('name')}》({selected.get('expected_ke')}氪金);本委托条件齐备,排队等待"
row = {"id": f"{key}:{index}", "task_type_id": str(key), "name": name, "status": status,
"reward_money": reward.get("money", 0), "reward_ke": reward.get("ke", 0), "reason": battle_message(text),
"city": meta.get("city"), "active": "city" not in meta,
"reward_money": reward.get("money", 0), "reward_ke": reward.get("ke", 0), "reason": _task_diagnostic_reason(text),
"city": offer.get("city_name") or meta.get("city"), "city_id": meta.get("city"), "active": "city" not in meta,
"reason_kind": reason_kind, "reason_type": REASON_KINDS.get(reason_kind, "条件待核对"),
"resources": offer.get("resources") or diagnostic.get("resources") or [],
"progress_plan": offer.get("progress_plan") or diagnostic.get("progress_plan") or [],
"next_step": _task_diagnostic_reason(offer.get("next_step") or diagnostic.get("next_action") or text),
"selection_reason": _text(offer.get("selection_reason") or (selection.get("selection_reason") if offer and offer == selected else None)
or diagnostic.get("selection_reason") or meta.get("selection_reason") or (reason if "city" in meta else None),
"较高氪金的可执行委托优先" if offer.get("eligible") is True else "接取条件待核对" if "city" in meta else "已接取,优先推进当前委托")}
@@ -677,7 +710,9 @@ def _commissions(dto, engine, config, query):
continue
dto["rows"].append(row)
dto["details"][row["id"]] = {"描述": info.get("des", ""), "标注奖励": reward_summary(catalog, reward),
"城市": _text(meta.get("city")), "选择 / 回退原因": row["selection_reason"], "需求 / 下一步": row["reason"],
"城市": _text(row["city"]), "城市解锁条件": offer.get("unlock_condition", ""),
"原因类型": row["reason_type"], "资源需求与可用量": row["resources"], "补齐计划": ";".join(row["progress_plan"]),
"下一步": row["next_step"], "选择 / 回退原因": row["selection_reason"], "需求 / 下一步": row["reason"],
"交付限制": {"允许物品": engine.quest_policy.allow_items, "允许魔物": engine.quest_policy.allow_monsters,
"单次金币上限": engine.quest_policy.max_money, "允许已支持战斗": engine.quest_policy.battle_tasks},
"接取优先级": "跨城市按标注氪金 20 → 15 → 10 优先;20 氪金均不可用时回退到可执行的 15 / 10 氪金委托"}