@swrpg-online/dice 1.3.0 → 1.4.1

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.
@@ -0,0 +1,17 @@
1
+ import { DieFaceSymbols } from "./types";
2
+ export declare const BOOST_DIE_FACES: Record<number, DieFaceSymbols>;
3
+ export declare const SETBACK_DIE_FACES: Record<number, DieFaceSymbols>;
4
+ export declare const ABILITY_DIE_FACES: Record<number, DieFaceSymbols>;
5
+ export declare const DIFFICULTY_DIE_FACES: Record<number, DieFaceSymbols>;
6
+ export declare const PROFICIENCY_DIE_FACES: Record<number, DieFaceSymbols>;
7
+ export declare const CHALLENGE_DIE_FACES: Record<number, DieFaceSymbols>;
8
+ export declare const FORCE_DIE_FACES: Record<number, DieFaceSymbols>;
9
+ export declare const DICE_FACES: {
10
+ readonly boost: Record<number, DieFaceSymbols>;
11
+ readonly setback: Record<number, DieFaceSymbols>;
12
+ readonly ability: Record<number, DieFaceSymbols>;
13
+ readonly difficulty: Record<number, DieFaceSymbols>;
14
+ readonly proficiency: Record<number, DieFaceSymbols>;
15
+ readonly challenge: Record<number, DieFaceSymbols>;
16
+ readonly force: Record<number, DieFaceSymbols>;
17
+ };
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DICE_FACES = exports.FORCE_DIE_FACES = exports.CHALLENGE_DIE_FACES = exports.PROFICIENCY_DIE_FACES = exports.DIFFICULTY_DIE_FACES = exports.ABILITY_DIE_FACES = exports.SETBACK_DIE_FACES = exports.BOOST_DIE_FACES = void 0;
4
+ exports.BOOST_DIE_FACES = {
5
+ 1: {}, // Blank
6
+ 2: {}, // Blank
7
+ 3: { successes: 1 }, // (S)
8
+ 4: { successes: 1, advantages: 1 }, // (S)(A)
9
+ 5: { advantages: 2 }, // (A)(A)
10
+ 6: { advantages: 1 }, // (A)
11
+ };
12
+ exports.SETBACK_DIE_FACES = {
13
+ 1: {}, // Blank
14
+ 2: {}, // Blank
15
+ 3: { failures: 1 }, // (F)
16
+ 4: { failures: 1 }, // (F)
17
+ 5: { threats: 1 }, // (TH)
18
+ 6: { threats: 1 }, // (TH)
19
+ };
20
+ exports.ABILITY_DIE_FACES = {
21
+ 1: {}, // Blank
22
+ 2: { successes: 1 }, // (S)
23
+ 3: { successes: 1 }, // (S)
24
+ 4: { successes: 2 }, // (S)(S)
25
+ 5: { advantages: 1 }, // (A)
26
+ 6: { advantages: 1 }, // (A)
27
+ 7: { successes: 1, advantages: 1 }, // (S)(A)
28
+ 8: { advantages: 2 }, // (A)(A)
29
+ };
30
+ exports.DIFFICULTY_DIE_FACES = {
31
+ 1: {}, // Blank
32
+ 2: { failures: 1 }, // (F)
33
+ 3: { failures: 2 }, // (F)(F)
34
+ 4: { threats: 1 }, // (TH)
35
+ 5: { threats: 1 }, // (TH)
36
+ 6: { threats: 1 }, // (TH)
37
+ 7: { threats: 2 }, // (TH)(TH)
38
+ 8: { failures: 1, threats: 1 }, // (F)(TH)
39
+ };
40
+ exports.PROFICIENCY_DIE_FACES = {
41
+ 1: {}, // Blank
42
+ 2: { successes: 1 }, // (S)
43
+ 3: { successes: 1 }, // (S)
44
+ 4: { successes: 2 }, // (S)(S)
45
+ 5: { successes: 2 }, // (S)(S)
46
+ 6: { advantages: 1 }, // (A)
47
+ 7: { successes: 1, advantages: 1 }, // (S)(A)
48
+ 8: { successes: 1, advantages: 1 }, // (S)(A)
49
+ 9: { successes: 1, advantages: 1 }, // (S)(A)
50
+ 10: { advantages: 2 }, // (A)(A)
51
+ 11: { successes: 1, advantages: 1 }, // (S)(A)
52
+ 12: { triumphs: 1 }, // (TR) - Triumph also counts as Success
53
+ };
54
+ exports.CHALLENGE_DIE_FACES = {
55
+ 1: {}, // Blank
56
+ 2: { failures: 1 }, // (F)
57
+ 3: { failures: 1 }, // (F)
58
+ 4: { failures: 2 }, // (F)(F)
59
+ 5: { failures: 2 }, // (F)(F)
60
+ 6: { threats: 1 }, // (TH)
61
+ 7: { threats: 1 }, // (TH)
62
+ 8: { failures: 1, threats: 1 }, // (F)(TH)
63
+ 9: { failures: 1, threats: 1 }, // (F)(TH)
64
+ 10: { threats: 2 }, // (TH)(TH)
65
+ 11: { threats: 2 }, // (TH)(TH)
66
+ 12: { despairs: 1 }, // (D) - Despair also counts as Failure
67
+ };
68
+ exports.FORCE_DIE_FACES = {
69
+ 1: { darkSide: 1 }, // (DS)
70
+ 2: { darkSide: 1 }, // (DS)
71
+ 3: { darkSide: 1 }, // (DS)
72
+ 4: { darkSide: 1 }, // (DS)
73
+ 5: { darkSide: 1 }, // (DS)
74
+ 6: { darkSide: 1 }, // (DS)
75
+ 7: { darkSide: 2 }, // (DS)(DS)
76
+ 8: { lightSide: 1 }, // (LS)
77
+ 9: { lightSide: 1 }, // (LS)
78
+ 10: { lightSide: 2 }, // (LS)(LS)
79
+ 11: { lightSide: 2 }, // (LS)(LS)
80
+ 12: { lightSide: 2 }, // (LS)(LS)
81
+ };
82
+ exports.DICE_FACES = {
83
+ boost: exports.BOOST_DIE_FACES,
84
+ setback: exports.SETBACK_DIE_FACES,
85
+ ability: exports.ABILITY_DIE_FACES,
86
+ difficulty: exports.DIFFICULTY_DIE_FACES,
87
+ proficiency: exports.PROFICIENCY_DIE_FACES,
88
+ challenge: exports.CHALLENGE_DIE_FACES,
89
+ force: exports.FORCE_DIE_FACES,
90
+ };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
1
  export { roll } from "./dice";
