// 🧠 Focus Power (DH2) — WP test + Phenomena/Perils with mode presets const actor = canvas.tokens.controlled[0]?.actor ?? game.user.character; if (!actor) return ui.notifications.warn("Zaznacz token."); new Dialog({ title: "🧠 Focus Power", content: `
`, buttons: { roll: { label: "Roll", callback: async html => { const wp = Number(html.find('[name="wp"]').val()); const pr = Number(html.find('[name="pr"]').val()); const mode = html.find('[name="mode"]').val(); const flat = Number(html.find('[name="flat"]').val()); const thr = Number(html.find('[name="thr"]').val()); let effPR = pr, ppmod = 0, ppAlways = false, note = ""; if (mode==="fettered"){ effPR = Math.max(1, Math.floor(pr/2)); note="(Fettered: PR/2, brak Phenomena)"; } if (mode==="push"){ effPR = pr+3; ppmod=10; ppAlways = true; note="(Push: +3 PR, Phenomena zawsze, +10)"; } const target = wp + flat; const roll = await (new Roll("1d100")).roll({async:true}); const ok = roll.total <= target; const dos = ok ? 1 + Math.floor((target - roll.total)/10) : Math.floor((roll.total - target)/10); const doubles = (roll.total%11===0) || (roll.total===100); const info = `
Target${target}Roll${roll.total}
Result${ok?'SUCCESS':'FAIL'} — ${ok?dos+' DoS':dos+' DoF'} ${doubles?' — DOUBLES':''}
Eff. PR${effPR}Range hint${effPR*10} m (jeśli moc tak działa)
`; roll.toMessage({speaker: ChatMessage.getSpeaker({actor}), flavor:`🧠 Focus Power ${note}
${info}`}); const needPP = (mode==="unfettered" && doubles) || (mode==="push") ; if (needPP){ const tbl = game.tables.getName("Psychic Phenomena"); if (tbl){ const r = await (new Roll(`1d100 + ${ppmod}`)).roll({async:true}); await tbl.draw({displayResults:true, roll:r}); if (r.total >= thr){ const per = game.tables.getName("Perils of the Warp"); if (per) await per.draw({displayResults:true}); } } else ChatMessage.create({content:"Utwórz RollTable: Psychic Phenomena (+ Perils of the Warp)"}); } }} } }).render(true);