@randsum/daggerheart
Version:
A flexible, type-safe dice roller for building Daggerheart-compatible applications
4 lines (2 loc) • 931 B
JavaScript
import{roll as x,validateNotation as O}from"@randsum/roller";import{roll as g}from"@randsum/roller";function p(e,l){if(e===l)return"critical hope";if(e>l)return"hope";return"fear"}function u({rollingWith:e,amplifyHope:l=!1,amplifyFear:d=!1,modifier:s=0}){let r=g(...[{sides:l?20:12,key:"hope"},{sides:d?20:12,key:"fear"},e?{sides:6,key:e,arithmetic:e==="Advantage"?"add":"subtract"}:void 0].filter((t)=>!!t)),a=r.rolls.find((t)=>t.parameters.key==="hope"),o=r.rolls.find((t)=>t.parameters.key==="fear"),n=r.rolls.find((t)=>e&&t.parameters.key===e);if(!a||!o)throw new Error("Failed to properly roll.");let R=n?{roll:n.appliedTotal}:void 0;return{...r,result:{total:r.total+s,type:p(a.total,o.total),details:{hope:i(a),fear:i(o),advantage:R,modifier:s}}}}function i(e){return{roll:e.total,amplified:e.parameters.sides===20}}export{O as validateNotation,u as rollDaggerheart,x as roll};
//# debugId=C61ED6B6BAA481C264756E2164756E21