fix: keep automatic cultivation on one stable primary per species

This commit is contained in:
AttilaNet
2026-11-13 08:51:03 +08:00
parent 01ad2e3ab9
commit 4fbe895999
35 changed files with 2069 additions and 322 deletions
+23 -2
View File
@@ -165,17 +165,38 @@ class TaskLogTests(unittest.TestCase):
market = next(key for key, row in engine.catalog.data["markets"].items() if row.get("money", 0) > 0)
engine.policy.daily_buy_money = 1000000
engine.planner.notes = []
primary = next(iter(engine.cultivation.select(engine.snapshot).values()))
food = next(mon for mon in engine.snapshot.monsters.values()
if mon.get("process") == 3 and mon.get("typeId") == primary["typeId"]
and int(mon["id"]) != int(primary["id"]) and not mon.get("lock") and not mon.get("sysLock"))
original_post = engine.client.http.post
def consume_feed(url, data, **kwargs):
if url.endswith("monsterService/monsterIntensify"):
payload = fixtures.decode(data, engine.client.session.key)
foods = {int(mid) for mid in payload["foods"]}
engine.client.raw["monsters"] = [mon for mon in engine.client.raw["monsters"] if int(mon["id"]) not in foods]
return original_post(url, data, **kwargs)
actions = [
Action("buy", "莉莉托斯市场十连抽蛋 ×10,花费100金币", "gachaService/gachaGetEggs", {"id": market, "num": 1}),
Action("sell", "派遣 测试魔物 #1", "monsterService/monsterSell", {"monsterIds": [1]}),
Action("feed", "喂养 测试魔物 ← 素材", "monsterService/monsterIntensify", {"targetId": 1, "foods": []}),
Action("feed", "喂养 测试魔物 ← 素材", "monsterService/monsterIntensify",
{"targetId": int(primary["id"]), "foods": [int(food["id"])]}),
]
for action in actions:
with self.subTest(kind=action.kind):
worker._running = True
after = self.manager.logs(identifier, debug=True)["next"]
with patch.object(engine, "plans", return_value=[action]):
calls_before = len(fixtures.FakeClient.calls)
with patch.object(engine, "plans", return_value=[action]), \
patch.object(engine.client.http, "post", side_effect=consume_feed):
self.tick(identifier, "poll")
if action.kind == "feed":
self.assertEqual([{key: payload[key] for key in action.payload}
for _, url, payload in fixtures.FakeClient.calls[calls_before:]
if url.endswith(action.path)], [action.payload])
self.assertNotIn(int(food["id"]), engine.snapshot.monsters)
entries = self.entries(identifier, after, debug=True)
result = [row for row in entries if not row["debug"]]
self.assertEqual({row["category"] for row in result}, {"hatching"})