@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/.claude/worktrees/amazing-matsumoto-27220c/LICENSE +21 -0
- package/.claude/worktrees/amazing-matsumoto-27220c/README.md +518 -0
- package/.claude/worktrees/vibrant-lovelace-0cc9e7/LICENSE +21 -0
- package/.claude/worktrees/vibrant-lovelace-0cc9e7/README.md +518 -0
- package/.claude/worktrees/wizardly-mclean-e375de/LICENSE +21 -0
- package/.claude/worktrees/wizardly-mclean-e375de/README.md +518 -0
- package/CHANGELOG.md +224 -0
- package/README.md +17 -0
- package/dist/builder/index.cjs +555 -295
- package/dist/builder/index.cjs.map +1 -1
- package/dist/builder/index.d.cts +9 -10
- package/dist/builder/index.d.ts +9 -10
- package/dist/builder/index.js +555 -295
- package/dist/builder/index.js.map +1 -1
- package/dist/index.cjs +619 -256
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +61 -3
- package/dist/index.d.ts +61 -3
- package/dist/index.js +613 -257
- package/dist/index.js.map +1 -1
- package/dist/{pmf-BC1poIqF.d.cts → pmf-D5VRghZI.d.cts} +204 -10
- package/dist/{pmf-BC1poIqF.d.ts → pmf-D5VRghZI.d.ts} +204 -10
- package/package.json +12 -14
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,63 @@
|
|
|
1
|
-
import { P as PMF } from './pmf-
|
|
2
|
-
export { B as Bin, C as CritConfig, D as DamageDistribution,
|
|
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-
|
|
2
|
-
export { B as Bin, C as CritConfig, D as DamageDistribution,
|
|
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 };
|