@yipe/dice 0.2.23 → 0.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/dist/index.d.cts CHANGED
@@ -1,5 +1,63 @@
1
- import { P as PMF } from './pmf-BC1poIqF.cjs';
2
- export { B as Bin, C as CritConfig, D as DamageDistribution, i as DiceQuery, E as EPS, L as LRUCache, O as OutcomeLabelMap, j as OutcomeSnapshot, a as OutcomeType, R as Rounding, S as Snapshot, o as onAnyHit, b as onCritOnly, c as onHitOnly, e as onMissDamageOnly, d as onMissOnly, h as onPotentCantripOnly, g as onSaveFailOnly, f as onSaveHalfOnly, p as pmfCache } from './pmf-BC1poIqF.cjs';
1
+ import { P as PMF } from './pmf-D5VRghZI.cjs';
2
+ export { A as ALL_OUTCOME_TYPES, B as Bin, C as CritConfig, D as DamageDistribution, l as DiceQuery, E as EPS, L as LRUCache, M as MISS_NONE_OUTCOME, d as OUTCOME_DISPLAY_ORDER, O as OutcomeLabelMap, m as OutcomeSnapshot, a as OutcomeType, b as RollType, R as Rounding, S as Snapshot, c as critProbability, o as onAnyHit, e as onCritOnly, f as onHitOnly, h as onMissDamageOnly, g as onMissOnly, k as onPotentCantripOnly, j as onSaveFailOnly, i as onSaveHalfOnly, p as pmfCache, s as sortOutcomes } from './pmf-D5VRghZI.cjs';
3
+
4
+ /**
5
+ * Bounce odds — the "birthday problem" for bouncing damage dice (e.g. Chromatic
6
+ * Orb): the probability that at least two of K dice with S faces show the same
7
+ * value, which is what lets the spell jump to another target.
8
+ *
9
+ * Accounts for two modifiers:
10
+ * - **Elemental Adept** (`minimumDieRoll >= 2`): rolls below the minimum are
11
+ * bumped up to it, collapsing the low faces onto a single heavier value.
12
+ * - **Empowered Spell** (`rerollDamageDice > 0`): a number of dice may be
13
+ * rerolled once, giving a second chance at a match.
14
+ *
15
+ * The base and Elemental-Adept cases are computed exactly (see
16
+ * {@link pAllDistinct}); the Empowered-Spell reroll is an explicit model layered
17
+ * on the exact base match probability.
18
+ */
19
+ /** Options that modify bounce odds via metamagic / feats. */
20
+ interface BounceOddsOptions {
21
+ /** Minimum die roll — e.g. 2 for Elemental Adept, 3 for Great Weapon Fighting 2024. */
22
+ minimumDieRoll?: number;
23
+ /** Number of dice that may be rerolled once — e.g. CHA modifier for Empowered Spell. */
24
+ rerollDamageDice?: number;
25
+ }
26
+ /**
27
+ * P(at least two of `diceCount` dice with `dieFaces` faces match), honoring
28
+ * Elemental Adept and Empowered Spell. Returns a probability in [0, 1].
29
+ *
30
+ * @param diceCount Number of dice rolled.
31
+ * @param dieFaces Faces per die (e.g. 8 for d8).
32
+ * @param options Optional metamagic / feat modifiers.
33
+ */
34
+ declare function calculateBounceOdds(diceCount: number, dieFaces: number, options?: BounceOddsOptions): number;
35
+
36
+ /**
37
+ * Error thrown when a dice expression cannot be parsed.
38
+ *
39
+ * Extends the built-in {@link Error}, so existing `catch (e)` / message checks
40
+ * continue to work, while callers can now narrow with `instanceof DiceParseError`.
41
+ *
42
+ * @example
43
+ * try {
44
+ * parse("d6@3");
45
+ * } catch (e) {
46
+ * if (e instanceof DiceParseError) {
47
+ * // e.expression === "d6@3"
48
+ * }
49
+ * }
50
+ */
51
+ declare class DiceParseError extends Error {
52
+ /** The original expression that failed to parse, when available. */
53
+ readonly expression?: string;
54
+ /** The underlying error that triggered this one, when available. */
55
+ readonly cause?: unknown;
56
+ constructor(message: string, options?: {
57
+ expression?: string;
58
+ cause?: unknown;
59
+ });
60
+ }
3
61
 
4
62
  /** Enable or disable the internal parse cache. */
5
63
  declare function setCachingEnabled(enabled: boolean): void;
@@ -50,4 +108,4 @@ declare class Mixture<L extends string = string> {
50
108
  static mix<L extends string = string>(items: Array<[label: L, pmf: PMF, weight: number]>, eps?: number): PMF;
51
109
  }
52
110
 
