briyah 1.5.0 → 2.0.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.
Files changed (226) hide show
  1. package/README.md +1092 -994
  2. package/data/common/config/markup +1 -1
  3. package/data/common/prompts/character/progress_character.json +5 -5
  4. package/data/common/prompts/illustrator/describe_scene.json +11 -3
  5. package/data/common/prompts/perceive.json +2 -2
  6. package/data/common/prompts/room_moderator/moderate.json +34 -34
  7. package/data/common/prompts/story_moderator/moderate.json +62 -62
  8. package/data/packs/dnd5e/agents/battle-master.json +6 -0
  9. package/data/packs/dnd5e/agents/campaign-designer.json +6 -0
  10. package/data/packs/dnd5e/agents/character-creator.json +6 -0
  11. package/data/packs/dnd5e/agents/dungeon-master.json +6 -0
  12. package/data/packs/dnd5e/agents/player.json +13 -0
  13. package/data/packs/dnd5e/agents/table-moderator.json +6 -0
  14. package/data/{common/artifacts/dnd5e/dungeon_master-procedure.md → packs/dnd5e/artifacts/battle_master-combat.md} +31 -131
  15. package/data/packs/dnd5e/artifacts/dungeon_master-procedure.md +192 -0
  16. package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/manifest.json +8 -2
  17. package/data/packs/dnd5e/pack.json +6 -0
  18. package/data/packs/dnd5e/prompts/battle_master/defaults_config.json +23 -0
  19. package/data/packs/dnd5e/prompts/battle_master/perceive.json +33 -0
  20. package/data/packs/dnd5e/prompts/battle_master/perceive.prompt +378 -0
  21. package/data/{common → packs/dnd5e}/prompts/character_creator/defaults_config.json +1 -1
  22. package/data/{common → packs/dnd5e}/prompts/character_creator/perceive.prompt +29 -0
  23. package/data/{common → packs/dnd5e}/prompts/dnd_player/perceive.prompt +40 -22
  24. package/data/{common → packs/dnd5e}/prompts/dnd_room_moderator/moderate.json +34 -34
  25. package/data/{common → packs/dnd5e}/prompts/dnd_room_moderator/moderate.prompt +14 -3
  26. package/data/{common → packs/dnd5e}/prompts/dungeon_master/defaults_config.json +1 -0
  27. package/data/{common → packs/dnd5e}/prompts/dungeon_master/perceive.prompt +122 -115
  28. package/data/packs/dnd5e/prompts/dungeon_master/system_instruction.prompt +0 -0
  29. package/data/packs/dnd5e/rooms/table.json +16 -0
  30. package/dist-sdk/server/src/ai/LLM/base-ai.service.js +4 -13
  31. package/dist-sdk/server/src/ai/LLM/deepseek.service.d.ts +2 -1
  32. package/dist-sdk/server/src/ai/LLM/deepseek.service.js +65 -77
  33. package/dist-sdk/server/src/ai/agent-config.d.ts +2 -0
  34. package/dist-sdk/server/src/ai/agent-store.service.js +8 -0
  35. package/dist-sdk/server/src/ai/agent.d.ts +6 -0
  36. package/dist-sdk/server/src/ai/agent.js +25 -2
  37. package/dist-sdk/server/src/ai/artifact.service.d.ts +3 -1
  38. package/dist-sdk/server/src/ai/artifact.service.js +12 -5
  39. package/dist-sdk/server/src/ai/pack-artifacts.d.ts +3 -3
  40. package/dist-sdk/server/src/ai/pack-artifacts.js +21 -15
  41. package/dist-sdk/server/src/app/user-service-factory.js +9 -1
  42. package/dist-sdk/server/src/app.controller.d.ts +11 -11
  43. package/dist-sdk/server/src/app.controller.js +178 -88
  44. package/dist-sdk/server/src/app.service.d.ts +28 -7
  45. package/dist-sdk/server/src/app.service.js +121 -91
  46. package/dist-sdk/server/src/common/errors.d.ts +0 -3
  47. package/dist-sdk/server/src/common/errors.js +1 -11
  48. package/dist-sdk/server/src/config/prompt-resolver.d.ts +39 -0
  49. package/dist-sdk/server/src/config/prompt-resolver.js +189 -0
  50. package/dist-sdk/server/src/config/user-config.service.d.ts +17 -0
  51. package/dist-sdk/server/src/config/user-config.service.js +103 -0
  52. package/dist-sdk/server/src/config/user-paths.service.d.ts +4 -4
  53. package/dist-sdk/server/src/config/user-paths.service.js +12 -16
  54. package/dist-sdk/server/src/packs/pack-instantiation.service.d.ts +35 -0
  55. package/dist-sdk/server/src/packs/pack-instantiation.service.js +154 -0
  56. package/dist-sdk/server/src/packs/pack-manifest.d.ts +52 -0
  57. package/dist-sdk/server/src/packs/pack-manifest.js +256 -0
  58. package/dist-sdk/server/src/packs/pack.service.d.ts +24 -0
  59. package/dist-sdk/server/src/packs/pack.service.js +151 -0
  60. package/dist-sdk/server/src/room/room-config.d.ts +5 -0
  61. package/dist-sdk/server/src/room/room-store.service.d.ts +3 -0
  62. package/dist-sdk/server/src/room/room-store.service.js +41 -5
  63. package/dist-sdk/server/src/room/room.d.ts +7 -0
  64. package/dist-sdk/server/src/room/room.js +29 -1
  65. package/dist-sdk/server/src/sdk/briyah.d.ts +2 -0
  66. package/dist-sdk/server/src/sdk/briyah.js +45 -8
  67. package/dist-sdk/server/src/sdk/index.d.ts +6 -1
  68. package/dist-sdk/server/src/sdk/index.js +6 -2
  69. package/dist-sdk/server/src/shared/shared.module.js +0 -3
  70. package/dist-sdk/server/src/story/story.service.d.ts +2 -2
  71. package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.d.ts +17 -0
  72. package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.js +54 -0
  73. package/dist-sdk/server/src/tools/packs/dnd5e/data/races.d.ts +3 -0
  74. package/dist-sdk/server/src/tools/packs/dnd5e/data/races.js +6 -0
  75. package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.d.ts +2 -0
  76. package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.js +4 -0
  77. package/dist-sdk/server/src/tools/packs/dnd5e/engine/backgrounds.d.ts +1 -1
  78. package/dist-sdk/server/src/tools/packs/dnd5e/engine/backgrounds.js +6 -3
  79. package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.d.ts +3 -0
  80. package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.js +45 -5
  81. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.d.ts +27 -0
  82. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.js +103 -0
  83. package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.d.ts +7 -0
  84. package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.js +83 -0
  85. package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.d.ts +19 -0
  86. package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.js +130 -0
  87. package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.d.ts +2 -1
  88. package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.js +13 -2
  89. package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.d.ts +6 -0
  90. package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.js +16 -0
  91. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +10 -0
  92. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +82 -1
  93. package/dist-sdk/server/src/tools/packs/dnd5e/index.js +2 -0
  94. package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.js +51 -6
  95. package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.js +19 -9
  96. package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.d.ts +2 -0
  97. package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.js +134 -0
  98. package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.js +31 -13
  99. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +2 -0
  100. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +25 -8
  101. package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +70 -4
  102. package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.js +27 -0
  103. package/dist-sdk/server/src/tools/packs/index.d.ts +1 -2
  104. package/dist-sdk/server/src/tools/packs/index.js +5 -11
  105. package/dist-sdk/shared/types/app.types.d.ts +72 -13
  106. package/docs/assets/hierarchy.js +1 -1
  107. package/docs/assets/highlight.css +8 -1
  108. package/docs/assets/icons.js +1 -1
  109. package/docs/assets/icons.svg +1 -1
  110. package/docs/assets/main.js +4 -4
  111. package/docs/assets/navigation.js +1 -1
  112. package/docs/assets/search.js +1 -1
  113. package/docs/assets/style.css +18 -3
  114. package/docs/classes/Agent.html +702 -37
  115. package/docs/classes/Briyah.html +250 -33
  116. package/docs/classes/BriyahConfigService.html +117 -10
  117. package/docs/classes/NativeToolRegistry.html +156 -11
  118. package/docs/classes/PackInstantiationService.html +146 -0
  119. package/docs/classes/PackService.html +247 -0
  120. package/docs/classes/Room.html +1190 -77
  121. package/docs/classes/RoomMessage.html +260 -29
  122. package/docs/enums/MessageAction.html +123 -3
  123. package/docs/functions/availableToolPacks.html +41 -2
  124. package/docs/functions/dnd5eTools.html +42 -3
  125. package/docs/functions/installToolPacks.html +48 -0
  126. package/docs/functions/registerToolPacks.html +54 -6
  127. package/docs/hierarchy.html +42 -1
  128. package/docs/index.html +158 -25
  129. package/docs/interfaces/AgentCreationOptions.html +110 -11
  130. package/docs/interfaces/AgentInfo.html +188 -3
  131. package/docs/interfaces/AgentMessagesResponse.html +71 -2
  132. package/docs/interfaces/AppService.html +2775 -474
  133. package/docs/interfaces/Artifact.html +81 -4
  134. package/docs/interfaces/ArtifactMetadata.html +104 -3
  135. package/docs/interfaces/ArtifactWriteOptions.html +75 -6
  136. package/docs/interfaces/AttachDocumentResponse.html +61 -2
  137. package/docs/interfaces/BriyahConfigOptions.html +107 -10
  138. package/docs/interfaces/ChapterInfo.html +61 -2
  139. package/docs/interfaces/Character.html +81 -2
  140. package/docs/interfaces/CreateAgentResponse.html +56 -2
  141. package/docs/interfaces/CreateRoomResponse.html +61 -2
  142. package/docs/interfaces/CreateStoryResponse.html +56 -2
  143. package/docs/interfaces/FileList.html +56 -2
  144. package/docs/interfaces/FileMetadata.html +84 -3
  145. package/docs/interfaces/IConfigService.html +76 -3
  146. package/docs/interfaces/InstantiateModels.html +64 -0
  147. package/docs/interfaces/InstantiateRoomResult.html +70 -0
  148. package/docs/interfaces/LoadedPack.html +131 -0
  149. package/docs/interfaces/LoggingOptions.html +86 -7
  150. package/docs/interfaces/Message.html +80 -2
  151. package/docs/interfaces/ModelChoice.html +73 -0
  152. package/docs/interfaces/ModelInfo.html +71 -2
  153. package/docs/interfaces/NativeToolDefinition.html +96 -9
  154. package/docs/interfaces/PackAgentTemplate.html +101 -0
  155. package/docs/interfaces/PackRoomTemplate.html +108 -0
  156. package/docs/interfaces/PackView.html +172 -0
  157. package/docs/interfaces/PreparedPromptResponse.html +61 -2
  158. package/docs/interfaces/ProcessTextResponse.html +81 -2
  159. package/docs/interfaces/PromptFile.html +69 -2
  160. package/docs/interfaces/PromptFileContent.html +75 -2
  161. package/docs/interfaces/PromptFilesResponse.html +56 -2
  162. package/docs/interfaces/PromptFolder.html +79 -2
  163. package/docs/interfaces/PromptFolderDefaults.html +136 -5
  164. package/docs/interfaces/PromptFolderDefaultsResponse.html +65 -4
  165. package/docs/interfaces/PromptFoldersResponse.html +56 -2
  166. package/docs/interfaces/RoomDetails.html +133 -4
  167. package/docs/interfaces/RoomInfo.html +84 -2
  168. package/docs/interfaces/RoomMessageUpdate.html +91 -2
  169. package/docs/interfaces/RoomMessagesResponse.html +61 -2
  170. package/docs/interfaces/SendMessageResult.html +61 -2
  171. package/docs/interfaces/StoryErrorEvent.html +76 -4
  172. package/docs/interfaces/StoryIdea.html +71 -2
  173. package/docs/interfaces/StoryInfo.html +173 -3
  174. package/docs/interfaces/StoryIntroduceCharacterEvent.html +71 -4
  175. package/docs/interfaces/StoryProgressChapterEvent.html +64 -3
  176. package/docs/interfaces/StoryState.html +99 -6
  177. package/docs/interfaces/StoryStateEvent.html +69 -3
  178. package/docs/interfaces/ToolArtifact.html +81 -4
  179. package/docs/interfaces/ToolCaller.html +75 -6
  180. package/docs/interfaces/ToolDefinition.html +76 -2
  181. package/docs/interfaces/ToolHelpers.html +91 -6
  182. package/docs/interfaces/ToolParameter.html +71 -2
  183. package/docs/interfaces/ToolRoomAccess.html +200 -24
  184. package/docs/interfaces/ToolSummary.html +71 -2
  185. package/docs/interfaces/ToolsResponse.html +66 -2
  186. package/docs/interfaces/Transaction.html +96 -2
  187. package/docs/interfaces/TransactionHistoryResponse.html +61 -2
  188. package/docs/modules.html +53 -1
  189. package/docs/types/PackOrigin.html +34 -0
  190. package/docs/types/PromptScope.html +34 -1
  191. package/docs/types/RoomTurnMode.html +36 -2
  192. package/docs/types/ToolContext.html +36 -2
  193. package/docs/types/ToolRunResult.html +34 -1
  194. package/package.json +139 -139
  195. package/src/tools/packs/dnd5e/README.md +149 -26
  196. package/dist-sdk/server/src/library/library.service.d.ts +0 -14
  197. package/dist-sdk/server/src/library/library.service.js +0 -165
  198. package/docs/functions/enabledToolPacks.html +0 -2
  199. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/campaign_designer-setting.md +0 -0
  200. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/character_creator-basics.md +0 -0
  201. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-barbarian.md +0 -0
  202. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-bard.md +0 -0
  203. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-cleric.md +0 -0
  204. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-druid.md +0 -0
  205. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-fighter.md +0 -0
  206. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-monk.md +0 -0
  207. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-paladin.md +0 -0
  208. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-ranger.md +0 -0
  209. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-rogue.md +0 -0
  210. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-sorcerer.md +0 -0
  211. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-warlock.md +0 -0
  212. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-wizard.md +0 -0
  213. /package/data/{common/prompts/campaign_designer → packs/dnd5e/prompts/battle_master}/system_instruction.prompt +0 -0
  214. /package/data/{common → packs/dnd5e}/prompts/campaign_designer/defaults_config.json +0 -0
  215. /package/data/{common → packs/dnd5e}/prompts/campaign_designer/perceive.json +0 -0
  216. /package/data/{common → packs/dnd5e}/prompts/campaign_designer/perceive.prompt +0 -0
  217. /package/data/{common/prompts/character_creator → packs/dnd5e/prompts/campaign_designer}/system_instruction.prompt +0 -0
  218. /package/data/{common → packs/dnd5e}/prompts/character_creator/perceive.json +0 -0
  219. /package/data/{common/prompts/dnd_player → packs/dnd5e/prompts/character_creator}/system_instruction.prompt +0 -0
  220. /package/data/{common → packs/dnd5e}/prompts/dnd_player/defaults_config.json +0 -0
  221. /package/data/{common → packs/dnd5e}/prompts/dnd_player/perceive.json +0 -0
  222. /package/data/{common/prompts/dnd_room_moderator → packs/dnd5e/prompts/dnd_player}/system_instruction.prompt +0 -0
  223. /package/data/{common → packs/dnd5e}/prompts/dnd_room_moderator/defaults_config.json +0 -0
  224. /package/data/{common/prompts/dungeon_master → packs/dnd5e/prompts/dnd_room_moderator}/system_instruction.prompt +0 -0
  225. /package/data/{common → packs/dnd5e}/prompts/dungeon_master/compact_agent.prompt +0 -0
  226. /package/data/{common → packs/dnd5e}/prompts/dungeon_master/perceive.json +0 -0
