Stage 5 of the §14.3 integration plan, on protocol 14 (docs rust-link/PROTOCOL.md §20.8). - dt.started and dt.won are public kinds, dt.ended a staff kind. The new dangerousTreasures.js reads each row per viewer: grid and invaderCount for everyone, the winner's name for the presence audience (D376), the position, the step's key, the winner's Steam id and the invaders for staff. - Feed lines in the World events filter: "A Dangerous Treasures event has started · K12", "Alice won the treasure · K12 · 3 players fought for it". - Triggers rust.dt.started (with byEvent) and rust.dt.won, public, cooldown subject the server, names only. - eventDangerousTreasures.js: rust.dt.start, "Start a Dangerous Treasures event" (risk change, reversible none, budget rust.dt.events), server and difficulty. Refused at verify where the server said DT is not loaded or console.plugins is false (Rust-Plugins#34). dt-not-ready answers "Dangerous Treasures is not ready yet" with retryAfterMs 600000 (D365, D371); dt-no-spot retries on core's delay; DT's own refusals are permanent. - Treasure Hunter (D375): treasuresWon -> treasures_won, the title category treasureswon, and a sortable Treasures column shown where the server reports DT or a row counts one. - The map draws a running chest on the world layer; the server settings' plugin line names DT and whether a step can start one, from the integrations read's new `console`. - coreApi ^1.15.0, ci/core-ref.json pinned to website main at #215's merge. ci/bundle.json ships the two new files; swagger fragment and engagement manifest regenerated; README lists DT. Server 627/627 (16 new in test/dangerousTreasures.test.js) and every check; client 92/92, build and externals. Booted against the pinned core: 45 triggers, 13 actions, 11 budgets, 21 option sources; 89 routes unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E14m6SuuY6i1vASFeGDBeY
98 lines
3.8 KiB
JavaScript
98 lines
3.8 KiB
JavaScript
// ── Dangerous Treasures (protocol 14, PLAN_REDESIGNS §14.3.4) ──────────────
|
|
//
|
|
// nivex's Dangerous Treasures opens a guarded, burning treasure chest somewhere
|
|
// on the map. Its events reach this module as three kinds: `dt.started`
|
|
// (public), `dt.won` (public) and `dt.ended` (staff's). The chest emptied is
|
|
// *Treasure Hunter*'s count, from the tally's `treasuresWon` (D375). A run's step
|
|
// opens one (`eventDangerousTreasures.js`).
|
|
//
|
|
// ── Who may read what ──────────────────────────────────────────────────────
|
|
//
|
|
// As a world event is read (`worldEvents.js`, D353, D376): the event and its
|
|
// grid are public; the winner's name shows only to the operator's presence
|
|
// audience, so with presence left at staff a signed-out visitor reads "The
|
|
// treasure was won at K12"; Steam ids, the invaders' among them, and the
|
|
// position are staff's. How many fought for it is a count, and names nobody.
|
|
// The step's key, when a step opened it, is staff's too.
|
|
|
|
const { gridOf } = require('./worldEvents')
|
|
|
|
const KINDS = Object.freeze(['dt.started', 'dt.won', 'dt.ended'])
|
|
|
|
/** DT's three shipped difficulties, as `dtevent <level>` takes them. */
|
|
const LEVELS = Object.freeze([
|
|
{ value: 0, label: 'Easy' },
|
|
{ value: 1, label: 'Medium' },
|
|
{ value: 2, label: 'Hard' },
|
|
])
|
|
|
|
const STEAM_ID = /^\d{17}$/
|
|
|
|
function isKind(kind) {
|
|
return KINDS.includes(kind)
|
|
}
|
|
|
|
/**
|
|
* One `dt.*` frame for one viewer: `{ staff, presence, geometry }`. Passes the
|
|
* envelope, adds `grid`; a win adds `invaderCount`, and `name` for the presence
|
|
* audience. Staff also get `x`, `z`, the step's `key`, the winner's `steamId` and
|
|
* the `invaders`. Any other frame is returned as is.
|
|
*/
|
|
function shapeFor(frame, { staff = false, presence = false, geometry = null } = {}) {
|
|
if (!frame || !isKind(frame.kind)) return frame
|
|
|
|
const out = {}
|
|
for (const key of ['kind', 'type', 't', 'serverId', 'wipeId']) {
|
|
if (frame[key] !== undefined) out[key] = frame[key]
|
|
}
|
|
|
|
const grid = gridOf(geometry, frame.x, frame.z)
|
|
if (grid) out.grid = grid
|
|
|
|
if (frame.kind === 'dt.won') {
|
|
const invaders = Array.isArray(frame.invaders) ? frame.invaders : []
|
|
const count = Number(frame.invaderCount)
|
|
out.invaderCount = Number.isInteger(count) && count >= 0 ? count : invaders.length
|
|
if ((presence || staff) && typeof frame.name === 'string' && frame.name) out.name = frame.name
|
|
if (staff) {
|
|
if (STEAM_ID.test(String(frame.steamId || ''))) out.steamId = String(frame.steamId)
|
|
out.invaders = invaders.map(String).filter((id) => STEAM_ID.test(id))
|
|
}
|
|
}
|
|
|
|
if (staff) {
|
|
for (const key of ['x', 'z', 'key']) {
|
|
if (frame[key] !== undefined) out[key] = frame[key]
|
|
}
|
|
}
|
|
|
|
return out
|
|
}
|
|
|
|
/**
|
|
* A server's last report about Dangerous Treasures and its console, from
|
|
* `servers.db.dtReportFor`: `{ dangerousTreasures, consolePlugins }`, each null
|
|
* where the plugin never said (no state yet, or a plugin before protocol 14).
|
|
* `dangerousTreasures` is `{ loaded, version }`.
|
|
*/
|
|
function reportOf(row) {
|
|
const parse = (value) => {
|
|
if (value === null || value === undefined) return null
|
|
if (typeof value !== 'string') return value
|
|
try {
|
|
return JSON.parse(value)
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
const dt = row ? parse(row.dangerousTreasures) : null
|
|
const probe = row ? parse(row.console) : null
|
|
return {
|
|
dangerousTreasures:
|
|
dt && typeof dt === 'object' ? { loaded: dt.loaded === true, version: typeof dt.version === 'string' ? dt.version : null } : null,
|
|
consolePlugins: probe && typeof probe === 'object' && typeof probe.plugins === 'boolean' ? probe.plugins : null,
|
|
}
|
|
}
|
|
|
|
module.exports = { KINDS, LEVELS, isKind, shapeFor, reportOf }
|