briyah 1.3.5 → 1.4.0
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 +689 -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 +3 -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 +6 -4
- 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,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resetBackgroundIndex = resetBackgroundIndex;
|
|
4
|
+
exports.resolveBackground = resolveBackground;
|
|
5
|
+
exports.backgroundNames = backgroundNames;
|
|
6
|
+
exports.applyBackground = applyBackground;
|
|
7
|
+
exports.backgroundFeature = backgroundFeature;
|
|
8
|
+
exports.describeBackground = describeBackground;
|
|
9
|
+
const backgrounds_1 = require("../data/backgrounds");
|
|
10
|
+
const srd_1 = require("../data/srd");
|
|
11
|
+
const coerce_1 = require("./coerce");
|
|
12
|
+
let backgroundIndexCache = null;
|
|
13
|
+
function backgroundIndex() {
|
|
14
|
+
if (!backgroundIndexCache) {
|
|
15
|
+
backgroundIndexCache = new Map();
|
|
16
|
+
for (const background of Object.values(backgrounds_1.BACKGROUNDS)) {
|
|
17
|
+
backgroundIndexCache.set((0, coerce_1.nameKey)(background.name), background);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return backgroundIndexCache;
|
|
21
|
+
}
|
|
22
|
+
function resetBackgroundIndex() {
|
|
23
|
+
backgroundIndexCache = null;
|
|
24
|
+
}
|
|
25
|
+
function resolveBackground(name) {
|
|
26
|
+
const key = (0, coerce_1.nameKey)(name || '');
|
|
27
|
+
if (!key)
|
|
28
|
+
return {};
|
|
29
|
+
const exact = backgroundIndex().get(key);
|
|
30
|
+
if (exact)
|
|
31
|
+
return { background: exact };
|
|
32
|
+
const matches = (0, coerce_1.matchNames)(name, [...backgroundIndex().keys()]);
|
|
33
|
+
if (matches.length === 1)
|
|
34
|
+
return { background: backgroundIndex().get(matches[0]) };
|
|
35
|
+
if (matches.length > 1) {
|
|
36
|
+
return { ambiguous: matches.map((k) => backgroundIndex().get(k).name).sort() };
|
|
37
|
+
}
|
|
38
|
+
return {};
|
|
39
|
+
}
|
|
40
|
+
function backgroundNames() {
|
|
41
|
+
return Object.values(backgrounds_1.BACKGROUNDS).map((background) => background.name).sort();
|
|
42
|
+
}
|
|
43
|
+
function applyBackground(state, withEquipment = true) {
|
|
44
|
+
const { background } = resolveBackground(state.bg || '');
|
|
45
|
+
const result = {
|
|
46
|
+
known: false,
|
|
47
|
+
changes: [],
|
|
48
|
+
outstanding: [],
|
|
49
|
+
equipment: [],
|
|
50
|
+
coin: [],
|
|
51
|
+
};
|
|
52
|
+
if (!background) {
|
|
53
|
+
if (state.bg) {
|
|
54
|
+
result.outstanding.push(`"${state.bg}" is not the one background the SRD carries (${backgroundNames().join(', ')}), so nothing was granted automatically. The SRD's own customization rule allows it: give the two skills in "skills" and the gear in "equipment".`);
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
result.background = background.name;
|
|
59
|
+
result.known = true;
|
|
60
|
+
for (const skill of background.skills) {
|
|
61
|
+
if (!srd_1.SKILL_ABILITY[skill])
|
|
62
|
+
continue;
|
|
63
|
+
if (state.skillProf.includes(skill)) {
|
|
64
|
+
result.outstanding.push(`${skill} was already proficient, so ${background.name} grants a different skill of the player's choice instead`);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
state.skillProf.push(skill);
|
|
68
|
+
result.changes.push(`proficient in ${skill}`);
|
|
69
|
+
}
|
|
70
|
+
if (background.tools?.length) {
|
|
71
|
+
result.changes.push(`tool proficiency: ${background.tools.join(', ')}`);
|
|
72
|
+
}
|
|
73
|
+
if (background.languageChoices) {
|
|
74
|
+
result.outstanding.push(`${background.languageChoices} language${background.languageChoices === 1 ? '' : 's'} of the player's choice`);
|
|
75
|
+
}
|
|
76
|
+
if (withEquipment) {
|
|
77
|
+
result.equipment = [...(background.equipment || [])];
|
|
78
|
+
result.coin = Object.entries(background.coin || {}).map(([denomination, amount]) => `+${amount} ${denomination}`);
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
function backgroundFeature(state) {
|
|
83
|
+
return resolveBackground(state.bg || '').background?.feature;
|
|
84
|
+
}
|
|
85
|
+
function describeBackground(background) {
|
|
86
|
+
const lines = [`## ${background.name}`];
|
|
87
|
+
lines.push(`**Skills:** ${background.skills.join(', ')}`);
|
|
88
|
+
if (background.tools?.length)
|
|
89
|
+
lines.push(`**Tools:** ${background.tools.join(', ')}`);
|
|
90
|
+
if (background.languageChoices) {
|
|
91
|
+
lines.push(`**Languages:** ${background.languageChoices} of your choice`);
|
|
92
|
+
}
|
|
93
|
+
if (background.equipment?.length) {
|
|
94
|
+
const coin = Object.entries(background.coin || {})
|
|
95
|
+
.map(([denomination, amount]) => `${amount} ${denomination}`)
|
|
96
|
+
.join(', ');
|
|
97
|
+
lines.push(`**Equipment:** ${background.equipment.join(', ')}${coin ? `, and ${coin}` : ''}`);
|
|
98
|
+
}
|
|
99
|
+
lines.push('', `**Feature: ${background.feature.n}.** ${background.feature.text}`);
|
|
100
|
+
const suggestions = background.suggestions;
|
|
101
|
+
if (suggestions) {
|
|
102
|
+
lines.push('', '**Suggested characteristics** — read one out rather than inventing:');
|
|
103
|
+
lines.push(`- *Traits:* ${suggestions.traits.join(' / ')}`);
|
|
104
|
+
lines.push(`- *Ideals:* ${suggestions.ideals.join(' / ')}`);
|
|
105
|
+
lines.push(`- *Bonds:* ${suggestions.bonds.join(' / ')}`);
|
|
106
|
+
lines.push(`- *Flaws:* ${suggestions.flaws.join(' / ')}`);
|
|
107
|
+
}
|
|
108
|
+
return lines.join('\n');
|
|
109
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { MonsterBlock } from '../data/monsters';
|
|
2
|
+
export declare const BESTIARY_ARTIFACT = "Bestiary";
|
|
3
|
+
export declare const MONSTER_LIST_CAP = 60;
|
|
4
|
+
export declare const NEAR_MATCH_CAP = 8;
|
|
5
|
+
export type MonsterSource = 'bestiary' | 'srd';
|
|
6
|
+
export interface MonsterLookup {
|
|
7
|
+
block?: MonsterBlock;
|
|
8
|
+
source?: MonsterSource;
|
|
9
|
+
ambiguous?: string[];
|
|
10
|
+
}
|
|
11
|
+
export declare class BestiaryError extends Error {
|
|
12
|
+
readonly violation: string;
|
|
13
|
+
constructor(violation: string, message: string);
|
|
14
|
+
}
|
|
15
|
+
export declare function parseBestiary(body: string | undefined): Record<string, MonsterBlock>;
|
|
16
|
+
export declare function resolveMonster(name: string, campaign: Record<string, MonsterBlock>): MonsterLookup;
|
|
17
|
+
export interface MonsterListing {
|
|
18
|
+
campaign: string[];
|
|
19
|
+
shipped: string[];
|
|
20
|
+
campaignTotal: number;
|
|
21
|
+
shippedTotal: number;
|
|
22
|
+
truncated?: boolean;
|
|
23
|
+
filter?: string;
|
|
24
|
+
}
|
|
25
|
+
export declare function availableMonsters(campaign: Record<string, MonsterBlock>, filter?: string): MonsterListing;
|
|
26
|
+
export declare function nearMonsters(name: string, campaign: Record<string, MonsterBlock>, limit?: number): string[];
|
|
27
|
+
export declare function resetShippedIndex(): void;
|
|
28
|
+
export declare function normalizeMonster(name: string, raw: any): MonsterBlock;
|
|
29
|
+
export declare function renderBestiary(entries: Record<string, MonsterBlock>): string;
|
|
30
|
+
export declare function describeMonster(block: MonsterBlock): string;
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BestiaryError = exports.NEAR_MATCH_CAP = exports.MONSTER_LIST_CAP = exports.BESTIARY_ARTIFACT = void 0;
|
|
4
|
+
exports.parseBestiary = parseBestiary;
|
|
5
|
+
exports.resolveMonster = resolveMonster;
|
|
6
|
+
exports.availableMonsters = availableMonsters;
|
|
7
|
+
exports.nearMonsters = nearMonsters;
|
|
8
|
+
exports.resetShippedIndex = resetShippedIndex;
|
|
9
|
+
exports.normalizeMonster = normalizeMonster;
|
|
10
|
+
exports.renderBestiary = renderBestiary;
|
|
11
|
+
exports.describeMonster = describeMonster;
|
|
12
|
+
const monsters_1 = require("../data/monsters");
|
|
13
|
+
const srd_1 = require("../data/srd");
|
|
14
|
+
const coerce_1 = require("./coerce");
|
|
15
|
+
const sheet_1 = require("./sheet");
|
|
16
|
+
exports.BESTIARY_ARTIFACT = 'Bestiary';
|
|
17
|
+
const STATE_FENCE_TAG = 'briyah-state';
|
|
18
|
+
exports.MONSTER_LIST_CAP = 60;
|
|
19
|
+
exports.NEAR_MATCH_CAP = 8;
|
|
20
|
+
let shippedIndexCache = null;
|
|
21
|
+
function shippedIndex() {
|
|
22
|
+
if (!shippedIndexCache) {
|
|
23
|
+
shippedIndexCache = new Map();
|
|
24
|
+
for (const [key, block] of Object.entries(monsters_1.SRD_MONSTERS)) {
|
|
25
|
+
shippedIndexCache.set((0, coerce_1.nameKey)(key), block);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return shippedIndexCache;
|
|
29
|
+
}
|
|
30
|
+
function shippedKeys() {
|
|
31
|
+
return [...shippedIndex().keys()];
|
|
32
|
+
}
|
|
33
|
+
class BestiaryError extends Error {
|
|
34
|
+
violation;
|
|
35
|
+
constructor(violation, message) {
|
|
36
|
+
super(message);
|
|
37
|
+
this.name = 'BestiaryError';
|
|
38
|
+
this.violation = violation;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.BestiaryError = BestiaryError;
|
|
42
|
+
function parseBestiary(body) {
|
|
43
|
+
if (!body || !body.trim())
|
|
44
|
+
return {};
|
|
45
|
+
const lines = body.split('\n');
|
|
46
|
+
const open = lines.findIndex((line) => line.trim() === '```' + STATE_FENCE_TAG);
|
|
47
|
+
if (open === -1) {
|
|
48
|
+
throw new BestiaryError('bestiary_corrupt', `The "${exports.BESTIARY_ARTIFACT}" artifact has no "${STATE_FENCE_TAG}" block, so its creatures cannot be read. It was probably overwritten by hand or by a PUBLISH action.`);
|
|
49
|
+
}
|
|
50
|
+
const closeOffset = lines.slice(open + 1).findIndex((line) => line.trim() === '```');
|
|
51
|
+
if (closeOffset === -1) {
|
|
52
|
+
throw new BestiaryError('bestiary_corrupt', `The "${exports.BESTIARY_ARTIFACT}" artifact's "${STATE_FENCE_TAG}" block is not closed.`);
|
|
53
|
+
}
|
|
54
|
+
const json = lines.slice(open + 1, open + 1 + closeOffset).join('\n');
|
|
55
|
+
let parsed;
|
|
56
|
+
try {
|
|
57
|
+
parsed = JSON.parse(json);
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
throw new BestiaryError('bestiary_corrupt', `The "${exports.BESTIARY_ARTIFACT}" artifact's "${STATE_FENCE_TAG}" block is not valid JSON (${e.message}).`);
|
|
61
|
+
}
|
|
62
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
63
|
+
return {};
|
|
64
|
+
}
|
|
65
|
+
const out = {};
|
|
66
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
67
|
+
if (value && typeof value === 'object')
|
|
68
|
+
out[(0, coerce_1.nameKey)(key)] = value;
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
function resolveMonster(name, campaign) {
|
|
73
|
+
const key = (0, coerce_1.nameKey)(name);
|
|
74
|
+
if (!key)
|
|
75
|
+
return {};
|
|
76
|
+
if (campaign[key])
|
|
77
|
+
return { block: campaign[key], source: 'bestiary' };
|
|
78
|
+
const shipped = shippedIndex().get(key);
|
|
79
|
+
if (shipped)
|
|
80
|
+
return { block: shipped, source: 'srd' };
|
|
81
|
+
const campaignMatches = (0, coerce_1.matchNames)(name, Object.keys(campaign));
|
|
82
|
+
if (campaignMatches.length === 1) {
|
|
83
|
+
return { block: campaign[campaignMatches[0]], source: 'bestiary' };
|
|
84
|
+
}
|
|
85
|
+
if (campaignMatches.length > 1) {
|
|
86
|
+
return { ambiguous: campaignMatches.map((k) => campaign[k].name).sort() };
|
|
87
|
+
}
|
|
88
|
+
const shippedMatches = (0, coerce_1.matchNames)(name, shippedKeys());
|
|
89
|
+
if (shippedMatches.length === 1) {
|
|
90
|
+
return { block: shippedIndex().get(shippedMatches[0]), source: 'srd' };
|
|
91
|
+
}
|
|
92
|
+
if (shippedMatches.length > 1) {
|
|
93
|
+
return { ambiguous: shippedMatches.map((k) => shippedIndex().get(k).name).sort() };
|
|
94
|
+
}
|
|
95
|
+
return {};
|
|
96
|
+
}
|
|
97
|
+
function availableMonsters(campaign, filter) {
|
|
98
|
+
const needle = (0, coerce_1.nameKey)(filter || '');
|
|
99
|
+
const keep = (name) => !needle || (0, coerce_1.nameKey)(name).includes(needle);
|
|
100
|
+
const campaignAll = Object.values(campaign)
|
|
101
|
+
.map((block) => block.name)
|
|
102
|
+
.filter(keep)
|
|
103
|
+
.sort();
|
|
104
|
+
const shippedAll = [...shippedIndex().values()]
|
|
105
|
+
.map((block) => block.name)
|
|
106
|
+
.filter(keep)
|
|
107
|
+
.sort();
|
|
108
|
+
return {
|
|
109
|
+
campaign: campaignAll.slice(0, exports.MONSTER_LIST_CAP),
|
|
110
|
+
shipped: shippedAll.slice(0, exports.MONSTER_LIST_CAP),
|
|
111
|
+
campaignTotal: campaignAll.length,
|
|
112
|
+
shippedTotal: shippedAll.length,
|
|
113
|
+
truncated: campaignAll.length > exports.MONSTER_LIST_CAP || shippedAll.length > exports.MONSTER_LIST_CAP
|
|
114
|
+
? true
|
|
115
|
+
: undefined,
|
|
116
|
+
filter: filter || undefined,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function nearMonsters(name, campaign, limit = exports.NEAR_MATCH_CAP) {
|
|
120
|
+
const words = (0, coerce_1.nameKey)(name).split(' ').filter((w) => w.length > 2);
|
|
121
|
+
if (words.length === 0)
|
|
122
|
+
return [];
|
|
123
|
+
const candidates = [
|
|
124
|
+
...Object.values(campaign).map((block) => block.name),
|
|
125
|
+
...[...shippedIndex().values()].map((block) => block.name),
|
|
126
|
+
];
|
|
127
|
+
return candidates
|
|
128
|
+
.map((candidate) => {
|
|
129
|
+
const key = (0, coerce_1.nameKey)(candidate);
|
|
130
|
+
const score = words.filter((word) => key.includes(word)).length;
|
|
131
|
+
return { candidate, score };
|
|
132
|
+
})
|
|
133
|
+
.filter((entry) => entry.score > 0)
|
|
134
|
+
.sort((a, b) => b.score - a.score || a.candidate.localeCompare(b.candidate))
|
|
135
|
+
.slice(0, limit)
|
|
136
|
+
.map((entry) => entry.candidate);
|
|
137
|
+
}
|
|
138
|
+
function resetShippedIndex() {
|
|
139
|
+
shippedIndexCache = null;
|
|
140
|
+
}
|
|
141
|
+
function proseList(name, field, value) {
|
|
142
|
+
if (value === undefined || value === null)
|
|
143
|
+
return undefined;
|
|
144
|
+
const example = `"${field}": [{"n":"Innate Spellcasting","text":"At will: disguise self, speak with plants."}]`;
|
|
145
|
+
if (!Array.isArray(value)) {
|
|
146
|
+
throw new BestiaryError('bad_block', `"${name}" needs "${field}" as a list of named paragraphs, not ${typeof value === 'string' ? 'a single string' : `a ${typeof value}`}. Give each one a name and its text, and split prose covering several of them into separate entries: ${example}`);
|
|
147
|
+
}
|
|
148
|
+
return value.map((entry) => {
|
|
149
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry) || !entry.n || !entry.text) {
|
|
150
|
+
throw new BestiaryError('bad_block', `Every entry in "${field}" on "${name}" needs a name ("n") and its text. Received: ${JSON.stringify(entry)}. Example: ${example}`);
|
|
151
|
+
}
|
|
152
|
+
return { ...entry, n: String(entry.n), text: String(entry.text) };
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
function wordList(name, field, value) {
|
|
156
|
+
if (value === undefined || value === null)
|
|
157
|
+
return undefined;
|
|
158
|
+
if (!Array.isArray(value)) {
|
|
159
|
+
throw new BestiaryError('bad_block', `"${name}" needs "${field}" as a list, e.g. "${field}": ["cold", "bludgeoning from nonmagical attacks"]. Received: ${JSON.stringify(value)}`);
|
|
160
|
+
}
|
|
161
|
+
return value.map((entry) => String(entry));
|
|
162
|
+
}
|
|
163
|
+
function normalizeMonster(name, raw) {
|
|
164
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
165
|
+
throw new BestiaryError('bad_block', `A creature definition must be a JSON object. Example: {"ac":14,"hp":27,"speed":"30 ft.","abil":{"str":12,"dex":16,"con":12,"int":10,"wis":11,"cha":10},"attacks":[{"n":"Shortsword","atk":5,"dmg":"1d6+3","type":"piercing"}]}`);
|
|
166
|
+
}
|
|
167
|
+
const ac = Number(raw.ac);
|
|
168
|
+
const hp = Number(raw.hp);
|
|
169
|
+
if (!Number.isFinite(ac) || ac < 1) {
|
|
170
|
+
throw new BestiaryError('bad_block', `"${name}" needs a numeric armour class ("ac").`);
|
|
171
|
+
}
|
|
172
|
+
if (!Number.isFinite(hp) || hp < 1) {
|
|
173
|
+
throw new BestiaryError('bad_block', `"${name}" needs a numeric hit point total ("hp").`);
|
|
174
|
+
}
|
|
175
|
+
const attacks = Array.isArray(raw.attacks) ? raw.attacks : [];
|
|
176
|
+
const traits = proseList(name, 'traits', raw.traits);
|
|
177
|
+
const actions = proseList(name, 'actions', raw.actions);
|
|
178
|
+
const reactions = proseList(name, 'reactions', raw.reactions);
|
|
179
|
+
const resist = wordList(name, 'resist', raw.resist);
|
|
180
|
+
const immune = wordList(name, 'immune', raw.immune);
|
|
181
|
+
const vuln = wordList(name, 'vuln', raw.vuln);
|
|
182
|
+
const condImmune = wordList(name, 'condImmune', raw.condImmune);
|
|
183
|
+
const hasSomethingToDo = [traits, actions, reactions].some((list) => list && list.length > 0);
|
|
184
|
+
if (attacks.length === 0 && !hasSomethingToDo && !raw.legendary) {
|
|
185
|
+
throw new BestiaryError('bad_block', `"${name}" has nothing it can do. Give it an attack: [{"n":"Claws","atk":4,"dmg":"2d4+2","type":"slashing"}], or an action: [{"n":"Shriek","text":"Emits a shriek audible within 300 feet."}].`);
|
|
186
|
+
}
|
|
187
|
+
for (const attack of attacks) {
|
|
188
|
+
if (!attack || !attack.n || !Number.isFinite(Number(attack.atk)) || !attack.dmg) {
|
|
189
|
+
throw new BestiaryError('bad_block', `Every attack on "${name}" needs a name, a numeric "atk" bonus and a "dmg" dice expression. Received: ${JSON.stringify(attack)}`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const abil = {};
|
|
193
|
+
for (const ability of srd_1.ABILITIES) {
|
|
194
|
+
const score = Number(raw.abil?.[ability]);
|
|
195
|
+
abil[ability] = Number.isFinite(score) ? score : 10;
|
|
196
|
+
}
|
|
197
|
+
const block = {
|
|
198
|
+
...raw,
|
|
199
|
+
name: String(raw.name || name),
|
|
200
|
+
ac,
|
|
201
|
+
hp,
|
|
202
|
+
speed: String(raw.speed || '30 ft.'),
|
|
203
|
+
abil,
|
|
204
|
+
attacks: attacks.map((a) => ({ ...a, atk: Number(a.atk), dmg: String(a.dmg) })),
|
|
205
|
+
};
|
|
206
|
+
if (traits)
|
|
207
|
+
block.traits = traits;
|
|
208
|
+
if (actions)
|
|
209
|
+
block.actions = actions;
|
|
210
|
+
if (reactions)
|
|
211
|
+
block.reactions = reactions;
|
|
212
|
+
if (resist)
|
|
213
|
+
block.resist = resist;
|
|
214
|
+
if (immune)
|
|
215
|
+
block.immune = immune;
|
|
216
|
+
if (vuln)
|
|
217
|
+
block.vuln = vuln;
|
|
218
|
+
if (condImmune)
|
|
219
|
+
block.condImmune = condImmune;
|
|
220
|
+
if (raw.legendary) {
|
|
221
|
+
const options = proseList(name, 'legendary.options', raw.legendary.options) ?? [];
|
|
222
|
+
if (options.length === 0) {
|
|
223
|
+
delete block.legendary;
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
const per = Number(raw.legendary.per);
|
|
227
|
+
block.legendary = { per: Number.isFinite(per) && per > 0 ? per : 3, options };
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return block;
|
|
231
|
+
}
|
|
232
|
+
function renderBestiary(entries) {
|
|
233
|
+
const names = Object.keys(entries).sort();
|
|
234
|
+
const lines = [
|
|
235
|
+
`# ${exports.BESTIARY_ARTIFACT}`,
|
|
236
|
+
'',
|
|
237
|
+
'Creatures belonging to this campaign. Written and read by the 5e tools —',
|
|
238
|
+
'do not edit the block at the bottom by hand.',
|
|
239
|
+
'',
|
|
240
|
+
];
|
|
241
|
+
if (names.length === 0) {
|
|
242
|
+
lines.push('*No campaign creatures yet.*', '');
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
for (const key of names) {
|
|
246
|
+
lines.push(describeMonster(entries[key]), '');
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
lines.push('```' + STATE_FENCE_TAG, JSON.stringify(entries), '```', '');
|
|
250
|
+
return lines.join('\n');
|
|
251
|
+
}
|
|
252
|
+
function describeMonster(block) {
|
|
253
|
+
const lines = [];
|
|
254
|
+
const descriptors = [block.size, block.kind].filter(Boolean).join(' ');
|
|
255
|
+
lines.push(`## ${block.name}`);
|
|
256
|
+
if (descriptors)
|
|
257
|
+
lines.push(`*${descriptors}*`);
|
|
258
|
+
const acNote = block.acNote ? ` (${block.acNote})` : '';
|
|
259
|
+
const hpDice = block.hpDice ? ` (${block.hpDice})` : '';
|
|
260
|
+
lines.push(`**AC ${block.ac}**${acNote} | **HP ${block.hp}**${hpDice} | **Speed ${block.speed}**${block.cr ? ` | **CR ${block.cr}**` : ''}`);
|
|
261
|
+
lines.push(srd_1.ABILITIES.map((ability) => `${ability.toUpperCase()} ${block.abil[ability]} (${(0, sheet_1.signed)(abilityModifier(block.abil[ability]))})`).join(' · '));
|
|
262
|
+
const saves = srd_1.ABILITIES.filter((ability) => Number.isFinite(Number(block.saves?.[ability])));
|
|
263
|
+
if (saves.length > 0) {
|
|
264
|
+
lines.push('**Saves:** ' +
|
|
265
|
+
saves
|
|
266
|
+
.map((ability) => `${ability.toUpperCase()} ${(0, sheet_1.signed)(Number(block.saves[ability]))}`)
|
|
267
|
+
.join(' · '));
|
|
268
|
+
}
|
|
269
|
+
if (block.skills && Object.keys(block.skills).length > 0) {
|
|
270
|
+
lines.push('**Skills:** ' +
|
|
271
|
+
Object.entries(block.skills)
|
|
272
|
+
.map(([skill, bonus]) => `${(0, sheet_1.titleCase)(skill)} ${(0, sheet_1.signed)(Number(bonus))}`)
|
|
273
|
+
.join(' · '));
|
|
274
|
+
}
|
|
275
|
+
if (block.senses)
|
|
276
|
+
lines.push(`**Senses:** ${block.senses}`);
|
|
277
|
+
if (block.languages)
|
|
278
|
+
lines.push(`**Languages:** ${block.languages}`);
|
|
279
|
+
if (words(block.resist))
|
|
280
|
+
lines.push(`**Resistant to:** ${words(block.resist)}`);
|
|
281
|
+
if (words(block.immune))
|
|
282
|
+
lines.push(`**Immune to:** ${words(block.immune)}`);
|
|
283
|
+
if (words(block.vuln))
|
|
284
|
+
lines.push(`**Vulnerable to:** ${words(block.vuln)}`);
|
|
285
|
+
if (words(block.condImmune))
|
|
286
|
+
lines.push(`**Cannot be:** ${words(block.condImmune)}`);
|
|
287
|
+
for (const trait of paragraphs(block.traits)) {
|
|
288
|
+
lines.push(`**${trait.n}.** ${trait.text}`);
|
|
289
|
+
}
|
|
290
|
+
if (block.multiattack)
|
|
291
|
+
lines.push(`**Multiattack:** ${block.multiattack}`);
|
|
292
|
+
for (const attack of block.attacks || []) {
|
|
293
|
+
const reach = attack.reach ? `, ${attack.reach}` : '';
|
|
294
|
+
const type = attack.type ? ` ${attack.type}` : '';
|
|
295
|
+
const note = attack.note ? ` — ${attack.note}` : '';
|
|
296
|
+
lines.push(`**${attack.n}:** ${(0, sheet_1.signed)(attack.atk)} to hit${reach}, ${attack.dmg}${type}.${note}`);
|
|
297
|
+
}
|
|
298
|
+
for (const action of paragraphs(block.actions)) {
|
|
299
|
+
lines.push(`**${action.n}.** ${action.text}`);
|
|
300
|
+
}
|
|
301
|
+
const reactions = paragraphs(block.reactions);
|
|
302
|
+
if (reactions.length > 0) {
|
|
303
|
+
lines.push('**Reactions**');
|
|
304
|
+
for (const reaction of reactions) {
|
|
305
|
+
lines.push(`**${reaction.n}.** ${reaction.text}`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
const legendary = paragraphs(block.legendary?.options);
|
|
309
|
+
if (legendary.length > 0) {
|
|
310
|
+
lines.push(`**Legendary Actions** — ${block.legendary.per} per round, one at a time, at the end of another creature's turn; spent actions are regained at the start of its turn.`);
|
|
311
|
+
for (const option of legendary) {
|
|
312
|
+
lines.push(`**${option.n}.** ${option.text}`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
return lines.join('\n');
|
|
316
|
+
}
|
|
317
|
+
function paragraphs(value) {
|
|
318
|
+
if (!Array.isArray(value))
|
|
319
|
+
return [];
|
|
320
|
+
return value.filter((entry) => entry && typeof entry === 'object' && entry.n && entry.text);
|
|
321
|
+
}
|
|
322
|
+
function words(value) {
|
|
323
|
+
if (!Array.isArray(value) || value.length === 0)
|
|
324
|
+
return '';
|
|
325
|
+
return value.map((entry) => String(entry)).join(', ');
|
|
326
|
+
}
|
|
327
|
+
function abilityModifier(score) {
|
|
328
|
+
return Math.floor(((Number(score) || 10) - 10) / 2);
|
|
329
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { MagicItem } from '../data/magic-items';
|
|
2
|
+
export declare const ITEMS_ARTIFACT = "Magic Items";
|
|
3
|
+
export declare class ItemError extends Error {
|
|
4
|
+
readonly violation: string;
|
|
5
|
+
constructor(violation: string, message: string);
|
|
6
|
+
}
|
|
7
|
+
export declare function parseCampaignItems(body: string | undefined): Record<string, MagicItem>;
|
|
8
|
+
export declare function normalizeItem(name: string, raw: any): MagicItem;
|
|
9
|
+
export declare function renderCampaignItems(entries: Record<string, MagicItem>): string;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ItemError = exports.ITEMS_ARTIFACT = void 0;
|
|
4
|
+
exports.parseCampaignItems = parseCampaignItems;
|
|
5
|
+
exports.normalizeItem = normalizeItem;
|
|
6
|
+
exports.renderCampaignItems = renderCampaignItems;
|
|
7
|
+
const coerce_1 = require("./coerce");
|
|
8
|
+
const items_1 = require("./items");
|
|
9
|
+
exports.ITEMS_ARTIFACT = 'Magic Items';
|
|
10
|
+
const STATE_FENCE_TAG = 'briyah-state';
|
|
11
|
+
class ItemError extends Error {
|
|
12
|
+
violation;
|
|
13
|
+
constructor(violation, message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.name = 'ItemError';
|
|
16
|
+
this.violation = violation;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.ItemError = ItemError;
|
|
20
|
+
function parseCampaignItems(body) {
|
|
21
|
+
if (!body || !body.trim())
|
|
22
|
+
return {};
|
|
23
|
+
const lines = body.split('\n');
|
|
24
|
+
const open = lines.findIndex((line) => line.trim() === '```' + STATE_FENCE_TAG);
|
|
25
|
+
if (open === -1) {
|
|
26
|
+
throw new ItemError('items_corrupt', `The "${exports.ITEMS_ARTIFACT}" artifact has no "${STATE_FENCE_TAG}" block, so its items cannot be read. It was probably overwritten by hand or by a PUBLISH action.`);
|
|
27
|
+
}
|
|
28
|
+
const closeOffset = lines.slice(open + 1).findIndex((line) => line.trim() === '```');
|
|
29
|
+
if (closeOffset === -1) {
|
|
30
|
+
throw new ItemError('items_corrupt', `The "${exports.ITEMS_ARTIFACT}" artifact's "${STATE_FENCE_TAG}" block is not closed.`);
|
|
31
|
+
}
|
|
32
|
+
const json = lines.slice(open + 1, open + 1 + closeOffset).join('\n');
|
|
33
|
+
let parsed;
|
|
34
|
+
try {
|
|
35
|
+
parsed = JSON.parse(json);
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
throw new ItemError('items_corrupt', `The "${exports.ITEMS_ARTIFACT}" artifact's "${STATE_FENCE_TAG}" block is not valid JSON (${e.message}).`);
|
|
39
|
+
}
|
|
40
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
41
|
+
return {};
|
|
42
|
+
const out = {};
|
|
43
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
44
|
+
if (value && typeof value === 'object')
|
|
45
|
+
out[(0, coerce_1.nameKey)(key)] = value;
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
function normalizeItem(name, raw) {
|
|
50
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
51
|
+
throw new ItemError('bad_item', `An item definition must be a JSON object. Example: {"name":"Kesh's signet","type":"ring","rarity":"rare","attunement":true,"text":"What it does."}`);
|
|
52
|
+
}
|
|
53
|
+
const text = String(raw.text || '').trim();
|
|
54
|
+
if (!text) {
|
|
55
|
+
throw new ItemError('bad_item', `"${name}" needs a "text" describing what it does. A magic item is its text — without one there is nothing for the table to use.`);
|
|
56
|
+
}
|
|
57
|
+
const item = {
|
|
58
|
+
...raw,
|
|
59
|
+
name: String(raw.name || name),
|
|
60
|
+
type: String(raw.type || 'wondrous item').toLowerCase(),
|
|
61
|
+
text,
|
|
62
|
+
};
|
|
63
|
+
for (const field of ['acBonus', 'attackBonus', 'damageBonus', 'saveBonus']) {
|
|
64
|
+
if (item[field] === undefined)
|
|
65
|
+
continue;
|
|
66
|
+
const value = Number(item[field]);
|
|
67
|
+
if (!Number.isFinite(value)) {
|
|
68
|
+
throw new ItemError('bad_item', `"${item.name}" has a non-numeric ${field}.`);
|
|
69
|
+
}
|
|
70
|
+
item[field] = value;
|
|
71
|
+
}
|
|
72
|
+
if (item.charges) {
|
|
73
|
+
const max = Number(item.charges.max);
|
|
74
|
+
if (!Number.isFinite(max) || max < 1) {
|
|
75
|
+
throw new ItemError('bad_item', `"${item.name}" has charges with no usable maximum. Example: {"charges":{"max":7,"recharge":"1d6+1 daily at dawn"}}`);
|
|
76
|
+
}
|
|
77
|
+
item.charges = { ...item.charges, max };
|
|
78
|
+
}
|
|
79
|
+
return item;
|
|
80
|
+
}
|
|
81
|
+
function renderCampaignItems(entries) {
|
|
82
|
+
const names = Object.keys(entries).sort();
|
|
83
|
+
const lines = [
|
|
84
|
+
`# ${exports.ITEMS_ARTIFACT}`,
|
|
85
|
+
'',
|
|
86
|
+
'Magic items belonging to this campaign. Written and read by the 5e tools —',
|
|
87
|
+
'do not edit the block at the bottom by hand.',
|
|
88
|
+
'',
|
|
89
|
+
];
|
|
90
|
+
if (names.length === 0) {
|
|
91
|
+
lines.push('*No campaign items yet.*', '');
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
for (const key of names) {
|
|
95
|
+
lines.push((0, items_1.describeItem)(entries[key]), '');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
lines.push('```' + STATE_FENCE_TAG, JSON.stringify(entries), '```', '');
|
|
99
|
+
return lines.join('\n');
|
|
100
|
+
}
|