feat(events): four event recipes for the New event page
All checks were successful
PR Checks / client-build (pull_request) Successful in 31s
PR Checks / server-tests (pull_request) Successful in 38s
PR Checks / frozen-manifest (pull_request) Successful in 50s

Authoring flows phase 2 (docs AUTHORING_FLOWS_PLAN.md §5, §6.4, D418-D419).
Registers four templates through registerEventTemplates (MODULE_API 1.13.0,
no contract change): Announcement, Boss raid, Seasonal event for a few hours
(core.lease on uo.seasonal.status, up to the 12 h lease ceiling) and
Gathering giveaway (participation count at a landmark, then uo.item.grant to
everyone counted). build() makes no shard call.

Adds server/scripts/templateBuild.js and a frozen-manifest CI step that load
the module through the pinned core's real loader and fill every recipe in
through buildFromTemplate, so core's own spec validator sees them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014HJEmd5sBSpNXicS4gmT1t
This commit is contained in:
2026-12-01 15:46:30 -06:00
parent 706d22ab78
commit be713728ee
10 changed files with 1320 additions and 1 deletions

593
server/eventTemplates.js Normal file
View File

@@ -0,0 +1,593 @@
// ── Event templates ("recipes") ─────────────────────────────────────────────
//
// Four named starting points for a new event, through core's
// `api.registerEventTemplates` (MODULE_API 1.13.0). The author fills in a few
// inputs; `build()` turns them into an ordinary draft — phases, steps, params —
// which the editor opens unsaved. Core validates the plan as a spec and keeps
// nothing about the template, so this file can change without touching a single
// event it was ever used for.
//
// uo.template.announce tell everyone, and optionally leave a news item up
// uo.template.boss_raid a named boss at a landmark for a while
// uo.template.seasonal one of ServUO's seasonal events, on for a few hours
// uo.template.gathering_giveaway a gift for everyone who turned up
//
// **`build()` makes no sidecar or shard call, and reads no database.** A recipe
// has to fill in while the shard is down — the dry run is what checks the live
// world — so everything checked here is what the inputs alone can say: formats,
// ranges, and rules between two inputs. Whether the landmark exists or the
// creature can be built is the actions' own business, at the dry run.
//
// **There is no teardown step in any of these, and that is on purpose.** What a
// run made with a `reversible: 'ledger'` action (a boss, a news article, a
// participation slot) or a `core.lease` is put back by core when the run ends.
// A phase with `advance.after` is what keeps it alive until then: the hold IS
// the length of the event.
//
// **No `default` on an input** — core drops the key — so every default lives in
// `build()`, and an input left empty arrives as absent.
const {
MAX_BROADCAST_LEN,
MAX_NEWS_TITLE,
MAX_NEWS_BODY,
MAX_AREA_RADIUS,
MAX_BOSSES,
MAX_BOSS_MULTIPLIER,
MAX_GRANT_STACK,
MAX_PROP_LEASE_MS,
GRANTABLE,
SEASONAL_EVENTS,
SEASONAL_LABELS,
} = require('./config/uoEventActions')
/** How long a Town Cryer news item stays up when the author gives a title and no length: a day. */
const DEFAULT_NEWS_MINUTES = 1440
/** The default area a giveaway counts around its place, in tiles. */
const DEFAULT_RADIUS = 40
/**
* The longest a phase may be held: thirty days, core's own paste guard on
* `advance.after` (`MAX_AFTER_SECONDS` in the spec validator). Not a policy of
* ours — a hold longer than any event this is for is a typo, and core would
* refuse it anyway, but in its words rather than the author's.
*/
const MAX_HOLD_MINUTES = 30 * 24 * 60
/** What a seasonal lease may be held for, in minutes. The lease declares 12 hours. */
const MAX_SEASONAL_MINUTES = Math.floor(MAX_PROP_LEASE_MS / 60_000)
// ── Small readers ───────────────────────────────────────────────────────────
/** An optional input is absent, null or empty. */
const isBlank = (v) => v === undefined || v === null || (typeof v === 'string' && v.trim() === '')
/** A string input, trimmed and collapsed to one line — or '' when absent. */
const oneLine = (v) => (isBlank(v) ? '' : String(v).replace(/\s+/g, ' ').trim())
/** "30 minutes", "1 hour", "3 hours", "90 minutes". */
function minutesWords(n) {
if (n >= 60 && n % 60 === 0) {
const hours = n / 60
return `${hours} hour${hours === 1 ? '' : 's'}`
}
return `${n} minute${n === 1 ? '' : 's'}`
}
/** "OrcCaptain" → "Orc Captain". A name that is not plain CamelCase is left as the shard spells it. */
function creatureWords(type) {
return /^[A-Za-z]+$/.test(type) ? type.replace(/([a-z])([A-Z])/g, '$1 $2') : type
}
/** A place as the author picked it, `facet/name` or `facet/group/name`, or null. */
function readPlace(raw) {
const place = oneLine(raw)
const parts = place.split('/')
if (parts.length < 2 || parts.some((p) => p.trim() === '')) return null
return { value: place, name: parts[parts.length - 1].trim() }
}
const placeRefusal = (raw) => `"${raw}" is not a place — pick one from the list, as facet/name`
/**
* A whole number of minutes in 1..max, or a refusal in the author's words.
* `what` finishes "<what> lasts 1 to N minutes": "the raid", "the event".
*/
function readMinutes(raw, max, what) {
const minutes = Number(raw)
if (isBlank(raw) || !Number.isInteger(minutes) || minutes < 1 || minutes > max) {
return { ok: false, error: `${what} lasts 1 to ${max} minutes, and "${raw}" is not that` }
}
return { ok: true, minutes }
}
/** A broadcast line: one line of at most `MAX_BROADCAST_LEN` characters. */
function readMessage(raw, what) {
const text = oneLine(raw)
if (text.length > MAX_BROADCAST_LEN) {
return {
ok: false,
error: `${what} is sent as one broadcast, which is capped at ${MAX_BROADCAST_LEN} characters, and this is ${text.length}`,
}
}
return { ok: true, text }
}
// ── 1. Announcement ─────────────────────────────────────────────────────────
const announce = {
id: 'uo.template.announce',
label: 'Announcement',
description:
'Tells everyone who is online a message, once. Add a news title and the same text is also posted in the in-game Town Cryer news window, and stays there for the length you choose. Nothing in the world changes; you can change every part of the plan before saving it.',
inputs: [
{
name: 'text',
type: 'string',
required: true,
example: 'The gates of Britain open at dusk. Gather at the bank.',
description: `What to tell everyone online, up to ${MAX_BROADCAST_LEN} characters. It goes out once.`,
},
{
name: 'hue',
type: 'int',
required: false,
example: 1153,
description: 'The colour of the message, as an Ultima Online colour number. Left empty, the shard uses its usual system colour.',
},
{
name: 'newsTitle',
type: 'string',
required: false,
example: 'The Britannian Midsummer Fair',
description: `A heading for a Town Cryer news article carrying the same text, up to ${MAX_NEWS_TITLE} characters. Leave it empty to post no article.`,
},
{
name: 'newsMinutes',
type: 'int',
required: false,
example: 1440,
duration: 'minutes',
description: `How long the news article stays up, in minutes. Only with a news title. Left empty, it stays ${DEFAULT_NEWS_MINUTES} minutes (a day).`,
},
],
build({ inputs }) {
const message = readMessage(inputs.text, 'the announcement')
if (!message.ok) return message
if (!message.text) return { ok: false, error: 'the announcement has no text to send' }
let hue
if (!isBlank(inputs.hue)) {
hue = Number(inputs.hue)
if (!Number.isInteger(hue) || hue < 0) {
return { ok: false, error: `"${inputs.hue}" is not a colour this shard will take; use a whole number, 0 or more` }
}
}
const newsTitle = oneLine(inputs.newsTitle)
if (!newsTitle && !isBlank(inputs.newsMinutes)) {
return { ok: false, error: 'a news length needs a news title; give the article a title, or clear the length' }
}
const steps = [
{
actionId: 'uo.broadcast',
label: 'Tell everyone online',
params: { text: message.text, ...(hue === undefined ? {} : { hue }) },
},
]
const phase = { key: 'announce', label: 'Announce', steps }
let summary = `Tells everyone online "${message.text}".`
if (newsTitle) {
if (newsTitle.length > MAX_NEWS_TITLE) {
return {
ok: false,
error: `a news title is capped at ${MAX_NEWS_TITLE} characters and this is ${newsTitle.length}`,
}
}
// The body is the broadcast text, which is already within the broadcast cap;
// the check is for the day the two caps move apart.
if (message.text.length > MAX_NEWS_BODY) {
return {
ok: false,
error: `a news article is capped at ${MAX_NEWS_BODY} characters and the text is ${message.text.length}`,
}
}
let minutes = DEFAULT_NEWS_MINUTES
if (!isBlank(inputs.newsMinutes)) {
const read = readMinutes(inputs.newsMinutes, MAX_HOLD_MINUTES, 'the news article')
if (!read.ok) return read
minutes = read.minutes
}
steps.push({
actionId: 'uo.news.post',
label: 'Post the news article',
// `announce: false`: the broadcast above has already told everyone, and the
// criers proclaiming the title as well would be the same news twice.
params: { title: newsTitle, body: message.text, announce: false },
})
// The article is taken down when the run ends, so the hold is what keeps it
// posted — the phase lasts exactly as long as the article should.
phase.advance = { after: `${minutes}m` }
summary += ` Posts "${newsTitle}" in the Town Cryer news for ${minutesWords(minutes)}.`
}
return {
title: `Announcement: ${message.text.length > 60 ? `${message.text.slice(0, 57)}...` : message.text}`,
summary,
spec: { schedule: { kind: 'manual' }, phases: [phase] },
}
},
}
// ── 2. Boss raid ────────────────────────────────────────────────────────────
const bossRaid = {
id: 'uo.template.boss_raid',
label: 'Boss raid',
description:
'A named boss appears at a landmark, the shard is told so, and the boss is removed when the time is up. It needs boss spawning to be switched on: actions that put things in the world are off until an operator enables them. The boss is cleared when the run ends, even if nobody kills it.',
inputs: [
{
name: 'place',
type: 'string',
required: true,
example: 'Felucca/Britain',
source: 'uo.options.landmarks',
description: 'Where the boss appears.',
},
{
name: 'creature',
type: 'string',
required: true,
example: 'OrcCaptain',
source: 'uo.options.creatures',
description: 'The kind of creature the boss is built from.',
},
{
name: 'name',
type: 'string',
required: true,
example: 'Gruk the Unbroken',
description: 'What the boss is called. An unnamed boss is just a hard monster.',
},
{
name: 'minutes',
type: 'int',
required: true,
example: 30,
duration: 'minutes',
description: 'How many minutes the boss stays before it is cleared away.',
},
{
name: 'count',
type: 'int',
required: false,
example: 1,
description: `How many bosses, 1 to ${MAX_BOSSES}. Left empty, one.`,
},
{
name: 'strength',
type: 'float',
required: false,
example: 3,
description: `How many times tougher than normal, and how many times harder it hits, 1 to ${MAX_BOSS_MULTIPLIER}. Left empty, or 1, it is as strong as the creature normally is.`,
},
{
name: 'message',
type: 'string',
required: false,
example: 'Gruk the Unbroken has appeared near Britain!',
description: `What the shard is told when the boss appears, up to ${MAX_BROADCAST_LEN} characters. Left empty, "<name> has appeared near <place>!".`,
},
],
build({ inputs }) {
const place = readPlace(inputs.place)
if (!place) return { ok: false, error: placeRefusal(inputs.place) }
const creature = oneLine(inputs.creature)
if (!creature) return { ok: false, error: 'pick a creature for the boss to be built from' }
const name = oneLine(inputs.name)
if (!name) return { ok: false, error: 'a boss needs a name' }
const read = readMinutes(inputs.minutes, MAX_HOLD_MINUTES, 'a raid')
if (!read.ok) return read
const { minutes } = read
let count = 1
if (!isBlank(inputs.count)) {
count = Number(inputs.count)
if (!Number.isInteger(count) || count < 1 || count > MAX_BOSSES) {
return { ok: false, error: `a raid has 1 to ${MAX_BOSSES} bosses, and "${inputs.count}" is not that` }
}
}
let strength = 1
if (!isBlank(inputs.strength)) {
strength = Number(inputs.strength)
if (!Number.isFinite(strength) || strength < 1 || strength > MAX_BOSS_MULTIPLIER) {
return {
ok: false,
error: `a boss is 1 to ${MAX_BOSS_MULTIPLIER} times as strong as normal, and "${inputs.strength}" is not`,
}
}
}
const message = readMessage(
isBlank(inputs.message) ? `${name} has appeared near ${place.name}!` : inputs.message,
isBlank(inputs.message) ? 'the default message (shorten the boss name or write your own)' : 'the message',
)
if (!message.ok) return message
const spawn = {
place: place.value,
creature,
name,
count,
// 1 is "as normal", so it is left out rather than written as a multiplier
// that does nothing.
...(strength > 1 ? { hitsMultiplier: strength, damageMultiplier: strength } : {}),
}
const who = count === 1 ? name : `${count} bosses called ${name}`
return {
title: `${creatureWords(creature)} raid at ${place.value} for ${minutesWords(minutes)}`,
summary:
`${who}, built from ${creatureWords(creature)}${strength > 1 ? ` and ${strength} times as strong` : ''}, ` +
`appear${count === 1 ? 's' : ''} near ${place.value} and ${count === 1 ? 'is' : 'are'} removed after ${minutesWords(minutes)}.`,
spec: {
schedule: { kind: 'manual' },
phases: [
{
key: 'raid',
label: 'The raid',
// The boss is cleared when the run ends, so the hold is its lifetime.
advance: { after: `${minutes}m` },
steps: [
{ actionId: 'uo.boss.spawn', label: count === 1 ? 'Spawn the boss' : 'Spawn the bosses', params: spawn },
{ actionId: 'uo.broadcast', label: 'Tell everyone it has appeared', params: { text: message.text } },
],
},
],
},
}
},
}
// ── 3. Seasonal event ───────────────────────────────────────────────────────
const seasonal = {
id: 'uo.template.seasonal',
label: 'Seasonal event for a few hours',
description:
`Switches one of ServUO's own seasonal events on, and back off by itself when the time is up (up to ${MAX_SEASONAL_MINUTES / 60} hours). Six of the eight add or remove things in the world when they change, so this is a bigger switch than it looks. It borrows the event's setting and puts the old one back when the run ends.`,
inputs: [
{
name: 'event',
type: 'string',
required: true,
example: 'Fellowship',
source: 'uo.options.seasonal',
description: 'Which of the shard\'s seasonal events to switch on.',
},
{
name: 'minutes',
type: 'int',
required: true,
example: 180,
duration: 'minutes',
description: `How many minutes it stays on, up to ${MAX_SEASONAL_MINUTES} (${MAX_SEASONAL_MINUTES / 60} hours). 180 is three hours.`,
},
{
name: 'message',
type: 'string',
required: false,
example: 'The Krampus has come to Britannia for a few hours!',
description: `What the shard is told once it is on, up to ${MAX_BROADCAST_LEN} characters. Left empty, nobody is told.`,
},
],
build({ inputs }) {
const event = oneLine(inputs.event)
if (!SEASONAL_EVENTS.includes(event)) {
return {
ok: false,
error: `"${inputs.event}" is not a seasonal event this recipe can switch on — pick one from the list`,
}
}
const read = readMinutes(inputs.minutes, MAX_SEASONAL_MINUTES, 'a seasonal event')
if (!read.ok) return read
const { minutes } = read
const message = readMessage(inputs.message, 'the message')
if (!message.ok) return message
const label = SEASONAL_LABELS[event] || event
const steps = [
{
actionId: 'core.lease',
label: `Switch on ${label}`,
params: { lease: 'uo.seasonal.status', target: event, value: 'Active', minutes },
},
]
if (message.text) {
steps.push({ actionId: 'uo.broadcast', label: 'Tell everyone it is on', params: { text: message.text } })
}
return {
title: `${label} for ${minutesWords(minutes)}`,
summary: `Switches ${label} on for ${minutesWords(minutes)}, then puts it back as it was.`,
spec: {
schedule: { kind: 'manual' },
phases: [
{
key: 'season',
label,
// The lease is given back when the run ends, so the hold is how long the
// event stays on — and the lease's own `minutes` is the game's deadline.
advance: { after: `${minutes}m` },
steps,
},
],
},
}
},
}
// ── 4. Gathering giveaway ───────────────────────────────────────────────────
const gatheringGiveaway = {
id: 'uo.template.gathering_giveaway',
label: 'Gathering giveaway',
description:
'Players gather at a landmark for a while; when the time is up, everyone the shard counted in the area during that window is given the item. Gifts go into backpacks and cannot be taken back, so check the item and amount before you start.',
inputs: [
{
name: 'place',
type: 'string',
required: true,
example: 'Felucca/Britain',
source: 'uo.options.landmarks',
description: 'Where players gather.',
},
{
name: 'minutes',
type: 'int',
required: true,
example: 30,
duration: 'minutes',
description: 'How many minutes players have to gather before the gifts are handed out.',
},
{
name: 'item',
type: 'string',
required: true,
example: 'gold',
source: 'uo.options.items',
description: 'What everyone is given. The list is what the shard is willing to hand out.',
},
{
name: 'amount',
type: 'int',
required: false,
example: 500,
description: `How many each, up to ${MAX_GRANT_STACK}. Only items that stack, like gold, can be given more than one at a time. Left empty, one.`,
},
{
name: 'radius',
type: 'int',
required: false,
example: DEFAULT_RADIUS,
description: `How many tiles around the place count as being there, 1 to ${MAX_AREA_RADIUS}. Left empty, ${DEFAULT_RADIUS}.`,
},
{
name: 'message',
type: 'string',
required: false,
example: 'Gather near Britain in the next 30 minutes for a gift!',
description: `What the shard is told when the gathering opens, up to ${MAX_BROADCAST_LEN} characters. Left empty, "Gather near <place> in the next <minutes> minutes for a gift!".`,
},
],
build({ inputs }) {
const place = readPlace(inputs.place)
if (!place) return { ok: false, error: placeRefusal(inputs.place) }
const read = readMinutes(inputs.minutes, MAX_HOLD_MINUTES, 'a gathering')
if (!read.ok) return read
const { minutes } = read
const itemKey = oneLine(inputs.item)
const item = GRANTABLE.find((g) => g.key === itemKey)
if (!item) {
return { ok: false, error: `this shard does not give out "${inputs.item}" — pick one from the list` }
}
let amount = 1
if (!isBlank(inputs.amount)) {
amount = Number(inputs.amount)
if (!Number.isInteger(amount) || amount < 1 || amount > MAX_GRANT_STACK) {
return { ok: false, error: `give 1 to ${MAX_GRANT_STACK} each, and "${inputs.amount}" is not that` }
}
}
if (!item.stackable && amount > 1) {
return { ok: false, error: `${item.label} does not stack, so it can only be given one at a time` }
}
let radius = DEFAULT_RADIUS
if (!isBlank(inputs.radius)) {
radius = Number(inputs.radius)
if (!Number.isInteger(radius) || radius < 1 || radius > MAX_AREA_RADIUS) {
return { ok: false, error: `the gathering area is 1 to ${MAX_AREA_RADIUS} tiles, and "${inputs.radius}" is not that` }
}
}
const custom = !isBlank(inputs.message)
const message = readMessage(
custom ? inputs.message : `Gather near ${place.name} in the next ${minutesWords(minutes)} for a gift!`,
custom ? 'the message' : 'the default message (write your own)',
)
if (!message.ok) return message
const gift = amount === 1 ? `one ${item.label.toLowerCase()}` : `${amount} ${item.label.toLowerCase()}`
return {
title: `Gathering giveaway at ${place.value} for ${minutesWords(minutes)}`,
summary:
`Players gather within ${radius} tiles of ${place.value} for ${minutesWords(minutes)}; ` +
`then everyone who was there is given ${gift} each. Gifts cannot be taken back.`,
spec: {
schedule: { kind: 'manual' },
phases: [
{
key: 'gather',
label: 'Gather',
// The counting slot is given back when the run ends, so this hold is the
// window: the reward phase starts when it is up, not before.
advance: { after: `${minutes}m` },
steps: [
{ actionId: 'uo.broadcast', label: 'Invite everyone', params: { text: message.text } },
{
actionId: 'uo.participation.open',
label: 'Start counting who is there',
params: { place: place.value, radius },
},
],
},
{
key: 'reward',
label: 'Give the gifts',
steps: [
{ actionId: 'uo.participation.collect', label: 'Record who was there', params: {} },
{ actionId: 'uo.item.grant', label: 'Give everyone the gift', params: { item: item.key, amount } },
{
actionId: 'uo.broadcast',
label: 'Say thank you',
params: { text: 'Thank you for coming — gifts are in your backpacks.' },
},
],
},
],
},
}
},
}
const TEMPLATES = [announce, bossRaid, seasonal, gatheringGiveaway]
module.exports = {
TEMPLATES,
DEFAULT_NEWS_MINUTES,
DEFAULT_RADIUS,
MAX_HOLD_MINUTES,
MAX_SEASONAL_MINUTES,
minutesWords,
creatureWords,
}