2
- export type { DicePool, RollResult } from "./types";
3
- export { createSkillCheck, createCombatCheck, createOpposedCheck, createDifficultyPool, } from "./pools";
2
+ export type { DicePool, RollResult, DiceResult, RollOptions, DieFaceSymbols, BoostDieFace, SetbackDieFace, AbilityDieFace, DifficultyDieFace, ProficiencyDieFace, ChallengeDieFace, ForceDieFace, Symbol, } from "./types";
3
+ export { SYMBOLS } from "./types";
4
+ export { BOOST_DIE_FACES, SETBACK_DIE_FACES, ABILITY_DIE_FACES, DIFFICULTY_DIE_FACES, PROFICIENCY_DIE_FACES, CHALLENGE_DIE_FACES, FORCE_DIE_FACES, DICE_FACES, } from "./diceFaces";
5
+ export { createSkillCheck, createCombatCheck, createOpposedCheck, createDifficultyPool, applyTalentModifiers, } from "./pools";
6
+ export type { PoolModifiers } from "./pools";
package/dist/index.js CHANGED
@@ -1,10 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createDifficultyPool = exports.createOpposedCheck = exports.createCombatCheck = exports.createSkillCheck = exports.roll = void 0;
3
+ exports.applyTalentModifiers = exports.createDifficultyPool = exports.createOpposedCheck = exports.createCombatCheck = exports.createSkillCheck = exports.DICE_FACES = exports.FORCE_DIE_FACES = exports.CHALLENGE_DIE_FACES = exports.PROFICIENCY_DIE_FACES = exports.DIFFICULTY_DIE_FACES = exports.ABILITY_DIE_FACES = exports.SETBACK_DIE_FACES = exports.BOOST_DIE_FACES = exports.SYMBOLS = exports.roll = void 0;
4
4
  var dice_1 = require("./dice");
5
5
  Object.defineProperty(exports, "roll", { enumerable: true, get: function () { return dice_1.roll; } });
