briyah 2.0.1 → 2.0.3
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/LICENSE +216 -0
- package/README.md +19 -10
- package/data/common/config/markup +1 -1
- package/data/common/config/model_prices.json +46369 -46361
- package/data/common/config/rpg_models.json +60 -0
- package/data/common/prompts/narrator/create_chapter.prompt +12 -1
- package/data/common/prompts/pdf_converter/convert_pdf_page.prompt +8 -1
- package/data/common/prompts/perceive.prompt +287 -291
- package/data/packs/dnd5e/agents/player.json +11 -11
- package/data/packs/dnd5e/artifacts/background-acolyte.md +66 -0
- package/data/packs/dnd5e/artifacts/character_creator-basics.md +31 -13
- package/data/packs/dnd5e/artifacts/class-barbarian.md +4 -1
- package/data/packs/dnd5e/artifacts/class-bard.md +2 -1
- package/data/packs/dnd5e/artifacts/class-cleric.md +2 -1
- package/data/packs/dnd5e/artifacts/class-druid.md +3 -1
- package/data/packs/dnd5e/artifacts/class-fighter.md +3 -1
- package/data/packs/dnd5e/artifacts/class-monk.md +2 -1
- package/data/packs/dnd5e/artifacts/class-paladin.md +2 -1
- package/data/packs/dnd5e/artifacts/class-ranger.md +3 -1
- package/data/packs/dnd5e/artifacts/class-rogue.md +3 -1
- package/data/packs/dnd5e/artifacts/class-sorcerer.md +2 -1
- package/data/packs/dnd5e/artifacts/class-warlock.md +3 -1
- package/data/packs/dnd5e/artifacts/class-wizard.md +2 -1
- package/data/packs/dnd5e/artifacts/manifest.json +6 -0
- package/data/packs/dnd5e/pack.json +1 -1
- package/data/packs/dnd5e/prompts/battle_master/perceive.prompt +491 -378
- package/data/packs/dnd5e/prompts/campaign_designer/perceive.prompt +24 -7
- package/data/packs/dnd5e/prompts/character_creator/defaults_config.json +21 -31
- package/data/packs/dnd5e/prompts/character_creator/perceive.prompt +236 -99
- package/data/packs/dnd5e/prompts/dnd_player/defaults_config.json +5 -5
- package/data/packs/dnd5e/prompts/dnd_player/perceive.prompt +28 -10
- package/data/packs/dnd5e/prompts/dnd_room_moderator/defaults_config.json +9 -9
- package/data/packs/dnd5e/prompts/dnd_room_moderator/moderate.prompt +13 -10
- package/data/packs/dnd5e/prompts/dungeon_master/defaults_config.json +32 -30
- package/data/packs/dnd5e/prompts/dungeon_master/perceive.prompt +794 -764
- package/data/packs/dnd5e/rooms/campaign.json +15 -0
- package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +3 -0
- package/dist-sdk/server/src/ai/LLM/anthropic.service.js +40 -11
- 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 +16 -0
- package/dist-sdk/server/src/ai/LLM/deepseek.service.js +5 -3
- package/dist-sdk/server/src/ai/agent-store.service.js +1 -1
- package/dist-sdk/server/src/ai/artifact.service.d.ts +2 -0
- package/dist-sdk/server/src/ai/artifact.service.js +6 -0
- package/dist-sdk/server/src/ai/pack-artifacts.d.ts +2 -0
- package/dist-sdk/server/src/ai/pack-artifacts.js +65 -8
- package/dist-sdk/server/src/app/user-service-factory.js +6 -1
- package/dist-sdk/server/src/app/user-service-manager.js +1 -1
- package/dist-sdk/server/src/app.controller.d.ts +9 -1
- package/dist-sdk/server/src/app.controller.js +123 -12
- package/dist-sdk/server/src/app.service.d.ts +24 -2
- package/dist-sdk/server/src/app.service.js +123 -109
- package/dist-sdk/server/src/auth/auth.controller.js +4 -0
- package/dist-sdk/server/src/auth/auth.service.d.ts +2 -1
- package/dist-sdk/server/src/auth/dto/phone-login.dto.d.ts +2 -1
- package/dist-sdk/server/src/documents/pdf-conversion.d.ts +43 -0
- package/dist-sdk/server/src/documents/pdf-conversion.js +175 -0
- package/dist-sdk/server/src/room/nickname.d.ts +1 -0
- package/dist-sdk/server/src/room/nickname.js +15 -0
- package/dist-sdk/server/src/room/room-store.service.d.ts +1 -0
- package/dist-sdk/server/src/room/room-store.service.js +9 -1
- package/dist-sdk/server/src/room/room.d.ts +43 -3
- package/dist-sdk/server/src/room/room.js +317 -35
- package/dist-sdk/server/src/rpg/rpg-models.d.ts +9 -0
- package/dist-sdk/server/src/rpg/rpg-models.js +128 -0
- package/dist-sdk/server/src/rpg/rpg-roster.d.ts +8 -0
- package/dist-sdk/server/src/rpg/rpg-roster.js +34 -0
- package/dist-sdk/server/src/rpg/rpg.service.d.ts +29 -0
- package/dist-sdk/server/src/rpg/rpg.service.js +199 -0
- package/dist-sdk/server/src/sdk/index.d.ts +4 -2
- package/dist-sdk/server/src/sdk/index.js +6 -1
- package/dist-sdk/server/src/story/story.service.d.ts +2 -1
- package/dist-sdk/server/src/story/story.service.js +42 -4
- package/dist-sdk/server/src/tools/core/index.d.ts +3 -0
- package/dist-sdk/server/src/tools/core/index.js +9 -0
- package/dist-sdk/server/src/tools/core/rename.tool.d.ts +2 -0
- package/dist-sdk/server/src/tools/core/rename.tool.js +61 -0
- package/dist-sdk/server/src/tools/native-tool.types.d.ts +15 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.d.ts +0 -21
- package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.js +1 -56
- package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.d.ts +10 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.js +67 -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.js +7 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.js +4 -3
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.d.ts +6 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.js +92 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.d.ts +32 -5
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.js +177 -28
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.d.ts +1 -13
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.js +15 -145
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.d.ts +7 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.js +11 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.d.ts +5 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.js +45 -2
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.js +3 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.d.ts +21 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.js +45 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.js +6 -4
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +56 -4
- package/dist-sdk/server/src/tools/packs/dnd5e/index.js +3 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.js +117 -15
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.d.ts +2 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.js +96 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.js +40 -3
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.js +36 -27
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.js +7 -4
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +15 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +73 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +49 -13
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.js +68 -2
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.js +119 -14
- package/dist-sdk/server/src/tools/packs/index.d.ts +2 -0
- package/dist-sdk/server/src/tools/packs/index.js +16 -5
- package/dist-sdk/server/src/tools/shared/coerce.d.ts +13 -0
- package/dist-sdk/server/src/tools/shared/coerce.js +147 -0
- package/dist-sdk/server/src/tools/tool-execution.service.d.ts +3 -2
- package/dist-sdk/server/src/tools/tool-execution.service.js +4 -1
- package/dist-sdk/shared/types/app.types.d.ts +63 -0
- package/dist-sdk/shared/types/app.types.js +2 -1
- 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 +73 -73
- package/docs/classes/Briyah.html +16 -16
- package/docs/classes/BriyahConfigService.html +7 -7
- package/docs/classes/NativeToolRegistry.html +10 -10
- package/docs/classes/PackInstantiationService.html +7 -7
- package/docs/classes/PackService.html +13 -13
- package/docs/classes/Room.html +216 -95
- package/docs/classes/RoomMessage.html +22 -22
- package/docs/enums/MessageAction.html +18 -18
- package/docs/functions/availableToolPacks.html +5 -5
- package/docs/functions/buildMarkdown.html +54 -0
- package/docs/functions/dnd5eTools.html +4 -4
- package/docs/functions/installToolPacks.html +8 -5
- package/docs/functions/pageMarker.html +45 -0
- package/docs/functions/registerToolPacks.html +4 -4
- package/docs/functions/splitMarkdownIntoPages.html +51 -0
- package/docs/functions/stripWrappingFence.html +52 -0
- package/docs/hierarchy.html +13 -9
- package/docs/index.html +11 -8
- package/docs/interfaces/AgentCreationOptions.html +12 -12
- package/docs/interfaces/AgentInfo.html +30 -30
- package/docs/interfaces/AgentMessagesResponse.html +8 -8
- package/docs/interfaces/AppService.html +276 -198
- package/docs/interfaces/Artifact.html +9 -9
- package/docs/interfaces/ArtifactMetadata.html +13 -13
- package/docs/interfaces/ArtifactWriteOptions.html +7 -7
- package/docs/interfaces/AttachDocumentResponse.html +6 -6
- package/docs/interfaces/BriyahConfigOptions.html +12 -12
- package/docs/interfaces/ChapterInfo.html +6 -6
- package/docs/interfaces/Character.html +10 -10
- package/docs/interfaces/ConversionAgent.html +78 -0
- package/docs/interfaces/CreateAgentResponse.html +5 -5
- package/docs/interfaces/CreateRoomResponse.html +6 -6
- package/docs/interfaces/CreateStoryResponse.html +5 -5
- package/docs/interfaces/FileList.html +5 -5
- package/docs/interfaces/FileMetadata.html +10 -10
- package/docs/interfaces/IConfigService.html +5 -5
- package/docs/interfaces/InstantiateModels.html +6 -6
- package/docs/interfaces/InstantiateRoomResult.html +7 -7
- package/docs/interfaces/LoadedPack.html +16 -16
- package/docs/interfaces/LoggingOptions.html +9 -9
- package/docs/interfaces/Message.html +9 -9
- package/docs/interfaces/ModelChoice.html +7 -7
- package/docs/interfaces/ModelInfo.html +8 -8
- package/docs/interfaces/NativeToolDefinition.html +10 -10
- package/docs/interfaces/PackAgentTemplate.html +9 -9
- package/docs/interfaces/PackRoomTemplate.html +11 -11
- package/docs/interfaces/PackView.html +20 -20
- package/docs/interfaces/PdfConversionOptions.html +102 -0
- package/docs/interfaces/PdfConversionResult.html +97 -0
- package/docs/interfaces/PdfMarkdownOptions.html +198 -0
- package/docs/interfaces/PdfMarkdownResult.html +106 -0
- package/docs/interfaces/PdfPageMarkdown.html +94 -0
- package/docs/interfaces/PreparedPromptResponse.html +6 -6
- package/docs/interfaces/ProcessTextResponse.html +10 -10
- package/docs/interfaces/PromptFile.html +7 -7
- package/docs/interfaces/PromptFileContent.html +8 -8
- package/docs/interfaces/PromptFilesResponse.html +5 -5
- package/docs/interfaces/PromptFolder.html +8 -8
- package/docs/interfaces/PromptFolderDefaults.html +19 -19
- package/docs/interfaces/PromptFolderDefaultsResponse.html +7 -7
- package/docs/interfaces/PromptFoldersResponse.html +5 -5
- package/docs/interfaces/RoomDetails.html +19 -19
- package/docs/interfaces/RoomErrorUpdate.html +8 -8
- package/docs/interfaces/RoomInfo.html +10 -10
- package/docs/interfaces/RoomMessageUpdate.html +13 -13
- package/docs/interfaces/RoomMessagesResponse.html +6 -6
- package/docs/interfaces/SendMessageResult.html +6 -6
- package/docs/interfaces/StoryErrorEvent.html +8 -8
- package/docs/interfaces/StoryIdea.html +8 -8
- package/docs/interfaces/StoryInfo.html +28 -28
- package/docs/interfaces/StoryIntroduceCharacterEvent.html +7 -7
- package/docs/interfaces/StoryProgressChapterEvent.html +6 -6
- package/docs/interfaces/StoryState.html +12 -12
- package/docs/interfaces/StoryStateEvent.html +7 -7
- package/docs/interfaces/ToolArtifact.html +9 -9
- package/docs/interfaces/ToolCaller.html +7 -7
- package/docs/interfaces/ToolDefinition.html +9 -9
- package/docs/interfaces/ToolHelpers.html +17 -8
- package/docs/interfaces/ToolPackDocuments.html +100 -0
- package/docs/interfaces/ToolParameter.html +8 -8
- package/docs/interfaces/ToolRoomAccess.html +49 -16
- package/docs/interfaces/ToolSummary.html +8 -8
- package/docs/interfaces/ToolsResponse.html +7 -7
- package/docs/interfaces/Transaction.html +13 -13
- package/docs/interfaces/TransactionHistoryResponse.html +6 -6
- package/docs/modules.html +8 -8
- package/docs/types/PackOrigin.html +4 -4
- package/docs/types/PromptScope.html +4 -4
- package/docs/types/RoomTurnMode.html +4 -4
- package/docs/types/RoomUpdate.html +4 -4
- package/docs/types/RosterOverrides.html +4 -4
- package/docs/types/ToolContext.html +4 -4
- package/docs/types/ToolRunResult.html +4 -4
- package/package.json +32 -3
- package/src/tools/packs/dnd5e/README.md +147 -66
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/backgrounds.d.ts +0 -20
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/backgrounds.js +0 -112
|
@@ -5,21 +5,34 @@ const coerce_1 = require("../engine/coerce");
|
|
|
5
5
|
const encounter_1 = require("../engine/encounter");
|
|
6
6
|
const sheet_1 = require("../engine/sheet");
|
|
7
7
|
const shared_1 = require("./shared");
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
8
|
+
function readOutcome(room, state) {
|
|
9
|
+
return state.order.map((combatant) => {
|
|
10
|
+
let sheet;
|
|
11
|
+
try {
|
|
12
|
+
sheet = (0, shared_1.loadSheet)(room, combatant.name).state;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return { name: combatant.name, hitPoints: '—', status: 'unknown' };
|
|
16
|
+
}
|
|
17
|
+
const outcome = {
|
|
18
|
+
name: sheet.name,
|
|
19
|
+
hitPoints: `${sheet.hp.cur}/${sheet.hp.max}`,
|
|
20
|
+
status: describeStanding(sheet),
|
|
21
|
+
};
|
|
22
|
+
if (outcome.status === 'dying') {
|
|
23
|
+
outcome.deathSaves = `${sheet.deathSaves.s} success / ${sheet.deathSaves.f} failure`;
|
|
24
|
+
}
|
|
25
|
+
if (sheet.cond.length > 0)
|
|
26
|
+
outcome.conditions = sheet.cond.map((c) => c.n);
|
|
27
|
+
return outcome;
|
|
28
|
+
});
|
|
20
29
|
}
|
|
21
|
-
function
|
|
22
|
-
|
|
30
|
+
function describeStanding(sheet) {
|
|
31
|
+
if (sheet.hp.cur > 0)
|
|
32
|
+
return 'standing';
|
|
33
|
+
if (sheet.foe || sheet.deathSaves.f >= 3)
|
|
34
|
+
return 'dead';
|
|
35
|
+
return sheet.stable ? 'stable' : 'dying';
|
|
23
36
|
}
|
|
24
37
|
function describe(room, state) {
|
|
25
38
|
const up = (0, encounter_1.currentCombatant)(state);
|
|
@@ -33,13 +46,13 @@ function describe(room, state) {
|
|
|
33
46
|
initiative: c.init,
|
|
34
47
|
acted: i < state.turn,
|
|
35
48
|
up: i === state.turn,
|
|
36
|
-
down: isDown(room, c) || undefined,
|
|
49
|
+
down: (0, shared_1.isDown)(room, c) || undefined,
|
|
37
50
|
})),
|
|
38
51
|
};
|
|
39
52
|
}
|
|
40
53
|
exports.encounterTool = {
|
|
41
54
|
name: 'encounter',
|
|
42
|
-
description: 'Read or advance the fight in progress. "action" is status (the default — the round, the initiative order, and whose turn it is), next (mark the current combatant done and move to the next, rolling into the next round at the end of the order), remove (take a combatant out of the order entirely), or end (finish the fight and clear its monsters). A dead monster is skipped automatically by "next", so you never call on a corpse; a dying character is not skipped, because their turn is when they roll a death saving throw. Use "next" once per turn instead of re-copying the order into your situation line — the stored order cannot drift, and a re-copied one did.',
|
|
55
|
+
description: 'Read or advance the fight in progress. "action" is status (the default — the round, the initiative order, and whose turn it is), next (mark the current combatant done and move to the next, rolling into the next round at the end of the order), remove (take a combatant out of the order entirely), or end (finish the fight and clear its monsters). A dead monster is skipped automatically by "next", so you never call on a corpse; a dying character is not skipped, because their turn is when they roll a death saving throw. Use "next" once per turn instead of re-copying the order into your situation line — the stored order cannot drift, and a re-copied one did. "end" also returns "outcome": every combatant\'s hit points, conditions and death saves read off their sheets. Report the fight from that and not from memory — it is the difference between a character who is dying and one who is dead, and a report written from memory has got that wrong.',
|
|
43
56
|
parameters: [
|
|
44
57
|
{
|
|
45
58
|
name: 'action',
|
|
@@ -73,12 +86,14 @@ exports.encounterTool = {
|
|
|
73
86
|
throw e;
|
|
74
87
|
}
|
|
75
88
|
if (action === 'end') {
|
|
89
|
+
const outcome = state ? readOutcome(room, state) : undefined;
|
|
76
90
|
const cleared = (0, shared_1.clearFoes)(room);
|
|
77
91
|
room.remove(sheet_1.ENCOUNTER_ARTIFACT);
|
|
78
92
|
return {
|
|
79
93
|
ended: true,
|
|
80
94
|
clearedMonsters: cleared.length > 0 ? cleared : undefined,
|
|
81
|
-
|
|
95
|
+
outcome,
|
|
96
|
+
note: 'The encounter is over. Report the outcome to the room leader and stop. Report it from "outcome" above and not from memory — it is read from the sheets, so a character it calls dying is alive and still rolling death saving throws, whatever was said during the fight.',
|
|
82
97
|
};
|
|
83
98
|
}
|
|
84
99
|
if (!state) {
|
|
@@ -105,16 +120,16 @@ exports.encounterTool = {
|
|
|
105
120
|
options: [`In the order: ${state.order.map((c) => c.name).join(', ')}`],
|
|
106
121
|
};
|
|
107
122
|
}
|
|
108
|
-
writeEncounter(room, state);
|
|
123
|
+
(0, shared_1.writeEncounter)(room, state);
|
|
109
124
|
return { removed: name, ...describe(room, state) };
|
|
110
125
|
}
|
|
111
126
|
if (action !== 'next') {
|
|
112
127
|
throw new Error(`"${action}" is not an action. Use status, next, remove, or end.`);
|
|
113
128
|
}
|
|
114
129
|
const before = state.round;
|
|
115
|
-
const { combatant, skipped } = (0, encounter_1.advanceTurn)(state, (c) => isDown(room, c));
|
|
116
|
-
writeEncounter(room, state);
|
|
117
|
-
const remaining = (0, shared_1.listFoeNames)(room).filter((name) => !isDown(room, { name, init: 0, foe: true }));
|
|
130
|
+
const { combatant, skipped } = (0, encounter_1.advanceTurn)(state, (c) => (0, shared_1.isDown)(room, c));
|
|
131
|
+
(0, shared_1.writeEncounter)(room, state);
|
|
132
|
+
const remaining = (0, shared_1.listFoeNames)(room).filter((name) => !(0, shared_1.isDown)(room, { name, init: 0, foe: true }));
|
|
118
133
|
return {
|
|
119
134
|
...describe(room, state),
|
|
120
135
|
newRound: state.round > before ? state.round : undefined,
|
|
@@ -126,9 +141,3 @@ exports.encounterTool = {
|
|
|
126
141
|
};
|
|
127
142
|
},
|
|
128
143
|
};
|
|
129
|
-
function writeEncounter(room, state) {
|
|
130
|
-
room.update(sheet_1.ENCOUNTER_ARTIFACT, () => (0, encounter_1.renderEncounter)(state, downNames(room, state)), {
|
|
131
|
-
viewers: room.agentNicknames,
|
|
132
|
-
transient: true,
|
|
133
|
-
});
|
|
134
|
-
}
|
|
@@ -11,7 +11,7 @@ const DEFINE_EXAMPLE = '{"name":"Kesh\'s enforcer","ac":15,"hp":58,"hpDice":"9d8
|
|
|
11
11
|
const MAX_INSTANCES = 12;
|
|
12
12
|
exports.statBlockTool = {
|
|
13
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: ' +
|
|
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 by name, kind or size — "filter": "fey", "filter": "undead", "filter": "dragon", "filter": "huge" all work, as does part of a name like "giant". 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
15
|
DEFINE_EXAMPLE,
|
|
16
16
|
parameters: [
|
|
17
17
|
{
|
|
@@ -41,7 +41,7 @@ exports.statBlockTool = {
|
|
|
41
41
|
{
|
|
42
42
|
name: 'filter',
|
|
43
43
|
type: 'string',
|
|
44
|
-
description: 'With creature = "list", show only
|
|
44
|
+
description: 'With creature = "list", show only creatures whose name, kind or size contains this text — "fey", "fiend", "undead", "beast", "huge", or part of a name like "giant"',
|
|
45
45
|
required: false,
|
|
46
46
|
},
|
|
47
47
|
],
|
|
@@ -65,8 +65,11 @@ exports.statBlockTool = {
|
|
|
65
65
|
filter: available.filter,
|
|
66
66
|
truncated: available.truncated,
|
|
67
67
|
note: available.truncated
|
|
68
|
-
? `Only the first names are shown. Narrow with the "filter" parameter, e.g. filter: "giant".`
|
|
69
|
-
: `Anything not listed needs defining with the "define" parameter before it can be run. Campaign entries override built-in ones of the same name
|
|
68
|
+
? `Only the first names are shown. Narrow with the "filter" parameter, which matches name, kind and size — e.g. filter: "giant", filter: "fey", filter: "huge".`
|
|
69
|
+
: `Anything not listed needs defining with the "define" parameter before it can be run. Campaign entries override built-in ones of the same name.` +
|
|
70
|
+
(available.filter
|
|
71
|
+
? ` This is everything matching "${available.filter}" by name, kind or size — try a different word before concluding the table has none.`
|
|
72
|
+
: ''),
|
|
70
73
|
};
|
|
71
74
|
}
|
|
72
75
|
const resolved = (0, bestiary_1.resolveMonster)(creature, campaign);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { ToolHelpers, ToolRoomAccess } from '../../../native-tool.types';
|
|
1
|
+
import { ToolHelpers, ToolPackDocuments, ToolRoomAccess } from '../../../native-tool.types';
|
|
2
|
+
import { GuideKind } from '../engine/guides';
|
|
2
3
|
import { MutationResult, Refusal } from '../engine/character';
|
|
4
|
+
import { Combatant, EncounterState } from '../engine/encounter';
|
|
3
5
|
import { SheetError, SheetState } from '../engine/sheet';
|
|
4
6
|
export interface RefusalResult {
|
|
5
7
|
applied: false;
|
|
@@ -10,6 +12,7 @@ export interface RefusalResult {
|
|
|
10
12
|
state?: Record<string, any>;
|
|
11
13
|
}
|
|
12
14
|
export declare function requireRoom(helpers: ToolHelpers): ToolRoomAccess;
|
|
15
|
+
export declare function requirePackDocuments(helpers: ToolHelpers): ToolPackDocuments;
|
|
13
16
|
export interface LoadedSheet {
|
|
14
17
|
artifactName: string;
|
|
15
18
|
characterName: string;
|
|
@@ -19,6 +22,10 @@ export interface LoadedSheet {
|
|
|
19
22
|
}
|
|
20
23
|
export declare function listCharacterNames(room: ToolRoomAccess): string[];
|
|
21
24
|
export declare function listFoeNames(room: ToolRoomAccess): string[];
|
|
25
|
+
export declare function isDown(room: ToolRoomAccess, combatant: Combatant): boolean;
|
|
26
|
+
export declare function downNames(room: ToolRoomAccess, state: EncounterState): string[];
|
|
27
|
+
export declare function readEncounter(room: ToolRoomAccess): EncounterState | null;
|
|
28
|
+
export declare function writeEncounter(room: ToolRoomAccess, state: EncounterState): void;
|
|
22
29
|
export declare function clearFoes(room: ToolRoomAccess, keep?: string[]): string[];
|
|
23
30
|
export declare function loadSheet(room: ToolRoomAccess, name: string): LoadedSheet;
|
|
24
31
|
export declare function mutateSheet(room: ToolRoomAccess, name: string, mutate: (sheet: LoadedSheet) => MutationResult): {
|
|
@@ -27,6 +34,13 @@ export declare function mutateSheet(room: ToolRoomAccess, name: string, mutate:
|
|
|
27
34
|
};
|
|
28
35
|
export declare function writeNewSheet(room: ToolRoomAccess, state: SheetState, notes: string, replace: boolean): string;
|
|
29
36
|
export declare function refreshPartyStatus(room: ToolRoomAccess): string;
|
|
37
|
+
export interface GuideShare {
|
|
38
|
+
artifactName: string;
|
|
39
|
+
viewers: string[];
|
|
40
|
+
unknown: string[];
|
|
41
|
+
created: boolean;
|
|
42
|
+
}
|
|
43
|
+
export declare function shareGuide(room: ToolRoomAccess, kind: GuideKind, name: string, body: string, players: readonly string[]): GuideShare;
|
|
30
44
|
export declare function partyLine(state: SheetState): string;
|
|
31
45
|
export declare function toRefusalResult(refusal: Refusal, state?: SheetState): RefusalResult;
|
|
32
46
|
export declare function liveState(state: SheetState): Record<string, any>;
|
|
@@ -1,20 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.requireRoom = requireRoom;
|
|
4
|
+
exports.requirePackDocuments = requirePackDocuments;
|
|
4
5
|
exports.listCharacterNames = listCharacterNames;
|
|
5
6
|
exports.listFoeNames = listFoeNames;
|
|
7
|
+
exports.isDown = isDown;
|
|
8
|
+
exports.downNames = downNames;
|
|
9
|
+
exports.readEncounter = readEncounter;
|
|
10
|
+
exports.writeEncounter = writeEncounter;
|
|
6
11
|
exports.clearFoes = clearFoes;
|
|
7
12
|
exports.loadSheet = loadSheet;
|
|
8
13
|
exports.mutateSheet = mutateSheet;
|
|
9
14
|
exports.writeNewSheet = writeNewSheet;
|
|
10
15
|
exports.refreshPartyStatus = refreshPartyStatus;
|
|
16
|
+
exports.shareGuide = shareGuide;
|
|
11
17
|
exports.partyLine = partyLine;
|
|
12
18
|
exports.toRefusalResult = toRefusalResult;
|
|
13
19
|
exports.liveState = liveState;
|
|
14
20
|
exports.sheetErrorToRefusal = sheetErrorToRefusal;
|
|
15
21
|
exports.sheetHeadline = sheetHeadline;
|
|
22
|
+
const guides_1 = require("../engine/guides");
|
|
16
23
|
const coerce_1 = require("../engine/coerce");
|
|
17
24
|
const character_1 = require("../engine/character");
|
|
25
|
+
const encounter_1 = require("../engine/encounter");
|
|
18
26
|
const sheet_1 = require("../engine/sheet");
|
|
19
27
|
const rules_1 = require("../engine/rules");
|
|
20
28
|
function requireRoom(helpers) {
|
|
@@ -23,6 +31,12 @@ function requireRoom(helpers) {
|
|
|
23
31
|
}
|
|
24
32
|
return helpers.room;
|
|
25
33
|
}
|
|
34
|
+
function requirePackDocuments(helpers) {
|
|
35
|
+
if (!helpers.packDocuments) {
|
|
36
|
+
throw new Error('This tool needs to read the pack\'s documents, and this deployment provides no access to them.');
|
|
37
|
+
}
|
|
38
|
+
return helpers.packDocuments;
|
|
39
|
+
}
|
|
26
40
|
function listCharacterNames(room) {
|
|
27
41
|
return room
|
|
28
42
|
.list()
|
|
@@ -32,6 +46,36 @@ function listCharacterNames(room) {
|
|
|
32
46
|
function listFoeNames(room) {
|
|
33
47
|
return room.list().filter(sheet_1.isFoeArtifact).map(sheet_1.foeNameFromArtifact);
|
|
34
48
|
}
|
|
49
|
+
function isDown(room, combatant) {
|
|
50
|
+
if (!combatant.foe)
|
|
51
|
+
return false;
|
|
52
|
+
const artifact = room.get((0, sheet_1.foeArtifactName)(combatant.name));
|
|
53
|
+
if (!artifact)
|
|
54
|
+
return true;
|
|
55
|
+
try {
|
|
56
|
+
return (0, sheet_1.parseSheet)(artifact.body).hp.cur <= 0;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function downNames(room, state) {
|
|
63
|
+
return state.order.filter((c) => isDown(room, c)).map((c) => c.name);
|
|
64
|
+
}
|
|
65
|
+
function readEncounter(room) {
|
|
66
|
+
try {
|
|
67
|
+
return (0, encounter_1.parseEncounter)(room.get(sheet_1.ENCOUNTER_ARTIFACT)?.body);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function writeEncounter(room, state) {
|
|
74
|
+
room.update(sheet_1.ENCOUNTER_ARTIFACT, () => (0, encounter_1.renderEncounter)(state, downNames(room, state)), {
|
|
75
|
+
viewers: room.agentNicknames,
|
|
76
|
+
transient: true,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
35
79
|
function clearFoes(room, keep = []) {
|
|
36
80
|
const kept = new Set(keep.map((name) => (0, coerce_1.nameKey)(name)));
|
|
37
81
|
const removed = listFoeNames(room).filter((name) => !kept.has((0, coerce_1.nameKey)(name)));
|
|
@@ -99,6 +143,9 @@ function mutateSheet(room, name, mutate) {
|
|
|
99
143
|
creator: sheet.state.owner,
|
|
100
144
|
transient: true,
|
|
101
145
|
});
|
|
146
|
+
if (!(0, character_1.isRefusal)(result) && !result.state.foe) {
|
|
147
|
+
refreshPartyStatus(room);
|
|
148
|
+
}
|
|
102
149
|
return { result, sheet };
|
|
103
150
|
}
|
|
104
151
|
function writeNewSheet(room, state, notes, replace) {
|
|
@@ -138,6 +185,29 @@ function refreshPartyStatus(room) {
|
|
|
138
185
|
});
|
|
139
186
|
return body;
|
|
140
187
|
}
|
|
188
|
+
function shareGuide(room, kind, name, body, players) {
|
|
189
|
+
const artifactName = (0, guides_1.guideArtifactName)(kind, name);
|
|
190
|
+
const unknown = [];
|
|
191
|
+
const wanted = new Set([room.caller.nickname]);
|
|
192
|
+
for (const player of players) {
|
|
193
|
+
const matched = (0, coerce_1.matchName)(player, room.agentNicknames);
|
|
194
|
+
if (matched)
|
|
195
|
+
wanted.add(matched);
|
|
196
|
+
else
|
|
197
|
+
unknown.push(player);
|
|
198
|
+
}
|
|
199
|
+
const existing = room.get(artifactName);
|
|
200
|
+
for (const viewer of existing?.viewers || [])
|
|
201
|
+
wanted.add(viewer);
|
|
202
|
+
const viewers = room.agentNicknames.filter((nickname) => wanted.has(nickname));
|
|
203
|
+
const unchanged = existing?.body === body &&
|
|
204
|
+
existing.viewers.length === viewers.length &&
|
|
205
|
+
viewers.every((nickname) => existing.viewers.includes(nickname));
|
|
206
|
+
if (!unchanged) {
|
|
207
|
+
room.update(artifactName, () => body, { viewers });
|
|
208
|
+
}
|
|
209
|
+
return { artifactName, viewers, unknown, created: !existing };
|
|
210
|
+
}
|
|
141
211
|
function partyLine(state) {
|
|
142
212
|
const parts = [`${state.hp.cur}/${(0, rules_1.effectiveMaxHp)(state)} HP`];
|
|
143
213
|
if (state.hp.temp > 0)
|
|
@@ -150,6 +220,9 @@ function partyLine(state) {
|
|
|
150
220
|
parts.push(state.cond.map((c) => c.n).join('/'));
|
|
151
221
|
if (state.exh > 0)
|
|
152
222
|
parts.push(`exhaustion ${state.exh}`);
|
|
223
|
+
for (const boon of state.boons || []) {
|
|
224
|
+
parts.push(`holding ${boon.n} ${boon.die}${boon.from ? ` from ${boon.from}` : ''}`);
|
|
225
|
+
}
|
|
153
226
|
if (state.hp.cur === 0) {
|
|
154
227
|
parts.push(state.deathSaves.f >= 3
|
|
155
228
|
? 'dead'
|
|
@@ -35,21 +35,21 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.patchSheetTool = exports.readSheetTool = exports.createSheetTool = void 0;
|
|
37
37
|
const coerce_1 = require("../engine/coerce");
|
|
38
|
+
const guides_1 = require("../engine/guides");
|
|
38
39
|
const character_1 = require("../engine/character");
|
|
39
40
|
const rules = __importStar(require("../engine/rules"));
|
|
40
41
|
const races_1 = require("../engine/races");
|
|
41
|
-
const backgrounds_1 = require("../engine/backgrounds");
|
|
42
42
|
const encumbrance_1 = require("../engine/encumbrance");
|
|
43
43
|
const feats_1 = require("../engine/feats");
|
|
44
44
|
const spells_1 = require("../engine/spells");
|
|
45
45
|
const srd_1 = require("../data/srd");
|
|
46
46
|
const sheet_1 = require("../engine/sheet");
|
|
47
47
|
const shared_1 = require("./shared");
|
|
48
|
-
const SPEC_EXAMPLE = '{"class":"Ranger","subclass":"Hunter","level":3,"race":"Wood Elf","background":"Outlander","alignment":"NG","abilities":{"str":10,"dex":16,"con":14,"int":11,"wis":15,"cha":9},"skills":["perception","stealth","survival"],"equipment":["studded leather","longbow","arrows x40"],"attacks":[{"n":"Longbow","atk":5,"dmg":"1d8+3","type":"piercing"}],"spells":["hunter\'s mark"],"backstory":"Raised by the Emberwood circle."}';
|
|
48
|
+
const SPEC_EXAMPLE = '{"class":"Ranger","subclass":"Hunter","level":3,"race":"Wood Elf","background":"Outlander","alignment":"NG","abilities":{"str":10,"dex":16,"con":14,"int":11,"wis":15,"cha":9},"skills":["perception","stealth","survival"],"languages":["Giant"],"equipment":["studded leather","longbow","arrows x40"],"attacks":[{"n":"Longbow","atk":5,"dmg":"1d8+3","type":"piercing"}],"spells":["hunter\'s mark"],"backstory":"Raised by the Emberwood circle."}';
|
|
49
49
|
const SET_EXAMPLE = '{"ac":18,"hp.max":32,"speed":25,"resist":["fire"],"uses.channel_divinity.cur":0}';
|
|
50
50
|
exports.createSheetTool = {
|
|
51
51
|
name: 'create_sheet',
|
|
52
|
-
description: 'Create a character sheet. "character" is the character\'s name. "spec" is a JSON object describing them; only the class is genuinely required and everything else is derived or defaulted. Hit points, armour class, proficiency bonus, saving throws, skill modifiers, spell slots and hit dice are all computed from the 5e rules, so do not work them out yourself. Put tool proficiencies the player *chose* in "tools", e.g. "tools":["Lute","Drum","Flute"] for a bard — the ones their class, race and background grant outright are added for you, and the result says which choices are still owed. Include a "backstory" string to seed the sheet\'s notes section, which later tool calls never overwrite. "owner" is the nickname of the agent who plays this character — set it, because the sheet is made readable to that agent alone, and because it is how the rest of the table is told who they are: the owning agent\'s public description becomes the character\'s name, race and class, replacing whatever placeholder they were created with. Set "replace" to true to overwrite an existing sheet. Example spec: ' +
|
|
52
|
+
description: 'Create a character sheet. "character" is the character\'s name. "spec" is a JSON object describing them; only the class is genuinely required and everything else is derived or defaulted. Hit points, armour class, proficiency bonus, saving throws, skill modifiers, spell slots and hit dice are all computed from the 5e rules, so do not work them out yourself. Put tool proficiencies the player *chose* in "tools", e.g. "tools":["Lute","Drum","Flute"] for a bard — the ones their class, race and background grant outright are added for you, and the result says which choices are still owed. Put languages the player *chose* in "languages" — a background\'s and the extra one a race lets them pick — since no tool here knows what a background grants; what the race speaks natively is added for you. Include a "backstory" string to seed the sheet\'s notes section, which later tool calls never overwrite. "owner" is the nickname of the agent who plays this character — set it, because the sheet is made readable to that agent alone, and because it is how the rest of the table is told who they are: the owning agent\'s public description becomes the character\'s name, race and class, replacing whatever placeholder they were created with. The class\'s own rules are shared with that agent at the same time, as a "Class: ..." document they read from then on, so a player always knows their own features. Set "replace" to true to overwrite an existing sheet. Example spec: ' +
|
|
53
53
|
SPEC_EXAMPLE,
|
|
54
54
|
parameters: [
|
|
55
55
|
{ name: 'character', type: 'string', description: "The character's name", required: true },
|
|
@@ -81,7 +81,6 @@ exports.createSheetTool = {
|
|
|
81
81
|
const owner = args.owner ? (0, coerce_1.str)(args.owner, 'owner') : undefined;
|
|
82
82
|
const state = (0, character_1.buildCharacter)(name, spec, owner);
|
|
83
83
|
const raceResult = (0, character_1.lastRaceResult)();
|
|
84
|
-
const backgroundResult = (0, character_1.lastBackgroundResult)();
|
|
85
84
|
const classToolResult = (0, character_1.lastClassToolResult)();
|
|
86
85
|
for (const item of state.inv) {
|
|
87
86
|
if (isWorn(item.n))
|
|
@@ -94,11 +93,22 @@ exports.createSheetTool = {
|
|
|
94
93
|
(0, shared_1.refreshPartyStatus)(room);
|
|
95
94
|
const identity = publicIdentity(state);
|
|
96
95
|
const described = state.owner ? room.setDescription(state.owner, identity) : false;
|
|
96
|
+
const renamed = state.owner ? room.renameAgent(state.owner, state.name) : undefined;
|
|
97
|
+
const guides = shareGuidesForCharacter(room, helpers.packDocuments, state);
|
|
97
98
|
return {
|
|
98
99
|
created: artifactName,
|
|
99
100
|
headline: (0, shared_1.sheetHeadline)(state),
|
|
100
|
-
owner: state.owner,
|
|
101
|
+
owner: renamed?.renamed ? renamed.to : state.owner,
|
|
101
102
|
publicIdentity: described ? identity : undefined,
|
|
103
|
+
renamedTo: renamed?.renamed ? renamed.to : undefined,
|
|
104
|
+
renameNote: renamed?.renamed
|
|
105
|
+
? `The table now knows this player as "${renamed.to}". Address them by that name from here on.`
|
|
106
|
+
: renamed?.reason === 'ambiguous'
|
|
107
|
+
? `Their agent could NOT be renamed: "${renamed.to}" would be confused with "${renamed.conflictsWith}". ` +
|
|
108
|
+
`Keep addressing them as "${state.owner}", or ask the player for a character name that does not clash.`
|
|
109
|
+
: undefined,
|
|
110
|
+
classGuides: guides.classes.length > 0 ? guides.classes : undefined,
|
|
111
|
+
classesWithoutRules: guides.missingClasses.length > 0 ? guides.missingClasses : undefined,
|
|
102
112
|
spellsOffList: (() => {
|
|
103
113
|
const off = (0, spells_1.offListSpells)(state, state.spells || []);
|
|
104
114
|
return off.length > 0
|
|
@@ -109,12 +119,11 @@ exports.createSheetTool = {
|
|
|
109
119
|
})(),
|
|
110
120
|
background: state.bg
|
|
111
121
|
? {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
: undefined,
|
|
122
|
+
recorded: state.bg,
|
|
123
|
+
shared: guides.background,
|
|
124
|
+
stillToChoose: [
|
|
125
|
+
`Nothing is granted automatically. Check that ${state.bg}'s two skills are in "skills", any languages it grants in "languages", its gear in "equipment" and its coin in "coin" — read them with rules_lookup topic "${state.bg}" if you have not.`,
|
|
126
|
+
],
|
|
118
127
|
}
|
|
119
128
|
: undefined,
|
|
120
129
|
race: raceResult.race
|
|
@@ -138,6 +147,7 @@ exports.createSheetTool = {
|
|
|
138
147
|
: undefined,
|
|
139
148
|
}
|
|
140
149
|
: undefined,
|
|
150
|
+
languages: state.languages?.length ? state.languages : undefined,
|
|
141
151
|
derived: {
|
|
142
152
|
hitPoints: `${state.hp.cur}/${state.hp.max}`,
|
|
143
153
|
armorClass: `${state.ac} (${rules.computeArmorClass(state).explanation})`,
|
|
@@ -156,6 +166,33 @@ exports.createSheetTool = {
|
|
|
156
166
|
};
|
|
157
167
|
},
|
|
158
168
|
};
|
|
169
|
+
function shareGuidesForCharacter(room, documents, state) {
|
|
170
|
+
const result = { classes: [], missingClasses: [] };
|
|
171
|
+
if (!documents)
|
|
172
|
+
return result;
|
|
173
|
+
const players = state.owner ? [state.owner] : [];
|
|
174
|
+
const share = (kind, wanted) => {
|
|
175
|
+
const guides = (0, guides_1.listGuides)(kind, documents.list(guides_1.DND5E_PACK, kind.prefix));
|
|
176
|
+
const match = (0, guides_1.resolveGuide)(wanted, guides);
|
|
177
|
+
const body = match.guide ? documents.read(guides_1.DND5E_PACK, match.guide.fileName) : null;
|
|
178
|
+
if (!match.guide || !body || !body.trim())
|
|
179
|
+
return undefined;
|
|
180
|
+
const shared = (0, shared_1.shareGuide)(room, kind, match.guide.name, body, players);
|
|
181
|
+
return `${shared.artifactName} — read by ${shared.viewers.join(', ')}`;
|
|
182
|
+
};
|
|
183
|
+
for (const entry of state.class) {
|
|
184
|
+
const wanted = srd_1.CLASSES[entry.c]?.name || entry.c;
|
|
185
|
+
const line = share(guides_1.CLASS_GUIDE, wanted);
|
|
186
|
+
if (line)
|
|
187
|
+
result.classes.push(line);
|
|
188
|
+
else
|
|
189
|
+
result.missingClasses.push(wanted);
|
|
190
|
+
}
|
|
191
|
+
if (state.bg) {
|
|
192
|
+
result.background = share(guides_1.BACKGROUND_GUIDE, state.bg);
|
|
193
|
+
}
|
|
194
|
+
return result;
|
|
195
|
+
}
|
|
159
196
|
function publicIdentity(state) {
|
|
160
197
|
const classes = state.class
|
|
161
198
|
.map((entry) => {
|
|
@@ -240,10 +277,9 @@ exports.readSheetTool = {
|
|
|
240
277
|
};
|
|
241
278
|
}
|
|
242
279
|
if (wants('background') && state.bg) {
|
|
243
|
-
const feature = (0, backgrounds_1.backgroundFeature)(state);
|
|
244
280
|
result.background = {
|
|
245
281
|
name: state.bg,
|
|
246
|
-
|
|
282
|
+
note: `Read what it grants with rules_lookup topic "${state.bg}". Anything recorded for this character is in the notes.`,
|
|
247
283
|
};
|
|
248
284
|
}
|
|
249
285
|
if (wants('race') && state.race) {
|
|
@@ -184,7 +184,7 @@ function findPlanned(plan, name) {
|
|
|
184
184
|
}
|
|
185
185
|
exports.spendTool = {
|
|
186
186
|
name: 'spend',
|
|
187
|
-
description: 'Spend or restore a limited resource on a character sheet. "resource" is slot, hit_die, or the name of a feature or item on the sheet such as favored_foe, "Channel Divinity", or "healer\'s kit". "level" is required when resource is slot and must be 1 to 9. "amount" defaults to 1; a negative amount restores. If the character has no such resource or none remaining, nothing is changed and you are told so along with what they do still have — so you can rely on this tool to enforce the rules rather than tracking counts yourself. Returns the remaining count.',
|
|
187
|
+
description: 'Spend or restore a limited resource on a character sheet. "resource" is slot, hit_die, or the name of a feature or item on the sheet such as favored_foe, "Channel Divinity", or "healer\'s kit". "level" is required when resource is slot and must be 1 to 9. "amount" defaults to 1; a negative amount restores. If the character has no such resource or none remaining, nothing is changed and you are told so along with what they do still have — so you can rely on this tool to enforce the rules rather than tracking counts yourself. Returns the remaining count. Set "target" when the resource hands a die to somebody else — Bardic Inspiration, Bless, Guidance: the giver spends it and the target is recorded as holding the die, so it is offered back when a roll of theirs comes close. To use a held die, call spend on the holder with the boon name and no target. It rolls the die, adds it to the roll that character just made, says whether the total now beats the DC, and rolls the damage itself when the die turns a miss into a hit — so apply the damage with apply_hp and do not roll it again. The roll has to have happened already: a die is added to a d20 after it is rolled, and spending one with nothing to add it to is refused.',
|
|
188
188
|
parameters: [
|
|
189
189
|
{ name: 'character', type: 'string', description: 'Whose resource to spend', required: true },
|
|
190
190
|
{
|
|
@@ -205,6 +205,18 @@ exports.spendTool = {
|
|
|
205
205
|
description: 'How many to spend; negative restores. Defaults to 1.',
|
|
206
206
|
required: false,
|
|
207
207
|
},
|
|
208
|
+
{
|
|
209
|
+
name: 'target',
|
|
210
|
+
type: 'string',
|
|
211
|
+
description: 'Who receives the die, for a resource that hands one to another character',
|
|
212
|
+
required: false,
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
name: 'die',
|
|
216
|
+
type: 'string',
|
|
217
|
+
description: "The die handed over, e.g. d6. Defaults to the Bardic Inspiration die for the giver's level, or d4.",
|
|
218
|
+
required: false,
|
|
219
|
+
},
|
|
208
220
|
],
|
|
209
221
|
async handler(args, helpers) {
|
|
210
222
|
const room = (0, shared_1.requireRoom)(helpers);
|
|
@@ -212,18 +224,72 @@ exports.spendTool = {
|
|
|
212
224
|
const resource = (0, coerce_1.str)(args.resource, 'resource');
|
|
213
225
|
const amount = args.amount !== undefined && args.amount !== '' ? (0, coerce_1.int)(args.amount, 'amount', 1) : 1;
|
|
214
226
|
const level = args.level !== undefined && args.level !== '' ? (0, coerce_1.int)(args.level, 'level') : undefined;
|
|
227
|
+
const target = args.target ? (0, coerce_1.str)(args.target, 'target') : undefined;
|
|
228
|
+
if (!target && holdsBoon(room, character, resource)) {
|
|
229
|
+
const used = (0, shared_1.mutateSheet)(room, character, (sheet) => (0, character_1.spendBoon)(sheet.state, resource));
|
|
230
|
+
if ((0, character_1.isRefusal)(used.result)) {
|
|
231
|
+
return (0, shared_1.toRefusalResult)(used.result.refusal, reloadState(room, character));
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
character: used.result.state.name,
|
|
235
|
+
applied: true,
|
|
236
|
+
summary: used.result.summary,
|
|
237
|
+
details: used.result.details,
|
|
238
|
+
roll: used.result.applied,
|
|
239
|
+
state: (0, shared_1.liveState)(used.result.state),
|
|
240
|
+
};
|
|
241
|
+
}
|
|
215
242
|
const { result } = (0, shared_1.mutateSheet)(room, character, (sheet) => (0, character_1.spendResource)(sheet.state, resource, amount, level));
|
|
216
243
|
if ((0, character_1.isRefusal)(result)) {
|
|
217
244
|
return (0, shared_1.toRefusalResult)(result.refusal, reloadState(room, character));
|
|
218
245
|
}
|
|
246
|
+
let granted;
|
|
247
|
+
if (target && amount > 0) {
|
|
248
|
+
const die = args.die ? (0, coerce_1.str)(args.die, 'die') : boonDie(result.state, resource);
|
|
249
|
+
const grant = (0, shared_1.mutateSheet)(room, target, (sheet) => (0, character_1.grantBoon)(sheet.state, { n: boonName(resource), die, from: result.state.name }));
|
|
250
|
+
if ((0, character_1.isRefusal)(grant.result)) {
|
|
251
|
+
return (0, shared_1.toRefusalResult)(grant.result.refusal, reloadState(room, target));
|
|
252
|
+
}
|
|
253
|
+
granted = grant.result.summary;
|
|
254
|
+
}
|
|
219
255
|
return {
|
|
220
256
|
character: result.state.name,
|
|
221
257
|
applied: true,
|
|
222
|
-
summary: result.summary,
|
|
258
|
+
summary: granted ? `${result.summary} ${granted}` : result.summary,
|
|
259
|
+
details: result.details,
|
|
223
260
|
state: (0, shared_1.liveState)(result.state),
|
|
224
261
|
};
|
|
225
262
|
},
|
|
226
263
|
};
|
|
264
|
+
function holdsBoon(room, character, resource) {
|
|
265
|
+
try {
|
|
266
|
+
const wanted = resource.trim().toLowerCase();
|
|
267
|
+
return ((0, shared_1.loadSheet)(room, character).state.boons || []).some((boon) => boon.n.toLowerCase() === wanted || boon.n.toLowerCase().includes(wanted));
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
function boonDie(giver, resource) {
|
|
274
|
+
if (!resource.trim().toLowerCase().includes('inspiration'))
|
|
275
|
+
return 'd4';
|
|
276
|
+
const bard = giver.class.find((entry) => entry.c === 'bard');
|
|
277
|
+
const level = bard ? Number(bard.lvl) || 1 : 1;
|
|
278
|
+
if (level >= 15)
|
|
279
|
+
return 'd12';
|
|
280
|
+
if (level >= 10)
|
|
281
|
+
return 'd10';
|
|
282
|
+
if (level >= 5)
|
|
283
|
+
return 'd8';
|
|
284
|
+
return 'd6';
|
|
285
|
+
}
|
|
286
|
+
function boonName(resource) {
|
|
287
|
+
return resource
|
|
288
|
+
.trim()
|
|
289
|
+
.split(/\s+/)
|
|
290
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
291
|
+
.join(' ');
|
|
292
|
+
}
|
|
227
293
|
function reloadState(room, character) {
|
|
228
294
|
try {
|
|
229
295
|
return (0, shared_1.loadSheet)(room, character).state;
|
|
@@ -2,5 +2,6 @@ import { NativeToolDefinition } from '../../../native-tool.types';
|
|
|
2
2
|
export declare const conditionsTool: NativeToolDefinition;
|
|
3
3
|
export declare const inventoryTool: NativeToolDefinition;
|
|
4
4
|
export declare const awardXpTool: NativeToolDefinition;
|
|
5
|
+
export declare const awardCoinTool: NativeToolDefinition;
|
|
5
6
|
export declare const levelUpTool: NativeToolDefinition;
|
|
6
7
|
export declare const rulesLookupTool: NativeToolDefinition;
|