@yipe/dice 0.10.0 → 0.12.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/README.md +278 -8
- package/dist/builder/ac.d.ts +44 -1
- package/dist/builder/ac.d.ts.map +1 -1
- package/dist/builder/arguments.d.ts +6 -0
- package/dist/builder/arguments.d.ts.map +1 -0
- package/dist/builder/ast.d.ts +36 -7
- package/dist/builder/ast.d.ts.map +1 -1
- package/dist/builder/attack.d.ts +104 -2
- package/dist/builder/attack.d.ts.map +1 -1
- package/dist/builder/dc.d.ts +13 -0
- package/dist/builder/dc.d.ts.map +1 -1
- package/dist/builder/example.d.ts +11 -15
- package/dist/builder/example.d.ts.map +1 -1
- package/dist/builder/expression.d.ts +72 -0
- package/dist/builder/expression.d.ts.map +1 -0
- package/dist/builder/factory.d.ts +2 -3
- package/dist/builder/factory.d.ts.map +1 -1
- package/dist/builder/index.cjs +3844 -1273
- package/dist/builder/index.cjs.map +1 -1
- package/dist/builder/index.js +3836 -1274
- package/dist/builder/index.js.map +1 -1
- package/dist/builder/nodes.d.ts +8 -1
- package/dist/builder/nodes.d.ts.map +1 -1
- package/dist/builder/prob.d.ts +9 -0
- package/dist/builder/prob.d.ts.map +1 -1
- package/dist/builder/roll.d.ts +157 -19
- package/dist/builder/roll.d.ts.map +1 -1
- package/dist/builder/save.d.ts +6 -1
- package/dist/builder/save.d.ts.map +1 -1
- package/dist/builder/types.d.ts +19 -0
- package/dist/builder/types.d.ts.map +1 -1
- package/dist/common/bounce.d.ts +63 -5
- package/dist/common/bounce.d.ts.map +1 -1
- package/dist/common/lru-cache.d.ts +29 -1
- package/dist/common/lru-cache.d.ts.map +1 -1
- package/dist/common/types.d.ts +33 -0
- package/dist/common/types.d.ts.map +1 -1
- package/dist/index.cjs +1288 -388
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1285 -389
- package/dist/index.js.map +1 -1
- package/dist/parser/dice.d.ts +52 -16
- package/dist/parser/dice.d.ts.map +1 -1
- package/dist/parser/parser.d.ts +1 -5
- package/dist/parser/parser.d.ts.map +1 -1
- package/dist/parser/rollType.d.ts +4 -4
- package/dist/parser/scaleDice.d.ts +14 -0
- package/dist/parser/scaleDice.d.ts.map +1 -0
- package/dist/pmf/mixture.d.ts +17 -3
- package/dist/pmf/mixture.d.ts.map +1 -1
- package/dist/pmf/pmf.d.ts +130 -33
- package/dist/pmf/pmf.d.ts.map +1 -1
- package/dist/pmf/query.d.ts +25 -12
- package/dist/pmf/query.d.ts.map +1 -1
- package/dist/turn/effects.d.ts +114 -0
- package/dist/turn/effects.d.ts.map +1 -0
- package/dist/turn/index.d.ts +3 -1
- package/dist/turn/index.d.ts.map +1 -1
- package/dist/turn/plan.d.ts +115 -12
- package/dist/turn/plan.d.ts.map +1 -1
- package/dist/turn/state.d.ts +22 -8
- package/dist/turn/state.d.ts.map +1 -1
- package/dist/turn/turn.d.ts +162 -26
- package/dist/turn/turn.d.ts.map +1 -1
- package/dist/turn/types.d.ts +180 -21
- package/dist/turn/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/builder/attack.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import type { DiceMatchInfo } from "../common/types.js";
|
|
1
2
|
import { PMF } from "../pmf/pmf.js";
|
|
2
3
|
import type { DiceQuery } from "../pmf/query.js";
|
|
3
4
|
import type { ACBuilder } from "./ac.js";
|
|
4
5
|
import { AlwaysCritBuilder, AlwaysHitBuilder, RollBuilder } from "./roll.js";
|
|
5
|
-
import type { AttackResolution, CheckBuilder } from "./types.js";
|
|
6
|
+
import type { AttackResolution, Check, CheckBuilder } from "./types.js";
|
|
6
7
|
type ActionEffect = RollBuilder;
|
|
7
8
|
/** Clears the resolved-attack PMF cache (test/bench seam; mirrors {@link clearParserCache}). */
|
|
8
9
|
export declare function clearAttackCache(): void;
|
|
@@ -11,7 +12,11 @@ export declare class AttackBuilder implements CheckBuilder {
|
|
|
11
12
|
private readonly hitEffect?;
|
|
12
13
|
private readonly critEffect?;
|
|
13
14
|
private readonly missEffect?;
|
|
14
|
-
|
|
15
|
+
private readonly separateDamage;
|
|
16
|
+
private readonly rerollThreshold?;
|
|
17
|
+
private readonly minimumDieValue?;
|
|
18
|
+
private readonly halfOnMissFlag;
|
|
19
|
+
constructor(check: ACBuilder | AlwaysHitBuilder | AlwaysCritBuilder, hitEffect?: ActionEffect | undefined, critEffect?: ActionEffect | null | undefined, missEffect?: ActionEffect | undefined, separateDamage?: readonly RollBuilder[], rerollThreshold?: number | undefined, minimumDieValue?: number | undefined, halfOnMissFlag?: boolean);
|
|
15
20
|
onCrit(val: number): AttackBuilder;
|
|
16
21
|
onCrit(val: string): AttackBuilder;
|
|
17
22
|
onCrit(val: RollBuilder): AttackBuilder;
|
|
@@ -27,14 +32,111 @@ export declare class AttackBuilder implements CheckBuilder {
|
|
|
27
32
|
onMiss(count: number, die: RollBuilder, modifier: number): AttackBuilder;
|
|
28
33
|
onMiss(count: number, sides: number, modifier: number): AttackBuilder;
|
|
29
34
|
noCrit(): AttackBuilder;
|
|
35
|
+
/**
|
|
36
|
+
* Adds a second damage channel, convolved into the hit AND crit payloads (its dice double on
|
|
37
|
+
* a crit like any attack damage) but excluded from base-payload transforms — base-payload
|
|
38
|
+
* rerolls and once-per-turn reroll substitutions never touch it. Chainable; several calls
|
|
39
|
+
* accumulate into one convolved channel.
|
|
40
|
+
*/
|
|
41
|
+
plusSeparateDamage(damage: RollBuilder): AttackBuilder;
|
|
42
|
+
/**
|
|
43
|
+
* Lets every die group of the BASE payload (hit, and the crit branch when it is explicit)
|
|
44
|
+
* reroll low faces once, leaving `plusSeparateDamage` channels untouched — so a weapon reads in
|
|
45
|
+
* whichever order the caller likes. The threshold is a permission cap, not an obligation: a
|
|
46
|
+
* group rerolls faces `1..min(threshold, cap)`, where `cap` is the largest face whose kept value
|
|
47
|
+
* `max(face, floor)` is below the expected value of a fresh floored face (`floor` from the
|
|
48
|
+
* group's own `minimum` and {@link minimumDamageDie}; with no floor, `floor(sides / 2)`). For a
|
|
49
|
+
* die that does not explode that is optimal play, and the result is monotone in `threshold`.
|
|
50
|
+
* A group's own `reroll` is kept when it is higher. `RollBuilder.reroll()` keeps its own
|
|
51
|
+
* obligation semantics; this is the attack-level verb.
|
|
52
|
+
*/
|
|
53
|
+
rerollDamage(threshold: number): AttackBuilder;
|
|
54
|
+
/**
|
|
55
|
+
* Raises every die of the BASE payload (hit, and the crit branch when it is explicit) to at
|
|
56
|
+
* least `minimum`, leaving `plusSeparateDamage` channels untouched. A group's own higher
|
|
57
|
+
* `minimum` is kept. Order-independent with respect to `plusSeparateDamage` and
|
|
58
|
+
* `rerollDamage` (whose cap accounts for the floor).
|
|
59
|
+
*/
|
|
60
|
+
minimumDamageDie(minimum: number): AttackBuilder;
|
|
61
|
+
/**
|
|
62
|
+
* The miss payload becomes `floor(resolved hit payload / 2)` — base plus every
|
|
63
|
+
* `plusSeparateDamage` channel, never the crit payload. Labelled `missDamage`: it is not a
|
|
64
|
+
* landing, so no `first-hit`/`every-hit`/condition trigger reads it, and no reroll
|
|
65
|
+
* substitution touches it. Mutually exclusive with `onMiss()`.
|
|
66
|
+
*/
|
|
67
|
+
halfOnMiss(): AttackBuilder;
|
|
68
|
+
/**
|
|
69
|
+
* The one way to re-derive hit/crit/miss probabilities for an existing attack: `vsAC` and the
|
|
70
|
+
* turn-level condition variants are both callers. Throws if this attack's check has no AC (an
|
|
71
|
+
* `AlwaysHitBuilder`, or a crit-from-always-hit override) — there is nothing to rebind.
|
|
72
|
+
*/
|
|
73
|
+
withCheck(fn: (check: Check) => Check): AttackBuilder;
|
|
74
|
+
private toCheck;
|
|
75
|
+
private static buildCheck;
|
|
76
|
+
/**
|
|
77
|
+
* The base-payload transform for a `rerollDamage` threshold and a `minimumDamageDie` floor
|
|
78
|
+
* (either may be unset). Each only ever raises a group's own `minimum`/`reroll`, and the reroll
|
|
79
|
+
* cap reads the final floor, so applying it again after the other call lands on the same config
|
|
80
|
+
* whichever order the two calls came in.
|
|
81
|
+
*/
|
|
82
|
+
private static baseTransform;
|
|
83
|
+
/** Applies the `rerollDamage`/`minimumDamageDie` values already set on this builder to `effect`. */
|
|
84
|
+
private withStoredBaseTransforms;
|
|
85
|
+
/**
|
|
86
|
+
* Shared by `rerollDamage`/`minimumDamageDie`: rewrite every die-bearing `RollConfig` of a
|
|
87
|
+
* base-payload effect. Refuses (rather than silently no-oping) an effect with no real dice
|
|
88
|
+
* descriptor — a parsed string or a half/scale/maxOf/pooled/composite wrapper — matching the
|
|
89
|
+
* "refuse rather than approximate" bar the reroll substitution's `no-dice-descriptor` uses.
|
|
90
|
+
*/
|
|
91
|
+
private static mapEveryDieGroup;
|
|
92
|
+
/**
|
|
93
|
+
* The attack as a string `parse()` reads back to the same outcomes, up to the natural-1 miss and
|
|
94
|
+
* natural-20 hit, which the grammar does not model. The crit clause is always printed, since a
|
|
95
|
+
* string without one crits with its hit dice doubled: `noCrit()` prints `xcrit0 (<hit>)` (no
|
|
96
|
+
* natural face crits, so every landing is a hit), and a crit range keeps its `xcritN`. A check
|
|
97
|
+
* that crits on every hit (`alwaysCrits()`) prints `xcritS`, S the natural die's size; one that
|
|
98
|
+
* always hits prints just its natural roll, which never totals 0.
|
|
99
|
+
*/
|
|
30
100
|
toExpression(): string;
|
|
101
|
+
/**
|
|
102
|
+
* Hit, crit and miss weights of `check`. A natural 1 misses; a natural 20 hits and crits
|
|
103
|
+
* whatever the AC, the crit threshold, or crit-on-hit; any other natural roll hits when the total
|
|
104
|
+
* reaches the AC, and crits when it is in the crit range (or every hit crits: `alwaysCrits()`).
|
|
105
|
+
* An always-hitting check crits on a natural 20 or in its crit range. A check with no die has no
|
|
106
|
+
* natural roll, so it hits exactly when its flat total and bonus dice reach the AC and never
|
|
107
|
+
* crits unless every hit does.
|
|
108
|
+
*/
|
|
31
109
|
resolveProbabilities(check: ACBuilder | AlwaysHitBuilder | AlwaysCritBuilder, eps?: number): {
|
|
32
110
|
pSuccess: number;
|
|
33
111
|
pHit: number;
|
|
34
112
|
pCrit: number;
|
|
35
113
|
pMiss: number;
|
|
36
114
|
};
|
|
115
|
+
/** Resolves the attack into its weighted slices. `eps` defaults to 0, as for {@link toPMF}: no reachable damage value is pruned. */
|
|
37
116
|
resolve(eps?: number): AttackResolution;
|
|
117
|
+
/**
|
|
118
|
+
* For `dice-match` trigger slicing (`turn/types.ts`'s `HasDiceMatchInfo`): the exact
|
|
119
|
+
* per-damage-value match probability for the hit and crit branches, or `null` per branch when no
|
|
120
|
+
* descriptor is available — a string-parsed effect, a wrapped transform whose PMF isn't fully
|
|
121
|
+
* captured by its `RollConfig`s (half/scale/maxOf/pooled — `cacheKey()` returns `null` for
|
|
122
|
+
* exactly these), a `keep`/`bestOf` pool (ambiguous "the dice" under crit doubling), an
|
|
123
|
+
* exploding pool (per-die `explode` or a pool-wide budget: extra dice join the total), a pool
|
|
124
|
+
* rolled with advantage/disadvantage (one kept die, not a pool), a subtracted pool (its faces
|
|
125
|
+
* lower the damage), a multi-die-type pool, or (crit) `noCrit()`. A single die is supported and
|
|
126
|
+
* can never match (an empty map).
|
|
127
|
+
*
|
|
128
|
+
* The crit branch is built from the SAME crit-effect selection `resolve()` uses (an explicit
|
|
129
|
+
* `onCrit` roll, or the hit dice auto-doubled via `copy().doubleDice()`), so its descriptor
|
|
130
|
+
* reflects the crit branch's REAL doubled pool, not the hit pool re-used blindly.
|
|
131
|
+
*
|
|
132
|
+
* Reads ONLY `hitEffect`/`critEffect` (the base pool) — `plusSeparateDamage` channels are a
|
|
133
|
+
* separate channel, so their dice never count toward a match.
|
|
134
|
+
*/
|
|
135
|
+
diceMatchInfo(_eps?: number): {
|
|
136
|
+
hit: DiceMatchInfo | null;
|
|
137
|
+
crit: DiceMatchInfo | null;
|
|
138
|
+
};
|
|
139
|
+
private matchInfoForEffect;
|
|
38
140
|
/**
|
|
39
141
|
* A cheap, complete key for this attack's resolved PMF, or `null` when it can't be cached soundly (an
|
|
40
142
|
* effect whose PMF isn't captured by its {@link RollConfig}s — see {@link RollBuilder.cacheKey}). Composed
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attack.d.ts","sourceRoot":"","sources":["../../src/builder/attack.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"attack.d.ts","sourceRoot":"","sources":["../../src/builder/attack.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAe,MAAM,iBAAiB,CAAC;AAIlE,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAKtC,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAGhB,WAAW,EACZ,MAAM,QAAQ,CAAC;AAChB,OAAO,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,YAAY,EAAwB,MAAM,SAAS,CAAC;AAE3F,KAAK,YAAY,GAAG,WAAW,CAAC;AAYhC,gGAAgG;AAChG,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC;AAED,qBAAa,aAAc,YAAW,YAAY;IAE9C,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,gBAAgB,GAAG,iBAAiB;IAChE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;IAC3B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC;IAC5B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC;IAI5B,OAAO,CAAC,QAAQ,CAAC,cAAc;IAI/B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC;IACjC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC;IACjC,OAAO,CAAC,QAAQ,CAAC,cAAc;IAdjC,YACW,KAAK,EAAE,SAAS,GAAG,gBAAgB,GAAG,iBAAiB,EAC/C,SAAS,CAAC,EAAE,YAAY,YAAA,EACxB,UAAU,CAAC,EAAE,YAAY,GAAG,IAAI,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;IAwChB,KAAK,CAAC,GAAG,GAAE,MAAU,GAAG,GAAG,CAQ1B;IAED,IAAI,GAAG,QAEN;IAGD,OAAO,CAAC,GAAG,GAAE,MAAU,GAAG,SAAS,CAElC;CACF"}
|
package/dist/builder/dc.d.ts
CHANGED
|
@@ -28,6 +28,19 @@ export declare class DCBuilder extends RollBuilder {
|
|
|
28
28
|
* serializes. So extend the base key with the DC, mirroring {@link AlwaysHitBuilder.cacheKey}.
|
|
29
29
|
*/
|
|
30
30
|
cacheKey(): string | null;
|
|
31
|
+
/**
|
|
32
|
+
* P(success) and P(failure) of this save: success iff natural roll + bonus dice + modifier ≥ DC,
|
|
33
|
+
* with no natural-1/natural-20 rule (a check with no die compares its flat total alone). Each side
|
|
34
|
+
* is summed from its own outcomes, so a certain success has a failure chance of exactly 0.
|
|
35
|
+
*/
|
|
36
|
+
saveProbabilities(): {
|
|
37
|
+
pSuccess: number;
|
|
38
|
+
pFail: number;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* The check outcome as a PMF: a success at 0, a failure at 1 (so `hitProbability()` is the
|
|
42
|
+
* chance the save fails — the chance the effect lands). `SaveBuilder.resolve().check` is this PMF.
|
|
43
|
+
*/
|
|
31
44
|
toPMF(eps?: number): PMF;
|
|
32
45
|
}
|
|
33
46
|
export {};
|
package/dist/builder/dc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dc.d.ts","sourceRoot":"","sources":["../../src/builder/dc.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dc.d.ts","sourceRoot":"","sources":["../../src/builder/dc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAIjC,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,UAAU,UAAU;IAClB,EAAE,EAAE,MAAM,CAAC;CACZ;AAQD,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F"}
|
|
@@ -12,9 +12,7 @@ export declare const fullAttackWithCritAndMiss: import("./attack.js").AttackBuil
|
|
|
12
12
|
export declare const fullAttackWithCritAndMissExprExpected = "(d20 + 5 AC 10) * (2d6) crit (4d6) miss (5)";
|
|
13
13
|
export declare const basicDamageRoll: RollBuilder;
|
|
14
14
|
export declare const basicDamageRollExprExpected = "1d6 + 3";
|
|
15
|
-
/** Basic 2d6 + 3 damage roll
|
|
16
|
-
* For multiple dice, you need to use roll().
|
|
17
|
-
*/
|
|
15
|
+
/** Basic 2d6 + 3 damage roll; multiple dice use roll(). */
|
|
18
16
|
export declare const basic2d6Plus3: RollBuilder;
|
|
19
17
|
export declare const basic2d6Plus3ExprExpected = "2d6 + 3";
|
|
20
18
|
/** Rollling 2 x (1d6+3) */
|
|
@@ -32,18 +30,17 @@ export declare const basicShorthandD6RollExprExpected = "2d6 + 3";
|
|
|
32
30
|
/** Using die shortcuts without roll() */
|
|
33
31
|
export declare const shortcutDie: RollBuilder;
|
|
34
32
|
export declare const shortcutDieExprExpected = "1d8 + 2";
|
|
35
|
-
/** Flat modifier only (no dice)
|
|
36
|
-
*
|
|
37
|
-
* Many methods take pure numbers, so this may not even be needed in many cases.
|
|
33
|
+
/** Flat modifier only (no dice); roll.flat(n) is the same. Pure-number args are accepted
|
|
34
|
+
* directly, so a bare flat is rarely needed.
|
|
38
35
|
* */
|
|
39
36
|
export declare const flatFive: RollBuilder;
|
|
40
37
|
export declare const flatFiveExprExpected = "5";
|
|
41
38
|
/** Negative base dice */
|
|
42
39
|
export declare const negativeBaseDieInline: RollBuilder;
|
|
43
|
-
export declare const negativeBaseDieInlineExprExpected = "-1d8";
|
|
40
|
+
export declare const negativeBaseDieInlineExprExpected = "0 - 1d8";
|
|
44
41
|
/** Negative base dice explicit */
|
|
45
42
|
export declare const negativeBaseDie: RollBuilder;
|
|
46
|
-
export declare const negativeBaseDieExprExpected = "-1d8";
|
|
43
|
+
export declare const negativeBaseDieExprExpected = "0 - 1d8";
|
|
47
44
|
/** Subtracting a bonus die via negative roll part.
|
|
48
45
|
* Useful for effects like Bane
|
|
49
46
|
*/
|
|
@@ -54,10 +51,10 @@ export declare const singleD20: RollBuilder;
|
|
|
54
51
|
export declare const singleD20ExprExpected = "d20";
|
|
55
52
|
/** Adding a bunch */
|
|
56
53
|
export declare const addAWholeBunch: RollBuilder;
|
|
57
|
-
export declare const addAWholeBunchExprExpected = "
|
|
54
|
+
export declare const addAWholeBunchExprExpected = "d20 + 1d12 + 1d10 + 1d8 + 1d6";
|
|
58
55
|
/** Subtracting a bunch */
|
|
59
56
|
export declare const subtractAWholeBunch: RollBuilder;
|
|
60
|
-
export declare const subtractAWholeBunchExprExpected = "-1d20 - 1d12 - 1d10 - 1d8
|
|
57
|
+
export declare const subtractAWholeBunchExprExpected = "1d6 - 1d20 - 1d12 - 1d10 - 1d8";
|
|
61
58
|
export declare const addingMultipleConstants: RollBuilder;
|
|
62
59
|
export declare const addingMultipleConstantsExprExpected = "1d6 + 6";
|
|
63
60
|
export declare const realisticChaining: RollBuilder;
|
|
@@ -92,8 +89,7 @@ export declare const disD20ExprExpected = "d20 < d20";
|
|
|
92
89
|
/** Advantage on hd20. */
|
|
93
90
|
export declare const advHd20: RollBuilder;
|
|
94
91
|
export declare const advHd20ExprExpected = "hd20 > hd20";
|
|
95
|
-
/** Complex chain: 2d6 + 1d8 + 4(d4 reroll 1) + 5
|
|
96
|
-
* Note that reroll(1) applies to the immediate roll before it.
|
|
92
|
+
/** Complex chain: 2d6 + 1d8 + 4(d4 reroll 1) + 5; reroll(1) applies to the roll before it.
|
|
97
93
|
*/
|
|
98
94
|
export declare const complexDamage: RollBuilder;
|
|
99
95
|
export declare const complexDamageExprExpected = "4(d4 reroll 1) + 1d8 + 2d6 + 5";
|
|
@@ -109,7 +105,7 @@ export declare const bestOfExampleExprExpected = "4kh3(1d6)";
|
|
|
109
105
|
/** Double a d6 roll, resulting in 2d6. */
|
|
110
106
|
export declare const doubleD6: RollBuilder;
|
|
111
107
|
export declare const doubleD6ExprExpected = "2d6";
|
|
112
|
-
/** Double a d6+1 roll, resulting in 2d6+2
|
|
108
|
+
/** Double a d6+1 roll, resulting in 2d6+2 — modifiers double too. */
|
|
113
109
|
export declare const doubleD6Plus1: RollBuilder;
|
|
114
110
|
export declare const doubleD6Plus1ExprExpected = "2d6 + 2";
|
|
115
111
|
/** Double a 2d6 roll, resulting in 4d6. */
|
|
@@ -145,10 +141,10 @@ export declare const detailedAttack: ReturnType<ACBuilder["onHit"]>;
|
|
|
145
141
|
export declare const detailedAttackExprExpected = "(d20 + 9 AC 17) * (1d12 + 5) xcrit2 (2d12 + 5) miss (0)";
|
|
146
142
|
/** Attack where all hits become crits (natural 1s still miss). */
|
|
147
143
|
export declare const alwaysCritsAttack: ReturnType<ACBuilder["onHit"]>;
|
|
148
|
-
export declare const alwaysCritsAttackExprExpected = "d20 + 5 * (1d8)
|
|
144
|
+
export declare const alwaysCritsAttackExprExpected = "(d20 + 5 AC 10) * (1d8) xcrit20 (2d8)";
|
|
149
145
|
/** Attack that always hits and always crits (no misses at all). */
|
|
150
146
|
export declare const alwaysHitsAlwaysCrits: ReturnType<ACBuilder["onHit"]>;
|
|
151
|
-
export declare const alwaysHitsAlwaysCritsExprExpected = "d20 * (1d8)
|
|
147
|
+
export declare const alwaysHitsAlwaysCritsExprExpected = "d20 * (1d8) xcrit20 (2d8)";
|
|
152
148
|
/**
|
|
153
149
|
* Basic save: d20 + 5 vs DC 15; on failure, take 3d6.
|
|
154
150
|
* Use `saveHalf()` to apply half damage on success.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"example.d.ts","sourceRoot":"","sources":["../../src/builder/example.ts"],"names":[],"mappings":"AAEA,OAAO,MAAM,CAAC;AACd,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,MAAM,CAAC;AACd,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEtC,OAAO,KAA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e;IACf,oBAAoB;EAEvB;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,WAAW;IAUjB,MAAM;QAAI,GAAG;QAAa,UAAU;;IACpC,OAAO;QAAI,GAAG;QAAa,UAAU;;IACrC,IAAI;QACF,GAAG;QACH,UAAU;;EAIf;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,WAAW;;;QAYvC,IAAI;QACJ,OAAO;;;;;;;;;;;;EASZ;AAED,wBAAgB,YAAY;;;YAlFtB,GAAG;YACH,UAAU;YACV,KAAK;;;YAGL,GAAG;YACH,UAAU;YACV,KAAK;;;YAGL,GAAG;YACH,UAAU;YACV,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAoCG,GAAG;YAAa,UAAU;;;YACzB,GAAG;YAAa,UAAU;;;YAEnC,GAAG;YACH,UAAU;;;;;;;;;;;;;YAkBV,IAAI;YACJ,OAAO;;;;;;;;;;;;;EA4BZ"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { ExpressionNode } from "./nodes.js";
|
|
2
|
+
import type { RollConfig } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Printing builders as strings the parser reads back to the same distribution.
|
|
5
|
+
*
|
|
6
|
+
* The grammar reads every binary operator left to right at one precedence, so a term that is
|
|
7
|
+
* itself an expression (`d8 reroll 1`, `3>d6`, `d4 > d4`, `(1d6) // 2`) is parenthesised whenever
|
|
8
|
+
* something precedes it, and every operand of a `>`/`<` chain is an atom. `+` adds only to a
|
|
9
|
+
* non-zero running total, so a term joins with ` + ` only when everything before it can never
|
|
10
|
+
* total 0, and with ` ~+ ` (always add) otherwise. The grammar has no unary minus: a sum whose
|
|
11
|
+
* every term is subtracted starts from `0 - `.
|
|
12
|
+
*
|
|
13
|
+
* Each die group is printed from the AST node the resolver reads (`astFromRollConfigs`), so the
|
|
14
|
+
* string follows the builder's own reading of counts, keeps, roll types and signs.
|
|
15
|
+
*/
|
|
16
|
+
/** One additive term of a printed sum: the text of its magnitude, its sign, and the range of that
|
|
17
|
+
* magnitude when it is known. */
|
|
18
|
+
export type ExpressionTerm = {
|
|
19
|
+
readonly text: string;
|
|
20
|
+
readonly sign: 1 | -1;
|
|
21
|
+
readonly range?: readonly [number, number];
|
|
22
|
+
};
|
|
23
|
+
type PrintOptions = {
|
|
24
|
+
/** A lone plain d20 prints as `d20` rather than `1d20` (the check's natural roll). */
|
|
25
|
+
readonly d20Shorthand?: boolean;
|
|
26
|
+
/** A keep-1-of-2 or keep-1-of-3 prints as a `>` / `<` chain (a roll type on a non-d20 die). */
|
|
27
|
+
readonly rollTypeChain?: boolean;
|
|
28
|
+
};
|
|
29
|
+
/** `text` as one argument: parenthesised unless it already is one. */
|
|
30
|
+
export declare function atom(text: string): string;
|
|
31
|
+
/** A number as one argument; the grammar has no negative literal, so `-3` is `(0 - 3)`. */
|
|
32
|
+
export declare function numberAtom(value: number): string;
|
|
33
|
+
/**
|
|
34
|
+
* Joins signed terms into one sum. Zero terms are dropped; a positive term leads when there is
|
|
35
|
+
* one. A term after the first is parenthesised unless it is atomic, and a positive term joins
|
|
36
|
+
* with ` + ` only when the running total before it can never be 0 (its range excludes 0).
|
|
37
|
+
*/
|
|
38
|
+
export declare function joinTerms(terms: readonly ExpressionTerm[]): string;
|
|
39
|
+
/**
|
|
40
|
+
* The text of a scaled result `round(value * numerator / denominator)`: `N ** (inner)`,
|
|
41
|
+
* `(inner) // D`, `(inner) / D` or `(inner) ** N // D`. `**` is the product (`*` is the attack
|
|
42
|
+
* gate); `//` rounds down and `/` rounds up. Round-half and fractional factors have no token.
|
|
43
|
+
*/
|
|
44
|
+
export declare function printScale(inner: string, numerator: number, denominator: number, rounding: "floor" | "round" | "ceil"): string;
|
|
45
|
+
/** The text of an AST node, read by the parser as the same distribution the resolver gives it. */
|
|
46
|
+
export declare function printNode(node: ExpressionNode, options?: PrintOptions): string;
|
|
47
|
+
/** The least and greatest value `node` can resolve to. */
|
|
48
|
+
export declare function nodeRange(node: ExpressionNode): [number, number];
|
|
49
|
+
/**
|
|
50
|
+
* The terms of a plain roll's configs: every die group, then the total of their flats. `root` is
|
|
51
|
+
* the natural-roll config (a d20 root prints first, as `d20`).
|
|
52
|
+
*/
|
|
53
|
+
export declare function configTerms(configs: readonly RollConfig[], root: RollConfig | undefined): ExpressionTerm[];
|
|
54
|
+
/** The minimal shape of a check the printer reads. */
|
|
55
|
+
type CheckDice = {
|
|
56
|
+
getRootDieConfig(): RollConfig | undefined;
|
|
57
|
+
getBonusDiceConfigs(): RollConfig[];
|
|
58
|
+
readonly modifier: number;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* A check's natural roll as the check resolvers read it: ONE root die with its reroll/minimum,
|
|
62
|
+
* rolled with its roll type (`d20`, `hd20`, `d20 > d20`, `(d20 reroll d2) < (d20 reroll d2)`).
|
|
63
|
+
* `undefined` for a check with no die.
|
|
64
|
+
*/
|
|
65
|
+
export declare function rootDieExpression(check: CheckDice): string | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* The to-hit/save total of a check as its resolvers read it: the root die ({@link
|
|
68
|
+
* rootDieExpression}), its flat total, and every bonus die group (Bless, Bane, Guidance).
|
|
69
|
+
*/
|
|
70
|
+
export declare function checkExpression(check: CheckDice): string;
|
|
71
|
+
export {};
|
|
72
|
+
//# sourceMappingURL=expression.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expression.d.ts","sourceRoot":"","sources":["../../src/builder/expression.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAW,cAAc,EAAY,MAAM,SAAS,CAAC;AACjE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C;;;;;;;;;;;;GAYG;AAEH;iCACiC;AACjC,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IA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AAC;AAEF;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,CAMtE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAaxD"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { PMF } from "../pmf/pmf.js";
|
|
1
|
+
import { PMF } from "../pmf/pmf.js";
|
|
3
2
|
import { RollBuilder } from "./roll.js";
|
|
4
3
|
import type { RollFactory } from "./types.js";
|
|
5
4
|
export declare function d(sides: number | string): RollBuilder;
|
|
@@ -13,5 +12,5 @@ export declare const hd20: RollBuilder;
|
|
|
13
12
|
export declare const d100: RollBuilder;
|
|
14
13
|
export declare const flat: (n: number) => RollBuilder;
|
|
15
14
|
export declare const roll: RollFactory;
|
|
16
|
-
export declare const builderPMFCache: LRUCache<string, PMF>;
|
|
15
|
+
export declare const builderPMFCache: import("..").LRUCache<string, PMF>;
|
|
17
16
|
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/builder/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/builder/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAwB3C,wBAAgB,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,WAAW,CAKrD;AAED,eAAO,MAAM,EAAE,aAA0B,CAAC;AAC1C,eAAO,MAAM,EAAE,aAA0B,CAAC;AAC1C,eAAO,MAAM,EAAE,aAA0B,CAAC;AAC1C,eAAO,MAAM,GAAG,aAA2B,CAAC;AAC5C,eAAO,MAAM,GAAG,aAA2B,CAAC;AAC5C,eAAO,MAAM,GAAG,aAA2B,CAAC;AAC5C,eAAO,MAAM,IAAI,aAAqC,CAAC;AACvD,eAAO,MAAM,IAAI,aAA4B,CAAC;AAC9C,eAAO,MAAM,IAAI,MAAO,MAAM,gBAA+B,CAAC;AAE9D,eAAO,MAAM,IAAI,EAAE,WAAmC,CAAC;AAEvD,eAAO,MAAM,eAAe,oCAAwB,CAAC"}
|