// inventory.ts — player inventory and resource ledger // // Every grant and spend must produce a ledger entry so the economy is // fully auditable. The wallet tracks numeric resources (gold, wood, etc.). // The inventory tracks discrete items and character roster membership. // Resource IDs — must match the keys used in content/schema/resource.yaml export const RESOURCE_IDS = [ "gold", "wood", "stone", "knowledge", "experience", "mana", "diamond", ] as const; export type ResourceId = typeof RESOURCE_IDS[number]; export function rpcGetInventory( ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, _payload: string ): string { // TODO PR 4: read character roster and item inventory from storage logger.info(`inventory/get stub called by ${ctx.userId}`); return JSON.stringify({ characters: [], items: [], message: "Inventory is stubbed. Implement in PR 4.", }); } export function rpcGetResources( ctx: nkruntime.Context, logger: nkruntime.Logger, nk: nkruntime.Nakama, _payload: string ): string { // Read wallet balances — these are already tracked by Nakama's wallet system const account = nk.accountGetId(ctx.userId); const wallet = account.wallet ?? {}; const resources: Record = {}; for (const id of RESOURCE_IDS) { resources[id] = Number(wallet[id] ?? 0); } return JSON.stringify({ resources }); }