6
+ var types_1 = require("./types");
7
+ Object.defineProperty(exports, "SYMBOLS", { enumerable: true, get: function () { return types_1.SYMBOLS; } });
8
+ var diceFaces_1 = require("./diceFaces");
9
+ Object.defineProperty(exports, "BOOST_DIE_FACES", { enumerable: true, get: function () { return diceFaces_1.BOOST_DIE_FACES; } });
10
+ Object.defineProperty(exports, "SETBACK_DIE_FACES", { enumerable: true, get: function () { return diceFaces_1.SETBACK_DIE_FACES; } });
11
+ Object.defineProperty(exports, "ABILITY_DIE_FACES", { enumerable: true, get: function () { return diceFaces_1.ABILITY_DIE_FACES; } });
12
+ Object.defineProperty(exports, "DIFFICULTY_DIE_FACES", { enumerable: true, get: function () { return diceFaces_1.DIFFICULTY_DIE_FACES; } });
13
+ Object.defineProperty(exports, "PROFICIENCY_DIE_FACES", { enumerable: true, get: function () { return diceFaces_1.PROFICIENCY_DIE_FACES; } });
14
+ Object.defineProperty(exports, "CHALLENGE_DIE_FACES", { enumerable: true, get: function () { return diceFaces_1.CHALLENGE_DIE_FACES; } });
15
+ Object.defineProperty(exports, "FORCE_DIE_FACES", { enumerable: true, get: function () { return diceFaces_1.FORCE_DIE_FACES; } });
16
+ Object.defineProperty(exports, "DICE_FACES", { enumerable: true, get: function () { return diceFaces_1.DICE_FACES; } });
6
17
  var pools_1 = require("./pools");
7
18
  Object.defineProperty(exports, "createSkillCheck", { enumerable: true, get: function () { return pools_1.createSkillCheck; } });
8
19
  Object.defineProperty(exports, "createCombatCheck", { enumerable: true, get: function () { return pools_1.createCombatCheck; } });
9
20
  Object.defineProperty(exports, "createOpposedCheck", { enumerable: true, get: function () { return pools_1.createOpposedCheck; } });
10
21
  Object.defineProperty(exports, "createDifficultyPool", { enumerable: true, get: function () { return pools_1.createDifficultyPool; } });
22
+ Object.defineProperty(exports, "applyTalentModifiers", { enumerable: true, get: function () { return pools_1.applyTalentModifiers; } });
package/dist/pools.d.ts CHANGED
@@ -1,32 +1,59 @@
1
1
  import { DicePool } from "./types";
2
+ /**
3
+ * Options for applying talent or equipment modifiers to a dice pool
4
+ */
5
+ export type PoolModifiers = {
6
+ automaticSuccesses?: number;
7
+ automaticFailures?: number;
8
+ automaticAdvantages?: number;
9
+ automaticThreats?: number;
10
+ automaticTriumphs?: number;
11
+ automaticDespairs?: number;
12
+ upgradeAbility?: number;
13
+ upgradeDifficulty?: number;
14
+ downgradeProficiency?: number;
15
+ downgradeChallenge?: number;
16
+ };
2
17
  /**
3
18
  * Creates a basic skill check dice pool
4
19
  * @param ability Number of ability (green) dice
5
20
  * @param proficiency Number of proficiency (yellow) dice
21
+ * @param modifiers Optional modifiers from talents, equipment, etc.
6
22
  * @returns DicePool configured for a basic skill check
7
23
  */
8
- export declare const createSkillCheck: (ability: number, proficiency: number) => DicePool;
24
+ export declare const createSkillCheck: (ability: number, proficiency: number, modifiers?: PoolModifiers) => DicePool;
9
25
  /**
10
26
  * Creates a combat check dice pool with optional boost die
11
27
  * @param ability Number of ability (green) dice
12
28
  * @param proficiency Number of proficiency (yellow) dice
13
29
  * @param boost Number of boost (blue) dice
30
+ * @param modifiers Optional modifiers from talents, equipment, etc.
14
31
  * @returns DicePool configured for a combat check
15
32
  */
16
- export declare const createCombatCheck: (ability: number, proficiency: number, boost?: number) => DicePool;
33
+ export declare const createCombatCheck: (ability: number, proficiency: number, boost?: number, modifiers?: PoolModifiers) => DicePool;
17
34
  /**
18
35
  * Creates an opposed check dice pool
19
36
  * @param ability Number of ability (green) dice
20
37
  * @param proficiency Number of proficiency (yellow) dice
21
38
  * @param difficulty Number of difficulty (purple) dice
22
39
  * @param challenge Number of challenge (red) dice
40
+ * @param modifiers Optional modifiers from talents, equipment, etc.
23
41
  * @returns DicePool configured for an opposed check
24
42
  */
