65 lines
3.5 KiB
Python
65 lines
3.5 KiB
Python
import copy
|
|
import unittest
|
|
from ranch_assistant.engine import Engine, demo_snapshot
|
|
from ranch_assistant.model import Catalog, Planner, Policy
|
|
|
|
|
|
class BatchFeedingTests(unittest.TestCase):
|
|
def setUp(self):
|
|
self.catalog = Catalog()
|
|
self.snapshot = demo_snapshot(self.catalog)
|
|
template = self.snapshot.raw["monsters"][0]
|
|
foods = [copy.deepcopy(template) | {"id": 101 + i, "process": 3, "mode": 2, "roomId": 1} for i in range(4)]
|
|
self.snapshot.raw["monsters"] = foods + [self.snapshot.monsters[900]]
|
|
self.snapshot.raw["stacks"] = []
|
|
self.planner = Planner(self.catalog)
|
|
self.planner.managed.update(m["id"] for m in foods)
|
|
self.policy = Policy(strategy="experience", protect_star=6, protect_quality=5, feed_target=900, fill=False)
|
|
|
|
def test_all_eligible_foods_use_one_request_and_log_names_and_ids(self):
|
|
actions = self.planner.plan(self.snapshot, self.policy)
|
|
self.assertEqual(len(actions), 1)
|
|
self.assertEqual(actions[0].payload, {"targetId": 900, "foods": [101, 102, 103, 104]})
|
|
for mid in (900, 101, 102, 103, 104):
|
|
self.assertIn(self.catalog.monster_label(self.snapshot.monsters[mid]), actions[0].description)
|
|
|
|
def test_locked_team_and_unmanaged_foods_are_excluded(self):
|
|
self.snapshot.monsters[102]["lock"] = 1
|
|
self.snapshot.raw["teams"][0]["monsters"].append(103)
|
|
self.planner.managed.discard(104)
|
|
self.assertEqual(self.planner.plan(self.snapshot, self.policy)[0].payload["foods"], [101])
|
|
|
|
def test_remaining_experience_bounds_batch_at_current_breakthrough_cap(self):
|
|
target = self.snapshot.monsters[900]
|
|
target.update(level=19, potentialLevel=2, exp=self.catalog.data["monster_level"]["20"] - 1)
|
|
self.assertEqual(self.planner.plan(self.snapshot, self.policy)[0].payload["foods"], [101])
|
|
target["level"] = 20
|
|
self.assertFalse(any(a.kind == "feed" for a in self.planner.plan(self.snapshot, self.policy)))
|
|
|
|
def test_full_first_target_advances_to_next_priority(self):
|
|
first = self.snapshot.monsters[900]
|
|
first.update(level=20, potentialLevel=2)
|
|
self.snapshot.raw["monsters"].append(copy.deepcopy(first) | {"id": 901, "level": 1, "exp": 0})
|
|
self.policy.feed_targets = {"900": 1, "901": 2}
|
|
self.assertEqual(self.planner.plan(self.snapshot, self.policy)[0].payload["targetId"], 901)
|
|
|
|
def test_collect_then_feed_all_in_two_batches(self):
|
|
for mid in (101, 102, 103, 104):
|
|
self.snapshot.monsters[mid].update(process=2, roomId=None)
|
|
self.snapshot.raw["stacks"] = [{"id": i + 1, "position": i, "monsterId": 101 + i} for i in range(4)]
|
|
engine = Engine(self.catalog)
|
|
engine.snapshot, engine.policy, engine.auto = self.snapshot, self.policy, True
|
|
_, actions, _ = engine.poll()
|
|
self.assertTrue(all(self.snapshot.monsters[mid]["process"] == 3 for mid in (101, 102, 103, 104)))
|
|
self.assertEqual(actions[0].payload["foods"], [101, 102, 103, 104])
|
|
engine.poll()
|
|
self.assertEqual(set(self.snapshot.monsters), {900})
|
|
|
|
def test_collection_reserves_room_space_for_entire_batch(self):
|
|
for mid in (101, 102, 103, 104):
|
|
self.snapshot.monsters[mid].update(process=2, roomId=None)
|
|
room_type = str(self.snapshot.raw["rooms"][0]["typeId"])
|
|
self.catalog.data["room_info"][room_type]["maxNum"] = 3
|
|
actions = self.planner.plan(self.snapshot, self.policy)
|
|
self.assertEqual(sum(len(d["monsterId"]) for d in actions[0].payload["datas"]), 2)
|