import{a as j}from"./chunk-PL2RISLB.js";import{a as x}from"./chunk-QXXFZBB5.js";import{b as z}from"./chunk-7DBUQ2CV.js";import{b as _}from"./chunk-KC6VWGIB.js";import{C as W,a as C,e as $,n as h,t as y,z as F}from"./chunk-IRFDE6LX.js";import{Platform as ae}from"@dndbeyond/event-pipeline-lib/shared";var G=()=>new URLSearchParams(globalThis.window?.location.search??"")?.get("platform")??ae.Web;var re=({diceNotation:S,action:w,rollType:M=F.Roll,rollKind:k,entityId:N,entityType:E,userId:a,setId:O,gameId:R,name:H,avatarUrl:J,valueOverride:X,operand:i,dmId:v},Y,Z,I)=>{let c=k?k.toLowerCase():"",g=z.getState().getDiceRollPrivacy(Number(a))?.rollTo||y.Everyone,o=c==="advantage"?"adv":c==="disadvantage"?"disadv":null,m;i||o==="adv"?m=2:o==="disadv"?m=1:m=0;let ee=c==="critical hit",d=S.replace(/\s+/g,"").split(/(?=[+-])/).map(e=>{let[r,l]=e.split("d");return[l?`d${l}`:"constant",Number(r)*(l&&ee?2:1)+(l&&o?1:0)]}),u=d.find(([e])=>e==="constant")?.[1]||0,P=d.reduce((e,[r,l])=>(e[r]=l,e),{}),t={constant:u,text:"",total:0,values:[]},L=g===y.Self?"userId":"gameId",Q=x(),te=Object.keys(P).filter(e=>e!=="constant").length!==0,V=!!(_.getState().getUserDiceData(Number(a))?.settings.visibility!==W.Disabled&&($||!Y&&Z)&&te),K=V?h.Deferred:h.Fulfilled,oe=v===a,U=String(g===y.Self?a===v?a:v:R),f={rollId:Q,diceRolled:{},results:{},action:w,type:M,kind:c,diceSet:O,audience:g,isDm:oe,eventType:K},T={data:{action:w,context:{entityId:N,entityType:E,messageScope:L,messageTarget:U,name:H,avatarUrl:J},rollId:Q,rolls:[{diceNotation:{constant:u,set:d.map(([e,r],l)=>{if(e==="constant"){t.text+=`+${u}`,t.total+=u;return}let s=e,q=[],ie=l===d.length-1;return{count:P[s],dice:[...Array(r)].map((ne,A)=>{f.diceRolled[s]=P[s];let n=X??Math.floor(Math.random()*Number(s.slice(1))+1);f.results[s]=[...f.results[s]||[],n];let b=A===r-1;(i||o)&&(q.push(n),A===0&&(t.text+="(")),t.text+=n,(i||o)&&(t.text+=b?")":","),!(i||o)&&!(b&&(u||ie))&&(t.text+="+");let B=(le,se)=>q.sort((p,D)=>le===1?p-D:D-p).slice(0,se).reduce((p,D)=>p+D,0);return t.total+=(i||o)&&!b?0:i?B(m,i):o?B(o==="adv"?2:1,1):n,t.values.push(n),{dieType:s,dieValue:n}}),dieType:s,operation:m,operand:i}}).filter(Boolean)},rollKind:c,rollType:M,result:t}],setId:O},dateTime:String(Date.now()),entityId:N,entityType:E,eventType:K,...R&&{gameId:R},id:x(),messageScope:L,messageTarget:U,persist:!V,source:G(),...a&&{userId:a}};return window[j]?.dispatch(T),I?.({...f,total:t.total}),C&&console.log("Rolled Dice Payload:",T),T};export{G as a,re as b};
//# sourceMappingURL=chunk-2UU42VTN.js.map
