183 lines
4.1 KiB
JavaScript
183 lines
4.1 KiB
JavaScript
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`,
|
|
label: `Stat Base`,
|
|
autofocus: true,
|
|
options: [
|
|
{ label: "Heroism", value: "heroism" },
|
|
{ label: "Observation", value: "observation" },
|
|
{ label: "Nimbleness", value: "nimbleness" },
|
|
{ label: "Khaos", value: "khaos" },
|
|
]
|
|
},
|
|
{
|
|
type: `input`,
|
|
inputType: `number`,
|
|
key: `bonusDice`,
|
|
label: `Bonus Dice`,
|
|
},
|
|
{ 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)`,
|
|
},
|
|
{
|
|
type: `checkbox`,
|
|
key: `isCriticalRoll`,
|
|
label: `Is Critical Group Roll?`,
|
|
},
|
|
],
|
|
});
|
|
|
|
// 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, bonusDice, inspo, unspo, isCriticalRoll, } = 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 + bonusDice;
|
|
if (inspo) diceCount++;
|
|
if (unspo) diceCount--;
|
|
|
|
let modifier = `kh1`;
|
|
if (diceCount <= 0) {
|
|
diceCount = 2 + Math.abs(diceCount);
|
|
modifier = `kl1`;
|
|
};
|
|
|
|
const r = new Roll(`${diceCount}d6${modifier}`);
|
|
await r.evaluate();
|
|
|
|
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 = ``;
|
|
if (!isCriticalRoll) {
|
|
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;
|
|
};
|
|
}
|
|
else {
|
|
switch (total) {
|
|
case 1:
|
|
case 2:
|
|
case 3:
|
|
outcome = `Failure`;
|
|
notifType = redNotif;
|
|
break;
|
|
case 4:
|
|
case 5:
|
|
case 6:
|
|
outcome = `Pass`;
|
|
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;
|
|
};
|
|
|
|
/*
|
|
TODO: Add stats tracking here
|
|
*/
|
|
|
|
const chatData = ChatMessage.applyRollMode(
|
|
{
|
|
flavor: `${attr.name} Roll`,
|
|
content,
|
|
},
|
|
rollMode,
|
|
);
|
|
|
|
await ChatMessage.implementation.create(chatData);
|
|
};
|
|
|
|
await rollDice();
|