Towns: found a second, travel with a pouch, banks per town, looted when it falls
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
11e4d98d49
commit
685aaa839e
3 changed files with 512 additions and 49 deletions
36
app.py
36
app.py
|
|
@ -201,8 +201,9 @@ def roster(world: dict, now: float) -> list[dict]:
|
|||
people = []
|
||||
for player in world["players"].values():
|
||||
action = game.ACTION_BY_ID[player["action"]["id"]] if player["action"] else None
|
||||
game.regen(world, player, now)
|
||||
game.regen(game.here(world, player), player, now)
|
||||
people.append({
|
||||
"at": player["at"], "travel": player["travel"] and player["travel"]["to"],
|
||||
"xp": player["xp"], "equip": player["equip"], "joined": player["joined"],
|
||||
"hp": int(player["hp"]), "max_hp": game.max_hp(player), "power": game.combat_power(player),
|
||||
"fighter": {key: value for key, value in game.fighter(player, game.blessing(player), {}).items()
|
||||
|
|
@ -226,6 +227,9 @@ def roster(world: dict, now: float) -> list[dict]:
|
|||
return sorted(people, key=lambda p: -p["donated"])
|
||||
|
||||
|
||||
ROAD_ROUTES = ("/api/board", "/api/board/delete", "/api/charter/sign", "/api/charter/cancel") # what you can still do on the road
|
||||
|
||||
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
server_version = "Guildhall"
|
||||
store: Store
|
||||
|
|
@ -303,9 +307,9 @@ class Handler(BaseHTTPRequestHandler):
|
|||
game.catch_up(world, now, self.store.rng)
|
||||
if player:
|
||||
summary = game.take_summary(player, game.empty_summary())
|
||||
game.regen(world, player, now)
|
||||
game.regen(game.here(world, player), player, now)
|
||||
player["last_active"] = now
|
||||
game.watch_fight(world, player, now) # looking at it: your manual abilities hold
|
||||
game.watch_fight(game.here(world, player), player, now) # looking at it: your manual abilities hold
|
||||
self.store.save()
|
||||
self.send_json(self.state(uid, summary))
|
||||
elif path.startswith("/api/"):
|
||||
|
|
@ -335,9 +339,9 @@ class Handler(BaseHTTPRequestHandler):
|
|||
else:
|
||||
game.catch_up(world, now, self.store.rng) # everyone, so the fires are as they really are
|
||||
summary = game.take_summary(player, game.empty_summary())
|
||||
game.regen(world, player, now)
|
||||
game.regen(game.here(world, player), player, now)
|
||||
player["last_active"] = now
|
||||
game.watch_fight(world, player, now)
|
||||
game.watch_fight(game.here(world, player), player, now)
|
||||
error = self.player_route(path, player, body, now)
|
||||
if error is None:
|
||||
game.process_player(world, player, now, self.store.rng) # a new fight is drawn up at once
|
||||
|
|
@ -352,7 +356,18 @@ class Handler(BaseHTTPRequestHandler):
|
|||
self.send_json(self.state(uid))
|
||||
|
||||
def player_route(self, path: str, player: dict, body: dict, now: float) -> str | None:
|
||||
world = self.store.world
|
||||
world = game.here(self.store.world, player)
|
||||
if player["travel"] and path not in ROAD_ROUTES:
|
||||
return "You're on the road"
|
||||
if path == "/api/travel":
|
||||
pouch = body.get("pouch")
|
||||
return game.travel(world, player, str(body.get("to")), pouch if isinstance(pouch, dict) else {}, now)
|
||||
if path == "/api/charter":
|
||||
return game.propose_charter(world, player, body.get("name"), now)
|
||||
if path == "/api/charter/sign":
|
||||
return game.sign_charter(world, player, now)
|
||||
if path == "/api/charter/cancel":
|
||||
return game.cancel_charter(world, player)
|
||||
item = body.get("item")
|
||||
qty = body.get("qty")
|
||||
if path in ("/api/donate", "/api/sell", "/api/give"):
|
||||
|
|
@ -453,11 +468,7 @@ class Handler(BaseHTTPRequestHandler):
|
|||
if path == "/api/install":
|
||||
return game.install(world, player, str(body.get("fitting")), str(body.get("source")), now)
|
||||
if path == "/api/garrison":
|
||||
raid = game.upcoming_raid(world)
|
||||
if body.get("join") and not raid:
|
||||
return "There's no raid to stand guard for"
|
||||
player["garrison"] = bool(body.get("join"))
|
||||
return None
|
||||
return game.stand_guard(world, player, bool(body.get("join")), now)
|
||||
if path == "/api/board/delete":
|
||||
message = next((m for m in world["board"] if m.get("id") == body.get("id")), None)
|
||||
if not message:
|
||||
|
|
@ -621,6 +632,8 @@ class Handler(BaseHTTPRequestHandler):
|
|||
world = self.store.world
|
||||
now = self.store.now()
|
||||
player = world["players"].get(uid)
|
||||
if player:
|
||||
world = game.here(world, player)
|
||||
upcoming = game.upcoming_event(world)
|
||||
unseen = game.unseen_threat(world, player) if player else None
|
||||
# Newest first by when it happened: raids are announced long before they land.
|
||||
|
|
@ -639,6 +652,7 @@ class Handler(BaseHTTPRequestHandler):
|
|||
"happenings": game.happenings_view(world, now),
|
||||
"history": history,
|
||||
"orders": world["orders"],
|
||||
"kingdom": game.kingdom_view(world, now),
|
||||
"threat_report": unseen and {"id": unseen["id"], "kind": unseen["kind"], "at": unseen["resolved"],
|
||||
"report": unseen["report"]},
|
||||
"players": roster(world, now),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue