77 lines
3.7 KiB
Markdown
77 lines
3.7 KiB
Markdown
# Trading — merchants and the trade window
|
||
|
||
Trading adds shops to a game. A shop is data: what the merchant sells, what they buy back, and at which prices. A scenario opens it, and the player trades in a window with two inventories — the merchant's goods on the left, the player's bag on the right. Money is an ordinary item, the gold coin, so it lies in the bag, is saved with it and can be given by a scenario like any other item.
|
||
|
||
In RPG Plus the village merchant trades this way: talk to him and the window opens.
|
||
|
||
## Buying
|
||
|
||
Pick goods on the left. The middle shows the item, its price, your wallet, a quantity slider with **−**, **+** and **All**, and the total. **Buy** completes the deal:
|
||
|
||

|
||
|
||
The hero came with 25 coins; the elixir cost 10, so the wallet shows 15 and the elixir is in the bag. The slider only goes as far as the money allows — now 1.
|
||
|
||
## Selling
|
||
|
||
Pick an item in your bag. Items the merchant buys have a price tag; the others cannot be sold here. **All** sets the quantity to everything you have:
|
||
|
||

|
||
|
||

|
||
|
||
15 + 3 × 4 = **27** coins. Esc or the cross closes the window.
|
||
|
||
The merchant's stock never runs out, and what you sell is not offered back: a shop has no state of its own, only your bag changes.
|
||
|
||
## A shop in data
|
||
|
||
Shops are entities of kind `shop`, in a mod's `shops/` folder. The village merchant as RPG Demo defines it:
|
||
|
||
```json
|
||
{
|
||
"Kind": "shop",
|
||
"Items": [
|
||
{
|
||
"Id": "rpg_demo/village_merchant",
|
||
"Name": "rpg_demo/shop/village_merchant",
|
||
"Sells": [ { "Item": "rpg_demo/elixir", "Price": 10 } ],
|
||
"Buys": [
|
||
{ "Item": "rpg_demo/branches", "Price": 1 },
|
||
{ "Item": "rpg_demo/stones", "Price": 2 }
|
||
]
|
||
}
|
||
]
|
||
}
|
||
```
|
||
|
||
- `Name` — the translation key of the window title.
|
||
- `Sells` — what the player can buy, in this order, with the price of one.
|
||
- `Buys` — what the merchant pays for; anything else is refused.
|
||
- `Currency` (optional) — the money item; the default is `money/coin`, the gold coin of this mod.
|
||
- A price below 1 is ignored: a free item is a gift and belongs in a scenario.
|
||
|
||
RPG Plus adds its gear and goods to the same merchant without touching RPG Demo's file, with a patch in its own `patches/shop.json`:
|
||
|
||
```json
|
||
{ "Items": [ { "Id": "rpg_demo/village_merchant",
|
||
"Sells$add": [ { "Item": "classic/iron_sword", "Price": 30 } ],
|
||
"Buys$add": [ { "Item": "rpg_plus/wolf_pelt", "Price": 4 } ] } ] }
|
||
```
|
||
|
||
## Opening a shop
|
||
|
||
```scenario
|
||
text "Oh, a customer! Elixirs, fresh, almost no sediment." key=rpg_demo/merchant/line1
|
||
action trade.open shop=rpg_demo/village_merchant
|
||
end
|
||
```
|
||
|
||
The merchant's map event runs this scenario. Any scenario can open a shop the same way — a dialog answer, a click on an interactive object.
|
||
|
||
## If something goes wrong
|
||
|
||
1. **An item in the bag cannot be sold.** It is not in the shop's `Buys`.
|
||
2. **Buy does nothing.** Not enough coins for one; the window says so.
|
||
3. **The window does not open.** The `shop=` id does not match a shop's `Id`; the log names it.
|