
Stocks/Market
Stock Market package A drop-in stock market for any Craft world. Stocks drift back toward their usual price, move with their sector and with the stocks they are linked to, and now and then jump. Every stock card shows a 30-day graph, a Bullish or Bearish pill with a confidence score, and a nightly market "insight" spliced together by a word chain from two corpora of meme-trading lines, so it reads as almost-advice that falls apart halfway through. It is a simplified copy of the market in Wealth Quest, with nothing that depends on Wealth Quest: no World State, no characters, no money system. It moves prices and reports big moves. Buying, selling and holdings belong to the world that installs it. What is in it File/type What it does Scripts/Stock Market.script.js Moves the market once per night. GM-only. .craft/file-types/stock.json The Stock type: usual price, volatility, sector, links, and the computed price, change and graph. .craft/file-types/market.json The Market type: the list of stocks, today's prices, and the script's stored levels. Stock Market/Stock Market.market.json The market itself. The script looks for a Market file named "Stock Market". Stock Market/*.stock.json Six fictional sample stocks, linked to each other. tools/make_types.py Rebuilds the two type files (only needed when changing them). How a night works Run once per in-story night. For each stock, in log space: It is pulled part of the way back toward its usual price. Its sector moves, and the stock follows the sector by its tier's weight. Sectors are just the text in the sector field: stocks with the same text share one sector, made on first use, and an empty sector moves on its own. Each linked stock adds a quarter of yesterday's move: the same way for Moves With, the opposite way for Moves Against, scaled to the follower's volatility. All links together are capped at two links' worth. Random noise, and a small chance of a jump. Jumps lean back toward the usual price, so nothing stays stuck high or low. A floor and ceiling per tier. Volatility Daily noise Typical range steady small about ±5% normal moderate about ±15% lively larger about −10% to +30% wild big roughly half to double frenzy huge a tenth to eight times fixed none never moves, no graph Fail-safes: a link to the stock itself, to a missing stock or to a stock not on this market is ignored; a duplicate link counts once; a stock not listed on the market's Stocks is never moved. The script returns the three biggest moves of the night with what drove each one (its own news, its sector, or yesterday's move in a linked stock) and tells the GM to give each one a reason in the story's news. First run: the sample market ships with 30 days of history already in it. A Market file with no history plays 30 quiet nights of backstory on its first run, without reporting, so every graph is full from the first day. Skipped days: pass day (the story's day number) and the script catches up one night per missing day, up to 30. Running it twice for the same day changes nothing. Making it run each night The script has the trigger "A night passes or the story skips ahead one or more days", so the GM will call it on its own. In a world that already has a script for a new day, call it from there instead and give it the day number: await scripts.stockMarket({ day }); Then you can remove the trigger line from the script, so it never runs twice. Adding stocks Make a Stock file, set its usual price, volatility, sector and links, and add it to the Stocks list on the market file. The script fills in the stock's Market field itself the next night. Prices are read from the market file, so a stock's card shows its usual price until the first night after it is added, and its graph fills in over the following nights. The price a world's buy and sell rules should use is the stock's computed Price Today (price). The graph and the ticker Both layouts draw their charts from the same stored points, as URL-encoded SVG built with $concat: The graph on the stock card is an Image (size: "full") whose src is an SVG 400 x 100 with preserveAspectRatio='none': a filled area, the line, and a dot for today. The dot is a zero-length line with round caps, since a circle would stretch. The ticker is the small sparkline beside the price on the stock card and beside each name in the market's price list. It is a Stack sized w-14 h-5 whose bgImage is the line alone. The stock card binds it with $state (/forecast/points), the price list with $item (points on each quote), which is the pattern for putting it in any repeated list, such as a character's holdings. The colour comes from the forecast: green when Bullish, red when Bearish, already URL-encoded as svgColor (%2334d399, %23f87171).