Add v1.2 development quest progression and experimental battle runtime
This commit is contained in:
@@ -0,0 +1,733 @@
|
||||
"""Offline source-derived progression tests; no clients or game servers."""
|
||||
from copy import deepcopy
|
||||
from dataclasses import asdict, replace
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
import zipfile
|
||||
|
||||
from ranch_assistant.game_data import (
|
||||
BATTLES_NAME, DATA_DIR, DATA_NAME, MANIFEST_NAME,
|
||||
ORIGINAL_APK_SHA256, ProgressionData, ProgressionDataError, load_progression_data,
|
||||
)
|
||||
from ranch_assistant.model import Catalog, Policy, Snapshot
|
||||
from ranch_assistant.progression import ProgressionPlanner, ProgressionPolicy
|
||||
from ranch_assistant.quests import QuestPolicy
|
||||
from tools.build_progression_data import farming_index, summarize_script
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
|
||||
|
||||
def step(kind="none", **changes):
|
||||
return {"statusType": kind, "statusValue": {}, "story": "", "afterStory": "",
|
||||
"position": "", "npc": "", "unlockStages": [], "condition": {}, **changes}
|
||||
|
||||
|
||||
def task(type_id="100", *, steps=None, **changes):
|
||||
return {"id": type_id, "name": "离线测试任务", "type": 1, "startStep": step(),
|
||||
"steps": [step()] if steps is None else steps, "closed": False,
|
||||
"nextTasks": [], "unlockTasks": [], "unlockStages": [], **changes}
|
||||
|
||||
|
||||
def snapshot(**changes):
|
||||
return Snapshot({"master": {"id": 1, "level": 20, "money": 2000, "ti": 50},
|
||||
"items": [], "monsters": [], "stacks": [], "rooms": [], "teams": [],
|
||||
"history": {"unlockCity": {"1": True}, "unlockStage": {"0101": [1, 2, 3]},
|
||||
"passStage": {}, "passTask": {}, "unlockTask": {}, "openHardMode": True},
|
||||
"currentTasks": [{"id": 11, "typeId": "100", "curStep": 1, "stepValue": None}],
|
||||
**changes})
|
||||
|
||||
|
||||
def config(tasks=None, **changes):
|
||||
return {"task_info": tasks or {"100": task()}, "scripts": {
|
||||
"linear": {"supported": True, "answer": None, "dialogue_lines": 5},
|
||||
"accept": {"supported": True, "answer": True, "dialogue_lines": 3},
|
||||
"choice": {"supported": False, "answer": None, "block_reasons": ["unsupported command: option"]}},
|
||||
"game_setting": {"cityInfo": {"1": {"name": "莉莉托斯", "cid": "1"}}}, "setting": {},
|
||||
"stage_info": {"0101": {"id": "0101", "name": "王城郊外 1-1", "city": 1, "cost": {"ti": 2},
|
||||
"level": {str(i): {"cost": i, "battle_available": True} for i in (1, 2, 3)}}},
|
||||
"npc_info": {"nina": {"name": "妮娜"}}, "stage_sp": {}, **changes}
|
||||
|
||||
|
||||
class ProgressionTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.catalog = Catalog()
|
||||
|
||||
def setUp(self):
|
||||
self.policy = ProgressionPolicy(enabled=True)
|
||||
self.ranch = Policy(keep_money=1000)
|
||||
self.snapshot = snapshot()
|
||||
self.planner = ProgressionPlanner(self.catalog, config())
|
||||
|
||||
def plan(self):
|
||||
return self.planner.plan(self.snapshot, self.policy, self.ranch)
|
||||
|
||||
def next(self, kind):
|
||||
planned = self.plan()
|
||||
self.assertTrue(planned)
|
||||
self.assertEqual(planned[0].kind, kind, planned[0].description)
|
||||
return planned[0]
|
||||
|
||||
def test_policy_defaults_roundtrip_and_validation(self):
|
||||
policy = ProgressionPolicy()
|
||||
self.assertFalse(policy.enabled)
|
||||
self.assertEqual(ProgressionPolicy.from_dict(json.loads(json.dumps(asdict(policy)))), policy)
|
||||
for changes in ({"enabled": "false"}, {"reserve_ti": -1}, {"stop_after_loss": 0},
|
||||
{"max_money": float("nan")}, {"allow_items": 1}, {"team": ""},
|
||||
{"team": "has\nnewline"}, {"team": " too much space "}, {"team": "x" * 65},
|
||||
{"battle_mode": "faithful_estimate"},
|
||||
{"item_reserves": {"20001": -2}}, {"item_reserves": {"token": 1}}):
|
||||
with self.subTest(changes=changes), self.assertRaises(ValueError):
|
||||
ProgressionPolicy(**changes)
|
||||
with self.assertRaises(ValueError):
|
||||
ProgressionPolicy.from_dict({"session": "must-not-import"})
|
||||
self.assertEqual(ProgressionPolicy(team="自定义编队").team, "自定义编队")
|
||||
self.assertEqual(ProgressionPolicy(team="bonusTeam4").battle_mode, "original")
|
||||
self.assertEqual(ProgressionPolicy(battle_mode="experimental").to_dict()["battle_mode"], "experimental")
|
||||
self.assertEqual(self.planner.plan(self.snapshot, ProgressionPolicy(), self.ranch), [])
|
||||
|
||||
def test_nonbattle_server_ack_then_local_complete_then_reward(self):
|
||||
original = deepcopy(self.snapshot.raw)
|
||||
action = self.next("progression_step")
|
||||
self.assertEqual(action.path, "taskService/taskCompleteStep")
|
||||
self.assertEqual(action.payload, {"taskId": 11, "taskTypeId": "100", "removeIds": None})
|
||||
self.assertNotIn("battleData", action.payload)
|
||||
self.planner.mark_started(self.snapshot, action)
|
||||
self.assertTrue(self.plan()[0].block_reason)
|
||||
self.planner.acknowledge(self.snapshot, action, {"taskStepValue": None})
|
||||
self.assertFalse(self.planner.acknowledge(self.snapshot, action, {}))
|
||||
local = self.next("progression_local_step")
|
||||
self.assertEqual(local.path, "")
|
||||
self.planner.acknowledge(self.snapshot, local)
|
||||
reward = self.next("progression_complete")
|
||||
self.assertEqual(reward.payload, {"taskId": 11, "taskTypeId": "100"})
|
||||
self.planner.acknowledge(self.snapshot, reward, {"reward": {}})
|
||||
self.assertEqual(self.plan(), [])
|
||||
self.assertEqual(self.snapshot.raw, original)
|
||||
|
||||
def test_ordinary_dialogue_and_navigation_are_logical_and_do_not_submit_twice(self):
|
||||
self.planner = ProgressionPlanner(self.catalog, config({"100": task(steps=[
|
||||
step(story="linear", afterStory="linear", position="city1_market", npc="nina"), step()])}))
|
||||
nav = self.next("progression_navigate")
|
||||
self.assertEqual(nav.position, "city1_market")
|
||||
self.assertEqual(nav.payload, {})
|
||||
self.assertEqual(nav.npc_name, "妮娜")
|
||||
self.assertIn("市场", nav.location)
|
||||
self.planner.acknowledge(self.snapshot, nav)
|
||||
before = self.next("progression_dialogue")
|
||||
self.assertEqual(before.phase, "before")
|
||||
self.planner.acknowledge(self.snapshot, before)
|
||||
server = self.next("progression_step")
|
||||
self.assertEqual(self.snapshot.raw["currentTasks"][0]["curStep"], 1)
|
||||
self.planner.acknowledge(self.snapshot, server, {})
|
||||
after = self.next("progression_dialogue")
|
||||
self.assertEqual(after.phase, "after")
|
||||
self.planner.acknowledge(self.snapshot, after)
|
||||
self.planner.acknowledge(self.snapshot, self.next("progression_local_step"))
|
||||
following = self.next("progression_step")
|
||||
self.assertEqual(following.step_number, 2)
|
||||
self.assertEqual(self.snapshot.raw["currentTasks"][0]["curStep"], 1)
|
||||
|
||||
def test_empty_before_story_does_not_skip_after_story(self):
|
||||
self.planner = ProgressionPlanner(self.catalog, config({"100": task(steps=[step(afterStory="linear")])}))
|
||||
self.planner.acknowledge(self.snapshot, self.next("progression_step"), {})
|
||||
self.assertEqual(self.next("progression_dialogue").phase, "after")
|
||||
|
||||
def test_server_step_advance_does_not_skip_unfinished_acknowledged_after_story(self):
|
||||
self.planner = ProgressionPlanner(self.catalog, config({"100": task(steps=[step(afterStory="linear"), step()])}))
|
||||
self.planner.acknowledge(self.snapshot, self.next("progression_step"), {})
|
||||
self.snapshot.raw["currentTasks"][0]["curStep"] = 2
|
||||
self.assertEqual(self.next("progression_dialogue").step_number, 1)
|
||||
|
||||
def test_finished_received_unlocked_states_deduplicate(self):
|
||||
self.snapshot.raw["history"]["unlockTask"] = {"100": True}
|
||||
rows = self.planner.rows(self.snapshot, self.policy, self.ranch)
|
||||
self.assertEqual(len(rows), 1)
|
||||
self.assertEqual(rows[0]["state"], "received")
|
||||
self.assertEqual(self.next("progression_step").task_id, 11)
|
||||
self.snapshot.raw["history"]["passTask"] = {"100": True}
|
||||
self.assertEqual(self.plan(), [])
|
||||
self.assertEqual(self.planner.rows(self.snapshot, self.policy, self.ranch)[0]["state"], "finished")
|
||||
|
||||
def test_task_history_id_lists_are_supported_alongside_flag_mappings(self):
|
||||
self.snapshot.raw["currentTasks"] = []
|
||||
self.snapshot.raw["history"]["unlockTask"] = [100]
|
||||
self.next("progression_accept")
|
||||
self.snapshot.raw["history"]["passTask"] = [100]
|
||||
self.assertEqual(self.plan(), [])
|
||||
|
||||
def test_accept_uses_verified_payload_and_success_instance(self):
|
||||
self.snapshot.raw["currentTasks"] = []
|
||||
self.snapshot.raw["history"]["unlockTask"] = {"100": True}
|
||||
accept = self.next("progression_accept")
|
||||
self.assertEqual(accept.path, "taskService/taskReceive")
|
||||
self.assertEqual(accept.payload, {"taskTypeId": "100"})
|
||||
self.planner.acknowledge(self.snapshot, accept, {"task": {"id": 15, "typeId": "100", "stepValue": None}})
|
||||
self.assertEqual(self.next("progression_step").task_id, 15)
|
||||
|
||||
def test_start_answer_is_required_and_choice_scripts_are_blocked(self):
|
||||
self.snapshot.raw["currentTasks"] = []
|
||||
self.snapshot.raw["history"]["unlockTask"] = {"100": True}
|
||||
for name in ("linear", "choice", "missing"):
|
||||
with self.subTest(name=name):
|
||||
self.planner = ProgressionPlanner(self.catalog, config({"100": task(startStep=step(story=name))}))
|
||||
self.assertTrue(self.plan()[0].block_reason)
|
||||
self.planner = ProgressionPlanner(self.catalog, config({"100": task(startStep=step(story="accept"))}))
|
||||
self.planner.acknowledge(self.snapshot, self.next("progression_dialogue"))
|
||||
self.next("progression_accept")
|
||||
|
||||
def test_missing_accept_response_never_invents_an_instance(self):
|
||||
self.snapshot.raw["currentTasks"] = []
|
||||
self.snapshot.raw["history"]["unlockTask"] = {"100": True}
|
||||
action = self.next("progression_accept")
|
||||
self.assertFalse(self.planner.acknowledge(self.snapshot, action, {}))
|
||||
self.assertIn("禁止自动重发", self.plan()[0].block_reason)
|
||||
|
||||
def test_reward_reply_received_successor_and_unlocked_sidequest(self):
|
||||
self.planner = ProgressionPlanner(self.catalog, config({
|
||||
"100": task(), "101": task("101"), "200": task("200", type=2)}))
|
||||
self.snapshot.raw["currentTasks"][0]["curStep"] = 2
|
||||
action = self.next("progression_complete")
|
||||
self.planner.acknowledge(self.snapshot, action, {
|
||||
"nextTasks": [{"id": 12, "typeId": "101", "curStep": 1}], "unlockTasks": ["200"]})
|
||||
following = self.next("progression_step")
|
||||
self.assertEqual(following.task_type_id, "101")
|
||||
states = {row["task_type_id"]: row["state"] for row in self.planner.rows(self.snapshot, self.policy, self.ranch)}
|
||||
self.assertEqual(states, {"100": "finished", "101": "received", "200": "unlocked"})
|
||||
|
||||
def test_graph_repair_uses_explicit_edges_and_three_exact_arrays(self):
|
||||
self.planner = ProgressionPlanner(self.catalog, config({
|
||||
"100": task(nextTasks=["500", "501"], unlockTasks=["700"]),
|
||||
"500": task("500"), "501": task("501", closed=True), "700": task("700", type=2)}))
|
||||
self.snapshot.raw["currentTasks"] = []
|
||||
self.snapshot.raw["history"]["passTask"] = {"100": True, "unrelated": False}
|
||||
self.policy.sidequests = True
|
||||
action = self.next("progression_update")
|
||||
self.assertEqual(action.path, "taskService/taskUpdate")
|
||||
self.assertEqual(action.payload, {"receiveTasks": [{"prev": "100", "taskTypeId": "500"}],
|
||||
"unlockTasks": [{"prev": "100", "taskTypeId": "700"}], "removeTasks": []})
|
||||
self.snapshot.raw["history"]["unlockTask"] = {"500": True, "700": True}
|
||||
self.policy.accept = False
|
||||
self.assertNotIn("progression_update", [action.kind for action in self.plan()])
|
||||
|
||||
def test_graph_no_guessed_first_task_and_legacy_root_is_respected(self):
|
||||
self.snapshot.raw["currentTasks"] = []
|
||||
self.assertEqual(self.plan(), [])
|
||||
data = config({"999": task("999", nextTasks=["100"]), "100": task()}, setting={"useOldNewTaskFunction": True})
|
||||
self.planner = ProgressionPlanner(self.catalog, data)
|
||||
self.snapshot.raw["history"]["passTask"] = {"999": True}
|
||||
self.assertEqual(self.plan(), [])
|
||||
|
||||
def test_closed_task_removal_ack_is_not_replayed_on_a_stale_snapshot(self):
|
||||
self.planner = ProgressionPlanner(self.catalog, config({"100": task(closed=True)}))
|
||||
action = self.next("progression_update")
|
||||
self.assertEqual(action.payload, {"unlockTasks": [], "receiveTasks": [], "removeTasks": [11]})
|
||||
self.planner.acknowledge(self.snapshot, action, {})
|
||||
self.assertEqual(self.plan(), [])
|
||||
|
||||
def test_declared_conditions_time_and_loader_anomaly_are_conservative(self):
|
||||
self.assertFalse(self.planner.condition({"minLevel": 21}, self.snapshot)[0])
|
||||
self.assertFalse(self.planner.condition({"maxLevel": 19}, self.snapshot)[0])
|
||||
self.assertFalse(self.planner.condition({"close": True}, self.snapshot)[0])
|
||||
self.assertFalse(self.planner.condition({"unfinishTask": ["100"]}, self.snapshot)[0])
|
||||
self.assertFalse(self.planner.condition({"passStage": ["0101"]}, self.snapshot)[0])
|
||||
self.assertTrue(self.planner.condition({"unlockStage": ["0101"]}, self.snapshot)[0])
|
||||
self.assertFalse(self.planner.condition({"lang": "CN"}, self.snapshot)[0])
|
||||
self.snapshot.raw["client_context"] = {"lang": "CN", "platform": "ANDROID", "channel": "DYD"}
|
||||
self.assertTrue(self.planner.condition({"lang": "CN", "platform": "ANDROID"}, self.snapshot)[0])
|
||||
self.assertFalse(self.planner.condition({"futureFlag": True}, self.snapshot)[0])
|
||||
with patch("ranch_assistant.model.time.time", return_value=1794112200):
|
||||
# 2026-11-08 12:30 UTC+8, Sunday == AS3 day 0.
|
||||
self.assertTrue(self.planner.condition({"week": [0], "startTime": 1230, "endTime": 1230}, self.snapshot)[0])
|
||||
self.assertFalse(self.planner.condition({"week": [1]}, self.snapshot)[0])
|
||||
self.assertFalse(self.planner.condition({"endTimestamp": 1}, self.snapshot)[0])
|
||||
|
||||
def test_guide_gates_and_special_gacha_stay_blocked(self):
|
||||
self.planner = ProgressionPlanner(self.catalog, config({"100": task(steps=[step(passGuide="minefail")])}))
|
||||
self.assertTrue(self.plan()[0].block_reason)
|
||||
self.snapshot.raw["history"]["guide_record"] = {"minefail": True}
|
||||
self.next("progression_step")
|
||||
self.planner = ProgressionPlanner(self.catalog, config({"1001006": task("1001006", steps=[step()] * 4)}))
|
||||
self.snapshot.raw["currentTasks"] = [{"id": 12, "typeId": "1001006", "curStep": 4}]
|
||||
self.assertIn("特殊抽蛋", self.plan()[0].block_reason)
|
||||
|
||||
def test_item_reserve_locks_and_exact_remove_ids(self):
|
||||
self.planner = ProgressionPlanner(self.catalog, config({"100": task(steps=[step("getItem", statusValue={"type": 30001, "num": 3, "remove": True})])}))
|
||||
self.snapshot.raw["items"] = [{"id": 1, "typeId": 30001, "num": 2}, {"id": 2, "typeId": 30001, "num": 4},
|
||||
{"id": 3, "typeId": 30001, "num": 100, "lock": True}]
|
||||
self.assertIn("未启用", self.plan()[0].block_reason)
|
||||
self.policy.allow_items = True
|
||||
self.policy.item_reserves = {"30001": 4}
|
||||
self.assertIn("保留", self.plan()[0].block_reason)
|
||||
self.policy.item_reserves = {"30001": 3}
|
||||
action = self.next("progression_step")
|
||||
self.assertEqual(action.payload["removeIds"], [1, 2])
|
||||
self.assertEqual(self.snapshot.raw["items"][1]["num"], 4)
|
||||
|
||||
def test_observation_only_items_still_send_source_ids_without_allowing_consumption(self):
|
||||
self.planner = ProgressionPlanner(self.catalog, config({"100": task(steps=[step("getItem", statusValue={"type": 30001, "num": 2, "remove": False})])}))
|
||||
self.snapshot.raw["items"] = [{"id": 1, "typeId": 30001, "num": 2}]
|
||||
self.policy.item_reserves = {"30001": 100}
|
||||
self.assertEqual(self.next("progression_step").payload["removeIds"], [1])
|
||||
|
||||
def test_money_removal_respects_maximum_and_ranch_reserve(self):
|
||||
self.planner = ProgressionPlanner(self.catalog, config({"100": task(steps=[step("getMoney", statusValue={"money": 1200, "remove": True})])}))
|
||||
self.assertIn("上限", self.plan()[0].block_reason)
|
||||
self.policy.max_money = 1200
|
||||
self.assertIn("保留", self.plan()[0].block_reason)
|
||||
self.snapshot.raw["master"]["money"] = 2200
|
||||
self.next("progression_step")
|
||||
|
||||
def test_monster_submission_never_consumes_team_locked_or_reserved_monsters(self):
|
||||
self.planner = ProgressionPlanner(self.catalog, config({"100": task(steps=[step("getMonster", statusValue={"type": 1001010, "num": 1, "mode": 2, "remove": True})])}))
|
||||
base = self.catalog.monster(1001010)
|
||||
monster = {"id": 1, "typeId": 1001010, "mode": 2, "process": 3, "level": 1,
|
||||
**{"g" + stat.capitalize(): base[stat + "_grow_min"] for stat in ("atk", "def", "hp", "dex")}}
|
||||
self.snapshot.raw["monsters"] = [monster]
|
||||
self.policy.allow_monsters = True
|
||||
self.ranch.protect_quality = 5
|
||||
self.assertEqual(self.next("progression_step").payload["removeIds"], [1])
|
||||
for changes in ({"lock": True}, {"entangle": True}, {"equip1": 3}, {"inExploreTeam": True}):
|
||||
with self.subTest(changes=changes):
|
||||
self.snapshot.raw["monsters"] = [monster | changes]
|
||||
self.assertTrue(self.plan()[0].block_reason)
|
||||
self.snapshot.raw["monsters"] = [monster]
|
||||
self.snapshot.raw["teams"] = [{"monsters": [1]}]
|
||||
self.assertTrue(self.plan()[0].block_reason)
|
||||
self.snapshot.raw["teams"] = []
|
||||
self.ranch.reserved_types = [1001010]
|
||||
self.assertTrue(self.plan()[0].block_reason)
|
||||
|
||||
def test_kill_target_uses_step_value_and_never_configured_relative_count(self):
|
||||
self.planner = ProgressionPlanner(self.catalog, config({"100": task(steps=[step("killMonster", statusValue={"type": 1001010, "num": 2})])}))
|
||||
self.snapshot.raw["currentTasks"][0]["stepValue"] = 150
|
||||
self.snapshot.raw["history"]["numKillMonsters"] = {"1001010": 149}
|
||||
self.assertTrue(self.plan()[0].block_reason)
|
||||
self.snapshot.raw["history"]["numKillMonsters"]["1001010"] = 150
|
||||
self.next("progression_step")
|
||||
self.snapshot.raw["currentTasks"][0]["stepValue"] = None
|
||||
self.assertIn("未同步", self.plan()[0].block_reason)
|
||||
|
||||
def test_pass_stage_and_task_battle_route_are_distinct_and_never_sweeps(self):
|
||||
for kind in ("battle", "passStage"):
|
||||
with self.subTest(kind=kind):
|
||||
value = {"stage": "0101", "level": "1"} if kind == "passStage" else {}
|
||||
self.planner = ProgressionPlanner(self.catalog, config({"100": task(steps=[step(kind, statusValue=value, battle={"teams": [{"mons": []}]})])}))
|
||||
self.snapshot.raw["history"]["passStage"] = {"0101": [1, 2, 3]}
|
||||
action = self.next("progression_battle")
|
||||
self.assertEqual(action.path, "battleService/battleStart")
|
||||
self.assertEqual(action.payload, {"battleType": "task", "taskTypeId": "100"})
|
||||
self.assertEqual(action.battle_kind, "task" if kind == "battle" else "passStage")
|
||||
self.assertEqual(action.stage_id, "" if kind == "battle" else "0101")
|
||||
self.assertNotIn("battleData", action.payload)
|
||||
self.planner.battle_lost(self.snapshot, action)
|
||||
self.assertIn("战败", self.plan()[0].block_reason)
|
||||
|
||||
def test_task_pass_stage_stamina_and_hard_mode_gates(self):
|
||||
self.planner = ProgressionPlanner(self.catalog, config({"100": task(steps=[step("passStage", statusValue={"stage": "0101", "level": 2})])}))
|
||||
self.snapshot.raw["history"]["openHardMode"] = False
|
||||
self.assertIn("高难度", self.plan()[0].block_reason)
|
||||
self.snapshot.raw["history"]["openHardMode"] = True
|
||||
self.policy.reserve_ti = 47
|
||||
self.assertIn("体力", self.plan()[0].block_reason)
|
||||
self.policy.reserve_ti = 46
|
||||
self.next("progression_battle")
|
||||
|
||||
def test_battle_start_or_local_win_is_not_a_step_settlement(self):
|
||||
self.planner = ProgressionPlanner(self.catalog, config({"100": task(steps=[step("battle", battle={"teams": []})])}))
|
||||
action = self.next("progression_battle")
|
||||
for response in ({"resCode": 0}, {"win": True}, {"resCode": 1, "reward": {}}):
|
||||
with self.subTest(response=response), self.assertRaises(ValueError):
|
||||
self.planner.acknowledge(self.snapshot, action, response)
|
||||
|
||||
def test_pass_stage_local_flags_require_confirmed_settlement(self):
|
||||
self.planner = ProgressionPlanner(self.catalog, config({"100": task(steps=[
|
||||
step("passStage", statusValue={"stage": "0101", "level": 1}),
|
||||
step(condition={"passStage": ["0101"]})])}))
|
||||
action = self.next("progression_battle")
|
||||
self.assertFalse(self.planner.condition({"passStage": ["0101"]}, self.snapshot)[0])
|
||||
self.planner.acknowledge(self.snapshot, action, {"costTi": 3, "unlockStage": [], "lockStage": []})
|
||||
self.assertTrue(self.planner.condition({"passStage": ["0101"]}, self.snapshot)[0])
|
||||
self.planner.acknowledge(self.snapshot, self.next("progression_local_step"))
|
||||
self.assertEqual(self.next("progression_step").step_number, 2)
|
||||
|
||||
def test_wrong_account_stale_and_invalid_wire_steps_are_not_accepted(self):
|
||||
action = self.next("progression_step")
|
||||
other = snapshot(master={"id": 2})
|
||||
with self.assertRaises(ValueError):
|
||||
self.planner.acknowledge(other, action, {})
|
||||
with self.assertRaises(ValueError):
|
||||
self.planner.acknowledge(self.snapshot, replace(action, payload={}), {})
|
||||
self.snapshot.raw["currentTasks"][0]["curStep"] = 0
|
||||
self.planner = ProgressionPlanner(self.catalog, config())
|
||||
self.assertIn("一基步骤", self.plan()[0].block_reason)
|
||||
|
||||
def test_pending_request_survives_restore_and_is_not_replayed(self):
|
||||
action = self.next("progression_step")
|
||||
self.planner.mark_started(self.snapshot, action)
|
||||
restored = ProgressionPlanner(self.catalog, config())
|
||||
restored.restore_state(json.loads(json.dumps(self.planner.export_state())))
|
||||
self.assertTrue(restored.plan(self.snapshot, self.policy, self.ranch)[0].block_reason)
|
||||
self.snapshot.raw["currentTasks"][0]["curStep"] = 2
|
||||
planned = restored.plan(self.snapshot, self.policy, self.ranch)[0]
|
||||
self.assertEqual(planned.kind, "progression_local_step")
|
||||
|
||||
def test_local_progress_import_requires_an_actual_step_ack(self):
|
||||
cursor = {"11:100": {"task_id": 11, "task_type_id": "100", "steps": {
|
||||
"1": {"kind": "progression_dialogue", "phase": "before", "acknowledged": True}}}}
|
||||
planned = self.planner.plan(self.snapshot, self.policy, self.ranch, local_progress=cursor)
|
||||
self.assertEqual(planned[0].kind, "progression_step")
|
||||
cursor["11:100"]["steps"]["1"] = {"kind": "progression_step", "acknowledged": True, "response": {"taskStepValue": None}}
|
||||
planned = self.planner.plan(self.snapshot, self.policy, self.ranch, local_progress=cursor)
|
||||
self.assertEqual(planned[0].kind, "progression_local_step")
|
||||
|
||||
def test_unknown_types_are_visible_and_commissions_are_not_duplicated(self):
|
||||
self.planner = ProgressionPlanner(self.catalog, config({"100": task(type=6), "400": task("400", type=4)}))
|
||||
self.snapshot.raw["currentTasks"].append({"id": 12, "typeId": "400", "curStep": 1})
|
||||
rows = self.planner.rows(self.snapshot, self.policy, self.ranch)
|
||||
self.assertEqual({row["category"] for row in rows}, {"unknown", "commission"})
|
||||
self.policy.commissions = True
|
||||
self.assertTrue(all(not action.path for action in self.plan()))
|
||||
self.assertIn("QuestPolicy", next(row for row in rows if row["category"] == "commission")["block_reason"])
|
||||
|
||||
|
||||
class CommissionProgressionTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.catalog = Catalog()
|
||||
|
||||
def setUp(self):
|
||||
self.snapshot = snapshot(currentTasks=[{"id": 40, "typeId": "400", "curStep": 1}])
|
||||
self.snapshot.raw["history"].update(loopTaskTime=int(self.snapshot.now), loopTaskNum=6, loopTask={"1": []})
|
||||
self.quest = QuestPolicy(enabled=True)
|
||||
self.ranch = Policy(keep_money=1000)
|
||||
self.battle_policy = ProgressionPolicy(team="teamB", reserve_ti=5)
|
||||
self.planner = ProgressionPlanner(self.catalog, config({"400": task("400", type=4)}))
|
||||
|
||||
def plans(self):
|
||||
return self.planner.commission_plan(self.snapshot, self.quest, self.ranch, battle_policy=self.battle_policy)
|
||||
|
||||
def next(self, kind):
|
||||
actions = self.plans()
|
||||
self.assertTrue(actions)
|
||||
self.assertEqual(actions[0].kind, kind, actions[0].description)
|
||||
return actions[0]
|
||||
|
||||
def offers(self, values=None):
|
||||
self.snapshot.raw["currentTasks"] = []
|
||||
self.snapshot.raw["history"]["loopTask"] = {"1": ["400"] if values is None else values}
|
||||
|
||||
def test_current_commission_uses_full_nonbattle_acknowledgement_flow(self):
|
||||
self.snapshot.raw["history"]["passTask"] = {"400": True} # Prior day's same type.
|
||||
action = self.next("progression_step")
|
||||
self.planner.acknowledge(self.snapshot, action, {})
|
||||
self.planner.acknowledge(self.snapshot, self.next("progression_local_step"))
|
||||
reward = self.next("progression_complete")
|
||||
self.planner.acknowledge(self.snapshot, reward, {})
|
||||
self.assertEqual(self.plans(), [])
|
||||
self.assertEqual(self.planner.commission_rows(self.snapshot, self.quest, self.ranch)[0]["state"], "finished")
|
||||
|
||||
def test_battle_and_pass_stage_use_quest_battle_switch_and_task_route(self):
|
||||
for kind in ("battle", "passStage"):
|
||||
with self.subTest(kind=kind):
|
||||
value = {"stage": "0101", "level": 1} if kind == "passStage" else {}
|
||||
self.planner = ProgressionPlanner(self.catalog, config({"400": task("400", type=4, steps=[
|
||||
step(kind, battle={"teams": []}, statusValue=value, afterStory="linear")])}))
|
||||
self.quest.battle_tasks = False
|
||||
self.assertIn("战斗开关", self.plans()[0].block_reason)
|
||||
self.quest.battle_tasks = True
|
||||
action = self.next("progression_battle")
|
||||
self.assertEqual(action.payload, {"battleType": "task", "taskTypeId": "400"})
|
||||
self.assertEqual(action.battle_kind, "task" if kind == "battle" else "passStage")
|
||||
self.assertEqual(action.team, "teamB")
|
||||
self.assertEqual(action.battle_mode, "original")
|
||||
self.planner.acknowledge(self.snapshot, action, {"reward": {}})
|
||||
self.assertEqual(self.next("progression_dialogue").phase, "after")
|
||||
|
||||
def test_offer_acceptance_has_exact_loop_payload_and_spends_one_slot_once(self):
|
||||
self.offers()
|
||||
self.snapshot.raw["history"]["loopTaskNum"] = 1
|
||||
action = self.next("progression_loop_accept")
|
||||
self.assertEqual(action.path, "taskService/taskLoopReceive")
|
||||
self.assertEqual(action.payload, {"taskTypeId": "400", "city": 1})
|
||||
response = {"task": {"id": 41, "typeId": "400", "curStep": 1}}
|
||||
self.assertTrue(self.planner.acknowledge(self.snapshot, action, response))
|
||||
self.assertFalse(self.planner.acknowledge(self.snapshot, action, response))
|
||||
account = next(iter(self.planner.export_state()["accounts"].values()))
|
||||
self.assertEqual(account["commissions"]["remaining"], 0)
|
||||
self.assertEqual(self.next("progression_step").task_id, 41)
|
||||
self.planner.acknowledge(self.snapshot, self.next("progression_step"), {})
|
||||
self.planner.acknowledge(self.snapshot, self.next("progression_local_step"))
|
||||
self.planner.acknowledge(self.snapshot, self.next("progression_complete"), {})
|
||||
self.assertEqual(self.plans(), [])
|
||||
|
||||
def test_quest_enabled_accept_city_and_quota_are_authoritative(self):
|
||||
self.offers()
|
||||
self.quest.enabled = False
|
||||
self.assertEqual(self.plans(), [])
|
||||
self.quest.enabled = True
|
||||
self.quest.accept = False
|
||||
self.assertEqual(self.plans(), [])
|
||||
self.quest.accept = True
|
||||
self.quest.city = 2
|
||||
self.assertEqual(self.plans(), [])
|
||||
self.quest.city = 1
|
||||
self.snapshot.raw["history"]["loopTaskNum"] = 0
|
||||
self.assertEqual(self.plans(), [])
|
||||
self.snapshot.raw["history"]["loopTaskNum"] = 1
|
||||
self.next("progression_loop_accept")
|
||||
|
||||
def test_quest_resources_control_offer_acceptance(self):
|
||||
self.planner = ProgressionPlanner(self.catalog, config({"400": task("400", type=4, steps=[
|
||||
step("getItem", statusValue={"type": 30001, "num": 3, "remove": True}, afterStory="linear")])}))
|
||||
self.offers()
|
||||
self.snapshot.raw["items"] = [{"id": 1, "typeId": 30001, "num": 5}]
|
||||
self.assertEqual(self.plans(), [])
|
||||
self.quest.allow_items = True
|
||||
self.quest.item_reserves = {"30001": 3}
|
||||
self.assertEqual(self.plans(), [])
|
||||
row = self.planner.commission_rows(self.snapshot, self.quest, self.ranch)[0]
|
||||
self.assertIn("保留", row["block_reason"])
|
||||
self.assertFalse(row["supported"])
|
||||
self.quest.item_reserves = {"30001": 2}
|
||||
self.next("progression_loop_accept")
|
||||
|
||||
def test_offer_with_linear_stories_is_accepted_and_choice_is_not(self):
|
||||
self.offers()
|
||||
for name, expected in (("linear", True), ("choice", False)):
|
||||
with self.subTest(name=name):
|
||||
self.planner = ProgressionPlanner(self.catalog, config({"400": task("400", type=4, steps=[step(story=name)])}))
|
||||
self.assertEqual(bool(self.plans()), expected)
|
||||
|
||||
def test_battle_offers_need_existing_battle_tasks_opt_in(self):
|
||||
self.offers()
|
||||
self.planner = ProgressionPlanner(self.catalog, config({"400": task("400", type=4, steps=[step("battle", battle={"teams": []})])}))
|
||||
self.assertEqual(self.plans(), [])
|
||||
self.quest.battle_tasks = True
|
||||
self.next("progression_loop_accept")
|
||||
|
||||
def test_reset_expires_old_instance_and_uses_confirmed_new_offers(self):
|
||||
self.snapshot.raw["history"]["loopTaskTime"] -= 86400
|
||||
self.snapshot.raw["history"]["loopTaskNum"] = 0
|
||||
action = self.next("progression_loop_reset")
|
||||
self.assertEqual(action.path, "taskService/taskLoopFlush")
|
||||
self.assertEqual(action.payload, {})
|
||||
self.planner.acknowledge(self.snapshot, action, {"loopTask": {"1": [400]}})
|
||||
following = self.next("progression_loop_accept")
|
||||
self.assertEqual(following.payload, {"taskTypeId": "400", "city": 1})
|
||||
account = next(iter(self.planner.export_state()["accounts"].values()))
|
||||
self.assertIn("40", account["commissions"]["expired_ids"])
|
||||
self.assertEqual(account["commissions"]["remaining"], 6)
|
||||
|
||||
def test_uncertain_loop_accept_reconciles_without_spending_quota_twice(self):
|
||||
self.offers()
|
||||
self.snapshot.raw["history"]["loopTaskNum"] = 1
|
||||
action = self.next("progression_loop_accept")
|
||||
self.planner.mark_uncertain(self.snapshot, action)
|
||||
self.assertTrue(self.plans()[0].block_reason)
|
||||
self.snapshot.raw["currentTasks"] = [{"id": 41, "typeId": "400", "curStep": 1}]
|
||||
self.snapshot.raw["history"]["loopTaskNum"] = 0
|
||||
self.next("progression_step")
|
||||
account = next(iter(self.planner.export_state()["accounts"].values()))
|
||||
self.assertEqual(account["commissions"]["remaining"], 0)
|
||||
|
||||
def test_cn_reset_uses_ten_second_grace(self):
|
||||
midnight = 1794067200 # 2026-11-08 00:00 UTC+8.
|
||||
with patch("ranch_assistant.model.time.time", return_value=midnight + 5):
|
||||
self.snapshot.raw["history"]["loopTaskTime"] = midnight - 100
|
||||
self.assertNotEqual(self.plans()[0].kind, "progression_loop_reset")
|
||||
with patch("ranch_assistant.model.time.time", return_value=midnight + 11):
|
||||
self.assertEqual(self.plans()[0].kind, "progression_loop_reset")
|
||||
|
||||
|
||||
class RecoveredProgressionDataTests(unittest.TestCase):
|
||||
def test_full_original_tasks_static_manifest_and_battle_archive(self):
|
||||
data = load_progression_data()
|
||||
self.assertEqual(len(data.tasks), 1165)
|
||||
self.assertEqual(sum(len(task["steps"]) for task in data.tasks.values()), 3462)
|
||||
self.assertEqual(len(data.stages), 1178)
|
||||
self.assertEqual(len(data.scripts), 4269)
|
||||
self.assertEqual(data.manifest["source"]["apk_sha256"], ORIGINAL_APK_SHA256)
|
||||
self.assertEqual(len(Catalog().data["task_info"]), 83)
|
||||
self.assertEqual(data.task("1001002")["steps"][0]["story"], "task_1001002")
|
||||
self.assertIs(type(data.task("1001001")["unlockTasks"]), list)
|
||||
self.assertEqual(data.manifest["source"]["amf_reader_sha256"], hashlib.sha256((ROOT / "ranch_assistant/amf.py").read_bytes()).hexdigest())
|
||||
self.assertTrue(data.script("task_1001002")["supported"])
|
||||
for name, record in data.manifest["artifacts"].items():
|
||||
self.assertEqual(hashlib.sha256((DATA_DIR / name).read_bytes()).hexdigest(), record["sha256"])
|
||||
self.assertLess((DATA_DIR / BATTLES_NAME).stat().st_size, 3_000_000)
|
||||
with zipfile.ZipFile(DATA_DIR / BATTLES_NAME) as archive:
|
||||
self.assertEqual(len(archive.namelist()), 1178)
|
||||
self.assertTrue(all(name.startswith("stages/") and name.endswith(".json") for name in archive.namelist()))
|
||||
self.assertTrue(all(info.date_time == (1980, 1, 1, 0, 0, 0) for info in archive.infolist()))
|
||||
self.assertTrue(data.stage_battle("0101", 1))
|
||||
self.assertTrue(data.task_battle("1001001", 1))
|
||||
|
||||
def test_loader_never_opens_apk_or_eagerly_reads_battles(self):
|
||||
with patch("ranch_assistant.game_data.zipfile.ZipFile", side_effect=AssertionError("eager archive read")):
|
||||
data = ProgressionData()
|
||||
self.assertEqual(len(data.tasks), 1165)
|
||||
|
||||
def test_artifact_tampering_is_rejected(self):
|
||||
with patch("ranch_assistant.game_data.Path.read_bytes", return_value=b"tampered"):
|
||||
with self.assertRaisesRegex(ProgressionDataError, "hash mismatch"):
|
||||
ProgressionData()
|
||||
|
||||
def test_shared_static_data_is_not_mutated_by_account_planning(self):
|
||||
data = load_progression_data()
|
||||
before = json.dumps(data.data, sort_keys=True, ensure_ascii=True)
|
||||
planner = ProgressionPlanner(Catalog(), data)
|
||||
planner.rows(snapshot(), ProgressionPolicy(), Policy())
|
||||
planner.plan(snapshot(master={"id": 2}), ProgressionPolicy(enabled=True), Policy())
|
||||
self.assertEqual(json.dumps(data.data, sort_keys=True, ensure_ascii=True), before)
|
||||
|
||||
def test_linear_hide_newlines_and_placeholders_are_presentation(self):
|
||||
expressions = [
|
||||
{"key": "text", "para": {"text": "[show]你好 [{gn.myName}][r]下一行\n[hide][cm]"}},
|
||||
{"key": "event", "para": {"event": "GAoEvent", "eventData": "true"}},
|
||||
]
|
||||
summary = summarize_script(json.dumps({"exps": expressions}).encode(), "fixture")
|
||||
self.assertTrue(summary["supported"], summary)
|
||||
self.assertTrue(summary["answer"])
|
||||
self.assertEqual(summary["dialogue_lines"], 1)
|
||||
for expression in ({"key": "option", "para": {"options": []}}, {"key": "jump", "para": {"tag": "x"}},
|
||||
{"key": "event", "para": {"event": "GAoEvent", "eventData": '{"action":"gacha"}'}}):
|
||||
with self.subTest(expression=expression):
|
||||
summary = summarize_script(json.dumps({"exps": [expression]}).encode(), "fixture")
|
||||
self.assertFalse(summary["supported"])
|
||||
|
||||
|
||||
class FarmingAndAreaTests(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.catalog = Catalog()
|
||||
|
||||
def setUp(self):
|
||||
self.snapshot = snapshot()
|
||||
self.policy = ProgressionPolicy(enabled=True)
|
||||
self.ranch = Policy(keep_money=1000)
|
||||
self.data = config(farming={"kills": {"1001010": [{"stage_id": "0101", "difficulty": 1, "configured_enemies": 2}]},
|
||||
"items": {key: [{"stage_id": "0101", "difficulty": 1}] for key in ("30001", "1001010")}})
|
||||
|
||||
def planner(self, current_step):
|
||||
data = deepcopy(self.data)
|
||||
data["task_info"]["100"]["steps"] = [current_step]
|
||||
return ProgressionPlanner(self.catalog, data)
|
||||
|
||||
def test_kill_farming_has_no_task_wire_context_and_never_uses_sweep(self):
|
||||
planner = self.planner(step("killMonster", statusValue={"type": 1001010, "num": 5}))
|
||||
self.snapshot.raw["currentTasks"][0]["stepValue"] = 5
|
||||
self.snapshot.raw["history"]["numKillMonsters"] = {"1001010": 0}
|
||||
self.snapshot.raw["history"]["passStage"] = {"0101": [1, 2, 3]}
|
||||
action = planner.plan(self.snapshot, self.policy, self.ranch)[0]
|
||||
self.assertEqual(action.kind, "stage_battle")
|
||||
self.assertEqual(action.battle_kind, "ordinary_stage")
|
||||
self.assertEqual((action.task_id, action.task_type_id), (0, ""))
|
||||
self.assertEqual((action.source_task_id, action.source_task_type_id, action.source_step_number), (11, "100", 1))
|
||||
self.assertEqual(action.payload, {"stageTypeId": "0101", "stageLevel": "1"})
|
||||
self.assertEqual(action.path, "stageService/stageStart")
|
||||
with self.assertRaises(ValueError):
|
||||
planner.acknowledge(self.snapshot, action, {"reward": {}})
|
||||
self.assertEqual(self.snapshot.raw["currentTasks"][0]["curStep"], 1)
|
||||
self.snapshot.raw["history"]["numKillMonsters"]["1001010"] = 5
|
||||
self.assertEqual(planner.plan(self.snapshot, self.policy, self.ranch)[0].kind, "progression_step")
|
||||
|
||||
def test_loot_uses_sweep_only_after_three_difficulties_are_cleared(self):
|
||||
planner = self.planner(step("getItem", statusValue={"type": 30001, "num": 3, "remove": False}))
|
||||
self.snapshot.raw["history"]["passStage"] = {"0101": [3]}
|
||||
self.assertEqual(planner.plan(self.snapshot, self.policy, self.ranch)[0].kind, "stage_battle")
|
||||
self.snapshot.raw["history"]["passStage"] = {"0101": [1, 2, 3]}
|
||||
action = planner.plan(self.snapshot, self.policy, self.ranch)[0]
|
||||
self.assertEqual(action.kind, "sweep")
|
||||
self.assertEqual(action.task_id, 0)
|
||||
self.assertEqual(action.source_task_type_id, "100")
|
||||
self.policy.allow_sweep = False
|
||||
self.assertEqual(planner.plan(self.snapshot, self.policy, self.ranch)[0].kind, "stage_battle")
|
||||
|
||||
def test_egg_farming_and_reserves_wait_for_actual_inventory(self):
|
||||
planner = self.planner(step("getMonster", statusValue={"type": 1001010, "num": 2, "mode": 0, "remove": True}))
|
||||
self.policy.allow_items = True
|
||||
self.policy.item_reserves = {"1001010": 2}
|
||||
self.snapshot.raw["items"] = [{"id": 1, "typeId": 1001010, "num": 3}]
|
||||
self.assertEqual(planner.plan(self.snapshot, self.policy, self.ranch)[0].kind, "stage_battle")
|
||||
self.snapshot.raw["items"][0]["num"] = 4
|
||||
self.assertEqual(planner.plan(self.snapshot, self.policy, self.ranch)[0].kind, "progression_step")
|
||||
|
||||
def test_farming_respects_disabled_consumption_stamina_locks_and_premium(self):
|
||||
planner = self.planner(step("getItem", statusValue={"type": 30001, "num": 3, "remove": True}))
|
||||
self.assertTrue(planner.plan(self.snapshot, self.policy, self.ranch)[0].block_reason)
|
||||
self.policy.allow_items = True
|
||||
self.policy.reserve_ti = 48
|
||||
self.assertTrue(planner.plan(self.snapshot, self.policy, self.ranch)[0].block_reason)
|
||||
self.policy.reserve_ti = 0
|
||||
self.snapshot.raw["history"]["unlockStage"] = {}
|
||||
self.assertTrue(planner.plan(self.snapshot, self.policy, self.ranch)[0].block_reason)
|
||||
self.snapshot.raw["history"]["unlockStage"] = {"0101": [1]}
|
||||
self.data["stage_info"]["0101"]["cost"]["ke"] = 1
|
||||
self.assertTrue(self.planner(step("getItem", statusValue={"type": 30001, "num": 1})).plan(self.snapshot, self.policy, self.ranch)[0].block_reason)
|
||||
|
||||
def test_task_interception_and_auto_farm_switch_are_honored(self):
|
||||
current = step("getItem", statusValue={"type": 30001, "num": 3})
|
||||
planner = self.planner(current)
|
||||
self.policy.auto_farm = False
|
||||
self.assertTrue(planner.plan(self.snapshot, self.policy, self.ranch)[0].block_reason)
|
||||
self.policy.auto_farm = True
|
||||
data = deepcopy(self.data)
|
||||
data["task_info"]["100"]["steps"] = [current]
|
||||
data["task_info"]["200"] = task("200", type=2, steps=[step(position="city1_wild_stage0101_level1")])
|
||||
planner = ProgressionPlanner(self.catalog, data)
|
||||
self.snapshot.raw["currentTasks"].append({"id": 12, "typeId": "200", "curStep": 1})
|
||||
self.assertTrue(planner.plan(self.snapshot, self.policy, self.ranch)[0].block_reason)
|
||||
|
||||
def test_farming_ticket_locks_and_gift_reserves_are_protected(self):
|
||||
self.data["stage_info"]["0101"]["cost"]["items"] = [{"typeId": 30002, "num": 1}]
|
||||
self.policy.allow_items = True
|
||||
self.snapshot.raw["items"] = [{"id": 2, "typeId": 30002, "num": 1, "sysLock": True}]
|
||||
planner = self.planner(step("getItem", statusValue={"type": 30001, "num": 2}))
|
||||
self.assertTrue(planner.plan(self.snapshot, self.policy, self.ranch)[0].block_reason)
|
||||
self.snapshot.raw["items"][0]["sysLock"] = False
|
||||
self.ranch.gift_items = {"30002": {"enabled": True, "reserve": 1}}
|
||||
self.assertTrue(planner.plan(self.snapshot, self.policy, self.ranch)[0].block_reason)
|
||||
|
||||
def test_static_index_excludes_juveniles_allies_objects_and_zero_chance(self):
|
||||
monsters = [
|
||||
{"type": "1001010", "team": 2, "mode": 2},
|
||||
{"type": "1001020", "team": 2, "mode": 1},
|
||||
{"type": "1001030", "team": 1, "mode": 2},
|
||||
{"type": "1001040", "team": 2, "mode": 2, "isObject": True},
|
||||
]
|
||||
reward = {"rewards": [
|
||||
{"item_num": 1, "item_chance": 1, "items": [{"name": "30001,1,2", "value": 1}]},
|
||||
{"item_num": 1, "item_chance": 0, "items": [{"name": "30002,1,1", "value": 1}]},
|
||||
{"num": 1, "chance": 1, "monMode": 0, "monsters": [{"name": "1001010", "value": 1}]},
|
||||
{"num": 1, "chance": 1, "monMode": 2, "monsters": [{"name": "1001020", "value": 1}]},
|
||||
]}
|
||||
index = farming_index({"0101": {"level": {"1": {"battle": {"teams": [{"mons": monsters}]}, "reward": reward}}}})
|
||||
self.assertEqual(set(index["kills"]), {"1001010"})
|
||||
self.assertEqual(set(index["items"]), {"30001", "1001010"})
|
||||
|
||||
def test_area_and_dungeon_navigation_use_recovered_conditions_and_labels(self):
|
||||
self.data["area_info"] = {"areaInfo": {"1f": {"name": "森林", "city": "1", "openStage": "0101"}},
|
||||
"areaMap": {"1": {"positions": [
|
||||
{"posId": "city1_wild_1f", "action": "area", "actionPara": {"area": "1f"}, "condition": {"finishTask": ["200"]}},
|
||||
{"posId": "city1_dungeon1", "action": "dungeon", "actionPara": {"dungeon": "dungeon1"}, "condition": {}},
|
||||
]}}}
|
||||
self.data["mine_info"] = {"mines": {"dungeon1": {"pos": "city1_dungeon1", "name": "试炼矿洞"}}}
|
||||
planner = self.planner(step(position="city1_wild_1f", story="linear"))
|
||||
self.assertTrue(planner.plan(self.snapshot, self.policy, self.ranch)[0].block_reason)
|
||||
self.snapshot.raw["history"]["passTask"] = {"200": True}
|
||||
action = planner.plan(self.snapshot, self.policy, self.ranch)[0]
|
||||
self.assertEqual(action.kind, "progression_navigate")
|
||||
self.assertIn("森林", action.location)
|
||||
planner = self.planner(step(position="city1_dungeon1", story="linear"))
|
||||
action = planner.plan(self.snapshot, self.policy, self.ranch)[0]
|
||||
self.assertEqual(action.kind, "progression_navigate")
|
||||
self.assertIn("试炼矿洞", action.location)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user