@yipe/dice 0.2.10 → 0.2.11

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.
@@ -1,38 +1,42 @@
1
1
  import { P as PMF, i as DiceQuery, L as LRUCache } from '../pmf-D1p2Re-J.cjs';
2
2
 
3
- type ExpressionNode = DieNode | ConstantNode | SumNode | AddNode | KeepNode | D20RollNode;
3
+ type ExpressionNode = DieNode | ConstantNode | SumNode | AddNode | KeepNode | D20RollNode | HalfNode;
4
4
  type DieNode = {
5
- type: 'die';
5
+ type: "die";
6
6
  sides: number;
7
7
  reroll?: number;
8
8
  minimum?: number;
9
9
  explode?: number;
10
10
  };
11
11
  type ConstantNode = {
12
- type: 'constant';
12
+ type: "constant";
13
13
  value: number;
14
14
  };
15
15
  type SumNode = {
16
- type: 'sum';
16
+ type: "sum";
17
17
  count: number;
18
18
  child: ExpressionNode;
19
19
  };
20
20
  type AddNode = {
21
- type: 'add';
21
+ type: "add";
22
22
  children: {
23
23
  node: ExpressionNode;
24
24
  sign: 1 | -1;
25
25
  }[];
26
26
  };
27
27
  type KeepNode = {
28
- type: 'keep';
29
- mode: 'highest' | 'lowest';
28
+ type: "keep";
29
+ mode: "highest" | "lowest";
30
30
  count: number;
31
31
  child: SumNode | KeepNode;
32
32
  };
33
33
  type D20RollNode = {
34
- type: 'd20Roll';
35
- rollType: 'advantage' | 'disadvantage' | 'elven accuracy';
34
+ type: "d20Roll";
35
+ rollType: "advantage" | "disadvantage" | "elven accuracy";
36
+ child: ExpressionNode;
37
+ };
38
+ type HalfNode = {
39
+ type: "half";
36
40
  child: ExpressionNode;
37
41
  };
38
42
 
@@ -151,6 +155,17 @@ declare class RollBuilder {
151
155
  get modifier(): number;
152
156
  get rollType(): RollType;
153
157
  get baseReroll(): number;
158
+ half(): HalfRollBuilder;
159
+ }
160
+ declare class HalfRollBuilder extends RollBuilder {
161
+ private readonly innerRoll;
162
+ constructor(innerRoll: RollBuilder);
163
+ get lastConfig(): any;
164
+ getSubRollConfigs(): readonly RollConfig[];
165
+ toExpression(): string;
166
+ toAST(): ExpressionNode;
167
+ toPMF(eps?: number): PMF;
168
+ copy(): HalfRollBuilder;
154
169
  }
155
170
 
156
171
  type ActionEffect = RollBuilder;
@@ -264,4 +279,4 @@ declare const flat: (n: number) => RollBuilder;
264
279
  declare const roll: RollFactory;
265
280
  declare const builderPMFCache: LRUCache<string, PMF>;
266
281
 
267
- export { ACBuilder, type AttackConfig, type AttackResolution, type CheckBuilder, DCBuilder, type KeepMode, type Resolution, RollBuilder, type RollConfig, type RollFactory, type RollType, SaveBuilder, type SaveOutcome, type SaveResolution, builderPMFCache, d, d10, d100, d12, d20, d4, d6, d8, defaultConfig, flat, hd20, roll };
282
+ export { ACBuilder, type AttackConfig, type AttackResolution, type CheckBuilder, DCBuilder, HalfRollBuilder, type KeepMode, type Resolution, RollBuilder, type RollConfig, type RollFactory, type RollType, SaveBuilder, type SaveOutcome, type SaveResolution, builderPMFCache, d, d10, d100, d12, d20, d4, d6, d8, defaultConfig, flat, hd20, roll };
@@ -1,38 +1,42 @@
1
1
  import { P as PMF, i as DiceQuery, L as LRUCache } from '../pmf-D1p2Re-J.js';
