briyah 1.3.5 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +849 -684
- package/data/common/artifacts/dnd5e/campaign_designer-setting.md +112 -0
- package/data/common/artifacts/dnd5e/character_creator-basics.md +40 -0
- package/data/common/artifacts/dnd5e/class-barbarian.md +64 -0
- package/data/common/artifacts/dnd5e/class-bard.md +63 -0
- package/data/common/artifacts/dnd5e/class-cleric.md +60 -0
- package/data/common/artifacts/dnd5e/class-druid.md +56 -0
- package/data/common/artifacts/dnd5e/class-fighter.md +53 -0
- package/data/common/artifacts/dnd5e/class-monk.md +77 -0
- package/data/common/artifacts/dnd5e/class-paladin.md +66 -0
- package/data/common/artifacts/dnd5e/class-ranger.md +73 -0
- package/data/common/artifacts/dnd5e/class-rogue.md +62 -0
- package/data/common/artifacts/dnd5e/class-sorcerer.md +67 -0
- package/data/common/artifacts/dnd5e/class-warlock.md +83 -0
- package/data/common/artifacts/dnd5e/class-wizard.md +51 -0
- package/data/common/artifacts/dnd5e/dungeon_master-procedure.md +348 -0
- package/data/common/artifacts/dnd5e/manifest.json +95 -0
- package/data/common/config/markup +1 -1
- package/data/common/config/model_prices.json +1250 -237
- package/data/common/prompts/campaign_designer/defaults_config.json +16 -0
- package/data/common/prompts/campaign_designer/perceive.json +29 -0
- package/data/common/prompts/campaign_designer/perceive.prompt +345 -0
- package/data/common/prompts/campaign_designer/system_instruction.prompt +0 -0
- package/data/common/prompts/character_creator/defaults_config.json +31 -0
- package/data/common/prompts/character_creator/perceive.json +29 -0
- package/data/common/prompts/character_creator/perceive.prompt +621 -0
- package/data/common/prompts/character_creator/system_instruction.prompt +0 -0
- package/data/common/prompts/dnd_player/defaults_config.json +5 -0
- package/data/common/prompts/dnd_player/perceive.json +29 -0
- package/data/common/prompts/dnd_player/perceive.prompt +312 -0
- package/data/common/prompts/dnd_player/system_instruction.prompt +0 -0
- package/data/common/prompts/dnd_room_moderator/defaults_config.json +9 -0
- package/data/common/prompts/dnd_room_moderator/moderate.json +34 -0
- package/data/common/prompts/dnd_room_moderator/moderate.prompt +291 -0
- package/data/common/prompts/dnd_room_moderator/system_instruction.prompt +0 -0
- package/data/common/prompts/dungeon_master/compact_agent.prompt +24 -0
- package/data/common/prompts/dungeon_master/defaults_config.json +29 -0
- package/data/common/prompts/dungeon_master/perceive.json +33 -0
- package/data/common/prompts/dungeon_master/perceive.prompt +757 -0
- package/data/common/prompts/dungeon_master/system_instruction.prompt +0 -0
- package/data/common/prompts/room_moderator/moderate.json +34 -29
- package/data/common/prompts/room_moderator/moderate.prompt +230 -210
- package/data/common/prompts/story_moderator/moderate.prompt +5 -2
- package/data/common/prompts/story_moderator/moderate_to_alice.mock +6 -6
- package/data/common/prompts/story_moderator/moderate_to_bob.mock +6 -6
- package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +2 -0
- package/dist-sdk/server/src/ai/LLM/anthropic.service.js +34 -22
- package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +1 -0
- package/dist-sdk/server/src/ai/LLM/base-ai.service.js +4 -1
- package/dist-sdk/server/src/ai/agent-config.d.ts +1 -0
- package/dist-sdk/server/src/ai/agent-store.service.js +6 -4
- package/dist-sdk/server/src/ai/agent.d.ts +7 -0
- package/dist-sdk/server/src/ai/agent.js +33 -2
- package/dist-sdk/server/src/ai/artifact.service.d.ts +2 -0
- package/dist-sdk/server/src/ai/artifact.service.js +29 -1
- package/dist-sdk/server/src/ai/pack-artifacts.d.ts +7 -0
- package/dist-sdk/server/src/ai/pack-artifacts.js +155 -0
- package/dist-sdk/server/src/app/stripe.controller.js +5 -0
- package/dist-sdk/server/src/app.controller.d.ts +18 -18
- package/dist-sdk/server/src/app.controller.js +249 -25
- package/dist-sdk/server/src/app.service.d.ts +30 -17
- package/dist-sdk/server/src/app.service.js +303 -35
- package/dist-sdk/server/src/auth/auth.controller.js +3 -2
- package/dist-sdk/server/src/auth/owner-only.decorator.d.ts +1 -0
- package/dist-sdk/server/src/auth/owner-only.decorator.js +8 -0
- package/dist-sdk/server/src/auth/twilio.service.d.ts +5 -1
- package/dist-sdk/server/src/auth/twilio.service.js +5 -3
- package/dist-sdk/server/src/config/user-paths.service.d.ts +2 -0
- package/dist-sdk/server/src/config/user-paths.service.js +8 -0
- package/dist-sdk/server/src/room/artifact-store.service.js +10 -2
- package/dist-sdk/server/src/room/artifact.d.ts +1 -0
- package/dist-sdk/server/src/room/message.d.ts +2 -1
- package/dist-sdk/server/src/room/message.js +5 -4
- package/dist-sdk/server/src/room/room-config.d.ts +3 -0
- package/dist-sdk/server/src/room/room-store.service.d.ts +4 -2
- package/dist-sdk/server/src/room/room-store.service.js +46 -12
- package/dist-sdk/server/src/room/room.d.ts +29 -3
- package/dist-sdk/server/src/room/room.js +390 -122
- package/dist-sdk/server/src/sdk/briyah.js +12 -0
- package/dist-sdk/server/src/sdk/index.d.ts +4 -1
- package/dist-sdk/server/src/sdk/index.js +9 -1
- package/dist-sdk/server/src/story/story.service.js +10 -12
- package/dist-sdk/server/src/tools/native-tool.types.d.ts +31 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.d.ts +22 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.js +59 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.d.ts +24 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/feats.js +11 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.d.ts +5 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.generated.js +154 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.js +9 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.d.ts +20 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.d.ts +2 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.generated.js +1824 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/magic-items.js +6 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.d.ts +44 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.d.ts +2 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.generated.js +17293 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/monsters.js +5 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/races.d.ts +41 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/races.js +250 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.d.ts +16 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.d.ts +2 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.generated.js +3760 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/spells.js +12 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.d.ts +63 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.js +449 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.d.ts +23 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/weapons.js +88 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/backgrounds.d.ts +20 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/backgrounds.js +109 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.d.ts +30 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.js +329 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.d.ts +9 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/campaign-items.js +100 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.d.ts +117 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.js +1057 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.d.ts +13 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.js +147 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.d.ts +27 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.js +263 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.d.ts +26 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encumbrance.js +129 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.d.ts +22 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/feats.js +127 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.d.ts +33 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/items.js +137 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.d.ts +26 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.js +182 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.d.ts +48 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.js +344 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +98 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +456 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.d.ts +27 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/spells.js +123 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.d.ts +23 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/weapons.js +201 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/index.d.ts +3 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/index.js +35 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.d.ts +2 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.js +323 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.d.ts +3 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.js +117 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.d.ts +2 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/item.tool.js +122 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.d.ts +2 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.js +157 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +32 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +203 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.d.ts +4 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +465 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.d.ts +2 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/spell.tool.js +116 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.d.ts +4 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.js +234 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.d.ts +6 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.js +616 -0
- package/dist-sdk/server/src/tools/packs/index.d.ts +7 -0
- package/dist-sdk/server/src/tools/packs/index.js +45 -0
- package/dist-sdk/server/src/tools/tool-execution.service.d.ts +2 -2
- package/dist-sdk/server/src/tools/tool-execution.service.js +7 -6
- package/dist-sdk/shared/types/app.types.d.ts +63 -0
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/Agent.html +51 -15
- package/docs/classes/Briyah.html +14 -14
- package/docs/classes/BriyahConfigService.html +5 -5
- package/docs/classes/NativeToolRegistry.html +21 -0
- package/docs/classes/Room.html +79 -29
- package/docs/classes/RoomMessage.html +32 -15
- package/docs/enums/MessageAction.html +3 -3
- package/docs/functions/availableToolPacks.html +2 -0
- package/docs/functions/dnd5eTools.html +5 -0
- package/docs/functions/enabledToolPacks.html +2 -0
- package/docs/functions/registerToolPacks.html +6 -0
- package/docs/hierarchy.html +1 -1
- package/docs/index.html +69 -3
- package/docs/interfaces/AgentInfo.html +17 -2
- package/docs/interfaces/AgentMessagesResponse.html +2 -2
- package/docs/interfaces/AppService.html +230 -181
- package/docs/interfaces/Artifact.html +15 -3
- package/docs/interfaces/ArtifactMetadata.html +5 -2
- package/docs/interfaces/ArtifactWriteOptions.html +21 -0
- package/docs/interfaces/AttachDocumentResponse.html +2 -2
- package/docs/interfaces/BriyahConfigOptions.html +9 -9
- package/docs/interfaces/ChapterInfo.html +2 -2
- package/docs/interfaces/Character.html +2 -2
- package/docs/interfaces/CreateAgentResponse.html +2 -2
- package/docs/interfaces/CreateRoomResponse.html +2 -2
- package/docs/interfaces/CreateStoryResponse.html +2 -2
- package/docs/interfaces/FileList.html +2 -2
- package/docs/interfaces/FileMetadata.html +3 -3
- package/docs/interfaces/IConfigService.html +3 -3
- package/docs/interfaces/LoggingOptions.html +6 -6
- package/docs/interfaces/Message.html +2 -2
- package/docs/interfaces/ModelInfo.html +2 -2
- package/docs/interfaces/NativeToolDefinition.html +11 -7
- package/docs/interfaces/PreparedPromptResponse.html +2 -2
- package/docs/interfaces/ProcessTextResponse.html +2 -2
- package/docs/interfaces/PromptFile.html +2 -2
- package/docs/interfaces/PromptFileContent.html +2 -2
- package/docs/interfaces/PromptFilesResponse.html +2 -2
- package/docs/interfaces/PromptFolder.html +2 -2
- package/docs/interfaces/PromptFoldersResponse.html +2 -2
- package/docs/interfaces/RoomDetails.html +15 -2
- package/docs/interfaces/RoomInfo.html +3 -2
- package/docs/interfaces/RoomMessageUpdate.html +2 -2
- package/docs/interfaces/RoomMessagesResponse.html +2 -2
- package/docs/interfaces/SendMessageResult.html +2 -2
- package/docs/interfaces/StoryErrorEvent.html +3 -3
- package/docs/interfaces/StoryIdea.html +2 -2
- package/docs/interfaces/StoryInfo.html +3 -3
- package/docs/interfaces/StoryIntroduceCharacterEvent.html +3 -3
- package/docs/interfaces/StoryProgressChapterEvent.html +3 -3
- package/docs/interfaces/StoryState.html +5 -5
- package/docs/interfaces/StoryStateEvent.html +3 -3
- package/docs/interfaces/ToolArtifact.html +8 -0
- package/docs/interfaces/ToolCaller.html +8 -0
- package/docs/interfaces/ToolDefinition.html +2 -2
- package/docs/interfaces/ToolHelpers.html +7 -3
- package/docs/interfaces/ToolParameter.html +2 -2
- package/docs/interfaces/ToolRoomAccess.html +51 -0
- package/docs/interfaces/ToolSummary.html +3 -2
- package/docs/interfaces/ToolsResponse.html +2 -2
- package/docs/interfaces/Transaction.html +2 -2
- package/docs/interfaces/TransactionHistoryResponse.html +2 -2
- package/docs/modules.html +1 -1
- package/docs/types/PromptScope.html +1 -1
- package/docs/types/ToolContext.html +2 -2
- package/docs/types/ToolRunResult.html +1 -1
- package/package.json +8 -5
- package/src/tools/packs/dnd5e/README.md +614 -0
- package/dist-sdk/server/src/ai/LLM/base-ai.service.spec.d.ts +0 -1
- package/dist-sdk/server/src/ai/LLM/base-ai.service.spec.js +0 -89
- package/dist-sdk/server/src/ai/LLM/comfyui-client.spec.d.ts +0 -1
- package/dist-sdk/server/src/ai/LLM/comfyui-client.spec.js +0 -143
- package/dist-sdk/server/src/ai/LLM/comfyui-workflow.spec.d.ts +0 -1
- package/dist-sdk/server/src/ai/LLM/comfyui-workflow.spec.js +0 -207
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rollInitiativeTool = exports.rollDiceTool = void 0;
|
|
4
|
+
const coerce_1 = require("../engine/coerce");
|
|
5
|
+
const dice_1 = require("../engine/dice");
|
|
6
|
+
const sheet_1 = require("../engine/sheet");
|
|
7
|
+
const shared_1 = require("./shared");
|
|
8
|
+
const coerce_2 = require("../engine/coerce");
|
|
9
|
+
exports.rollDiceTool = {
|
|
10
|
+
name: 'roll_dice',
|
|
11
|
+
description: 'Roll dice and get the totals. "expressions" is a semicolon-separated list, each optionally labelled with "label=". Supports NdM with + and - modifiers, kh/kl (keep the highest/lowest N, default 1), dh/dl (drop), adv/dis (roll a d20 twice and take the higher/lower), r1 (reroll each 1 once), min2 (treat dice below 2 as 2), crit (double the dice), and xN (repeat the roll N times). Returns each label with its individual dice, any dropped dice, and the total. At most 20 expressions and 100 dice per call. Examples: "attack=1d20+5 adv; damage=2d6+3" — "hp=4d6kh3 x6" — "1d20".',
|
|
12
|
+
parameters: [
|
|
13
|
+
{
|
|
14
|
+
name: 'expressions',
|
|
15
|
+
type: 'string',
|
|
16
|
+
description: 'Semicolon-separated dice expressions, e.g. "attack=1d20+5 adv; damage=2d6+3"',
|
|
17
|
+
required: true,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: 'reason',
|
|
21
|
+
type: 'string',
|
|
22
|
+
description: 'What the roll is for, echoed back so the log reads clearly',
|
|
23
|
+
required: false,
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
async handler(args) {
|
|
27
|
+
const expressions = (0, coerce_1.str)(args.expressions, 'expressions');
|
|
28
|
+
const results = (0, dice_1.rollExpressions)(expressions);
|
|
29
|
+
return {
|
|
30
|
+
reason: args.reason ? (0, coerce_1.str)(args.reason, 'reason') : undefined,
|
|
31
|
+
rolls: results.map((result) => ({
|
|
32
|
+
label: result.label,
|
|
33
|
+
dice: result.dice.map((d) => d.value),
|
|
34
|
+
dropped: result.dice.filter((d) => d.dropped).map((d) => d.value),
|
|
35
|
+
modifier: result.modifier,
|
|
36
|
+
total: result.total,
|
|
37
|
+
natural20: result.natural20,
|
|
38
|
+
natural1: result.natural1,
|
|
39
|
+
})),
|
|
40
|
+
summary: results.map(dice_1.describeRoll).join(' · '),
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
exports.rollInitiativeTool = {
|
|
45
|
+
name: 'roll_initiative',
|
|
46
|
+
description: 'Roll initiative for a whole encounter in one call and get the turn order. "combatants" is a semicolon-separated list: a bare Name for a character who has a sheet (their modifier is read from it), or Name+N / Name-N for monsters and NPCs. Ties break toward the higher modifier, then by the order given. The order is also written to the "Encounter" artifact so everyone can see whose turn it is. Example: "Thalia; Dorn; Goblin A+2; Goblin B+2; Hobgoblin Captain+1".',
|
|
47
|
+
parameters: [
|
|
48
|
+
{
|
|
49
|
+
name: 'combatants',
|
|
50
|
+
type: 'string',
|
|
51
|
+
description: 'Semicolon-separated combatants, e.g. "Thalia; Dorn; Goblin A+2; Goblin B+2"',
|
|
52
|
+
required: true,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'encounter_name',
|
|
56
|
+
type: 'string',
|
|
57
|
+
description: 'A name for the encounter, shown in the Encounter artifact',
|
|
58
|
+
required: false,
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
async handler(args, helpers) {
|
|
62
|
+
const room = (0, shared_1.requireRoom)(helpers);
|
|
63
|
+
const entries = (0, coerce_1.list)(args.combatants);
|
|
64
|
+
if (entries.length === 0) {
|
|
65
|
+
throw new Error('No combatants given. Example: "Thalia; Dorn; Goblin A+2; Goblin B+2".');
|
|
66
|
+
}
|
|
67
|
+
const known = (0, shared_1.listCharacterNames)(room);
|
|
68
|
+
const rolled = entries.map((entry, index) => {
|
|
69
|
+
const parsed = parseCombatant(entry);
|
|
70
|
+
let modifier = parsed.modifier;
|
|
71
|
+
let source = 'given';
|
|
72
|
+
if (modifier === null) {
|
|
73
|
+
const matched = (0, coerce_2.matchName)(parsed.name, known);
|
|
74
|
+
if (matched) {
|
|
75
|
+
modifier = (0, shared_1.loadSheet)(room, matched).state.initBonus;
|
|
76
|
+
source = 'sheet';
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
modifier = 0;
|
|
80
|
+
source = 'assumed 0';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const roll = (0, dice_1.rollD20)(modifier, 'normal', dice_1.defaultRng);
|
|
84
|
+
return { name: parsed.name, modifier, source, index, roll };
|
|
85
|
+
});
|
|
86
|
+
rolled.sort((a, b) => b.roll.total - a.roll.total || b.modifier - a.modifier || a.index - b.index);
|
|
87
|
+
const order = rolled.map((entry, position) => ({
|
|
88
|
+
position: position + 1,
|
|
89
|
+
name: entry.name,
|
|
90
|
+
initiative: entry.roll.total,
|
|
91
|
+
roll: entry.roll.kept[0],
|
|
92
|
+
modifier: entry.modifier,
|
|
93
|
+
}));
|
|
94
|
+
const encounterName = args.encounter_name ? (0, coerce_1.str)(args.encounter_name, 'encounter_name') : 'Encounter';
|
|
95
|
+
room.update(sheet_1.ENCOUNTER_ARTIFACT, () => [
|
|
96
|
+
`# ${encounterName}`,
|
|
97
|
+
'',
|
|
98
|
+
'Round 1. Initiative order:',
|
|
99
|
+
'',
|
|
100
|
+
...order.map((e) => `${e.position}. ${e.name} — ${e.initiative}`),
|
|
101
|
+
'',
|
|
102
|
+
].join('\n'), { viewers: room.agentNicknames });
|
|
103
|
+
return {
|
|
104
|
+
encounter: encounterName,
|
|
105
|
+
order,
|
|
106
|
+
summary: order.map((e) => `${e.name} ${e.initiative}`).join(', '),
|
|
107
|
+
note: `Initiative order written to the "${sheet_1.ENCOUNTER_ARTIFACT}" artifact. Call on each combatant in this order.`,
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
function parseCombatant(entry) {
|
|
112
|
+
const match = /^(.*?)\s*([+\-−]\s*\d+)$/.exec(entry.trim());
|
|
113
|
+
if (!match)
|
|
114
|
+
return { name: entry.trim(), modifier: null };
|
|
115
|
+
const raw = match[2].replace(/\s+/g, '').replace('−', '-');
|
|
116
|
+
return { name: match[1].trim(), modifier: (0, coerce_1.int)(raw, 'combatants', 0) };
|
|
117
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.magicItemTool = void 0;
|
|
4
|
+
const coerce_1 = require("../engine/coerce");
|
|
5
|
+
const items_1 = require("../engine/items");
|
|
6
|
+
const srd_1 = require("../data/srd");
|
|
7
|
+
const shared_1 = require("./shared");
|
|
8
|
+
const campaign_items_1 = require("../engine/campaign-items");
|
|
9
|
+
const DEFINE_EXAMPLE = '{"name":"Kesh\'s signet","type":"ring","rarity":"rare","attunement":true,"acBonus":1,"text":"While attuned, you gain a +1 bonus to AC and can speak the name of the ring\'s maker to send a message to them once per day."}';
|
|
10
|
+
exports.magicItemTool = {
|
|
11
|
+
name: 'magic_item',
|
|
12
|
+
description: 'Get what a magic item does, or define one for this campaign. Reading: give "item" a name and you get its type, rarity, whether it needs attunement, its charges, any bonus it gives to armour class, attack rolls, damage or saving throws, and its full rules text. Use the item\'s full name: a partial name that matches several items comes back asking which one you meant, rather than guessing. Set "item" to "list" to see what is available, with "filter" to narrow by name, type or rarity — "filter": "ring", "filter": "legendary", "filter": "potion". Defining: pass "define" as a JSON object to add or replace an item in this campaign, which is where anything not in the book belongs; a campaign entry always wins over the built-in table. Example define: ' +
|
|
13
|
+
DEFINE_EXAMPLE,
|
|
14
|
+
parameters: [
|
|
15
|
+
{
|
|
16
|
+
name: 'item',
|
|
17
|
+
type: 'string',
|
|
18
|
+
description: 'The item to look up or define, or "list" to see what is available',
|
|
19
|
+
required: true,
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: 'define',
|
|
23
|
+
type: 'string',
|
|
24
|
+
description: `A JSON object defining the item, e.g. ${DEFINE_EXAMPLE}`,
|
|
25
|
+
required: false,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: 'filter',
|
|
29
|
+
type: 'string',
|
|
30
|
+
description: 'With item = "list", show only items matching this name, type or rarity',
|
|
31
|
+
required: false,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
async handler(args, helpers) {
|
|
35
|
+
const room = (0, shared_1.requireRoom)(helpers);
|
|
36
|
+
const wanted = (0, coerce_1.str)(args.item, 'item');
|
|
37
|
+
if (!wanted)
|
|
38
|
+
throw new Error('Name an item, or "list" to see what is available.');
|
|
39
|
+
const existing = room.get(campaign_items_1.ITEMS_ARTIFACT);
|
|
40
|
+
const campaign = (0, campaign_items_1.parseCampaignItems)(existing?.body);
|
|
41
|
+
if (args.define !== undefined && args.define !== '' && args.define !== null) {
|
|
42
|
+
return define(room, wanted, args.define, campaign);
|
|
43
|
+
}
|
|
44
|
+
if (['list', 'all', 'names'].includes(wanted.toLowerCase())) {
|
|
45
|
+
const filter = args.filter ? (0, coerce_1.str)(args.filter, 'filter') : undefined;
|
|
46
|
+
const available = (0, items_1.availableItems)(campaign, filter);
|
|
47
|
+
return {
|
|
48
|
+
campaign: available.campaign,
|
|
49
|
+
builtIn: available.shipped,
|
|
50
|
+
totals: { campaign: available.campaignTotal, builtIn: available.shippedTotal },
|
|
51
|
+
filter: available.filter,
|
|
52
|
+
truncated: available.truncated,
|
|
53
|
+
note: available.truncated
|
|
54
|
+
? 'Only the first names are shown. Narrow with the "filter" parameter, which matches name, type and rarity — e.g. filter: "wand" or filter: "legendary".'
|
|
55
|
+
: 'Anything not listed needs defining with the "define" parameter. Campaign entries override built-in ones of the same name.',
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const resolved = (0, items_1.resolveItem)(wanted, campaign);
|
|
59
|
+
if (resolved.ambiguous) {
|
|
60
|
+
return {
|
|
61
|
+
found: false,
|
|
62
|
+
item: wanted,
|
|
63
|
+
ambiguous: resolved.ambiguous,
|
|
64
|
+
message: `"${wanted}" matches ${resolved.ambiguous.length} items. Ask again with the full name.`,
|
|
65
|
+
note: 'Do not pick one at random and do not invent what it does.',
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (!resolved.item) {
|
|
69
|
+
const suggestions = (0, items_1.nearItems)(wanted, campaign);
|
|
70
|
+
const totals = (0, items_1.availableItems)(campaign);
|
|
71
|
+
return {
|
|
72
|
+
found: false,
|
|
73
|
+
item: wanted,
|
|
74
|
+
message: `No magic item called "${wanted}" in this campaign or the built-in table.`,
|
|
75
|
+
didYouMean: suggestions.length > 0 ? suggestions : undefined,
|
|
76
|
+
options: [
|
|
77
|
+
`Define it with the "define" parameter: ${DEFINE_EXAMPLE}`,
|
|
78
|
+
'Ask the campaign designer to write it, if there is one in the room',
|
|
79
|
+
`${totals.shippedTotal} built-in and ${totals.campaignTotal} campaign items are available; list them with item: "list" and a "filter".`,
|
|
80
|
+
],
|
|
81
|
+
note: 'Do not invent what an item does. An invented item is a promise to the players you cannot take back.',
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
found: true,
|
|
86
|
+
item: resolved.item.name,
|
|
87
|
+
source: resolved.source,
|
|
88
|
+
details: compact(resolved.item),
|
|
89
|
+
entry: (0, items_1.describeItem)(resolved.item),
|
|
90
|
+
attribution: resolved.source === 'srd' ? srd_1.SRD_ATTRIBUTION : undefined,
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
function define(room, wanted, raw, campaign) {
|
|
95
|
+
const supplied = (0, coerce_1.jsonObject)(raw, 'define', DEFINE_EXAMPLE);
|
|
96
|
+
const item = (0, campaign_items_1.normalizeItem)(wanted, supplied);
|
|
97
|
+
const key = (0, coerce_1.nameKey)(item.name || wanted);
|
|
98
|
+
const replaced = campaign[key] !== undefined;
|
|
99
|
+
room.update(campaign_items_1.ITEMS_ARTIFACT, (current) => {
|
|
100
|
+
const entries = (0, campaign_items_1.parseCampaignItems)(current?.body);
|
|
101
|
+
entries[key] = item;
|
|
102
|
+
return (0, campaign_items_1.renderCampaignItems)(entries);
|
|
103
|
+
}, { viewers: [room.caller.nickname] });
|
|
104
|
+
return {
|
|
105
|
+
defined: item.name,
|
|
106
|
+
replaced,
|
|
107
|
+
entry: (0, items_1.describeItem)(item),
|
|
108
|
+
note: `Stored in the "${campaign_items_1.ITEMS_ARTIFACT}" artifact. Look it up with magic_item from now on; it overrides any built-in item of the same name.`,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function compact(item) {
|
|
112
|
+
return {
|
|
113
|
+
type: item.subtype ? `${item.type} (${item.subtype})` : item.type,
|
|
114
|
+
rarity: item.rarityNote || item.rarity,
|
|
115
|
+
attunement: item.attunement,
|
|
116
|
+
charges: item.charges,
|
|
117
|
+
acBonus: item.acBonus,
|
|
118
|
+
attackBonus: item.attackBonus,
|
|
119
|
+
damageBonus: item.damageBonus,
|
|
120
|
+
saveBonus: item.saveBonus,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.statBlockTool = void 0;
|
|
4
|
+
const coerce_1 = require("../engine/coerce");
|
|
5
|
+
const dice_1 = require("../engine/dice");
|
|
6
|
+
const bestiary_1 = require("../engine/bestiary");
|
|
7
|
+
const srd_1 = require("../data/srd");
|
|
8
|
+
const coerce_2 = require("../engine/coerce");
|
|
9
|
+
const shared_1 = require("./shared");
|
|
10
|
+
const DEFINE_EXAMPLE = '{"name":"Kesh\'s enforcer","ac":15,"hp":58,"hpDice":"9d8+18","speed":"30 ft.","abil":{"str":17,"dex":14,"con":15,"int":10,"wis":12,"cha":11},"resist":["cold","bludgeoning from nonmagical attacks"],"traits":[{"n":"Brutal Reprisal","text":"When first bloodied, it makes one maul attack as a reaction."}],"multiattack":"Two maul attacks.","attacks":[{"n":"Maul","atk":6,"dmg":"2d6+4","type":"bludgeoning","reach":"5 ft","note":"On a hit the target makes a DC 14 Strength save or is knocked prone."}]}';
|
|
11
|
+
const MAX_INSTANCES = 12;
|
|
12
|
+
exports.statBlockTool = {
|
|
13
|
+
name: 'stat_block',
|
|
14
|
+
description: 'Get a creature\'s statistics, or define one for this campaign. Reading: give "creature" a name and you get armour class, hit points, speed, ability scores, saving throw bonuses, attacks with their bonus and damage dice, traits, non-attack actions such as breath weapons, reactions, legendary actions, and any resistances — everything needed to run it. Use the creature\'s full name: a partial name that matches several creatures comes back asking which one you meant, rather than guessing. Set "creature" to "list" to see what is available, with "filter" to narrow it. Defining: pass "define" as a JSON object to add or replace a creature in this campaign\'s bestiary, which is where anything not built in belongs; a bestiary entry always wins over the built-in table, so you can override one too. "traits", "actions", "reactions" and "legendary.options" are each a list of named paragraphs — [{"n":"Name","text":"What it does."}] — so give every one of them its own entry rather than writing several into one string. "resist", "immune", "vuln" and "condImmune" are lists of words. Set "count" to get individually rolled hit point totals for a group, labelled A, B, C — you track those yourself as the fight runs. Example define: ' +
|
|
15
|
+
DEFINE_EXAMPLE,
|
|
16
|
+
parameters: [
|
|
17
|
+
{
|
|
18
|
+
name: 'creature',
|
|
19
|
+
type: 'string',
|
|
20
|
+
description: 'The creature to look up or define, or "list" to see what is available',
|
|
21
|
+
required: true,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'define',
|
|
25
|
+
type: 'string',
|
|
26
|
+
description: `A JSON object defining the creature, e.g. ${DEFINE_EXAMPLE}`,
|
|
27
|
+
required: false,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'count',
|
|
31
|
+
type: 'number',
|
|
32
|
+
description: 'How many of this creature are present; returns a rolled hit point total for each',
|
|
33
|
+
required: false,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'filter',
|
|
37
|
+
type: 'string',
|
|
38
|
+
description: 'With creature = "list", show only names containing this text, e.g. "giant"',
|
|
39
|
+
required: false,
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
async handler(args, helpers) {
|
|
43
|
+
const room = (0, shared_1.requireRoom)(helpers);
|
|
44
|
+
const creature = (0, coerce_1.str)(args.creature, 'creature');
|
|
45
|
+
if (!creature)
|
|
46
|
+
throw new Error('Name a creature, or "list" to see what is available.');
|
|
47
|
+
const existing = room.get(bestiary_1.BESTIARY_ARTIFACT);
|
|
48
|
+
const campaign = (0, bestiary_1.parseBestiary)(existing?.body);
|
|
49
|
+
if (args.define !== undefined && args.define !== '' && args.define !== null) {
|
|
50
|
+
return define(room, creature, args.define, campaign);
|
|
51
|
+
}
|
|
52
|
+
if (['list', 'all', 'names'].includes(creature.toLowerCase())) {
|
|
53
|
+
const filter = args.filter ? (0, coerce_1.str)(args.filter, 'filter') : undefined;
|
|
54
|
+
const available = (0, bestiary_1.availableMonsters)(campaign, filter);
|
|
55
|
+
return {
|
|
56
|
+
campaign: available.campaign,
|
|
57
|
+
builtIn: available.shipped,
|
|
58
|
+
totals: { campaign: available.campaignTotal, builtIn: available.shippedTotal },
|
|
59
|
+
filter: available.filter,
|
|
60
|
+
truncated: available.truncated,
|
|
61
|
+
note: available.truncated
|
|
62
|
+
? `Only the first names are shown. Narrow with the "filter" parameter, e.g. filter: "giant".`
|
|
63
|
+
: `Anything not listed needs defining with the "define" parameter before it can be run. Campaign entries override built-in ones of the same name.`,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
const resolved = (0, bestiary_1.resolveMonster)(creature, campaign);
|
|
67
|
+
if (resolved.ambiguous) {
|
|
68
|
+
return {
|
|
69
|
+
found: false,
|
|
70
|
+
creature,
|
|
71
|
+
ambiguous: resolved.ambiguous,
|
|
72
|
+
message: `"${creature}" matches ${resolved.ambiguous.length} creatures. Ask again with the full name.`,
|
|
73
|
+
note: 'Do not pick one at random and do not invent the numbers.',
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (!resolved.block) {
|
|
77
|
+
const suggestions = (0, bestiary_1.nearMonsters)(creature, campaign);
|
|
78
|
+
const totals = (0, bestiary_1.availableMonsters)(campaign);
|
|
79
|
+
return {
|
|
80
|
+
found: false,
|
|
81
|
+
creature,
|
|
82
|
+
message: `No statistics for "${creature}" in this campaign's bestiary or the built-in table.`,
|
|
83
|
+
didYouMean: suggestions.length > 0 ? suggestions : undefined,
|
|
84
|
+
options: [
|
|
85
|
+
`Define it with the "define" parameter: ${DEFINE_EXAMPLE}`,
|
|
86
|
+
'Ask the campaign designer to stat it, if there is one in the room',
|
|
87
|
+
`${totals.shippedTotal} built-in and ${totals.campaignTotal} campaign creatures are available; list them with creature: "list" and a "filter".`,
|
|
88
|
+
],
|
|
89
|
+
note: 'Do not invent the numbers. A creature run on made-up statistics corrupts every roll in the fight.',
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
found: true,
|
|
94
|
+
creature: resolved.block.name,
|
|
95
|
+
source: resolved.source,
|
|
96
|
+
block: compact(resolved.block),
|
|
97
|
+
statBlock: (0, bestiary_1.describeMonster)(resolved.block),
|
|
98
|
+
attribution: resolved.source === 'srd' ? srd_1.SRD_ATTRIBUTION : undefined,
|
|
99
|
+
...instanceHitPoints(resolved.block, args.count),
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
function define(room, creature, raw, campaign) {
|
|
104
|
+
const supplied = (0, coerce_1.jsonObject)(raw, 'define', DEFINE_EXAMPLE);
|
|
105
|
+
const block = (0, bestiary_1.normalizeMonster)(creature, supplied);
|
|
106
|
+
const key = (0, coerce_2.nameKey)(block.name || creature);
|
|
107
|
+
const replaced = campaign[key] !== undefined;
|
|
108
|
+
room.update(bestiary_1.BESTIARY_ARTIFACT, (current) => {
|
|
109
|
+
const entries = (0, bestiary_1.parseBestiary)(current?.body);
|
|
110
|
+
entries[key] = block;
|
|
111
|
+
return (0, bestiary_1.renderBestiary)(entries);
|
|
112
|
+
}, { viewers: [room.caller.nickname] });
|
|
113
|
+
return {
|
|
114
|
+
defined: block.name,
|
|
115
|
+
replaced,
|
|
116
|
+
statBlock: (0, bestiary_1.describeMonster)(block),
|
|
117
|
+
note: `Stored in the "${bestiary_1.BESTIARY_ARTIFACT}" artifact. Look it up with stat_block from now on; it overrides any built-in creature of the same name.`,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function instanceHitPoints(block, count) {
|
|
121
|
+
if (count === undefined || count === null || count === '')
|
|
122
|
+
return {};
|
|
123
|
+
const wanted = (0, coerce_1.int)(count, 'count', 1);
|
|
124
|
+
if (wanted < 1)
|
|
125
|
+
return {};
|
|
126
|
+
if (wanted > MAX_INSTANCES) {
|
|
127
|
+
throw new Error(`At most ${MAX_INSTANCES} of one creature per call; ${wanted} were asked for. Run them as two groups.`);
|
|
128
|
+
}
|
|
129
|
+
const labels = 'ABCDEFGHIJKL';
|
|
130
|
+
const instances = [];
|
|
131
|
+
for (let i = 0; i < wanted; i++) {
|
|
132
|
+
const hp = block.hpDice
|
|
133
|
+
? Math.max((0, dice_1.rollOne)(block.hpDice, dice_1.defaultRng).total, 1)
|
|
134
|
+
: block.hp;
|
|
135
|
+
instances.push({ name: `${block.name} ${labels[i]}`, hp });
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
instances,
|
|
139
|
+
instanceNote: 'These totals are not stored anywhere. Track them in your situation line as the fight runs.',
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function compact(block) {
|
|
143
|
+
return {
|
|
144
|
+
ac: block.ac,
|
|
145
|
+
hp: block.hp,
|
|
146
|
+
speed: block.speed,
|
|
147
|
+
abil: block.abil,
|
|
148
|
+
saves: block.saves,
|
|
149
|
+
attacks: block.attacks,
|
|
150
|
+
multiattack: block.multiattack,
|
|
151
|
+
resist: block.resist,
|
|
152
|
+
immune: block.immune,
|
|
153
|
+
vuln: block.vuln,
|
|
154
|
+
condImmune: block.condImmune,
|
|
155
|
+
cr: block.cr,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ToolHelpers, ToolRoomAccess } from '../../../native-tool.types';
|
|
2
|
+
import { MutationResult, Refusal } from '../engine/character';
|
|
3
|
+
import { SheetError, SheetState } from '../engine/sheet';
|
|
4
|
+
export interface RefusalResult {
|
|
5
|
+
applied: false;
|
|
6
|
+
violation: string;
|
|
7
|
+
message: string;
|
|
8
|
+
rule?: string;
|
|
9
|
+
options?: string[];
|
|
10
|
+
state?: Record<string, any>;
|
|
11
|
+
}
|
|
12
|
+
export declare function requireRoom(helpers: ToolHelpers): ToolRoomAccess;
|
|
13
|
+
export interface LoadedSheet {
|
|
14
|
+
artifactName: string;
|
|
15
|
+
characterName: string;
|
|
16
|
+
state: SheetState;
|
|
17
|
+
notes: string;
|
|
18
|
+
warnings: string[];
|
|
19
|
+
}
|
|
20
|
+
export declare function listCharacterNames(room: ToolRoomAccess): string[];
|
|
21
|
+
export declare function loadSheet(room: ToolRoomAccess, name: string): LoadedSheet;
|
|
22
|
+
export declare function mutateSheet(room: ToolRoomAccess, name: string, mutate: (sheet: LoadedSheet) => MutationResult): {
|
|
23
|
+
result: MutationResult;
|
|
24
|
+
sheet: LoadedSheet;
|
|
25
|
+
};
|
|
26
|
+
export declare function writeNewSheet(room: ToolRoomAccess, state: SheetState, notes: string, replace: boolean): string;
|
|
27
|
+
export declare function refreshPartyStatus(room: ToolRoomAccess): string;
|
|
28
|
+
export declare function partyLine(state: SheetState): string;
|
|
29
|
+
export declare function toRefusalResult(refusal: Refusal, state?: SheetState): RefusalResult;
|
|
30
|
+
export declare function liveState(state: SheetState): Record<string, any>;
|
|
31
|
+
export declare function sheetErrorToRefusal(error: SheetError, artifactName: string): RefusalResult;
|
|
32
|
+
export declare function sheetHeadline(state: SheetState): string;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.requireRoom = requireRoom;
|
|
4
|
+
exports.listCharacterNames = listCharacterNames;
|
|
5
|
+
exports.loadSheet = loadSheet;
|
|
6
|
+
exports.mutateSheet = mutateSheet;
|
|
7
|
+
exports.writeNewSheet = writeNewSheet;
|
|
8
|
+
exports.refreshPartyStatus = refreshPartyStatus;
|
|
9
|
+
exports.partyLine = partyLine;
|
|
10
|
+
exports.toRefusalResult = toRefusalResult;
|
|
11
|
+
exports.liveState = liveState;
|
|
12
|
+
exports.sheetErrorToRefusal = sheetErrorToRefusal;
|
|
13
|
+
exports.sheetHeadline = sheetHeadline;
|
|
14
|
+
const coerce_1 = require("../engine/coerce");
|
|
15
|
+
const character_1 = require("../engine/character");
|
|
16
|
+
const sheet_1 = require("../engine/sheet");
|
|
17
|
+
const rules_1 = require("../engine/rules");
|
|
18
|
+
function requireRoom(helpers) {
|
|
19
|
+
if (!helpers.room) {
|
|
20
|
+
throw new Error('This tool needs a room: run it from a room conversation rather than the Tools test panel.');
|
|
21
|
+
}
|
|
22
|
+
return helpers.room;
|
|
23
|
+
}
|
|
24
|
+
function listCharacterNames(room) {
|
|
25
|
+
return room
|
|
26
|
+
.list()
|
|
27
|
+
.filter(sheet_1.isSheetArtifact)
|
|
28
|
+
.map(sheet_1.characterNameFromArtifact);
|
|
29
|
+
}
|
|
30
|
+
function loadSheet(room, name) {
|
|
31
|
+
const known = listCharacterNames(room);
|
|
32
|
+
if (known.length === 0) {
|
|
33
|
+
throw new Error('No character sheets exist in this room yet. Create one with create_sheet first.');
|
|
34
|
+
}
|
|
35
|
+
const matched = (0, coerce_1.matchName)(name, known);
|
|
36
|
+
if (!matched) {
|
|
37
|
+
throw new Error(`No sheet named "${name}". Known sheets: ${known.join(', ')}.`);
|
|
38
|
+
}
|
|
39
|
+
const artifactName = (0, sheet_1.sheetArtifactName)(matched);
|
|
40
|
+
const artifact = room.get(artifactName);
|
|
41
|
+
if (!artifact) {
|
|
42
|
+
throw new Error(`The sheet artifact "${artifactName}" disappeared while being read.`);
|
|
43
|
+
}
|
|
44
|
+
let raw;
|
|
45
|
+
try {
|
|
46
|
+
raw = JSON.parse(extractStateJson(artifact.body));
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
raw = {};
|
|
50
|
+
}
|
|
51
|
+
const state = (0, sheet_1.parseSheet)(artifact.body);
|
|
52
|
+
return {
|
|
53
|
+
artifactName,
|
|
54
|
+
characterName: matched,
|
|
55
|
+
state,
|
|
56
|
+
notes: (0, sheet_1.extractNotes)(artifact.body),
|
|
57
|
+
warnings: (0, sheet_1.collectWarnings)(raw, state),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function extractStateJson(body) {
|
|
61
|
+
const lines = (body || '').split('\n');
|
|
62
|
+
const open = lines.findIndex((line) => line.trim() === '```briyah-state');
|
|
63
|
+
if (open === -1)
|
|
64
|
+
return '{}';
|
|
65
|
+
const close = lines.slice(open + 1).findIndex((line) => line.trim() === '```');
|
|
66
|
+
if (close === -1)
|
|
67
|
+
return '{}';
|
|
68
|
+
return lines.slice(open + 1, open + 1 + close).join('\n');
|
|
69
|
+
}
|
|
70
|
+
function mutateSheet(room, name, mutate) {
|
|
71
|
+
const sheet = loadSheet(room, name);
|
|
72
|
+
let result;
|
|
73
|
+
room.update(sheet.artifactName, () => {
|
|
74
|
+
result = mutate(sheet);
|
|
75
|
+
if ((0, character_1.isRefusal)(result))
|
|
76
|
+
return null;
|
|
77
|
+
const written = result.state;
|
|
78
|
+
written.rev = (sheet.state.rev || 0) + 1;
|
|
79
|
+
return (0, sheet_1.renderSheet)(written, sheet.notes);
|
|
80
|
+
}, {
|
|
81
|
+
viewers: [sheet.state.owner || room.caller.nickname],
|
|
82
|
+
creator: sheet.state.owner,
|
|
83
|
+
transient: true,
|
|
84
|
+
});
|
|
85
|
+
return { result, sheet };
|
|
86
|
+
}
|
|
87
|
+
function writeNewSheet(room, state, notes, replace) {
|
|
88
|
+
const artifactName = (0, sheet_1.sheetArtifactName)(state.name);
|
|
89
|
+
const existing = room.get(artifactName);
|
|
90
|
+
if (existing && !replace) {
|
|
91
|
+
throw new Error(`A sheet for "${state.name}" already exists. Pass replace=true to overwrite it, or use patch_sheet to change specific fields.`);
|
|
92
|
+
}
|
|
93
|
+
const owner = state.owner || room.caller.nickname;
|
|
94
|
+
room.put(artifactName, (0, sheet_1.renderSheet)(state, notes), {
|
|
95
|
+
viewers: [owner],
|
|
96
|
+
creator: owner,
|
|
97
|
+
transient: true,
|
|
98
|
+
});
|
|
99
|
+
return artifactName;
|
|
100
|
+
}
|
|
101
|
+
function refreshPartyStatus(room) {
|
|
102
|
+
const names = listCharacterNames(room);
|
|
103
|
+
if (names.length === 0)
|
|
104
|
+
return '';
|
|
105
|
+
const lines = [];
|
|
106
|
+
for (const name of names) {
|
|
107
|
+
const artifact = room.get((0, sheet_1.sheetArtifactName)(name));
|
|
108
|
+
if (!artifact)
|
|
109
|
+
continue;
|
|
110
|
+
try {
|
|
111
|
+
lines.push(partyLine((0, sheet_1.parseSheet)(artifact.body)));
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
lines.push(`- ${name}: sheet unreadable`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const body = ['# Party Status', '', ...lines, ''].join('\n');
|
|
118
|
+
room.update(sheet_1.PARTY_STATUS_ARTIFACT, () => body, {
|
|
119
|
+
viewers: room.agentNicknames.filter((n) => n !== room.caller.nickname || !room.caller.isLeader),
|
|
120
|
+
transient: true,
|
|
121
|
+
});
|
|
122
|
+
return body;
|
|
123
|
+
}
|
|
124
|
+
function partyLine(state) {
|
|
125
|
+
const parts = [`${state.hp.cur}/${(0, rules_1.effectiveMaxHp)(state)} HP`];
|
|
126
|
+
if (state.hp.temp > 0)
|
|
127
|
+
parts.push(`+${state.hp.temp} temp`);
|
|
128
|
+
parts.push(`AC ${state.ac}`);
|
|
129
|
+
const movement = (0, rules_1.effectiveSpeed)(state);
|
|
130
|
+
if (movement.speed !== state.speed)
|
|
131
|
+
parts.push(`speed ${movement.speed} ft`);
|
|
132
|
+
if (state.cond.length > 0)
|
|
133
|
+
parts.push(state.cond.map((c) => c.n).join('/'));
|
|
134
|
+
if (state.exh > 0)
|
|
135
|
+
parts.push(`exhaustion ${state.exh}`);
|
|
136
|
+
if (state.hp.cur === 0) {
|
|
137
|
+
parts.push(state.deathSaves.f >= 3
|
|
138
|
+
? 'dead'
|
|
139
|
+
: state.stable
|
|
140
|
+
? 'stable'
|
|
141
|
+
: `dying ${state.deathSaves.s}s/${state.deathSaves.f}f`);
|
|
142
|
+
}
|
|
143
|
+
return `- ${state.name} (level ${(0, rules_1.totalLevel)(state)}): ${parts.join(', ')}`;
|
|
144
|
+
}
|
|
145
|
+
function toRefusalResult(refusal, state) {
|
|
146
|
+
const result = {
|
|
147
|
+
applied: false,
|
|
148
|
+
violation: refusal.violation,
|
|
149
|
+
message: refusal.message,
|
|
150
|
+
};
|
|
151
|
+
if (refusal.rule)
|
|
152
|
+
result.rule = refusal.rule;
|
|
153
|
+
if (refusal.options && refusal.options.length > 0)
|
|
154
|
+
result.options = refusal.options;
|
|
155
|
+
if (state)
|
|
156
|
+
result.state = liveState(state);
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
function liveState(state) {
|
|
160
|
+
const movement = (0, rules_1.effectiveSpeed)(state);
|
|
161
|
+
const block = {
|
|
162
|
+
hp: `${state.hp.cur}/${(0, rules_1.effectiveMaxHp)(state)}`,
|
|
163
|
+
ac: state.ac,
|
|
164
|
+
};
|
|
165
|
+
if (movement.speed !== state.speed)
|
|
166
|
+
block.speed = `${movement.speed} ft (${movement.reasons.join(', ')})`;
|
|
167
|
+
if (state.hp.temp > 0)
|
|
168
|
+
block.temp = state.hp.temp;
|
|
169
|
+
if (state.cond.length > 0)
|
|
170
|
+
block.conditions = state.cond.map((c) => (c.dur ? `${c.n} (${c.dur})` : c.n));
|
|
171
|
+
if (state.exh > 0)
|
|
172
|
+
block.exhaustion = state.exh;
|
|
173
|
+
if (state.hp.cur === 0) {
|
|
174
|
+
block.dying = state.deathSaves.f >= 3 ? 'dead' : state.stable ? 'stable' : true;
|
|
175
|
+
block.deathSaves = `${state.deathSaves.s} success / ${state.deathSaves.f} failure`;
|
|
176
|
+
}
|
|
177
|
+
const slots = Object.entries(state.slots)
|
|
178
|
+
.filter(([, pool]) => pool.max > 0)
|
|
179
|
+
.map(([level, pool]) => [level, `${pool.cur}/${pool.max}`]);
|
|
180
|
+
if (slots.length > 0)
|
|
181
|
+
block.slots = Object.fromEntries(slots);
|
|
182
|
+
const hitDice = Object.entries(state.hd).map(([die, pool]) => [die, `${pool.cur}/${pool.max}`]);
|
|
183
|
+
if (hitDice.length > 0)
|
|
184
|
+
block.hitDice = Object.fromEntries(hitDice);
|
|
185
|
+
return block;
|
|
186
|
+
}
|
|
187
|
+
function sheetErrorToRefusal(error, artifactName) {
|
|
188
|
+
return {
|
|
189
|
+
applied: false,
|
|
190
|
+
violation: error.violation,
|
|
191
|
+
message: error.message,
|
|
192
|
+
rule: undefined,
|
|
193
|
+
options: [
|
|
194
|
+
`Restore it with patch_sheet, passing a full state object`,
|
|
195
|
+
`Read what survives in "${artifactName}" — the prose summary above the state block often has enough to rebuild from`,
|
|
196
|
+
`Do NOT publish "${artifactName}" by hand — that would destroy what data remains`,
|
|
197
|
+
],
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function sheetHeadline(state) {
|
|
201
|
+
const level = (0, rules_1.totalLevel)(state);
|
|
202
|
+
return `${state.name} — level ${level}, ${state.hp.cur}/${(0, rules_1.effectiveMaxHp)(state)} HP, AC ${state.ac}, proficiency ${(0, sheet_1.signed)((0, rules_1.proficiencyBonus)(state))}`;
|
|
203
|
+
}
|