Character sheets; make one then go back to what you were doing

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rope 2026-10-18 19:35:21 +01:00
parent d2991ebf7a
commit 34dc85284d
5 changed files with 167 additions and 9 deletions

24
game.py
View file

@ -642,7 +642,7 @@ def gain_xp(world: dict, player: dict, skill: str, xp: float, now: float, summar
def empty_summary() -> dict:
return {"done": 0, "items": {}, "overflow": {}, "xp": {}, "levels": [], "eaten": {}, "damage": 0,
"gold": 0, "wins": 0, "losses": 0, "lucky": 0, "stopped": None}
"gold": 0, "wins": 0, "losses": 0, "lucky": 0, "stopped": None, "resumed": None}
def process_player(world: dict, player: dict, now: float, rng: random.Random | None = None) -> dict:
@ -673,6 +673,16 @@ def process_player(world: dict, player: dict, now: float, rng: random.Random | N
_complete(world, player, action, current["start"] + duration, rng, summary)
summary["done"] += 1
current["start"] += duration
if player["action"] is current and "left" in current:
current["left"] -= 1
if current["left"] <= 0:
back = current.get("resume")
if back:
player["action"] = current = {"id": back, "start": current["start"]}
action = ACTION_BY_ID[back]
summary["resumed"] = back
else:
stop(player)
if player["action"] and limit < now and current["start"] < now:
current["start"] = now
return summary
@ -683,14 +693,22 @@ def stop(player: dict, reason: str | None = None) -> None:
player["stopped"] = reason
def start_action(world: dict, player: dict, action_id: str, now: float) -> str | None:
def start_action(world: dict, player: dict, action_id: str, now: float, once: bool = False) -> str | None:
"""Start an action. `once` does it a single time, then goes back to what you were doing."""
action = ACTION_BY_ID.get(action_id)
if not action:
return "No such action"
reason = can_start(world, player, action)
if reason:
return reason
player["action"] = {"id": action_id, "start": now}
entry = {"id": action_id, "start": now}
if once:
current = player["action"]
back = current and (current.get("resume") or current["id"])
entry["left"] = 1
if back and back != action_id:
entry["resume"] = back
player["action"] = entry
player["stopped"] = None
return None