Update the gun macros

This commit is contained in:
Oliver-Akins 2025-05-16 18:53:59 -06:00
parent 9d4704897f
commit 9cee87b81e
6 changed files with 403 additions and 6 deletions

View file

@ -36,12 +36,17 @@ async function main() {
},
],
});
const { statBase, extraDice } = answers;
const { extraDice } = answers;
let { statBase } = answers;
let rollMode = game.settings.get(`core`, `rollMode`);
let diceCount = statBase;
diceCount += extraDice;
if (statBase === 6) {
diceCount += 6;
};
let statGain = 0;
let gunLoss = 0;
let successes = 0;
let critsOnly = 0;
@ -68,9 +73,16 @@ async function main() {
classes += ` success`;
}
if (statBase === 6 && i <= 6) {
if (i === 6) {
statBase -= 1;
};
continue
}
if (succeeded) {
try {
const { holdTheTrigger } = await DialogManager.ask({
const { holdTheTrigger, ventHeat } = await DialogManager.ask({
id: `mini-gun-hold-the-trigger`,
question: `Hold The Trigger?`,
inputs: [
@ -102,16 +114,17 @@ async function main() {
heatMeter += (holdTheTrigger ? 1 : -1);
if (holdTheTrigger) {
diceCount += 1;
}
};
if (heatMeter >= 6) {
heatMeter = 0;
gunLoss += 2;
}
statBase -= 2;
};
} catch {};
}
// Save dice stats if present
WorldAPI?.saveRollValue?.(sidesOnDice, total);
WorldAPI?.saveRollValue?.(6, total);
results.push(`<li class="${classes}">${total}</li>`);
};

View file

@ -0,0 +1,166 @@
const notifStyle = `
font-size: 1.5rem;
margin: 0.5rem 0;
padding: 6px 8px;
box-shadow: 0 0 10px var(--color-shadow-dark);
color: var(--color-text-light-1);
border-radius: 5px;
text-align: center;`;
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 main() {
let heatMeter = game.user.getFlag(`world`, `heatMeter`) ?? 0;
const answers = await DialogManager.ask({
id: `mini-gun-dice-pool`,
question: `Set up your dice pool:`,
inputs: [
{
key: `statBase`,
inputType: `number`,
label: `Stat Base`,
autofocus: true,
},
{
key: `extraDice`,
inputType: `number`,
label: `Extra Dice`,
defaultValue: 0,
},
],
});
const { extraDice } = answers;
let { statBase } = answers;
let rollMode = game.settings.get(`core`, `rollMode`);
let diceCount = statBase;
diceCount += extraDice;
if (statBase === 6) {
diceCount += 6;
};
let statGain = 0;
let gunLoss = 0;
let successes = 0;
let critsOnly = 0;
let results = [];
for (let i = 0; i < diceCount; i++) {
let succeeded = false;
let r = new Roll(`1d6`);
await r.evaluate();
let classes = `roll die d6`;
const total = r.total;
if (total <= statBase) {
successes += 1;
succeeded = true;
}
else {
classes += ` discarded`
}
if (total === statBase) {
successes += 1;
critsOnly += 1;
classes += ` success`;
}
if (statBase === 6 && i <= 6) {
if (i === 6) {
statBase -= 1;
};
continue
}
if (succeeded) {
try {
const { holdTheTrigger, ventHeat } = await DialogManager.ask({
id: `mini-gun-hold-the-trigger`,
question: `Hold The Trigger?`,
inputs: [
{
key: `_1`,
inputType: `hidden`,
label: `Success Count: ${successes}`,
},
{
key: `_2`,
inputType: `hidden`,
label: `Total Dice Rolled: ${i + 1}/${diceCount}`,
},
{
key: `_3`,
inputType: `hidden`,
label: `Current Heat: ${heatMeter}/6`,
},
{
key: `holdTheTrigger`,
inputType: `checkbox`,
label: `Hold The Trigger?`,
details: `If you hold the trigger, you roll an additional dice, and gain 1 heat. If you don't hold the trigger, you lose one heat. When you reach 6 heat, you lost all heat and lose 2 GUN.`,
defaultValue: false,
autofocus: true,
}
],
});
heatMeter += (holdTheTrigger ? 1 : -1);
if (holdTheTrigger) {
diceCount += 1;
};
if (heatMeter >= 6) {
heatMeter = 0;
gunLoss += 2;
statBase -= 2;
}
} catch {};
}
// Save dice stats if present
WorldAPI?.saveRollValue?.(6, total);
results.push(`<li class="${classes}">${total}</li>`);
};
game.user.setFlag(`world`, `heatMeter`, heatMeter);
WorldAPI?.saveRollValue?.(20, Math.min(diceCount, 20));
WorldAPI?.saveRollValue?.(100, successes === 0 ? 100 : successes);
let content = `Rolls:<div class="dice-tooltip"><ol class="dice-rolls">${results.join(`\n`)}</ol></div><hr>Gain 1 Momentum<br>Successes: ${successes}<br>Crits: ${critsOnly}<br>Final Heat: ${heatMeter}`;
if (gunLoss > 0) {
content += `<div style="${notifStyle} ${redNotif}">Lose ${gunLoss} GUN</div>`;
}
if (successes >= 8) {
content += `<div style="${notifStyle} ${greenNotif}">POP OFF</div> Add one to your hobby stat and gain 1 additional Momentum!`;
}
else if (successes === 0) {
content += `<div style="${notifStyle} ${redNotif}">Pinned Down</div> Roll a d6, rescuing you becomes a new objective`;
}
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: `(Gun: Mini-Gun)`,
content,
},
rollMode,
);
await ChatMessage.implementation.create(chatData);
}
main();