Crafting queue

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rope 2026-10-26 22:51:56 +00:00
parent 912f94f775
commit 40e5274c4e
5 changed files with 207 additions and 17 deletions

View file

@ -84,6 +84,74 @@ class ActionTest(unittest.TestCase):
self.assertGreater(p["bank"]["stone"], 100)
self.assertEqual(p["bank"]["stone"], 100 + summary["lucky"])
def _smith(self, bars):
world = world_with(("fred", "commoner"))
p = world["players"]["fred"]
p["xp"]["smithing"] = game.XP_TABLE[10]
p["bank"] = {"copper_bar": bars}
game.start_action(world, p, "mine_stone", T0)
return world, p
def test_queue_runs_in_order_then_back_to_work(self):
world, p = self._smith(6)
self.assertIsNone(game.start_action(world, p, "smith_copper_helmet", T0, once=1))
self.assertIsNone(game.queue_add(world, p, "smith_copper_legs", 1, T0))
self.assertEqual(p["queue"], [{"id": "smith_copper_legs", "n": 1}])
summary = game.process_player(world, p, T0 + 500, random.Random(1))
self.assertEqual((p["bank"].get("copper_helmet"), p["bank"].get("copper_legs")), (1, 1))
self.assertEqual(p["action"]["id"], "mine_stone")
self.assertEqual(summary["resumed"], "mine_stone")
self.assertEqual(p["queue"], [])
def test_queue_skips_what_you_cant_make(self):
world, p = self._smith(4)
game.start_action(world, p, "smith_copper_helmet", T0, once=1)
game.queue_add(world, p, "smith_copper_legs", 1, T0) # 4 bars, only 2 left by then
game.queue_add(world, p, "smith_copper_sword", 1, T0)
summary = game.process_player(world, p, T0 + 500, random.Random(1))
self.assertEqual((p["bank"].get("copper_helmet"), p["bank"].get("copper_sword")), (1, 1))
self.assertNotIn("copper_legs", p["bank"])
self.assertEqual(summary["skipped"], ["smith_copper_legs"])
self.assertEqual(summary["resumed"], "mine_stone") # not the queued makes on the way
self.assertEqual(p["action"]["id"], "mine_stone")
def test_running_out_mid_make_moves_on_to_the_next(self):
world, p = self._smith(5)
game.start_action(world, p, "smith_copper_helmet", T0, once=3) # bars for 2
game.queue_add(world, p, "smith_copper_rivets", 1, T0)
summary = game.process_player(world, p, T0 + 500, random.Random(1))
self.assertEqual((p["bank"].get("copper_helmet"), p["bank"].get("copper_rivets")), (2, 5))
self.assertEqual(summary["skipped"], ["smith_copper_helmet"])
self.assertEqual(p["action"]["id"], "mine_stone")
def test_out_of_materials_with_nothing_queued_still_stops(self):
world, p = self._smith(4)
game.start_action(world, p, "smith_copper_helmet", T0, once=3)
summary = game.process_player(world, p, T0 + 500, random.Random(1))
self.assertIsNone(p["action"])
self.assertTrue(summary["stopped"].startswith("Out of"))
def test_queue_rules(self):
world, p = self._smith(4)
self.assertEqual(game.queue_add(world, p, "cut_logs", 1, T0), "Only crafting can be queued")
self.assertIsNone(game.queue_add(world, p, "smith_copper_helmet", 1, T0))
self.assertEqual(p["action"]["id"], "smith_copper_helmet") # nothing being made: it just starts
self.assertEqual(p["action"]["resume"], "mine_stone")
p["bank"] = {}
for _ in range(game.QUEUE_MAX):
self.assertIsNone(game.queue_add(world, p, "smith_copper_helmet", 1, T0)) # bars aren't checked yet
self.assertEqual(game.queue_add(world, p, "smith_copper_helmet", 1, T0), f"Queue full ({game.QUEUE_MAX})")
high = next(a["id"] for a in game.ACTIONS if game.queueable(a) and a["skill"] == "smithing" and a["level"] > 10)
self.assertTrue(game.queue_add(world, p, high, 1, T0).startswith("Needs level"))
self.assertIsNone(game.queue_remove(p, 0))
self.assertEqual(len(p["queue"]), game.QUEUE_MAX - 1)
game.start_action(world, p, "mine_stone", T0)
self.assertEqual(p["queue"], [])
game.start_action(world, p, "smith_copper_helmet", T0, once=1)
game.queue_add(world, p, "smith_copper_legs", 1, T0)
game.drop_out(world, p, T0)
self.assertEqual(p["queue"], [])
def test_offline_cap(self):
world = world_with(("fred", "commoner"))
p = world["players"]["fred"]