@yipe/dice 0.4.0 → 0.6.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/builder/ac.d.ts +25 -0
- package/dist/builder/ac.d.ts.map +1 -0
- package/dist/builder/ast.d.ts +9 -0
- package/dist/builder/ast.d.ts.map +1 -0
- package/dist/builder/attack.d.ts +41 -0
- package/dist/builder/attack.d.ts.map +1 -0
- package/dist/builder/d20.d.ts +6 -0
- package/dist/builder/d20.d.ts.map +1 -0
- package/dist/builder/dc.d.ts +26 -0
- package/dist/builder/dc.d.ts.map +1 -0
- package/dist/builder/example.d.ts +356 -0
- package/dist/builder/example.d.ts.map +1 -0
- package/dist/builder/factory.d.ts +17 -0
- package/dist/builder/factory.d.ts.map +1 -0
- package/dist/builder/index.cjs +106 -0
- package/dist/builder/index.cjs.map +1 -1
- package/dist/builder/index.d.ts +8 -379
- package/dist/builder/index.d.ts.map +1 -0
- package/dist/builder/index.js +105 -1
- package/dist/builder/index.js.map +1 -1
- package/dist/builder/nodes.d.ts +61 -0
- package/dist/builder/nodes.d.ts.map +1 -0
- package/dist/builder/prob.d.ts +3 -0
- package/dist/builder/prob.d.ts.map +1 -0
- package/dist/builder/roll.d.ts +205 -0
- package/dist/builder/roll.d.ts.map +1 -0
- package/dist/builder/save.d.ts +19 -0
- package/dist/builder/save.d.ts.map +1 -0
- package/dist/builder/types.d.ts +66 -0
- package/dist/builder/types.d.ts.map +1 -0
- package/dist/common/bounce.d.ts +32 -0
- package/dist/common/bounce.d.ts.map +1 -0
- package/dist/common/errors.d.ts +26 -0
- package/dist/common/errors.d.ts.map +1 -0
- package/dist/common/lru-cache.d.ts +17 -0
- package/dist/common/lru-cache.d.ts.map +1 -0
- package/dist/common/types.d.ts +65 -0
- package/dist/common/types.d.ts.map +1 -0
- package/dist/index.d.ts +9 -111
- package/dist/index.d.ts.map +1 -0
- package/dist/parser/dice.d.ts +70 -0
- package/dist/parser/dice.d.ts.map +1 -0
- package/dist/parser/parser.d.ts +14 -0
- package/dist/parser/parser.d.ts.map +1 -0
- package/dist/pmf/mixture.d.ts +37 -0
- package/dist/pmf/mixture.d.ts.map +1 -0
- package/dist/pmf/pmf.d.ts +380 -0
- package/dist/pmf/pmf.d.ts.map +1 -0
- package/dist/{pmf-D5VRghZI.d.ts → pmf/query.d.ts} +6 -464
- package/dist/pmf/query.d.ts.map +1 -0
- package/package.json +16 -15
- package/.claude/worktrees/amazing-matsumoto-27220c/LICENSE +0 -21
- package/.claude/worktrees/amazing-matsumoto-27220c/README.md +0 -518
- package/.claude/worktrees/vibrant-lovelace-0cc9e7/LICENSE +0 -21
- package/.claude/worktrees/vibrant-lovelace-0cc9e7/README.md +0 -518
- package/.claude/worktrees/wizardly-mclean-e375de/LICENSE +0 -21
- package/.claude/worktrees/wizardly-mclean-e375de/README.md +0 -518
- package/CHANGELOG.md +0 -224
- package/dist/builder/index.d.cts +0 -379
- package/dist/index.d.cts +0 -111
- package/dist/pmf-D5VRghZI.d.cts +0 -1129
package/CHANGELOG.md
DELETED
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project are documented here.
|
|
4
|
-
|
|
5
|
-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
-
|
|
8
|
-
## [0.4.0]
|
|
9
|
-
|
|
10
|
-
Pushes damage-attribution / provenance and D&D-probability logic that the
|
|
11
|
-
consuming app (dprcalc) had hand-rolled over PMF internals down into the
|
|
12
|
-
library, so the provenance model and dice math stay owned here. All additive
|
|
13
|
-
except the Elemental-Adept bounce fix noted below.
|
|
14
|
-
|
|
15
|
-
### Added
|
|
16
|
-
|
|
17
|
-
- **`PMF.applyHitFrequency(frequency)`** — provenance-preserving mass
|
|
18
|
-
redistribution for effects that only occur with some probability (conditional
|
|
19
|
-
attacks, on-hit riders, sub-one AoE fractions): scales every hit bin (damage
|
|
20
|
-
> 0) by `frequency` and moves the freed mass into a `missNone` bin. Unlike a
|
|
21
|
-
bare `scaleMass`/`mapDamage`, it scales per-label `count` **and** `attr`, so a
|
|
22
|
-
frequency-scaled PMF still renders correctly in the damage-attribution charts.
|
|
23
|
-
Replaces the app's hand-rolled `applyFrequencyToPMF`, which dropped `attr`.
|
|
24
|
-
- **`PMF.missNone(epsilon?)`** / **`MISS_NONE_OUTCOME`** — canonical "clean miss"
|
|
25
|
-
delta (point mass at 0 tagged with the `missNone` `OutcomeType`, distinct from
|
|
26
|
-
`PMF.zero`'s builder-side `miss` label), and the label as a single source of
|
|
27
|
-
truth.
|
|
28
|
-
- **`PMF.hitProbability()` / `PMF.missProbability()`** — the `1 - P(0)` idiom
|
|
29
|
-
(miss encoded at damage 0), centralized.
|
|
30
|
-
- **`PMF.rebin(maxBuckets)`** — coarsen a wide distribution into ≤ N contiguous
|
|
31
|
-
equal-width buckets, aggregating `count`/`attr` provenance. For charting wide
|
|
32
|
-
distributions, not DPR math.
|
|
33
|
-
- **`PMF.attributionByValue()` / `DiceQuery.attributionByValue()`** — split each
|
|
34
|
-
damage value's probability mass across outcome labels (by `attr` for
|
|
35
|
-
damage-bearing bins, by `count` for the clean-miss bin), returning per-label
|
|
36
|
-
`value → mass` series. The provenance core of the stacked attribution chart.
|
|
37
|
-
- **`DiceQuery.countSinglesWith(label)`** — how many independent single PMFs can
|
|
38
|
-
produce a given outcome label.
|
|
39
|
-
- **`ALL_OUTCOME_TYPES`**, **`OUTCOME_DISPLAY_ORDER`**, **`sortOutcomes()`** —
|
|
40
|
-
canonical `OutcomeType` enumeration + stack / display orderings, replacing
|
|
41
|
-
per-consumer outcome tables.
|
|
42
|
-
- **`critProbability(critRange, rollType)`** and **`RollType`** (now exported
|
|
43
|
-
from the package root as well as `@yipe/dice/builder`) — advantage-aware
|
|
44
|
-
P(crit) for a given crit window.
|
|
45
|
-
- **`calculateBounceOdds(diceCount, dieFaces, options?)`** and
|
|
46
|
-
**`BounceOddsOptions`** — the "birthday problem" for bouncing damage dice
|
|
47
|
-
(Chromatic Orb), honoring Elemental Adept and Empowered Spell. Moved out of the
|
|
48
|
-
app; the base and Elemental-Adept cases are now computed **exactly** (verified
|
|
49
|
-
against brute-force enumeration in `tests/bounce.test.ts`).
|
|
50
|
-
|
|
51
|
-
### Fixed
|
|
52
|
-
|
|
53
|
-
- **`calculateBounceOdds` Elemental Adept was approximate.** The former
|
|
54
|
-
hand-derived adjustment factor drifted from the exact value by up to ~3.5%
|
|
55
|
-
(e.g. 3×d8, min-roll 3: 0.4965 → 0.5313). The Elemental-Adept branch now uses
|
|
56
|
-
an exact elementary-symmetric-polynomial computation. Consumers relying on the
|
|
57
|
-
old numbers for bouncing spells with Elemental Adept will see small DPR shifts.
|
|
58
|
-
- **`calculateBounceOdds` Empowered Spell returned certainty when rerolling all
|
|
59
|
-
dice.** When `rerollDamageDice >= diceCount` (no dice kept), the model claimed
|
|
60
|
-
a guaranteed match (1.0) instead of treating the reroll as a second
|
|
61
|
-
independent roll. It now correctly yields `1 - (1 - pMatch)^2` in that case
|
|
62
|
-
(e.g. 3×d8 reroll-all: 1.0 → 0.5693).
|
|
63
|
-
|
|
64
|
-
## [0.3.0]
|
|
65
|
-
|
|
66
|
-
### Fixed (mathematical correctness)
|
|
67
|
-
|
|
68
|
-
Every fix is verified against an independent brute-force enumeration (see
|
|
69
|
-
`tests/math-correctness.test.ts`).
|
|
70
|
-
|
|
71
|
-
- **`DiceQuery.probabilityOf(label)` over-counted.** It summed the full `bin.p`
|
|
72
|
-
of every combined bin that merely *contained* a label, but bins hold multiple
|
|
73
|
-
mutually-exclusive outcomes — so `probabilityOf('crit')` returned 0.49 where
|
|
74
|
-
the true P(crit)=0.05. It now returns the correct Poisson-binomial marginal
|
|
75
|
-
(= `probAtLeastOne`). `missChance()` is fixed by the same change.
|
|
76
|
-
- **`DiceQuery.probExactlyK([labels], k)` array-path** delegated to the buggy
|
|
77
|
-
`probabilityOf`, disagreeing with the (correct) single-label string path; both
|
|
78
|
-
now match the true binomial.
|
|
79
|
-
- **`DiceQuery.variance()/stddev()`** used the unstable `E[X²]−E[X]²` form and
|
|
80
|
-
lost all precision under a large constant damage offset (`1d6 + 1e8` gave
|
|
81
|
-
variance 2 instead of 35/12). Now uses the centered, additive-per-single form.
|
|
82
|
-
- **`DiceQuery.mean()/variance()`** now stay consistent with an explicitly
|
|
83
|
-
supplied `combined` that diverges from `convolve(singles)`.
|
|
84
|
-
- **`PMF.convolve()` produced `NaN`** for a zero-mass operand (divide-by-zero in
|
|
85
|
-
the mass rescale), silently poisoning `DiceQuery.combined`. A zero-mass
|
|
86
|
-
convolution now correctly yields mass 0.
|
|
87
|
-
- **`probAtLeastOne` is now mass-invariant** (per-attack probability divided by
|
|
88
|
-
the single's mass) and clamped to `[0,1]` (was returning `1.0000000002`).
|
|
89
|
-
- **`PMF.firstSuccessWeights`** throws on `pSpecial > pSuccess` instead of
|
|
90
|
-
returning out-of-range probabilities.
|
|
91
|
-
- **Parser `hd6`/`hd20` (reroll-one)** used a weighted union giving
|
|
92
|
-
`P(1)=1/(2s−1)`; now uses `reroll(1)` for the correct `P(1)=1/s²`. The parser
|
|
93
|
-
`hd` distribution now matches the builder's `reroll(1)` exactly (the
|
|
94
|
-
previously loosened tests are tightened).
|
|
95
|
-
- **`DiceQuery.snapshot()` outcome probabilities** (`atLeastOneProbability`,
|
|
96
|
-
`allProbability`) were aggregated as expected counts and could exceed 1 for
|
|
97
|
-
multi-attack queries. They now use the correct Poisson-binomial marginals
|
|
98
|
-
(P(≥1) and P(all)) and are always in [0,1]. (`damageRange.avg` remains a
|
|
99
|
-
size-biased mean for N≥2 — see Known limitations.)
|
|
100
|
-
- **Parser save-for-half mislabeled outcomes** on odd/constant damage (e.g.
|
|
101
|
-
`(d20 DC 15) * (3) save half`): the brittle "2×half ∈ hit" detection
|
|
102
|
-
false-negatived, tagging the success mass as `saveFail` and the failure mass
|
|
103
|
-
as `hit`. Detection is now deterministic (the presence of a save distribution),
|
|
104
|
-
so `saveHalf`/`saveFail` are always labeled correctly.
|
|
105
|
-
- **`PMF.compact()` corrupted PMFs that shared bin objects.** It deleted
|
|
106
|
-
sub-epsilon `count`/`attr` entries *in place* and reused that same bin
|
|
107
|
-
reference in the compacted map. Because bins are shared by reference across
|
|
108
|
-
PMFs (the `branch()` / `addScaled()` / `scaleMass()` fast paths can carry
|
|
109
|
-
another PMF's bin objects), this silently mutated the source PMF — and the
|
|
110
|
-
receiver's own bins. `compact()` now clones each surviving bin before pruning;
|
|
111
|
-
the compacted result is unchanged.
|
|
112
|
-
|
|
113
|
-
### Security / hardening
|
|
114
|
-
|
|
115
|
-
- **Parser resource-exhaustion guards.** Adversarial expressions are rejected
|
|
116
|
-
with a `DiceParseError` instead of exhausting CPU/memory: a die over 1,000,000
|
|
117
|
-
faces, a dice count over 10,000, a keep whose `faces^count` enumeration would
|
|
118
|
-
exceed 1,000,000 outcomes, and a binary operation whose `faces₁ × faces₂` work
|
|
119
|
-
would exceed 100,000,000 face pairs. The last closes a gap the per-operand
|
|
120
|
-
caps missed — two individually-legal large dice (e.g. `d100000 + d100000`,
|
|
121
|
-
~10¹⁰ operations) previously hung for tens of seconds. All legitimate
|
|
122
|
-
expressions, including `d100000`, still parse.
|
|
123
|
-
|
|
124
|
-
### Known limitations (documented; recommend maintainer review)
|
|
125
|
-
|
|
126
|
-
These are real but require API/architecture decisions, so they are documented
|
|
127
|
-
and pinned by tests rather than changed blindly:
|
|
128
|
-
|
|
129
|
-
- **Parser crit probability with bonus to-hit dice is wrong.** With bonus dice in
|
|
130
|
-
the to-hit (e.g. Bless, `d20 + 5 + 1d4`), the string parser collapses crit to
|
|
131
|
-
`1/(20·∏bonusSides)` (and the DPR is off by a few %), because the natural-20
|
|
132
|
-
slice can't be separated after the bonus dice are convolved. **The builder API
|
|
133
|
-
computes it correctly** — use `d20.plus(..).plus(bonusDie).ac(..).onCrit(..)`.
|
|
134
|
-
- **Multi-attack conditional damage `avg` is size-biased.** The `avg` returned by
|
|
135
|
-
`damageStatsFrom()` (single label), `outcomeDamageRanges()` and
|
|
136
|
-
`snapshot().damageRange` aggregates the combined PMF's `count` (an *expected
|
|
137
|
-
count* for N≥2 attacks), so it is the size-biased mean E[dmg·#label]/E[#label]
|
|
138
|
-
rather than a clean conditional expectation. It is correct for a single attack.
|
|
139
|
-
(The associated *probabilities* are now correct — see Fixed.)
|
|
140
|
-
- **`PMF.mixN`/`gate`/`branch` build O(2ⁿ) identifier strings**, which can blow up
|
|
141
|
-
(multi-MB, eventual `RangeError`) for very deep (≈20+) gate chains. Prefer
|
|
142
|
-
`PMF.exclusive`/`PMF.mix` for large mixtures.
|
|
143
|
-
|
|
144
|
-
### Breaking
|
|
145
|
-
|
|
146
|
-
- **`PMF.toJSON()` now returns a plain object** (`{ bins, normalized, identifier }`)
|
|
147
|
-
instead of a JSON string, following the standard `toJSON` contract. This means
|
|
148
|
-
`JSON.stringify(pmf)` no longer double-encodes. If you relied on the old string
|
|
149
|
-
return, call the new `PMF.toJSONString()` instead.
|
|
150
|
-
- **`DiceQuery.firstSuccessSplit()` is typed as `OutcomeType | OutcomeType[]`**
|
|
151
|
-
(previously `string | string[]`). Only affects callers passing arbitrary strings;
|
|
152
|
-
valid outcome labels are unchanged.
|
|
153
|
-
|
|
154
|
-
### Added
|
|
155
|
-
|
|
156
|
-
- **`DiceParseError`** — `parse()` now throws this typed error (a subclass of
|
|
157
|
-
`Error`) instead of a plain `Error`. Existing `try/catch` and message checks keep
|
|
158
|
-
working; you can now narrow with `instanceof DiceParseError` and read
|
|
159
|
-
`error.expression` / `error.cause`.
|
|
160
|
-
- **`PMF.toJSONString()`** — returns the JSON string form (the previous
|
|
161
|
-
`toJSON()` behavior).
|
|
162
|
-
- **`DiceQuery.stdev()`** — alias of `stddev()`, matching `PMF.stdev()`.
|
|
163
|
-
- **`PMF.hasAttribution()`** — O(1) check for whether a PMF already carries
|
|
164
|
-
damage-attribution metadata.
|
|
165
|
-
|
|
166
|
-
### Performance
|
|
167
|
-
|
|
168
|
-
- **`DiceQuery.mean()` / `variance()` / `stddev()` use moment additivity**
|
|
169
|
-
(`E[ΣX]=ΣE[X]`, `Var[ΣX]=ΣVar[X]`) computed directly from the single PMFs.
|
|
170
|
-
- **`DiceQuery.combined` is now built lazily** (on first access) instead of in
|
|
171
|
-
the constructor. Combined with the above, a query used only for DPR / mean /
|
|
172
|
-
variance never performs the N-way convolution — multi-attack stats-only
|
|
173
|
-
queries are ~10000× faster (e.g. ~17 ms → ~0.001 ms for a heavy 4-attack
|
|
174
|
-
expression). The materialized `combined` distribution is unchanged; mean and
|
|
175
|
-
variance may differ from the previous convolution-based values by at most a
|
|
176
|
-
few ULP (well within the library's tolerances).
|
|
177
|
-
- **`DiceQuery.combinedWithAttribution()` reuses `combined`** when every single
|
|
178
|
-
already carries attribution (as parser-generated PMFs do), avoiding a
|
|
179
|
-
redundant convolution pass. Result is bit-for-bit identical.
|
|
180
|
-
- **`PMF.convolve()` inner loop accumulates directly into destination bins**
|
|
181
|
-
instead of allocating a temporary bin per term and merging — ~1.6× faster
|
|
182
|
-
convolution (the cost of building the combined distribution for charts). The
|
|
183
|
-
probability channel is bit-identical; per-label `count`/`attr` provenance may
|
|
184
|
-
re-associate by at most a few ULP (≤1e-14 even at 16 attacks, ~100× below the
|
|
185
|
-
eps pruning threshold).
|
|
186
|
-
- **Convolution cache-key fingerprint is memoized** on each (immutable) PMF
|
|
187
|
-
instead of re-summing every bin key on every `convolve()` call — ~36% faster
|
|
188
|
-
on warm cache hits. Bit-identical (`PMF.fingerprint()` returns the same string).
|
|
189
|
-
- **`Dice.calculateHitDistribution()` no longer clones outcome distributions per
|
|
190
|
-
face** — it reads the stored maps once instead of `O(faces × outcomes)` clones,
|
|
191
|
-
~10% faster cold parsing of wide-support expressions. Bit-identical.
|
|
192
|
-
- **`DiceQuery.toStackedChartData()` drops a dead `O(N×L)` precomputation pass**
|
|
193
|
-
whose result was discarded — ~2× faster. Bit-identical.
|
|
194
|
-
- Minor bit-identical cleanups on the parse path (`Dice.toPMF` iterates the
|
|
195
|
-
internal face map directly; `multiplyDiceByDice` uses a `Map`).
|
|
196
|
-
- **`DiceQuery` count queries (`probExactlyK` / `probAtLeastK` / `probAtMostK`,
|
|
197
|
-
array-label paths)** compute each attack's success probability and the binomial
|
|
198
|
-
DP once instead of rebuilding a query per requested count (~3× on the looped
|
|
199
|
-
variants).
|
|
200
|
-
- **`PMF.branch()` assembles its Bernoulli mixture in a single pass** rather than
|
|
201
|
-
chaining two `addScaled` calls (which copied the failure branch's bins twice).
|
|
202
|
-
- **`keepSumPMF` packs its DP state into a single integer key** instead of a
|
|
203
|
-
`"used|r"` string parsed on every transition.
|
|
204
|
-
- **`computeMaxOfPMF` walks the support once with a running CDF** for large pools,
|
|
205
|
-
reducing the max-of computation from O(N²) to O(N).
|
|
206
|
-
- **`Dice.reroll()` uses a `Set` for membership** and **`Dice.binaryOp()` hoists
|
|
207
|
-
the inner die's face list** out of its loop.
|
|
208
|
-
|
|
209
|
-
All of the above were verified bit-for-bit identical (probabilities, counts,
|
|
210
|
-
means, variance) across the full expression corpus.
|
|
211
|
-
|
|
212
|
-
### Changed
|
|
213
|
-
|
|
214
|
-
- Removed the stale `package-lock.json` (the project uses Yarn 4) and dropped the
|
|
215
|
-
unused `ts-node` / `tsconfig-paths` dev dependencies.
|
|
216
|
-
- Removed `console.error` calls from the parser so the library no longer writes to
|
|
217
|
-
a consumer's console.
|
|
218
|
-
- Internal refactors with no behavioral change: deduplicated `Bin` clone/scale
|
|
219
|
-
logic in `PMF`, removed dead code and impossible iterator branches, and tightened
|
|
220
|
-
internal `any` usage.
|
|
221
|
-
- `Dice.outcomeData` is typed `Partial<Record<OutcomeType, …>>` (dropping an
|
|
222
|
-
unsound `as Record<…>` cast); `getFullOutcomeDistribution()`'s return type
|
|
223
|
-
matches. Type-only change; runtime output is unchanged.
|
|
224
|
-
- Added a `yarn format` script (ESLint autofix).
|
package/dist/builder/index.d.cts
DELETED
|
@@ -1,379 +0,0 @@
|
|
|
1
|
-
import { b as RollType, P as PMF, l as DiceQuery, C as CritConfig, L as LRUCache } from '../pmf-D5VRghZI.cjs';
|
|
2
|
-
|
|
3
|
-
type RollFactory = {
|
|
4
|
-
(count: number, sides?: number, modifier?: number): RollBuilder;
|
|
5
|
-
(count: number, die: RollBuilder, modifier?: number): RollBuilder;
|
|
6
|
-
d(sides: number | string): RollBuilder;
|
|
7
|
-
hd20(): RollBuilder;
|
|
8
|
-
d4(): RollBuilder;
|
|
9
|
-
d6(): RollBuilder;
|
|
10
|
-
d8(): RollBuilder;
|
|
11
|
-
d10(): RollBuilder;
|
|
12
|
-
d12(): RollBuilder;
|
|
13
|
-
d20(): RollBuilder;
|
|
14
|
-
d100(): RollBuilder;
|
|
15
|
-
flat(n: number): RollBuilder;
|
|
16
|
-
};
|
|
17
|
-
type KeepMode = "highest" | "lowest";
|
|
18
|
-
type RollConfig = {
|
|
19
|
-
count: number;
|
|
20
|
-
sides: number;
|
|
21
|
-
modifier: number;
|
|
22
|
-
reroll: number;
|
|
23
|
-
explode: number;
|
|
24
|
-
minimum: number;
|
|
25
|
-
bestOf: number;
|
|
26
|
-
keep: {
|
|
27
|
-
total: number;
|
|
28
|
-
count: number;
|
|
29
|
-
mode: KeepMode;
|
|
30
|
-
} | undefined;
|
|
31
|
-
rollType: RollType;
|
|
32
|
-
isSubtraction?: boolean;
|
|
33
|
-
};
|
|
34
|
-
type Resolution = {
|
|
35
|
-
pmf: PMF;
|
|
36
|
-
check: PMF;
|
|
37
|
-
weights: {
|
|
38
|
-
[key: string]: number;
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
type AttackResolution = Resolution & {
|
|
42
|
-
hit: PMF;
|
|
43
|
-
crit: PMF;
|
|
44
|
-
miss: PMF;
|
|
45
|
-
weights: {
|
|
46
|
-
hit: number;
|
|
47
|
-
crit: number;
|
|
48
|
-
miss: number;
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
type SaveResolution = Resolution & {
|
|
52
|
-
saveFail: PMF;
|
|
53
|
-
saveSuccess: PMF;
|
|
54
|
-
weights: {
|
|
55
|
-
success: number;
|
|
56
|
-
fail: number;
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
interface CheckBuilder {
|
|
60
|
-
resolve(eps?: number): Resolution;
|
|
61
|
-
toExpression(): string;
|
|
62
|
-
readonly pmf: PMF;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
type SaveOutcome = "normal" | "half";
|
|
66
|
-
declare class SaveBuilder implements CheckBuilder {
|
|
67
|
-
readonly check: DCBuilder;
|
|
68
|
-
private readonly failureEffect?;
|
|
69
|
-
private readonly saveOutcome;
|
|
70
|
-
constructor(check: DCBuilder, failureEffect?: RollBuilder | undefined, saveOutcome?: SaveOutcome);
|
|
71
|
-
saveHalf(): SaveBuilder;
|
|
72
|
-
toExpression(): string;
|
|
73
|
-
resolve(eps?: number): SaveResolution;
|
|
74
|
-
toPMF(eps?: number): PMF;
|
|
75
|
-
get pmf(): PMF;
|
|
76
|
-
toQuery(eps?: number): DiceQuery;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
interface SaveConfig {
|
|
80
|
-
dc: number;
|
|
81
|
-
}
|
|
82
|
-
declare class DCBuilder extends RollBuilder {
|
|
83
|
-
private readonly saveConfig;
|
|
84
|
-
constructor(baseRoll: RollBuilder, saveConfig?: SaveConfig);
|
|
85
|
-
dc(saveDC: number): DCBuilder;
|
|
86
|
-
get saveDC(): number;
|
|
87
|
-
add(anotherRoll: RollBuilder): DCBuilder;
|
|
88
|
-
addRoll(count?: number): DCBuilder;
|
|
89
|
-
onSaveFailure(val: number): SaveBuilder;
|
|
90
|
-
onSaveFailure(val: string): SaveBuilder;
|
|
91
|
-
onSaveFailure(val: RollBuilder): SaveBuilder;
|
|
92
|
-
onSaveFailure(count: number, die: RollBuilder): SaveBuilder;
|
|
93
|
-
onSaveFailure(count: number, sides: number): SaveBuilder;
|
|
94
|
-
onSaveFailure(count: number, die: RollBuilder, modifier: number): SaveBuilder;
|
|
95
|
-
onSaveFailure(count: number, sides: number, modifier: number): SaveBuilder;
|
|
96
|
-
withElvenAccuracy(): never;
|
|
97
|
-
toExpression(): string;
|
|
98
|
-
toPMF(eps?: number): PMF;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
type ExpressionNode = DieNode | ConstantNode | SumNode | AddNode | KeepNode | D20RollNode | HalfNode | MaxOfNode;
|
|
102
|
-
type DieNode = {
|
|
103
|
-
type: "die";
|
|
104
|
-
sides: number;
|
|
105
|
-
reroll?: number;
|
|
106
|
-
minimum?: number;
|
|
107
|
-
explode?: number;
|
|
108
|
-
};
|
|
109
|
-
type ConstantNode = {
|
|
110
|
-
type: "constant";
|
|
111
|
-
value: number;
|
|
112
|
-
};
|
|
113
|
-
type SumNode = {
|
|
114
|
-
type: "sum";
|
|
115
|
-
count: number;
|
|
116
|
-
child: ExpressionNode;
|
|
117
|
-
};
|
|
118
|
-
type AddNode = {
|
|
119
|
-
type: "add";
|
|
120
|
-
children: {
|
|
121
|
-
node: ExpressionNode;
|
|
122
|
-
sign: 1 | -1;
|
|
123
|
-
}[];
|
|
124
|
-
};
|
|
125
|
-
type KeepNode = {
|
|
126
|
-
type: "keep";
|
|
127
|
-
mode: "highest" | "lowest";
|
|
128
|
-
count: number;
|
|
129
|
-
child: SumNode | KeepNode;
|
|
130
|
-
};
|
|
131
|
-
type D20RollNode = {
|
|
132
|
-
type: "d20Roll";
|
|
133
|
-
rollType: "advantage" | "disadvantage" | "elven accuracy";
|
|
134
|
-
child: ExpressionNode;
|
|
135
|
-
};
|
|
136
|
-
type HalfNode = {
|
|
137
|
-
type: "half";
|
|
138
|
-
child: ExpressionNode;
|
|
139
|
-
};
|
|
140
|
-
type MaxOfNode = {
|
|
141
|
-
type: "maxOf";
|
|
142
|
-
count: number;
|
|
143
|
-
child: ExpressionNode;
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
declare const defaultConfig: RollConfig;
|
|
147
|
-
declare class RollBuilder {
|
|
148
|
-
protected readonly subRollConfigs: readonly RollConfig[];
|
|
149
|
-
constructor(countOrConfigs?: number | readonly RollConfig[]);
|
|
150
|
-
protected create(configs: readonly RollConfig[]): RollBuilder;
|
|
151
|
-
protected get lastConfig(): RollConfig;
|
|
152
|
-
hasHiddenState(): boolean;
|
|
153
|
-
getSubRollConfigs(): readonly RollConfig[];
|
|
154
|
-
static fromConfig(config: Partial<RollConfig>): RollBuilder;
|
|
155
|
-
static fromConfigs(configs: Partial<RollConfig>[]): RollBuilder;
|
|
156
|
-
static fromArgs(...args: any[]): RollBuilder;
|
|
157
|
-
d(sides: number | undefined): RollBuilder;
|
|
158
|
-
plus(modOrRoll: number | RollBuilder | undefined): RollBuilder;
|
|
159
|
-
plus(count: number, die: RollBuilder): RollBuilder;
|
|
160
|
-
minus(modOrRoll: number | RollBuilder | undefined): RollBuilder;
|
|
161
|
-
minus(count: number, die: RollBuilder): RollBuilder;
|
|
162
|
-
/** Apply one-pass reroll threshold (k): reroll faces 1..k once, must keep. */
|
|
163
|
-
reroll(value: number): RollBuilder;
|
|
164
|
-
/** Set finite explode count for max-face explosions (Infinity allowed). */
|
|
165
|
-
explode(count?: number | undefined): RollBuilder;
|
|
166
|
-
/** Apply per-die minimum value (min > 0). */
|
|
167
|
-
minimum(val: number | undefined): RollBuilder;
|
|
168
|
-
bestOf(count: number | undefined): RollBuilder;
|
|
169
|
-
keepHighest(total: number, count: number): RollBuilder;
|
|
170
|
-
keepLowest(total: number, count: number): RollBuilder;
|
|
171
|
-
keepHighestAll(total: number, count: number): PooledRollBuilder;
|
|
172
|
-
keepLowestAll(total: number, count: number): PooledRollBuilder;
|
|
173
|
-
withAdvantage(): RollBuilder;
|
|
174
|
-
withDisadvantage(): RollBuilder;
|
|
175
|
-
add(anotherRoll: RollBuilder | undefined): RollBuilder;
|
|
176
|
-
withBonus(anotherRoll: RollBuilder): RollBuilder;
|
|
177
|
-
addRoll(count?: number): RollBuilder;
|
|
178
|
-
scaleDice(scale: number): RollBuilder;
|
|
179
|
-
doubleDice(): RollBuilder;
|
|
180
|
-
alwaysHits(): AlwaysHitBuilder;
|
|
181
|
-
alwaysCrits(): AlwaysCritBuilder;
|
|
182
|
-
copy(): RollBuilder;
|
|
183
|
-
d4: () => RollBuilder;
|
|
184
|
-
d6: () => RollBuilder;
|
|
185
|
-
d8: () => RollBuilder;
|
|
186
|
-
d10: () => RollBuilder;
|
|
187
|
-
d12: () => RollBuilder;
|
|
188
|
-
d20: () => RollBuilder;
|
|
189
|
-
d100: () => RollBuilder;
|
|
190
|
-
withElvenAccuracy(): RollBuilder;
|
|
191
|
-
toExpression(): string;
|
|
192
|
-
toPMF(eps?: number): PMF;
|
|
193
|
-
get pmf(): PMF;
|
|
194
|
-
toQuery(eps?: number): DiceQuery;
|
|
195
|
-
toAST(): ExpressionNode;
|
|
196
|
-
private configToSingleExpressionWithoutModifier;
|
|
197
|
-
getRootDieConfig(): RollConfig | undefined;
|
|
198
|
-
getAllDieConfigs(): readonly RollConfig[];
|
|
199
|
-
getBonusDiceConfigs(): RollConfig[];
|
|
200
|
-
getBonusDicePMFs(check: RollBuilder, eps?: number): PMF[];
|
|
201
|
-
get modifier(): number;
|
|
202
|
-
get rollType(): RollType;
|
|
203
|
-
get baseReroll(): number;
|
|
204
|
-
half(): HalfRollBuilder;
|
|
205
|
-
maxOf(count: number): MaxOfRollBuilder;
|
|
206
|
-
ac(_targetAC: number): ACBuilder;
|
|
207
|
-
dc(_saveDC: number): DCBuilder;
|
|
208
|
-
}
|
|
209
|
-
declare class HalfRollBuilder extends RollBuilder {
|
|
210
|
-
private readonly innerRoll;
|
|
211
|
-
constructor(innerRoll: RollBuilder);
|
|
212
|
-
hasHiddenState(): boolean;
|
|
213
|
-
get lastConfig(): RollConfig;
|
|
214
|
-
getSubRollConfigs(): readonly RollConfig[];
|
|
215
|
-
toExpression(): string;
|
|
216
|
-
toAST(): ExpressionNode;
|
|
217
|
-
toPMF(eps?: number): PMF;
|
|
218
|
-
copy(): HalfRollBuilder;
|
|
219
|
-
}
|
|
220
|
-
declare class MaxOfRollBuilder extends RollBuilder {
|
|
221
|
-
private readonly innerRoll;
|
|
222
|
-
private readonly count;
|
|
223
|
-
private readonly diceCount?;
|
|
224
|
-
private readonly diceSides?;
|
|
225
|
-
constructor(innerRoll: RollBuilder, count: number, diceCount?: number | undefined, diceSides?: number | undefined);
|
|
226
|
-
hasHiddenState(): boolean;
|
|
227
|
-
get lastConfig(): RollConfig;
|
|
228
|
-
getSubRollConfigs(): readonly RollConfig[];
|
|
229
|
-
toExpression(): string;
|
|
230
|
-
toAST(): ExpressionNode;
|
|
231
|
-
toPMF(eps?: number): PMF;
|
|
232
|
-
copy(): MaxOfRollBuilder;
|
|
233
|
-
}
|
|
234
|
-
declare class AlwaysHitBuilder extends RollBuilder {
|
|
235
|
-
readonly attackConfig: CritConfig;
|
|
236
|
-
constructor(baseRoll: RollBuilder, attackConfig?: CritConfig);
|
|
237
|
-
protected create(configs: readonly RollConfig[]): RollBuilder;
|
|
238
|
-
onHit(val: number): AttackBuilder;
|
|
239
|
-
onHit(val: string): AttackBuilder;
|
|
240
|
-
onHit(val: RollBuilder): AttackBuilder;
|
|
241
|
-
onHit(count: number, die: RollBuilder): AttackBuilder;
|
|
242
|
-
onHit(count: number, sides: number): AttackBuilder;
|
|
243
|
-
onHit(count: number, die: RollBuilder, modifier: number): AttackBuilder;
|
|
244
|
-
onHit(count: number, sides: number, modifier: number): AttackBuilder;
|
|
245
|
-
get critThreshold(): number;
|
|
246
|
-
critOn(critThreshold: number): AlwaysHitBuilder;
|
|
247
|
-
alwaysCrits(): AlwaysCritBuilder;
|
|
248
|
-
toExpression(): string;
|
|
249
|
-
toPMF(): PMF;
|
|
250
|
-
copy(): AlwaysHitBuilder;
|
|
251
|
-
}
|
|
252
|
-
declare class AlwaysCritBuilder extends RollBuilder {
|
|
253
|
-
readonly attackConfig: CritConfig & {
|
|
254
|
-
ac?: number;
|
|
255
|
-
};
|
|
256
|
-
readonly fromAlwaysHit: boolean;
|
|
257
|
-
constructor(baseRoll: RollBuilder, attackConfig?: CritConfig & {
|
|
258
|
-
ac?: number;
|
|
259
|
-
}, fromAlwaysHit?: boolean);
|
|
260
|
-
protected create(configs: readonly RollConfig[]): RollBuilder;
|
|
261
|
-
onHit(val: number): AttackBuilder;
|
|
262
|
-
onHit(val: string): AttackBuilder;
|
|
263
|
-
onHit(val: RollBuilder): AttackBuilder;
|
|
264
|
-
onHit(count: number, die: RollBuilder): AttackBuilder;
|
|
265
|
-
onHit(count: number, sides: number): AttackBuilder;
|
|
266
|
-
onHit(count: number, die: RollBuilder, modifier: number): AttackBuilder;
|
|
267
|
-
onHit(count: number, sides: number, modifier: number): AttackBuilder;
|
|
268
|
-
get critThreshold(): number;
|
|
269
|
-
critOn(critThreshold: number): AlwaysCritBuilder;
|
|
270
|
-
toExpression(): string;
|
|
271
|
-
toPMF(): PMF;
|
|
272
|
-
copy(): AlwaysCritBuilder;
|
|
273
|
-
}
|
|
274
|
-
declare class ParsedRollBuilder extends RollBuilder {
|
|
275
|
-
private readonly cachedPMF;
|
|
276
|
-
private readonly originalExpression;
|
|
277
|
-
constructor(expression: string);
|
|
278
|
-
hasHiddenState(): boolean;
|
|
279
|
-
protected create(configs: readonly RollConfig[]): RollBuilder;
|
|
280
|
-
toPMF(_eps?: number): PMF;
|
|
281
|
-
toExpression(): string;
|
|
282
|
-
toAST(): ExpressionNode;
|
|
283
|
-
copy(): ParsedRollBuilder;
|
|
284
|
-
doubleDice(): ParsedRollBuilder;
|
|
285
|
-
}
|
|
286
|
-
declare class PooledRollBuilder extends RollBuilder {
|
|
287
|
-
private readonly baseAST;
|
|
288
|
-
private readonly baseExpression;
|
|
289
|
-
constructor(baseAST: ExpressionNode, baseExpression: string, configs?: readonly RollConfig[]);
|
|
290
|
-
protected create(configs: readonly RollConfig[]): PooledRollBuilder;
|
|
291
|
-
hasHiddenState(): boolean;
|
|
292
|
-
d(_sides: number | undefined): RollBuilder;
|
|
293
|
-
reroll(_value: number): RollBuilder;
|
|
294
|
-
explode(_count?: number | undefined): RollBuilder;
|
|
295
|
-
minimum(_val: number | undefined): RollBuilder;
|
|
296
|
-
bestOf(_count: number | undefined): RollBuilder;
|
|
297
|
-
keepHighest(_total: number, _count: number): RollBuilder;
|
|
298
|
-
keepLowest(_total: number, _count: number): RollBuilder;
|
|
299
|
-
withAdvantage(): RollBuilder;
|
|
300
|
-
withDisadvantage(): RollBuilder;
|
|
301
|
-
withElvenAccuracy(): RollBuilder;
|
|
302
|
-
toAST(): ExpressionNode;
|
|
303
|
-
toExpression(): string;
|
|
304
|
-
copy(): PooledRollBuilder;
|
|
305
|
-
scaleDice(scale: number): RollBuilder;
|
|
306
|
-
times(count: number): PooledRollBuilder;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
type ActionEffect = RollBuilder;
|
|
310
|
-
declare class AttackBuilder implements CheckBuilder {
|
|
311
|
-
readonly check: ACBuilder | AlwaysHitBuilder | AlwaysCritBuilder;
|
|
312
|
-
private readonly hitEffect?;
|
|
313
|
-
private readonly critEffect?;
|
|
314
|
-
private readonly missEffect?;
|
|
315
|
-
constructor(check: ACBuilder | AlwaysHitBuilder | AlwaysCritBuilder, hitEffect?: ActionEffect | undefined, critEffect?: (ActionEffect | null) | undefined, missEffect?: ActionEffect | undefined);
|
|
316
|
-
onCrit(val: number): AttackBuilder;
|
|
317
|
-
onCrit(val: string): AttackBuilder;
|
|
318
|
-
onCrit(val: RollBuilder): AttackBuilder;
|
|
319
|
-
onCrit(count: number, die: RollBuilder): AttackBuilder;
|
|
320
|
-
onCrit(count: number, sides: number): AttackBuilder;
|
|
321
|
-
onCrit(count: number, die: RollBuilder, modifier: number): AttackBuilder;
|
|
322
|
-
onCrit(count: number, sides: number, modifier: number): AttackBuilder;
|
|
323
|
-
onMiss(val: number): AttackBuilder;
|
|
324
|
-
onMiss(val: string): AttackBuilder;
|
|
325
|
-
onMiss(val: RollBuilder): AttackBuilder;
|
|
326
|
-
onMiss(count: number, die: RollBuilder): AttackBuilder;
|
|
327
|
-
onMiss(count: number, sides: number): AttackBuilder;
|
|
328
|
-
onMiss(count: number, die: RollBuilder, modifier: number): AttackBuilder;
|
|
329
|
-
onMiss(count: number, sides: number, modifier: number): AttackBuilder;
|
|
330
|
-
noCrit(): AttackBuilder;
|
|
331
|
-
toExpression(): string;
|
|
332
|
-
resolveProbabilities(check: ACBuilder | AlwaysHitBuilder | AlwaysCritBuilder, eps?: number): {
|
|
333
|
-
pSuccess: number;
|
|
334
|
-
pHit: number;
|
|
335
|
-
pCrit: number;
|
|
336
|
-
pMiss: number;
|
|
337
|
-
};
|
|
338
|
-
resolve(eps?: number): AttackResolution;
|
|
339
|
-
toPMF(eps?: number): PMF;
|
|
340
|
-
get pmf(): PMF;
|
|
341
|
-
toQuery(eps?: number): DiceQuery;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
interface AttackConfig {
|
|
345
|
-
ac: number;
|
|
346
|
-
critThreshold: number;
|
|
347
|
-
}
|
|
348
|
-
declare class ACBuilder extends RollBuilder {
|
|
349
|
-
readonly attackConfig: AttackConfig;
|
|
350
|
-
constructor(baseRoll: RollBuilder, ac: number, attackConfig?: AttackConfig);
|
|
351
|
-
onHit(val: number): AttackBuilder;
|
|
352
|
-
onHit(val: string): AttackBuilder;
|
|
353
|
-
onHit(val: RollBuilder): AttackBuilder;
|
|
354
|
-
onHit(count: number, die: RollBuilder): AttackBuilder;
|
|
355
|
-
onHit(count: number, sides: number): AttackBuilder;
|
|
356
|
-
onHit(count: number, die: RollBuilder, modifier: number): AttackBuilder;
|
|
357
|
-
onHit(count: number, sides: number, modifier: number): AttackBuilder;
|
|
358
|
-
get critThreshold(): number;
|
|
359
|
-
critOn(threshold: number): ACBuilder;
|
|
360
|
-
alwaysCrits(): AlwaysCritBuilder;
|
|
361
|
-
toExpression(): string;
|
|
362
|
-
toPMF(eps?: number): PMF;
|
|
363
|
-
copy(): ACBuilder;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
declare function d(sides: number | string): RollBuilder;
|
|
367
|
-
declare const d4: RollBuilder;
|
|
368
|
-
declare const d6: RollBuilder;
|
|
369
|
-
declare const d8: RollBuilder;
|
|
370
|
-
declare const d10: RollBuilder;
|
|
371
|
-
declare const d12: RollBuilder;
|
|
372
|
-
declare const d20: RollBuilder;
|
|
373
|
-
declare const hd20: RollBuilder;
|
|
374
|
-
declare const d100: RollBuilder;
|
|
375
|
-
declare const flat: (n: number) => RollBuilder;
|
|
376
|
-
declare const roll: RollFactory;
|
|
377
|
-
declare const builderPMFCache: LRUCache<string, PMF>;
|
|
378
|
-
|
|
379
|
-
export { ACBuilder, AlwaysCritBuilder, AlwaysHitBuilder, AttackBuilder, type AttackConfig, type AttackResolution, type CheckBuilder, DCBuilder, HalfRollBuilder, type KeepMode, MaxOfRollBuilder, ParsedRollBuilder, PooledRollBuilder, type Resolution, RollBuilder, type RollConfig, type RollFactory, RollType, SaveBuilder, type SaveOutcome, type SaveResolution, builderPMFCache, d, d10, d100, d12, d20, d4, d6, d8, defaultConfig, flat, hd20, roll };
|