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