53
- export { Mixture, PMF, clearParserCache, getCachingEnabled, parse, setCachingEnabled };
111
+ export { type BounceOddsOptions, DiceParseError, Mixture, PMF, calculateBounceOdds, clearParserCache, getCachingEnabled, parse, setCachingEnabled };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,63 @@
1
- import { P as PMF } from './pmf-BC1poIqF.js';
2
- export { B as Bin, C as CritConfig, D as DamageDistribution, i as DiceQuery, E as EPS, L as LRUCache, O as OutcomeLabelMap, j as OutcomeSnapshot, a as OutcomeType, R as Rounding, S as Snapshot, o as onAnyHit, b as onCritOnly, c as onHitOnly, e as onMissDamageOnly, d as onMissOnly, h as onPotentCantripOnly, g as onSaveFailOnly, f as onSaveHalfOnly, p as pmfCache } from './pmf-BC1poIqF.js';
1
+ import { P as PMF } from './pmf-D5VRghZI.js';
2
+ export { A as ALL_OUTCOME_TYPES, B as Bin, C as CritConfig, D as DamageDistribution, l as DiceQuery, E as EPS, L as LRUCache, M as MISS_NONE_OUTCOME, d as OUTCOME_DISPLAY_ORDER, O as OutcomeLabelMap, m as OutcomeSnapshot, a as OutcomeType, b as RollType, R as Rounding, S as Snapshot, c as critProbability, o as onAnyHit, e as onCritOnly, f as onHitOnly, h as onMissDamageOnly, g as onMissOnly, k as onPotentCantripOnly, j as onSaveFailOnly, i as onSaveHalfOnly, p as pmfCache, s as sortOutcomes } from './pmf-D5VRghZI.js';
3
+
4
+ /**
5
+ * Bounce odds — the "birthday problem" for bouncing damage dice (e.g. Chromatic
6
+ * Orb): the probability that at least two of K dice with S faces show the same
7
+ * value, which is what lets the spell jump to another target.
8
+ *
9
+ * Accounts for two modifiers:
10
+ * - **Elemental Adept** (`minimumDieRoll >= 2`): rolls below the minimum are
11
+ * bumped up to it, collapsing the low faces onto a single heavier value.
12
+ * - **Empowered Spell** (`rerollDamageDice > 0`): a number of dice may be
13
+ * rerolled once, giving a second chance at a match.
14
+ *
15
+ * The base and Elemental-Adept cases are computed exactly (see
16
+ * {@link pAllDistinct}); the Empowered-Spell reroll is an explicit model layered
17
+ * on the exact base match probability.
18
+ */
19
+ /** Options that modify bounce odds via metamagic / feats. */
20
+ interface BounceOddsOptions {
21
+ /** Minimum die roll — e.g. 2 for Elemental Adept, 3 for Great Weapon Fighting 2024. */
22
+ minimumDieRoll?: number;
23
+ /** Number of dice that may be rerolled once — e.g. CHA modifier for Empowered Spell. */
24
+ rerollDamageDice?: number;
25
+ }
26
+ /**
27
+ * P(at least two of `diceCount` dice with `dieFaces` faces match), honoring
28
+ * Elemental Adept and Empowered Spell. Returns a probability in [0, 1].
29
+ *
30
+ * @param diceCount Number of dice rolled.
31
+ * @param dieFaces Faces per die (e.g. 8 for d8).
32
+ * @param options Optional metamagic / feat modifiers.
33
+ */
34
+ declare function calculateBounceOdds(diceCount: number, dieFaces: number, options?: BounceOddsOptions): number;
35
+
36
+ /**
37
+ * Error thrown when a dice expression cannot be parsed.
38
+ *
39
+ * Extends the built-in {@link Error}, so existing `catch (e)` / message checks
40
+ * continue to work, while callers can now narrow with `instanceof DiceParseError`.
41
+ *
42
+ * @example
43
+ * try {
44
+ * parse("d6@3");
45
+ * } catch (e) {
46
+ * if (e instanceof DiceParseError) {
47
+ * // e.expression === "d6@3"
48
+ * }
49
+ * }
50
+ */
51
+ declare class DiceParseError extends Error {
52
+ /** The original expression that failed to parse, when available. */
53
+ readonly expression?: string;
54
+ /** The underlying error that triggered this one, when available. */
55
+ readonly cause?: unknown;
56
+ constructor(message: string, options?: {
57
+ expression?: string;
58
+ cause?: unknown;
59
+ });
60
+ }
3
61
 
4
62
  /** Enable or disable the internal parse cache. */
5
63
  declare function setCachingEnabled(enabled: boolean): void;
@@ -50,4 +108,4 @@ declare class Mixture<L extends string = string> {
50
108
  static mix<L extends string = string>(items: Array<[label: L, pmf: PMF, weight: number]>, eps?: number): PMF;
51
109
  }
52
110
 
53
- export { Mixture, PMF, clearParserCache, getCachingEnabled, parse, setCachingEnabled };
111
+ export { type BounceOddsOptions, DiceParseError, Mixture, PMF, calculateBounceOdds, clearParserCache, getCachingEnabled, parse, setCachingEnabled };