2
2
 
3
- type ExpressionNode = DieNode | ConstantNode | SumNode | AddNode | KeepNode | D20RollNode;
3
+ type ExpressionNode = DieNode | ConstantNode | SumNode | AddNode | KeepNode | D20RollNode | HalfNode;
4
4
  type DieNode = {
5
- type: 'die';
5
+ type: "die";
6
6
  sides: number;
7
7
  reroll?: number;
8
8
  minimum?: number;
9
9
  explode?: number;
10
10
  };
11
11
  type ConstantNode = {
12
- type: 'constant';
12
+ type: "constant";
13
13
  value: number;
14
14
  };
15
15
  type SumNode = {
16
- type: 'sum';
16
+ type: "sum";
17
17
  count: number;
18
18
  child: ExpressionNode;
19
19
  };
20
20
  type AddNode = {
21
- type: 'add';
21
+ type: "add";
22
22
  children: {
23
23
  node: ExpressionNode;
24
24
  sign: 1 | -1;
25
25
  }[];
26
26
  };
27
27
  type KeepNode = {
28
- type: 'keep';
29
- mode: 'highest' | 'lowest';
28
+ type: "keep";
29
+ mode: "highest" | "lowest";
30
30
  count: number;
31
31
  child: SumNode | KeepNode;
32
32
  };
33
33
  type D20RollNode = {
34
- type: 'd20Roll';
35
- rollType: 'advantage' | 'disadvantage' | 'elven accuracy';
34
+ type: "d20Roll";
35
+ rollType: "advantage" | "disadvantage" | "elven accuracy";
36
+ child: ExpressionNode;
37
+ };
38
+ type HalfNode = {
39
+ type: "half";
36
40
  child: ExpressionNode;
37
41
  };
38
42
 
@@ -151,6 +155,17 @@ declare class RollBuilder {
151
155
  get modifier(): number;
152
156
  get rollType(): RollType;
153
157
  get baseReroll(): number;
158
+ half(): HalfRollBuilder;
159
+ }
160
+ declare class HalfRollBuilder extends RollBuilder {
161
+ private readonly innerRoll;
162
+ constructor(innerRoll: RollBuilder);
163
+ get lastConfig(): any;
164
+ getSubRollConfigs(): readonly RollConfig[];
165
+ toExpression(): string;
166
+ toAST(): ExpressionNode;
167
+ toPMF(eps?: number): PMF;
168
+ copy(): HalfRollBuilder;
154
169
  }
155
170
 
156
171
  type ActionEffect = RollBuilder;
@@ -264,4 +279,4 @@ declare const flat: (n: number) => RollBuilder;
264
279
  declare const roll: RollFactory;
265
280
  declare const builderPMFCache: LRUCache<string, PMF>;
266
281
 
267
- export { ACBuilder, type AttackConfig, type AttackResolution, type CheckBuilder, DCBuilder, type KeepMode, type Resolution, RollBuilder, type RollConfig, type RollFactory, type RollType, SaveBuilder, type SaveOutcome, type SaveResolution, builderPMFCache, d, d10, d100, d12, d20, d4, d6, d8, defaultConfig, flat, hd20, roll };
282
+ export { ACBuilder, type AttackConfig, type AttackResolution, type CheckBuilder, DCBuilder, HalfRollBuilder, type KeepMode, type Resolution, RollBuilder, type RollConfig, type RollFactory, type RollType, SaveBuilder, type SaveOutcome, type SaveResolution, builderPMFCache, d, d10, d100, d12, d20, d4, d6, d8, defaultConfig, flat, hd20, roll };
@@ -2873,6 +2873,37 @@ var RollBuilder = class _RollBuilder {
2873
2873
  const rootConfig = this.getRootDieConfig();
2874
2874
  return rootConfig?.reroll || 0;
2875
2875
  }
