@yipe/dice 0.2.2 → 0.2.4
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.d.cts
CHANGED
|
@@ -198,7 +198,6 @@ declare class ACBuilder extends RollBuilder {
|
|
|
198
198
|
onHit(count: number, sides: number): AttackBuilder;
|
|
199
199
|
onHit(count: number, die: RollBuilder, modifier: number): AttackBuilder;
|
|
200
200
|
onHit(count: number, sides: number, modifier: number): AttackBuilder;
|
|
201
|
-
dc(_: number): never;
|
|
202
201
|
get critThreshold(): number;
|
|
203
202
|
critOn(threshold: number): ACBuilder;
|
|
204
203
|
toExpression(): string;
|
package/dist/builder/index.d.ts
CHANGED
|
@@ -198,7 +198,6 @@ declare class ACBuilder extends RollBuilder {
|
|
|
198
198
|
onHit(count: number, sides: number): AttackBuilder;
|
|
199
199
|
onHit(count: number, die: RollBuilder, modifier: number): AttackBuilder;
|
|
200
200
|
onHit(count: number, sides: number, modifier: number): AttackBuilder;
|
|
201
|
-
dc(_: number): never;
|
|
202
201
|
get critThreshold(): number;
|
|
203
202
|
critOn(threshold: number): ACBuilder;
|
|
204
203
|
toExpression(): string;
|
package/dist/builder/index.js
CHANGED
|
@@ -2566,6 +2566,7 @@ var RollBuilder = class _RollBuilder {
|
|
|
2566
2566
|
/** Apply one-pass reroll threshold (k): reroll faces 1..k once, must keep. */
|
|
2567
2567
|
reroll(value) {
|
|
2568
2568
|
if (isNaN(value)) throw new Error("Invalid NaN value for reroll");
|
|
2569
|
+
if (value === this.lastConfig.reroll) return this;
|
|
2569
2570
|
const newConfigs = this.getSubRollConfigs();
|
|
2570
2571
|
newConfigs[newConfigs.length - 1].reroll = value;
|
|
2571
2572
|
return new this.constructor(newConfigs);
|
|
@@ -2662,19 +2663,43 @@ var RollBuilder = class _RollBuilder {
|
|
|
2662
2663
|
return new this.constructor(newConfigs);
|
|
2663
2664
|
}
|
|
2664
2665
|
toExpression() {
|
|
2665
|
-
const
|
|
2666
|
+
const originalDiceConfigs = this.subRollConfigs.filter(
|
|
2666
2667
|
(config) => config.sides && config.sides > 0
|
|
2667
2668
|
);
|
|
2669
|
+
const configGroups = /* @__PURE__ */ new Map();
|
|
2670
|
+
for (const config of originalDiceConfigs) {
|
|
2671
|
+
const keyConfig = { ...config };
|
|
2672
|
+
delete keyConfig.count;
|
|
2673
|
+
delete keyConfig.modifier;
|
|
2674
|
+
const key = JSON.stringify(keyConfig);
|
|
2675
|
+
const existingGroup = configGroups.get(key);
|
|
2676
|
+
if (existingGroup) {
|
|
2677
|
+
existingGroup.totalCount += config.count;
|
|
2678
|
+
} else {
|
|
2679
|
+
configGroups.set(key, { config, totalCount: config.count });
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
const diceConfigs = Array.from(configGroups.values()).map(({ config, totalCount }) => ({
|
|
2683
|
+
...config,
|
|
2684
|
+
count: totalCount
|
|
2685
|
+
})).sort((a, b) => {
|
|
2686
|
+
if (b.sides !== a.sides) return b.sides - a.sides;
|
|
2687
|
+
const complexity = (c) => (c.reroll > 0 ? 1 : 0) + (c.minimum > 0 ? 1 : 0) + (c.explode > 0 ? 1 : 0) + (c.bestOf > 0 ? 1 : 0) + (c.keep ? 1 : 0);
|
|
2688
|
+
return complexity(b) - complexity(a);
|
|
2689
|
+
});
|
|
2668
2690
|
const totalModifier = this.subRollConfigs.reduce(
|
|
2669
2691
|
(sum, config) => sum + config.modifier,
|
|
2670
2692
|
0
|
|
2671
2693
|
);
|
|
2672
2694
|
if (diceConfigs.length === 0) return totalModifier.toString();
|
|
2673
2695
|
const rootConfig = this.getRootDieConfig();
|
|
2696
|
+
const newRootConfig = rootConfig ? diceConfigs.find(
|
|
2697
|
+
(c) => c.sides === rootConfig.sides && c.rollType === rootConfig.rollType && c.reroll === rootConfig.reroll && c.explode === rootConfig.explode && c.minimum === rootConfig.minimum && c.bestOf === rootConfig.bestOf && c.keep === rootConfig.keep
|
|
2698
|
+
) : void 0;
|
|
2674
2699
|
const diceExpressions = diceConfigs.map(
|
|
2675
2700
|
(config) => this.configToSingleExpressionWithoutModifier(
|
|
2676
2701
|
config,
|
|
2677
|
-
config ===
|
|
2702
|
+
config === newRootConfig
|
|
2678
2703
|
)
|
|
2679
2704
|
);
|
|
2680
2705
|
let result = "";
|
|
@@ -3275,11 +3300,6 @@ var ACBuilder = class _ACBuilder extends RollBuilder {
|
|
|
3275
3300
|
const damageRoll = RollBuilder.fromArgs(...args);
|
|
3276
3301
|
return new AttackBuilder(this, damageRoll);
|
|
3277
3302
|
}
|
|
3278
|
-
dc(_) {
|
|
3279
|
-
throw new Error(
|
|
3280
|
-
"Cannot use dc() on an AttackRollBuilder. Use ac() for attack rolls instead."
|
|
3281
|
-
);
|
|
3282
|
-
}
|
|
3283
3303
|
get critThreshold() {
|
|
3284
3304
|
return this.attackConfig.critThreshold;
|
|
3285
3305
|
}
|