Add a macro for One Honk Two Furious' rolling logic

This commit is contained in:
Oliver-Akins 2025-07-27 00:10:13 -06:00
parent 6de3a2d2f4
commit 708917ae99

View file

@ -0,0 +1,153 @@
const notifStyle = `
font-size: 1.5rem;
margin: 0.5rem 0;
padding: 6px 8px;
box-shadow: 0 0 10px var(--color-shadow-dark);
color: white;
border-radius: 5px;
text-align: center;
background: var(--color-level-info-bg);
border: 1px solid var(--color-level-info-border);`;
const greenNotif = `
background: var(--color-level-success-bg);
border: 1px solid var(--color-level-success-border);`;
const redNotif = `
background: var(--color-level-error-bg);
border: 1px solid var(--color-level-error);`;
async function rollDice() {
const response = await taf.DialogManager.ask({
id: `hjonkin-dice-pool`,
inputs: [
{
type: `select`,
key: `stat`,
inputType: `number`,
label: `Stat Base`,
autofocus: true,
options: [
{ label: "Heroism", value: "heroism" },
{ label: "Observation", value: "observation" },
{ label: "Nimbleness", value: "nimbleness" },
{ label: "Khaos", value: "khaos" },
]
},
{ type: `divider` },
{
type: `details`,
details: `If your goose shows impressive problem solving, or extreme stupidity (like swimming in lava), your dice pool may be affected accordingly.`,
},
{
type: `checkbox`,
key: `inspo`,
label: `Inspiration (+1d6)`,
},
{
type: `checkbox`,
key: `unspo`,
label: `Unspiration (-1d6)`,
},
],
});
// Handle all of the non-success states
if (response.state === `errored`) {
ui.notifications.error(response.error);
return;
};
if (response.state === `fronted`) {
return;
};
let rollMode = game.settings.get(`core`, `rollMode`);
console.log(response);
const { stat, inspo, unspo } = response.answers;
if (game.user.isGM) {
ui.notifications.info(`The macro won't work for GMs`);
return;
};
const attr = game.user.character.system.attr[stat];
let diceCount = attr.value;
if (inspo) diceCount++;
if (unspo) diceCount--;
let modifier = `kh1`;
if (diceCount <= 0) {
diceCount = 2 + Math.abs(diceCount);
modifier = `kl1`;
};
console.table({modifier, diceCount});
const r = new Roll(`${diceCount}d6${modifier}`);
await r.evaluate();
console.log(r)
const diceResults = [];
const diceHTML = [];
let countOfOnes = 0;
let countOfSixes = 0;
for (let die of r.dice) {
for (const result of die.results) {
let classes = [`roll`, `dice`, `d6`];
if (result.result === 6) countOfSixes++;
else if (result.result === 1) countOfOnes++;
if (result.active) classes.push(`success`);
if (result.discarded) classes.push(`discarded`);
diceResults.push(result.result);
diceHTML.push(`<li class="${classes.join(` `)}">${result.result}</li>`);
};
};
const total = r.total;
let outcome;
let notifType = ``;
switch (total) {
case 1:
case 2:
case 3:
outcome = `Failure`;
notifType = redNotif;
break;
case 4:
case 5:
outcome = `Partial Success`;
break;
case 6:
outcome = `Full Success!`;
notifType = greenNotif;
break;
};
let content = `Rolls:<div class="dice-tooltip"><ol class="dice-rolls">${diceHTML.join(`\n`)}</ol></div><hr><div style="${notifStyle} ${notifType}">${outcome}</div>`;
if (countOfSixes >= 2) {
content += `<div style="${notifStyle} ${greenNotif}">Good Luck</div>`;
};
if (countOfOnes >= 2) {
content += `<div style="${notifStyle} ${redNotif}">Bad Luck</div>`;
};
if (rollMode === CONST.DICE_ROLL_MODES.BLIND) {
ui.notifications.info(`Cannot make a blind roll from the macro, rolling with mode "Private GM Roll" instead`);
rollMode = CONST.DICE_ROLL_MODES.PRIVATE;
};
const chatData = ChatMessage.applyRollMode(
{
flavor: `${attr.name} Roll`,
content,
},
rollMode,
);
await ChatMessage.implementation.create(chatData);
};
await rollDice();