# Vendor services

A **service** is something a vendor *does* rather than sells: sharpening a blade, a blessing, a
curse on a rival, clearing out a cellar by filling it with rats first. The player pays, and the
service's steps run once.

Add one on the character's **Vendor** tab under **Services**. Each has a name, a price in an
item, an optional line telling the narrator what the vendor does, and a body of steps edited
with the same step editor (and code view) as everything else.

Players buy a service the way they buy goods: "sharpen my sword", "bless Bram for me", "how
much for the blessing?". Asking only quotes the price. Nothing runs until they pay.

## Three people

A service has up to three people in it:

| Who | What they are | How a step reaches them |
|---|---|---|
| **Recipient** | who the service is for: the buyer, or whoever they bought it for | the default, no `targets` |
| **Vendor** | who does the work | `targets: "self"` |
| **Buyer** | who paid | `targets: "buyer"` |

When the buyer buys it for themselves, the buyer and the recipient are the same person, and a
step aimed at either lands on them. Buying for someone else only works when that person is in
the scene. If they aren't, the purchase is refused and nothing is paid.

`"buyer"` only means something inside a service. Anywhere else it reaches nobody.

```js
// Blessing of the Grove
$.heal({ amount: 10 })                                  // whoever it's for
$.applyEffect({ effect: "Blessed" })                    // whoever it's for
$.adjustField({ field: "mana", by: -5, targets: "self" }) // the vendor pays in mana
$.bond({ bond: "trust", by: 1, targets: "buyer" })      // whoever paid
```

## What the body can read

The body runs as though the vendor cast it at the recipient, so every step means what it means
in an [ability](/docs/steps). Expressions see the three people too:

| Read | Is |
|---|---|
| `$.subject` | the recipient |
| `$.equipped` | the recipient's equipped slots |
| `$.source` | the vendor |
| `$.player`, `$.items` | the buyer and what they carry |

That covers "do this to my held item":

```js
// Sharpen Blade: works on whatever is in the recipient's weapon slot
$.itemHealth({ item: $.equipped.weapon, by: 20 })
$.narrate("The edge sings off the whetstone.")
```

Slot names are your game's own, so use the one your layout declares.

And anything a step can do to the world:

```js
// Rat Problem: sold by a very honest exterminator
$.spawn("Rat")
$.spawn("Rat")
$.spawn("Rat")
```

## Price and paying

The price works like any other vendor price. It can be haggled, it is quoted when asked, and the
buyer's purse pays it before the body runs, so the body sees what they have left. A vendor with
a [till](/docs/vendor-stock) takes the payment into it.

A service is never out of stock and is bought one at a time. It costs the vendor no cooldown or
resources unless the body spends them, as the mana example does.

## Good services

- **Make the recipient matter.** A service that only ever helps the buyer could be an item.
  One you can buy *for* a companion, or *against* someone, is something only a person can offer.
- **Let the vendor pay a cost.** A healer who tires with every blessing is a character. A
  `targets: "self"` step is how.
- **Write the description for the narrator.** "lays moss on the wound and hums" is what the
  scene is built from. Leave it empty when the name already says it.