25
- export declare const createOpposedCheck: (ability: number, proficiency: number, difficulty: number, challenge?: number) => DicePool;
43
+ export declare const createOpposedCheck: (ability: number, proficiency: number, difficulty: number, challenge?: number, modifiers?: PoolModifiers) => DicePool;
26
44
  /**
27
45
  * Creates a difficulty check dice pool
28
46
  * @param difficulty Number of difficulty (purple) dice
29
47
  * @param challenge Number of challenge (red) dice
48
+ * @param modifiers Optional modifiers from talents, equipment, etc.
30
49
  * @returns DicePool configured for a pure difficulty check
31
50
  */
32
- export declare const createDifficultyPool: (difficulty: number, challenge?: number) => DicePool;
51
+ export declare const createDifficultyPool: (difficulty: number, challenge?: number, modifiers?: PoolModifiers) => DicePool;
52
+ /**
53
+ * Applies talent modifiers to an existing dice pool
54
+ * Common use case for talents that add automatic advantages, successes, or upgrade dice
55
+ * @param pool The base dice pool
56
+ * @param modifiers The modifiers to apply
57
+ * @returns A new dice pool with modifiers applied
58
+ */
59
+ export declare const applyTalentModifiers: (pool: DicePool, modifiers: PoolModifiers) => DicePool;
package/dist/pools.js CHANGED
@@ -1,15 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createDifficultyPool = exports.createOpposedCheck = exports.createCombatCheck = exports.createSkillCheck = void 0;
3
+ exports.applyTalentModifiers = exports.createDifficultyPool = exports.createOpposedCheck = exports.createCombatCheck = exports.createSkillCheck = void 0;
4
4
  /**
5
5
  * Creates a basic skill check dice pool
6
6
  * @param ability Number of ability (green) dice
7
7
  * @param proficiency Number of proficiency (yellow) dice
8
+ * @param modifiers Optional modifiers from talents, equipment, etc.
8
9
  * @returns DicePool configured for a basic skill check
9
10
  */
