@yipe/dice 0.2.16 → 0.2.19

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.
@@ -58,8 +58,29 @@ declare const onPotentCantripOnly: OutcomeType[];
58
58
  declare class DiceQuery {
59
59
  readonly singles: PMF[];
60
60
  readonly combined: PMF;
61
+ private _combinedWithAttr?;
61
62
  constructor(singles: PMF | PMF[], combined?: PMF, eps?: number);
62
63
  private static readonly DEFAULT_OUTCOMES;
64
+ /**
65
+ * Returns a new PMF with damage attribution metadata populated.
66
+ *
67
+ * This method computes attribution on-demand for builder-generated PMFs,
68
+ * enabling them to work with damage attribution charts. The `attr` field
69
+ * tracks how much damage each outcome type contributes at each damage value.
70
+ *
71
+ * For each bin at damage D: sum(attr.values()) ≈ D × P(damage = D)
72
+ *
73
+ * Performance: Cached after first call. Adds minimal overhead vs `combined`.
74
+ *
75
+ * @returns PMF with attr field populated for damage attribution charts
76
+ *
77
+ * @example
78
+ * const attack = d20.plus(5).ac(15).onHit(d(2,6).plus(3)).onCrit(d(2,6))
79
+ * const query = attack.toQuery()
80
+ * const pmf = query.combinedWithAttribution()
81
+ * // Now pmf can be used with toDamageAttributionChartSeries()
82
+ */
83
+ combinedWithAttribution(): PMF;
63
84
  /**
64
85
  * Returns the expected damage across all possible outcomes.
65
86
  *
@@ -743,6 +764,16 @@ declare class PMF {
743
764
  pmf: PMF;
744
765
  weight: number;
745
766
  } | [PMF, number]>, eps?: number): PMF;
767
+ /**
768
+ * Adds damage attribution metadata to this PMF based on existing count metadata.
769
+ * For each bin, sets attr[outcome] = damage × count[outcome].
770
+ *
771
+ * This enables damage attribution charts to work with builder-generated PMFs.
772
+ * The parser generates attr automatically, but builder PMFs only have count.
773
+ *
774
+ * @returns New PMF with attr field populated in each bin
775
+ */
776
+ withAttribution(): PMF;
746
777
  /**
747
778
  * General-purpose N-way mixture.
748
779
  * weights: Array of [weight, PMF].
@@ -58,8 +58,29 @@ declare const onPotentCantripOnly: OutcomeType[];
58
58
  declare class DiceQuery {
59
59
  readonly singles: PMF[];
60
60
  readonly combined: PMF;
61
+ private _combinedWithAttr?;
61
62
  constructor(singles: PMF | PMF[], combined?: PMF, eps?: number);
62
63
  private static readonly DEFAULT_OUTCOMES;
64
+ /**
65
+ * Returns a new PMF with damage attribution metadata populated.
66
+ *
67
+ * This method computes attribution on-demand for builder-generated PMFs,
68
+ * enabling them to work with damage attribution charts. The `attr` field
69
+ * tracks how much damage each outcome type contributes at each damage value.
70
+ *
71
+ * For each bin at damage D: sum(attr.values()) ≈ D × P(damage = D)
72
+ *
73
+ * Performance: Cached after first call. Adds minimal overhead vs `combined`.
74
+ *
75
+ * @returns PMF with attr field populated for damage attribution charts
76
+ *
77
+ * @example
78
+ * const attack = d20.plus(5).ac(15).onHit(d(2,6).plus(3)).onCrit(d(2,6))
79
+ * const query = attack.toQuery()
80
+ * const pmf = query.combinedWithAttribution()
81
+ * // Now pmf can be used with toDamageAttributionChartSeries()
82
+ */
83
+ combinedWithAttribution(): PMF;
63
84
  /**
64
85
  * Returns the expected damage across all possible outcomes.
65
86
  *
@@ -743,6 +764,16 @@ declare class PMF {
743
764
  pmf: PMF;
744
765
  weight: number;
745
766
  } | [PMF, number]>, eps?: number): PMF;
767
+ /**
768
+ * Adds damage attribution metadata to this PMF based on existing count metadata.
769
+ * For each bin, sets attr[outcome] = damage × count[outcome].
770
+ *
771
+ * This enables damage attribution charts to work with builder-generated PMFs.
772
+ * The parser generates attr automatically, but builder PMFs only have count.
773
+ *
774
+ * @returns New PMF with attr field populated in each bin
775
+ */
776
+ withAttribution(): PMF;
746
777
  /**
747
778
  * General-purpose N-way mixture.
748
779
  * weights: Array of [weight, PMF].
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yipe/dice",
3
- "version": "0.2.16",
3
+ "version": "0.2.19",
4
4
  "description": "A high-performance dice probability engine for D&D 5e DPR calculations. Powers dprcalc.com.",
5
5
  "keywords": [
6
6
  "dnd",