@archivist-gg/dnd5e 0.1.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 (322) hide show
  1. package/LICENSE +21 -0
  2. package/LICENSES/SRD.md +37 -0
  3. package/README.md +65 -0
  4. package/dist/armor/armor.codec.d.ts +10 -0
  5. package/dist/armor/armor.codec.js +8 -0
  6. package/dist/armor/armor.entity-type.d.ts +2 -0
  7. package/dist/armor/armor.parser.d.ts +3 -0
  8. package/dist/armor/armor.parser.js +7 -0
  9. package/dist/armor/armor.schema.d.ts +25 -0
  10. package/dist/armor/armor.schema.js +6 -0
  11. package/dist/armor/armor.types.d.ts +26 -0
  12. package/dist/armor/armor.types.js +0 -0
  13. package/dist/background/background.codec.d.ts +9 -0
  14. package/dist/background/background.codec.js +11 -0
  15. package/dist/background/background.entity-type.d.ts +2 -0
  16. package/dist/background/background.parser.d.ts +3 -0
  17. package/dist/background/background.parser.js +10 -0
  18. package/dist/background/background.schema.d.ts +74 -0
  19. package/dist/background/background.schema.js +9 -0
  20. package/dist/background/background.types.d.ts +52 -0
  21. package/dist/background/background.types.js +0 -0
  22. package/dist/chunk-24GFQU7T.js +18 -0
  23. package/dist/chunk-3DZ74AKK.js +28 -0
  24. package/dist/chunk-3TM34RSJ.js +23 -0
  25. package/dist/chunk-3TRGRSCH.js +8 -0
  26. package/dist/chunk-4C2KOKLF.js +185 -0
  27. package/dist/chunk-4F6AIZ36.js +19 -0
  28. package/dist/chunk-4SSDYJS2.js +86 -0
  29. package/dist/chunk-4TIJKN6O.js +37 -0
  30. package/dist/chunk-537BHVSH.js +18 -0
  31. package/dist/chunk-5INR4NSL.js +18 -0
  32. package/dist/chunk-5XUXXAQJ.js +30 -0
  33. package/dist/chunk-656QCX4U.js +22 -0
  34. package/dist/chunk-66XXW2Z2.js +133 -0
  35. package/dist/chunk-6NK2MUD3.js +114 -0
  36. package/dist/chunk-6PXE7T7C.js +79 -0
  37. package/dist/chunk-7P65Q426.js +158 -0
  38. package/dist/chunk-A7T5L7SS.js +83 -0
  39. package/dist/chunk-AFKTJXRA.js +39 -0
  40. package/dist/chunk-B7UXKNLD.js +46 -0
  41. package/dist/chunk-BAXWWGFJ.js +45 -0
  42. package/dist/chunk-BH6AMZVY.js +25 -0
  43. package/dist/chunk-CDW7R2QT.js +62 -0
  44. package/dist/chunk-DABBCYTT.js +68 -0
  45. package/dist/chunk-DC74TZNA.js +46 -0
  46. package/dist/chunk-DNAJRMNN.js +68 -0
  47. package/dist/chunk-DRNZJNJP.js +19 -0
  48. package/dist/chunk-FEOB24KP.js +18 -0
  49. package/dist/chunk-FFULAF2P.js +63 -0
  50. package/dist/chunk-FUK7QSN5.js +19 -0
  51. package/dist/chunk-GIOH5JB5.js +19 -0
  52. package/dist/chunk-GJOI2GHP.js +25 -0
  53. package/dist/chunk-GZ46OVGZ.js +31 -0
  54. package/dist/chunk-HCP3GMHS.js +44 -0
  55. package/dist/chunk-IDTDACM6.js +19 -0
  56. package/dist/chunk-IKSMX4TN.js +0 -0
  57. package/dist/chunk-IXZXFFFW.js +269 -0
  58. package/dist/chunk-J2RYSZMQ.js +16 -0
  59. package/dist/chunk-JEYQU3JT.js +36 -0
  60. package/dist/chunk-LSLSG67V.js +31 -0
  61. package/dist/chunk-LWFTHJIE.js +24 -0
  62. package/dist/chunk-MDEJHMKK.js +52 -0
  63. package/dist/chunk-N2JE7BWL.js +81 -0
  64. package/dist/chunk-NAEPSZAM.js +88 -0
  65. package/dist/chunk-NXR3BD2V.js +90 -0
  66. package/dist/chunk-PKC77VZP.js +18 -0
  67. package/dist/chunk-PMADYMUI.js +19 -0
  68. package/dist/chunk-PTXBIDG7.js +63 -0
  69. package/dist/chunk-PZOWBI3B.js +49 -0
  70. package/dist/chunk-QQ5W2AZP.js +515 -0
  71. package/dist/chunk-QS5L5YTJ.js +24 -0
  72. package/dist/chunk-QYZV2MQA.js +97 -0
  73. package/dist/chunk-R2ZV233X.js +233 -0
  74. package/dist/chunk-RAWJTA45.js +271 -0
  75. package/dist/chunk-RSDRMH54.js +18 -0
  76. package/dist/chunk-RVYYKYFL.js +18 -0
  77. package/dist/chunk-SSXBYF3P.js +18 -0
  78. package/dist/chunk-TJCNX6UZ.js +521 -0
  79. package/dist/chunk-TZK36BU7.js +38 -0
  80. package/dist/chunk-UC4FE5X3.js +65 -0
  81. package/dist/chunk-WP2CX2JO.js +235 -0
  82. package/dist/chunk-WYGD2UGN.js +14 -0
  83. package/dist/chunk-XJNECUPT.js +31 -0
  84. package/dist/chunk-XURS6Q6Q.js +127 -0
  85. package/dist/chunk-Y4I74YEG.js +33 -0
  86. package/dist/chunk-Z4TL2V7S.js +18 -0
  87. package/dist/chunk-Z6GXV2GO.js +121 -0
  88. package/dist/chunk-ZLG6FQFB.js +237 -0
  89. package/dist/chunk-ZMR77DDL.js +18 -0
  90. package/dist/class/class.codec.d.ts +10 -0
  91. package/dist/class/class.codec.js +15 -0
  92. package/dist/class/class.entity-type.d.ts +2 -0
  93. package/dist/class/class.parser.d.ts +3 -0
  94. package/dist/class/class.parser.js +14 -0
  95. package/dist/class/class.schema.d.ts +202 -0
  96. package/dist/class/class.schema.js +13 -0
  97. package/dist/class/class.slug.d.ts +11 -0
  98. package/dist/class/class.slug.js +8 -0
  99. package/dist/class/class.types.d.ts +74 -0
  100. package/dist/class/class.types.js +0 -0
  101. package/dist/data-srd/index.generated.d.ts +7 -0
  102. package/dist/data-srd/index.generated.js +146 -0
  103. package/dist/dnd/constants.d.ts +16 -0
  104. package/dist/dnd/constants.js +36 -0
  105. package/dist/dnd/formula-tags.d.ts +16 -0
  106. package/dist/dnd/formula-tags.js +119 -0
  107. package/dist/dnd/math.d.ts +24 -0
  108. package/dist/dnd/math.js +35 -0
  109. package/dist/dnd/prose-tags.d.ts +16 -0
  110. package/dist/dnd/prose-tags.js +18 -0
  111. package/dist/dnd/resource-die.d.ts +6 -0
  112. package/dist/dnd/resource-die.js +17 -0
  113. package/dist/dnd/resource-formula.d.ts +41 -0
  114. package/dist/dnd/resource-formula.js +159 -0
  115. package/dist/dnd/srd-tag-converter.d.ts +44 -0
  116. package/dist/dnd/srd-tag-converter.js +12 -0
  117. package/dist/dnd/tag-grammar.d.ts +19 -0
  118. package/dist/dnd/tag-grammar.js +12 -0
  119. package/dist/encounter/encounter.ai-schema.d.ts +29 -0
  120. package/dist/encounter/encounter.ai-schema.js +8 -0
  121. package/dist/encounter/encounter.entity-type.d.ts +2 -0
  122. package/dist/encounter/encounter.generatable.d.ts +2 -0
  123. package/dist/entities/base-item-resolver.d.ts +21 -0
  124. package/dist/entities/base-item-resolver.js +9 -0
  125. package/dist/entities/slug.d.ts +5 -0
  126. package/dist/entities/slug.js +6 -0
  127. package/dist/feat/feat.codec.d.ts +9 -0
  128. package/dist/feat/feat.codec.js +10 -0
  129. package/dist/feat/feat.entity-type.d.ts +2 -0
  130. package/dist/feat/feat.parser.d.ts +3 -0
  131. package/dist/feat/feat.parser.js +9 -0
  132. package/dist/feat/feat.schema.d.ts +194 -0
  133. package/dist/feat/feat.schema.js +8 -0
  134. package/dist/feat/feat.types.d.ts +42 -0
  135. package/dist/feat/feat.types.js +0 -0
  136. package/dist/index.d.ts +12 -0
  137. package/dist/index.js +139149 -0
  138. package/dist/inline-tag-parser.d.ts +11 -0
  139. package/dist/inline-tag-parser.js +6 -0
  140. package/dist/item/item.actions-map.d.ts +41 -0
  141. package/dist/item/item.actions-map.js +85 -0
  142. package/dist/item/item.ai-schema.d.ts +35 -0
  143. package/dist/item/item.ai-schema.js +6 -0
  144. package/dist/item/item.attunement.d.ts +18 -0
  145. package/dist/item/item.attunement.js +12 -0
  146. package/dist/item/item.bonuses.d.ts +2 -0
  147. package/dist/item/item.bonuses.js +7 -0
  148. package/dist/item/item.codec.d.ts +3 -0
  149. package/dist/item/item.codec.js +8 -0
  150. package/dist/item/item.conditions.d.ts +10 -0
  151. package/dist/item/item.conditions.js +8 -0
  152. package/dist/item/item.conditions.types.d.ts +28 -0
  153. package/dist/item/item.conditions.types.js +0 -0
  154. package/dist/item/item.enrichment.d.ts +4 -0
  155. package/dist/item/item.enrichment.js +9 -0
  156. package/dist/item/item.entity-type.d.ts +2 -0
  157. package/dist/item/item.generatable.d.ts +2 -0
  158. package/dist/item/item.parser.d.ts +3 -0
  159. package/dist/item/item.parser.js +7 -0
  160. package/dist/item/item.schema.d.ts +174 -0
  161. package/dist/item/item.schema.js +8 -0
  162. package/dist/item/item.types.d.ts +108 -0
  163. package/dist/item/item.types.js +0 -0
  164. package/dist/monster/monster.ai-schema.d.ts +67 -0
  165. package/dist/monster/monster.ai-schema.js +6 -0
  166. package/dist/monster/monster.codec.d.ts +13 -0
  167. package/dist/monster/monster.enrichment.d.ts +10 -0
  168. package/dist/monster/monster.enrichment.js +19 -0
  169. package/dist/monster/monster.entity-type.d.ts +2 -0
  170. package/dist/monster/monster.generatable.d.ts +2 -0
  171. package/dist/monster/monster.parser.d.ts +3 -0
  172. package/dist/monster/monster.parser.js +6 -0
  173. package/dist/monster/monster.resolve.d.ts +10 -0
  174. package/dist/monster/monster.types.d.ts +29 -0
  175. package/dist/monster/monster.types.js +1 -0
  176. package/dist/npc/npc.ai-schema.d.ts +6 -0
  177. package/dist/npc/npc.entity-type.d.ts +2 -0
  178. package/dist/npc/npc.generatable.d.ts +2 -0
  179. package/dist/optional-feature/optional-feature.codec.d.ts +14 -0
  180. package/dist/optional-feature/optional-feature.codec.js +11 -0
  181. package/dist/optional-feature/optional-feature.entity-type.d.ts +2 -0
  182. package/dist/optional-feature/optional-feature.parser.d.ts +3 -0
  183. package/dist/optional-feature/optional-feature.parser.js +10 -0
  184. package/dist/optional-feature/optional-feature.schema.d.ts +236 -0
  185. package/dist/optional-feature/optional-feature.schema.js +9 -0
  186. package/dist/pack.d.ts +11 -0
  187. package/dist/pc/conditions.constants.d.ts +3 -0
  188. package/dist/pc/conditions.constants.js +8 -0
  189. package/dist/pc/decision-recognizer.d.ts +4 -0
  190. package/dist/pc/decision-recognizer.js +8 -0
  191. package/dist/pc/pc.conditions.d.ts +3 -0
  192. package/dist/pc/pc.conditions.js +6 -0
  193. package/dist/pc/pc.decision-engine.d.ts +97 -0
  194. package/dist/pc/pc.decision-engine.js +19 -0
  195. package/dist/pc/pc.equipment.d.ts +12 -0
  196. package/dist/pc/pc.equipment.js +15 -0
  197. package/dist/pc/pc.feature-effects.d.ts +95 -0
  198. package/dist/pc/pc.feature-effects.js +9 -0
  199. package/dist/pc/pc.formula-context.d.ts +4 -0
  200. package/dist/pc/pc.formula-context.js +11 -0
  201. package/dist/pc/pc.parser.d.ts +3 -0
  202. package/dist/pc/pc.parser.js +41 -0
  203. package/dist/pc/pc.pools.d.ts +12 -0
  204. package/dist/pc/pc.pools.js +15 -0
  205. package/dist/pc/pc.proficiencies.d.ts +8 -0
  206. package/dist/pc/pc.proficiencies.js +47 -0
  207. package/dist/pc/pc.proficiency-query.d.ts +11 -0
  208. package/dist/pc/pc.proficiency-query.js +17 -0
  209. package/dist/pc/pc.recalc.d.ts +105 -0
  210. package/dist/pc/pc.recalc.js +662 -0
  211. package/dist/pc/pc.resolver.d.ts +34 -0
  212. package/dist/pc/pc.resolver.js +267 -0
  213. package/dist/pc/pc.resource-seed.d.ts +10 -0
  214. package/dist/pc/pc.resource-seed.js +40 -0
  215. package/dist/pc/pc.rest.d.ts +23 -0
  216. package/dist/pc/pc.rest.js +128 -0
  217. package/dist/pc/pc.schema.d.ts +294 -0
  218. package/dist/pc/pc.schema.js +7 -0
  219. package/dist/pc/pc.slotting.d.ts +22 -0
  220. package/dist/pc/pc.slotting.js +20 -0
  221. package/dist/pc/pc.spellcasting.d.ts +56 -0
  222. package/dist/pc/pc.spellcasting.js +16 -0
  223. package/dist/pc/pc.table-column.d.ts +12 -0
  224. package/dist/pc/pc.table-column.js +8 -0
  225. package/dist/pc/pc.types.d.ts +514 -0
  226. package/dist/pc/pc.types.js +0 -0
  227. package/dist/race/race.codec.d.ts +9 -0
  228. package/dist/race/race.codec.js +13 -0
  229. package/dist/race/race.entity-type.d.ts +2 -0
  230. package/dist/race/race.parser.d.ts +3 -0
  231. package/dist/race/race.parser.js +12 -0
  232. package/dist/race/race.schema.d.ts +67 -0
  233. package/dist/race/race.schema.js +11 -0
  234. package/dist/race/race.types.d.ts +44 -0
  235. package/dist/race/race.types.js +0 -0
  236. package/dist/schemas/attack-schema.d.ts +38 -0
  237. package/dist/schemas/choice-schema.d.ts +5 -0
  238. package/dist/schemas/choice-schema.js +7 -0
  239. package/dist/schemas/duration-schema.d.ts +13 -0
  240. package/dist/schemas/duration-schema.js +6 -0
  241. package/dist/schemas/equipment-grant-schema.d.ts +6 -0
  242. package/dist/schemas/equipment-grant-schema.js +12 -0
  243. package/dist/schemas/feature-effect-schema.d.ts +131 -0
  244. package/dist/schemas/feature-effect-schema.js +6 -0
  245. package/dist/schemas/feature-schema.d.ts +2 -0
  246. package/dist/schemas/feature-schema.js +10 -0
  247. package/dist/schemas/index.d.ts +6 -0
  248. package/dist/schemas/resource-schema.d.ts +95 -0
  249. package/dist/schemas/resource-schema.js +12 -0
  250. package/dist/schemas/selection-pool-schema.d.ts +34 -0
  251. package/dist/schemas/selection-pool-schema.js +10 -0
  252. package/dist/spell/spell.access.d.ts +15 -0
  253. package/dist/spell/spell.access.js +25 -0
  254. package/dist/spell/spell.ai-schema.d.ts +24 -0
  255. package/dist/spell/spell.ai-schema.js +6 -0
  256. package/dist/spell/spell.codec.d.ts +3 -0
  257. package/dist/spell/spell.codec.js +8 -0
  258. package/dist/spell/spell.enrichment.d.ts +2 -0
  259. package/dist/spell/spell.enrichment.js +9 -0
  260. package/dist/spell/spell.entity-type.d.ts +2 -0
  261. package/dist/spell/spell.filter.d.ts +15 -0
  262. package/dist/spell/spell.filter.js +87 -0
  263. package/dist/spell/spell.generatable.d.ts +2 -0
  264. package/dist/spell/spell.parser.d.ts +3 -0
  265. package/dist/spell/spell.parser.js +7 -0
  266. package/dist/spell/spell.scaling.d.ts +14 -0
  267. package/dist/spell/spell.scaling.js +28 -0
  268. package/dist/spell/spell.schema.d.ts +31 -0
  269. package/dist/spell/spell.schema.js +6 -0
  270. package/dist/spell/spell.types.d.ts +25 -0
  271. package/dist/spell/spell.types.js +0 -0
  272. package/dist/srd-store.d.ts +53 -0
  273. package/dist/subclass/subclass.codec.d.ts +11 -0
  274. package/dist/subclass/subclass.codec.js +14 -0
  275. package/dist/subclass/subclass.entity-type.d.ts +2 -0
  276. package/dist/subclass/subclass.parser.d.ts +3 -0
  277. package/dist/subclass/subclass.parser.js +13 -0
  278. package/dist/subclass/subclass.schema.d.ts +118 -0
  279. package/dist/subclass/subclass.schema.js +12 -0
  280. package/dist/subclass/subclass.types.d.ts +20 -0
  281. package/dist/subclass/subclass.types.js +0 -0
  282. package/dist/types/abilities.d.ts +8 -0
  283. package/dist/types/abilities.js +0 -0
  284. package/dist/types/ac.d.ts +5 -0
  285. package/dist/types/attack.d.ts +22 -0
  286. package/dist/types/attack.js +0 -0
  287. package/dist/types/casting-option.d.ts +14 -0
  288. package/dist/types/casting-option.js +0 -0
  289. package/dist/types/choice.d.ts +66 -0
  290. package/dist/types/choice.js +6 -0
  291. package/dist/types/edition.d.ts +4 -0
  292. package/dist/types/edition.js +0 -0
  293. package/dist/types/equipment-grant.d.ts +41 -0
  294. package/dist/types/equipment-grant.js +0 -0
  295. package/dist/types/feature-effect.d.ts +79 -0
  296. package/dist/types/feature-effect.js +0 -0
  297. package/dist/types/feature.d.ts +41 -0
  298. package/dist/types/feature.js +0 -0
  299. package/dist/types/formula-context.d.ts +7 -0
  300. package/dist/types/formula-context.js +0 -0
  301. package/dist/types/hp.d.ts +4 -0
  302. package/dist/types/index.d.ts +10 -0
  303. package/dist/types/item-conditions.types.d.ts +63 -0
  304. package/dist/types/item-conditions.types.js +0 -0
  305. package/dist/types/optional-feature.types.d.ts +60 -0
  306. package/dist/types/optional-feature.types.js +0 -0
  307. package/dist/types/resource.d.ts +44 -0
  308. package/dist/types/resource.js +0 -0
  309. package/dist/types/selection-pool.d.ts +37 -0
  310. package/dist/types/selection-pool.js +0 -0
  311. package/dist/types/speed.d.ts +8 -0
  312. package/dist/weapon/weapon.codec.d.ts +12 -0
  313. package/dist/weapon/weapon.codec.js +8 -0
  314. package/dist/weapon/weapon.entity-type.d.ts +2 -0
  315. package/dist/weapon/weapon.parser.d.ts +3 -0
  316. package/dist/weapon/weapon.parser.js +7 -0
  317. package/dist/weapon/weapon.schema.d.ts +34 -0
  318. package/dist/weapon/weapon.schema.js +6 -0
  319. package/dist/weapon/weapon.types.d.ts +36 -0
  320. package/dist/weapon/weapon.types.js +0 -0
  321. package/package.json +32 -0
  322. package/src/data-srd/ATTRIBUTION.md +2 -0
