Files
conjurer/rpg/focus_power.js
T
2025-08-15 19:31:22 +02:00

51 lines
3.2 KiB
JavaScript

// 🧠 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: `
<form>
<div class="form-group"><label>Willpower (target)</label><input name="wp" type="number" value="40"/></div>
<div class="form-group"><label>Psychic Rating (PR)</label><input name="pr" type="number" value="3"/></div>
<div class="form-group"><label>Mode</label>
<select name="mode"><option value="fettered">Fettered (no PP; PR/2)</option><option value="unfettered" selected>Unfettered (PP on doubles)</option><option value="push">Push (always PP; +PR)</option></select></div>
<div class="form-group"><label>Power difficulty/gear/etc. (flat mod)</label><input name="flat" type="number" value="0"/></div>
<div class="form-group"><label>Perils threshold</label><input name="thr" type="number" value="75"/></div>
</form>`,
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 = `<table style="width:100%;border-collapse:collapse">
<tr><td><b>Target</b></td><td>${target}</td><td><b>Roll</b></td><td>${roll.total}</td></tr>
<tr><td><b>Result</b></td><td colspan="3">${ok?'<span style="color:green">SUCCESS</span>':'<span style="color:red">FAIL</span>'}${ok?dos+' DoS':dos+' DoF'} ${doubles?' — <b>DOUBLES</b>':''}</td></tr>
<tr><td><b>Eff. PR</b></td><td>${effPR}</td><td><b>Range hint</b></td><td>${effPR*10} m (jeśli moc tak działa)</td></tr>
</table>`;
roll.toMessage({speaker: ChatMessage.getSpeaker({actor}), flavor:`🧠 <b>Focus Power</b> ${note}<br/>${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: <b>Psychic Phenomena</b> (+ <b>Perils of the Warp</b>)"});
}
}}
}
}).render(true);