random-tables-mcp
Version:
An MCP (Model Context Protocol) server for managing and rolling on random-table assets used in tabletop RPGs. Create, update, and roll on random tables with support for nested tables, weighted entries, and range-based results.
58 lines • 2.22 kB
JavaScript
/**
* Represents the result of a roll on a random table.
*/
export class RollResult {
/**
* Creates a new RollResult instance.
* @param tableId ID of the table rolled on.
* @param entryId ID of the resulting entry.
* @param content Content of the resulting entry.
* @param isTemplate Whether the content is a template.
* @param resolvedContent Optional resolved content if the original content was a template.
* @param timestamp When the roll occurred (defaults to current time).
*/
constructor(tableId, entryId, content, isTemplate = false, resolvedContent, timestamp = new Date()) {
this.tableId = tableId;
this.entryId = entryId;
this.content = content;
this.isTemplate = isTemplate;
this.resolvedContent = resolvedContent;
this.timestamp = timestamp;
}
/**
* Creates a RollResult from a plain object.
* @param obj The object to create the result from.
* @returns A new RollResult instance.
*/
static fromObject(obj) {
const timestamp = obj.timestamp
? obj.timestamp instanceof Date
? obj.timestamp
: new Date(obj.timestamp)
: new Date();
return new RollResult(obj.tableId, obj.entryId, obj.content, obj.isTemplate ?? false, obj.resolvedContent, timestamp);
}
/**
* Converts this result to a plain object.
* @returns A plain object representation of this result.
*/
toObject() {
return {
tableId: this.tableId,
entryId: this.entryId,
content: this.content,
isTemplate: this.isTemplate,
resolvedContent: this.resolvedContent,
timestamp: this.timestamp.toISOString(),
};
}
/**
* Creates a new RollResult with resolved content.
* @param resolvedContent The resolved content.
* @returns A new RollResult with the same properties but with resolved content.
*/
withResolvedContent(resolvedContent) {
return new RollResult(this.tableId, this.entryId, this.content, this.isTemplate, resolvedContent, this.timestamp);
}
}
//# sourceMappingURL=roll-result.js.map