@@ -0,0 +1,267 @@
1
+ import {
2
+ resolveAllPools
3
+ } from "../chunk-6PXE7T7C.js";
4
+ import {
5
+ normalizeKnownSpell,
6
+ resolveSpellcasting
7
+ } from "../chunk-IXZXFFFW.js";
8
+ import "../chunk-5XUXXAQJ.js";
9
+ import "../chunk-TJCNX6UZ.js";
10
+ import "../chunk-BH6AMZVY.js";
11
+ import "../chunk-JEYQU3JT.js";
12
+ import "../chunk-J2RYSZMQ.js";
13
+ import "../chunk-NAEPSZAM.js";
14
+ import "../chunk-WP2CX2JO.js";
15
+
16
+ // src/pc/pc.resolver.ts
17
+ var SLUG_RE = /^\[\[(.+?)\]\]$/;
18
+ function stripSlug(ref) {
19
+ if (!ref) return null;
20
+ const m = ref.match(SLUG_RE);
21
+ return m ? m[1] : ref;
22
+ }
23
+ var PCResolver = class {
24
+ constructor(entities) {
25
+ this.entities = entities;
26
+ }
27
+ /** Exposed so recalc() can apply equipment bonuses (Pass A / Pass B). */
28
+ get registry() {
29
+ return this.entities;
30
+ }
31
+ resolve(character) {
32
+ var _a, _b, _c, _d, _e;
33
+ const warnings = [];
34
+ const lookup = (rawRef, type) => {
35
+ const slug = stripSlug(rawRef);
36
+ if (!slug) return null;
37
+ const reg = this.entities.getByTypeAndSlug(type, slug);
38
+ if (!reg) {
39
+ warnings.push(`Slug [[${slug}]] not found in compendium as ${type}.`);
40
+ return null;
41
+ }
42
+ const data = reg.data;
43
+ return data.slug == null ? { ...data, slug: reg.slug } : data;
44
+ };
45
+ const race = lookup(character.race, "race");
46
+ const background = lookup(character.background, "background");
47
+ const classes = character.class.map((c) => ({
48
+ entity: lookup(c.name, "class"),
49
+ level: c.level,
50
+ subclass: lookup(c.subclass, "subclass"),
51
+ choices: c.choices
52
+ }));
53
+ const featSlugs = collectFeatSlugs(character);
54
+ const feats = [];
55
+ for (const slug of featSlugs) {
56
+ const f = lookup(`[[${slug}]]`, "feat");
57
+ if (f) feats.push(f);
58
+ }
59
+ const totalLevel = classes.reduce((sum, c) => sum + c.level, 0);
60
+ const features = collectResolvedFeatures(race, classes, background, feats);
61
+ const extraFeatures = collectChosenGrantedFeatures(character, classes, this.entities, race, background);
62
+ features.push(...extraFeatures);
63
+ const primaryCasterSlug = (_a = classes.map((c, i) => c.entity && resolveSpellcasting(c) ? stripSlug(character.class[i].name) : null).find((slug) => slug != null)) != null ? _a : null;
64
+ const spells = [];
65
+ for (const raw of (_b = character.spells.known) != null ? _b : []) {
66
+ const n = normalizeKnownSpell(raw);
67
+ const reg = this.entities.getByTypeAndSlug("spell", n.slug);
68
+ if (!reg) {
69
+ warnings.push(`Spell [[${n.slug}]] not found in compendium.`);
70
+ continue;
71
+ }
72
+ const entity = reg.data;
73
+ const isCantrip = ((_c = entity.level) != null ? _c : 0) === 0;
74
+ const classSlug = (_d = n.classSlug) != null ? _d : primaryCasterSlug;
75
+ const prep = isCantrip || n.alwaysPrepared ? true : (_e = n.preparedFlag) != null ? _e : false;
76
+ spells.push({ entity, slug: n.slug, classSlug, source: n.source, prepared: prep, alwaysPrepared: n.alwaysPrepared });
77
+ }
78
+ const resolvedCharacter = {
79
+ definition: character,
80
+ race,
81
+ classes,
82
+ background,
83
+ feats,
84
+ totalLevel,
85
+ features,
86
+ spells,
87
+ pools: [],
88
+ state: character.state
89
+ };
90
+ resolvedCharacter.pools = resolveAllPools(resolvedCharacter, this.entities);
91
+ return { character: resolvedCharacter, warnings };
92
+ }
93
+ };
94
+ function collectFeatSlugs(character) {
95
+ const slugs = /* @__PURE__ */ new Set();
96
+ for (const c of character.class) {
97
+ for (const [, choiceBlock] of Object.entries(c.choices)) {
98
+ const feat = choiceBlock == null ? void 0 : choiceBlock.feat;
99
+ if (typeof feat === "string") {
100
+ const s = stripSlug(feat);
101
+ if (s) slugs.add(s);
102
+ }
103
+ }
104
+ }
105
+ return [...slugs];
106
+ }
107
+ function collectChosenGrantedFeatures(character, classes, registry, race = null, background = null) {
108
+ var _a, _b;
109
+ const out = [];
110
+ classes.forEach((c, i) => {
111
+ var _a2, _b2, _c, _d;
112
+ if (!c.entity) return;
113
+ const entity = c.entity;
114
+ const entry = character.class[i];
115
+ if (!entry) return;
116
+ for (const [lvlStr, atLevel] of Object.entries(entry.choices)) {
117
+ const lvl = Number(lvlStr);
118
+ if (!Number.isFinite(lvl) || lvl > entry.level) continue;
119
+ const features = (_b2 = ((_a2 = entity.features_by_level) != null ? _a2 : {})[lvl]) != null ? _b2 : [];
120
+ const subFeatures = c.subclass ? (_d = ((_c = c.subclass.features_by_level) != null ? _c : {})[lvl]) != null ? _d : [] : [];
121
+ for (const feature of [...features, ...subFeatures]) {
122
+ walkChoiceGrants(feature.choices, atLevel, (granted) => {
123
+ out.push({ feature: granted, source: { kind: "class", slug: entity.slug, level: lvl } });
124
+ }, registry);
125
+ }
126
+ }
127
+ });
128
+ const oc = (_a = character.origin_choices) != null ? _a : {};
129
+ const originAt = (ns) => {
130
+ const at = {};
131
+ for (const [key, val] of Object.entries(oc)) {
132
+ if (key.startsWith(`${ns}:`)) at[key.slice(ns.length + 1)] = val;
133
+ }
134
+ return at;
135
+ };
136
+ if (race) {
137
+ const atRace = originAt("race");
138
+ const emitRace = (granted) => {
139
+ out.push({ feature: granted, source: { kind: "race", slug: race.slug } });
140
+ };
141
+ walkChoiceGrants(race.choices, atRace, emitRace, registry);
142
+ for (const trait of (_b = race.traits) != null ? _b : []) {
143
+ walkChoiceGrants(trait.choices, atRace, emitRace, registry);
144
+ }
145
+ }
146
+ if (background) {
147
+ const atBg = originAt("background");
148
+ const emitBg = (granted) => {
149
+ out.push({ feature: granted, source: { kind: "background", slug: background.slug } });
150
+ };
151
+ walkChoiceGrants(background.choices, atBg, emitBg, registry);
152
+ if (background.feature) {
153
+ walkChoiceGrants(background.feature.choices, atBg, emitBg, registry);
154
+ }
155
+ }
156
+ return out;
157
+ }
158
+ function walkChoiceGrants(choices, atLevel, emit, registry) {
159
+ var _a, _b, _c, _d;
160
+ for (const ch of choices != null ? choices : []) {
161
+ const sel = atLevel[ch.id];
162
+ if (ch.kind === "select-entity" && ch.entity_type === "optional-feature") {
163
+ const slugs = Array.isArray(sel) ? sel : typeof sel === "string" ? [sel] : [];
164
+ for (const slug of slugs) {
165
+ const reg = registry.getByTypeAndSlug("optional-feature", (_a = stripSlug(String(slug))) != null ? _a : String(slug));
166
+ if (!reg) continue;
167
+ const d = reg.data;
168
+ emit({
169
+ id: (_b = d.slug) != null ? _b : String(slug),
170
+ name: (_c = d.name) != null ? _c : String(slug),
171
+ description: d.description,
172
+ effects: d.effects,
173
+ ...d.action_cost ? { action: d.action_cost } : {}
174
+ });
175
+ }
176
+ }
177
+ if (ch.kind === "select-inline") {
178
+ const branch = typeof sel === "string" ? ch.options.find((o) => o.value === sel) : void 0;
179
+ if ((_d = branch == null ? void 0 : branch.effects) == null ? void 0 : _d.length) {
180
+ emit({ id: `${ch.id}-${branch.value}`, name: branch.label, description: branch.description, effects: branch.effects });
181
+ }
182
+ if (branch == null ? void 0 : branch.choices) walkChoiceGrants(branch.choices, atLevel, emit, registry);
183
+ }
184
+ }
185
+ }
186
+ function collectResolvedFeatures(race, classes, background, feats) {
187
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
188
+ const out = [];
189
+ for (const c of classes) {
190
+ if (!c.entity) continue;
191
+ const slug = c.entity.slug;
192
+ const byLevel = (_a = c.entity.features_by_level) != null ? _a : {};
193
+ for (const [lvlStr, feats0] of Object.entries(byLevel)) {
194
+ const lvl = parseInt(lvlStr, 10);
195
+ if (Number.isNaN(lvl) || lvl > c.level) continue;
196
+ for (const feat of feats0) {
197
+ out.push({ feature: feat, source: { kind: "class", slug, level: lvl } });
198
+ }
199
+ }
200
+ if ((_b = c.entity.resources) == null ? void 0 : _b.length) {
201
+ out.push({
202
+ feature: { name: c.entity.name, resources: c.entity.resources },
203
+ source: { kind: "class", slug, level: 1 }
204
+ });
205
+ }
206
+ if (c.subclass) {
207
+ const sSlug = c.subclass.slug;
208
+ const sByLevel = (_c = c.subclass.features_by_level) != null ? _c : {};
209
+ for (const [lvlStr, feats0] of Object.entries(sByLevel)) {
210
+ const lvl = parseInt(lvlStr, 10);
211
+ if (Number.isNaN(lvl) || lvl > c.level) continue;
212
+ for (const feat of feats0) {
213
+ out.push({ feature: feat, source: { kind: "subclass", slug: sSlug, level: lvl } });
214
+ }
215
+ }
216
+ if ((_d = c.subclass.resources) == null ? void 0 : _d.length) {
217
+ out.push({
218
+ feature: { name: c.subclass.name, resources: c.subclass.resources },
219
+ source: { kind: "subclass", slug: sSlug, level: 1 }
220
+ });
221
+ }
222
+ }
223
+ }
224
+ if (race) {
225
+ const traits = (_e = race.traits) != null ? _e : [];
226
+ for (const feat of traits) {
227
+ out.push({ feature: feat, source: { kind: "race", slug: race.slug } });
228
+ }
229
+ }
230
+ if (background) {
231
+ const bgFeature = background.feature;
232
+ if (bgFeature) {
233
+ out.push({ feature: bgFeature, source: { kind: "background", slug: background.slug } });
234
+ }
235
+ }
236
+ for (const feat of feats) {
237
+ const bundled = (_f = feat.features) != null ? _f : [];
238
+ const entityEffects = (_g = feat.effects) != null ? _g : [];
239
+ if (bundled.length > 0) {
240
+ bundled.forEach((f, i) => {
241
+ var _a2;
242
+ const feature = i === 0 && entityEffects.length > 0 ? { ...f, effects: [...(_a2 = f.effects) != null ? _a2 : [], ...entityEffects] } : f;
243
+ out.push({ feature, source: { kind: "feat", slug: feat.slug } });
244
+ });
245
+ } else {
246
+ const name = (_h = feat.name) != null ? _h : feat.slug;
247
+ const description = (_i = feat.description) != null ? _i : "";
248
+ out.push({
249
+ feature: {
250
+ name,
251
+ description,
252
+ ...feat.resources ? { resources: feat.resources } : {},
253
+ ...entityEffects.length > 0 ? { effects: entityEffects } : {}
254
+ },
255
+ source: { kind: "feat", slug: feat.slug }
256
+ });
257
+ }
258
+ }
259
+ return out;
260
+ }
261
+ export {
262
+ PCResolver,
263
+ collectChosenGrantedFeatures,
264
+ collectFeatSlugs,
265
+ collectResolvedFeatures,
266
+ stripSlug
267
+ };
@@ -0,0 +1,10 @@
1
+ import type { ResolvedCharacter, DerivedStats, FeatureSource } from "./pc.types.js";
2
+ import type { FormulaBindings } from "@archivist-gg/dnd5e/dnd/resource-formula";
3
+ /** Build the DSL bindings for a resource granted via `source`. `class_level`
4
+ * is the character's level in the granting class; for a `subclass` source it
5
+ * is the level in the class that OWNS that subclass, and it falls back to the
6
+ * total level for race/background/feat sources (or when the class isn't found).
7
+ * Also binds `columns` — the numeric values of that (sub)class's table row at
8
+ * `class_level` (empty when there is no table/row), backing the `column('Name')`
9
+ * accessor in the DSL. Ability mods come from the final (post-bonus) derived mods. */
10
+ export declare function resourceBindings(resolved: ResolvedCharacter, derived: DerivedStats, source: FeatureSource): FormulaBindings;
@@ -0,0 +1,40 @@
1
+ import {
2
+ numericColumnsAt
3
+ } from "../chunk-5XUXXAQJ.js";
4
+
5
+ // src/pc/pc.resource-seed.ts
6
+ function resourceBindings(resolved, derived, source) {
7
+ var _a, _b, _c, _d;
8
+ let classLevel = resolved.totalLevel;
9
+ let table;
10
+ if (source.kind === "class") {
11
+ const c = resolved.classes.find((c2) => {
12
+ var _a2;
13
+ return ((_a2 = c2.entity) == null ? void 0 : _a2.slug) === source.slug;
14
+ });
15
+ classLevel = (_a = c == null ? void 0 : c.level) != null ? _a : resolved.totalLevel;
16
+ table = (_b = c == null ? void 0 : c.entity) == null ? void 0 : _b.table;
17
+ } else if (source.kind === "subclass") {
18
+ const c = resolved.classes.find((c2) => {
19
+ var _a2;
20
+ return ((_a2 = c2.subclass) == null ? void 0 : _a2.slug) === source.slug;
21
+ });
22
+ classLevel = (_c = c == null ? void 0 : c.level) != null ? _c : resolved.totalLevel;
23
+ table = (_d = c == null ? void 0 : c.subclass) == null ? void 0 : _d.table;
24
+ }
25
+ return {
26
+ level: resolved.totalLevel,
27
+ class_level: classLevel,
28
+ prof: derived.proficiencyBonus,
29
+ str_mod: derived.mods.str,
30
+ dex_mod: derived.mods.dex,
31
+ con_mod: derived.mods.con,
32
+ int_mod: derived.mods.int,
33
+ wis_mod: derived.mods.wis,
34
+ cha_mod: derived.mods.cha,
35
+ columns: numericColumnsAt(table, classLevel)
36
+ };
37
+ }
38
+ export {
39
+ resourceBindings
40
+ };
@@ -0,0 +1,23 @@
1
+ import type { EntityRegistry } from "@archivist-gg/core";
2
+ import type { Character, DerivedStats, ResolvedCharacter } from "./pc.types.js";
3
+ export type RestType = "short" | "long";
4
+ export type RestCategoryId = "hp-to-max" | "hd-regain" | "spell-slots" | "pact-slots" | "exhaustion" | `feature:${string}` | `item:${number}`;
5
+ export interface RestCategory {
6
+ id: RestCategoryId;
7
+ label: string;
8
+ preview: string;
9
+ }
10
+ export interface RestPlan {
11
+ type: RestType;
12
+ categories: RestCategory[];
13
+ hdAvailable: Array<{
14
+ die: string;
15
+ remaining: number;
16
+ }>;
17
+ /** Internal: per-die HD-regain target captured at plan time so apply is idempotent. */
18
+ hdRegainDist?: Array<{
19
+ die: string;
20
+ targetUsed: number;
21
+ }>;
22
+ }
23
+ export declare function computeRestPlan(character: Character, resolved: ResolvedCharacter, derived: DerivedStats, registry: EntityRegistry | null, type: RestType): RestPlan;
@@ -0,0 +1,128 @@
1
+ // src/pc/pc.rest.ts
2
+ function resolveItemName(entry, registry) {
3
+ var _a;
4
+ if (!registry) return void 0;
5
+ const ref = entry.item.match(/^\[\[(.+?)\]\]$/);
6
+ const slug = ref ? ref[1] : entry.item;
7
+ return (_a = registry.getBySlug(slug)) == null ? void 0 : _a.name;
8
+ }
9
+ function findResourceById(resolved, id) {
10
+ var _a, _b, _c;
11
+ for (const rf of (_a = resolved.features) != null ? _a : []) {
12
+ for (const r of (_b = rf.feature.resources) != null ? _b : []) {
13
+ if (r.id === id) return { label: (_c = r.name) != null ? _c : rf.feature.name, reset: r.reset };
14
+ }
15
+ }
16
+ return void 0;
17
+ }
18
+ function computeRestPlan(character, resolved, derived, registry, type) {
19
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
20
+ const cats = [];
21
+ let hdRegainDist;
22
+ const pact = character.state.spell_slots_pact;
23
+ if (pact && pact.used > 0) {
24
+ cats.push({ id: "pact-slots", label: "Pact Magic Slots", preview: "all reset" });
25
+ }
26
+ if (type === "long") {
27
+ if (character.state.hp.current < derived.hp.max) {
28
+ cats.push({
29
+ id: "hp-to-max",
30
+ label: "Hit Points",
31
+ preview: `${character.state.hp.current} \u2192 ${derived.hp.max}`
32
+ });
33
+ }
34
+ if (character.state.exhaustion > 0) {
35
+ cats.push({
36
+ id: "exhaustion",
37
+ label: "Exhaustion",
38
+ preview: `${character.state.exhaustion} \u2192 ${character.state.exhaustion - 1}`
39
+ });
40
+ }
41
+ const slotsUsed = Object.values((_a = character.state.spell_slots) != null ? _a : {}).reduce((s, slot) => {
42
+ var _a2;
43
+ return s + ((_a2 = slot.used) != null ? _a2 : 0);
44
+ }, 0);
45
+ if (slotsUsed > 0) {
46
+ cats.push({ id: "spell-slots", label: "Spell Slots", preview: "all reset" });
47
+ }
48
+ const totalLevel = (_b = resolved.totalLevel) != null ? _b : 0;
49
+ const regainBudget = Math.max(1, Math.floor(totalLevel / 2));
50
+ const pools = Object.entries((_c = character.state.hit_dice) != null ? _c : {}).map(([die, hd]) => ({ die, used: hd.used, total: hd.total })).filter((p) => p.used > 0).sort((a, b) => b.used - a.used);
51
+ if (pools.length > 0) {
52
+ let left = regainBudget;
53
+ const dist = [];
54
+ for (const p of pools) {
55
+ if (left === 0) break;
56
+ const give = Math.min(p.used, left);
57
+ if (give > 0) dist.push({ die: p.die, give, targetUsed: p.used - give });
58
+ left -= give;
59
+ }
60
+ const totalGive = dist.reduce((s, d) => s + d.give, 0);
61
+ if (totalGive > 0) {
62
+ const detail = dist.map((d) => `${d.die}: +${d.give}`).join(", ");
63
+ cats.push({
64
+ id: "hd-regain",
65
+ label: "Hit Dice",
66
+ preview: `+${totalGive} (${detail})`
67
+ });
68
+ hdRegainDist = dist.map((d) => ({ die: d.die, targetUsed: d.targetUsed }));
69
+ }
70
+ }
71
+ for (const [key, fu] of Object.entries((_d = character.state.feature_uses) != null ? _d : {})) {
72
+ if (fu.used <= 0) continue;
73
+ const res = findResourceById(resolved, key);
74
+ const reset = (_e = res == null ? void 0 : res.reset) != null ? _e : "long-rest";
75
+ if (reset !== "short-rest" && reset !== "long-rest" && reset !== "dawn" && reset !== "dusk") continue;
76
+ cats.push({
77
+ id: `feature:${key}`,
78
+ label: (_f = res == null ? void 0 : res.label) != null ? _f : key,
79
+ preview: `${fu.used}/${fu.max} restored`
80
+ });
81
+ }
82
+ character.equipment.forEach((entry, idx) => {
83
+ var _a2, _b2, _c2, _d2, _e2;
84
+ const rec = (_a2 = entry.state) == null ? void 0 : _a2.recovery;
85
+ const charges = (_b2 = entry.state) == null ? void 0 : _b2.charges;
86
+ if (!rec || !charges) return;
87
+ if (charges.current >= charges.max) return;
88
+ if (rec.reset !== "short" && rec.reset !== "long" && rec.reset !== "dawn") return;
89
+ const label = (_e2 = (_d2 = (_c2 = entry.overrides) == null ? void 0 : _c2.name) != null ? _d2 : resolveItemName(entry, registry)) != null ? _e2 : entry.item;
90
+ cats.push({
91
+ id: `item:${idx}`,
92
+ label,
93
+ preview: `${charges.current} \u2192 ${charges.max}`
94
+ });
95
+ });
96
+ }
97
+ if (type === "short") {
98
+ for (const [key, fu] of Object.entries((_g = character.state.feature_uses) != null ? _g : {})) {
99
+ if (fu.used <= 0) continue;
100
+ const res = findResourceById(resolved, key);
101
+ if (((_h = res == null ? void 0 : res.reset) != null ? _h : "long-rest") !== "short-rest") continue;
102
+ cats.push({
103
+ id: `feature:${key}`,
104
+ label: (_i = res == null ? void 0 : res.label) != null ? _i : key,
105
+ preview: `${fu.used}/${fu.max} restored`
106
+ });
107
+ }
108
+ character.equipment.forEach((entry, idx) => {
109
+ var _a2, _b2, _c2, _d2, _e2;
110
+ const rec = (_a2 = entry.state) == null ? void 0 : _a2.recovery;
111
+ const charges = (_b2 = entry.state) == null ? void 0 : _b2.charges;
112
+ if (!rec || !charges) return;
113
+ if (charges.current >= charges.max) return;
114
+ if (rec.reset !== "short") return;
115
+ const label = (_e2 = (_d2 = (_c2 = entry.overrides) == null ? void 0 : _c2.name) != null ? _d2 : resolveItemName(entry, registry)) != null ? _e2 : entry.item;
116
+ cats.push({
117
+ id: `item:${idx}`,
118
+ label,
119
+ preview: `${charges.current} \u2192 ${charges.max}`
120
+ });
121
+ });
122
+ }
123
+ const hdAvailable = type === "short" ? Object.entries((_j = character.state.hit_dice) != null ? _j : {}).filter(([, hd]) => hd.used < hd.total).map(([die, hd]) => ({ die, remaining: hd.total - hd.used })) : [];
124
+ return { type, categories: cats, hdAvailable, hdRegainDist };
125
+ }
126
+ export {
127
+ computeRestPlan
128
+ };