NPCs and the Economy
NPCs sell, buy, train, talk and hand out quests. They are interacted with by
pressing E, the same way as gathering nodes: the server validates range and
auth in ClientInteract, builds the whole dialogue payload server-side, and
answers with ReceiveNpcDialogue. The client never prices anything — it renders
the numbers it is given, and every transaction recomputes the charge from the
same tables, so a window that lies is harmless.
The vendor near spawn is Anyxa, who sells bandages, bow-making supplies, blunt arrows, and turnip seed and seed potatoes (Farming), and gives a new character a free felling axe through dialogue. She lives in the red and green bow-top vardo parked behind her.
What an NPC is
An NPC is a world_entities row whose node type has Kind = "NPC". The node
type is only a visual preset: name, model and appearance. What the NPC does
is set per entity, in world_entities.NpcData (jsonb, cached with the world).
{"name": "Merchant Tali", "roles": ["Vendor", "Trainer"],
"stock": [6, 12, 14], "trains": [44], "model_path": "res://models/placeholders/anyxa.glb"}
The roles are Vendor, Trainer, Quest, Taskmaster and Banker.
- Vendor actions need the Vendor role. An omitted
stocksells every item with a positive base price; an explicit empty array is an empty shop. - Training needs the Trainer role and the skill listed in
trains. An empty array means no training. - Banker puts an "Open your bank" button in the NPC window. It opens the
storage window on the player's account bank: 100 slots shared by every
character of the account. Store an item by dragging it from the inventory or
with its right-click Store. Take it back with Take, a double-click,
or by dragging it to the inventory. Rows move whole, as in a cart, so a
crafted copy keeps its quality, durability, material and stats. Barnaby,
beside Nyx, is the first banker; any NPC can be given the role in the GM
panel or the admin NPC editor. Checked by
scripts/check_bank.py. roles: []disables every service. Interacting still opens the NPC window, with no service actions.- Stored stock and training stay in place while a role is disabled, but expose nothing.
model_pathgives one NPC its own model. It must start withres://, end in.tscn,.glbor.gltf, and exist in the client. Empty falls back to the preset's model.
Older databases had separate Vendor, Trainer and Taskmaster node kinds.
Migration UnifyNpcKinds copied them into entity roles.
World entities are placed in-game, not seeded in the repo, so NPC content lives
in the live database (covered by backup-postgres.sh). Placing an NPC happens in
the in-game GM panel (GM Tools), and authoring it
happens in the admin panel's NPC editor.
The NPC editor
Open /Npcs in the admin panel (Admin role). Place the NPC in-game first, then
choose Edit NPC.
- Services: assign Vendor and Trainer independently of appearance, and pick stock and skills from filterable catalogues. Stock is limited to 32 items and training to eight skills, the same limits the server enforces. An item needs a positive base price before it can be stocked.
- Conversation map: topics on a canvas, linked by player replies. A reply points to a topic, creates a new one, or ends the conversation. Undo and redo cover text, replies, links and node movement. The preview follows the authored replies, including loops and endings. The limits are 64 topics, eight replies per topic, 2,000 characters of NPC text and 200 characters per reply.
- Check topics: + Check adds a topic the player never sees. It tests one thing (has N of an item in the pack, a skill at level N or more, or a player tag) and goes on to its pass or fail topic (below).
- Relationship rules: per-tier prices, and minimum standings for stock, skills and replies (below).
- Player relationships: search for a character and set their standing with this NPC. Changes are audited and apply to the next interaction without a reload.
The tree is saved in NpcData.dialogue_tree
({version: 1, start, nodes: [{id, text, x, y, choices: [{text, next}]}]};
a check topic adds kind: "check", check: {type, itemId, quantity, skillId, level, tag}, pass and fail, and has no replies).
A save checks the original revision, does a compare-and-swap, writes an audit
entry and queues a content reload, all in one transaction. A concurrent edit is
refused with your fields kept. NpcDialogueTree.cs is shared by the game server
and the admin panel, so both validate with the same code.
Relationships
Each character has a separate standing with each placed NPC: Neutral (0),
Friendly (1), Honored (2) or Revered (3). A missing row means Neutral. Standings
are kept in character_npc_relationships, keyed by character and NPC entity.
- Prices. By default, buying costs 100 / 95 / 90 / 85% of the price at each tier, and selling pays 100 / 105 / 110 / 115%. The editor can change these within 50–200% for buying and 0–125% for selling. Prices round down, with a 1 copper minimum.
- Gates. Each stock item, trainable skill and dialogue reply can need a minimum standing. The server filters them before sending the payload, so the client never receives a hidden branch.
- Changing standing. Standing changes through the admin editor and through dialogue replies. Buying and selling do not change it.
Buying, selling and training re-read the NPC's rules and the character's standing inside the transaction, so a request for a hidden item is refused even if the client knows its id.
The old global characters.RelationshipTier and NpcData.relationship_tier are
still stored but no longer affect prices.
Dialogue effects
Each reply can change standing by −3 to +3 tiers, clamped to Neutral–Revered. An effect applies once per character, NPC and reply. Replaying the conversation, looping, double-clicking or reconnecting does not repeat it.
A reply can also take items (1–100, every time it is chosen, from unequipped stacks; too few and the whole reply fails) and set or clear player tags.
A reply can give an item, once per character and NPC. A gift is asked for
once: when it has been given, its reply is hidden, and the server refuses it if
a client sends it anyway (npc_dialogue_item_grants). Two conditions hide a
reply until they hold, checked again when it is chosen:
- Shown after gift (
afterGift): this NPC has given the character the gift on another reply in the same conversation. - Shown while offerable (
whileOffered): this NPC could offer the character that quest now (not active, not done unless it repeats, level and prerequisite met).
Live dialogue goes through ClientChooseNpcDialogue(npcEntityId, choiceId, token). The server tracks the active topic and issues a single-use token for
each prompt. The client never sends a standing change or a next topic. Receipts
are kept in npc_dialogue_relationship_effects, whose primary key refuses a
duplicate.
Check topics and player tags
A player tag is a named marker a character has or lacks (met_anyxa,
gave_pelts): letters, numbers, _ and -, up to 64 characters. Tags live in
character_tags. Conversation replies, quest completion, the chat hooks Set
player tag / Clear player tag and the admin character page set and clear
them.
A check topic branches on one condition:
| check | passes when |
|---|---|
| item | the pack holds at least N (equipped gear doesn't count) |
| skill | the skill is at level N or more (never learned counts as 0) |
| tag | the character has the tag |
Chain checks for "and"; swap the exits for "lacks". A check can be the start topic, for a greeting that changes once a tag is set. The server resolves checks each time it sends a topic, so the client never receives a check, its condition or a tag name. An item check followed by a reply that takes the items is the usual delivery pattern; the reply re-checks the count when it is chosen.
Quests
Quests are authored in the admin panel's quest catalogue: talk quests, item deliveries, kill counts and crafting counts. A quest also sets its minimum level, prerequisite quests, whether it repeats, its turn-in NPC and its relationship reward.
- Give an NPC the Quest role and set a reply's quest action to Offer
quest or Turn in quest. Acceptance only happens through a dialogue offer.
The old standalone
ClientAcceptQuestis refused. - Kills and crafts count only after acceptance. A kill counts for the player or pet that lands the final blow. A crafting or refining job counts once when its output is collected.
- A delivery needs enough unequipped items. Turning in consumes the items and applies the reward in one transaction, and a receipt stops a second claim.
- A repeatable quest must need a delivery, and starts again from zero.
- Gifts and teaching. A quest can hand over items when accepted (the
tools for the job) and when completed, as an NPC's gift: quality 1, Gold as
coins. It can also teach recipes on completion. A recipe any quest teaches is
hidden at stations, and refused, until the character has learned it
(
character_known_recipes). The offer says all of it under its quest tag ("Gives Iron Wedges, Beetle; teaches Club"), a turn-in says what completion gives and teaches, and the quest journal lists both. - Tags. Completion can set and clear player tags, which conversation check topics branch on.
Anyxa's club quests
Offered in her conversation once she has given you the axe: after "…Thanks."
she has "Anything else I should know?". Come back later and that line is on her
opening topic instead, while Good Wood can still be offered (the axe reply is
gone by then: gifts are asked for once). This is also the way in for anyone
given the axe before the quests existed (migration
20270404120000_AnyxaQuestEntry).
- Good Wood: accepting gives quality-1 Iron Wedges and a Beetle. Split a felled log where it lies (for a new player, spruce: the only wood they can fell) and bring her one Billet. Completion teaches the Club.
- Shape a Club (after Good Wood): accepting gives a quality-1 Drawknife. Make one Club at a Shaving Bench; you keep it. Completion pays 10 gold.
The second offer and both turn-ins sit on her opening topic and show only when they apply. Her lines are hers to rewrite in Admin.
The quest journal (L) lists accepted quests beside their details and objective
bars, and can abandon a quest.
Money
Money is one purse counted in coppers and read as gold, silver and copper:
ten copper make a silver, ten silver a gold (1g = 10s = 100c). Every amount the
server stores, charges, pays or sends is in coppers: item quantities, base
prices, plot prices and deposits, auction prices, guild purses, quest and loot
rewards. Players read it as "3g 4s 2c": Money.Text on the server,
GameState.money_text on the client. Gold a player types (a deposit, a GM
plot's price) is sent as coppers. The admin edits base prices in coppers.
Smaller coins came with logs into timber (2026-11-07): a log now gives dozens
of pieces, and at a 1-gold floor each log was suddenly worth ten times what it
was. Migration CopperCoins multiplied every amount by 100 (nobody's money or
prices changed value) and then priced a log's pieces so a log is worth about
what it was. Since 2026-11-08 wood is priced by weight and tier instead
(see What wood is worth in Refining and Crafting): an oak log
35g 14c, an oak board 1g 54c, a spruce board 53c (base prices; vendors pay a
fifth). Each wood sells apart: the Sell tab lists "Oak Board" and "Spruce
Board" as two rows, sold with ClientSellItemOf.
Coins are item 99: stackable, droppable, unsellable (Unsellable plus
BasePrice=0 — two independent refusals), weight 0.0001 per copper (a gold's
worth weighs 0.01, as a gold coin did). It is earned by
selling to vendors and spent at vendors and trainers. Because it is in the pack,
it goes into the death pack when a player dies
(Combat, Pets and Riding).
The balance lives in PlayerSession.Gold: loaded once at login, then every
transaction — buy, sell, train — returns the exact post-transaction balance, so
ReceiveGoldUpdate is never an increment applied to whatever the client last
happened to hold.
Stacks cap at 1,000,000 coppers (10,000 gold) and split when a sale overflows the top stack.
Because gold can live in several rows, every gold change addresses rows by id:
credits fill the oldest stack to the cap before starting the next, debits drain
the oldest stack first and delete it at zero, and balances are summed. The
aggregate UPDATE ... WHERE CharacterId AND ItemId=99 this replaced subtracted
the whole price from every matching row at once — an addition that becomes a
multiplication the moment a second stack exists. Materials use the same drain
shape: input consumption walks stacks oldest first, so a material split across
quality stacks costs one input, not one per stack.
Prices
The buy price is the base price × (1 + 0.05 × quality), then the NPC's tier percentage. The sell price is 20% of the buy price, with a 1 copper floor, then the NPC's tier percentage. Gathered and refined goods have starter sell prices.
Multi-tasking
Multi-tasking (skill 44) is bought from a trainer, not trained through use. Each level allows one more concurrent job: 1 + level, capped at 4 slots (3 purchased levels). The levels cost 10g, 50g and 200g.
RPCs
| RPC | Direction | Purpose |
|---|---|---|
ClientInteract | client→server | E-key interaction (nodes, stations, NPCs) |
ClientChooseNpcDialogue | client→server | choose a dialogue reply |
ClientBuyItem | client→server | Buy from vendor |
ClientSellItem | client→server | Sell to vendor |
ClientTrainSkill | client→server | Train from a trainer |
ClientGetNpcData | client→server | GM: read one entity's NPC content |
ClientSetNpcData | client→server | GM: write or clear one entity's NPC content |
ReceiveNpcDialogue | server→client | dialogue, roles, priced stock, offers, gold |
ReceiveNpcData | server→client | GM: the content the editor just loaded |
ReceiveGoldUpdate | server→client | gold balance |
ReceiveTrainResult | server→client | training outcome |
The NPC window (NpcPanel.tscn) has tabs, shows sale prices and amounts, and
colours its feedback.
Checks
scripts/check_npc_economy.pydrives the whole loop against a live server: content → dialogue payload → buy → sell (1g floor) → refusal on insufficient gold → cap refusal at level 3 → four jobs land and the fifth is refused →ActiveJobCountself-heals → the 10,000 stack splits and a spend against two stacks drains once. It restores Test01 to a neutral state afterwards.scripts/check_npc_roles.pychecks roles, prices, bounds, gates, branch filtering and payloads without a database.scripts/check_npc_relationships.pyandscripts/check_npc_dialogue_effects.pyuse real clients, thenpcverifytest accounts and temporary NPCs. Create the accounts withpython scripts/create_test_accounts.py --count 2 --prefix npcverify.tools/Moondog.NpcEditorChecksruns the editor handlers against PostgreSQL.scripts/check_gm_tools.pycovers authoring from the GM panel: a Player'sGet/Setare refused and logged, and the GM run round-trips content with theSetNpcDataaudit row asserted.