Fix away summary merge for deliveries
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
450abc9be9
commit
f042a718cd
2 changed files with 14 additions and 2 deletions
7
game.py
7
game.py
|
|
@ -3560,7 +3560,7 @@ def empty_summary() -> dict:
|
|||
return {"done": 0, "items": {}, "overflow": {}, "xp": {}, "levels": [], "eaten": {}, "used": {}, "damage": 0,
|
||||
"gold": 0, "wins": 0, "losses": 0, "lucky": 0, "stopped": None, "resumed": None, "run_over": None, "skipped": [],
|
||||
"sold": {}, "sold_gold": 0, "pp_spent": 0, "pp_gained": 0, "prayer_out": False, "second_wind": 0,
|
||||
"kept": 0, "potions_drunk": {}, "potion_out": [], "labour": 0}
|
||||
"kept": 0, "potions_drunk": {}, "potion_out": [], "labour": 0, "delivered": {}}
|
||||
|
||||
|
||||
def process_player(world: dict, player: dict, now: float, rng: random.Random | None = None) -> dict:
|
||||
|
|
@ -4174,8 +4174,11 @@ def merge_summary(into: dict, more: dict) -> dict:
|
|||
elif isinstance(value, (int, float)):
|
||||
into[key] = into.get(key, 0) + value
|
||||
elif isinstance(value, dict):
|
||||
bucket = into.get(key)
|
||||
if not isinstance(bucket, dict): # new to this summary, or an older save's count
|
||||
bucket = into[key] = {}
|
||||
for item, qty in value.items():
|
||||
into.setdefault(key, {})[item] = into[key].get(item, 0) + qty
|
||||
bucket[item] = bucket.get(item, 0) + qty
|
||||
elif key == "levels":
|
||||
into[key] = [entry for entry in into.get(key, []) if entry[0] not in {s for s, _ in value}] + value
|
||||
elif isinstance(value, list):
|
||||
|
|
|
|||
|
|
@ -2887,6 +2887,15 @@ class WorkOrderTest(unittest.TestCase):
|
|||
self.assertEqual((order["status"], self.world["city"]["stockpile"].get("stone")), ("done", 2))
|
||||
self.assertEqual(self.fred["action"]["id"], "mine_copper")
|
||||
|
||||
def test_away_summaries_take_deliveries_even_from_older_saves(self):
|
||||
old = game.empty_summary()
|
||||
old["delivered"] = 3 # how a save from before kept it
|
||||
del old["potions_drunk"]
|
||||
more = game.empty_summary()
|
||||
more["delivered"], more["potions_drunk"] = {"copper_ore": 2}, {"mining_potion": 1}
|
||||
merged = game.merge_summary(old, more)
|
||||
self.assertEqual((merged["delivered"], merged["potions_drunk"]), ({"copper_ore": 2}, {"mining_potion": 1}))
|
||||
|
||||
def test_a_gem_order_is_filled_by_any_rock_that_turns_it_up(self):
|
||||
game.post_order(self.world, self.mike, "gather", "quartz", 1, None, 0, T0)
|
||||
order = self.world["orders"][0]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue