Fix incubator dispatch 997 by using active monsterIds contract

This commit is contained in:
AttilaNet
2026-11-07 23:24:59 +08:00
parent 42edc111d1
commit 5f0a9eaac3
11 changed files with 93 additions and 21 deletions
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+67
View File
@@ -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)
+1 -1
View File
@@ -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)