10
- const createSkillCheck = (ability, proficiency) => ({
11
+ const createSkillCheck = (ability, proficiency, modifiers) => ({
11
12
  abilityDice: Math.max(0, ability),
12
13
  proficiencyDice: Math.max(0, proficiency),
14
+ ...modifiers,
13
15
  });
14
16
  exports.createSkillCheck = createSkillCheck;
15
17
  /**
@@ -17,12 +19,14 @@ exports.createSkillCheck = createSkillCheck;
17
19
  * @param ability Number of ability (green) dice
18
20
  * @param proficiency Number of proficiency (yellow) dice
19
21
  * @param boost Number of boost (blue) dice
22
+ * @param modifiers Optional modifiers from talents, equipment, etc.
20
23
  * @returns DicePool configured for a combat check
21
24
  */
22
- const createCombatCheck = (ability, proficiency, boost = 0) => ({
25
+ const createCombatCheck = (ability, proficiency, boost = 0, modifiers) => ({
23
26
  abilityDice: Math.max(0, ability),
24
27
  proficiencyDice: Math.max(0, proficiency),
25
28
  boostDice: Math.max(0, boost),
29
+ ...modifiers,
26
30
  });
27
31
  exports.createCombatCheck = createCombatCheck;
28
32
  /**
@@ -31,23 +35,48 @@ exports.createCombatCheck = createCombatCheck;
31
35
  * @param proficiency Number of proficiency (yellow) dice
32
36
  * @param difficulty Number of difficulty (purple) dice
33
37
  * @param challenge Number of challenge (red) dice
38
+ * @param modifiers Optional modifiers from talents, equipment, etc.
34
39
  * @returns DicePool configured for an opposed check
35
40
  */
36
- const createOpposedCheck = (ability, proficiency, difficulty, challenge = 0) => ({
41
+ const createOpposedCheck = (ability, proficiency, difficulty, challenge = 0, modifiers) => ({
37
42
  abilityDice: Math.max(0, ability),
38
43
  proficiencyDice: Math.max(0, proficiency),
39
44
  difficultyDice: Math.max(0, difficulty),
40
45
  challengeDice: Math.max(0, challenge),
46
+ ...modifiers,
41
47
  });
42
48
  exports.createOpposedCheck = createOpposedCheck;
43
49
  /**
44
50
  * Creates a difficulty check dice pool
45
51
  * @param difficulty Number of difficulty (purple) dice
46
52
  * @param challenge Number of challenge (red) dice
53
+ * @param modifiers Optional modifiers from talents, equipment, etc.
47
54
  * @returns DicePool configured for a pure difficulty check
48
55
  */
49
- const createDifficultyPool = (difficulty, challenge = 0) => ({
56
+ const createDifficultyPool = (difficulty, challenge = 0, modifiers) => ({
50
57
  difficultyDice: Math.max(0, difficulty),
51
58
  challengeDice: Math.max(0, challenge),
59
+ ...modifiers,
52
60
  });
53
61
  exports.createDifficultyPool = createDifficultyPool;
62
+ /**
63
+ * Applies talent modifiers to an existing dice pool
64
+ * Common use case for talents that add automatic advantages, successes, or upgrade dice
65
+ * @param pool The base dice pool
66
+ * @param modifiers The modifiers to apply
67
+ * @returns A new dice pool with modifiers applied
68
+ */
69
+ const applyTalentModifiers = (pool, modifiers) => ({
70
+ ...pool,
71
+ automaticSuccesses: (pool.automaticSuccesses || 0) + (modifiers.automaticSuccesses || 0),
72
+ automaticFailures: (pool.automaticFailures || 0) + (modifiers.automaticFailures || 0),
73
+ automaticAdvantages: (pool.automaticAdvantages || 0) + (modifiers.automaticAdvantages || 0),
74
+ automaticThreats: (pool.automaticThreats || 0) + (modifiers.automaticThreats || 0),
75
+ automaticTriumphs: (pool.automaticTriumphs || 0) + (modifiers.automaticTriumphs || 0),
76
+ automaticDespairs: (pool.automaticDespairs || 0) + (modifiers.automaticDespairs || 0),
77
+ upgradeAbility: (pool.upgradeAbility || 0) + (modifiers.upgradeAbility || 0),
78
+ upgradeDifficulty: (pool.upgradeDifficulty || 0) + (modifiers.upgradeDifficulty || 0),
79
+ downgradeProficiency: (pool.downgradeProficiency || 0) + (modifiers.downgradeProficiency || 0),
80
+ downgradeChallenge: (pool.downgradeChallenge || 0) + (modifiers.downgradeChallenge || 0),
81
+ });
82
+ exports.applyTalentModifiers = applyTalentModifiers;
package/dist/types.d.ts CHANGED
@@ -6,6 +6,18 @@ export type DicePool = {
6
6
  difficultyDice?: number;
7
7
  challengeDice?: number;
8
8
  forceDice?: number;
9
+ automaticSuccesses?: number;
10
+ automaticFailures?: number;
11
+ automaticAdvantages?: number;
12
+ automaticThreats?: number;
13
+ automaticTriumphs?: number;
14
+ automaticDespairs?: number;
15
+ automaticLightSide?: number;
16
+ automaticDarkSide?: number;
17
+ upgradeAbility?: number;
18
+ upgradeDifficulty?: number;
19
+ downgradeProficiency?: number;
20
+ downgradeChallenge?: number;
9
21
  };
10
22
  export type DiceResult = {
11
23
  successes: number;
@@ -39,6 +51,23 @@ export declare const SYMBOLS: {
39
51
  readonly DARK: "DARK";
40
52
  };
41
53
  export type Symbol = keyof typeof SYMBOLS;
54
+ export type DieFaceSymbols = {
55
+ successes?: number;
56
+ failures?: number;
57
+ advantages?: number;
58
+ threats?: number;
59
+ triumphs?: number;
60
+ despairs?: number;
61
+ lightSide?: number;
62
+ darkSide?: number;
63
+ };
64
+ export type BoostDieFace = 1 | 2 | 3 | 4 | 5 | 6;
65
+ export type SetbackDieFace = 1 | 2 | 3 | 4 | 5 | 6;
66
+ export type AbilityDieFace = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
67
+ export type DifficultyDieFace = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
68
+ export type ProficiencyDieFace = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
69
+ export type ChallengeDieFace = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
70
+ export type ForceDieFace = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
42
71
  export type RollOptions = {
43
72
  hints?: boolean;
44
73
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swrpg-online/dice",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
4
  "description": "A TypeScript library that creates dice rolls using the narrative dice system for the Star Wars Roleplaying Game by Fantasy Flight Games and Edge Studio.",
5
5
  "keywords": [
6
6
  "swrpg",
@@ -81,7 +81,7 @@
81
81
  "rollup": "^2.79.2",
82
82
  "rollup-plugin-terser": "^7.0.2",
83
83
  "semantic-release": "^24.2.0",
84
- "ts-jest": "^29.4.1",
84
+ "ts-jest": "^29.4.4",
85
85
  "tslib": "^2.8.1",
86
86
  "typescript": "^5.7.2"
87
87
  },