Merchants

Merchants are NPCs that sell their goods and restock on a semi random basis. The first one the player will see (if the player chooses to start in ) will be. For other villages with procedurally generated village merchants, they will be and have a bonus +3 to Ego.

Restocking
Merchants do not keep their wares: they rotate their stock around every 5 to 8 in game days(for more detailed math, view ). When a merchant restocks, their trading inventory is refreshed and new items will repopulate the inventory. These items will generally be of similar tier and type as the initial stock.

For how the trading system works, check Commerce.

Legendary Merchants
Merchants have a chance of spawning Legendary Merchants, loyal to the Merchants' Guild. They live in their own lairs, and are always guarded by two random hired guards. All stock will contain the Maker's Mark of the Merchant, which is a random Code page 437 character from 1-254 (in decimal) excluding all alphanumerics, &, ^, and white space.

In-depth Restocking Formula
Merchants restock randomly according to their Chance and Restock Frequency. LastRestockTick is the last ingameTick that they have refreshed their wares. Currently, Chance is specified as 71, and RestockFrequency is 5 ingame days, or 6,000 ticks. It calls  to find a random integer between half the restock frequency and the restock frequency:

When the merchant is first created, LastRestock tick is set to

$$\text{LastRestockTick} = \text{TickOnCreation} + \text{Random}( \frac{RestockFrequency}{2}, RestockFrequency)$$

which substitutes to

$$\text{LastRestockTick} = \text{TickOnCreation} + \text{Random}(3000, 6000)$$

Every EndTurn, this is called:

If the current in game turn count-LastRestockTick is greater than RestockFrequency, LastRestockTick is set to equal the current GameTick.

$$\text{num1} = \text{InGameTurn} - \text{LastRestockTick} \ge 6000$$ $$\rightarrow$$

$$\text{RestockCheck} = \frac { \text{71}}{6000} \times \text{num1} $$ $$\rightarrow$$

If $$\text{RestockCheck} \ge 100$$ or $$\text{RestockCheck} \ge \text{Random}(1,100)$$,

the merchant will restock. This means that about 8450-8451 turns (a little more over an ingame week) after the last restock must pass in order to guarantee a restock. The earliest that a merchant can restock is 6,000 turns, with a 71% chance of restocking, or 9,000 turns at a 100% restock if this is the first time the merchant restocks.

If a merchant is holding a quest item, they will not destroy the quest item during restock. any other item that contains the tag  will also not be restocked. Merchants that are following the player do not restock, and if the player is also a merchant via Domination, they will not restock.

Trade Prices
Trade prices in are variable, and depend on a number of factors, including the player's Ego modifier and their reputation with the merchant.

For more details about trade prices, refer to the commerce page.