Update D30 descriptions and add simple shield option for NPCs

This commit is contained in:
2026-04-16 23:42:24 +02:00
parent 8c9a13faf1
commit 81584ed5d6
4 changed files with 124 additions and 17 deletions

View File

@@ -527,6 +527,75 @@ export default class LethalFantasyUtils {
}
/* -------------------------------------------- */
/**
* Prompt the GM or player to choose an ad-hoc shield dice and DR value.
* Used when the defender has no pre-configured shield equipment.
* @param {string} defenderName
* @param {number} attackRoll
* @param {number} defenseRoll
* @returns {Promise<{formula: string, damageReduction: number}|null>}
*/
static async promptAdHocShield(defenderName, attackRoll, defenseRoll) {
const choices = this.getCombatBonusDiceChoices()
const optionsHtml = choices.map(c => `<option value="${c}">${c.toUpperCase()}</option>`).join("")
const content = `
<div class="grit-luck-dialog">
<div class="combat-status">
<p><strong>${defenderName}</strong> uses a shield (not equipped)</p>
<p>Attack: <strong>${attackRoll}</strong> — Current defense: <strong>${defenseRoll}</strong></p>
</div>
<div class="weapon-selection" style="margin-top:8px;">
<label for="shield-dice">Shield dice:</label>
<select id="shield-dice" name="shieldDice" style="width: 100%; margin-top: 4px;">
${optionsHtml}
</select>
</div>
<div class="weapon-selection" style="margin-top:8px;">
<label for="shield-dr">Shield DR value:</label>
<input id="shield-dr" name="shieldDR" type="number" min="0" value="0" style="width: 100%; margin-top: 4px;" />
</div>
</div>
`
const raw = await foundry.applications.api.DialogV2.wait({
window: { title: "Ad-hoc Shield Roll" },
classes: ["lethalfantasy"],
content,
buttons: [
{
action: "roll",
label: "Roll Shield",
icon: "fa-solid fa-shield",
callback: (event, button) => {
const shieldDice = button.form?.elements?.shieldDice ?? button.closest("form")?.elements?.shieldDice
const shieldDR = button.form?.elements?.shieldDR ?? button.closest("form")?.elements?.shieldDR
return {
formula: shieldDice?.value ?? "1d6",
damageReduction: Number(shieldDR?.value) || 0
}
}
},
{
action: "cancel",
label: "Cancel",
icon: "fa-solid fa-xmark",
callback: () => null
}
],
rejectClose: false
})
return raw ?? null
}
/* -------------------------------------------- */
/**
* Roll a bonus die formula, optionally showing Dice So Nice animation and posting a chat message.
* @param {string} formula
* @param {Actor} actor
* @param {Function} [messageContent]
* @returns {Promise<number>}
*/
static async rollBonusDie(formula, actor, messageContent) {
const roll = new Roll(formula)
await roll.evaluate()