Fix incubator dispatch 997 by using active monsterIds contract
This commit is contained in:
@@ -174,6 +174,9 @@
|
||||
培育室的“同步孵化 / 成长”可单独更新这些状态,本次不执行派遣或喂养。
|
||||
“仅监控”不会结算或派遣;需点“开始执行勾选功能”才能自动处理。
|
||||
保留原因会显示在培育室建议和日志中,例如达到保留星级、综合资质A/S、锁定或未启用派遣。
|
||||
培育室与牧场派遣都使用 `monsterService/monsterSell` 的 `monsterIds` 数组参数,
|
||||
不需要先收取到牧场。旧版培育室误用了遗留包装的 `monsterId` 字段,会触发服务端997
|
||||
“网络错误”;现已统一修正自动派遣和右键手动派遣。
|
||||
培育室魔物的 `roomId=null` 已兼容,统计牧场容量时不会再因空字段中断整轮策略。
|
||||
|
||||
- 魔物表可多选,使用按钮或右键锁定/解锁。派遣、指定喂养会列出将消耗的魔物并要求确认;
|
||||
@@ -232,7 +235,7 @@
|
||||
- 自定义表:`typeId, sell_money, sell_exp, time_total`(秒),可只提供部分
|
||||
覆盖列;中文列名“编号、派遣金币、强化经验、孵化秒数”也支持。
|
||||
- 测试:`python -m unittest discover -s ranch_assistant/tests -v`。
|
||||
- 100 项测试通过,覆盖难度列表解析、扫荡条件/请求顺序/异常暂停/跨角色每日额度、
|
||||
- 101 项测试通过,包含培育室派遣997的加密HTTP复现与修复回归;覆盖难度列表解析、扫荡条件/请求顺序/异常暂停/跨角色每日额度、
|
||||
签到与邮件JSON/空VIP/时间单位/失败不重试、树形规则恢复和截图页不重叠;以及
|
||||
加密HTTP十连→实际赠蛋→负数空坑孵化→成长结算→派遣→余额刷新、逐种优先级和补货、
|
||||
多目标喂养优先级、锁定/手动派遣/喂养、开坑与建牧场的费用复核和取消确认、金币/库存/每日额度限制、
|
||||
|
||||
@@ -82,9 +82,4 @@ def manual_monster_actions(catalog, snapshot, kind, monster_ids, target_id=0):
|
||||
return [Action("feed", f"将 {len(ids)} 只素材喂给 #{target_id}", "monsterService/monsterIntensify", {"targetId": int(target_id), "foods": ids})]
|
||||
if kind != "sell":
|
||||
raise ValueError("未知魔物操作")
|
||||
actions = []
|
||||
for process, field in ((2, "monsterId"), (3, "monsterIds")):
|
||||
group = [int(m["id"]) for m in monsters if m.get("process") == process]
|
||||
if group:
|
||||
actions.append(Action("sell", f"派遣 {len(group)} 只魔物", "monsterService/monsterSell", {field: group}))
|
||||
return actions
|
||||
return [Action("sell", f"派遣 {len(ids)} 只魔物", "monsterService/monsterSell", {"monsterIds": ids})]
|
||||
|
||||
@@ -458,8 +458,9 @@ class Planner:
|
||||
disposition = "keep"
|
||||
self.statuses[mid] = "保留:" + reason if disposition == "keep" else "待派遣" if disposition == "sell" else "待喂养"
|
||||
if disposition == "sell":
|
||||
key = "monsterId" if mon.get("process") == 2 else "monsterIds"
|
||||
actions.append(Action("sell", f"派遣 {name} #{mid}", "monsterService/monsterSell", {key: [mid]}))
|
||||
# MonsterCenter also routes mature incubator monsters through
|
||||
# NetMonster.sellMonsters, whose active parameter is plural.
|
||||
actions.append(Action("sell", f"派遣 {name} #{mid}", "monsterService/monsterSell", {"monsterIds": [mid]}))
|
||||
elif mon.get("process") == 2 and policy.collect:
|
||||
room = snapshot.room_available(self.catalog, policy.room_id)
|
||||
if room is not None:
|
||||
|
||||
@@ -254,7 +254,7 @@ class AutomationTests(unittest.TestCase):
|
||||
elif name == "stackCheckProcess":
|
||||
state["monsters"][0]["mode"] = 2
|
||||
elif name == "monsterSell":
|
||||
assert body["monsterId"] == [101]
|
||||
assert body["monsterIds"] == [101]
|
||||
state["monsters"] = []
|
||||
state["stacks"][0]["monsterId"] = -1
|
||||
state["master"]["money"] += 150
|
||||
|
||||
@@ -222,7 +222,7 @@ class WireIntegrationTests(unittest.TestCase):
|
||||
if mon.get("process") == 2: mon["mode"] = 2
|
||||
response = {"resCode": 0}
|
||||
elif self.path.endswith("monsterSell"):
|
||||
mid = body["monsterId"][0]
|
||||
mid = body["monsterIds"][0]
|
||||
state["monsters"] = [m for m in state["monsters"] if m["id"] != mid]
|
||||
for slot in state["stacks"]:
|
||||
if slot["monsterId"] == mid: slot["monsterId"] = 0
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
"""The live 997 trace: mature incubator dispatch used an obsolete parameter."""
|
||||
import copy
|
||||
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
||||
import threading
|
||||
import unittest
|
||||
|
||||
from ranch_assistant.api import Client, DEFAULT_KEY, Session, decode, encode
|
||||
from ranch_assistant.engine import Engine, demo_snapshot
|
||||
from ranch_assistant.model import Catalog, Policy
|
||||
|
||||
|
||||
class DispatchWireTests(unittest.TestCase):
|
||||
def test_auto_dispatch_from_incubator_uses_active_client_contract(self):
|
||||
catalog = Catalog()
|
||||
state = copy.deepcopy(demo_snapshot(catalog).raw)
|
||||
mon = state["monsters"][0]
|
||||
mon.update(process=2, mode=2, roomId=None)
|
||||
state["monsters"] = [mon]
|
||||
state["stacks"] = [{"id": 1, "position": 0, "monsterId": mon["id"]}]
|
||||
state["items"] = []
|
||||
calls = []
|
||||
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
def log_message(self, *args):
|
||||
pass
|
||||
|
||||
def do_POST(self):
|
||||
body = decode(self.rfile.read(int(self.headers["Content-Length"])), DEFAULT_KEY)
|
||||
calls.append((self.path, body))
|
||||
if self.path.endswith("monsterSell"):
|
||||
# NetMonster.sellMonsters and the successful live trace use
|
||||
# monsterIds. NetStack's unused singular field gets 997.
|
||||
if body.get("monsterIds") != [mon["id"]] or "monsterId" in body:
|
||||
response = {"resCode": 997, "resMsg": "网络错误!"}
|
||||
else:
|
||||
state["monsters"] = []
|
||||
state["stacks"][0]["monsterId"] = -1
|
||||
state["master"]["money"] += 150
|
||||
response = {"resCode": 0, "money": 150}
|
||||
else:
|
||||
response = state | {"resCode": 0}
|
||||
data = encode(response, DEFAULT_KEY)
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Length", str(len(data)))
|
||||
self.end_headers()
|
||||
self.wfile.write(data)
|
||||
|
||||
server = ThreadingHTTPServer(("127.0.0.1", 0), Handler)
|
||||
thread = threading.Thread(target=server.serve_forever, daemon=True)
|
||||
thread.start()
|
||||
client = Client(Session(f"http://127.0.0.1:{server.server_port}/", "synthetic-token"))
|
||||
try:
|
||||
engine = Engine(catalog, client)
|
||||
engine.policy = Policy(strategy="gold", protect_star=6, protect_quality=5, fill=False, buy=False)
|
||||
engine.auto = True
|
||||
snapshot, _, message = engine.poll()
|
||||
self.assertNotIn(mon["id"], snapshot.monsters)
|
||||
self.assertEqual(snapshot.raw["stacks"][0]["monsterId"], -1)
|
||||
self.assertIn("派遣", message)
|
||||
sells = [body for path, body in calls if path.endswith("monsterSell")]
|
||||
self.assertEqual(len(sells), 1)
|
||||
self.assertEqual(sells[0]["monsterIds"], [mon["id"]])
|
||||
finally:
|
||||
client.close()
|
||||
server.shutdown()
|
||||
server.server_close()
|
||||
thread.join(2)
|
||||
@@ -98,7 +98,7 @@ class GrowthTests(unittest.TestCase):
|
||||
client = GrowthClient(self.catalog, age=610)
|
||||
engine = self.engine(client)
|
||||
snapshot, _, _ = engine.poll()
|
||||
self.assertEqual([body for name, body in client.calls if name == "monsterService/monsterSell"], [{"monsterId": [501]}])
|
||||
self.assertEqual([body for name, body in client.calls if name == "monsterService/monsterSell"], [{"monsterIds": [501]}])
|
||||
self.assertNotIn(501, snapshot.monsters)
|
||||
self.assertLess([name for name, _ in client.calls].index("growth"), [name for name, _ in client.calls].index("monsterService/monsterSell"))
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ class ManagementTests(unittest.TestCase):
|
||||
def test_manual_dispatch_payloads_and_feed_guards(self):
|
||||
self.snapshot.monsters[102]["process"] = 3
|
||||
actions = manual_monster_actions(self.catalog, self.snapshot, "sell", [101, 102])
|
||||
self.assertEqual([a.payload for a in actions], [{"monsterId": [101]}, {"monsterIds": [102]}])
|
||||
self.assertEqual([a.payload for a in actions], [{"monsterIds": [101, 102]}])
|
||||
action = manual_monster_actions(self.catalog, self.snapshot, "feed", [102], 900)[0]
|
||||
self.assertEqual(action.payload, {"targetId": 900, "foods": [102]})
|
||||
self.snapshot.monsters[900].update(level=20, potentialLevel=2)
|
||||
|
||||
Reference in New Issue
Block a user