2876
+ half() {
2877
+ return new HalfRollBuilder(this);
2878
+ }
2879
+ };
2880
+ var HalfRollBuilder = class _HalfRollBuilder extends RollBuilder {
2881
+ constructor(innerRoll) {
2882
+ super(0);
2883
+ this.innerRoll = innerRoll;
2884
+ }
2885
+ get lastConfig() {
2886
+ return this.innerRoll.lastConfig;
2887
+ }
2888
+ getSubRollConfigs() {
2889
+ return this.innerRoll.getSubRollConfigs();
2890
+ }
2891
+ toExpression() {
2892
+ const innerExpression = this.innerRoll.toExpression();
2893
+ return `(${innerExpression}) // 2`;
2894
+ }
2895
+ toAST() {
2896
+ return {
2897
+ type: "half",
2898
+ child: this.innerRoll.toAST()
2899
+ };
2900
+ }
2901
+ toPMF(eps = 0) {
2902
+ return pmfFromRollBuilder(this, eps);
2903
+ }
2904
+ copy() {
2905
+ return new _HalfRollBuilder(this.innerRoll.copy());
2906
+ }
2876
2907
  };
2877
2908
 
2878
2909
  // src/builder/factory.ts
@@ -3040,14 +3071,17 @@ function resolve(node, eps = defaultEps) {
3040
3071
  const rerollOne = !!childDie && (childDie.reroll || 0) >= 1;
3041
3072
  return d20RollPMF(node.rollType, rerollOne);
3042
3073
  }
3074
+ case "half": {
3075
+ const childPMF = resolve(node.child, eps);
3076
+ return childPMF.scaleDamage(0.5, "floor");
3077
+ }
3043
3078
  }
3044
3079
  })();
3045
3080
  builderPMFCache.set(cacheKey, result);
3046
3081
  return result;
3047
3082
  }
3048
3083
  function pmfFromRollBuilder(rb, eps = defaultEps) {
3049
- const configs = rb.getSubRollConfigs?.() ?? [];
3050
- const ast = astFromRollConfigs(configs) || { type: "constant", value: 0 };
3084
+ const ast = rb.toAST();
3051
3085
  return resolve(ast, eps);
3052
3086
  }
3053
3087
  function resolveSingleDie(die, eps = defaultEps) {
@@ -3110,6 +3144,7 @@ function findDie(node) {
3110
3144
  return void 0;
3111
3145
  case "sum":
3112
3146
  case "d20Roll":
3147
+ case "half":
3113
3148
  return findDie(node.child);
3114
3149
  case "keep":
3115
3150
  return findDie(node.child.child);
@@ -3175,6 +3210,8 @@ function getASTSignature(node) {
3175
3210
  return `keep{c:${node.count},m:${node.mode},ch:${getASTSignature(
3176
3211
  node.child
3177
3212
  )}}`;
3213
+ case "half":
3214
+ return `half{ch:${getASTSignature(node.child)}}`;
3178
3215
  case "add": {
3179
3216
  let constantValue = 0;
3180
3217
  const otherChildrenSigs = [];
@@ -3544,6 +3581,6 @@ RollBuilder.prototype.dc = function(saveDC) {
3544
3581
  return new DCBuilder(this).dc(saveDC);
3545
3582
  };
3546
3583
 
3547
- export { ACBuilder, DCBuilder, RollBuilder, SaveBuilder, builderPMFCache, d, d10, d100, d12, d20, d4, d6, d8, defaultConfig, flat, hd20, roll };
3584
+ export { ACBuilder, DCBuilder, HalfRollBuilder, RollBuilder, SaveBuilder, builderPMFCache, d, d10, d100, d12, d20, d4, d6, d8, defaultConfig, flat, hd20, roll };
3548
3585
  //# sourceMappingURL=index.js.map
3549
3586
  //# sourceMappingURL=index.js.map