@@ -5,6 +5,7 @@ exports.proficiencyBonus = proficiencyBonus;
5
5
  exports.abilityModifier = abilityModifier;
6
6
  exports.saveModifier = saveModifier;
7
7
  exports.skillModifier = skillModifier;
8
+ exports.toolCheckModifier = toolCheckModifier;
8
9
  exports.passivePerception = passivePerception;
9
10
  exports.spellcastingClass = spellcastingClass;
10
11
  exports.spellSaveDc = spellSaveDc;
@@ -34,6 +35,7 @@ const items_1 = require("./items");
34
35
  const races_1 = require("./races");
35
36
  const encumbrance_1 = require("./encumbrance");
36
37
  const coerce_1 = require("./coerce");
38
+ const kits_1 = require("./kits");
37
39
  function totalLevel(state) {
38
40
  const level = state.class.reduce((sum, entry) => sum + (Number(entry.lvl) || 0), 0);
39
41
  return Math.max(level, 1);
@@ -46,6 +48,9 @@ function abilityModifier(state, ability) {
46
48
  return Math.floor(((Number(state.abil[ability]) || 10) - 10) / 2);
47
49
  }
48
50
  function saveModifier(state, ability) {
51
+ const printed = state.saveBonus?.[ability];
52
+ if (typeof printed === 'number' && Number.isFinite(printed))
53
+ return printed;
49
54
  const base = abilityModifier(state, ability);
50
55
  return state.saveProf.includes(ability) ? base + proficiencyBonus(state) : base;
51
56
  }
@@ -62,6 +67,17 @@ function skillModifier(state, skill) {
62
67
  return base + prof;
63
68
  return base;
64
69
  }
70
+ function toolCheckModifier(state, tool, ability) {
71
+ const base = abilityModifier(state, ability);
72
+ const prof = proficiencyBonus(state);
73
+ if ((0, kits_1.hasToolExpertise)(state, tool)) {
74
+ return { modifier: base + prof * 2, proficient: true, expertise: true };
75
+ }
76
+ if ((0, kits_1.hasToolProficiency)(state, tool)) {
77
+ return { modifier: base + prof, proficient: true, expertise: false };
78
+ }
79
+ return { modifier: base, proficient: false, expertise: false };
80
+ }
65
81
  function passivePerception(state) {
66
82
  return 10 + skillModifier(state, 'perception');
67
83
  }
@@ -1,6 +1,7 @@
1
1
  import { AbilityKey } from '../data/srd';
2
2
  export declare const SHEET_STATE_VERSION = 1;
3
3
  export declare const SHEET_NAME_PREFIX = "Sheet: ";
4
+ export declare const FOE_NAME_PREFIX = "Foe: ";
4
5
  export declare const PARTY_STATUS_ARTIFACT = "Party Status";
5
6
  export declare const ENCOUNTER_ARTIFACT = "Encounter";
6
7
  export interface ClassEntry {
@@ -49,6 +50,8 @@ export interface SheetState {
49
50
  saveProf: AbilityKey[];
50
51
  skillProf: string[];
51
52
  skillExp: string[];
53
+ toolProf: string[];
54
+ toolExp: string[];
52
55
  hp: {
53
56
  max: number;
54
57
  cur: number;
@@ -80,6 +83,8 @@ export interface SheetState {
80
83
  inv: InventoryItem[];
81
84
  coin: Record<string, number>;
82
85
  xp: number;
86
+ foe?: boolean;
87
+ saveBonus?: Partial<Record<AbilityKey, number>>;
83
88
  [key: string]: any;
84
89
  }
85
90
  export declare class SheetError extends Error {
@@ -89,8 +94,13 @@ export declare class SheetError extends Error {
89
94
  export declare function sheetArtifactName(characterName: string): string;
90
95
  export declare function characterNameFromArtifact(artifactName: string): string;
91
96
  export declare function isSheetArtifact(artifactName: string): boolean;
97
+ export declare function foeArtifactName(foeName: string): string;
98
+ export declare function foeNameFromArtifact(artifactName: string): string;
99
+ export declare function isFoeArtifact(artifactName: string): boolean;
100
+ export declare function combatantArtifactName(state: SheetState): string;
92
101
  export declare function parseSheet(body: string): SheetState;
93
102
  export declare function extractNotes(body: string): string;
103
+ export declare function sheetFieldNames(): string[];
94
104
  export declare function collectWarnings(raw: any, normalized: SheetState): string[];
95
105
  export declare function clamp(value: number, min: number, max: number): number;
96
106
  export declare function renderSheet(state: SheetState, notes: string): string;
@@ -33,12 +33,17 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.SheetError = exports.ENCOUNTER_ARTIFACT = exports.PARTY_STATUS_ARTIFACT = exports.SHEET_NAME_PREFIX = exports.SHEET_STATE_VERSION = void 0;
36
+ exports.SheetError = exports.ENCOUNTER_ARTIFACT = exports.PARTY_STATUS_ARTIFACT = exports.FOE_NAME_PREFIX = exports.SHEET_NAME_PREFIX = exports.SHEET_STATE_VERSION = void 0;
37
37
  exports.sheetArtifactName = sheetArtifactName;
38
38
  exports.characterNameFromArtifact = characterNameFromArtifact;
39
39
  exports.isSheetArtifact = isSheetArtifact;
40
+ exports.foeArtifactName = foeArtifactName;
41
+ exports.foeNameFromArtifact = foeNameFromArtifact;
42
+ exports.isFoeArtifact = isFoeArtifact;
43
+ exports.combatantArtifactName = combatantArtifactName;
40
44
  exports.parseSheet = parseSheet;
41
45
  exports.extractNotes = extractNotes;
46
+ exports.sheetFieldNames = sheetFieldNames;
42
47
  exports.collectWarnings = collectWarnings;
43
48
  exports.clamp = clamp;
44
49
  exports.renderSheet = renderSheet;
@@ -48,9 +53,11 @@ const srd_1 = require("../data/srd");
48
53
  const rules = __importStar(require("./rules"));
49
54
  const races_1 = require("./races");
50
55
  const backgrounds_1 = require("./backgrounds");
56
+ const kits_1 = require("./kits");
51
57
  const encumbrance_1 = require("./encumbrance");
52
58
  exports.SHEET_STATE_VERSION = 1;
53
59
  exports.SHEET_NAME_PREFIX = 'Sheet: ';
60
+ exports.FOE_NAME_PREFIX = 'Foe: ';
54
61
  exports.PARTY_STATUS_ARTIFACT = 'Party Status';
55
62
  exports.ENCOUNTER_ARTIFACT = 'Encounter';
56
63
  const STATE_FENCE_TAG = 'briyah-state';
@@ -77,6 +84,20 @@ function characterNameFromArtifact(artifactName) {
77
84
  function isSheetArtifact(artifactName) {
78
85
  return artifactName.startsWith(exports.SHEET_NAME_PREFIX);
79
86
  }
87
+ function foeArtifactName(foeName) {
88
+ return `${exports.FOE_NAME_PREFIX}${foeName}`;
89
+ }
90
+ function foeNameFromArtifact(artifactName) {
91
+ return artifactName.startsWith(exports.FOE_NAME_PREFIX)
92
+ ? artifactName.slice(exports.FOE_NAME_PREFIX.length)
93
+ : artifactName;
94
+ }
95
+ function isFoeArtifact(artifactName) {
96
+ return artifactName.startsWith(exports.FOE_NAME_PREFIX);
97
+ }
98
+ function combatantArtifactName(state) {
99
+ return state.foe ? foeArtifactName(state.name) : sheetArtifactName(state.name);
100
+ }
80
101
  function parseSheet(body) {
81
102
  const block = extractStateBlock(body);
82
103
  if (block === null) {
@@ -147,6 +168,8 @@ function normalizeState(raw) {
147
168
  saveProf: toStringArray(raw.saveProf),
148
169
  skillProf: toStringArray(raw.skillProf).map((s) => s.toLowerCase()),
149
170
  skillExp: toStringArray(raw.skillExp).map((s) => s.toLowerCase()),
171
+ toolProf: toStringArray(raw.toolProf),
172
+ toolExp: toStringArray(raw.toolExp),
150
173
  hp: {
151
174
  max: Math.max(Number(raw.hp?.max) || 1, 1),
152
175
  cur: Number.isFinite(Number(raw.hp?.cur)) ? Number(raw.hp.cur) : Number(raw.hp?.max) || 1,
@@ -175,10 +198,26 @@ function normalizeState(raw) {
175
198
  inv: normalizeInventory(raw.inv),
176
199
  coin: normalizeCoin(raw.coin),
177
200
  xp: Math.max(Number(raw.xp) || 0, 0),
201
+ foe: raw.foe === true ? true : undefined,
202
+ saveBonus: normalizeSaveBonus(raw.saveBonus),
178
203
  };
179
204
  state.hp.cur = clamp(state.hp.cur, 0, state.hp.max);
180
205
  return state;
181
206
  }
207
+ function normalizeSaveBonus(raw) {
208
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw))
209
+ return undefined;
210
+ const out = {};
211
+ for (const ability of srd_1.ABILITIES) {
212
+ const value = Number(raw[ability]);
213
+ if (Number.isFinite(value))
214
+ out[ability] = value;
215
+ }
216
+ return Object.keys(out).length > 0 ? out : undefined;
217
+ }
218
+ function sheetFieldNames() {
219
+ return Object.keys(normalizeState({})).sort();
220
+ }
182
221
  function collectWarnings(raw, normalized) {
183
222
  const warnings = [];
184
223
  const rawCur = Number(raw?.hp?.cur);
@@ -313,7 +352,42 @@ function trimNotes(notes) {
313
352
  function signed(value) {
314
353
  return value >= 0 ? `+${value}` : `${value}`;
315
354
  }
355
+ function renderFoeSummary(state) {
356
+ const lines = [`# ${state.name}`];
357
+ const dead = state.deathSaves.f >= 3 || state.hp.cur <= 0;
358
+ lines.push(`**HP ${state.hp.cur}/${state.hp.max}**${state.hp.temp > 0 ? ` +${state.hp.temp} temp` : ''}` +
359
+ ` | **AC ${state.ac}** | **Speed ${state.speed} ft**${dead ? ' | **DEAD**' : ''}`);
360
+ lines.push(srd_1.ABILITIES.map((ability) => `${ability.toUpperCase()} ${state.abil[ability]} (${signed(rules.abilityModifier(state, ability))})`).join(' · '));
361
+ const saves = srd_1.ABILITIES.filter((ability) => state.saveBonus?.[ability] !== undefined);
362
+ if (saves.length > 0) {
363
+ lines.push('**Saves:** ' +
364
+ saves.map((a) => `${a.toUpperCase()} ${signed(state.saveBonus[a])}`).join(' · '));
365
+ }
366
+ if (state.attacks.length > 0) {
367
+ lines.push('**Attacks:** ' +
368
+ state.attacks
369
+ .map((attack) => {
370
+ const type = attack.type ? ` ${attack.type}` : '';
371
+ const range = attack.range ? `, ${attack.range}` : '';
372
+ return `${attack.n} ${signed(attack.atk)} (${attack.dmg}${type}${range})`;
373
+ })
374
+ .join(' · '));
375
+ }
376
+ if (state.resist.length > 0)
377
+ lines.push(`**Resistant to:** ${state.resist.join(', ')}`);
378
+ if (state.immune.length > 0)
379
+ lines.push(`**Immune to:** ${state.immune.join(', ')}`);
380
+ if (state.vuln.length > 0)
381
+ lines.push(`**Vulnerable to:** ${state.vuln.join(', ')}`);
382
+ if (state.cond.length > 0) {
383
+ lines.push('**Conditions:** ' +
384
+ state.cond.map((c) => (c.dur ? `${c.n} (${c.dur})` : c.n)).join(', '));
385
+ }
386
+ return lines.join('\n');
387
+ }
316
388
  function renderSummary(state) {
389
+ if (state.foe)
390
+ return renderFoeSummary(state);
317
391
  const level = rules.totalLevel(state);
318
392
  const prof = rules.proficiencyBonus(state);
319
393
  const classLine = state.class
@@ -354,6 +428,13 @@ function renderSummary(state) {
354
428
  .map((skill) => `${titleCase(skill)} ${signed(rules.skillModifier(state, skill))}`)
355
429
  .join(' · '));
356
430
  }
431
+ const tools = [...new Set([...(state.toolProf || []), ...(state.toolExp || [])])];
432
+ if (tools.length > 0) {
433
+ lines.push('**Tools (proficient):** ' +
434
+ tools
435
+ .map((tool) => `${tool}${(0, kits_1.hasToolExpertise)(state, tool) ? '*' : ''}`)
436
+ .join(' · '));
437
+ }
357
438
  if (state.attacks.length > 0) {
358
439
  lines.push('**Attacks:** ' +
359
440
  state.attacks
@@ -7,6 +7,7 @@ const dice_tools_1 = require("./tools/dice.tools");
7
7
  const state_tools_1 = require("./tools/state.tools");
8
8
  const sheet_tools_1 = require("./tools/sheet.tools");
9
9
  const world_tools_1 = require("./tools/world.tools");
10
+ const encounter_tool_1 = require("./tools/encounter.tool");
10
11
  const monster_tool_1 = require("./tools/monster.tool");
11
12
  const item_tool_1 = require("./tools/item.tool");
12
13
  const spell_tool_1 = require("./tools/spell.tool");
@@ -14,6 +15,7 @@ function dnd5eTools() {
14
15
  return [
15
16
  dice_tools_1.rollDiceTool,
16
17
  dice_tools_1.rollInitiativeTool,
18
+ encounter_tool_1.encounterTool,
17
19
  check_tool_1.checkTool,
18
20
  state_tools_1.applyHpTool,
19
21
  state_tools_1.restTool,
@@ -39,12 +39,14 @@ const dice_1 = require("../engine/dice");
39
39
  const rules = __importStar(require("../engine/rules"));
40
40
  const sheet_1 = require("../engine/sheet");
41
41
  const character_1 = require("../engine/character");
42
+ const kits_1 = require("../engine/kits");
42
43
  const shared_1 = require("./shared");
43
44
  const BATCH_EXAMPLE = '[{"character":"Thalia","kind":"save","subject":"dex","dc":15},{"character":"Dorn","kind":"save","subject":"dex","dc":15}]';
44
45
  const MAX_BATCH = 12;
46
+ const DEFAULT_TOOL_ABILITY = 'dex';
45
47
  exports.checkTool = {
46
48
  name: 'check',
47
- description: 'Make one or more d20 rolls for a character using the modifiers on their sheet. "kind" is skill, ability, save, attack, initiative, or death (a death saving throw). "subject" names what is rolled: a skill (stealth), an ability (dex), or an attack listed on the sheet (Longbow). Give "dc" if you know the target number; omit it to get the raw total and judge for yourself. "mode" is normal, advantage or disadvantage — the character\'s own conditions and exhaustion are applied on top of what you ask for. "bonus" is any situational modifier. For an attack it also rolls damage, doubling the dice on a critical hit. Death saving throws are recorded on the sheet, and three successes or failures are reported. To make several rolls at once — a group saving throw, two attacks in a round — set "batch" to a JSON array of objects using the same keys and leave the other parameters out: ' +
49
+ description: 'Make one or more d20 rolls for a character using the modifiers on their sheet. "kind" is skill, ability, save, attack, initiative, tool, or death (a death saving throw). "subject" names what is rolled: a skill (stealth), an ability (dex), a tool (thieves\' tools), or an attack listed on the sheet (Longbow). For a tool check the proficiency bonus is added only if the character actually has that tool proficiency, and doubled for expertise; "ability" says which ability the check uses and defaults to dex, so pass it for anything that is not a Dexterity check — "ability":"int" to identify a poison with a poisoner\'s kit. Give "dc" if you know the target number; omit it to get the raw total and judge for yourself. "mode" is normal, advantage or disadvantage — the character\'s own conditions and exhaustion are applied on top of what you ask for. "bonus" is any situational modifier. For an attack it also rolls damage, doubling the dice on a critical hit. Death saving throws are recorded on the sheet, and three successes or failures are reported. To make several rolls at once — a group saving throw, two attacks in a round — set "batch" to a JSON array of objects using the same keys and leave the other parameters out: ' +
48
50
  BATCH_EXAMPLE +
49
51
  '. One batched call costs one turn instead of several.',
50
52
  parameters: [
@@ -52,13 +54,19 @@ exports.checkTool = {
52
54
  {
53
55
  name: 'kind',
54
56
  type: 'string',
55
- description: 'skill, ability, save, attack, initiative, or death',
57
+ description: 'skill, ability, save, attack, initiative, tool, or death',
56
58
  required: false,
57
59
  },
58
60
  {
59
61
  name: 'subject',
60
62
  type: 'string',
61
- description: 'The skill, ability, or attack name being rolled',
63
+ description: 'The skill, ability, tool, or attack name being rolled',
64
+ required: false,
65
+ },
66
+ {
67
+ name: 'ability',
68
+ type: 'string',
69
+ description: 'For a tool check, which ability it uses; defaults to dex',
62
70
  required: false,
63
71
  },
64
72
  { name: 'dc', type: 'number', description: 'The target number, if you know it', required: false },
@@ -118,6 +126,7 @@ function collectRequests(args) {
118
126
  dc: entry.dc !== undefined && entry.dc !== null && entry.dc !== '' ? (0, coerce_1.int)(entry.dc, 'dc') : undefined,
119
127
  mode: entry.mode !== undefined ? (0, coerce_1.str)(entry.mode, 'mode') : undefined,
120
128
  bonus: entry.bonus !== undefined && entry.bonus !== '' ? (0, coerce_1.int)(entry.bonus, 'bonus', 0) : 0,
129
+ ability: entry.ability !== undefined ? (0, coerce_1.str)(entry.ability, 'ability') : undefined,
121
130
  };
122
131
  });
123
132
  }
@@ -134,10 +143,13 @@ function normalizeKind(raw) {
134
143
  initiative: 'initiative',
135
144
  death: 'death',
136
145
  'death save': 'death',
146
+ tool: 'tool',
147
+ tools: 'tool',
148
+ 'tool check': 'tool',
137
149
  };
138
150
  const kind = known[key];
139
151
  if (!kind) {
140
- throw new Error(`"${raw}" is not a kind of roll. Use skill, ability, save, attack, initiative, or death.`);
152
+ throw new Error(`"${raw}" is not a kind of roll. Use skill, ability, save, attack, initiative, tool, or death.`);
141
153
  }
142
154
  return kind;
143
155
  }
@@ -160,7 +172,9 @@ function resolveCheck(room, request) {
160
172
  const kind = request.kind === 'attack' ? 'attack' : request.kind === 'save' ? 'save' : 'check';
161
173
  const subject = kind === 'save'
162
174
  ? rules.resolveAbility(request.subject || '')
163
- : (request.subject || '').trim().toLowerCase();
175
+ : request.kind === 'tool'
176
+ ? toolAbility(request)
177
+ : (request.subject || '').trim().toLowerCase();
164
178
  const effects = rules.conditionEffects(state, kind, subject);
165
179
  if (effects.autoFail) {
166
180
  const outcome = {
@@ -220,8 +234,12 @@ function resolveCheck(room, request) {
220
234
  outcome.passed = roll.total >= request.dc;
221
235
  }
222
236
  outcome.detail = describeOutcome(outcome, roll.kept[0]);
237
+ if (resolved.note)
238
+ outcome.note = resolved.note;
223
239
  if (sheet.warnings.length > 0) {
224
- outcome.note = `Sheet warnings: ${sheet.warnings.join(' ')}`;
240
+ outcome.note = [outcome.note, `Sheet warnings: ${sheet.warnings.join(' ')}`]
241
+ .filter(Boolean)
242
+ .join(' ');
225
243
  }
226
244
  if (rules.isIncapacitated(state) && request.kind === 'attack') {
227
245
  outcome.note = [outcome.note, `${state.name} is incapacitated and should not be attacking.`]
@@ -230,6 +248,16 @@ function resolveCheck(room, request) {
230
248
  }
231
249
  return outcome;
232
250
  }
251
+ function toolAbility(request) {
252
+ const named = (request.ability || '').trim();
253
+ if (!named)
254
+ return DEFAULT_TOOL_ABILITY;
255
+ const ability = rules.resolveAbility(named);
256
+ if (!ability) {
257
+ throw new Error(`"${named}" is not an ability. A tool check uses str, dex, con, int, wis or cha.`);
258
+ }
259
+ return ability;
260
+ }
233
261
  function resolveModifier(state, request) {
234
262
  const subject = (request.subject || '').trim();
235
263
  if (request.kind === 'initiative') {
@@ -250,6 +278,23 @@ function resolveModifier(state, request) {
250
278
  attack: { dmg: attack.dmg, type: attack.type },
251
279
  };
252
280
  }
281
+ if (request.kind === 'tool') {
282
+ if (!subject) {
283
+ throw new Error('A tool check needs a "subject" naming the tool, e.g. "thieves\' tools".');
284
+ }
285
+ const ability = toolAbility(request);
286
+ const tool = (0, kits_1.canonicalToolName)(subject);
287
+ const resolved = rules.toolCheckModifier(state, tool, ability);
288
+ return {
289
+ modifier: resolved.modifier,
290
+ label: `${tool} (${ability.toUpperCase()})`,
291
+ note: resolved.proficient
292
+ ? resolved.expertise
293
+ ? `${state.name} has expertise with ${tool}, so the proficiency bonus is doubled.`
294
+ : undefined
295
+ : `${state.name} is not proficient with ${tool}, so no proficiency bonus was added. The roll is legal without it.`,
296
+ };
297
+ }
253
298
  if (request.kind === 'skill') {
254
299
  const skill = subject.toLowerCase();
255
300
  if (!rules.skillNames().includes(skill)) {
@@ -4,6 +4,7 @@ exports.rollInitiativeTool = exports.rollDiceTool = void 0;
4
4
  const coerce_1 = require("../engine/coerce");
5
5
  const dice_1 = require("../engine/dice");
6
6
  const sheet_1 = require("../engine/sheet");
7
+ const encounter_1 = require("../engine/encounter");
7
8
  const shared_1 = require("./shared");
8
9
  const coerce_2 = require("../engine/coerce");
9
10
  exports.rollDiceTool = {
@@ -91,20 +92,29 @@ exports.rollInitiativeTool = {
91
92
  roll: entry.roll.kept[0],
92
93
  modifier: entry.modifier,
93
94
  }));
95
+ const cleared = (0, shared_1.clearFoes)(room, order.map((entry) => entry.name));
94
96
  const encounterName = args.encounter_name ? (0, coerce_1.str)(args.encounter_name, 'encounter_name') : 'Encounter';
95
- room.update(sheet_1.ENCOUNTER_ARTIFACT, () => [
96
- `# ${encounterName}`,
97
- '',
98
- 'Round 1. Initiative order:',
99
- '',
100
- ...order.map((e) => `${e.position}. ${e.name} — ${e.initiative}`),
101
- '',
102
- ].join('\n'), { viewers: room.agentNicknames });
97
+ const tracked = (0, shared_1.listFoeNames)(room);
98
+ const isFoe = new Set(tracked.map((name) => (0, coerce_2.nameKey)(name)));
99
+ const encounter = (0, encounter_1.newEncounter)(encounterName, order.map((entry) => ({
100
+ name: entry.name,
101
+ init: entry.initiative,
102
+ foe: isFoe.has((0, coerce_2.nameKey)(entry.name)) ? true : undefined,
103
+ })));
104
+ room.update(sheet_1.ENCOUNTER_ARTIFACT, () => (0, encounter_1.renderEncounter)(encounter), {
105
+ viewers: room.agentNicknames,
106
+ transient: true,
107
+ });
103
108
  return {
104
109
  encounter: encounterName,
105
110
  order,
106
111
  summary: order.map((e) => `${e.name} ${e.initiative}`).join(', '),
107
- note: `Initiative order written to the "${sheet_1.ENCOUNTER_ARTIFACT}" artifact. Call on each combatant in this order.`,
112
+ trackedMonsters: tracked.length > 0 ? tracked : undefined,
113
+ clearedFromLastFight: cleared.length > 0 ? cleared : undefined,
114
+ note: `Round 1, ${order[0]?.name} is up. The order is stored in the "${sheet_1.ENCOUNTER_ARTIFACT}" artifact — call encounter with action "next" at the end of each turn rather than tracking it yourself.` +
115
+ (tracked.length > 0
116
+ ? ` Hit points are tracked for ${tracked.join(', ')} — use apply_hp on them by name rather than counting in your head.`
117
+ : ' No monsters are being tracked: place them with stat_block\'s "place" parameter so their hit points are kept for you.'),
108
118
  };
109
119
  },
110
120
  };
@@ -0,0 +1,2 @@
1
+ import { NativeToolDefinition } from '../../../native-tool.types';
2
+ export declare const encounterTool: NativeToolDefinition;
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.encounterTool = void 0;
4
+ const coerce_1 = require("../engine/coerce");
5
+ const encounter_1 = require("../engine/encounter");
6
+ const sheet_1 = require("../engine/sheet");
7
+ const shared_1 = require("./shared");
8
+ function isDown(room, combatant) {
9
+ if (!combatant.foe)
10
+ return false;
11
+ const artifact = room.get((0, sheet_1.foeArtifactName)(combatant.name));
12
+ if (!artifact)
13
+ return true;
14
+ try {
15
+ return (0, sheet_1.parseSheet)(artifact.body).hp.cur <= 0;
16
+ }
17
+ catch {
18
+ return false;
19
+ }
20
+ }
21
+ function downNames(room, state) {
22
+ return state.order.filter((c) => isDown(room, c)).map((c) => c.name);
23
+ }
24
+ function describe(room, state) {
25
+ const up = (0, encounter_1.currentCombatant)(state);
26
+ return {
27
+ encounter: state.name,
28
+ round: state.round,
29
+ turn: up?.name,
30
+ order: state.order.map((c, i) => ({
31
+ position: i + 1,
32
+ name: c.name,
33
+ initiative: c.init,
34
+ acted: i < state.turn,
35
+ up: i === state.turn,
36
+ down: isDown(room, c) || undefined,
37
+ })),
38
+ };
39
+ }
40
+ exports.encounterTool = {
41
+ 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.',
43
+ parameters: [
44
+ {
45
+ name: 'action',
46
+ type: 'string',
47
+ description: 'status, next, remove, or end',
48
+ required: false,
49
+ },
50
+ {
51
+ name: 'combatant',
52
+ type: 'string',
53
+ description: 'For "remove", who to take out of the order',
54
+ required: false,
55
+ },
56
+ ],
57
+ async handler(args, helpers) {
58
+ const room = (0, shared_1.requireRoom)(helpers);
59
+ const action = (0, coerce_1.str)(args.action, 'action', 'status').toLowerCase().trim();
60
+ let state;
61
+ try {
62
+ state = (0, encounter_1.parseEncounter)(room.get(sheet_1.ENCOUNTER_ARTIFACT)?.body);
63
+ }
64
+ catch (e) {
65
+ if (e instanceof encounter_1.EncounterError) {
66
+ return {
67
+ applied: false,
68
+ violation: e.violation,
69
+ message: e.message,
70
+ options: ['Call roll_initiative to start a fresh encounter'],
71
+ };
72
+ }
73
+ throw e;
74
+ }
75
+ if (action === 'end') {
76
+ const cleared = (0, shared_1.clearFoes)(room);
77
+ room.remove(sheet_1.ENCOUNTER_ARTIFACT);
78
+ return {
79
+ ended: true,
80
+ clearedMonsters: cleared.length > 0 ? cleared : undefined,
81
+ note: 'The encounter is over. Report the outcome to the room leader and stop.',
82
+ };
83
+ }
84
+ if (!state) {
85
+ return {
86
+ applied: false,
87
+ violation: 'no_encounter',
88
+ message: 'No fight is running.',
89
+ options: ['Call roll_initiative to start one'],
90
+ };
91
+ }
92
+ if (action === 'status') {
93
+ return describe(room, state);
94
+ }
95
+ if (action === 'remove') {
96
+ const name = (0, coerce_1.str)(args.combatant, 'combatant');
97
+ if (!name) {
98
+ throw new Error('Removing a combatant needs a "combatant" name.');
99
+ }
100
+ if (!(0, encounter_1.removeCombatant)(state, name)) {
101
+ return {
102
+ applied: false,
103
+ violation: 'not_in_encounter',
104
+ message: `"${name}" is not in the initiative order.`,
105
+ options: [`In the order: ${state.order.map((c) => c.name).join(', ')}`],
106
+ };
107
+ }
108
+ writeEncounter(room, state);
109
+ return { removed: name, ...describe(room, state) };
110
+ }
111
+ if (action !== 'next') {
112
+ throw new Error(`"${action}" is not an action. Use status, next, remove, or end.`);
113
+ }
114
+ 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 }));
118
+ return {
119
+ ...describe(room, state),
120
+ newRound: state.round > before ? state.round : undefined,
121
+ skipped: skipped.length > 0 ? skipped : undefined,
122
+ monstersStanding: remaining.length,
123
+ note: remaining.length === 0
124
+ ? 'No monster is still standing. If the fight is over, call encounter with action "end" and report the outcome to the room leader.'
125
+ : `${combatant?.name} is up.`,
126
+ };
127
+ },
128
+ };
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
+ }
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.statBlockTool = void 0;
4
4
  const coerce_1 = require("../engine/coerce");
5
- const dice_1 = require("../engine/dice");
5
+ const foes_1 = require("../engine/foes");
6
6
  const bestiary_1 = require("../engine/bestiary");
7
7
  const srd_1 = require("../data/srd");
8
8
  const coerce_2 = require("../engine/coerce");
@@ -32,6 +32,12 @@ exports.statBlockTool = {
32
32
  description: 'How many of this creature are present; returns a rolled hit point total for each',
33
33
  required: false,
34
34
  },
35
+ {
36
+ name: 'place',
37
+ type: 'boolean',
38
+ description: 'Put them in the fight as tracked combatants, named Goblin A, Goblin B and so on. Their hit points are then kept for you: roll their attacks with check, apply damage with apply_hp, and set conditions with conditions, all by name. Do this at the start of every encounter.',
39
+ required: false,
40
+ },
35
41
  {
36
42
  name: 'filter',
37
43
  type: 'string',
@@ -96,7 +102,7 @@ exports.statBlockTool = {
96
102
  block: compact(resolved.block),
97
103
  statBlock: (0, bestiary_1.describeMonster)(resolved.block),
98
104
  attribution: resolved.source === 'srd' ? srd_1.SRD_ATTRIBUTION : undefined,
99
- ...instanceHitPoints(resolved.block, args.count),
105
+ ...instanceHitPoints(helpers.room, resolved.block, args.count, (0, coerce_1.bool)(args.place)),
100
106
  };
101
107
  },
102
108
  };
@@ -117,26 +123,38 @@ function define(room, creature, raw, campaign) {
117
123
  note: `Stored in the "${bestiary_1.BESTIARY_ARTIFACT}" artifact. Look it up with stat_block from now on; it overrides any built-in creature of the same name.`,
118
124
  };
119
125
  }
120
- function instanceHitPoints(block, count) {
121
- if (count === undefined || count === null || count === '')
122
- return {};
126
+ function instanceHitPoints(room, block, count, place) {
127
+ if (count === undefined || count === null || count === '') {
128
+ if (!place)
129
+ return {};
130
+ count = 1;
131
+ }
123
132
  const wanted = (0, coerce_1.int)(count, 'count', 1);
124
133
  if (wanted < 1)
125
134
  return {};
126
135
  if (wanted > MAX_INSTANCES) {
127
136
  throw new Error(`At most ${MAX_INSTANCES} of one creature per call; ${wanted} were asked for. Run them as two groups.`);
128
137
  }
129
- const labels = 'ABCDEFGHIJKL';
130
- const instances = [];
131
- for (let i = 0; i < wanted; i++) {
132
- const hp = block.hpDice
133
- ? Math.max((0, dice_1.rollOne)(block.hpDice, dice_1.defaultRng).total, 1)
134
- : block.hp;
135
- instances.push({ name: `${block.name} ${labels[i]}`, hp });
138
+ const names = (0, foes_1.foeNames)(block.name, wanted);
139
+ const instances = names.map((name) => ({ name, hp: (0, foes_1.rollFoeHitPoints)(block) }));
140
+ if (!place) {
141
+ return {
142
+ instances,
143
+ instanceNote: 'These totals are not stored anywhere. Pass place=true to put them in the fight, and then check, apply_hp and conditions all work on them by name.',
144
+ };
145
+ }
146
+ if (!room) {
147
+ throw new Error('Placing combatants needs a room: run this from a room conversation rather than the Tools test panel.');
148
+ }
149
+ for (const instance of instances) {
150
+ const state = (0, foes_1.buildFoe)(block, instance.name, instance.hp, room.caller.nickname);
151
+ (0, shared_1.writeNewSheet)(room, state, '', true);
136
152
  }
137
153
  return {
138
154
  instances,
139
- instanceNote: 'These totals are not stored anywhere. Track them in your situation line as the fight runs.',
155
+ placed: names,
156
+ placeNote: `In the fight now. Roll their attacks with check (character: "${names[0]}", kind: "attack", subject: "${block.attacks?.[0]?.n || 'its attack'}", dc: the target's AC) — ` +
157
+ 'it compares against the armour class for you. Apply damage to them with apply_hp, and set conditions with conditions. Their hit points are tracked for you; do not carry them in your situation line.',
140
158
  };
141
159
  }
142
160
  function compact(block) {
@@ -18,6 +18,8 @@ export interface LoadedSheet {
18
18
  warnings: string[];
19
19
  }
20
20
  export declare function listCharacterNames(room: ToolRoomAccess): string[];
21
+ export declare function listFoeNames(room: ToolRoomAccess): string[];
22
+ export declare function clearFoes(room: ToolRoomAccess, keep?: string[]): string[];
21
23
  export declare function loadSheet(room: ToolRoomAccess, name: string): LoadedSheet;
22
24
  export declare function mutateSheet(room: ToolRoomAccess, name: string, mutate: (sheet: LoadedSheet) => MutationResult): {
23
25
  result: MutationResult;