diff --git a/app.py b/app.py index 143c4ea..bbba87c 100644 --- a/app.py +++ b/app.py @@ -121,8 +121,8 @@ def player_view(world: dict, player: dict, now: float) -> dict: "boosts": {ab: [game.ITEMS[i]["name"] for i in player["equip"].values() if i and ab in game.ITEMS[i].get("mods", {})] for ab in me["mods"]}} view["health_potion"] = game.health_potion(player) - view["perk_costs"] = {perk: game.perk_cost(player, perk) for perk in player["perks"]} - view["rent_cost"] = game.rent_cost(player) + view["perk_costs"] = {perk: game.perk_cost(world, player, perk) for perk in player["perks"]} + view["rent_cost"] = game.rent_cost(world, player) view["caravan"] = game.caravan_view(world, player, now) view["titles"] = game.titles(player) view["achievements"] = game.achievements(player) @@ -212,7 +212,7 @@ def roster(world: dict, now: float) -> list[dict]: if key in ("max_hit", "accuracy", "evasion", "crit", "interval", "block", "damage")}, "armour": game.armour(player), "reduction": round(game.damage_reduction(player), 3), "ward": game.magic_ward(player), "ward_reduction": round(game.reduction(game.magic_ward(player)), 3), - "favour": player["favour"], + "favour": game.favour_saved(player), "id": player["id"], "name": player["name"], "cls": player["cls"], "total": sum(game.skill_level(player, skill) for skill in game.SKILL_IDS), "levels": {skill: game.skill_level(player, skill) for skill in game.SKILL_IDS}, @@ -490,7 +490,7 @@ class Handler(BaseHTTPRequestHandler): if path == "/api/wages": return game.pay_wages(world, player, qty if qty == "all" or isinstance(qty, int) else -1, str(body.get("source")), now) if path == "/api/rent": - return game.rent_slot(player) + return game.rent_slot(world, player) if path == "/api/buy": skill = body.get("skill") return game.buy_ware(world, player, str(body.get("ware")), str(skill) if skill else None, now) @@ -531,7 +531,7 @@ class Handler(BaseHTTPRequestHandler): if path == "/api/plot": return game.plant_second_plot(world, player, body.get("id") or None) if path == "/api/perk": - return game.buy_perk(player, str(body.get("perk"))) + return game.buy_perk(world, player, str(body.get("perk"))) if path == "/api/pin": return game.toggle_pin(player, str(body.get("skill"))) if path == "/api/track": diff --git a/game.py b/game.py index 5835631..8b7d599 100644 --- a/game.py +++ b/game.py @@ -1684,7 +1684,7 @@ RAID_TRAITS = ["lightly armoured, heavy on archers", "mounted and fast, few bows # --- world --------------------------------------------------------------- -WORLD_VERSION = 41 +WORLD_VERSION = 42 HOME_CITY = "guildhall" CITY_KEYS = ("events", "next_event_at", "next_minor_at", "next_hardship_at", "next_fortune_at", "caravan", "orders") TRAVEL_TIME = 12 * 60 # game seconds on the road between two towns @@ -2066,6 +2066,13 @@ def migrate(world: dict, now: float | None = None) -> World: # The war council, and guards on the march. world.doc.update(marches=[], council=[], next_march_id=1) world["version"] = 41 + if world["version"] < 42: + # Favour belongs to the town it was earned in. All of it so far counts as the first town's. + for player in world["players"].values(): + player.update(town_favour={}, town_slots={}, town_rented={}) + if player["at"] != HOME_CITY: + player["town_favour"][HOME_CITY], player["favour"] = player["favour"], 0 + world["version"] = 42 return world @@ -2404,6 +2411,9 @@ def new_player(uid: str, name: str, cls: str, now: float) -> dict: "rented": 0, "boosts": [], "bought": None, "deeds": {}, "owned": [], "look": dict(DEFAULT_LOOK), "garrison": False, "at": HOME_CITY, "banks": {}, "travel": None, # banks: what you left in the towns you're not in + "town_favour": {}, # likewise your favour: `favour` is what you hold in the town you're in + "town_slots": {}, # bank slots bought with favour, each good only in its town + "town_rented": {}, # and those rented with gold "donated": 0, "gave": {}, # item (or "gold"): {qty, worth, favour} given to the city, see credit() "ledger": [], # what you did, see note() and track() @@ -2418,7 +2428,8 @@ def skill_level(player: dict, skill: str) -> int: def bank_slots(world: dict, player: dict) -> int: return (BASE_SLOTS + 3 * building_level(world, "storehouse") + TIER_SLOTS * world["city"]["tier"] - + player["perks"]["bank_slot"] + player["rented"] + fitted(world, "shelving") + int(gear_bonus(player, "slots"))) + + player["perks"]["bank_slot"] + player["town_slots"].get(world.here, 0) + + player["rented"] + player["town_rented"].get(world.here, 0) + fitted(world, "shelving") + int(gear_bonus(player, "slots"))) def stack_size(world: dict, player: dict | None = None) -> int: @@ -4419,7 +4430,11 @@ def _to_city(world: dict, order: dict, giver: dict, qty: int, now: float, used: if not helper: continue for reagent, n in items.items(): - favour[uid] = favour.get(uid, 0) + credit(helper, reagent, n, rate, ITEMS[reagent]["value"] * n * scale) + earned = credit(helper, reagent, n, rate, ITEMS[reagent]["value"] * n * scale) + favour[uid] = favour.get(uid, 0) + earned + if helper["at"] != world.here: # earned here, though they've moved on + helper["favour"] -= earned + helper["town_favour"][world.here] = helper["town_favour"].get(world.here, 0) + earned note(world, helper, now, "Donated", reagent, n, label=label) favour[giver["id"]] = favour.get(giver["id"], 0) + credit(giver, item, qty, rate, worth - pooled * scale) note(world, giver, now, "Donated", item, qty, label=label) @@ -4596,7 +4611,9 @@ def arrive(world: World, player: dict) -> None: """Off the road: into this town's bank, pouch unpacked, and back to work.""" trip, player["travel"] = player["travel"], None player["banks"][player["at"]] = player["bank"] + player["town_favour"][player["at"]] = player["favour"] player["at"], player["bank"] = trip["to"], player["banks"].pop(trip["to"], {}) + player["favour"] = player["town_favour"].pop(trip["to"], 0) player["arrived"] = trip["arrive"] world = here(world, player) for item, qty in trip["pouch"].items(): @@ -5757,7 +5774,7 @@ def _loot_banks(world: World, event: dict, share: float, now: float) -> bool: looted = False for player in world["players"].values(): bank = player["bank"] if player["at"] == world.here else player["banks"].get(world.here, {}) - locked = (player["rented"] + gear_bonus(player, "slots")) / max(1, bank_slots(world, player)) + locked = (player["rented"] + player["town_rented"].get(world.here, 0) + gear_bonus(player, "slots")) / max(1, bank_slots(world, player)) for item in list(bank): gone = int(bank[item] * share * BANK_LOOT * (1 - min(1, locked))) if gone: @@ -6615,16 +6632,19 @@ RENT_BASE = 1000 # gold for the first rented bank slot... RENT_GROWTH = 1.35 # ...and each one after costs this much more -def rent_cost(player: dict) -> int: - return int(round(RENT_BASE * RENT_GROWTH ** player["rented"] / 50) * 50) +def rent_cost(world: World, player: dict) -> int: + """Each slot rented in a town costs more there. The first town's carries on from the + slots rented before they became per town, which stay good everywhere.""" + rented = player["town_rented"].get(world.here, 0) + (player["rented"] if world.here == HOME_CITY else 0) + return int(round(RENT_BASE * RENT_GROWTH ** rented / 50) * 50) -def rent_slot(player: dict) -> str | None: - cost = rent_cost(player) +def rent_slot(world: World, player: dict) -> str | None: + cost = rent_cost(world, player) if player["gold"] < cost: return f"Needs {cost:,} gold" player["gold"] -= cost - player["rented"] += 1 + player["town_rented"][world.here] = player["town_rented"].get(world.here, 0) + 1 return None @@ -7095,20 +7115,28 @@ def spend_favour(world: dict, player: dict, kind: str, now: float) -> str | None return None -def perk_cost(player: dict, perk: str) -> int: +def perk_cost(world: World, player: dict, perk: str) -> int: + """A bank slot's price doubles with each bought in this town. The first town's carries on from + the slots bought before they became per town, which stay good everywhere.""" if perk == "bank_slot": - return 500 * 2 ** player["perks"]["bank_slot"] + bought = player["town_slots"].get(world.here, 0) + return 500 * 2 ** (bought + (player["perks"]["bank_slot"] if world.here == HOME_CITY else 0)) raise KeyError(perk) -def buy_perk(player: dict, perk: str) -> str | None: +def favour_saved(player: dict) -> float: + """Your favour across every town.""" + return player["favour"] + sum(player["town_favour"].values()) + + +def buy_perk(world: World, player: dict, perk: str) -> str | None: if perk not in player["perks"]: return "No such perk" - cost = perk_cost(player, perk) + cost = perk_cost(world, player, perk) if player["favour"] < cost: return f"Needs {cost:,} favour" player["favour"] -= cost - player["perks"][perk] += 1 + player["town_slots"][world.here] = player["town_slots"].get(world.here, 0) + 1 return None @@ -7398,6 +7426,10 @@ ORDER_RECIPES, ORDER_RAW = _order_sources() # What changed, shown on the Patch notes page. Newest first; every shipped change adds a # line here (new / balance / fix), and a new release a new entry on top. PATCH_NOTES = [ + {"date": "2026-11-04", "title": "Favour per town", "notes": [ + ("new", "Favour is earned and spent per town. What you've saved so far stays in Guildhall."), + ("new", "Bank slots: favour price starts at 500 and gold at 1,000 in each town, rising there. New ones work only in that town. Ones you already own work everywhere."), + ]}, {"date": "2026-11-04", "title": "War council", "notes": [ ("new", "War council on the Kingdom page: propose sending guards to another town. 1h vote: a majority of active players settles it, else the votes cast. Tie: they stay."), ("new", "Guards march 20h with their kit and wage, stand one fight, then march home. Lost fight: some die. Their posts stay empty while they're away."), diff --git a/static/app.js b/static/app.js index ef71ee3..394e6f4 100644 --- a/static/app.js +++ b/static/app.js @@ -769,7 +769,7 @@ function sidebar() {
Yours for good. Each costs 35% more.
Yours for good, in this town. Each costs 35% more.
${FAVOUR} ${fmt(me.favour)} favour · ${fmt(me.donated)} given in total
+${FAVOUR} ${fmt(me.favour)} favour in ${esc(townName(me.at))} · ${fmt(me.donated)} given in total
+ ${Object.entries(me.town_favour).filter(([, n]) => Math.round(n)).map(([id, n]) => `${FAVOUR} ${fmt(n)} in ${esc(townName(id))}
`).join("")}More to spend on in .