@randsum/blades
Version:
Blades in the Dark compatible dice rolling implementation
11 lines • 2.3 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../src/rollBlades/index.ts", "../src/rollBlades/interpretHit.ts"],
"sourcesContent": [
"import type { RollRecord } from '@randsum/roller'\nimport { roll } from '@randsum/roller'\nimport { interpretHit } from './interpretHit'\nimport type { BladesResult } from '../types'\n\nexport function rollBlades(count: number): {\n result: BladesResult\n total: number\n rolls: RollRecord[]\n} {\n if (!Number.isInteger(count)) {\n throw new Error(`Blades dice pool must be an integer, received: ${count}`)\n }\n\n if (count < 0) {\n throw new Error(`Blades dice pool must be non-negative, received: ${count}`)\n }\n\n if (count > 10) {\n throw new Error(`Blades dice pool is unusually large (${count}). Maximum recommended is 10.`)\n }\n const canCrit = count > 0\n const rollResult = roll({\n sides: 6,\n quantity: canCrit ? count : 2,\n ...(canCrit\n ? {}\n : {\n modifiers: { drop: { highest: 1 } }\n })\n })\n return {\n ...rollResult,\n result: interpretHit(rollResult, canCrit)\n }\n}\n",
"import type { RollerRollResult } from '@randsum/roller'\nimport type { BladesResult } from '../types'\n\nexport function interpretHit({ rolls }: RollerRollResult, canCrit: boolean): BladesResult {\n const sortedRolls = rolls.flatMap(roll => roll.rolls)\n const sixes = sortedRolls.filter(r => r === 6).length\n if (sixes >= 2 && canCrit) {\n return 'critical'\n }\n\n switch (sortedRolls[0]) {\n case 6:\n return 'success'\n case 5:\n case 4:\n return 'partial'\n default:\n return 'failure'\n }\n}\n"
],
"mappings": "2hBACqB,IAArB,6BCEO,SAAS,CAAY,EAAG,SAA2B,EAAgC,CACxF,IAAM,EAAc,EAAM,QAAQ,KAAQ,EAAK,KAAK,EAEpD,GADc,EAAY,OAAO,KAAK,IAAM,CAAC,EAAE,QAClC,GAAK,EAChB,MAAO,WAGT,OAAQ,EAAY,QACb,GACH,MAAO,cACJ,OACA,GACH,MAAO,kBAEP,MAAO,WDZN,SAAS,CAAU,CAAC,EAIzB,CACA,IAAK,OAAO,UAAU,CAAK,EACzB,MAAM,IAAI,MAAM,kDAAkD,GAAO,EAG3E,GAAI,EAAQ,EACV,MAAM,IAAI,MAAM,oDAAoD,GAAO,EAG7E,GAAI,EAAQ,GACV,MAAM,IAAI,MAAM,wCAAwC,gCAAoC,EAE9F,IAAM,EAAU,EAAQ,EAClB,EAAa,OAAK,CACtB,MAAO,EACP,SAAU,EAAU,EAAQ,KACxB,EACA,CAAC,EACD,CACE,UAAW,CAAE,KAAM,CAAE,QAAS,CAAE,CAAE,CACpC,CACN,CAAC,EACD,MAAO,IACF,EACH,OAAQ,EAAa,EAAY,CAAO,CAC1C",
"debugId": "B4D7EAD18F900EDD64756E2164756E21",
"names": []
}