@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.
- package/dist/builder/index.cjs +40 -2
- package/dist/builder/index.cjs.map +1 -1
- package/dist/builder/index.d.cts +25 -10
- package/dist/builder/index.d.ts +25 -10
- package/dist/builder/index.js +40 -3
- package/dist/builder/index.js.map +1 -1
- package/package.json +1 -1
package/dist/builder/index.cjs
CHANGED
|
@@ -2875,6 +2875,37 @@ var RollBuilder = class _RollBuilder {
|
|
|
2875
2875
|
const rootConfig = this.getRootDieConfig();
|
|
2876
2876
|
return rootConfig?.reroll || 0;
|
|
2877
2877
|
}
|
|
2878
|
+
half() {
|
|
2879
|
+
return new HalfRollBuilder(this);
|
|
2880
|
+
}
|
|
2881
|
+
};
|
|
2882
|
+
var HalfRollBuilder = class _HalfRollBuilder extends RollBuilder {
|
|
2883
|
+
constructor(innerRoll) {
|
|
2884
|
+
super(0);
|
|
2885
|
+
this.innerRoll = innerRoll;
|
|
2886
|
+
}
|
|
2887
|
+
get lastConfig() {
|
|
2888
|
+
return this.innerRoll.lastConfig;
|
|
2889
|
+
}
|
|
2890
|
+
getSubRollConfigs() {
|
|
2891
|
+
return this.innerRoll.getSubRollConfigs();
|
|
2892
|
+
}
|
|
2893
|
+
toExpression() {
|
|
2894
|
+
const innerExpression = this.innerRoll.toExpression();
|
|
2895
|
+
return `(${innerExpression}) // 2`;
|
|
2896
|
+
}
|
|
2897
|
+
toAST() {
|
|
2898
|
+
return {
|
|
2899
|
+
type: "half",
|
|
2900
|
+
child: this.innerRoll.toAST()
|
|
2901
|
+
};
|
|
2902
|
+
}
|
|
2903
|
+
toPMF(eps = 0) {
|
|
2904
|
+
return pmfFromRollBuilder(this, eps);
|
|
2905
|
+
}
|
|
2906
|
+
copy() {
|
|
2907
|
+
return new _HalfRollBuilder(this.innerRoll.copy());
|
|
2908
|
+
}
|
|
2878
2909
|
};
|
|
2879
2910
|
|
|
2880
2911
|
// src/builder/factory.ts
|
|
@@ -3042,14 +3073,17 @@ function resolve(node, eps = defaultEps) {
|
|
|
3042
3073
|
const rerollOne = !!childDie && (childDie.reroll || 0) >= 1;
|
|
3043
3074
|
return d20RollPMF(node.rollType, rerollOne);
|
|
3044
3075
|
}
|
|
3076
|
+
case "half": {
|
|
3077
|
+
const childPMF = resolve(node.child, eps);
|
|
3078
|
+
return childPMF.scaleDamage(0.5, "floor");
|
|
3079
|
+
}
|
|
3045
3080
|
}
|
|
3046
3081
|
})();
|
|
3047
3082
|
builderPMFCache.set(cacheKey, result);
|
|
3048
3083
|
return result;
|
|
3049
3084
|
}
|
|
3050
3085
|
function pmfFromRollBuilder(rb, eps = defaultEps) {
|
|
3051
|
-
const
|
|
3052
|
-
const ast = astFromRollConfigs(configs) || { type: "constant", value: 0 };
|
|
3086
|
+
const ast = rb.toAST();
|
|
3053
3087
|
return resolve(ast, eps);
|
|
3054
3088
|
}
|
|
3055
3089
|
function resolveSingleDie(die, eps = defaultEps) {
|
|
@@ -3112,6 +3146,7 @@ function findDie(node) {
|
|
|
3112
3146
|
return void 0;
|
|
3113
3147
|
case "sum":
|
|
3114
3148
|
case "d20Roll":
|
|
3149
|
+
case "half":
|
|
3115
3150
|
return findDie(node.child);
|
|
3116
3151
|
case "keep":
|
|
3117
3152
|
return findDie(node.child.child);
|
|
@@ -3177,6 +3212,8 @@ function getASTSignature(node) {
|
|
|
3177
3212
|
return `keep{c:${node.count},m:${node.mode},ch:${getASTSignature(
|
|
3178
3213
|
node.child
|
|
3179
3214
|
)}}`;
|
|
3215
|
+
case "half":
|
|
3216
|
+
return `half{ch:${getASTSignature(node.child)}}`;
|
|
3180
3217
|
case "add": {
|
|
3181
3218
|
let constantValue = 0;
|
|
3182
3219
|
const otherChildrenSigs = [];
|
|
@@ -3548,6 +3585,7 @@ RollBuilder.prototype.dc = function(saveDC) {
|
|
|
3548
3585
|
|
|
3549
3586
|
exports.ACBuilder = ACBuilder;
|
|
3550
3587
|
exports.DCBuilder = DCBuilder;
|
|
3588
|
+
exports.HalfRollBuilder = HalfRollBuilder;
|
|
3551
3589
|
exports.RollBuilder = RollBuilder;
|
|
3552
3590
|
exports.SaveBuilder = SaveBuilder;
|
|
3553
3591
|
exports.builderPMFCache = builderPMFCache;
|